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 "bufferviewmanager.h"
27 #include "bufferwidget.h"
28 #include "channellistdlg.h"
29 #include "chatlinemodel.h"
30 #include "chatmonitorfilter.h"
31 #include "chatmonitorview.h"
34 #include "clientbacklogmanager.h"
35 #include "coreinfodlg.h"
36 #include "coreconnectdlg.h"
37 #include "debuglogwidget.h"
38 #include "iconloader.h"
39 #include "inputwidget.h"
40 #include "inputline.h"
41 #include "irclistmodel.h"
42 #include "jumpkeyhandler.h"
43 #include "msgprocessorstatuswidget.h"
44 #include "nicklistwidget.h"
45 #include "qtuiapplication.h"
46 #include "qtuimessageprocessor.h"
47 #include "qtuisettings.h"
48 #include "sessionsettings.h"
49 #include "settingsdlg.h"
50 #include "settingspagedlg.h"
51 #include "topicwidget.h"
52 #include "verticaldock.h"
55 # include "desktopnotificationbackend.h"
57 #include "systraynotificationbackend.h"
58 #include "taskbarnotificationbackend.h"
60 #include "settingspages/aliasessettingspage.h"
61 #include "settingspages/appearancesettingspage.h"
62 #include "settingspages/bufferviewsettingspage.h"
63 #include "settingspages/colorsettingspage.h"
64 #include "settingspages/fontssettingspage.h"
65 #include "settingspages/generalsettingspage.h"
66 #include "settingspages/highlightsettingspage.h"
67 #include "settingspages/identitiessettingspage.h"
68 #include "settingspages/networkssettingspage.h"
69 #include "settingspages/notificationssettingspage.h"
71 MainWin::MainWin(QWidget *parent)
72 : QMainWindow(parent),
73 coreLagLabel(new QLabel()),
74 sslLabel(new QLabel()),
75 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
77 _trayIcon(new QSystemTrayIcon(this))
79 QtUiSettings uiSettings;
80 QString style = uiSettings.value("Style", QString()).toString();
81 if(!style.isEmpty()) {
82 QApplication::setStyle(style);
85 setWindowTitle("Quassel IRC");
86 setWindowIconText("Quassel IRC");
89 installEventFilter(new JumpKeyHandler(this));
91 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
92 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
94 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
97 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
98 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
99 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
102 void MainWin::init() {
104 if(s.value("MainWinSize").isValid())
105 resize(s.value("MainWinSize").toSize());
107 resize(QSize(800, 500));
109 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
110 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
111 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
114 setDockNestingEnabled(true);
115 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
116 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
117 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
118 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
120 // Order is sometimes important
133 // restore mainwin state
134 restoreState(s.value("MainWinState").toByteArray());
136 // restore locked state of docks
137 QtUi::actionCollection("General")->action("LockDockPositions")->setChecked(s.value("LockDocks", false).toBool());
139 setDisconnectedState(); // Disable menus and stuff
143 showCoreConnectionDlg(true); // autoconnect if appropriate
146 MainWin::~MainWin() {
148 s.setValue("MainWinSize", size());
149 s.setValue("MainWinPos", pos());
150 s.setValue("MainWinState", saveState());
153 void MainWin::updateIcon() {
155 if(Client::isConnected())
156 icon = DesktopIcon("quassel", IconLoader::SizeEnormous);
158 icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous);
160 qApp->setWindowIcon(icon);
161 systemTrayIcon()->setIcon(icon);
164 void MainWin::setupActions() {
165 ActionCollection *coll = QtUi::actionCollection("General");
167 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
168 this, SLOT(showCoreConnectionDlg())));
169 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
170 Client::instance(), SLOT(disconnectFromCore())));
171 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
172 this, SLOT(showCoreInfoDlg())));
173 coll->addAction("EditNetworks", new Action(SmallIcon("configure"), tr("Edit &Networks..."), coll,
174 this, SLOT(on_actionEditNetworks_triggered())));
175 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
176 qApp, SLOT(quit()), tr("Ctrl+Q")));
179 coll->addAction("ManageBufferViews", new Action(SmallIcon("view-tree"), tr("&Manage Buffer Views..."), coll,
180 this, SLOT(on_actionManageViews_triggered())));
181 Action *lockAct = coll->addAction("LockDockPositions", new Action(tr("&Lock Dock Positions"), coll));
182 lockAct->setCheckable(true);
183 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockDockPositions_toggled(bool)));
185 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
186 0, 0, tr("Ctrl+F")))->setCheckable(true);
187 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
188 0, 0))->setCheckable(true);
191 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
192 this, SLOT(showSettingsDlg()), tr("F7")));
195 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel..."), coll,
196 this, SLOT(showAboutDlg())));
197 coll->addAction("AboutQt", new Action(tr("About &Qt..."), coll,
198 qApp, SLOT(aboutQt())));
199 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
200 this, SLOT(on_actionDebugNetworkModel_triggered())));
201 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
202 this, SLOT(on_actionDebugLog_triggered())));
205 void MainWin::setupMenus() {
206 ActionCollection *coll = QtUi::actionCollection("General");
208 _fileMenu = menuBar()->addMenu(tr("&File"));
209 _fileMenu->addAction(coll->action("ConnectCore"));
210 _fileMenu->addAction(coll->action("DisconnectCore"));
211 _fileMenu->addAction(coll->action("CoreInfo"));
212 _fileMenu->addSeparator();
213 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
214 _networksMenu->addAction(coll->action("EditNetworks"));
215 _networksMenu->addSeparator();
216 _fileMenu->addSeparator();
217 _fileMenu->addAction(coll->action("Quit"));
219 _viewMenu = menuBar()->addMenu(tr("&View"));
220 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
221 _bufferViewsMenu->addAction(coll->action("ManageBufferViews"));
222 _viewMenu->addSeparator();
223 _viewMenu->addAction(coll->action("ToggleSearchBar"));
224 _viewMenu->addAction(coll->action("ToggleStatusBar"));
225 _viewMenu->addSeparator();
226 _viewMenu->addAction(coll->action("LockDockPositions"));
228 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
229 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
231 _helpMenu = menuBar()->addMenu(tr("&Help"));
232 _helpMenu->addAction(coll->action("AboutQuassel"));
233 _helpMenu->addAction(coll->action("AboutQt"));
234 _helpMenu->addSeparator();
235 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
236 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
237 _helpDebugMenu->addAction(coll->action("DebugLog"));
240 void MainWin::setupBufferWidget() {
241 _bufferWidget = new BufferWidget(this);
242 _bufferWidget->setModel(Client::bufferModel());
243 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
244 setCentralWidget(_bufferWidget);
247 void MainWin::setupViews() {
251 void MainWin::addBufferView(int bufferViewConfigId) {
252 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
255 void MainWin::addBufferView(BufferViewConfig *config) {
256 BufferViewDock *dock;
258 dock = new BufferViewDock(config, this);
260 dock = new BufferViewDock(this);
262 //create the view and initialize it's filter
263 BufferView *view = new BufferView(dock);
264 view->setFilteredModel(Client::bufferModel(), config);
267 connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList()));
269 Client::bufferModel()->synchronizeView(view);
271 dock->setWidget(view);
274 addDockWidget(Qt::LeftDockWidgetArea, dock);
275 _bufferViewsMenu->addAction(dock->toggleViewAction());
277 _netViews.append(dock);
280 void MainWin::removeBufferView(int bufferViewConfigId) {
282 BufferViewDock *dock;
283 foreach(QAction *action, _bufferViewsMenu->actions()) {
284 actionData = action->data();
285 if(!actionData.isValid())
288 dock = qobject_cast<BufferViewDock *>(action->parent());
289 if(dock && actionData.toInt() == bufferViewConfigId) {
290 removeAction(action);
296 void MainWin::on_actionEditNetworks_triggered() {
297 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
301 void MainWin::on_actionManageViews_triggered() {
302 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
306 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
307 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
308 foreach(VerticalDock *dock, docks) {
309 dock->showTitle(!lock);
311 QtUiSettings().setValue("LockDocks", lock);
314 void MainWin::setupNickWidget() {
316 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
317 nickDock->setObjectName("NickDock");
318 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
320 _nickListWidget = new NickListWidget(nickDock);
321 nickDock->setWidget(_nickListWidget);
323 addDockWidget(Qt::RightDockWidgetArea, nickDock);
324 _viewMenu->addAction(nickDock->toggleViewAction());
325 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
326 nickDock->toggleViewAction()->setIcon(SmallIcon("view-sidetree"));
327 // See NickListDock::NickListDock();
328 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
330 // attach the NickListWidget to the BufferModel and the default selection
331 _nickListWidget->setModel(Client::bufferModel());
332 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
335 void MainWin::setupChatMonitor() {
336 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
337 dock->setObjectName("ChatMonitorDock");
339 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
340 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
342 dock->setWidget(chatView);
345 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
346 _viewMenu->addAction(dock->toggleViewAction());
347 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
350 void MainWin::setupInputWidget() {
351 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
352 dock->setObjectName("InputDock");
354 InputWidget *inputWidget = new InputWidget(dock);
355 dock->setWidget(inputWidget);
357 addDockWidget(Qt::BottomDockWidgetArea, dock);
359 _viewMenu->addAction(dock->toggleViewAction());
360 dock->toggleViewAction()->setText(tr("Show Input Line"));
362 inputWidget->setModel(Client::bufferModel());
363 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
365 _bufferWidget->setFocusProxy(inputWidget);
367 inputWidget->inputLine()->installEventFilter(_bufferWidget);
370 void MainWin::setupTopicWidget() {
371 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
372 dock->setObjectName("TopicDock");
373 TopicWidget *topicwidget = new TopicWidget(dock);
375 dock->setWidget(topicwidget);
377 topicwidget->setModel(Client::bufferModel());
378 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
380 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
382 _viewMenu->addAction(dock->toggleViewAction());
383 dock->toggleViewAction()->setText(tr("Show Topic Line"));
386 void MainWin::setupTitleSetter() {
387 _titleSetter.setModel(Client::bufferModel());
388 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
391 void MainWin::setupStatusBar() {
392 // MessageProcessor progress
393 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
394 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
397 updateLagIndicator(0);
398 statusBar()->addPermanentWidget(coreLagLabel);
399 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
402 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
403 sslLabel->setPixmap(QPixmap());
404 statusBar()->addPermanentWidget(sslLabel);
406 _viewMenu->addSeparator();
407 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
409 QtUiSettings uiSettings;
411 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
412 showStatusbar->setChecked(enabled);
413 enabled ? statusBar()->show() : statusBar()->hide();
415 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
416 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
418 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
419 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
422 void MainWin::saveStatusBarStatus(bool enabled) {
423 QtUiSettings uiSettings;
424 uiSettings.setValue("ShowStatusBar", enabled);
427 void MainWin::setupSystray() {
428 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
429 SLOT(messagesInserted(const QModelIndex &, int, int)));
431 ActionCollection *coll = QtUi::actionCollection("General");
432 systrayMenu = new QMenu(this);
433 systrayMenu->addAction(coll->action("AboutQuassel"));
434 systrayMenu->addSeparator();
435 systrayMenu->addAction(coll->action("ConnectCore"));
436 systrayMenu->addAction(coll->action("DisconnectCore"));
437 systrayMenu->addSeparator();
438 systrayMenu->addAction(coll->action("Quit"));
440 systemTrayIcon()->setContextMenu(systrayMenu);
443 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
444 systemTrayIcon()->show();
448 connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
449 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
454 void MainWin::changeEvent(QEvent *event) {
455 if(event->type() == QEvent::WindowStateChange) {
456 if(windowState() & Qt::WindowMinimized) {
458 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
466 void MainWin::connectedToCore() {
467 Q_CHECK_PTR(Client::bufferViewManager());
468 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
469 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
470 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
473 Client::backlogManager()->requestInitialBacklog();
476 void MainWin::setConnectedState() {
477 ActionCollection *coll = QtUi::actionCollection("General");
478 //ui.menuCore->setEnabled(true);
479 coll->action("ConnectCore")->setEnabled(false);
480 coll->action("DisconnectCore")->setEnabled(true);
481 coll->action("CoreInfo")->setEnabled(true);
482 // _viewMenu->setEnabled(true);
483 statusBar()->showMessage(tr("Connected to core."));
484 if(sslLabel->width() == 0)
485 sslLabel->setPixmap(SmallIcon("security-low"));
489 void MainWin::loadLayout() {
491 int accountId = Client::currentCoreAccount().toInt();
492 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
495 void MainWin::saveLayout() {
497 int accountId = Client::currentCoreAccount().toInt();
498 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
501 void MainWin::updateLagIndicator(int lag) {
502 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
506 void MainWin::securedConnection() {
507 // todo: make status bar entry
508 sslLabel->setPixmap(SmallIcon("security-high"));
511 void MainWin::disconnectedFromCore() {
512 // save core specific layout and remove bufferviews;
515 BufferViewDock *dock;
516 foreach(QAction *action, _bufferViewsMenu->actions()) {
517 actionData = action->data();
518 if(!actionData.isValid())
521 dock = qobject_cast<BufferViewDock *>(action->parent());
522 if(dock && actionData.toInt() != -1) {
523 removeAction(action);
528 restoreState(s.value("MainWinState").toByteArray());
529 setDisconnectedState();
532 void MainWin::setDisconnectedState() {
533 ActionCollection *coll = QtUi::actionCollection("General");
534 //ui.menuCore->setEnabled(false);
535 coll->action("ConnectCore")->setEnabled(true);
536 coll->action("DisconnectCore")->setEnabled(false);
537 coll->action("CoreInfo")->setEnabled(false);
538 //_viewMenu->setEnabled(false);
539 statusBar()->showMessage(tr("Not connected to core."));
540 sslLabel->setPixmap(QPixmap());
544 void MainWin::showCoreConnectionDlg(bool autoConnect) {
545 CoreConnectDlg(autoConnect, this).exec();
548 void MainWin::showChannelList(NetworkId netId) {
549 ChannelListDlg *channelListDlg = new ChannelListDlg();
551 if(!netId.isValid()) {
552 QAction *action = qobject_cast<QAction *>(sender());
554 netId = action->data().value<NetworkId>();
557 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
558 channelListDlg->setNetwork(netId);
559 channelListDlg->show();
562 void MainWin::showCoreInfoDlg() {
563 CoreInfoDlg(this).exec();
566 void MainWin::showSettingsDlg() {
567 SettingsDlg *dlg = new SettingsDlg();
569 //Category: Appearance
570 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
571 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
572 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
573 //Category: Behaviour
574 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
575 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
576 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
577 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
579 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
580 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
581 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
586 void MainWin::showAboutDlg() {
587 AboutDlg(this).exec();
590 void MainWin::closeEvent(QCloseEvent *event) {
592 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
600 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
601 if(activationReason == QSystemTrayIcon::Trigger) {
606 void MainWin::toggleVisibility() {
607 if(isHidden() /*|| !isActiveWindow()*/) {
618 // setFocus(); //Qt::ActiveWindowFocusReason
621 if(systemTrayIcon()->isSystemTrayAvailable ()) {
624 if(!systemTrayIcon()->isVisible()) {
625 systemTrayIcon()->show();
633 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
636 if(QApplication::activeWindow() != 0)
639 for(int i = start; i <= end; i++) {
640 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
642 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
645 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
646 if(flags.testFlag(Message::Backlog)) continue;
647 flags |= Message::Backlog; // we only want to trigger a highlight once!
648 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
650 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
651 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
653 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
654 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
655 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
656 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
657 QtUi::invokeNotification(bufId, sender, contents);
662 bool MainWin::event(QEvent *event) {
663 if(event->type() == QEvent::WindowActivate)
664 QtUi::closeNotifications();
665 return QMainWindow::event(event);
668 void MainWin::clientNetworkCreated(NetworkId id) {
669 const Network *net = Client::network(id);
670 QAction *act = new QAction(net->networkName(), this);
671 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
672 act->setData(QVariant::fromValue<NetworkId>(id));
673 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
674 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
676 QAction *beforeAction = 0;
677 foreach(QAction *action, _networksMenu->actions()) {
678 if(!action->data().isValid()) // ignore stock actions
680 if(net->networkName().localeAwareCompare(action->text()) < 0) {
681 beforeAction = action;
685 _networksMenu->insertAction(beforeAction, act);
688 void MainWin::clientNetworkUpdated() {
689 const Network *net = qobject_cast<const Network *>(sender());
693 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
697 action->setText(net->networkName());
699 switch(net->connectionState()) {
700 case Network::Initialized:
701 action->setIcon(SmallIcon("network-connect"));
703 case Network::Disconnected:
704 action->setIcon(SmallIcon("network-disconnect"));
707 action->setIcon(SmallIcon("network-wired"));
711 void MainWin::clientNetworkRemoved(NetworkId id) {
712 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
716 action->deleteLater();
719 void MainWin::connectOrDisconnectFromNet() {
720 QAction *act = qobject_cast<QAction *>(sender());
722 const Network *net = Client::network(act->data().value<NetworkId>());
724 if(net->connectionState() == Network::Disconnected) net->requestConnect();
725 else net->requestDisconnect();
728 void MainWin::on_actionDebugNetworkModel_triggered() {
729 QTreeView *view = new QTreeView;
730 view->setAttribute(Qt::WA_DeleteOnClose);
731 view->setWindowTitle("Debug NetworkModel View");
732 view->setModel(Client::networkModel());
733 view->setColumnWidth(0, 250);
734 view->setColumnWidth(1, 250);
735 view->setColumnWidth(2, 80);
736 view->resize(610, 300);
740 void MainWin::on_actionDebugLog_triggered() {
741 DebugLogWidget *logWidget = new DebugLogWidget(0);
745 void MainWin::saveStateToSession(const QString &sessionId) {
747 SessionSettings s(sessionId);
749 s.setValue("MainWinSize", size());
750 s.setValue("MainWinPos", pos());
751 s.setValue("MainWinState", saveState());
754 void MainWin::saveStateToSessionSettings(SessionSettings & s)
756 s.setValue("MainWinSize", size());
757 s.setValue("MainWinPos", pos());
758 s.setValue("MainWinState", saveState());
761 void MainWin::showStatusBarMessage(const QString &message) {
762 statusBar()->showMessage(message, 10000);