Unity 8
ActiveCallHint.qml
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  */
16 
17 import QtQuick 2.4
18 import Ubuntu.Telephony 0.1 as Telephony
19 import Ubuntu.Components 1.3
20 import Unity.Application 0.1
21 import "../Components"
22 
23 Item {
24  id: callHint
25 
26  property bool greeterShown: false
27 
28  readonly property bool active: {
29  var application = ApplicationManager.findApplication("dialer-app");
30 
31  if (callManager.callIndicatorVisible) {
32  // at the moment, callIndicatorVisible is only "valid" if dialer is in focus.
33  if (application && ApplicationManager.focusedApplicationId === "dialer-app") {
34  // Don't show if application is still starting; might get a fleeting true/false.
35  return application.state !== ApplicationInfoInterface.Starting;
36  }
37  }
38  if (greeterShown || ApplicationManager.focusedApplicationId !== "dialer-app") {
39  if (application) {
40  // Don't show if application is still starting; might get a fleeting true/false.
41  return application.state !== ApplicationInfoInterface.Starting && callManager.hasCalls;
42  }
43  return callManager.hasCalls;
44  }
45  return false;
46  }
47  readonly property QtObject contactWatcher: _contactWatcher
48  property int labelSwitchInterval: 6000
49  implicitWidth: row.x + row.width
50 
51  Component.onCompleted: {
52  telepathyHelper.registerChannelObserver("unity8");
53  }
54 
55  function showLiveCall() {
56  Qt.openUrlExternally("dialer:///?view=liveCall");
57  }
58 
59  Component {
60  id: contactColumn
61 
62  Column {
63  id: column
64  objectName: "contactColumn"
65 
66  anchors.left: parent.left
67 
68  Component.onCompleted: {
69  if (index === 0) {
70  labelPathView.column1 = column;
71  } else {
72  labelPathView.column2 = column;
73  }
74  }
75 
76  Label {
77  height: callHint.height
78  verticalAlignment: Text.AlignVCenter
79  text: i18n.tr("Tap to return to call...");
80  }
81 
82  Label {
83  objectName: "contactLabel"
84  height: callHint.height
85  verticalAlignment: Text.AlignVCenter
86  width: Math.max(contentWidth, 1)
87 
88  text: {
89  if (!d.activeCall) {
90  return "";
91  } else if (d.activeCall.isConference) {
92  return i18n.tr("Conference");
93  } else {
94  return contactWatcher.alias !== "" ? contactWatcher.alias : contactWatcher.phoneNumber;
95  }
96  }
97  }
98  }
99  }
100 
101  Row {
102  id: row
103  anchors {
104  top: parent.top
105  bottom: parent.bottom
106  left: parent.left
107  leftMargin: units.gu(1)
108  }
109  spacing: units.gu(1)
110 
111  Label {
112  id: time
113  objectName: "timeLabel"
114 
115  anchors {
116  top: parent.top
117  bottom: parent.bottom
118  }
119  verticalAlignment: Text.AlignVCenter
120  horizontalAlignment: Text.AlignRight
121  text: {
122  var m = Math.floor(d.callTime/60);
123  var ss = d.callTime % 60;
124  if (ss >= 10) {
125  return m + ":" + ss;
126  } else {
127  return m + ":0" + ss;
128  }
129  }
130  }
131 
132  PathView {
133  id: labelPathView
134  objectName: "labelPathView"
135 
136  anchors {
137  top: parent.top
138  bottom: parent.bottom
139  }
140  width: column1 && column2 ? Math.max(column1.width, column1.width) : 0
141  clip: true
142 
143  property Column column1
144  property Column column2
145  property int columnHeight: column1 ? column1.height : 0
146 
147  delegate: contactColumn
148  model: 2
149  offset: 0
150  interactive: false
151 
152  path: Path {
153  startY: -labelPathView.columnHeight / 2
154  PathLine {
155  y: labelPathView.columnHeight * 1.5
156  }
157  }
158 
159  Behavior on offset {
160  id: offsetBehaviour
161  SmoothedAnimation {
162  id: offsetAnimation
163  // ensure we go faster than the label switch
164  duration: labelSwitchInterval/8
165  velocity: 0.75
166  easing.type: Easing.InOutQuad
167  }
168  }
169  }
170  }
171 
172  Timer {
173  id: alternateLabelTimer
174  running: callHint.active
175  interval: labelPathView.offset % 1.0 !== 0 ? labelSwitchInterval : labelSwitchInterval/4
176  repeat: true
177 
178  onRunningChanged: {
179  if (running) {
180  offsetBehaviour.enabled = false;
181  labelPathView.offset = 0;
182  offsetBehaviour.enabled = true;
183  }
184  }
185 
186  onTriggered: {
187  labelPathView.offset = labelPathView.offset + 0.5;
188  }
189  }
190 
191  Telephony.ContactWatcher {
192  id: _contactWatcher
193  objectName: "contactWatcher"
194  phoneNumber: d.activeCall ? d.activeCall.phoneNumber : ""
195  }
196 
197  QtObject {
198  id: d
199 
200  property QtObject activeCall: {
201  if (callManager.foregroundCall) {
202  return callManager.foregroundCall;
203  }
204  return callManager.backgroundCall;
205  }
206  property int callTime: activeCall ? activeCall.elapsedTime : 0
207  }
208 }