- Improved the speed of IrcServerHandler (and other BasicHandler
[quassel.git] / src / qtui / mainwin.cpp
index c24120b..6c63404 100644 (file)
@@ -1,11 +1,11 @@
 /***************************************************************************
 /***************************************************************************
- *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
+ *   (at your option) version 3.                                           *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+//#define SPUTDEV
 
 #include "mainwin.h"
 
 #include "bufferview.h"
 
 #include "mainwin.h"
 
 #include "bufferview.h"
-#include "chatline.h"
+#include "chatline-old.h"
 #include "client.h"
 #include "coreconnectdlg.h"
 #include "client.h"
 #include "coreconnectdlg.h"
+#include "networkmodel.h"
+#include "buffermodel.h"
+#include "nicklistwidget.h"
 #include "serverlist.h"
 #include "settingsdlg.h"
 #include "serverlist.h"
 #include "settingsdlg.h"
-//#include "settingspage.h"
 #include "signalproxy.h"
 #include "signalproxy.h"
-
 #include "topicwidget.h"
 #include "topicwidget.h"
+#include "uisettings.h"
+
+#include "selectionmodelsynchronizer.h"
+#include "mappedselectionmodel.h"
+
+#include "settingspages/fontssettingspage.h"
+#include "settingspages/identitiessettingspage.h"
+
+#include "debugconsole.h"
 
 MainWin::MainWin(QtUi *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui) {
   ui.setupUi(this);
   setWindowTitle("Quassel IRC");
   //setWindowTitle(QString::fromUtf8("Κυασελ Εγαρζη"));
 
 MainWin::MainWin(QtUi *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui) {
   ui.setupUi(this);
   setWindowTitle("Quassel IRC");
   //setWindowTitle(QString::fromUtf8("Κυασελ Εγαρζη"));
-  setWindowIcon(QIcon(":/qirc-icon.png"));
+  setWindowIcon(QIcon(":icons/quassel-icon.png"));
   setWindowIconText("Quassel IRC");
 
   statusBar()->showMessage(tr("Waiting for core..."));
   setWindowIconText("Quassel IRC");
 
   statusBar()->showMessage(tr("Waiting for core..."));
-  
+  serverListDlg = new ServerListDlg(this);
+  settingsDlg = new SettingsDlg(this);
+  debugConsole = new DebugConsole(this);
 }
 
 void MainWin::init() {
 }
 
 void MainWin::init() {
@@ -55,51 +68,76 @@ void MainWin::init() {
 
   statusBar()->showMessage(tr("Not connected to core."));
   systray = new QSystemTrayIcon(this);
 
   statusBar()->showMessage(tr("Not connected to core."));
   systray = new QSystemTrayIcon(this);
-  systray->setIcon(QIcon(":/qirc-icon.png"));
+  systray->setIcon(QIcon(":/icons/quassel-icon.png"));
   systray->show();
 
   //setupSettingsDlg();
 
   setupMenus();
   setupViews();
   systray->show();
 
   //setupSettingsDlg();
 
   setupMenus();
   setupViews();
+  setupSettingsDlg();
 
 
-  QSettings s;
-  s.beginGroup("Geometry");
-  //resize(s.value("MainWinSize", QSize(500, 400)).toSize());
-  //move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
-  if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
-  s.endGroup();
+  // create nick dock
+  nickDock = new QDockWidget(tr("Nicks"), this);
+  nickDock->setObjectName("NickDock");
+  nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
 
 
-  //s.beginGroup("Buffers");
-  //QString net = s.value("CurrentNetwork", "").toString();
-  //QString buf = s.value("CurrentBuffer", "").toString();
-  //s.endGroup();
+  nickListWidget = new NickListWidget(nickDock);
+  nickDock->setWidget(nickListWidget);
+
+  addDockWidget(Qt::RightDockWidgetArea, nickDock);
+  ui.menuViews->addAction(nickDock->toggleViewAction());
+
+  // restore mainwin state
+  UiSettings s;
+  restoreState(s.value("MainWinState").toByteArray());
 
   disconnectedFromCore();  // Disable menus and stuff
   showCoreConnectionDlg(true); // autoconnect if appropriate
   //ui.actionConnectCore->activate(QAction::Trigger);
 
 
   disconnectedFromCore();  // Disable menus and stuff
   showCoreConnectionDlg(true); // autoconnect if appropriate
   //ui.actionConnectCore->activate(QAction::Trigger);
 
-  serverListDlg = new ServerListDlg(this);
   if(serverListDlg->showOnStartup()) {
     showServerList();
   }
   if(serverListDlg->showOnStartup()) {
     showServerList();
   }
+  
+  setDockNestingEnabled(true);
+  
+  
+  // new Topic Stuff... should be probably refactored out into a separate method
+  
+  setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
+  setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
 
 
-  // TESTING
-//   setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
-//   setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
+  setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
+  setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
 
 
-//   setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
-//   setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
-  
-//   QDockWidget *dock = new QDockWidget("Topic Dock", this);
-//   dock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
 
 
-//   TopicWidget *topicwidget = new TopicWidget(dock);
-//   dock->setWidget(topicwidget);
-  
-//   addDockWidget(Qt::TopDockWidgetArea, dock);
+  QDockWidget *dock = new QDockWidget(tr("Topic Dock"), this);
+  dock->setObjectName("TopicDock");
+  dock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
+
+  TopicWidget *topicwidget = new TopicWidget(dock);
+  dock->setWidget(topicwidget);
+
+  Client::bufferModel()->mapProperty(1, Qt::DisplayRole, topicwidget, "topic");
+
+  addDockWidget(Qt::TopDockWidgetArea, dock);
+
+  ui.menuViews->addAction(dock->toggleViewAction());
+
 
 
-//   ui.menuViews->addAction(dock->toggleViewAction());
+  // attach the BufferWidget to the PropertyMapper
+  Client::bufferModel()->mapProperty(0, NetworkModel::BufferIdRole, ui.bufferWidget, "currentBuffer");
+  connect(Client::networkModel(), SIGNAL(bufferAboutToBeRemoved(BufferId)),
+         ui.bufferWidget, SLOT(removeBuffer(BufferId)));
+
+  // attach the NickList to the PropertyMapper
+  Client::bufferModel()->mapProperty(0, NetworkModel::BufferIdRole, nickListWidget, "currentBuffer");
+  
+  
+#ifdef SPUTDEV
+  showSettingsDlg();
+#endif
 
 }
 
 
 }
 
@@ -126,47 +164,49 @@ void MainWin::setupMenus() {
   connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
   connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
   connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
   connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
   connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
   connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
-  ui.actionSettingsDlg->setEnabled(false);
+  connect(ui.actionDebug_Console, SIGNAL(triggered()), this, SLOT(showDebugConsole()));
   connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
   connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
-  // for debugging
-  connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
-  Client::signalProxy()->attachSignal(this, SIGNAL(importOldBacklog()));
 }
 
 void MainWin::setupViews() {
 }
 
 void MainWin::setupViews() {
-  
-  BufferTreeModel *model = Client::bufferModel();
-  connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
-
-  addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QStringList());
-  addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QStringList());
-  addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QStringList());
-  addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QStringList());
-  addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QStringList());
-  
+  BufferModel *model = Client::bufferModel();
+
+  addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QList<uint>());
+  addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QList<uint>());
+  addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QList<uint>());
+  addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QList<uint>());
+  addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QList<uint>());
+
   ui.menuViews->addSeparator();
 }
 
   ui.menuViews->addSeparator();
 }
 
-void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, const BufferViewFilter::Modes &mode, const QStringList &nets) {
+void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, const BufferViewFilter::Modes &mode, const QList<uint> &nets) {
   QDockWidget *dock = new QDockWidget(viewname, this);
   dock->setObjectName(QString("ViewDock-" + viewname)); // should be unique for mainwindow state!
   dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
   QDockWidget *dock = new QDockWidget(viewname, this);
   dock->setObjectName(QString("ViewDock-" + viewname)); // should be unique for mainwindow state!
   dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
-  //dock->setContentsMargins(4,4,4,4);
 
   //create the view and initialize it's filter
   BufferView *view = new BufferView(dock);
 
   //create the view and initialize it's filter
   BufferView *view = new BufferView(dock);
+  view->show();
   view->setFilteredModel(model, mode, nets);
   view->setFilteredModel(model, mode, nets);
+  Client::bufferModel()->synchronizeView(view);
   dock->setWidget(view);
   dock->setWidget(view);
-  
+  dock->show();
+
   addDockWidget(Qt::LeftDockWidgetArea, dock);
   ui.menuViews->addAction(dock->toggleViewAction());
 
   netViews.append(dock);
 }
 
   addDockWidget(Qt::LeftDockWidgetArea, dock);
   ui.menuViews->addAction(dock->toggleViewAction());
 
   netViews.append(dock);
 }
 
+void MainWin::setupSettingsDlg() {
+  settingsDlg->registerSettingsPage(new FontsSettingsPage(settingsDlg));
+  settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg));
+}
+
 void MainWin::connectedToCore() {
   foreach(BufferInfo id, Client::allBufferInfos()) {
 void MainWin::connectedToCore() {
   foreach(BufferInfo id, Client::allBufferInfos()) {
-    emit requestBacklog(id, 100, -1);
+    emit requestBacklog(id, 1000, -1);
   }
 
   ui.menuViews->setEnabled(true);
   }
 
   ui.menuViews->setEnabled(true);
@@ -175,6 +215,7 @@ void MainWin::connectedToCore() {
   ui.actionDisconnectCore->setEnabled(true);
   ui.actionNetworkList->setEnabled(true);
   ui.bufferWidget->show();
   ui.actionDisconnectCore->setEnabled(true);
   ui.actionNetworkList->setEnabled(true);
   ui.bufferWidget->show();
+  statusBar()->showMessage(tr("Connected to core."));
 }
 
 void MainWin::disconnectedFromCore() {
 }
 
 void MainWin::disconnectedFromCore() {
@@ -184,7 +225,8 @@ void MainWin::disconnectedFromCore() {
   ui.actionNetworkList->setEnabled(false);
   ui.bufferWidget->hide();
   ui.actionConnectCore->setEnabled(true);
   ui.actionNetworkList->setEnabled(false);
   ui.bufferWidget->hide();
   ui.actionConnectCore->setEnabled(true);
-  //qDebug() << "mainwin disconnected";
+  nickListWidget->reset();
+  statusBar()->showMessage(tr("Not connected to core."));
 }
 
 AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
 }
 
 AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
@@ -218,20 +260,18 @@ void MainWin::showSettingsDlg() {
   settingsDlg->show();
 }
 
   settingsDlg->show();
 }
 
+void MainWin::showDebugConsole() {
+  debugConsole->show();
+}
+
 void MainWin::closeEvent(QCloseEvent *event)
 {
   //if (userReallyWantsToQuit()) {
     ui.bufferWidget->saveState();
 void MainWin::closeEvent(QCloseEvent *event)
 {
   //if (userReallyWantsToQuit()) {
     ui.bufferWidget->saveState();
-    QSettings s;
-    s.beginGroup("Geometry");
+    UiSettings s;
     s.setValue("MainWinSize", size());
     s.setValue("MainWinPos", pos());
     s.setValue("MainWinState", saveState());
     s.setValue("MainWinSize", size());
     s.setValue("MainWinPos", pos());
     s.setValue("MainWinState", saveState());
-    s.endGroup();
-    s.beginGroup("Buffers");
-    //s.setValue("CurrentNetwork", currentNetwork);
-    s.setValue("CurrentBuffer", currentBuffer);
-    s.endGroup();
     delete systray;
     event->accept();
   //} else {
     delete systray;
     event->accept();
   //} else {
@@ -239,23 +279,3 @@ void MainWin::closeEvent(QCloseEvent *event)
   //}
 }
 
   //}
 }
 
-void MainWin::showBuffer(BufferInfo id) {
-  showBuffer(Client::buffer(id));
-}
-
-void MainWin::showBuffer(Buffer *b) {
-  currentBuffer = b->bufferInfo().groupId();
-  //emit bufferSelected(b);
-  //qApp->processEvents();
-      
-  ui.bufferWidget->setBuffer(b);
-  //emit bufferSelected(b);
-}
-
-void MainWin::importBacklog() {
-  if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
-                                "<b>This will permanently delete the contents of your database!</b>",
-                                QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
-    emit importOldBacklog();
-  }
-}