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"
32 #include "clientbacklogmanager.h"
33 #include "coreinfodlg.h"
34 #include "coreconnectdlg.h"
35 #include "msgprocessorstatuswidget.h"
36 #include "qtuimessageprocessor.h"
37 #include "networkmodel.h"
38 #include "buffermodel.h"
39 #include "nicklistwidget.h"
40 #include "settingsdlg.h"
41 #include "settingspagedlg.h"
42 #include "signalproxy.h"
43 #include "topicwidget.h"
44 #include "inputwidget.h"
45 #include "irclistmodel.h"
46 #include "verticaldock.h"
47 #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"
66 #include "debugconsole.h"
68 #include "qtuistyle.h"
70 MainWin::MainWin(QtUi *_gui, QWidget *parent)
71 : QMainWindow(parent),
73 coreLagLabel(new QLabel()),
74 sslLabel(new QLabel()),
75 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
77 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),
82 timer(new QTimer(this)),
83 channelListDlg(new ChannelListDlg(this)),
84 settingsDlg(new SettingsDlg(this)),
85 debugConsole(new DebugConsole(this))
87 UiSettings uiSettings;
88 loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
90 QString style = uiSettings.value("Style", QString("")).toString();
92 QApplication::setStyle(style);
96 setWindowTitle("Quassel IRC");
97 setWindowIcon(offlineTrayIcon);
98 qApp->setWindowIcon(offlineTrayIcon);
99 systray->setIcon(offlineTrayIcon);
100 setWindowIconText("Quassel IRC");
102 statusBar()->showMessage(tr("Waiting for core..."));
104 installEventFilter(new JumpKeyHandler(this));
107 desktopNotifications = new org::freedesktop::Notifications(
108 "org.freedesktop.Notifications",
109 "/org/freedesktop/Notifications",
110 QDBusConnection::sessionBus(), this);
112 connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint)));
113 connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&)));
117 void MainWin::init() {
119 if(s.value("MainWinSize").isValid())
120 resize(s.value("MainWinSize").toSize());
122 resize(QSize(800, 500));
124 Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
126 connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(saveLayout()));
128 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkCreated(NetworkId)));
129 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
133 statusBar()->showMessage(tr("Not connected to core."));
136 setDockNestingEnabled(true);
138 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
139 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
140 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
141 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());
162 setDisconnectedState(); // Disable menus and stuff
163 showCoreConnectionDlg(true); // autoconnect if appropriate
165 // attach the BufferWidget to the BufferModel and the default selection
166 ui.bufferWidget->setModel(Client::bufferModel());
167 ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
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.actionDebug_Console, SIGNAL(triggered()), this, SLOT(showDebugConsole()));
187 connect(ui.actionAboutQuassel, SIGNAL(triggered()), this, SLOT(showAboutDlg()));
188 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
191 void MainWin::setupViews() {
195 void MainWin::addBufferView(int bufferViewConfigId) {
196 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
199 void MainWin::addBufferView(BufferViewConfig *config) {
200 BufferViewDock *dock;
202 dock = new BufferViewDock(config, this);
204 dock = new BufferViewDock(this);
206 //create the view and initialize it's filter
207 BufferView *view = new BufferView(dock);
208 view->setFilteredModel(Client::bufferModel(), config);
211 connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList()));
213 Client::bufferModel()->synchronizeView(view);
215 dock->setWidget(view);
218 addDockWidget(Qt::LeftDockWidgetArea, dock);
219 ui.menuBufferViews->addAction(dock->toggleViewAction());
221 _netViews.append(dock);
224 void MainWin::removeBufferView(int bufferViewConfigId) {
226 BufferViewDock *dock;
227 foreach(QAction *action, ui.menuBufferViews->actions()) {
228 actionData = action->data();
229 if(!actionData.isValid())
232 dock = qobject_cast<BufferViewDock *>(action->parent());
233 if(dock && actionData.toInt() == bufferViewConfigId) {
234 removeAction(action);
240 void MainWin::setupSettingsDlg() {
241 //Category: Appearance
242 settingsDlg->registerSettingsPage(new ColorSettingsPage(settingsDlg));
243 settingsDlg->registerSettingsPage(new FontsSettingsPage(settingsDlg));
244 settingsDlg->registerSettingsPage(new AppearanceSettingsPage(settingsDlg)); //General
245 //Category: Behaviour
246 settingsDlg->registerSettingsPage(new GeneralSettingsPage(settingsDlg));
247 settingsDlg->registerSettingsPage(new HighlightSettingsPage(settingsDlg));
248 settingsDlg->registerSettingsPage(new AliasesSettingsPage(settingsDlg));
249 settingsDlg->registerSettingsPage(new NotificationsSettingsPage(settingsDlg));
251 settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg));
252 settingsDlg->registerSettingsPage(new NetworksSettingsPage(settingsDlg));
253 settingsDlg->registerSettingsPage(new BufferViewSettingsPage(settingsDlg));
256 void MainWin::on_actionEditNetworks_triggered() {
257 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
261 void MainWin::on_actionManageViews_triggered() {
262 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
266 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
267 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
268 foreach(VerticalDock *dock, docks) {
269 dock->showTitle(!lock);
271 QtUiSettings().setValue("LockDocks", lock);
274 void MainWin::setupNickWidget() {
276 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
277 nickDock->setObjectName("NickDock");
278 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
280 nickListWidget = new NickListWidget(nickDock);
281 nickDock->setWidget(nickListWidget);
283 addDockWidget(Qt::RightDockWidgetArea, nickDock);
284 ui.menuViews->addAction(nickDock->toggleViewAction());
285 // See NickListDock::NickListDock();
286 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
288 // attach the NickListWidget to the BufferModel and the default selection
289 nickListWidget->setModel(Client::bufferModel());
290 nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
293 void MainWin::setupChatMonitor() {
294 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
295 dock->setObjectName("ChatMonitorDock");
297 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
298 ChatView *chatView = new ChatView(filter, this);
300 dock->setWidget(chatView);
303 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
304 ui.menuViews->addAction(dock->toggleViewAction());
307 void MainWin::setupInputWidget() {
308 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
309 dock->setObjectName("InputDock");
311 InputWidget *inputWidget = new InputWidget(dock);
312 dock->setWidget(inputWidget);
314 addDockWidget(Qt::BottomDockWidgetArea, dock);
316 ui.menuViews->addAction(dock->toggleViewAction());
318 inputWidget->setModel(Client::bufferModel());
319 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
321 ui.bufferWidget->setFocusProxy(inputWidget);
324 void MainWin::setupTopicWidget() {
325 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
326 dock->setObjectName("TopicDock");
327 TopicWidget *topicwidget = new TopicWidget(dock);
328 connect(topicwidget, SIGNAL(topicChanged(const QString &)), this, SLOT(changeTopic(const QString &)));
330 dock->setWidget(topicwidget);
332 topicwidget->setModel(Client::bufferModel());
333 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
335 addDockWidget(Qt::TopDockWidgetArea, dock);
337 ui.menuViews->addAction(dock->toggleViewAction());
340 void MainWin::setupStatusBar() {
341 // MessageProcessor progress
342 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
343 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
346 updateLagIndicator(0);
347 statusBar()->addPermanentWidget(coreLagLabel);
348 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
351 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
352 sslLabel->setPixmap(QPixmap());
353 statusBar()->addPermanentWidget(sslLabel);
355 ui.menuViews->addSeparator();
356 QAction *showStatusbar = ui.menuViews->addAction(tr("Statusbar"));
357 showStatusbar->setCheckable(true);
359 UiSettings uiSettings;
361 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
362 showStatusbar->setChecked(enabled);
363 enabled ? statusBar()->show() : statusBar()->hide();
365 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
366 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
369 void MainWin::saveStatusBarStatus(bool enabled) {
370 UiSettings uiSettings;
371 uiSettings.setValue("ShowStatusBar", enabled);
374 void MainWin::setupSystray() {
375 connect(timer, SIGNAL(timeout()), this, SLOT(makeTrayIconBlink()));
376 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
377 this, SLOT(messagesInserted(const QModelIndex &, int, int)));
379 systrayMenu = new QMenu(this);
380 systrayMenu->addAction(ui.actionAboutQuassel);
381 systrayMenu->addSeparator();
382 systrayMenu->addAction(ui.actionConnectCore);
383 systrayMenu->addAction(ui.actionDisconnectCore);
384 systrayMenu->addSeparator();
385 systrayMenu->addAction(ui.actionQuit);
387 systray->setContextMenu(systrayMenu);
390 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
395 connect(systray, SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
396 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
401 void MainWin::changeEvent(QEvent *event) {
402 if(event->type() == QEvent::WindowStateChange) {
403 if(windowState() & Qt::WindowMinimized) {
405 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
413 // FIXME this should be made prettier...
414 void MainWin::changeTopic(const QString &topic) {
415 BufferId id = ui.bufferWidget->currentBuffer();
416 if(!id.isValid()) return;
417 Buffer *buffer = Client::buffer(id);
418 if(buffer) Client::userInput(buffer->bufferInfo(), QString("/topic %1").arg(topic));
421 void MainWin::connectedToCore() {
422 Q_CHECK_PTR(Client::bufferViewManager());
423 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
424 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
425 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
427 foreach(BufferInfo id, Client::allBufferInfos()) {
428 Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1);
433 void MainWin::setConnectedState() {
434 //ui.menuCore->setEnabled(true);
435 ui.actionConnectCore->setEnabled(false);
436 ui.actionDisconnectCore->setEnabled(true);
437 ui.actionCoreInfo->setEnabled(true);
438 ui.menuViews->setEnabled(true);
439 ui.bufferWidget->show();
440 statusBar()->showMessage(tr("Connected to core."));
441 setWindowIcon(onlineTrayIcon);
442 qApp->setWindowIcon(onlineTrayIcon);
443 systray->setIcon(onlineTrayIcon);
444 if(sslLabel->width() == 0)
445 sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/no-ssl")));
448 void MainWin::loadLayout() {
450 int accountId = Client::currentCoreAccount().toInt();
451 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
454 void MainWin::saveLayout() {
456 int accountId = Client::currentCoreAccount().toInt();
457 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
460 void MainWin::updateLagIndicator(int lag) {
461 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
465 void MainWin::securedConnection() {
466 // todo: make status bar entry
467 sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/ssl")));
470 void MainWin::disconnectedFromCore() {
471 // save core specific layout and remove bufferviews;
474 BufferViewDock *dock;
475 foreach(QAction *action, ui.menuBufferViews->actions()) {
476 actionData = action->data();
477 if(!actionData.isValid())
480 dock = qobject_cast<BufferViewDock *>(action->parent());
481 if(dock && actionData.toInt() != -1) {
482 removeAction(action);
487 restoreState(s.value("MainWinState").toByteArray());
488 setDisconnectedState();
491 void MainWin::setDisconnectedState() {
492 //ui.menuCore->setEnabled(false);
493 ui.actionConnectCore->setEnabled(true);
494 ui.actionDisconnectCore->setEnabled(false);
495 ui.actionCoreInfo->setEnabled(false);
496 ui.menuViews->setEnabled(false);
497 ui.bufferWidget->hide();
498 statusBar()->showMessage(tr("Not connected to core."));
499 setWindowIcon(offlineTrayIcon);
500 qApp->setWindowIcon(offlineTrayIcon);
501 systray->setIcon(offlineTrayIcon);
502 sslLabel->setPixmap(QPixmap());
505 void MainWin::showCoreConnectionDlg(bool autoConnect) {
506 coreConnectDlg = new CoreConnectDlg(this, autoConnect);
507 connect(coreConnectDlg, SIGNAL(finished(int)), this, SLOT(coreConnectionDlgFinished(int)));
508 coreConnectDlg->setModal(true);
509 coreConnectDlg->show();
512 void MainWin::coreConnectionDlgFinished(int /*code*/) {
513 coreConnectDlg->close();
517 void MainWin::showChannelList(NetworkId netId) {
518 if(!netId.isValid()) {
519 QAction *action = qobject_cast<QAction *>(sender());
521 netId = action->data().value<NetworkId>();
523 channelListDlg->setNetwork(netId);
524 channelListDlg->show();
527 void MainWin::showCoreInfoDlg() {
528 CoreInfoDlg dlg(this);
532 void MainWin::showSettingsDlg() {
536 void MainWin::showDebugConsole() {
537 debugConsole->show();
540 void MainWin::showAboutDlg() {
545 void MainWin::closeEvent(QCloseEvent *event) {
547 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
555 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
556 if(activationReason == QSystemTrayIcon::Trigger) {
561 void MainWin::toggleVisibility() {
562 if(isHidden() /*|| !isActiveWindow()*/) {
573 // setFocus(); //Qt::ActiveWindowFocusReason
576 if(systray->isSystemTrayAvailable ()) {
579 if(!systray->isVisible()) {
588 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
590 if(QApplication::activeWindow() != 0)
596 for(int i = start; i <= end; i++) {
597 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
599 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
602 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
603 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
604 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
606 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
607 QString title = Client::networkModel()->networkName(bufId) + " - " + Client::networkModel()->bufferName(bufId);
609 // FIXME Don't instantiate this for every highlight...
610 UiSettings uiSettings;
612 bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool();
613 bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool();
614 if(displayBubble || displayDesktop) {
615 if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) {
616 QString text = idx.data(ChatLineModel::DisplayRole).toString();
617 if(displayBubble) displayTrayIconMessage(title, text);
619 if(displayDesktop) sendDesktopNotification(title, text);
622 if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
623 QApplication::alert(this);
624 setTrayIconActivity(true);
631 bool MainWin::event(QEvent *event) {
632 if(event->type() == QEvent::WindowActivate)
633 setTrayIconActivity(false);
634 return QMainWindow::event(event);
640 Using the notification-daemon from Freedesktop's Galago project
641 http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify
643 void MainWin::sendDesktopNotification(const QString &title, const QString &message) {
645 QMap<QString, QVariant> hints;
646 UiSettings uiSettings;
648 hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up
649 hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up
651 actions << "click" << "Click Me!";
653 QDBusReply<uint> reply = desktopNotifications->Notify(
654 "Quassel", // Application name
655 notificationId, // ID of previous notification to replace
656 "", // Icon to display
657 title, // Summary / Header of the message to display
658 QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display
659 actions, // Actions from which the user may choose
660 hints, // Hints to the server displaying the message
661 uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds
664 if(!reply.isValid()) {
666 // could also happen if no notification service runs, so... whatever :)
667 //qDebug() << "Error on sending notification..." << reply.error();
671 notificationId = reply.value();
673 // qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString();
677 void MainWin::desktopNotificationClosed(uint id, uint reason) {
678 Q_UNUSED(id); Q_UNUSED(reason);
679 // qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString();
684 void MainWin::desktopNotificationInvoked(uint id, const QString & action) {
685 Q_UNUSED(id); Q_UNUSED(action);
686 // qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString();
689 #endif /* HAVE_DBUS */
691 void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
692 systray->showMessage(title, message);
695 void MainWin::setTrayIconActivity(bool active) {
697 if(!timer->isActive())
701 systray->setIcon(onlineTrayIcon);
705 void MainWin::makeTrayIconBlink() {
707 systray->setIcon(onlineTrayIcon);
708 trayIconActive = false;
710 systray->setIcon(activeTrayIcon);
711 trayIconActive = true;
715 void MainWin::clientNetworkCreated(NetworkId id) {
716 const Network *net = Client::network(id);
717 QAction *act = new QAction(net->networkName(), this);
718 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
719 act->setData(QVariant::fromValue<NetworkId>(id));
720 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
721 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
723 QAction *beforeAction = 0;
724 foreach(QAction *action, ui.menuNetworks->actions()) {
725 if(action->isSeparator()) {
726 beforeAction = action;
729 if(net->networkName().localeAwareCompare(action->text()) < 0) {
730 beforeAction = action;
734 Q_CHECK_PTR(beforeAction);
735 ui.menuNetworks->insertAction(beforeAction, act);
738 void MainWin::clientNetworkUpdated() {
739 const Network *net = qobject_cast<const Network *>(sender());
743 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
747 action->setText(net->networkName());
749 switch(net->connectionState()) {
750 case Network::Initialized:
751 action->setIcon(QIcon(":/16x16/actions/network-connect"));
753 case Network::Disconnected:
754 action->setIcon(QIcon(":/16x16/actions/network-disconnect"));
757 action->setIcon(QIcon(":/16x16/actions/gear"));
761 void MainWin::clientNetworkRemoved(NetworkId id) {
762 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
766 action->deleteLater();
769 void MainWin::connectOrDisconnectFromNet() {
770 QAction *act = qobject_cast<QAction *>(sender());
772 const Network *net = Client::network(act->data().value<NetworkId>());
774 if(net->connectionState() == Network::Disconnected) net->requestConnect();
775 else net->requestDisconnect();
780 void MainWin::on_actionDebugNetworkModel_triggered(bool) {
781 QTreeView *view = new QTreeView;
782 view->setAttribute(Qt::WA_DeleteOnClose);
783 view->setWindowTitle("Debug NetworkModel View");
784 view->setModel(Client::networkModel());
785 view->setColumnWidth(0, 250);
786 view->setColumnWidth(1, 250);
787 view->setColumnWidth(2, 80);
788 view->resize(610, 300);