simple sqlite-based call history

still doesn't get updated real-time
This commit is contained in:
Marco Martin 2015-04-26 19:50:19 +02:00
parent c3f65ad5e8
commit 16cbc31fd1
2 changed files with 71 additions and 0 deletions

View file

@ -36,6 +36,7 @@ Item {
status.text = status.text + number status.text = status.text + number
} }
//TODO: move in root item
function call() { function call() {
if (!voiceCallmanager.activeVoiceCall) { if (!voiceCallmanager.activeVoiceCall) {
console.log("Calling: " + status.text); console.log("Calling: " + status.text);

View file

@ -21,10 +21,80 @@ 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.kde.plasma.extras 2.0 as PlasmaExtras
import QtQuick.LocalStorage 2.0
Item { Item {
//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})
}
}
)
}
PlasmaComponents.Label { PlasmaComponents.Label {
anchors.centerIn: parent anchors.centerIn: parent
text: i18n("No recent calls") text: i18n("No recent calls")
visible: false
}
PlasmaExtras.ScrollArea {
anchors.fill: parent
ListView {
id: view
model: ListModel {
id: historyModel
}
delegate: MouseArea {
width: view.width
height: childrenRect.height
onClicked: call(model.number);
RowLayout {
width: view.width
PlasmaComponents.Label {
text: model.number
Layout.fillWidth: true
}
PlasmaComponents.Label {
text: Qt.formatDateTime(model.time, Qt.locale().dateTimeFormat(Locale.LongFormat));
}
}
}
}
} }
} }