~ubuntu-branches/ubuntu/saucy/plasma-mobile/saucy

« back to all changes in this revision

Viewing changes to applets/digital-clock/contents/ui/main.qml

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-12-22 01:58:11 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20121222015811-zqq9spgc9e0gin07
Tags: 3.0-0ubuntu1
* New upstream release
* Update install files
* Run wrap-and-sort
* Add plasma-mobile-dev
* Drop plasma-active-keyboardcontainer

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2012 Marco Martin <mart@kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library General Public License as
 
6
 *   published by the Free Software Foundation; either version 2, or
 
7
 *   (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU Library General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Library General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
import QtQuick 1.1
 
21
import org.kde.plasma.core 0.1 as PlasmaCore
 
22
import org.kde.plasma.components 0.1 as PlasmaComponents
 
23
import org.kde.locale 0.1 as KLocale
 
24
import org.kde.plasma.mobilecomponents 0.1 as MobileComponents
 
25
import QtMultimediaKit 1.1
 
26
 
 
27
Item {
 
28
    id: root
 
29
    property int minimumWidth: row.implicitWidth + 4
 
30
    property int minimumHeight: theme.smallMediumIconSize
 
31
 
 
32
    property variant dateTime
 
33
 
 
34
    function twoDigitString(number)
 
35
    {
 
36
        return number < 10 ? "0"+number : number
 
37
    }
 
38
 
 
39
    KLocale.Locale {
 
40
        id: locale
 
41
    }
 
42
 
 
43
    PlasmaCore.DataSource {
 
44
        id: clockSource
 
45
        engine: "time"
 
46
        interval: 30000
 
47
        connectedSources: ["Local"]
 
48
        onDataChanged: dateTime = new Date(data["Local"]["DateTime"])
 
49
    }
 
50
 
 
51
    PlasmaCore.DataSource {
 
52
        id: alarmsSource
 
53
        engine: "org.kde.alarms"
 
54
        interval: 0
 
55
        connectedSources: sources
 
56
        onNewData: {
 
57
            //ringing?
 
58
            if (data.active) {
 
59
                var dialog = dialogComponent.createObject(root)
 
60
                dialog.alarmData = data
 
61
                dialog.open()
 
62
            }
 
63
        }
 
64
    }
 
65
 
 
66
    Audio {
 
67
        id: audio
 
68
        onStopped: play()
 
69
    }
 
70
    Component {
 
71
        id: dialogComponent
 
72
        PlasmaComponents.CommonDialog {
 
73
            id: dialog
 
74
            property variant alarmData
 
75
            onAlarmDataChanged: {
 
76
                audio.source = alarmData["audioFile"]
 
77
                if (alarmData["audioFile"] != "") {
 
78
                    audio.play()
 
79
                }
 
80
            }
 
81
 
 
82
            titleText: i18n("Alarm")
 
83
            content: Column {
 
84
                width: theme.defaultFont.mSize.width * 30
 
85
                height: Math.max(implicitHeight, theme.defaultFont.mSize.height * 8)
 
86
                PlasmaComponents.Label {
 
87
                    text: dialog.alarmData["message"]
 
88
                    width: parent.width
 
89
                    horizontalAlignment: Text.AlignHCenter
 
90
                    verticalAlignment: Text.AlignVCenter
 
91
                }
 
92
                PlasmaComponents.Label {
 
93
                    text: i18n("Alarm for %1", locale.formatDateTime(dialog.alarmData["dateTime"]))
 
94
                    width: parent.width
 
95
                    horizontalAlignment: Text.AlignHCenter
 
96
                    verticalAlignment: Text.AlignVCenter
 
97
                }
 
98
            }
 
99
            buttonTexts: [i18n("Dismiss"), i18n("Snooze")]
 
100
 
 
101
            function performAlarmAction(operationName, id) {
 
102
                var service = alarmsSource.serviceForSource("")
 
103
                var operation = service.operationDescription(operationName)
 
104
 
 
105
                operation["Id"] = id
 
106
                if (operationName == "defer") {
 
107
                    operation["Minutes"] = 5
 
108
                }
 
109
 
 
110
                service.startOperationCall(operation)
 
111
            }
 
112
            onButtonClicked: {
 
113
                if (index == 0) {
 
114
                    performAlarmAction("dismiss", dialog.alarmData["id"])
 
115
                } else if (index == 1) {
 
116
                    performAlarmAction("defer", dialog.alarmData["id"])
 
117
                }
 
118
                audio.source = ""
 
119
                audio.stop()
 
120
                destroy()
 
121
            }
 
122
            onClickedOutside: {
 
123
                performAlarmAction("defer", dialog.alarmData["id"])
 
124
                audio.source = ""
 
125
                audio.stop()
 
126
                destroy()
 
127
            }
 
128
        }
 
129
    }
 
130
 
 
131
    PlasmaCore.Svg {
 
132
        id: configIconsSvg
 
133
        imagePath: "widgets/configuration-icons"
 
134
    }
 
135
 
 
136
 
 
137
    MouseArea {
 
138
        anchors.fill: parent
 
139
        enabled: alarmsSource.sources.length > 0
 
140
 
 
141
        onClicked: plasmoid.runApplication("active-alarms")
 
142
 
 
143
        Row {
 
144
            id: row
 
145
            anchors.centerIn: parent
 
146
            height: parent.height - 8
 
147
            MobileComponents.TextEffects {
 
148
                id: clockText
 
149
                effect: MobileComponents.TextEffects.TexturedText
 
150
                pixelSize: parent.height
 
151
                anchors.verticalCenter: parent.verticalCenter
 
152
                text: twoDigitString(dateTime.getHours()) + ":" + twoDigitString(dateTime.getMinutes())
 
153
            }
 
154
            PlasmaCore.SvgItem {
 
155
                id: alarmIcon
 
156
                svg: PlasmaCore.Svg {imagePath: "icons/korgac"}
 
157
                elementId: "korgac"
 
158
                height: parent.height
 
159
                width: height
 
160
                visible: alarmsSource.sources.length > 0
 
161
            }
 
162
        }
 
163
    }
 
164
}