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>
37 #include "awaylogfilter.h"
38 #include "awaylogview.h"
40 #include "actioncollection.h"
41 #include "bufferhotlistfilter.h"
42 #include "buffermodel.h"
43 #include "bufferview.h"
44 #include "bufferviewoverlay.h"
45 #include "bufferviewoverlayfilter.h"
46 #include "bufferwidget.h"
47 #include "channellistdlg.h"
48 #include "chatlinemodel.h"
49 #include "chatmonitorfilter.h"
50 #include "chatmonitorview.h"
53 #include "clientsyncer.h"
54 #include "clientbacklogmanager.h"
55 #include "clientbufferviewconfig.h"
56 #include "clientbufferviewmanager.h"
57 #include "coreinfodlg.h"
58 #include "coreconnectdlg.h"
59 #include "contextmenuactionprovider.h"
60 #include "debugbufferviewoverlay.h"
61 #include "debuglogwidget.h"
62 #include "debugmessagemodelfilter.h"
63 #include "flatproxymodel.h"
64 #include "iconloader.h"
65 #include "inputwidget.h"
66 #include "inputline.h"
67 #include "irclistmodel.h"
68 #include "ircconnectionwizard.h"
69 #include "jumpkeyhandler.h"
70 #include "msgprocessorstatuswidget.h"
71 #include "nicklistwidget.h"
72 #include "qtuiapplication.h"
73 #include "qtuimessageprocessor.h"
74 #include "qtuisettings.h"
75 #include "settingsdlg.h"
76 #include "settingspagedlg.h"
77 #include "systemtray.h"
78 #include "toolbaractionprovider.h"
79 #include "topicwidget.h"
80 #include "verticaldock.h"
84 # include "desktopnotificationbackend.h"
87 # include "phononnotificationbackend.h"
89 # include "systraynotificationbackend.h"
90 # include "taskbarnotificationbackend.h"
92 # include "knotificationbackend.h"
95 #include "settingspages/aliasessettingspage.h"
96 #include "settingspages/appearancesettingspage.h"
97 #include "settingspages/backlogsettingspage.h"
98 #include "settingspages/bufferviewsettingspage.h"
99 #include "settingspages/chatmonitorsettingspage.h"
100 #include "settingspages/colorsettingspage.h"
101 #include "settingspages/generalsettingspage.h"
102 #include "settingspages/highlightsettingspage.h"
103 #include "settingspages/identitiessettingspage.h"
104 #include "settingspages/networkssettingspage.h"
105 #include "settingspages/notificationssettingspage.h"
107 MainWin::MainWin(QWidget *parent)
109 : KMainWindow(parent),
110 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
112 : QMainWindow(parent),
114 coreLagLabel(new QLabel()),
115 sslLabel(new QLabel()),
116 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
124 QtUiSettings uiSettings;
125 QString style = uiSettings.value("Style", QString()).toString();
126 if(!style.isEmpty()) {
127 QApplication::setStyle(style);
130 QApplication::setQuitOnLastWindowClosed(false);
132 setWindowTitle("Quassel IRC");
133 setWindowIconText("Quassel IRC");
136 installEventFilter(new JumpKeyHandler(this));
139 void MainWin::init() {
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
168 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
169 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
171 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
174 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
178 QtUi::registerNotificationBackend(new KNotificationBackend(this));
179 #endif /* HAVE_KDE */
181 setDisconnectedState(); // Disable menus and stuff
184 setAutoSaveSettings();
187 // restore mainwin state
189 restoreStateFromSettings(s);
191 // restore locked state of docks
192 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
194 if(Quassel::runMode() != Quassel::Monolithic) {
195 showCoreConnectionDlg(true); // autoconnect if appropriate
201 MainWin::~MainWin() {
205 void MainWin::quit() {
207 saveStateToSettings(s);
209 QApplication::quit();
212 void MainWin::saveStateToSettings(UiSettings &s) {
213 s.setValue("MainWinSize", _normalSize);
214 s.setValue("MainWinPos", _normalPos);
215 s.setValue("MainWinState", saveState());
216 s.setValue("MainWinGeometry", saveGeometry());
217 s.setValue("MainWinMinimized", isMinimized());
218 s.setValue("MainWinMaximized", isMaximized());
219 s.setValue("MainWinHidden", !isVisible());
222 saveAutoSaveSettings();
226 void MainWin::restoreStateFromSettings(UiSettings &s) {
227 _normalSize = s.value("MainWinSize", size()).toSize();
228 _normalPos = s.value("MainWinPos", pos()).toPoint();
229 bool maximized = s.value("MainWinMaximized", false).toBool();
232 restoreGeometry(s.value("MainWinGeometry").toByteArray());
235 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
240 restoreState(s.value("MainWinState").toByteArray());
246 if(s.value("MainWinHidden").toBool())
248 else if(s.value("MainWinMinimized").toBool())
256 void MainWin::updateIcon() {
258 const int size = 128;
264 if(Client::isConnected())
265 icon = DesktopIcon("quassel", size);
267 icon = DesktopIcon("quassel_inactive", size);
269 qApp->setWindowIcon(icon);
272 void MainWin::setupActions() {
273 ActionCollection *coll = QtUi::actionCollection("General");
275 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
276 this, SLOT(showCoreConnectionDlg())));
277 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
278 Client::instance(), SLOT(disconnectFromCore())));
279 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
280 this, SLOT(showCoreInfoDlg())));
281 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
282 this, SLOT(on_actionConfigureNetworks_triggered())));
283 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
284 this, SLOT(quit()), tr("Ctrl+Q")));
287 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
288 this, SLOT(on_actionConfigureViews_triggered())));
290 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
291 lockAct->setCheckable(true);
292 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
294 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
295 0, 0, QKeySequence::Find))->setCheckable(true);
296 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
297 this, SLOT(showAwayLog())));
298 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
299 0, 0))->setCheckable(true);
302 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
303 this, SLOT(showSettingsDlg()), tr("F7")));
306 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
307 this, SLOT(showAboutDlg())));
308 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
309 qApp, SLOT(aboutQt())));
310 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
311 this, SLOT(on_actionDebugNetworkModel_triggered())));
312 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
313 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
314 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
315 this, SLOT(on_actionDebugMessageModel_triggered())));
316 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
317 this, SLOT(on_actionDebugHotList_triggered())));
318 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
319 this, SLOT(on_actionDebugLog_triggered())));
322 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot buffer"), coll,
323 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
326 void MainWin::setupMenus() {
327 ActionCollection *coll = QtUi::actionCollection("General");
329 _fileMenu = menuBar()->addMenu(tr("&File"));
331 static const QStringList coreActions = QStringList()
332 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
335 foreach(QString actionName, coreActions) {
336 coreAction = coll->action(actionName);
337 _fileMenu->addAction(coreAction);
338 flagRemoteCoreOnly(coreAction);
340 flagRemoteCoreOnly(_fileMenu->addSeparator());
342 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
343 _networksMenu->addAction(coll->action("ConfigureNetworks"));
344 _networksMenu->addSeparator();
345 _fileMenu->addSeparator();
346 _fileMenu->addAction(coll->action("Quit"));
348 _viewMenu = menuBar()->addMenu(tr("&View"));
349 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
350 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
351 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
352 _viewMenu->addSeparator();
353 _viewMenu->addAction(coll->action("ToggleSearchBar"));
355 coreAction = coll->action("ShowAwayLog");
356 flagRemoteCoreOnly(coreAction);
357 _viewMenu->addAction(coreAction);
359 _viewMenu->addAction(coll->action("ToggleStatusBar"));
360 _viewMenu->addSeparator();
361 _viewMenu->addAction(coll->action("LockLayout"));
363 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
365 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
366 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
368 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
370 _helpMenu = menuBar()->addMenu(tr("&Help"));
371 _helpMenu->addAction(coll->action("AboutQuassel"));
373 _helpMenu->addAction(coll->action("AboutQt"));
375 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
377 _helpMenu->addSeparator();
378 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
379 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
380 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
381 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
382 _helpDebugMenu->addAction(coll->action("DebugHotList"));
383 _helpDebugMenu->addAction(coll->action("DebugLog"));
386 void MainWin::setupBufferWidget() {
387 _bufferWidget = new BufferWidget(this);
388 _bufferWidget->setModel(Client::bufferModel());
389 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
390 setCentralWidget(_bufferWidget);
393 void MainWin::addBufferView(int bufferViewConfigId) {
394 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
397 void MainWin::addBufferView(ClientBufferViewConfig *config) {
401 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
402 BufferViewDock *dock = new BufferViewDock(config, this);
404 //create the view and initialize it's filter
405 BufferView *view = new BufferView(dock);
406 view->setFilteredModel(Client::bufferModel(), config);
407 view->installEventFilter(_inputWidget->inputLine()); // for key presses
410 Client::bufferModel()->synchronizeView(view);
412 dock->setWidget(view);
415 addDockWidget(Qt::LeftDockWidgetArea, dock);
416 _bufferViewsMenu->addAction(dock->toggleViewAction());
418 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
419 _bufferViews.append(dock);
422 void MainWin::removeBufferView(int bufferViewConfigId) {
424 BufferViewDock *dock;
425 foreach(QAction *action, _bufferViewsMenu->actions()) {
426 actionData = action->data();
427 if(!actionData.isValid())
430 dock = qobject_cast<BufferViewDock *>(action->parent());
431 if(dock && actionData.toInt() == bufferViewConfigId) {
432 removeAction(action);
438 void MainWin::bufferViewToggled(bool enabled) {
439 QAction *action = qobject_cast<QAction *>(sender());
441 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
444 Client::bufferViewOverlay()->addView(dock->bufferViewId());
445 BufferViewConfig *config = dock->config();
446 if(config && config->isInitialized()) {
447 BufferIdList buffers;
448 if(config->networkId().isValid()) {
449 foreach(BufferId bufferId, config->bufferList()) {
450 if(Client::networkModel()->networkId(bufferId) == config->networkId())
453 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
454 if(Client::networkModel()->networkId(bufferId) == config->networkId())
458 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
460 Client::backlogManager()->checkForBacklog(buffers);
463 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
467 BufferView *MainWin::allBuffersView() const {
468 // "All Buffers" is always the first dock created
469 if(_bufferViews.count() > 0)
470 return _bufferViews[0]->bufferView();
474 void MainWin::showNotificationsDlg() {
475 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
479 void MainWin::on_actionConfigureNetworks_triggered() {
480 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
484 void MainWin::on_actionConfigureViews_triggered() {
485 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
489 void MainWin::on_actionLockLayout_toggled(bool lock) {
490 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
491 foreach(VerticalDock *dock, docks) {
492 dock->showTitle(!lock);
494 if(Client::bufferViewManager()) {
495 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
496 config->setLocked(lock);
499 QtUiSettings().setValue("LockLayout", lock);
502 void MainWin::setupNickWidget() {
504 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
505 nickDock->setObjectName("NickDock");
506 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
508 _nickListWidget = new NickListWidget(nickDock);
509 nickDock->setWidget(_nickListWidget);
511 addDockWidget(Qt::RightDockWidgetArea, nickDock);
512 _viewMenu->addAction(nickDock->toggleViewAction());
513 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
515 // See NickListDock::NickListDock();
516 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
518 // attach the NickListWidget to the BufferModel and the default selection
519 _nickListWidget->setModel(Client::bufferModel());
520 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
523 void MainWin::setupChatMonitor() {
524 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
525 dock->setObjectName("ChatMonitorDock");
527 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
528 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
530 dock->setWidget(chatView);
533 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
534 _viewMenu->addAction(dock->toggleViewAction());
535 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
538 void MainWin::setupInputWidget() {
539 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
540 dock->setObjectName("InputDock");
542 _inputWidget = new InputWidget(dock);
543 dock->setWidget(_inputWidget);
545 addDockWidget(Qt::BottomDockWidgetArea, dock);
547 _viewMenu->addAction(dock->toggleViewAction());
548 dock->toggleViewAction()->setText(tr("Show Input Line"));
550 _inputWidget->setModel(Client::bufferModel());
551 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
553 _bufferWidget->setFocusProxy(_inputWidget);
555 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
558 void MainWin::setupTopicWidget() {
559 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
560 dock->setObjectName("TopicDock");
561 TopicWidget *topicwidget = new TopicWidget(dock);
563 dock->setWidget(topicwidget);
565 topicwidget->setModel(Client::bufferModel());
566 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
568 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
570 _viewMenu->addAction(dock->toggleViewAction());
571 dock->toggleViewAction()->setText(tr("Show Topic Line"));
574 void MainWin::setupTitleSetter() {
575 _titleSetter.setModel(Client::bufferModel());
576 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
579 void MainWin::setupStatusBar() {
580 // MessageProcessor progress
581 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
584 updateLagIndicator();
585 statusBar()->addPermanentWidget(coreLagLabel);
586 coreLagLabel->hide();
587 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
590 sslLabel->setPixmap(QPixmap());
591 statusBar()->addPermanentWidget(sslLabel);
594 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
596 QtUiSettings uiSettings;
598 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
599 showStatusbar->setChecked(enabled);
600 enabled ? statusBar()->show() : statusBar()->hide();
602 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
603 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
606 void MainWin::setupHotList() {
607 FlatProxyModel *flatProxy = new FlatProxyModel(this);
608 flatProxy->setSourceModel(Client::bufferModel());
609 _bufferHotList = new BufferHotListFilter(flatProxy);
612 void MainWin::saveStatusBarStatus(bool enabled) {
613 QtUiSettings uiSettings;
614 uiSettings.setValue("ShowStatusBar", enabled);
617 void MainWin::setupSystray() {
618 _systemTray = new SystemTray(this);
621 void MainWin::setupToolBars() {
622 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
623 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
624 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
625 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
628 setUnifiedTitleAndToolBarOnMac(true);
632 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
634 _mainToolBar = new QToolBar(this);
635 _mainToolBar->setObjectName("MainToolBar");
637 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
638 addToolBar(_mainToolBar);
640 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
641 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
644 void MainWin::connectedToCore() {
645 Q_CHECK_PTR(Client::bufferViewManager());
646 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
647 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
648 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
653 void MainWin::setConnectedState() {
654 ActionCollection *coll = QtUi::actionCollection("General");
656 coll->action("ConnectCore")->setEnabled(false);
657 coll->action("DisconnectCore")->setEnabled(true);
658 coll->action("CoreInfo")->setEnabled(true);
660 foreach(QAction *action, _fileMenu->actions()) {
661 if(isRemoteCoreOnly(action))
662 action->setVisible(!Client::internalCore());
665 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
666 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
667 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
668 if(!Client::internalCore()) {
669 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
670 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
671 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
674 // _viewMenu->setEnabled(true);
675 if(!Client::internalCore())
676 statusBar()->showMessage(tr("Connected to core."));
678 statusBar()->clearMessage();
680 if(Client::signalProxy()->isSecure()) {
681 sslLabel->setPixmap(SmallIcon("security-high"));
683 sslLabel->setPixmap(SmallIcon("security-low"));
686 sslLabel->setVisible(!Client::internalCore());
687 coreLagLabel->setVisible(!Client::internalCore());
689 systemTray()->setState(SystemTray::Active);
691 if(Client::networkIds().isEmpty()) {
692 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
697 void MainWin::loadLayout() {
699 int accountId = Client::currentCoreAccount().toInt();
700 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
703 void MainWin::saveLayout() {
705 int accountId = Client::currentCoreAccount().toInt();
706 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
709 void MainWin::updateLagIndicator(int lag) {
710 QString text = tr("Core Lag: %1");
712 text = text.arg('-');
714 text = text.arg("%1 msec").arg(lag);
715 coreLagLabel->setText(text);
718 void MainWin::disconnectedFromCore() {
719 // save core specific layout and remove bufferviews;
722 BufferViewDock *dock;
723 foreach(QAction *action, _bufferViewsMenu->actions()) {
724 actionData = action->data();
725 if(!actionData.isValid())
728 dock = qobject_cast<BufferViewDock *>(action->parent());
729 if(dock && actionData.toInt() != -1) {
730 removeAction(action);
735 restoreState(s.value("MainWinState").toByteArray());
736 setDisconnectedState();
739 void MainWin::setDisconnectedState() {
740 ActionCollection *coll = QtUi::actionCollection("General");
741 //ui.menuCore->setEnabled(false);
742 coll->action("ConnectCore")->setEnabled(true);
743 coll->action("DisconnectCore")->setEnabled(false);
744 coll->action("CoreInfo")->setEnabled(false);
745 //_viewMenu->setEnabled(false);
746 statusBar()->showMessage(tr("Not connected to core."));
747 sslLabel->setPixmap(QPixmap());
749 updateLagIndicator();
750 coreLagLabel->hide();
751 if(msgProcessorStatusWidget)
752 msgProcessorStatusWidget->setProgress(0, 0);
754 systemTray()->setState(SystemTray::Inactive);
757 void MainWin::startInternalCore() {
758 ClientSyncer *syncer = new ClientSyncer();
759 Client::registerClientSyncer(syncer);
760 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
761 syncer->useInternalCore();
764 void MainWin::showCoreConnectionDlg(bool autoConnect) {
765 CoreConnectDlg(autoConnect, this).exec();
768 void MainWin::showChannelList(NetworkId netId) {
769 ChannelListDlg *channelListDlg = new ChannelListDlg();
771 if(!netId.isValid()) {
772 QAction *action = qobject_cast<QAction *>(sender());
774 netId = action->data().value<NetworkId>();
777 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
778 channelListDlg->setNetwork(netId);
779 channelListDlg->show();
782 void MainWin::showCoreInfoDlg() {
783 CoreInfoDlg(this).exec();
786 void MainWin::showAwayLog() {
789 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
790 _awayLog = new AwayLogView(filter, 0);
791 filter->setParent(_awayLog);
792 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
793 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
797 void MainWin::awayLogDestroyed() {
801 void MainWin::showSettingsDlg() {
802 SettingsDlg *dlg = new SettingsDlg();
804 //Category: Appearance
805 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
806 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
807 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
808 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
809 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
810 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
811 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
814 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
815 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
816 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
817 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
822 void MainWin::showAboutDlg() {
823 AboutDlg(this).exec();
827 void MainWin::showShortcutsDlg() {
828 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
832 /********************************************************************************************************/
834 bool MainWin::event(QEvent *event) {
835 if(event->type() == QEvent::WindowActivate)
836 QtUi::closeNotifications();
837 return QMainWindow::event(event);
840 void MainWin::moveEvent(QMoveEvent *event) {
841 if(!(windowState() & Qt::WindowMaximized))
842 _normalPos = event->pos();
844 QMainWindow::moveEvent(event);
847 void MainWin::resizeEvent(QResizeEvent *event) {
848 if(!(windowState() & Qt::WindowMaximized))
849 _normalSize = event->size();
851 QMainWindow::resizeEvent(event);
854 void MainWin::closeEvent(QCloseEvent *event) {
856 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
858 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
867 void MainWin::changeEvent(QEvent *event) {
869 if(event->type() == QEvent::ActivationChange)
870 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
873 QMainWindow::changeEvent(event);
876 void MainWin::hideToTray() {
877 if(!systemTray()->isSystemTrayAvailable()) {
878 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
882 systemTray()->setIconVisible();
885 void MainWin::toggleMinimizedToTray() {
887 // the problem is that we lose focus when the systray icon is activated
888 // and we don't know the former active window
889 // therefore we watch for activation event and use our stopwatch :)
890 // courtesy: KSystemTrayIcon
891 if(GetTickCount() - dwTickCount >= 300)
892 // we weren't active in the last 300ms -> activate
899 if(!isVisible() || isMinimized())
908 void MainWin::forceActivated() {
910 // Bypass focus stealing prevention
911 QX11Info::setAppUserTime(QX11Info::appTime());
914 if(windowState() & Qt::WindowMinimized) {
916 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
919 // this does not actually work on all platforms... and causes more evil than good
920 // move(frameGeometry().topLeft()); // avoid placement policies
926 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
929 bool hasFocus = QApplication::activeWindow() != 0;
931 for(int i = start; i <= end; i++) {
932 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
934 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
937 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
938 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
940 flags |= Message::Backlog; // we only want to trigger a highlight once!
941 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
943 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
944 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
946 if(hasFocus && bufId == _bufferWidget->currentBuffer())
949 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
950 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
951 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
952 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
953 AbstractNotificationBackend::NotificationType type;
955 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
956 type = AbstractNotificationBackend::PrivMsg;
957 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
958 type = AbstractNotificationBackend::PrivMsgFocused;
959 else if(flags & Message::Highlight && !hasFocus)
960 type = AbstractNotificationBackend::Highlight;
962 type = AbstractNotificationBackend::HighlightFocused;
964 QtUi::invokeNotification(bufId, type, sender, contents);
969 void MainWin::clientNetworkCreated(NetworkId id) {
970 const Network *net = Client::network(id);
971 QAction *act = new QAction(net->networkName(), this);
972 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
973 act->setData(QVariant::fromValue<NetworkId>(id));
974 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
975 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
977 QAction *beforeAction = 0;
978 foreach(QAction *action, _networksMenu->actions()) {
979 if(!action->data().isValid()) // ignore stock actions
981 if(net->networkName().localeAwareCompare(action->text()) < 0) {
982 beforeAction = action;
986 _networksMenu->insertAction(beforeAction, act);
989 void MainWin::clientNetworkUpdated() {
990 const Network *net = qobject_cast<const Network *>(sender());
994 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
998 action->setText(net->networkName());
1000 switch(net->connectionState()) {
1001 case Network::Initialized:
1002 action->setIcon(SmallIcon("network-connect"));
1004 case Network::Disconnected:
1005 action->setIcon(SmallIcon("network-disconnect"));
1008 action->setIcon(SmallIcon("network-wired"));
1012 void MainWin::clientNetworkRemoved(NetworkId id) {
1013 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1017 action->deleteLater();
1020 void MainWin::connectOrDisconnectFromNet() {
1021 QAction *act = qobject_cast<QAction *>(sender());
1023 const Network *net = Client::network(act->data().value<NetworkId>());
1025 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1026 else net->requestDisconnect();
1029 void MainWin::on_jumpHotBuffer_triggered() {
1030 if(!_bufferHotList->rowCount())
1033 QModelIndex topIndex = _bufferHotList->index(0, 0);
1034 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1035 Client::bufferModel()->switchToBuffer(bufferId);
1038 void MainWin::on_actionDebugNetworkModel_triggered() {
1039 QTreeView *view = new QTreeView;
1040 view->setAttribute(Qt::WA_DeleteOnClose);
1041 view->setWindowTitle("Debug NetworkModel View");
1042 view->setModel(Client::networkModel());
1043 view->setColumnWidth(0, 250);
1044 view->setColumnWidth(1, 250);
1045 view->setColumnWidth(2, 80);
1046 view->resize(610, 300);
1050 void MainWin::on_actionDebugHotList_triggered() {
1051 QTreeView *view = new QTreeView;
1052 view->setAttribute(Qt::WA_DeleteOnClose);
1053 view->setModel(_bufferHotList);
1057 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1058 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1059 overlay->setAttribute(Qt::WA_DeleteOnClose);
1063 void MainWin::on_actionDebugMessageModel_triggered() {
1064 QTableView *view = new QTableView(0);
1065 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1066 filter->setSourceModel(Client::messageModel());
1067 view->setModel(filter);
1068 view->setAttribute(Qt::WA_DeleteOnClose, true);
1069 view->verticalHeader()->hide();
1070 view->horizontalHeader()->setStretchLastSection(true);
1074 void MainWin::on_actionDebugLog_triggered() {
1075 DebugLogWidget *logWidget = new DebugLogWidget(0);
1079 void MainWin::showStatusBarMessage(const QString &message) {
1080 statusBar()->showMessage(message, 10000);