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 "bufferviewoverlay.h"
39 #include "bufferviewoverlayfilter.h"
40 #include "bufferwidget.h"
41 #include "channellistdlg.h"
42 #include "chatlinemodel.h"
43 #include "chatmonitorfilter.h"
44 #include "chatmonitorview.h"
47 #include "clientsyncer.h"
48 #include "clientbacklogmanager.h"
49 #include "clientbufferviewconfig.h"
50 #include "clientbufferviewmanager.h"
51 #include "coreinfodlg.h"
52 #include "coreconnectdlg.h"
53 #include "contextmenuactionprovider.h"
54 #include "debuglogwidget.h"
55 #include "debugmessagemodelfilter.h"
56 #include "iconloader.h"
57 #include "inputwidget.h"
58 #include "inputline.h"
59 #include "irclistmodel.h"
60 #include "ircconnectionwizard.h"
61 #include "jumpkeyhandler.h"
62 #include "msgprocessorstatuswidget.h"
63 #include "nicklistwidget.h"
64 #include "qtuiapplication.h"
65 #include "qtuimessageprocessor.h"
66 #include "qtuisettings.h"
67 #include "sessionsettings.h"
68 #include "settingsdlg.h"
69 #include "settingspagedlg.h"
70 #include "systemtray.h"
71 #include "toolbaractionprovider.h"
72 #include "topicwidget.h"
73 #include "verticaldock.h"
77 # include "desktopnotificationbackend.h"
80 # include "phononnotificationbackend.h"
82 # include "systraynotificationbackend.h"
83 # include "taskbarnotificationbackend.h"
85 # include "knotificationbackend.h"
88 #include "settingspages/aliasessettingspage.h"
89 #include "settingspages/appearancesettingspage.h"
90 #include "settingspages/backlogsettingspage.h"
91 #include "settingspages/bufferviewsettingspage.h"
92 #include "settingspages/chatmonitorsettingspage.h"
93 #include "settingspages/colorsettingspage.h"
94 #include "settingspages/generalsettingspage.h"
95 #include "settingspages/highlightsettingspage.h"
96 #include "settingspages/identitiessettingspage.h"
97 #include "settingspages/networkssettingspage.h"
98 #include "settingspages/notificationssettingspage.h"
100 MainWin::MainWin(QWidget *parent)
102 : KMainWindow(parent),
103 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
105 : QMainWindow(parent),
107 coreLagLabel(new QLabel()),
108 sslLabel(new QLabel()),
109 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
113 QtUiSettings uiSettings;
114 QString style = uiSettings.value("Style", QString()).toString();
115 if(!style.isEmpty()) {
116 QApplication::setStyle(style);
119 QApplication::setQuitOnLastWindowClosed(false);
121 setWindowTitle("Quassel IRC");
122 setWindowIconText("Quassel IRC");
125 installEventFilter(new JumpKeyHandler(this));
127 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
128 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
129 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
132 void MainWin::init() {
134 if(s.value("MainWinSize").isValid())
135 resize(s.value("MainWinSize").toSize());
137 resize(QSize(800, 500));
139 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
140 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
141 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
142 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
143 SLOT(messagesInserted(const QModelIndex &, int, int)));
144 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
147 setDockNestingEnabled(true);
148 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
149 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
150 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
151 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
153 // Order is sometimes important
167 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
168 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
170 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
173 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
177 QtUi::registerNotificationBackend(new KNotificationBackend(this));
178 #endif /* HAVE_KDE */
180 // restore mainwin state
181 restoreState(s.value("MainWinState").toByteArray());
183 // restore locked state of docks
184 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
186 setDisconnectedState(); // Disable menus and stuff
190 if(Quassel::runMode() != Quassel::Monolithic) {
191 showCoreConnectionDlg(true); // autoconnect if appropriate
197 MainWin::~MainWin() {
199 s.setValue("MainWinSize", size());
200 s.setValue("MainWinPos", pos());
201 s.setValue("MainWinState", saveState());
204 void MainWin::updateIcon() {
206 const int size = 128;
212 if(Client::isConnected())
213 icon = DesktopIcon("quassel", size);
215 icon = DesktopIcon("quassel_inactive", size);
217 qApp->setWindowIcon(icon);
220 void MainWin::setupActions() {
221 ActionCollection *coll = QtUi::actionCollection("General");
223 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
224 this, SLOT(showCoreConnectionDlg())));
225 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
226 Client::instance(), SLOT(disconnectFromCore())));
227 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
228 this, SLOT(showCoreInfoDlg())));
229 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
230 this, SLOT(on_actionConfigureNetworks_triggered())));
231 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
232 qApp, SLOT(quit()), tr("Ctrl+Q")));
235 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
236 this, SLOT(on_actionConfigureViews_triggered())));
238 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
239 lockAct->setCheckable(true);
240 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
242 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
243 0, 0, tr("Ctrl+F")))->setCheckable(true);
244 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
245 this, SLOT(showAwayLog())));
246 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
247 0, 0))->setCheckable(true);
250 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
251 this, SLOT(showSettingsDlg()), tr("F7")));
254 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
255 this, SLOT(showAboutDlg())));
256 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
257 qApp, SLOT(aboutQt())));
258 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
259 this, SLOT(on_actionDebugNetworkModel_triggered())));
260 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
261 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
262 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
263 this, SLOT(on_actionDebugMessageModel_triggered())));
264 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
265 this, SLOT(on_actionDebugLog_triggered())));
268 void MainWin::setupMenus() {
269 ActionCollection *coll = QtUi::actionCollection("General");
271 _fileMenu = menuBar()->addMenu(tr("&File"));
273 static const QStringList coreActions = QStringList()
274 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
277 foreach(QString actionName, coreActions) {
278 coreAction = coll->action(actionName);
279 _fileMenu->addAction(coreAction);
280 flagRemoteCoreOnly(coreAction);
282 flagRemoteCoreOnly(_fileMenu->addSeparator());
284 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
285 _networksMenu->addAction(coll->action("ConfigureNetworks"));
286 _networksMenu->addSeparator();
287 _fileMenu->addSeparator();
288 _fileMenu->addAction(coll->action("Quit"));
290 _viewMenu = menuBar()->addMenu(tr("&View"));
291 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
292 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
293 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
294 _viewMenu->addSeparator();
295 _viewMenu->addAction(coll->action("ToggleSearchBar"));
297 coreAction = coll->action("ShowAwayLog");
298 flagRemoteCoreOnly(coreAction);
299 _viewMenu->addAction(coreAction);
301 _viewMenu->addAction(coll->action("ToggleStatusBar"));
302 _viewMenu->addSeparator();
303 _viewMenu->addAction(coll->action("LockLayout"));
305 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
307 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
308 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
310 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
312 _helpMenu = menuBar()->addMenu(tr("&Help"));
313 _helpMenu->addAction(coll->action("AboutQuassel"));
315 _helpMenu->addAction(coll->action("AboutQt"));
317 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
319 _helpMenu->addSeparator();
320 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
321 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
322 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
323 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
324 _helpDebugMenu->addAction(coll->action("DebugLog"));
327 void MainWin::setupBufferWidget() {
328 _bufferWidget = new BufferWidget(this);
329 _bufferWidget->setModel(Client::bufferModel());
330 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
331 setCentralWidget(_bufferWidget);
334 void MainWin::addBufferView(int bufferViewConfigId) {
335 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
338 void MainWin::addBufferView(ClientBufferViewConfig *config) {
342 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
343 BufferViewDock *dock = new BufferViewDock(config, this);
345 //create the view and initialize it's filter
346 BufferView *view = new BufferView(dock);
347 view->setFilteredModel(Client::bufferModel(), config);
348 view->installEventFilter(_inputWidget->inputLine()); // for key presses
351 Client::bufferModel()->synchronizeView(view);
353 dock->setWidget(view);
356 addDockWidget(Qt::LeftDockWidgetArea, dock);
357 _bufferViewsMenu->addAction(dock->toggleViewAction());
359 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
360 _bufferViews.append(dock);
363 void MainWin::removeBufferView(int bufferViewConfigId) {
365 BufferViewDock *dock;
366 foreach(QAction *action, _bufferViewsMenu->actions()) {
367 actionData = action->data();
368 if(!actionData.isValid())
371 dock = qobject_cast<BufferViewDock *>(action->parent());
372 if(dock && actionData.toInt() == bufferViewConfigId) {
373 removeAction(action);
379 void MainWin::bufferViewToggled(bool enabled) {
380 QAction *action = qobject_cast<QAction *>(sender());
382 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
385 Client::bufferViewOverlay()->addView(dock->bufferViewId());
387 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
391 BufferView *MainWin::allBuffersView() const {
392 // "All Buffers" is always the first dock created
393 if(_bufferViews.count() > 0)
394 return _bufferViews[0]->bufferView();
398 void MainWin::showNotificationsDlg() {
399 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
403 void MainWin::on_actionConfigureNetworks_triggered() {
404 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
408 void MainWin::on_actionConfigureViews_triggered() {
409 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
413 void MainWin::on_actionLockLayout_toggled(bool lock) {
414 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
415 foreach(VerticalDock *dock, docks) {
416 dock->showTitle(!lock);
418 if(Client::bufferViewManager()) {
419 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
420 config->setLocked(lock);
423 QtUiSettings().setValue("LockLayout", lock);
426 void MainWin::setupNickWidget() {
428 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
429 nickDock->setObjectName("NickDock");
430 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
432 _nickListWidget = new NickListWidget(nickDock);
433 nickDock->setWidget(_nickListWidget);
435 addDockWidget(Qt::RightDockWidgetArea, nickDock);
436 _viewMenu->addAction(nickDock->toggleViewAction());
437 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
439 // See NickListDock::NickListDock();
440 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
442 // attach the NickListWidget to the BufferModel and the default selection
443 _nickListWidget->setModel(Client::bufferModel());
444 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
447 void MainWin::setupChatMonitor() {
448 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
449 dock->setObjectName("ChatMonitorDock");
451 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
452 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
454 dock->setWidget(chatView);
457 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
458 _viewMenu->addAction(dock->toggleViewAction());
459 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
462 void MainWin::setupInputWidget() {
463 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
464 dock->setObjectName("InputDock");
466 _inputWidget = new InputWidget(dock);
467 dock->setWidget(_inputWidget);
469 addDockWidget(Qt::BottomDockWidgetArea, dock);
471 _viewMenu->addAction(dock->toggleViewAction());
472 dock->toggleViewAction()->setText(tr("Show Input Line"));
474 _inputWidget->setModel(Client::bufferModel());
475 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
477 _bufferWidget->setFocusProxy(_inputWidget);
479 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
482 void MainWin::setupTopicWidget() {
483 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
484 dock->setObjectName("TopicDock");
485 TopicWidget *topicwidget = new TopicWidget(dock);
487 dock->setWidget(topicwidget);
489 topicwidget->setModel(Client::bufferModel());
490 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
492 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
494 _viewMenu->addAction(dock->toggleViewAction());
495 dock->toggleViewAction()->setText(tr("Show Topic Line"));
498 void MainWin::setupTitleSetter() {
499 _titleSetter.setModel(Client::bufferModel());
500 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
503 void MainWin::setupStatusBar() {
504 // MessageProcessor progress
505 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
508 updateLagIndicator();
509 statusBar()->addPermanentWidget(coreLagLabel);
510 coreLagLabel->hide();
511 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
514 sslLabel->setPixmap(QPixmap());
515 statusBar()->addPermanentWidget(sslLabel);
518 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
520 QtUiSettings uiSettings;
522 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
523 showStatusbar->setChecked(enabled);
524 enabled ? statusBar()->show() : statusBar()->hide();
526 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
527 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
530 void MainWin::saveStatusBarStatus(bool enabled) {
531 QtUiSettings uiSettings;
532 uiSettings.setValue("ShowStatusBar", enabled);
535 void MainWin::setupSystray() {
536 _systemTray = new SystemTray(this);
539 connect(systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayActivated(QSystemTrayIcon::ActivationReason)));
544 void MainWin::setupToolBars() {
545 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
546 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
547 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
548 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
551 setUnifiedTitleAndToolBarOnMac(true);
553 _mainToolBar = addToolBar("Main Toolbar");
554 _mainToolBar->setObjectName("MainToolBar");
556 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
557 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
559 //_nickToolBar = addToolBar("User");
560 //_nickToolBar->setObjectName("NickToolBar");
561 //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
564 _mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
565 //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
569 void MainWin::changeEvent(QEvent *event) {
570 if(event->type() == QEvent::WindowStateChange) {
571 if(windowState() & Qt::WindowMinimized) {
573 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
581 void MainWin::connectedToCore() {
582 Q_CHECK_PTR(Client::bufferViewManager());
583 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
584 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
585 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
590 void MainWin::setConnectedState() {
591 ActionCollection *coll = QtUi::actionCollection("General");
593 coll->action("ConnectCore")->setEnabled(false);
594 coll->action("DisconnectCore")->setEnabled(true);
595 coll->action("CoreInfo")->setEnabled(true);
597 foreach(QAction *action, _fileMenu->actions()) {
598 if(isRemoteCoreOnly(action))
599 action->setVisible(!Client::internalCore());
602 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
603 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
604 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
605 if(!Client::internalCore()) {
606 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
607 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
608 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
611 // _viewMenu->setEnabled(true);
612 if(!Client::internalCore())
613 statusBar()->showMessage(tr("Connected to core."));
615 statusBar()->clearMessage();
617 if(Client::signalProxy()->isSecure()) {
618 sslLabel->setPixmap(SmallIcon("security-high"));
620 sslLabel->setPixmap(SmallIcon("security-low"));
623 sslLabel->setVisible(!Client::internalCore());
624 coreLagLabel->setVisible(!Client::internalCore());
626 systemTray()->setState(SystemTray::Active);
628 if(Client::networkIds().isEmpty()) {
629 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
634 void MainWin::loadLayout() {
636 int accountId = Client::currentCoreAccount().toInt();
637 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
640 void MainWin::saveLayout() {
642 int accountId = Client::currentCoreAccount().toInt();
643 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
646 void MainWin::updateLagIndicator(int lag) {
647 QString text = tr("Core Lag: %1");
649 text = text.arg('-');
651 text = text.arg("%1 msec").arg(lag);
652 coreLagLabel->setText(text);
655 void MainWin::disconnectedFromCore() {
656 // save core specific layout and remove bufferviews;
659 BufferViewDock *dock;
660 foreach(QAction *action, _bufferViewsMenu->actions()) {
661 actionData = action->data();
662 if(!actionData.isValid())
665 dock = qobject_cast<BufferViewDock *>(action->parent());
666 if(dock && actionData.toInt() != -1) {
667 removeAction(action);
672 restoreState(s.value("MainWinState").toByteArray());
673 setDisconnectedState();
676 void MainWin::setDisconnectedState() {
677 ActionCollection *coll = QtUi::actionCollection("General");
678 //ui.menuCore->setEnabled(false);
679 coll->action("ConnectCore")->setEnabled(true);
680 coll->action("DisconnectCore")->setEnabled(false);
681 coll->action("CoreInfo")->setEnabled(false);
682 //_viewMenu->setEnabled(false);
683 statusBar()->showMessage(tr("Not connected to core."));
684 sslLabel->setPixmap(QPixmap());
686 updateLagIndicator();
687 coreLagLabel->hide();
688 if(msgProcessorStatusWidget)
689 msgProcessorStatusWidget->setProgress(0, 0);
691 systemTray()->setState(SystemTray::Inactive);
694 void MainWin::startInternalCore() {
695 ClientSyncer *syncer = new ClientSyncer();
696 Client::registerClientSyncer(syncer);
697 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
698 syncer->useInternalCore();
701 void MainWin::showCoreConnectionDlg(bool autoConnect) {
702 CoreConnectDlg(autoConnect, this).exec();
705 void MainWin::showChannelList(NetworkId netId) {
706 ChannelListDlg *channelListDlg = new ChannelListDlg();
708 if(!netId.isValid()) {
709 QAction *action = qobject_cast<QAction *>(sender());
711 netId = action->data().value<NetworkId>();
714 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
715 channelListDlg->setNetwork(netId);
716 channelListDlg->show();
719 void MainWin::showCoreInfoDlg() {
720 CoreInfoDlg(this).exec();
723 void MainWin::showAwayLog() {
726 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
727 _awayLog = new AwayLogView(filter, 0);
728 filter->setParent(_awayLog);
729 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
730 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
734 void MainWin::awayLogDestroyed() {
738 void MainWin::showSettingsDlg() {
739 SettingsDlg *dlg = new SettingsDlg();
741 //Category: Appearance
742 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
743 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
744 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
745 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
746 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
747 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
748 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
751 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
752 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
753 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
754 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
759 void MainWin::showAboutDlg() {
760 AboutDlg(this).exec();
764 void MainWin::showShortcutsDlg() {
765 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
769 void MainWin::closeEvent(QCloseEvent *event) {
771 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
773 if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
774 toggleMinimizedToTray();
778 QApplication::quit();
782 void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) {
783 if(activationReason == QSystemTrayIcon::Trigger) {
784 toggleMinimizedToTray();
788 void MainWin::hideToTray() {
789 if(!systemTray()->isSystemTrayAvailable()) {
790 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
795 systemTray()->setIconVisible();
798 void MainWin::toggleMinimizedToTray() {
799 if(windowState() & Qt::WindowMinimized) {
801 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
806 setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized);
811 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
814 if(QApplication::activeWindow() != 0)
817 for(int i = start; i <= end; i++) {
818 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
820 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
823 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
824 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self)) continue;
825 flags |= Message::Backlog; // we only want to trigger a highlight once!
826 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
828 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
829 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
831 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
832 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
833 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
834 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
835 QtUi::invokeNotification(bufId, sender, contents);
840 bool MainWin::event(QEvent *event) {
841 if(event->type() == QEvent::WindowActivate)
842 QtUi::closeNotifications();
843 return QMainWindow::event(event);
846 void MainWin::clientNetworkCreated(NetworkId id) {
847 const Network *net = Client::network(id);
848 QAction *act = new QAction(net->networkName(), this);
849 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
850 act->setData(QVariant::fromValue<NetworkId>(id));
851 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
852 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
854 QAction *beforeAction = 0;
855 foreach(QAction *action, _networksMenu->actions()) {
856 if(!action->data().isValid()) // ignore stock actions
858 if(net->networkName().localeAwareCompare(action->text()) < 0) {
859 beforeAction = action;
863 _networksMenu->insertAction(beforeAction, act);
866 void MainWin::clientNetworkUpdated() {
867 const Network *net = qobject_cast<const Network *>(sender());
871 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
875 action->setText(net->networkName());
877 switch(net->connectionState()) {
878 case Network::Initialized:
879 action->setIcon(SmallIcon("network-connect"));
881 case Network::Disconnected:
882 action->setIcon(SmallIcon("network-disconnect"));
885 action->setIcon(SmallIcon("network-wired"));
889 void MainWin::clientNetworkRemoved(NetworkId id) {
890 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
894 action->deleteLater();
897 void MainWin::connectOrDisconnectFromNet() {
898 QAction *act = qobject_cast<QAction *>(sender());
900 const Network *net = Client::network(act->data().value<NetworkId>());
902 if(net->connectionState() == Network::Disconnected) net->requestConnect();
903 else net->requestDisconnect();
906 void MainWin::on_actionDebugNetworkModel_triggered() {
907 QTreeView *view = new QTreeView;
908 view->setAttribute(Qt::WA_DeleteOnClose);
909 view->setWindowTitle("Debug NetworkModel View");
910 view->setModel(Client::networkModel());
911 view->setColumnWidth(0, 250);
912 view->setColumnWidth(1, 250);
913 view->setColumnWidth(2, 80);
914 view->resize(610, 300);
918 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
919 QTreeView *view = new QTreeView;
920 view->setAttribute(Qt::WA_DeleteOnClose);
921 view->setWindowTitle("Debug BufferViewOverlay View");
922 BufferViewOverlayFilter *filter = new BufferViewOverlayFilter(Client::bufferModel(), Client::bufferViewOverlay());
923 filter->setParent(view);
924 view->setModel(filter);
925 view->setColumnWidth(0, 250);
926 view->setColumnWidth(1, 250);
927 view->setColumnWidth(2, 80);
928 view->resize(610, 300);
932 void MainWin::on_actionDebugMessageModel_triggered() {
933 QTableView *view = new QTableView(0);
934 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
935 filter->setSourceModel(Client::messageModel());
936 view->setModel(filter);
937 view->setAttribute(Qt::WA_DeleteOnClose, true);
938 view->verticalHeader()->hide();
939 view->horizontalHeader()->setStretchLastSection(true);
943 void MainWin::on_actionDebugLog_triggered() {
944 DebugLogWidget *logWidget = new DebugLogWidget(0);
948 void MainWin::saveStateToSession(const QString &sessionId) {
950 SessionSettings s(sessionId);
952 s.setValue("MainWinSize", size());
953 s.setValue("MainWinPos", pos());
954 s.setValue("MainWinState", saveState());
957 void MainWin::saveStateToSessionSettings(SessionSettings & s)
959 s.setValue("MainWinSize", size());
960 s.setValue("MainWinPos", pos());
961 s.setValue("MainWinState", saveState());
964 void MainWin::showStatusBarMessage(const QString &message) {
965 statusBar()->showMessage(message, 10000);