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);
472 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
478 void MainWin::bufferViewToggled(bool enabled) {
479 QAction *action = qobject_cast<QAction *>(sender());
481 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
484 // Make sure we don't toggle backlog fetch for a view we've already removed
485 if(!_bufferViews.contains(dock))
489 Client::bufferViewOverlay()->addView(dock->bufferViewId());
490 BufferViewConfig *config = dock->config();
491 if(config && config->isInitialized()) {
492 BufferIdList buffers;
493 if(config->networkId().isValid()) {
494 foreach(BufferId bufferId, config->bufferList()) {
495 if(Client::networkModel()->networkId(bufferId) == config->networkId())
498 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
499 if(Client::networkModel()->networkId(bufferId) == config->networkId())
503 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
505 Client::backlogManager()->checkForBacklog(buffers);
508 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
512 BufferView *MainWin::allBuffersView() const {
513 // "All Buffers" is always the first dock created
514 if(_bufferViews.count() > 0)
515 return _bufferViews[0]->bufferView();
519 void MainWin::showNotificationsDlg() {
520 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
524 void MainWin::on_actionConfigureNetworks_triggered() {
525 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
529 void MainWin::on_actionConfigureViews_triggered() {
530 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
534 void MainWin::on_actionLockLayout_toggled(bool lock) {
535 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
536 foreach(VerticalDock *dock, docks) {
537 dock->showTitle(!lock);
539 if(Client::bufferViewManager()) {
540 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
541 config->setLocked(lock);
544 QtUiSettings().setValue("LockLayout", lock);
547 void MainWin::setupNickWidget() {
549 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
550 nickDock->setObjectName("NickDock");
551 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
553 _nickListWidget = new NickListWidget(nickDock);
554 nickDock->setWidget(_nickListWidget);
556 addDockWidget(Qt::RightDockWidgetArea, nickDock);
557 _viewMenu->addAction(nickDock->toggleViewAction());
558 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
560 // See NickListDock::NickListDock();
561 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
563 // attach the NickListWidget to the BufferModel and the default selection
564 _nickListWidget->setModel(Client::bufferModel());
565 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
568 void MainWin::setupChatMonitor() {
569 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
570 dock->setObjectName("ChatMonitorDock");
572 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
573 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
575 dock->setWidget(chatView);
578 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
579 _viewMenu->addAction(dock->toggleViewAction());
580 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
583 void MainWin::setupInputWidget() {
584 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
585 dock->setObjectName("InputDock");
587 _inputWidget = new InputWidget(dock);
588 dock->setWidget(_inputWidget);
590 addDockWidget(Qt::BottomDockWidgetArea, dock);
592 _viewMenu->addAction(dock->toggleViewAction());
593 dock->toggleViewAction()->setText(tr("Show Input Line"));
595 _inputWidget->setModel(Client::bufferModel());
596 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
598 _bufferWidget->setFocusProxy(_inputWidget);
600 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
603 void MainWin::setupTopicWidget() {
604 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
605 dock->setObjectName("TopicDock");
606 TopicWidget *topicwidget = new TopicWidget(dock);
608 dock->setWidget(topicwidget);
610 topicwidget->setModel(Client::bufferModel());
611 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
613 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
615 _viewMenu->addAction(dock->toggleViewAction());
616 dock->toggleViewAction()->setText(tr("Show Topic Line"));
619 void MainWin::setupTitleSetter() {
620 _titleSetter.setModel(Client::bufferModel());
621 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
624 void MainWin::setupStatusBar() {
625 // MessageProcessor progress
626 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
629 updateLagIndicator();
630 statusBar()->addPermanentWidget(coreLagLabel);
631 coreLagLabel->hide();
632 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
635 sslLabel->setPixmap(QPixmap());
636 statusBar()->addPermanentWidget(sslLabel);
639 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
641 QtUiSettings uiSettings;
643 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
644 showStatusbar->setChecked(enabled);
645 enabled ? statusBar()->show() : statusBar()->hide();
647 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
648 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
651 void MainWin::setupHotList() {
652 FlatProxyModel *flatProxy = new FlatProxyModel(this);
653 flatProxy->setSourceModel(Client::bufferModel());
654 _bufferHotList = new BufferHotListFilter(flatProxy);
657 void MainWin::saveMenuBarStatus(bool enabled) {
658 QtUiSettings uiSettings;
659 uiSettings.setValue("ShowMenuBar", enabled);
662 void MainWin::saveStatusBarStatus(bool enabled) {
663 QtUiSettings uiSettings;
664 uiSettings.setValue("ShowStatusBar", enabled);
667 void MainWin::setupSystray() {
668 _systemTray = new SystemTray(this);
671 void MainWin::setupToolBars() {
672 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
673 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
674 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
675 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
678 setUnifiedTitleAndToolBarOnMac(true);
682 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
684 _mainToolBar = new QToolBar(this);
685 _mainToolBar->setObjectName("MainToolBar");
687 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
688 addToolBar(_mainToolBar);
690 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
691 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
694 void MainWin::connectedToCore() {
695 Q_CHECK_PTR(Client::bufferViewManager());
696 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
697 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
698 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
703 void MainWin::setConnectedState() {
704 ActionCollection *coll = QtUi::actionCollection("General");
706 coll->action("ConnectCore")->setEnabled(false);
707 coll->action("DisconnectCore")->setEnabled(true);
708 coll->action("CoreInfo")->setEnabled(true);
710 foreach(QAction *action, _fileMenu->actions()) {
711 if(isRemoteCoreOnly(action))
712 action->setVisible(!Client::internalCore());
715 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
716 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
717 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
718 if(!Client::internalCore()) {
719 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
720 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
721 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
724 // _viewMenu->setEnabled(true);
725 if(!Client::internalCore())
726 statusBar()->showMessage(tr("Connected to core."));
728 statusBar()->clearMessage();
730 if(Client::signalProxy()->isSecure()) {
731 sslLabel->setPixmap(SmallIcon("security-high"));
733 sslLabel->setPixmap(SmallIcon("security-low"));
736 sslLabel->setVisible(!Client::internalCore());
737 coreLagLabel->setVisible(!Client::internalCore());
739 systemTray()->setState(SystemTray::Active);
741 if(Client::networkIds().isEmpty()) {
742 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
747 void MainWin::loadLayout() {
749 int accountId = Client::currentCoreAccount().toInt();
750 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
751 if(state.isEmpty()) {
752 // Make sure that the default bufferview is shown
753 if(_bufferViews.count())
754 _bufferViews.at(0)->show();
758 restoreState(state, accountId);
759 _layoutLoaded = true;
762 void MainWin::saveLayout() {
764 int accountId = _bufferViews.count()? Client::currentCoreAccount().toInt() : 0; // only save if we still have a layout!
766 s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
769 void MainWin::updateLagIndicator(int lag) {
770 QString text = tr("Core Lag: %1");
772 text = text.arg('-');
774 text = text.arg("%1 msec").arg(lag);
775 coreLagLabel->setText(text);
778 void MainWin::disconnectedFromCore() {
779 // save core specific layout and remove bufferviews;
781 _layoutLoaded = false;
784 BufferViewDock *dock;
785 foreach(QAction *action, _bufferViewsMenu->actions()) {
786 actionData = action->data();
787 if(!actionData.isValid())
790 dock = qobject_cast<BufferViewDock *>(action->parent());
791 if(dock && actionData.toInt() != -1) {
792 removeAction(action);
793 _bufferViews.removeAll(dock);
794 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
800 restoreState(s.value("MainWinState").toByteArray());
801 setDisconnectedState();
804 void MainWin::setDisconnectedState() {
805 ActionCollection *coll = QtUi::actionCollection("General");
806 //ui.menuCore->setEnabled(false);
807 coll->action("ConnectCore")->setEnabled(true);
808 coll->action("DisconnectCore")->setEnabled(false);
809 coll->action("CoreInfo")->setEnabled(false);
810 //_viewMenu->setEnabled(false);
811 statusBar()->showMessage(tr("Not connected to core."));
812 sslLabel->setPixmap(QPixmap());
814 updateLagIndicator();
815 coreLagLabel->hide();
816 if(msgProcessorStatusWidget)
817 msgProcessorStatusWidget->setProgress(0, 0);
819 systemTray()->setState(SystemTray::Inactive);
822 void MainWin::startInternalCore() {
823 ClientSyncer *syncer = new ClientSyncer();
824 Client::registerClientSyncer(syncer);
825 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
826 syncer->useInternalCore();
829 void MainWin::showCoreConnectionDlg(bool autoConnect) {
830 CoreConnectDlg(autoConnect, this).exec();
833 void MainWin::showChannelList(NetworkId netId) {
834 ChannelListDlg *channelListDlg = new ChannelListDlg();
836 if(!netId.isValid()) {
837 QAction *action = qobject_cast<QAction *>(sender());
839 netId = action->data().value<NetworkId>();
842 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
843 channelListDlg->setNetwork(netId);
844 channelListDlg->show();
847 void MainWin::showIgnoreList(QString newRule) {
848 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
849 // prepare config dialog for new rule
850 if(!newRule.isEmpty())
851 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
855 void MainWin::showCoreInfoDlg() {
856 CoreInfoDlg(this).exec();
859 void MainWin::showAwayLog() {
862 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
863 _awayLog = new AwayLogView(filter, 0);
864 filter->setParent(_awayLog);
865 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
866 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
870 void MainWin::awayLogDestroyed() {
874 void MainWin::showSettingsDlg() {
875 SettingsDlg *dlg = new SettingsDlg();
877 //Category: Interface
878 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
879 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
880 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
881 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
882 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
883 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
884 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
885 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
886 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
887 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
890 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
891 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
892 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
893 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
894 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
895 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
900 void MainWin::showAboutDlg() {
901 AboutDlg(this).exec();
905 void MainWin::showShortcutsDlg() {
906 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
910 /********************************************************************************************************/
912 bool MainWin::event(QEvent *event) {
913 if(event->type() == QEvent::WindowActivate) {
914 BufferId buffer = Client::bufferModel()->currentBuffer();
916 QtUi::closeNotifications(buffer);
918 return QMainWindow::event(event);
921 void MainWin::moveEvent(QMoveEvent *event) {
922 if(!(windowState() & Qt::WindowMaximized))
923 _normalPos = event->pos();
925 QMainWindow::moveEvent(event);
928 void MainWin::resizeEvent(QResizeEvent *event) {
929 if(!(windowState() & Qt::WindowMaximized))
930 _normalSize = event->size();
932 QMainWindow::resizeEvent(event);
935 void MainWin::closeEvent(QCloseEvent *event) {
937 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
939 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
948 void MainWin::changeEvent(QEvent *event) {
950 if(event->type() == QEvent::ActivationChange)
951 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
954 QMainWindow::changeEvent(event);
957 void MainWin::hideToTray() {
958 if(!systemTray()->isSystemTrayAvailable()) {
959 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
963 systemTray()->setIconVisible();
966 void MainWin::toggleMinimizedToTray() {
968 // the problem is that we lose focus when the systray icon is activated
969 // and we don't know the former active window
970 // therefore we watch for activation event and use our stopwatch :)
971 // courtesy: KSystemTrayIcon
972 if(GetTickCount() - dwTickCount >= 300)
973 // we weren't active in the last 300ms -> activate
980 if(!isVisible() || isMinimized())
989 void MainWin::forceActivated() {
992 KWindowSystem::forceActiveWindow(winId());
996 // Bypass focus stealing prevention
997 QX11Info::setAppUserTime(QX11Info::appTime());
1000 if(windowState() & Qt::WindowMinimized) {
1002 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
1005 // this does not actually work on all platforms... and causes more evil than good
1006 // move(frameGeometry().topLeft()); // avoid placement policies
1010 #endif /* HAVE_KDE */
1013 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1016 bool hasFocus = QApplication::activeWindow() != 0;
1018 for(int i = start; i <= end; i++) {
1019 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1020 if(!idx.isValid()) {
1021 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1024 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1025 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1028 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1029 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1031 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1034 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1035 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1036 Client::networkModel()->networkName(bufId))))
1038 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1039 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1040 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1041 AbstractNotificationBackend::NotificationType type;
1043 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1044 type = AbstractNotificationBackend::PrivMsg;
1045 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1046 type = AbstractNotificationBackend::PrivMsgFocused;
1047 else if(flags & Message::Highlight && !hasFocus)
1048 type = AbstractNotificationBackend::Highlight;
1050 type = AbstractNotificationBackend::HighlightFocused;
1052 QtUi::invokeNotification(bufId, type, sender, contents);
1057 void MainWin::currentBufferChanged(BufferId buffer) {
1058 if(buffer.isValid())
1059 QtUi::closeNotifications(buffer);
1062 void MainWin::clientNetworkCreated(NetworkId id) {
1063 const Network *net = Client::network(id);
1064 QAction *act = new QAction(net->networkName(), this);
1065 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1066 act->setData(QVariant::fromValue<NetworkId>(id));
1067 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1068 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1070 QAction *beforeAction = 0;
1071 foreach(QAction *action, _networksMenu->actions()) {
1072 if(!action->data().isValid()) // ignore stock actions
1074 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1075 beforeAction = action;
1079 _networksMenu->insertAction(beforeAction, act);
1082 void MainWin::clientNetworkUpdated() {
1083 const Network *net = qobject_cast<const Network *>(sender());
1087 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1091 action->setText(net->networkName());
1093 switch(net->connectionState()) {
1094 case Network::Initialized:
1095 action->setIcon(SmallIcon("network-connect"));
1097 case Network::Disconnected:
1098 action->setIcon(SmallIcon("network-disconnect"));
1101 action->setIcon(SmallIcon("network-wired"));
1105 void MainWin::clientNetworkRemoved(NetworkId id) {
1106 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1110 action->deleteLater();
1113 void MainWin::connectOrDisconnectFromNet() {
1114 QAction *act = qobject_cast<QAction *>(sender());
1116 const Network *net = Client::network(act->data().value<NetworkId>());
1118 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1119 else net->requestDisconnect();
1122 void MainWin::on_jumpHotBuffer_triggered() {
1123 if(!_bufferHotList->rowCount())
1126 QModelIndex topIndex = _bufferHotList->index(0, 0);
1127 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1128 Client::bufferModel()->switchToBuffer(bufferId);
1131 void MainWin::on_actionDebugNetworkModel_triggered() {
1132 QTreeView *view = new QTreeView;
1133 view->setAttribute(Qt::WA_DeleteOnClose);
1134 view->setWindowTitle("Debug NetworkModel View");
1135 view->setModel(Client::networkModel());
1136 view->setColumnWidth(0, 250);
1137 view->setColumnWidth(1, 250);
1138 view->setColumnWidth(2, 80);
1139 view->resize(610, 300);
1143 void MainWin::on_actionDebugHotList_triggered() {
1144 QTreeView *view = new QTreeView;
1145 view->setAttribute(Qt::WA_DeleteOnClose);
1146 view->setModel(_bufferHotList);
1150 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1151 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1152 overlay->setAttribute(Qt::WA_DeleteOnClose);
1156 void MainWin::on_actionDebugMessageModel_triggered() {
1157 QTableView *view = new QTableView(0);
1158 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1159 filter->setSourceModel(Client::messageModel());
1160 view->setModel(filter);
1161 view->setAttribute(Qt::WA_DeleteOnClose, true);
1162 view->verticalHeader()->hide();
1163 view->horizontalHeader()->setStretchLastSection(true);
1167 void MainWin::on_actionDebugLog_triggered() {
1168 DebugLogWidget *logWidget = new DebugLogWidget(0);
1172 void MainWin::showStatusBarMessage(const QString &message) {
1173 statusBar()->showMessage(message, 10000);