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>
36 #include "awaylogfilter.h"
37 #include "awaylogview.h"
39 #include "actioncollection.h"
40 #include "buffermodel.h"
41 #include "bufferview.h"
42 #include "bufferviewoverlay.h"
43 #include "bufferviewoverlayfilter.h"
44 #include "bufferwidget.h"
45 #include "channellistdlg.h"
46 #include "chatlinemodel.h"
47 #include "chatmonitorfilter.h"
48 #include "chatmonitorview.h"
51 #include "clientsyncer.h"
52 #include "clientbacklogmanager.h"
53 #include "clientbufferviewconfig.h"
54 #include "clientbufferviewmanager.h"
55 #include "coreinfodlg.h"
56 #include "coreconnectdlg.h"
57 #include "contextmenuactionprovider.h"
58 #include "debugbufferviewoverlay.h"
59 #include "debuglogwidget.h"
60 #include "debugmessagemodelfilter.h"
61 #include "iconloader.h"
62 #include "inputwidget.h"
63 #include "inputline.h"
64 #include "irclistmodel.h"
65 #include "ircconnectionwizard.h"
66 #include "jumpkeyhandler.h"
67 #include "msgprocessorstatuswidget.h"
68 #include "nicklistwidget.h"
69 #include "qtuiapplication.h"
70 #include "qtuimessageprocessor.h"
71 #include "qtuisettings.h"
72 #include "settingsdlg.h"
73 #include "settingspagedlg.h"
74 #include "systemtray.h"
75 #include "toolbaractionprovider.h"
76 #include "topicwidget.h"
77 #include "verticaldock.h"
81 # include "desktopnotificationbackend.h"
84 # include "phononnotificationbackend.h"
86 # include "systraynotificationbackend.h"
87 # include "taskbarnotificationbackend.h"
89 # include "knotificationbackend.h"
92 #include "settingspages/aliasessettingspage.h"
93 #include "settingspages/appearancesettingspage.h"
94 #include "settingspages/backlogsettingspage.h"
95 #include "settingspages/bufferviewsettingspage.h"
96 #include "settingspages/chatmonitorsettingspage.h"
97 #include "settingspages/colorsettingspage.h"
98 #include "settingspages/generalsettingspage.h"
99 #include "settingspages/highlightsettingspage.h"
100 #include "settingspages/identitiessettingspage.h"
101 #include "settingspages/networkssettingspage.h"
102 #include "settingspages/notificationssettingspage.h"
104 MainWin::MainWin(QWidget *parent)
106 : KMainWindow(parent),
107 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
109 : QMainWindow(parent),
111 coreLagLabel(new QLabel()),
112 sslLabel(new QLabel()),
113 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
121 QtUiSettings uiSettings;
122 QString style = uiSettings.value("Style", QString()).toString();
123 if(!style.isEmpty()) {
124 QApplication::setStyle(style);
127 QApplication::setQuitOnLastWindowClosed(false);
129 setWindowTitle("Quassel IRC");
130 setWindowIconText("Quassel IRC");
133 installEventFilter(new JumpKeyHandler(this));
135 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
136 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
137 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
138 connect(app, SIGNAL(aboutToQuit()), SLOT(aboutToQuit()));
141 void MainWin::init() {
142 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
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
170 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
171 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
173 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
176 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
180 QtUi::registerNotificationBackend(new KNotificationBackend(this));
181 #endif /* HAVE_KDE */
183 setDisconnectedState(); // Disable menus and stuff
185 // restore mainwin state
187 restoreStateFromSettings(s);
189 // restore locked state of docks
190 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
192 if(Quassel::runMode() != Quassel::Monolithic) {
193 showCoreConnectionDlg(true); // autoconnect if appropriate
199 MainWin::~MainWin() {
203 void MainWin::aboutToQuit() {
205 saveStateToSettings(s);
208 void MainWin::saveStateToSettings(UiSettings &s) {
209 s.setValue("MainWinSize", _normalSize);
210 s.setValue("MainWinPos", _normalPos);
211 s.setValue("MainWinState", saveState());
212 s.setValue("MainWinGeometry", saveGeometry());
213 s.setValue("MainWinMinimized", isMinimized());
214 s.setValue("MainWinHidden", _isHidden);
217 void MainWin::restoreStateFromSettings(UiSettings &s) {
218 restoreGeometry(s.value("MainWinGeometry").toByteArray());
220 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
221 resize(s.value("MainWinSize", QSize(800, 500)).toSize());
222 move(s.value("MainWinPos").toPoint());
225 restoreState(s.value("MainWinState").toByteArray());
228 if(s.value("MainWinHidden").toBool())
230 else if(s.value("MainWinMinimized").toBool())
236 void MainWin::updateIcon() {
238 const int size = 128;
244 if(Client::isConnected())
245 icon = DesktopIcon("quassel", size);
247 icon = DesktopIcon("quassel_inactive", size);
249 qApp->setWindowIcon(icon);
252 void MainWin::setupActions() {
253 ActionCollection *coll = QtUi::actionCollection("General");
255 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
256 this, SLOT(showCoreConnectionDlg())));
257 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
258 Client::instance(), SLOT(disconnectFromCore())));
259 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
260 this, SLOT(showCoreInfoDlg())));
261 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
262 this, SLOT(on_actionConfigureNetworks_triggered())));
263 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
264 qApp, SLOT(quit()), tr("Ctrl+Q")));
267 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
268 this, SLOT(on_actionConfigureViews_triggered())));
270 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
271 lockAct->setCheckable(true);
272 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
274 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
275 0, 0, QKeySequence::Find))->setCheckable(true);
276 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
277 this, SLOT(showAwayLog())));
278 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
279 0, 0))->setCheckable(true);
282 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
283 this, SLOT(showSettingsDlg()), tr("F7")));
286 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
287 this, SLOT(showAboutDlg())));
288 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
289 qApp, SLOT(aboutQt())));
290 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
291 this, SLOT(on_actionDebugNetworkModel_triggered())));
292 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
293 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
294 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
295 this, SLOT(on_actionDebugMessageModel_triggered())));
296 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
297 this, SLOT(on_actionDebugLog_triggered())));
300 void MainWin::setupMenus() {
301 ActionCollection *coll = QtUi::actionCollection("General");
303 _fileMenu = menuBar()->addMenu(tr("&File"));
305 static const QStringList coreActions = QStringList()
306 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
309 foreach(QString actionName, coreActions) {
310 coreAction = coll->action(actionName);
311 _fileMenu->addAction(coreAction);
312 flagRemoteCoreOnly(coreAction);
314 flagRemoteCoreOnly(_fileMenu->addSeparator());
316 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
317 _networksMenu->addAction(coll->action("ConfigureNetworks"));
318 _networksMenu->addSeparator();
319 _fileMenu->addSeparator();
320 _fileMenu->addAction(coll->action("Quit"));
322 _viewMenu = menuBar()->addMenu(tr("&View"));
323 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
324 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
325 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
326 _viewMenu->addSeparator();
327 _viewMenu->addAction(coll->action("ToggleSearchBar"));
329 coreAction = coll->action("ShowAwayLog");
330 flagRemoteCoreOnly(coreAction);
331 _viewMenu->addAction(coreAction);
333 _viewMenu->addAction(coll->action("ToggleStatusBar"));
334 _viewMenu->addSeparator();
335 _viewMenu->addAction(coll->action("LockLayout"));
337 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
339 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
340 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
342 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
344 _helpMenu = menuBar()->addMenu(tr("&Help"));
345 _helpMenu->addAction(coll->action("AboutQuassel"));
347 _helpMenu->addAction(coll->action("AboutQt"));
349 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
351 _helpMenu->addSeparator();
352 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
353 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
354 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
355 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
356 _helpDebugMenu->addAction(coll->action("DebugLog"));
359 void MainWin::setupBufferWidget() {
360 _bufferWidget = new BufferWidget(this);
361 _bufferWidget->setModel(Client::bufferModel());
362 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
363 setCentralWidget(_bufferWidget);
366 void MainWin::addBufferView(int bufferViewConfigId) {
367 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
370 void MainWin::addBufferView(ClientBufferViewConfig *config) {
374 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
375 BufferViewDock *dock = new BufferViewDock(config, this);
377 //create the view and initialize it's filter
378 BufferView *view = new BufferView(dock);
379 view->setFilteredModel(Client::bufferModel(), config);
380 view->installEventFilter(_inputWidget->inputLine()); // for key presses
383 Client::bufferModel()->synchronizeView(view);
385 dock->setWidget(view);
388 addDockWidget(Qt::LeftDockWidgetArea, dock);
389 _bufferViewsMenu->addAction(dock->toggleViewAction());
391 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
392 _bufferViews.append(dock);
395 void MainWin::removeBufferView(int bufferViewConfigId) {
397 BufferViewDock *dock;
398 foreach(QAction *action, _bufferViewsMenu->actions()) {
399 actionData = action->data();
400 if(!actionData.isValid())
403 dock = qobject_cast<BufferViewDock *>(action->parent());
404 if(dock && actionData.toInt() == bufferViewConfigId) {
405 removeAction(action);
411 void MainWin::bufferViewToggled(bool enabled) {
412 QAction *action = qobject_cast<QAction *>(sender());
414 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
417 Client::bufferViewOverlay()->addView(dock->bufferViewId());
418 BufferViewConfig *config = dock->config();
419 if(config && config->isInitialized()) {
420 BufferIdList buffers;
421 if(config->networkId().isValid()) {
422 foreach(BufferId bufferId, config->bufferList()) {
423 if(Client::networkModel()->networkId(bufferId) == config->networkId())
426 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
427 if(Client::networkModel()->networkId(bufferId) == config->networkId())
431 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
433 Client::backlogManager()->checkForBacklog(buffers);
436 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
440 BufferView *MainWin::allBuffersView() const {
441 // "All Buffers" is always the first dock created
442 if(_bufferViews.count() > 0)
443 return _bufferViews[0]->bufferView();
447 void MainWin::showNotificationsDlg() {
448 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
452 void MainWin::on_actionConfigureNetworks_triggered() {
453 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
457 void MainWin::on_actionConfigureViews_triggered() {
458 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
462 void MainWin::on_actionLockLayout_toggled(bool lock) {
463 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
464 foreach(VerticalDock *dock, docks) {
465 dock->showTitle(!lock);
467 if(Client::bufferViewManager()) {
468 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
469 config->setLocked(lock);
472 QtUiSettings().setValue("LockLayout", lock);
475 void MainWin::setupNickWidget() {
477 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
478 nickDock->setObjectName("NickDock");
479 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
481 _nickListWidget = new NickListWidget(nickDock);
482 nickDock->setWidget(_nickListWidget);
484 addDockWidget(Qt::RightDockWidgetArea, nickDock);
485 _viewMenu->addAction(nickDock->toggleViewAction());
486 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
488 // See NickListDock::NickListDock();
489 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
491 // attach the NickListWidget to the BufferModel and the default selection
492 _nickListWidget->setModel(Client::bufferModel());
493 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
496 void MainWin::setupChatMonitor() {
497 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
498 dock->setObjectName("ChatMonitorDock");
500 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
501 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
503 dock->setWidget(chatView);
506 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
507 _viewMenu->addAction(dock->toggleViewAction());
508 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
511 void MainWin::setupInputWidget() {
512 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
513 dock->setObjectName("InputDock");
515 _inputWidget = new InputWidget(dock);
516 dock->setWidget(_inputWidget);
518 addDockWidget(Qt::BottomDockWidgetArea, dock);
520 _viewMenu->addAction(dock->toggleViewAction());
521 dock->toggleViewAction()->setText(tr("Show Input Line"));
523 _inputWidget->setModel(Client::bufferModel());
524 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
526 _bufferWidget->setFocusProxy(_inputWidget);
528 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
531 void MainWin::setupTopicWidget() {
532 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
533 dock->setObjectName("TopicDock");
534 TopicWidget *topicwidget = new TopicWidget(dock);
536 dock->setWidget(topicwidget);
538 topicwidget->setModel(Client::bufferModel());
539 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
541 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
543 _viewMenu->addAction(dock->toggleViewAction());
544 dock->toggleViewAction()->setText(tr("Show Topic Line"));
547 void MainWin::setupTitleSetter() {
548 _titleSetter.setModel(Client::bufferModel());
549 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
552 void MainWin::setupStatusBar() {
553 // MessageProcessor progress
554 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
557 updateLagIndicator();
558 statusBar()->addPermanentWidget(coreLagLabel);
559 coreLagLabel->hide();
560 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
563 sslLabel->setPixmap(QPixmap());
564 statusBar()->addPermanentWidget(sslLabel);
567 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
569 QtUiSettings uiSettings;
571 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
572 showStatusbar->setChecked(enabled);
573 enabled ? statusBar()->show() : statusBar()->hide();
575 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
576 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
579 void MainWin::saveStatusBarStatus(bool enabled) {
580 QtUiSettings uiSettings;
581 uiSettings.setValue("ShowStatusBar", enabled);
584 void MainWin::setupSystray() {
585 _systemTray = new SystemTray(this);
588 void MainWin::setupToolBars() {
589 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
590 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
591 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
592 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
595 setUnifiedTitleAndToolBarOnMac(true);
597 _mainToolBar = addToolBar(tr("Main Toolbar"));
598 _mainToolBar->setObjectName("MainToolBar");
600 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
601 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
603 //_nickToolBar = addToolBar("User");
604 //_nickToolBar->setObjectName("NickToolBar");
605 //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
608 _mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
609 //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
613 void MainWin::connectedToCore() {
614 Q_CHECK_PTR(Client::bufferViewManager());
615 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
616 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
617 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
622 void MainWin::setConnectedState() {
623 ActionCollection *coll = QtUi::actionCollection("General");
625 coll->action("ConnectCore")->setEnabled(false);
626 coll->action("DisconnectCore")->setEnabled(true);
627 coll->action("CoreInfo")->setEnabled(true);
629 foreach(QAction *action, _fileMenu->actions()) {
630 if(isRemoteCoreOnly(action))
631 action->setVisible(!Client::internalCore());
634 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
635 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
636 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
637 if(!Client::internalCore()) {
638 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
639 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
640 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
643 // _viewMenu->setEnabled(true);
644 if(!Client::internalCore())
645 statusBar()->showMessage(tr("Connected to core."));
647 statusBar()->clearMessage();
649 if(Client::signalProxy()->isSecure()) {
650 sslLabel->setPixmap(SmallIcon("security-high"));
652 sslLabel->setPixmap(SmallIcon("security-low"));
655 sslLabel->setVisible(!Client::internalCore());
656 coreLagLabel->setVisible(!Client::internalCore());
658 systemTray()->setState(SystemTray::Active);
660 if(Client::networkIds().isEmpty()) {
661 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
666 void MainWin::loadLayout() {
668 int accountId = Client::currentCoreAccount().toInt();
669 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
672 void MainWin::saveLayout() {
674 int accountId = Client::currentCoreAccount().toInt();
675 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
678 void MainWin::updateLagIndicator(int lag) {
679 QString text = tr("Core Lag: %1");
681 text = text.arg('-');
683 text = text.arg("%1 msec").arg(lag);
684 coreLagLabel->setText(text);
687 void MainWin::disconnectedFromCore() {
688 // save core specific layout and remove bufferviews;
691 BufferViewDock *dock;
692 foreach(QAction *action, _bufferViewsMenu->actions()) {
693 actionData = action->data();
694 if(!actionData.isValid())
697 dock = qobject_cast<BufferViewDock *>(action->parent());
698 if(dock && actionData.toInt() != -1) {
699 removeAction(action);
704 restoreState(s.value("MainWinState").toByteArray());
705 setDisconnectedState();
708 void MainWin::setDisconnectedState() {
709 ActionCollection *coll = QtUi::actionCollection("General");
710 //ui.menuCore->setEnabled(false);
711 coll->action("ConnectCore")->setEnabled(true);
712 coll->action("DisconnectCore")->setEnabled(false);
713 coll->action("CoreInfo")->setEnabled(false);
714 //_viewMenu->setEnabled(false);
715 statusBar()->showMessage(tr("Not connected to core."));
716 sslLabel->setPixmap(QPixmap());
718 updateLagIndicator();
719 coreLagLabel->hide();
720 if(msgProcessorStatusWidget)
721 msgProcessorStatusWidget->setProgress(0, 0);
723 systemTray()->setState(SystemTray::Inactive);
726 void MainWin::startInternalCore() {
727 ClientSyncer *syncer = new ClientSyncer();
728 Client::registerClientSyncer(syncer);
729 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
730 syncer->useInternalCore();
733 void MainWin::showCoreConnectionDlg(bool autoConnect) {
734 CoreConnectDlg(autoConnect, this).exec();
737 void MainWin::showChannelList(NetworkId netId) {
738 ChannelListDlg *channelListDlg = new ChannelListDlg();
740 if(!netId.isValid()) {
741 QAction *action = qobject_cast<QAction *>(sender());
743 netId = action->data().value<NetworkId>();
746 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
747 channelListDlg->setNetwork(netId);
748 channelListDlg->show();
751 void MainWin::showCoreInfoDlg() {
752 CoreInfoDlg(this).exec();
755 void MainWin::showAwayLog() {
758 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
759 _awayLog = new AwayLogView(filter, 0);
760 filter->setParent(_awayLog);
761 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
762 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
766 void MainWin::awayLogDestroyed() {
770 void MainWin::showSettingsDlg() {
771 SettingsDlg *dlg = new SettingsDlg();
773 //Category: Appearance
774 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
775 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
776 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
777 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
778 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
779 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
780 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
783 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
784 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
785 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
786 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
791 void MainWin::showAboutDlg() {
792 AboutDlg(this).exec();
796 void MainWin::showShortcutsDlg() {
797 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
801 /********************************************************************************************************/
803 bool MainWin::event(QEvent *event) {
804 if(event->type() == QEvent::WindowActivate)
805 QtUi::closeNotifications();
806 return QMainWindow::event(event);
809 void MainWin::moveEvent(QMoveEvent *event) {
810 if(!(windowState() & Qt::WindowMaximized))
811 _normalPos = event->pos();
816 void MainWin::resizeEvent(QResizeEvent *event) {
817 if(!(windowState() & Qt::WindowMaximized))
818 _normalSize = event->size();
823 void MainWin::closeEvent(QCloseEvent *event) {
825 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
827 if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
828 toggleMinimizedToTray();
832 QApplication::quit();
836 void MainWin::changeEvent(QEvent *event) {
837 if(event->type() == QEvent::WindowStateChange) {
838 if(windowState() & Qt::WindowMinimized) {
840 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
849 else if(event->type() == QEvent::ActivationChange)
850 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
856 void MainWin::hideToTray() {
857 if(!systemTray()->isSystemTrayAvailable()) {
858 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
862 systemTray()->setIconVisible();
866 void MainWin::toggleMinimizedToTray() {
868 // the problem is that we lose focus when the systray icon is activated
869 // and we don't know the former active window
870 // therefore we watch for activation event and use our stopwatch :)
871 // courtesy: KSystemTrayIcon
872 if(GetTickCount() - dwTickCount >= 300)
873 // we weren't active in the last 300ms -> activate
880 if(!isVisible() || isMinimized())
889 void MainWin::forceActivated() {
891 // Bypass focus stealing prevention
892 QX11Info::setAppUserTime(QX11Info::appTime());
895 if(windowState() & Qt::WindowMinimized) {
897 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
900 move(frameGeometry().topLeft()); // avoid placement policies
907 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
910 bool hasFocus = QApplication::activeWindow() != 0;
912 for(int i = start; i <= end; i++) {
913 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
915 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
918 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
919 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
921 flags |= Message::Backlog; // we only want to trigger a highlight once!
922 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
924 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
925 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
927 if(hasFocus && bufId == _bufferWidget->currentBuffer())
930 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
931 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
932 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
933 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
934 AbstractNotificationBackend::NotificationType type;
936 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
937 type = AbstractNotificationBackend::PrivMsg;
938 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
939 type = AbstractNotificationBackend::PrivMsgFocused;
940 else if(flags & Message::Highlight && !hasFocus)
941 type = AbstractNotificationBackend::Highlight;
943 type = AbstractNotificationBackend::HighlightFocused;
945 QtUi::invokeNotification(bufId, type, sender, contents);
950 void MainWin::clientNetworkCreated(NetworkId id) {
951 const Network *net = Client::network(id);
952 QAction *act = new QAction(net->networkName(), this);
953 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
954 act->setData(QVariant::fromValue<NetworkId>(id));
955 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
956 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
958 QAction *beforeAction = 0;
959 foreach(QAction *action, _networksMenu->actions()) {
960 if(!action->data().isValid()) // ignore stock actions
962 if(net->networkName().localeAwareCompare(action->text()) < 0) {
963 beforeAction = action;
967 _networksMenu->insertAction(beforeAction, act);
970 void MainWin::clientNetworkUpdated() {
971 const Network *net = qobject_cast<const Network *>(sender());
975 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
979 action->setText(net->networkName());
981 switch(net->connectionState()) {
982 case Network::Initialized:
983 action->setIcon(SmallIcon("network-connect"));
985 case Network::Disconnected:
986 action->setIcon(SmallIcon("network-disconnect"));
989 action->setIcon(SmallIcon("network-wired"));
993 void MainWin::clientNetworkRemoved(NetworkId id) {
994 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
998 action->deleteLater();
1001 void MainWin::connectOrDisconnectFromNet() {
1002 QAction *act = qobject_cast<QAction *>(sender());
1004 const Network *net = Client::network(act->data().value<NetworkId>());
1006 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1007 else net->requestDisconnect();
1010 void MainWin::on_actionDebugNetworkModel_triggered() {
1011 QTreeView *view = new QTreeView;
1012 view->setAttribute(Qt::WA_DeleteOnClose);
1013 view->setWindowTitle("Debug NetworkModel View");
1014 view->setModel(Client::networkModel());
1015 view->setColumnWidth(0, 250);
1016 view->setColumnWidth(1, 250);
1017 view->setColumnWidth(2, 80);
1018 view->resize(610, 300);
1022 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1023 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1024 overlay->setAttribute(Qt::WA_DeleteOnClose);
1028 void MainWin::on_actionDebugMessageModel_triggered() {
1029 QTableView *view = new QTableView(0);
1030 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1031 filter->setSourceModel(Client::messageModel());
1032 view->setModel(filter);
1033 view->setAttribute(Qt::WA_DeleteOnClose, true);
1034 view->verticalHeader()->hide();
1035 view->horizontalHeader()->setStretchLastSection(true);
1039 void MainWin::on_actionDebugLog_triggered() {
1040 DebugLogWidget *logWidget = new DebugLogWidget(0);
1045 void MainWin::saveStateToSession(const QString &sessionId) {
1047 SessionSettings s(sessionId);
1049 s.setValue("MainWinSize", size());
1050 s.setValue("MainWinPos", pos());
1051 s.setValue("MainWinState", saveState());
1055 void MainWin::saveStateToSessionSettings(SessionSettings & s)
1057 s.setValue("MainWinSize", size());
1058 s.setValue("MainWinPos", pos());
1059 s.setValue("MainWinState", saveState());
1062 void MainWin::showStatusBarMessage(const QString &message) {
1063 statusBar()->showMessage(message, 10000);