/***************************************************************************
- * 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
+
+#ifdef Q_WS_X11
+# include <QX11Info>
+#endif
+
#include "aboutdlg.h"
-#include "chatwidget.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 "chatline-old.h"
+#include "bufferviewoverlay.h"
+#include "bufferviewoverlayfilter.h"
+#include "bufferwidget.h"
+#include "channellistdlg.h"
+#include "chatlinemodel.h"
+#include "chatmonitorfilter.h"
+#include "chatmonitorview.h"
+#include "chatview.h"
#include "client.h"
+#include "clientsyncer.h"
#include "clientbacklogmanager.h"
+#include "clientbufferviewconfig.h"
+#include "clientbufferviewmanager.h"
+#include "coreinfodlg.h"
#include "coreconnectdlg.h"
-#include "networkmodel.h"
-#include "buffermodel.h"
+#include "contextmenuactionprovider.h"
+#include "debuglogwidget.h"
+#include "debugmessagemodelfilter.h"
+#include "iconloader.h"
+#include "inputwidget.h"
+#include "inputline.h"
+#include "irclistmodel.h"
+#include "ircconnectionwizard.h"
+#include "jumpkeyhandler.h"
+#include "msgprocessorstatuswidget.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 "systemtray.h"
+#include "toolbaractionprovider.h"
#include "topicwidget.h"
-#include "inputwidget.h"
#include "verticaldock.h"
-#include "uisettings.h"
-#include "qtuisettings.h"
-#include "jumpkeyhandler.h"
-
-#include "uisettings.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/highlightsettingspage.h"
#include "settingspages/identitiessettingspage.h"
#include "settingspages/networkssettingspage.h"
+#include "settingspages/notificationssettingspage.h"
-
-#include "debugconsole.h"
-#include "global.h"
-#include "qtuistyle.h"
-
-
-MainWin::MainWin(QtUi *_gui, QWidget *parent)
+MainWin::MainWin(QWidget *parent)
+#ifdef HAVE_KDE
+ : KMainWindow(parent),
+ _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
+#else
: QMainWindow(parent),
- gui(_gui),
+#endif
+ 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)),
- settingsDlg(new SettingsDlg(this)),
- debugConsole(new DebugConsole(this))
+ _awayLog(0)
{
- ui.setupUi(this);
+#ifdef Q_WS_WIN
+ dwTickCount = 0;
+#endif
+
+ QtUiSettings uiSettings;
+ QString style = uiSettings.value("Style", QString()).toString();
+ if(!style.isEmpty()) {
+ QApplication::setStyle(style);
+ }
+
+ 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));
- UiSettings uiSettings;
- QString style = uiSettings.value("Style", QString("")).toString();
- if(style != "") {
- QApplication::setStyle(style);
- }
+ QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
+ 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));
- 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)));
- //ui.bufferWidget->init();
+ 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::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+ SLOT(messagesInserted(const QModelIndex &, int, int)));
+ 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();
-
- setupSettingsDlg();
+ 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
+ QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", 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());
+ show();
- _titleSetter.setModel(Client::bufferModel());
- _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
+ if(Quassel::runMode() != Quassel::Monolithic) {
+ showCoreConnectionDlg(true); // autoconnect if appropriate
+ } else {
+ startInternalCore();
+ }
}
MainWin::~MainWin() {
s.setValue("MainWinState", saveState());
}
+void MainWin::updateIcon() {
+#ifdef Q_WS_MAC
+ const int size = 128;
+#else
+ const int size = 48;
+#endif
+
+ QPixmap icon;
+ if(Client::isConnected())
+ icon = DesktopIcon("quassel", size);
+ else
+ icon = DesktopIcon("quassel_inactive", size);
+ setWindowIcon(icon);
+ qApp->setWindowIcon(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("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("LockLayout", new Action(tr("&Lock Layout"), coll));
+ lockAct->setCheckable(true);
+ connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
+
+ coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
+ 0, 0, QKeySequence::Find))->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("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
+ this, SLOT(on_actionDebugBufferViewOverlay_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.actionQuit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()));
- //connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
- connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
- connect(ui.actionDebug_Console, SIGNAL(triggered()), this, SLOT(showDebugConsole()));
- 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"));
- actionEditNetworks = new QAction(QIcon(":/22x22/actions/configure"), tr("Edit &Networks..."), this);
- ui.menuNetworks->addAction(actionEditNetworks);
- connect(actionEditNetworks, SIGNAL(triggered()), this, SLOT(showNetworkDlg()));
- connect(ui.actionManageViews, SIGNAL(triggered()), this, SLOT(showManageViewsDlg()));
+ 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"));
+ _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
+ _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("LockLayout"));
+
+ _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("DebugBufferViewOverlay"));
+ _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
+ _helpDebugMenu->addAction(coll->action("DebugLog"));
}
-void MainWin::setupViews() {
- QAction *separator = ui.menuViews->addSeparator();
- separator->setData("__EOBV__");
- addBufferView();
+void MainWin::setupBufferWidget() {
+ _bufferWidget = new BufferWidget(this);
+ _bufferWidget->setModel(Client::bufferModel());
+ _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
+ setCentralWidget(_bufferWidget);
}
void MainWin::addBufferView(int bufferViewConfigId) {
- addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
+ addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
}
-void MainWin::addBufferView(BufferViewConfig *config) {
- BufferViewDock *dock;
- if(config)
- dock = new BufferViewDock(config, this);
- else
- dock = new BufferViewDock(this);
+void MainWin::addBufferView(ClientBufferViewConfig *config) {
+ if(!config)
+ return;
+
+ config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
+ 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();
Client::bufferModel()->synchronizeView(view);
dock->show();
addDockWidget(Qt::LeftDockWidgetArea, dock);
+ _bufferViewsMenu->addAction(dock->toggleViewAction());
- QAction *endOfBufferViews = 0;
- foreach(QAction *action, ui.menuViews->actions()) {
- if(action->data().toString() == "__EOBV__") {
- endOfBufferViews = action;
- break;
- }
- }
- Q_CHECK_PTR(endOfBufferViews);
- ui.menuViews->insertAction(endOfBufferViews, dock->toggleViewAction());
-
- _netViews.append(dock);
+ connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
+ _bufferViews.append(dock);
}
void MainWin::removeBufferView(int bufferViewConfigId) {
QVariant actionData;
BufferViewDock *dock;
- foreach(QAction *action, ui.menuViews->actions()) {
+ foreach(QAction *action, _bufferViewsMenu->actions()) {
actionData = action->data();
if(!actionData.isValid())
continue;
-
- if(actionData.toString() == "__EOBV__")
- break;
dock = qobject_cast<BufferViewDock *>(action->parent());
if(dock && actionData.toInt() == bufferViewConfigId) {
}
}
-void MainWin::setupSettingsDlg() {
- //Category: Appearance
- settingsDlg->registerSettingsPage(new ColorSettingsPage(settingsDlg));
- settingsDlg->registerSettingsPage(new FontsSettingsPage(settingsDlg));
- settingsDlg->registerSettingsPage(new AppearanceSettingsPage(settingsDlg)); //General
- //Category: Behaviour
- settingsDlg->registerSettingsPage(new GeneralSettingsPage(settingsDlg));
- settingsDlg->registerSettingsPage(new HighlightSettingsPage(settingsDlg));
- //Category: General
- settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg));
- settingsDlg->registerSettingsPage(new NetworksSettingsPage(settingsDlg));
- settingsDlg->registerSettingsPage(new BufferViewSettingsPage(settingsDlg));
-}
-
-void MainWin::showNetworkDlg() {
+void MainWin::bufferViewToggled(bool enabled) {
+ QAction *action = qobject_cast<QAction *>(sender());
+ Q_ASSERT(action);
+ BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
+ Q_ASSERT(dock);
+ if(enabled) {
+ Client::bufferViewOverlay()->addView(dock->bufferViewId());
+ BufferViewConfig *config = dock->config();
+ if(config && config->isInitialized()) {
+ BufferIdList buffers;
+ if(config->networkId().isValid()) {
+ foreach(BufferId bufferId, config->bufferList()) {
+ if(Client::networkModel()->networkId(bufferId) == config->networkId())
+ buffers << bufferId;
+ }
+ foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
+ if(Client::networkModel()->networkId(bufferId) == config->networkId())
+ buffers << bufferId;
+ }
+ } else {
+ buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
+ }
+ Client::backlogManager()->checkForBacklog(buffers);
+ }
+ } else {
+ Client::bufferViewOverlay()->removeView(dock->bufferViewId());
+ }
+}
+
+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::showManageViewsDlg() {
+void MainWin::on_actionConfigureViews_triggered() {
SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
dlg.exec();
}
+void MainWin::on_actionLockLayout_toggled(bool lock) {
+ QList<VerticalDock *> docks = findChildren<VerticalDock *>();
+ foreach(VerticalDock *dock, docks) {
+ dock->showTitle(!lock);
+ }
+ if(Client::bufferViewManager()) {
+ foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
+ config->setLocked(lock);
+ }
+ }
+ QtUiSettings().setValue("LockLayout", lock);
+}
+
void MainWin::setupNickWidget() {
// create nick dock
NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
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"));
+
// 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() {
VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
dock->setObjectName("ChatMonitorDock");
- ChatWidget *chatWidget = new ChatWidget(0, this);
- chatWidget->show();
- dock->setWidget(chatWidget);
- dock->show();
-
- Buffer *buf = Client::monitorBuffer();
- if(!buf)
- return;
-
- chatWidget->setContents(buf->contents());
- connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
- connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
+ ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
+ ChatMonitorView *chatView = new ChatMonitorView(filter, this);
+ chatView->show();
+ dock->setWidget(chatView);
+ dock->hide();
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() {
VerticalDock *dock = new VerticalDock(tr("Topic"), this);
dock->setObjectName("TopicDock");
TopicWidget *topicwidget = new TopicWidget(dock);
- connect(topicwidget, SIGNAL(topicChanged(const QString &)), this, SLOT(changeTopic(const QString &)));
dock->setWidget(topicwidget);
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() {
- connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
+ // MessageProcessor progress
+ statusBar()->addPermanentWidget(msgProcessorStatusWidget);
+
+ // Core Lag:
+ updateLagIndicator();
+ statusBar()->addPermanentWidget(coreLagLabel);
+ coreLagLabel->hide();
+ connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
+
+ // SSL indicator
sslLabel->setPixmap(QPixmap());
statusBar()->addPermanentWidget(sslLabel);
+ sslLabel->hide();
- ui.menuViews->addSeparator();
- QAction *showStatusbar = ui.menuViews->addAction(tr("Statusbar"));
- showStatusbar->setCheckable(true);
+ QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
- UiSettings uiSettings;
+ QtUiSettings uiSettings;
bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
showStatusbar->setChecked(enabled);
}
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::instance(), SIGNAL(messageReceived(const Message &)), this, SLOT(receiveMessage(const Message &)));
-
- systrayMenu = new QMenu(this);
- systrayMenu->addAction(ui.actionAboutQuassel);
- systrayMenu->addSeparator();
- systrayMenu->addAction(ui.actionConnectCore);
- systrayMenu->addAction(ui.actionDisconnectCore);
- systrayMenu->addSeparator();
- systrayMenu->addAction(ui.actionQuit);
-
- systray->setContextMenu(systrayMenu);
-
- UiSettings s;
- if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
- systray->show();
- }
+ _systemTray = new SystemTray(this);
+}
+
+void MainWin::setupToolBars() {
+ connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
+ QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
+ connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
+ QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
-#ifndef Q_WS_MAC
- connect(systray, SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
- this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
+#ifdef Q_WS_MAC
+ setUnifiedTitleAndToolBarOnMac(true);
#endif
+ _mainToolBar = addToolBar(tr("Main Toolbar"));
+ _mainToolBar->setObjectName("MainToolBar");
-}
+ QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
+ _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
-void MainWin::changeEvent(QEvent *event) {
- if(event->type() == QEvent::WindowStateChange) {
- if(windowState() & Qt::WindowMinimized) {
- UiSettings s;
- if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
- toggleVisibility();
- event->ignore();
- }
- }
- }
-}
+ //_nickToolBar = addToolBar("User");
+ //_nickToolBar->setObjectName("NickToolBar");
+ //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
-// FIXME this should be made prettier...
-void MainWin::changeTopic(const QString &topic) {
- BufferId id = ui.bufferWidget->currentBuffer();
- if(!id.isValid()) return;
- Buffer *buffer = Client::buffer(id);
- if(buffer) Client::userInput(buffer->bufferInfo(), QString("/topic %1").arg(topic));
+#ifdef HAVE_KDE
+ _mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+#endif
}
void MainWin::connectedToCore() {
connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
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();
}
void MainWin::setConnectedState() {
- ui.menuViews->setEnabled(true);
- //ui.menuCore->setEnabled(true);
- ui.actionConnectCore->setEnabled(false);
- ui.actionDisconnectCore->setEnabled(true);
- //ui.actionNetworkList->setEnabled(true);
- ui.bufferWidget->show();
- 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")));
+ 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();
+ systemTray()->setState(SystemTray::Active);
+
+ if(Client::networkIds().isEmpty()) {
+ IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
+ wizard->show();
+ }
}
void MainWin::loadLayout() {
if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
}
-void MainWin::securedConnection() {
- // todo: make status bar entry
- qDebug() << "secured the connection";
-
- sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/ssl")));
+void MainWin::updateLagIndicator(int lag) {
+ 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.menuViews->actions()) {
+ foreach(QAction *action, _bufferViewsMenu->actions()) {
actionData = action->data();
if(!actionData.isValid())
continue;
-
- if(actionData.toString() == "__EOBV__")
- break;
dock = qobject_cast<BufferViewDock *>(action->parent());
if(dock && actionData.toInt() != -1) {
}
void MainWin::setDisconnectedState() {
- ui.menuViews->setEnabled(false);
+ ActionCollection *coll = QtUi::actionCollection("General");
//ui.menuCore->setEnabled(false);
- ui.actionDisconnectCore->setEnabled(false);
- //ui.actionNetworkList->setEnabled(false);
- ui.bufferWidget->hide();
- ui.actionConnectCore->setEnabled(true);
- // nickListWidget->reset();
+ 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());
+ sslLabel->hide();
+ updateLagIndicator();
+ coreLagLabel->hide();
+ if(msgProcessorStatusWidget)
+ msgProcessorStatusWidget->setProgress(0, 0);
+ updateIcon();
+ systemTray()->setState(SystemTray::Inactive);
}
-AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
- return new ChatLineOld(msg);
+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) {
- coreConnectDlg = new CoreConnectDlg(this, autoConnect);
- connect(coreConnectDlg, SIGNAL(finished(int)), this, SLOT(coreConnectionDlgFinished(int)));
- coreConnectDlg->setModal(true);
- coreConnectDlg->show();
+ CoreConnectDlg(autoConnect, this).exec();
}
-void MainWin::coreConnectionDlgFinished(int /*code*/) {
- coreConnectDlg->close();
- //exit(1);
+void MainWin::showChannelList(NetworkId netId) {
+ ChannelListDlg *channelListDlg = new ChannelListDlg();
+
+ if(!netId.isValid()) {
+ QAction *action = qobject_cast<QAction *>(sender());
+ if(action)
+ netId = action->data().value<NetworkId>();
+ }
+
+ channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
+ channelListDlg->setNetwork(netId);
+ channelListDlg->show();
}
-void MainWin::showSettingsDlg() {
- settingsDlg->show();
+void MainWin::showCoreInfoDlg() {
+ CoreInfoDlg(this).exec();
}
-void MainWin::showDebugConsole() {
- debugConsole->show();
+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();
+
+ //Category: Appearance
+ dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
+ dlg->registerSettingsPage(new ColorSettingsPage(dlg));
+ dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
+ dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
+ dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
+ dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
+ dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
+
+ //Category: Misc
+ dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
+ dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
+ dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
+ dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
+
+ dlg->show();
}
void MainWin::showAboutDlg() {
- AboutDlg dlg(this);
- dlg.exec();
+ 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()) {
+ toggleMinimizedToTray();
event->ignore();
} else {
event->accept();
+ QApplication::quit();
}
}
-void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
- if (activationReason == QSystemTrayIcon::Trigger) {
- toggleVisibility();
- }
+bool MainWin::event(QEvent *event) {
+ if(event->type() == QEvent::WindowActivate)
+ QtUi::closeNotifications();
+ return QMainWindow::event(event);
}
-void MainWin::toggleVisibility() {
- if(isHidden() /*|| !isActiveWindow()*/) {
- show();
- if(isMinimized())
- if (isMaximized())
- showMaximized();
- else
- showNormal();
-
- raise();
- activateWindow();
- // setFocus(); //Qt::ActiveWindowFocusReason
-
- } else {
- if(systray->isSystemTrayAvailable ()) {
- clearFocus();
- hide();
- if(!systray->isVisible()) {
- systray->show();
+void MainWin::changeEvent(QEvent *event) {
+ if(event->type() == QEvent::WindowStateChange) {
+ if(windowState() & Qt::WindowMinimized) {
+ QtUiSettings s;
+ if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
+ hideToTray();
+ event->accept();
+ return;
}
- } else {
- lower();
}
}
+
+#ifdef Q_WS_WIN
+ else if(event->type() == QEvent::ActivationChange)
+ dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
+#endif
+
+ event->ignore();
}
-void MainWin::receiveMessage(const Message &msg) {
- if(QApplication::activeWindow() != 0)
+void MainWin::hideToTray() {
+ if(!systemTray()->isSystemTrayAvailable()) {
+ qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
return;
+ }
+ hide();
+ systemTray()->setIconVisible();
+}
- if(msg.flags() & Message::Highlight || msg.bufferInfo().type() == BufferInfo::QueryBuffer) {
- QString title = msg.bufferInfo().bufferName();;
- if(msg.bufferInfo().type() != BufferInfo::QueryBuffer) {
- QString sender = msg.sender();
- int i = sender.indexOf("!");
- if(i != -1)
- sender = sender.left(i);
- title += QString(" - %1").arg(sender);
- }
-
- UiSettings uiSettings;
+void MainWin::toggleMinimizedToTray() {
+#ifdef Q_WS_WIN
+ // the problem is that we lose focus when the systray icon is activated
+ // and we don't know the former active window
+ // therefore we watch for activation event and use our stopwatch :)
+ // courtesy: KSystemTrayIcon
+ if(GetTickCount() - dwTickCount >= 300)
+ // we weren't active in the last 300ms -> activate
+ forceActivated();
+ else
+ hideToTray();
- if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) {
- // FIXME don't invoke style engine for this!
- QString text = QtUi::style()->styleString(Message::mircToInternal(msg.text())).text;
- displayTrayIconMessage(title, text);
- }
+#else
- if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
- QApplication::alert(this);
- setTrayIconActivity(true);
- }
- }
-}
+ if(!isVisible() || isMinimized())
+ // restore
+ forceActivated();
+ else
+ hideToTray();
-bool MainWin::event(QEvent *event) {
- if(event->type() == QEvent::WindowActivate)
- setTrayIconActivity(false);
- return QMainWindow::event(event);
+#endif
}
-void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
- systray->showMessage(title, message);
-}
+void MainWin::forceActivated() {
+#ifdef Q_WS_X11
+ // Bypass focus stealing prevention
+ QX11Info::setAppUserTime(QX11Info::appTime());
+#endif
-void MainWin::setTrayIconActivity(bool active) {
- if(active) {
- if(!timer->isActive())
- timer->start(500);
- } else {
- timer->stop();
- systray->setIcon(onlineTrayIcon);
+ if(windowState() & Qt::WindowMinimized) {
+ // restore
+ setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
}
-}
-void MainWin::makeTrayIconBlink() {
- if(trayIconActive) {
- systray->setIcon(onlineTrayIcon);
- trayIconActive = false;
- } else {
- systray->setIcon(activeTrayIcon);
- trayIconActive = true;
- }
+ move(frameGeometry().topLeft()); // avoid placement policies
+ show();
+ raise();
+ activateWindow();
}
+void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
+ Q_UNUSED(parent);
+ bool hasFocus = QApplication::activeWindow() != 0;
+
+ for(int i = start; i <= end; i++) {
+ QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
+ if(!idx.isValid()) {
+ qDebug() << "MainWin::messagesInserted(): Invalid model index!";
+ continue;
+ }
+ Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
+ if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
+ 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<BufferId>();
+ BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
+
+ if(hasFocus && bufId == _bufferWidget->currentBuffer())
+ continue;
+
+ if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
+ QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
+ QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
+ QString contents = idx.data(ChatLineModel::DisplayRole).toString();
+ AbstractNotificationBackend::NotificationType type;
+
+ if(bufType == BufferInfo::QueryBuffer && !hasFocus)
+ type = AbstractNotificationBackend::PrivMsg;
+ else if(bufType == BufferInfo::QueryBuffer && hasFocus)
+ type = AbstractNotificationBackend::PrivMsgFocused;
+ else if(flags & Message::Highlight && !hasFocus)
+ type = AbstractNotificationBackend::Highlight;
+ else
+ type = AbstractNotificationBackend::HighlightFocused;
+
+ QtUi::invokeNotification(bufId, type, sender, contents);
+ }
+ }
+}
void MainWin::clientNetworkCreated(NetworkId id) {
const Network *net = Client::network(id);
QAction *act = new QAction(net->networkName(), this);
+ act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
act->setData(QVariant::fromValue<NetworkId>(id));
connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
- bool inserted = false;
- for(int i = 0; i < networkActions.count(); i++) {
- if(net->networkName().localeAwareCompare(networkActions[i]->text()) < 0) {
- networkActions.insert(i, act);
- inserted = true;
+
+ QAction *beforeAction = 0;
+ foreach(QAction *action, _networksMenu->actions()) {
+ if(!action->data().isValid()) // ignore stock actions
+ continue;
+ if(net->networkName().localeAwareCompare(action->text()) < 0) {
+ beforeAction = action;
break;
}
}
- if(!inserted) networkActions.append(act);
- ui.menuNetworks->clear(); // why the f*** isn't there a QMenu::insertAction()???
- foreach(QAction *a, networkActions) ui.menuNetworks->addAction(a);
- ui.menuNetworks->addSeparator();
- ui.menuNetworks->addAction(actionEditNetworks);
+ _networksMenu->insertAction(beforeAction, act);
}
void MainWin::clientNetworkUpdated() {
const Network *net = qobject_cast<const Network *>(sender());
- if(!net) return;
- foreach(QAction *a, networkActions) {
- if(a->data().value<NetworkId>() == net->networkId()) {
- a->setText(net->networkName());
- if(net->connectionState() == Network::Initialized) {
- a->setIcon(QIcon(":/16x16/actions/network-connect"));
- //a->setEnabled(true);
- } else if(net->connectionState() == Network::Disconnected) {
- a->setIcon(QIcon(":/16x16/actions/network-disconnect"));
- //a->setEnabled(true);
- } else {
- a->setIcon(QIcon(":/16x16/actions/gear"));
- //a->setEnabled(false);
- }
- return;
- }
+ if(!net)
+ return;
+
+ QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
+ if(!action)
+ return;
+
+ action->setText(net->networkName());
+
+ switch(net->connectionState()) {
+ case Network::Initialized:
+ action->setIcon(SmallIcon("network-connect"));
+ break;
+ case Network::Disconnected:
+ action->setIcon(SmallIcon("network-disconnect"));
+ break;
+ default:
+ action->setIcon(SmallIcon("network-wired"));
}
}
void MainWin::clientNetworkRemoved(NetworkId id) {
- QList<QAction *>::iterator actionIter = networkActions.begin();;
- QAction *action;
- while(actionIter != networkActions.end()) {
- action = *actionIter;
- if(action->data().value<NetworkId>() == id) {
- action->deleteLater();
- actionIter = networkActions.erase(actionIter);
- } else
- actionIter++;
- }
+ QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
+ if(!action)
+ return;
+
+ action->deleteLater();
}
void MainWin::connectOrDisconnectFromNet() {
else net->requestDisconnect();
}
+void MainWin::on_actionDebugNetworkModel_triggered() {
+ QTreeView *view = new QTreeView;
+ view->setAttribute(Qt::WA_DeleteOnClose);
+ view->setWindowTitle("Debug NetworkModel View");
+ view->setModel(Client::networkModel());
+ view->setColumnWidth(0, 250);
+ view->setColumnWidth(1, 250);
+ view->setColumnWidth(2, 80);
+ view->resize(610, 300);
+ view->show();
+}
+
+void MainWin::on_actionDebugBufferViewOverlay_triggered() {
+ QTreeView *view = new QTreeView;
+ view->setAttribute(Qt::WA_DeleteOnClose);
+ view->setWindowTitle("Debug BufferViewOverlay View");
+ BufferViewOverlayFilter *filter = new BufferViewOverlayFilter(Client::bufferModel(), Client::bufferViewOverlay());
+ filter->setParent(view);
+ view->setModel(filter);
+ view->setColumnWidth(0, 250);
+ view->setColumnWidth(1, 250);
+ view->setColumnWidth(2, 80);
+ 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);
+}
+