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)));
119 setDockNestingEnabled(true);
120 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
121 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
122 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
123 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
125 // Order is sometimes important
138 // restore mainwin state
139 restoreState(s.value("MainWinState").toByteArray());
141 // restore locked state of docks
142 QtUi::actionCollection("General")->action("LockDockPositions")->setChecked(s.value("LockDocks", false).toBool());
144 setDisconnectedState(); // Disable menus and stuff
147 showCoreConnectionDlg(true); // autoconnect if appropriate
150 MainWin::~MainWin() {
152 s.setValue("MainWinSize", size());
153 s.setValue("MainWinPos", pos());
154 s.setValue("MainWinState", saveState());
157 void MainWin::updateIcon() {
159 if(Client::isConnected())
160 icon = DesktopIcon("quassel", IconLoader::SizeEnormous);
162 icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous);
164 qApp->setWindowIcon(icon);
165 systemTrayIcon()->setIcon(icon);
168 void MainWin::setupActions() {
169 ActionCollection *coll = QtUi::actionCollection("General");
171 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
172 this, SLOT(showCoreConnectionDlg())));
173 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
174 Client::instance(), SLOT(disconnectFromCore())));
175 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
176 this, SLOT(showCoreInfoDlg())));
177 coll->addAction("EditNetworks", new Action(SmallIcon("configure"), tr("Edit &Networks..."), coll,
178 this, SLOT(on_actionEditNetworks_triggered())));
179 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
180 qApp, SLOT(quit()), tr("Ctrl+Q")));
183 coll->addAction("ManageBufferViews", new Action(SmallIcon("view-tree"), tr("&Manage Buffer Views..."), coll,
184 this, SLOT(on_actionManageViews_triggered())));
185 Action *lockAct = coll->addAction("LockDockPositions", new Action(tr("&Lock Dock Positions"), coll));
186 lockAct->setCheckable(true);
187 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockDockPositions_toggled(bool)));
189 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
190 0, 0, tr("Ctrl+F")))->setCheckable(true);
191 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
192 0, 0))->setCheckable(true);
195 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
196 this, SLOT(showSettingsDlg()), tr("F7")));
199 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel..."), coll,
200 this, SLOT(showAboutDlg())));
201 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt..."), coll,
202 qApp, SLOT(aboutQt())));
203 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
204 this, SLOT(on_actionDebugNetworkModel_triggered())));
205 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
206 this, SLOT(on_actionDebugMessageModel_triggered())));
207 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
208 this, SLOT(on_actionDebugLog_triggered())));
211 void MainWin::setupMenus() {
212 ActionCollection *coll = QtUi::actionCollection("General");
214 _fileMenu = menuBar()->addMenu(tr("&File"));
215 _fileMenu->addAction(coll->action("ConnectCore"));
216 _fileMenu->addAction(coll->action("DisconnectCore"));
217 _fileMenu->addAction(coll->action("CoreInfo"));
218 _fileMenu->addSeparator();
219 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
220 _networksMenu->addAction(coll->action("EditNetworks"));
221 _networksMenu->addSeparator();
222 _fileMenu->addSeparator();
223 _fileMenu->addAction(coll->action("Quit"));
225 _viewMenu = menuBar()->addMenu(tr("&View"));
226 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
227 _bufferViewsMenu->addAction(coll->action("ManageBufferViews"));
228 _viewMenu->addSeparator();
229 _viewMenu->addAction(coll->action("ToggleSearchBar"));
230 _viewMenu->addAction(coll->action("ToggleStatusBar"));
231 _viewMenu->addSeparator();
232 _viewMenu->addAction(coll->action("LockDockPositions"));
234 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
235 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
237 _helpMenu = menuBar()->addMenu(tr("&Help"));
238 _helpMenu->addAction(coll->action("AboutQuassel"));
239 _helpMenu->addAction(coll->action("AboutQt"));
240 _helpMenu->addSeparator();
241 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
242 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
243 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
244 _helpDebugMenu->addAction(coll->action("DebugLog"));
247 void MainWin::setupBufferWidget() {
248 _bufferWidget = new BufferWidget(this);
249 _bufferWidget->setModel(Client::bufferModel());
250 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
251 setCentralWidget(_bufferWidget);
254 void MainWin::setupViews() {
258 void MainWin::addBufferView(int bufferViewConfigId) {
259 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
262 void MainWin::addBufferView(BufferViewConfig *config) {
263 BufferViewDock *dock;
265 dock = new BufferViewDock(config, this);
267 dock = new BufferViewDock(this);
269 //create the view and initialize it's filter
270 BufferView *view = new BufferView(dock);
271 view->setFilteredModel(Client::bufferModel(), config);
274 connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList()));
276 Client::bufferModel()->synchronizeView(view);
278 dock->setWidget(view);
281 addDockWidget(Qt::LeftDockWidgetArea, dock);
282 _bufferViewsMenu->addAction(dock->toggleViewAction());
284 _bufferViews.append(dock);
287 void MainWin::removeBufferView(int bufferViewConfigId) {
289 BufferViewDock *dock;
290 foreach(QAction *action, _bufferViewsMenu->actions()) {
291 actionData = action->data();
292 if(!actionData.isValid())
295 dock = qobject_cast<BufferViewDock *>(action->parent());
296 if(dock && actionData.toInt() == bufferViewConfigId) {
297 removeAction(action);
303 BufferView *MainWin::allBuffersView() const {
304 // "All Buffers" is always the first dock created
305 if(_bufferViews.count() > 0)
306 return _bufferViews[0]->bufferView();
310 void MainWin::on_actionEditNetworks_triggered() {
311 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
315 void MainWin::on_actionManageViews_triggered() {
316 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
320 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
321 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
322 foreach(VerticalDock *dock, docks) {
323 dock->showTitle(!lock);
325 QtUiSettings().setValue("LockDocks", lock);
328 void MainWin::setupNickWidget() {
330 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
331 nickDock->setObjectName("NickDock");
332 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
334 _nickListWidget = new NickListWidget(nickDock);
335 nickDock->setWidget(_nickListWidget);
337 addDockWidget(Qt::RightDockWidgetArea, nickDock);
338 _viewMenu->addAction(nickDock->toggleViewAction());
339 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
340 nickDock->toggleViewAction()->setIcon(SmallIcon("view-sidetree"));
341 // See NickListDock::NickListDock();
342 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
344 // attach the NickListWidget to the BufferModel and the default selection
345 _nickListWidget->setModel(Client::bufferModel());
346 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
349 void MainWin::setupChatMonitor() {
350 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
351 dock->setObjectName("ChatMonitorDock");
353 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
354 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
356 dock->setWidget(chatView);
359 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
360 _viewMenu->addAction(dock->toggleViewAction());
361 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
364 void MainWin::setupInputWidget() {
365 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
366 dock->setObjectName("InputDock");
368 InputWidget *inputWidget = new InputWidget(dock);
369 dock->setWidget(inputWidget);
371 addDockWidget(Qt::BottomDockWidgetArea, dock);
373 _viewMenu->addAction(dock->toggleViewAction());
374 dock->toggleViewAction()->setText(tr("Show Input Line"));
376 inputWidget->setModel(Client::bufferModel());
377 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
379 _bufferWidget->setFocusProxy(inputWidget);
381 inputWidget->inputLine()->installEventFilter(_bufferWidget);
384 void MainWin::setupTopicWidget() {
385 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
386 dock->setObjectName("TopicDock");
387 TopicWidget *topicwidget = new TopicWidget(dock);
389 dock->setWidget(topicwidget);
391 topicwidget->setModel(Client::bufferModel());
392 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
394 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
396 _viewMenu->addAction(dock->toggleViewAction());
397 dock->toggleViewAction()->setText(tr("Show Topic Line"));
400 void MainWin::setupTitleSetter() {
401 _titleSetter.setModel(Client::bufferModel());
402 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
405 void MainWin::setupStatusBar() {
406 // MessageProcessor progress
407 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
408 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
411 updateLagIndicator(0);
412 statusBar()->addPermanentWidget(coreLagLabel);
413 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
416 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
417 sslLabel->setPixmap(QPixmap());
418 statusBar()->addPermanentWidget(sslLabel);
420 _viewMenu->addSeparator();
421 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
423 QtUiSettings uiSettings;
425 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
426 showStatusbar->setChecked(enabled);
427 enabled ? statusBar()->show() : statusBar()->hide();
429 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
430 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
432 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
433 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
436 void MainWin::saveStatusBarStatus(bool enabled) {
437 QtUiSettings uiSettings;
438 uiSettings.setValue("ShowStatusBar", enabled);
441 void MainWin::setupSystray() {
442 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
443 SLOT(messagesInserted(const QModelIndex &, int, int)));
445 ActionCollection *coll = QtUi::actionCollection("General");
446 systrayMenu = new QMenu(this);
447 systrayMenu->addAction(coll->action("AboutQuassel"));
448 systrayMenu->addSeparator();
449 systrayMenu->addAction(coll->action("ConnectCore"));
450 systrayMenu->addAction(coll->action("DisconnectCore"));
451 systrayMenu->addSeparator();
452 systrayMenu->addAction(coll->action("Quit"));
454 systemTrayIcon()->setContextMenu(systrayMenu);
457 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
458 systemTrayIcon()->show();
462 connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
463 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
468 void MainWin::changeEvent(QEvent *event) {
469 if(event->type() == QEvent::WindowStateChange) {
470 if(windowState() & Qt::WindowMinimized) {
472 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
480 void MainWin::connectedToCore() {
481 Q_CHECK_PTR(Client::bufferViewManager());
482 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
483 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
484 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
489 void MainWin::setConnectedState() {
490 ActionCollection *coll = QtUi::actionCollection("General");
491 //ui.menuCore->setEnabled(true);
492 coll->action("ConnectCore")->setEnabled(false);
493 coll->action("DisconnectCore")->setEnabled(true);
494 coll->action("CoreInfo")->setEnabled(true);
495 // _viewMenu->setEnabled(true);
496 statusBar()->showMessage(tr("Connected to core."));
497 if(sslLabel->width() == 0)
498 sslLabel->setPixmap(SmallIcon("security-low"));
502 void MainWin::loadLayout() {
504 int accountId = Client::currentCoreAccount().toInt();
505 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
508 void MainWin::saveLayout() {
510 int accountId = Client::currentCoreAccount().toInt();
511 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
514 void MainWin::updateLagIndicator(int lag) {
515 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
519 void MainWin::securedConnection() {
520 // todo: make status bar entry
521 sslLabel->setPixmap(SmallIcon("security-high"));
524 void MainWin::disconnectedFromCore() {
525 // save core specific layout and remove bufferviews;
528 BufferViewDock *dock;
529 foreach(QAction *action, _bufferViewsMenu->actions()) {
530 actionData = action->data();
531 if(!actionData.isValid())
534 dock = qobject_cast<BufferViewDock *>(action->parent());
535 if(dock && actionData.toInt() != -1) {
536 removeAction(action);
541 restoreState(s.value("MainWinState").toByteArray());
542 setDisconnectedState();
545 void MainWin::setDisconnectedState() {
546 ActionCollection *coll = QtUi::actionCollection("General");
547 //ui.menuCore->setEnabled(false);
548 coll->action("ConnectCore")->setEnabled(true);
549 coll->action("DisconnectCore")->setEnabled(false);
550 coll->action("CoreInfo")->setEnabled(false);
551 //_viewMenu->setEnabled(false);
552 statusBar()->showMessage(tr("Not connected to core."));
553 sslLabel->setPixmap(QPixmap());
557 void MainWin::showCoreConnectionDlg(bool autoConnect) {
558 CoreConnectDlg(autoConnect, this).exec();
561 void MainWin::showChannelList(NetworkId netId) {
562 ChannelListDlg *channelListDlg = new ChannelListDlg();
564 if(!netId.isValid()) {
565 QAction *action = qobject_cast<QAction *>(sender());
567 netId = action->data().value<NetworkId>();
570 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
571 channelListDlg->setNetwork(netId);
572 channelListDlg->show();
575 void MainWin::showCoreInfoDlg() {
576 CoreInfoDlg(this).exec();
579 void MainWin::showSettingsDlg() {
580 SettingsDlg *dlg = new SettingsDlg();
582 //Category: Appearance
583 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
584 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
585 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
586 //Category: Behaviour
587 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
588 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
589 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
590 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
591 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
593 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
594 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
595 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
600 void MainWin::showAboutDlg() {
601 AboutDlg(this).exec();
604 void MainWin::closeEvent(QCloseEvent *event) {
606 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
611 QApplication::quit();
615 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
616 if(activationReason == QSystemTrayIcon::Trigger) {
621 void MainWin::toggleVisibility() {
622 if(isHidden() /*|| !isActiveWindow()*/) {
633 // setFocus(); //Qt::ActiveWindowFocusReason
636 if(systemTrayIcon()->isSystemTrayAvailable ()) {
639 if(!systemTrayIcon()->isVisible()) {
640 systemTrayIcon()->show();
648 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
651 if(QApplication::activeWindow() != 0)
654 for(int i = start; i <= end; i++) {
655 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
657 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
660 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
661 if(flags.testFlag(Message::Backlog)) continue;
662 flags |= Message::Backlog; // we only want to trigger a highlight once!
663 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
665 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
666 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
668 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
669 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
670 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
671 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
672 QtUi::invokeNotification(bufId, sender, contents);
677 bool MainWin::event(QEvent *event) {
678 if(event->type() == QEvent::WindowActivate)
679 QtUi::closeNotifications();
680 return QMainWindow::event(event);
683 void MainWin::clientNetworkCreated(NetworkId id) {
684 const Network *net = Client::network(id);
685 QAction *act = new QAction(net->networkName(), this);
686 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
687 act->setData(QVariant::fromValue<NetworkId>(id));
688 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
689 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
691 QAction *beforeAction = 0;
692 foreach(QAction *action, _networksMenu->actions()) {
693 if(!action->data().isValid()) // ignore stock actions
695 if(net->networkName().localeAwareCompare(action->text()) < 0) {
696 beforeAction = action;
700 _networksMenu->insertAction(beforeAction, act);
703 void MainWin::clientNetworkUpdated() {
704 const Network *net = qobject_cast<const Network *>(sender());
708 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
712 action->setText(net->networkName());
714 switch(net->connectionState()) {
715 case Network::Initialized:
716 action->setIcon(SmallIcon("network-connect"));
718 case Network::Disconnected:
719 action->setIcon(SmallIcon("network-disconnect"));
722 action->setIcon(SmallIcon("network-wired"));
726 void MainWin::clientNetworkRemoved(NetworkId id) {
727 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
731 action->deleteLater();
734 void MainWin::connectOrDisconnectFromNet() {
735 QAction *act = qobject_cast<QAction *>(sender());
737 const Network *net = Client::network(act->data().value<NetworkId>());
739 if(net->connectionState() == Network::Disconnected) net->requestConnect();
740 else net->requestDisconnect();
743 void MainWin::on_actionDebugNetworkModel_triggered() {
744 QTreeView *view = new QTreeView;
745 view->setAttribute(Qt::WA_DeleteOnClose);
746 view->setWindowTitle("Debug NetworkModel View");
747 view->setModel(Client::networkModel());
748 view->setColumnWidth(0, 250);
749 view->setColumnWidth(1, 250);
750 view->setColumnWidth(2, 80);
751 view->resize(610, 300);
755 void MainWin::on_actionDebugMessageModel_triggered() {
756 QTableView *view = new QTableView(0);
757 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
758 filter->setSourceModel(Client::messageModel());
759 view->setModel(filter);
760 view->setAttribute(Qt::WA_DeleteOnClose, true);
761 view->verticalHeader()->hide();
762 view->horizontalHeader()->setStretchLastSection(true);
766 void MainWin::on_actionDebugLog_triggered() {
767 DebugLogWidget *logWidget = new DebugLogWidget(0);
771 void MainWin::saveStateToSession(const QString &sessionId) {
773 SessionSettings s(sessionId);
775 s.setValue("MainWinSize", size());
776 s.setValue("MainWinPos", pos());
777 s.setValue("MainWinState", saveState());
780 void MainWin::saveStateToSessionSettings(SessionSettings & s)
782 s.setValue("MainWinSize", size());
783 s.setValue("MainWinPos", pos());
784 s.setValue("MainWinState", saveState());
787 void MainWin::showStatusBarMessage(const QString &message) {
788 statusBar()->showMessage(message, 10000);