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/NSString.h>
26 #import <Foundation/NSUserDefaults.h>
28 #import <NGExtensions/NGExtensions.h>
29 #import <NGCards/iCalPerson.h>
31 #import <SOGo/AgenorUserManager.h>
32 #import <SOGo/SOGoUser.h>
33 #import <SOGoUI/UIxComponent.h>
34 #import <Appointments/SOGoAppointmentFolder.h>
36 #import "UIxCalendarSelector.h"
39 darkenedColor (const char value)
43 if (value >= '0' && value <= '9')
44 newValue = ((value - '0') / 2) + '0';
45 else if (value >= 'a' && value <= 'f')
46 newValue = ((value + 10 - 'a') / 2) + '0';
47 else if (value >= 'A' && value <= 'F')
48 newValue = ((value + 10 - 'A') / 2) + '0';
55 static inline NSString *
56 colorForNumber (unsigned int number)
58 unsigned int index, currentValue;
59 unsigned char colorTable[] = { 1, 1, 1 };
64 else if (number == NSNotFound)
68 currentValue = number;
79 color = [NSString stringWithFormat: @"#%2x%2x%2x",
80 (255 / colorTable[2]) - 1,
81 (255 / colorTable[1]) - 1,
82 (255 / colorTable[0]) - 1];
88 @implementation UIxCalendarSelector
92 if ((self = [super init]))
95 currentCalendarFolder = nil;
103 [currentCalendarFolder release];
108 - (NSArray *) calendarFolders
110 NSArray *calendarFolders;
111 NSEnumerator *newFolders;
112 NSDictionary *currentFolder;
116 = [[self clientObject] calendarFoldersInContext: context];
119 colors = [NSMutableDictionary new];
121 newFolders = [calendarFolders objectEnumerator];
122 currentFolder = [newFolders nextObject];
123 while (currentFolder)
125 [colors setObject: colorForNumber (count)
126 forKey: [currentFolder objectForKey: @"folder"]];
128 currentFolder = [newFolders nextObject];
132 return calendarFolders;
135 - (void) setCurrentCalendarFolder: (NSDictionary *) newCurrentCalendarFolder
137 ASSIGN (currentCalendarFolder, newCurrentCalendarFolder);
140 - (NSDictionary *) currentCalendarFolder
142 return currentCalendarFolder;
145 - (NSString *) currentCalendarSpanBG
149 colorKey = [currentCalendarFolder objectForKey: @"folder"];
151 return [colors objectForKey: colorKey];
154 - (NSString *) currentCalendarLogin
158 parts = [[currentCalendarFolder objectForKey: @"folder"]
159 componentsSeparatedByString: @":"];
161 return (([parts count] > 1)
162 ? [parts objectAtIndex: 0]
163 : [[context activeUser] login]);
166 - (NSString *) currentCalendarStyle
170 color = [self currentCalendarSpanBG];
172 return [NSString stringWithFormat: @"color: %@; background-color: %@;",
176 @end /* UIxCalendarSelector */