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>
36 #include "awaylogfilter.h"
37 #include "awaylogview.h"
39 #include "actioncollection.h"
40 #include "buffermodel.h"
41 #include "bufferview.h"
42 #include "bufferwidget.h"
43 #include "channellistdlg.h"
44 #include "chatlinemodel.h"
45 #include "chatmonitorfilter.h"
46 #include "chatmonitorview.h"
49 #include "clientsyncer.h"
50 #include "clientbacklogmanager.h"
51 #include "clientbufferviewconfig.h"
52 #include "clientbufferviewmanager.h"
53 #include "coreinfodlg.h"
54 #include "coreconnectdlg.h"
55 #include "contextmenuactionprovider.h"
56 #include "debuglogwidget.h"
57 #include "debugmessagemodelfilter.h"
58 #include "iconloader.h"
59 #include "inputwidget.h"
60 #include "inputline.h"
61 #include "irclistmodel.h"
62 #include "ircconnectionwizard.h"
63 #include "jumpkeyhandler.h"
64 #include "msgprocessorstatuswidget.h"
65 #include "nicklistwidget.h"
66 #include "qtuiapplication.h"
67 #include "qtuimessageprocessor.h"
68 #include "qtuisettings.h"
69 #include "settingsdlg.h"
70 #include "settingspagedlg.h"
71 #include "systemtray.h"
72 #include "toolbaractionprovider.h"
73 #include "topicwidget.h"
74 #include "verticaldock.h"
78 # include "desktopnotificationbackend.h"
81 # include "phononnotificationbackend.h"
83 # include "systraynotificationbackend.h"
84 # include "taskbarnotificationbackend.h"
86 # include "knotificationbackend.h"
89 #include "settingspages/aliasessettingspage.h"
90 #include "settingspages/appearancesettingspage.h"
91 #include "settingspages/backlogsettingspage.h"
92 #include "settingspages/bufferviewsettingspage.h"
93 #include "settingspages/chatmonitorsettingspage.h"
94 #include "settingspages/colorsettingspage.h"
95 #include "settingspages/generalsettingspage.h"
96 #include "settingspages/highlightsettingspage.h"
97 #include "settingspages/identitiessettingspage.h"
98 #include "settingspages/networkssettingspage.h"
99 #include "settingspages/notificationssettingspage.h"
101 MainWin::MainWin(QWidget *parent)
103 : KMainWindow(parent),
104 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
106 : QMainWindow(parent),
108 coreLagLabel(new QLabel()),
109 sslLabel(new QLabel()),
110 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
118 QtUiSettings uiSettings;
119 QString style = uiSettings.value("Style", QString()).toString();
120 if(!style.isEmpty()) {
121 QApplication::setStyle(style);
124 QApplication::setQuitOnLastWindowClosed(false);
126 setWindowTitle("Quassel IRC");
127 setWindowIconText("Quassel IRC");
130 installEventFilter(new JumpKeyHandler(this));
132 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
133 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
134 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
137 void MainWin::init() {
139 if(s.value("MainWinSize").isValid())
140 resize(s.value("MainWinSize").toSize());
142 resize(QSize(800, 500));
144 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
145 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
146 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
147 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
148 SLOT(messagesInserted(const QModelIndex &, int, int)));
149 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
152 setDockNestingEnabled(true);
153 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
154 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
155 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
156 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
158 // Order is sometimes important
172 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
173 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
175 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
178 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
182 QtUi::registerNotificationBackend(new KNotificationBackend(this));
183 #endif /* HAVE_KDE */
185 // restore mainwin state
186 restoreState(s.value("MainWinState").toByteArray());
188 // restore locked state of docks
189 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
191 setDisconnectedState(); // Disable menus and stuff
195 if(Quassel::runMode() != Quassel::Monolithic) {
196 showCoreConnectionDlg(true); // autoconnect if appropriate
202 MainWin::~MainWin() {
204 s.setValue("MainWinSize", size());
205 s.setValue("MainWinPos", pos());
206 s.setValue("MainWinState", saveState());
209 void MainWin::updateIcon() {
211 const int size = 128;
217 if(Client::isConnected())
218 icon = DesktopIcon("quassel", size);
220 icon = DesktopIcon("quassel_inactive", size);
222 qApp->setWindowIcon(icon);
225 void MainWin::setupActions() {
226 ActionCollection *coll = QtUi::actionCollection("General");
228 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
229 this, SLOT(showCoreConnectionDlg())));
230 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
231 Client::instance(), SLOT(disconnectFromCore())));
232 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
233 this, SLOT(showCoreInfoDlg())));
234 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
235 this, SLOT(on_actionConfigureNetworks_triggered())));
236 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
237 qApp, SLOT(quit()), tr("Ctrl+Q")));
240 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
241 this, SLOT(on_actionConfigureViews_triggered())));
243 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
244 lockAct->setCheckable(true);
245 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
247 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
248 0, 0, tr("Ctrl+F")))->setCheckable(true);
249 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
250 this, SLOT(showAwayLog())));
251 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
252 0, 0))->setCheckable(true);
255 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
256 this, SLOT(showSettingsDlg()), tr("F7")));
259 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
260 this, SLOT(showAboutDlg())));
261 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
262 qApp, SLOT(aboutQt())));
263 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
264 this, SLOT(on_actionDebugNetworkModel_triggered())));
265 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
266 this, SLOT(on_actionDebugMessageModel_triggered())));
267 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
268 this, SLOT(on_actionDebugLog_triggered())));
271 void MainWin::setupMenus() {
272 ActionCollection *coll = QtUi::actionCollection("General");
274 _fileMenu = menuBar()->addMenu(tr("&File"));
276 static const QStringList coreActions = QStringList()
277 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
280 foreach(QString actionName, coreActions) {
281 coreAction = coll->action(actionName);
282 _fileMenu->addAction(coreAction);
283 flagRemoteCoreOnly(coreAction);
285 flagRemoteCoreOnly(_fileMenu->addSeparator());
287 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
288 _networksMenu->addAction(coll->action("ConfigureNetworks"));
289 _networksMenu->addSeparator();
290 _fileMenu->addSeparator();
291 _fileMenu->addAction(coll->action("Quit"));
293 _viewMenu = menuBar()->addMenu(tr("&View"));
294 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
295 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
296 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
297 _viewMenu->addSeparator();
298 _viewMenu->addAction(coll->action("ToggleSearchBar"));
300 coreAction = coll->action("ShowAwayLog");
301 flagRemoteCoreOnly(coreAction);
302 _viewMenu->addAction(coreAction);
304 _viewMenu->addAction(coll->action("ToggleStatusBar"));
305 _viewMenu->addSeparator();
306 _viewMenu->addAction(coll->action("LockLayout"));
308 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
310 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
311 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
313 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
315 _helpMenu = menuBar()->addMenu(tr("&Help"));
316 _helpMenu->addAction(coll->action("AboutQuassel"));
318 _helpMenu->addAction(coll->action("AboutQt"));
320 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
322 _helpMenu->addSeparator();
323 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
324 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
325 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
326 _helpDebugMenu->addAction(coll->action("DebugLog"));
329 void MainWin::setupBufferWidget() {
330 _bufferWidget = new BufferWidget(this);
331 _bufferWidget->setModel(Client::bufferModel());
332 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
333 setCentralWidget(_bufferWidget);
336 void MainWin::addBufferView(int bufferViewConfigId) {
337 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
340 void MainWin::addBufferView(ClientBufferViewConfig *config) {
344 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
345 BufferViewDock *dock = new BufferViewDock(config, this);
347 //create the view and initialize it's filter
348 BufferView *view = new BufferView(dock);
349 view->setFilteredModel(Client::bufferModel(), config);
350 view->installEventFilter(_inputWidget->inputLine()); // for key presses
353 Client::bufferModel()->synchronizeView(view);
355 dock->setWidget(view);
358 addDockWidget(Qt::LeftDockWidgetArea, dock);
359 _bufferViewsMenu->addAction(dock->toggleViewAction());
361 _bufferViews.append(dock);
364 void MainWin::removeBufferView(int bufferViewConfigId) {
366 BufferViewDock *dock;
367 foreach(QAction *action, _bufferViewsMenu->actions()) {
368 actionData = action->data();
369 if(!actionData.isValid())
372 dock = qobject_cast<BufferViewDock *>(action->parent());
373 if(dock && actionData.toInt() == bufferViewConfigId) {
374 removeAction(action);
380 BufferView *MainWin::allBuffersView() const {
381 // "All Buffers" is always the first dock created
382 if(_bufferViews.count() > 0)
383 return _bufferViews[0]->bufferView();
387 void MainWin::showNotificationsDlg() {
388 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
392 void MainWin::on_actionConfigureNetworks_triggered() {
393 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
397 void MainWin::on_actionConfigureViews_triggered() {
398 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
402 void MainWin::on_actionLockLayout_toggled(bool lock) {
403 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
404 foreach(VerticalDock *dock, docks) {
405 dock->showTitle(!lock);
407 if(Client::bufferViewManager()) {
408 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
409 config->setLocked(lock);
412 QtUiSettings().setValue("LockLayout", lock);
415 void MainWin::setupNickWidget() {
417 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
418 nickDock->setObjectName("NickDock");
419 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
421 _nickListWidget = new NickListWidget(nickDock);
422 nickDock->setWidget(_nickListWidget);
424 addDockWidget(Qt::RightDockWidgetArea, nickDock);
425 _viewMenu->addAction(nickDock->toggleViewAction());
426 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
428 // See NickListDock::NickListDock();
429 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
431 // attach the NickListWidget to the BufferModel and the default selection
432 _nickListWidget->setModel(Client::bufferModel());
433 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
436 void MainWin::setupChatMonitor() {
437 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
438 dock->setObjectName("ChatMonitorDock");
440 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
441 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
443 dock->setWidget(chatView);
446 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
447 _viewMenu->addAction(dock->toggleViewAction());
448 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
451 void MainWin::setupInputWidget() {
452 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
453 dock->setObjectName("InputDock");
455 _inputWidget = new InputWidget(dock);
456 dock->setWidget(_inputWidget);
458 addDockWidget(Qt::BottomDockWidgetArea, dock);
460 _viewMenu->addAction(dock->toggleViewAction());
461 dock->toggleViewAction()->setText(tr("Show Input Line"));
463 _inputWidget->setModel(Client::bufferModel());
464 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
466 _bufferWidget->setFocusProxy(_inputWidget);
468 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
471 void MainWin::setupTopicWidget() {
472 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
473 dock->setObjectName("TopicDock");
474 TopicWidget *topicwidget = new TopicWidget(dock);
476 dock->setWidget(topicwidget);
478 topicwidget->setModel(Client::bufferModel());
479 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
481 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
483 _viewMenu->addAction(dock->toggleViewAction());
484 dock->toggleViewAction()->setText(tr("Show Topic Line"));
487 void MainWin::setupTitleSetter() {
488 _titleSetter.setModel(Client::bufferModel());
489 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
492 void MainWin::setupStatusBar() {
493 // MessageProcessor progress
494 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
497 updateLagIndicator();
498 statusBar()->addPermanentWidget(coreLagLabel);
499 coreLagLabel->hide();
500 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
503 sslLabel->setPixmap(QPixmap());
504 statusBar()->addPermanentWidget(sslLabel);
507 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
509 QtUiSettings uiSettings;
511 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
512 showStatusbar->setChecked(enabled);
513 enabled ? statusBar()->show() : statusBar()->hide();
515 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
516 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
519 void MainWin::saveStatusBarStatus(bool enabled) {
520 QtUiSettings uiSettings;
521 uiSettings.setValue("ShowStatusBar", enabled);
524 void MainWin::setupSystray() {
525 _systemTray = new SystemTray(this);
528 void MainWin::setupToolBars() {
529 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
530 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
531 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
532 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
535 setUnifiedTitleAndToolBarOnMac(true);
537 _mainToolBar = addToolBar("Main Toolbar");
538 _mainToolBar->setObjectName("MainToolBar");
540 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
541 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
543 //_nickToolBar = addToolBar("User");
544 //_nickToolBar->setObjectName("NickToolBar");
545 //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
548 _mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
549 //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
553 void MainWin::connectedToCore() {
554 Q_CHECK_PTR(Client::bufferViewManager());
555 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
556 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
557 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
562 void MainWin::setConnectedState() {
563 ActionCollection *coll = QtUi::actionCollection("General");
565 coll->action("ConnectCore")->setEnabled(false);
566 coll->action("DisconnectCore")->setEnabled(true);
567 coll->action("CoreInfo")->setEnabled(true);
569 foreach(QAction *action, _fileMenu->actions()) {
570 if(isRemoteCoreOnly(action))
571 action->setVisible(!Client::internalCore());
574 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
575 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
576 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
577 if(!Client::internalCore()) {
578 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
579 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
580 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
583 // _viewMenu->setEnabled(true);
584 if(!Client::internalCore())
585 statusBar()->showMessage(tr("Connected to core."));
587 statusBar()->clearMessage();
589 if(Client::signalProxy()->isSecure()) {
590 sslLabel->setPixmap(SmallIcon("security-high"));
592 sslLabel->setPixmap(SmallIcon("security-low"));
595 sslLabel->setVisible(!Client::internalCore());
596 coreLagLabel->setVisible(!Client::internalCore());
598 systemTray()->setState(SystemTray::Active);
600 if(Client::networkIds().isEmpty()) {
601 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
606 void MainWin::loadLayout() {
608 int accountId = Client::currentCoreAccount().toInt();
609 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
612 void MainWin::saveLayout() {
614 int accountId = Client::currentCoreAccount().toInt();
615 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
618 void MainWin::updateLagIndicator(int lag) {
619 QString text = tr("Core Lag: %1");
621 text = text.arg('-');
623 text = text.arg("%1 msec").arg(lag);
624 coreLagLabel->setText(text);
627 void MainWin::disconnectedFromCore() {
628 // save core specific layout and remove bufferviews;
631 BufferViewDock *dock;
632 foreach(QAction *action, _bufferViewsMenu->actions()) {
633 actionData = action->data();
634 if(!actionData.isValid())
637 dock = qobject_cast<BufferViewDock *>(action->parent());
638 if(dock && actionData.toInt() != -1) {
639 removeAction(action);
644 restoreState(s.value("MainWinState").toByteArray());
645 setDisconnectedState();
648 void MainWin::setDisconnectedState() {
649 ActionCollection *coll = QtUi::actionCollection("General");
650 //ui.menuCore->setEnabled(false);
651 coll->action("ConnectCore")->setEnabled(true);
652 coll->action("DisconnectCore")->setEnabled(false);
653 coll->action("CoreInfo")->setEnabled(false);
654 //_viewMenu->setEnabled(false);
655 statusBar()->showMessage(tr("Not connected to core."));
656 sslLabel->setPixmap(QPixmap());
658 updateLagIndicator();
659 coreLagLabel->hide();
660 if(msgProcessorStatusWidget)
661 msgProcessorStatusWidget->setProgress(0, 0);
663 systemTray()->setState(SystemTray::Inactive);
666 void MainWin::startInternalCore() {
667 ClientSyncer *syncer = new ClientSyncer();
668 Client::registerClientSyncer(syncer);
669 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
670 syncer->useInternalCore();
673 void MainWin::showCoreConnectionDlg(bool autoConnect) {
674 CoreConnectDlg(autoConnect, this).exec();
677 void MainWin::showChannelList(NetworkId netId) {
678 ChannelListDlg *channelListDlg = new ChannelListDlg();
680 if(!netId.isValid()) {
681 QAction *action = qobject_cast<QAction *>(sender());
683 netId = action->data().value<NetworkId>();
686 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
687 channelListDlg->setNetwork(netId);
688 channelListDlg->show();
691 void MainWin::showCoreInfoDlg() {
692 CoreInfoDlg(this).exec();
695 void MainWin::showAwayLog() {
698 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
699 _awayLog = new AwayLogView(filter, 0);
700 filter->setParent(_awayLog);
701 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
702 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
706 void MainWin::awayLogDestroyed() {
710 void MainWin::showSettingsDlg() {
711 SettingsDlg *dlg = new SettingsDlg();
713 //Category: Appearance
714 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
715 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
716 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
717 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
718 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
719 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
720 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
723 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
724 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
725 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
726 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
731 void MainWin::showAboutDlg() {
732 AboutDlg(this).exec();
736 void MainWin::showShortcutsDlg() {
737 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
741 void MainWin::closeEvent(QCloseEvent *event) {
743 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
745 if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
746 toggleMinimizedToTray();
750 QApplication::quit();
754 bool MainWin::event(QEvent *event) {
755 if(event->type() == QEvent::WindowActivate)
756 QtUi::closeNotifications();
757 return QMainWindow::event(event);
760 void MainWin::changeEvent(QEvent *event) {
761 if(event->type() == QEvent::WindowStateChange) {
762 if(windowState() & Qt::WindowMinimized) {
764 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
773 else if(event->type() == QEvent::ActivationChange)
774 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
780 void MainWin::hideToTray() {
781 if(!systemTray()->isSystemTrayAvailable()) {
782 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
786 systemTray()->setIconVisible();
789 void MainWin::toggleMinimizedToTray() {
791 // the problem is that we lose focus when the systray icon is activated
792 // and we don't know the former active window
793 // therefore we watch for activation event and use our stopwatch :)
794 // courtesy: KSystemTrayIcon
795 if(GetTickCount() - dwTickCount >= 300)
796 // we weren't active in the last 300ms -> activate
803 if(!isVisible() || isMinimized())
812 void MainWin::forceActivated() {
814 // Bypass focus stealing prevention
815 QX11Info::setAppUserTime(QX11Info::appTime());
818 if(windowState() & Qt::WindowMinimized) {
820 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
823 move(frameGeometry().topLeft()); // avoid placement policies
829 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
832 if(QApplication::activeWindow() != 0)
835 for(int i = start; i <= end; i++) {
836 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
838 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
841 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
842 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self)) continue;
843 flags |= Message::Backlog; // we only want to trigger a highlight once!
844 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
846 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
847 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
849 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
850 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
851 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
852 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
853 QtUi::invokeNotification(bufId, sender, contents);
858 void MainWin::clientNetworkCreated(NetworkId id) {
859 const Network *net = Client::network(id);
860 QAction *act = new QAction(net->networkName(), this);
861 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
862 act->setData(QVariant::fromValue<NetworkId>(id));
863 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
864 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
866 QAction *beforeAction = 0;
867 foreach(QAction *action, _networksMenu->actions()) {
868 if(!action->data().isValid()) // ignore stock actions
870 if(net->networkName().localeAwareCompare(action->text()) < 0) {
871 beforeAction = action;
875 _networksMenu->insertAction(beforeAction, act);
878 void MainWin::clientNetworkUpdated() {
879 const Network *net = qobject_cast<const Network *>(sender());
883 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
887 action->setText(net->networkName());
889 switch(net->connectionState()) {
890 case Network::Initialized:
891 action->setIcon(SmallIcon("network-connect"));
893 case Network::Disconnected:
894 action->setIcon(SmallIcon("network-disconnect"));
897 action->setIcon(SmallIcon("network-wired"));
901 void MainWin::clientNetworkRemoved(NetworkId id) {
902 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
906 action->deleteLater();
909 void MainWin::connectOrDisconnectFromNet() {
910 QAction *act = qobject_cast<QAction *>(sender());
912 const Network *net = Client::network(act->data().value<NetworkId>());
914 if(net->connectionState() == Network::Disconnected) net->requestConnect();
915 else net->requestDisconnect();
918 void MainWin::on_actionDebugNetworkModel_triggered() {
919 QTreeView *view = new QTreeView;
920 view->setAttribute(Qt::WA_DeleteOnClose);
921 view->setWindowTitle("Debug NetworkModel View");
922 view->setModel(Client::networkModel());
923 view->setColumnWidth(0, 250);
924 view->setColumnWidth(1, 250);
925 view->setColumnWidth(2, 80);
926 view->resize(610, 300);
930 void MainWin::on_actionDebugMessageModel_triggered() {
931 QTableView *view = new QTableView(0);
932 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
933 filter->setSourceModel(Client::messageModel());
934 view->setModel(filter);
935 view->setAttribute(Qt::WA_DeleteOnClose, true);
936 view->verticalHeader()->hide();
937 view->horizontalHeader()->setStretchLastSection(true);
941 void MainWin::on_actionDebugLog_triggered() {
942 DebugLogWidget *logWidget = new DebugLogWidget(0);
946 void MainWin::saveStateToSession(const QString &sessionId) {
948 SessionSettings s(sessionId);
950 s.setValue("MainWinSize", size());
951 s.setValue("MainWinPos", pos());
952 s.setValue("MainWinState", saveState());
955 void MainWin::saveStateToSessionSettings(SessionSettings & s)
957 s.setValue("MainWinSize", size());
958 s.setValue("MainWinPos", pos());
959 s.setValue("MainWinState", saveState());
962 void MainWin::showStatusBarMessage(const QString &message) {
963 statusBar()->showMessage(message, 10000);