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 "clientbacklogmanager.h"
45 #include "coreinfodlg.h"
46 #include "coreconnectdlg.h"
47 #include "debuglogwidget.h"
48 #include "debugmessagemodelfilter.h"
49 #include "iconloader.h"
50 #include "inputwidget.h"
51 #include "inputline.h"
52 #include "irclistmodel.h"
53 #include "jumpkeyhandler.h"
54 #include "msgprocessorstatuswidget.h"
55 #include "nicklistwidget.h"
56 #include "qtuiapplication.h"
57 #include "qtuimessageprocessor.h"
58 #include "qtuisettings.h"
59 #include "sessionsettings.h"
60 #include "settingsdlg.h"
61 #include "settingspagedlg.h"
62 #include "topicwidget.h"
63 #include "verticaldock.h"
67 # include "desktopnotificationbackend.h"
70 # include "phononnotificationbackend.h"
72 # include "systraynotificationbackend.h"
73 # include "taskbarnotificationbackend.h"
75 # include "knotificationbackend.h"
78 #include "settingspages/aliasessettingspage.h"
79 #include "settingspages/appearancesettingspage.h"
80 #include "settingspages/backlogsettingspage.h"
81 #include "settingspages/bufferviewsettingspage.h"
82 #include "settingspages/chatmonitorsettingspage.h"
83 #include "settingspages/colorsettingspage.h"
84 #include "settingspages/fontssettingspage.h"
85 #include "settingspages/generalsettingspage.h"
86 #include "settingspages/highlightsettingspage.h"
87 #include "settingspages/identitiessettingspage.h"
88 #include "settingspages/networkssettingspage.h"
89 #include "settingspages/notificationssettingspage.h"
91 MainWin::MainWin(QWidget *parent)
93 : KMainWindow(parent),
94 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
96 : QMainWindow(parent),
98 coreLagLabel(new QLabel()),
99 sslLabel(new QLabel()),
100 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
102 _trayIcon(new QSystemTrayIcon(this))
104 QtUiSettings uiSettings;
105 QString style = uiSettings.value("Style", QString()).toString();
106 if(!style.isEmpty()) {
107 QApplication::setStyle(style);
110 QApplication::setQuitOnLastWindowClosed(false);
112 setWindowTitle("Quassel IRC");
113 setWindowIconText("Quassel IRC");
116 installEventFilter(new JumpKeyHandler(this));
119 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
120 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
122 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
125 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
129 QtUi::registerNotificationBackend(new KNotificationBackend(this));
130 #endif /* HAVE_KDE */
132 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
133 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
134 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
137 void MainWin::init() {
139 if(s.value("MainWinSize").isValid())
140 resize(s.value("MainWinSize").toSize());
142 resize(QSize(800, 500));
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::mainUi()->actionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
150 setDockNestingEnabled(true);
151 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
152 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
153 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
154 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
156 // Order is sometimes important
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 showCoreConnectionDlg(true); // autoconnect if appropriate
181 MainWin::~MainWin() {
183 s.setValue("MainWinSize", size());
184 s.setValue("MainWinPos", pos());
185 s.setValue("MainWinState", saveState());
188 void MainWin::updateIcon() {
190 if(Client::isConnected())
191 icon = DesktopIcon("quassel", IconLoader::SizeEnormous);
193 icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous);
195 qApp->setWindowIcon(icon);
196 systemTrayIcon()->setIcon(icon);
199 void MainWin::setupActions() {
200 ActionCollection *coll = QtUi::actionCollection("General");
202 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
203 this, SLOT(showCoreConnectionDlg())));
204 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
205 Client::instance(), SLOT(disconnectFromCore())));
206 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
207 this, SLOT(showCoreInfoDlg())));
208 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
209 this, SLOT(on_actionConfigureNetworks_triggered())));
210 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
211 qApp, SLOT(quit()), tr("Ctrl+Q")));
214 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
215 this, SLOT(on_actionConfigureViews_triggered())));
216 QAction *lockAct = coll->addAction("LockDockPositions", new Action(tr("&Lock Dock Positions"), coll));
217 lockAct->setCheckable(true);
218 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockDockPositions_toggled(bool)));
220 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
221 0, 0, tr("Ctrl+F")))->setCheckable(true);
222 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
223 0, 0))->setCheckable(true);
226 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
227 this, SLOT(showSettingsDlg()), tr("F7")));
230 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
231 this, SLOT(showAboutDlg())));
232 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
233 qApp, SLOT(aboutQt())));
234 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
235 this, SLOT(on_actionDebugNetworkModel_triggered())));
236 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
237 this, SLOT(on_actionDebugMessageModel_triggered())));
238 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
239 this, SLOT(on_actionDebugLog_triggered())));
242 void MainWin::setupMenus() {
243 ActionCollection *coll = QtUi::actionCollection("General");
245 _fileMenu = menuBar()->addMenu(tr("&File"));
247 static const QStringList coreActions = QStringList()
248 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
251 foreach(QString actionName, coreActions) {
252 coreAction = coll->action(actionName);
253 _fileMenu->addAction(coreAction);
254 flagRemoteCoreOnly(coreAction);
256 flagRemoteCoreOnly(_fileMenu->addSeparator());
258 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
259 _networksMenu->addAction(coll->action("ConfigureNetworks"));
260 _networksMenu->addSeparator();
261 _fileMenu->addSeparator();
262 _fileMenu->addAction(coll->action("Quit"));
264 _viewMenu = menuBar()->addMenu(tr("&View"));
265 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
266 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
267 _viewMenu->addSeparator();
268 _viewMenu->addAction(coll->action("ToggleSearchBar"));
269 _viewMenu->addAction(coll->action("ToggleStatusBar"));
270 _viewMenu->addSeparator();
271 _viewMenu->addAction(coll->action("LockDockPositions"));
273 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
275 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
276 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
278 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
280 _helpMenu = menuBar()->addMenu(tr("&Help"));
281 _helpMenu->addAction(coll->action("AboutQuassel"));
283 _helpMenu->addAction(coll->action("AboutQt"));
285 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
287 _helpMenu->addSeparator();
288 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
289 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
290 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
291 _helpDebugMenu->addAction(coll->action("DebugLog"));
294 void MainWin::setupBufferWidget() {
295 _bufferWidget = new BufferWidget(this);
296 _bufferWidget->setModel(Client::bufferModel());
297 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
298 setCentralWidget(_bufferWidget);
301 void MainWin::setupViews() {
305 void MainWin::addBufferView(int bufferViewConfigId) {
306 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
309 void MainWin::addBufferView(BufferViewConfig *config) {
310 BufferViewDock *dock;
312 dock = new BufferViewDock(config, this);
314 dock = new BufferViewDock(this);
316 //create the view and initialize it's filter
317 BufferView *view = new BufferView(dock);
318 view->setFilteredModel(Client::bufferModel(), config);
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 *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(0);
462 statusBar()->addPermanentWidget(coreLagLabel);
463 coreLagLabel->hide();
464 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
467 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
468 sslLabel->setPixmap(QPixmap());
469 statusBar()->addPermanentWidget(sslLabel);
472 _viewMenu->addSeparator();
473 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
475 QtUiSettings uiSettings;
477 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
478 showStatusbar->setChecked(enabled);
479 enabled ? statusBar()->show() : statusBar()->hide();
481 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
482 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
484 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
485 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
488 void MainWin::saveStatusBarStatus(bool enabled) {
489 QtUiSettings uiSettings;
490 uiSettings.setValue("ShowStatusBar", enabled);
493 void MainWin::setupSystray() {
494 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
495 SLOT(messagesInserted(const QModelIndex &, int, int)));
497 ActionCollection *coll = QtUi::actionCollection("General");
498 systrayMenu = new QMenu(this);
499 systrayMenu->addAction(coll->action("ConnectCore"));
500 systrayMenu->addAction(coll->action("DisconnectCore"));
501 systrayMenu->addAction(coll->action("CoreInfo"));
502 systrayMenu->addSeparator();
503 systrayMenu->addAction(coll->action("Quit"));
505 systemTrayIcon()->setContextMenu(systrayMenu);
508 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
509 systemTrayIcon()->show();
513 connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
514 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
519 void MainWin::changeEvent(QEvent *event) {
520 if(event->type() == QEvent::WindowStateChange) {
521 if(windowState() & Qt::WindowMinimized) {
523 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
531 void MainWin::connectedToCore() {
532 Q_CHECK_PTR(Client::bufferViewManager());
533 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
534 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
535 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
540 void MainWin::setConnectedState() {
541 ActionCollection *coll = QtUi::actionCollection("General");
543 coll->action("ConnectCore")->setEnabled(false);
544 coll->action("DisconnectCore")->setEnabled(true);
545 coll->action("CoreInfo")->setEnabled(true);
547 foreach(QAction *action, _fileMenu->actions()) {
548 if(isRemoteCoreOnly(action))
549 action->setVisible(!Client::internalCore());
552 // _viewMenu->setEnabled(true);
553 if(!Client::internalCore())
554 statusBar()->showMessage(tr("Connected to core."));
556 if(sslLabel->width() == 0)
557 sslLabel->setPixmap(SmallIcon("security-low"));
559 sslLabel->setVisible(!Client::internalCore());
560 coreLagLabel->setVisible(!Client::internalCore());
564 void MainWin::loadLayout() {
566 int accountId = Client::currentCoreAccount().toInt();
567 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
570 void MainWin::saveLayout() {
572 int accountId = Client::currentCoreAccount().toInt();
573 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
576 void MainWin::updateLagIndicator(int lag) {
577 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
581 void MainWin::securedConnection() {
582 // todo: make status bar entry
583 sslLabel->setPixmap(SmallIcon("security-high"));
586 void MainWin::disconnectedFromCore() {
587 // save core specific layout and remove bufferviews;
590 BufferViewDock *dock;
591 foreach(QAction *action, _bufferViewsMenu->actions()) {
592 actionData = action->data();
593 if(!actionData.isValid())
596 dock = qobject_cast<BufferViewDock *>(action->parent());
597 if(dock && actionData.toInt() != -1) {
598 removeAction(action);
603 restoreState(s.value("MainWinState").toByteArray());
604 setDisconnectedState();
607 void MainWin::setDisconnectedState() {
608 ActionCollection *coll = QtUi::actionCollection("General");
609 //ui.menuCore->setEnabled(false);
610 coll->action("ConnectCore")->setEnabled(true);
611 coll->action("DisconnectCore")->setEnabled(false);
612 coll->action("CoreInfo")->setEnabled(false);
613 //_viewMenu->setEnabled(false);
614 statusBar()->showMessage(tr("Not connected to core."));
615 sslLabel->setPixmap(QPixmap());
617 coreLagLabel->hide();
621 void MainWin::showCoreConnectionDlg(bool autoConnect) {
622 CoreConnectDlg(autoConnect, this).exec();
625 void MainWin::showChannelList(NetworkId netId) {
626 ChannelListDlg *channelListDlg = new ChannelListDlg();
628 if(!netId.isValid()) {
629 QAction *action = qobject_cast<QAction *>(sender());
631 netId = action->data().value<NetworkId>();
634 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
635 channelListDlg->setNetwork(netId);
636 channelListDlg->show();
639 void MainWin::showCoreInfoDlg() {
640 CoreInfoDlg(this).exec();
643 void MainWin::showSettingsDlg() {
644 SettingsDlg *dlg = new SettingsDlg();
646 //Category: Appearance
647 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
648 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
649 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
650 //Category: Behaviour
651 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
652 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
653 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
654 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
655 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
656 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
658 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
659 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
660 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
665 void MainWin::showAboutDlg() {
666 AboutDlg(this).exec();
670 void MainWin::showShortcutsDlg() {
671 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
675 void MainWin::closeEvent(QCloseEvent *event) {
677 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
682 QApplication::quit();
686 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
687 if(activationReason == QSystemTrayIcon::Trigger) {
692 void MainWin::toggleVisibility() {
693 if(isHidden() /*|| !isActiveWindow()*/) {
704 // setFocus(); //Qt::ActiveWindowFocusReason
707 if(systemTrayIcon()->isSystemTrayAvailable ()) {
710 if(!systemTrayIcon()->isVisible()) {
711 systemTrayIcon()->show();
719 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
722 if(QApplication::activeWindow() != 0)
725 for(int i = start; i <= end; i++) {
726 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
728 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
731 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
732 if(flags.testFlag(Message::Backlog)) continue;
733 flags |= Message::Backlog; // we only want to trigger a highlight once!
734 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
736 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
737 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
739 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
740 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
741 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
742 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
743 QtUi::invokeNotification(bufId, sender, contents);
748 bool MainWin::event(QEvent *event) {
749 if(event->type() == QEvent::WindowActivate)
750 QtUi::closeNotifications();
751 return QMainWindow::event(event);
754 void MainWin::clientNetworkCreated(NetworkId id) {
755 const Network *net = Client::network(id);
756 QAction *act = new QAction(net->networkName(), this);
757 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
758 act->setData(QVariant::fromValue<NetworkId>(id));
759 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
760 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
762 QAction *beforeAction = 0;
763 foreach(QAction *action, _networksMenu->actions()) {
764 if(!action->data().isValid()) // ignore stock actions
766 if(net->networkName().localeAwareCompare(action->text()) < 0) {
767 beforeAction = action;
771 _networksMenu->insertAction(beforeAction, act);
774 void MainWin::clientNetworkUpdated() {
775 const Network *net = qobject_cast<const Network *>(sender());
779 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
783 action->setText(net->networkName());
785 switch(net->connectionState()) {
786 case Network::Initialized:
787 action->setIcon(SmallIcon("network-connect"));
789 case Network::Disconnected:
790 action->setIcon(SmallIcon("network-disconnect"));
793 action->setIcon(SmallIcon("network-wired"));
797 void MainWin::clientNetworkRemoved(NetworkId id) {
798 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
802 action->deleteLater();
805 void MainWin::connectOrDisconnectFromNet() {
806 QAction *act = qobject_cast<QAction *>(sender());
808 const Network *net = Client::network(act->data().value<NetworkId>());
810 if(net->connectionState() == Network::Disconnected) net->requestConnect();
811 else net->requestDisconnect();
814 void MainWin::on_actionDebugNetworkModel_triggered() {
815 QTreeView *view = new QTreeView;
816 view->setAttribute(Qt::WA_DeleteOnClose);
817 view->setWindowTitle("Debug NetworkModel View");
818 view->setModel(Client::networkModel());
819 view->setColumnWidth(0, 250);
820 view->setColumnWidth(1, 250);
821 view->setColumnWidth(2, 80);
822 view->resize(610, 300);
826 void MainWin::on_actionDebugMessageModel_triggered() {
827 QTableView *view = new QTableView(0);
828 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
829 filter->setSourceModel(Client::messageModel());
830 view->setModel(filter);
831 view->setAttribute(Qt::WA_DeleteOnClose, true);
832 view->verticalHeader()->hide();
833 view->horizontalHeader()->setStretchLastSection(true);
837 void MainWin::on_actionDebugLog_triggered() {
838 DebugLogWidget *logWidget = new DebugLogWidget(0);
842 void MainWin::saveStateToSession(const QString &sessionId) {
844 SessionSettings s(sessionId);
846 s.setValue("MainWinSize", size());
847 s.setValue("MainWinPos", pos());
848 s.setValue("MainWinState", saveState());
851 void MainWin::saveStateToSessionSettings(SessionSettings & s)
853 s.setValue("MainWinSize", size());
854 s.setValue("MainWinPos", pos());
855 s.setValue("MainWinState", saveState());
858 void MainWin::showStatusBarMessage(const QString &message) {
859 statusBar()->showMessage(message, 10000);