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>
33 #include "actioncollection.h"
34 #include "buffermodel.h"
35 #include "bufferview.h"
36 #include "bufferviewmanager.h"
37 #include "bufferwidget.h"
38 #include "channellistdlg.h"
39 #include "chatlinemodel.h"
40 #include "chatmonitorfilter.h"
41 #include "chatmonitorview.h"
44 #include "clientsyncer.h"
45 #include "clientbacklogmanager.h"
46 #include "coreinfodlg.h"
47 #include "coreconnectdlg.h"
48 #include "debuglogwidget.h"
49 #include "debugmessagemodelfilter.h"
50 #include "iconloader.h"
51 #include "inputwidget.h"
52 #include "inputline.h"
53 #include "irclistmodel.h"
54 #include "jumpkeyhandler.h"
55 #include "msgprocessorstatuswidget.h"
56 #include "nicklistwidget.h"
57 #include "qtuiapplication.h"
58 #include "qtuimessageprocessor.h"
59 #include "qtuisettings.h"
60 #include "sessionsettings.h"
61 #include "settingsdlg.h"
62 #include "settingspagedlg.h"
63 #include "topicwidget.h"
64 #include "verticaldock.h"
68 # include "desktopnotificationbackend.h"
71 # include "phononnotificationbackend.h"
73 # include "systraynotificationbackend.h"
74 # include "taskbarnotificationbackend.h"
76 # include "knotificationbackend.h"
79 #include "settingspages/aliasessettingspage.h"
80 #include "settingspages/appearancesettingspage.h"
81 #include "settingspages/backlogsettingspage.h"
82 #include "settingspages/bufferviewsettingspage.h"
83 #include "settingspages/chatmonitorsettingspage.h"
84 #include "settingspages/colorsettingspage.h"
85 #include "settingspages/fontssettingspage.h"
86 #include "settingspages/generalsettingspage.h"
87 #include "settingspages/highlightsettingspage.h"
88 #include "settingspages/identitiessettingspage.h"
89 #include "settingspages/networkssettingspage.h"
90 #include "settingspages/notificationssettingspage.h"
92 MainWin::MainWin(QWidget *parent)
94 : KMainWindow(parent),
95 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
97 : QMainWindow(parent),
99 coreLagLabel(new QLabel()),
100 sslLabel(new QLabel()),
101 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
103 _trayIcon(new QSystemTrayIcon(this))
105 QtUiSettings uiSettings;
106 QString style = uiSettings.value("Style", QString()).toString();
107 if(!style.isEmpty()) {
108 QApplication::setStyle(style);
111 QApplication::setQuitOnLastWindowClosed(false);
113 setWindowTitle("Quassel IRC");
114 setWindowIconText("Quassel IRC");
117 installEventFilter(new JumpKeyHandler(this));
119 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
120 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
121 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
124 void MainWin::init() {
126 if(s.value("MainWinSize").isValid())
127 resize(s.value("MainWinSize").toSize());
129 resize(QSize(800, 500));
131 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
132 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
133 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
134 connect(Client::mainUi()->actionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
137 setDockNestingEnabled(true);
138 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
139 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
140 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
141 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
143 // Order is sometimes important
156 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
157 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
159 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
162 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
166 QtUi::registerNotificationBackend(new KNotificationBackend(this));
167 #endif /* HAVE_KDE */
169 // restore mainwin state
170 restoreState(s.value("MainWinState").toByteArray());
172 // restore locked state of docks
173 QtUi::actionCollection("General")->action("LockDockPositions")->setChecked(s.value("LockDocks", false).toBool());
175 setDisconnectedState(); // Disable menus and stuff
178 if(Quassel::runMode() != Quassel::Monolithic) {
179 showCoreConnectionDlg(true); // autoconnect if appropriate
185 MainWin::~MainWin() {
187 s.setValue("MainWinSize", size());
188 s.setValue("MainWinPos", pos());
189 s.setValue("MainWinState", saveState());
192 void MainWin::updateIcon() {
194 if(Client::isConnected())
195 icon = DesktopIcon("quassel", IconLoader::SizeEnormous);
197 icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous);
199 qApp->setWindowIcon(icon);
200 systemTrayIcon()->setIcon(icon);
203 void MainWin::setupActions() {
204 ActionCollection *coll = QtUi::actionCollection("General");
206 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
207 this, SLOT(showCoreConnectionDlg())));
208 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
209 Client::instance(), SLOT(disconnectFromCore())));
210 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
211 this, SLOT(showCoreInfoDlg())));
212 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
213 this, SLOT(on_actionConfigureNetworks_triggered())));
214 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
215 qApp, SLOT(quit()), tr("Ctrl+Q")));
218 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
219 this, SLOT(on_actionConfigureViews_triggered())));
220 QAction *lockAct = coll->addAction("LockDockPositions", new Action(tr("&Lock Dock Positions"), coll));
221 lockAct->setCheckable(true);
222 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockDockPositions_toggled(bool)));
224 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
225 0, 0, tr("Ctrl+F")))->setCheckable(true);
226 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
227 0, 0))->setCheckable(true);
230 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
231 this, SLOT(showSettingsDlg()), tr("F7")));
234 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
235 this, SLOT(showAboutDlg())));
236 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
237 qApp, SLOT(aboutQt())));
238 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
239 this, SLOT(on_actionDebugNetworkModel_triggered())));
240 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
241 this, SLOT(on_actionDebugMessageModel_triggered())));
242 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
243 this, SLOT(on_actionDebugLog_triggered())));
246 void MainWin::setupMenus() {
247 ActionCollection *coll = QtUi::actionCollection("General");
249 _fileMenu = menuBar()->addMenu(tr("&File"));
251 static const QStringList coreActions = QStringList()
252 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
255 foreach(QString actionName, coreActions) {
256 coreAction = coll->action(actionName);
257 _fileMenu->addAction(coreAction);
258 flagRemoteCoreOnly(coreAction);
260 flagRemoteCoreOnly(_fileMenu->addSeparator());
262 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
263 _networksMenu->addAction(coll->action("ConfigureNetworks"));
264 _networksMenu->addSeparator();
265 _fileMenu->addSeparator();
266 _fileMenu->addAction(coll->action("Quit"));
268 _viewMenu = menuBar()->addMenu(tr("&View"));
269 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
270 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
271 _viewMenu->addSeparator();
272 _viewMenu->addAction(coll->action("ToggleSearchBar"));
273 _viewMenu->addAction(coll->action("ToggleStatusBar"));
274 _viewMenu->addSeparator();
275 _viewMenu->addAction(coll->action("LockDockPositions"));
277 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
279 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
280 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
282 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
284 _helpMenu = menuBar()->addMenu(tr("&Help"));
285 _helpMenu->addAction(coll->action("AboutQuassel"));
287 _helpMenu->addAction(coll->action("AboutQt"));
289 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
291 _helpMenu->addSeparator();
292 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
293 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
294 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
295 _helpDebugMenu->addAction(coll->action("DebugLog"));
298 void MainWin::setupBufferWidget() {
299 _bufferWidget = new BufferWidget(this);
300 _bufferWidget->setModel(Client::bufferModel());
301 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
302 setCentralWidget(_bufferWidget);
305 void MainWin::addBufferView(int bufferViewConfigId) {
306 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
309 void MainWin::addBufferView(BufferViewConfig *config) {
313 BufferViewDock *dock = new BufferViewDock(config, this);
315 //create the view and initialize it's filter
316 BufferView *view = new BufferView(dock);
317 view->setFilteredModel(Client::bufferModel(), config);
318 view->installEventFilter(_inputWidget->inputLine()); // for key presses
321 Client::bufferModel()->synchronizeView(view);
323 dock->setWidget(view);
326 addDockWidget(Qt::LeftDockWidgetArea, dock);
327 _bufferViewsMenu->addAction(dock->toggleViewAction());
329 _bufferViews.append(dock);
332 void MainWin::removeBufferView(int bufferViewConfigId) {
334 BufferViewDock *dock;
335 foreach(QAction *action, _bufferViewsMenu->actions()) {
336 actionData = action->data();
337 if(!actionData.isValid())
340 dock = qobject_cast<BufferViewDock *>(action->parent());
341 if(dock && actionData.toInt() == bufferViewConfigId) {
342 removeAction(action);
348 BufferView *MainWin::allBuffersView() const {
349 // "All Buffers" is always the first dock created
350 if(_bufferViews.count() > 0)
351 return _bufferViews[0]->bufferView();
355 void MainWin::showNotificationsDlg() {
356 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
360 void MainWin::on_actionConfigureNetworks_triggered() {
361 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
365 void MainWin::on_actionConfigureViews_triggered() {
366 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
370 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
371 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
372 foreach(VerticalDock *dock, docks) {
373 dock->showTitle(!lock);
375 QtUiSettings().setValue("LockDocks", lock);
378 void MainWin::setupNickWidget() {
380 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
381 nickDock->setObjectName("NickDock");
382 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
384 _nickListWidget = new NickListWidget(nickDock);
385 nickDock->setWidget(_nickListWidget);
387 addDockWidget(Qt::RightDockWidgetArea, nickDock);
388 _viewMenu->addAction(nickDock->toggleViewAction());
389 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
390 nickDock->toggleViewAction()->setIcon(SmallIcon("view-sidetree"));
391 // See NickListDock::NickListDock();
392 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
394 // attach the NickListWidget to the BufferModel and the default selection
395 _nickListWidget->setModel(Client::bufferModel());
396 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
399 void MainWin::setupChatMonitor() {
400 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
401 dock->setObjectName("ChatMonitorDock");
403 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
404 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
406 dock->setWidget(chatView);
409 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
410 _viewMenu->addAction(dock->toggleViewAction());
411 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
414 void MainWin::setupInputWidget() {
415 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
416 dock->setObjectName("InputDock");
418 _inputWidget = new InputWidget(dock);
419 dock->setWidget(_inputWidget);
421 addDockWidget(Qt::BottomDockWidgetArea, dock);
423 _viewMenu->addAction(dock->toggleViewAction());
424 dock->toggleViewAction()->setText(tr("Show Input Line"));
426 _inputWidget->setModel(Client::bufferModel());
427 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
429 _bufferWidget->setFocusProxy(_inputWidget);
431 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
434 void MainWin::setupTopicWidget() {
435 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
436 dock->setObjectName("TopicDock");
437 TopicWidget *topicwidget = new TopicWidget(dock);
439 dock->setWidget(topicwidget);
441 topicwidget->setModel(Client::bufferModel());
442 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
444 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
446 _viewMenu->addAction(dock->toggleViewAction());
447 dock->toggleViewAction()->setText(tr("Show Topic Line"));
450 void MainWin::setupTitleSetter() {
451 _titleSetter.setModel(Client::bufferModel());
452 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
455 void MainWin::setupStatusBar() {
456 // MessageProcessor progress
457 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
458 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
461 updateLagIndicator();
462 statusBar()->addPermanentWidget(coreLagLabel);
463 coreLagLabel->hide();
464 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
467 sslLabel->setPixmap(QPixmap());
468 statusBar()->addPermanentWidget(sslLabel);
471 _viewMenu->addSeparator();
472 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
474 QtUiSettings uiSettings;
476 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
477 showStatusbar->setChecked(enabled);
478 enabled ? statusBar()->show() : statusBar()->hide();
480 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
481 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
483 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
484 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
487 void MainWin::saveStatusBarStatus(bool enabled) {
488 QtUiSettings uiSettings;
489 uiSettings.setValue("ShowStatusBar", enabled);
492 void MainWin::setupSystray() {
493 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
494 SLOT(messagesInserted(const QModelIndex &, int, int)));
496 ActionCollection *coll = QtUi::actionCollection("General");
497 systrayMenu = new QMenu(this);
498 systrayMenu->addAction(coll->action("ConnectCore"));
499 systrayMenu->addAction(coll->action("DisconnectCore"));
500 systrayMenu->addAction(coll->action("CoreInfo"));
501 systrayMenu->addSeparator();
502 systrayMenu->addAction(coll->action("Quit"));
504 systemTrayIcon()->setContextMenu(systrayMenu);
507 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
508 systemTrayIcon()->show();
512 connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
513 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
518 void MainWin::changeEvent(QEvent *event) {
519 if(event->type() == QEvent::WindowStateChange) {
520 if(windowState() & Qt::WindowMinimized) {
522 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
530 void MainWin::connectedToCore() {
531 Q_CHECK_PTR(Client::bufferViewManager());
532 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
533 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
534 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
539 void MainWin::setConnectedState() {
540 ActionCollection *coll = QtUi::actionCollection("General");
542 coll->action("ConnectCore")->setEnabled(false);
543 coll->action("DisconnectCore")->setEnabled(true);
544 coll->action("CoreInfo")->setEnabled(true);
546 foreach(QAction *action, _fileMenu->actions()) {
547 if(isRemoteCoreOnly(action))
548 action->setVisible(!Client::internalCore());
551 // _viewMenu->setEnabled(true);
552 if(!Client::internalCore())
553 statusBar()->showMessage(tr("Connected to core."));
555 if(Client::signalProxy()->isSecure()) {
556 sslLabel->setPixmap(SmallIcon("security-high"));
558 sslLabel->setPixmap(SmallIcon("security-low"));
561 sslLabel->setVisible(!Client::internalCore());
562 coreLagLabel->setVisible(!Client::internalCore());
566 void MainWin::loadLayout() {
568 int accountId = Client::currentCoreAccount().toInt();
569 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
572 void MainWin::saveLayout() {
574 int accountId = Client::currentCoreAccount().toInt();
575 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
578 void MainWin::updateLagIndicator(int lag) {
579 QString text = tr("Core Lag: %1");
581 text = text.arg('-');
583 text = text.arg("%1 msec").arg(lag);
584 coreLagLabel->setText(text);
587 void MainWin::disconnectedFromCore() {
588 // save core specific layout and remove bufferviews;
591 BufferViewDock *dock;
592 foreach(QAction *action, _bufferViewsMenu->actions()) {
593 actionData = action->data();
594 if(!actionData.isValid())
597 dock = qobject_cast<BufferViewDock *>(action->parent());
598 if(dock && actionData.toInt() != -1) {
599 removeAction(action);
604 restoreState(s.value("MainWinState").toByteArray());
605 setDisconnectedState();
608 void MainWin::setDisconnectedState() {
609 ActionCollection *coll = QtUi::actionCollection("General");
610 //ui.menuCore->setEnabled(false);
611 coll->action("ConnectCore")->setEnabled(true);
612 coll->action("DisconnectCore")->setEnabled(false);
613 coll->action("CoreInfo")->setEnabled(false);
614 //_viewMenu->setEnabled(false);
615 statusBar()->showMessage(tr("Not connected to core."));
616 sslLabel->setPixmap(QPixmap());
618 updateLagIndicator();
619 coreLagLabel->hide();
623 void MainWin::startInternalCore() {
624 ClientSyncer *syncer = new ClientSyncer();
625 Client::registerClientSyncer(syncer);
626 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
627 syncer->useInternalCore();
630 void MainWin::showCoreConnectionDlg(bool autoConnect) {
631 CoreConnectDlg(autoConnect, this).exec();
634 void MainWin::showChannelList(NetworkId netId) {
635 ChannelListDlg *channelListDlg = new ChannelListDlg();
637 if(!netId.isValid()) {
638 QAction *action = qobject_cast<QAction *>(sender());
640 netId = action->data().value<NetworkId>();
643 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
644 channelListDlg->setNetwork(netId);
645 channelListDlg->show();
648 void MainWin::showCoreInfoDlg() {
649 CoreInfoDlg(this).exec();
652 void MainWin::showSettingsDlg() {
653 SettingsDlg *dlg = new SettingsDlg();
655 //Category: Appearance
656 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
657 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
658 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
659 //Category: Behaviour
660 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
661 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
662 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
663 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
664 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
665 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
667 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
668 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
669 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
674 void MainWin::showAboutDlg() {
675 AboutDlg(this).exec();
679 void MainWin::showShortcutsDlg() {
680 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
684 void MainWin::closeEvent(QCloseEvent *event) {
686 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
688 if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
693 QApplication::quit();
697 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
698 if(activationReason == QSystemTrayIcon::Trigger) {
703 void MainWin::toggleVisibility() {
704 if(isHidden() /*|| !isActiveWindow()*/) {
715 // setFocus(); //Qt::ActiveWindowFocusReason
718 if(systemTrayIcon()->isSystemTrayAvailable ()) {
721 if(!systemTrayIcon()->isVisible()) {
722 systemTrayIcon()->show();
730 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
733 if(QApplication::activeWindow() != 0)
736 for(int i = start; i <= end; i++) {
737 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
739 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
742 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
743 if(flags.testFlag(Message::Backlog)) continue;
744 flags |= Message::Backlog; // we only want to trigger a highlight once!
745 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
747 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
748 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
750 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
751 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
752 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
753 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
754 QtUi::invokeNotification(bufId, sender, contents);
759 bool MainWin::event(QEvent *event) {
760 if(event->type() == QEvent::WindowActivate)
761 QtUi::closeNotifications();
762 return QMainWindow::event(event);
765 void MainWin::clientNetworkCreated(NetworkId id) {
766 const Network *net = Client::network(id);
767 QAction *act = new QAction(net->networkName(), this);
768 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
769 act->setData(QVariant::fromValue<NetworkId>(id));
770 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
771 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
773 QAction *beforeAction = 0;
774 foreach(QAction *action, _networksMenu->actions()) {
775 if(!action->data().isValid()) // ignore stock actions
777 if(net->networkName().localeAwareCompare(action->text()) < 0) {
778 beforeAction = action;
782 _networksMenu->insertAction(beforeAction, act);
785 void MainWin::clientNetworkUpdated() {
786 const Network *net = qobject_cast<const Network *>(sender());
790 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
794 action->setText(net->networkName());
796 switch(net->connectionState()) {
797 case Network::Initialized:
798 action->setIcon(SmallIcon("network-connect"));
800 case Network::Disconnected:
801 action->setIcon(SmallIcon("network-disconnect"));
804 action->setIcon(SmallIcon("network-wired"));
808 void MainWin::clientNetworkRemoved(NetworkId id) {
809 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
813 action->deleteLater();
816 void MainWin::connectOrDisconnectFromNet() {
817 QAction *act = qobject_cast<QAction *>(sender());
819 const Network *net = Client::network(act->data().value<NetworkId>());
821 if(net->connectionState() == Network::Disconnected) net->requestConnect();
822 else net->requestDisconnect();
825 void MainWin::on_actionDebugNetworkModel_triggered() {
826 QTreeView *view = new QTreeView;
827 view->setAttribute(Qt::WA_DeleteOnClose);
828 view->setWindowTitle("Debug NetworkModel View");
829 view->setModel(Client::networkModel());
830 view->setColumnWidth(0, 250);
831 view->setColumnWidth(1, 250);
832 view->setColumnWidth(2, 80);
833 view->resize(610, 300);
837 void MainWin::on_actionDebugMessageModel_triggered() {
838 QTableView *view = new QTableView(0);
839 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
840 filter->setSourceModel(Client::messageModel());
841 view->setModel(filter);
842 view->setAttribute(Qt::WA_DeleteOnClose, true);
843 view->verticalHeader()->hide();
844 view->horizontalHeader()->setStretchLastSection(true);
848 void MainWin::on_actionDebugLog_triggered() {
849 DebugLogWidget *logWidget = new DebugLogWidget(0);
853 void MainWin::saveStateToSession(const QString &sessionId) {
855 SessionSettings s(sessionId);
857 s.setValue("MainWinSize", size());
858 s.setValue("MainWinPos", pos());
859 s.setValue("MainWinState", saveState());
862 void MainWin::saveStateToSessionSettings(SessionSettings & s)
864 s.setValue("MainWinSize", size());
865 s.setValue("MainWinPos", pos());
866 s.setValue("MainWinState", saveState());
869 void MainWin::showStatusBarMessage(const QString &message) {
870 statusBar()->showMessage(message, 10000);