1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 # include <KActionCollection>
27 # include <KShortcutsDialog>
28 # include <KStatusBar>
32 #include "awaylogfilter.h"
33 #include "awaylogview.h"
35 #include "actioncollection.h"
36 #include "buffermodel.h"
37 #include "bufferview.h"
38 #include "bufferwidget.h"
39 #include "channellistdlg.h"
40 #include "chatlinemodel.h"
41 #include "chatmonitorfilter.h"
42 #include "chatmonitorview.h"
45 #include "clientsyncer.h"
46 #include "clientbacklogmanager.h"
47 #include "clientbufferviewconfig.h"
48 #include "clientbufferviewmanager.h"
49 #include "coreinfodlg.h"
50 #include "coreconnectdlg.h"
51 #include "contextmenuactionprovider.h"
52 #include "debuglogwidget.h"
53 #include "debugmessagemodelfilter.h"
54 #include "iconloader.h"
55 #include "inputwidget.h"
56 #include "inputline.h"
57 #include "irclistmodel.h"
58 #include "jumpkeyhandler.h"
59 #include "msgprocessorstatuswidget.h"
60 #include "nicklistwidget.h"
61 #include "qtuiapplication.h"
62 #include "qtuimessageprocessor.h"
63 #include "qtuisettings.h"
64 #include "sessionsettings.h"
65 #include "settingsdlg.h"
66 #include "settingspagedlg.h"
67 #include "toolbaractionprovider.h"
68 #include "topicwidget.h"
69 #include "verticaldock.h"
73 # include "desktopnotificationbackend.h"
76 # include "phononnotificationbackend.h"
78 # include "systraynotificationbackend.h"
79 # include "taskbarnotificationbackend.h"
81 # include "knotificationbackend.h"
84 #include "settingspages/aliasessettingspage.h"
85 #include "settingspages/appearancesettingspage.h"
86 #include "settingspages/backlogsettingspage.h"
87 #include "settingspages/bufferviewsettingspage.h"
88 #include "settingspages/chatmonitorsettingspage.h"
89 #include "settingspages/colorsettingspage.h"
90 #include "settingspages/fontssettingspage.h"
91 #include "settingspages/generalsettingspage.h"
92 #include "settingspages/highlightsettingspage.h"
93 #include "settingspages/identitiessettingspage.h"
94 #include "settingspages/networkssettingspage.h"
95 #include "settingspages/notificationssettingspage.h"
97 MainWin::MainWin(QWidget *parent)
99 : KMainWindow(parent),
100 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
102 : QMainWindow(parent),
104 coreLagLabel(new QLabel()),
105 sslLabel(new QLabel()),
106 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
108 _trayIcon(new QSystemTrayIcon(this)),
111 QtUiSettings uiSettings;
112 QString style = uiSettings.value("Style", QString()).toString();
113 if(!style.isEmpty()) {
114 QApplication::setStyle(style);
117 QApplication::setQuitOnLastWindowClosed(false);
119 setWindowTitle("Quassel IRC");
120 setWindowIconText("Quassel IRC");
123 installEventFilter(new JumpKeyHandler(this));
125 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
126 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
127 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
130 void MainWin::init() {
132 if(s.value("MainWinSize").isValid())
133 resize(s.value("MainWinSize").toSize());
135 resize(QSize(800, 500));
137 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
138 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
139 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
140 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
143 setDockNestingEnabled(true);
144 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
145 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
146 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
147 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
149 // Order is sometimes important
163 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
164 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
166 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
169 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
173 QtUi::registerNotificationBackend(new KNotificationBackend(this));
174 #endif /* HAVE_KDE */
176 // restore mainwin state
177 restoreState(s.value("MainWinState").toByteArray());
179 // restore locked state of docks
180 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
182 setDisconnectedState(); // Disable menus and stuff
185 if(Quassel::runMode() != Quassel::Monolithic) {
186 showCoreConnectionDlg(true); // autoconnect if appropriate
192 MainWin::~MainWin() {
194 s.setValue("MainWinSize", size());
195 s.setValue("MainWinPos", pos());
196 s.setValue("MainWinState", saveState());
199 void MainWin::updateIcon() {
201 if(Client::isConnected())
202 icon = DesktopIcon("quassel", IconLoader::SizeEnormous);
204 icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous);
206 qApp->setWindowIcon(icon);
207 systemTrayIcon()->setIcon(icon);
210 void MainWin::setupActions() {
211 ActionCollection *coll = QtUi::actionCollection("General");
213 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
214 this, SLOT(showCoreConnectionDlg())));
215 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
216 Client::instance(), SLOT(disconnectFromCore())));
217 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
218 this, SLOT(showCoreInfoDlg())));
219 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
220 this, SLOT(on_actionConfigureNetworks_triggered())));
221 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
222 qApp, SLOT(quit()), tr("Ctrl+Q")));
225 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
226 this, SLOT(on_actionConfigureViews_triggered())));
228 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
229 lockAct->setCheckable(true);
230 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
232 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
233 0, 0, tr("Ctrl+F")))->setCheckable(true);
234 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
235 this, SLOT(showAwayLog())));
236 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
237 0, 0))->setCheckable(true);
240 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
241 this, SLOT(showSettingsDlg()), tr("F7")));
244 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
245 this, SLOT(showAboutDlg())));
246 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
247 qApp, SLOT(aboutQt())));
248 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
249 this, SLOT(on_actionDebugNetworkModel_triggered())));
250 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
251 this, SLOT(on_actionDebugMessageModel_triggered())));
252 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
253 this, SLOT(on_actionDebugLog_triggered())));
256 void MainWin::setupMenus() {
257 ActionCollection *coll = QtUi::actionCollection("General");
259 _fileMenu = menuBar()->addMenu(tr("&File"));
261 static const QStringList coreActions = QStringList()
262 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
265 foreach(QString actionName, coreActions) {
266 coreAction = coll->action(actionName);
267 _fileMenu->addAction(coreAction);
268 flagRemoteCoreOnly(coreAction);
270 flagRemoteCoreOnly(_fileMenu->addSeparator());
272 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
273 _networksMenu->addAction(coll->action("ConfigureNetworks"));
274 _networksMenu->addSeparator();
275 _fileMenu->addSeparator();
276 _fileMenu->addAction(coll->action("Quit"));
278 _viewMenu = menuBar()->addMenu(tr("&View"));
279 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
280 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
281 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
282 _viewMenu->addSeparator();
283 _viewMenu->addAction(coll->action("ToggleSearchBar"));
285 coreAction = coll->action("ShowAwayLog");
286 flagRemoteCoreOnly(coreAction);
287 _viewMenu->addAction(coreAction);
289 _viewMenu->addAction(coll->action("ToggleStatusBar"));
290 _viewMenu->addSeparator();
291 _viewMenu->addAction(coll->action("LockLayout"));
293 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
295 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
296 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
298 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
300 _helpMenu = menuBar()->addMenu(tr("&Help"));
301 _helpMenu->addAction(coll->action("AboutQuassel"));
303 _helpMenu->addAction(coll->action("AboutQt"));
305 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
307 _helpMenu->addSeparator();
308 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
309 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
310 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
311 _helpDebugMenu->addAction(coll->action("DebugLog"));
314 void MainWin::setupBufferWidget() {
315 _bufferWidget = new BufferWidget(this);
316 _bufferWidget->setModel(Client::bufferModel());
317 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
318 setCentralWidget(_bufferWidget);
321 void MainWin::addBufferView(int bufferViewConfigId) {
322 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
325 void MainWin::addBufferView(ClientBufferViewConfig *config) {
329 BufferViewDock *dock = new BufferViewDock(config, this);
331 //create the view and initialize it's filter
332 BufferView *view = new BufferView(dock);
333 view->setFilteredModel(Client::bufferModel(), config);
334 view->installEventFilter(_inputWidget->inputLine()); // for key presses
337 Client::bufferModel()->synchronizeView(view);
339 dock->setWidget(view);
342 addDockWidget(Qt::LeftDockWidgetArea, dock);
343 _bufferViewsMenu->addAction(dock->toggleViewAction());
345 _bufferViews.append(dock);
348 void MainWin::removeBufferView(int bufferViewConfigId) {
350 BufferViewDock *dock;
351 foreach(QAction *action, _bufferViewsMenu->actions()) {
352 actionData = action->data();
353 if(!actionData.isValid())
356 dock = qobject_cast<BufferViewDock *>(action->parent());
357 if(dock && actionData.toInt() == bufferViewConfigId) {
358 removeAction(action);
364 BufferView *MainWin::allBuffersView() const {
365 // "All Buffers" is always the first dock created
366 if(_bufferViews.count() > 0)
367 return _bufferViews[0]->bufferView();
371 void MainWin::showNotificationsDlg() {
372 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
376 void MainWin::on_actionConfigureNetworks_triggered() {
377 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
381 void MainWin::on_actionConfigureViews_triggered() {
382 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
386 void MainWin::on_actionLockLayout_toggled(bool lock) {
387 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
388 foreach(VerticalDock *dock, docks) {
389 dock->showTitle(!lock);
391 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
392 config->setLocked(lock);
394 QtUiSettings().setValue("LockLayout", lock);
397 void MainWin::setupNickWidget() {
399 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
400 nickDock->setObjectName("NickDock");
401 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
403 _nickListWidget = new NickListWidget(nickDock);
404 nickDock->setWidget(_nickListWidget);
406 addDockWidget(Qt::RightDockWidgetArea, nickDock);
407 _viewMenu->addAction(nickDock->toggleViewAction());
408 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
409 nickDock->toggleViewAction()->setIcon(SmallIcon("view-sidetree"));
410 // See NickListDock::NickListDock();
411 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
413 // attach the NickListWidget to the BufferModel and the default selection
414 _nickListWidget->setModel(Client::bufferModel());
415 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
418 void MainWin::setupChatMonitor() {
419 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
420 dock->setObjectName("ChatMonitorDock");
422 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
423 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
425 dock->setWidget(chatView);
428 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
429 _viewMenu->addAction(dock->toggleViewAction());
430 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
433 void MainWin::setupInputWidget() {
434 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
435 dock->setObjectName("InputDock");
437 _inputWidget = new InputWidget(dock);
438 dock->setWidget(_inputWidget);
440 addDockWidget(Qt::BottomDockWidgetArea, dock);
442 _viewMenu->addAction(dock->toggleViewAction());
443 dock->toggleViewAction()->setText(tr("Show Input Line"));
445 _inputWidget->setModel(Client::bufferModel());
446 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
448 _bufferWidget->setFocusProxy(_inputWidget);
450 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
453 void MainWin::setupTopicWidget() {
454 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
455 dock->setObjectName("TopicDock");
456 TopicWidget *topicwidget = new TopicWidget(dock);
458 dock->setWidget(topicwidget);
460 topicwidget->setModel(Client::bufferModel());
461 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
463 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
465 _viewMenu->addAction(dock->toggleViewAction());
466 dock->toggleViewAction()->setText(tr("Show Topic Line"));
469 void MainWin::setupTitleSetter() {
470 _titleSetter.setModel(Client::bufferModel());
471 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
474 void MainWin::setupStatusBar() {
475 // MessageProcessor progress
476 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
479 updateLagIndicator();
480 statusBar()->addPermanentWidget(coreLagLabel);
481 coreLagLabel->hide();
482 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
485 sslLabel->setPixmap(QPixmap());
486 statusBar()->addPermanentWidget(sslLabel);
489 _viewMenu->addSeparator();
490 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
492 QtUiSettings uiSettings;
494 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
495 showStatusbar->setChecked(enabled);
496 enabled ? statusBar()->show() : statusBar()->hide();
498 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
499 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
502 void MainWin::saveStatusBarStatus(bool enabled) {
503 QtUiSettings uiSettings;
504 uiSettings.setValue("ShowStatusBar", enabled);
507 void MainWin::setupSystray() {
508 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
509 SLOT(messagesInserted(const QModelIndex &, int, int)));
511 ActionCollection *coll = QtUi::actionCollection("General");
512 systrayMenu = new QMenu(this);
513 systrayMenu->addAction(coll->action("ConnectCore"));
514 systrayMenu->addAction(coll->action("DisconnectCore"));
515 systrayMenu->addAction(coll->action("CoreInfo"));
516 systrayMenu->addSeparator();
517 systrayMenu->addAction(coll->action("Quit"));
519 systemTrayIcon()->setContextMenu(systrayMenu);
522 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
523 systemTrayIcon()->show();
527 connect(systemTrayIcon(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayActivated(QSystemTrayIcon::ActivationReason)));
531 void MainWin::setupToolBars() {
532 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
533 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
534 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
535 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
537 _mainToolBar = addToolBar("Main Toolbar");
538 _mainToolBar->setObjectName("MainToolBar");
539 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
540 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
542 //_nickToolBar = addToolBar("User");
543 //_nickToolBar->setObjectName("NickToolBar");
544 //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
547 _mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
548 //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
552 void MainWin::changeEvent(QEvent *event) {
553 if(event->type() == QEvent::WindowStateChange) {
554 if(windowState() & Qt::WindowMinimized) {
556 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
564 void MainWin::connectedToCore() {
565 Q_CHECK_PTR(Client::bufferViewManager());
566 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
567 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
568 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
573 void MainWin::setConnectedState() {
574 ActionCollection *coll = QtUi::actionCollection("General");
576 coll->action("ConnectCore")->setEnabled(false);
577 coll->action("DisconnectCore")->setEnabled(true);
578 coll->action("CoreInfo")->setEnabled(true);
580 foreach(QAction *action, _fileMenu->actions()) {
581 if(isRemoteCoreOnly(action))
582 action->setVisible(!Client::internalCore());
585 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
586 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
587 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
588 if(!Client::internalCore()) {
589 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
590 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
591 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
594 // _viewMenu->setEnabled(true);
595 if(!Client::internalCore())
596 statusBar()->showMessage(tr("Connected to core."));
598 statusBar()->clearMessage();
600 if(Client::signalProxy()->isSecure()) {
601 sslLabel->setPixmap(SmallIcon("security-high"));
603 sslLabel->setPixmap(SmallIcon("security-low"));
606 sslLabel->setVisible(!Client::internalCore());
607 coreLagLabel->setVisible(!Client::internalCore());
611 void MainWin::loadLayout() {
613 int accountId = Client::currentCoreAccount().toInt();
614 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
617 void MainWin::saveLayout() {
619 int accountId = Client::currentCoreAccount().toInt();
620 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
623 void MainWin::updateLagIndicator(int lag) {
624 QString text = tr("Core Lag: %1");
626 text = text.arg('-');
628 text = text.arg("%1 msec").arg(lag);
629 coreLagLabel->setText(text);
632 void MainWin::disconnectedFromCore() {
633 // save core specific layout and remove bufferviews;
636 BufferViewDock *dock;
637 foreach(QAction *action, _bufferViewsMenu->actions()) {
638 actionData = action->data();
639 if(!actionData.isValid())
642 dock = qobject_cast<BufferViewDock *>(action->parent());
643 if(dock && actionData.toInt() != -1) {
644 removeAction(action);
649 restoreState(s.value("MainWinState").toByteArray());
650 setDisconnectedState();
653 void MainWin::setDisconnectedState() {
654 ActionCollection *coll = QtUi::actionCollection("General");
655 //ui.menuCore->setEnabled(false);
656 coll->action("ConnectCore")->setEnabled(true);
657 coll->action("DisconnectCore")->setEnabled(false);
658 coll->action("CoreInfo")->setEnabled(false);
659 //_viewMenu->setEnabled(false);
660 statusBar()->showMessage(tr("Not connected to core."));
661 sslLabel->setPixmap(QPixmap());
663 updateLagIndicator();
664 coreLagLabel->hide();
665 if(msgProcessorStatusWidget)
666 msgProcessorStatusWidget->setProgress(0, 0);
670 void MainWin::startInternalCore() {
671 ClientSyncer *syncer = new ClientSyncer();
672 Client::registerClientSyncer(syncer);
673 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
674 syncer->useInternalCore();
677 void MainWin::showCoreConnectionDlg(bool autoConnect) {
678 CoreConnectDlg(autoConnect, this).exec();
681 void MainWin::showChannelList(NetworkId netId) {
682 ChannelListDlg *channelListDlg = new ChannelListDlg();
684 if(!netId.isValid()) {
685 QAction *action = qobject_cast<QAction *>(sender());
687 netId = action->data().value<NetworkId>();
690 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
691 channelListDlg->setNetwork(netId);
692 channelListDlg->show();
695 void MainWin::showCoreInfoDlg() {
696 CoreInfoDlg(this).exec();
699 void MainWin::showAwayLog() {
702 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
703 _awayLog = new AwayLogView(filter, 0);
704 filter->setParent(_awayLog);
705 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
706 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
710 void MainWin::awayLogDestroyed() {
714 void MainWin::showSettingsDlg() {
715 SettingsDlg *dlg = new SettingsDlg();
717 //Category: Appearance
718 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
719 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
720 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
721 //Category: Behaviour
722 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
723 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
724 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
725 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
726 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
727 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
729 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
730 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
731 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
736 void MainWin::showAboutDlg() {
737 AboutDlg(this).exec();
741 void MainWin::showShortcutsDlg() {
742 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
746 void MainWin::closeEvent(QCloseEvent *event) {
748 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
750 if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
751 toggleMinimizedToTray();
755 QApplication::quit();
759 void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) {
760 if(activationReason == QSystemTrayIcon::Trigger) {
761 toggleMinimizedToTray();
765 void MainWin::hideToTray() {
766 if(!systemTrayIcon()->isSystemTrayAvailable()) {
767 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
773 systemTrayIcon()->show();
776 void MainWin::toggleMinimizedToTray() {
777 if(windowState() & Qt::WindowMinimized) {
779 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
783 setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized);
788 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
791 if(QApplication::activeWindow() != 0)
794 for(int i = start; i <= end; i++) {
795 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
797 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
800 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
801 if(flags.testFlag(Message::Backlog)) continue;
802 flags |= Message::Backlog; // we only want to trigger a highlight once!
803 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
805 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
806 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
808 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
809 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
810 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
811 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
812 QtUi::invokeNotification(bufId, sender, contents);
817 bool MainWin::event(QEvent *event) {
818 if(event->type() == QEvent::WindowActivate)
819 QtUi::closeNotifications();
820 return QMainWindow::event(event);
823 void MainWin::clientNetworkCreated(NetworkId id) {
824 const Network *net = Client::network(id);
825 QAction *act = new QAction(net->networkName(), this);
826 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
827 act->setData(QVariant::fromValue<NetworkId>(id));
828 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
829 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
831 QAction *beforeAction = 0;
832 foreach(QAction *action, _networksMenu->actions()) {
833 if(!action->data().isValid()) // ignore stock actions
835 if(net->networkName().localeAwareCompare(action->text()) < 0) {
836 beforeAction = action;
840 _networksMenu->insertAction(beforeAction, act);
843 void MainWin::clientNetworkUpdated() {
844 const Network *net = qobject_cast<const Network *>(sender());
848 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
852 action->setText(net->networkName());
854 switch(net->connectionState()) {
855 case Network::Initialized:
856 action->setIcon(SmallIcon("network-connect"));
858 case Network::Disconnected:
859 action->setIcon(SmallIcon("network-disconnect"));
862 action->setIcon(SmallIcon("network-wired"));
866 void MainWin::clientNetworkRemoved(NetworkId id) {
867 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
871 action->deleteLater();
874 void MainWin::connectOrDisconnectFromNet() {
875 QAction *act = qobject_cast<QAction *>(sender());
877 const Network *net = Client::network(act->data().value<NetworkId>());
879 if(net->connectionState() == Network::Disconnected) net->requestConnect();
880 else net->requestDisconnect();
883 void MainWin::on_actionDebugNetworkModel_triggered() {
884 QTreeView *view = new QTreeView;
885 view->setAttribute(Qt::WA_DeleteOnClose);
886 view->setWindowTitle("Debug NetworkModel View");
887 view->setModel(Client::networkModel());
888 view->setColumnWidth(0, 250);
889 view->setColumnWidth(1, 250);
890 view->setColumnWidth(2, 80);
891 view->resize(610, 300);
895 void MainWin::on_actionDebugMessageModel_triggered() {
896 QTableView *view = new QTableView(0);
897 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
898 filter->setSourceModel(Client::messageModel());
899 view->setModel(filter);
900 view->setAttribute(Qt::WA_DeleteOnClose, true);
901 view->verticalHeader()->hide();
902 view->horizontalHeader()->setStretchLastSection(true);
906 void MainWin::on_actionDebugLog_triggered() {
907 DebugLogWidget *logWidget = new DebugLogWidget(0);
911 void MainWin::saveStateToSession(const QString &sessionId) {
913 SessionSettings s(sessionId);
915 s.setValue("MainWinSize", size());
916 s.setValue("MainWinPos", pos());
917 s.setValue("MainWinState", saveState());
920 void MainWin::saveStateToSessionSettings(SessionSettings & s)
922 s.setValue("MainWinSize", size());
923 s.setValue("MainWinPos", pos());
924 s.setValue("MainWinState", saveState());
927 void MainWin::showStatusBarMessage(const QString &message) {
928 statusBar()->showMessage(message, 10000);