#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
-#import <Foundation/NSString.h>
-#import <Foundation/NSUserDefaults.h>
+#import <Foundation/NSValue.h>
-#import <NGExtensions/NGExtensions.h>
-#import <NGCards/iCalPerson.h>
+#import <SOGo/NSDictionary+Utilities.h>
+
+#import <SoObjects/SOGo/SOGoUser.h>
-#import <SOGo/SOGoUser.h>
-#import <SOGoUI/UIxComponent.h>
#import <Appointments/SOGoAppointmentFolder.h>
+#import <Appointments/SOGoAppointmentFolders.h>
#import "UIxCalendarSelector.h"
-static inline char
-darkenedColor (const char value)
-{
- char newValue;
-
- if (value >= '0' && value <= '9')
- newValue = ((value - '0') / 2) + '0';
- else if (value >= 'a' && value <= 'f')
- newValue = ((value + 10 - 'a') / 2) + '0';
- else if (value >= 'A' && value <= 'F')
- newValue = ((value + 10 - 'A') / 2) + '0';
- else
- newValue = value;
+// static inline char
+// darkenedColor (const char value)
+// {
+// char newValue;
- return newValue;
-}
+// if (value >= '0' && value <= '9')
+// newValue = ((value - '0') / 2) + '0';
+// else if (value >= 'a' && value <= 'f')
+// newValue = ((value + 10 - 'a') / 2) + '0';
+// else if (value >= 'A' && value <= 'F')
+// newValue = ((value + 10 - 'A') / 2) + '0';
+// else
+// newValue = value;
+
+// return newValue;
+// }
static inline NSString *
colorForNumber (unsigned int number)
{
if ((self = [super init]))
{
- colors = nil;
- currentCalendarFolder = nil;
+ calendars = nil;
+ currentCalendar = nil;
}
return self;
- (void) dealloc
{
- [currentCalendarFolder release];
- [colors release];
+ [calendars release];
+ [currentCalendar release];
[super dealloc];
}
-- (NSArray *) calendarFolders
+- (NSArray *) calendars
{
- NSArray *calendarFolders;
- NSEnumerator *newFolders;
- NSDictionary *currentFolder;
- unsigned int count;
-
- calendarFolders = [[self clientObject] calendarFolders];
- if (!colors)
+ NSArray *folders, *roles;
+ SOGoAppointmentFolders *co;
+ SOGoAppointmentFolder *folder;
+ NSMutableDictionary *calendar;
+ unsigned int count, max;
+ NSString *folderName, *fDisplayName;
+ NSNumber *isActive;
+ SOGoUser *user;
+
+ if (!calendars)
{
- colors = [NSMutableDictionary new];
- count = 0;
- newFolders = [calendarFolders objectEnumerator];
- currentFolder = [newFolders nextObject];
- while (currentFolder)
+ co = [self clientObject];
+ user = [[self context] activeUser];
+ folders = [co subFolders];
+ max = [folders count];
+ calendars = [[NSMutableArray alloc] initWithCapacity: max];
+ for (count = 0; count < max; count++)
{
- [colors setObject: colorForNumber (count)
- forKey: [currentFolder objectForKey: @"folder"]];
- count++;
- currentFolder = [newFolders nextObject];
+ folder = [folders objectAtIndex: count];
+ roles = [user rolesForObject: folder inContext: [self context]];
+ calendar = [NSMutableDictionary dictionary];
+ folderName = [folder nameInContainer];
+ fDisplayName = [folder displayName];
+ if ([fDisplayName isEqualToString: [co defaultFolderName]])
+ fDisplayName = [self labelForKey: fDisplayName];
+ [calendar setObject: [NSString stringWithFormat: @"/%@", folderName]
+ forKey: @"id"];
+ [calendar setObject: fDisplayName forKey: @"displayName"];
+ [calendar setObject: folderName forKey: @"folder"];
+ [calendar setObject: colorForNumber (count)
+ forKey: @"color"];
+ isActive = [NSNumber numberWithBool: [folder isActive]];
+ [calendar setObject: isActive forKey: @"active"];
+ [calendar setObject: [folder ownerInContext: context]
+ forKey: @"owner"];
+ [calendar setObject: [roles componentsJoinedByString: @","]
+ forKey: @"roles"];
+ [calendars addObject: calendar];
}
}
- return calendarFolders;
-}
-
-- (void) setCurrentCalendarFolder: (NSDictionary *) newCurrentCalendarFolder
-{
- ASSIGN (currentCalendarFolder, newCurrentCalendarFolder);
+ return calendars;
}
-- (NSDictionary *) currentCalendarFolder
+- (void) setCurrentCalendar: (NSDictionary *) newCalendar
{
- return currentCalendarFolder;
+ ASSIGN (currentCalendar, newCalendar);
}
-- (NSString *) currentCalendarSpanBG
+- (NSDictionary *) currentCalendar
{
- NSString *colorKey;
-
- colorKey = [currentCalendarFolder objectForKey: @"folder"];
-
- return [colors objectForKey: colorKey];
+ return currentCalendar;
}
-- (NSString *) currentCalendarLogin
+- (NSString *) currentCalendarClass
{
- NSArray *parts;
- NSMutableString *login;
-
- login = [NSMutableString string];
- parts = [[currentCalendarFolder objectForKey: @"folder"]
- componentsSeparatedByString: @":"];
- [login appendString: (([parts count] > 1)
- ? [parts objectAtIndex: 0]
- : [[context activeUser] login])];
- [login replaceString: @"." withString: @"_"];
- [login replaceString: @"#" withString: @"_"];
- [login replaceString: @"@" withString: @"_"];
-
- return login;
+ return [currentCalendar
+ keysWithFormat: @"colorBox calendarFolder%{folder}"];
}
- (NSString *) currentCalendarStyle
{
- NSString *color;
-
- color = [self currentCalendarSpanBG];
-
- return [NSString stringWithFormat: @"color: %@; background-color: %@;",
- color, color];
+ return [currentCalendar
+ keysWithFormat: @"color: %{color}; background-color: %{color};"];
}
@end /* UIxCalendarSelector */