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 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
141 QtUiSettings uiSettings;
142 QString style = uiSettings.value("Style", QString()).toString();
143 if(!style.isEmpty()) {
144 QApplication::setStyle(style);
147 QApplication::setQuitOnLastWindowClosed(false);
149 setWindowTitle("Quassel IRC");
150 setWindowIconText("Quassel IRC");
153 installEventFilter(new JumpKeyHandler(this));
156 void MainWin::init() {
157 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
158 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
159 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
160 SLOT(messagesInserted(const QModelIndex &, int, int)));
161 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
162 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
164 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
165 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
166 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
167 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool*)), SLOT(handleNoSslInClient(bool *)));
168 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool*)), SLOT(handleNoSslInCore(bool *)));
170 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
174 setDockNestingEnabled(true);
175 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
176 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
177 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
178 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
180 // Order is sometimes important
195 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
196 # ifndef QT_NO_SYSTEMTRAYICON
197 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
200 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
203 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
207 QtUi::registerNotificationBackend(new KNotificationBackend(this));
208 #endif /* HAVE_KDE */
210 #ifdef HAVE_INDICATEQT
211 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
214 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
216 setDisconnectedState(); // Disable menus and stuff
219 setAutoSaveSettings();
222 // restore mainwin state
224 restoreStateFromSettings(s);
226 // restore locked state of docks
227 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
229 CoreConnection *conn = Client::coreConnection();
230 if(!conn->connectToCore()) {
231 // No autoconnect selected (or no accounts)
232 showCoreConnectionDlg();
236 MainWin::~MainWin() {
240 void MainWin::quit() {
242 saveStateToSettings(s);
244 QApplication::quit();
247 void MainWin::saveStateToSettings(UiSettings &s) {
248 s.setValue("MainWinSize", _normalSize);
249 s.setValue("MainWinPos", _normalPos);
250 s.setValue("MainWinState", saveState());
251 s.setValue("MainWinGeometry", saveGeometry());
252 s.setValue("MainWinMinimized", isMinimized());
253 s.setValue("MainWinMaximized", isMaximized());
254 s.setValue("MainWinHidden", !isVisible());
257 saveAutoSaveSettings();
261 void MainWin::restoreStateFromSettings(UiSettings &s) {
262 _normalSize = s.value("MainWinSize", size()).toSize();
263 _normalPos = s.value("MainWinPos", pos()).toPoint();
264 bool maximized = s.value("MainWinMaximized", false).toBool();
267 restoreGeometry(s.value("MainWinGeometry").toByteArray());
270 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
275 restoreState(s.value("MainWinState").toByteArray());
281 if(s.value("MainWinHidden").toBool() && QtUi::haveSystemTray())
282 QtUi::hideMainWidget();
283 else if(s.value("MainWinMinimized").toBool())
291 void MainWin::updateIcon() {
293 const int size = 128;
299 if(Client::isConnected())
300 icon = DesktopIcon("quassel", size);
302 icon = DesktopIcon("quassel_inactive", size);
304 qApp->setWindowIcon(icon);
307 void MainWin::setupActions() {
308 ActionCollection *coll = QtUi::actionCollection("General");
310 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
311 this, SLOT(showCoreConnectionDlg())));
312 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
313 Client::instance(), SLOT(disconnectFromCore())));
314 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
315 this, SLOT(showCoreInfoDlg())));
316 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
317 this, SLOT(on_actionConfigureNetworks_triggered())));
318 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
319 this, SLOT(quit()), tr("Ctrl+Q")));
322 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
323 this, SLOT(on_actionConfigureViews_triggered())));
325 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
326 lockAct->setCheckable(true);
327 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
329 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
330 0, 0, QKeySequence::Find))->setCheckable(true);
331 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
332 this, SLOT(showAwayLog())));
333 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
334 0, 0, tr("Ctrl+M")))->setCheckable(true);
336 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
337 0, 0))->setCheckable(true);
340 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
341 this, SLOT(showSettingsDlg()), tr("F7")));
344 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
345 this, SLOT(showAboutDlg())));
346 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
347 qApp, SLOT(aboutQt())));
348 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
349 this, SLOT(on_actionDebugNetworkModel_triggered())));
350 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
351 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
352 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
353 this, SLOT(on_actionDebugMessageModel_triggered())));
354 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
355 this, SLOT(on_actionDebugHotList_triggered())));
356 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
357 this, SLOT(on_actionDebugLog_triggered())));
358 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
359 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
362 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
363 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
366 void MainWin::setupMenus() {
367 ActionCollection *coll = QtUi::actionCollection("General");
369 _fileMenu = menuBar()->addMenu(tr("&File"));
371 static const QStringList coreActions = QStringList()
372 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
375 foreach(QString actionName, coreActions) {
376 coreAction = coll->action(actionName);
377 _fileMenu->addAction(coreAction);
378 flagRemoteCoreOnly(coreAction);
380 flagRemoteCoreOnly(_fileMenu->addSeparator());
382 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
383 _networksMenu->addAction(coll->action("ConfigureNetworks"));
384 _networksMenu->addSeparator();
385 _fileMenu->addSeparator();
386 _fileMenu->addAction(coll->action("Quit"));
388 _viewMenu = menuBar()->addMenu(tr("&View"));
389 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
390 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
391 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
392 _viewMenu->addSeparator();
394 _viewMenu->addAction(coll->action("ToggleMenuBar"));
395 _viewMenu->addAction(coll->action("ToggleStatusBar"));
396 _viewMenu->addAction(coll->action("ToggleSearchBar"));
398 coreAction = coll->action("ShowAwayLog");
399 flagRemoteCoreOnly(coreAction);
400 _viewMenu->addAction(coreAction);
402 _viewMenu->addSeparator();
403 _viewMenu->addAction(coll->action("LockLayout"));
405 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
407 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
408 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
410 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
412 _helpMenu = menuBar()->addMenu(tr("&Help"));
413 _helpMenu->addAction(coll->action("AboutQuassel"));
415 _helpMenu->addAction(coll->action("AboutQt"));
417 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
419 _helpMenu->addSeparator();
420 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
421 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
422 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
423 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
424 _helpDebugMenu->addAction(coll->action("DebugHotList"));
425 _helpDebugMenu->addAction(coll->action("DebugLog"));
426 _helpDebugMenu->addSeparator();
427 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
430 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
432 QtUiSettings uiSettings;
433 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
434 showMenuBar->setChecked(enabled);
435 enabled ? menuBar()->show() : menuBar()->hide();
437 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
438 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
441 void MainWin::setupBufferWidget() {
442 _bufferWidget = new BufferWidget(this);
443 _bufferWidget->setModel(Client::bufferModel());
444 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
445 setCentralWidget(_bufferWidget);
448 void MainWin::addBufferView(int bufferViewConfigId) {
449 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
452 void MainWin::addBufferView(ClientBufferViewConfig *config) {
456 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
457 BufferViewDock *dock = new BufferViewDock(config, this);
459 //create the view and initialize it's filter
460 BufferView *view = new BufferView(dock);
461 view->setFilteredModel(Client::bufferModel(), config);
462 view->installEventFilter(_inputWidget); // for key presses
464 Client::bufferModel()->synchronizeView(view);
466 dock->setWidget(view);
467 dock->setVisible(_layoutLoaded); // don't show before state has been restored
469 addDockWidget(Qt::LeftDockWidgetArea, dock);
470 _bufferViewsMenu->addAction(dock->toggleViewAction());
472 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
473 _bufferViews.append(dock);
476 void MainWin::removeBufferView(int bufferViewConfigId) {
478 BufferViewDock *dock;
479 foreach(QAction *action, _bufferViewsMenu->actions()) {
480 actionData = action->data();
481 if(!actionData.isValid())
484 dock = qobject_cast<BufferViewDock *>(action->parent());
485 if(dock && actionData.toInt() == bufferViewConfigId) {
486 removeAction(action);
487 _bufferViews.removeAll(dock);
488 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
494 void MainWin::bufferViewToggled(bool enabled) {
495 QAction *action = qobject_cast<QAction *>(sender());
497 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
500 // Make sure we don't toggle backlog fetch for a view we've already removed
501 if(!_bufferViews.contains(dock))
505 Client::bufferViewOverlay()->addView(dock->bufferViewId());
506 BufferViewConfig *config = dock->config();
507 if(config && config->isInitialized()) {
508 BufferIdList buffers;
509 if(config->networkId().isValid()) {
510 foreach(BufferId bufferId, config->bufferList()) {
511 if(Client::networkModel()->networkId(bufferId) == config->networkId())
514 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
515 if(Client::networkModel()->networkId(bufferId) == config->networkId())
519 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
521 Client::backlogManager()->checkForBacklog(buffers);
524 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
528 BufferView *MainWin::allBuffersView() const {
529 // "All Buffers" is always the first dock created
530 if(_bufferViews.count() > 0)
531 return _bufferViews[0]->bufferView();
535 void MainWin::showNotificationsDlg() {
536 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
540 void MainWin::on_actionConfigureNetworks_triggered() {
541 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
545 void MainWin::on_actionConfigureViews_triggered() {
546 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
550 void MainWin::on_actionLockLayout_toggled(bool lock) {
551 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
552 foreach(VerticalDock *dock, docks) {
553 dock->showTitle(!lock);
555 if(Client::bufferViewManager()) {
556 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
557 config->setLocked(lock);
560 QtUiSettings().setValue("LockLayout", lock);
563 void MainWin::setupNickWidget() {
565 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
566 nickDock->setObjectName("NickDock");
567 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
569 _nickListWidget = new NickListWidget(nickDock);
570 nickDock->setWidget(_nickListWidget);
572 addDockWidget(Qt::RightDockWidgetArea, nickDock);
573 _viewMenu->addAction(nickDock->toggleViewAction());
574 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
576 // See NickListDock::NickListDock();
577 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
579 // attach the NickListWidget to the BufferModel and the default selection
580 _nickListWidget->setModel(Client::bufferModel());
581 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
584 void MainWin::setupChatMonitor() {
585 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
586 dock->setObjectName("ChatMonitorDock");
588 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
589 _chatMonitorView = new ChatMonitorView(filter, this);
590 _chatMonitorView->setFocusProxy(_inputWidget);
591 _chatMonitorView->show();
592 dock->setWidget(_chatMonitorView);
595 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
596 _viewMenu->addAction(dock->toggleViewAction());
597 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
600 void MainWin::setupInputWidget() {
601 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
602 dock->setObjectName("InputDock");
604 _inputWidget = new InputWidget(dock);
605 dock->setWidget(_inputWidget);
607 addDockWidget(Qt::BottomDockWidgetArea, dock);
609 _viewMenu->addAction(dock->toggleViewAction());
610 dock->toggleViewAction()->setText(tr("Show Input Line"));
612 _inputWidget->setModel(Client::bufferModel());
613 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
615 _bufferWidget->setFocusProxy(_inputWidget);
617 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
619 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
622 void MainWin::setupTopicWidget() {
623 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
624 dock->setObjectName("TopicDock");
625 _topicWidget = new TopicWidget(dock);
627 dock->setWidget(_topicWidget);
629 _topicWidget->setModel(Client::bufferModel());
630 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
632 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
634 _viewMenu->addAction(dock->toggleViewAction());
635 dock->toggleViewAction()->setText(tr("Show Topic Line"));
638 void MainWin::setupTitleSetter() {
639 _titleSetter.setModel(Client::bufferModel());
640 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
643 void MainWin::setupStatusBar() {
644 // MessageProcessor progress
645 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
648 _coreConnectionStatusWidget->update();
649 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
651 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
653 QtUiSettings uiSettings;
655 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
656 showStatusbar->setChecked(enabled);
657 enabled ? statusBar()->show() : statusBar()->hide();
659 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
660 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
662 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
665 void MainWin::setupHotList() {
666 FlatProxyModel *flatProxy = new FlatProxyModel(this);
667 flatProxy->setSourceModel(Client::bufferModel());
668 _bufferHotList = new BufferHotListFilter(flatProxy);
671 void MainWin::saveMenuBarStatus(bool enabled) {
672 QtUiSettings uiSettings;
673 uiSettings.setValue("ShowMenuBar", enabled);
676 void MainWin::saveStatusBarStatus(bool enabled) {
677 QtUiSettings uiSettings;
678 uiSettings.setValue("ShowStatusBar", enabled);
681 void MainWin::setupSystray() {
683 _systemTray = new StatusNotifierItem(this);
684 #elif !defined QT_NO_SYSTEMTRAYICON
685 _systemTray = new LegacySystemTray(this);
687 _systemTray = new SystemTray(this); // dummy
692 void MainWin::setupToolBars() {
693 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
694 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
695 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
696 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
699 setUnifiedTitleAndToolBarOnMac(true);
703 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
705 _mainToolBar = new QToolBar(this);
706 _mainToolBar->setObjectName("MainToolBar");
708 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
709 addToolBar(_mainToolBar);
711 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
712 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
715 void MainWin::connectedToCore() {
716 Q_CHECK_PTR(Client::bufferViewManager());
717 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
718 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
719 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
724 void MainWin::setConnectedState() {
725 ActionCollection *coll = QtUi::actionCollection("General");
727 coll->action("ConnectCore")->setEnabled(false);
728 coll->action("DisconnectCore")->setEnabled(true);
729 coll->action("CoreInfo")->setEnabled(true);
731 foreach(QAction *action, _fileMenu->actions()) {
732 if(isRemoteCoreOnly(action))
733 action->setVisible(!Client::internalCore());
736 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
737 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
738 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
739 if(!Client::internalCore()) {
740 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
741 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
742 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
745 // _viewMenu->setEnabled(true);
746 if(!Client::internalCore())
747 statusBar()->showMessage(tr("Connected to core."));
749 statusBar()->clearMessage();
751 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
753 systemTray()->setState(SystemTray::Active);
755 if(Client::networkIds().isEmpty()) {
756 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
761 void MainWin::loadLayout() {
763 int accountId = Client::currentCoreAccount().accountId().toInt();
764 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
765 if(state.isEmpty()) {
766 // Make sure that the default bufferview is shown
767 if(_bufferViews.count())
768 _bufferViews.at(0)->show();
772 restoreState(state, accountId);
773 _layoutLoaded = true;
776 void MainWin::saveLayout() {
778 int accountId = _bufferViews.count()? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
780 s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
783 void MainWin::disconnectedFromCore() {
784 // save core specific layout and remove bufferviews;
786 _layoutLoaded = false;
789 BufferViewDock *dock;
790 foreach(QAction *action, _bufferViewsMenu->actions()) {
791 actionData = action->data();
792 if(!actionData.isValid())
795 dock = qobject_cast<BufferViewDock *>(action->parent());
796 if(dock && actionData.toInt() != -1) {
797 removeAction(action);
798 _bufferViews.removeAll(dock);
799 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
805 restoreState(s.value("MainWinState").toByteArray());
806 setDisconnectedState();
809 void MainWin::setDisconnectedState() {
810 ActionCollection *coll = QtUi::actionCollection("General");
811 //ui.menuCore->setEnabled(false);
812 coll->action("ConnectCore")->setEnabled(true);
813 coll->action("DisconnectCore")->setEnabled(false);
814 coll->action("CoreInfo")->setEnabled(false);
815 //_viewMenu->setEnabled(false);
816 statusBar()->showMessage(tr("Not connected to core."));
817 if(_msgProcessorStatusWidget)
818 _msgProcessorStatusWidget->setProgress(0, 0);
820 systemTray()->setState(SystemTray::Passive);
823 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
824 Q_UNUSED(errorMessage)
825 CoreConnectAuthDlg dlg(account, this);
826 *valid = (dlg.exec() == QDialog::Accepted);
829 void MainWin::handleNoSslInClient(bool *accepted) {
830 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client 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;
837 void MainWin::handleNoSslInCore(bool *accepted) {
838 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
839 QMessageBox::Ignore|QMessageBox::Cancel, this);
840 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
841 box.setDefaultButton(QMessageBox::Ignore);
842 *accepted = box.exec() == QMessageBox::Ignore;
848 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently) {
849 QString errorString = "<ul>";
850 foreach(const QSslError error, socket->sslErrors())
851 errorString += QString("<li>%1</li>").arg(error.errorString());
852 errorString += "</ul>";
854 QMessageBox box(QMessageBox::Warning,
855 tr("Untrusted Security Certificate"),
856 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
857 QMessageBox::Cancel, this);
858 box.setInformativeText(errorString);
859 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
860 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
862 QMessageBox::ButtonRole role;
865 role = box.buttonRole(box.clickedButton());
866 if(role == QMessageBox::HelpRole) {
867 SslInfoDlg dlg(socket, this);
870 } while(role == QMessageBox::HelpRole);
872 *accepted = role == QMessageBox::AcceptRole;
874 QMessageBox box2(QMessageBox::Warning,
875 tr("Untrusted Security Certificate"),
876 tr("Would you like to accept this certificate forever without being prompted?"),
878 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
879 box2.addButton(tr("Forever"), QMessageBox::YesRole);
881 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
885 #endif /* HAVE_SSL */
887 void MainWin::handleCoreConnectionError(const QString &error) {
888 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
891 void MainWin::showCoreConnectionDlg() {
892 CoreConnectDlg dlg(this);
893 if(dlg.exec() == QDialog::Accepted) {
894 AccountId accId = dlg.selectedAccount();
896 Client::coreConnection()->connectToCore(accId);
900 void MainWin::showCoreConfigWizard(const QVariantList &backends) {
901 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
906 void MainWin::showChannelList(NetworkId netId) {
907 ChannelListDlg *channelListDlg = new ChannelListDlg();
909 if(!netId.isValid()) {
910 QAction *action = qobject_cast<QAction *>(sender());
912 netId = action->data().value<NetworkId>();
915 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
916 channelListDlg->setNetwork(netId);
917 channelListDlg->show();
920 void MainWin::showIgnoreList(QString newRule) {
921 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
922 // prepare config dialog for new rule
923 if(!newRule.isEmpty())
924 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
928 void MainWin::showCoreInfoDlg() {
929 CoreInfoDlg(this).exec();
932 void MainWin::showAwayLog() {
935 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
936 _awayLog = new AwayLogView(filter, 0);
937 filter->setParent(_awayLog);
938 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
939 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
943 void MainWin::awayLogDestroyed() {
947 void MainWin::showSettingsDlg() {
948 SettingsDlg *dlg = new SettingsDlg();
950 //Category: Interface
951 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
952 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
953 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
954 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
955 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
956 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
957 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
958 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
959 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
960 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
963 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
964 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
965 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
966 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
967 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
969 // Category: Remote Cores
970 if(Quassel::runMode() != Quassel::Monolithic) {
971 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
972 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
978 void MainWin::showAboutDlg() {
979 AboutDlg(this).exec();
983 void MainWin::showShortcutsDlg() {
984 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
988 /********************************************************************************************************/
990 bool MainWin::event(QEvent *event) {
991 if(event->type() == QEvent::WindowActivate) {
992 BufferId buffer = Client::bufferModel()->currentBuffer();
994 QtUi::closeNotifications(buffer);
996 return QMainWindow::event(event);
999 void MainWin::moveEvent(QMoveEvent *event) {
1000 if(!(windowState() & Qt::WindowMaximized))
1001 _normalPos = event->pos();
1003 QMainWindow::moveEvent(event);
1006 void MainWin::resizeEvent(QResizeEvent *event) {
1007 if(!(windowState() & Qt::WindowMaximized))
1008 _normalSize = event->size();
1010 QMainWindow::resizeEvent(event);
1013 void MainWin::closeEvent(QCloseEvent *event) {
1015 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
1017 if(!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1018 QtUi::hideMainWidget();
1026 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1029 bool hasFocus = QApplication::activeWindow() != 0;
1031 for(int i = start; i <= end; i++) {
1032 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1033 if(!idx.isValid()) {
1034 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1037 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1038 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1041 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1042 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1044 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1047 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1048 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1049 Client::networkModel()->networkName(bufId))))
1051 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1052 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1053 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1054 AbstractNotificationBackend::NotificationType type;
1056 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1057 type = AbstractNotificationBackend::PrivMsg;
1058 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1059 type = AbstractNotificationBackend::PrivMsgFocused;
1060 else if(flags & Message::Highlight && !hasFocus)
1061 type = AbstractNotificationBackend::Highlight;
1063 type = AbstractNotificationBackend::HighlightFocused;
1065 QtUi::invokeNotification(bufId, type, sender, contents);
1070 void MainWin::currentBufferChanged(BufferId buffer) {
1071 if(buffer.isValid())
1072 QtUi::closeNotifications(buffer);
1075 void MainWin::clientNetworkCreated(NetworkId id) {
1076 const Network *net = Client::network(id);
1077 QAction *act = new QAction(net->networkName(), this);
1078 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1079 act->setData(QVariant::fromValue<NetworkId>(id));
1080 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1081 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1083 QAction *beforeAction = 0;
1084 foreach(QAction *action, _networksMenu->actions()) {
1085 if(!action->data().isValid()) // ignore stock actions
1087 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1088 beforeAction = action;
1092 _networksMenu->insertAction(beforeAction, act);
1095 void MainWin::clientNetworkUpdated() {
1096 const Network *net = qobject_cast<const Network *>(sender());
1100 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1104 action->setText(net->networkName());
1106 switch(net->connectionState()) {
1107 case Network::Initialized:
1108 action->setIcon(SmallIcon("network-connect"));
1110 case Network::Disconnected:
1111 action->setIcon(SmallIcon("network-disconnect"));
1114 action->setIcon(SmallIcon("network-wired"));
1118 void MainWin::clientNetworkRemoved(NetworkId id) {
1119 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1123 action->deleteLater();
1126 void MainWin::connectOrDisconnectFromNet() {
1127 QAction *act = qobject_cast<QAction *>(sender());
1129 const Network *net = Client::network(act->data().value<NetworkId>());
1131 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1132 else net->requestDisconnect();
1135 void MainWin::on_jumpHotBuffer_triggered() {
1136 if(!_bufferHotList->rowCount())
1139 QModelIndex topIndex = _bufferHotList->index(0, 0);
1140 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1141 Client::bufferModel()->switchToBuffer(bufferId);
1144 void MainWin::on_actionDebugNetworkModel_triggered() {
1145 QTreeView *view = new QTreeView;
1146 view->setAttribute(Qt::WA_DeleteOnClose);
1147 view->setWindowTitle("Debug NetworkModel View");
1148 view->setModel(Client::networkModel());
1149 view->setColumnWidth(0, 250);
1150 view->setColumnWidth(1, 250);
1151 view->setColumnWidth(2, 80);
1152 view->resize(610, 300);
1156 void MainWin::on_actionDebugHotList_triggered() {
1157 QTreeView *view = new QTreeView;
1158 view->setAttribute(Qt::WA_DeleteOnClose);
1159 view->setModel(_bufferHotList);
1163 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1164 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1165 overlay->setAttribute(Qt::WA_DeleteOnClose);
1169 void MainWin::on_actionDebugMessageModel_triggered() {
1170 QTableView *view = new QTableView(0);
1171 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1172 filter->setSourceModel(Client::messageModel());
1173 view->setModel(filter);
1174 view->setAttribute(Qt::WA_DeleteOnClose, true);
1175 view->verticalHeader()->hide();
1176 view->horizontalHeader()->setStretchLastSection(true);
1180 void MainWin::on_actionDebugLog_triggered() {
1181 DebugLogWidget *logWidget = new DebugLogWidget(0);
1185 void MainWin::showStatusBarMessage(const QString &message) {
1186 statusBar()->showMessage(message, 10000);