1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 # include <KActionCollection>
27 # include <KShortcutsDialog>
28 # include <KStatusBar>
37 #include "awaylogfilter.h"
38 #include "awaylogview.h"
40 #include "actioncollection.h"
41 #include "bufferhotlistfilter.h"
42 #include "buffermodel.h"
43 #include "bufferview.h"
44 #include "bufferviewoverlay.h"
45 #include "bufferviewoverlayfilter.h"
46 #include "bufferwidget.h"
47 #include "channellistdlg.h"
48 #include "chatlinemodel.h"
49 #include "chatmonitorfilter.h"
50 #include "chatmonitorview.h"
53 #include "clientsyncer.h"
54 #include "clientbacklogmanager.h"
55 #include "clientbufferviewconfig.h"
56 #include "clientbufferviewmanager.h"
57 #include "clientignorelistmanager.h"
58 #include "coreinfodlg.h"
59 #include "coreconnectdlg.h"
60 #include "contextmenuactionprovider.h"
61 #include "debugbufferviewoverlay.h"
62 #include "debuglogwidget.h"
63 #include "debugmessagemodelfilter.h"
64 #include "flatproxymodel.h"
65 #include "iconloader.h"
66 #include "inputwidget.h"
67 #include "irclistmodel.h"
68 #include "ircconnectionwizard.h"
69 #include "jumpkeyhandler.h"
70 #include "msgprocessorstatuswidget.h"
71 #include "nicklistwidget.h"
72 #include "qtuiapplication.h"
73 #include "qtuimessageprocessor.h"
74 #include "qtuisettings.h"
75 #include "qtuistyle.h"
76 #include "settingsdlg.h"
77 #include "settingspagedlg.h"
78 #include "systemtray.h"
79 #include "toolbaractionprovider.h"
80 #include "topicwidget.h"
81 #include "verticaldock.h"
85 # include "desktopnotificationbackend.h"
88 # include "phononnotificationbackend.h"
90 # include "systraynotificationbackend.h"
91 # include "taskbarnotificationbackend.h"
93 # include "knotificationbackend.h"
96 #include "settingspages/aliasessettingspage.h"
97 #include "settingspages/appearancesettingspage.h"
98 #include "settingspages/backlogsettingspage.h"
99 #include "settingspages/bufferviewsettingspage.h"
100 #include "settingspages/chatmonitorsettingspage.h"
101 #include "settingspages/chatviewsettingspage.h"
102 #include "settingspages/connectionsettingspage.h"
103 #include "settingspages/generalsettingspage.h"
104 #include "settingspages/highlightsettingspage.h"
105 #include "settingspages/identitiessettingspage.h"
106 #include "settingspages/ignorelistsettingspage.h"
107 #include "settingspages/inputwidgetsettingspage.h"
108 #include "settingspages/itemviewsettingspage.h"
109 #include "settingspages/networkssettingspage.h"
110 #include "settingspages/notificationssettingspage.h"
112 MainWin::MainWin(QWidget *parent)
114 : KMainWindow(parent),
115 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
117 : QMainWindow(parent),
119 coreLagLabel(new QLabel()),
120 sslLabel(new QLabel()),
121 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
129 QtUiSettings uiSettings;
130 QString style = uiSettings.value("Style", QString()).toString();
131 if(!style.isEmpty()) {
132 QApplication::setStyle(style);
135 QApplication::setQuitOnLastWindowClosed(false);
137 setWindowTitle("Quassel IRC");
138 setWindowIconText("Quassel IRC");
141 installEventFilter(new JumpKeyHandler(this));
144 void MainWin::init() {
145 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
146 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
147 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
148 SLOT(messagesInserted(const QModelIndex &, int, int)));
149 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
152 setDockNestingEnabled(true);
153 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
154 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
155 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
156 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
158 // Order is sometimes important
173 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
174 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
176 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
179 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
183 QtUi::registerNotificationBackend(new KNotificationBackend(this));
184 #endif /* HAVE_KDE */
186 setDisconnectedState(); // Disable menus and stuff
189 setAutoSaveSettings();
192 // restore mainwin state
194 restoreStateFromSettings(s);
196 // restore locked state of docks
197 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
199 if(Quassel::runMode() != Quassel::Monolithic) {
200 showCoreConnectionDlg(true); // autoconnect if appropriate
206 MainWin::~MainWin() {
210 void MainWin::quit() {
212 saveStateToSettings(s);
214 QApplication::quit();
217 void MainWin::saveStateToSettings(UiSettings &s) {
218 s.setValue("MainWinSize", _normalSize);
219 s.setValue("MainWinPos", _normalPos);
220 s.setValue("MainWinState", saveState());
221 s.setValue("MainWinGeometry", saveGeometry());
222 s.setValue("MainWinMinimized", isMinimized());
223 s.setValue("MainWinMaximized", isMaximized());
224 s.setValue("MainWinHidden", !isVisible());
227 saveAutoSaveSettings();
231 void MainWin::restoreStateFromSettings(UiSettings &s) {
232 _normalSize = s.value("MainWinSize", size()).toSize();
233 _normalPos = s.value("MainWinPos", pos()).toPoint();
234 bool maximized = s.value("MainWinMaximized", false).toBool();
237 restoreGeometry(s.value("MainWinGeometry").toByteArray());
240 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
245 restoreState(s.value("MainWinState").toByteArray());
251 if(s.value("MainWinHidden").toBool())
253 else if(s.value("MainWinMinimized").toBool())
261 void MainWin::updateIcon() {
263 const int size = 128;
269 if(Client::isConnected())
270 icon = DesktopIcon("quassel", size);
272 icon = DesktopIcon("quassel_inactive", size);
274 qApp->setWindowIcon(icon);
277 void MainWin::setupActions() {
278 ActionCollection *coll = QtUi::actionCollection("General");
280 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
281 this, SLOT(showCoreConnectionDlg())));
282 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
283 Client::instance(), SLOT(disconnectFromCore())));
284 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
285 this, SLOT(showCoreInfoDlg())));
286 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
287 this, SLOT(on_actionConfigureNetworks_triggered())));
288 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
289 this, SLOT(quit()), tr("Ctrl+Q")));
292 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
293 this, SLOT(on_actionConfigureViews_triggered())));
295 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
296 lockAct->setCheckable(true);
297 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
299 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
300 0, 0, QKeySequence::Find))->setCheckable(true);
301 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
302 this, SLOT(showAwayLog())));
303 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
304 0, 0))->setCheckable(true);
307 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
308 this, SLOT(showSettingsDlg()), tr("F7")));
311 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
312 this, SLOT(showAboutDlg())));
313 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
314 qApp, SLOT(aboutQt())));
315 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
316 this, SLOT(on_actionDebugNetworkModel_triggered())));
317 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
318 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
319 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
320 this, SLOT(on_actionDebugMessageModel_triggered())));
321 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
322 this, SLOT(on_actionDebugHotList_triggered())));
323 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
324 this, SLOT(on_actionDebugLog_triggered())));
325 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
326 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
329 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
330 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
333 void MainWin::setupMenus() {
334 ActionCollection *coll = QtUi::actionCollection("General");
336 _fileMenu = menuBar()->addMenu(tr("&File"));
338 static const QStringList coreActions = QStringList()
339 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
342 foreach(QString actionName, coreActions) {
343 coreAction = coll->action(actionName);
344 _fileMenu->addAction(coreAction);
345 flagRemoteCoreOnly(coreAction);
347 flagRemoteCoreOnly(_fileMenu->addSeparator());
349 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
350 _networksMenu->addAction(coll->action("ConfigureNetworks"));
351 _networksMenu->addSeparator();
352 _fileMenu->addSeparator();
353 _fileMenu->addAction(coll->action("Quit"));
355 _viewMenu = menuBar()->addMenu(tr("&View"));
356 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
357 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
358 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
359 _viewMenu->addSeparator();
360 _viewMenu->addAction(coll->action("ToggleSearchBar"));
362 coreAction = coll->action("ShowAwayLog");
363 flagRemoteCoreOnly(coreAction);
364 _viewMenu->addAction(coreAction);
366 _viewMenu->addAction(coll->action("ToggleStatusBar"));
367 _viewMenu->addSeparator();
368 _viewMenu->addAction(coll->action("LockLayout"));
370 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
372 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
373 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
375 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
377 _helpMenu = menuBar()->addMenu(tr("&Help"));
378 _helpMenu->addAction(coll->action("AboutQuassel"));
380 _helpMenu->addAction(coll->action("AboutQt"));
382 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
384 _helpMenu->addSeparator();
385 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
386 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
387 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
388 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
389 _helpDebugMenu->addAction(coll->action("DebugHotList"));
390 _helpDebugMenu->addAction(coll->action("DebugLog"));
391 _helpDebugMenu->addSeparator();
392 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
395 void MainWin::setupBufferWidget() {
396 _bufferWidget = new BufferWidget(this);
397 _bufferWidget->setModel(Client::bufferModel());
398 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
399 setCentralWidget(_bufferWidget);
402 void MainWin::addBufferView(int bufferViewConfigId) {
403 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
406 void MainWin::addBufferView(ClientBufferViewConfig *config) {
410 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
411 BufferViewDock *dock = new BufferViewDock(config, this);
413 //create the view and initialize it's filter
414 BufferView *view = new BufferView(dock);
415 view->setFilteredModel(Client::bufferModel(), config);
416 view->installEventFilter(_inputWidget); // for key presses
419 Client::bufferModel()->synchronizeView(view);
421 dock->setWidget(view);
424 addDockWidget(Qt::LeftDockWidgetArea, dock);
425 _bufferViewsMenu->addAction(dock->toggleViewAction());
427 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
428 _bufferViews.append(dock);
431 void MainWin::removeBufferView(int bufferViewConfigId) {
433 BufferViewDock *dock;
434 foreach(QAction *action, _bufferViewsMenu->actions()) {
435 actionData = action->data();
436 if(!actionData.isValid())
439 dock = qobject_cast<BufferViewDock *>(action->parent());
440 if(dock && actionData.toInt() == bufferViewConfigId) {
441 removeAction(action);
447 void MainWin::bufferViewToggled(bool enabled) {
448 QAction *action = qobject_cast<QAction *>(sender());
450 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
453 Client::bufferViewOverlay()->addView(dock->bufferViewId());
454 BufferViewConfig *config = dock->config();
455 if(config && config->isInitialized()) {
456 BufferIdList buffers;
457 if(config->networkId().isValid()) {
458 foreach(BufferId bufferId, config->bufferList()) {
459 if(Client::networkModel()->networkId(bufferId) == config->networkId())
462 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
463 if(Client::networkModel()->networkId(bufferId) == config->networkId())
467 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
469 Client::backlogManager()->checkForBacklog(buffers);
472 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
476 BufferView *MainWin::allBuffersView() const {
477 // "All Buffers" is always the first dock created
478 if(_bufferViews.count() > 0)
479 return _bufferViews[0]->bufferView();
483 void MainWin::showNotificationsDlg() {
484 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
488 void MainWin::on_actionConfigureNetworks_triggered() {
489 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
493 void MainWin::on_actionConfigureViews_triggered() {
494 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
498 void MainWin::on_actionLockLayout_toggled(bool lock) {
499 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
500 foreach(VerticalDock *dock, docks) {
501 dock->showTitle(!lock);
503 if(Client::bufferViewManager()) {
504 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
505 config->setLocked(lock);
508 QtUiSettings().setValue("LockLayout", lock);
511 void MainWin::setupNickWidget() {
513 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
514 nickDock->setObjectName("NickDock");
515 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
517 _nickListWidget = new NickListWidget(nickDock);
518 nickDock->setWidget(_nickListWidget);
520 addDockWidget(Qt::RightDockWidgetArea, nickDock);
521 _viewMenu->addAction(nickDock->toggleViewAction());
522 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
524 // See NickListDock::NickListDock();
525 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
527 // attach the NickListWidget to the BufferModel and the default selection
528 _nickListWidget->setModel(Client::bufferModel());
529 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
532 void MainWin::setupChatMonitor() {
533 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
534 dock->setObjectName("ChatMonitorDock");
536 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
537 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
539 dock->setWidget(chatView);
542 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
543 _viewMenu->addAction(dock->toggleViewAction());
544 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
547 void MainWin::setupInputWidget() {
548 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
549 dock->setObjectName("InputDock");
551 _inputWidget = new InputWidget(dock);
552 dock->setWidget(_inputWidget);
554 addDockWidget(Qt::BottomDockWidgetArea, dock);
556 _viewMenu->addAction(dock->toggleViewAction());
557 dock->toggleViewAction()->setText(tr("Show Input Line"));
559 _inputWidget->setModel(Client::bufferModel());
560 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
562 _bufferWidget->setFocusProxy(_inputWidget);
564 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
567 void MainWin::setupTopicWidget() {
568 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
569 dock->setObjectName("TopicDock");
570 TopicWidget *topicwidget = new TopicWidget(dock);
572 dock->setWidget(topicwidget);
574 topicwidget->setModel(Client::bufferModel());
575 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
577 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
579 _viewMenu->addAction(dock->toggleViewAction());
580 dock->toggleViewAction()->setText(tr("Show Topic Line"));
583 void MainWin::setupTitleSetter() {
584 _titleSetter.setModel(Client::bufferModel());
585 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
588 void MainWin::setupStatusBar() {
589 // MessageProcessor progress
590 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
593 updateLagIndicator();
594 statusBar()->addPermanentWidget(coreLagLabel);
595 coreLagLabel->hide();
596 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
599 sslLabel->setPixmap(QPixmap());
600 statusBar()->addPermanentWidget(sslLabel);
603 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
605 QtUiSettings uiSettings;
607 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
608 showStatusbar->setChecked(enabled);
609 enabled ? statusBar()->show() : statusBar()->hide();
611 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
612 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
615 void MainWin::setupHotList() {
616 FlatProxyModel *flatProxy = new FlatProxyModel(this);
617 flatProxy->setSourceModel(Client::bufferModel());
618 _bufferHotList = new BufferHotListFilter(flatProxy);
621 void MainWin::saveStatusBarStatus(bool enabled) {
622 QtUiSettings uiSettings;
623 uiSettings.setValue("ShowStatusBar", enabled);
626 void MainWin::setupSystray() {
627 _systemTray = new SystemTray(this);
630 void MainWin::setupToolBars() {
631 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
632 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
633 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
634 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
637 setUnifiedTitleAndToolBarOnMac(true);
641 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
643 _mainToolBar = new QToolBar(this);
644 _mainToolBar->setObjectName("MainToolBar");
646 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
647 addToolBar(_mainToolBar);
649 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
650 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
653 void MainWin::connectedToCore() {
654 Q_CHECK_PTR(Client::bufferViewManager());
655 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
656 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
657 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
662 void MainWin::setConnectedState() {
663 ActionCollection *coll = QtUi::actionCollection("General");
665 coll->action("ConnectCore")->setEnabled(false);
666 coll->action("DisconnectCore")->setEnabled(true);
667 coll->action("CoreInfo")->setEnabled(true);
669 foreach(QAction *action, _fileMenu->actions()) {
670 if(isRemoteCoreOnly(action))
671 action->setVisible(!Client::internalCore());
674 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
675 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
676 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
677 if(!Client::internalCore()) {
678 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
679 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
680 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
683 // _viewMenu->setEnabled(true);
684 if(!Client::internalCore())
685 statusBar()->showMessage(tr("Connected to core."));
687 statusBar()->clearMessage();
689 if(Client::signalProxy()->isSecure()) {
690 sslLabel->setPixmap(SmallIcon("security-high"));
692 sslLabel->setPixmap(SmallIcon("security-low"));
695 sslLabel->setVisible(!Client::internalCore());
696 coreLagLabel->setVisible(!Client::internalCore());
698 systemTray()->setState(SystemTray::Active);
700 if(Client::networkIds().isEmpty()) {
701 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
706 void MainWin::loadLayout() {
708 int accountId = Client::currentCoreAccount().toInt();
709 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
712 void MainWin::saveLayout() {
714 int accountId = Client::currentCoreAccount().toInt();
715 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
718 void MainWin::updateLagIndicator(int lag) {
719 QString text = tr("Core Lag: %1");
721 text = text.arg('-');
723 text = text.arg("%1 msec").arg(lag);
724 coreLagLabel->setText(text);
727 void MainWin::disconnectedFromCore() {
728 // save core specific layout and remove bufferviews;
731 BufferViewDock *dock;
732 foreach(QAction *action, _bufferViewsMenu->actions()) {
733 actionData = action->data();
734 if(!actionData.isValid())
737 dock = qobject_cast<BufferViewDock *>(action->parent());
738 if(dock && actionData.toInt() != -1) {
739 removeAction(action);
744 restoreState(s.value("MainWinState").toByteArray());
745 setDisconnectedState();
748 void MainWin::setDisconnectedState() {
749 ActionCollection *coll = QtUi::actionCollection("General");
750 //ui.menuCore->setEnabled(false);
751 coll->action("ConnectCore")->setEnabled(true);
752 coll->action("DisconnectCore")->setEnabled(false);
753 coll->action("CoreInfo")->setEnabled(false);
754 //_viewMenu->setEnabled(false);
755 statusBar()->showMessage(tr("Not connected to core."));
756 sslLabel->setPixmap(QPixmap());
758 updateLagIndicator();
759 coreLagLabel->hide();
760 if(msgProcessorStatusWidget)
761 msgProcessorStatusWidget->setProgress(0, 0);
763 systemTray()->setState(SystemTray::Inactive);
766 void MainWin::startInternalCore() {
767 ClientSyncer *syncer = new ClientSyncer();
768 Client::registerClientSyncer(syncer);
769 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
770 syncer->useInternalCore();
773 void MainWin::showCoreConnectionDlg(bool autoConnect) {
774 CoreConnectDlg(autoConnect, this).exec();
777 void MainWin::showChannelList(NetworkId netId) {
778 ChannelListDlg *channelListDlg = new ChannelListDlg();
780 if(!netId.isValid()) {
781 QAction *action = qobject_cast<QAction *>(sender());
783 netId = action->data().value<NetworkId>();
786 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
787 channelListDlg->setNetwork(netId);
788 channelListDlg->show();
791 void MainWin::showCoreInfoDlg() {
792 CoreInfoDlg(this).exec();
795 void MainWin::showAwayLog() {
798 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
799 _awayLog = new AwayLogView(filter, 0);
800 filter->setParent(_awayLog);
801 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
802 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
806 void MainWin::awayLogDestroyed() {
810 void MainWin::showSettingsDlg() {
811 SettingsDlg *dlg = new SettingsDlg();
813 //Category: Interface
814 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
815 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
816 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
817 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
818 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
819 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
820 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
821 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
822 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
825 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
826 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
827 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
828 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
829 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
830 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
835 void MainWin::showAboutDlg() {
836 AboutDlg(this).exec();
840 void MainWin::showShortcutsDlg() {
841 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
845 /********************************************************************************************************/
847 bool MainWin::event(QEvent *event) {
848 if(event->type() == QEvent::WindowActivate)
849 QtUi::closeNotifications();
850 return QMainWindow::event(event);
853 void MainWin::moveEvent(QMoveEvent *event) {
854 if(!(windowState() & Qt::WindowMaximized))
855 _normalPos = event->pos();
857 QMainWindow::moveEvent(event);
860 void MainWin::resizeEvent(QResizeEvent *event) {
861 if(!(windowState() & Qt::WindowMaximized))
862 _normalSize = event->size();
864 QMainWindow::resizeEvent(event);
867 void MainWin::closeEvent(QCloseEvent *event) {
869 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
871 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
880 void MainWin::changeEvent(QEvent *event) {
882 if(event->type() == QEvent::ActivationChange)
883 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
886 QMainWindow::changeEvent(event);
889 void MainWin::hideToTray() {
890 if(!systemTray()->isSystemTrayAvailable()) {
891 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
895 systemTray()->setIconVisible();
898 void MainWin::toggleMinimizedToTray() {
900 // the problem is that we lose focus when the systray icon is activated
901 // and we don't know the former active window
902 // therefore we watch for activation event and use our stopwatch :)
903 // courtesy: KSystemTrayIcon
904 if(GetTickCount() - dwTickCount >= 300)
905 // we weren't active in the last 300ms -> activate
912 if(!isVisible() || isMinimized())
921 void MainWin::forceActivated() {
923 // Bypass focus stealing prevention
924 QX11Info::setAppUserTime(QX11Info::appTime());
927 if(windowState() & Qt::WindowMinimized) {
929 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
932 // this does not actually work on all platforms... and causes more evil than good
933 // move(frameGeometry().topLeft()); // avoid placement policies
939 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
942 bool hasFocus = QApplication::activeWindow() != 0;
944 for(int i = start; i <= end; i++) {
945 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
947 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
950 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
951 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
954 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
955 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
957 if(hasFocus && bufId == _bufferWidget->currentBuffer())
960 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) &&
961 !Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId))) {
962 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
963 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
964 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
965 AbstractNotificationBackend::NotificationType type;
967 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
968 type = AbstractNotificationBackend::PrivMsg;
969 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
970 type = AbstractNotificationBackend::PrivMsgFocused;
971 else if(flags & Message::Highlight && !hasFocus)
972 type = AbstractNotificationBackend::Highlight;
974 type = AbstractNotificationBackend::HighlightFocused;
976 QtUi::invokeNotification(bufId, type, sender, contents);
981 void MainWin::clientNetworkCreated(NetworkId id) {
982 const Network *net = Client::network(id);
983 QAction *act = new QAction(net->networkName(), this);
984 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
985 act->setData(QVariant::fromValue<NetworkId>(id));
986 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
987 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
989 QAction *beforeAction = 0;
990 foreach(QAction *action, _networksMenu->actions()) {
991 if(!action->data().isValid()) // ignore stock actions
993 if(net->networkName().localeAwareCompare(action->text()) < 0) {
994 beforeAction = action;
998 _networksMenu->insertAction(beforeAction, act);
1001 void MainWin::clientNetworkUpdated() {
1002 const Network *net = qobject_cast<const Network *>(sender());
1006 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1010 action->setText(net->networkName());
1012 switch(net->connectionState()) {
1013 case Network::Initialized:
1014 action->setIcon(SmallIcon("network-connect"));
1016 case Network::Disconnected:
1017 action->setIcon(SmallIcon("network-disconnect"));
1020 action->setIcon(SmallIcon("network-wired"));
1024 void MainWin::clientNetworkRemoved(NetworkId id) {
1025 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1029 action->deleteLater();
1032 void MainWin::connectOrDisconnectFromNet() {
1033 QAction *act = qobject_cast<QAction *>(sender());
1035 const Network *net = Client::network(act->data().value<NetworkId>());
1037 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1038 else net->requestDisconnect();
1041 void MainWin::on_jumpHotBuffer_triggered() {
1042 if(!_bufferHotList->rowCount())
1045 QModelIndex topIndex = _bufferHotList->index(0, 0);
1046 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1047 Client::bufferModel()->switchToBuffer(bufferId);
1050 void MainWin::on_actionDebugNetworkModel_triggered() {
1051 QTreeView *view = new QTreeView;
1052 view->setAttribute(Qt::WA_DeleteOnClose);
1053 view->setWindowTitle("Debug NetworkModel View");
1054 view->setModel(Client::networkModel());
1055 view->setColumnWidth(0, 250);
1056 view->setColumnWidth(1, 250);
1057 view->setColumnWidth(2, 80);
1058 view->resize(610, 300);
1062 void MainWin::on_actionDebugHotList_triggered() {
1063 QTreeView *view = new QTreeView;
1064 view->setAttribute(Qt::WA_DeleteOnClose);
1065 view->setModel(_bufferHotList);
1069 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1070 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1071 overlay->setAttribute(Qt::WA_DeleteOnClose);
1075 void MainWin::on_actionDebugMessageModel_triggered() {
1076 QTableView *view = new QTableView(0);
1077 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1078 filter->setSourceModel(Client::messageModel());
1079 view->setModel(filter);
1080 view->setAttribute(Qt::WA_DeleteOnClose, true);
1081 view->verticalHeader()->hide();
1082 view->horizontalHeader()->setStretchLastSection(true);
1086 void MainWin::on_actionDebugLog_triggered() {
1087 DebugLogWidget *logWidget = new DebugLogWidget(0);
1091 void MainWin::showStatusBarMessage(const QString &message) {
1092 statusBar()->showMessage(message, 10000);