fixing BR #261 (making fields removable from the chatmonitor). Changes effect current...
[quassel.git] / src / qtui / mainwin.cpp
index e134bc0..9d0de30 100644 (file)
 #include "mainwin.h"
 
 #include "aboutdlg.h"
-#include "chatwidget.h"
 #include "bufferview.h"
 #include "bufferviewconfig.h"
 #include "bufferviewfilter.h"
 #include "bufferviewmanager.h"
 #include "channellistdlg.h"
+#include "chatlinemodel.h"
+#include "chatmonitorfilter.h"
+#include "chatmonitorview.h"
+#include "chatview.h"
 #include "client.h"
 #include "clientbacklogmanager.h"
 #include "coreinfodlg.h"
 #include "coreconnectdlg.h"
+#include "msgprocessorstatuswidget.h"
+#include "qtuimessageprocessor.h"
 #include "networkmodel.h"
 #include "buffermodel.h"
 #include "nicklistwidget.h"
@@ -68,6 +73,7 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent)
     gui(_gui),
     coreLagLabel(new QLabel()),
     sslLabel(new QLabel()),
+    msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
     _titleSetter(this),
     systray(new QSystemTrayIcon(this)),
     activeTrayIcon(":/icons/quassel-icon-active.png"),
@@ -81,12 +87,12 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent)
 {
   UiSettings uiSettings;
   loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
-  
+
   QString style = uiSettings.value("Style", QString("")).toString();
   if(style != "") {
     QApplication::setStyle(style);
   }
-  
+
   ui.setupUi(this);
   setWindowTitle("Quassel IRC");
   setWindowIcon(offlineTrayIcon);
@@ -150,9 +156,9 @@ void MainWin::init() {
   // restore mainwin state
   restoreState(s.value("MainWinState").toByteArray());
 
-  // restore locked state of docks  
+  // restore locked state of docks
   ui.actionLockDockPositions->setChecked(s.value("LockDocks", false).toBool());
-  
+
 
   setDisconnectedState();  // Disable menus and stuff
   showCoreConnectionDlg(true); // autoconnect if appropriate
@@ -204,7 +210,7 @@ void MainWin::addBufferView(BufferViewConfig *config) {
   view->show();
 
   connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList()));
-  
+
   Client::bufferModel()->synchronizeView(view);
 
   dock->setWidget(view);
@@ -286,26 +292,17 @@ void MainWin::setupNickWidget() {
 }
 
 void MainWin::setupChatMonitor() {
-#ifndef SPUTDEV
   VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
   dock->setObjectName("ChatMonitorDock");
 
-  ChatWidget *chatWidget = new ChatWidget(0, this);
-  chatWidget->show();
-  dock->setWidget(chatWidget);
+  ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
+  ChatMonitorView *chatView = new ChatMonitorView(filter, this);
+  chatView->show();
+  dock->setWidget(chatView);
   dock->show();
 
-  Buffer *buf = Client::monitorBuffer();
-  if(!buf)
-    return;
-
-  chatWidget->setContents(buf->contents());
-  connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
-  connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
-
   addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
   ui.menuViews->addAction(dock->toggleViewAction());
-#endif /* SPUTDEV */
 }
 
 void MainWin::setupInputWidget() {
@@ -342,6 +339,10 @@ void MainWin::setupTopicWidget() {
 }
 
 void MainWin::setupStatusBar() {
+  // MessageProcessor progress
+  statusBar()->addPermanentWidget(msgProcessorStatusWidget);
+  connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
+
   // Core Lag:
   updateLagIndicator(0);
   statusBar()->addPermanentWidget(coreLagLabel);
@@ -373,7 +374,8 @@ void MainWin::saveStatusBarStatus(bool enabled) {
 
 void MainWin::setupSystray() {
   connect(timer, SIGNAL(timeout()), this, SLOT(makeTrayIconBlink()));
-  connect(Client::instance(), SIGNAL(messageReceived(const Message &)), this, SLOT(receiveMessage(const Message &)));
+  connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+                            this, SLOT(messagesInserted(const QModelIndex &, int, int)));
 
   systrayMenu = new QMenu(this);
   systrayMenu->addAction(ui.actionAboutQuassel);
@@ -457,7 +459,7 @@ void MainWin::saveLayout() {
 }
 
 void MainWin::updateLagIndicator(int lag) {
-  coreLagLabel->setText(QString("Core Lag: %1 msec").arg(lag));
+  coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
 }
 
 
@@ -584,37 +586,45 @@ void MainWin::toggleVisibility() {
   }
 }
 
-void MainWin::receiveMessage(const Message &msg) {
+void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
+  Q_UNUSED(parent);
   if(QApplication::activeWindow() != 0)
     return;
 
-  if(msg.flags() & Message::Highlight || msg.bufferInfo().type() == BufferInfo::QueryBuffer) {
-    QString title = msg.bufferInfo().bufferName();;
-    if(msg.bufferInfo().type() != BufferInfo::QueryBuffer) {
-      QString sender = msg.sender();
-      int i = sender.indexOf("!");
-      if(i != -1)
-        sender = sender.left(i);
-      title += QString(" - %1").arg(sender);
-    }
+  // FIXME
+  return;
 
-    UiSettings uiSettings;
-
-#ifndef SPUTDEV
-    bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool();
-    bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool();
-    if(displayBubble || displayDesktop) {
-      // FIXME don't invoke style engine for this!
-      QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText;
-      if(displayBubble) displayTrayIconMessage(title, text);
-#  ifdef HAVE_DBUS
-      if(displayDesktop) sendDesktopNotification(title, text);
-#  endif
+  for(int i = start; i <= end; i++) {
+    QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
+    if(!idx.isValid()) {
+      qDebug() << "MainWin::messagesInserted(): Invalid model index!";
+      continue;
     }
-#endif
-    if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
-      QApplication::alert(this);
-      setTrayIconActivity(true);
+    Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
+    BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
+    BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
+
+    if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
+      QString title = Client::networkModel()->networkName(bufId) + " - " + Client::networkModel()->bufferName(bufId);
+
+      // FIXME Don't instantiate this for every highlight...
+      UiSettings uiSettings;
+
+      bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool();
+      bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool();
+      if(displayBubble || displayDesktop) {
+        if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) {
+          QString text = idx.data(ChatLineModel::DisplayRole).toString();
+          if(displayBubble) displayTrayIconMessage(title, text);
+#   ifdef HAVE_DBUS
+          if(displayDesktop) sendDesktopNotification(title, text);
+#   endif
+        }
+        if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
+          QApplication::alert(this);
+          setTrayIconActivity(true);
+        }
+      }
     }
   }
 }
@@ -753,7 +763,7 @@ void MainWin::clientNetworkRemoved(NetworkId id) {
   QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
   if(!action)
     return;
-  
+
   action->deleteLater();
 }
 
@@ -766,3 +776,16 @@ void MainWin::connectOrDisconnectFromNet() {
   else net->requestDisconnect();
 }
 
+
+
+void MainWin::on_actionDebugNetworkModel_triggered(bool) {
+  QTreeView *view = new QTreeView;
+  view->setAttribute(Qt::WA_DeleteOnClose);
+  view->setWindowTitle("Debug NetworkModel View");
+  view->setModel(Client::networkModel());
+  view->setColumnWidth(0, 250);
+  view->setColumnWidth(1, 250);
+  view->setColumnWidth(2, 80);
+  view->resize(610, 300);
+  view->show();
+}