2
* Copyright (C) 2013-2014 Canonical Ltd
4
* This file is part of Ubuntu Calendar App
6
* Ubuntu Calendar App is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 3 as
8
* published by the Free Software Foundation.
10
* Ubuntu Calendar App is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
import Ubuntu.Components 1.1
21
import QtOrganizer 5.0
22
import "Defines.js" as Defines
23
import "Recurrence.js" as Recurrence
29
function getWeekDaysIndex(daysOfWeek){
30
for (var index = Recurrence.Weekdays; index < Recurrence.OnDiffDays; index++) {
31
if (compareArrays(daysOfWeek, Recurrence.weeklyDays[index])) {
35
return Recurrence.OnDiffDays;
38
function compareArrays(daysOfWeek, actualArray) {
39
if (daysOfWeek.length !== actualArray.length) return false;
40
for (var i = 0; i < actualArray.length; i++) {
41
if (daysOfWeek[i] !== actualArray[i]) return false;
46
function getDaysOfWeek(index, weekDays) {
48
if (index !== Recurrence.OnDiffDays) {
49
daysOfWeek = Recurrence.weeklyDays[index];
51
daysOfWeek = weekDays.length === 0 ? [date.getDay()] : weekDays;
56
//Function to get Weeknames in narrow Format
57
function getDays(daysOfWeek) {
59
for (var j = 0; j < daysOfWeek.length; ++j) {
61
days.push(Qt.locale().dayName(daysOfWeek[j], Locale.NarrowFormat))
63
days = days.join(', ');
67
function getString(rule,recurrence){
68
var dateFormat = Qt.locale().dateFormat(Locale.LongFormat);
70
if (rule.limit === undefined) {
71
str = i18n.tr(recurrence)
72
} else if (rule.limit !== undefined && parseInt(rule.limit)) {
73
// TRANSLATORS: the argument refers to multiple recurrence of event with count .
74
// E.g. "Daily; 5 times."
75
str = i18n.tr("%1; %2 time", "%1; %2 times", rule.limit).arg(recurrence).arg(rule.limit)
77
// TRANSLATORS: the argument refers to recurrence until user selected date.
78
// E.g. "Daily; until 12/12/2014."
79
str = i18n.tr("%1; until %2").arg(recurrence).arg(rule.limit.toLocaleString(Qt.locale(), dateFormat))
84
function getRecurrenceString(rule) {
85
var index = rule.frequency;
88
//Check if reccurence is weekly or not
89
if (index === RecurrenceRule.Weekly) {
90
index = getWeekDaysIndex(rule.daysOfWeek.sort())
91
// We are using a custom index
92
// because we have more options than the Qt RecurrenceRule enum.
93
} else if (index === RecurrenceRule.Monthly) {
94
index = Recurrence.Monthly // If reccurence is Monthly
95
} else if (index === RecurrenceRule.Yearly) {
96
index = Recurrence.Yearly // If reccurence is Yearly
98
// if reccurrence is on different days.
99
if (index === Recurrence.OnDiffDays) {
100
// TRANSLATORS: the argument refers to several different days of the week.
101
// E.g. "Weekly on Mondays, Tuesdays"
102
recurrence += i18n.tr("Weekly on %1").arg(getDays(rule.daysOfWeek.sort()))
104
recurrence += Defines.recurrenceLabel[index]
106
str = getString(rule,recurrence);