]> err.no Git - scalable-opengroupware.org/blobdiff - UI/Scheduler/UIxCalendarSelector.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1263 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Scheduler / UIxCalendarSelector.m
index d28e94847ccb1666c25686ab5a8d1dff45a7be89..1e49c8e247c12303c553623ff12f8a42f0ef130e 100644 (file)
 
 #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/AgenorUserManager.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)
@@ -91,8 +89,8 @@ colorForNumber (unsigned int number)
 {
   if ((self = [super init]))
     {
-      colors = nil;
-      currentCalendarFolder = nil;
+      calendars = nil;
+      currentCalendar = nil;
     }
 
   return self;
@@ -100,77 +98,77 @@ colorForNumber (unsigned int number)
 
 - (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] calendarFoldersInContext: context];
-  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;
+  return calendars;
 }
 
-- (void) setCurrentCalendarFolder: (NSDictionary *) newCurrentCalendarFolder
+- (void) setCurrentCalendar: (NSDictionary *) newCalendar
 {
-  ASSIGN (currentCalendarFolder, newCurrentCalendarFolder);
+  ASSIGN (currentCalendar, newCalendar);
 }
 
-- (NSDictionary *) currentCalendarFolder
+- (NSDictionary *) currentCalendar
 {
-  return currentCalendarFolder;
+  return currentCalendar;
 }
 
-- (NSString *) currentCalendarSpanBG
+- (NSString *) currentCalendarClass
 {
-  NSString *colorKey;
-
-  colorKey = [currentCalendarFolder objectForKey: @"folder"];
-
-  return [colors objectForKey: colorKey];
-}
-
-- (NSString *) currentCalendarLogin
-{
-  NSArray *parts;
-
-  parts = [[currentCalendarFolder objectForKey: @"folder"]
-           componentsSeparatedByString: @":"];
-
-  return (([parts count] > 1)
-         ? [parts objectAtIndex: 0]
-         : [[context activeUser] 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 */