shift-shell/dialer/package/contents/ui/main.qml

184 lines
5.5 KiB
QML
Raw Normal View History

2015-04-21 08:57:37 +00:00
/**
* Copyright 2014 Aaron Seigo <aseigo@kde.org>
* Copyright 2014 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.
*/
2015-04-20 20:48:51 +00:00
import QtQuick 2.3
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1
2015-04-26 19:36:17 +00:00
import QtQuick.LocalStorage 2.0
2015-04-20 20:56:24 +00:00
import org.kde.plasma.core 2.0 as PlasmaCore
2015-04-20 19:05:28 +00:00
import org.kde.plasma.extras 2.0 as PlasmaExtras
ApplicationWindow {
id: root
2015-04-20 19:05:28 +00:00
//BEGIN PROPERTIES
width: 600
height: 800
2015-04-26 14:42:14 +00:00
//keep track if we were visible when ringing
property bool wasVisible
2015-04-26 19:36:17 +00:00
//support a single provider for now
property string providerId: ofonoWrapper.providerId
2015-04-26 19:36:17 +00:00
//was the last call an incoming one?
property bool isIncoming
2015-04-20 19:05:28 +00:00
//END PROPERTIES
//BEGIN SIGNAL HANDLERS
2015-04-26 14:42:14 +00:00
Connections {
target: dialerUtils
onMissedCallsActionTriggered: {
root.visible = true;
}
}
onVisibleChanged: {
//reset missed calls if the status is not STATUS_INCOMING when got visible
if (visible && ofonoWrapper.status != "incoming") {
2015-04-26 14:42:14 +00:00
dialerUtils.resetMissedCalls();
}
}
//END SIGNAL HANDLERS
2015-04-26 19:36:17 +00:00
//BEGIN FUNCTIONS
function call(number) {
dialerUtils.dial(number);
2015-04-26 19:36:17 +00:00
}
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) {
2015-04-28 10:23:36 +00:00
var rs = tx.executeSql("INSERT INTO History VALUES(NULL, ?, datetime('now'), ?, ? )", [number, duration, callType]);
2015-04-26 19:36:17 +00:00
var rs = tx.executeSql('SELECT * FROM History where id=?', [rs.insertId]);
for(var i = 0; i < rs.rows.length; i++) {
2015-04-27 11:25:47 +00:00
var row = rs.rows.item(i);
2015-04-28 10:23:36 +00:00
row.date = Qt.formatDate(row.time, "yyyy-MM-dd");
2015-04-27 11:25:47 +00:00
row.originalIndex = historyModel.count;
historyModel.append(row);
2015-04-26 19:36:17 +00:00
}
}
)
}
2015-04-27 11:25:47 +00:00
//index is historyModel row number, not db id and not sortmodel row number
function removeCallFromHistory(index) {
var item = historyModel.get(index);
if (!item) {
return;
}
var db = LocalStorage.openDatabaseSync("PlasmaPhoneDialer", "1.0", "Call history of the Plasma Phone dialer", 1000000);
db.transaction(
function(tx) {
2015-04-27 09:14:53 +00:00
tx.executeSql("DELETE from History WHERE id=?", [item.id]);
}
)
2015-04-27 11:25:47 +00:00
historyModel.remove(index);
}
function clearHistory() {
var db = LocalStorage.openDatabaseSync("PlasmaPhoneDialer", "1.0", "Call history of the Plasma Phone dialer", 1000000);
db.transaction(
function(tx) {
tx.executeSql("DELETE from History");
}
)
historyModel.clear();
}
2015-04-26 19:36:17 +00:00
//END FUNCTIONS
//BEGIN DATABASE
Component.onCompleted: {
//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
2015-04-28 10:23:36 +00:00
tx.executeSql('CREATE TABLE IF NOT EXISTS History(id INTEGER PRIMARY KEY AUTOINCREMENT, number TEXT, time DATETIME, duration INTEGER, callType INTEGER)');
2015-04-26 19:36:17 +00:00
var rs = tx.executeSql('SELECT * FROM History');
for(var i = 0; i < rs.rows.length; i++) {
2015-04-27 11:25:47 +00:00
var row = rs.rows.item(i);
2015-04-28 10:23:36 +00:00
row.date = Qt.formatDate(row.time, "yyyy-MM-dd");
2015-04-27 11:25:47 +00:00
row.originalIndex = historyModel.count;
historyModel.append(row);
2015-04-26 19:36:17 +00:00
}
}
)
}
//END DATABASE
2015-04-20 19:05:28 +00:00
//BEGIN MODELS
2015-04-26 19:36:17 +00:00
ListModel {
id: historyModel
}
2015-05-20 09:12:25 +00:00
OfonoWrapper {
id: ofonoWrapper
}
2015-04-26 19:36:17 +00:00
2015-04-20 19:05:28 +00:00
//END MODELS
2015-04-20 19:05:28 +00:00
//BEGIN UI
PlasmaExtras.ConditionalLoader {
anchors.fill: parent
when: root.visible && dialerUtils.callState == "idle"
2015-04-21 09:23:31 +00:00
source: Qt.resolvedUrl("Dialer/DialPage.qml")
z: dialerUtils.callState == "idle" ? 2 : 0
opacity: dialerUtils.callState == "idle" ? 1 : 0
2015-04-20 20:48:51 +00:00
Behavior on opacity {
OpacityAnimator {
duration: units.shortDuration
easing.type: Easing.InOutQuad
}
}
}
2015-04-20 19:05:28 +00:00
PlasmaExtras.ConditionalLoader {
anchors.fill: parent
when: dialerUtils.callState != "idle"
2015-04-20 19:05:28 +00:00
source: Qt.resolvedUrl("Call/CallPage.qml")
opacity: dialerUtils.callState != "idle" ? 1 : 0
z: dialerUtils.callState != "idle" ? 2 : 0
2015-04-20 20:48:51 +00:00
Behavior on opacity {
OpacityAnimator {
duration: units.shortDuration
easing.type: Easing.InOutQuad
}
}
2015-04-20 19:05:28 +00:00
}
//END UI
}