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/SOGoUser.h>
32 #import <SOGoUI/UIxComponent.h>
33 #import <Appointments/SOGoAppointmentFolder.h>
35 #import "UIxCalendarSelector.h"
38 darkenedColor (const char value)
42 if (value >= '0' && value <= '9')
43 newValue = ((value - '0') / 2) + '0';
44 else if (value >= 'a' && value <= 'f')
45 newValue = ((value + 10 - 'a') / 2) + '0';
46 else if (value >= 'A' && value <= 'F')
47 newValue = ((value + 10 - 'A') / 2) + '0';
54 static inline NSString *
55 colorForNumber (unsigned int number)
57 unsigned int index, currentValue;
58 unsigned char colorTable[] = { 1, 1, 1 };
63 else if (number == NSNotFound)
67 currentValue = number;
78 color = [NSString stringWithFormat: @"#%2x%2x%2x",
79 (255 / colorTable[2]) - 1,
80 (255 / colorTable[1]) - 1,
81 (255 / colorTable[0]) - 1];
87 @implementation UIxCalendarSelector
91 if ((self = [super init]))
94 currentCalendarFolder = nil;
102 [currentCalendarFolder release];
107 - (NSArray *) calendarFolders
109 NSArray *calendarFolders;
110 NSEnumerator *newFolders;
111 NSDictionary *currentFolder;
114 calendarFolders = [[self clientObject] calendarFolders];
117 colors = [NSMutableDictionary new];
119 newFolders = [calendarFolders objectEnumerator];
120 currentFolder = [newFolders nextObject];
121 while (currentFolder)
123 [colors setObject: colorForNumber (count)
124 forKey: [currentFolder objectForKey: @"folder"]];
126 currentFolder = [newFolders nextObject];
130 return calendarFolders;
133 - (void) setCurrentCalendarFolder: (NSDictionary *) newCurrentCalendarFolder
135 ASSIGN (currentCalendarFolder, newCurrentCalendarFolder);
138 - (NSDictionary *) currentCalendarFolder
140 return currentCalendarFolder;
143 - (NSString *) currentCalendarSpanBG
147 colorKey = [currentCalendarFolder objectForKey: @"folder"];
149 return [colors objectForKey: colorKey];
152 - (NSString *) currentCalendarLogin
156 parts = [[currentCalendarFolder objectForKey: @"folder"]
157 componentsSeparatedByString: @":"];
159 return (([parts count] > 1)
160 ? [parts objectAtIndex: 0]
161 : [[context activeUser] login]);
164 - (NSString *) currentCalendarStyle
168 color = [self currentCalendarSpanBG];
170 return [NSString stringWithFormat: @"color: %@; background-color: %@;",
174 @end /* UIxCalendarSelector */