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 QAction *action = qobject_cast<QAction *>(sender());
496 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
499 // Make sure we don't toggle backlog fetch for a view we've already removed
500 if(!_bufferViews.contains(dock))
504 Client::bufferViewOverlay()->addView(dock->bufferViewId());
505 BufferViewConfig *config = dock->config();
506 if(config && config->isInitialized()) {
507 BufferIdList buffers;
508 if(config->networkId().isValid()) {
509 foreach(BufferId bufferId, config->bufferList()) {
510 if(Client::networkModel()->networkId(bufferId) == config->networkId())
513 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
514 if(Client::networkModel()->networkId(bufferId) == config->networkId())
518 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
520 Client::backlogManager()->checkForBacklog(buffers);
523 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
527 BufferView *MainWin::allBuffersView() const {
528 // "All Buffers" is always the first dock created
529 if(_bufferViews.count() > 0)
530 return _bufferViews[0]->bufferView();
534 void MainWin::showNotificationsDlg() {
535 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
539 void MainWin::on_actionConfigureNetworks_triggered() {
540 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
544 void MainWin::on_actionConfigureViews_triggered() {
545 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
549 void MainWin::on_actionLockLayout_toggled(bool lock) {
550 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
551 foreach(VerticalDock *dock, docks) {
552 dock->showTitle(!lock);
554 if(Client::bufferViewManager()) {
555 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
556 config->setLocked(lock);
559 QtUiSettings().setValue("LockLayout", lock);
562 void MainWin::setupNickWidget() {
564 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
565 nickDock->setObjectName("NickDock");
566 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
568 _nickListWidget = new NickListWidget(nickDock);
569 nickDock->setWidget(_nickListWidget);
571 addDockWidget(Qt::RightDockWidgetArea, nickDock);
572 _viewMenu->addAction(nickDock->toggleViewAction());
573 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
575 // See NickListDock::NickListDock();
576 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
578 // attach the NickListWidget to the BufferModel and the default selection
579 _nickListWidget->setModel(Client::bufferModel());
580 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
583 void MainWin::setupChatMonitor() {
584 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
585 dock->setObjectName("ChatMonitorDock");
587 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
588 _chatMonitorView = new ChatMonitorView(filter, this);
589 _chatMonitorView->setFocusProxy(_inputWidget);
590 _chatMonitorView->show();
591 dock->setWidget(_chatMonitorView);
594 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
595 _viewMenu->addAction(dock->toggleViewAction());
596 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
599 void MainWin::setupInputWidget() {
600 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
601 dock->setObjectName("InputDock");
603 _inputWidget = new InputWidget(dock);
604 dock->setWidget(_inputWidget);
606 addDockWidget(Qt::BottomDockWidgetArea, dock);
608 _viewMenu->addAction(dock->toggleViewAction());
609 dock->toggleViewAction()->setText(tr("Show Input Line"));
611 _inputWidget->setModel(Client::bufferModel());
612 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
614 _bufferWidget->setFocusProxy(_inputWidget);
616 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
618 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
621 void MainWin::setupTopicWidget() {
622 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
623 dock->setObjectName("TopicDock");
624 _topicWidget = new TopicWidget(dock);
626 dock->setWidget(_topicWidget);
628 _topicWidget->setModel(Client::bufferModel());
629 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
631 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
633 _viewMenu->addAction(dock->toggleViewAction());
634 dock->toggleViewAction()->setText(tr("Show Topic Line"));
637 void MainWin::setupTitleSetter() {
638 _titleSetter.setModel(Client::bufferModel());
639 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
642 void MainWin::setupStatusBar() {
643 // MessageProcessor progress
644 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
647 _coreConnectionStatusWidget->update();
648 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
650 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
652 QtUiSettings uiSettings;
654 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
655 showStatusbar->setChecked(enabled);
656 enabled ? statusBar()->show() : statusBar()->hide();
658 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
659 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
661 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
664 void MainWin::setupHotList() {
665 FlatProxyModel *flatProxy = new FlatProxyModel(this);
666 flatProxy->setSourceModel(Client::bufferModel());
667 _bufferHotList = new BufferHotListFilter(flatProxy);
670 void MainWin::saveMenuBarStatus(bool enabled) {
671 QtUiSettings uiSettings;
672 uiSettings.setValue("ShowMenuBar", enabled);
675 void MainWin::saveStatusBarStatus(bool enabled) {
676 QtUiSettings uiSettings;
677 uiSettings.setValue("ShowStatusBar", enabled);
680 void MainWin::setupSystray() {
682 _systemTray = new StatusNotifierItem(this);
683 #elif !defined QT_NO_SYSTEMTRAYICON
684 _systemTray = new LegacySystemTray(this);
686 _systemTray = new SystemTray(this); // dummy
691 void MainWin::setupToolBars() {
692 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
693 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
694 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
695 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
698 setUnifiedTitleAndToolBarOnMac(true);
702 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
704 _mainToolBar = new QToolBar(this);
705 _mainToolBar->setObjectName("MainToolBar");
707 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
708 addToolBar(_mainToolBar);
710 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
711 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
714 void MainWin::connectedToCore() {
715 Q_CHECK_PTR(Client::bufferViewManager());
716 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
717 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
718 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
723 void MainWin::setConnectedState() {
724 ActionCollection *coll = QtUi::actionCollection("General");
726 coll->action("ConnectCore")->setEnabled(false);
727 coll->action("DisconnectCore")->setEnabled(true);
728 coll->action("CoreInfo")->setEnabled(true);
730 foreach(QAction *action, _fileMenu->actions()) {
731 if(isRemoteCoreOnly(action))
732 action->setVisible(!Client::internalCore());
735 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
736 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
737 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
738 if(!Client::internalCore()) {
739 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
740 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
741 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
744 // _viewMenu->setEnabled(true);
745 if(!Client::internalCore())
746 statusBar()->showMessage(tr("Connected to core."));
748 statusBar()->clearMessage();
750 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
752 systemTray()->setState(SystemTray::Active);
754 if(Client::networkIds().isEmpty()) {
755 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
760 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
761 if(lastUsedBufferId.isValid())
762 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
766 void MainWin::loadLayout() {
768 int accountId = Client::currentCoreAccount().accountId().toInt();
769 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
770 if(state.isEmpty()) {
771 foreach(BufferViewDock *view, _bufferViews)
773 _layoutLoaded = true;
777 restoreState(state, accountId);
778 _layoutLoaded = true;
781 void MainWin::saveLayout() {
783 int accountId = _bufferViews.count()? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
785 s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
788 void MainWin::disconnectedFromCore() {
789 // save core specific layout and remove bufferviews;
791 _layoutLoaded = false;
794 BufferViewDock *dock;
795 foreach(QAction *action, _bufferViewsMenu->actions()) {
796 actionData = action->data();
797 if(!actionData.isValid())
800 dock = qobject_cast<BufferViewDock *>(action->parent());
801 if(dock && actionData.toInt() != -1) {
802 removeAction(action);
803 _bufferViews.removeAll(dock);
804 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
810 restoreState(s.value("MainWinState").toByteArray());
811 setDisconnectedState();
814 void MainWin::setDisconnectedState() {
815 ActionCollection *coll = QtUi::actionCollection("General");
816 //ui.menuCore->setEnabled(false);
817 coll->action("ConnectCore")->setEnabled(true);
818 coll->action("DisconnectCore")->setEnabled(false);
819 coll->action("CoreInfo")->setEnabled(false);
820 //_viewMenu->setEnabled(false);
821 statusBar()->showMessage(tr("Not connected to core."));
822 if(_msgProcessorStatusWidget)
823 _msgProcessorStatusWidget->setProgress(0, 0);
825 systemTray()->setState(SystemTray::Passive);
828 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
829 Q_UNUSED(errorMessage)
830 CoreConnectAuthDlg dlg(account, this);
831 *valid = (dlg.exec() == QDialog::Accepted);
834 void MainWin::handleNoSslInClient(bool *accepted) {
835 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client 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;
842 void MainWin::handleNoSslInCore(bool *accepted) {
843 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
844 QMessageBox::Ignore|QMessageBox::Cancel, this);
845 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
846 box.setDefaultButton(QMessageBox::Ignore);
847 *accepted = box.exec() == QMessageBox::Ignore;
853 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently) {
854 QString errorString = "<ul>";
855 foreach(const QSslError error, socket->sslErrors())
856 errorString += QString("<li>%1</li>").arg(error.errorString());
857 errorString += "</ul>";
859 QMessageBox box(QMessageBox::Warning,
860 tr("Untrusted Security Certificate"),
861 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
862 QMessageBox::Cancel, this);
863 box.setInformativeText(errorString);
864 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
865 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
867 QMessageBox::ButtonRole role;
870 role = box.buttonRole(box.clickedButton());
871 if(role == QMessageBox::HelpRole) {
872 SslInfoDlg dlg(socket, this);
875 } while(role == QMessageBox::HelpRole);
877 *accepted = role == QMessageBox::AcceptRole;
879 QMessageBox box2(QMessageBox::Warning,
880 tr("Untrusted Security Certificate"),
881 tr("Would you like to accept this certificate forever without being prompted?"),
883 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
884 box2.addButton(tr("Forever"), QMessageBox::YesRole);
886 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
890 #endif /* HAVE_SSL */
892 void MainWin::handleCoreConnectionError(const QString &error) {
893 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
896 void MainWin::showCoreConnectionDlg() {
897 CoreConnectDlg dlg(this);
898 if(dlg.exec() == QDialog::Accepted) {
899 AccountId accId = dlg.selectedAccount();
901 Client::coreConnection()->connectToCore(accId);
905 void MainWin::showCoreConfigWizard(const QVariantList &backends) {
906 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
911 void MainWin::showChannelList(NetworkId netId) {
912 ChannelListDlg *channelListDlg = new ChannelListDlg();
914 if(!netId.isValid()) {
915 QAction *action = qobject_cast<QAction *>(sender());
917 netId = action->data().value<NetworkId>();
920 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
921 channelListDlg->setNetwork(netId);
922 channelListDlg->show();
925 void MainWin::showIgnoreList(QString newRule) {
926 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
927 // prepare config dialog for new rule
928 if(!newRule.isEmpty())
929 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
933 void MainWin::showCoreInfoDlg() {
934 CoreInfoDlg(this).exec();
937 void MainWin::showAwayLog() {
940 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
941 _awayLog = new AwayLogView(filter, 0);
942 filter->setParent(_awayLog);
943 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
944 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
948 void MainWin::awayLogDestroyed() {
952 void MainWin::showSettingsDlg() {
953 SettingsDlg *dlg = new SettingsDlg();
955 //Category: Interface
956 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
957 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
958 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
959 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
960 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
961 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
962 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
963 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
964 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
965 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
968 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
969 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
970 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
971 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
972 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
974 // Category: Remote Cores
975 if(Quassel::runMode() != Quassel::Monolithic) {
976 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
977 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
983 void MainWin::showAboutDlg() {
984 AboutDlg(this).exec();
988 void MainWin::showShortcutsDlg() {
989 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
993 /********************************************************************************************************/
995 bool MainWin::event(QEvent *event) {
996 if(event->type() == QEvent::WindowActivate) {
997 BufferId buffer = Client::bufferModel()->currentBuffer();
999 QtUi::closeNotifications(buffer);
1001 return QMainWindow::event(event);
1004 void MainWin::moveEvent(QMoveEvent *event) {
1005 if(!(windowState() & Qt::WindowMaximized))
1006 _normalPos = event->pos();
1008 QMainWindow::moveEvent(event);
1011 void MainWin::resizeEvent(QResizeEvent *event) {
1012 if(!(windowState() & Qt::WindowMaximized))
1013 _normalSize = event->size();
1015 QMainWindow::resizeEvent(event);
1018 void MainWin::closeEvent(QCloseEvent *event) {
1020 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
1022 if(!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1023 QtUi::hideMainWidget();
1031 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1034 bool hasFocus = QApplication::activeWindow() != 0;
1036 for(int i = start; i <= end; i++) {
1037 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1038 if(!idx.isValid()) {
1039 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1042 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1043 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1046 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1047 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1049 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1052 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1053 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1054 Client::networkModel()->networkName(bufId))))
1056 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1057 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1058 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1059 AbstractNotificationBackend::NotificationType type;
1061 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1062 type = AbstractNotificationBackend::PrivMsg;
1063 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1064 type = AbstractNotificationBackend::PrivMsgFocused;
1065 else if(flags & Message::Highlight && !hasFocus)
1066 type = AbstractNotificationBackend::Highlight;
1068 type = AbstractNotificationBackend::HighlightFocused;
1070 QtUi::invokeNotification(bufId, type, sender, contents);
1075 void MainWin::currentBufferChanged(BufferId buffer) {
1076 if(buffer.isValid())
1077 QtUi::closeNotifications(buffer);
1080 void MainWin::clientNetworkCreated(NetworkId id) {
1081 const Network *net = Client::network(id);
1082 QAction *act = new QAction(net->networkName(), this);
1083 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1084 act->setData(QVariant::fromValue<NetworkId>(id));
1085 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1086 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1088 QAction *beforeAction = 0;
1089 foreach(QAction *action, _networksMenu->actions()) {
1090 if(!action->data().isValid()) // ignore stock actions
1092 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1093 beforeAction = action;
1097 _networksMenu->insertAction(beforeAction, act);
1100 void MainWin::clientNetworkUpdated() {
1101 const Network *net = qobject_cast<const Network *>(sender());
1105 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1109 action->setText(net->networkName());
1111 switch(net->connectionState()) {
1112 case Network::Initialized:
1113 action->setIcon(SmallIcon("network-connect"));
1115 case Network::Disconnected:
1116 action->setIcon(SmallIcon("network-disconnect"));
1119 action->setIcon(SmallIcon("network-wired"));
1123 void MainWin::clientNetworkRemoved(NetworkId id) {
1124 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1128 action->deleteLater();
1131 void MainWin::connectOrDisconnectFromNet() {
1132 QAction *act = qobject_cast<QAction *>(sender());
1134 const Network *net = Client::network(act->data().value<NetworkId>());
1136 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1137 else net->requestDisconnect();
1140 void MainWin::on_jumpHotBuffer_triggered() {
1141 if(!_bufferHotList->rowCount())
1144 QModelIndex topIndex = _bufferHotList->index(0, 0);
1145 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1146 Client::bufferModel()->switchToBuffer(bufferId);
1149 void MainWin::on_actionDebugNetworkModel_triggered() {
1150 QTreeView *view = new QTreeView;
1151 view->setAttribute(Qt::WA_DeleteOnClose);
1152 view->setWindowTitle("Debug NetworkModel View");
1153 view->setModel(Client::networkModel());
1154 view->setColumnWidth(0, 250);
1155 view->setColumnWidth(1, 250);
1156 view->setColumnWidth(2, 80);
1157 view->resize(610, 300);
1161 void MainWin::on_actionDebugHotList_triggered() {
1162 QTreeView *view = new QTreeView;
1163 view->setAttribute(Qt::WA_DeleteOnClose);
1164 view->setModel(_bufferHotList);
1168 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1169 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1170 overlay->setAttribute(Qt::WA_DeleteOnClose);
1174 void MainWin::on_actionDebugMessageModel_triggered() {
1175 QTableView *view = new QTableView(0);
1176 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1177 filter->setSourceModel(Client::messageModel());
1178 view->setModel(filter);
1179 view->setAttribute(Qt::WA_DeleteOnClose, true);
1180 view->verticalHeader()->hide();
1181 view->horizontalHeader()->setStretchLastSection(true);
1185 void MainWin::on_actionDebugLog_triggered() {
1186 DebugLogWidget *logWidget = new DebugLogWidget(0);
1190 void MainWin::showStatusBarMessage(const QString &message) {
1191 statusBar()->showMessage(message, 10000);