From c58e932db2a3254a513a670b9e3aef06df68d0e9 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sun, 26 Apr 2015 21:36:17 +0200 Subject: [PATCH] correctly insert values in the history --- dialer/package/contents/ui/Dialer/Dialer.qml | 20 +---- dialer/package/contents/ui/Dialer/History.qml | 83 ++++++++--------- dialer/package/contents/ui/main.qml | 89 +++++++++++++++++-- 3 files changed, 125 insertions(+), 67 deletions(-) diff --git a/dialer/package/contents/ui/Dialer/Dialer.qml b/dialer/package/contents/ui/Dialer/Dialer.qml index 061ae94e..da2806b7 100644 --- a/dialer/package/contents/ui/Dialer/Dialer.qml +++ b/dialer/package/contents/ui/Dialer/Dialer.qml @@ -36,22 +36,6 @@ Item { status.text = status.text + number } - //TODO: move in root item - function call() { - if (!voiceCallmanager.activeVoiceCall) { - console.log("Calling: " + status.text); - voiceCallmanager.dial(providerId, status.text); - - } else { - console.log("Hanging up: " + status.text); - status.text = ''; - var call = voiceCallmanager.activeVoiceCall; - if (call) { - call.hangup(); - } - } - } - ColumnLayout { id: dialPadArea @@ -94,7 +78,9 @@ Item { enabled: status.text.length > 0 opacity: enabled ? 1 : 0.5 source: "call-start" - callback: call + callback: function() { + call(status.text); + } } Item { Layout.minimumWidth: dialPadArea.width/3 diff --git a/dialer/package/contents/ui/Dialer/History.qml b/dialer/package/contents/ui/Dialer/History.qml index c117fa59..a21e503c 100644 --- a/dialer/package/contents/ui/Dialer/History.qml +++ b/dialer/package/contents/ui/Dialer/History.qml @@ -22,49 +22,19 @@ import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras -import QtQuick.LocalStorage 2.0 -Item { +Rectangle { + color: syspal.base - //TODO: move in root item - property string providerId: voiceCallmanager.providers.id(0) - function call(number) { - if (!voiceCallmanager.activeVoiceCall) { - console.log("Calling: " + status.text); - voiceCallmanager.dial(providerId, number); - - } else { - console.log("Hanging up: " + status.text); - status.text = ''; - var call = voiceCallmanager.activeVoiceCall; - if (call) { - call.hangup(); - } - } - } - - Component.onCompleted: { - var db = LocalStorage.openDatabaseSync("PlasmaPhoneDialer", "1.0", "Call history of the Plasma Phone dialer", 1000000); - - db.transaction( - function(tx) { - // Create the database if it doesn't already exist - //callType: wether is incoming, outgoing, unanswered - tx.executeSql('CREATE TABLE IF NOT EXISTS History(number TEXT, time DATETIME, callType TEXT)'); - - // Add (another) greeting row - //tx.executeSql("INSERT INTO History VALUES(?, datetime('now') )", ['+39000']); - - // Show all added greetings - var rs = tx.executeSql('SELECT * FROM History'); - - var r = "" - for(var i = 0; i < rs.rows.length; i++) { - r += rs.rows.item(i).number + ", " + rs.rows.item(i).time + "\n" - historyModel.append({number: rs.rows.item(i).number, time: rs.rows.item(i).time}) - } - } - ) + function secondsToTimeString(seconds) { + seconds = Math.floor(seconds/1000) + var h = Math.floor(seconds / 3600); + var m = Math.floor((seconds - (h * 3600)) / 60); + var s = seconds - h * 3600 - m * 60; + if(h < 10) h = '0' + h; + if(m < 10) m = '0' + m; + if(s < 10) s = '0' + s; + return '' + h + ':' + m + ':' + s; } PlasmaComponents.Label { @@ -76,8 +46,18 @@ Item { anchors.fill: parent ListView { id: view - model: ListModel { - id: historyModel + model: historyModel + section { + property: "date" + labelPositioning: ViewSection.CurrentLabelAtStart + delegate: Rectangle { + width: view.width + height: childrenRect.height + color: syspal.base + PlasmaComponents.Label { + text: Qt.formatDate(section, Qt.locale().dateFormat(Locale.LongFormat)); + } + } } delegate: MouseArea { width: view.width @@ -86,12 +66,27 @@ Item { RowLayout { width: view.width + PlasmaComponents.Label { + text: { + switch (model.callType) { + case 0: + return "miss"; + case 1: + return "incoming"; + case 2: + return "outgoing"; + } + } + } PlasmaComponents.Label { text: model.number Layout.fillWidth: true } PlasmaComponents.Label { - text: Qt.formatDateTime(model.time, Qt.locale().dateTimeFormat(Locale.LongFormat)); + text: i18n("Duration: %1", secondsToTimeString(model.duration)); + } + PlasmaComponents.Label { + text: Qt.formatTime(model.date+" "+model.time, Qt.locale().timeFormat(Locale.LongFormat)); } } } diff --git a/dialer/package/contents/ui/main.qml b/dialer/package/contents/ui/main.qml index 8e9dbce9..7cd2b453 100644 --- a/dialer/package/contents/ui/main.qml +++ b/dialer/package/contents/ui/main.qml @@ -21,6 +21,7 @@ import QtQuick 2.3 import QtQuick.Controls 1.3 import QtQuick.Layouts 1.1 +import QtQuick.LocalStorage 2.0 import org.nemomobile.voicecall 1.0 import MeeGo.QOfono 0.2 import org.kde.plasma.core 2.0 as PlasmaCore @@ -38,18 +39,28 @@ ApplicationWindow { property int previousStatus //keep track if we were visible when ringing property bool wasVisible + //support a single provider for now + property string providerId: voiceCallmanager.providers.id(0) + //was the last call an incoming one? + property bool isIncoming //END PROPERTIES //BEGIN SIGNAL HANDLERS onStatusChanged: { + //STATUS_ACTIVE + if (status == 1) { + root.isIncoming = voiceCallmanager.activeVoiceCall.isIncoming; //STATUS_INCOMING - if (status == 5) { + } else if (status == 5) { wasVisible = root.visible; root.visible = true; //Was STATUS_INCOMING now is STATUS_DISCONNECTED: Missed call! } else if (status == 7 && previousStatus == 5) { dialerUtils.notifyMissedCall(); root.visible = wasVisible; + insertCallInHistory(voiceCallmanager.activeVoiceCall.lineId, 0, 0); + } else if (status == 7) { + insertCallInHistory(voiceCallmanager.activeVoiceCall.lineId, voiceCallmanager.activeVoiceCall.duration, isIncoming ? 1 : 2); } previousStatus = status; @@ -70,7 +81,76 @@ ApplicationWindow { } //END SIGNAL HANDLERS +//BEGIN FUNCTIONS + function call(number) { + if (!voiceCallmanager.activeVoiceCall) { + console.log("Calling: " + status.text); + voiceCallmanager.dial(providerId, number); + + } else { + console.log("Hanging up: " + status.text); + status.text = ''; + var call = voiceCallmanager.activeVoiceCall; + if (call) { + call.hangup(); + } + } + } + + function insertCallInHistory(number, duration, callType) { + //DATABSE + var db = LocalStorage.openDatabaseSync("PlasmaPhoneDialer", "1.0", "Call history of the Plasma Phone dialer", 1000000); + + db.transaction( + function(tx) { + var rs = tx.executeSql("INSERT INTO History VALUES(NULL, ?, date('now'), time('now'), ?, ? )", [number, duration, callType]); + + // Show all added greetings + var rs = tx.executeSql('SELECT * FROM History where id=?', [rs.insertId]); + + for(var i = 0; i < rs.rows.length; i++) { + historyModel.append(rs.rows.item(i)); + } + } + ) + } + +//END FUNCTIONS + +//BEGIN DATABASE + Component.onCompleted: { + //HACK: make sure activeVoiceCall is loaded if already existing + voiceCallmanager.voiceCalls.onVoiceCallsChanged(); + voiceCallmanager.onActiveVoiceCallChanged(); + + //DATABSE + var db = LocalStorage.openDatabaseSync("PlasmaPhoneDialer", "1.0", "Call history of the Plasma Phone dialer", 1000000); + + db.transaction( + function(tx) { + // Create the database if it doesn't already exist + //callType: wether is incoming, outgoing, unanswered + tx.executeSql('CREATE TABLE IF NOT EXISTS History(id INTEGER PRIMARY KEY AUTOINCREMENT, number TEXT, date DATE, time TIME, duration INTEGER, callType INTEGER)'); + + // Add (another) greeting row + // tx.executeSql("INSERT INTO History VALUES(NULL, ?, date('now'), time('now'), ? )", ['+39000', 0]); + + // Show all added greetings + var rs = tx.executeSql('SELECT * FROM History'); + + for(var i = 0; i < rs.rows.length; i++) { + historyModel.append(rs.rows.item(i)); + } + } + ) + } +//END DATABASE + //BEGIN MODELS + ListModel { + id: historyModel + } + OfonoManager { id: ofonoManager onAvailableChanged: { @@ -142,6 +222,8 @@ ApplicationWindow { console.log('*** QML *** VCM ERROR: ' + message); } } + + SystemPalette {id: syspal} //END MODELS //BEGIN UI @@ -174,9 +256,4 @@ ApplicationWindow { } //END UI - Component.onCompleted: { - //HACK: make sure activeVoiceCall is loaded if already existing - voiceCallmanager.voiceCalls.onVoiceCallsChanged(); - voiceCallmanager.onActiveVoiceCallChanged(); - } }