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 "coreinfodlg.h"
58 #include "coreconnectdlg.h"
59 #include "contextmenuactionprovider.h"
60 #include "debugbufferviewoverlay.h"
61 #include "debuglogwidget.h"
62 #include "debugmessagemodelfilter.h"
63 #include "flatproxymodel.h"
64 #include "iconloader.h"
65 #include "inputwidget.h"
66 #include "irclistmodel.h"
67 #include "ircconnectionwizard.h"
68 #include "jumpkeyhandler.h"
69 #include "msgprocessorstatuswidget.h"
70 #include "nicklistwidget.h"
71 #include "qtuiapplication.h"
72 #include "qtuimessageprocessor.h"
73 #include "qtuisettings.h"
74 #include "qtuistyle.h"
75 #include "settingsdlg.h"
76 #include "settingspagedlg.h"
77 #include "systemtray.h"
78 #include "toolbaractionprovider.h"
79 #include "topicwidget.h"
80 #include "verticaldock.h"
84 # include "desktopnotificationbackend.h"
87 # include "phononnotificationbackend.h"
89 # include "systraynotificationbackend.h"
90 # include "taskbarnotificationbackend.h"
92 # include "knotificationbackend.h"
95 #include "settingspages/aliasessettingspage.h"
96 #include "settingspages/appearancesettingspage.h"
97 #include "settingspages/backlogsettingspage.h"
98 #include "settingspages/bufferviewsettingspage.h"
99 #include "settingspages/chatmonitorsettingspage.h"
100 #include "settingspages/chatviewsettingspage.h"
101 #include "settingspages/connectionsettingspage.h"
102 #include "settingspages/generalsettingspage.h"
103 #include "settingspages/highlightsettingspage.h"
104 #include "settingspages/identitiessettingspage.h"
105 #include "settingspages/inputwidgetsettingspage.h"
106 #include "settingspages/itemviewsettingspage.h"
107 #include "settingspages/networkssettingspage.h"
108 #include "settingspages/notificationssettingspage.h"
110 MainWin::MainWin(QWidget *parent)
112 : KMainWindow(parent),
113 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
115 : QMainWindow(parent),
117 coreLagLabel(new QLabel()),
118 sslLabel(new QLabel()),
119 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
127 QtUiSettings uiSettings;
128 QString style = uiSettings.value("Style", QString()).toString();
129 if(!style.isEmpty()) {
130 QApplication::setStyle(style);
133 QApplication::setQuitOnLastWindowClosed(false);
135 setWindowTitle("Quassel IRC");
136 setWindowIconText("Quassel IRC");
139 installEventFilter(new JumpKeyHandler(this));
142 void MainWin::init() {
143 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
144 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
145 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
146 SLOT(messagesInserted(const QModelIndex &, int, int)));
147 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
150 setDockNestingEnabled(true);
151 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
152 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
153 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
154 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
156 // Order is sometimes important
171 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
172 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
174 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
177 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
181 QtUi::registerNotificationBackend(new KNotificationBackend(this));
182 #endif /* HAVE_KDE */
184 setDisconnectedState(); // Disable menus and stuff
187 setAutoSaveSettings();
190 // restore mainwin state
192 restoreStateFromSettings(s);
194 // restore locked state of docks
195 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
197 if(Quassel::runMode() != Quassel::Monolithic) {
198 showCoreConnectionDlg(true); // autoconnect if appropriate
204 MainWin::~MainWin() {
208 void MainWin::quit() {
210 saveStateToSettings(s);
212 QApplication::quit();
215 void MainWin::saveStateToSettings(UiSettings &s) {
216 s.setValue("MainWinSize", _normalSize);
217 s.setValue("MainWinPos", _normalPos);
218 s.setValue("MainWinState", saveState());
219 s.setValue("MainWinGeometry", saveGeometry());
220 s.setValue("MainWinMinimized", isMinimized());
221 s.setValue("MainWinMaximized", isMaximized());
222 s.setValue("MainWinHidden", !isVisible());
225 saveAutoSaveSettings();
229 void MainWin::restoreStateFromSettings(UiSettings &s) {
230 _normalSize = s.value("MainWinSize", size()).toSize();
231 _normalPos = s.value("MainWinPos", pos()).toPoint();
232 bool maximized = s.value("MainWinMaximized", false).toBool();
235 restoreGeometry(s.value("MainWinGeometry").toByteArray());
238 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
243 restoreState(s.value("MainWinState").toByteArray());
249 if(s.value("MainWinHidden").toBool())
251 else if(s.value("MainWinMinimized").toBool())
259 void MainWin::updateIcon() {
261 const int size = 128;
267 if(Client::isConnected())
268 icon = DesktopIcon("quassel", size);
270 icon = DesktopIcon("quassel_inactive", size);
272 qApp->setWindowIcon(icon);
275 void MainWin::setupActions() {
276 ActionCollection *coll = QtUi::actionCollection("General");
278 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
279 this, SLOT(showCoreConnectionDlg())));
280 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
281 Client::instance(), SLOT(disconnectFromCore())));
282 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
283 this, SLOT(showCoreInfoDlg())));
284 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
285 this, SLOT(on_actionConfigureNetworks_triggered())));
286 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
287 this, SLOT(quit()), tr("Ctrl+Q")));
290 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
291 this, SLOT(on_actionConfigureViews_triggered())));
293 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
294 lockAct->setCheckable(true);
295 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
297 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
298 0, 0, QKeySequence::Find))->setCheckable(true);
299 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
300 this, SLOT(showAwayLog())));
301 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
302 0, 0))->setCheckable(true);
305 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
306 this, SLOT(showSettingsDlg()), tr("F7")));
309 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
310 this, SLOT(showAboutDlg())));
311 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
312 qApp, SLOT(aboutQt())));
313 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
314 this, SLOT(on_actionDebugNetworkModel_triggered())));
315 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
316 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
317 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
318 this, SLOT(on_actionDebugMessageModel_triggered())));
319 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
320 this, SLOT(on_actionDebugHotList_triggered())));
321 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
322 this, SLOT(on_actionDebugLog_triggered())));
323 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
324 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
327 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
328 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
331 void MainWin::setupMenus() {
332 ActionCollection *coll = QtUi::actionCollection("General");
334 _fileMenu = menuBar()->addMenu(tr("&File"));
336 static const QStringList coreActions = QStringList()
337 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
340 foreach(QString actionName, coreActions) {
341 coreAction = coll->action(actionName);
342 _fileMenu->addAction(coreAction);
343 flagRemoteCoreOnly(coreAction);
345 flagRemoteCoreOnly(_fileMenu->addSeparator());
347 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
348 _networksMenu->addAction(coll->action("ConfigureNetworks"));
349 _networksMenu->addSeparator();
350 _fileMenu->addSeparator();
351 _fileMenu->addAction(coll->action("Quit"));
353 _viewMenu = menuBar()->addMenu(tr("&View"));
354 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
355 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
356 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
357 _viewMenu->addSeparator();
358 _viewMenu->addAction(coll->action("ToggleSearchBar"));
360 coreAction = coll->action("ShowAwayLog");
361 flagRemoteCoreOnly(coreAction);
362 _viewMenu->addAction(coreAction);
364 _viewMenu->addAction(coll->action("ToggleStatusBar"));
365 _viewMenu->addSeparator();
366 _viewMenu->addAction(coll->action("LockLayout"));
368 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
370 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
371 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
373 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
375 _helpMenu = menuBar()->addMenu(tr("&Help"));
376 _helpMenu->addAction(coll->action("AboutQuassel"));
378 _helpMenu->addAction(coll->action("AboutQt"));
380 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
382 _helpMenu->addSeparator();
383 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
384 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
385 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
386 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
387 _helpDebugMenu->addAction(coll->action("DebugHotList"));
388 _helpDebugMenu->addAction(coll->action("DebugLog"));
389 _helpDebugMenu->addSeparator();
390 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
393 void MainWin::setupBufferWidget() {
394 _bufferWidget = new BufferWidget(this);
395 _bufferWidget->setModel(Client::bufferModel());
396 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
397 setCentralWidget(_bufferWidget);
400 void MainWin::addBufferView(int bufferViewConfigId) {
401 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
404 void MainWin::addBufferView(ClientBufferViewConfig *config) {
408 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
409 BufferViewDock *dock = new BufferViewDock(config, this);
411 //create the view and initialize it's filter
412 BufferView *view = new BufferView(dock);
413 view->setFilteredModel(Client::bufferModel(), config);
414 view->installEventFilter(_inputWidget); // for key presses
417 Client::bufferModel()->synchronizeView(view);
419 dock->setWidget(view);
422 addDockWidget(Qt::LeftDockWidgetArea, dock);
423 _bufferViewsMenu->addAction(dock->toggleViewAction());
425 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
426 _bufferViews.append(dock);
429 void MainWin::removeBufferView(int bufferViewConfigId) {
431 BufferViewDock *dock;
432 foreach(QAction *action, _bufferViewsMenu->actions()) {
433 actionData = action->data();
434 if(!actionData.isValid())
437 dock = qobject_cast<BufferViewDock *>(action->parent());
438 if(dock && actionData.toInt() == bufferViewConfigId) {
439 removeAction(action);
445 void MainWin::bufferViewToggled(bool enabled) {
446 QAction *action = qobject_cast<QAction *>(sender());
448 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
451 Client::bufferViewOverlay()->addView(dock->bufferViewId());
452 BufferViewConfig *config = dock->config();
453 if(config && config->isInitialized()) {
454 BufferIdList buffers;
455 if(config->networkId().isValid()) {
456 foreach(BufferId bufferId, config->bufferList()) {
457 if(Client::networkModel()->networkId(bufferId) == config->networkId())
460 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
461 if(Client::networkModel()->networkId(bufferId) == config->networkId())
465 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
467 Client::backlogManager()->checkForBacklog(buffers);
470 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
474 BufferView *MainWin::allBuffersView() const {
475 // "All Buffers" is always the first dock created
476 if(_bufferViews.count() > 0)
477 return _bufferViews[0]->bufferView();
481 void MainWin::showNotificationsDlg() {
482 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
486 void MainWin::on_actionConfigureNetworks_triggered() {
487 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
491 void MainWin::on_actionConfigureViews_triggered() {
492 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
496 void MainWin::on_actionLockLayout_toggled(bool lock) {
497 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
498 foreach(VerticalDock *dock, docks) {
499 dock->showTitle(!lock);
501 if(Client::bufferViewManager()) {
502 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
503 config->setLocked(lock);
506 QtUiSettings().setValue("LockLayout", lock);
509 void MainWin::setupNickWidget() {
511 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
512 nickDock->setObjectName("NickDock");
513 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
515 _nickListWidget = new NickListWidget(nickDock);
516 nickDock->setWidget(_nickListWidget);
518 addDockWidget(Qt::RightDockWidgetArea, nickDock);
519 _viewMenu->addAction(nickDock->toggleViewAction());
520 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
522 // See NickListDock::NickListDock();
523 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
525 // attach the NickListWidget to the BufferModel and the default selection
526 _nickListWidget->setModel(Client::bufferModel());
527 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
530 void MainWin::setupChatMonitor() {
531 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
532 dock->setObjectName("ChatMonitorDock");
534 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
535 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
537 dock->setWidget(chatView);
540 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
541 _viewMenu->addAction(dock->toggleViewAction());
542 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
545 void MainWin::setupInputWidget() {
546 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
547 dock->setObjectName("InputDock");
549 _inputWidget = new InputWidget(dock);
550 dock->setWidget(_inputWidget);
552 addDockWidget(Qt::BottomDockWidgetArea, dock);
554 _viewMenu->addAction(dock->toggleViewAction());
555 dock->toggleViewAction()->setText(tr("Show Input Line"));
557 _inputWidget->setModel(Client::bufferModel());
558 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
560 _bufferWidget->setFocusProxy(_inputWidget);
562 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
565 void MainWin::setupTopicWidget() {
566 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
567 dock->setObjectName("TopicDock");
568 TopicWidget *topicwidget = new TopicWidget(dock);
570 dock->setWidget(topicwidget);
572 topicwidget->setModel(Client::bufferModel());
573 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
575 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
577 _viewMenu->addAction(dock->toggleViewAction());
578 dock->toggleViewAction()->setText(tr("Show Topic Line"));
581 void MainWin::setupTitleSetter() {
582 _titleSetter.setModel(Client::bufferModel());
583 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
586 void MainWin::setupStatusBar() {
587 // MessageProcessor progress
588 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
591 updateLagIndicator();
592 statusBar()->addPermanentWidget(coreLagLabel);
593 coreLagLabel->hide();
594 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
597 sslLabel->setPixmap(QPixmap());
598 statusBar()->addPermanentWidget(sslLabel);
601 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
603 QtUiSettings uiSettings;
605 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
606 showStatusbar->setChecked(enabled);
607 enabled ? statusBar()->show() : statusBar()->hide();
609 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
610 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
613 void MainWin::setupHotList() {
614 FlatProxyModel *flatProxy = new FlatProxyModel(this);
615 flatProxy->setSourceModel(Client::bufferModel());
616 _bufferHotList = new BufferHotListFilter(flatProxy);
619 void MainWin::saveStatusBarStatus(bool enabled) {
620 QtUiSettings uiSettings;
621 uiSettings.setValue("ShowStatusBar", enabled);
624 void MainWin::setupSystray() {
625 _systemTray = new SystemTray(this);
628 void MainWin::setupToolBars() {
629 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
630 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
631 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
632 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
635 setUnifiedTitleAndToolBarOnMac(true);
639 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
641 _mainToolBar = new QToolBar(this);
642 _mainToolBar->setObjectName("MainToolBar");
644 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
645 addToolBar(_mainToolBar);
647 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
648 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
651 void MainWin::connectedToCore() {
652 Q_CHECK_PTR(Client::bufferViewManager());
653 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
654 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
655 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
660 void MainWin::setConnectedState() {
661 ActionCollection *coll = QtUi::actionCollection("General");
663 coll->action("ConnectCore")->setEnabled(false);
664 coll->action("DisconnectCore")->setEnabled(true);
665 coll->action("CoreInfo")->setEnabled(true);
667 foreach(QAction *action, _fileMenu->actions()) {
668 if(isRemoteCoreOnly(action))
669 action->setVisible(!Client::internalCore());
672 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
673 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
674 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
675 if(!Client::internalCore()) {
676 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
677 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
678 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
681 // _viewMenu->setEnabled(true);
682 if(!Client::internalCore())
683 statusBar()->showMessage(tr("Connected to core."));
685 statusBar()->clearMessage();
687 if(Client::signalProxy()->isSecure()) {
688 sslLabel->setPixmap(SmallIcon("security-high"));
690 sslLabel->setPixmap(SmallIcon("security-low"));
693 sslLabel->setVisible(!Client::internalCore());
694 coreLagLabel->setVisible(!Client::internalCore());
696 systemTray()->setState(SystemTray::Active);
698 if(Client::networkIds().isEmpty()) {
699 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
704 void MainWin::loadLayout() {
706 int accountId = Client::currentCoreAccount().toInt();
707 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
710 void MainWin::saveLayout() {
712 int accountId = Client::currentCoreAccount().toInt();
713 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
716 void MainWin::updateLagIndicator(int lag) {
717 QString text = tr("Core Lag: %1");
719 text = text.arg('-');
721 text = text.arg("%1 msec").arg(lag);
722 coreLagLabel->setText(text);
725 void MainWin::disconnectedFromCore() {
726 // save core specific layout and remove bufferviews;
729 BufferViewDock *dock;
730 foreach(QAction *action, _bufferViewsMenu->actions()) {
731 actionData = action->data();
732 if(!actionData.isValid())
735 dock = qobject_cast<BufferViewDock *>(action->parent());
736 if(dock && actionData.toInt() != -1) {
737 removeAction(action);
742 restoreState(s.value("MainWinState").toByteArray());
743 setDisconnectedState();
746 void MainWin::setDisconnectedState() {
747 ActionCollection *coll = QtUi::actionCollection("General");
748 //ui.menuCore->setEnabled(false);
749 coll->action("ConnectCore")->setEnabled(true);
750 coll->action("DisconnectCore")->setEnabled(false);
751 coll->action("CoreInfo")->setEnabled(false);
752 //_viewMenu->setEnabled(false);
753 statusBar()->showMessage(tr("Not connected to core."));
754 sslLabel->setPixmap(QPixmap());
756 updateLagIndicator();
757 coreLagLabel->hide();
758 if(msgProcessorStatusWidget)
759 msgProcessorStatusWidget->setProgress(0, 0);
761 systemTray()->setState(SystemTray::Inactive);
764 void MainWin::startInternalCore() {
765 ClientSyncer *syncer = new ClientSyncer();
766 Client::registerClientSyncer(syncer);
767 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
768 syncer->useInternalCore();
771 void MainWin::showCoreConnectionDlg(bool autoConnect) {
772 CoreConnectDlg(autoConnect, this).exec();
775 void MainWin::showChannelList(NetworkId netId) {
776 ChannelListDlg *channelListDlg = new ChannelListDlg();
778 if(!netId.isValid()) {
779 QAction *action = qobject_cast<QAction *>(sender());
781 netId = action->data().value<NetworkId>();
784 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
785 channelListDlg->setNetwork(netId);
786 channelListDlg->show();
789 void MainWin::showCoreInfoDlg() {
790 CoreInfoDlg(this).exec();
793 void MainWin::showAwayLog() {
796 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
797 _awayLog = new AwayLogView(filter, 0);
798 filter->setParent(_awayLog);
799 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
800 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
804 void MainWin::awayLogDestroyed() {
808 void MainWin::showSettingsDlg() {
809 SettingsDlg *dlg = new SettingsDlg();
811 //Category: Interface
812 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
813 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
814 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
815 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
816 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
817 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
818 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
819 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
820 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
823 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
824 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
825 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
826 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
827 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
832 void MainWin::showAboutDlg() {
833 AboutDlg(this).exec();
837 void MainWin::showShortcutsDlg() {
838 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
842 /********************************************************************************************************/
844 bool MainWin::event(QEvent *event) {
845 if(event->type() == QEvent::WindowActivate)
846 QtUi::closeNotifications();
847 return QMainWindow::event(event);
850 void MainWin::moveEvent(QMoveEvent *event) {
851 if(!(windowState() & Qt::WindowMaximized))
852 _normalPos = event->pos();
854 QMainWindow::moveEvent(event);
857 void MainWin::resizeEvent(QResizeEvent *event) {
858 if(!(windowState() & Qt::WindowMaximized))
859 _normalSize = event->size();
861 QMainWindow::resizeEvent(event);
864 void MainWin::closeEvent(QCloseEvent *event) {
866 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
868 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
877 void MainWin::changeEvent(QEvent *event) {
879 if(event->type() == QEvent::ActivationChange)
880 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
883 QMainWindow::changeEvent(event);
886 void MainWin::hideToTray() {
887 if(!systemTray()->isSystemTrayAvailable()) {
888 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
892 systemTray()->setIconVisible();
895 void MainWin::toggleMinimizedToTray() {
897 // the problem is that we lose focus when the systray icon is activated
898 // and we don't know the former active window
899 // therefore we watch for activation event and use our stopwatch :)
900 // courtesy: KSystemTrayIcon
901 if(GetTickCount() - dwTickCount >= 300)
902 // we weren't active in the last 300ms -> activate
909 if(!isVisible() || isMinimized())
918 void MainWin::forceActivated() {
920 // Bypass focus stealing prevention
921 QX11Info::setAppUserTime(QX11Info::appTime());
924 if(windowState() & Qt::WindowMinimized) {
926 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
929 // this does not actually work on all platforms... and causes more evil than good
930 // move(frameGeometry().topLeft()); // avoid placement policies
936 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
939 bool hasFocus = QApplication::activeWindow() != 0;
941 for(int i = start; i <= end; i++) {
942 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
944 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
947 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
948 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
951 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
952 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
954 if(hasFocus && bufId == _bufferWidget->currentBuffer())
957 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
958 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
959 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
960 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
961 AbstractNotificationBackend::NotificationType type;
963 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
964 type = AbstractNotificationBackend::PrivMsg;
965 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
966 type = AbstractNotificationBackend::PrivMsgFocused;
967 else if(flags & Message::Highlight && !hasFocus)
968 type = AbstractNotificationBackend::Highlight;
970 type = AbstractNotificationBackend::HighlightFocused;
972 QtUi::invokeNotification(bufId, type, sender, contents);
977 void MainWin::clientNetworkCreated(NetworkId id) {
978 const Network *net = Client::network(id);
979 QAction *act = new QAction(net->networkName(), this);
980 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
981 act->setData(QVariant::fromValue<NetworkId>(id));
982 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
983 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
985 QAction *beforeAction = 0;
986 foreach(QAction *action, _networksMenu->actions()) {
987 if(!action->data().isValid()) // ignore stock actions
989 if(net->networkName().localeAwareCompare(action->text()) < 0) {
990 beforeAction = action;
994 _networksMenu->insertAction(beforeAction, act);
997 void MainWin::clientNetworkUpdated() {
998 const Network *net = qobject_cast<const Network *>(sender());
1002 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1006 action->setText(net->networkName());
1008 switch(net->connectionState()) {
1009 case Network::Initialized:
1010 action->setIcon(SmallIcon("network-connect"));
1012 case Network::Disconnected:
1013 action->setIcon(SmallIcon("network-disconnect"));
1016 action->setIcon(SmallIcon("network-wired"));
1020 void MainWin::clientNetworkRemoved(NetworkId id) {
1021 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1025 action->deleteLater();
1028 void MainWin::connectOrDisconnectFromNet() {
1029 QAction *act = qobject_cast<QAction *>(sender());
1031 const Network *net = Client::network(act->data().value<NetworkId>());
1033 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1034 else net->requestDisconnect();
1037 void MainWin::on_jumpHotBuffer_triggered() {
1038 if(!_bufferHotList->rowCount())
1041 QModelIndex topIndex = _bufferHotList->index(0, 0);
1042 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1043 Client::bufferModel()->switchToBuffer(bufferId);
1046 void MainWin::on_actionDebugNetworkModel_triggered() {
1047 QTreeView *view = new QTreeView;
1048 view->setAttribute(Qt::WA_DeleteOnClose);
1049 view->setWindowTitle("Debug NetworkModel View");
1050 view->setModel(Client::networkModel());
1051 view->setColumnWidth(0, 250);
1052 view->setColumnWidth(1, 250);
1053 view->setColumnWidth(2, 80);
1054 view->resize(610, 300);
1058 void MainWin::on_actionDebugHotList_triggered() {
1059 QTreeView *view = new QTreeView;
1060 view->setAttribute(Qt::WA_DeleteOnClose);
1061 view->setModel(_bufferHotList);
1065 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1066 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1067 overlay->setAttribute(Qt::WA_DeleteOnClose);
1071 void MainWin::on_actionDebugMessageModel_triggered() {
1072 QTableView *view = new QTableView(0);
1073 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1074 filter->setSourceModel(Client::messageModel());
1075 view->setModel(filter);
1076 view->setAttribute(Qt::WA_DeleteOnClose, true);
1077 view->verticalHeader()->hide();
1078 view->horizontalHeader()->setStretchLastSection(true);
1082 void MainWin::on_actionDebugLog_triggered() {
1083 DebugLogWidget *logWidget = new DebugLogWidget(0);
1087 void MainWin::showStatusBarMessage(const QString &message) {
1088 statusBar()->showMessage(message, 10000);