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-03-27 16:59:32 +00:00
import org . nemomobile . voicecall 1.0
import MeeGo . QOfono 0.2
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-20 17:08:31 +00:00
property int status: voiceCallmanager . activeVoiceCall ? voiceCallmanager.activeVoiceCall.status : 0
2015-04-26 14:42:14 +00:00
//keep track of the status we were in
property int previousStatus
//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: voiceCallmanager . providers . id ( 0 )
//was the last call an incoming one?
property bool isIncoming
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
onStatusChanged: {
2015-04-26 19:36:17 +00:00
//STATUS_ACTIVE
if ( status == 1 ) {
root . isIncoming = voiceCallmanager . activeVoiceCall . isIncoming ;
2015-04-21 10:28:14 +00:00
//STATUS_INCOMING
2015-04-26 19:36:17 +00:00
} else if ( status == 5 ) {
2015-04-26 14:42:14 +00:00
wasVisible = root . visible ;
2015-04-21 10:28:14 +00:00
root . visible = true ;
2015-04-28 09:18:56 +00:00
dialerUtils . notifyRinging ( ) ;
2015-04-26 14:42:14 +00:00
//Was STATUS_INCOMING now is STATUS_DISCONNECTED: Missed call!
} else if ( status == 7 && previousStatus == 5 ) {
2015-04-27 10:06:01 +00:00
var prettyDate = Qt . formatTime ( voiceCallmanager . activeVoiceCall . startedAt , Qt . locale ( ) . timeFormat ( Locale . ShortFormat ) ) ;
dialerUtils . notifyMissedCall ( voiceCallmanager . activeVoiceCall . lineId , i18n ( "%1 called at %2" , voiceCallmanager . activeVoiceCall . lineId , prettyDate ) ) ;
2015-04-26 14:42:14 +00:00
root . visible = wasVisible ;
2015-04-26 19:36:17 +00:00
insertCallInHistory ( voiceCallmanager . activeVoiceCall . lineId , 0 , 0 ) ;
} else if ( status == 7 ) {
insertCallInHistory ( voiceCallmanager . activeVoiceCall . lineId , voiceCallmanager . activeVoiceCall . duration , isIncoming ? 1 : 2 ) ;
2015-04-28 09:31:39 +00:00
}
if ( status != 5 ) {
2015-04-28 09:18:56 +00:00
dialerUtils . stopRinging ( ) ;
2015-04-26 14:42:14 +00:00
}
previousStatus = status ;
}
Connections {
target: dialerUtils
onMissedCallsActionTriggered: {
root . visible = true ;
}
}
onVisibleChanged: {
//reset missed calls if the status is not STATUS_INCOMING when got visible
if ( visible && status != 5 ) {
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 ) {
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 ) {
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: {
//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
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-04-20 14:31:02 +00:00
OfonoManager {
2015-03-27 16:59:32 +00:00
id: ofonoManager
onAvailableChanged: {
console . log ( "Ofono is " + available )
}
onModemAdded: {
console . log ( "modem added " + modem )
}
onModemRemoved: console . log ( "modem removed" )
}
OfonoConnMan {
id: ofono1
Component.onCompleted: {
console . log ( ofonoManager . modems )
}
modemPath: ofonoManager . modems . length > 0 ? ofonoManager . modems [ 0 ] : ""
}
OfonoModem {
id: modem1
modemPath: ofonoManager . modems . length > 0 ? ofonoManager . modems [ 0 ] : ""
}
OfonoContextConnection {
id: context1
contextPath : ofono1 . contexts . length > 0 ? ofono1 . contexts [ 0 ] : ""
Component.onCompleted: {
print ( "Context Active: " + context1 . active )
}
onActiveChanged: {
print ( "Context Active: " + context1 . active )
}
}
OfonoNetworkRegistration {
id: netreg
Component.onCompleted: {
netreg . scan ( )
}
onNetworkOperatorsChanged : {
console . log ( "operators :" + netreg . currentOperator [ "Name" ] . toString ( ) )
}
modemPath: ofonoManager . modems . length ? ofonoManager . modems [ 0 ] : ""
}
OfonoNetworkOperator {
id: netop
}
2015-04-20 19:05:28 +00:00
2015-04-20 16:08:56 +00:00
VoiceCallManager {
id: voiceCallmanager
2015-03-27 16:59:32 +00:00
onActiveVoiceCallChanged: {
if ( activeVoiceCall ) {
//main.activeVoiceCallPerson = people.personByPhoneNumber(activeVoiceCall.lineId);
2015-04-20 17:08:31 +00:00
// dialerOverlay.item.numberEntryText = activeVoiceCall.lineId;
2015-03-27 16:59:32 +00:00
} else {
2015-04-20 17:08:31 +00:00
// dialerOverlay.item.numberEntryText = '';
2015-03-27 16:59:32 +00:00
//main.activeVoiceCallPerson = null;
}
}
onError: {
console . log ( '*** QML *** VCM ERROR: ' + message ) ;
}
}
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-04-20 19:05:28 +00:00
when: root . visible && root . status == 0
2015-04-21 09:23:31 +00:00
source: Qt . resolvedUrl ( "Dialer/DialPage.qml" )
2015-04-21 08:54:30 +00:00
z: root . status == 0 ? 2 : 0
2015-04-20 19:05:28 +00:00
opacity: root . status == 0 ? 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
when: root . status > 0
source: Qt . resolvedUrl ( "Call/CallPage.qml" )
opacity: root . status > 0 ? 1 : 0
2015-04-21 08:54:30 +00:00
z: root . status > 0 ? 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
}