X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmainwin.cpp;h=0a3147f64bafa4de0b6caaed21b68657950b3e75;hp=d302ee148272043de388aef166b363be9f2a8df1;hb=d1a868e19f07cd719f958ab5d401d3c4564c91b3;hpb=4df7862b00b2113dabdf52342b2c15560313f476 diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index d302ee14..0a3147f6 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -18,12 +18,13 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "mainwin.h" - +#include #include "aboutdlg.h" -#include "bufferview.h" -#include "bufferviewconfig.h" -#include "bufferviewfilter.h" +#include "action.h" +#include "actioncollection.h" +#include "buffermodel.h" #include "bufferviewmanager.h" +#include "bufferwidget.h" #include "channellistdlg.h" #include "chatlinemodel.h" #include "chatmonitorfilter.h" @@ -33,24 +34,29 @@ #include "clientbacklogmanager.h" #include "coreinfodlg.h" #include "coreconnectdlg.h" +#include "debuglogwidget.h" +#include "debugmessagemodelfilter.h" +#include "iconloader.h" +#include "inputwidget.h" +#include "inputline.h" +#include "irclistmodel.h" +#include "jumpkeyhandler.h" #include "msgprocessorstatuswidget.h" -#include "qtuimessageprocessor.h" -#include "networkmodel.h" -#include "buffermodel.h" #include "nicklistwidget.h" +#include "qtuiapplication.h" +#include "qtuimessageprocessor.h" +#include "qtuisettings.h" +#include "sessionsettings.h" #include "settingsdlg.h" #include "settingspagedlg.h" -#include "signalproxy.h" #include "topicwidget.h" -#include "inputwidget.h" -#include "irclistmodel.h" #include "verticaldock.h" -#include "uisettings.h" -#include "qtuisettings.h" -#include "jumpkeyhandler.h" -#include "selectionmodelsynchronizer.h" -#include "mappedselectionmodel.h" +#ifdef HAVE_DBUS +# include "desktopnotificationbackend.h" +#endif +#include "systraynotificationbackend.h" +#include "taskbarnotificationbackend.h" #include "settingspages/aliasessettingspage.h" #include "settingspages/appearancesettingspage.h" @@ -63,51 +69,37 @@ #include "settingspages/networkssettingspage.h" #include "settingspages/notificationssettingspage.h" -#include "global.h" -#include "qtuistyle.h" - MainWin::MainWin(QWidget *parent) : QMainWindow(parent), coreLagLabel(new QLabel()), sslLabel(new QLabel()), msgProcessorStatusWidget(new MsgProcessorStatusWidget()), - _titleSetter(this), - systray(new QSystemTrayIcon(this)), - - activeTrayIcon(":/icons/quassel-icon-active.png"), - onlineTrayIcon(":/icons/quassel-icon.png"), - offlineTrayIcon(":/icons/quassel-icon-offline.png"), - trayIconActive(false), - - timer(new QTimer(this)) + _trayIcon(new QSystemTrayIcon(this)) { - UiSettings uiSettings; - QString style = uiSettings.value("Style", QString("")).toString(); - if(style != "") { + QtUiSettings uiSettings; + QString style = uiSettings.value("Style", QString()).toString(); + if(!style.isEmpty()) { QApplication::setStyle(style); } - ui.setupUi(this); + QApplication::setQuitOnLastWindowClosed(false); + setWindowTitle("Quassel IRC"); - setWindowIcon(offlineTrayIcon); - qApp->setWindowIcon(offlineTrayIcon); - systray->setIcon(offlineTrayIcon); setWindowIconText("Quassel IRC"); - - statusBar()->showMessage(tr("Waiting for core...")); + updateIcon(); installEventFilter(new JumpKeyHandler(this)); + QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this)); + QtUi::registerNotificationBackend(new SystrayNotificationBackend(this)); #ifdef HAVE_DBUS - desktopNotifications = new org::freedesktop::Notifications( - "org.freedesktop.Notifications", - "/org/freedesktop/Notifications", - QDBusConnection::sessionBus(), this); - notificationId = 0; - connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint))); - connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&))); + QtUi::registerNotificationBackend(new DesktopNotificationBackend(this)); #endif + + QtUiApplication* app = qobject_cast qApp; + connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&))); + connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&))); } void MainWin::init() { @@ -117,50 +109,40 @@ void MainWin::init() { else resize(QSize(800, 500)); - Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant))); - - connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(saveLayout())); - - connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkCreated(NetworkId))); - connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId))); + connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout())); + connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId))); + connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId))); - show(); - - statusBar()->showMessage(tr("Not connected to core.")); - - // DOCK OPTIONS + // Setup Dock Areas setDockNestingEnabled(true); - setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); - // setup stuff... + // Order is sometimes important + setupActions(); + setupBufferWidget(); setupMenus(); setupViews(); - setupNickWidget(); setupTopicWidget(); setupChatMonitor(); + setupNickWidget(); setupInputWidget(); setupStatusBar(); setupSystray(); + setupTitleSetter(); // restore mainwin state restoreState(s.value("MainWinState").toByteArray()); // restore locked state of docks - ui.actionLockDockPositions->setChecked(s.value("LockDocks", false).toBool()); + QtUi::actionCollection("General")->action("LockDockPositions")->setChecked(s.value("LockDocks", false).toBool()); setDisconnectedState(); // Disable menus and stuff - showCoreConnectionDlg(true); // autoconnect if appropriate - - // attach the BufferWidget to the BufferModel and the default selection - ui.bufferWidget->setModel(Client::bufferModel()); - ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); - _titleSetter.setModel(Client::bufferModel()); - _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel()); + show(); + showCoreConnectionDlg(true); // autoconnect if appropriate } MainWin::~MainWin() { @@ -170,14 +152,101 @@ MainWin::~MainWin() { s.setValue("MainWinState", saveState()); } +void MainWin::updateIcon() { + QPixmap icon; + if(Client::isConnected()) + icon = DesktopIcon("quassel", IconLoader::SizeEnormous); + else + icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous); + setWindowIcon(icon); + qApp->setWindowIcon(icon); + systemTrayIcon()->setIcon(icon); +} + +void MainWin::setupActions() { + ActionCollection *coll = QtUi::actionCollection("General"); + // File + coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll, + this, SLOT(showCoreConnectionDlg()))); + coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll, + Client::instance(), SLOT(disconnectFromCore()))); + coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll, + this, SLOT(showCoreInfoDlg()))); + coll->addAction("EditNetworks", new Action(SmallIcon("configure"), tr("Edit &Networks..."), coll, + this, SLOT(on_actionEditNetworks_triggered()))); + coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll, + qApp, SLOT(quit()), tr("Ctrl+Q"))); + + // View + coll->addAction("ManageBufferViews", new Action(SmallIcon("view-tree"), tr("&Manage Buffer Views..."), coll, + this, SLOT(on_actionManageViews_triggered()))); + Action *lockAct = coll->addAction("LockDockPositions", new Action(tr("&Lock Dock Positions"), coll)); + lockAct->setCheckable(true); + connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockDockPositions_toggled(bool))); + + coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll, + 0, 0, tr("Ctrl+F")))->setCheckable(true); + coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll, + 0, 0))->setCheckable(true); + + // Settings + coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll, + this, SLOT(showSettingsDlg()), tr("F7"))); + + // Help + coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel..."), coll, + this, SLOT(showAboutDlg()))); + coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt..."), coll, + qApp, SLOT(aboutQt()))); + coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll, + this, SLOT(on_actionDebugNetworkModel_triggered()))); + coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll, + this, SLOT(on_actionDebugMessageModel_triggered()))); + coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll, + this, SLOT(on_actionDebugLog_triggered()))); +} + void MainWin::setupMenus() { - connect(ui.actionConnectCore, SIGNAL(triggered()), this, SLOT(showCoreConnectionDlg())); - connect(ui.actionDisconnectCore, SIGNAL(triggered()), Client::instance(), SLOT(disconnectFromCore())); - connect(ui.actionCoreInfo, SIGNAL(triggered()), this, SLOT(showCoreInfoDlg())); - connect(ui.actionQuit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit())); - connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg())); - connect(ui.actionAboutQuassel, SIGNAL(triggered()), this, SLOT(showAboutDlg())); - connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt())); + ActionCollection *coll = QtUi::actionCollection("General"); + + _fileMenu = menuBar()->addMenu(tr("&File")); + _fileMenu->addAction(coll->action("ConnectCore")); + _fileMenu->addAction(coll->action("DisconnectCore")); + _fileMenu->addAction(coll->action("CoreInfo")); + _fileMenu->addSeparator(); + _networksMenu = _fileMenu->addMenu(tr("&Networks")); + _networksMenu->addAction(coll->action("EditNetworks")); + _networksMenu->addSeparator(); + _fileMenu->addSeparator(); + _fileMenu->addAction(coll->action("Quit")); + + _viewMenu = menuBar()->addMenu(tr("&View")); + _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views")); + _bufferViewsMenu->addAction(coll->action("ManageBufferViews")); + _viewMenu->addSeparator(); + _viewMenu->addAction(coll->action("ToggleSearchBar")); + _viewMenu->addAction(coll->action("ToggleStatusBar")); + _viewMenu->addSeparator(); + _viewMenu->addAction(coll->action("LockDockPositions")); + + _settingsMenu = menuBar()->addMenu(tr("&Settings")); + _settingsMenu->addAction(coll->action("ConfigureQuassel")); + + _helpMenu = menuBar()->addMenu(tr("&Help")); + _helpMenu->addAction(coll->action("AboutQuassel")); + _helpMenu->addAction(coll->action("AboutQt")); + _helpMenu->addSeparator(); + _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug")); + _helpDebugMenu->addAction(coll->action("DebugNetworkModel")); + _helpDebugMenu->addAction(coll->action("DebugMessageModel")); + _helpDebugMenu->addAction(coll->action("DebugLog")); +} + +void MainWin::setupBufferWidget() { + _bufferWidget = new BufferWidget(this); + _bufferWidget->setModel(Client::bufferModel()); + _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); + setCentralWidget(_bufferWidget); } void MainWin::setupViews() { @@ -208,7 +277,7 @@ void MainWin::addBufferView(BufferViewConfig *config) { dock->show(); addDockWidget(Qt::LeftDockWidgetArea, dock); - ui.menuBufferViews->addAction(dock->toggleViewAction()); + _bufferViewsMenu->addAction(dock->toggleViewAction()); _netViews.append(dock); } @@ -216,7 +285,7 @@ void MainWin::addBufferView(BufferViewConfig *config) { void MainWin::removeBufferView(int bufferViewConfigId) { QVariant actionData; BufferViewDock *dock; - foreach(QAction *action, ui.menuBufferViews->actions()) { + foreach(QAction *action, _bufferViewsMenu->actions()) { actionData = action->data(); if(!actionData.isValid()) continue; @@ -253,17 +322,19 @@ void MainWin::setupNickWidget() { nickDock->setObjectName("NickDock"); nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - nickListWidget = new NickListWidget(nickDock); - nickDock->setWidget(nickListWidget); + _nickListWidget = new NickListWidget(nickDock); + nickDock->setWidget(_nickListWidget); addDockWidget(Qt::RightDockWidgetArea, nickDock); - ui.menuViews->addAction(nickDock->toggleViewAction()); + _viewMenu->addAction(nickDock->toggleViewAction()); + nickDock->toggleViewAction()->setText(tr("Show Nick List")); + nickDock->toggleViewAction()->setIcon(SmallIcon("view-sidetree")); // See NickListDock::NickListDock(); // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool))); // attach the NickListWidget to the BufferModel and the default selection - nickListWidget->setModel(Client::bufferModel()); - nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); + _nickListWidget->setModel(Client::bufferModel()); + _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); } void MainWin::setupChatMonitor() { @@ -277,7 +348,8 @@ void MainWin::setupChatMonitor() { dock->show(); addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical); - ui.menuViews->addAction(dock->toggleViewAction()); + _viewMenu->addAction(dock->toggleViewAction()); + dock->toggleViewAction()->setText(tr("Show Chat Monitor")); } void MainWin::setupInputWidget() { @@ -289,12 +361,15 @@ void MainWin::setupInputWidget() { addDockWidget(Qt::BottomDockWidgetArea, dock); - ui.menuViews->addAction(dock->toggleViewAction()); + _viewMenu->addAction(dock->toggleViewAction()); + dock->toggleViewAction()->setText(tr("Show Input Line")); inputWidget->setModel(Client::bufferModel()); inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); - ui.bufferWidget->setFocusProxy(inputWidget); + _bufferWidget->setFocusProxy(inputWidget); + + inputWidget->inputLine()->installEventFilter(_bufferWidget); } void MainWin::setupTopicWidget() { @@ -307,9 +382,15 @@ void MainWin::setupTopicWidget() { topicwidget->setModel(Client::bufferModel()); topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); - addDockWidget(Qt::TopDockWidgetArea, dock); + addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical); - ui.menuViews->addAction(dock->toggleViewAction()); + _viewMenu->addAction(dock->toggleViewAction()); + dock->toggleViewAction()->setText(tr("Show Topic Line")); +} + +void MainWin::setupTitleSetter() { + _titleSetter.setModel(Client::bufferModel()); + _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel()); } void MainWin::setupStatusBar() { @@ -327,11 +408,10 @@ void MainWin::setupStatusBar() { sslLabel->setPixmap(QPixmap()); statusBar()->addPermanentWidget(sslLabel); - ui.menuViews->addSeparator(); - QAction *showStatusbar = ui.menuViews->addAction(tr("Statusbar")); - showStatusbar->setCheckable(true); + _viewMenu->addSeparator(); + QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar"); - UiSettings uiSettings; + QtUiSettings uiSettings; bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool(); showStatusbar->setChecked(enabled); @@ -339,35 +419,38 @@ void MainWin::setupStatusBar() { connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool))); connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool))); + + connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &))); + connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &))); } void MainWin::saveStatusBarStatus(bool enabled) { - UiSettings uiSettings; + QtUiSettings uiSettings; uiSettings.setValue("ShowStatusBar", enabled); } void MainWin::setupSystray() { - connect(timer, SIGNAL(timeout()), this, SLOT(makeTrayIconBlink())); connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(messagesInserted(const QModelIndex &, int, int))); + SLOT(messagesInserted(const QModelIndex &, int, int))); + ActionCollection *coll = QtUi::actionCollection("General"); systrayMenu = new QMenu(this); - systrayMenu->addAction(ui.actionAboutQuassel); + systrayMenu->addAction(coll->action("AboutQuassel")); systrayMenu->addSeparator(); - systrayMenu->addAction(ui.actionConnectCore); - systrayMenu->addAction(ui.actionDisconnectCore); + systrayMenu->addAction(coll->action("ConnectCore")); + systrayMenu->addAction(coll->action("DisconnectCore")); systrayMenu->addSeparator(); - systrayMenu->addAction(ui.actionQuit); + systrayMenu->addAction(coll->action("Quit")); - systray->setContextMenu(systrayMenu); + systemTrayIcon()->setContextMenu(systrayMenu); - UiSettings s; + QtUiSettings s; if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) { - systray->show(); + systemTrayIcon()->show(); } #ifndef Q_WS_MAC - connect(systray, SIGNAL(activated( QSystemTrayIcon::ActivationReason )), + connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )), this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason ))); #endif @@ -376,7 +459,7 @@ void MainWin::setupSystray() { void MainWin::changeEvent(QEvent *event) { if(event->type() == QEvent::WindowStateChange) { if(windowState() & Qt::WindowMinimized) { - UiSettings s; + QtUiSettings s; if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) { toggleVisibility(); event->ignore(); @@ -391,25 +474,21 @@ void MainWin::connectedToCore() { connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int))); connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout())); - foreach(BufferInfo id, Client::allBufferInfos()) { - Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1); - } setConnectedState(); + Client::backlogManager()->requestInitialBacklog(); } void MainWin::setConnectedState() { + ActionCollection *coll = QtUi::actionCollection("General"); //ui.menuCore->setEnabled(true); - ui.actionConnectCore->setEnabled(false); - ui.actionDisconnectCore->setEnabled(true); - ui.actionCoreInfo->setEnabled(true); - ui.menuViews->setEnabled(true); - ui.bufferWidget->show(); + coll->action("ConnectCore")->setEnabled(false); + coll->action("DisconnectCore")->setEnabled(true); + coll->action("CoreInfo")->setEnabled(true); + // _viewMenu->setEnabled(true); statusBar()->showMessage(tr("Connected to core.")); - setWindowIcon(onlineTrayIcon); - qApp->setWindowIcon(onlineTrayIcon); - systray->setIcon(onlineTrayIcon); if(sslLabel->width() == 0) - sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/no-ssl"))); + sslLabel->setPixmap(SmallIcon("security-low")); + updateIcon(); } void MainWin::loadLayout() { @@ -431,7 +510,7 @@ void MainWin::updateLagIndicator(int lag) { void MainWin::securedConnection() { // todo: make status bar entry - sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/ssl"))); + sslLabel->setPixmap(SmallIcon("security-high")); } void MainWin::disconnectedFromCore() { @@ -439,7 +518,7 @@ void MainWin::disconnectedFromCore() { saveLayout(); QVariant actionData; BufferViewDock *dock; - foreach(QAction *action, ui.menuBufferViews->actions()) { + foreach(QAction *action, _bufferViewsMenu->actions()) { actionData = action->data(); if(!actionData.isValid()) continue; @@ -456,17 +535,15 @@ void MainWin::disconnectedFromCore() { } void MainWin::setDisconnectedState() { + ActionCollection *coll = QtUi::actionCollection("General"); //ui.menuCore->setEnabled(false); - ui.actionConnectCore->setEnabled(true); - ui.actionDisconnectCore->setEnabled(false); - ui.actionCoreInfo->setEnabled(false); - ui.menuViews->setEnabled(false); - ui.bufferWidget->hide(); + coll->action("ConnectCore")->setEnabled(true); + coll->action("DisconnectCore")->setEnabled(false); + coll->action("CoreInfo")->setEnabled(false); + //_viewMenu->setEnabled(false); statusBar()->showMessage(tr("Not connected to core.")); - setWindowIcon(offlineTrayIcon); - qApp->setWindowIcon(offlineTrayIcon); - systray->setIcon(offlineTrayIcon); sslLabel->setPixmap(QPixmap()); + updateIcon(); } void MainWin::showCoreConnectionDlg(bool autoConnect) { @@ -516,12 +593,13 @@ void MainWin::showAboutDlg() { } void MainWin::closeEvent(QCloseEvent *event) { - UiSettings s; + QtUiSettings s; if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) { toggleVisibility(); event->ignore(); } else { event->accept(); + QApplication::quit(); } } @@ -546,11 +624,11 @@ void MainWin::toggleVisibility() { // setFocus(); //Qt::ActiveWindowFocusReason } else { - if(systray->isSystemTrayAvailable ()) { + if(systemTrayIcon()->isSystemTrayAvailable ()) { clearFocus(); hide(); - if(!systray->isVisible()) { - systray->show(); + if(!systemTrayIcon()->isVisible()) { + systemTrayIcon()->show(); } } else { lower(); @@ -560,12 +638,10 @@ void MainWin::toggleVisibility() { void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) { Q_UNUSED(parent); + if(QApplication::activeWindow() != 0) return; - // FIXME - return; - for(int i = start; i <= end; i++) { QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn); if(!idx.isValid()) { @@ -573,118 +649,28 @@ void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) { continue; } Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt(); + if(flags.testFlag(Message::Backlog)) continue; + flags |= Message::Backlog; // we only want to trigger a highlight once! + Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole); + BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value(); 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); - } - } + QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn); + QString sender = senderIdx.data(ChatLineModel::EditRole).toString(); + QString contents = idx.data(ChatLineModel::DisplayRole).toString(); + QtUi::invokeNotification(bufId, sender, contents); } } } bool MainWin::event(QEvent *event) { if(event->type() == QEvent::WindowActivate) - setTrayIconActivity(false); + QtUi::closeNotifications(); return QMainWindow::event(event); } -#ifdef HAVE_DBUS - -/* -Using the notification-daemon from Freedesktop's Galago project -http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify -*/ -void MainWin::sendDesktopNotification(const QString &title, const QString &message) { - QStringList actions; - QMap hints; - UiSettings uiSettings; - - hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up - hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up - - actions << "click" << "Click Me!"; - - QDBusReply reply = desktopNotifications->Notify( - "Quassel", // Application name - notificationId, // ID of previous notification to replace - "", // Icon to display - title, // Summary / Header of the message to display - QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display - actions, // Actions from which the user may choose - hints, // Hints to the server displaying the message - uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds - ); - - if(!reply.isValid()) { - /* ERROR */ - // could also happen if no notification service runs, so... whatever :) - //qDebug() << "Error on sending notification..." << reply.error(); - return; - } - - notificationId = reply.value(); - - // qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString(); -} - - -void MainWin::desktopNotificationClosed(uint id, uint reason) { - Q_UNUSED(id); Q_UNUSED(reason); - // qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString(); - notificationId = 0; -} - - -void MainWin::desktopNotificationInvoked(uint id, const QString & action) { - Q_UNUSED(id); Q_UNUSED(action); - // qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString(); -} - -#endif /* HAVE_DBUS */ - -void MainWin::displayTrayIconMessage(const QString &title, const QString &message) { - systray->showMessage(title, message); -} - -void MainWin::setTrayIconActivity(bool active) { - if(active) { - if(!timer->isActive()) - timer->start(500); - } else { - timer->stop(); - systray->setIcon(onlineTrayIcon); - } -} - -void MainWin::makeTrayIconBlink() { - if(trayIconActive) { - systray->setIcon(onlineTrayIcon); - trayIconActive = false; - } else { - systray->setIcon(activeTrayIcon); - trayIconActive = true; - } -} - void MainWin::clientNetworkCreated(NetworkId id) { const Network *net = Client::network(id); QAction *act = new QAction(net->networkName(), this); @@ -694,18 +680,15 @@ void MainWin::clientNetworkCreated(NetworkId id) { connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet())); QAction *beforeAction = 0; - foreach(QAction *action, ui.menuNetworks->actions()) { - if(action->isSeparator()) { - beforeAction = action; - break; - } + foreach(QAction *action, _networksMenu->actions()) { + if(!action->data().isValid()) // ignore stock actions + continue; if(net->networkName().localeAwareCompare(action->text()) < 0) { beforeAction = action; break; } } - Q_CHECK_PTR(beforeAction); - ui.menuNetworks->insertAction(beforeAction, act); + _networksMenu->insertAction(beforeAction, act); } void MainWin::clientNetworkUpdated() { @@ -721,13 +704,13 @@ void MainWin::clientNetworkUpdated() { switch(net->connectionState()) { case Network::Initialized: - action->setIcon(QIcon(":/16x16/actions/network-connect")); + action->setIcon(SmallIcon("network-connect")); break; case Network::Disconnected: - action->setIcon(QIcon(":/16x16/actions/network-disconnect")); + action->setIcon(SmallIcon("network-disconnect")); break; default: - action->setIcon(QIcon(":/16x16/actions/gear")); + action->setIcon(SmallIcon("network-wired")); } } @@ -748,9 +731,7 @@ void MainWin::connectOrDisconnectFromNet() { else net->requestDisconnect(); } - - -void MainWin::on_actionDebugNetworkModel_triggered(bool) { +void MainWin::on_actionDebugNetworkModel_triggered() { QTreeView *view = new QTreeView; view->setAttribute(Qt::WA_DeleteOnClose); view->setWindowTitle("Debug NetworkModel View"); @@ -761,3 +742,39 @@ void MainWin::on_actionDebugNetworkModel_triggered(bool) { view->resize(610, 300); view->show(); } + +void MainWin::on_actionDebugMessageModel_triggered() { + QTableView *view = new QTableView(0); + DebugMessageModelFilter *filter = new DebugMessageModelFilter(view); + filter->setSourceModel(Client::messageModel()); + view->setModel(filter); + view->setAttribute(Qt::WA_DeleteOnClose, true); + view->verticalHeader()->hide(); + view->horizontalHeader()->setStretchLastSection(true); + view->show(); +} + +void MainWin::on_actionDebugLog_triggered() { + DebugLogWidget *logWidget = new DebugLogWidget(0); + logWidget->show(); +} + +void MainWin::saveStateToSession(const QString &sessionId) { + return; + SessionSettings s(sessionId); + + s.setValue("MainWinSize", size()); + s.setValue("MainWinPos", pos()); + s.setValue("MainWinState", saveState()); +} + +void MainWin::saveStateToSessionSettings(SessionSettings & s) +{ + s.setValue("MainWinSize", size()); + s.setValue("MainWinPos", pos()); + s.setValue("MainWinState", saveState()); +} + +void MainWin::showStatusBarMessage(const QString &message) { + statusBar()->showMessage(message, 10000); +}