~nick-dedekind/ubuntu-settings-components/bluetooth-menu

« back to all changes in this revision

Viewing changes to Ubuntu/Settings/Components/Calendar.qml

  • Committer: Tarmac
  • Author(s): Nick Dedekind
  • Date: 2013-10-04 09:14:39 UTC
  • mfrom: (49.1.11 usc)
  • Revision ID: tarmac-20131004091439-bj4ts24iv1kmm7a7
Reworked directory, qml and resources into a more workable structure for release.

Approved by Andrea Cimitan, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
    onMaximumDateChanged: {
76
76
        if (!priv.ready) return
77
77
 
78
 
        var i = calendarModel.count - 1
79
 
        while (i >= 0 && calendarModel.get(i).monthStart > maximumDate) {
80
 
            calendarModel.remove(i)
81
 
            i--
82
 
        }
83
 
 
84
 
        if (calendarModel.count == 0) {
85
 
            priv.__populateModel()
86
 
        }
 
78
        priv.__populateModel()
87
79
    }
88
80
 
89
81
    onMinimumDateChanged: {
90
82
        if (!priv.ready) return
91
83
 
92
 
        var i = 0
93
 
        while (i < calendarModel.count && calendarModel.get(0).monthStart < minimumDate) {
94
 
            calendarModel.remove(0)
95
 
            i++
96
 
        }
97
 
 
98
 
        if (calendarModel.count == 0) {
99
 
            priv.__populateModel()
100
 
        }
 
84
        priv.__populateModel()
101
85
    }
102
86
 
103
87
    ListModel {
138
122
            //  disable the onCurrentIndexChanged logic
139
123
            priv.ready = false
140
124
 
141
 
            var minimumAddedDate = priv.__getRealMinimumDate(currentDate.addMonths(-2));
142
 
            var maximumAddedDate = priv.__getRealMaximumDate(currentDate.addMonths(2));
143
 
 
144
 
            var count = Math.min(DateExt.diffMonths(minimumAddedDate, maximumAddedDate) + 1, 5)
145
 
            for (var i = 0; i < count; ++i) {
146
 
                calendarModel.append({"monthStart": minimumAddedDate.monthStart().addMonths(i)});
 
125
            var minimumAddedDate = priv.__getRealMinimumDate(currentDate.addMonths(-2)).monthStart();
 
126
            var maximumAddedDate = priv.__getRealMaximumDate(currentDate.addMonths(2)).monthStart();
 
127
 
 
128
            // Remove old minimum months
 
129
            while (calendarModel.count > 0 && calendarModel.get(0).monthStart < minimumAddedDate) {
 
130
                calendarModel.remove(0);
 
131
            }
 
132
            // Remove old maximum months
 
133
            while (calendarModel.count > 0 && calendarModel.get(calendarModel.count - 1).monthStart > maximumAddedDate) {
 
134
                calendarModel.remove(calendarModel.count - 1);
 
135
            }
 
136
 
 
137
            // Add new months
 
138
            i = 0;
 
139
            while (calendarModel.count > 0 && calendarModel.get(0).monthStart > minimumAddedDate) {
 
140
                calendarModel.insert(0, {"monthStart": calendarModel.get(0).monthStart.addMonths(-1)});
 
141
                ++i;
 
142
            }
 
143
 
 
144
            if (calendarModel.count > 0) {
 
145
                var i = 0;
 
146
                while (calendarModel.count > 0 && calendarModel.get(calendarModel.count - 1).monthStart < maximumAddedDate) {
 
147
                    calendarModel.append({"monthStart": calendarModel.get(calendarModel.count - 1).monthStart.addMonths(1)});
 
148
                    ++i;
 
149
                }
 
150
            } else {
 
151
                var i = 0;
 
152
                do {
 
153
                    calendarModel.append({"monthStart": minimumAddedDate.addMonths(i)});
 
154
                    ++i;
 
155
                } while (calendarModel.get(i-1).monthStart < maximumAddedDate)
147
156
            }
148
157
 
149
158
            currentIndex = DateExt.diffMonths(minimumAddedDate, currentDate);