Skip to main content
- harbour-friendly / qml / harbour-friendly.qml
1import QtQuick 2.0
2import Sailfish.Silica 1.0
3import org.nemomobile.notifications 1.0
5import "../core/qml/models"
6import "./pages"
7import "./models"
9ApplicationWindow
11 HarbourSettingsModel { id: settingsSchema }
13 NetworkModel { id: networkModel }
15 FriendsModel { id: friendsModel }
17 PMListModel { id: pmListModel }
19 Notification {
20 id: applicationNotification
21 category: "x-nemo.messaging.im.preview"
22 appName: "Friendly"
23 appIcon: "harbour-friendly"
25 onClosed: {
26 if (reason == 2) { // Notification.DismissedByUser
27 activate();
28 pageStack.push(Qt.resolvedUrl("NotificationsPage.qml"));
29 }
30 }
31 onClicked : { }
32 }
35 PingModel {
36 id: pingModel
38 onNotification: {
39 // (array notificationlist)
40 // (n.id, n.name, n.date_rel, n.timestamp, n.photo, n.note)
42 console.log("pingModel.onNotification", notificationlist.length);
44 if (notificationlist.length === 0) return
46 var notificationbody = qsTr("%1 new notifications").arg(notificationlist.length);
48 if (notificationlist.length === 1 ) {
49 notificationbody = notificationlist[0].note;
50 }
52 // messaggio popup, suono, non in elenco, sparisce quando scade
53 applicationNotification.category = "x-nemo.messaging.im.preview";
54 applicationNotification.replacesId = 0;
55 applicationNotification.summary = "";
56 applicationNotification.body = "";
57 applicationNotification.previewSummary = "Friendica"
58 applicationNotification.previewBody = notificationbody
59 applicationNotification.itemCount = notificationlist.length;
60 applicationNotification.timestamp = new Date();
61 applicationNotification.publish();
64 for (var k=0; k<notificationlist.length; k++) {
65 var n = notificationlist[k];
68 applicationNotification.category = "x-nemo.messaging.im";
69 applicationNotification.replacesId = 0;
70 applicationNotification.summary = n.note
71 applicationNotification.body = ""
72 applicationNotification.previewSummary = ""
73 applicationNotification.previewBody = ""
74 applicationNotification.itemCount = 1
75 applicationNotification.timestamp = new Date(n.timestamp * 1000);
76 applicationNotification.publish();
77 }
80 }
81 }
84 Timer {
85 id: pingModelTimer
86 repeat: true
87 interval: (cover.status === Cover.Active ? settings.data.tPingUpdate : settings.data.tCoverUpdates) * 1000
88 running: true
89 onTriggered: {
90 pingModel.reload();
91 }
92 }
94 Component.onCompleted: {
96 /**
97 * Looks like QML creates elements from bottom-up, then calls onCompleted().
98 * like:
99 * ApplicationWindow <- NetworkPage <- NetworkModel
100 *
101 * Every object under the one wich sets 'settings.data' will
102 * see 'null' as 'settings.data' in its 'Component.onCompleted'.
103 * To be sure that everiting works, any other components must
104 * use settings.data in 'Component.onCompleted' wrapped in an handler for
105 * 'settings.settingsChanged' event, expecially if it want to set an handler
106 * listening for any data value change.
107 *
108 **/
111 //reload models on settings changed
112 settings.settingsChanged.connect( function() {
113 if (settings.data._valid) {
114 pingModel.reload();
115 networkModel.reload();
116 friendsModel.reload();
117 }
118 });
120 settings.data = settingsSchema;
121 var r = settings.readSettings();
122 console.log("readSettings", r);
124 }
126 id: applicationWindow
127 initialPage: Component { NetworkPage { } }
128 cover: Qt.resolvedUrl("cover/CoverPage.qml")
129 allowedOrientations: Orientation.All
130 _defaultPageOrientations: Orientation.All