1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 #include "actioncollection.h"
25 #include "buffermodel.h"
26 #include "bufferviewmanager.h"
27 #include "bufferwidget.h"
28 #include "channellistdlg.h"
29 #include "chatlinemodel.h"
30 #include "chatmonitorfilter.h"
31 #include "chatmonitorview.h"
34 #include "clientbacklogmanager.h"
35 #include "coreinfodlg.h"
36 #include "coreconnectdlg.h"
37 #include "iconloader.h"
38 #include "inputwidget.h"
39 #include "irclistmodel.h"
40 #include "jumpkeyhandler.h"
41 #include "msgprocessorstatuswidget.h"
42 #include "nicklistwidget.h"
43 #include "qtuiapplication.h"
44 #include "qtuimessageprocessor.h"
45 #include "qtuisettings.h"
46 #include "sessionsettings.h"
47 #include "settingsdlg.h"
48 #include "settingspagedlg.h"
49 #include "topicwidget.h"
50 #include "verticaldock.h"
53 # include "desktopnotificationbackend.h"
55 #include "systraynotificationbackend.h"
56 #include "taskbarnotificationbackend.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"
69 MainWin::MainWin(QWidget *parent)
70 : QMainWindow(parent),
71 coreLagLabel(new QLabel()),
72 sslLabel(new QLabel()),
73 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
75 _trayIcon(new QSystemTrayIcon(this))
77 QtUiSettings uiSettings;
78 QString style = uiSettings.value("Style", QString("")).toString();
80 QApplication::setStyle(style);
83 setWindowTitle("Quassel IRC");
84 setWindowIconText("Quassel IRC");
87 installEventFilter(new JumpKeyHandler(this));
89 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
90 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
92 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
95 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
96 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
97 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
100 void MainWin::init() {
102 if(s.value("MainWinSize").isValid())
103 resize(s.value("MainWinSize").toSize());
105 resize(QSize(800, 500));
107 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
108 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
109 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
111 // Order is sometimes important
125 setDockNestingEnabled(true);
126 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
127 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
128 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
129 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
131 // restore mainwin state
132 restoreState(s.value("MainWinState").toByteArray());
134 // restore locked state of docks
135 QtUi::actionCollection("General")->action("LockDockPositions")->setChecked(s.value("LockDocks", false).toBool());
137 setDisconnectedState(); // Disable menus and stuff
141 showCoreConnectionDlg(true); // autoconnect if appropriate
144 MainWin::~MainWin() {
146 s.setValue("MainWinSize", size());
147 s.setValue("MainWinPos", pos());
148 s.setValue("MainWinState", saveState());
151 void MainWin::updateIcon() {
153 if(Client::isConnected())
154 icon = DesktopIcon("quassel", IconLoader::SizeEnormous);
156 icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous);
158 qApp->setWindowIcon(icon);
159 systemTrayIcon()->setIcon(icon);
162 void MainWin::setupActions() {
163 ActionCollection *coll = QtUi::actionCollection("General");
165 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
166 this, SLOT(showCoreConnectionDlg())));
167 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
168 Client::instance(), SLOT(disconnectFromCore())));
169 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
170 this, SLOT(showCoreInfoDlg())));
171 coll->addAction("EditNetworks", new Action(SmallIcon("configure"), tr("Edit &Networks..."), coll,
172 this, SLOT(on_actionEditNetworks_triggered())));
173 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
174 qApp, SLOT(quit()), tr("Ctrl+Q")));
177 coll->addAction("ManageBufferViews", new Action(SmallIcon("view-tree"), tr("&Manage Buffer Views..."), coll,
178 this, SLOT(on_actionManageViews_triggered())));
179 connect(coll->addAction("LockDockPositions", new Action(tr("&Lock Dock Positions"), coll)), SIGNAL(toggled(bool)),
180 this, SLOT(on_actionLockDockPositions_toggled(bool)));
181 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
182 0, 0, tr("Ctrl+F")))->setCheckable(true);
183 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
184 0, 0))->setCheckable(true);
187 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
188 this, SLOT(showSettingsDlg()), tr("F7")));
191 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel..."), coll,
192 this, SLOT(showAboutDlg())));
193 coll->addAction("AboutQt", new Action(tr("About &Qt..."), coll,
194 qApp, SLOT(aboutQt())));
195 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
196 this, SLOT(on_actionDebugNetworkModel_triggered())));
199 void MainWin::setupMenus() {
200 ActionCollection *coll = QtUi::actionCollection("General");
202 _fileMenu = menuBar()->addMenu(tr("&File"));
203 _fileMenu->addAction(coll->action("ConnectCore"));
204 _fileMenu->addAction(coll->action("DisconnectCore"));
205 _fileMenu->addAction(coll->action("CoreInfo"));
206 _fileMenu->addSeparator();
207 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
208 _networksMenu->addAction(coll->action("EditNetworks"));
209 _networksMenu->addSeparator();
210 _fileMenu->addSeparator();
211 _fileMenu->addAction(coll->action("Quit"));
213 _viewMenu = menuBar()->addMenu(tr("&View"));
214 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
215 _bufferViewsMenu->addAction(coll->action("ManageBufferViews"));
216 _viewMenu->addSeparator();
217 _viewMenu->addAction(coll->action("ToggleSearchBar"));
218 _viewMenu->addAction(coll->action("ToggleStatusBar"));
219 _viewMenu->addSeparator();
221 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
222 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
224 _helpMenu = menuBar()->addMenu(tr("&Help"));
225 _helpMenu->addAction(coll->action("AboutQuassel"));
226 _helpMenu->addAction(coll->action("AboutQt"));
227 _helpMenu->addSeparator();
228 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
229 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
232 void MainWin::setupBufferWidget() {
233 _bufferWidget = new BufferWidget(this);
234 _bufferWidget->setModel(Client::bufferModel());
235 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
236 setCentralWidget(_bufferWidget);
239 void MainWin::setupViews() {
243 void MainWin::addBufferView(int bufferViewConfigId) {
244 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
247 void MainWin::addBufferView(BufferViewConfig *config) {
248 BufferViewDock *dock;
250 dock = new BufferViewDock(config, this);
252 dock = new BufferViewDock(this);
254 //create the view and initialize it's filter
255 BufferView *view = new BufferView(dock);
256 view->setFilteredModel(Client::bufferModel(), config);
259 connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList()));
261 Client::bufferModel()->synchronizeView(view);
263 dock->setWidget(view);
266 addDockWidget(Qt::LeftDockWidgetArea, dock);
267 _bufferViewsMenu->addAction(dock->toggleViewAction());
269 _netViews.append(dock);
272 void MainWin::removeBufferView(int bufferViewConfigId) {
274 BufferViewDock *dock;
275 foreach(QAction *action, _bufferViewsMenu->actions()) {
276 actionData = action->data();
277 if(!actionData.isValid())
280 dock = qobject_cast<BufferViewDock *>(action->parent());
281 if(dock && actionData.toInt() == bufferViewConfigId) {
282 removeAction(action);
288 void MainWin::on_actionEditNetworks_triggered() {
289 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
293 void MainWin::on_actionManageViews_triggered() {
294 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
298 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
299 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
300 foreach(VerticalDock *dock, docks) {
301 dock->showTitle(!lock);
303 QtUiSettings().setValue("LockDocks", lock);
306 void MainWin::setupNickWidget() {
308 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
309 nickDock->setObjectName("NickDock");
310 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
312 _nickListWidget = new NickListWidget(nickDock);
313 nickDock->setWidget(_nickListWidget);
315 addDockWidget(Qt::RightDockWidgetArea, nickDock);
316 _viewMenu->addAction(nickDock->toggleViewAction());
317 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
318 nickDock->toggleViewAction()->setIcon(SmallIcon("view-sidetree"));
319 // See NickListDock::NickListDock();
320 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
322 // attach the NickListWidget to the BufferModel and the default selection
323 _nickListWidget->setModel(Client::bufferModel());
324 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
327 void MainWin::setupChatMonitor() {
328 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
329 dock->setObjectName("ChatMonitorDock");
331 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
332 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
334 dock->setWidget(chatView);
337 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
338 _viewMenu->addAction(dock->toggleViewAction());
339 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
342 void MainWin::setupInputWidget() {
343 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
344 dock->setObjectName("InputDock");
346 InputWidget *inputWidget = new InputWidget(dock);
347 dock->setWidget(inputWidget);
349 addDockWidget(Qt::BottomDockWidgetArea, dock);
351 _viewMenu->addAction(dock->toggleViewAction());
352 dock->toggleViewAction()->setText(tr("Show Input Line"));
354 inputWidget->setModel(Client::bufferModel());
355 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
357 _bufferWidget->setFocusProxy(inputWidget);
360 void MainWin::setupTopicWidget() {
361 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
362 dock->setObjectName("TopicDock");
363 TopicWidget *topicwidget = new TopicWidget(dock);
365 dock->setWidget(topicwidget);
367 topicwidget->setModel(Client::bufferModel());
368 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
370 addDockWidget(Qt::TopDockWidgetArea, dock);
372 _viewMenu->addAction(dock->toggleViewAction());
373 dock->toggleViewAction()->setText(tr("Show Topic Line"));
376 void MainWin::setupTitleSetter() {
377 _titleSetter.setModel(Client::bufferModel());
378 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
381 void MainWin::setupStatusBar() {
382 // MessageProcessor progress
383 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
384 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
387 updateLagIndicator(0);
388 statusBar()->addPermanentWidget(coreLagLabel);
389 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
392 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
393 sslLabel->setPixmap(QPixmap());
394 statusBar()->addPermanentWidget(sslLabel);
396 _viewMenu->addSeparator();
397 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
399 UiSettings uiSettings;
401 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
402 showStatusbar->setChecked(enabled);
403 enabled ? statusBar()->show() : statusBar()->hide();
405 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
406 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
409 void MainWin::saveStatusBarStatus(bool enabled) {
410 UiSettings uiSettings;
411 uiSettings.setValue("ShowStatusBar", enabled);
414 void MainWin::setupSystray() {
415 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
416 SLOT(messagesInserted(const QModelIndex &, int, int)));
418 ActionCollection *coll = QtUi::actionCollection("General");
419 systrayMenu = new QMenu(this);
420 systrayMenu->addAction(coll->action("AboutQuassel"));
421 systrayMenu->addSeparator();
422 systrayMenu->addAction(coll->action("ConnectCore"));
423 systrayMenu->addAction(coll->action("DisconnectCore"));
424 systrayMenu->addSeparator();
425 systrayMenu->addAction(coll->action("Quit"));
427 systemTrayIcon()->setContextMenu(systrayMenu);
430 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
431 systemTrayIcon()->show();
435 connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
436 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
441 void MainWin::changeEvent(QEvent *event) {
442 if(event->type() == QEvent::WindowStateChange) {
443 if(windowState() & Qt::WindowMinimized) {
445 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
453 void MainWin::connectedToCore() {
454 Q_CHECK_PTR(Client::bufferViewManager());
455 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
456 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
457 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
459 Client::backlogManager()->requestInitialBacklog();
463 void MainWin::setConnectedState() {
464 ActionCollection *coll = QtUi::actionCollection("General");
465 //ui.menuCore->setEnabled(true);
466 coll->action("ConnectCore")->setEnabled(false);
467 coll->action("DisconnectCore")->setEnabled(true);
468 coll->action("CoreInfo")->setEnabled(true);
469 _viewMenu->setEnabled(true);
470 _bufferWidget->show();
471 statusBar()->showMessage(tr("Connected to core."));
472 if(sslLabel->width() == 0)
473 sslLabel->setPixmap(SmallIcon("security-low"));
477 void MainWin::loadLayout() {
479 int accountId = Client::currentCoreAccount().toInt();
480 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
483 void MainWin::saveLayout() {
485 int accountId = Client::currentCoreAccount().toInt();
486 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
489 void MainWin::updateLagIndicator(int lag) {
490 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
494 void MainWin::securedConnection() {
495 // todo: make status bar entry
496 sslLabel->setPixmap(SmallIcon("security-high"));
499 void MainWin::disconnectedFromCore() {
500 // save core specific layout and remove bufferviews;
503 BufferViewDock *dock;
504 foreach(QAction *action, _bufferViewsMenu->actions()) {
505 actionData = action->data();
506 if(!actionData.isValid())
509 dock = qobject_cast<BufferViewDock *>(action->parent());
510 if(dock && actionData.toInt() != -1) {
511 removeAction(action);
516 restoreState(s.value("MainWinState").toByteArray());
517 setDisconnectedState();
520 void MainWin::setDisconnectedState() {
521 ActionCollection *coll = QtUi::actionCollection("General");
522 //ui.menuCore->setEnabled(false);
523 coll->action("ConnectCore")->setEnabled(true);
524 coll->action("DisconnectCore")->setEnabled(false);
525 coll->action("CoreInfo")->setEnabled(false);
526 _viewMenu->setEnabled(false);
527 _bufferWidget->hide();
528 statusBar()->showMessage(tr("Not connected to core."));
529 sslLabel->setPixmap(QPixmap());
533 void MainWin::showCoreConnectionDlg(bool autoConnect) {
534 CoreConnectDlg(autoConnect, this).exec();
537 void MainWin::showChannelList(NetworkId netId) {
538 ChannelListDlg *channelListDlg = new ChannelListDlg();
540 if(!netId.isValid()) {
541 QAction *action = qobject_cast<QAction *>(sender());
543 netId = action->data().value<NetworkId>();
546 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
547 channelListDlg->setNetwork(netId);
548 channelListDlg->show();
551 void MainWin::showCoreInfoDlg() {
552 CoreInfoDlg(this).exec();
555 void MainWin::showSettingsDlg() {
556 SettingsDlg *dlg = new SettingsDlg();
558 //Category: Appearance
559 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
560 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
561 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
562 //Category: Behaviour
563 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
564 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
565 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
566 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
568 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
569 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
570 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
575 void MainWin::showAboutDlg() {
576 AboutDlg(this).exec();
579 void MainWin::closeEvent(QCloseEvent *event) {
581 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
589 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
590 if(activationReason == QSystemTrayIcon::Trigger) {
595 void MainWin::toggleVisibility() {
596 if(isHidden() /*|| !isActiveWindow()*/) {
607 // setFocus(); //Qt::ActiveWindowFocusReason
610 if(systemTrayIcon()->isSystemTrayAvailable ()) {
613 if(!systemTrayIcon()->isVisible()) {
614 systemTrayIcon()->show();
622 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
625 if(QApplication::activeWindow() != 0)
628 for(int i = start; i <= end; i++) {
629 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
631 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
634 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
635 if(flags.testFlag(Message::Backlog)) continue;
636 flags |= Message::Backlog; // we only want to trigger a highlight once!
637 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
639 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
640 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
642 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
643 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
644 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
645 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
646 QtUi::invokeNotification(bufId, sender, contents);
651 bool MainWin::event(QEvent *event) {
652 if(event->type() == QEvent::WindowActivate)
653 QtUi::closeNotifications();
654 return QMainWindow::event(event);
657 void MainWin::clientNetworkCreated(NetworkId id) {
658 const Network *net = Client::network(id);
659 QAction *act = new QAction(net->networkName(), this);
660 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
661 act->setData(QVariant::fromValue<NetworkId>(id));
662 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
663 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
665 QAction *beforeAction = 0;
666 foreach(QAction *action, _networksMenu->actions()) {
667 if(!action->data().isValid()) // ignore stock actions
669 if(net->networkName().localeAwareCompare(action->text()) < 0) {
670 beforeAction = action;
674 _networksMenu->insertAction(beforeAction, act);
677 void MainWin::clientNetworkUpdated() {
678 const Network *net = qobject_cast<const Network *>(sender());
682 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
686 action->setText(net->networkName());
688 switch(net->connectionState()) {
689 case Network::Initialized:
690 action->setIcon(SmallIcon("network-connect"));
692 case Network::Disconnected:
693 action->setIcon(SmallIcon("network-disconnect"));
696 action->setIcon(SmallIcon("network-wired"));
700 void MainWin::clientNetworkRemoved(NetworkId id) {
701 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
705 action->deleteLater();
708 void MainWin::connectOrDisconnectFromNet() {
709 QAction *act = qobject_cast<QAction *>(sender());
711 const Network *net = Client::network(act->data().value<NetworkId>());
713 if(net->connectionState() == Network::Disconnected) net->requestConnect();
714 else net->requestDisconnect();
717 void MainWin::on_actionDebugNetworkModel_triggered() {
718 QTreeView *view = new QTreeView;
719 view->setAttribute(Qt::WA_DeleteOnClose);
720 view->setWindowTitle("Debug NetworkModel View");
721 view->setModel(Client::networkModel());
722 view->setColumnWidth(0, 250);
723 view->setColumnWidth(1, 250);
724 view->setColumnWidth(2, 80);
725 view->resize(610, 300);
729 void MainWin::saveStateToSession(const QString &sessionId) {
731 SessionSettings s(sessionId);
733 s.setValue("MainWinSize", size());
734 s.setValue("MainWinPos", pos());
735 s.setValue("MainWinState", saveState());
738 void MainWin::saveStateToSessionSettings(SessionSettings & s)
740 s.setValue("MainWinSize", size());
741 s.setValue("MainWinPos", pos());
742 s.setValue("MainWinState", saveState());