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 "chatwidget.h"
24 #include "bufferview.h"
25 #include "bufferviewconfig.h"
26 #include "bufferviewfilter.h"
27 #include "bufferviewmanager.h"
28 #include "channellistdlg.h"
30 #include "clientbacklogmanager.h"
31 #include "coreinfodlg.h"
32 #include "coreconnectdlg.h"
33 #include "networkmodel.h"
34 #include "buffermodel.h"
35 #include "nicklistwidget.h"
36 #include "settingsdlg.h"
37 #include "settingspagedlg.h"
38 #include "signalproxy.h"
39 #include "topicwidget.h"
40 #include "inputwidget.h"
41 #include "irclistmodel.h"
42 #include "verticaldock.h"
43 #include "uisettings.h"
45 #include "qtuisettings.h"
46 #include "jumpkeyhandler.h"
48 #include "uisettings.h"
50 #include "selectionmodelsynchronizer.h"
51 #include "mappedselectionmodel.h"
53 #include "settingspages/aliasessettingspage.h"
54 #include "settingspages/appearancesettingspage.h"
55 #include "settingspages/bufferviewsettingspage.h"
56 #include "settingspages/colorsettingspage.h"
57 #include "settingspages/fontssettingspage.h"
58 #include "settingspages/generalsettingspage.h"
59 #include "settingspages/highlightsettingspage.h"
60 #include "settingspages/identitiessettingspage.h"
61 #include "settingspages/networkssettingspage.h"
64 #include "debugconsole.h"
66 #include "qtuistyle.h"
68 MainWin::MainWin(QtUi *_gui, QWidget *parent)
69 : QMainWindow(parent),
71 coreLagLabel(new QLabel()),
72 sslLabel(new QLabel()),
74 systray(new QSystemTrayIcon(this)),
75 activeTrayIcon(":/icons/quassel-icon-active.png"),
76 onlineTrayIcon(":/icons/quassel-icon.png"),
77 offlineTrayIcon(":/icons/quassel-icon-offline.png"),
78 trayIconActive(false),
79 timer(new QTimer(this)),
80 channelListDlg(new ChannelListDlg(this)),
81 settingsDlg(new SettingsDlg(this)),
82 debugConsole(new DebugConsole(this))
84 UiSettings uiSettings;
85 loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
87 QString style = uiSettings.value("Style", QString("")).toString();
89 QApplication::setStyle(style);
93 setWindowTitle("Quassel IRC");
94 setWindowIcon(offlineTrayIcon);
95 qApp->setWindowIcon(offlineTrayIcon);
96 systray->setIcon(offlineTrayIcon);
97 setWindowIconText("Quassel IRC");
99 statusBar()->showMessage(tr("Waiting for core..."));
101 installEventFilter(new JumpKeyHandler(this));
103 UiSettings uiSettings;
104 QString style = uiSettings.value("Style", QString("")).toString();
106 QApplication::setStyle(style);
110 desktopNotifications = new org::freedesktop::Notifications(
111 "org.freedesktop.Notifications",
112 "/org/freedesktop/Notifications",
113 QDBusConnection::sessionBus(), this);
115 connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint)));
116 connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&)));
120 void MainWin::init() {
122 if(s.value("MainWinSize").isValid())
123 resize(s.value("MainWinSize").toSize());
125 resize(QSize(800, 500));
127 Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
129 connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(saveLayout()));
131 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkCreated(NetworkId)));
132 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
136 statusBar()->showMessage(tr("Not connected to core."));
139 setDockNestingEnabled(true);
141 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
142 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
143 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
144 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
158 // restore mainwin state
159 restoreState(s.value("MainWinState").toByteArray());
161 // restore locked state of docks
162 ui.actionLockDockPositions->setChecked(s.value("LockDocks", false).toBool());
165 setDisconnectedState(); // Disable menus and stuff
166 showCoreConnectionDlg(true); // autoconnect if appropriate
168 // attach the BufferWidget to the BufferModel and the default selection
169 ui.bufferWidget->setModel(Client::bufferModel());
170 ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
172 _titleSetter.setModel(Client::bufferModel());
173 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
176 MainWin::~MainWin() {
178 s.setValue("MainWinSize", size());
179 s.setValue("MainWinPos", pos());
180 s.setValue("MainWinState", saveState());
183 void MainWin::setupMenus() {
184 connect(ui.actionConnectCore, SIGNAL(triggered()), this, SLOT(showCoreConnectionDlg()));
185 connect(ui.actionDisconnectCore, SIGNAL(triggered()), Client::instance(), SLOT(disconnectFromCore()));
186 connect(ui.actionCoreInfo, SIGNAL(triggered()), this, SLOT(showCoreInfoDlg()));
187 connect(ui.actionQuit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()));
188 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
189 // connect(ui.actionDebug_Console, SIGNAL(triggered()), this, SLOT(showDebugConsole()));
190 connect(ui.actionAboutQuassel, SIGNAL(triggered()), this, SLOT(showAboutDlg()));
191 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
194 void MainWin::setupViews() {
198 void MainWin::addBufferView(int bufferViewConfigId) {
199 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
202 void MainWin::addBufferView(BufferViewConfig *config) {
203 BufferViewDock *dock;
205 dock = new BufferViewDock(config, this);
207 dock = new BufferViewDock(this);
209 //create the view and initialize it's filter
210 BufferView *view = new BufferView(dock);
211 view->setFilteredModel(Client::bufferModel(), config);
214 connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList()));
216 Client::bufferModel()->synchronizeView(view);
218 dock->setWidget(view);
221 addDockWidget(Qt::LeftDockWidgetArea, dock);
222 ui.menuBufferViews->addAction(dock->toggleViewAction());
224 _netViews.append(dock);
227 void MainWin::removeBufferView(int bufferViewConfigId) {
229 BufferViewDock *dock;
230 foreach(QAction *action, ui.menuBufferViews->actions()) {
231 actionData = action->data();
232 if(!actionData.isValid())
235 dock = qobject_cast<BufferViewDock *>(action->parent());
236 if(dock && actionData.toInt() == bufferViewConfigId) {
237 removeAction(action);
243 void MainWin::setupSettingsDlg() {
244 //Category: Appearance
245 settingsDlg->registerSettingsPage(new ColorSettingsPage(settingsDlg));
246 settingsDlg->registerSettingsPage(new FontsSettingsPage(settingsDlg));
247 settingsDlg->registerSettingsPage(new AppearanceSettingsPage(settingsDlg)); //General
248 //Category: Behaviour
249 settingsDlg->registerSettingsPage(new GeneralSettingsPage(settingsDlg));
250 settingsDlg->registerSettingsPage(new HighlightSettingsPage(settingsDlg));
251 settingsDlg->registerSettingsPage(new AliasesSettingsPage(settingsDlg));
253 settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg));
254 settingsDlg->registerSettingsPage(new NetworksSettingsPage(settingsDlg));
255 settingsDlg->registerSettingsPage(new BufferViewSettingsPage(settingsDlg));
258 void MainWin::on_actionEditNetworks_triggered() {
259 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
263 void MainWin::on_actionManageViews_triggered() {
264 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
268 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
269 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
270 foreach(VerticalDock *dock, docks) {
271 dock->showTitle(!lock);
273 QtUiSettings().setValue("LockDocks", lock);
276 void MainWin::setupNickWidget() {
278 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
279 nickDock->setObjectName("NickDock");
280 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
282 nickListWidget = new NickListWidget(nickDock);
283 nickDock->setWidget(nickListWidget);
285 addDockWidget(Qt::RightDockWidgetArea, nickDock);
286 ui.menuViews->addAction(nickDock->toggleViewAction());
287 // See NickListDock::NickListDock();
288 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
290 // attach the NickListWidget to the BufferModel and the default selection
291 nickListWidget->setModel(Client::bufferModel());
292 nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
295 void MainWin::setupChatMonitor() {
297 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
298 dock->setObjectName("ChatMonitorDock");
300 ChatWidget *chatWidget = new ChatWidget(0, this);
302 dock->setWidget(chatWidget);
305 Buffer *buf = Client::monitorBuffer();
309 chatWidget->setContents(buf->contents());
310 connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
311 connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
313 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
314 ui.menuViews->addAction(dock->toggleViewAction());
318 void MainWin::setupInputWidget() {
319 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
320 dock->setObjectName("InputDock");
322 InputWidget *inputWidget = new InputWidget(dock);
323 dock->setWidget(inputWidget);
325 addDockWidget(Qt::BottomDockWidgetArea, dock);
327 ui.menuViews->addAction(dock->toggleViewAction());
329 inputWidget->setModel(Client::bufferModel());
330 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
332 ui.bufferWidget->setFocusProxy(inputWidget);
335 void MainWin::setupTopicWidget() {
336 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
337 dock->setObjectName("TopicDock");
338 TopicWidget *topicwidget = new TopicWidget(dock);
339 connect(topicwidget, SIGNAL(topicChanged(const QString &)), this, SLOT(changeTopic(const QString &)));
341 dock->setWidget(topicwidget);
343 topicwidget->setModel(Client::bufferModel());
344 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
346 addDockWidget(Qt::TopDockWidgetArea, dock);
348 ui.menuViews->addAction(dock->toggleViewAction());
351 void MainWin::setupStatusBar() {
353 updateLagIndicator(0);
354 statusBar()->addPermanentWidget(coreLagLabel);
355 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
358 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
359 sslLabel->setPixmap(QPixmap());
360 statusBar()->addPermanentWidget(sslLabel);
362 ui.menuViews->addSeparator();
363 QAction *showStatusbar = ui.menuViews->addAction(tr("Statusbar"));
364 showStatusbar->setCheckable(true);
366 UiSettings uiSettings;
368 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
369 showStatusbar->setChecked(enabled);
370 enabled ? statusBar()->show() : statusBar()->hide();
372 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
373 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
376 void MainWin::saveStatusBarStatus(bool enabled) {
377 UiSettings uiSettings;
378 uiSettings.setValue("ShowStatusBar", enabled);
381 void MainWin::setupSystray() {
382 connect(timer, SIGNAL(timeout()), this, SLOT(makeTrayIconBlink()));
383 connect(Client::instance(), SIGNAL(messageReceived(const Message &)), this, SLOT(receiveMessage(const Message &)));
385 systrayMenu = new QMenu(this);
386 systrayMenu->addAction(ui.actionAboutQuassel);
387 systrayMenu->addSeparator();
388 systrayMenu->addAction(ui.actionConnectCore);
389 systrayMenu->addAction(ui.actionDisconnectCore);
390 systrayMenu->addSeparator();
391 systrayMenu->addAction(ui.actionQuit);
393 systray->setContextMenu(systrayMenu);
396 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
401 connect(systray, SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
402 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
407 void MainWin::changeEvent(QEvent *event) {
408 if(event->type() == QEvent::WindowStateChange) {
409 if(windowState() & Qt::WindowMinimized) {
411 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
419 // FIXME this should be made prettier...
420 void MainWin::changeTopic(const QString &topic) {
421 BufferId id = ui.bufferWidget->currentBuffer();
422 if(!id.isValid()) return;
423 Buffer *buffer = Client::buffer(id);
424 if(buffer) Client::userInput(buffer->bufferInfo(), QString("/topic %1").arg(topic));
427 void MainWin::connectedToCore() {
428 Q_CHECK_PTR(Client::bufferViewManager());
429 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
430 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
431 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
433 foreach(BufferInfo id, Client::allBufferInfos()) {
434 Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1);
439 void MainWin::setConnectedState() {
440 //ui.menuCore->setEnabled(true);
441 ui.actionConnectCore->setEnabled(false);
442 ui.actionDisconnectCore->setEnabled(true);
443 ui.actionCoreInfo->setEnabled(true);
444 ui.menuViews->setEnabled(true);
445 ui.bufferWidget->show();
446 statusBar()->showMessage(tr("Connected to core."));
447 setWindowIcon(onlineTrayIcon);
448 qApp->setWindowIcon(onlineTrayIcon);
449 systray->setIcon(onlineTrayIcon);
450 if(sslLabel->width() == 0)
451 sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/no-ssl")));
454 void MainWin::loadLayout() {
456 int accountId = Client::currentCoreAccount().toInt();
457 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
460 void MainWin::saveLayout() {
462 int accountId = Client::currentCoreAccount().toInt();
463 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
466 void MainWin::updateLagIndicator(int lag) {
467 coreLagLabel->setText(QString("Core Lag: %1 msec").arg(lag));
471 void MainWin::securedConnection() {
472 // todo: make status bar entry
473 sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/ssl")));
476 void MainWin::disconnectedFromCore() {
477 // save core specific layout and remove bufferviews;
480 BufferViewDock *dock;
481 foreach(QAction *action, ui.menuBufferViews->actions()) {
482 actionData = action->data();
483 if(!actionData.isValid())
486 dock = qobject_cast<BufferViewDock *>(action->parent());
487 if(dock && actionData.toInt() != -1) {
488 removeAction(action);
493 restoreState(s.value("MainWinState").toByteArray());
494 setDisconnectedState();
497 void MainWin::setDisconnectedState() {
498 //ui.menuCore->setEnabled(false);
499 ui.actionConnectCore->setEnabled(true);
500 ui.actionDisconnectCore->setEnabled(false);
501 ui.actionCoreInfo->setEnabled(false);
502 ui.menuViews->setEnabled(false);
503 ui.bufferWidget->hide();
504 statusBar()->showMessage(tr("Not connected to core."));
505 setWindowIcon(offlineTrayIcon);
506 qApp->setWindowIcon(offlineTrayIcon);
507 systray->setIcon(offlineTrayIcon);
508 sslLabel->setPixmap(QPixmap());
511 void MainWin::showCoreConnectionDlg(bool autoConnect) {
512 coreConnectDlg = new CoreConnectDlg(this, autoConnect);
513 connect(coreConnectDlg, SIGNAL(finished(int)), this, SLOT(coreConnectionDlgFinished(int)));
514 coreConnectDlg->setModal(true);
515 coreConnectDlg->show();
518 void MainWin::coreConnectionDlgFinished(int /*code*/) {
519 coreConnectDlg->close();
523 void MainWin::showChannelList(NetworkId netId) {
524 if(!netId.isValid()) {
525 QAction *action = qobject_cast<QAction *>(sender());
527 netId = action->data().value<NetworkId>();
529 channelListDlg->setNetwork(netId);
530 channelListDlg->show();
533 void MainWin::showCoreInfoDlg() {
534 CoreInfoDlg dlg(this);
538 void MainWin::showSettingsDlg() {
542 void MainWin::showDebugConsole() {
543 debugConsole->show();
546 void MainWin::showAboutDlg() {
551 void MainWin::closeEvent(QCloseEvent *event) {
553 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
561 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
562 if(activationReason == QSystemTrayIcon::Trigger) {
567 void MainWin::toggleVisibility() {
568 if(isHidden() /*|| !isActiveWindow()*/) {
579 // setFocus(); //Qt::ActiveWindowFocusReason
582 if(systray->isSystemTrayAvailable ()) {
585 if(!systray->isVisible()) {
594 void MainWin::receiveMessage(const Message &msg) {
595 if(QApplication::activeWindow() != 0)
598 if(msg.flags() & Message::Highlight || msg.bufferInfo().type() == BufferInfo::QueryBuffer) {
599 QString title = msg.bufferInfo().bufferName();;
600 if(msg.bufferInfo().type() != BufferInfo::QueryBuffer) {
601 QString sender = msg.sender();
602 int i = sender.indexOf("!");
604 sender = sender.left(i);
605 title += QString(" - %1").arg(sender);
608 UiSettings uiSettings;
611 bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool();
612 bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool();
613 if(displayBubble || displayDesktop) {
614 // FIXME don't invoke style engine for this!
615 QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText;
616 if(displayBubble) displayTrayIconMessage(title, text);
618 if(displayDesktop) sendDesktopNotification(title, text);
622 if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
623 QApplication::alert(this);
624 setTrayIconActivity(true);
629 bool MainWin::event(QEvent *event) {
630 if(event->type() == QEvent::WindowActivate)
631 setTrayIconActivity(false);
632 return QMainWindow::event(event);
638 Using the notification-daemon from Freedesktop's Galago project
639 http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify
641 void MainWin::sendDesktopNotification(const QString &title, const QString &message) {
643 QMap<QString, QVariant> hints;
644 UiSettings uiSettings;
646 hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up
647 hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up
649 actions << "click" << "Click Me!";
651 QDBusReply<uint> reply = desktopNotifications->Notify(
652 "Quassel", // Application name
653 notificationId, // ID of previous notification to replace
654 "", // Icon to display
655 title, // Summary / Header of the message to display
656 QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display
657 actions, // Actions from which the user may choose
658 hints, // Hints to the server displaying the message
659 uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds
662 if(!reply.isValid()) {
664 qDebug() << "Error on sending notification...";
668 notificationId = reply.value();
670 qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString();
674 void MainWin::desktopNotificationClosed(uint id, uint reason) {
675 qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString();
680 void MainWin::desktopNotificationInvoked(uint id, const QString & action) {
681 qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString();
684 #endif /* HAVE_DBUS */
686 void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
687 systray->showMessage(title, message);
690 void MainWin::setTrayIconActivity(bool active) {
692 if(!timer->isActive())
696 systray->setIcon(onlineTrayIcon);
700 void MainWin::makeTrayIconBlink() {
702 systray->setIcon(onlineTrayIcon);
703 trayIconActive = false;
705 systray->setIcon(activeTrayIcon);
706 trayIconActive = true;
710 void MainWin::clientNetworkCreated(NetworkId id) {
711 const Network *net = Client::network(id);
712 QAction *act = new QAction(net->networkName(), this);
713 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
714 act->setData(QVariant::fromValue<NetworkId>(id));
715 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
716 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
718 QAction *beforeAction = 0;
719 foreach(QAction *action, ui.menuNetworks->actions()) {
720 if(action->isSeparator()) {
721 beforeAction = action;
724 if(net->networkName().localeAwareCompare(action->text()) < 0) {
725 beforeAction = action;
729 Q_CHECK_PTR(beforeAction);
730 ui.menuNetworks->insertAction(beforeAction, act);
733 void MainWin::clientNetworkUpdated() {
734 const Network *net = qobject_cast<const Network *>(sender());
738 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
742 action->setText(net->networkName());
744 switch(net->connectionState()) {
745 case Network::Initialized:
746 action->setIcon(QIcon(":/16x16/actions/network-connect"));
748 case Network::Disconnected:
749 action->setIcon(QIcon(":/16x16/actions/network-disconnect"));
752 action->setIcon(QIcon(":/16x16/actions/gear"));
756 void MainWin::clientNetworkRemoved(NetworkId id) {
757 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
761 action->deleteLater();
764 void MainWin::connectOrDisconnectFromNet() {
765 QAction *act = qobject_cast<QAction *>(sender());
767 const Network *net = Client::network(act->data().value<NetworkId>());
769 if(net->connectionState() == Network::Disconnected) net->requestConnect();
770 else net->requestDisconnect();