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>
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]))
93 colors = [NSMutableDictionary new];
94 calendarFolders = nil;
95 currentCalendarFolder = nil;
103 [calendarFolders release];
104 [currentCalendarFolder release];
109 - (void) setCalendarFolders: (NSArray *) newCalendarFolders
111 NSEnumerator *newFolders;
112 NSDictionary *currentFolder;
115 ASSIGN (calendarFolders, newCalendarFolders);
117 newFolders = [calendarFolders objectEnumerator];
118 currentFolder = [newFolders nextObject];
120 while (currentFolder)
122 [colors setObject: colorForNumber (count)
123 forKey: [currentFolder objectForKey: @"folder"]];
125 currentFolder = [newFolders nextObject];
129 - (NSArray *) calendarFolders
131 return calendarFolders;
134 - (void) setCurrentCalendarFolder: (NSDictionary *) newCurrentCalendarFolder
136 ASSIGN (currentCalendarFolder, newCurrentCalendarFolder);
139 - (NSDictionary *) currentCalendarFolder
141 return currentCalendarFolder;
144 - (NSString *) currentCalendarSpanBG
148 colorKey = [currentCalendarFolder objectForKey: @"folder"];
150 return [colors objectForKey: colorKey];
153 - (NSString *) currentCalendarLogin
157 parts = [[currentCalendarFolder objectForKey: @"folder"]
158 componentsSeparatedByString: @":"];
160 return (([parts count] > 1)
161 ? [parts objectAtIndex: 0]
162 : [[context activeUser] login]);
165 - (NSString *) currentCalendarStyle
169 color = [self currentCalendarSpanBG];
171 return [NSString stringWithFormat: @"color: %@; background-color: %@;",
175 @end /* UIxCalendarSelector */