1 /* UIxCalendarSelector.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
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)
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.
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.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSValue.h>
27 #import <SOGo/NSDictionary+Utilities.h>
28 #import <Appointments/SOGoAppointmentFolder.h>
29 #import <Appointments/SOGoAppointmentFolders.h>
31 #import "UIxCalendarSelector.h"
34 // darkenedColor (const char value)
38 // if (value >= '0' && value <= '9')
39 // newValue = ((value - '0') / 2) + '0';
40 // else if (value >= 'a' && value <= 'f')
41 // newValue = ((value + 10 - 'a') / 2) + '0';
42 // else if (value >= 'A' && value <= 'F')
43 // newValue = ((value + 10 - 'A') / 2) + '0';
50 static inline NSString *
51 colorForNumber (unsigned int number)
53 unsigned int index, currentValue;
54 unsigned char colorTable[] = { 1, 1, 1 };
59 else if (number == NSNotFound)
63 currentValue = number;
74 color = [NSString stringWithFormat: @"#%2x%2x%2x",
75 (255 / colorTable[2]) - 1,
76 (255 / colorTable[1]) - 1,
77 (255 / colorTable[0]) - 1];
83 @implementation UIxCalendarSelector
87 if ((self = [super init]))
90 currentCalendar = nil;
99 [currentCalendar release];
103 - (NSArray *) calendars
106 SOGoAppointmentFolder *folder;
107 NSMutableDictionary *calendar;
108 unsigned int count, max;
109 NSString *folderName;
114 folders = [[self clientObject] subFolders];
115 max = [folders count];
116 calendars = [[NSMutableArray alloc] initWithCapacity: max];
117 for (count = 0; count < max; count++)
119 folder = [folders objectAtIndex: count];
120 calendar = [NSMutableDictionary dictionary];
121 folderName = [folder nameInContainer];
123 [NSString stringWithFormat: @"/%@", folderName]
125 [calendar setObject: [folder displayName]
126 forKey: @"displayName"];
127 [calendar setObject: folderName forKey: @"folder"];
128 [calendar setObject: colorForNumber (count)
130 isActive = [NSNumber numberWithBool: [folder isActive]];
131 [calendar setObject: isActive forKey: @"active"];
132 [calendars addObject: calendar];
139 - (void) setCurrentCalendar: (NSDictionary *) newCalendar
141 ASSIGN (currentCalendar, newCalendar);
144 - (NSDictionary *) currentCalendar
146 return currentCalendar;
149 - (NSString *) currentCalendarStyle
151 return [currentCalendar
152 keysWithFormat: @"color: %{color}; background-color: %{color};"];
155 @end /* UIxCalendarSelector */