File: SyncServicePage.qml

package info (click to toggle)
lomiri-cloudsync-app 0.8.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,560 kB
  • sloc: cpp: 1,053; python: 67; javascript: 25; makefile: 21; sh: 9
file content (184 lines) | stat: -rw-r--r-- 6,745 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import QtQuick 2.4
import Lomiri.Components 1.3

import "../components"

Page {
    id: syncServicePage

    header: PageHeader {
        title: i18n.tr("Settings")
        flickable: flickable
    }

    Timer {
        id: continuousCheck
        interval: 50
        running: true
        repeat: true
        onTriggered: {
            // hide back navigation in double-column mode
            if (apl.columns === 1) {
                header.navigationActions[0].visible = true
            } else {
                header.navigationActions[0].visible = false
            }
        }
    }

    Timer {
        //timer updates time since last sync
        interval: 10000;
        running: serviceController.serviceRunning
        repeat: true
        onTriggered: daemonController.getLastSync()
    }

    Flickable {
        id: flickable
        anchors.fill: parent
        flickableDirection: Flickable.AutoFlickIfNeeded

        Column {
            id: dataColumn
            spacing: units.gu(3)
            anchors {
                top: parent.top; left: parent.left; right: parent.right
            }

            Column {
                width: parent.width
                ListItem {
                    ListItemLayout {
                        title.text: i18n.tr("Status: %1").arg(serviceController.serviceRunning ? daemonController.syncActive ? i18n.tr("Syncing") : i18n.tr("Idle") : i18n.tr("Stopped"))
                        anchors{verticalCenter: parent.verticalCenter}


                        Button{
                            text: serviceController.serviceRunning ? i18n.tr("Stop") : i18n.tr("Start")
                            color: serviceController.serviceRunning ? LomiriColors.red : LomiriColors.green
                            SlotsLayout.position: SlotsLayout.Trailing;

                            onClicked: {
                                console.log("SyncServicePage :: onButtonClicked - Start Sync daemon")
                                connectionStatus.status = serviceController.serviceRunning ? i18n.tr("Stop Service") : i18n.tr("Start Service")
                                connectionStatus.indicationIcon = serviceController.serviceRunning ? "paused" : "updating"
                                serviceController.setServiceRunning(!serviceController.serviceRunning)
                            }
                        }
                    }
                }

                ListItem {
                    ListItemLayout {
                        property string lastSyncTime: daemonController.lastSync ? timeSince(daemonController.lastSync) : owncloud.settings.lastSync ? timeSince(owncloud.settings.lastSync) : i18n.tr("Sync Required")
                        title.text: i18n.tr("Last Sync:")
                        subtitle.text: lastSyncTime
                        anchors{verticalCenter: parent.verticalCenter}

                        Button{
                            text: i18n.tr("Sync")
                            visible: serviceController.serviceRunning && !daemonController.syncActive
                            color: LomiriColors.green
                            SlotsLayout.position: SlotsLayout.Trailing;

                            onClicked: {
                                console.log("SyncServicePage :: Accounts.qml - onButtonClicked - Start Sync")
                                daemonController.forceSync();
                                connectionStatus.status = i18n.tr("Sync Starting")
                                connectionStatus.indicationIcon = "updating"
                            }
                        }
                    }
                }

                ListItem {
                    //visible: owncloud.settings.owncloudcmdVersion

                    onClicked: daemonController.getOwncloudcmdVersion()

                    ListItemLayout {
                        title.text: i18n.tr("Client: %1").arg(owncloud.settings.owncloudcmdVersion)
                        anchors{verticalCenter: parent.verticalCenter}
                    }
                }
                
                ListItem {
                    //visible: owncloud.settings.owncloudSyncdVersion

                    onClicked: daemonController.getOwncloudSyncdVersion()

                    ListItemLayout {
                        title.text: i18n.tr("Service: %1").arg(owncloud.settings.owncloudSyncdVersion)
                        anchors{verticalCenter: parent.verticalCenter}
                    }
                }
                
                ListItem {
                    ListItemLayout {
                        title.text: i18n.tr("Service autostart:")
                        subtitle.text: i18n.tr("Enable/Disable service autostart:")
                        anchors{verticalCenter: parent.verticalCenter}

                        Switch {
                            id: serviceEnableSwitch
                            checked: serviceController.isServiceEnabled
                            onClicked: {
                                console.log("SyncServicePage :: onSwitchToggled - Enable/Disable service")
                                serviceController.setServiceEnable(serviceEnableSwitch.checked)
                            }
                        }
                    }
                }
            }
        }
    }



    function timeSince(date) {

        //console.log("SyncServicePage :: SyncServicePage.qml - timeSince() - epoch time:" + date)

        var seconds = Math.floor(new Date().getTime() - date) / 1000;

        var interval = Math.floor(seconds / 31536000);

        if (interval > 1) {
            return i18n.tr("Never");
        }
        interval = Math.floor(seconds / 2592000);
        if (interval > 1) {
            return i18n.tr("%1 Months Ago".arg(interval));
        }
        interval = Math.floor(seconds / 86400);
        if (interval > 1) {
            return i18n.tr("%1 Days Ago".arg(interval));
        }
        interval = Math.floor(seconds / 3600);
        if (interval > 1) {
            return i18n.tr("%1  Hours Ago".arg(interval));
        }
        interval = Math.floor(seconds / 60);
        if (interval > 1) {
            return i18n.tr("%1 Minutes Ago".arg(interval));
        }
        if (seconds > 60 && seconds < 120) {
            return i18n.tr("A Minute Ago");
        }

        if (seconds > 30 && seconds < 60) {
            return i18n.tr("%1 Seconds Ago".arg(Math.floor(seconds)));
        }

        return i18n.tr("Just Now") //Math.floor(seconds) + i18n.tr(" Seconds Ago");
    }



    PopupStatusBox{
        id: connectionStatus
        autoHide: true
        anchors{left: parent.left; right:parent.right; bottom: parent.bottom;}
    }
}