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 ***************************************************************************/
23 #include "bufferview.h"
24 #include "bufferviewconfig.h"
25 #include "bufferviewfilter.h"
26 #include "bufferviewmanager.h"
27 #include "channellistdlg.h"
28 #include "chatlinemodel.h"
29 #include "chatmonitorfilter.h"
30 #include "chatmonitorview.h"
32 #include "chatviewsearchbar.h"
34 #include "clientbacklogmanager.h"
35 #include "coreinfodlg.h"
36 #include "coreconnectdlg.h"
37 #include "msgprocessorstatuswidget.h"
38 #include "qtuimessageprocessor.h"
39 #include "qtuiapplication.h"
40 #include "networkmodel.h"
41 #include "buffermodel.h"
42 #include "nicklistwidget.h"
43 #include "settingsdlg.h"
44 #include "settingspagedlg.h"
45 #include "signalproxy.h"
46 #include "topicwidget.h"
47 #include "inputwidget.h"
48 #include "irclistmodel.h"
49 #include "verticaldock.h"
50 #include "uisettings.h"
51 #include "qtuisettings.h"
52 #include "jumpkeyhandler.h"
53 #include "sessionsettings.h"
55 #include "selectionmodelsynchronizer.h"
56 #include "mappedselectionmodel.h"
58 #include "settingspages/aliasessettingspage.h"
59 #include "settingspages/appearancesettingspage.h"
60 #include "settingspages/bufferviewsettingspage.h"
61 #include "settingspages/colorsettingspage.h"
62 #include "settingspages/fontssettingspage.h"
63 #include "settingspages/generalsettingspage.h"
64 #include "settingspages/highlightsettingspage.h"
65 #include "settingspages/identitiessettingspage.h"
66 #include "settingspages/networkssettingspage.h"
67 #include "settingspages/notificationssettingspage.h"
70 #include "qtuistyle.h"
72 MainWin::MainWin(QWidget *parent)
73 : QMainWindow(parent),
74 coreLagLabel(new QLabel()),
75 sslLabel(new QLabel()),
76 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
79 systray(new QSystemTrayIcon(this)),
81 activeTrayIcon(":/icons/quassel-icon-active.png"),
82 onlineTrayIcon(":/icons/quassel-icon.png"),
83 offlineTrayIcon(":/icons/quassel-icon-offline.png"),
84 trayIconActive(false),
86 timer(new QTimer(this))
88 UiSettings uiSettings;
89 QString style = uiSettings.value("Style", QString("")).toString();
91 QApplication::setStyle(style);
95 setWindowTitle("Quassel IRC");
96 setWindowIcon(offlineTrayIcon);
97 qApp->setWindowIcon(offlineTrayIcon);
98 systray->setIcon(offlineTrayIcon);
99 setWindowIconText("Quassel IRC");
101 statusBar()->showMessage(tr("Waiting for core..."));
103 installEventFilter(new JumpKeyHandler(this));
106 desktopNotifications = new org::freedesktop::Notifications(
107 "org.freedesktop.Notifications",
108 "/org/freedesktop/Notifications",
109 QDBusConnection::sessionBus(), this);
111 connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint)));
112 connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&)));
114 QtUiApplication* app = dynamic_cast<QtUiApplication*> qApp;
115 connect(app, SIGNAL(saveStateToSession(const QString&)), this, SLOT(saveStateToSession(const QString&)));
116 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), this, SLOT(saveStateToSessionSettings(SessionSettings&)));
119 void MainWin::init() {
121 if(s.value("MainWinSize").isValid())
122 resize(s.value("MainWinSize").toSize());
124 resize(QSize(800, 500));
126 Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
128 connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(saveLayout()));
130 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkCreated(NetworkId)));
131 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
135 statusBar()->showMessage(tr("Not connected to core."));
138 setDockNestingEnabled(true);
140 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
141 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
142 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
143 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
155 // restore mainwin state
156 restoreState(s.value("MainWinState").toByteArray());
158 // restore locked state of docks
159 ui.actionLockDockPositions->setChecked(s.value("LockDocks", false).toBool());
161 setDisconnectedState(); // Disable menus and stuff
162 showCoreConnectionDlg(true); // autoconnect if appropriate
164 // attach the BufferWidget to the BufferModel and the default selection
165 ui.bufferWidget->setModel(Client::bufferModel());
166 ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
167 ui.menuViews->addAction(ui.bufferWidget->searchBar()->toggleViewAction());
169 _titleSetter.setModel(Client::bufferModel());
170 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
173 MainWin::~MainWin() {
175 s.setValue("MainWinSize", size());
176 s.setValue("MainWinPos", pos());
177 s.setValue("MainWinState", saveState());
180 void MainWin::setupMenus() {
181 connect(ui.actionConnectCore, SIGNAL(triggered()), this, SLOT(showCoreConnectionDlg()));
182 connect(ui.actionDisconnectCore, SIGNAL(triggered()), Client::instance(), SLOT(disconnectFromCore()));
183 connect(ui.actionCoreInfo, SIGNAL(triggered()), this, SLOT(showCoreInfoDlg()));
184 connect(ui.actionQuit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()));
185 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
186 connect(ui.actionAboutQuassel, SIGNAL(triggered()), this, SLOT(showAboutDlg()));
187 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
190 void MainWin::setupViews() {
194 void MainWin::addBufferView(int bufferViewConfigId) {
195 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
198 void MainWin::addBufferView(BufferViewConfig *config) {
199 BufferViewDock *dock;
201 dock = new BufferViewDock(config, this);
203 dock = new BufferViewDock(this);
205 //create the view and initialize it's filter
206 BufferView *view = new BufferView(dock);
207 view->setFilteredModel(Client::bufferModel(), config);
210 connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList()));
212 Client::bufferModel()->synchronizeView(view);
214 dock->setWidget(view);
217 addDockWidget(Qt::LeftDockWidgetArea, dock);
218 ui.menuBufferViews->addAction(dock->toggleViewAction());
220 _netViews.append(dock);
223 void MainWin::removeBufferView(int bufferViewConfigId) {
225 BufferViewDock *dock;
226 foreach(QAction *action, ui.menuBufferViews->actions()) {
227 actionData = action->data();
228 if(!actionData.isValid())
231 dock = qobject_cast<BufferViewDock *>(action->parent());
232 if(dock && actionData.toInt() == bufferViewConfigId) {
233 removeAction(action);
239 void MainWin::on_actionEditNetworks_triggered() {
240 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
244 void MainWin::on_actionManageViews_triggered() {
245 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
249 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
250 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
251 foreach(VerticalDock *dock, docks) {
252 dock->showTitle(!lock);
254 QtUiSettings().setValue("LockDocks", lock);
257 void MainWin::setupNickWidget() {
259 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
260 nickDock->setObjectName("NickDock");
261 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
263 nickListWidget = new NickListWidget(nickDock);
264 nickDock->setWidget(nickListWidget);
266 addDockWidget(Qt::RightDockWidgetArea, nickDock);
267 ui.menuViews->addAction(nickDock->toggleViewAction());
268 // See NickListDock::NickListDock();
269 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
271 // attach the NickListWidget to the BufferModel and the default selection
272 nickListWidget->setModel(Client::bufferModel());
273 nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
276 void MainWin::setupChatMonitor() {
277 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
278 dock->setObjectName("ChatMonitorDock");
280 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
281 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
283 dock->setWidget(chatView);
286 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
287 ui.menuViews->addAction(dock->toggleViewAction());
290 void MainWin::setupInputWidget() {
291 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
292 dock->setObjectName("InputDock");
294 InputWidget *inputWidget = new InputWidget(dock);
295 dock->setWidget(inputWidget);
297 addDockWidget(Qt::BottomDockWidgetArea, dock);
299 ui.menuViews->addAction(dock->toggleViewAction());
301 inputWidget->setModel(Client::bufferModel());
302 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
304 ui.bufferWidget->setFocusProxy(inputWidget);
307 void MainWin::setupTopicWidget() {
308 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
309 dock->setObjectName("TopicDock");
310 TopicWidget *topicwidget = new TopicWidget(dock);
312 dock->setWidget(topicwidget);
314 topicwidget->setModel(Client::bufferModel());
315 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
317 addDockWidget(Qt::TopDockWidgetArea, dock);
319 ui.menuViews->addAction(dock->toggleViewAction());
322 void MainWin::setupStatusBar() {
323 // MessageProcessor progress
324 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
325 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
328 updateLagIndicator(0);
329 statusBar()->addPermanentWidget(coreLagLabel);
330 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
333 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
334 sslLabel->setPixmap(QPixmap());
335 statusBar()->addPermanentWidget(sslLabel);
337 ui.menuViews->addSeparator();
338 QAction *showStatusbar = ui.menuViews->addAction(tr("Statusbar"));
339 showStatusbar->setCheckable(true);
341 UiSettings uiSettings;
343 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
344 showStatusbar->setChecked(enabled);
345 enabled ? statusBar()->show() : statusBar()->hide();
347 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
348 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
351 void MainWin::saveStatusBarStatus(bool enabled) {
352 UiSettings uiSettings;
353 uiSettings.setValue("ShowStatusBar", enabled);
356 void MainWin::setupSystray() {
357 connect(timer, SIGNAL(timeout()), this, SLOT(makeTrayIconBlink()));
358 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
359 this, SLOT(messagesInserted(const QModelIndex &, int, int)));
361 systrayMenu = new QMenu(this);
362 systrayMenu->addAction(ui.actionAboutQuassel);
363 systrayMenu->addSeparator();
364 systrayMenu->addAction(ui.actionConnectCore);
365 systrayMenu->addAction(ui.actionDisconnectCore);
366 systrayMenu->addSeparator();
367 systrayMenu->addAction(ui.actionQuit);
369 systray->setContextMenu(systrayMenu);
372 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
377 connect(systray, SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
378 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
383 void MainWin::changeEvent(QEvent *event) {
384 if(event->type() == QEvent::WindowStateChange) {
385 if(windowState() & Qt::WindowMinimized) {
387 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
395 void MainWin::connectedToCore() {
396 Q_CHECK_PTR(Client::bufferViewManager());
397 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
398 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
399 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
401 foreach(BufferInfo id, Client::allBufferInfos()) {
402 Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1);
407 void MainWin::setConnectedState() {
408 //ui.menuCore->setEnabled(true);
409 ui.actionConnectCore->setEnabled(false);
410 ui.actionDisconnectCore->setEnabled(true);
411 ui.actionCoreInfo->setEnabled(true);
412 ui.menuViews->setEnabled(true);
413 ui.bufferWidget->show();
414 statusBar()->showMessage(tr("Connected to core."));
415 setWindowIcon(onlineTrayIcon);
416 qApp->setWindowIcon(onlineTrayIcon);
417 systray->setIcon(onlineTrayIcon);
418 if(sslLabel->width() == 0)
419 sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/no-ssl")));
422 void MainWin::loadLayout() {
424 int accountId = Client::currentCoreAccount().toInt();
425 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
428 void MainWin::saveLayout() {
430 int accountId = Client::currentCoreAccount().toInt();
431 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
434 void MainWin::updateLagIndicator(int lag) {
435 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
439 void MainWin::securedConnection() {
440 // todo: make status bar entry
441 sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/ssl")));
444 void MainWin::disconnectedFromCore() {
445 // save core specific layout and remove bufferviews;
448 BufferViewDock *dock;
449 foreach(QAction *action, ui.menuBufferViews->actions()) {
450 actionData = action->data();
451 if(!actionData.isValid())
454 dock = qobject_cast<BufferViewDock *>(action->parent());
455 if(dock && actionData.toInt() != -1) {
456 removeAction(action);
461 restoreState(s.value("MainWinState").toByteArray());
462 setDisconnectedState();
465 void MainWin::setDisconnectedState() {
466 //ui.menuCore->setEnabled(false);
467 ui.actionConnectCore->setEnabled(true);
468 ui.actionDisconnectCore->setEnabled(false);
469 ui.actionCoreInfo->setEnabled(false);
470 ui.menuViews->setEnabled(false);
471 ui.bufferWidget->hide();
472 statusBar()->showMessage(tr("Not connected to core."));
473 setWindowIcon(offlineTrayIcon);
474 qApp->setWindowIcon(offlineTrayIcon);
475 systray->setIcon(offlineTrayIcon);
476 sslLabel->setPixmap(QPixmap());
479 void MainWin::showCoreConnectionDlg(bool autoConnect) {
480 CoreConnectDlg(autoConnect, this).exec();
483 void MainWin::showChannelList(NetworkId netId) {
484 ChannelListDlg *channelListDlg = new ChannelListDlg();
486 if(!netId.isValid()) {
487 QAction *action = qobject_cast<QAction *>(sender());
489 netId = action->data().value<NetworkId>();
492 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
493 channelListDlg->setNetwork(netId);
494 channelListDlg->show();
497 void MainWin::showCoreInfoDlg() {
498 CoreInfoDlg(this).exec();
501 void MainWin::showSettingsDlg() {
502 SettingsDlg *dlg = new SettingsDlg();
504 //Category: Appearance
505 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
506 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
507 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
508 //Category: Behaviour
509 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
510 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
511 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
512 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
514 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
515 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
516 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
521 void MainWin::showAboutDlg() {
522 AboutDlg(this).exec();
525 void MainWin::closeEvent(QCloseEvent *event) {
527 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
535 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
536 if(activationReason == QSystemTrayIcon::Trigger) {
541 void MainWin::toggleVisibility() {
542 if(isHidden() /*|| !isActiveWindow()*/) {
553 // setFocus(); //Qt::ActiveWindowFocusReason
556 if(systray->isSystemTrayAvailable ()) {
559 if(!systray->isVisible()) {
568 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
571 if(QApplication::activeWindow() != 0)
574 for(int i = start; i <= end; i++) {
575 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
577 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
580 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
581 if(flags.testFlag(Message::Backlog)) continue;
582 flags |= Message::Backlog; // we only want to trigger a highlight once!
583 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
585 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
586 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
588 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
589 QString title = Client::networkModel()->networkName(bufId) + " - " + Client::networkModel()->bufferName(bufId);
591 // FIXME Don't instantiate this for every highlight...
592 UiSettings uiSettings;
594 bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool();
595 bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool();
596 if(displayBubble || displayDesktop) {
597 if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) {
598 QString text = idx.data(ChatLineModel::DisplayRole).toString();
599 if(displayBubble) displayTrayIconMessage(title, text);
601 if(displayDesktop) sendDesktopNotification(title, text);
604 if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
605 QApplication::alert(this);
606 setTrayIconActivity(true);
613 bool MainWin::event(QEvent *event) {
614 if(event->type() == QEvent::WindowActivate)
615 setTrayIconActivity(false);
616 return QMainWindow::event(event);
622 Using the notification-daemon from Freedesktop's Galago project
623 http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify
625 void MainWin::sendDesktopNotification(const QString &title, const QString &message) {
627 QMap<QString, QVariant> hints;
628 UiSettings uiSettings;
630 hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up
631 hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up
633 actions << "click" << "Click Me!";
635 QDBusReply<uint> reply = desktopNotifications->Notify(
636 "Quassel", // Application name
637 notificationId, // ID of previous notification to replace
638 "", // Icon to display
639 title, // Summary / Header of the message to display
640 QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display
641 actions, // Actions from which the user may choose
642 hints, // Hints to the server displaying the message
643 uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds
646 if(!reply.isValid()) {
648 // could also happen if no notification service runs, so... whatever :)
649 //qDebug() << "Error on sending notification..." << reply.error();
653 notificationId = reply.value();
655 // qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString();
659 void MainWin::desktopNotificationClosed(uint id, uint reason) {
660 Q_UNUSED(id); Q_UNUSED(reason);
661 // qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString();
666 void MainWin::desktopNotificationInvoked(uint id, const QString & action) {
667 Q_UNUSED(id); Q_UNUSED(action);
668 // qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString();
671 #endif /* HAVE_DBUS */
673 void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
674 systray->showMessage(title, message);
677 void MainWin::setTrayIconActivity(bool active) {
679 if(!timer->isActive())
683 systray->setIcon(onlineTrayIcon);
687 void MainWin::makeTrayIconBlink() {
689 systray->setIcon(onlineTrayIcon);
690 trayIconActive = false;
692 systray->setIcon(activeTrayIcon);
693 trayIconActive = true;
697 void MainWin::clientNetworkCreated(NetworkId id) {
698 const Network *net = Client::network(id);
699 QAction *act = new QAction(net->networkName(), this);
700 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
701 act->setData(QVariant::fromValue<NetworkId>(id));
702 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
703 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
705 QAction *beforeAction = 0;
706 foreach(QAction *action, ui.menuNetworks->actions()) {
707 if(action->isSeparator()) {
708 beforeAction = action;
711 if(net->networkName().localeAwareCompare(action->text()) < 0) {
712 beforeAction = action;
716 Q_CHECK_PTR(beforeAction);
717 ui.menuNetworks->insertAction(beforeAction, act);
720 void MainWin::clientNetworkUpdated() {
721 const Network *net = qobject_cast<const Network *>(sender());
725 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
729 action->setText(net->networkName());
731 switch(net->connectionState()) {
732 case Network::Initialized:
733 action->setIcon(QIcon(":/16x16/actions/network-connect"));
735 case Network::Disconnected:
736 action->setIcon(QIcon(":/16x16/actions/network-disconnect"));
739 action->setIcon(QIcon(":/16x16/actions/gear"));
743 void MainWin::clientNetworkRemoved(NetworkId id) {
744 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
748 action->deleteLater();
751 void MainWin::connectOrDisconnectFromNet() {
752 QAction *act = qobject_cast<QAction *>(sender());
754 const Network *net = Client::network(act->data().value<NetworkId>());
756 if(net->connectionState() == Network::Disconnected) net->requestConnect();
757 else net->requestDisconnect();
762 void MainWin::on_actionDebugNetworkModel_triggered(bool) {
763 QTreeView *view = new QTreeView;
764 view->setAttribute(Qt::WA_DeleteOnClose);
765 view->setWindowTitle("Debug NetworkModel View");
766 view->setModel(Client::networkModel());
767 view->setColumnWidth(0, 250);
768 view->setColumnWidth(1, 250);
769 view->setColumnWidth(2, 80);
770 view->resize(610, 300);
774 void MainWin::saveStateToSession(const QString &sessionId) {
776 SessionSettings s(sessionId);
778 s.setValue("MainWinSize", size());
779 s.setValue("MainWinPos", pos());
780 s.setValue("MainWinState", saveState());
783 void MainWin::saveStateToSessionSettings(SessionSettings & s)
785 s.setValue("MainWinSize", size());
786 s.setValue("MainWinPos", pos());
787 s.setValue("MainWinState", saveState());