X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmainwin.cpp;h=f1e21175162e7135b8706033e60238f8d025e56c;hp=ceedb9b1147b388e8fb7022cecfd14a97695ba9d;hb=17331c42de77ff91ce297354f9ba9eed6ecb4256;hpb=5c78a50fa720e5f82fcaa03c0176feab71d74c8e diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index ceedb9b1..f1e21175 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -19,48 +19,72 @@ ***************************************************************************/ #include "mainwin.h" +#ifdef HAVE_KDE +# include +# include +# include +# include +# include +# include +#endif + #include "aboutdlg.h" +#include "awaylogfilter.h" +#include "awaylogview.h" #include "action.h" #include "actioncollection.h" +#include "buffermodel.h" #include "bufferview.h" -#include "bufferviewconfig.h" -#include "bufferviewfilter.h" #include "bufferviewmanager.h" +#include "bufferwidget.h" #include "channellistdlg.h" #include "chatlinemodel.h" #include "chatmonitorfilter.h" #include "chatmonitorview.h" #include "chatview.h" -#include "chatviewsearchbar.h" #include "client.h" +#include "clientsyncer.h" #include "clientbacklogmanager.h" #include "coreinfodlg.h" #include "coreconnectdlg.h" +#include "contextmenuactionprovider.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 "qtuiapplication.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 "toolbaractionprovider.h" #include "topicwidget.h" -#include "inputwidget.h" -#include "irclistmodel.h" #include "verticaldock.h" -#include "uisettings.h" -#include "qtuisettings.h" -#include "jumpkeyhandler.h" -#include "sessionsettings.h" -#include "selectionmodelsynchronizer.h" -#include "mappedselectionmodel.h" +#ifndef HAVE_KDE +# ifdef HAVE_DBUS +# include "desktopnotificationbackend.h" +# endif +# ifdef HAVE_PHONON +# include "phononnotificationbackend.h" +# endif +# include "systraynotificationbackend.h" +# include "taskbarnotificationbackend.h" +#else /* HAVE_KDE */ +# include "knotificationbackend.h" +#endif /* HAVE_KDE */ #include "settingspages/aliasessettingspage.h" #include "settingspages/appearancesettingspage.h" +#include "settingspages/backlogsettingspage.h" #include "settingspages/bufferviewsettingspage.h" +#include "settingspages/chatmonitorsettingspage.h" #include "settingspages/colorsettingspage.h" #include "settingspages/fontssettingspage.h" #include "settingspages/generalsettingspage.h" @@ -69,55 +93,37 @@ #include "settingspages/networkssettingspage.h" #include "settingspages/notificationssettingspage.h" -#include "qtuistyle.h" - MainWin::MainWin(QWidget *parent) +#ifdef HAVE_KDE + : KMainWindow(parent), + _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())), +#else : QMainWindow(parent), +#endif coreLagLabel(new QLabel()), sslLabel(new QLabel()), msgProcessorStatusWidget(new MsgProcessorStatusWidget()), - _titleSetter(this), _trayIcon(new QSystemTrayIcon(this)), - - activeTrayIcon(DesktopIcon("quassel_newmessage", IconLoader::SizeEnormous)), - onlineTrayIcon(DesktopIcon("quassel", IconLoader::SizeEnormous)), - offlineTrayIcon(DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous)), - trayIconActive(false), - - timer(new QTimer(this)), - _actionCollection(new ActionCollection(this)) + _awayLog(0) { - 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); - setWindowTitle("Quassel IRC"); - setWindowIcon(offlineTrayIcon); - qApp->setWindowIcon(offlineTrayIcon); - systemTrayIcon()->setIcon(offlineTrayIcon); - setWindowIconText("Quassel IRC"); - QtUi::actionCollection()->addAssociatedWidget(this); + QApplication::setQuitOnLastWindowClosed(false); - statusBar()->showMessage(tr("Waiting for core...")); + setWindowTitle("Quassel IRC"); + setWindowIconText("Quassel IRC"); + updateIcon(); installEventFilter(new JumpKeyHandler(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&))); -#endif QtUiApplication* app = qobject_cast qApp; - connect(app, SIGNAL(saveStateToSession(const QString&)), this, SLOT(saveStateToSession(const QString&))); - connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), this, SLOT(saveStateToSessionSettings(SessionSettings&))); + connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&))); + connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&))); } void MainWin::init() { @@ -127,50 +133,59 @@ void MainWin::init() { else resize(QSize(800, 500)); - 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))); + connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(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(); + setupToolBars(); setupSystray(); + setupTitleSetter(); + +#ifndef HAVE_KDE + QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this)); + QtUi::registerNotificationBackend(new SystrayNotificationBackend(this)); +# ifdef HAVE_PHONON + QtUi::registerNotificationBackend(new PhononNotificationBackend(this)); +# endif +# ifdef HAVE_DBUS + QtUi::registerNotificationBackend(new DesktopNotificationBackend(this)); +# endif + +#else /* HAVE_KDE */ + QtUi::registerNotificationBackend(new KNotificationBackend(this)); +#endif /* HAVE_KDE */ // 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()); - ui.menuViews->addAction(QtUi::actionCollection()->action("toggleSearchBar")); - - _titleSetter.setModel(Client::bufferModel()); - _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel()); + show(); + if(Quassel::runMode() != Quassel::Monolithic) { + showCoreConnectionDlg(true); // autoconnect if appropriate + } else { + startInternalCore(); + } } MainWin::~MainWin() { @@ -180,31 +195,124 @@ 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() { - // TODO don't get these from *.ui anymore... we shouldn't need one - ui.actionQuit->setIcon(SmallIcon("application-exit")); - ui.actionSettingsDlg->setIcon(SmallIcon("configure")); - ui.actionManageViews->setIcon(SmallIcon("view-tree")); - ui.actionManageViews2->setIcon(SmallIcon("view-tree")); - ui.actionAboutQt->setIcon(SmallIcon("qt")); - ui.actionAboutQuassel->setIcon(SmallIcon("quassel")); - ui.actionConnectCore->setIcon(SmallIcon("network-connect")); - ui.actionDisconnectCore->setIcon(SmallIcon("network-disconnect")); - ui.actionCoreInfo->setIcon(SmallIcon("help-about")); + 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("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll, + this, SLOT(on_actionConfigureNetworks_triggered()))); + coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll, + qApp, SLOT(quit()), tr("Ctrl+Q"))); + + // View + coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll, + this, SLOT(on_actionConfigureViews_triggered()))); + QAction *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("ShowAwayLog", new Action(tr("Show Away Log"), coll, + this, SLOT(showAwayLog()))); + 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")); + + static const QStringList coreActions = QStringList() + << "ConnectCore" << "DisconnectCore" << "CoreInfo"; + + QAction *coreAction; + foreach(QString actionName, coreActions) { + coreAction = coll->action(actionName); + _fileMenu->addAction(coreAction); + flagRemoteCoreOnly(coreAction); + } + flagRemoteCoreOnly(_fileMenu->addSeparator()); + + _networksMenu = _fileMenu->addMenu(tr("&Networks")); + _networksMenu->addAction(coll->action("ConfigureNetworks")); + _networksMenu->addSeparator(); + _fileMenu->addSeparator(); + _fileMenu->addAction(coll->action("Quit")); + + _viewMenu = menuBar()->addMenu(tr("&View")); + _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views")); + _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews")); + _viewMenu->addSeparator(); + _viewMenu->addAction(coll->action("ToggleSearchBar")); + + coreAction = coll->action("ShowAwayLog"); + flagRemoteCoreOnly(coreAction); + _viewMenu->addAction(coreAction); + + _viewMenu->addAction(coll->action("ToggleStatusBar")); + _viewMenu->addSeparator(); + _viewMenu->addAction(coll->action("LockDockPositions")); + + _settingsMenu = menuBar()->addMenu(tr("&Settings")); +#ifdef HAVE_KDE + _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this)); + _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this)); +#endif + _settingsMenu->addAction(coll->action("ConfigureQuassel")); + + _helpMenu = menuBar()->addMenu(tr("&Help")); + _helpMenu->addAction(coll->action("AboutQuassel")); +#ifndef HAVE_KDE + _helpMenu->addAction(coll->action("AboutQt")); +#else + _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this)); +#endif + _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::setupViews() { - addBufferView(); +void MainWin::setupBufferWidget() { + _bufferWidget = new BufferWidget(this); + _bufferWidget->setModel(Client::bufferModel()); + _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); + setCentralWidget(_bufferWidget); } void MainWin::addBufferView(int bufferViewConfigId) { @@ -212,34 +320,32 @@ void MainWin::addBufferView(int bufferViewConfigId) { } void MainWin::addBufferView(BufferViewConfig *config) { - BufferViewDock *dock; - if(config) - dock = new BufferViewDock(config, this); - else - dock = new BufferViewDock(this); + if(!config) + return; + + BufferViewDock *dock = new BufferViewDock(config, this); //create the view and initialize it's filter BufferView *view = new BufferView(dock); view->setFilteredModel(Client::bufferModel(), config); + view->installEventFilter(_inputWidget->inputLine()); // for key presses view->show(); - connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList())); - Client::bufferModel()->synchronizeView(view); dock->setWidget(view); dock->show(); addDockWidget(Qt::LeftDockWidgetArea, dock); - ui.menuBufferViews->addAction(dock->toggleViewAction()); + _bufferViewsMenu->addAction(dock->toggleViewAction()); - _netViews.append(dock); + _bufferViews.append(dock); } 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; @@ -252,12 +358,24 @@ void MainWin::removeBufferView(int bufferViewConfigId) { } } -void MainWin::on_actionEditNetworks_triggered() { +BufferView *MainWin::allBuffersView() const { + // "All Buffers" is always the first dock created + if(_bufferViews.count() > 0) + return _bufferViews[0]->bufferView(); + return 0; +} + +void MainWin::showNotificationsDlg() { + SettingsPageDlg dlg(new NotificationsSettingsPage(this), this); + dlg.exec(); +} + +void MainWin::on_actionConfigureNetworks_triggered() { SettingsPageDlg dlg(new NetworksSettingsPage(this), this); dlg.exec(); } -void MainWin::on_actionManageViews_triggered() { +void MainWin::on_actionConfigureViews_triggered() { SettingsPageDlg dlg(new BufferViewSettingsPage(this), this); dlg.exec(); } @@ -276,17 +394,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() { @@ -300,24 +420,28 @@ 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() { VerticalDock *dock = new VerticalDock(tr("Inputline"), this); dock->setObjectName("InputDock"); - InputWidget *inputWidget = new InputWidget(dock); - dock->setWidget(inputWidget); + _inputWidget = new InputWidget(dock); + dock->setWidget(_inputWidget); 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()); - inputWidget->setModel(Client::bufferModel()); - inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); + _bufferWidget->setFocusProxy(_inputWidget); - ui.bufferWidget->setFocusProxy(inputWidget); + _inputWidget->inputLine()->installEventFilter(_bufferWidget); } void MainWin::setupTopicWidget() { @@ -330,31 +454,36 @@ void MainWin::setupTopicWidget() { topicwidget->setModel(Client::bufferModel()); topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); - addDockWidget(Qt::TopDockWidgetArea, dock); + addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical); + + _viewMenu->addAction(dock->toggleViewAction()); + dock->toggleViewAction()->setText(tr("Show Topic Line")); +} - ui.menuViews->addAction(dock->toggleViewAction()); +void MainWin::setupTitleSetter() { + _titleSetter.setModel(Client::bufferModel()); + _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel()); } void MainWin::setupStatusBar() { // MessageProcessor progress statusBar()->addPermanentWidget(msgProcessorStatusWidget); - connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int))); // Core Lag: - updateLagIndicator(0); + updateLagIndicator(); statusBar()->addPermanentWidget(coreLagLabel); + coreLagLabel->hide(); connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int))); // SSL indicator - connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection())); sslLabel->setPixmap(QPixmap()); statusBar()->addPermanentWidget(sslLabel); + sslLabel->hide(); - 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); @@ -365,44 +494,61 @@ void MainWin::setupStatusBar() { } 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->addSeparator(); - systrayMenu->addAction(ui.actionConnectCore); - systrayMenu->addAction(ui.actionDisconnectCore); + systrayMenu->addAction(coll->action("ConnectCore")); + systrayMenu->addAction(coll->action("DisconnectCore")); + systrayMenu->addAction(coll->action("CoreInfo")); systrayMenu->addSeparator(); - systrayMenu->addAction(ui.actionQuit); + systrayMenu->addAction(coll->action("Quit")); systemTrayIcon()->setContextMenu(systrayMenu); - UiSettings s; + QtUiSettings s; if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) { systemTrayIcon()->show(); } #ifndef Q_WS_MAC - connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )), - this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason ))); + connect(systemTrayIcon(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayActivated(QSystemTrayIcon::ActivationReason))); #endif +} + +void MainWin::setupToolBars() { + connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)), + QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex))); + connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)), + QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList))); + _networkToolBar = addToolBar("Network"); + _networkToolBar->setObjectName("NetworkToolBar"); + QtUi::toolBarActionProvider()->addActions(_networkToolBar, ToolBarActionProvider::NetworkToolBar); + + //_nickToolBar = addToolBar("User"); + //_nickToolBar->setObjectName("NickToolBar"); + //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar); + +#ifdef HAVE_KDE + _networkToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); +#endif } 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(); + hideToTray(); + event->accept(); } } } @@ -414,23 +560,45 @@ void MainWin::connectedToCore() { connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int))); connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout())); - Client::backlogManager()->requestInitialBacklog(); setConnectedState(); } void MainWin::setConnectedState() { - //ui.menuCore->setEnabled(true); - ui.actionConnectCore->setEnabled(false); - ui.actionDisconnectCore->setEnabled(true); - ui.actionCoreInfo->setEnabled(true); - ui.menuViews->setEnabled(true); - ui.bufferWidget->show(); - statusBar()->showMessage(tr("Connected to core.")); - setWindowIcon(onlineTrayIcon); - qApp->setWindowIcon(onlineTrayIcon); - systemTrayIcon()->setIcon(onlineTrayIcon); - if(sslLabel->width() == 0) + ActionCollection *coll = QtUi::actionCollection("General"); + + coll->action("ConnectCore")->setEnabled(false); + coll->action("DisconnectCore")->setEnabled(true); + coll->action("CoreInfo")->setEnabled(true); + + foreach(QAction *action, _fileMenu->actions()) { + if(isRemoteCoreOnly(action)) + action->setVisible(!Client::internalCore()); + } + + disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int))); + disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &))); + disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &))); + if(!Client::internalCore()) { + connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int))); + connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &))); + connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &))); + } + + // _viewMenu->setEnabled(true); + if(!Client::internalCore()) + statusBar()->showMessage(tr("Connected to core.")); + else + statusBar()->clearMessage(); + + if(Client::signalProxy()->isSecure()) { + sslLabel->setPixmap(SmallIcon("security-high")); + } else { sslLabel->setPixmap(SmallIcon("security-low")); + } + + sslLabel->setVisible(!Client::internalCore()); + coreLagLabel->setVisible(!Client::internalCore()); + updateIcon(); } void MainWin::loadLayout() { @@ -446,13 +614,12 @@ void MainWin::saveLayout() { } void MainWin::updateLagIndicator(int lag) { - coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag)); -} - - -void MainWin::securedConnection() { - // todo: make status bar entry - sslLabel->setPixmap(SmallIcon("security-high")); + QString text = tr("Core Lag: %1"); + if(lag == -1) + text = text.arg('-'); + else + text = text.arg("%1 msec").arg(lag); + coreLagLabel->setText(text); } void MainWin::disconnectedFromCore() { @@ -460,7 +627,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; @@ -477,17 +644,25 @@ 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); - systemTrayIcon()->setIcon(offlineTrayIcon); sslLabel->setPixmap(QPixmap()); + sslLabel->hide(); + updateLagIndicator(); + coreLagLabel->hide(); + updateIcon(); +} + +void MainWin::startInternalCore() { + ClientSyncer *syncer = new ClientSyncer(); + Client::registerClientSyncer(syncer); + connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection); + syncer->useInternalCore(); } void MainWin::showCoreConnectionDlg(bool autoConnect) { @@ -512,6 +687,21 @@ void MainWin::showCoreInfoDlg() { CoreInfoDlg(this).exec(); } +void MainWin::showAwayLog() { + if(_awayLog) + return; + AwayLogFilter *filter = new AwayLogFilter(Client::messageModel()); + _awayLog = new AwayLogView(filter, 0); + filter->setParent(_awayLog); + connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed())); + _awayLog->setAttribute(Qt::WA_DeleteOnClose); + _awayLog->show(); +} + +void MainWin::awayLogDestroyed() { + _awayLog = 0; +} + void MainWin::showSettingsDlg() { SettingsDlg *dlg = new SettingsDlg(); @@ -521,9 +711,11 @@ void MainWin::showSettingsDlg() { dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General //Category: Behaviour dlg->registerSettingsPage(new GeneralSettingsPage(dlg)); + dlg->registerSettingsPage(new BacklogSettingsPage(dlg)); dlg->registerSettingsPage(new HighlightSettingsPage(dlg)); dlg->registerSettingsPage(new AliasesSettingsPage(dlg)); dlg->registerSettingsPage(new NotificationsSettingsPage(dlg)); + dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg)); //Category: General dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg)); dlg->registerSettingsPage(new NetworksSettingsPage(dlg)); @@ -536,46 +728,51 @@ void MainWin::showAboutDlg() { AboutDlg(this).exec(); } +#ifdef HAVE_KDE +void MainWin::showShortcutsDlg() { + KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed); +} +#endif + void MainWin::closeEvent(QCloseEvent *event) { - UiSettings s; - if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) { - toggleVisibility(); + QtUiSettings s; + QtUiApplication* app = qobject_cast qApp; + Q_ASSERT(app); + if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) { + toggleMinimizedToTray(); event->ignore(); } else { event->accept(); + QApplication::quit(); } } -void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) { +void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) { if(activationReason == QSystemTrayIcon::Trigger) { - toggleVisibility(); + toggleMinimizedToTray(); } } -void MainWin::toggleVisibility() { - if(isHidden() /*|| !isActiveWindow()*/) { - show(); - if(isMinimized()) { - if(isMaximized()) - showMaximized(); - else - showNormal(); - } +void MainWin::hideToTray() { + if(!systemTrayIcon()->isSystemTrayAvailable()) { + qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!"; + return; + } - raise(); - activateWindow(); - // setFocus(); //Qt::ActiveWindowFocusReason + clearFocus(); + hide(); + systemTrayIcon()->show(); +} +void MainWin::toggleMinimizedToTray() { + if(windowState() & Qt::WindowMinimized) { + // restore + setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); + show(); + raise(); } else { - if(systemTrayIcon()->isSystemTrayAvailable ()) { - clearFocus(); - hide(); - if(!systemTrayIcon()->isVisible()) { - systemTrayIcon()->show(); - } - } else { - lower(); - } + setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized); + hideToTray(); } } @@ -600,114 +797,20 @@ void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) { 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) { - systemTrayIcon()->showMessage(title, message); -} - -void MainWin::setTrayIconActivity(bool active) { - if(active) { - if(!timer->isActive()) - timer->start(500); - } else { - timer->stop(); - systemTrayIcon()->setIcon(onlineTrayIcon); - } -} - -void MainWin::makeTrayIconBlink() { - if(trayIconActive) { - systemTrayIcon()->setIcon(onlineTrayIcon); - trayIconActive = false; - } else { - systemTrayIcon()->setIcon(activeTrayIcon); - trayIconActive = true; - } -} - void MainWin::clientNetworkCreated(NetworkId id) { const Network *net = Client::network(id); QAction *act = new QAction(net->networkName(), this); @@ -717,18 +820,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() { @@ -771,9 +871,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"); @@ -785,6 +883,22 @@ void MainWin::on_actionDebugNetworkModel_triggered(bool) { 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); @@ -800,3 +914,8 @@ void MainWin::saveStateToSessionSettings(SessionSettings & s) s.setValue("MainWinPos", pos()); s.setValue("MainWinState", saveState()); } + +void MainWin::showStatusBarMessage(const QString &message) { + statusBar()->showMessage(message, 10000); +} +