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"
33 #include "clientbacklogmanager.h"
34 #include "coreinfodlg.h"
35 #include "coreconnectdlg.h"
36 #include "msgprocessorstatuswidget.h"
37 #include "qtuimessageprocessor.h"
38 #include "networkmodel.h"
39 #include "buffermodel.h"
40 #include "nicklistwidget.h"
41 #include "settingsdlg.h"
42 #include "settingspagedlg.h"
43 #include "signalproxy.h"
44 #include "topicwidget.h"
45 #include "inputwidget.h"
46 #include "irclistmodel.h"
47 #include "verticaldock.h"
48 #include "uisettings.h"
49 #include "qtuisettings.h"
50 #include "jumpkeyhandler.h"
52 #include "selectionmodelsynchronizer.h"
53 #include "mappedselectionmodel.h"
55 #include "settingspages/aliasessettingspage.h"
56 #include "settingspages/appearancesettingspage.h"
57 #include "settingspages/bufferviewsettingspage.h"
58 #include "settingspages/colorsettingspage.h"
59 #include "settingspages/fontssettingspage.h"
60 #include "settingspages/generalsettingspage.h"
61 #include "settingspages/highlightsettingspage.h"
62 #include "settingspages/identitiessettingspage.h"
63 #include "settingspages/networkssettingspage.h"
64 #include "settingspages/notificationssettingspage.h"
67 #include "qtuistyle.h"
69 MainWin::MainWin(QWidget *parent)
70 : QMainWindow(parent),
71 coreLagLabel(new QLabel()),
72 sslLabel(new QLabel()),
73 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
76 systray(new QSystemTrayIcon(this)),
78 activeTrayIcon(":/icons/quassel-icon-active.png"),
79 onlineTrayIcon(":/icons/quassel-icon.png"),
80 offlineTrayIcon(":/icons/quassel-icon-offline.png"),
81 trayIconActive(false),
83 timer(new QTimer(this))
85 UiSettings uiSettings;
86 QString style = uiSettings.value("Style", QString("")).toString();
88 QApplication::setStyle(style);
92 setWindowTitle("Quassel IRC");
93 setWindowIcon(offlineTrayIcon);
94 qApp->setWindowIcon(offlineTrayIcon);
95 systray->setIcon(offlineTrayIcon);
96 setWindowIconText("Quassel IRC");
98 statusBar()->showMessage(tr("Waiting for core..."));
100 installEventFilter(new JumpKeyHandler(this));
103 desktopNotifications = new org::freedesktop::Notifications(
104 "org.freedesktop.Notifications",
105 "/org/freedesktop/Notifications",
106 QDBusConnection::sessionBus(), this);
108 connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint)));
109 connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&)));
113 void MainWin::init() {
115 if(s.value("MainWinSize").isValid())
116 resize(s.value("MainWinSize").toSize());
118 resize(QSize(800, 500));
120 Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
122 connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(saveLayout()));
124 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkCreated(NetworkId)));
125 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
129 statusBar()->showMessage(tr("Not connected to core."));
132 setDockNestingEnabled(true);
134 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
135 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
136 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
137 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
149 // restore mainwin state
150 restoreState(s.value("MainWinState").toByteArray());
152 // restore locked state of docks
153 ui.actionLockDockPositions->setChecked(s.value("LockDocks", false).toBool());
155 setDisconnectedState(); // Disable menus and stuff
156 showCoreConnectionDlg(true); // autoconnect if appropriate
158 // attach the BufferWidget to the BufferModel and the default selection
159 ui.bufferWidget->setModel(Client::bufferModel());
160 ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
162 _titleSetter.setModel(Client::bufferModel());
163 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
166 MainWin::~MainWin() {
168 s.setValue("MainWinSize", size());
169 s.setValue("MainWinPos", pos());
170 s.setValue("MainWinState", saveState());
173 void MainWin::setupMenus() {
174 connect(ui.actionConnectCore, SIGNAL(triggered()), this, SLOT(showCoreConnectionDlg()));
175 connect(ui.actionDisconnectCore, SIGNAL(triggered()), Client::instance(), SLOT(disconnectFromCore()));
176 connect(ui.actionCoreInfo, SIGNAL(triggered()), this, SLOT(showCoreInfoDlg()));
177 connect(ui.actionQuit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()));
178 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
179 connect(ui.actionAboutQuassel, SIGNAL(triggered()), this, SLOT(showAboutDlg()));
180 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
183 void MainWin::setupViews() {
187 void MainWin::addBufferView(int bufferViewConfigId) {
188 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
191 void MainWin::addBufferView(BufferViewConfig *config) {
192 BufferViewDock *dock;
194 dock = new BufferViewDock(config, this);
196 dock = new BufferViewDock(this);
198 //create the view and initialize it's filter
199 BufferView *view = new BufferView(dock);
200 view->setFilteredModel(Client::bufferModel(), config);
203 connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList()));
205 Client::bufferModel()->synchronizeView(view);
207 dock->setWidget(view);
210 addDockWidget(Qt::LeftDockWidgetArea, dock);
211 ui.menuBufferViews->addAction(dock->toggleViewAction());
213 _netViews.append(dock);
216 void MainWin::removeBufferView(int bufferViewConfigId) {
218 BufferViewDock *dock;
219 foreach(QAction *action, ui.menuBufferViews->actions()) {
220 actionData = action->data();
221 if(!actionData.isValid())
224 dock = qobject_cast<BufferViewDock *>(action->parent());
225 if(dock && actionData.toInt() == bufferViewConfigId) {
226 removeAction(action);
232 void MainWin::on_actionEditNetworks_triggered() {
233 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
237 void MainWin::on_actionManageViews_triggered() {
238 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
242 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
243 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
244 foreach(VerticalDock *dock, docks) {
245 dock->showTitle(!lock);
247 QtUiSettings().setValue("LockDocks", lock);
250 void MainWin::setupNickWidget() {
252 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
253 nickDock->setObjectName("NickDock");
254 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
256 nickListWidget = new NickListWidget(nickDock);
257 nickDock->setWidget(nickListWidget);
259 addDockWidget(Qt::RightDockWidgetArea, nickDock);
260 ui.menuViews->addAction(nickDock->toggleViewAction());
261 // See NickListDock::NickListDock();
262 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
264 // attach the NickListWidget to the BufferModel and the default selection
265 nickListWidget->setModel(Client::bufferModel());
266 nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
269 void MainWin::setupChatMonitor() {
270 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
271 dock->setObjectName("ChatMonitorDock");
273 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
274 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
276 dock->setWidget(chatView);
279 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
280 ui.menuViews->addAction(dock->toggleViewAction());
283 void MainWin::setupInputWidget() {
284 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
285 dock->setObjectName("InputDock");
287 InputWidget *inputWidget = new InputWidget(dock);
288 dock->setWidget(inputWidget);
290 addDockWidget(Qt::BottomDockWidgetArea, dock);
292 ui.menuViews->addAction(dock->toggleViewAction());
294 inputWidget->setModel(Client::bufferModel());
295 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
297 ui.bufferWidget->setFocusProxy(inputWidget);
300 void MainWin::setupTopicWidget() {
301 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
302 dock->setObjectName("TopicDock");
303 TopicWidget *topicwidget = new TopicWidget(dock);
305 dock->setWidget(topicwidget);
307 topicwidget->setModel(Client::bufferModel());
308 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
310 addDockWidget(Qt::TopDockWidgetArea, dock);
312 ui.menuViews->addAction(dock->toggleViewAction());
315 void MainWin::setupStatusBar() {
316 // MessageProcessor progress
317 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
318 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
321 updateLagIndicator(0);
322 statusBar()->addPermanentWidget(coreLagLabel);
323 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
326 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
327 sslLabel->setPixmap(QPixmap());
328 statusBar()->addPermanentWidget(sslLabel);
330 ui.menuViews->addSeparator();
331 QAction *showStatusbar = ui.menuViews->addAction(tr("Statusbar"));
332 showStatusbar->setCheckable(true);
334 UiSettings uiSettings;
336 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
337 showStatusbar->setChecked(enabled);
338 enabled ? statusBar()->show() : statusBar()->hide();
340 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
341 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
344 void MainWin::saveStatusBarStatus(bool enabled) {
345 UiSettings uiSettings;
346 uiSettings.setValue("ShowStatusBar", enabled);
349 void MainWin::setupSystray() {
350 connect(timer, SIGNAL(timeout()), this, SLOT(makeTrayIconBlink()));
351 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
352 this, SLOT(messagesInserted(const QModelIndex &, int, int)));
354 systrayMenu = new QMenu(this);
355 systrayMenu->addAction(ui.actionAboutQuassel);
356 systrayMenu->addSeparator();
357 systrayMenu->addAction(ui.actionConnectCore);
358 systrayMenu->addAction(ui.actionDisconnectCore);
359 systrayMenu->addSeparator();
360 systrayMenu->addAction(ui.actionQuit);
362 systray->setContextMenu(systrayMenu);
365 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
370 connect(systray, SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
371 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
376 void MainWin::changeEvent(QEvent *event) {
377 if(event->type() == QEvent::WindowStateChange) {
378 if(windowState() & Qt::WindowMinimized) {
380 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
388 void MainWin::connectedToCore() {
389 Q_CHECK_PTR(Client::bufferViewManager());
390 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
391 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
392 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
394 foreach(BufferInfo id, Client::allBufferInfos()) {
395 Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1);
400 void MainWin::setConnectedState() {
401 //ui.menuCore->setEnabled(true);
402 ui.actionConnectCore->setEnabled(false);
403 ui.actionDisconnectCore->setEnabled(true);
404 ui.actionCoreInfo->setEnabled(true);
405 ui.menuViews->setEnabled(true);
406 ui.bufferWidget->show();
407 statusBar()->showMessage(tr("Connected to core."));
408 setWindowIcon(onlineTrayIcon);
409 qApp->setWindowIcon(onlineTrayIcon);
410 systray->setIcon(onlineTrayIcon);
411 if(sslLabel->width() == 0)
412 sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/no-ssl")));
415 void MainWin::loadLayout() {
417 int accountId = Client::currentCoreAccount().toInt();
418 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
421 void MainWin::saveLayout() {
423 int accountId = Client::currentCoreAccount().toInt();
424 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
427 void MainWin::updateLagIndicator(int lag) {
428 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
432 void MainWin::securedConnection() {
433 // todo: make status bar entry
434 sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/ssl")));
437 void MainWin::disconnectedFromCore() {
438 // save core specific layout and remove bufferviews;
441 BufferViewDock *dock;
442 foreach(QAction *action, ui.menuBufferViews->actions()) {
443 actionData = action->data();
444 if(!actionData.isValid())
447 dock = qobject_cast<BufferViewDock *>(action->parent());
448 if(dock && actionData.toInt() != -1) {
449 removeAction(action);
454 restoreState(s.value("MainWinState").toByteArray());
455 setDisconnectedState();
458 void MainWin::setDisconnectedState() {
459 //ui.menuCore->setEnabled(false);
460 ui.actionConnectCore->setEnabled(true);
461 ui.actionDisconnectCore->setEnabled(false);
462 ui.actionCoreInfo->setEnabled(false);
463 ui.menuViews->setEnabled(false);
464 ui.bufferWidget->hide();
465 statusBar()->showMessage(tr("Not connected to core."));
466 setWindowIcon(offlineTrayIcon);
467 qApp->setWindowIcon(offlineTrayIcon);
468 systray->setIcon(offlineTrayIcon);
469 sslLabel->setPixmap(QPixmap());
472 void MainWin::showCoreConnectionDlg(bool autoConnect) {
473 CoreConnectDlg(autoConnect, this).exec();
476 void MainWin::showChannelList(NetworkId netId) {
477 ChannelListDlg *channelListDlg = new ChannelListDlg();
479 if(!netId.isValid()) {
480 QAction *action = qobject_cast<QAction *>(sender());
482 netId = action->data().value<NetworkId>();
485 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
486 channelListDlg->setNetwork(netId);
487 channelListDlg->show();
490 void MainWin::showCoreInfoDlg() {
491 CoreInfoDlg(this).exec();
494 void MainWin::showSettingsDlg() {
495 SettingsDlg *dlg = new SettingsDlg();
497 //Category: Appearance
498 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
499 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
500 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
501 //Category: Behaviour
502 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
503 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
504 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
505 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
507 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
508 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
509 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
514 void MainWin::showAboutDlg() {
515 AboutDlg(this).exec();
518 void MainWin::closeEvent(QCloseEvent *event) {
520 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
528 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
529 if(activationReason == QSystemTrayIcon::Trigger) {
534 void MainWin::toggleVisibility() {
535 if(isHidden() /*|| !isActiveWindow()*/) {
546 // setFocus(); //Qt::ActiveWindowFocusReason
549 if(systray->isSystemTrayAvailable ()) {
552 if(!systray->isVisible()) {
561 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
563 if(QApplication::activeWindow() != 0)
569 for(int i = start; i <= end; i++) {
570 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
572 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
575 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
576 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
577 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
579 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
580 QString title = Client::networkModel()->networkName(bufId) + " - " + Client::networkModel()->bufferName(bufId);
582 // FIXME Don't instantiate this for every highlight...
583 UiSettings uiSettings;
585 bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool();
586 bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool();
587 if(displayBubble || displayDesktop) {
588 if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) {
589 QString text = idx.data(ChatLineModel::DisplayRole).toString();
590 if(displayBubble) displayTrayIconMessage(title, text);
592 if(displayDesktop) sendDesktopNotification(title, text);
595 if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
596 QApplication::alert(this);
597 setTrayIconActivity(true);
604 bool MainWin::event(QEvent *event) {
605 if(event->type() == QEvent::WindowActivate)
606 setTrayIconActivity(false);
607 return QMainWindow::event(event);
613 Using the notification-daemon from Freedesktop's Galago project
614 http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify
616 void MainWin::sendDesktopNotification(const QString &title, const QString &message) {
618 QMap<QString, QVariant> hints;
619 UiSettings uiSettings;
621 hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up
622 hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up
624 actions << "click" << "Click Me!";
626 QDBusReply<uint> reply = desktopNotifications->Notify(
627 "Quassel", // Application name
628 notificationId, // ID of previous notification to replace
629 "", // Icon to display
630 title, // Summary / Header of the message to display
631 QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display
632 actions, // Actions from which the user may choose
633 hints, // Hints to the server displaying the message
634 uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds
637 if(!reply.isValid()) {
639 // could also happen if no notification service runs, so... whatever :)
640 //qDebug() << "Error on sending notification..." << reply.error();
644 notificationId = reply.value();
646 // qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString();
650 void MainWin::desktopNotificationClosed(uint id, uint reason) {
651 Q_UNUSED(id); Q_UNUSED(reason);
652 // qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString();
657 void MainWin::desktopNotificationInvoked(uint id, const QString & action) {
658 Q_UNUSED(id); Q_UNUSED(action);
659 // qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString();
662 #endif /* HAVE_DBUS */
664 void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
665 systray->showMessage(title, message);
668 void MainWin::setTrayIconActivity(bool active) {
670 if(!timer->isActive())
674 systray->setIcon(onlineTrayIcon);
678 void MainWin::makeTrayIconBlink() {
680 systray->setIcon(onlineTrayIcon);
681 trayIconActive = false;
683 systray->setIcon(activeTrayIcon);
684 trayIconActive = true;
688 void MainWin::clientNetworkCreated(NetworkId id) {
689 const Network *net = Client::network(id);
690 QAction *act = new QAction(net->networkName(), this);
691 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
692 act->setData(QVariant::fromValue<NetworkId>(id));
693 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
694 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
696 QAction *beforeAction = 0;
697 foreach(QAction *action, ui.menuNetworks->actions()) {
698 if(action->isSeparator()) {
699 beforeAction = action;
702 if(net->networkName().localeAwareCompare(action->text()) < 0) {
703 beforeAction = action;
707 Q_CHECK_PTR(beforeAction);
708 ui.menuNetworks->insertAction(beforeAction, act);
711 void MainWin::clientNetworkUpdated() {
712 const Network *net = qobject_cast<const Network *>(sender());
716 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
720 action->setText(net->networkName());
722 switch(net->connectionState()) {
723 case Network::Initialized:
724 action->setIcon(QIcon(":/16x16/actions/network-connect"));
726 case Network::Disconnected:
727 action->setIcon(QIcon(":/16x16/actions/network-disconnect"));
730 action->setIcon(QIcon(":/16x16/actions/gear"));
734 void MainWin::clientNetworkRemoved(NetworkId id) {
735 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
739 action->deleteLater();
742 void MainWin::connectOrDisconnectFromNet() {
743 QAction *act = qobject_cast<QAction *>(sender());
745 const Network *net = Client::network(act->data().value<NetworkId>());
747 if(net->connectionState() == Network::Disconnected) net->requestConnect();
748 else net->requestDisconnect();
753 void MainWin::on_actionDebugNetworkModel_triggered(bool) {
754 QTreeView *view = new QTreeView;
755 view->setAttribute(Qt::WA_DeleteOnClose);
756 view->setWindowTitle("Debug NetworkModel View");
757 view->setModel(Client::networkModel());
758 view->setColumnWidth(0, 250);
759 view->setColumnWidth(1, 250);
760 view->setColumnWidth(2, 80);
761 view->resize(610, 300);