1 /***************************************************************************
2 * Copyright (C) 2005-08 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));
120 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
121 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
123 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
126 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
130 QtUi::registerNotificationBackend(new KNotificationBackend(this));
131 #endif /* HAVE_KDE */
133 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
134 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
135 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
138 void MainWin::init() {
140 if(s.value("MainWinSize").isValid())
141 resize(s.value("MainWinSize").toSize());
143 resize(QSize(800, 500));
145 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
146 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
147 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
148 connect(Client::mainUi()->actionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
151 setDockNestingEnabled(true);
152 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
153 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
154 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
155 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
157 // Order is sometimes important
170 // restore mainwin state
171 restoreState(s.value("MainWinState").toByteArray());
173 // restore locked state of docks
174 QtUi::actionCollection("General")->action("LockDockPositions")->setChecked(s.value("LockDocks", false).toBool());
176 setDisconnectedState(); // Disable menus and stuff
179 if(Quassel::runMode() != Quassel::Monolithic) {
180 showCoreConnectionDlg(true); // autoconnect if appropriate
186 MainWin::~MainWin() {
188 s.setValue("MainWinSize", size());
189 s.setValue("MainWinPos", pos());
190 s.setValue("MainWinState", saveState());
193 void MainWin::updateIcon() {
195 if(Client::isConnected())
196 icon = DesktopIcon("quassel", IconLoader::SizeEnormous);
198 icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous);
200 qApp->setWindowIcon(icon);
201 systemTrayIcon()->setIcon(icon);
204 void MainWin::setupActions() {
205 ActionCollection *coll = QtUi::actionCollection("General");
207 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
208 this, SLOT(showCoreConnectionDlg())));
209 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
210 Client::instance(), SLOT(disconnectFromCore())));
211 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
212 this, SLOT(showCoreInfoDlg())));
213 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
214 this, SLOT(on_actionConfigureNetworks_triggered())));
215 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
216 qApp, SLOT(quit()), tr("Ctrl+Q")));
219 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
220 this, SLOT(on_actionConfigureViews_triggered())));
221 QAction *lockAct = coll->addAction("LockDockPositions", new Action(tr("&Lock Dock Positions"), coll));
222 lockAct->setCheckable(true);
223 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockDockPositions_toggled(bool)));
225 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
226 0, 0, tr("Ctrl+F")))->setCheckable(true);
227 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
228 0, 0))->setCheckable(true);
231 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
232 this, SLOT(showSettingsDlg()), tr("F7")));
235 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
236 this, SLOT(showAboutDlg())));
237 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
238 qApp, SLOT(aboutQt())));
239 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
240 this, SLOT(on_actionDebugNetworkModel_triggered())));
241 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
242 this, SLOT(on_actionDebugMessageModel_triggered())));
243 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
244 this, SLOT(on_actionDebugLog_triggered())));
247 void MainWin::setupMenus() {
248 ActionCollection *coll = QtUi::actionCollection("General");
250 _fileMenu = menuBar()->addMenu(tr("&File"));
252 static const QStringList coreActions = QStringList()
253 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
256 foreach(QString actionName, coreActions) {
257 coreAction = coll->action(actionName);
258 _fileMenu->addAction(coreAction);
259 flagRemoteCoreOnly(coreAction);
261 flagRemoteCoreOnly(_fileMenu->addSeparator());
263 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
264 _networksMenu->addAction(coll->action("ConfigureNetworks"));
265 _networksMenu->addSeparator();
266 _fileMenu->addSeparator();
267 _fileMenu->addAction(coll->action("Quit"));
269 _viewMenu = menuBar()->addMenu(tr("&View"));
270 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
271 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
272 _viewMenu->addSeparator();
273 _viewMenu->addAction(coll->action("ToggleSearchBar"));
274 _viewMenu->addAction(coll->action("ToggleStatusBar"));
275 _viewMenu->addSeparator();
276 _viewMenu->addAction(coll->action("LockDockPositions"));
278 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
280 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
281 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
283 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
285 _helpMenu = menuBar()->addMenu(tr("&Help"));
286 _helpMenu->addAction(coll->action("AboutQuassel"));
288 _helpMenu->addAction(coll->action("AboutQt"));
290 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
292 _helpMenu->addSeparator();
293 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
294 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
295 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
296 _helpDebugMenu->addAction(coll->action("DebugLog"));
299 void MainWin::setupBufferWidget() {
300 _bufferWidget = new BufferWidget(this);
301 _bufferWidget->setModel(Client::bufferModel());
302 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
303 setCentralWidget(_bufferWidget);
306 void MainWin::setupViews() {
310 void MainWin::addBufferView(int bufferViewConfigId) {
311 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
314 void MainWin::addBufferView(BufferViewConfig *config) {
315 BufferViewDock *dock;
317 dock = new BufferViewDock(config, this);
319 dock = new BufferViewDock(this);
321 //create the view and initialize it's filter
322 BufferView *view = new BufferView(dock);
323 view->setFilteredModel(Client::bufferModel(), config);
326 Client::bufferModel()->synchronizeView(view);
328 dock->setWidget(view);
331 addDockWidget(Qt::LeftDockWidgetArea, dock);
332 _bufferViewsMenu->addAction(dock->toggleViewAction());
334 _bufferViews.append(dock);
337 void MainWin::removeBufferView(int bufferViewConfigId) {
339 BufferViewDock *dock;
340 foreach(QAction *action, _bufferViewsMenu->actions()) {
341 actionData = action->data();
342 if(!actionData.isValid())
345 dock = qobject_cast<BufferViewDock *>(action->parent());
346 if(dock && actionData.toInt() == bufferViewConfigId) {
347 removeAction(action);
353 BufferView *MainWin::allBuffersView() const {
354 // "All Buffers" is always the first dock created
355 if(_bufferViews.count() > 0)
356 return _bufferViews[0]->bufferView();
360 void MainWin::showNotificationsDlg() {
361 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
365 void MainWin::on_actionConfigureNetworks_triggered() {
366 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
370 void MainWin::on_actionConfigureViews_triggered() {
371 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
375 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
376 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
377 foreach(VerticalDock *dock, docks) {
378 dock->showTitle(!lock);
380 QtUiSettings().setValue("LockDocks", lock);
383 void MainWin::setupNickWidget() {
385 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
386 nickDock->setObjectName("NickDock");
387 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
389 _nickListWidget = new NickListWidget(nickDock);
390 nickDock->setWidget(_nickListWidget);
392 addDockWidget(Qt::RightDockWidgetArea, nickDock);
393 _viewMenu->addAction(nickDock->toggleViewAction());
394 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
395 nickDock->toggleViewAction()->setIcon(SmallIcon("view-sidetree"));
396 // See NickListDock::NickListDock();
397 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
399 // attach the NickListWidget to the BufferModel and the default selection
400 _nickListWidget->setModel(Client::bufferModel());
401 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
404 void MainWin::setupChatMonitor() {
405 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
406 dock->setObjectName("ChatMonitorDock");
408 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
409 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
411 dock->setWidget(chatView);
414 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
415 _viewMenu->addAction(dock->toggleViewAction());
416 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
419 void MainWin::setupInputWidget() {
420 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
421 dock->setObjectName("InputDock");
423 InputWidget *inputWidget = new InputWidget(dock);
424 dock->setWidget(inputWidget);
426 addDockWidget(Qt::BottomDockWidgetArea, dock);
428 _viewMenu->addAction(dock->toggleViewAction());
429 dock->toggleViewAction()->setText(tr("Show Input Line"));
431 inputWidget->setModel(Client::bufferModel());
432 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
434 _bufferWidget->setFocusProxy(inputWidget);
436 inputWidget->inputLine()->installEventFilter(_bufferWidget);
439 void MainWin::setupTopicWidget() {
440 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
441 dock->setObjectName("TopicDock");
442 TopicWidget *topicwidget = new TopicWidget(dock);
444 dock->setWidget(topicwidget);
446 topicwidget->setModel(Client::bufferModel());
447 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
449 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
451 _viewMenu->addAction(dock->toggleViewAction());
452 dock->toggleViewAction()->setText(tr("Show Topic Line"));
455 void MainWin::setupTitleSetter() {
456 _titleSetter.setModel(Client::bufferModel());
457 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
460 void MainWin::setupStatusBar() {
461 // MessageProcessor progress
462 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
463 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
466 updateLagIndicator(0);
467 statusBar()->addPermanentWidget(coreLagLabel);
468 coreLagLabel->hide();
469 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
472 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
473 sslLabel->setPixmap(QPixmap());
474 statusBar()->addPermanentWidget(sslLabel);
477 _viewMenu->addSeparator();
478 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
480 QtUiSettings uiSettings;
482 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
483 showStatusbar->setChecked(enabled);
484 enabled ? statusBar()->show() : statusBar()->hide();
486 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
487 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
489 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
490 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
493 void MainWin::saveStatusBarStatus(bool enabled) {
494 QtUiSettings uiSettings;
495 uiSettings.setValue("ShowStatusBar", enabled);
498 void MainWin::setupSystray() {
499 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
500 SLOT(messagesInserted(const QModelIndex &, int, int)));
502 ActionCollection *coll = QtUi::actionCollection("General");
503 systrayMenu = new QMenu(this);
504 systrayMenu->addAction(coll->action("ConnectCore"));
505 systrayMenu->addAction(coll->action("DisconnectCore"));
506 systrayMenu->addAction(coll->action("CoreInfo"));
507 systrayMenu->addSeparator();
508 systrayMenu->addAction(coll->action("Quit"));
510 systemTrayIcon()->setContextMenu(systrayMenu);
513 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
514 systemTrayIcon()->show();
518 connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
519 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
524 void MainWin::changeEvent(QEvent *event) {
525 if(event->type() == QEvent::WindowStateChange) {
526 if(windowState() & Qt::WindowMinimized) {
528 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
536 void MainWin::connectedToCore() {
537 Q_CHECK_PTR(Client::bufferViewManager());
538 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
539 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
540 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
545 void MainWin::setConnectedState() {
546 ActionCollection *coll = QtUi::actionCollection("General");
548 coll->action("ConnectCore")->setEnabled(false);
549 coll->action("DisconnectCore")->setEnabled(true);
550 coll->action("CoreInfo")->setEnabled(true);
552 foreach(QAction *action, _fileMenu->actions()) {
553 if(isRemoteCoreOnly(action))
554 action->setVisible(!Client::internalCore());
557 // _viewMenu->setEnabled(true);
558 if(!Client::internalCore())
559 statusBar()->showMessage(tr("Connected to core."));
561 if(sslLabel->width() == 0)
562 sslLabel->setPixmap(SmallIcon("security-low"));
564 sslLabel->setVisible(!Client::internalCore());
565 coreLagLabel->setVisible(!Client::internalCore());
569 void MainWin::loadLayout() {
571 int accountId = Client::currentCoreAccount().toInt();
572 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
575 void MainWin::saveLayout() {
577 int accountId = Client::currentCoreAccount().toInt();
578 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
581 void MainWin::updateLagIndicator(int lag) {
582 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
586 void MainWin::securedConnection() {
587 // todo: make status bar entry
588 sslLabel->setPixmap(SmallIcon("security-high"));
591 void MainWin::disconnectedFromCore() {
592 // save core specific layout and remove bufferviews;
595 BufferViewDock *dock;
596 foreach(QAction *action, _bufferViewsMenu->actions()) {
597 actionData = action->data();
598 if(!actionData.isValid())
601 dock = qobject_cast<BufferViewDock *>(action->parent());
602 if(dock && actionData.toInt() != -1) {
603 removeAction(action);
608 restoreState(s.value("MainWinState").toByteArray());
609 setDisconnectedState();
612 void MainWin::setDisconnectedState() {
613 ActionCollection *coll = QtUi::actionCollection("General");
614 //ui.menuCore->setEnabled(false);
615 coll->action("ConnectCore")->setEnabled(true);
616 coll->action("DisconnectCore")->setEnabled(false);
617 coll->action("CoreInfo")->setEnabled(false);
618 //_viewMenu->setEnabled(false);
619 statusBar()->showMessage(tr("Not connected to core."));
620 sslLabel->setPixmap(QPixmap());
622 coreLagLabel->hide();
626 void MainWin::startInternalCore() {
627 ClientSyncer *syncer = new ClientSyncer();
628 Client::registerClientSyncer(syncer);
629 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
630 syncer->useInternalCore();
633 void MainWin::showCoreConnectionDlg(bool autoConnect) {
634 CoreConnectDlg(autoConnect, this).exec();
637 void MainWin::showChannelList(NetworkId netId) {
638 ChannelListDlg *channelListDlg = new ChannelListDlg();
640 if(!netId.isValid()) {
641 QAction *action = qobject_cast<QAction *>(sender());
643 netId = action->data().value<NetworkId>();
646 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
647 channelListDlg->setNetwork(netId);
648 channelListDlg->show();
651 void MainWin::showCoreInfoDlg() {
652 CoreInfoDlg(this).exec();
655 void MainWin::showSettingsDlg() {
656 SettingsDlg *dlg = new SettingsDlg();
658 //Category: Appearance
659 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
660 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
661 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
662 //Category: Behaviour
663 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
664 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
665 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
666 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
667 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
668 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
670 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
671 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
672 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
677 void MainWin::showAboutDlg() {
678 AboutDlg(this).exec();
682 void MainWin::showShortcutsDlg() {
683 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
687 void MainWin::closeEvent(QCloseEvent *event) {
689 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
694 QApplication::quit();
698 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
699 if(activationReason == QSystemTrayIcon::Trigger) {
704 void MainWin::toggleVisibility() {
705 if(isHidden() /*|| !isActiveWindow()*/) {
716 // setFocus(); //Qt::ActiveWindowFocusReason
719 if(systemTrayIcon()->isSystemTrayAvailable ()) {
722 if(!systemTrayIcon()->isVisible()) {
723 systemTrayIcon()->show();
731 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
734 if(QApplication::activeWindow() != 0)
737 for(int i = start; i <= end; i++) {
738 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
740 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
743 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
744 if(flags.testFlag(Message::Backlog)) continue;
745 flags |= Message::Backlog; // we only want to trigger a highlight once!
746 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
748 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
749 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
751 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
752 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
753 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
754 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
755 QtUi::invokeNotification(bufId, sender, contents);
760 bool MainWin::event(QEvent *event) {
761 if(event->type() == QEvent::WindowActivate)
762 QtUi::closeNotifications();
763 return QMainWindow::event(event);
766 void MainWin::clientNetworkCreated(NetworkId id) {
767 const Network *net = Client::network(id);
768 QAction *act = new QAction(net->networkName(), this);
769 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
770 act->setData(QVariant::fromValue<NetworkId>(id));
771 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
772 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
774 QAction *beforeAction = 0;
775 foreach(QAction *action, _networksMenu->actions()) {
776 if(!action->data().isValid()) // ignore stock actions
778 if(net->networkName().localeAwareCompare(action->text()) < 0) {
779 beforeAction = action;
783 _networksMenu->insertAction(beforeAction, act);
786 void MainWin::clientNetworkUpdated() {
787 const Network *net = qobject_cast<const Network *>(sender());
791 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
795 action->setText(net->networkName());
797 switch(net->connectionState()) {
798 case Network::Initialized:
799 action->setIcon(SmallIcon("network-connect"));
801 case Network::Disconnected:
802 action->setIcon(SmallIcon("network-disconnect"));
805 action->setIcon(SmallIcon("network-wired"));
809 void MainWin::clientNetworkRemoved(NetworkId id) {
810 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
814 action->deleteLater();
817 void MainWin::connectOrDisconnectFromNet() {
818 QAction *act = qobject_cast<QAction *>(sender());
820 const Network *net = Client::network(act->data().value<NetworkId>());
822 if(net->connectionState() == Network::Disconnected) net->requestConnect();
823 else net->requestDisconnect();
826 void MainWin::on_actionDebugNetworkModel_triggered() {
827 QTreeView *view = new QTreeView;
828 view->setAttribute(Qt::WA_DeleteOnClose);
829 view->setWindowTitle("Debug NetworkModel View");
830 view->setModel(Client::networkModel());
831 view->setColumnWidth(0, 250);
832 view->setColumnWidth(1, 250);
833 view->setColumnWidth(2, 80);
834 view->resize(610, 300);
838 void MainWin::on_actionDebugMessageModel_triggered() {
839 QTableView *view = new QTableView(0);
840 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
841 filter->setSourceModel(Client::messageModel());
842 view->setModel(filter);
843 view->setAttribute(Qt::WA_DeleteOnClose, true);
844 view->verticalHeader()->hide();
845 view->horizontalHeader()->setStretchLastSection(true);
849 void MainWin::on_actionDebugLog_triggered() {
850 DebugLogWidget *logWidget = new DebugLogWidget(0);
854 void MainWin::saveStateToSession(const QString &sessionId) {
856 SessionSettings s(sessionId);
858 s.setValue("MainWinSize", size());
859 s.setValue("MainWinPos", pos());
860 s.setValue("MainWinState", saveState());
863 void MainWin::saveStateToSessionSettings(SessionSettings & s)
865 s.setValue("MainWinSize", size());
866 s.setValue("MainWinPos", pos());
867 s.setValue("MainWinState", saveState());
870 void MainWin::showStatusBarMessage(const QString &message) {
871 statusBar()->showMessage(message, 10000);