mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
correctly insert values in the history
This commit is contained in:
parent
16cbc31fd1
commit
c58e932db2
3 changed files with 125 additions and 67 deletions
|
|
@ -36,22 +36,6 @@ Item {
|
||||||
status.text = status.text + number
|
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 {
|
ColumnLayout {
|
||||||
id: dialPadArea
|
id: dialPadArea
|
||||||
|
|
||||||
|
|
@ -94,7 +78,9 @@ Item {
|
||||||
enabled: status.text.length > 0
|
enabled: status.text.length > 0
|
||||||
opacity: enabled ? 1 : 0.5
|
opacity: enabled ? 1 : 0.5
|
||||||
source: "call-start"
|
source: "call-start"
|
||||||
callback: call
|
callback: function() {
|
||||||
|
call(status.text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Item {
|
Item {
|
||||||
Layout.minimumWidth: dialPadArea.width/3
|
Layout.minimumWidth: dialPadArea.width/3
|
||||||
|
|
|
||||||
|
|
@ -22,49 +22,19 @@ 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 org.kde.plasma.extras 2.0 as PlasmaExtras
|
||||||
import QtQuick.LocalStorage 2.0
|
|
||||||
|
|
||||||
Item {
|
Rectangle {
|
||||||
|
color: syspal.base
|
||||||
|
|
||||||
//TODO: move in root item
|
function secondsToTimeString(seconds) {
|
||||||
property string providerId: voiceCallmanager.providers.id(0)
|
seconds = Math.floor(seconds/1000)
|
||||||
function call(number) {
|
var h = Math.floor(seconds / 3600);
|
||||||
if (!voiceCallmanager.activeVoiceCall) {
|
var m = Math.floor((seconds - (h * 3600)) / 60);
|
||||||
console.log("Calling: " + status.text);
|
var s = seconds - h * 3600 - m * 60;
|
||||||
voiceCallmanager.dial(providerId, number);
|
if(h < 10) h = '0' + h;
|
||||||
|
if(m < 10) m = '0' + m;
|
||||||
} else {
|
if(s < 10) s = '0' + s;
|
||||||
console.log("Hanging up: " + status.text);
|
return '' + h + ':' + m + ':' + s;
|
||||||
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 {
|
||||||
|
|
@ -76,8 +46,18 @@ Item {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
ListView {
|
ListView {
|
||||||
id: view
|
id: view
|
||||||
model: ListModel {
|
model: historyModel
|
||||||
id: 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 {
|
delegate: MouseArea {
|
||||||
width: view.width
|
width: view.width
|
||||||
|
|
@ -86,12 +66,27 @@ Item {
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
width: view.width
|
width: view.width
|
||||||
|
PlasmaComponents.Label {
|
||||||
|
text: {
|
||||||
|
switch (model.callType) {
|
||||||
|
case 0:
|
||||||
|
return "miss";
|
||||||
|
case 1:
|
||||||
|
return "incoming";
|
||||||
|
case 2:
|
||||||
|
return "outgoing";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
PlasmaComponents.Label {
|
PlasmaComponents.Label {
|
||||||
text: model.number
|
text: model.number
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
}
|
}
|
||||||
PlasmaComponents.Label {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
import QtQuick 2.3
|
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 org.nemomobile.voicecall 1.0
|
import org.nemomobile.voicecall 1.0
|
||||||
import MeeGo.QOfono 0.2
|
import MeeGo.QOfono 0.2
|
||||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||||
|
|
@ -38,18 +39,28 @@ ApplicationWindow {
|
||||||
property int previousStatus
|
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
|
||||||
|
property string providerId: voiceCallmanager.providers.id(0)
|
||||||
|
//was the last call an incoming one?
|
||||||
|
property bool isIncoming
|
||||||
//END PROPERTIES
|
//END PROPERTIES
|
||||||
|
|
||||||
//BEGIN SIGNAL HANDLERS
|
//BEGIN SIGNAL HANDLERS
|
||||||
onStatusChanged: {
|
onStatusChanged: {
|
||||||
|
//STATUS_ACTIVE
|
||||||
|
if (status == 1) {
|
||||||
|
root.isIncoming = voiceCallmanager.activeVoiceCall.isIncoming;
|
||||||
//STATUS_INCOMING
|
//STATUS_INCOMING
|
||||||
if (status == 5) {
|
} else if (status == 5) {
|
||||||
wasVisible = root.visible;
|
wasVisible = root.visible;
|
||||||
root.visible = true;
|
root.visible = true;
|
||||||
//Was STATUS_INCOMING now is STATUS_DISCONNECTED: Missed call!
|
//Was STATUS_INCOMING now is STATUS_DISCONNECTED: Missed call!
|
||||||
} else if (status == 7 && previousStatus == 5) {
|
} else if (status == 7 && previousStatus == 5) {
|
||||||
dialerUtils.notifyMissedCall();
|
dialerUtils.notifyMissedCall();
|
||||||
root.visible = wasVisible;
|
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;
|
previousStatus = status;
|
||||||
|
|
@ -70,7 +81,76 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
//END SIGNAL HANDLERS
|
//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
|
//BEGIN MODELS
|
||||||
|
ListModel {
|
||||||
|
id: historyModel
|
||||||
|
}
|
||||||
|
|
||||||
OfonoManager {
|
OfonoManager {
|
||||||
id: ofonoManager
|
id: ofonoManager
|
||||||
onAvailableChanged: {
|
onAvailableChanged: {
|
||||||
|
|
@ -142,6 +222,8 @@ ApplicationWindow {
|
||||||
console.log('*** QML *** VCM ERROR: ' + message);
|
console.log('*** QML *** VCM ERROR: ' + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemPalette {id: syspal}
|
||||||
//END MODELS
|
//END MODELS
|
||||||
|
|
||||||
//BEGIN UI
|
//BEGIN UI
|
||||||
|
|
@ -174,9 +256,4 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
//END UI
|
//END UI
|
||||||
Component.onCompleted: {
|
|
||||||
//HACK: make sure activeVoiceCall is loaded if already existing
|
|
||||||
voiceCallmanager.voiceCalls.onVoiceCallsChanged();
|
|
||||||
voiceCallmanager.onActiveVoiceCallChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue