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 "actioncollection.h"
25 #include "buffermodel.h"
26 #include "bufferview.h"
27 #include "bufferviewmanager.h"
28 #include "bufferwidget.h"
29 #include "channellistdlg.h"
30 #include "chatlinemodel.h"
31 #include "chatmonitorfilter.h"
32 #include "chatmonitorview.h"
35 #include "clientbacklogmanager.h"
36 #include "coreinfodlg.h"
37 #include "coreconnectdlg.h"
38 #include "debuglogwidget.h"
39 #include "debugmessagemodelfilter.h"
40 #include "iconloader.h"
41 #include "inputwidget.h"
42 #include "inputline.h"
43 #include "irclistmodel.h"
44 #include "jumpkeyhandler.h"
45 #include "msgprocessorstatuswidget.h"
46 #include "nicklistwidget.h"
47 #include "qtuiapplication.h"
48 #include "qtuimessageprocessor.h"
49 #include "qtuisettings.h"
50 #include "sessionsettings.h"
51 #include "settingsdlg.h"
52 #include "settingspagedlg.h"
53 #include "topicwidget.h"
54 #include "verticaldock.h"
57 # include "desktopnotificationbackend.h"
59 #include "systraynotificationbackend.h"
60 #include "taskbarnotificationbackend.h"
62 #include "settingspages/aliasessettingspage.h"
63 #include "settingspages/appearancesettingspage.h"
64 #include "settingspages/backlogsettingspage.h"
65 #include "settingspages/bufferviewsettingspage.h"
66 #include "settingspages/colorsettingspage.h"
67 #include "settingspages/fontssettingspage.h"
68 #include "settingspages/generalsettingspage.h"
69 #include "settingspages/highlightsettingspage.h"
70 #include "settingspages/identitiessettingspage.h"
71 #include "settingspages/networkssettingspage.h"
72 #include "settingspages/notificationssettingspage.h"
74 MainWin::MainWin(QWidget *parent)
75 : QMainWindow(parent),
76 coreLagLabel(new QLabel()),
77 sslLabel(new QLabel()),
78 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
80 _trayIcon(new QSystemTrayIcon(this))
82 QtUiSettings uiSettings;
83 QString style = uiSettings.value("Style", QString()).toString();
84 if(!style.isEmpty()) {
85 QApplication::setStyle(style);
88 QApplication::setQuitOnLastWindowClosed(false);
90 setWindowTitle("Quassel IRC");
91 setWindowIconText("Quassel IRC");
94 installEventFilter(new JumpKeyHandler(this));
96 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
97 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
99 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
102 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
103 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
104 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
107 void MainWin::init() {
109 if(s.value("MainWinSize").isValid())
110 resize(s.value("MainWinSize").toSize());
112 resize(QSize(800, 500));
114 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
115 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
116 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
117 connect(Client::mainUi()->actionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
120 setDockNestingEnabled(true);
121 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
122 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
123 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
124 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
126 // Order is sometimes important
139 // restore mainwin state
140 restoreState(s.value("MainWinState").toByteArray());
142 // restore locked state of docks
143 QtUi::actionCollection("General")->action("LockDockPositions")->setChecked(s.value("LockDocks", false).toBool());
145 setDisconnectedState(); // Disable menus and stuff
148 showCoreConnectionDlg(true); // autoconnect if appropriate
151 MainWin::~MainWin() {
153 s.setValue("MainWinSize", size());
154 s.setValue("MainWinPos", pos());
155 s.setValue("MainWinState", saveState());
158 void MainWin::updateIcon() {
160 if(Client::isConnected())
161 icon = DesktopIcon("quassel", IconLoader::SizeEnormous);
163 icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous);
165 qApp->setWindowIcon(icon);
166 systemTrayIcon()->setIcon(icon);
169 void MainWin::setupActions() {
170 ActionCollection *coll = QtUi::actionCollection("General");
172 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
173 this, SLOT(showCoreConnectionDlg())));
174 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
175 Client::instance(), SLOT(disconnectFromCore())));
176 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
177 this, SLOT(showCoreInfoDlg())));
178 coll->addAction("EditNetworks", new Action(SmallIcon("configure"), tr("Edit &Networks..."), coll,
179 this, SLOT(on_actionEditNetworks_triggered())));
180 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
181 qApp, SLOT(quit()), tr("Ctrl+Q")));
184 coll->addAction("ManageBufferViews", new Action(SmallIcon("view-tree"), tr("&Manage Buffer Views..."), coll,
185 this, SLOT(on_actionManageViews_triggered())));
186 Action *lockAct = coll->addAction("LockDockPositions", new Action(tr("&Lock Dock Positions"), coll));
187 lockAct->setCheckable(true);
188 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockDockPositions_toggled(bool)));
190 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
191 0, 0, tr("Ctrl+F")))->setCheckable(true);
192 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
193 0, 0))->setCheckable(true);
196 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
197 this, SLOT(showSettingsDlg()), tr("F7")));
200 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel..."), coll,
201 this, SLOT(showAboutDlg())));
202 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt..."), coll,
203 qApp, SLOT(aboutQt())));
204 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
205 this, SLOT(on_actionDebugNetworkModel_triggered())));
206 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
207 this, SLOT(on_actionDebugMessageModel_triggered())));
208 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
209 this, SLOT(on_actionDebugLog_triggered())));
212 void MainWin::setupMenus() {
213 ActionCollection *coll = QtUi::actionCollection("General");
215 _fileMenu = menuBar()->addMenu(tr("&File"));
216 _fileMenu->addAction(coll->action("ConnectCore"));
217 _fileMenu->addAction(coll->action("DisconnectCore"));
218 _fileMenu->addAction(coll->action("CoreInfo"));
219 _fileMenu->addSeparator();
220 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
221 _networksMenu->addAction(coll->action("EditNetworks"));
222 _networksMenu->addSeparator();
223 _fileMenu->addSeparator();
224 _fileMenu->addAction(coll->action("Quit"));
226 _viewMenu = menuBar()->addMenu(tr("&View"));
227 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
228 _bufferViewsMenu->addAction(coll->action("ManageBufferViews"));
229 _viewMenu->addSeparator();
230 _viewMenu->addAction(coll->action("ToggleSearchBar"));
231 _viewMenu->addAction(coll->action("ToggleStatusBar"));
232 _viewMenu->addSeparator();
233 _viewMenu->addAction(coll->action("LockDockPositions"));
235 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
236 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
238 _helpMenu = menuBar()->addMenu(tr("&Help"));
239 _helpMenu->addAction(coll->action("AboutQuassel"));
240 _helpMenu->addAction(coll->action("AboutQt"));
241 _helpMenu->addSeparator();
242 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
243 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
244 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
245 _helpDebugMenu->addAction(coll->action("DebugLog"));
248 void MainWin::setupBufferWidget() {
249 _bufferWidget = new BufferWidget(this);
250 _bufferWidget->setModel(Client::bufferModel());
251 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
252 setCentralWidget(_bufferWidget);
255 void MainWin::setupViews() {
259 void MainWin::addBufferView(int bufferViewConfigId) {
260 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
263 void MainWin::addBufferView(BufferViewConfig *config) {
264 BufferViewDock *dock;
266 dock = new BufferViewDock(config, this);
268 dock = new BufferViewDock(this);
270 //create the view and initialize it's filter
271 BufferView *view = new BufferView(dock);
272 view->setFilteredModel(Client::bufferModel(), config);
275 Client::bufferModel()->synchronizeView(view);
277 dock->setWidget(view);
280 addDockWidget(Qt::LeftDockWidgetArea, dock);
281 _bufferViewsMenu->addAction(dock->toggleViewAction());
283 _bufferViews.append(dock);
286 void MainWin::removeBufferView(int bufferViewConfigId) {
288 BufferViewDock *dock;
289 foreach(QAction *action, _bufferViewsMenu->actions()) {
290 actionData = action->data();
291 if(!actionData.isValid())
294 dock = qobject_cast<BufferViewDock *>(action->parent());
295 if(dock && actionData.toInt() == bufferViewConfigId) {
296 removeAction(action);
302 BufferView *MainWin::allBuffersView() const {
303 // "All Buffers" is always the first dock created
304 if(_bufferViews.count() > 0)
305 return _bufferViews[0]->bufferView();
309 void MainWin::on_actionEditNetworks_triggered() {
310 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
314 void MainWin::on_actionManageViews_triggered() {
315 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
319 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
320 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
321 foreach(VerticalDock *dock, docks) {
322 dock->showTitle(!lock);
324 QtUiSettings().setValue("LockDocks", lock);
327 void MainWin::setupNickWidget() {
329 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
330 nickDock->setObjectName("NickDock");
331 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
333 _nickListWidget = new NickListWidget(nickDock);
334 nickDock->setWidget(_nickListWidget);
336 addDockWidget(Qt::RightDockWidgetArea, nickDock);
337 _viewMenu->addAction(nickDock->toggleViewAction());
338 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
339 nickDock->toggleViewAction()->setIcon(SmallIcon("view-sidetree"));
340 // See NickListDock::NickListDock();
341 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
343 // attach the NickListWidget to the BufferModel and the default selection
344 _nickListWidget->setModel(Client::bufferModel());
345 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
348 void MainWin::setupChatMonitor() {
349 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
350 dock->setObjectName("ChatMonitorDock");
352 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
353 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
355 dock->setWidget(chatView);
358 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
359 _viewMenu->addAction(dock->toggleViewAction());
360 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
363 void MainWin::setupInputWidget() {
364 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
365 dock->setObjectName("InputDock");
367 InputWidget *inputWidget = new InputWidget(dock);
368 dock->setWidget(inputWidget);
370 addDockWidget(Qt::BottomDockWidgetArea, dock);
372 _viewMenu->addAction(dock->toggleViewAction());
373 dock->toggleViewAction()->setText(tr("Show Input Line"));
375 inputWidget->setModel(Client::bufferModel());
376 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
378 _bufferWidget->setFocusProxy(inputWidget);
380 inputWidget->inputLine()->installEventFilter(_bufferWidget);
383 void MainWin::setupTopicWidget() {
384 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
385 dock->setObjectName("TopicDock");
386 TopicWidget *topicwidget = new TopicWidget(dock);
388 dock->setWidget(topicwidget);
390 topicwidget->setModel(Client::bufferModel());
391 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
393 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
395 _viewMenu->addAction(dock->toggleViewAction());
396 dock->toggleViewAction()->setText(tr("Show Topic Line"));
399 void MainWin::setupTitleSetter() {
400 _titleSetter.setModel(Client::bufferModel());
401 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
404 void MainWin::setupStatusBar() {
405 // MessageProcessor progress
406 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
407 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
410 updateLagIndicator(0);
411 statusBar()->addPermanentWidget(coreLagLabel);
412 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
415 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
416 sslLabel->setPixmap(QPixmap());
417 statusBar()->addPermanentWidget(sslLabel);
419 _viewMenu->addSeparator();
420 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
422 QtUiSettings uiSettings;
424 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
425 showStatusbar->setChecked(enabled);
426 enabled ? statusBar()->show() : statusBar()->hide();
428 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
429 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
431 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
432 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
435 void MainWin::saveStatusBarStatus(bool enabled) {
436 QtUiSettings uiSettings;
437 uiSettings.setValue("ShowStatusBar", enabled);
440 void MainWin::setupSystray() {
441 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
442 SLOT(messagesInserted(const QModelIndex &, int, int)));
444 ActionCollection *coll = QtUi::actionCollection("General");
445 systrayMenu = new QMenu(this);
446 systrayMenu->addAction(coll->action("AboutQuassel"));
447 systrayMenu->addSeparator();
448 systrayMenu->addAction(coll->action("ConnectCore"));
449 systrayMenu->addAction(coll->action("DisconnectCore"));
450 systrayMenu->addSeparator();
451 systrayMenu->addAction(coll->action("Quit"));
453 systemTrayIcon()->setContextMenu(systrayMenu);
456 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
457 systemTrayIcon()->show();
461 connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
462 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
467 void MainWin::changeEvent(QEvent *event) {
468 if(event->type() == QEvent::WindowStateChange) {
469 if(windowState() & Qt::WindowMinimized) {
471 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
479 void MainWin::connectedToCore() {
480 Q_CHECK_PTR(Client::bufferViewManager());
481 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
482 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
483 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
488 void MainWin::setConnectedState() {
489 ActionCollection *coll = QtUi::actionCollection("General");
490 //ui.menuCore->setEnabled(true);
491 coll->action("ConnectCore")->setEnabled(false);
492 coll->action("DisconnectCore")->setEnabled(true);
493 coll->action("CoreInfo")->setEnabled(true);
494 // _viewMenu->setEnabled(true);
495 statusBar()->showMessage(tr("Connected to core."));
496 if(sslLabel->width() == 0)
497 sslLabel->setPixmap(SmallIcon("security-low"));
501 void MainWin::loadLayout() {
503 int accountId = Client::currentCoreAccount().toInt();
504 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
507 void MainWin::saveLayout() {
509 int accountId = Client::currentCoreAccount().toInt();
510 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
513 void MainWin::updateLagIndicator(int lag) {
514 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
518 void MainWin::securedConnection() {
519 // todo: make status bar entry
520 sslLabel->setPixmap(SmallIcon("security-high"));
523 void MainWin::disconnectedFromCore() {
524 // save core specific layout and remove bufferviews;
527 BufferViewDock *dock;
528 foreach(QAction *action, _bufferViewsMenu->actions()) {
529 actionData = action->data();
530 if(!actionData.isValid())
533 dock = qobject_cast<BufferViewDock *>(action->parent());
534 if(dock && actionData.toInt() != -1) {
535 removeAction(action);
540 restoreState(s.value("MainWinState").toByteArray());
541 setDisconnectedState();
544 void MainWin::setDisconnectedState() {
545 ActionCollection *coll = QtUi::actionCollection("General");
546 //ui.menuCore->setEnabled(false);
547 coll->action("ConnectCore")->setEnabled(true);
548 coll->action("DisconnectCore")->setEnabled(false);
549 coll->action("CoreInfo")->setEnabled(false);
550 //_viewMenu->setEnabled(false);
551 statusBar()->showMessage(tr("Not connected to core."));
552 sslLabel->setPixmap(QPixmap());
556 void MainWin::showCoreConnectionDlg(bool autoConnect) {
557 CoreConnectDlg(autoConnect, this).exec();
560 void MainWin::showChannelList(NetworkId netId) {
561 ChannelListDlg *channelListDlg = new ChannelListDlg();
563 if(!netId.isValid()) {
564 QAction *action = qobject_cast<QAction *>(sender());
566 netId = action->data().value<NetworkId>();
569 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
570 channelListDlg->setNetwork(netId);
571 channelListDlg->show();
574 void MainWin::showCoreInfoDlg() {
575 CoreInfoDlg(this).exec();
578 void MainWin::showSettingsDlg() {
579 SettingsDlg *dlg = new SettingsDlg();
581 //Category: Appearance
582 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
583 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
584 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
585 //Category: Behaviour
586 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
587 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
588 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
589 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
590 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
592 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
593 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
594 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
599 void MainWin::showAboutDlg() {
600 AboutDlg(this).exec();
603 void MainWin::closeEvent(QCloseEvent *event) {
605 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
610 QApplication::quit();
614 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
615 if(activationReason == QSystemTrayIcon::Trigger) {
620 void MainWin::toggleVisibility() {
621 if(isHidden() /*|| !isActiveWindow()*/) {
632 // setFocus(); //Qt::ActiveWindowFocusReason
635 if(systemTrayIcon()->isSystemTrayAvailable ()) {
638 if(!systemTrayIcon()->isVisible()) {
639 systemTrayIcon()->show();
647 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
650 if(QApplication::activeWindow() != 0)
653 for(int i = start; i <= end; i++) {
654 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
656 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
659 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
660 if(flags.testFlag(Message::Backlog)) continue;
661 flags |= Message::Backlog; // we only want to trigger a highlight once!
662 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
664 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
665 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
667 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
668 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
669 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
670 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
671 QtUi::invokeNotification(bufId, sender, contents);
676 bool MainWin::event(QEvent *event) {
677 if(event->type() == QEvent::WindowActivate)
678 QtUi::closeNotifications();
679 return QMainWindow::event(event);
682 void MainWin::clientNetworkCreated(NetworkId id) {
683 const Network *net = Client::network(id);
684 QAction *act = new QAction(net->networkName(), this);
685 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
686 act->setData(QVariant::fromValue<NetworkId>(id));
687 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
688 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
690 QAction *beforeAction = 0;
691 foreach(QAction *action, _networksMenu->actions()) {
692 if(!action->data().isValid()) // ignore stock actions
694 if(net->networkName().localeAwareCompare(action->text()) < 0) {
695 beforeAction = action;
699 _networksMenu->insertAction(beforeAction, act);
702 void MainWin::clientNetworkUpdated() {
703 const Network *net = qobject_cast<const Network *>(sender());
707 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
711 action->setText(net->networkName());
713 switch(net->connectionState()) {
714 case Network::Initialized:
715 action->setIcon(SmallIcon("network-connect"));
717 case Network::Disconnected:
718 action->setIcon(SmallIcon("network-disconnect"));
721 action->setIcon(SmallIcon("network-wired"));
725 void MainWin::clientNetworkRemoved(NetworkId id) {
726 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
730 action->deleteLater();
733 void MainWin::connectOrDisconnectFromNet() {
734 QAction *act = qobject_cast<QAction *>(sender());
736 const Network *net = Client::network(act->data().value<NetworkId>());
738 if(net->connectionState() == Network::Disconnected) net->requestConnect();
739 else net->requestDisconnect();
742 void MainWin::on_actionDebugNetworkModel_triggered() {
743 QTreeView *view = new QTreeView;
744 view->setAttribute(Qt::WA_DeleteOnClose);
745 view->setWindowTitle("Debug NetworkModel View");
746 view->setModel(Client::networkModel());
747 view->setColumnWidth(0, 250);
748 view->setColumnWidth(1, 250);
749 view->setColumnWidth(2, 80);
750 view->resize(610, 300);
754 void MainWin::on_actionDebugMessageModel_triggered() {
755 QTableView *view = new QTableView(0);
756 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
757 filter->setSourceModel(Client::messageModel());
758 view->setModel(filter);
759 view->setAttribute(Qt::WA_DeleteOnClose, true);
760 view->verticalHeader()->hide();
761 view->horizontalHeader()->setStretchLastSection(true);
765 void MainWin::on_actionDebugLog_triggered() {
766 DebugLogWidget *logWidget = new DebugLogWidget(0);
770 void MainWin::saveStateToSession(const QString &sessionId) {
772 SessionSettings s(sessionId);
774 s.setValue("MainWinSize", size());
775 s.setValue("MainWinPos", pos());
776 s.setValue("MainWinState", saveState());
779 void MainWin::saveStateToSessionSettings(SessionSettings & s)
781 s.setValue("MainWinSize", size());
782 s.setValue("MainWinPos", pos());
783 s.setValue("MainWinState", saveState());
786 void MainWin::showStatusBarMessage(const QString &message) {
787 statusBar()->showMessage(message, 10000);