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 "bufferwidget.h"
43 #include "channellistdlg.h"
44 #include "chatlinemodel.h"
45 #include "chatmonitorfilter.h"
46 #include "chatmonitorview.h"
49 #include "clientsyncer.h"
50 #include "clientbacklogmanager.h"
51 #include "clientbufferviewconfig.h"
52 #include "clientbufferviewmanager.h"
53 #include "coreinfodlg.h"
54 #include "coreconnectdlg.h"
55 #include "contextmenuactionprovider.h"
56 #include "debuglogwidget.h"
57 #include "debugmessagemodelfilter.h"
58 #include "iconloader.h"
59 #include "inputwidget.h"
60 #include "inputline.h"
61 #include "irclistmodel.h"
62 #include "ircconnectionwizard.h"
63 #include "jumpkeyhandler.h"
64 #include "msgprocessorstatuswidget.h"
65 #include "nicklistwidget.h"
66 #include "qtuiapplication.h"
67 #include "qtuimessageprocessor.h"
68 #include "qtuisettings.h"
69 #include "settingsdlg.h"
70 #include "settingspagedlg.h"
71 #include "systemtray.h"
72 #include "toolbaractionprovider.h"
73 #include "topicwidget.h"
74 #include "verticaldock.h"
78 # include "desktopnotificationbackend.h"
81 # include "phononnotificationbackend.h"
83 # include "systraynotificationbackend.h"
84 # include "taskbarnotificationbackend.h"
86 # include "knotificationbackend.h"
89 #include "settingspages/aliasessettingspage.h"
90 #include "settingspages/appearancesettingspage.h"
91 #include "settingspages/backlogsettingspage.h"
92 #include "settingspages/bufferviewsettingspage.h"
93 #include "settingspages/chatmonitorsettingspage.h"
94 #include "settingspages/colorsettingspage.h"
95 #include "settingspages/generalsettingspage.h"
96 #include "settingspages/highlightsettingspage.h"
97 #include "settingspages/identitiessettingspage.h"
98 #include "settingspages/networkssettingspage.h"
99 #include "settingspages/notificationssettingspage.h"
101 MainWin::MainWin(QWidget *parent)
103 : KMainWindow(parent),
104 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
106 : QMainWindow(parent),
108 coreLagLabel(new QLabel()),
109 sslLabel(new QLabel()),
110 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
118 QtUiSettings uiSettings;
119 QString style = uiSettings.value("Style", QString()).toString();
120 if(!style.isEmpty()) {
121 QApplication::setStyle(style);
124 QApplication::setQuitOnLastWindowClosed(false);
126 setWindowTitle("Quassel IRC");
127 setWindowIconText("Quassel IRC");
130 installEventFilter(new JumpKeyHandler(this));
132 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
133 connect(app, SIGNAL(aboutToQuit()), SLOT(aboutToQuit()));
136 void MainWin::init() {
137 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
138 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
139 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
140 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
141 SLOT(messagesInserted(const QModelIndex &, int, int)));
142 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
145 setDockNestingEnabled(true);
146 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
147 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
148 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
149 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
151 // Order is sometimes important
165 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
166 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
168 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
171 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
175 QtUi::registerNotificationBackend(new KNotificationBackend(this));
176 #endif /* HAVE_KDE */
178 setDisconnectedState(); // Disable menus and stuff
180 // restore mainwin state
182 restoreStateFromSettings(s);
184 // restore locked state of docks
185 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
187 if(Quassel::runMode() != Quassel::Monolithic) {
188 showCoreConnectionDlg(true); // autoconnect if appropriate
194 MainWin::~MainWin() {
198 void MainWin::aboutToQuit() {
200 saveStateToSettings(s);
203 void MainWin::saveStateToSettings(UiSettings &s) {
204 s.setValue("MainWinSize", _normalSize);
205 s.setValue("MainWinPos", _normalPos);
206 s.setValue("MainWinState", saveState());
207 s.setValue("MainWinGeometry", saveGeometry());
208 s.setValue("MainWinMinimized", isMinimized());
209 s.setValue("MainWinMaximized", isMaximized());
210 s.setValue("MainWinHidden", _isHidden);
213 void MainWin::restoreStateFromSettings(UiSettings &s) {
214 _normalSize = s.value("MainWinSize", size()).toSize();
215 _normalPos = s.value("MainWinPos", pos()).toPoint();
216 bool maximized = s.value("MainWinMaximized", false).toBool();
218 restoreGeometry(s.value("MainWinGeometry").toByteArray());
221 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
226 restoreState(s.value("MainWinState").toByteArray());
229 if(s.value("MainWinHidden").toBool())
231 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, tr("Ctrl+F")))->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("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
296 this, SLOT(on_actionDebugMessageModel_triggered())));
297 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
298 this, SLOT(on_actionDebugLog_triggered())));
301 void MainWin::setupMenus() {
302 ActionCollection *coll = QtUi::actionCollection("General");
304 _fileMenu = menuBar()->addMenu(tr("&File"));
306 static const QStringList coreActions = QStringList()
307 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
310 foreach(QString actionName, coreActions) {
311 coreAction = coll->action(actionName);
312 _fileMenu->addAction(coreAction);
313 flagRemoteCoreOnly(coreAction);
315 flagRemoteCoreOnly(_fileMenu->addSeparator());
317 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
318 _networksMenu->addAction(coll->action("ConfigureNetworks"));
319 _networksMenu->addSeparator();
320 _fileMenu->addSeparator();
321 _fileMenu->addAction(coll->action("Quit"));
323 _viewMenu = menuBar()->addMenu(tr("&View"));
324 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
325 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
326 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
327 _viewMenu->addSeparator();
328 _viewMenu->addAction(coll->action("ToggleSearchBar"));
330 coreAction = coll->action("ShowAwayLog");
331 flagRemoteCoreOnly(coreAction);
332 _viewMenu->addAction(coreAction);
334 _viewMenu->addAction(coll->action("ToggleStatusBar"));
335 _viewMenu->addSeparator();
336 _viewMenu->addAction(coll->action("LockLayout"));
338 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
340 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
341 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
343 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
345 _helpMenu = menuBar()->addMenu(tr("&Help"));
346 _helpMenu->addAction(coll->action("AboutQuassel"));
348 _helpMenu->addAction(coll->action("AboutQt"));
350 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
352 _helpMenu->addSeparator();
353 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
354 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
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 _bufferViews.append(dock);
394 void MainWin::removeBufferView(int bufferViewConfigId) {
396 BufferViewDock *dock;
397 foreach(QAction *action, _bufferViewsMenu->actions()) {
398 actionData = action->data();
399 if(!actionData.isValid())
402 dock = qobject_cast<BufferViewDock *>(action->parent());
403 if(dock && actionData.toInt() == bufferViewConfigId) {
404 removeAction(action);
410 BufferView *MainWin::allBuffersView() const {
411 // "All Buffers" is always the first dock created
412 if(_bufferViews.count() > 0)
413 return _bufferViews[0]->bufferView();
417 void MainWin::showNotificationsDlg() {
418 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
422 void MainWin::on_actionConfigureNetworks_triggered() {
423 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
427 void MainWin::on_actionConfigureViews_triggered() {
428 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
432 void MainWin::on_actionLockLayout_toggled(bool lock) {
433 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
434 foreach(VerticalDock *dock, docks) {
435 dock->showTitle(!lock);
437 if(Client::bufferViewManager()) {
438 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
439 config->setLocked(lock);
442 QtUiSettings().setValue("LockLayout", lock);
445 void MainWin::setupNickWidget() {
447 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
448 nickDock->setObjectName("NickDock");
449 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
451 _nickListWidget = new NickListWidget(nickDock);
452 nickDock->setWidget(_nickListWidget);
454 addDockWidget(Qt::RightDockWidgetArea, nickDock);
455 _viewMenu->addAction(nickDock->toggleViewAction());
456 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
458 // See NickListDock::NickListDock();
459 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
461 // attach the NickListWidget to the BufferModel and the default selection
462 _nickListWidget->setModel(Client::bufferModel());
463 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
466 void MainWin::setupChatMonitor() {
467 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
468 dock->setObjectName("ChatMonitorDock");
470 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
471 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
473 dock->setWidget(chatView);
476 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
477 _viewMenu->addAction(dock->toggleViewAction());
478 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
481 void MainWin::setupInputWidget() {
482 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
483 dock->setObjectName("InputDock");
485 _inputWidget = new InputWidget(dock);
486 dock->setWidget(_inputWidget);
488 addDockWidget(Qt::BottomDockWidgetArea, dock);
490 _viewMenu->addAction(dock->toggleViewAction());
491 dock->toggleViewAction()->setText(tr("Show Input Line"));
493 _inputWidget->setModel(Client::bufferModel());
494 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
496 _bufferWidget->setFocusProxy(_inputWidget);
498 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
501 void MainWin::setupTopicWidget() {
502 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
503 dock->setObjectName("TopicDock");
504 TopicWidget *topicwidget = new TopicWidget(dock);
506 dock->setWidget(topicwidget);
508 topicwidget->setModel(Client::bufferModel());
509 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
511 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
513 _viewMenu->addAction(dock->toggleViewAction());
514 dock->toggleViewAction()->setText(tr("Show Topic Line"));
517 void MainWin::setupTitleSetter() {
518 _titleSetter.setModel(Client::bufferModel());
519 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
522 void MainWin::setupStatusBar() {
523 // MessageProcessor progress
524 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
527 updateLagIndicator();
528 statusBar()->addPermanentWidget(coreLagLabel);
529 coreLagLabel->hide();
530 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
533 sslLabel->setPixmap(QPixmap());
534 statusBar()->addPermanentWidget(sslLabel);
537 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
539 QtUiSettings uiSettings;
541 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
542 showStatusbar->setChecked(enabled);
543 enabled ? statusBar()->show() : statusBar()->hide();
545 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
546 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
549 void MainWin::saveStatusBarStatus(bool enabled) {
550 QtUiSettings uiSettings;
551 uiSettings.setValue("ShowStatusBar", enabled);
554 void MainWin::setupSystray() {
555 _systemTray = new SystemTray(this);
558 void MainWin::setupToolBars() {
559 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
560 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
561 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
562 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
565 setUnifiedTitleAndToolBarOnMac(true);
567 _mainToolBar = addToolBar("Main Toolbar");
568 _mainToolBar->setObjectName("MainToolBar");
570 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
571 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
573 //_nickToolBar = addToolBar("User");
574 //_nickToolBar->setObjectName("NickToolBar");
575 //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
578 _mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
579 //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
583 void MainWin::connectedToCore() {
584 Q_CHECK_PTR(Client::bufferViewManager());
585 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
586 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
587 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
592 void MainWin::setConnectedState() {
593 ActionCollection *coll = QtUi::actionCollection("General");
595 coll->action("ConnectCore")->setEnabled(false);
596 coll->action("DisconnectCore")->setEnabled(true);
597 coll->action("CoreInfo")->setEnabled(true);
599 foreach(QAction *action, _fileMenu->actions()) {
600 if(isRemoteCoreOnly(action))
601 action->setVisible(!Client::internalCore());
604 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
605 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
606 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
607 if(!Client::internalCore()) {
608 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
609 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
610 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
613 // _viewMenu->setEnabled(true);
614 if(!Client::internalCore())
615 statusBar()->showMessage(tr("Connected to core."));
617 statusBar()->clearMessage();
619 if(Client::signalProxy()->isSecure()) {
620 sslLabel->setPixmap(SmallIcon("security-high"));
622 sslLabel->setPixmap(SmallIcon("security-low"));
625 sslLabel->setVisible(!Client::internalCore());
626 coreLagLabel->setVisible(!Client::internalCore());
628 systemTray()->setState(SystemTray::Active);
630 if(Client::networkIds().isEmpty()) {
631 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
636 void MainWin::loadLayout() {
638 int accountId = Client::currentCoreAccount().toInt();
639 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
642 void MainWin::saveLayout() {
644 int accountId = Client::currentCoreAccount().toInt();
645 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
648 void MainWin::updateLagIndicator(int lag) {
649 QString text = tr("Core Lag: %1");
651 text = text.arg('-');
653 text = text.arg("%1 msec").arg(lag);
654 coreLagLabel->setText(text);
657 void MainWin::disconnectedFromCore() {
658 // save core specific layout and remove bufferviews;
661 BufferViewDock *dock;
662 foreach(QAction *action, _bufferViewsMenu->actions()) {
663 actionData = action->data();
664 if(!actionData.isValid())
667 dock = qobject_cast<BufferViewDock *>(action->parent());
668 if(dock && actionData.toInt() != -1) {
669 removeAction(action);
674 restoreState(s.value("MainWinState").toByteArray());
675 setDisconnectedState();
678 void MainWin::setDisconnectedState() {
679 ActionCollection *coll = QtUi::actionCollection("General");
680 //ui.menuCore->setEnabled(false);
681 coll->action("ConnectCore")->setEnabled(true);
682 coll->action("DisconnectCore")->setEnabled(false);
683 coll->action("CoreInfo")->setEnabled(false);
684 //_viewMenu->setEnabled(false);
685 statusBar()->showMessage(tr("Not connected to core."));
686 sslLabel->setPixmap(QPixmap());
688 updateLagIndicator();
689 coreLagLabel->hide();
690 if(msgProcessorStatusWidget)
691 msgProcessorStatusWidget->setProgress(0, 0);
693 systemTray()->setState(SystemTray::Inactive);
696 void MainWin::startInternalCore() {
697 ClientSyncer *syncer = new ClientSyncer();
698 Client::registerClientSyncer(syncer);
699 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
700 syncer->useInternalCore();
703 void MainWin::showCoreConnectionDlg(bool autoConnect) {
704 CoreConnectDlg(autoConnect, this).exec();
707 void MainWin::showChannelList(NetworkId netId) {
708 ChannelListDlg *channelListDlg = new ChannelListDlg();
710 if(!netId.isValid()) {
711 QAction *action = qobject_cast<QAction *>(sender());
713 netId = action->data().value<NetworkId>();
716 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
717 channelListDlg->setNetwork(netId);
718 channelListDlg->show();
721 void MainWin::showCoreInfoDlg() {
722 CoreInfoDlg(this).exec();
725 void MainWin::showAwayLog() {
728 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
729 _awayLog = new AwayLogView(filter, 0);
730 filter->setParent(_awayLog);
731 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
732 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
736 void MainWin::awayLogDestroyed() {
740 void MainWin::showSettingsDlg() {
741 SettingsDlg *dlg = new SettingsDlg();
743 //Category: Appearance
744 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
745 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
746 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
747 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
748 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
749 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
750 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
753 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
754 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
755 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
756 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
761 void MainWin::showAboutDlg() {
762 AboutDlg(this).exec();
766 void MainWin::showShortcutsDlg() {
767 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
771 /********************************************************************************************************/
773 bool MainWin::event(QEvent *event) {
774 if(event->type() == QEvent::WindowActivate)
775 QtUi::closeNotifications();
776 return QMainWindow::event(event);
779 void MainWin::moveEvent(QMoveEvent *event) {
780 if(!(windowState() & Qt::WindowMaximized))
781 _normalPos = event->pos();
783 QMainWindow::moveEvent(event);
786 void MainWin::resizeEvent(QResizeEvent *event) {
787 if(!(windowState() & Qt::WindowMaximized))
788 _normalSize = event->size();
790 QMainWindow::resizeEvent(event);
793 void MainWin::closeEvent(QCloseEvent *event) {
795 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
797 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
802 QApplication::quit();
806 void MainWin::changeEvent(QEvent *event) {
808 if(event->type() == QEvent::ActivationChange)
809 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
812 QMainWindow::changeEvent(event);
815 void MainWin::hideToTray() {
816 if(!systemTray()->isSystemTrayAvailable()) {
817 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
821 systemTray()->setIconVisible();
825 void MainWin::toggleMinimizedToTray() {
827 // the problem is that we lose focus when the systray icon is activated
828 // and we don't know the former active window
829 // therefore we watch for activation event and use our stopwatch :)
830 // courtesy: KSystemTrayIcon
831 if(GetTickCount() - dwTickCount >= 300)
832 // we weren't active in the last 300ms -> activate
839 if(!isVisible() || isMinimized())
848 void MainWin::forceActivated() {
850 // Bypass focus stealing prevention
851 QX11Info::setAppUserTime(QX11Info::appTime());
854 if(windowState() & Qt::WindowMinimized) {
856 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
859 // this does not actually work on all platforms... and causes more evil than good
860 // move(frameGeometry().topLeft()); // avoid placement policies
867 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
870 if(QApplication::activeWindow() != 0)
873 for(int i = start; i <= end; i++) {
874 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
876 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
879 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
880 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self)) continue;
881 flags |= Message::Backlog; // we only want to trigger a highlight once!
882 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
884 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
885 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
887 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
888 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
889 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
890 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
891 QtUi::invokeNotification(bufId, sender, contents);
896 void MainWin::clientNetworkCreated(NetworkId id) {
897 const Network *net = Client::network(id);
898 QAction *act = new QAction(net->networkName(), this);
899 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
900 act->setData(QVariant::fromValue<NetworkId>(id));
901 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
902 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
904 QAction *beforeAction = 0;
905 foreach(QAction *action, _networksMenu->actions()) {
906 if(!action->data().isValid()) // ignore stock actions
908 if(net->networkName().localeAwareCompare(action->text()) < 0) {
909 beforeAction = action;
913 _networksMenu->insertAction(beforeAction, act);
916 void MainWin::clientNetworkUpdated() {
917 const Network *net = qobject_cast<const Network *>(sender());
921 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
925 action->setText(net->networkName());
927 switch(net->connectionState()) {
928 case Network::Initialized:
929 action->setIcon(SmallIcon("network-connect"));
931 case Network::Disconnected:
932 action->setIcon(SmallIcon("network-disconnect"));
935 action->setIcon(SmallIcon("network-wired"));
939 void MainWin::clientNetworkRemoved(NetworkId id) {
940 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
944 action->deleteLater();
947 void MainWin::connectOrDisconnectFromNet() {
948 QAction *act = qobject_cast<QAction *>(sender());
950 const Network *net = Client::network(act->data().value<NetworkId>());
952 if(net->connectionState() == Network::Disconnected) net->requestConnect();
953 else net->requestDisconnect();
956 void MainWin::on_actionDebugNetworkModel_triggered() {
957 QTreeView *view = new QTreeView;
958 view->setAttribute(Qt::WA_DeleteOnClose);
959 view->setWindowTitle("Debug NetworkModel View");
960 view->setModel(Client::networkModel());
961 view->setColumnWidth(0, 250);
962 view->setColumnWidth(1, 250);
963 view->setColumnWidth(2, 80);
964 view->resize(610, 300);
968 void MainWin::on_actionDebugMessageModel_triggered() {
969 QTableView *view = new QTableView(0);
970 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
971 filter->setSourceModel(Client::messageModel());
972 view->setModel(filter);
973 view->setAttribute(Qt::WA_DeleteOnClose, true);
974 view->verticalHeader()->hide();
975 view->horizontalHeader()->setStretchLastSection(true);
979 void MainWin::on_actionDebugLog_triggered() {
980 DebugLogWidget *logWidget = new DebugLogWidget(0);
984 void MainWin::showStatusBarMessage(const QString &message) {
985 statusBar()->showMessage(message, 10000);