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>
30 # include <KWindowSystem>
38 #include "awaylogfilter.h"
39 #include "awaylogview.h"
41 #include "actioncollection.h"
42 #include "bufferhotlistfilter.h"
43 #include "buffermodel.h"
44 #include "bufferview.h"
45 #include "bufferviewoverlay.h"
46 #include "bufferviewoverlayfilter.h"
47 #include "bufferwidget.h"
48 #include "channellistdlg.h"
49 #include "chatlinemodel.h"
50 #include "chatmonitorfilter.h"
51 #include "chatmonitorview.h"
54 #include "clientsyncer.h"
55 #include "clientbacklogmanager.h"
56 #include "clientbufferviewconfig.h"
57 #include "clientbufferviewmanager.h"
58 #include "clientignorelistmanager.h"
59 #include "coreinfodlg.h"
60 #include "coreconnectdlg.h"
61 #include "contextmenuactionprovider.h"
62 #include "debugbufferviewoverlay.h"
63 #include "debuglogwidget.h"
64 #include "debugmessagemodelfilter.h"
65 #include "flatproxymodel.h"
66 #include "iconloader.h"
67 #include "inputwidget.h"
68 #include "irclistmodel.h"
69 #include "ircconnectionwizard.h"
70 #include "jumpkeyhandler.h"
71 #include "msgprocessorstatuswidget.h"
72 #include "nicklistwidget.h"
73 #include "qtuiapplication.h"
74 #include "qtuimessageprocessor.h"
75 #include "qtuisettings.h"
76 #include "qtuistyle.h"
77 #include "settingsdlg.h"
78 #include "settingspagedlg.h"
79 #include "systemtray.h"
80 #include "toolbaractionprovider.h"
81 #include "topicwidget.h"
82 #include "verticaldock.h"
86 # include "desktopnotificationbackend.h"
89 # include "phononnotificationbackend.h"
91 # include "systraynotificationbackend.h"
92 # include "taskbarnotificationbackend.h"
94 # include "knotificationbackend.h"
97 #ifdef HAVE_INDICATEQT
98 #include "indicatornotificationbackend.h"
101 #include "settingspages/aliasessettingspage.h"
102 #include "settingspages/appearancesettingspage.h"
103 #include "settingspages/backlogsettingspage.h"
104 #include "settingspages/bufferviewsettingspage.h"
105 #include "settingspages/chatmonitorsettingspage.h"
106 #include "settingspages/chatviewsettingspage.h"
107 #include "settingspages/connectionsettingspage.h"
108 #include "settingspages/generalsettingspage.h"
109 #include "settingspages/highlightsettingspage.h"
110 #include "settingspages/identitiessettingspage.h"
111 #include "settingspages/ignorelistsettingspage.h"
112 #include "settingspages/inputwidgetsettingspage.h"
113 #include "settingspages/itemviewsettingspage.h"
114 #include "settingspages/networkssettingspage.h"
115 #include "settingspages/notificationssettingspage.h"
116 #include "settingspages/topicwidgetsettingspage.h"
118 MainWin::MainWin(QWidget *parent)
120 : KMainWindow(parent),
121 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
123 : QMainWindow(parent),
125 coreLagLabel(new QLabel()),
126 sslLabel(new QLabel()),
127 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
136 QtUiSettings uiSettings;
137 QString style = uiSettings.value("Style", QString()).toString();
138 if(!style.isEmpty()) {
139 QApplication::setStyle(style);
142 QApplication::setQuitOnLastWindowClosed(false);
144 setWindowTitle("Quassel IRC");
145 setWindowIconText("Quassel IRC");
148 installEventFilter(new JumpKeyHandler(this));
151 void MainWin::init() {
152 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
153 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
154 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
155 SLOT(messagesInserted(const QModelIndex &, int, int)));
156 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
157 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
160 setDockNestingEnabled(true);
161 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
162 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
163 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
164 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
166 // Order is sometimes important
181 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
182 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
184 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
187 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
191 QtUi::registerNotificationBackend(new KNotificationBackend(this));
192 #endif /* HAVE_KDE */
194 #ifdef HAVE_INDICATEQT
195 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
198 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
200 setDisconnectedState(); // Disable menus and stuff
203 setAutoSaveSettings();
206 // restore mainwin state
208 restoreStateFromSettings(s);
210 // restore locked state of docks
211 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
213 if(Quassel::runMode() != Quassel::Monolithic) {
214 showCoreConnectionDlg(true); // autoconnect if appropriate
220 MainWin::~MainWin() {
224 void MainWin::quit() {
226 saveStateToSettings(s);
228 QApplication::quit();
231 void MainWin::saveStateToSettings(UiSettings &s) {
232 s.setValue("MainWinSize", _normalSize);
233 s.setValue("MainWinPos", _normalPos);
234 s.setValue("MainWinState", saveState());
235 s.setValue("MainWinGeometry", saveGeometry());
236 s.setValue("MainWinMinimized", isMinimized());
237 s.setValue("MainWinMaximized", isMaximized());
238 s.setValue("MainWinHidden", !isVisible());
241 saveAutoSaveSettings();
245 void MainWin::restoreStateFromSettings(UiSettings &s) {
246 _normalSize = s.value("MainWinSize", size()).toSize();
247 _normalPos = s.value("MainWinPos", pos()).toPoint();
248 bool maximized = s.value("MainWinMaximized", false).toBool();
251 restoreGeometry(s.value("MainWinGeometry").toByteArray());
254 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
259 restoreState(s.value("MainWinState").toByteArray());
265 if(s.value("MainWinHidden").toBool())
267 else if(s.value("MainWinMinimized").toBool())
275 void MainWin::updateIcon() {
277 const int size = 128;
283 if(Client::isConnected())
284 icon = DesktopIcon("quassel", size);
286 icon = DesktopIcon("quassel_inactive", size);
288 qApp->setWindowIcon(icon);
291 void MainWin::setupActions() {
292 ActionCollection *coll = QtUi::actionCollection("General");
294 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
295 this, SLOT(showCoreConnectionDlg())));
296 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
297 Client::instance(), SLOT(disconnectFromCore())));
298 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
299 this, SLOT(showCoreInfoDlg())));
300 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
301 this, SLOT(on_actionConfigureNetworks_triggered())));
302 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
303 this, SLOT(quit()), tr("Ctrl+Q")));
306 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
307 this, SLOT(on_actionConfigureViews_triggered())));
309 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
310 lockAct->setCheckable(true);
311 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
313 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
314 0, 0, QKeySequence::Find))->setCheckable(true);
315 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
316 this, SLOT(showAwayLog())));
317 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
318 0, 0, tr("Ctrl+M")))->setCheckable(true);
320 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
321 0, 0))->setCheckable(true);
324 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
325 this, SLOT(showSettingsDlg()), tr("F7")));
328 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
329 this, SLOT(showAboutDlg())));
330 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
331 qApp, SLOT(aboutQt())));
332 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
333 this, SLOT(on_actionDebugNetworkModel_triggered())));
334 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
335 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
336 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
337 this, SLOT(on_actionDebugMessageModel_triggered())));
338 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
339 this, SLOT(on_actionDebugHotList_triggered())));
340 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
341 this, SLOT(on_actionDebugLog_triggered())));
342 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
343 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
346 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
347 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
350 void MainWin::setupMenus() {
351 ActionCollection *coll = QtUi::actionCollection("General");
353 _fileMenu = menuBar()->addMenu(tr("&File"));
355 static const QStringList coreActions = QStringList()
356 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
359 foreach(QString actionName, coreActions) {
360 coreAction = coll->action(actionName);
361 _fileMenu->addAction(coreAction);
362 flagRemoteCoreOnly(coreAction);
364 flagRemoteCoreOnly(_fileMenu->addSeparator());
366 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
367 _networksMenu->addAction(coll->action("ConfigureNetworks"));
368 _networksMenu->addSeparator();
369 _fileMenu->addSeparator();
370 _fileMenu->addAction(coll->action("Quit"));
372 _viewMenu = menuBar()->addMenu(tr("&View"));
373 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
374 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
375 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
376 _viewMenu->addSeparator();
378 _viewMenu->addAction(coll->action("ToggleMenuBar"));
379 _viewMenu->addAction(coll->action("ToggleStatusBar"));
380 _viewMenu->addAction(coll->action("ToggleSearchBar"));
382 coreAction = coll->action("ShowAwayLog");
383 flagRemoteCoreOnly(coreAction);
384 _viewMenu->addAction(coreAction);
386 _viewMenu->addSeparator();
387 _viewMenu->addAction(coll->action("LockLayout"));
389 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
391 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
392 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
394 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
396 _helpMenu = menuBar()->addMenu(tr("&Help"));
397 _helpMenu->addAction(coll->action("AboutQuassel"));
399 _helpMenu->addAction(coll->action("AboutQt"));
401 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
403 _helpMenu->addSeparator();
404 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
405 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
406 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
407 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
408 _helpDebugMenu->addAction(coll->action("DebugHotList"));
409 _helpDebugMenu->addAction(coll->action("DebugLog"));
410 _helpDebugMenu->addSeparator();
411 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
414 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
416 QtUiSettings uiSettings;
417 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
418 showMenuBar->setChecked(enabled);
419 enabled ? menuBar()->show() : menuBar()->hide();
421 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
422 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
425 void MainWin::setupBufferWidget() {
426 _bufferWidget = new BufferWidget(this);
427 _bufferWidget->setModel(Client::bufferModel());
428 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
429 setCentralWidget(_bufferWidget);
432 void MainWin::addBufferView(int bufferViewConfigId) {
433 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
436 void MainWin::addBufferView(ClientBufferViewConfig *config) {
440 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
441 BufferViewDock *dock = new BufferViewDock(config, this);
443 //create the view and initialize it's filter
444 BufferView *view = new BufferView(dock);
445 view->setFilteredModel(Client::bufferModel(), config);
446 view->installEventFilter(_inputWidget); // for key presses
448 Client::bufferModel()->synchronizeView(view);
450 dock->setWidget(view);
451 dock->setVisible(_layoutLoaded); // don't show before state has been restored
453 addDockWidget(Qt::LeftDockWidgetArea, dock);
454 _bufferViewsMenu->addAction(dock->toggleViewAction());
456 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
457 _bufferViews.append(dock);
460 void MainWin::removeBufferView(int bufferViewConfigId) {
462 BufferViewDock *dock;
463 foreach(QAction *action, _bufferViewsMenu->actions()) {
464 actionData = action->data();
465 if(!actionData.isValid())
468 dock = qobject_cast<BufferViewDock *>(action->parent());
469 if(dock && actionData.toInt() == bufferViewConfigId) {
470 removeAction(action);
471 _bufferViews.removeAll(dock);
477 void MainWin::bufferViewToggled(bool enabled) {
478 QAction *action = qobject_cast<QAction *>(sender());
480 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
483 Client::bufferViewOverlay()->addView(dock->bufferViewId());
484 BufferViewConfig *config = dock->config();
485 if(config && config->isInitialized()) {
486 BufferIdList buffers;
487 if(config->networkId().isValid()) {
488 foreach(BufferId bufferId, config->bufferList()) {
489 if(Client::networkModel()->networkId(bufferId) == config->networkId())
492 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
493 if(Client::networkModel()->networkId(bufferId) == config->networkId())
497 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
499 Client::backlogManager()->checkForBacklog(buffers);
502 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
506 BufferView *MainWin::allBuffersView() const {
507 // "All Buffers" is always the first dock created
508 if(_bufferViews.count() > 0)
509 return _bufferViews[0]->bufferView();
513 void MainWin::showNotificationsDlg() {
514 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
518 void MainWin::on_actionConfigureNetworks_triggered() {
519 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
523 void MainWin::on_actionConfigureViews_triggered() {
524 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
528 void MainWin::on_actionLockLayout_toggled(bool lock) {
529 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
530 foreach(VerticalDock *dock, docks) {
531 dock->showTitle(!lock);
533 if(Client::bufferViewManager()) {
534 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
535 config->setLocked(lock);
538 QtUiSettings().setValue("LockLayout", lock);
541 void MainWin::setupNickWidget() {
543 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
544 nickDock->setObjectName("NickDock");
545 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
547 _nickListWidget = new NickListWidget(nickDock);
548 nickDock->setWidget(_nickListWidget);
550 addDockWidget(Qt::RightDockWidgetArea, nickDock);
551 _viewMenu->addAction(nickDock->toggleViewAction());
552 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
554 // See NickListDock::NickListDock();
555 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
557 // attach the NickListWidget to the BufferModel and the default selection
558 _nickListWidget->setModel(Client::bufferModel());
559 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
562 void MainWin::setupChatMonitor() {
563 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
564 dock->setObjectName("ChatMonitorDock");
566 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
567 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
569 dock->setWidget(chatView);
572 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
573 _viewMenu->addAction(dock->toggleViewAction());
574 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
577 void MainWin::setupInputWidget() {
578 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
579 dock->setObjectName("InputDock");
581 _inputWidget = new InputWidget(dock);
582 dock->setWidget(_inputWidget);
584 addDockWidget(Qt::BottomDockWidgetArea, dock);
586 _viewMenu->addAction(dock->toggleViewAction());
587 dock->toggleViewAction()->setText(tr("Show Input Line"));
589 _inputWidget->setModel(Client::bufferModel());
590 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
592 _bufferWidget->setFocusProxy(_inputWidget);
594 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
597 void MainWin::setupTopicWidget() {
598 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
599 dock->setObjectName("TopicDock");
600 TopicWidget *topicwidget = new TopicWidget(dock);
602 dock->setWidget(topicwidget);
604 topicwidget->setModel(Client::bufferModel());
605 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
607 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
609 _viewMenu->addAction(dock->toggleViewAction());
610 dock->toggleViewAction()->setText(tr("Show Topic Line"));
613 void MainWin::setupTitleSetter() {
614 _titleSetter.setModel(Client::bufferModel());
615 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
618 void MainWin::setupStatusBar() {
619 // MessageProcessor progress
620 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
623 updateLagIndicator();
624 statusBar()->addPermanentWidget(coreLagLabel);
625 coreLagLabel->hide();
626 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
629 sslLabel->setPixmap(QPixmap());
630 statusBar()->addPermanentWidget(sslLabel);
633 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
635 QtUiSettings uiSettings;
637 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
638 showStatusbar->setChecked(enabled);
639 enabled ? statusBar()->show() : statusBar()->hide();
641 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
642 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
645 void MainWin::setupHotList() {
646 FlatProxyModel *flatProxy = new FlatProxyModel(this);
647 flatProxy->setSourceModel(Client::bufferModel());
648 _bufferHotList = new BufferHotListFilter(flatProxy);
651 void MainWin::saveMenuBarStatus(bool enabled) {
652 QtUiSettings uiSettings;
653 uiSettings.setValue("ShowMenuBar", enabled);
656 void MainWin::saveStatusBarStatus(bool enabled) {
657 QtUiSettings uiSettings;
658 uiSettings.setValue("ShowStatusBar", enabled);
661 void MainWin::setupSystray() {
662 _systemTray = new SystemTray(this);
665 void MainWin::setupToolBars() {
666 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
667 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
668 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
669 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
672 setUnifiedTitleAndToolBarOnMac(true);
676 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
678 _mainToolBar = new QToolBar(this);
679 _mainToolBar->setObjectName("MainToolBar");
681 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
682 addToolBar(_mainToolBar);
684 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
685 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
688 void MainWin::connectedToCore() {
689 Q_CHECK_PTR(Client::bufferViewManager());
690 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
691 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
692 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
697 void MainWin::setConnectedState() {
698 ActionCollection *coll = QtUi::actionCollection("General");
700 coll->action("ConnectCore")->setEnabled(false);
701 coll->action("DisconnectCore")->setEnabled(true);
702 coll->action("CoreInfo")->setEnabled(true);
704 foreach(QAction *action, _fileMenu->actions()) {
705 if(isRemoteCoreOnly(action))
706 action->setVisible(!Client::internalCore());
709 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
710 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
711 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
712 if(!Client::internalCore()) {
713 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
714 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
715 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
718 // _viewMenu->setEnabled(true);
719 if(!Client::internalCore())
720 statusBar()->showMessage(tr("Connected to core."));
722 statusBar()->clearMessage();
724 if(Client::signalProxy()->isSecure()) {
725 sslLabel->setPixmap(SmallIcon("security-high"));
727 sslLabel->setPixmap(SmallIcon("security-low"));
730 sslLabel->setVisible(!Client::internalCore());
731 coreLagLabel->setVisible(!Client::internalCore());
733 systemTray()->setState(SystemTray::Active);
735 if(Client::networkIds().isEmpty()) {
736 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
741 void MainWin::loadLayout() {
743 int accountId = Client::currentCoreAccount().toInt();
744 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
745 _layoutLoaded = true;
748 void MainWin::saveLayout() {
750 int accountId = Client::currentCoreAccount().toInt();
751 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
754 void MainWin::updateLagIndicator(int lag) {
755 QString text = tr("Core Lag: %1");
757 text = text.arg('-');
759 text = text.arg("%1 msec").arg(lag);
760 coreLagLabel->setText(text);
763 void MainWin::disconnectedFromCore() {
764 // save core specific layout and remove bufferviews;
766 _layoutLoaded = false;
769 BufferViewDock *dock;
770 foreach(QAction *action, _bufferViewsMenu->actions()) {
771 actionData = action->data();
772 if(!actionData.isValid())
775 dock = qobject_cast<BufferViewDock *>(action->parent());
776 if(dock && actionData.toInt() != -1) {
777 removeAction(action);
778 _bufferViews.removeAll(dock);
784 restoreState(s.value("MainWinState").toByteArray());
785 setDisconnectedState();
788 void MainWin::setDisconnectedState() {
789 ActionCollection *coll = QtUi::actionCollection("General");
790 //ui.menuCore->setEnabled(false);
791 coll->action("ConnectCore")->setEnabled(true);
792 coll->action("DisconnectCore")->setEnabled(false);
793 coll->action("CoreInfo")->setEnabled(false);
794 //_viewMenu->setEnabled(false);
795 statusBar()->showMessage(tr("Not connected to core."));
796 sslLabel->setPixmap(QPixmap());
798 updateLagIndicator();
799 coreLagLabel->hide();
800 if(msgProcessorStatusWidget)
801 msgProcessorStatusWidget->setProgress(0, 0);
803 systemTray()->setState(SystemTray::Inactive);
806 void MainWin::startInternalCore() {
807 ClientSyncer *syncer = new ClientSyncer();
808 Client::registerClientSyncer(syncer);
809 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
810 syncer->useInternalCore();
813 void MainWin::showCoreConnectionDlg(bool autoConnect) {
814 CoreConnectDlg(autoConnect, this).exec();
817 void MainWin::showChannelList(NetworkId netId) {
818 ChannelListDlg *channelListDlg = new ChannelListDlg();
820 if(!netId.isValid()) {
821 QAction *action = qobject_cast<QAction *>(sender());
823 netId = action->data().value<NetworkId>();
826 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
827 channelListDlg->setNetwork(netId);
828 channelListDlg->show();
831 void MainWin::showIgnoreList(QString newRule) {
832 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
833 // prepare config dialog for new rule
834 if(!newRule.isEmpty())
835 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
839 void MainWin::showCoreInfoDlg() {
840 CoreInfoDlg(this).exec();
843 void MainWin::showAwayLog() {
846 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
847 _awayLog = new AwayLogView(filter, 0);
848 filter->setParent(_awayLog);
849 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
850 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
854 void MainWin::awayLogDestroyed() {
858 void MainWin::showSettingsDlg() {
859 SettingsDlg *dlg = new SettingsDlg();
861 //Category: Interface
862 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
863 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
864 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
865 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
866 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
867 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
868 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
869 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
870 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
871 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
874 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
875 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
876 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
877 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
878 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
879 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
884 void MainWin::showAboutDlg() {
885 AboutDlg(this).exec();
889 void MainWin::showShortcutsDlg() {
890 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
894 /********************************************************************************************************/
896 bool MainWin::event(QEvent *event) {
897 if(event->type() == QEvent::WindowActivate) {
898 BufferId buffer = Client::bufferModel()->currentBuffer();
900 QtUi::closeNotifications(buffer);
902 return QMainWindow::event(event);
905 void MainWin::moveEvent(QMoveEvent *event) {
906 if(!(windowState() & Qt::WindowMaximized))
907 _normalPos = event->pos();
909 QMainWindow::moveEvent(event);
912 void MainWin::resizeEvent(QResizeEvent *event) {
913 if(!(windowState() & Qt::WindowMaximized))
914 _normalSize = event->size();
916 QMainWindow::resizeEvent(event);
919 void MainWin::closeEvent(QCloseEvent *event) {
921 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
923 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
932 void MainWin::changeEvent(QEvent *event) {
934 if(event->type() == QEvent::ActivationChange)
935 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
938 QMainWindow::changeEvent(event);
941 void MainWin::hideToTray() {
942 if(!systemTray()->isSystemTrayAvailable()) {
943 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
947 systemTray()->setIconVisible();
950 void MainWin::toggleMinimizedToTray() {
952 // the problem is that we lose focus when the systray icon is activated
953 // and we don't know the former active window
954 // therefore we watch for activation event and use our stopwatch :)
955 // courtesy: KSystemTrayIcon
956 if(GetTickCount() - dwTickCount >= 300)
957 // we weren't active in the last 300ms -> activate
964 if(!isVisible() || isMinimized())
973 void MainWin::forceActivated() {
976 KWindowSystem::forceActiveWindow(winId());
980 // Bypass focus stealing prevention
981 QX11Info::setAppUserTime(QX11Info::appTime());
984 if(windowState() & Qt::WindowMinimized) {
986 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
989 // this does not actually work on all platforms... and causes more evil than good
990 // move(frameGeometry().topLeft()); // avoid placement policies
994 #endif /* HAVE_KDE */
997 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1000 bool hasFocus = QApplication::activeWindow() != 0;
1002 for(int i = start; i <= end; i++) {
1003 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1004 if(!idx.isValid()) {
1005 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1008 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1009 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1012 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1013 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1015 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1018 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1019 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1020 Client::networkModel()->networkName(bufId))))
1022 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1023 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1024 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1025 AbstractNotificationBackend::NotificationType type;
1027 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1028 type = AbstractNotificationBackend::PrivMsg;
1029 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1030 type = AbstractNotificationBackend::PrivMsgFocused;
1031 else if(flags & Message::Highlight && !hasFocus)
1032 type = AbstractNotificationBackend::Highlight;
1034 type = AbstractNotificationBackend::HighlightFocused;
1036 QtUi::invokeNotification(bufId, type, sender, contents);
1041 void MainWin::currentBufferChanged(BufferId buffer) {
1042 if(buffer.isValid())
1043 QtUi::closeNotifications(buffer);
1046 void MainWin::clientNetworkCreated(NetworkId id) {
1047 const Network *net = Client::network(id);
1048 QAction *act = new QAction(net->networkName(), this);
1049 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1050 act->setData(QVariant::fromValue<NetworkId>(id));
1051 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1052 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1054 QAction *beforeAction = 0;
1055 foreach(QAction *action, _networksMenu->actions()) {
1056 if(!action->data().isValid()) // ignore stock actions
1058 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1059 beforeAction = action;
1063 _networksMenu->insertAction(beforeAction, act);
1066 void MainWin::clientNetworkUpdated() {
1067 const Network *net = qobject_cast<const Network *>(sender());
1071 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1075 action->setText(net->networkName());
1077 switch(net->connectionState()) {
1078 case Network::Initialized:
1079 action->setIcon(SmallIcon("network-connect"));
1081 case Network::Disconnected:
1082 action->setIcon(SmallIcon("network-disconnect"));
1085 action->setIcon(SmallIcon("network-wired"));
1089 void MainWin::clientNetworkRemoved(NetworkId id) {
1090 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1094 action->deleteLater();
1097 void MainWin::connectOrDisconnectFromNet() {
1098 QAction *act = qobject_cast<QAction *>(sender());
1100 const Network *net = Client::network(act->data().value<NetworkId>());
1102 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1103 else net->requestDisconnect();
1106 void MainWin::on_jumpHotBuffer_triggered() {
1107 if(!_bufferHotList->rowCount())
1110 QModelIndex topIndex = _bufferHotList->index(0, 0);
1111 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1112 Client::bufferModel()->switchToBuffer(bufferId);
1115 void MainWin::on_actionDebugNetworkModel_triggered() {
1116 QTreeView *view = new QTreeView;
1117 view->setAttribute(Qt::WA_DeleteOnClose);
1118 view->setWindowTitle("Debug NetworkModel View");
1119 view->setModel(Client::networkModel());
1120 view->setColumnWidth(0, 250);
1121 view->setColumnWidth(1, 250);
1122 view->setColumnWidth(2, 80);
1123 view->resize(610, 300);
1127 void MainWin::on_actionDebugHotList_triggered() {
1128 QTreeView *view = new QTreeView;
1129 view->setAttribute(Qt::WA_DeleteOnClose);
1130 view->setModel(_bufferHotList);
1134 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1135 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1136 overlay->setAttribute(Qt::WA_DeleteOnClose);
1140 void MainWin::on_actionDebugMessageModel_triggered() {
1141 QTableView *view = new QTableView(0);
1142 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1143 filter->setSourceModel(Client::messageModel());
1144 view->setModel(filter);
1145 view->setAttribute(Qt::WA_DeleteOnClose, true);
1146 view->verticalHeader()->hide();
1147 view->horizontalHeader()->setStretchLastSection(true);
1151 void MainWin::on_actionDebugLog_triggered() {
1152 DebugLogWidget *logWidget = new DebugLogWidget(0);
1156 void MainWin::showStatusBarMessage(const QString &message) {
1157 statusBar()->showMessage(message, 10000);