| 1 |
/* |
| 2 |
* Copyright (C) 2015 Canonical, Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.4 |
| 18 |
|
| 19 |
import QOfono 0.2 |
| 20 |
|
| 21 |
import GSettings 1.0 |
| 22 |
|
| 23 |
Item { |
| 24 |
id: root |
| 25 |
|
| 26 |
property var sims: [] |
| 27 |
property var present: [] |
| 28 |
|
| 29 |
function filterPresentSims() |
| 30 |
{ |
| 31 |
var presentSims = [] |
| 32 |
sims.forEach(function (sim) { |
| 33 |
if (sim.present) { |
| 34 |
presentSims.push(sim) |
| 35 |
} |
| 36 |
}); |
| 37 |
root.present = presentSims |
| 38 |
} |
| 39 |
|
| 40 |
function createQML (modems) |
| 41 |
{ |
| 42 |
if (!phoneSettings.simNames) { |
| 43 |
return |
| 44 |
} |
| 45 |
|
| 46 |
var component = Qt.createComponent(Qt.resolvedUrl("Ofono.qml")); |
| 47 |
|
| 48 |
sims.forEach(function (sim) { |
| 49 |
sim.destroy(); |
| 50 |
}); |
| 51 |
var newSims = [] |
| 52 |
var presentSims = [] |
| 53 |
|
| 54 |
modems.forEach(function (path, index) { |
| 55 |
var sim = component.createObject(root, { |
| 56 |
path: path, |
| 57 |
name: phoneSettings.simNames[path] ? phoneSettings.simNames[path] : |
| 58 |
"SIM " + (index + 1) |
| 59 |
}); |
| 60 |
if (sim === null) { |
| 61 |
console.warn('Failed to create Sim qml:', component.errorString()); |
| 62 |
} else { |
| 63 |
newSims.push(sim) |
| 64 |
if (sim.present) { |
| 65 |
presentSims.push(sim) |
| 66 |
} |
| 67 |
sim.onPresentChanged.connect(filterPresentSims) |
| 68 |
} |
| 69 |
}); |
| 70 |
|
| 71 |
root.sims = newSims |
| 72 |
root.present = presentSims |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
GSettings { |
| 77 |
id: phoneSettings |
| 78 |
schema.id: "com.lomiri.phone" |
| 79 |
onChanged: { |
| 80 |
if (key === "simNames") { |
| 81 |
root.createQML(ofonoManager.modems.slice(0).sort()) |
| 82 |
} |
| 83 |
} |
| 84 |
onSchemaChanged: root.createQML(ofonoManager.modems.slice(0).sort()) |
| 85 |
} |
| 86 |
|
| 87 |
OfonoManager { |
| 88 |
id: ofonoManager |
| 89 |
onModemsChanged: root.createQML(modems.slice(0).sort()) |
| 90 |
} |
| 91 |
} |