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>
37 #include "awaylogfilter.h"
38 #include "awaylogview.h"
40 #include "actioncollection.h"
41 #include "bufferhotlistfilter.h"
42 #include "buffermodel.h"
43 #include "bufferview.h"
44 #include "bufferviewoverlay.h"
45 #include "bufferviewoverlayfilter.h"
46 #include "bufferwidget.h"
47 #include "channellistdlg.h"
48 #include "chatlinemodel.h"
49 #include "chatmonitorfilter.h"
50 #include "chatmonitorview.h"
53 #include "clientsyncer.h"
54 #include "clientbacklogmanager.h"
55 #include "clientbufferviewconfig.h"
56 #include "clientbufferviewmanager.h"
57 #include "clientignorelistmanager.h"
58 #include "coreinfodlg.h"
59 #include "coreconnectdlg.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 #include "settingspages/aliasessettingspage.h"
97 #include "settingspages/appearancesettingspage.h"
98 #include "settingspages/backlogsettingspage.h"
99 #include "settingspages/bufferviewsettingspage.h"
100 #include "settingspages/chatmonitorsettingspage.h"
101 #include "settingspages/chatviewsettingspage.h"
102 #include "settingspages/connectionsettingspage.h"
103 #include "settingspages/generalsettingspage.h"
104 #include "settingspages/highlightsettingspage.h"
105 #include "settingspages/identitiessettingspage.h"
106 #include "settingspages/ignorelistsettingspage.h"
107 #include "settingspages/inputwidgetsettingspage.h"
108 #include "settingspages/itemviewsettingspage.h"
109 #include "settingspages/networkssettingspage.h"
110 #include "settingspages/notificationssettingspage.h"
112 MainWin::MainWin(QWidget *parent)
114 : KMainWindow(parent),
115 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
117 : QMainWindow(parent),
119 coreLagLabel(new QLabel()),
120 sslLabel(new QLabel()),
121 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
129 QtUiSettings uiSettings;
130 QString style = uiSettings.value("Style", QString()).toString();
131 if(!style.isEmpty()) {
132 QApplication::setStyle(style);
135 QApplication::setQuitOnLastWindowClosed(false);
137 setWindowTitle("Quassel IRC");
138 setWindowIconText("Quassel IRC");
141 installEventFilter(new JumpKeyHandler(this));
144 void MainWin::init() {
145 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
146 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
147 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
148 SLOT(messagesInserted(const QModelIndex &, int, int)));
149 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
152 setDockNestingEnabled(true);
153 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
154 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
155 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
156 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
158 // Order is sometimes important
173 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
174 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
176 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
179 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
183 QtUi::registerNotificationBackend(new KNotificationBackend(this));
184 #endif /* HAVE_KDE */
186 setDisconnectedState(); // Disable menus and stuff
189 setAutoSaveSettings();
192 // restore mainwin state
194 restoreStateFromSettings(s);
196 // restore locked state of docks
197 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
199 if(Quassel::runMode() != Quassel::Monolithic) {
200 showCoreConnectionDlg(true); // autoconnect if appropriate
206 MainWin::~MainWin() {
210 void MainWin::quit() {
212 saveStateToSettings(s);
214 QApplication::quit();
217 void MainWin::saveStateToSettings(UiSettings &s) {
218 s.setValue("MainWinSize", _normalSize);
219 s.setValue("MainWinPos", _normalPos);
220 s.setValue("MainWinState", saveState());
221 s.setValue("MainWinGeometry", saveGeometry());
222 s.setValue("MainWinMinimized", isMinimized());
223 s.setValue("MainWinMaximized", isMaximized());
224 s.setValue("MainWinHidden", !isVisible());
227 saveAutoSaveSettings();
231 void MainWin::restoreStateFromSettings(UiSettings &s) {
232 _normalSize = s.value("MainWinSize", size()).toSize();
233 _normalPos = s.value("MainWinPos", pos()).toPoint();
234 bool maximized = s.value("MainWinMaximized", false).toBool();
237 restoreGeometry(s.value("MainWinGeometry").toByteArray());
240 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
245 restoreState(s.value("MainWinState").toByteArray());
251 if(s.value("MainWinHidden").toBool())
253 else if(s.value("MainWinMinimized").toBool())
261 void MainWin::updateIcon() {
263 const int size = 128;
269 if(Client::isConnected())
270 icon = DesktopIcon("quassel", size);
272 icon = DesktopIcon("quassel_inactive", size);
274 qApp->setWindowIcon(icon);
277 void MainWin::setupActions() {
278 ActionCollection *coll = QtUi::actionCollection("General");
280 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
281 this, SLOT(showCoreConnectionDlg())));
282 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
283 Client::instance(), SLOT(disconnectFromCore())));
284 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
285 this, SLOT(showCoreInfoDlg())));
286 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
287 this, SLOT(on_actionConfigureNetworks_triggered())));
288 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
289 this, SLOT(quit()), tr("Ctrl+Q")));
292 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
293 this, SLOT(on_actionConfigureViews_triggered())));
295 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
296 lockAct->setCheckable(true);
297 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
299 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
300 0, 0, QKeySequence::Find))->setCheckable(true);
301 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
302 this, SLOT(showAwayLog())));
303 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
304 0, 0, tr("Ctrl+M")))->setCheckable(true);
306 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
307 0, 0))->setCheckable(true);
310 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
311 this, SLOT(showSettingsDlg()), tr("F7")));
314 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
315 this, SLOT(showAboutDlg())));
316 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
317 qApp, SLOT(aboutQt())));
318 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
319 this, SLOT(on_actionDebugNetworkModel_triggered())));
320 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
321 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
322 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
323 this, SLOT(on_actionDebugMessageModel_triggered())));
324 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
325 this, SLOT(on_actionDebugHotList_triggered())));
326 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
327 this, SLOT(on_actionDebugLog_triggered())));
328 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
329 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
332 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
333 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
336 void MainWin::setupMenus() {
337 ActionCollection *coll = QtUi::actionCollection("General");
339 _fileMenu = menuBar()->addMenu(tr("&File"));
341 static const QStringList coreActions = QStringList()
342 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
345 foreach(QString actionName, coreActions) {
346 coreAction = coll->action(actionName);
347 _fileMenu->addAction(coreAction);
348 flagRemoteCoreOnly(coreAction);
350 flagRemoteCoreOnly(_fileMenu->addSeparator());
352 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
353 _networksMenu->addAction(coll->action("ConfigureNetworks"));
354 _networksMenu->addSeparator();
355 _fileMenu->addSeparator();
356 _fileMenu->addAction(coll->action("Quit"));
358 _viewMenu = menuBar()->addMenu(tr("&View"));
359 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
360 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
361 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
362 _viewMenu->addSeparator();
364 _viewMenu->addAction(coll->action("ToggleMenuBar"));
365 _viewMenu->addAction(coll->action("ToggleStatusBar"));
366 _viewMenu->addAction(coll->action("ToggleSearchBar"));
368 coreAction = coll->action("ShowAwayLog");
369 flagRemoteCoreOnly(coreAction);
370 _viewMenu->addAction(coreAction);
372 _viewMenu->addSeparator();
373 _viewMenu->addAction(coll->action("LockLayout"));
375 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
377 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
378 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
380 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
382 _helpMenu = menuBar()->addMenu(tr("&Help"));
383 _helpMenu->addAction(coll->action("AboutQuassel"));
385 _helpMenu->addAction(coll->action("AboutQt"));
387 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
389 _helpMenu->addSeparator();
390 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
391 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
392 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
393 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
394 _helpDebugMenu->addAction(coll->action("DebugHotList"));
395 _helpDebugMenu->addAction(coll->action("DebugLog"));
396 _helpDebugMenu->addSeparator();
397 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
400 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
402 QtUiSettings uiSettings;
403 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
404 showMenuBar->setChecked(enabled);
405 enabled ? menuBar()->show() : menuBar()->hide();
407 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
408 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
411 void MainWin::setupBufferWidget() {
412 _bufferWidget = new BufferWidget(this);
413 _bufferWidget->setModel(Client::bufferModel());
414 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
415 setCentralWidget(_bufferWidget);
418 void MainWin::addBufferView(int bufferViewConfigId) {
419 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
422 void MainWin::addBufferView(ClientBufferViewConfig *config) {
426 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
427 BufferViewDock *dock = new BufferViewDock(config, this);
429 //create the view and initialize it's filter
430 BufferView *view = new BufferView(dock);
431 view->setFilteredModel(Client::bufferModel(), config);
432 view->installEventFilter(_inputWidget); // for key presses
435 Client::bufferModel()->synchronizeView(view);
437 dock->setWidget(view);
440 addDockWidget(Qt::LeftDockWidgetArea, dock);
441 _bufferViewsMenu->addAction(dock->toggleViewAction());
443 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
444 _bufferViews.append(dock);
447 void MainWin::removeBufferView(int bufferViewConfigId) {
449 BufferViewDock *dock;
450 foreach(QAction *action, _bufferViewsMenu->actions()) {
451 actionData = action->data();
452 if(!actionData.isValid())
455 dock = qobject_cast<BufferViewDock *>(action->parent());
456 if(dock && actionData.toInt() == bufferViewConfigId) {
457 removeAction(action);
463 void MainWin::bufferViewToggled(bool enabled) {
464 QAction *action = qobject_cast<QAction *>(sender());
466 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
469 Client::bufferViewOverlay()->addView(dock->bufferViewId());
470 BufferViewConfig *config = dock->config();
471 if(config && config->isInitialized()) {
472 BufferIdList buffers;
473 if(config->networkId().isValid()) {
474 foreach(BufferId bufferId, config->bufferList()) {
475 if(Client::networkModel()->networkId(bufferId) == config->networkId())
478 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
479 if(Client::networkModel()->networkId(bufferId) == config->networkId())
483 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
485 Client::backlogManager()->checkForBacklog(buffers);
488 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
492 BufferView *MainWin::allBuffersView() const {
493 // "All Buffers" is always the first dock created
494 if(_bufferViews.count() > 0)
495 return _bufferViews[0]->bufferView();
499 void MainWin::showNotificationsDlg() {
500 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
504 void MainWin::on_actionConfigureNetworks_triggered() {
505 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
509 void MainWin::on_actionConfigureViews_triggered() {
510 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
514 void MainWin::on_actionLockLayout_toggled(bool lock) {
515 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
516 foreach(VerticalDock *dock, docks) {
517 dock->showTitle(!lock);
519 if(Client::bufferViewManager()) {
520 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
521 config->setLocked(lock);
524 QtUiSettings().setValue("LockLayout", lock);
527 void MainWin::setupNickWidget() {
529 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
530 nickDock->setObjectName("NickDock");
531 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
533 _nickListWidget = new NickListWidget(nickDock);
534 nickDock->setWidget(_nickListWidget);
536 addDockWidget(Qt::RightDockWidgetArea, nickDock);
537 _viewMenu->addAction(nickDock->toggleViewAction());
538 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
540 // See NickListDock::NickListDock();
541 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
543 // attach the NickListWidget to the BufferModel and the default selection
544 _nickListWidget->setModel(Client::bufferModel());
545 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
548 void MainWin::setupChatMonitor() {
549 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
550 dock->setObjectName("ChatMonitorDock");
552 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
553 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
555 dock->setWidget(chatView);
558 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
559 _viewMenu->addAction(dock->toggleViewAction());
560 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
563 void MainWin::setupInputWidget() {
564 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
565 dock->setObjectName("InputDock");
567 _inputWidget = new InputWidget(dock);
568 dock->setWidget(_inputWidget);
570 addDockWidget(Qt::BottomDockWidgetArea, dock);
572 _viewMenu->addAction(dock->toggleViewAction());
573 dock->toggleViewAction()->setText(tr("Show Input Line"));
575 _inputWidget->setModel(Client::bufferModel());
576 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
578 _bufferWidget->setFocusProxy(_inputWidget);
580 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
583 void MainWin::setupTopicWidget() {
584 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
585 dock->setObjectName("TopicDock");
586 TopicWidget *topicwidget = new TopicWidget(dock);
588 dock->setWidget(topicwidget);
590 topicwidget->setModel(Client::bufferModel());
591 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
593 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
595 _viewMenu->addAction(dock->toggleViewAction());
596 dock->toggleViewAction()->setText(tr("Show Topic Line"));
599 void MainWin::setupTitleSetter() {
600 _titleSetter.setModel(Client::bufferModel());
601 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
604 void MainWin::setupStatusBar() {
605 // MessageProcessor progress
606 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
609 updateLagIndicator();
610 statusBar()->addPermanentWidget(coreLagLabel);
611 coreLagLabel->hide();
612 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
615 sslLabel->setPixmap(QPixmap());
616 statusBar()->addPermanentWidget(sslLabel);
619 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
621 QtUiSettings uiSettings;
623 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
624 showStatusbar->setChecked(enabled);
625 enabled ? statusBar()->show() : statusBar()->hide();
627 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
628 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
631 void MainWin::setupHotList() {
632 FlatProxyModel *flatProxy = new FlatProxyModel(this);
633 flatProxy->setSourceModel(Client::bufferModel());
634 _bufferHotList = new BufferHotListFilter(flatProxy);
637 void MainWin::saveMenuBarStatus(bool enabled) {
638 QtUiSettings uiSettings;
639 uiSettings.setValue("ShowMenuBar", enabled);
642 void MainWin::saveStatusBarStatus(bool enabled) {
643 QtUiSettings uiSettings;
644 uiSettings.setValue("ShowStatusBar", enabled);
647 void MainWin::setupSystray() {
648 _systemTray = new SystemTray(this);
651 void MainWin::setupToolBars() {
652 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
653 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
654 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
655 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
658 setUnifiedTitleAndToolBarOnMac(true);
662 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
664 _mainToolBar = new QToolBar(this);
665 _mainToolBar->setObjectName("MainToolBar");
667 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
668 addToolBar(_mainToolBar);
670 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
671 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
674 void MainWin::connectedToCore() {
675 Q_CHECK_PTR(Client::bufferViewManager());
676 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
677 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
678 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
683 void MainWin::setConnectedState() {
684 ActionCollection *coll = QtUi::actionCollection("General");
686 coll->action("ConnectCore")->setEnabled(false);
687 coll->action("DisconnectCore")->setEnabled(true);
688 coll->action("CoreInfo")->setEnabled(true);
690 foreach(QAction *action, _fileMenu->actions()) {
691 if(isRemoteCoreOnly(action))
692 action->setVisible(!Client::internalCore());
695 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
696 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
697 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
698 if(!Client::internalCore()) {
699 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
700 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
701 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
704 // _viewMenu->setEnabled(true);
705 if(!Client::internalCore())
706 statusBar()->showMessage(tr("Connected to core."));
708 statusBar()->clearMessage();
710 if(Client::signalProxy()->isSecure()) {
711 sslLabel->setPixmap(SmallIcon("security-high"));
713 sslLabel->setPixmap(SmallIcon("security-low"));
716 sslLabel->setVisible(!Client::internalCore());
717 coreLagLabel->setVisible(!Client::internalCore());
719 systemTray()->setState(SystemTray::Active);
721 if(Client::networkIds().isEmpty()) {
722 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
727 void MainWin::loadLayout() {
729 int accountId = Client::currentCoreAccount().toInt();
730 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
733 void MainWin::saveLayout() {
735 int accountId = Client::currentCoreAccount().toInt();
736 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
739 void MainWin::updateLagIndicator(int lag) {
740 QString text = tr("Core Lag: %1");
742 text = text.arg('-');
744 text = text.arg("%1 msec").arg(lag);
745 coreLagLabel->setText(text);
748 void MainWin::disconnectedFromCore() {
749 // save core specific layout and remove bufferviews;
752 BufferViewDock *dock;
753 foreach(QAction *action, _bufferViewsMenu->actions()) {
754 actionData = action->data();
755 if(!actionData.isValid())
758 dock = qobject_cast<BufferViewDock *>(action->parent());
759 if(dock && actionData.toInt() != -1) {
760 removeAction(action);
765 restoreState(s.value("MainWinState").toByteArray());
766 setDisconnectedState();
769 void MainWin::setDisconnectedState() {
770 ActionCollection *coll = QtUi::actionCollection("General");
771 //ui.menuCore->setEnabled(false);
772 coll->action("ConnectCore")->setEnabled(true);
773 coll->action("DisconnectCore")->setEnabled(false);
774 coll->action("CoreInfo")->setEnabled(false);
775 //_viewMenu->setEnabled(false);
776 statusBar()->showMessage(tr("Not connected to core."));
777 sslLabel->setPixmap(QPixmap());
779 updateLagIndicator();
780 coreLagLabel->hide();
781 if(msgProcessorStatusWidget)
782 msgProcessorStatusWidget->setProgress(0, 0);
784 systemTray()->setState(SystemTray::Inactive);
787 void MainWin::startInternalCore() {
788 ClientSyncer *syncer = new ClientSyncer();
789 Client::registerClientSyncer(syncer);
790 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
791 syncer->useInternalCore();
794 void MainWin::showCoreConnectionDlg(bool autoConnect) {
795 CoreConnectDlg(autoConnect, this).exec();
798 void MainWin::showChannelList(NetworkId netId) {
799 ChannelListDlg *channelListDlg = new ChannelListDlg();
801 if(!netId.isValid()) {
802 QAction *action = qobject_cast<QAction *>(sender());
804 netId = action->data().value<NetworkId>();
807 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
808 channelListDlg->setNetwork(netId);
809 channelListDlg->show();
812 void MainWin::showCoreInfoDlg() {
813 CoreInfoDlg(this).exec();
816 void MainWin::showAwayLog() {
819 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
820 _awayLog = new AwayLogView(filter, 0);
821 filter->setParent(_awayLog);
822 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
823 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
827 void MainWin::awayLogDestroyed() {
831 void MainWin::showSettingsDlg() {
832 SettingsDlg *dlg = new SettingsDlg();
834 //Category: Interface
835 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
836 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
837 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
838 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
839 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
840 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
841 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
842 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
843 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
846 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
847 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
848 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
849 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
850 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
851 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
856 void MainWin::showAboutDlg() {
857 AboutDlg(this).exec();
861 void MainWin::showShortcutsDlg() {
862 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
866 /********************************************************************************************************/
868 bool MainWin::event(QEvent *event) {
869 if(event->type() == QEvent::WindowActivate)
870 QtUi::closeNotifications();
871 return QMainWindow::event(event);
874 void MainWin::moveEvent(QMoveEvent *event) {
875 if(!(windowState() & Qt::WindowMaximized))
876 _normalPos = event->pos();
878 QMainWindow::moveEvent(event);
881 void MainWin::resizeEvent(QResizeEvent *event) {
882 if(!(windowState() & Qt::WindowMaximized))
883 _normalSize = event->size();
885 QMainWindow::resizeEvent(event);
888 void MainWin::closeEvent(QCloseEvent *event) {
890 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
892 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
901 void MainWin::changeEvent(QEvent *event) {
903 if(event->type() == QEvent::ActivationChange)
904 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
907 QMainWindow::changeEvent(event);
910 void MainWin::hideToTray() {
911 if(!systemTray()->isSystemTrayAvailable()) {
912 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
916 systemTray()->setIconVisible();
919 void MainWin::toggleMinimizedToTray() {
921 // the problem is that we lose focus when the systray icon is activated
922 // and we don't know the former active window
923 // therefore we watch for activation event and use our stopwatch :)
924 // courtesy: KSystemTrayIcon
925 if(GetTickCount() - dwTickCount >= 300)
926 // we weren't active in the last 300ms -> activate
933 if(!isVisible() || isMinimized())
942 void MainWin::forceActivated() {
944 // Bypass focus stealing prevention
945 QX11Info::setAppUserTime(QX11Info::appTime());
948 if(windowState() & Qt::WindowMinimized) {
950 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
953 // this does not actually work on all platforms... and causes more evil than good
954 // move(frameGeometry().topLeft()); // avoid placement policies
960 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
963 bool hasFocus = QApplication::activeWindow() != 0;
965 for(int i = start; i <= end; i++) {
966 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
968 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
971 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
972 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
975 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
976 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
978 if(hasFocus && bufId == _bufferWidget->currentBuffer())
981 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
982 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
983 Client::networkModel()->networkName(bufId))))
985 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
986 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
987 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
988 AbstractNotificationBackend::NotificationType type;
990 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
991 type = AbstractNotificationBackend::PrivMsg;
992 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
993 type = AbstractNotificationBackend::PrivMsgFocused;
994 else if(flags & Message::Highlight && !hasFocus)
995 type = AbstractNotificationBackend::Highlight;
997 type = AbstractNotificationBackend::HighlightFocused;
999 QtUi::invokeNotification(bufId, type, sender, contents);
1004 void MainWin::clientNetworkCreated(NetworkId id) {
1005 const Network *net = Client::network(id);
1006 QAction *act = new QAction(net->networkName(), this);
1007 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1008 act->setData(QVariant::fromValue<NetworkId>(id));
1009 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1010 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1012 QAction *beforeAction = 0;
1013 foreach(QAction *action, _networksMenu->actions()) {
1014 if(!action->data().isValid()) // ignore stock actions
1016 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1017 beforeAction = action;
1021 _networksMenu->insertAction(beforeAction, act);
1024 void MainWin::clientNetworkUpdated() {
1025 const Network *net = qobject_cast<const Network *>(sender());
1029 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1033 action->setText(net->networkName());
1035 switch(net->connectionState()) {
1036 case Network::Initialized:
1037 action->setIcon(SmallIcon("network-connect"));
1039 case Network::Disconnected:
1040 action->setIcon(SmallIcon("network-disconnect"));
1043 action->setIcon(SmallIcon("network-wired"));
1047 void MainWin::clientNetworkRemoved(NetworkId id) {
1048 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1052 action->deleteLater();
1055 void MainWin::connectOrDisconnectFromNet() {
1056 QAction *act = qobject_cast<QAction *>(sender());
1058 const Network *net = Client::network(act->data().value<NetworkId>());
1060 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1061 else net->requestDisconnect();
1064 void MainWin::on_jumpHotBuffer_triggered() {
1065 if(!_bufferHotList->rowCount())
1068 QModelIndex topIndex = _bufferHotList->index(0, 0);
1069 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1070 Client::bufferModel()->switchToBuffer(bufferId);
1073 void MainWin::on_actionDebugNetworkModel_triggered() {
1074 QTreeView *view = new QTreeView;
1075 view->setAttribute(Qt::WA_DeleteOnClose);
1076 view->setWindowTitle("Debug NetworkModel View");
1077 view->setModel(Client::networkModel());
1078 view->setColumnWidth(0, 250);
1079 view->setColumnWidth(1, 250);
1080 view->setColumnWidth(2, 80);
1081 view->resize(610, 300);
1085 void MainWin::on_actionDebugHotList_triggered() {
1086 QTreeView *view = new QTreeView;
1087 view->setAttribute(Qt::WA_DeleteOnClose);
1088 view->setModel(_bufferHotList);
1092 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1093 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1094 overlay->setAttribute(Qt::WA_DeleteOnClose);
1098 void MainWin::on_actionDebugMessageModel_triggered() {
1099 QTableView *view = new QTableView(0);
1100 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1101 filter->setSourceModel(Client::messageModel());
1102 view->setModel(filter);
1103 view->setAttribute(Qt::WA_DeleteOnClose, true);
1104 view->verticalHeader()->hide();
1105 view->horizontalHeader()->setStretchLastSection(true);
1109 void MainWin::on_actionDebugLog_triggered() {
1110 DebugLogWidget *logWidget = new DebugLogWidget(0);
1114 void MainWin::showStatusBarMessage(const QString &message) {
1115 statusBar()->showMessage(message, 10000);