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 "coreconnectdlg.h"
59 #include "coreconnection.h"
60 #include "coreconnectionstatuswidget.h"
61 #include "coreinfodlg.h"
62 #include "contextmenuactionprovider.h"
63 #include "debugbufferviewoverlay.h"
64 #include "debuglogwidget.h"
65 #include "debugmessagemodelfilter.h"
66 #include "flatproxymodel.h"
67 #include "iconloader.h"
68 #include "inputwidget.h"
69 #include "irclistmodel.h"
70 #include "ircconnectionwizard.h"
71 #include "jumpkeyhandler.h"
72 #include "msgprocessorstatuswidget.h"
73 #include "nicklistwidget.h"
74 #include "qtuiapplication.h"
75 #include "qtuimessageprocessor.h"
76 #include "qtuisettings.h"
77 #include "qtuistyle.h"
78 #include "settingsdlg.h"
79 #include "settingspagedlg.h"
80 #include "systemtray.h"
81 #include "toolbaractionprovider.h"
82 #include "topicwidget.h"
83 #include "verticaldock.h"
87 # include "desktopnotificationbackend.h"
90 # include "phononnotificationbackend.h"
92 # include "systraynotificationbackend.h"
93 # include "taskbarnotificationbackend.h"
95 # include "knotificationbackend.h"
98 #ifdef HAVE_INDICATEQT
99 #include "indicatornotificationbackend.h"
102 #include "settingspages/aliasessettingspage.h"
103 #include "settingspages/appearancesettingspage.h"
104 #include "settingspages/backlogsettingspage.h"
105 #include "settingspages/bufferviewsettingspage.h"
106 #include "settingspages/chatmonitorsettingspage.h"
107 #include "settingspages/chatviewsettingspage.h"
108 #include "settingspages/connectionsettingspage.h"
109 #include "settingspages/coreaccountsettingspage.h"
110 #include "settingspages/generalsettingspage.h"
111 #include "settingspages/highlightsettingspage.h"
112 #include "settingspages/identitiessettingspage.h"
113 #include "settingspages/ignorelistsettingspage.h"
114 #include "settingspages/inputwidgetsettingspage.h"
115 #include "settingspages/itemviewsettingspage.h"
116 #include "settingspages/networkssettingspage.h"
117 #include "settingspages/notificationssettingspage.h"
118 #include "settingspages/topicwidgetsettingspage.h"
120 MainWin::MainWin(QWidget *parent)
122 : KMainWindow(parent),
123 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
125 : QMainWindow(parent),
127 coreLagLabel(new QLabel()),
128 sslLabel(new QLabel()),
129 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
130 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
139 QtUiSettings uiSettings;
140 QString style = uiSettings.value("Style", QString()).toString();
141 if(!style.isEmpty()) {
142 QApplication::setStyle(style);
145 QApplication::setQuitOnLastWindowClosed(false);
147 setWindowTitle("Quassel IRC");
148 setWindowIconText("Quassel IRC");
151 installEventFilter(new JumpKeyHandler(this));
154 void MainWin::init() {
155 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
156 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
157 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
158 SLOT(messagesInserted(const QModelIndex &, int, int)));
159 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
160 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
161 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
164 setDockNestingEnabled(true);
165 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
166 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
167 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
168 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
170 // Order is sometimes important
185 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
186 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
188 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
191 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
195 QtUi::registerNotificationBackend(new KNotificationBackend(this));
196 #endif /* HAVE_KDE */
198 #ifdef HAVE_INDICATEQT
199 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
202 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
204 setDisconnectedState(); // Disable menus and stuff
207 setAutoSaveSettings();
210 // restore mainwin state
212 restoreStateFromSettings(s);
214 // restore locked state of docks
215 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
217 CoreConnection *conn = Client::coreConnection();
218 if(!conn->connectToCore()) {
219 // No autoconnect selected (or no accounts)
220 showCoreConnectionDlg();
224 MainWin::~MainWin() {
228 void MainWin::quit() {
230 saveStateToSettings(s);
232 QApplication::quit();
235 void MainWin::saveStateToSettings(UiSettings &s) {
236 s.setValue("MainWinSize", _normalSize);
237 s.setValue("MainWinPos", _normalPos);
238 s.setValue("MainWinState", saveState());
239 s.setValue("MainWinGeometry", saveGeometry());
240 s.setValue("MainWinMinimized", isMinimized());
241 s.setValue("MainWinMaximized", isMaximized());
242 s.setValue("MainWinHidden", !isVisible());
245 saveAutoSaveSettings();
249 void MainWin::restoreStateFromSettings(UiSettings &s) {
250 _normalSize = s.value("MainWinSize", size()).toSize();
251 _normalPos = s.value("MainWinPos", pos()).toPoint();
252 bool maximized = s.value("MainWinMaximized", false).toBool();
255 restoreGeometry(s.value("MainWinGeometry").toByteArray());
258 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
263 restoreState(s.value("MainWinState").toByteArray());
269 if(s.value("MainWinHidden").toBool())
271 else if(s.value("MainWinMinimized").toBool())
279 void MainWin::updateIcon() {
281 const int size = 128;
287 if(Client::isConnected())
288 icon = DesktopIcon("quassel", size);
290 icon = DesktopIcon("quassel_inactive", size);
292 qApp->setWindowIcon(icon);
295 void MainWin::setupActions() {
296 ActionCollection *coll = QtUi::actionCollection("General");
298 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
299 this, SLOT(showCoreConnectionDlg())));
300 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
301 Client::instance(), SLOT(disconnectFromCore())));
302 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
303 this, SLOT(showCoreInfoDlg())));
304 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
305 this, SLOT(on_actionConfigureNetworks_triggered())));
306 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
307 this, SLOT(quit()), tr("Ctrl+Q")));
310 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
311 this, SLOT(on_actionConfigureViews_triggered())));
313 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
314 lockAct->setCheckable(true);
315 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
317 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
318 0, 0, QKeySequence::Find))->setCheckable(true);
319 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
320 this, SLOT(showAwayLog())));
321 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
322 0, 0, tr("Ctrl+M")))->setCheckable(true);
324 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
325 0, 0))->setCheckable(true);
328 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
329 this, SLOT(showSettingsDlg()), tr("F7")));
332 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
333 this, SLOT(showAboutDlg())));
334 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
335 qApp, SLOT(aboutQt())));
336 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
337 this, SLOT(on_actionDebugNetworkModel_triggered())));
338 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
339 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
340 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
341 this, SLOT(on_actionDebugMessageModel_triggered())));
342 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
343 this, SLOT(on_actionDebugHotList_triggered())));
344 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
345 this, SLOT(on_actionDebugLog_triggered())));
346 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
347 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
350 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
351 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
354 void MainWin::setupMenus() {
355 ActionCollection *coll = QtUi::actionCollection("General");
357 _fileMenu = menuBar()->addMenu(tr("&File"));
359 static const QStringList coreActions = QStringList()
360 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
363 foreach(QString actionName, coreActions) {
364 coreAction = coll->action(actionName);
365 _fileMenu->addAction(coreAction);
366 flagRemoteCoreOnly(coreAction);
368 flagRemoteCoreOnly(_fileMenu->addSeparator());
370 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
371 _networksMenu->addAction(coll->action("ConfigureNetworks"));
372 _networksMenu->addSeparator();
373 _fileMenu->addSeparator();
374 _fileMenu->addAction(coll->action("Quit"));
376 _viewMenu = menuBar()->addMenu(tr("&View"));
377 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
378 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
379 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
380 _viewMenu->addSeparator();
382 _viewMenu->addAction(coll->action("ToggleMenuBar"));
383 _viewMenu->addAction(coll->action("ToggleStatusBar"));
384 _viewMenu->addAction(coll->action("ToggleSearchBar"));
386 coreAction = coll->action("ShowAwayLog");
387 flagRemoteCoreOnly(coreAction);
388 _viewMenu->addAction(coreAction);
390 _viewMenu->addSeparator();
391 _viewMenu->addAction(coll->action("LockLayout"));
393 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
395 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
396 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
398 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
400 _helpMenu = menuBar()->addMenu(tr("&Help"));
401 _helpMenu->addAction(coll->action("AboutQuassel"));
403 _helpMenu->addAction(coll->action("AboutQt"));
405 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
407 _helpMenu->addSeparator();
408 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
409 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
410 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
411 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
412 _helpDebugMenu->addAction(coll->action("DebugHotList"));
413 _helpDebugMenu->addAction(coll->action("DebugLog"));
414 _helpDebugMenu->addSeparator();
415 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
418 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
420 QtUiSettings uiSettings;
421 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
422 showMenuBar->setChecked(enabled);
423 enabled ? menuBar()->show() : menuBar()->hide();
425 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
426 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
429 void MainWin::setupBufferWidget() {
430 _bufferWidget = new BufferWidget(this);
431 _bufferWidget->setModel(Client::bufferModel());
432 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
433 setCentralWidget(_bufferWidget);
436 void MainWin::addBufferView(int bufferViewConfigId) {
437 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
440 void MainWin::addBufferView(ClientBufferViewConfig *config) {
444 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
445 BufferViewDock *dock = new BufferViewDock(config, this);
447 //create the view and initialize it's filter
448 BufferView *view = new BufferView(dock);
449 view->setFilteredModel(Client::bufferModel(), config);
450 view->installEventFilter(_inputWidget); // for key presses
452 Client::bufferModel()->synchronizeView(view);
454 dock->setWidget(view);
455 dock->setVisible(_layoutLoaded); // don't show before state has been restored
457 addDockWidget(Qt::LeftDockWidgetArea, dock);
458 _bufferViewsMenu->addAction(dock->toggleViewAction());
460 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
461 _bufferViews.append(dock);
464 void MainWin::removeBufferView(int bufferViewConfigId) {
466 BufferViewDock *dock;
467 foreach(QAction *action, _bufferViewsMenu->actions()) {
468 actionData = action->data();
469 if(!actionData.isValid())
472 dock = qobject_cast<BufferViewDock *>(action->parent());
473 if(dock && actionData.toInt() == bufferViewConfigId) {
474 removeAction(action);
475 _bufferViews.removeAll(dock);
476 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
482 void MainWin::bufferViewToggled(bool enabled) {
483 QAction *action = qobject_cast<QAction *>(sender());
485 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
488 // Make sure we don't toggle backlog fetch for a view we've already removed
489 if(!_bufferViews.contains(dock))
493 Client::bufferViewOverlay()->addView(dock->bufferViewId());
494 BufferViewConfig *config = dock->config();
495 if(config && config->isInitialized()) {
496 BufferIdList buffers;
497 if(config->networkId().isValid()) {
498 foreach(BufferId bufferId, config->bufferList()) {
499 if(Client::networkModel()->networkId(bufferId) == config->networkId())
502 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
503 if(Client::networkModel()->networkId(bufferId) == config->networkId())
507 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
509 Client::backlogManager()->checkForBacklog(buffers);
512 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
516 BufferView *MainWin::allBuffersView() const {
517 // "All Buffers" is always the first dock created
518 if(_bufferViews.count() > 0)
519 return _bufferViews[0]->bufferView();
523 void MainWin::showNotificationsDlg() {
524 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
528 void MainWin::on_actionConfigureNetworks_triggered() {
529 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
533 void MainWin::on_actionConfigureViews_triggered() {
534 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
538 void MainWin::on_actionLockLayout_toggled(bool lock) {
539 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
540 foreach(VerticalDock *dock, docks) {
541 dock->showTitle(!lock);
543 if(Client::bufferViewManager()) {
544 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
545 config->setLocked(lock);
548 QtUiSettings().setValue("LockLayout", lock);
551 void MainWin::setupNickWidget() {
553 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
554 nickDock->setObjectName("NickDock");
555 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
557 _nickListWidget = new NickListWidget(nickDock);
558 nickDock->setWidget(_nickListWidget);
560 addDockWidget(Qt::RightDockWidgetArea, nickDock);
561 _viewMenu->addAction(nickDock->toggleViewAction());
562 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
564 // See NickListDock::NickListDock();
565 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
567 // attach the NickListWidget to the BufferModel and the default selection
568 _nickListWidget->setModel(Client::bufferModel());
569 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
572 void MainWin::setupChatMonitor() {
573 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
574 dock->setObjectName("ChatMonitorDock");
576 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
577 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
579 dock->setWidget(chatView);
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);
607 void MainWin::setupTopicWidget() {
608 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
609 dock->setObjectName("TopicDock");
610 TopicWidget *topicwidget = new TopicWidget(dock);
612 dock->setWidget(topicwidget);
614 topicwidget->setModel(Client::bufferModel());
615 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
617 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
619 _viewMenu->addAction(dock->toggleViewAction());
620 dock->toggleViewAction()->setText(tr("Show Topic Line"));
623 void MainWin::setupTitleSetter() {
624 _titleSetter.setModel(Client::bufferModel());
625 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
628 void MainWin::setupStatusBar() {
629 // MessageProcessor progress
630 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
633 _coreConnectionStatusWidget->update();
634 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
637 updateLagIndicator();
638 statusBar()->addPermanentWidget(coreLagLabel);
639 coreLagLabel->hide();
640 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
643 sslLabel->setPixmap(QPixmap());
644 statusBar()->addPermanentWidget(sslLabel);
647 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
649 QtUiSettings uiSettings;
651 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
652 showStatusbar->setChecked(enabled);
653 enabled ? statusBar()->show() : statusBar()->hide();
655 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
656 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
658 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
661 void MainWin::setupHotList() {
662 FlatProxyModel *flatProxy = new FlatProxyModel(this);
663 flatProxy->setSourceModel(Client::bufferModel());
664 _bufferHotList = new BufferHotListFilter(flatProxy);
667 void MainWin::saveMenuBarStatus(bool enabled) {
668 QtUiSettings uiSettings;
669 uiSettings.setValue("ShowMenuBar", enabled);
672 void MainWin::saveStatusBarStatus(bool enabled) {
673 QtUiSettings uiSettings;
674 uiSettings.setValue("ShowStatusBar", enabled);
677 void MainWin::setupSystray() {
678 _systemTray = new SystemTray(this);
681 void MainWin::setupToolBars() {
682 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
683 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
684 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
685 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
688 setUnifiedTitleAndToolBarOnMac(true);
692 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
694 _mainToolBar = new QToolBar(this);
695 _mainToolBar->setObjectName("MainToolBar");
697 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
698 addToolBar(_mainToolBar);
700 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
701 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
704 void MainWin::connectedToCore() {
705 Q_CHECK_PTR(Client::bufferViewManager());
706 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
707 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
708 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
713 void MainWin::setConnectedState() {
714 ActionCollection *coll = QtUi::actionCollection("General");
716 coll->action("ConnectCore")->setEnabled(false);
717 coll->action("DisconnectCore")->setEnabled(true);
718 coll->action("CoreInfo")->setEnabled(true);
720 foreach(QAction *action, _fileMenu->actions()) {
721 if(isRemoteCoreOnly(action))
722 action->setVisible(!Client::internalCore());
725 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
726 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
727 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
728 if(!Client::internalCore()) {
729 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
730 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
731 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
734 // _viewMenu->setEnabled(true);
735 if(!Client::internalCore())
736 statusBar()->showMessage(tr("Connected to core."));
738 statusBar()->clearMessage();
740 if(Client::signalProxy()->isSecure()) {
741 sslLabel->setPixmap(SmallIcon("security-high"));
743 sslLabel->setPixmap(SmallIcon("security-low"));
746 sslLabel->setVisible(!Client::internalCore());
747 coreLagLabel->setVisible(!Client::internalCore());
749 systemTray()->setState(SystemTray::Active);
751 if(Client::networkIds().isEmpty()) {
752 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
757 void MainWin::loadLayout() {
759 int accountId = Client::currentCoreAccount().accountId().toInt();
760 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
761 if(state.isEmpty()) {
762 // Make sure that the default bufferview is shown
763 if(_bufferViews.count())
764 _bufferViews.at(0)->show();
768 restoreState(state, accountId);
769 _layoutLoaded = true;
772 void MainWin::saveLayout() {
774 int accountId = Client::currentCoreAccount().accountId().toInt();
775 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
778 void MainWin::updateLagIndicator(int lag) {
779 QString text = tr("Core Lag: %1");
781 text = text.arg('-');
783 text = text.arg("%1 msec").arg(lag);
784 coreLagLabel->setText(text);
787 void MainWin::disconnectedFromCore() {
788 // save core specific layout and remove bufferviews;
790 _layoutLoaded = false;
793 BufferViewDock *dock;
794 foreach(QAction *action, _bufferViewsMenu->actions()) {
795 actionData = action->data();
796 if(!actionData.isValid())
799 dock = qobject_cast<BufferViewDock *>(action->parent());
800 if(dock && actionData.toInt() != -1) {
801 removeAction(action);
802 _bufferViews.removeAll(dock);
803 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
809 restoreState(s.value("MainWinState").toByteArray());
810 setDisconnectedState();
813 void MainWin::setDisconnectedState() {
814 ActionCollection *coll = QtUi::actionCollection("General");
815 //ui.menuCore->setEnabled(false);
816 coll->action("ConnectCore")->setEnabled(true);
817 coll->action("DisconnectCore")->setEnabled(false);
818 coll->action("CoreInfo")->setEnabled(false);
819 //_viewMenu->setEnabled(false);
820 statusBar()->showMessage(tr("Not connected to core."));
821 sslLabel->setPixmap(QPixmap());
823 updateLagIndicator();
824 coreLagLabel->hide();
825 if(_msgProcessorStatusWidget)
826 _msgProcessorStatusWidget->setProgress(0, 0);
828 systemTray()->setState(SystemTray::Inactive);
831 void MainWin::startInternalCore() {
835 void MainWin::showCoreConnectionDlg() {
836 CoreConnectDlg dlg(this);
837 if(dlg.exec() == QDialog::Accepted) {
838 AccountId accId = dlg.selectedAccount();
840 Client::coreConnection()->connectToCore(accId);
844 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
845 Q_UNUSED(errorMessage)
846 CoreConnectAuthDlg dlg(account, this);
847 *valid = (dlg.exec() == QDialog::Accepted);
850 void MainWin::showChannelList(NetworkId netId) {
851 ChannelListDlg *channelListDlg = new ChannelListDlg();
853 if(!netId.isValid()) {
854 QAction *action = qobject_cast<QAction *>(sender());
856 netId = action->data().value<NetworkId>();
859 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
860 channelListDlg->setNetwork(netId);
861 channelListDlg->show();
864 void MainWin::showIgnoreList(QString newRule) {
865 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
866 // prepare config dialog for new rule
867 if(!newRule.isEmpty())
868 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
872 void MainWin::showCoreInfoDlg() {
873 CoreInfoDlg(this).exec();
876 void MainWin::showAwayLog() {
879 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
880 _awayLog = new AwayLogView(filter, 0);
881 filter->setParent(_awayLog);
882 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
883 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
887 void MainWin::awayLogDestroyed() {
891 void MainWin::showSettingsDlg() {
892 SettingsDlg *dlg = new SettingsDlg();
894 //Category: Interface
895 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
896 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
897 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
898 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
899 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
900 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
901 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
902 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
903 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
904 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
907 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
908 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
909 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
910 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
911 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
912 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
914 if(Quassel::runMode() != Quassel::Monolithic) {
915 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
921 void MainWin::showAboutDlg() {
922 AboutDlg(this).exec();
926 void MainWin::showShortcutsDlg() {
927 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
931 /********************************************************************************************************/
933 bool MainWin::event(QEvent *event) {
934 if(event->type() == QEvent::WindowActivate) {
935 BufferId buffer = Client::bufferModel()->currentBuffer();
937 QtUi::closeNotifications(buffer);
939 return QMainWindow::event(event);
942 void MainWin::moveEvent(QMoveEvent *event) {
943 if(!(windowState() & Qt::WindowMaximized))
944 _normalPos = event->pos();
946 QMainWindow::moveEvent(event);
949 void MainWin::resizeEvent(QResizeEvent *event) {
950 if(!(windowState() & Qt::WindowMaximized))
951 _normalSize = event->size();
953 QMainWindow::resizeEvent(event);
956 void MainWin::closeEvent(QCloseEvent *event) {
958 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
960 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
969 void MainWin::changeEvent(QEvent *event) {
971 if(event->type() == QEvent::ActivationChange)
972 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
975 QMainWindow::changeEvent(event);
978 void MainWin::hideToTray() {
979 if(!systemTray()->isSystemTrayAvailable()) {
980 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
984 systemTray()->setIconVisible();
987 void MainWin::toggleMinimizedToTray() {
989 // the problem is that we lose focus when the systray icon is activated
990 // and we don't know the former active window
991 // therefore we watch for activation event and use our stopwatch :)
992 // courtesy: KSystemTrayIcon
993 if(GetTickCount() - dwTickCount >= 300)
994 // we weren't active in the last 300ms -> activate
1001 if(!isVisible() || isMinimized())
1010 void MainWin::forceActivated() {
1013 KWindowSystem::forceActiveWindow(winId());
1017 // Bypass focus stealing prevention
1018 QX11Info::setAppUserTime(QX11Info::appTime());
1021 if(windowState() & Qt::WindowMinimized) {
1023 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
1026 // this does not actually work on all platforms... and causes more evil than good
1027 // move(frameGeometry().topLeft()); // avoid placement policies
1031 #endif /* HAVE_KDE */
1034 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1037 bool hasFocus = QApplication::activeWindow() != 0;
1039 for(int i = start; i <= end; i++) {
1040 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1041 if(!idx.isValid()) {
1042 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1045 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1046 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1049 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1050 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1052 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1055 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1056 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1057 Client::networkModel()->networkName(bufId))))
1059 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1060 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1061 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1062 AbstractNotificationBackend::NotificationType type;
1064 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1065 type = AbstractNotificationBackend::PrivMsg;
1066 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1067 type = AbstractNotificationBackend::PrivMsgFocused;
1068 else if(flags & Message::Highlight && !hasFocus)
1069 type = AbstractNotificationBackend::Highlight;
1071 type = AbstractNotificationBackend::HighlightFocused;
1073 QtUi::invokeNotification(bufId, type, sender, contents);
1078 void MainWin::currentBufferChanged(BufferId buffer) {
1079 if(buffer.isValid())
1080 QtUi::closeNotifications(buffer);
1083 void MainWin::clientNetworkCreated(NetworkId id) {
1084 const Network *net = Client::network(id);
1085 QAction *act = new QAction(net->networkName(), this);
1086 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1087 act->setData(QVariant::fromValue<NetworkId>(id));
1088 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1089 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1091 QAction *beforeAction = 0;
1092 foreach(QAction *action, _networksMenu->actions()) {
1093 if(!action->data().isValid()) // ignore stock actions
1095 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1096 beforeAction = action;
1100 _networksMenu->insertAction(beforeAction, act);
1103 void MainWin::clientNetworkUpdated() {
1104 const Network *net = qobject_cast<const Network *>(sender());
1108 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1112 action->setText(net->networkName());
1114 switch(net->connectionState()) {
1115 case Network::Initialized:
1116 action->setIcon(SmallIcon("network-connect"));
1118 case Network::Disconnected:
1119 action->setIcon(SmallIcon("network-disconnect"));
1122 action->setIcon(SmallIcon("network-wired"));
1126 void MainWin::clientNetworkRemoved(NetworkId id) {
1127 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1131 action->deleteLater();
1134 void MainWin::connectOrDisconnectFromNet() {
1135 QAction *act = qobject_cast<QAction *>(sender());
1137 const Network *net = Client::network(act->data().value<NetworkId>());
1139 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1140 else net->requestDisconnect();
1143 void MainWin::on_jumpHotBuffer_triggered() {
1144 if(!_bufferHotList->rowCount())
1147 QModelIndex topIndex = _bufferHotList->index(0, 0);
1148 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1149 Client::bufferModel()->switchToBuffer(bufferId);
1152 void MainWin::on_actionDebugNetworkModel_triggered() {
1153 QTreeView *view = new QTreeView;
1154 view->setAttribute(Qt::WA_DeleteOnClose);
1155 view->setWindowTitle("Debug NetworkModel View");
1156 view->setModel(Client::networkModel());
1157 view->setColumnWidth(0, 250);
1158 view->setColumnWidth(1, 250);
1159 view->setColumnWidth(2, 80);
1160 view->resize(610, 300);
1164 void MainWin::on_actionDebugHotList_triggered() {
1165 QTreeView *view = new QTreeView;
1166 view->setAttribute(Qt::WA_DeleteOnClose);
1167 view->setModel(_bufferHotList);
1171 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1172 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1173 overlay->setAttribute(Qt::WA_DeleteOnClose);
1177 void MainWin::on_actionDebugMessageModel_triggered() {
1178 QTableView *view = new QTableView(0);
1179 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1180 filter->setSourceModel(Client::messageModel());
1181 view->setModel(filter);
1182 view->setAttribute(Qt::WA_DeleteOnClose, true);
1183 view->verticalHeader()->hide();
1184 view->horizontalHeader()->setStretchLastSection(true);
1188 void MainWin::on_actionDebugLog_triggered() {
1189 DebugLogWidget *logWidget = new DebugLogWidget(0);
1193 void MainWin::showStatusBarMessage(const QString &message) {
1194 statusBar()->showMessage(message, 10000);