]> err.no Git - scalable-opengroupware.org/blob - UI/PreferencesUI/UIxPreferences.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1087 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / PreferencesUI / UIxPreferences.m
1 /* UIxPreferences.m - this file is part of SOGo
2  *
3  * Copyright (C) 2007 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #import <Foundation/NSCalendarDate.h>
24 #import <Foundation/NSString.h>
25 #import <Foundation/NSTimeZone.h>
26 #import <Foundation/NSUserDefaults.h>
27
28 #import <NGObjWeb/WOContext.h>
29 #import <NGObjWeb/WORequest.h>
30
31 #import <SoObjects/SOGo/SOGoUser.h>
32
33 #import "UIxPreferences.h"
34
35 #warning this class is not finished
36 /* remaining:
37    default event length
38    default snooze length
39    refresh calendar every X minutes
40    workweek = from -> to
41    identities */
42
43 @implementation UIxPreferences
44
45 - (id) init
46 {
47   NSDictionary *locale;
48   
49   if ((self = [super init]))
50     {
51       item = nil;
52       hours = nil;
53       ASSIGN (user, [context activeUser]);
54       ASSIGN (userDefaults, [user userDefaults]);
55       ASSIGN (today, [NSCalendarDate date]);
56       locale = [context valueForKey: @"locale"];
57       ASSIGN (daysOfWeek,
58               [locale objectForKey: NSWeekDayNameArray]);
59     }
60
61   return self;
62 }
63
64 - (void) dealloc
65 {
66   [today release];
67   [item release];
68   [user release];
69   [userDefaults release];
70   [hours release];
71   [daysOfWeek release];
72   [super dealloc];
73 }
74
75 - (void) setItem: (NSString *) newItem
76 {
77   ASSIGN (item, newItem);
78 }
79
80 - (NSString *) item
81 {
82   return item;
83 }
84
85 - (NSString *) inTheOffice
86 {
87   NSString *inTheOffice;
88
89   inTheOffice = [userDefaults objectForKey: @"InTheOffice"];
90
91   return ((!inTheOffice || [inTheOffice boolValue])
92           ? @"YES" : @"NO");
93 }
94
95 - (void) setInTheOffice: (NSString *) newValue
96 {
97   [userDefaults setObject: newValue forKey: @"InTheOffice"];
98 }
99
100 - (void) setAutoReplyText: (NSString *) newAutoReplyText
101 {
102   [userDefaults setObject: newAutoReplyText forKey: @"AutoReplyText"];
103 }
104
105 - (NSString *) autoReplyText
106 {
107   return [userDefaults objectForKey: @"AutoReplyText"];
108 }
109
110 - (NSArray *) timeZonesList
111 {
112   return [NSTimeZone knownTimeZoneNames];
113 }
114
115 - (NSString *) userTimeZone
116 {
117   return [[user timeZone] timeZoneName];
118 }
119
120 - (void) setUserTimeZone: (NSString *) newUserTimeZone
121 {
122   [userDefaults setObject: newUserTimeZone forKey: @"TimeZone"];
123 }
124
125 - (NSArray *) shortDateFormatsList
126 {
127   NSMutableArray *shortDateFormatsList = nil;
128   NSString *key, *currentFormat;
129   unsigned int nbr;
130   BOOL done;
131
132   shortDateFormatsList = [NSMutableArray array];
133
134   nbr = 0;
135   done = NO;
136   while (!done)
137     {
138       key = [NSString stringWithFormat: @"shortDateFmt_%d", nbr];
139       currentFormat = [self labelForKey: key];
140       if ([currentFormat length] > 0)
141         {
142           [shortDateFormatsList addObject: currentFormat];
143           nbr++;
144         }
145       else
146         done = YES;
147     }
148
149   return shortDateFormatsList;
150 }
151
152 - (NSString *) itemShortDateFormatText
153 {
154   return [today descriptionWithCalendarFormat: item
155                 locale: [context valueForKey: @"locale"]];
156 }
157
158 - (NSString *) userShortDateFormat
159 {
160   return [userDefaults objectForKey: @"ShortDateFormat"];
161 }
162
163 - (void) setUserShortDateFormat: (NSString *) newFormat
164 {
165   [userDefaults setObject: newFormat forKey: @"ShortDateFormat"];
166 }
167
168 - (NSArray *) longDateFormatsList
169 {
170   NSMutableArray *longDateFormatsList = nil;
171   NSString *key, *currentFormat;
172   unsigned int nbr;
173   BOOL done;
174
175   longDateFormatsList = [NSMutableArray array];
176
177   nbr = 0;
178   done = NO;
179   while (!done)
180     {
181       key = [NSString stringWithFormat: @"longDateFmt_%d", nbr];
182       currentFormat = [self labelForKey: key];
183       if ([currentFormat length] > 0)
184         {
185           [longDateFormatsList addObject: currentFormat];
186           nbr++;
187         }
188       else
189         done = YES;
190     }
191
192   return longDateFormatsList;
193 }
194
195 - (NSString *) itemLongDateFormatText
196 {
197   return [today descriptionWithCalendarFormat: item
198                 locale: [context valueForKey: @"locale"]];
199 }
200
201 - (NSString *) userLongDateFormat
202 {
203   return [userDefaults objectForKey: @"LongDateFormat"];
204 }
205
206 - (void) setUserLongDateFormat: (NSString *) newFormat
207 {
208   [userDefaults setObject: newFormat forKey: @"LongDateFormat"];
209 }
210
211 - (NSArray *) timeFormatsList
212 {
213   NSMutableArray *timeFormatsList = nil;
214   NSString *key, *currentFormat;
215   unsigned int nbr;
216   BOOL done;
217
218   timeFormatsList = [NSMutableArray array];
219
220   nbr = 0;
221   done = NO;
222   while (!done)
223     {
224       key = [NSString stringWithFormat: @"timeFmt_%d", nbr];
225       currentFormat = [self labelForKey: key];
226       if ([currentFormat length] > 0)
227         {
228           [timeFormatsList addObject: currentFormat];
229           nbr++;
230         }
231       else
232         done = YES;
233     }
234
235   return timeFormatsList;
236 }
237
238 - (NSString *) itemTimeFormatText
239 {
240   return [today descriptionWithCalendarFormat: item
241                 locale: [context valueForKey: @"locale"]];
242 }
243
244 - (NSString *) userTimeFormat
245 {
246   return [userDefaults objectForKey: @"TimeFormat"];
247 }
248
249 - (void) setUserTimeFormat: (NSString *) newFormat
250 {
251   [userDefaults setObject: newFormat forKey: @"TimeFormat"];
252 }
253
254 - (NSArray *) daysList
255 {
256   NSMutableArray *daysList;
257   unsigned int currentDay;
258
259   daysList = [NSMutableArray new];
260   [daysList autorelease];
261   for (currentDay = 0; currentDay < 7; currentDay++)
262     [daysList addObject: [NSString stringWithFormat: @"%d", currentDay]];
263
264   return daysList;
265 }
266
267 - (NSString *) itemWeekStartDay
268 {
269   return [daysOfWeek objectAtIndex: [item intValue]];
270 }
271
272 - (NSString *) userWeekStartDay
273 {
274   return [userDefaults objectForKey: @"WeekStartDay"];
275 }
276
277 - (void) setUserWeekStartDay: (NSString *) newDay
278 {
279   [userDefaults setObject: newDay forKey: @"WeekStartDay"];
280 }
281
282 - (NSArray *) hoursList
283 {
284   unsigned int currentHour;
285
286   if (!hours)
287     {
288       hours = [[NSMutableArray alloc] initWithCapacity: 24];
289       for (currentHour = 0; currentHour < 24; currentHour++)
290         [hours addObject: [NSString stringWithFormat: @"%.2d:00",
291                                     currentHour]];
292     }
293
294   return hours;
295 }
296
297 - (NSString *) userDayStartTime
298 {
299   NSString *time;
300
301   time = [userDefaults objectForKey: @"DayStartTime"];
302   if (!time)
303     time = @"08:00";
304
305   return time;
306 }
307
308 - (void) setUserDayStartTime: (NSString *) newTime
309 {
310   [userDefaults setObject: newTime forKey: @"DayStartTime"];
311 }
312
313 - (NSString *) userDayEndTime
314 {
315   NSString *time;
316
317   time = [userDefaults objectForKey: @"DayEndTime"];
318   if (!time)
319     time = @"18:00";
320
321   return time;
322 }
323
324 - (void) setUserDayEndTime: (NSString *) newTime
325 {
326   [userDefaults setObject: newTime forKey: @"DayEndTime"];
327 }
328
329 - (NSArray *) firstWeekList
330 {
331   return [NSArray arrayWithObjects: SOGoWeekStartHideWeekNumbers,
332                   SOGoWeekStartJanuary1,
333                   SOGoWeekStartFirst4DayWeek,
334                   SOGoWeekStartFirstFullWeek, nil];
335 }
336
337 - (NSString *) itemFirstWeekText
338 {
339   return [self labelForKey: [NSString stringWithFormat: @"firstWeekOfYear_%@",
340                                       item]];
341 }
342
343 - (NSString *) userFirstWeek
344 {
345   return [userDefaults objectForKey: @"FirstWeek"];
346 }
347
348 - (void) setUserFirstWeek: (NSString *) newFirstWeek
349 {
350   [userDefaults setObject: newFirstWeek forKey: @"FirstWeek"];
351 }
352
353 - (NSString *) reminderEnabled
354 {
355   NSString *reminderEnabled;
356
357   reminderEnabled = [userDefaults objectForKey: @"ReminderEnabled"];
358
359   return ((!reminderEnabled || [reminderEnabled boolValue])
360           ? @"YES" : @"NO");
361 }
362
363 - (void) setReminderEnabled: (NSString *) newValue
364 {
365   [userDefaults setObject: newValue forKey: @"ReminderEnabled"];
366 }
367
368 - (NSString *) remindWithASound
369 {
370   NSString *remindWithASound;
371
372   remindWithASound = [userDefaults objectForKey: @"RemindWithASound"];
373
374   return ((!remindWithASound || [remindWithASound boolValue])
375           ? @"YES" : @"NO");
376 }
377
378 - (void) setRemindWithASound: (NSString *) newValue
379 {
380   [userDefaults setObject: newValue forKey: @"RemindWithASound"];
381 }
382
383 - (NSArray *) reminderTimesList
384 {
385   return [NSArray arrayWithObjects: @"0000", @"0005", @"0010", @"0015",
386                   @"0030", @"0100", @"0200", @"0400", @"0800", @"1200",
387                   @"2400", @"4800", nil];
388 }
389
390 - (NSString *) itemReminderTimeText
391 {
392   return [self labelForKey:
393                  [NSString stringWithFormat: @"reminderTime_%@", item]];
394 }
395
396 - (NSString *) userReminderTime
397 {
398   return [userDefaults objectForKey: @"ReminderTime"];
399 }
400
401 - (void) setReminderTime: (NSString *) newTime
402 {
403   [userDefaults setObject: newTime forKey: @"ReminderTime"];
404 }
405
406 - (id <WOActionResults>) defaultAction
407 {
408   id <WOActionResults> results;
409   WORequest *request;
410
411   request = [context request];
412   if ([[request method] isEqualToString: @"POST"])
413     {
414       [userDefaults synchronize];
415       results = [self jsCloseWithRefreshMethod: nil];
416     }
417   else
418     results = self;
419
420   return results;
421 }
422
423 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
424                            inContext: (WOContext*) context
425 {
426   return [[request method] isEqualToString: @"POST"];
427 }
428
429 @end