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 "bufferhotlistfilter.h"
41 #include "buffermodel.h"
42 #include "bufferview.h"
43 #include "bufferviewoverlay.h"
44 #include "bufferviewoverlayfilter.h"
45 #include "bufferwidget.h"
46 #include "channellistdlg.h"
47 #include "chatlinemodel.h"
48 #include "chatmonitorfilter.h"
49 #include "chatmonitorview.h"
52 #include "clientsyncer.h"
53 #include "clientbacklogmanager.h"
54 #include "clientbufferviewconfig.h"
55 #include "clientbufferviewmanager.h"
56 #include "coreinfodlg.h"
57 #include "coreconnectdlg.h"
58 #include "contextmenuactionprovider.h"
59 #include "debugbufferviewoverlay.h"
60 #include "debuglogwidget.h"
61 #include "debugmessagemodelfilter.h"
62 #include "flatproxymodel.h"
63 #include "iconloader.h"
64 #include "inputwidget.h"
65 #include "inputline.h"
66 #include "irclistmodel.h"
67 #include "ircconnectionwizard.h"
68 #include "jumpkeyhandler.h"
69 #include "msgprocessorstatuswidget.h"
70 #include "nicklistwidget.h"
71 #include "qtuiapplication.h"
72 #include "qtuimessageprocessor.h"
73 #include "qtuisettings.h"
74 #include "settingsdlg.h"
75 #include "settingspagedlg.h"
76 #include "systemtray.h"
77 #include "toolbaractionprovider.h"
78 #include "topicwidget.h"
79 #include "verticaldock.h"
83 # include "desktopnotificationbackend.h"
86 # include "phononnotificationbackend.h"
88 # include "systraynotificationbackend.h"
89 # include "taskbarnotificationbackend.h"
91 # include "knotificationbackend.h"
94 #include "settingspages/aliasessettingspage.h"
95 #include "settingspages/appearancesettingspage.h"
96 #include "settingspages/backlogsettingspage.h"
97 #include "settingspages/bufferviewsettingspage.h"
98 #include "settingspages/chatmonitorsettingspage.h"
99 #include "settingspages/colorsettingspage.h"
100 #include "settingspages/generalsettingspage.h"
101 #include "settingspages/highlightsettingspage.h"
102 #include "settingspages/identitiessettingspage.h"
103 #include "settingspages/networkssettingspage.h"
104 #include "settingspages/notificationssettingspage.h"
106 MainWin::MainWin(QWidget *parent)
108 : KMainWindow(parent),
109 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
111 : QMainWindow(parent),
113 coreLagLabel(new QLabel()),
114 sslLabel(new QLabel()),
115 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
123 QtUiSettings uiSettings;
124 QString style = uiSettings.value("Style", QString()).toString();
125 if(!style.isEmpty()) {
126 QApplication::setStyle(style);
129 QApplication::setQuitOnLastWindowClosed(false);
131 setWindowTitle("Quassel IRC");
132 setWindowIconText("Quassel IRC");
135 installEventFilter(new JumpKeyHandler(this));
137 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
138 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
139 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
140 connect(app, SIGNAL(aboutToQuit()), SLOT(aboutToQuit()));
143 void MainWin::init() {
144 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
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
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::aboutToQuit() {
208 saveStateToSettings(s);
211 void MainWin::saveStateToSettings(UiSettings &s) {
212 s.setValue("MainWinSize", _normalSize);
213 s.setValue("MainWinPos", _normalPos);
214 s.setValue("MainWinState", saveState());
215 s.setValue("MainWinGeometry", saveGeometry());
216 s.setValue("MainWinMinimized", isMinimized());
217 s.setValue("MainWinHidden", _isHidden);
220 void MainWin::restoreStateFromSettings(UiSettings &s) {
221 restoreGeometry(s.value("MainWinGeometry").toByteArray());
223 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
224 resize(s.value("MainWinSize", QSize(800, 500)).toSize());
225 move(s.value("MainWinPos").toPoint());
228 restoreState(s.value("MainWinState").toByteArray());
231 if(s.value("MainWinHidden").toBool())
233 else if(s.value("MainWinMinimized").toBool())
239 void MainWin::updateIcon() {
241 const int size = 128;
247 if(Client::isConnected())
248 icon = DesktopIcon("quassel", size);
250 icon = DesktopIcon("quassel_inactive", size);
252 qApp->setWindowIcon(icon);
255 void MainWin::setupActions() {
256 ActionCollection *coll = QtUi::actionCollection("General");
258 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
259 this, SLOT(showCoreConnectionDlg())));
260 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
261 Client::instance(), SLOT(disconnectFromCore())));
262 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
263 this, SLOT(showCoreInfoDlg())));
264 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
265 this, SLOT(on_actionConfigureNetworks_triggered())));
266 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
267 qApp, SLOT(quit()), tr("Ctrl+Q")));
270 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
271 this, SLOT(on_actionConfigureViews_triggered())));
273 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
274 lockAct->setCheckable(true);
275 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
277 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
278 0, 0, QKeySequence::Find))->setCheckable(true);
279 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
280 this, SLOT(showAwayLog())));
281 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
282 0, 0))->setCheckable(true);
285 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
286 this, SLOT(showSettingsDlg()), tr("F7")));
289 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
290 this, SLOT(showAboutDlg())));
291 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
292 qApp, SLOT(aboutQt())));
293 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
294 this, SLOT(on_actionDebugNetworkModel_triggered())));
295 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
296 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
297 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
298 this, SLOT(on_actionDebugMessageModel_triggered())));
299 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
300 this, SLOT(on_actionDebugHotList_triggered())));
301 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
302 this, SLOT(on_actionDebugLog_triggered())));
305 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot buffer"), coll,
306 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
309 void MainWin::setupMenus() {
310 ActionCollection *coll = QtUi::actionCollection("General");
312 _fileMenu = menuBar()->addMenu(tr("&File"));
314 static const QStringList coreActions = QStringList()
315 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
318 foreach(QString actionName, coreActions) {
319 coreAction = coll->action(actionName);
320 _fileMenu->addAction(coreAction);
321 flagRemoteCoreOnly(coreAction);
323 flagRemoteCoreOnly(_fileMenu->addSeparator());
325 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
326 _networksMenu->addAction(coll->action("ConfigureNetworks"));
327 _networksMenu->addSeparator();
328 _fileMenu->addSeparator();
329 _fileMenu->addAction(coll->action("Quit"));
331 _viewMenu = menuBar()->addMenu(tr("&View"));
332 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
333 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
334 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
335 _viewMenu->addSeparator();
336 _viewMenu->addAction(coll->action("ToggleSearchBar"));
338 coreAction = coll->action("ShowAwayLog");
339 flagRemoteCoreOnly(coreAction);
340 _viewMenu->addAction(coreAction);
342 _viewMenu->addAction(coll->action("ToggleStatusBar"));
343 _viewMenu->addSeparator();
344 _viewMenu->addAction(coll->action("LockLayout"));
346 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
348 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
349 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
351 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
353 _helpMenu = menuBar()->addMenu(tr("&Help"));
354 _helpMenu->addAction(coll->action("AboutQuassel"));
356 _helpMenu->addAction(coll->action("AboutQt"));
358 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
360 _helpMenu->addSeparator();
361 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
362 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
363 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
364 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
365 _helpDebugMenu->addAction(coll->action("DebugHotList"));
366 _helpDebugMenu->addAction(coll->action("DebugLog"));
369 void MainWin::setupBufferWidget() {
370 _bufferWidget = new BufferWidget(this);
371 _bufferWidget->setModel(Client::bufferModel());
372 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
373 setCentralWidget(_bufferWidget);
376 void MainWin::addBufferView(int bufferViewConfigId) {
377 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
380 void MainWin::addBufferView(ClientBufferViewConfig *config) {
384 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
385 BufferViewDock *dock = new BufferViewDock(config, this);
387 //create the view and initialize it's filter
388 BufferView *view = new BufferView(dock);
389 view->setFilteredModel(Client::bufferModel(), config);
390 view->installEventFilter(_inputWidget->inputLine()); // for key presses
393 Client::bufferModel()->synchronizeView(view);
395 dock->setWidget(view);
398 addDockWidget(Qt::LeftDockWidgetArea, dock);
399 _bufferViewsMenu->addAction(dock->toggleViewAction());
401 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
402 _bufferViews.append(dock);
405 void MainWin::removeBufferView(int bufferViewConfigId) {
407 BufferViewDock *dock;
408 foreach(QAction *action, _bufferViewsMenu->actions()) {
409 actionData = action->data();
410 if(!actionData.isValid())
413 dock = qobject_cast<BufferViewDock *>(action->parent());
414 if(dock && actionData.toInt() == bufferViewConfigId) {
415 removeAction(action);
421 void MainWin::bufferViewToggled(bool enabled) {
422 QAction *action = qobject_cast<QAction *>(sender());
424 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
427 Client::bufferViewOverlay()->addView(dock->bufferViewId());
428 BufferViewConfig *config = dock->config();
429 if(config && config->isInitialized()) {
430 BufferIdList buffers;
431 if(config->networkId().isValid()) {
432 foreach(BufferId bufferId, config->bufferList()) {
433 if(Client::networkModel()->networkId(bufferId) == config->networkId())
436 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
437 if(Client::networkModel()->networkId(bufferId) == config->networkId())
441 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
443 Client::backlogManager()->checkForBacklog(buffers);
446 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
450 BufferView *MainWin::allBuffersView() const {
451 // "All Buffers" is always the first dock created
452 if(_bufferViews.count() > 0)
453 return _bufferViews[0]->bufferView();
457 void MainWin::showNotificationsDlg() {
458 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
462 void MainWin::on_actionConfigureNetworks_triggered() {
463 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
467 void MainWin::on_actionConfigureViews_triggered() {
468 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
472 void MainWin::on_actionLockLayout_toggled(bool lock) {
473 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
474 foreach(VerticalDock *dock, docks) {
475 dock->showTitle(!lock);
477 if(Client::bufferViewManager()) {
478 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
479 config->setLocked(lock);
482 QtUiSettings().setValue("LockLayout", lock);
485 void MainWin::setupNickWidget() {
487 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
488 nickDock->setObjectName("NickDock");
489 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
491 _nickListWidget = new NickListWidget(nickDock);
492 nickDock->setWidget(_nickListWidget);
494 addDockWidget(Qt::RightDockWidgetArea, nickDock);
495 _viewMenu->addAction(nickDock->toggleViewAction());
496 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
498 // See NickListDock::NickListDock();
499 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
501 // attach the NickListWidget to the BufferModel and the default selection
502 _nickListWidget->setModel(Client::bufferModel());
503 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
506 void MainWin::setupChatMonitor() {
507 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
508 dock->setObjectName("ChatMonitorDock");
510 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
511 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
513 dock->setWidget(chatView);
516 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
517 _viewMenu->addAction(dock->toggleViewAction());
518 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
521 void MainWin::setupInputWidget() {
522 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
523 dock->setObjectName("InputDock");
525 _inputWidget = new InputWidget(dock);
526 dock->setWidget(_inputWidget);
528 addDockWidget(Qt::BottomDockWidgetArea, dock);
530 _viewMenu->addAction(dock->toggleViewAction());
531 dock->toggleViewAction()->setText(tr("Show Input Line"));
533 _inputWidget->setModel(Client::bufferModel());
534 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
536 _bufferWidget->setFocusProxy(_inputWidget);
538 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
541 void MainWin::setupTopicWidget() {
542 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
543 dock->setObjectName("TopicDock");
544 TopicWidget *topicwidget = new TopicWidget(dock);
546 dock->setWidget(topicwidget);
548 topicwidget->setModel(Client::bufferModel());
549 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
551 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
553 _viewMenu->addAction(dock->toggleViewAction());
554 dock->toggleViewAction()->setText(tr("Show Topic Line"));
557 void MainWin::setupTitleSetter() {
558 _titleSetter.setModel(Client::bufferModel());
559 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
562 void MainWin::setupStatusBar() {
563 // MessageProcessor progress
564 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
567 updateLagIndicator();
568 statusBar()->addPermanentWidget(coreLagLabel);
569 coreLagLabel->hide();
570 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
573 sslLabel->setPixmap(QPixmap());
574 statusBar()->addPermanentWidget(sslLabel);
577 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
579 QtUiSettings uiSettings;
581 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
582 showStatusbar->setChecked(enabled);
583 enabled ? statusBar()->show() : statusBar()->hide();
585 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
586 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
589 void MainWin::setupHotList() {
590 FlatProxyModel *flatProxy = new FlatProxyModel(this);
591 flatProxy->setSourceModel(Client::bufferModel());
592 _bufferHotList = new BufferHotListFilter(flatProxy);
595 void MainWin::saveStatusBarStatus(bool enabled) {
596 QtUiSettings uiSettings;
597 uiSettings.setValue("ShowStatusBar", enabled);
600 void MainWin::setupSystray() {
601 _systemTray = new SystemTray(this);
604 void MainWin::setupToolBars() {
605 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
606 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
607 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
608 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
611 setUnifiedTitleAndToolBarOnMac(true);
613 _mainToolBar = addToolBar(tr("Main Toolbar"));
614 _mainToolBar->setObjectName("MainToolBar");
616 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
617 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
619 //_nickToolBar = addToolBar("User");
620 //_nickToolBar->setObjectName("NickToolBar");
621 //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
624 _mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
625 //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
629 void MainWin::connectedToCore() {
630 Q_CHECK_PTR(Client::bufferViewManager());
631 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
632 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
633 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
638 void MainWin::setConnectedState() {
639 ActionCollection *coll = QtUi::actionCollection("General");
641 coll->action("ConnectCore")->setEnabled(false);
642 coll->action("DisconnectCore")->setEnabled(true);
643 coll->action("CoreInfo")->setEnabled(true);
645 foreach(QAction *action, _fileMenu->actions()) {
646 if(isRemoteCoreOnly(action))
647 action->setVisible(!Client::internalCore());
650 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
651 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
652 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
653 if(!Client::internalCore()) {
654 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
655 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
656 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
659 // _viewMenu->setEnabled(true);
660 if(!Client::internalCore())
661 statusBar()->showMessage(tr("Connected to core."));
663 statusBar()->clearMessage();
665 if(Client::signalProxy()->isSecure()) {
666 sslLabel->setPixmap(SmallIcon("security-high"));
668 sslLabel->setPixmap(SmallIcon("security-low"));
671 sslLabel->setVisible(!Client::internalCore());
672 coreLagLabel->setVisible(!Client::internalCore());
674 systemTray()->setState(SystemTray::Active);
676 if(Client::networkIds().isEmpty()) {
677 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
682 void MainWin::loadLayout() {
684 int accountId = Client::currentCoreAccount().toInt();
685 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
688 void MainWin::saveLayout() {
690 int accountId = Client::currentCoreAccount().toInt();
691 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
694 void MainWin::updateLagIndicator(int lag) {
695 QString text = tr("Core Lag: %1");
697 text = text.arg('-');
699 text = text.arg("%1 msec").arg(lag);
700 coreLagLabel->setText(text);
703 void MainWin::disconnectedFromCore() {
704 // save core specific layout and remove bufferviews;
707 BufferViewDock *dock;
708 foreach(QAction *action, _bufferViewsMenu->actions()) {
709 actionData = action->data();
710 if(!actionData.isValid())
713 dock = qobject_cast<BufferViewDock *>(action->parent());
714 if(dock && actionData.toInt() != -1) {
715 removeAction(action);
720 restoreState(s.value("MainWinState").toByteArray());
721 setDisconnectedState();
724 void MainWin::setDisconnectedState() {
725 ActionCollection *coll = QtUi::actionCollection("General");
726 //ui.menuCore->setEnabled(false);
727 coll->action("ConnectCore")->setEnabled(true);
728 coll->action("DisconnectCore")->setEnabled(false);
729 coll->action("CoreInfo")->setEnabled(false);
730 //_viewMenu->setEnabled(false);
731 statusBar()->showMessage(tr("Not connected to core."));
732 sslLabel->setPixmap(QPixmap());
734 updateLagIndicator();
735 coreLagLabel->hide();
736 if(msgProcessorStatusWidget)
737 msgProcessorStatusWidget->setProgress(0, 0);
739 systemTray()->setState(SystemTray::Inactive);
742 void MainWin::startInternalCore() {
743 ClientSyncer *syncer = new ClientSyncer();
744 Client::registerClientSyncer(syncer);
745 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
746 syncer->useInternalCore();
749 void MainWin::showCoreConnectionDlg(bool autoConnect) {
750 CoreConnectDlg(autoConnect, this).exec();
753 void MainWin::showChannelList(NetworkId netId) {
754 ChannelListDlg *channelListDlg = new ChannelListDlg();
756 if(!netId.isValid()) {
757 QAction *action = qobject_cast<QAction *>(sender());
759 netId = action->data().value<NetworkId>();
762 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
763 channelListDlg->setNetwork(netId);
764 channelListDlg->show();
767 void MainWin::showCoreInfoDlg() {
768 CoreInfoDlg(this).exec();
771 void MainWin::showAwayLog() {
774 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
775 _awayLog = new AwayLogView(filter, 0);
776 filter->setParent(_awayLog);
777 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
778 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
782 void MainWin::awayLogDestroyed() {
786 void MainWin::showSettingsDlg() {
787 SettingsDlg *dlg = new SettingsDlg();
789 //Category: Appearance
790 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
791 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
792 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
793 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
794 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
795 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
796 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
799 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
800 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
801 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
802 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
807 void MainWin::showAboutDlg() {
808 AboutDlg(this).exec();
812 void MainWin::showShortcutsDlg() {
813 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
817 /********************************************************************************************************/
819 bool MainWin::event(QEvent *event) {
820 if(event->type() == QEvent::WindowActivate)
821 QtUi::closeNotifications();
822 return QMainWindow::event(event);
825 void MainWin::moveEvent(QMoveEvent *event) {
826 if(!(windowState() & Qt::WindowMaximized))
827 _normalPos = event->pos();
832 void MainWin::resizeEvent(QResizeEvent *event) {
833 if(!(windowState() & Qt::WindowMaximized))
834 _normalSize = event->size();
839 void MainWin::closeEvent(QCloseEvent *event) {
841 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
843 if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
844 toggleMinimizedToTray();
848 QApplication::quit();
852 void MainWin::changeEvent(QEvent *event) {
853 if(event->type() == QEvent::WindowStateChange) {
854 if(windowState() & Qt::WindowMinimized) {
856 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
865 else if(event->type() == QEvent::ActivationChange)
866 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
872 void MainWin::hideToTray() {
873 if(!systemTray()->isSystemTrayAvailable()) {
874 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
878 systemTray()->setIconVisible();
882 void MainWin::toggleMinimizedToTray() {
884 // the problem is that we lose focus when the systray icon is activated
885 // and we don't know the former active window
886 // therefore we watch for activation event and use our stopwatch :)
887 // courtesy: KSystemTrayIcon
888 if(GetTickCount() - dwTickCount >= 300)
889 // we weren't active in the last 300ms -> activate
896 if(!isVisible() || isMinimized())
905 void MainWin::forceActivated() {
907 // Bypass focus stealing prevention
908 QX11Info::setAppUserTime(QX11Info::appTime());
911 if(windowState() & Qt::WindowMinimized) {
913 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
916 move(frameGeometry().topLeft()); // avoid placement policies
923 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
926 bool hasFocus = QApplication::activeWindow() != 0;
928 for(int i = start; i <= end; i++) {
929 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
931 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
934 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
935 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
937 flags |= Message::Backlog; // we only want to trigger a highlight once!
938 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
940 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
941 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
943 if(hasFocus && bufId == _bufferWidget->currentBuffer())
946 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
947 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
948 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
949 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
950 AbstractNotificationBackend::NotificationType type;
952 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
953 type = AbstractNotificationBackend::PrivMsg;
954 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
955 type = AbstractNotificationBackend::PrivMsgFocused;
956 else if(flags & Message::Highlight && !hasFocus)
957 type = AbstractNotificationBackend::Highlight;
959 type = AbstractNotificationBackend::HighlightFocused;
961 QtUi::invokeNotification(bufId, type, sender, contents);
966 void MainWin::clientNetworkCreated(NetworkId id) {
967 const Network *net = Client::network(id);
968 QAction *act = new QAction(net->networkName(), this);
969 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
970 act->setData(QVariant::fromValue<NetworkId>(id));
971 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
972 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
974 QAction *beforeAction = 0;
975 foreach(QAction *action, _networksMenu->actions()) {
976 if(!action->data().isValid()) // ignore stock actions
978 if(net->networkName().localeAwareCompare(action->text()) < 0) {
979 beforeAction = action;
983 _networksMenu->insertAction(beforeAction, act);
986 void MainWin::clientNetworkUpdated() {
987 const Network *net = qobject_cast<const Network *>(sender());
991 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
995 action->setText(net->networkName());
997 switch(net->connectionState()) {
998 case Network::Initialized:
999 action->setIcon(SmallIcon("network-connect"));
1001 case Network::Disconnected:
1002 action->setIcon(SmallIcon("network-disconnect"));
1005 action->setIcon(SmallIcon("network-wired"));
1009 void MainWin::clientNetworkRemoved(NetworkId id) {
1010 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1014 action->deleteLater();
1017 void MainWin::connectOrDisconnectFromNet() {
1018 QAction *act = qobject_cast<QAction *>(sender());
1020 const Network *net = Client::network(act->data().value<NetworkId>());
1022 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1023 else net->requestDisconnect();
1026 void MainWin::on_jumpHotBuffer_triggered() {
1027 if(!_bufferHotList->rowCount())
1030 QModelIndex topIndex = _bufferHotList->index(0, 0);
1031 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1032 Client::bufferModel()->switchToBuffer(bufferId);
1035 void MainWin::on_actionDebugNetworkModel_triggered() {
1036 QTreeView *view = new QTreeView;
1037 view->setAttribute(Qt::WA_DeleteOnClose);
1038 view->setWindowTitle("Debug NetworkModel View");
1039 view->setModel(Client::networkModel());
1040 view->setColumnWidth(0, 250);
1041 view->setColumnWidth(1, 250);
1042 view->setColumnWidth(2, 80);
1043 view->resize(610, 300);
1047 void MainWin::on_actionDebugHotList_triggered() {
1048 QTreeView *view = new QTreeView;
1049 view->setAttribute(Qt::WA_DeleteOnClose);
1050 view->setModel(_bufferHotList);
1054 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1055 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1056 overlay->setAttribute(Qt::WA_DeleteOnClose);
1060 void MainWin::on_actionDebugMessageModel_triggered() {
1061 QTableView *view = new QTableView(0);
1062 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1063 filter->setSourceModel(Client::messageModel());
1064 view->setModel(filter);
1065 view->setAttribute(Qt::WA_DeleteOnClose, true);
1066 view->verticalHeader()->hide();
1067 view->horizontalHeader()->setStretchLastSection(true);
1071 void MainWin::on_actionDebugLog_triggered() {
1072 DebugLogWidget *logWidget = new DebugLogWidget(0);
1077 void MainWin::saveStateToSession(const QString &sessionId) {
1079 SessionSettings s(sessionId);
1081 s.setValue("MainWinSize", size());
1082 s.setValue("MainWinPos", pos());
1083 s.setValue("MainWinState", saveState());
1087 void MainWin::saveStateToSessionSettings(SessionSettings & s)
1089 s.setValue("MainWinSize", size());
1090 s.setValue("MainWinPos", pos());
1091 s.setValue("MainWinState", saveState());
1094 void MainWin::showStatusBarMessage(const QString &message) {
1095 statusBar()->showMessage(message, 10000);