wrap voiceCall calls to a single qml file

this will make easier to port to $whatever if needed
This commit is contained in:
Marco Martin 2015-05-13 12:51:56 +02:00
parent 248095bdf3
commit e640d7f33f
4 changed files with 227 additions and 104 deletions

View file

@ -22,17 +22,15 @@ import QtQuick 2.0
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.nemomobile.voicecall 1.0
import "../Dialpad" import "../Dialpad"
Item { Item {
id: callPage id: callPage
state: voiceCallmanager.activeVoiceCall ? voiceCallmanager.activeVoiceCall.statusText : "disconnected" property string status: ofonoWrapper.status
property int status: voiceCallmanager.activeVoiceCall ? voiceCallmanager.activeVoiceCall.status : 0
property string providerId: voiceCallmanager.providers.id(0) property string providerId: ofonoWrapper.providerId
function secondsToTimeString(seconds) { function secondsToTimeString(seconds) {
seconds = Math.floor(seconds/1000) seconds = Math.floor(seconds/1000)
@ -46,7 +44,7 @@ Item {
} }
onStatusChanged: { onStatusChanged: {
if (status != 1) { if (status != "active") {
dialerButton.checked = false; dialerButton.checked = false;
} }
} }
@ -68,7 +66,7 @@ Item {
contentWidth: topContents.width contentWidth: topContents.width
contentHeight: topContents.height contentHeight: topContents.height
interactive: status == 1; interactive: status == "active";
Row { Row {
id: topContents id: topContents
Avatar { Avatar {
@ -80,9 +78,7 @@ Item {
height: topFlickable.height height: topFlickable.height
callback: function (string) { callback: function (string) {
if (voiceCallmanager.activeVoiceCall) { ofonoWrapper.sendToneToCall(string);
voiceCallmanager.activeVoiceCall.sendDtmf(string);
}
} }
} }
} }
@ -113,7 +109,7 @@ Item {
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter verticalAlignment: Qt.AlignVCenter
font.pointSize: theme.defaultFont.pointSize * 2 font.pointSize: theme.defaultFont.pointSize * 2
text: voiceCallmanager.activeVoiceCall ? voiceCallmanager.activeVoiceCall.lineId : "" text: ofonoWrapper.lineId
} }
PlasmaComponents.Label { PlasmaComponents.Label {
Layout.fillWidth: true Layout.fillWidth: true
@ -121,29 +117,29 @@ Item {
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter verticalAlignment: Qt.AlignVCenter
text: { text: {
if (!voiceCallmanager.activeVoiceCall) { if (!ofonoWrapper.hasActiveCall) {
return ''; return '';
//STATUS_DIALING //STATUS_DIALING
} else if (voiceCallmanager.activeVoiceCall.status == 3) { } else if (ofonoWrapper.status == "dialing") {
return i18n("Calling..."); return i18n("Calling...");
} else if (voiceCallmanager.activeVoiceCall.duration > 0) { } else if (ofonoWrapper.duration > 0) {
return secondsToTimeString(voiceCallmanager.activeVoiceCall.duration); return secondsToTimeString(ofonoWrapper.duration);
} else { } else {
return ''; return '';
} }
} }
} }
PlasmaComponents.ButtonRow { PlasmaComponents.ButtonRow {
opacity: status == 1 ? 1 : 0 opacity: status == "active" ? 1 : 0
exclusive: false exclusive: false
spacing: 0 spacing: 0
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
id: muteButton id: muteButton
flat: false flat: false
iconSource: voiceCallmanager.isMicrophoneMuted ? "audio-volume-muted" : "audio-volume-high" iconSource: ofonoWrapper.isMicrophoneMuted ? "audio-volume-muted" : "audio-volume-high"
onClicked: { onClicked: {
voiceCallmanager.isMicrophoneMuted = !voiceCallmanager.isMicrophoneMuted; ofonoWrapper.isMicrophoneMuted = !ofonoWrapper.isMicrophoneMuted;
} }
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
@ -170,30 +166,24 @@ Item {
AnswerSwipe { AnswerSwipe {
anchors.fill: parent anchors.fill: parent
//STATUS_INCOMING //STATUS_INCOMING
visible: status == 5 visible: status == "incoming"
onAccepted: { onAccepted: {
if (voiceCallmanager.activeVoiceCall) { ofonoWrapper.answer();
voiceCallmanager.activeVoiceCall.answer();
}
} }
onRejected: { onRejected: {
if (voiceCallmanager.activeVoiceCall) { ofonoWrapper.hangup();
voiceCallmanager.activeVoiceCall.hangup();
}
} }
} }
PlasmaComponents.Button { PlasmaComponents.Button {
anchors.fill: parent anchors.fill: parent
//STATUS_INCOMING //STATUS_INCOMING
visible: status != 5 visible: status != "incoming"
iconSource: "call-stop" iconSource: "call-stop"
Layout.fillWidth: true Layout.fillWidth: true
text: i18n("End Call") text: i18n("End Call")
onClicked: { onClicked: {
if (voiceCallmanager.activeVoiceCall) { ofonoWrapper.hangup();
voiceCallmanager.activeVoiceCall.hangup();
}
} }
} }
} }

View file

@ -22,7 +22,6 @@ import QtQuick 2.0
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.nemomobile.voicecall 1.0
import "../Dialpad" import "../Dialpad"
Item { Item {
@ -30,7 +29,7 @@ Item {
property alias numberEntryText: status.text property alias numberEntryText: status.text
property string providerId: voiceCallmanager.providers.id(0) property string providerId: ofonoWrapper.providerId
function addNumber(number) { function addNumber(number) {
status.text = status.text + number status.text = status.text + number
@ -59,10 +58,10 @@ Item {
addNumber(string); addNumber(string);
} }
pressedCallback: function (string) { pressedCallback: function (string) {
voiceCallmanager.startDtmfTone(string); ofonoWrapper.startTone(string);
} }
releasedCallback: function (string) { releasedCallback: function (string) {
voiceCallmanager.stopDtmfTone(); ofonoWrapper.stopTone();
} }
} }

View file

@ -0,0 +1,195 @@
/**
* Copyright 2015 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.3
import org.nemomobile.voicecall 1.0
Item {
id: root
//BEGIN PROPERTIES
property string status: "idle"
//support a single provider for now
property string providerId: voiceCallmanager.providers.id(0)
//was the last call an incoming one?
property bool isIncoming: voiceCallmanager.activeVoiceCall ? voiceCallmanager.activeVoiceCall.isIncoming : false
//is there a call in progress?
property bool hasActiveCall: voiceCallmanager.activeVoiceCall ? true : false
//if there is an active call, to what number?
property string lineId: voiceCallmanager.activeVoiceCall ? voiceCallmanager.activeVoiceCall.lineId : ""
//if there is a call, for how long?
property int duration: voiceCallmanager.activeVoiceCall ? voiceCallmanager.activeVoiceCall.duration : 0
//microphone muted?
property alias isMicrophoneMuted: voiceCallmanager.isMicrophoneMuted
//END PROPERTIES
//BEGIN SIGNAL HANDLERS
Connections {
target: dialerUtils
onMissedCallsActionTriggered: {
root.visible = true;
}
}
onVisibleChanged: {
//reset missed calls if the status is not STATUS_INCOMING when got visible
if (visible && status != 5) {
dialerUtils.resetMissedCalls();
}
}
//END SIGNAL HANDLERS
//BEGIN FUNCTIONS
function call(number) {
if (!voiceCallmanager.activeVoiceCall) {
console.log("Calling: " + providerId + " " + number);
voiceCallmanager.dial(providerId, number);
} else {
console.log("Hanging up: " + voiceCallmanager.activeVoiceCall.lineId);
status.text = '';
var call = voiceCallmanager.activeVoiceCall;
if (call) {
call.hangup();
}
}
}
function answer() {
if (voiceCallmanager.activeVoiceCall) {
voiceCallmanager.activeVoiceCall.answer();
}
}
function hangup() {
if (voiceCallmanager.activeVoiceCall) {
voiceCallmanager.activeVoiceCall.hangup();
}
}
function sendToneToCall(key) {
if (voiceCallmanager.activeVoiceCall) {
voiceCallmanager.activeVoiceCall.sendDtmf(key);
}
}
function startTone(string) {
voiceCallmanager.startDtmfTone(string);
}
function stopTone() {
voiceCallmanager.stopDtmfTone();
}
//END FUNCTIONS
//BEGIN DATABASE
Component.onCompleted: {
//HACK: make sure activeVoiceCall is loaded if already existing
voiceCallmanager.voiceCalls.onVoiceCallsChanged();
voiceCallmanager.onActiveVoiceCallChanged();
}
//END DATABASE
//BEGIN MODELS
VoiceCallManager {
id: voiceCallmanager
property int status: activeVoiceCall ? activeVoiceCall.status : 0
//keep track of the status we were in
property int previousStatus
onStatusChanged: {
//STATUS_INCOMING
if (status == 5) {
wasVisible = root.visible;
root.visible = true;
dialerUtils.notifyRinging();
//Was STATUS_INCOMING now is STATUS_DISCONNECTED: Missed call!
} else if (status == 7 && previousStatus == 5) {
var prettyDate = Qt.formatTime(voiceCallmanager.activeVoiceCall.startedAt, Qt.locale().timeFormat(Locale.ShortFormat));
dialerUtils.notifyMissedCall(voiceCallmanager.activeVoiceCall.lineId, i18n("%1 called at %2", voiceCallmanager.activeVoiceCall.lineId, prettyDate));
root.visible = wasVisible;
insertCallInHistory(voiceCallmanager.activeVoiceCall.lineId, 0, 0);
//STATUS_DISCONNECTED
} else if (status == 7) {
insertCallInHistory(voiceCallmanager.activeVoiceCall.lineId, voiceCallmanager.activeVoiceCall.duration, voiceCallmanager.activeVoiceCall.isIncoming ? 1 : 2);
}
//status not STATUS_INCOMING
if (status != 5) {
dialerUtils.stopRinging();
}
previousStatus = status;
switch (status) {
case 1:
root.status = "active";
break;
case 2:
root.status = "held";
break;
case 3:
root.status = "dialing";
break;
case 4:
root.status = "alerting";
break;
case 5:
root.status = "incoming";
break;
case 6:
root.status = "waiting";
break;
case 7:
root.status = "disconnected";
break;
case 0:
default:
root.status = "idle";
break;
}
}
onActiveVoiceCallChanged: {
if (activeVoiceCall) {
//main.activeVoiceCallPerson = people.personByPhoneNumber(activeVoiceCall.lineId);
// dialerOverlay.item.numberEntryText = activeVoiceCall.lineId;
} else {
// dialerOverlay.item.numberEntryText = '';
//main.activeVoiceCallPerson = null;
}
}
onError: {
console.log('*** QML *** VCM ERROR: ' + message);
}
}
//END MODELS
}

View file

@ -22,7 +22,6 @@ import QtQuick 2.3
import QtQuick.Controls 1.3 import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import QtQuick.LocalStorage 2.0 import QtQuick.LocalStorage 2.0
import org.nemomobile.voicecall 1.0
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.extras 2.0 as PlasmaExtras
@ -33,44 +32,15 @@ ApplicationWindow {
width: 600 width: 600
height: 800 height: 800
property int status: voiceCallmanager.activeVoiceCall ? voiceCallmanager.activeVoiceCall.status : 0
//keep track of the status we were in
property int previousStatus
//keep track if we were visible when ringing //keep track if we were visible when ringing
property bool wasVisible property bool wasVisible
//support a single provider for now //support a single provider for now
property string providerId: voiceCallmanager.providers.id(0) property string providerId: ofonoWrapper.providerId
//was the last call an incoming one? //was the last call an incoming one?
property bool isIncoming property bool isIncoming
//END PROPERTIES //END PROPERTIES
//BEGIN SIGNAL HANDLERS //BEGIN SIGNAL HANDLERS
onStatusChanged: {
//STATUS_ACTIVE
if (status == 1) {
root.isIncoming = voiceCallmanager.activeVoiceCall.isIncoming;
//STATUS_INCOMING
} else if (status == 5) {
wasVisible = root.visible;
root.visible = true;
dialerUtils.notifyRinging();
//Was STATUS_INCOMING now is STATUS_DISCONNECTED: Missed call!
} else if (status == 7 && previousStatus == 5) {
var prettyDate = Qt.formatTime(voiceCallmanager.activeVoiceCall.startedAt, Qt.locale().timeFormat(Locale.ShortFormat));
dialerUtils.notifyMissedCall(voiceCallmanager.activeVoiceCall.lineId, i18n("%1 called at %2", voiceCallmanager.activeVoiceCall.lineId, prettyDate));
root.visible = wasVisible;
insertCallInHistory(voiceCallmanager.activeVoiceCall.lineId, 0, 0);
} else if (status == 7) {
insertCallInHistory(voiceCallmanager.activeVoiceCall.lineId, voiceCallmanager.activeVoiceCall.duration, isIncoming ? 1 : 2);
}
if (status != 5) {
dialerUtils.stopRinging();
}
previousStatus = status;
}
Connections { Connections {
target: dialerUtils target: dialerUtils
onMissedCallsActionTriggered: { onMissedCallsActionTriggered: {
@ -80,7 +50,7 @@ ApplicationWindow {
onVisibleChanged: { onVisibleChanged: {
//reset missed calls if the status is not STATUS_INCOMING when got visible //reset missed calls if the status is not STATUS_INCOMING when got visible
if (visible && status != 5) { if (visible && ofonoWrapper.status != "incoming") {
dialerUtils.resetMissedCalls(); dialerUtils.resetMissedCalls();
} }
} }
@ -88,18 +58,7 @@ ApplicationWindow {
//BEGIN FUNCTIONS //BEGIN FUNCTIONS
function call(number) { function call(number) {
if (!voiceCallmanager.activeVoiceCall) { ofonoWrapper.call(number);
console.log("Calling: " + providerId + " " + number);
voiceCallmanager.dial(providerId, number);
} else {
console.log("Hanging up: " + voiceCallmanager.activeVoiceCall.lineId);
status.text = '';
var call = voiceCallmanager.activeVoiceCall;
if (call) {
call.hangup();
}
}
} }
function insertCallInHistory(number, duration, callType) { function insertCallInHistory(number, duration, callType) {
@ -157,10 +116,6 @@ ApplicationWindow {
//BEGIN DATABASE //BEGIN DATABASE
Component.onCompleted: { Component.onCompleted: {
//HACK: make sure activeVoiceCall is loaded if already existing
voiceCallmanager.voiceCalls.onVoiceCallsChanged();
voiceCallmanager.onActiveVoiceCallChanged();
//DATABSE //DATABSE
var db = LocalStorage.openDatabaseSync("PlasmaPhoneDialer", "1.0", "Call history of the Plasma Phone dialer", 1000000); var db = LocalStorage.openDatabaseSync("PlasmaPhoneDialer", "1.0", "Call history of the Plasma Phone dialer", 1000000);
@ -188,24 +143,8 @@ ApplicationWindow {
id: historyModel id: historyModel
} }
VoiceCallManager { OfonoWrapper {
id: voiceCallmanager id: ofonoWrapper
onActiveVoiceCallChanged: {
if (activeVoiceCall) {
//main.activeVoiceCallPerson = people.personByPhoneNumber(activeVoiceCall.lineId);
// dialerOverlay.item.numberEntryText = activeVoiceCall.lineId;
} else {
// dialerOverlay.item.numberEntryText = '';
//main.activeVoiceCallPerson = null;
}
}
onError: {
console.log('*** QML *** VCM ERROR: ' + message);
}
} }
//END MODELS //END MODELS
@ -213,10 +152,10 @@ ApplicationWindow {
//BEGIN UI //BEGIN UI
PlasmaExtras.ConditionalLoader { PlasmaExtras.ConditionalLoader {
anchors.fill: parent anchors.fill: parent
when: root.visible && root.status == 0 when: root.visible && ofonoWrapper.status == "idle"
source: Qt.resolvedUrl("Dialer/DialPage.qml") source: Qt.resolvedUrl("Dialer/DialPage.qml")
z: root.status == 0 ? 2 : 0 z: ofonoWrapper.status == "idle" ? 2 : 0
opacity: root.status == 0 ? 1 : 0 opacity: ofonoWrapper.status == "idle" ? 1 : 0
Behavior on opacity { Behavior on opacity {
OpacityAnimator { OpacityAnimator {
duration: units.shortDuration duration: units.shortDuration
@ -227,10 +166,10 @@ ApplicationWindow {
PlasmaExtras.ConditionalLoader { PlasmaExtras.ConditionalLoader {
anchors.fill: parent anchors.fill: parent
when: root.status > 0 when: ofonoWrapper.status != "idle"
source: Qt.resolvedUrl("Call/CallPage.qml") source: Qt.resolvedUrl("Call/CallPage.qml")
opacity: root.status > 0 ? 1 : 0 opacity: ofonoWrapper.status != "idle" ? 1 : 0
z: root.status > 0 ? 2 : 0 z: ofonoWrapper.status != "idle" ? 2 : 0
Behavior on opacity { Behavior on opacity {
OpacityAnimator { OpacityAnimator {
duration: units.shortDuration duration: units.shortDuration