correctly insert values in the history

This commit is contained in:
Marco Martin 2015-04-26 21:36:17 +02:00
parent 16cbc31fd1
commit c58e932db2
3 changed files with 125 additions and 67 deletions

View file

@ -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

View file

@ -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));
}
}
}

View file

@ -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();
}
}