Lomiri
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 Lomiri.Telephony 0.1 as Telephony
19 import Lomiri.Components 1.3
20 import QtMir.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("lomiri");
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  color: theme.palette.normal.activityText
81  }
82 
83  Label {
84  objectName: "contactLabel"
85  height: callHint.height
86  verticalAlignment: Text.AlignVCenter
87  width: Math.max(contentWidth, 1)
88 
89  text: {
90  if (!d.activeCall) {
91  return "";
92  } else if (d.activeCall.isConference) {
93  return i18n.tr("Conference");
94  } else {
95  return contactWatcher.alias !== "" ? contactWatcher.alias : contactWatcher.phoneNumber;
96  }
97  }
98  color: theme.palette.normal.activityText
99  }
100  }
101  }
102 
103  Row {
104  id: row
105  anchors {
106  top: parent.top
107  bottom: parent.bottom
108  left: parent.left
109  leftMargin: units.gu(1)
110  }
111  spacing: units.gu(1)
112 
113  Label {
114  id: time
115  objectName: "timeLabel"
116 
117  anchors {
118  top: parent.top
119  bottom: parent.bottom
120  }
121  verticalAlignment: Text.AlignVCenter
122  horizontalAlignment: Text.AlignRight
123  text: {
124  var m = Math.floor(d.callTime/60);
125  var ss = d.callTime % 60;
126  if (ss >= 10) {
127  return m + ":" + ss;
128  } else {
129  return m + ":0" + ss;
130  }
131  }
132  color: theme.palette.normal.activityText
133  }
134 
135  PathView {
136  id: labelPathView
137  objectName: "labelPathView"
138 
139  anchors {
140  top: parent.top
141  bottom: parent.bottom
142  }
143  width: column1 && column2 ? Math.max(column1.width, column1.width) : 0
144  clip: true
145 
146  property Column column1
147  property Column column2
148  property int columnHeight: column1 ? column1.height : 0
149 
150  delegate: contactColumn
151  model: 2
152  offset: 0
153  interactive: false
154 
155  path: Path {
156  startY: -labelPathView.columnHeight / 2
157  PathLine {
158  y: labelPathView.columnHeight * 1.5
159  }
160  }
161 
162  Behavior on offset {
163  id: offsetBehaviour
164  SmoothedAnimation {
165  id: offsetAnimation
166  // ensure we go faster than the label switch
167  duration: labelSwitchInterval/8
168  velocity: 0.75
169  easing.type: Easing.InOutQuad
170  }
171  }
172  }
173  }
174 
175  Timer {
176  id: alternateLabelTimer
177  running: callHint.active
178  interval: labelPathView.offset % 1.0 !== 0 ? labelSwitchInterval : labelSwitchInterval/4
179  repeat: true
180 
181  onRunningChanged: {
182  if (running) {
183  offsetBehaviour.enabled = false;
184  labelPathView.offset = 0;
185  offsetBehaviour.enabled = true;
186  }
187  }
188 
189  onTriggered: {
190  labelPathView.offset = labelPathView.offset + 0.5;
191  }
192  }
193 
194  Telephony.ContactWatcher {
195  id: _contactWatcher
196  objectName: "contactWatcher"
197  phoneNumber: d.activeCall ? d.activeCall.phoneNumber : ""
198  }
199 
200  QtObject {
201  id: d
202 
203  property QtObject activeCall: {
204  if (callManager.foregroundCall) {
205  return callManager.foregroundCall;
206  }
207  return callManager.backgroundCall;
208  }
209  property int callTime: activeCall ? activeCall.elapsedTime : 0
210  }
211 }