on d4bcf25 help sign in
unity8/Panel/Indicators/NetworkIndicatorWidget.qml
116 lines 3.4 kB history raw
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 * Authors:
17 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
20import QtQuick 2.0
21import Ubuntu.Components 0.1
22import Unity.Indicators 0.1 as Indicators
24Indicators.IndicatorWidget {
25 id: indicatorWidget
27 width: networkIcon.width + units.gu(1)
29 property int signalStrength: 0
30 property int connectionState: 0
32 Image {
33 id: networkIcon
34 objectName: "itemImage"
35 source: get_icon_for_signal(connectionState, signalStrength)
36 visible: source != ""
37 height: indicatorWidget.iconSize
38 width: indicatorWidget.iconSize
39 anchors {
40 verticalCenter: parent.verticalCenter
41 horizontalCenter: parent.horizontalCenter
42 }
43 }
45 function parseRootElement(type, data) {
46 if (type == "com.canonical.indicator.root.network")
47 return true;
48 return false;
49 }
51 onActionStateChanged: {
52 if (action == undefined || !action.valid) {
53 return;
54 }
56 if (action.state == undefined) {
57 connectionState = 0;
58 return;
59 }
61 connectionState = action.state[1];
62 if (connectionState == 2) {
63 signalStrength = action.state[2];
64 }
65 }
67 NumberAnimation {
68 id: activation_animation
69 target: indicatorWidget
70 property: "signalStrength"
71 from: 0
72 to: 100
73 duration: 2500 // 5 states in 2.5 seconds
74 loops: Animation.Infinite
75 }
77 states: [
78 State {
79 name: "unknown"
80 when: connectionState > 3 || connectionState < 1
81 PropertyChanges { target: activation_animation; running: false }
82 },
83 State {
84 name: "activating"
85 when: connectionState == 1
86 PropertyChanges { target: activation_animation; running: true }
87 },
88 State {
89 name: "activated"
90 when: connectionState == 2
91 PropertyChanges { target: activation_animation; running: false }
92 },
93 State {
94 name: "deactivating"
95 when: connectionState == 3
96 PropertyChanges { target: activation_animation; running: true }
97 }
98 ]
101 function get_icon_for_signal(con_state, value) {
102 if (con_state >= 1 && con_state <= 3) {
103 if (value == 0) {
104 return "image://gicon/nm-signal-00";
105 } else if (value <= 25) {
106 return "image://gicon/nm-signal-25";
107 } else if (value <= 50) {
108 return "image://gicon/nm-signal-50";
109 } else if (value <= 75) {
110 return "image://gicon/nm-signal-75";
111 }
112 return "image://gicon/nm-signal-100";
113 }
114 return "image://gicon/wifi-none";
115 }