/***************************************************************************
- * 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 *
***************************************************************************/
#include "mainwin.h"
+#ifdef HAVE_KDE
+# include <KAction>
+# include <KActionCollection>
+# include <KHelpMenu>
+# include <KMenuBar>
+# include <KShortcutsDialog>
+# include <KStatusBar>
+#endif
+
#include "aboutdlg.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 "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 "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"
#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))
+ _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);
- 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<QtUiApplication*> 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() {
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)));
-
- show();
-
- statusBar()->showMessage(tr("Not connected to core."));
+ 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(Client::mainUi()->actionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
- // 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();
+
+#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() {
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("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"));
+ _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) {
}
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;
}
}
-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();
}
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() {
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());
- ui.bufferWidget->setFocusProxy(inputWidget);
+ _bufferWidget->setFocusProxy(_inputWidget);
+
+ _inputWidget->inputLine()->installEventFilter(_bufferWidget);
}
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() {
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);
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->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::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();
}
}
}
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());
+ }
+
+ // _viewMenu->setEnabled(true);
+ if(!Client::internalCore())
+ statusBar()->showMessage(tr("Connected to core."));
+
+ 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() {
}
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() {
saveLayout();
QVariant actionData;
BufferViewDock *dock;
- foreach(QAction *action, ui.menuBufferViews->actions()) {
+ foreach(QAction *action, _bufferViewsMenu->actions()) {
actionData = action->data();
if(!actionData.isValid())
continue;
}
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) {
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));
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<QtUiApplication*> qApp;
+ Q_ASSERT(app);
+ if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
+ hideToTray();
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();
}
}
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<QString, QVariant> 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<uint> 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);
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() {
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");
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("MainWinPos", pos());
s.setValue("MainWinState", saveState());
}
+
+void MainWin::showStatusBarMessage(const QString &message) {
+ statusBar()->showMessage(message, 10000);
+}
+