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 "clientsyncer.h"
55 #include "clientbacklogmanager.h"
56 #include "clientbufferviewconfig.h"
57 #include "clientbufferviewmanager.h"
58 #include "clientignorelistmanager.h"
59 #include "coreinfodlg.h"
60 #include "coreconnectdlg.h"
61 #include "contextmenuactionprovider.h"
62 #include "debugbufferviewoverlay.h"
63 #include "debuglogwidget.h"
64 #include "debugmessagemodelfilter.h"
65 #include "flatproxymodel.h"
66 #include "iconloader.h"
67 #include "inputwidget.h"
68 #include "irclistmodel.h"
69 #include "ircconnectionwizard.h"
70 #include "jumpkeyhandler.h"
71 #include "msgprocessorstatuswidget.h"
72 #include "nicklistwidget.h"
73 #include "qtuiapplication.h"
74 #include "qtuimessageprocessor.h"
75 #include "qtuisettings.h"
76 #include "qtuistyle.h"
77 #include "settingsdlg.h"
78 #include "settingspagedlg.h"
79 #include "systemtray.h"
80 #include "toolbaractionprovider.h"
81 #include "topicwidget.h"
82 #include "verticaldock.h"
86 # include "desktopnotificationbackend.h"
89 # include "phononnotificationbackend.h"
91 # include "systraynotificationbackend.h"
92 # include "taskbarnotificationbackend.h"
94 # include "knotificationbackend.h"
97 #ifdef HAVE_INDICATEQT
98 #include "indicatornotificationbackend.h"
101 #include "settingspages/aliasessettingspage.h"
102 #include "settingspages/appearancesettingspage.h"
103 #include "settingspages/backlogsettingspage.h"
104 #include "settingspages/bufferviewsettingspage.h"
105 #include "settingspages/chatmonitorsettingspage.h"
106 #include "settingspages/chatviewsettingspage.h"
107 #include "settingspages/connectionsettingspage.h"
108 #include "settingspages/coreaccountsettingspage.h"
109 #include "settingspages/generalsettingspage.h"
110 #include "settingspages/highlightsettingspage.h"
111 #include "settingspages/identitiessettingspage.h"
112 #include "settingspages/ignorelistsettingspage.h"
113 #include "settingspages/inputwidgetsettingspage.h"
114 #include "settingspages/itemviewsettingspage.h"
115 #include "settingspages/networkssettingspage.h"
116 #include "settingspages/notificationssettingspage.h"
117 #include "settingspages/topicwidgetsettingspage.h"
119 MainWin::MainWin(QWidget *parent)
121 : KMainWindow(parent),
122 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
124 : QMainWindow(parent),
126 coreLagLabel(new QLabel()),
127 sslLabel(new QLabel()),
128 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
137 QtUiSettings uiSettings;
138 QString style = uiSettings.value("Style", QString()).toString();
139 if(!style.isEmpty()) {
140 QApplication::setStyle(style);
143 QApplication::setQuitOnLastWindowClosed(false);
145 setWindowTitle("Quassel IRC");
146 setWindowIconText("Quassel IRC");
149 installEventFilter(new JumpKeyHandler(this));
152 void MainWin::init() {
153 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
154 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
155 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
156 SLOT(messagesInserted(const QModelIndex &, int, int)));
157 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
158 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
161 setDockNestingEnabled(true);
162 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
163 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
164 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
165 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
167 // Order is sometimes important
182 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
183 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
185 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
188 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
192 QtUi::registerNotificationBackend(new KNotificationBackend(this));
193 #endif /* HAVE_KDE */
195 #ifdef HAVE_INDICATEQT
196 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
199 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
201 setDisconnectedState(); // Disable menus and stuff
204 setAutoSaveSettings();
207 // restore mainwin state
209 restoreStateFromSettings(s);
211 // restore locked state of docks
212 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
214 if(Quassel::runMode() != Quassel::Monolithic) {
215 showCoreConnectionDlg(true); // autoconnect if appropriate
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)));
652 void MainWin::setupHotList() {
653 FlatProxyModel *flatProxy = new FlatProxyModel(this);
654 flatProxy->setSourceModel(Client::bufferModel());
655 _bufferHotList = new BufferHotListFilter(flatProxy);
658 void MainWin::saveMenuBarStatus(bool enabled) {
659 QtUiSettings uiSettings;
660 uiSettings.setValue("ShowMenuBar", enabled);
663 void MainWin::saveStatusBarStatus(bool enabled) {
664 QtUiSettings uiSettings;
665 uiSettings.setValue("ShowStatusBar", enabled);
668 void MainWin::setupSystray() {
669 _systemTray = new SystemTray(this);
672 void MainWin::setupToolBars() {
673 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
674 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
675 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
676 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
679 setUnifiedTitleAndToolBarOnMac(true);
683 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
685 _mainToolBar = new QToolBar(this);
686 _mainToolBar->setObjectName("MainToolBar");
688 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
689 addToolBar(_mainToolBar);
691 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
692 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
695 void MainWin::connectedToCore() {
696 Q_CHECK_PTR(Client::bufferViewManager());
697 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
698 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
699 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
704 void MainWin::setConnectedState() {
705 ActionCollection *coll = QtUi::actionCollection("General");
707 coll->action("ConnectCore")->setEnabled(false);
708 coll->action("DisconnectCore")->setEnabled(true);
709 coll->action("CoreInfo")->setEnabled(true);
711 foreach(QAction *action, _fileMenu->actions()) {
712 if(isRemoteCoreOnly(action))
713 action->setVisible(!Client::internalCore());
716 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
717 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
718 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
719 if(!Client::internalCore()) {
720 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
721 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
722 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
725 // _viewMenu->setEnabled(true);
726 if(!Client::internalCore())
727 statusBar()->showMessage(tr("Connected to core."));
729 statusBar()->clearMessage();
731 if(Client::signalProxy()->isSecure()) {
732 sslLabel->setPixmap(SmallIcon("security-high"));
734 sslLabel->setPixmap(SmallIcon("security-low"));
737 sslLabel->setVisible(!Client::internalCore());
738 coreLagLabel->setVisible(!Client::internalCore());
740 systemTray()->setState(SystemTray::Active);
742 if(Client::networkIds().isEmpty()) {
743 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
748 void MainWin::loadLayout() {
750 int accountId = Client::currentCoreAccount().toInt();
751 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
752 if(state.isEmpty()) {
753 // Make sure that the default bufferview is shown
754 if(_bufferViews.count())
755 _bufferViews.at(0)->show();
759 restoreState(state, accountId);
760 _layoutLoaded = true;
763 void MainWin::saveLayout() {
765 int accountId = Client::currentCoreAccount().toInt();
766 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
769 void MainWin::updateLagIndicator(int lag) {
770 QString text = tr("Core Lag: %1");
772 text = text.arg('-');
774 text = text.arg("%1 msec").arg(lag);
775 coreLagLabel->setText(text);
778 void MainWin::disconnectedFromCore() {
779 // save core specific layout and remove bufferviews;
781 _layoutLoaded = false;
784 BufferViewDock *dock;
785 foreach(QAction *action, _bufferViewsMenu->actions()) {
786 actionData = action->data();
787 if(!actionData.isValid())
790 dock = qobject_cast<BufferViewDock *>(action->parent());
791 if(dock && actionData.toInt() != -1) {
792 removeAction(action);
793 _bufferViews.removeAll(dock);
794 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
800 restoreState(s.value("MainWinState").toByteArray());
801 setDisconnectedState();
804 void MainWin::setDisconnectedState() {
805 ActionCollection *coll = QtUi::actionCollection("General");
806 //ui.menuCore->setEnabled(false);
807 coll->action("ConnectCore")->setEnabled(true);
808 coll->action("DisconnectCore")->setEnabled(false);
809 coll->action("CoreInfo")->setEnabled(false);
810 //_viewMenu->setEnabled(false);
811 statusBar()->showMessage(tr("Not connected to core."));
812 sslLabel->setPixmap(QPixmap());
814 updateLagIndicator();
815 coreLagLabel->hide();
816 if(msgProcessorStatusWidget)
817 msgProcessorStatusWidget->setProgress(0, 0);
819 systemTray()->setState(SystemTray::Inactive);
822 void MainWin::startInternalCore() {
823 ClientSyncer *syncer = new ClientSyncer();
824 Client::registerClientSyncer(syncer);
825 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
826 syncer->useInternalCore();
829 void MainWin::showCoreConnectionDlg(bool autoConnect) {
830 CoreConnectDlg(autoConnect, this).exec();
833 void MainWin::showChannelList(NetworkId netId) {
834 ChannelListDlg *channelListDlg = new ChannelListDlg();
836 if(!netId.isValid()) {
837 QAction *action = qobject_cast<QAction *>(sender());
839 netId = action->data().value<NetworkId>();
842 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
843 channelListDlg->setNetwork(netId);
844 channelListDlg->show();
847 void MainWin::showIgnoreList(QString newRule) {
848 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
849 // prepare config dialog for new rule
850 if(!newRule.isEmpty())
851 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
855 void MainWin::showCoreInfoDlg() {
856 CoreInfoDlg(this).exec();
859 void MainWin::showAwayLog() {
862 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
863 _awayLog = new AwayLogView(filter, 0);
864 filter->setParent(_awayLog);
865 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
866 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
870 void MainWin::awayLogDestroyed() {
874 void MainWin::showSettingsDlg() {
875 SettingsDlg *dlg = new SettingsDlg();
877 //Category: Interface
878 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
879 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
880 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
881 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
882 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
883 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
884 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
885 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
886 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
887 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
890 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
891 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
892 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
893 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
894 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
895 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
897 if(Quassel::runMode() != Quassel::Monolithic) {
898 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
904 void MainWin::showAboutDlg() {
905 AboutDlg(this).exec();
909 void MainWin::showShortcutsDlg() {
910 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
914 /********************************************************************************************************/
916 bool MainWin::event(QEvent *event) {
917 if(event->type() == QEvent::WindowActivate) {
918 BufferId buffer = Client::bufferModel()->currentBuffer();
920 QtUi::closeNotifications(buffer);
922 return QMainWindow::event(event);
925 void MainWin::moveEvent(QMoveEvent *event) {
926 if(!(windowState() & Qt::WindowMaximized))
927 _normalPos = event->pos();
929 QMainWindow::moveEvent(event);
932 void MainWin::resizeEvent(QResizeEvent *event) {
933 if(!(windowState() & Qt::WindowMaximized))
934 _normalSize = event->size();
936 QMainWindow::resizeEvent(event);
939 void MainWin::closeEvent(QCloseEvent *event) {
941 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
943 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
952 void MainWin::changeEvent(QEvent *event) {
954 if(event->type() == QEvent::ActivationChange)
955 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
958 QMainWindow::changeEvent(event);
961 void MainWin::hideToTray() {
962 if(!systemTray()->isSystemTrayAvailable()) {
963 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
967 systemTray()->setIconVisible();
970 void MainWin::toggleMinimizedToTray() {
972 // the problem is that we lose focus when the systray icon is activated
973 // and we don't know the former active window
974 // therefore we watch for activation event and use our stopwatch :)
975 // courtesy: KSystemTrayIcon
976 if(GetTickCount() - dwTickCount >= 300)
977 // we weren't active in the last 300ms -> activate
984 if(!isVisible() || isMinimized())
993 void MainWin::forceActivated() {
996 KWindowSystem::forceActiveWindow(winId());
1000 // Bypass focus stealing prevention
1001 QX11Info::setAppUserTime(QX11Info::appTime());
1004 if(windowState() & Qt::WindowMinimized) {
1006 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
1009 // this does not actually work on all platforms... and causes more evil than good
1010 // move(frameGeometry().topLeft()); // avoid placement policies
1014 #endif /* HAVE_KDE */
1017 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1020 bool hasFocus = QApplication::activeWindow() != 0;
1022 for(int i = start; i <= end; i++) {
1023 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1024 if(!idx.isValid()) {
1025 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1028 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1029 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1032 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1033 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1035 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1038 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1039 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1040 Client::networkModel()->networkName(bufId))))
1042 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1043 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1044 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1045 AbstractNotificationBackend::NotificationType type;
1047 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1048 type = AbstractNotificationBackend::PrivMsg;
1049 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1050 type = AbstractNotificationBackend::PrivMsgFocused;
1051 else if(flags & Message::Highlight && !hasFocus)
1052 type = AbstractNotificationBackend::Highlight;
1054 type = AbstractNotificationBackend::HighlightFocused;
1056 QtUi::invokeNotification(bufId, type, sender, contents);
1061 void MainWin::currentBufferChanged(BufferId buffer) {
1062 if(buffer.isValid())
1063 QtUi::closeNotifications(buffer);
1066 void MainWin::clientNetworkCreated(NetworkId id) {
1067 const Network *net = Client::network(id);
1068 QAction *act = new QAction(net->networkName(), this);
1069 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1070 act->setData(QVariant::fromValue<NetworkId>(id));
1071 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1072 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1074 QAction *beforeAction = 0;
1075 foreach(QAction *action, _networksMenu->actions()) {
1076 if(!action->data().isValid()) // ignore stock actions
1078 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1079 beforeAction = action;
1083 _networksMenu->insertAction(beforeAction, act);
1086 void MainWin::clientNetworkUpdated() {
1087 const Network *net = qobject_cast<const Network *>(sender());
1091 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1095 action->setText(net->networkName());
1097 switch(net->connectionState()) {
1098 case Network::Initialized:
1099 action->setIcon(SmallIcon("network-connect"));
1101 case Network::Disconnected:
1102 action->setIcon(SmallIcon("network-disconnect"));
1105 action->setIcon(SmallIcon("network-wired"));
1109 void MainWin::clientNetworkRemoved(NetworkId id) {
1110 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1114 action->deleteLater();
1117 void MainWin::connectOrDisconnectFromNet() {
1118 QAction *act = qobject_cast<QAction *>(sender());
1120 const Network *net = Client::network(act->data().value<NetworkId>());
1122 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1123 else net->requestDisconnect();
1126 void MainWin::on_jumpHotBuffer_triggered() {
1127 if(!_bufferHotList->rowCount())
1130 QModelIndex topIndex = _bufferHotList->index(0, 0);
1131 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1132 Client::bufferModel()->switchToBuffer(bufferId);
1135 void MainWin::on_actionDebugNetworkModel_triggered() {
1136 QTreeView *view = new QTreeView;
1137 view->setAttribute(Qt::WA_DeleteOnClose);
1138 view->setWindowTitle("Debug NetworkModel View");
1139 view->setModel(Client::networkModel());
1140 view->setColumnWidth(0, 250);
1141 view->setColumnWidth(1, 250);
1142 view->setColumnWidth(2, 80);
1143 view->resize(610, 300);
1147 void MainWin::on_actionDebugHotList_triggered() {
1148 QTreeView *view = new QTreeView;
1149 view->setAttribute(Qt::WA_DeleteOnClose);
1150 view->setModel(_bufferHotList);
1154 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1155 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1156 overlay->setAttribute(Qt::WA_DeleteOnClose);
1160 void MainWin::on_actionDebugMessageModel_triggered() {
1161 QTableView *view = new QTableView(0);
1162 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1163 filter->setSourceModel(Client::messageModel());
1164 view->setModel(filter);
1165 view->setAttribute(Qt::WA_DeleteOnClose, true);
1166 view->verticalHeader()->hide();
1167 view->horizontalHeader()->setStretchLastSection(true);
1171 void MainWin::on_actionDebugLog_triggered() {
1172 DebugLogWidget *logWidget = new DebugLogWidget(0);
1176 void MainWin::showStatusBarMessage(const QString &message) {
1177 statusBar()->showMessage(message, 10000);