2 * Copyright 2013 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
20#include "indicatorclient_network.h"
21#include "networkagent.h"
27#include <qdbusmenumodel.h>
28#include <qdbusactiongroup.h>
29#include <qstateaction.h>
31IndicatorClientNetwork::IndicatorClientNetwork(QObject *parent)
32 : IndicatorClientCommon(parent),
36 setPriority(IndicatorPriority::NETWORK);
38 m_timedAnimation.setInterval(500);
39 connect(&m_timedAnimation, SIGNAL(timeout()), SLOT(animationNextFrame()));
42IndicatorClientNetwork::~IndicatorClientNetwork()
46void IndicatorClientNetwork::init(const QSettings& settings)
48 IndicatorClientCommon::init(settings);
50 qmlRegisterType<NetworkAgent>("NetworkSettings", 0, 1, "NetworkAgent");
51 setIcon(QUrl("image://gicon/wifi-none"));
54QUrl IndicatorClientNetwork::componentSource() const
56 return QUrl("qrc:/indicatorsclient/qml/NetworkIndicator.qml");
59bool IndicatorClientNetwork::parseRootElement(const QString &type, QMap<int, QVariant> data)
61 if (type == "com.canonical.indicator.root.network") {
66 QVariant action = data[QDBusMenuModel::Action];
67 m_action = actionGroup()->action(action.toString());
68 if (m_action->isValid()) {
69 updateNetworkStatus(m_action->state());
71 connect(m_action, SIGNAL(stateChanged(QVariant)), SLOT(updateNetworkStatus(QVariant)));
78QString IndicatorClientNetwork::getIconBasedOnSingal(uint signal) const
81 return "nm-signal-00";
82 } else if (signal <= 25) {
83 return "nm-signal-25";
84 } else if (signal <= 50) {
85 return "nm-signal-50";
86 } else if (signal <= 75) {
87 return "nm-signal-75";
89 return "nm-signal-100";
93void IndicatorClientNetwork::animationNextFrame()
99 iconName = "nm-signal-00";
102 iconName = "nm-signal-25";
105 iconName = "nm-signal-50";
108 iconName = "nm-signal-75";
111 iconName = "nm-signal-100";
120 setIcon(QUrl("image://gicon/" + iconName));
123void IndicatorClientNetwork::updateNetworkStatus(const QVariant &state)
125 if (state.isValid()) {
128 // - Connection state
130 QVariantList states = state.toList();
131 if (states.size() == 3) {
133 uint connectionState = states[1].toUInt();
134 switch (connectionState)
136 case 3: // NM_ACTIVE_CONNECTION_STATE_DEACTIVATING
137 case 1: // NM_ACTIVE_CONNECTION_STATE_ACTIVATING
138 m_timedAnimation.start();
139 iconName = "nm-signal-100";
141 case 2: // NM_ACTIVE_CONNECTION_STATE_ACTIVATED
142 m_timedAnimation.stop();
143 iconName = getIconBasedOnSingal(states[2].toUInt());
145 case 0: // NM_ACTIVE_CONNECTION_STATE_UNKNOWN
147 m_timedAnimation.stop();
148 iconName = "wifi-none";
152 setIcon(QUrl("image://gicon/" + iconName));
155 qWarning() << "Invalid network root state value";
156 m_timedAnimation.stop();
160 qWarning() << "Invalid network root state";
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list