~nik90/ubuntu-clock-app/fix-first-run-phone-issues

« back to all changes in this revision

Viewing changes to app/alarm/AlarmUtils.qml

  • Committer: Nekhelesh Ramananthan
  • Date: 2014-07-07 12:19:21 UTC
  • mfrom: (5.4.20 edit-alarm-feature)
  • Revision ID: krnekhelesh@gmail.com-20140707121921-z7jbap28ek43v2wd
Added support for creating new alarms and made the pulltoadd component as a generic component since it is required in two places.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import QtQuick 2.0
18
18
import Ubuntu.Components 1.1
19
19
 
 
20
/*
 
21
  Qt Object containing a collection of useful alarm functions
 
22
*/
20
23
QtObject {
21
24
    id: alarmUtils
22
25
 
23
 
    function format_day_string(value, type) {
24
 
        var occurs = get_day(value, type);
25
 
        var WeekDay = 0;
 
26
    // Function to format the alarm days accordingly to their occurance
 
27
    function format_day_string(value) {
 
28
        var occurs = _get_day(value)
 
29
 
 
30
        if (value === _get_weekdays()) {
 
31
            return i18n.tr("Weekdays")
 
32
        }
 
33
 
 
34
        else if (value === _get_weekends()) {
 
35
            return i18n.tr("Weekends")
 
36
        }
 
37
 
 
38
        else if (value === Alarm.Daily) {
 
39
            return i18n.tr("Daily")
 
40
        }
 
41
 
 
42
        else {
 
43
            return occurs
 
44
        }
 
45
    }
 
46
 
 
47
    /*
 
48
      INTERNAL FUNCTIONS
 
49
    */
 
50
 
 
51
    // Function to determine the locale's weekdays value
 
52
    function _get_weekdays() {
 
53
        var weekDays = 0
26
54
        for (var i = 0; i < Qt.locale().weekDays.length; ++i) {
27
55
            switch (Qt.locale().weekDays[i]) {
28
 
            case Qt.Monday:
29
 
                WeekDay |= Alarm.Monday
30
 
                break;
31
 
            case Qt.Tuesday:
32
 
                WeekDay |= Alarm.Tuesday
33
 
                break;
34
 
            case Qt.Wednesday:
35
 
                WeekDay |= Alarm.Wednesday
36
 
                break;
37
 
            case Qt.Thursday:
38
 
                WeekDay |= Alarm.Thursday
39
 
                break;
40
 
            case Qt.Friday:
41
 
                WeekDay |= Alarm.Friday
42
 
                break;
43
 
            case Qt.Saturday:
44
 
                WeekDay |= Alarm.Saturday
45
 
                break;
46
 
            case Qt.Sunday:
47
 
                WeekDay |= Alarm.Sunday
48
 
                break;
49
 
            }
50
 
        }
51
 
 
52
 
        if (value == WeekDay) {
53
 
            return i18n.tr("Every weekday")
54
 
        }
55
 
        else if (value == Alarm.Daily) {
56
 
            return i18n.tr("Daily")
57
 
        }
58
 
        else {
59
 
            if (type === Alarm.Repeating)
60
 
                return i18n.tr("Every ") + occurs
61
 
            else
62
 
                return i18n.tr("Once on ")  + occurs
63
 
        }
64
 
    }
65
 
 
66
 
    function get_day(value, type) {
67
 
        var occurs = [];
68
 
        if (value & Alarm.Monday) occurs.push(Qt.locale().standaloneDayName(1, Locale.ShortFormat));
69
 
        if (value & Alarm.Tuesday) occurs.push(Qt.locale().standaloneDayName(2, Locale.ShortFormat));
70
 
        if (value & Alarm.Wednesday) occurs.push(Qt.locale().standaloneDayName(3, Locale.ShortFormat));
71
 
        if (value & Alarm.Thursday) occurs.push(Qt.locale().standaloneDayName(4, Locale.ShortFormat));
72
 
        if (value & Alarm.Friday) occurs.push(Qt.locale().standaloneDayName(5, Locale.ShortFormat));
73
 
        if (value & Alarm.Saturday) occurs.push(Qt.locale().standaloneDayName(6, Locale.ShortFormat));
74
 
        if (value & Alarm.Sunday) occurs.push(Qt.locale().standaloneDayName(7, Locale.ShortFormat));
 
56
            case Qt.Monday: {
 
57
                weekDays |= Alarm.Monday
 
58
                break
 
59
            }
 
60
 
 
61
            case Qt.Tuesday: {
 
62
                weekDays |= Alarm.Tuesday
 
63
                break
 
64
            }
 
65
 
 
66
            case Qt.Wednesday: {
 
67
                weekDays |= Alarm.Wednesday
 
68
                break
 
69
            }
 
70
 
 
71
            case Qt.Thursday: {
 
72
                weekDays |= Alarm.Thursday
 
73
                break
 
74
            }
 
75
 
 
76
            case Qt.Friday: {
 
77
                weekDays |= Alarm.Friday
 
78
                break
 
79
            }
 
80
 
 
81
            case Qt.Saturday: {
 
82
                weekDays |= Alarm.Saturday
 
83
                break
 
84
            }
 
85
 
 
86
            case Qt.Sunday: {
 
87
                weekDays |= Alarm.Sunday
 
88
                break
 
89
            }
 
90
            }
 
91
        }
 
92
        return weekDays
 
93
    }
 
94
 
 
95
    // Function to determine the locale's weekends value
 
96
    function _get_weekends() {
 
97
        return (Alarm.Daily - _get_weekdays())
 
98
    }
 
99
 
 
100
    // Function to retrieve the days of the week in the locale system
 
101
    function _get_day(value) {
 
102
        var occurs = []
 
103
 
 
104
        if (value & Alarm.Monday) {
 
105
            occurs.push(Qt.locale().standaloneDayName(1, Locale.LongFormat))
 
106
        }
 
107
 
 
108
        if (value & Alarm.Tuesday) {
 
109
            occurs.push(Qt.locale().standaloneDayName(2, Locale.LongFormat))
 
110
        }
 
111
 
 
112
        if (value & Alarm.Wednesday) {
 
113
            occurs.push(Qt.locale().standaloneDayName(3, Locale.LongFormat))
 
114
        }
 
115
 
 
116
        if (value & Alarm.Thursday) {
 
117
            occurs.push(Qt.locale().standaloneDayName(4, Locale.LongFormat))
 
118
        }
 
119
 
 
120
        if (value & Alarm.Friday) {
 
121
            occurs.push(Qt.locale().standaloneDayName(5, Locale.LongFormat))
 
122
        }
 
123
 
 
124
        if (value & Alarm.Saturday) {
 
125
            occurs.push(Qt.locale().standaloneDayName(6, Locale.LongFormat))
 
126
        }
 
127
 
 
128
        if (value & Alarm.Sunday) {
 
129
            occurs.push(Qt.locale().standaloneDayName(0, Locale.LongFormat))
 
130
        }
 
131
 
 
132
        occurs = occurs.join(', ');
 
133
 
75
134
        return occurs;
76
135
    }
77
136
}