1 /***************************************************************************
2 * Copyright (C) 2005-2010 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 "phononnotificationbackend.h"
91 # include "systraynotificationbackend.h"
92 # include "taskbarnotificationbackend.h"
94 # include "knotificationbackend.h"
98 # include "sslinfodlg.h"
101 #ifdef HAVE_INDICATEQT
102 #include "indicatornotificationbackend.h"
105 #include "settingspages/aliasessettingspage.h"
106 #include "settingspages/appearancesettingspage.h"
107 #include "settingspages/backlogsettingspage.h"
108 #include "settingspages/bufferviewsettingspage.h"
109 #include "settingspages/chatmonitorsettingspage.h"
110 #include "settingspages/chatviewsettingspage.h"
111 #include "settingspages/connectionsettingspage.h"
112 #include "settingspages/coreaccountsettingspage.h"
113 #include "settingspages/coreconnectionsettingspage.h"
114 #include "settingspages/highlightsettingspage.h"
115 #include "settingspages/identitiessettingspage.h"
116 #include "settingspages/ignorelistsettingspage.h"
117 #include "settingspages/inputwidgetsettingspage.h"
118 #include "settingspages/itemviewsettingspage.h"
119 #include "settingspages/networkssettingspage.h"
120 #include "settingspages/notificationssettingspage.h"
121 #include "settingspages/topicwidgetsettingspage.h"
123 MainWin::MainWin(QWidget *parent)
125 : KMainWindow(parent),
126 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
128 : QMainWindow(parent),
130 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
131 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
136 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
138 QtUiSettings uiSettings;
139 QString style = uiSettings.value("Style", QString()).toString();
140 if(!style.isEmpty()) {
141 QApplication::setStyle(style);
144 QApplication::setQuitOnLastWindowClosed(false);
146 setWindowTitle("Quassel IRC");
147 setWindowIconText("Quassel IRC");
150 installEventFilter(new JumpKeyHandler(this));
153 void MainWin::init() {
154 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
155 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
156 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
157 SLOT(messagesInserted(const QModelIndex &, int, int)));
158 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
159 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
161 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
162 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
163 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
164 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool*)), SLOT(handleNoSslInClient(bool *)));
165 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool*)), SLOT(handleNoSslInCore(bool *)));
167 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
171 setDockNestingEnabled(true);
172 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
173 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
174 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
175 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
177 // Order is sometimes important
193 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
195 # ifndef QT_NO_SYSTEMTRAYICON
196 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
199 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
202 QtUi::registerNotificationBackend(new KNotificationBackend(this));
203 #endif /* HAVE_KDE */
205 #ifdef HAVE_INDICATEQT
206 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
209 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
211 setDisconnectedState(); // Disable menus and stuff
214 setAutoSaveSettings();
217 // restore mainwin state
219 restoreStateFromSettings(s);
221 // restore locked state of docks
222 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
224 CoreConnection *conn = Client::coreConnection();
225 if(!conn->connectToCore()) {
226 // No autoconnect selected (or no accounts)
227 showCoreConnectionDlg();
231 MainWin::~MainWin() {
235 void MainWin::quit() {
237 saveStateToSettings(s);
239 QApplication::quit();
242 void MainWin::saveStateToSettings(UiSettings &s) {
243 s.setValue("MainWinSize", _normalSize);
244 s.setValue("MainWinPos", _normalPos);
245 s.setValue("MainWinState", saveState());
246 s.setValue("MainWinGeometry", saveGeometry());
247 s.setValue("MainWinMinimized", isMinimized());
248 s.setValue("MainWinMaximized", isMaximized());
249 s.setValue("MainWinHidden", !isVisible());
250 BufferId lastBufId = Client::bufferModel()->currentBuffer();
251 if(lastBufId.isValid())
252 s.setValue("LastUsedBufferId", lastBufId.toInt());
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 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
317 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
318 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
321 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
322 this, SLOT(on_actionConfigureViews_triggered())));
324 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
325 lockAct->setCheckable(true);
326 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
328 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
329 0, 0, QKeySequence::Find))->setCheckable(true);
330 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
331 this, SLOT(showAwayLog())));
332 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
333 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
335 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
336 0, 0))->setCheckable(true);
339 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
340 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7)));
343 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
344 this, SLOT(showAboutDlg())));
345 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
346 qApp, SLOT(aboutQt())));
347 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
348 this, SLOT(on_actionDebugNetworkModel_triggered())));
349 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
350 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
351 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
352 this, SLOT(on_actionDebugMessageModel_triggered())));
353 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
354 this, SLOT(on_actionDebugHotList_triggered())));
355 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
356 this, SLOT(on_actionDebugLog_triggered())));
357 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
358 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
361 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
362 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
365 void MainWin::setupMenus() {
366 ActionCollection *coll = QtUi::actionCollection("General");
368 _fileMenu = menuBar()->addMenu(tr("&File"));
370 static const QStringList coreActions = QStringList()
371 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
374 foreach(QString actionName, coreActions) {
375 coreAction = coll->action(actionName);
376 _fileMenu->addAction(coreAction);
377 flagRemoteCoreOnly(coreAction);
379 flagRemoteCoreOnly(_fileMenu->addSeparator());
381 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
382 _networksMenu->addAction(coll->action("ConfigureNetworks"));
383 _networksMenu->addSeparator();
384 _fileMenu->addSeparator();
385 _fileMenu->addAction(coll->action("Quit"));
387 _viewMenu = menuBar()->addMenu(tr("&View"));
388 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
389 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
390 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
391 _viewMenu->addSeparator();
393 _viewMenu->addAction(coll->action("ToggleMenuBar"));
394 _viewMenu->addAction(coll->action("ToggleStatusBar"));
395 _viewMenu->addAction(coll->action("ToggleSearchBar"));
397 coreAction = coll->action("ShowAwayLog");
398 flagRemoteCoreOnly(coreAction);
399 _viewMenu->addAction(coreAction);
401 _viewMenu->addSeparator();
402 _viewMenu->addAction(coll->action("LockLayout"));
404 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
406 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
407 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
409 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
411 _helpMenu = menuBar()->addMenu(tr("&Help"));
412 _helpMenu->addAction(coll->action("AboutQuassel"));
414 _helpMenu->addAction(coll->action("AboutQt"));
416 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
418 _helpMenu->addSeparator();
419 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
420 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
421 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
422 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
423 _helpDebugMenu->addAction(coll->action("DebugHotList"));
424 _helpDebugMenu->addAction(coll->action("DebugLog"));
425 _helpDebugMenu->addSeparator();
426 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
429 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
431 QtUiSettings uiSettings;
432 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
433 showMenuBar->setChecked(enabled);
434 enabled ? menuBar()->show() : menuBar()->hide();
436 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
437 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
440 void MainWin::setupBufferWidget() {
441 _bufferWidget = new BufferWidget(this);
442 _bufferWidget->setModel(Client::bufferModel());
443 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
444 setCentralWidget(_bufferWidget);
447 void MainWin::addBufferView(int bufferViewConfigId) {
448 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
451 void MainWin::addBufferView(ClientBufferViewConfig *config) {
455 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
456 BufferViewDock *dock = new BufferViewDock(config, this);
458 //create the view and initialize it's filter
459 BufferView *view = new BufferView(dock);
460 view->setFilteredModel(Client::bufferModel(), config);
461 view->installEventFilter(_inputWidget); // for key presses
463 Client::bufferModel()->synchronizeView(view);
465 dock->setWidget(view);
466 dock->setVisible(_layoutLoaded); // don't show before state has been restored
468 addDockWidget(Qt::LeftDockWidgetArea, dock);
469 _bufferViewsMenu->addAction(dock->toggleViewAction());
471 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
472 _bufferViews.append(dock);
475 void MainWin::removeBufferView(int bufferViewConfigId) {
477 BufferViewDock *dock;
478 foreach(QAction *action, _bufferViewsMenu->actions()) {
479 actionData = action->data();
480 if(!actionData.isValid())
483 dock = qobject_cast<BufferViewDock *>(action->parent());
484 if(dock && actionData.toInt() == bufferViewConfigId) {
485 removeAction(action);
486 _bufferViews.removeAll(dock);
487 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
493 void MainWin::bufferViewToggled(bool enabled) {
494 if(!enabled && !isVisible()) {
495 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
496 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
499 QAction *action = qobject_cast<QAction *>(sender());
501 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
504 // Make sure we don't toggle backlog fetch for a view we've already removed
505 if(!_bufferViews.contains(dock))
509 Client::bufferViewOverlay()->addView(dock->bufferViewId());
511 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
515 BufferView *MainWin::allBuffersView() const {
516 // "All Buffers" is always the first dock created
517 if(_bufferViews.count() > 0)
518 return _bufferViews[0]->bufferView();
522 void MainWin::showNotificationsDlg() {
523 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
527 void MainWin::on_actionConfigureNetworks_triggered() {
528 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
532 void MainWin::on_actionConfigureViews_triggered() {
533 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
537 void MainWin::on_actionLockLayout_toggled(bool lock) {
538 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
539 foreach(VerticalDock *dock, docks) {
540 dock->showTitle(!lock);
542 if(Client::bufferViewManager()) {
543 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
544 config->setLocked(lock);
547 QtUiSettings().setValue("LockLayout", lock);
550 void MainWin::setupNickWidget() {
552 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
553 nickDock->setObjectName("NickDock");
554 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
556 _nickListWidget = new NickListWidget(nickDock);
557 nickDock->setWidget(_nickListWidget);
559 addDockWidget(Qt::RightDockWidgetArea, nickDock);
560 _viewMenu->addAction(nickDock->toggleViewAction());
561 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
563 // See NickListDock::NickListDock();
564 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
566 // attach the NickListWidget to the BufferModel and the default selection
567 _nickListWidget->setModel(Client::bufferModel());
568 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
571 void MainWin::setupChatMonitor() {
572 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
573 dock->setObjectName("ChatMonitorDock");
575 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
576 _chatMonitorView = new ChatMonitorView(filter, this);
577 _chatMonitorView->setFocusProxy(_inputWidget);
578 _chatMonitorView->show();
579 dock->setWidget(_chatMonitorView);
582 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
583 _viewMenu->addAction(dock->toggleViewAction());
584 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
587 void MainWin::setupInputWidget() {
588 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
589 dock->setObjectName("InputDock");
591 _inputWidget = new InputWidget(dock);
592 dock->setWidget(_inputWidget);
594 addDockWidget(Qt::BottomDockWidgetArea, dock);
596 _viewMenu->addAction(dock->toggleViewAction());
597 dock->toggleViewAction()->setText(tr("Show Input Line"));
599 _inputWidget->setModel(Client::bufferModel());
600 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
602 _bufferWidget->setFocusProxy(_inputWidget);
604 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
606 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
609 void MainWin::setupTopicWidget() {
610 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
611 dock->setObjectName("TopicDock");
612 _topicWidget = new TopicWidget(dock);
614 dock->setWidget(_topicWidget);
616 _topicWidget->setModel(Client::bufferModel());
617 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
619 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
621 _viewMenu->addAction(dock->toggleViewAction());
622 dock->toggleViewAction()->setText(tr("Show Topic Line"));
625 void MainWin::setupTitleSetter() {
626 _titleSetter.setModel(Client::bufferModel());
627 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
630 void MainWin::setupStatusBar() {
631 // MessageProcessor progress
632 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
635 _coreConnectionStatusWidget->update();
636 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
638 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
640 QtUiSettings uiSettings;
642 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
643 showStatusbar->setChecked(enabled);
644 enabled ? statusBar()->show() : statusBar()->hide();
646 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
647 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
649 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
652 void MainWin::setupHotList() {
653 FlatProxyModel *flatProxy = new FlatProxyModel(this);
654 flatProxy->setSourceModel(Client::bufferModel());
655 _bufferHotList = new BufferHotListFilter(flatProxy);
658 void MainWin::saveMenuBarStatus(bool enabled) {
659 QtUiSettings uiSettings;
660 uiSettings.setValue("ShowMenuBar", enabled);
663 void MainWin::saveStatusBarStatus(bool enabled) {
664 QtUiSettings uiSettings;
665 uiSettings.setValue("ShowStatusBar", enabled);
668 void MainWin::setupSystray() {
670 _systemTray = new StatusNotifierItem(this);
671 #elif !defined QT_NO_SYSTEMTRAYICON
672 _systemTray = new LegacySystemTray(this);
674 _systemTray = new SystemTray(this); // dummy
679 void MainWin::setupToolBars() {
680 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
681 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
682 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
683 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
686 setUnifiedTitleAndToolBarOnMac(true);
690 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
692 _mainToolBar = new QToolBar(this);
693 _mainToolBar->setObjectName("MainToolBar");
695 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
696 addToolBar(_mainToolBar);
698 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
699 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
702 void MainWin::connectedToCore() {
703 Q_CHECK_PTR(Client::bufferViewManager());
704 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
705 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
706 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
711 void MainWin::setConnectedState() {
712 ActionCollection *coll = QtUi::actionCollection("General");
714 coll->action("ConnectCore")->setEnabled(false);
715 coll->action("DisconnectCore")->setEnabled(true);
716 coll->action("CoreInfo")->setEnabled(true);
718 foreach(QAction *action, _fileMenu->actions()) {
719 if(isRemoteCoreOnly(action))
720 action->setVisible(!Client::internalCore());
723 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
724 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
725 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
726 if(!Client::internalCore()) {
727 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
728 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
729 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
732 // _viewMenu->setEnabled(true);
733 if(!Client::internalCore())
734 statusBar()->showMessage(tr("Connected to core."));
736 statusBar()->clearMessage();
738 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
740 systemTray()->setState(SystemTray::Active);
742 if(Client::networkIds().isEmpty()) {
743 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
748 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
749 if(lastUsedBufferId.isValid())
750 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
754 void MainWin::loadLayout() {
756 int accountId = Client::currentCoreAccount().accountId().toInt();
757 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
758 if(state.isEmpty()) {
759 foreach(BufferViewDock *view, _bufferViews)
761 _layoutLoaded = true;
765 restoreState(state, accountId);
766 _layoutLoaded = true;
769 void MainWin::saveLayout() {
771 int accountId = _bufferViews.count()? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
773 s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
776 void MainWin::disconnectedFromCore() {
777 // save core specific layout and remove bufferviews;
779 _layoutLoaded = false;
782 BufferViewDock *dock;
783 foreach(QAction *action, _bufferViewsMenu->actions()) {
784 actionData = action->data();
785 if(!actionData.isValid())
788 dock = qobject_cast<BufferViewDock *>(action->parent());
789 if(dock && actionData.toInt() != -1) {
790 removeAction(action);
791 _bufferViews.removeAll(dock);
797 restoreState(s.value("MainWinState").toByteArray());
798 setDisconnectedState();
801 void MainWin::setDisconnectedState() {
802 ActionCollection *coll = QtUi::actionCollection("General");
803 //ui.menuCore->setEnabled(false);
804 coll->action("ConnectCore")->setEnabled(true);
805 coll->action("DisconnectCore")->setEnabled(false);
806 coll->action("CoreInfo")->setEnabled(false);
807 //_viewMenu->setEnabled(false);
808 statusBar()->showMessage(tr("Not connected to core."));
809 if(_msgProcessorStatusWidget)
810 _msgProcessorStatusWidget->setProgress(0, 0);
812 systemTray()->setState(SystemTray::Passive);
815 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
816 Q_UNUSED(errorMessage)
817 CoreConnectAuthDlg dlg(account, this);
818 *valid = (dlg.exec() == QDialog::Accepted);
821 void MainWin::handleNoSslInClient(bool *accepted) {
822 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
823 QMessageBox::Ignore|QMessageBox::Cancel, this);
824 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
825 box.setDefaultButton(QMessageBox::Ignore);
826 *accepted = box.exec() == QMessageBox::Ignore;
829 void MainWin::handleNoSslInCore(bool *accepted) {
830 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
831 QMessageBox::Ignore|QMessageBox::Cancel, this);
832 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
833 box.setDefaultButton(QMessageBox::Ignore);
834 *accepted = box.exec() == QMessageBox::Ignore;
840 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently) {
841 QString errorString = "<ul>";
842 foreach(const QSslError error, socket->sslErrors())
843 errorString += QString("<li>%1</li>").arg(error.errorString());
844 errorString += "</ul>";
846 QMessageBox box(QMessageBox::Warning,
847 tr("Untrusted Security Certificate"),
848 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
849 QMessageBox::Cancel, this);
850 box.setInformativeText(errorString);
851 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
852 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
854 QMessageBox::ButtonRole role;
857 role = box.buttonRole(box.clickedButton());
858 if(role == QMessageBox::HelpRole) {
859 SslInfoDlg dlg(socket, this);
862 } while(role == QMessageBox::HelpRole);
864 *accepted = role == QMessageBox::AcceptRole;
866 QMessageBox box2(QMessageBox::Warning,
867 tr("Untrusted Security Certificate"),
868 tr("Would you like to accept this certificate forever without being prompted?"),
870 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
871 box2.addButton(tr("Forever"), QMessageBox::YesRole);
873 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
877 #endif /* HAVE_SSL */
879 void MainWin::handleCoreConnectionError(const QString &error) {
880 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
883 void MainWin::showCoreConnectionDlg() {
884 CoreConnectDlg dlg(this);
885 if(dlg.exec() == QDialog::Accepted) {
886 AccountId accId = dlg.selectedAccount();
888 Client::coreConnection()->connectToCore(accId);
892 void MainWin::showCoreConfigWizard(const QVariantList &backends) {
893 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
898 void MainWin::showChannelList(NetworkId netId) {
899 ChannelListDlg *channelListDlg = new ChannelListDlg();
901 if(!netId.isValid()) {
902 QAction *action = qobject_cast<QAction *>(sender());
904 netId = action->data().value<NetworkId>();
907 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
908 channelListDlg->setNetwork(netId);
909 channelListDlg->show();
912 void MainWin::showIgnoreList(QString newRule) {
913 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
914 // prepare config dialog for new rule
915 if(!newRule.isEmpty())
916 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
920 void MainWin::showCoreInfoDlg() {
921 CoreInfoDlg(this).exec();
924 void MainWin::showAwayLog() {
927 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
928 _awayLog = new AwayLogView(filter, 0);
929 filter->setParent(_awayLog);
930 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
931 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
935 void MainWin::awayLogDestroyed() {
939 void MainWin::showSettingsDlg() {
940 SettingsDlg *dlg = new SettingsDlg();
942 //Category: Interface
943 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
944 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
945 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
946 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
947 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
948 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
949 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
950 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
951 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
952 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
955 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
956 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
957 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
958 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
959 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
961 // Category: Remote Cores
962 if(Quassel::runMode() != Quassel::Monolithic) {
963 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
964 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
970 void MainWin::showAboutDlg() {
971 AboutDlg(this).exec();
975 void MainWin::showShortcutsDlg() {
976 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
980 /********************************************************************************************************/
982 bool MainWin::event(QEvent *event) {
983 if(event->type() == QEvent::WindowActivate) {
984 BufferId buffer = Client::bufferModel()->currentBuffer();
986 Client::instance()->markBufferAsRead(buffer);
988 return QMainWindow::event(event);
991 void MainWin::moveEvent(QMoveEvent *event) {
992 if(!(windowState() & Qt::WindowMaximized))
993 _normalPos = event->pos();
995 QMainWindow::moveEvent(event);
998 void MainWin::resizeEvent(QResizeEvent *event) {
999 if(!(windowState() & Qt::WindowMaximized))
1000 _normalSize = event->size();
1002 QMainWindow::resizeEvent(event);
1005 void MainWin::closeEvent(QCloseEvent *event) {
1007 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
1009 if(!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1010 QtUi::hideMainWidget();
1018 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1021 bool hasFocus = QApplication::activeWindow() != 0;
1023 for(int i = start; i <= end; i++) {
1024 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1025 if(!idx.isValid()) {
1026 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1029 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1030 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1033 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1034 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1036 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1039 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1040 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1041 Client::networkModel()->networkName(bufId))))
1043 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1044 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1045 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1046 AbstractNotificationBackend::NotificationType type;
1048 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1049 type = AbstractNotificationBackend::PrivMsg;
1050 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1051 type = AbstractNotificationBackend::PrivMsgFocused;
1052 else if(flags & Message::Highlight && !hasFocus)
1053 type = AbstractNotificationBackend::Highlight;
1055 type = AbstractNotificationBackend::HighlightFocused;
1057 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1062 void MainWin::currentBufferChanged(BufferId buffer) {
1063 if(buffer.isValid())
1064 Client::instance()->markBufferAsRead(buffer);
1067 void MainWin::clientNetworkCreated(NetworkId id) {
1068 const Network *net = Client::network(id);
1069 QAction *act = new QAction(net->networkName(), this);
1070 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1071 act->setData(QVariant::fromValue<NetworkId>(id));
1072 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1073 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1075 QAction *beforeAction = 0;
1076 foreach(QAction *action, _networksMenu->actions()) {
1077 if(!action->data().isValid()) // ignore stock actions
1079 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1080 beforeAction = action;
1084 _networksMenu->insertAction(beforeAction, act);
1087 void MainWin::clientNetworkUpdated() {
1088 const Network *net = qobject_cast<const Network *>(sender());
1092 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1096 action->setText(net->networkName());
1098 switch(net->connectionState()) {
1099 case Network::Initialized:
1100 action->setIcon(SmallIcon("network-connect"));
1102 case Network::Disconnected:
1103 action->setIcon(SmallIcon("network-disconnect"));
1106 action->setIcon(SmallIcon("network-wired"));
1110 void MainWin::clientNetworkRemoved(NetworkId id) {
1111 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1115 action->deleteLater();
1118 void MainWin::connectOrDisconnectFromNet() {
1119 QAction *act = qobject_cast<QAction *>(sender());
1121 const Network *net = Client::network(act->data().value<NetworkId>());
1123 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1124 else net->requestDisconnect();
1127 void MainWin::on_jumpHotBuffer_triggered() {
1128 if(!_bufferHotList->rowCount())
1131 QModelIndex topIndex = _bufferHotList->index(0, 0);
1132 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1133 Client::bufferModel()->switchToBuffer(bufferId);
1136 void MainWin::on_actionDebugNetworkModel_triggered() {
1137 QTreeView *view = new QTreeView;
1138 view->setAttribute(Qt::WA_DeleteOnClose);
1139 view->setWindowTitle("Debug NetworkModel View");
1140 view->setModel(Client::networkModel());
1141 view->setColumnWidth(0, 250);
1142 view->setColumnWidth(1, 250);
1143 view->setColumnWidth(2, 80);
1144 view->resize(610, 300);
1148 void MainWin::on_actionDebugHotList_triggered() {
1149 QTreeView *view = new QTreeView;
1150 view->setAttribute(Qt::WA_DeleteOnClose);
1151 view->setModel(_bufferHotList);
1155 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1156 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1157 overlay->setAttribute(Qt::WA_DeleteOnClose);
1161 void MainWin::on_actionDebugMessageModel_triggered() {
1162 QTableView *view = new QTableView(0);
1163 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1164 filter->setSourceModel(Client::messageModel());
1165 view->setModel(filter);
1166 view->setAttribute(Qt::WA_DeleteOnClose, true);
1167 view->verticalHeader()->hide();
1168 view->horizontalHeader()->setStretchLastSection(true);
1172 void MainWin::on_actionDebugLog_triggered() {
1173 DebugLogWidget *logWidget = new DebugLogWidget(0);
1177 void MainWin::showStatusBarMessage(const QString &message) {
1178 statusBar()->showMessage(message, 10000);