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 "inputline.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 "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/colorsettingspage.h"
101 #include "settingspages/connectionsettingspage.h"
102 #include "settingspages/generalsettingspage.h"
103 #include "settingspages/highlightsettingspage.h"
104 #include "settingspages/identitiessettingspage.h"
105 #include "settingspages/networkssettingspage.h"
106 #include "settingspages/notificationssettingspage.h"
108 MainWin::MainWin(QWidget *parent)
110 : KMainWindow(parent),
111 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
113 : QMainWindow(parent),
115 coreLagLabel(new QLabel()),
116 sslLabel(new QLabel()),
117 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
125 QtUiSettings uiSettings;
126 QString style = uiSettings.value("Style", QString()).toString();
127 if(!style.isEmpty()) {
128 QApplication::setStyle(style);
131 QApplication::setQuitOnLastWindowClosed(false);
133 setWindowTitle("Quassel IRC");
134 setWindowIconText("Quassel IRC");
137 installEventFilter(new JumpKeyHandler(this));
140 void MainWin::init() {
141 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
142 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
143 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
144 SLOT(messagesInserted(const QModelIndex &, int, int)));
145 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
148 setDockNestingEnabled(true);
149 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
150 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
151 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
152 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
154 // Order is sometimes important
169 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
170 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
172 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
175 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
179 QtUi::registerNotificationBackend(new KNotificationBackend(this));
180 #endif /* HAVE_KDE */
182 setDisconnectedState(); // Disable menus and stuff
185 setAutoSaveSettings();
188 // restore mainwin state
190 restoreStateFromSettings(s);
192 // restore locked state of docks
193 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
195 if(Quassel::runMode() != Quassel::Monolithic) {
196 showCoreConnectionDlg(true); // autoconnect if appropriate
202 MainWin::~MainWin() {
206 void MainWin::quit() {
208 saveStateToSettings(s);
210 QApplication::quit();
213 void MainWin::saveStateToSettings(UiSettings &s) {
214 s.setValue("MainWinSize", _normalSize);
215 s.setValue("MainWinPos", _normalPos);
216 s.setValue("MainWinState", saveState());
217 s.setValue("MainWinGeometry", saveGeometry());
218 s.setValue("MainWinMinimized", isMinimized());
219 s.setValue("MainWinMaximized", isMaximized());
220 s.setValue("MainWinHidden", !isVisible());
223 saveAutoSaveSettings();
227 void MainWin::restoreStateFromSettings(UiSettings &s) {
228 _normalSize = s.value("MainWinSize", size()).toSize();
229 _normalPos = s.value("MainWinPos", pos()).toPoint();
230 bool maximized = s.value("MainWinMaximized", false).toBool();
233 restoreGeometry(s.value("MainWinGeometry").toByteArray());
236 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
241 restoreState(s.value("MainWinState").toByteArray());
247 if(s.value("MainWinHidden").toBool())
249 else if(s.value("MainWinMinimized").toBool())
257 void MainWin::updateIcon() {
259 const int size = 128;
265 if(Client::isConnected())
266 icon = DesktopIcon("quassel", size);
268 icon = DesktopIcon("quassel_inactive", size);
270 qApp->setWindowIcon(icon);
273 void MainWin::setupActions() {
274 ActionCollection *coll = QtUi::actionCollection("General");
276 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
277 this, SLOT(showCoreConnectionDlg())));
278 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
279 Client::instance(), SLOT(disconnectFromCore())));
280 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
281 this, SLOT(showCoreInfoDlg())));
282 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
283 this, SLOT(on_actionConfigureNetworks_triggered())));
284 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
285 this, SLOT(quit()), tr("Ctrl+Q")));
288 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
289 this, SLOT(on_actionConfigureViews_triggered())));
291 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
292 lockAct->setCheckable(true);
293 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
295 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
296 0, 0, QKeySequence::Find))->setCheckable(true);
297 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
298 this, SLOT(showAwayLog())));
299 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
300 0, 0))->setCheckable(true);
303 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
304 this, SLOT(showSettingsDlg()), tr("F7")));
307 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
308 this, SLOT(showAboutDlg())));
309 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
310 qApp, SLOT(aboutQt())));
311 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
312 this, SLOT(on_actionDebugNetworkModel_triggered())));
313 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
314 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
315 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
316 this, SLOT(on_actionDebugMessageModel_triggered())));
317 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
318 this, SLOT(on_actionDebugHotList_triggered())));
319 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
320 this, SLOT(on_actionDebugLog_triggered())));
323 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot buffer"), coll,
324 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
327 void MainWin::setupMenus() {
328 ActionCollection *coll = QtUi::actionCollection("General");
330 _fileMenu = menuBar()->addMenu(tr("&File"));
332 static const QStringList coreActions = QStringList()
333 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
336 foreach(QString actionName, coreActions) {
337 coreAction = coll->action(actionName);
338 _fileMenu->addAction(coreAction);
339 flagRemoteCoreOnly(coreAction);
341 flagRemoteCoreOnly(_fileMenu->addSeparator());
343 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
344 _networksMenu->addAction(coll->action("ConfigureNetworks"));
345 _networksMenu->addSeparator();
346 _fileMenu->addSeparator();
347 _fileMenu->addAction(coll->action("Quit"));
349 _viewMenu = menuBar()->addMenu(tr("&View"));
350 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
351 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
352 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
353 _viewMenu->addSeparator();
354 _viewMenu->addAction(coll->action("ToggleSearchBar"));
356 coreAction = coll->action("ShowAwayLog");
357 flagRemoteCoreOnly(coreAction);
358 _viewMenu->addAction(coreAction);
360 _viewMenu->addAction(coll->action("ToggleStatusBar"));
361 _viewMenu->addSeparator();
362 _viewMenu->addAction(coll->action("LockLayout"));
364 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
366 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
367 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
369 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
371 _helpMenu = menuBar()->addMenu(tr("&Help"));
372 _helpMenu->addAction(coll->action("AboutQuassel"));
374 _helpMenu->addAction(coll->action("AboutQt"));
376 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
378 _helpMenu->addSeparator();
379 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
380 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
381 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
382 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
383 _helpDebugMenu->addAction(coll->action("DebugHotList"));
384 _helpDebugMenu->addAction(coll->action("DebugLog"));
387 void MainWin::setupBufferWidget() {
388 _bufferWidget = new BufferWidget(this);
389 _bufferWidget->setModel(Client::bufferModel());
390 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
391 setCentralWidget(_bufferWidget);
394 void MainWin::addBufferView(int bufferViewConfigId) {
395 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
398 void MainWin::addBufferView(ClientBufferViewConfig *config) {
402 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
403 BufferViewDock *dock = new BufferViewDock(config, this);
405 //create the view and initialize it's filter
406 BufferView *view = new BufferView(dock);
407 view->setFilteredModel(Client::bufferModel(), config);
408 view->installEventFilter(_inputWidget->inputLine()); // for key presses
411 Client::bufferModel()->synchronizeView(view);
413 dock->setWidget(view);
416 addDockWidget(Qt::LeftDockWidgetArea, dock);
417 _bufferViewsMenu->addAction(dock->toggleViewAction());
419 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
420 _bufferViews.append(dock);
423 void MainWin::removeBufferView(int bufferViewConfigId) {
425 BufferViewDock *dock;
426 foreach(QAction *action, _bufferViewsMenu->actions()) {
427 actionData = action->data();
428 if(!actionData.isValid())
431 dock = qobject_cast<BufferViewDock *>(action->parent());
432 if(dock && actionData.toInt() == bufferViewConfigId) {
433 removeAction(action);
439 void MainWin::bufferViewToggled(bool enabled) {
440 QAction *action = qobject_cast<QAction *>(sender());
442 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
445 Client::bufferViewOverlay()->addView(dock->bufferViewId());
446 BufferViewConfig *config = dock->config();
447 if(config && config->isInitialized()) {
448 BufferIdList buffers;
449 if(config->networkId().isValid()) {
450 foreach(BufferId bufferId, config->bufferList()) {
451 if(Client::networkModel()->networkId(bufferId) == config->networkId())
454 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
455 if(Client::networkModel()->networkId(bufferId) == config->networkId())
459 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
461 Client::backlogManager()->checkForBacklog(buffers);
464 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
468 BufferView *MainWin::allBuffersView() const {
469 // "All Buffers" is always the first dock created
470 if(_bufferViews.count() > 0)
471 return _bufferViews[0]->bufferView();
475 void MainWin::showNotificationsDlg() {
476 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
480 void MainWin::on_actionConfigureNetworks_triggered() {
481 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
485 void MainWin::on_actionConfigureViews_triggered() {
486 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
490 void MainWin::on_actionLockLayout_toggled(bool lock) {
491 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
492 foreach(VerticalDock *dock, docks) {
493 dock->showTitle(!lock);
495 if(Client::bufferViewManager()) {
496 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
497 config->setLocked(lock);
500 QtUiSettings().setValue("LockLayout", lock);
503 void MainWin::setupNickWidget() {
505 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
506 nickDock->setObjectName("NickDock");
507 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
509 _nickListWidget = new NickListWidget(nickDock);
510 nickDock->setWidget(_nickListWidget);
512 addDockWidget(Qt::RightDockWidgetArea, nickDock);
513 _viewMenu->addAction(nickDock->toggleViewAction());
514 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
516 // See NickListDock::NickListDock();
517 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
519 // attach the NickListWidget to the BufferModel and the default selection
520 _nickListWidget->setModel(Client::bufferModel());
521 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
524 void MainWin::setupChatMonitor() {
525 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
526 dock->setObjectName("ChatMonitorDock");
528 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
529 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
531 dock->setWidget(chatView);
534 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
535 _viewMenu->addAction(dock->toggleViewAction());
536 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
539 void MainWin::setupInputWidget() {
540 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
541 dock->setObjectName("InputDock");
543 _inputWidget = new InputWidget(dock);
544 dock->setWidget(_inputWidget);
546 addDockWidget(Qt::BottomDockWidgetArea, dock);
548 _viewMenu->addAction(dock->toggleViewAction());
549 dock->toggleViewAction()->setText(tr("Show Input Line"));
551 _inputWidget->setModel(Client::bufferModel());
552 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
554 _bufferWidget->setFocusProxy(_inputWidget);
556 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
559 void MainWin::setupTopicWidget() {
560 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
561 dock->setObjectName("TopicDock");
562 TopicWidget *topicwidget = new TopicWidget(dock);
564 dock->setWidget(topicwidget);
566 topicwidget->setModel(Client::bufferModel());
567 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
569 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
571 _viewMenu->addAction(dock->toggleViewAction());
572 dock->toggleViewAction()->setText(tr("Show Topic Line"));
575 void MainWin::setupTitleSetter() {
576 _titleSetter.setModel(Client::bufferModel());
577 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
580 void MainWin::setupStatusBar() {
581 // MessageProcessor progress
582 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
585 updateLagIndicator();
586 statusBar()->addPermanentWidget(coreLagLabel);
587 coreLagLabel->hide();
588 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
591 sslLabel->setPixmap(QPixmap());
592 statusBar()->addPermanentWidget(sslLabel);
595 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
597 QtUiSettings uiSettings;
599 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
600 showStatusbar->setChecked(enabled);
601 enabled ? statusBar()->show() : statusBar()->hide();
603 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
604 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
607 void MainWin::setupHotList() {
608 FlatProxyModel *flatProxy = new FlatProxyModel(this);
609 flatProxy->setSourceModel(Client::bufferModel());
610 _bufferHotList = new BufferHotListFilter(flatProxy);
613 void MainWin::saveStatusBarStatus(bool enabled) {
614 QtUiSettings uiSettings;
615 uiSettings.setValue("ShowStatusBar", enabled);
618 void MainWin::setupSystray() {
619 _systemTray = new SystemTray(this);
622 void MainWin::setupToolBars() {
623 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
624 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
625 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
626 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
629 setUnifiedTitleAndToolBarOnMac(true);
633 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
635 _mainToolBar = new QToolBar(this);
636 _mainToolBar->setObjectName("MainToolBar");
638 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
639 addToolBar(_mainToolBar);
641 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
642 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
645 void MainWin::connectedToCore() {
646 Q_CHECK_PTR(Client::bufferViewManager());
647 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
648 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
649 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
654 void MainWin::setConnectedState() {
655 ActionCollection *coll = QtUi::actionCollection("General");
657 coll->action("ConnectCore")->setEnabled(false);
658 coll->action("DisconnectCore")->setEnabled(true);
659 coll->action("CoreInfo")->setEnabled(true);
661 foreach(QAction *action, _fileMenu->actions()) {
662 if(isRemoteCoreOnly(action))
663 action->setVisible(!Client::internalCore());
666 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
667 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
668 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
669 if(!Client::internalCore()) {
670 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
671 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
672 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
675 // _viewMenu->setEnabled(true);
676 if(!Client::internalCore())
677 statusBar()->showMessage(tr("Connected to core."));
679 statusBar()->clearMessage();
681 if(Client::signalProxy()->isSecure()) {
682 sslLabel->setPixmap(SmallIcon("security-high"));
684 sslLabel->setPixmap(SmallIcon("security-low"));
687 sslLabel->setVisible(!Client::internalCore());
688 coreLagLabel->setVisible(!Client::internalCore());
690 systemTray()->setState(SystemTray::Active);
692 if(Client::networkIds().isEmpty()) {
693 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
698 void MainWin::loadLayout() {
700 int accountId = Client::currentCoreAccount().toInt();
701 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
704 void MainWin::saveLayout() {
706 int accountId = Client::currentCoreAccount().toInt();
707 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
710 void MainWin::updateLagIndicator(int lag) {
711 QString text = tr("Core Lag: %1");
713 text = text.arg('-');
715 text = text.arg("%1 msec").arg(lag);
716 coreLagLabel->setText(text);
719 void MainWin::disconnectedFromCore() {
720 // save core specific layout and remove bufferviews;
723 BufferViewDock *dock;
724 foreach(QAction *action, _bufferViewsMenu->actions()) {
725 actionData = action->data();
726 if(!actionData.isValid())
729 dock = qobject_cast<BufferViewDock *>(action->parent());
730 if(dock && actionData.toInt() != -1) {
731 removeAction(action);
736 restoreState(s.value("MainWinState").toByteArray());
737 setDisconnectedState();
740 void MainWin::setDisconnectedState() {
741 ActionCollection *coll = QtUi::actionCollection("General");
742 //ui.menuCore->setEnabled(false);
743 coll->action("ConnectCore")->setEnabled(true);
744 coll->action("DisconnectCore")->setEnabled(false);
745 coll->action("CoreInfo")->setEnabled(false);
746 //_viewMenu->setEnabled(false);
747 statusBar()->showMessage(tr("Not connected to core."));
748 sslLabel->setPixmap(QPixmap());
750 updateLagIndicator();
751 coreLagLabel->hide();
752 if(msgProcessorStatusWidget)
753 msgProcessorStatusWidget->setProgress(0, 0);
755 systemTray()->setState(SystemTray::Inactive);
758 void MainWin::startInternalCore() {
759 ClientSyncer *syncer = new ClientSyncer();
760 Client::registerClientSyncer(syncer);
761 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
762 syncer->useInternalCore();
765 void MainWin::showCoreConnectionDlg(bool autoConnect) {
766 CoreConnectDlg(autoConnect, this).exec();
769 void MainWin::showChannelList(NetworkId netId) {
770 ChannelListDlg *channelListDlg = new ChannelListDlg();
772 if(!netId.isValid()) {
773 QAction *action = qobject_cast<QAction *>(sender());
775 netId = action->data().value<NetworkId>();
778 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
779 channelListDlg->setNetwork(netId);
780 channelListDlg->show();
783 void MainWin::showCoreInfoDlg() {
784 CoreInfoDlg(this).exec();
787 void MainWin::showAwayLog() {
790 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
791 _awayLog = new AwayLogView(filter, 0);
792 filter->setParent(_awayLog);
793 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
794 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
798 void MainWin::awayLogDestroyed() {
802 void MainWin::showSettingsDlg() {
803 SettingsDlg *dlg = new SettingsDlg();
805 //Category: Appearance
806 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
807 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
808 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
809 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
810 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
811 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
812 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
815 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
816 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
817 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
818 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
819 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
824 void MainWin::showAboutDlg() {
825 AboutDlg(this).exec();
829 void MainWin::showShortcutsDlg() {
830 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
834 /********************************************************************************************************/
836 bool MainWin::event(QEvent *event) {
837 if(event->type() == QEvent::WindowActivate)
838 QtUi::closeNotifications();
839 return QMainWindow::event(event);
842 void MainWin::moveEvent(QMoveEvent *event) {
843 if(!(windowState() & Qt::WindowMaximized))
844 _normalPos = event->pos();
846 QMainWindow::moveEvent(event);
849 void MainWin::resizeEvent(QResizeEvent *event) {
850 if(!(windowState() & Qt::WindowMaximized))
851 _normalSize = event->size();
853 QMainWindow::resizeEvent(event);
856 void MainWin::closeEvent(QCloseEvent *event) {
858 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
860 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
869 void MainWin::changeEvent(QEvent *event) {
871 if(event->type() == QEvent::ActivationChange)
872 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
875 QMainWindow::changeEvent(event);
878 void MainWin::hideToTray() {
879 if(!systemTray()->isSystemTrayAvailable()) {
880 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
884 systemTray()->setIconVisible();
887 void MainWin::toggleMinimizedToTray() {
889 // the problem is that we lose focus when the systray icon is activated
890 // and we don't know the former active window
891 // therefore we watch for activation event and use our stopwatch :)
892 // courtesy: KSystemTrayIcon
893 if(GetTickCount() - dwTickCount >= 300)
894 // we weren't active in the last 300ms -> activate
901 if(!isVisible() || isMinimized())
910 void MainWin::forceActivated() {
912 // Bypass focus stealing prevention
913 QX11Info::setAppUserTime(QX11Info::appTime());
916 if(windowState() & Qt::WindowMinimized) {
918 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
921 // this does not actually work on all platforms... and causes more evil than good
922 // move(frameGeometry().topLeft()); // avoid placement policies
928 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
931 bool hasFocus = QApplication::activeWindow() != 0;
933 for(int i = start; i <= end; i++) {
934 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
936 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
939 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
940 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
942 flags |= Message::Backlog; // we only want to trigger a highlight once!
943 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
945 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
946 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
948 if(hasFocus && bufId == _bufferWidget->currentBuffer())
951 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
952 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
953 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
954 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
955 AbstractNotificationBackend::NotificationType type;
957 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
958 type = AbstractNotificationBackend::PrivMsg;
959 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
960 type = AbstractNotificationBackend::PrivMsgFocused;
961 else if(flags & Message::Highlight && !hasFocus)
962 type = AbstractNotificationBackend::Highlight;
964 type = AbstractNotificationBackend::HighlightFocused;
966 QtUi::invokeNotification(bufId, type, sender, contents);
971 void MainWin::clientNetworkCreated(NetworkId id) {
972 const Network *net = Client::network(id);
973 QAction *act = new QAction(net->networkName(), this);
974 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
975 act->setData(QVariant::fromValue<NetworkId>(id));
976 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
977 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
979 QAction *beforeAction = 0;
980 foreach(QAction *action, _networksMenu->actions()) {
981 if(!action->data().isValid()) // ignore stock actions
983 if(net->networkName().localeAwareCompare(action->text()) < 0) {
984 beforeAction = action;
988 _networksMenu->insertAction(beforeAction, act);
991 void MainWin::clientNetworkUpdated() {
992 const Network *net = qobject_cast<const Network *>(sender());
996 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1000 action->setText(net->networkName());
1002 switch(net->connectionState()) {
1003 case Network::Initialized:
1004 action->setIcon(SmallIcon("network-connect"));
1006 case Network::Disconnected:
1007 action->setIcon(SmallIcon("network-disconnect"));
1010 action->setIcon(SmallIcon("network-wired"));
1014 void MainWin::clientNetworkRemoved(NetworkId id) {
1015 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1019 action->deleteLater();
1022 void MainWin::connectOrDisconnectFromNet() {
1023 QAction *act = qobject_cast<QAction *>(sender());
1025 const Network *net = Client::network(act->data().value<NetworkId>());
1027 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1028 else net->requestDisconnect();
1031 void MainWin::on_jumpHotBuffer_triggered() {
1032 if(!_bufferHotList->rowCount())
1035 QModelIndex topIndex = _bufferHotList->index(0, 0);
1036 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1037 Client::bufferModel()->switchToBuffer(bufferId);
1040 void MainWin::on_actionDebugNetworkModel_triggered() {
1041 QTreeView *view = new QTreeView;
1042 view->setAttribute(Qt::WA_DeleteOnClose);
1043 view->setWindowTitle("Debug NetworkModel View");
1044 view->setModel(Client::networkModel());
1045 view->setColumnWidth(0, 250);
1046 view->setColumnWidth(1, 250);
1047 view->setColumnWidth(2, 80);
1048 view->resize(610, 300);
1052 void MainWin::on_actionDebugHotList_triggered() {
1053 QTreeView *view = new QTreeView;
1054 view->setAttribute(Qt::WA_DeleteOnClose);
1055 view->setModel(_bufferHotList);
1059 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1060 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1061 overlay->setAttribute(Qt::WA_DeleteOnClose);
1065 void MainWin::on_actionDebugMessageModel_triggered() {
1066 QTableView *view = new QTableView(0);
1067 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1068 filter->setSourceModel(Client::messageModel());
1069 view->setModel(filter);
1070 view->setAttribute(Qt::WA_DeleteOnClose, true);
1071 view->verticalHeader()->hide();
1072 view->horizontalHeader()->setStretchLastSection(true);
1076 void MainWin::on_actionDebugLog_triggered() {
1077 DebugLogWidget *logWidget = new DebugLogWidget(0);
1081 void MainWin::showStatusBarMessage(const QString &message) {
1082 statusBar()->showMessage(message, 10000);