on aa5da49 help sign in
unity8/qml/Panel/ActiveCallHint.qml
206 lines 6.2 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.0
18import Ubuntu.Telephony 0.1 as Telephony
19import Ubuntu.Components 0.1
20import Unity.Application 0.1
21import "../Components"
23Item {
24 id: callHint
26 readonly property bool active: {
27 var application = ApplicationManager.findApplication("dialer-app");
29 if (callManager.callIndicatorVisible) {
30 // at the moment, callIndicatorVisible is only "valid" if dialer is in focus.
31 if (application && ApplicationManager.focusedApplicationId === "dialer-app") {
32 // Don't show if application is still starting; might get a fleeting true/false.
33 return application.state !== ApplicationInfoInterface.Starting;
34 }
35 }
36 if (ApplicationManager.focusedApplicationId !== "dialer-app") {
37 if (application) {
38 // Don't show if application is still starting; might get a fleeting true/false.
39 return application.state !== ApplicationInfoInterface.Starting && callManager.hasCalls;
40 }
41 return callManager.hasCalls;
42 }
43 return false;
44 }
45 readonly property QtObject contactWatcher: _contactWatcher
46 property int labelSwitchInterval: 6000
47 implicitWidth: row.x + row.width
49 Component.onCompleted: {
50 telepathyHelper.registerChannelObserver("unity8");
51 }
53 function showLiveCall() {
54 Qt.openUrlExternally("dialer:///?view=liveCall");
55 }
57 Component {
58 id: contactColumn
60 Column {
61 id: column
62 objectName: "contactColumn"
64 anchors.left: parent.left
66 Component.onCompleted: {
67 if (index === 0) {
68 labelPathView.column1 = column;
69 } else {
70 labelPathView.column2 = column;
71 }
72 }
74 Label {
75 height: callHint.height
76 verticalAlignment: Text.AlignVCenter
77 text: i18n.tr("Tap to return to call...");
78 }
80 Label {
81 objectName: "contactLabel"
82 height: callHint.height
83 verticalAlignment: Text.AlignVCenter
84 width: Math.max(contentWidth, 1)
86 text: {
87 if (!d.activeCall) {
88 return "";
89 } else if (d.activeCall.isConference) {
90 return i18n.tr("Conference");
91 } else {
92 return contactWatcher.alias !== "" ? contactWatcher.alias : contactWatcher.phoneNumber;
93 }
94 }
95 }
96 }
97 }
99 Row {
100 id: row
101 anchors {
102 top: parent.top
103 bottom: parent.bottom
104 left: parent.left
105 leftMargin: units.gu(1)
106 }
107 spacing: units.gu(1)
109 Label {
110 id: time
111 objectName: "timeLabel"
113 anchors {
114 top: parent.top
115 bottom: parent.bottom
116 }
117 verticalAlignment: Text.AlignVCenter
118 horizontalAlignment: Text.AlignRight
119 text: {
120 var m = Math.round(d.callTime/60);
121 var ss = d.callTime % 60;
122 if (ss >= 10) {
123 return m + ":" + ss;
124 } else {
125 return m + ":0" + ss;
126 }
127 }
128 }
130 PathView {
131 id: labelPathView
132 objectName: "labelPathView"
134 anchors {
135 top: parent.top
136 bottom: parent.bottom
137 }
138 width: column1 && column2 ? Math.max(column1.width, column1.width) : 0
139 clip: true
141 property Column column1
142 property Column column2
143 property int columnHeight: column1 ? column1.height : 0
145 delegate: contactColumn
146 model: 2
147 offset: 0
148 interactive: false
150 path: Path {
151 startY: -labelPathView.columnHeight / 2
152 PathLine {
153 y: labelPathView.columnHeight * 1.5
154 }
155 }
157 Behavior on offset {
158 id: offsetBehaviour
159 SmoothedAnimation {
160 id: offsetAnimation
161 // ensure we go faster than the label switch
162 duration: labelSwitchInterval/8
163 velocity: 0.75
164 easing.type: Easing.InOutQuad
165 }
166 }
167 }
168 }
170 Timer {
171 id: alternateLabelTimer
172 running: callHint.active
173 interval: labelPathView.offset % 1.0 !== 0 ? labelSwitchInterval : labelSwitchInterval/4
174 repeat: true
176 onRunningChanged: {
177 if (running) {
178 offsetBehaviour.enabled = false;
179 labelPathView.offset = 0;
180 offsetBehaviour.enabled = true;
181 }
182 }
184 onTriggered: {
185 labelPathView.offset = labelPathView.offset + 0.5;
186 }
187 }
189 Telephony.ContactWatcher {
190 id: _contactWatcher
191 objectName: "contactWatcher"
192 phoneNumber: d.activeCall ? d.activeCall.phoneNumber : ""
193 }
195 QtObject {
196 id: d
198 property QtObject activeCall: {
199 if (callManager.foregroundCall) {
200 return callManager.foregroundCall;
201 }
202 return callManager.backgroundCall;
203 }
204 property int callTime: activeCall ? activeCall.elapsedTime : 0
205 }