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 "clientbacklogmanager.h"
55 #include "clientbufferviewconfig.h"
56 #include "clientbufferviewmanager.h"
57 #include "clientignorelistmanager.h"
58 #include "coreconfigwizard.h"
59 #include "coreconnectdlg.h"
60 #include "coreconnection.h"
61 #include "coreconnectionstatuswidget.h"
62 #include "coreinfodlg.h"
63 #include "contextmenuactionprovider.h"
64 #include "debugbufferviewoverlay.h"
65 #include "debuglogwidget.h"
66 #include "debugmessagemodelfilter.h"
67 #include "flatproxymodel.h"
68 #include "iconloader.h"
69 #include "inputwidget.h"
70 #include "irclistmodel.h"
71 #include "ircconnectionwizard.h"
72 #include "jumpkeyhandler.h"
73 #include "legacysystemtray.h"
74 #include "msgprocessorstatuswidget.h"
75 #include "nicklistwidget.h"
76 #include "qtuiapplication.h"
77 #include "qtuimessageprocessor.h"
78 #include "qtuisettings.h"
79 #include "qtuistyle.h"
80 #include "settingsdlg.h"
81 #include "settingspagedlg.h"
82 #include "statusnotifieritem.h"
83 #include "toolbaractionprovider.h"
84 #include "topicwidget.h"
85 #include "verticaldock.h"
89 # include "desktopnotificationbackend.h"
92 # include "phononnotificationbackend.h"
94 # include "systraynotificationbackend.h"
95 # include "taskbarnotificationbackend.h"
97 # include "knotificationbackend.h"
101 # include "sslinfodlg.h"
104 #ifdef HAVE_INDICATEQT
105 #include "indicatornotificationbackend.h"
108 #include "settingspages/aliasessettingspage.h"
109 #include "settingspages/appearancesettingspage.h"
110 #include "settingspages/backlogsettingspage.h"
111 #include "settingspages/bufferviewsettingspage.h"
112 #include "settingspages/chatmonitorsettingspage.h"
113 #include "settingspages/chatviewsettingspage.h"
114 #include "settingspages/connectionsettingspage.h"
115 #include "settingspages/coreaccountsettingspage.h"
116 #include "settingspages/coreconnectionsettingspage.h"
117 #include "settingspages/highlightsettingspage.h"
118 #include "settingspages/identitiessettingspage.h"
119 #include "settingspages/ignorelistsettingspage.h"
120 #include "settingspages/inputwidgetsettingspage.h"
121 #include "settingspages/itemviewsettingspage.h"
122 #include "settingspages/networkssettingspage.h"
123 #include "settingspages/notificationssettingspage.h"
124 #include "settingspages/topicwidgetsettingspage.h"
126 MainWin::MainWin(QWidget *parent)
128 : KMainWindow(parent),
129 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
131 : QMainWindow(parent),
133 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
134 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
139 QtUiSettings uiSettings;
140 QString style = uiSettings.value("Style", QString()).toString();
141 if(!style.isEmpty()) {
142 QApplication::setStyle(style);
145 QApplication::setQuitOnLastWindowClosed(false);
147 setWindowTitle("Quassel IRC");
148 setWindowIconText("Quassel IRC");
151 installEventFilter(new JumpKeyHandler(this));
154 void MainWin::init() {
155 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
156 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
157 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
158 SLOT(messagesInserted(const QModelIndex &, int, int)));
159 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
160 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
162 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
163 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
164 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
165 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool*)), SLOT(handleNoSslInClient(bool *)));
166 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool*)), SLOT(handleNoSslInCore(bool *)));
168 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
172 setDockNestingEnabled(true);
173 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
174 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
175 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
176 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
178 // Order is sometimes important
193 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
194 # ifndef QT_NO_SYSTEMTRAYICON
195 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
198 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
201 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
205 QtUi::registerNotificationBackend(new KNotificationBackend(this));
206 #endif /* HAVE_KDE */
208 #ifdef HAVE_INDICATEQT
209 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
212 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
214 setDisconnectedState(); // Disable menus and stuff
217 setAutoSaveSettings();
220 // restore mainwin state
222 restoreStateFromSettings(s);
224 // restore locked state of docks
225 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
227 CoreConnection *conn = Client::coreConnection();
228 if(!conn->connectToCore()) {
229 // No autoconnect selected (or no accounts)
230 showCoreConnectionDlg();
234 MainWin::~MainWin() {
238 void MainWin::quit() {
240 saveStateToSettings(s);
242 QApplication::quit();
245 void MainWin::saveStateToSettings(UiSettings &s) {
246 s.setValue("MainWinSize", _normalSize);
247 s.setValue("MainWinPos", _normalPos);
248 s.setValue("MainWinState", saveState());
249 s.setValue("MainWinGeometry", saveGeometry());
250 s.setValue("MainWinMinimized", isMinimized());
251 s.setValue("MainWinMaximized", isMaximized());
252 s.setValue("MainWinHidden", !isVisible());
255 saveAutoSaveSettings();
259 void MainWin::restoreStateFromSettings(UiSettings &s) {
260 _normalSize = s.value("MainWinSize", size()).toSize();
261 _normalPos = s.value("MainWinPos", pos()).toPoint();
262 bool maximized = s.value("MainWinMaximized", false).toBool();
265 restoreGeometry(s.value("MainWinGeometry").toByteArray());
268 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
273 restoreState(s.value("MainWinState").toByteArray());
279 if(s.value("MainWinHidden").toBool() && QtUi::haveSystemTray())
280 QtUi::hideMainWidget();
281 else if(s.value("MainWinMinimized").toBool())
289 void MainWin::updateIcon() {
291 const int size = 128;
297 if(Client::isConnected())
298 icon = DesktopIcon("quassel", size);
300 icon = DesktopIcon("quassel_inactive", size);
302 qApp->setWindowIcon(icon);
305 void MainWin::setupActions() {
306 ActionCollection *coll = QtUi::actionCollection("General");
308 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
309 this, SLOT(showCoreConnectionDlg())));
310 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
311 Client::instance(), SLOT(disconnectFromCore())));
312 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
313 this, SLOT(showCoreInfoDlg())));
314 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
315 this, SLOT(on_actionConfigureNetworks_triggered())));
316 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
317 this, SLOT(quit()), tr("Ctrl+Q")));
320 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
321 this, SLOT(on_actionConfigureViews_triggered())));
323 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
324 lockAct->setCheckable(true);
325 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
327 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
328 0, 0, QKeySequence::Find))->setCheckable(true);
329 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
330 this, SLOT(showAwayLog())));
331 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
332 0, 0, tr("Ctrl+M")))->setCheckable(true);
334 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
335 0, 0))->setCheckable(true);
338 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
339 this, SLOT(showSettingsDlg()), tr("F7")));
342 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
343 this, SLOT(showAboutDlg())));
344 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
345 qApp, SLOT(aboutQt())));
346 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
347 this, SLOT(on_actionDebugNetworkModel_triggered())));
348 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
349 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
350 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
351 this, SLOT(on_actionDebugMessageModel_triggered())));
352 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
353 this, SLOT(on_actionDebugHotList_triggered())));
354 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
355 this, SLOT(on_actionDebugLog_triggered())));
356 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
357 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
360 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
361 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
364 void MainWin::setupMenus() {
365 ActionCollection *coll = QtUi::actionCollection("General");
367 _fileMenu = menuBar()->addMenu(tr("&File"));
369 static const QStringList coreActions = QStringList()
370 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
373 foreach(QString actionName, coreActions) {
374 coreAction = coll->action(actionName);
375 _fileMenu->addAction(coreAction);
376 flagRemoteCoreOnly(coreAction);
378 flagRemoteCoreOnly(_fileMenu->addSeparator());
380 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
381 _networksMenu->addAction(coll->action("ConfigureNetworks"));
382 _networksMenu->addSeparator();
383 _fileMenu->addSeparator();
384 _fileMenu->addAction(coll->action("Quit"));
386 _viewMenu = menuBar()->addMenu(tr("&View"));
387 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
388 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
389 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
390 _viewMenu->addSeparator();
392 _viewMenu->addAction(coll->action("ToggleMenuBar"));
393 _viewMenu->addAction(coll->action("ToggleStatusBar"));
394 _viewMenu->addAction(coll->action("ToggleSearchBar"));
396 coreAction = coll->action("ShowAwayLog");
397 flagRemoteCoreOnly(coreAction);
398 _viewMenu->addAction(coreAction);
400 _viewMenu->addSeparator();
401 _viewMenu->addAction(coll->action("LockLayout"));
403 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
405 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
406 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
408 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
410 _helpMenu = menuBar()->addMenu(tr("&Help"));
411 _helpMenu->addAction(coll->action("AboutQuassel"));
413 _helpMenu->addAction(coll->action("AboutQt"));
415 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
417 _helpMenu->addSeparator();
418 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
419 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
420 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
421 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
422 _helpDebugMenu->addAction(coll->action("DebugHotList"));
423 _helpDebugMenu->addAction(coll->action("DebugLog"));
424 _helpDebugMenu->addSeparator();
425 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
428 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
430 QtUiSettings uiSettings;
431 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
432 showMenuBar->setChecked(enabled);
433 enabled ? menuBar()->show() : menuBar()->hide();
435 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
436 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
439 void MainWin::setupBufferWidget() {
440 _bufferWidget = new BufferWidget(this);
441 _bufferWidget->setModel(Client::bufferModel());
442 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
443 setCentralWidget(_bufferWidget);
446 void MainWin::addBufferView(int bufferViewConfigId) {
447 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
450 void MainWin::addBufferView(ClientBufferViewConfig *config) {
454 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
455 BufferViewDock *dock = new BufferViewDock(config, this);
457 //create the view and initialize it's filter
458 BufferView *view = new BufferView(dock);
459 view->setFilteredModel(Client::bufferModel(), config);
460 view->installEventFilter(_inputWidget); // for key presses
462 Client::bufferModel()->synchronizeView(view);
464 dock->setWidget(view);
465 dock->setVisible(_layoutLoaded); // don't show before state has been restored
467 addDockWidget(Qt::LeftDockWidgetArea, dock);
468 _bufferViewsMenu->addAction(dock->toggleViewAction());
470 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
471 _bufferViews.append(dock);
474 void MainWin::removeBufferView(int bufferViewConfigId) {
476 BufferViewDock *dock;
477 foreach(QAction *action, _bufferViewsMenu->actions()) {
478 actionData = action->data();
479 if(!actionData.isValid())
482 dock = qobject_cast<BufferViewDock *>(action->parent());
483 if(dock && actionData.toInt() == bufferViewConfigId) {
484 removeAction(action);
485 _bufferViews.removeAll(dock);
486 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
492 void MainWin::bufferViewToggled(bool enabled) {
493 QAction *action = qobject_cast<QAction *>(sender());
495 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
498 // Make sure we don't toggle backlog fetch for a view we've already removed
499 if(!_bufferViews.contains(dock))
503 Client::bufferViewOverlay()->addView(dock->bufferViewId());
504 BufferViewConfig *config = dock->config();
505 if(config && config->isInitialized()) {
506 BufferIdList buffers;
507 if(config->networkId().isValid()) {
508 foreach(BufferId bufferId, config->bufferList()) {
509 if(Client::networkModel()->networkId(bufferId) == config->networkId())
512 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
513 if(Client::networkModel()->networkId(bufferId) == config->networkId())
517 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
519 Client::backlogManager()->checkForBacklog(buffers);
522 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
526 BufferView *MainWin::allBuffersView() const {
527 // "All Buffers" is always the first dock created
528 if(_bufferViews.count() > 0)
529 return _bufferViews[0]->bufferView();
533 void MainWin::showNotificationsDlg() {
534 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
538 void MainWin::on_actionConfigureNetworks_triggered() {
539 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
543 void MainWin::on_actionConfigureViews_triggered() {
544 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
548 void MainWin::on_actionLockLayout_toggled(bool lock) {
549 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
550 foreach(VerticalDock *dock, docks) {
551 dock->showTitle(!lock);
553 if(Client::bufferViewManager()) {
554 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
555 config->setLocked(lock);
558 QtUiSettings().setValue("LockLayout", lock);
561 void MainWin::setupNickWidget() {
563 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
564 nickDock->setObjectName("NickDock");
565 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
567 _nickListWidget = new NickListWidget(nickDock);
568 nickDock->setWidget(_nickListWidget);
570 addDockWidget(Qt::RightDockWidgetArea, nickDock);
571 _viewMenu->addAction(nickDock->toggleViewAction());
572 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
574 // See NickListDock::NickListDock();
575 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
577 // attach the NickListWidget to the BufferModel and the default selection
578 _nickListWidget->setModel(Client::bufferModel());
579 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
582 void MainWin::setupChatMonitor() {
583 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
584 dock->setObjectName("ChatMonitorDock");
586 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
587 _chatMonitorView = new ChatMonitorView(filter, this);
588 _chatMonitorView->setFocusProxy(_inputWidget);
589 _chatMonitorView->show();
590 dock->setWidget(_chatMonitorView);
593 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
594 _viewMenu->addAction(dock->toggleViewAction());
595 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
598 void MainWin::setupInputWidget() {
599 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
600 dock->setObjectName("InputDock");
602 _inputWidget = new InputWidget(dock);
603 dock->setWidget(_inputWidget);
605 addDockWidget(Qt::BottomDockWidgetArea, dock);
607 _viewMenu->addAction(dock->toggleViewAction());
608 dock->toggleViewAction()->setText(tr("Show Input Line"));
610 _inputWidget->setModel(Client::bufferModel());
611 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
613 _bufferWidget->setFocusProxy(_inputWidget);
615 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
617 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
620 void MainWin::setupTopicWidget() {
621 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
622 dock->setObjectName("TopicDock");
623 _topicWidget = new TopicWidget(dock);
625 dock->setWidget(_topicWidget);
627 _topicWidget->setModel(Client::bufferModel());
628 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
630 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
632 _viewMenu->addAction(dock->toggleViewAction());
633 dock->toggleViewAction()->setText(tr("Show Topic Line"));
636 void MainWin::setupTitleSetter() {
637 _titleSetter.setModel(Client::bufferModel());
638 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
641 void MainWin::setupStatusBar() {
642 // MessageProcessor progress
643 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
646 _coreConnectionStatusWidget->update();
647 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
649 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
651 QtUiSettings uiSettings;
653 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
654 showStatusbar->setChecked(enabled);
655 enabled ? statusBar()->show() : statusBar()->hide();
657 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
658 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
660 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
663 void MainWin::setupHotList() {
664 FlatProxyModel *flatProxy = new FlatProxyModel(this);
665 flatProxy->setSourceModel(Client::bufferModel());
666 _bufferHotList = new BufferHotListFilter(flatProxy);
669 void MainWin::saveMenuBarStatus(bool enabled) {
670 QtUiSettings uiSettings;
671 uiSettings.setValue("ShowMenuBar", enabled);
674 void MainWin::saveStatusBarStatus(bool enabled) {
675 QtUiSettings uiSettings;
676 uiSettings.setValue("ShowStatusBar", enabled);
679 void MainWin::setupSystray() {
681 _systemTray = new StatusNotifierItem(this);
682 #elif !defined QT_NO_SYSTEMTRAYICON
683 _systemTray = new LegacySystemTray(this);
685 _systemTray = new SystemTray(this); // dummy
690 void MainWin::setupToolBars() {
691 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
692 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
693 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
694 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
697 setUnifiedTitleAndToolBarOnMac(true);
701 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
703 _mainToolBar = new QToolBar(this);
704 _mainToolBar->setObjectName("MainToolBar");
706 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
707 addToolBar(_mainToolBar);
709 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
710 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
713 void MainWin::connectedToCore() {
714 Q_CHECK_PTR(Client::bufferViewManager());
715 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
716 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
717 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
722 void MainWin::setConnectedState() {
723 ActionCollection *coll = QtUi::actionCollection("General");
725 coll->action("ConnectCore")->setEnabled(false);
726 coll->action("DisconnectCore")->setEnabled(true);
727 coll->action("CoreInfo")->setEnabled(true);
729 foreach(QAction *action, _fileMenu->actions()) {
730 if(isRemoteCoreOnly(action))
731 action->setVisible(!Client::internalCore());
734 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
735 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
736 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
737 if(!Client::internalCore()) {
738 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
739 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
740 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
743 // _viewMenu->setEnabled(true);
744 if(!Client::internalCore())
745 statusBar()->showMessage(tr("Connected to core."));
747 statusBar()->clearMessage();
749 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
751 systemTray()->setState(SystemTray::Active);
753 if(Client::networkIds().isEmpty()) {
754 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
759 void MainWin::loadLayout() {
761 int accountId = Client::currentCoreAccount().accountId().toInt();
762 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
763 if(state.isEmpty()) {
764 // Make sure that the default bufferview is shown
765 if(_bufferViews.count())
766 _bufferViews.at(0)->show();
770 restoreState(state, accountId);
771 _layoutLoaded = true;
774 void MainWin::saveLayout() {
776 int accountId = Client::currentCoreAccount().accountId().toInt();
777 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
780 void MainWin::disconnectedFromCore() {
781 // save core specific layout and remove bufferviews;
783 _layoutLoaded = false;
786 BufferViewDock *dock;
787 foreach(QAction *action, _bufferViewsMenu->actions()) {
788 actionData = action->data();
789 if(!actionData.isValid())
792 dock = qobject_cast<BufferViewDock *>(action->parent());
793 if(dock && actionData.toInt() != -1) {
794 removeAction(action);
795 _bufferViews.removeAll(dock);
796 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
802 restoreState(s.value("MainWinState").toByteArray());
803 setDisconnectedState();
806 void MainWin::setDisconnectedState() {
807 ActionCollection *coll = QtUi::actionCollection("General");
808 //ui.menuCore->setEnabled(false);
809 coll->action("ConnectCore")->setEnabled(true);
810 coll->action("DisconnectCore")->setEnabled(false);
811 coll->action("CoreInfo")->setEnabled(false);
812 //_viewMenu->setEnabled(false);
813 statusBar()->showMessage(tr("Not connected to core."));
814 if(_msgProcessorStatusWidget)
815 _msgProcessorStatusWidget->setProgress(0, 0);
817 systemTray()->setState(SystemTray::Passive);
820 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
821 Q_UNUSED(errorMessage)
822 CoreConnectAuthDlg dlg(account, this);
823 *valid = (dlg.exec() == QDialog::Accepted);
826 void MainWin::handleNoSslInClient(bool *accepted) {
827 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
828 QMessageBox::Ignore|QMessageBox::Cancel, this);
829 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
830 box.setDefaultButton(QMessageBox::Ignore);
831 *accepted = box.exec() == QMessageBox::Ignore;
834 void MainWin::handleNoSslInCore(bool *accepted) {
835 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
836 QMessageBox::Ignore|QMessageBox::Cancel, this);
837 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
838 box.setDefaultButton(QMessageBox::Ignore);
839 *accepted = box.exec() == QMessageBox::Ignore;
845 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently) {
846 QString errorString = "<ul>";
847 foreach(const QSslError error, socket->sslErrors())
848 errorString += QString("<li>%1</li>").arg(error.errorString());
849 errorString += "</ul>";
851 QMessageBox box(QMessageBox::Warning,
852 tr("Untrusted Security Certificate"),
853 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
854 QMessageBox::Cancel, this);
855 box.setInformativeText(errorString);
856 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
857 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
859 QMessageBox::ButtonRole role;
862 role = box.buttonRole(box.clickedButton());
863 if(role == QMessageBox::HelpRole) {
864 SslInfoDlg dlg(socket, this);
867 } while(role == QMessageBox::HelpRole);
869 *accepted = role == QMessageBox::AcceptRole;
871 QMessageBox box2(QMessageBox::Warning,
872 tr("Untrusted Security Certificate"),
873 tr("Would you like to accept this certificate forever without being prompted?"),
875 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
876 box2.addButton(tr("Forever"), QMessageBox::YesRole);
878 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
882 #endif /* HAVE_SSL */
884 void MainWin::handleCoreConnectionError(const QString &error) {
885 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
888 void MainWin::showCoreConnectionDlg() {
889 CoreConnectDlg dlg(this);
890 if(dlg.exec() == QDialog::Accepted) {
891 AccountId accId = dlg.selectedAccount();
893 Client::coreConnection()->connectToCore(accId);
897 void MainWin::showCoreConfigWizard(const QVariantList &backends) {
898 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
903 void MainWin::showChannelList(NetworkId netId) {
904 ChannelListDlg *channelListDlg = new ChannelListDlg();
906 if(!netId.isValid()) {
907 QAction *action = qobject_cast<QAction *>(sender());
909 netId = action->data().value<NetworkId>();
912 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
913 channelListDlg->setNetwork(netId);
914 channelListDlg->show();
917 void MainWin::showIgnoreList(QString newRule) {
918 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
919 // prepare config dialog for new rule
920 if(!newRule.isEmpty())
921 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
925 void MainWin::showCoreInfoDlg() {
926 CoreInfoDlg(this).exec();
929 void MainWin::showAwayLog() {
932 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
933 _awayLog = new AwayLogView(filter, 0);
934 filter->setParent(_awayLog);
935 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
936 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
940 void MainWin::awayLogDestroyed() {
944 void MainWin::showSettingsDlg() {
945 SettingsDlg *dlg = new SettingsDlg();
947 //Category: Interface
948 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
949 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
950 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
951 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
952 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
953 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
954 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
955 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
956 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
957 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
960 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
961 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
962 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
963 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
964 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
966 // Category: Remote Cores
967 if(Quassel::runMode() != Quassel::Monolithic) {
968 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
969 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
975 void MainWin::showAboutDlg() {
976 AboutDlg(this).exec();
980 void MainWin::showShortcutsDlg() {
981 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
985 /********************************************************************************************************/
987 bool MainWin::event(QEvent *event) {
988 if(event->type() == QEvent::WindowActivate) {
989 BufferId buffer = Client::bufferModel()->currentBuffer();
991 QtUi::closeNotifications(buffer);
993 return QMainWindow::event(event);
996 void MainWin::moveEvent(QMoveEvent *event) {
997 if(!(windowState() & Qt::WindowMaximized))
998 _normalPos = event->pos();
1000 QMainWindow::moveEvent(event);
1003 void MainWin::resizeEvent(QResizeEvent *event) {
1004 if(!(windowState() & Qt::WindowMaximized))
1005 _normalSize = event->size();
1007 QMainWindow::resizeEvent(event);
1010 void MainWin::closeEvent(QCloseEvent *event) {
1012 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
1014 if(!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1015 QtUi::hideMainWidget();
1023 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1026 bool hasFocus = QApplication::activeWindow() != 0;
1028 for(int i = start; i <= end; i++) {
1029 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1030 if(!idx.isValid()) {
1031 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1034 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1035 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1038 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1039 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1041 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1044 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1045 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1046 Client::networkModel()->networkName(bufId))))
1048 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1049 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1050 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1051 AbstractNotificationBackend::NotificationType type;
1053 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1054 type = AbstractNotificationBackend::PrivMsg;
1055 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1056 type = AbstractNotificationBackend::PrivMsgFocused;
1057 else if(flags & Message::Highlight && !hasFocus)
1058 type = AbstractNotificationBackend::Highlight;
1060 type = AbstractNotificationBackend::HighlightFocused;
1062 QtUi::invokeNotification(bufId, type, sender, contents);
1067 void MainWin::currentBufferChanged(BufferId buffer) {
1068 if(buffer.isValid())
1069 QtUi::closeNotifications(buffer);
1072 void MainWin::clientNetworkCreated(NetworkId id) {
1073 const Network *net = Client::network(id);
1074 QAction *act = new QAction(net->networkName(), this);
1075 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1076 act->setData(QVariant::fromValue<NetworkId>(id));
1077 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1078 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1080 QAction *beforeAction = 0;
1081 foreach(QAction *action, _networksMenu->actions()) {
1082 if(!action->data().isValid()) // ignore stock actions
1084 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1085 beforeAction = action;
1089 _networksMenu->insertAction(beforeAction, act);
1092 void MainWin::clientNetworkUpdated() {
1093 const Network *net = qobject_cast<const Network *>(sender());
1097 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1101 action->setText(net->networkName());
1103 switch(net->connectionState()) {
1104 case Network::Initialized:
1105 action->setIcon(SmallIcon("network-connect"));
1107 case Network::Disconnected:
1108 action->setIcon(SmallIcon("network-disconnect"));
1111 action->setIcon(SmallIcon("network-wired"));
1115 void MainWin::clientNetworkRemoved(NetworkId id) {
1116 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1120 action->deleteLater();
1123 void MainWin::connectOrDisconnectFromNet() {
1124 QAction *act = qobject_cast<QAction *>(sender());
1126 const Network *net = Client::network(act->data().value<NetworkId>());
1128 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1129 else net->requestDisconnect();
1132 void MainWin::on_jumpHotBuffer_triggered() {
1133 if(!_bufferHotList->rowCount())
1136 QModelIndex topIndex = _bufferHotList->index(0, 0);
1137 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1138 Client::bufferModel()->switchToBuffer(bufferId);
1141 void MainWin::on_actionDebugNetworkModel_triggered() {
1142 QTreeView *view = new QTreeView;
1143 view->setAttribute(Qt::WA_DeleteOnClose);
1144 view->setWindowTitle("Debug NetworkModel View");
1145 view->setModel(Client::networkModel());
1146 view->setColumnWidth(0, 250);
1147 view->setColumnWidth(1, 250);
1148 view->setColumnWidth(2, 80);
1149 view->resize(610, 300);
1153 void MainWin::on_actionDebugHotList_triggered() {
1154 QTreeView *view = new QTreeView;
1155 view->setAttribute(Qt::WA_DeleteOnClose);
1156 view->setModel(_bufferHotList);
1160 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1161 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1162 overlay->setAttribute(Qt::WA_DeleteOnClose);
1166 void MainWin::on_actionDebugMessageModel_triggered() {
1167 QTableView *view = new QTableView(0);
1168 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1169 filter->setSourceModel(Client::messageModel());
1170 view->setModel(filter);
1171 view->setAttribute(Qt::WA_DeleteOnClose, true);
1172 view->verticalHeader()->hide();
1173 view->horizontalHeader()->setStretchLastSection(true);
1177 void MainWin::on_actionDebugLog_triggered() {
1178 DebugLogWidget *logWidget = new DebugLogWidget(0);
1182 void MainWin::showStatusBarMessage(const QString &message) {
1183 statusBar()->showMessage(message, 10000);