2015-04-21 08:57:37 +00:00
/ * *
* Copyright 2014 Aaron Seigo < aseigo @ kde . org >
2015-03-27 16:59:32 +00:00
* 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
2015-03-27 16:59:32 +00:00
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
2015-03-27 16:59:32 +00:00
ApplicationWindow {
id: root
2015-04-20 19:05:28 +00:00
//BEGIN PROPERTIES
2015-03-27 16:59:32 +00:00
width: 600
height: 800
2015-04-21 10:12:10 +00:00
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
2015-05-13 10:51:56 +00:00
property string providerId: ofonoWrapper . providerId
2015-04-26 19:36:17 +00:00
//was the last call an incoming one?
property bool isIncoming
2015-06-18 23:24:46 +00:00
2015-04-20 19:05:28 +00:00
//END PROPERTIES
2015-04-20 17:08:31 +00:00
2015-04-21 10:28:14 +00:00
//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
2015-05-13 10:51:56 +00:00
if ( visible && ofonoWrapper . status != "incoming" ) {
2015-04-26 14:42:14 +00:00
dialerUtils . resetMissedCalls ( ) ;
2015-04-21 10:28:14 +00:00
}
}
//END SIGNAL HANDLERS
2015-04-26 19:36:17 +00:00
//BEGIN FUNCTIONS
function call ( number ) {
2015-06-18 23:24:46 +00:00
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 ) ;
2015-04-27 09:01:18 +00:00
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 09:01:18 +00:00
}
)
2015-04-27 11:25:47 +00:00
historyModel . remove ( index ) ;
2015-04-27 09:01:18 +00:00
}
2015-04-27 11:50:37 +00:00
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 {
2015-05-13 10:51:56 +00:00
id: ofonoWrapper
2015-03-27 16:59:32 +00:00
}
2015-04-26 19:36:17 +00:00
2015-04-20 19:05:28 +00:00
//END MODELS
2015-04-20 17:08:31 +00:00
2015-04-20 19:05:28 +00:00
//BEGIN UI
PlasmaExtras . ConditionalLoader {
2015-03-27 16:59:32 +00:00
anchors.fill: parent
2015-06-18 23:24:46 +00:00
when: root . visible && dialerUtils . callState == "idle"
2015-04-21 09:23:31 +00:00
source: Qt . resolvedUrl ( "Dialer/DialPage.qml" )
2015-06-18 23:24:46 +00:00
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-03-27 16:59:32 +00:00
}
2015-04-20 17:08:31 +00:00
2015-04-20 19:05:28 +00:00
PlasmaExtras . ConditionalLoader {
anchors.fill: parent
2015-06-18 23:24:46 +00:00
when: dialerUtils . callState != "idle"
2015-04-20 19:05:28 +00:00
source: Qt . resolvedUrl ( "Call/CallPage.qml" )
2015-06-18 23:24:46 +00:00
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
2015-03-27 16:59:32 +00:00
}