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>
29 #import <SoObjects/SOGo/SOGoUser.h>
31 #import <Appointments/SOGoAppointmentFolder.h>
32 #import <Appointments/SOGoAppointmentFolders.h>
34 #import "UIxCalendarSelector.h"
37 // darkenedColor (const char value)
41 // if (value >= '0' && value <= '9')
42 // newValue = ((value - '0') / 2) + '0';
43 // else if (value >= 'a' && value <= 'f')
44 // newValue = ((value + 10 - 'a') / 2) + '0';
45 // else if (value >= 'A' && value <= 'F')
46 // newValue = ((value + 10 - 'A') / 2) + '0';
53 static inline NSString *
54 colorForNumber (unsigned int number)
56 unsigned int index, currentValue;
57 unsigned char colorTable[] = { 1, 1, 1 };
62 else if (number == NSNotFound)
66 currentValue = number;
77 color = [NSString stringWithFormat: @"#%2x%2x%2x",
78 (255 / colorTable[2]) - 1,
79 (255 / colorTable[1]) - 1,
80 (255 / colorTable[0]) - 1];
86 @implementation UIxCalendarSelector
90 if ((self = [super init]))
93 currentCalendar = nil;
102 [currentCalendar release];
106 - (NSArray *) calendars
108 NSArray *folders, *roles;
109 SOGoAppointmentFolders *co;
110 SOGoAppointmentFolder *folder;
111 NSMutableDictionary *calendar;
112 unsigned int count, max;
113 NSString *folderName, *fDisplayName;
119 co = [self clientObject];
120 user = [[self context] activeUser];
121 folders = [co subFolders];
122 max = [folders count];
123 calendars = [[NSMutableArray alloc] initWithCapacity: max];
124 for (count = 0; count < max; count++)
126 folder = [folders objectAtIndex: count];
127 roles = [user rolesForObject: folder inContext: [self context]];
128 calendar = [NSMutableDictionary dictionary];
129 folderName = [folder nameInContainer];
130 fDisplayName = [folder displayName];
131 if ([fDisplayName isEqualToString: [co defaultFolderName]])
132 fDisplayName = [self labelForKey: fDisplayName];
133 [calendar setObject: [NSString stringWithFormat: @"/%@", folderName]
135 [calendar setObject: fDisplayName forKey: @"displayName"];
136 [calendar setObject: folderName forKey: @"folder"];
137 [calendar setObject: colorForNumber (count)
139 isActive = [NSNumber numberWithBool: [folder isActive]];
140 [calendar setObject: isActive forKey: @"active"];
141 [calendar setObject: [folder ownerInContext: context]
143 [calendar setObject: [roles componentsJoinedByString: @","]
145 [calendars addObject: calendar];
152 - (void) setCurrentCalendar: (NSDictionary *) newCalendar
154 ASSIGN (currentCalendar, newCalendar);
157 - (NSDictionary *) currentCalendar
159 return currentCalendar;
162 - (NSString *) currentCalendarClass
164 return [currentCalendar
165 keysWithFormat: @"colorBox calendarFolder%{folder}"];
168 - (NSString *) currentCalendarStyle
170 return [currentCalendar
171 keysWithFormat: @"color: %{color}; background-color: %{color};"];
174 @end /* UIxCalendarSelector */