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 "coreconnection.h"
59 #include "coreinfodlg.h"
60 #include "contextmenuactionprovider.h"
61 #include "debugbufferviewoverlay.h"
62 #include "debuglogwidget.h"
63 #include "debugmessagemodelfilter.h"
64 #include "flatproxymodel.h"
65 #include "iconloader.h"
66 #include "inputwidget.h"
67 #include "irclistmodel.h"
68 #include "ircconnectionwizard.h"
69 #include "jumpkeyhandler.h"
70 #include "msgprocessorstatuswidget.h"
71 #include "nicklistwidget.h"
72 #include "qtuiapplication.h"
73 #include "qtuimessageprocessor.h"
74 #include "qtuisettings.h"
75 #include "qtuistyle.h"
76 #include "settingsdlg.h"
77 #include "settingspagedlg.h"
78 #include "systemtray.h"
79 #include "toolbaractionprovider.h"
80 #include "topicwidget.h"
81 #include "verticaldock.h"
85 # include "desktopnotificationbackend.h"
88 # include "phononnotificationbackend.h"
90 # include "systraynotificationbackend.h"
91 # include "taskbarnotificationbackend.h"
93 # include "knotificationbackend.h"
96 #ifdef HAVE_INDICATEQT
97 #include "indicatornotificationbackend.h"
100 #include "settingspages/aliasessettingspage.h"
101 #include "settingspages/appearancesettingspage.h"
102 #include "settingspages/backlogsettingspage.h"
103 #include "settingspages/bufferviewsettingspage.h"
104 #include "settingspages/chatmonitorsettingspage.h"
105 #include "settingspages/chatviewsettingspage.h"
106 #include "settingspages/connectionsettingspage.h"
107 #include "settingspages/coreaccountsettingspage.h"
108 #include "settingspages/generalsettingspage.h"
109 #include "settingspages/highlightsettingspage.h"
110 #include "settingspages/identitiessettingspage.h"
111 #include "settingspages/ignorelistsettingspage.h"
112 #include "settingspages/inputwidgetsettingspage.h"
113 #include "settingspages/itemviewsettingspage.h"
114 #include "settingspages/networkssettingspage.h"
115 #include "settingspages/notificationssettingspage.h"
116 #include "settingspages/topicwidgetsettingspage.h"
118 MainWin::MainWin(QWidget *parent)
120 : KMainWindow(parent),
121 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
123 : QMainWindow(parent),
125 coreLagLabel(new QLabel()),
126 sslLabel(new QLabel()),
127 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
136 QtUiSettings uiSettings;
137 QString style = uiSettings.value("Style", QString()).toString();
138 if(!style.isEmpty()) {
139 QApplication::setStyle(style);
142 QApplication::setQuitOnLastWindowClosed(false);
144 setWindowTitle("Quassel IRC");
145 setWindowIconText("Quassel IRC");
148 installEventFilter(new JumpKeyHandler(this));
151 void MainWin::init() {
152 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
153 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
154 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
155 SLOT(messagesInserted(const QModelIndex &, int, int)));
156 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
157 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
160 setDockNestingEnabled(true);
161 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
162 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
163 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
164 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
166 // Order is sometimes important
181 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
182 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
184 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
187 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
191 QtUi::registerNotificationBackend(new KNotificationBackend(this));
192 #endif /* HAVE_KDE */
194 #ifdef HAVE_INDICATEQT
195 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
198 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
200 setDisconnectedState(); // Disable menus and stuff
203 setAutoSaveSettings();
206 // restore mainwin state
208 restoreStateFromSettings(s);
210 // restore locked state of docks
211 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
213 if(Quassel::runMode() != Quassel::Monolithic) {
214 //showCoreConnectionDlg(true); // autoconnect if appropriate
218 Client::coreConnection()->start();
221 MainWin::~MainWin() {
225 void MainWin::quit() {
227 saveStateToSettings(s);
229 QApplication::quit();
232 void MainWin::saveStateToSettings(UiSettings &s) {
233 s.setValue("MainWinSize", _normalSize);
234 s.setValue("MainWinPos", _normalPos);
235 s.setValue("MainWinState", saveState());
236 s.setValue("MainWinGeometry", saveGeometry());
237 s.setValue("MainWinMinimized", isMinimized());
238 s.setValue("MainWinMaximized", isMaximized());
239 s.setValue("MainWinHidden", !isVisible());
242 saveAutoSaveSettings();
246 void MainWin::restoreStateFromSettings(UiSettings &s) {
247 _normalSize = s.value("MainWinSize", size()).toSize();
248 _normalPos = s.value("MainWinPos", pos()).toPoint();
249 bool maximized = s.value("MainWinMaximized", false).toBool();
252 restoreGeometry(s.value("MainWinGeometry").toByteArray());
255 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
260 restoreState(s.value("MainWinState").toByteArray());
266 if(s.value("MainWinHidden").toBool())
268 else if(s.value("MainWinMinimized").toBool())
276 void MainWin::updateIcon() {
278 const int size = 128;
284 if(Client::isConnected())
285 icon = DesktopIcon("quassel", size);
287 icon = DesktopIcon("quassel_inactive", size);
289 qApp->setWindowIcon(icon);
292 void MainWin::setupActions() {
293 ActionCollection *coll = QtUi::actionCollection("General");
295 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
296 this, SLOT(showCoreConnectionDlg())));
297 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
298 Client::instance(), SLOT(disconnectFromCore())));
299 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
300 this, SLOT(showCoreInfoDlg())));
301 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
302 this, SLOT(on_actionConfigureNetworks_triggered())));
303 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
304 this, SLOT(quit()), tr("Ctrl+Q")));
307 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
308 this, SLOT(on_actionConfigureViews_triggered())));
310 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
311 lockAct->setCheckable(true);
312 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
314 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
315 0, 0, QKeySequence::Find))->setCheckable(true);
316 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
317 this, SLOT(showAwayLog())));
318 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
319 0, 0, tr("Ctrl+M")))->setCheckable(true);
321 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
322 0, 0))->setCheckable(true);
325 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
326 this, SLOT(showSettingsDlg()), tr("F7")));
329 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
330 this, SLOT(showAboutDlg())));
331 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
332 qApp, SLOT(aboutQt())));
333 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
334 this, SLOT(on_actionDebugNetworkModel_triggered())));
335 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
336 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
337 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
338 this, SLOT(on_actionDebugMessageModel_triggered())));
339 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
340 this, SLOT(on_actionDebugHotList_triggered())));
341 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
342 this, SLOT(on_actionDebugLog_triggered())));
343 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
344 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
347 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
348 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
351 void MainWin::setupMenus() {
352 ActionCollection *coll = QtUi::actionCollection("General");
354 _fileMenu = menuBar()->addMenu(tr("&File"));
356 static const QStringList coreActions = QStringList()
357 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
360 foreach(QString actionName, coreActions) {
361 coreAction = coll->action(actionName);
362 _fileMenu->addAction(coreAction);
363 flagRemoteCoreOnly(coreAction);
365 flagRemoteCoreOnly(_fileMenu->addSeparator());
367 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
368 _networksMenu->addAction(coll->action("ConfigureNetworks"));
369 _networksMenu->addSeparator();
370 _fileMenu->addSeparator();
371 _fileMenu->addAction(coll->action("Quit"));
373 _viewMenu = menuBar()->addMenu(tr("&View"));
374 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
375 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
376 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
377 _viewMenu->addSeparator();
379 _viewMenu->addAction(coll->action("ToggleMenuBar"));
380 _viewMenu->addAction(coll->action("ToggleStatusBar"));
381 _viewMenu->addAction(coll->action("ToggleSearchBar"));
383 coreAction = coll->action("ShowAwayLog");
384 flagRemoteCoreOnly(coreAction);
385 _viewMenu->addAction(coreAction);
387 _viewMenu->addSeparator();
388 _viewMenu->addAction(coll->action("LockLayout"));
390 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
392 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
393 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
395 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
397 _helpMenu = menuBar()->addMenu(tr("&Help"));
398 _helpMenu->addAction(coll->action("AboutQuassel"));
400 _helpMenu->addAction(coll->action("AboutQt"));
402 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
404 _helpMenu->addSeparator();
405 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
406 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
407 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
408 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
409 _helpDebugMenu->addAction(coll->action("DebugHotList"));
410 _helpDebugMenu->addAction(coll->action("DebugLog"));
411 _helpDebugMenu->addSeparator();
412 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
415 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
417 QtUiSettings uiSettings;
418 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
419 showMenuBar->setChecked(enabled);
420 enabled ? menuBar()->show() : menuBar()->hide();
422 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
423 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
426 void MainWin::setupBufferWidget() {
427 _bufferWidget = new BufferWidget(this);
428 _bufferWidget->setModel(Client::bufferModel());
429 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
430 setCentralWidget(_bufferWidget);
433 void MainWin::addBufferView(int bufferViewConfigId) {
434 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
437 void MainWin::addBufferView(ClientBufferViewConfig *config) {
441 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
442 BufferViewDock *dock = new BufferViewDock(config, this);
444 //create the view and initialize it's filter
445 BufferView *view = new BufferView(dock);
446 view->setFilteredModel(Client::bufferModel(), config);
447 view->installEventFilter(_inputWidget); // for key presses
449 Client::bufferModel()->synchronizeView(view);
451 dock->setWidget(view);
452 dock->setVisible(_layoutLoaded); // don't show before state has been restored
454 addDockWidget(Qt::LeftDockWidgetArea, dock);
455 _bufferViewsMenu->addAction(dock->toggleViewAction());
457 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
458 _bufferViews.append(dock);
461 void MainWin::removeBufferView(int bufferViewConfigId) {
463 BufferViewDock *dock;
464 foreach(QAction *action, _bufferViewsMenu->actions()) {
465 actionData = action->data();
466 if(!actionData.isValid())
469 dock = qobject_cast<BufferViewDock *>(action->parent());
470 if(dock && actionData.toInt() == bufferViewConfigId) {
471 removeAction(action);
472 _bufferViews.removeAll(dock);
473 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
479 void MainWin::bufferViewToggled(bool enabled) {
480 QAction *action = qobject_cast<QAction *>(sender());
482 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
485 // Make sure we don't toggle backlog fetch for a view we've already removed
486 if(!_bufferViews.contains(dock))
490 Client::bufferViewOverlay()->addView(dock->bufferViewId());
491 BufferViewConfig *config = dock->config();
492 if(config && config->isInitialized()) {
493 BufferIdList buffers;
494 if(config->networkId().isValid()) {
495 foreach(BufferId bufferId, config->bufferList()) {
496 if(Client::networkModel()->networkId(bufferId) == config->networkId())
499 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
500 if(Client::networkModel()->networkId(bufferId) == config->networkId())
504 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
506 Client::backlogManager()->checkForBacklog(buffers);
509 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
513 BufferView *MainWin::allBuffersView() const {
514 // "All Buffers" is always the first dock created
515 if(_bufferViews.count() > 0)
516 return _bufferViews[0]->bufferView();
520 void MainWin::showNotificationsDlg() {
521 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
525 void MainWin::on_actionConfigureNetworks_triggered() {
526 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
530 void MainWin::on_actionConfigureViews_triggered() {
531 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
535 void MainWin::on_actionLockLayout_toggled(bool lock) {
536 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
537 foreach(VerticalDock *dock, docks) {
538 dock->showTitle(!lock);
540 if(Client::bufferViewManager()) {
541 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
542 config->setLocked(lock);
545 QtUiSettings().setValue("LockLayout", lock);
548 void MainWin::setupNickWidget() {
550 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
551 nickDock->setObjectName("NickDock");
552 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
554 _nickListWidget = new NickListWidget(nickDock);
555 nickDock->setWidget(_nickListWidget);
557 addDockWidget(Qt::RightDockWidgetArea, nickDock);
558 _viewMenu->addAction(nickDock->toggleViewAction());
559 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
561 // See NickListDock::NickListDock();
562 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
564 // attach the NickListWidget to the BufferModel and the default selection
565 _nickListWidget->setModel(Client::bufferModel());
566 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
569 void MainWin::setupChatMonitor() {
570 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
571 dock->setObjectName("ChatMonitorDock");
573 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
574 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
576 dock->setWidget(chatView);
579 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
580 _viewMenu->addAction(dock->toggleViewAction());
581 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
584 void MainWin::setupInputWidget() {
585 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
586 dock->setObjectName("InputDock");
588 _inputWidget = new InputWidget(dock);
589 dock->setWidget(_inputWidget);
591 addDockWidget(Qt::BottomDockWidgetArea, dock);
593 _viewMenu->addAction(dock->toggleViewAction());
594 dock->toggleViewAction()->setText(tr("Show Input Line"));
596 _inputWidget->setModel(Client::bufferModel());
597 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
599 _bufferWidget->setFocusProxy(_inputWidget);
601 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
604 void MainWin::setupTopicWidget() {
605 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
606 dock->setObjectName("TopicDock");
607 TopicWidget *topicwidget = new TopicWidget(dock);
609 dock->setWidget(topicwidget);
611 topicwidget->setModel(Client::bufferModel());
612 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
614 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
616 _viewMenu->addAction(dock->toggleViewAction());
617 dock->toggleViewAction()->setText(tr("Show Topic Line"));
620 void MainWin::setupTitleSetter() {
621 _titleSetter.setModel(Client::bufferModel());
622 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
625 void MainWin::setupStatusBar() {
626 // MessageProcessor progress
627 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
630 updateLagIndicator();
631 statusBar()->addPermanentWidget(coreLagLabel);
632 coreLagLabel->hide();
633 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
636 sslLabel->setPixmap(QPixmap());
637 statusBar()->addPermanentWidget(sslLabel);
640 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
642 QtUiSettings uiSettings;
644 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
645 showStatusbar->setChecked(enabled);
646 enabled ? statusBar()->show() : statusBar()->hide();
648 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
649 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
651 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
654 void MainWin::setupHotList() {
655 FlatProxyModel *flatProxy = new FlatProxyModel(this);
656 flatProxy->setSourceModel(Client::bufferModel());
657 _bufferHotList = new BufferHotListFilter(flatProxy);
660 void MainWin::saveMenuBarStatus(bool enabled) {
661 QtUiSettings uiSettings;
662 uiSettings.setValue("ShowMenuBar", enabled);
665 void MainWin::saveStatusBarStatus(bool enabled) {
666 QtUiSettings uiSettings;
667 uiSettings.setValue("ShowStatusBar", enabled);
670 void MainWin::setupSystray() {
671 _systemTray = new SystemTray(this);
674 void MainWin::setupToolBars() {
675 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
676 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
677 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
678 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
681 setUnifiedTitleAndToolBarOnMac(true);
685 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
687 _mainToolBar = new QToolBar(this);
688 _mainToolBar->setObjectName("MainToolBar");
690 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
691 addToolBar(_mainToolBar);
693 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
694 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
697 void MainWin::connectedToCore() {
698 Q_CHECK_PTR(Client::bufferViewManager());
699 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
700 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
701 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
706 void MainWin::setConnectedState() {
707 ActionCollection *coll = QtUi::actionCollection("General");
709 coll->action("ConnectCore")->setEnabled(false);
710 coll->action("DisconnectCore")->setEnabled(true);
711 coll->action("CoreInfo")->setEnabled(true);
713 foreach(QAction *action, _fileMenu->actions()) {
714 if(isRemoteCoreOnly(action))
715 action->setVisible(!Client::internalCore());
718 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
719 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
720 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
721 if(!Client::internalCore()) {
722 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
723 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
724 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
727 // _viewMenu->setEnabled(true);
728 if(!Client::internalCore())
729 statusBar()->showMessage(tr("Connected to core."));
731 statusBar()->clearMessage();
733 if(Client::signalProxy()->isSecure()) {
734 sslLabel->setPixmap(SmallIcon("security-high"));
736 sslLabel->setPixmap(SmallIcon("security-low"));
739 sslLabel->setVisible(!Client::internalCore());
740 coreLagLabel->setVisible(!Client::internalCore());
742 systemTray()->setState(SystemTray::Active);
744 if(Client::networkIds().isEmpty()) {
745 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
750 void MainWin::loadLayout() {
752 int accountId = Client::currentCoreAccount().accountId().toInt();
753 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
754 if(state.isEmpty()) {
755 // Make sure that the default bufferview is shown
756 if(_bufferViews.count())
757 _bufferViews.at(0)->show();
761 restoreState(state, accountId);
762 _layoutLoaded = true;
765 void MainWin::saveLayout() {
767 int accountId = Client::currentCoreAccount().accountId().toInt();
768 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
771 void MainWin::updateLagIndicator(int lag) {
772 QString text = tr("Core Lag: %1");
774 text = text.arg('-');
776 text = text.arg("%1 msec").arg(lag);
777 coreLagLabel->setText(text);
780 void MainWin::disconnectedFromCore() {
781 // save core specific layout and remove bufferviews;
783 _layoutLoaded = false;
786 BufferViewDock *dock;
787 foreach(QAction *action, _bufferViewsMenu->actions()) {
788 actionData = action->data();
789 if(!actionData.isValid())
792 dock = qobject_cast<BufferViewDock *>(action->parent());
793 if(dock && actionData.toInt() != -1) {
794 removeAction(action);
795 _bufferViews.removeAll(dock);
796 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
802 restoreState(s.value("MainWinState").toByteArray());
803 setDisconnectedState();
806 void MainWin::setDisconnectedState() {
807 ActionCollection *coll = QtUi::actionCollection("General");
808 //ui.menuCore->setEnabled(false);
809 coll->action("ConnectCore")->setEnabled(true);
810 coll->action("DisconnectCore")->setEnabled(false);
811 coll->action("CoreInfo")->setEnabled(false);
812 //_viewMenu->setEnabled(false);
813 statusBar()->showMessage(tr("Not connected to core."));
814 sslLabel->setPixmap(QPixmap());
816 updateLagIndicator();
817 coreLagLabel->hide();
818 if(_msgProcessorStatusWidget)
819 _msgProcessorStatusWidget->setProgress(0, 0);
821 systemTray()->setState(SystemTray::Inactive);
824 void MainWin::startInternalCore() {
828 void MainWin::showChannelList(NetworkId netId) {
829 ChannelListDlg *channelListDlg = new ChannelListDlg();
831 if(!netId.isValid()) {
832 QAction *action = qobject_cast<QAction *>(sender());
834 netId = action->data().value<NetworkId>();
837 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
838 channelListDlg->setNetwork(netId);
839 channelListDlg->show();
842 void MainWin::showIgnoreList(QString newRule) {
843 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
844 // prepare config dialog for new rule
845 if(!newRule.isEmpty())
846 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
850 void MainWin::showCoreInfoDlg() {
851 CoreInfoDlg(this).exec();
854 void MainWin::showAwayLog() {
857 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
858 _awayLog = new AwayLogView(filter, 0);
859 filter->setParent(_awayLog);
860 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
861 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
865 void MainWin::awayLogDestroyed() {
869 void MainWin::showSettingsDlg() {
870 SettingsDlg *dlg = new SettingsDlg();
872 //Category: Interface
873 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
874 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
875 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
876 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
877 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
878 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
879 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
880 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
881 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
882 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
885 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
886 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
887 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
888 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
889 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
890 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
892 if(Quassel::runMode() != Quassel::Monolithic) {
893 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
899 void MainWin::showAboutDlg() {
900 AboutDlg(this).exec();
904 void MainWin::showShortcutsDlg() {
905 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
909 /********************************************************************************************************/
911 bool MainWin::event(QEvent *event) {
912 if(event->type() == QEvent::WindowActivate) {
913 BufferId buffer = Client::bufferModel()->currentBuffer();
915 QtUi::closeNotifications(buffer);
917 return QMainWindow::event(event);
920 void MainWin::moveEvent(QMoveEvent *event) {
921 if(!(windowState() & Qt::WindowMaximized))
922 _normalPos = event->pos();
924 QMainWindow::moveEvent(event);
927 void MainWin::resizeEvent(QResizeEvent *event) {
928 if(!(windowState() & Qt::WindowMaximized))
929 _normalSize = event->size();
931 QMainWindow::resizeEvent(event);
934 void MainWin::closeEvent(QCloseEvent *event) {
936 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
938 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
947 void MainWin::changeEvent(QEvent *event) {
949 if(event->type() == QEvent::ActivationChange)
950 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
953 QMainWindow::changeEvent(event);
956 void MainWin::hideToTray() {
957 if(!systemTray()->isSystemTrayAvailable()) {
958 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
962 systemTray()->setIconVisible();
965 void MainWin::toggleMinimizedToTray() {
967 // the problem is that we lose focus when the systray icon is activated
968 // and we don't know the former active window
969 // therefore we watch for activation event and use our stopwatch :)
970 // courtesy: KSystemTrayIcon
971 if(GetTickCount() - dwTickCount >= 300)
972 // we weren't active in the last 300ms -> activate
979 if(!isVisible() || isMinimized())
988 void MainWin::forceActivated() {
991 KWindowSystem::forceActiveWindow(winId());
995 // Bypass focus stealing prevention
996 QX11Info::setAppUserTime(QX11Info::appTime());
999 if(windowState() & Qt::WindowMinimized) {
1001 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
1004 // this does not actually work on all platforms... and causes more evil than good
1005 // move(frameGeometry().topLeft()); // avoid placement policies
1009 #endif /* HAVE_KDE */
1012 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1015 bool hasFocus = QApplication::activeWindow() != 0;
1017 for(int i = start; i <= end; i++) {
1018 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1019 if(!idx.isValid()) {
1020 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1023 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1024 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1027 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1028 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1030 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1033 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1034 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1035 Client::networkModel()->networkName(bufId))))
1037 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1038 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1039 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1040 AbstractNotificationBackend::NotificationType type;
1042 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1043 type = AbstractNotificationBackend::PrivMsg;
1044 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1045 type = AbstractNotificationBackend::PrivMsgFocused;
1046 else if(flags & Message::Highlight && !hasFocus)
1047 type = AbstractNotificationBackend::Highlight;
1049 type = AbstractNotificationBackend::HighlightFocused;
1051 QtUi::invokeNotification(bufId, type, sender, contents);
1056 void MainWin::currentBufferChanged(BufferId buffer) {
1057 if(buffer.isValid())
1058 QtUi::closeNotifications(buffer);
1061 void MainWin::clientNetworkCreated(NetworkId id) {
1062 const Network *net = Client::network(id);
1063 QAction *act = new QAction(net->networkName(), this);
1064 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1065 act->setData(QVariant::fromValue<NetworkId>(id));
1066 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1067 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1069 QAction *beforeAction = 0;
1070 foreach(QAction *action, _networksMenu->actions()) {
1071 if(!action->data().isValid()) // ignore stock actions
1073 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1074 beforeAction = action;
1078 _networksMenu->insertAction(beforeAction, act);
1081 void MainWin::clientNetworkUpdated() {
1082 const Network *net = qobject_cast<const Network *>(sender());
1086 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1090 action->setText(net->networkName());
1092 switch(net->connectionState()) {
1093 case Network::Initialized:
1094 action->setIcon(SmallIcon("network-connect"));
1096 case Network::Disconnected:
1097 action->setIcon(SmallIcon("network-disconnect"));
1100 action->setIcon(SmallIcon("network-wired"));
1104 void MainWin::clientNetworkRemoved(NetworkId id) {
1105 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1109 action->deleteLater();
1112 void MainWin::connectOrDisconnectFromNet() {
1113 QAction *act = qobject_cast<QAction *>(sender());
1115 const Network *net = Client::network(act->data().value<NetworkId>());
1117 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1118 else net->requestDisconnect();
1121 void MainWin::on_jumpHotBuffer_triggered() {
1122 if(!_bufferHotList->rowCount())
1125 QModelIndex topIndex = _bufferHotList->index(0, 0);
1126 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1127 Client::bufferModel()->switchToBuffer(bufferId);
1130 void MainWin::on_actionDebugNetworkModel_triggered() {
1131 QTreeView *view = new QTreeView;
1132 view->setAttribute(Qt::WA_DeleteOnClose);
1133 view->setWindowTitle("Debug NetworkModel View");
1134 view->setModel(Client::networkModel());
1135 view->setColumnWidth(0, 250);
1136 view->setColumnWidth(1, 250);
1137 view->setColumnWidth(2, 80);
1138 view->resize(610, 300);
1142 void MainWin::on_actionDebugHotList_triggered() {
1143 QTreeView *view = new QTreeView;
1144 view->setAttribute(Qt::WA_DeleteOnClose);
1145 view->setModel(_bufferHotList);
1149 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1150 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1151 overlay->setAttribute(Qt::WA_DeleteOnClose);
1155 void MainWin::on_actionDebugMessageModel_triggered() {
1156 QTableView *view = new QTableView(0);
1157 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1158 filter->setSourceModel(Client::messageModel());
1159 view->setModel(filter);
1160 view->setAttribute(Qt::WA_DeleteOnClose, true);
1161 view->verticalHeader()->hide();
1162 view->horizontalHeader()->setStretchLastSection(true);
1166 void MainWin::on_actionDebugLog_triggered() {
1167 DebugLogWidget *logWidget = new DebugLogWidget(0);
1171 void MainWin::showStatusBarMessage(const QString &message) {
1172 statusBar()->showMessage(message, 10000);