2007-03-29 20:08:40 +02:00
|
|
|
/* UIxCalendarSelector.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-03-29 20:08:40 +02:00
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
2007-11-12 22:20:18 +01:00
|
|
|
|
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
|
|
|
|
2007-04-02 21:26:26 +02:00
|
|
|
#import <Appointments/SOGoAppointmentFolder.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <Appointments/SOGoAppointmentFolders.h>
|
2007-03-29 20:08:40 +02:00
|
|
|
|
|
|
|
#import "UIxCalendarSelector.h"
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
// static inline char
|
|
|
|
// darkenedColor (const char value)
|
|
|
|
// {
|
|
|
|
// char newValue;
|
2007-03-29 20:08:40 +02:00
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
// 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;
|
|
|
|
// }
|
2007-03-29 20:08:40 +02:00
|
|
|
|
|
|
|
static inline NSString *
|
|
|
|
colorForNumber (unsigned int number)
|
|
|
|
{
|
|
|
|
unsigned int index, currentValue;
|
|
|
|
unsigned char colorTable[] = { 1, 1, 1 };
|
|
|
|
NSString *color;
|
|
|
|
|
|
|
|
if (number == 0)
|
|
|
|
color = @"#ccf";
|
|
|
|
else if (number == NSNotFound)
|
|
|
|
color = @"#f00";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentValue = number;
|
|
|
|
index = 0;
|
|
|
|
while (currentValue)
|
|
|
|
{
|
|
|
|
if (currentValue & 1)
|
|
|
|
colorTable[index]++;
|
|
|
|
if (index == 3)
|
|
|
|
index = 0;
|
|
|
|
currentValue >>= 1;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
color = [NSString stringWithFormat: @"#%2x%2x%2x",
|
|
|
|
(255 / colorTable[2]) - 1,
|
|
|
|
(255 / colorTable[1]) - 1,
|
|
|
|
(255 / colorTable[0]) - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
@implementation UIxCalendarSelector
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
calendars = nil;
|
|
|
|
currentCalendar = nil;
|
2007-03-29 20:08:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
[calendars release];
|
|
|
|
[currentCalendar release];
|
2007-03-29 20:08:40 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (NSArray *) calendars
|
2007-03-29 20:08:40 +02:00
|
|
|
{
|
2007-11-12 22:20:18 +01:00
|
|
|
NSArray *folders, *roles;
|
2007-11-08 18:26:03 +01:00
|
|
|
SOGoAppointmentFolders *co;
|
2007-09-15 00:01:02 +02:00
|
|
|
SOGoAppointmentFolder *folder;
|
|
|
|
NSMutableDictionary *calendar;
|
|
|
|
unsigned int count, max;
|
2007-11-08 18:26:03 +01:00
|
|
|
NSString *folderName, *fDisplayName;
|
2007-09-15 00:01:02 +02:00
|
|
|
NSNumber *isActive;
|
2007-11-12 22:20:18 +01:00
|
|
|
SOGoUser *user;
|
2007-09-15 00:01:02 +02:00
|
|
|
|
|
|
|
if (!calendars)
|
2007-03-29 20:08:40 +02:00
|
|
|
{
|
2007-11-08 18:26:03 +01:00
|
|
|
co = [self clientObject];
|
2007-11-12 22:20:18 +01:00
|
|
|
user = [[self context] activeUser];
|
2007-11-08 18:26:03 +01:00
|
|
|
folders = [co subFolders];
|
2007-09-15 00:01:02 +02:00
|
|
|
max = [folders count];
|
|
|
|
calendars = [[NSMutableArray alloc] initWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
2007-04-02 21:26:26 +02:00
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
folder = [folders objectAtIndex: count];
|
2007-11-12 22:20:18 +01:00
|
|
|
roles = [user rolesForObject: folder inContext: [self context]];
|
2007-09-15 00:01:02 +02:00
|
|
|
calendar = [NSMutableDictionary dictionary];
|
|
|
|
folderName = [folder nameInContainer];
|
2007-11-08 18:26:03 +01:00
|
|
|
fDisplayName = [folder displayName];
|
|
|
|
if ([fDisplayName isEqualToString: [co defaultFolderName]])
|
|
|
|
fDisplayName = [self labelForKey: fDisplayName];
|
|
|
|
[calendar setObject: [NSString stringWithFormat: @"/%@", folderName]
|
2007-09-15 00:01:02 +02:00
|
|
|
forKey: @"id"];
|
2007-11-08 18:26:03 +01:00
|
|
|
[calendar setObject: fDisplayName forKey: @"displayName"];
|
2007-09-15 00:01:02 +02:00
|
|
|
[calendar setObject: folderName forKey: @"folder"];
|
|
|
|
[calendar setObject: colorForNumber (count)
|
|
|
|
forKey: @"color"];
|
|
|
|
isActive = [NSNumber numberWithBool: [folder isActive]];
|
|
|
|
[calendar setObject: isActive forKey: @"active"];
|
2007-09-15 04:31:34 +02:00
|
|
|
[calendar setObject: [folder ownerInContext: context]
|
|
|
|
forKey: @"owner"];
|
2007-11-12 22:20:18 +01:00
|
|
|
[calendar setObject: [roles componentsJoinedByString: @","]
|
|
|
|
forKey: @"roles"];
|
2007-09-15 00:01:02 +02:00
|
|
|
[calendars addObject: calendar];
|
2007-04-02 21:26:26 +02:00
|
|
|
}
|
2007-03-29 20:08:40 +02:00
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
return calendars;
|
2007-03-29 20:08:40 +02:00
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (void) setCurrentCalendar: (NSDictionary *) newCalendar
|
2007-03-29 20:08:40 +02:00
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
ASSIGN (currentCalendar, newCalendar);
|
2007-03-29 20:08:40 +02:00
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (NSDictionary *) currentCalendar
|
2007-03-29 20:08:40 +02:00
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
return currentCalendar;
|
2007-03-29 20:08:40 +02:00
|
|
|
}
|
|
|
|
|
2007-10-24 17:52:08 +02:00
|
|
|
- (NSString *) currentCalendarClass
|
|
|
|
{
|
|
|
|
return [currentCalendar
|
|
|
|
keysWithFormat: @"colorBox calendarFolder%{folder}"];
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:08:40 +02:00
|
|
|
- (NSString *) currentCalendarStyle
|
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
return [currentCalendar
|
|
|
|
keysWithFormat: @"color: %{color}; background-color: %{color};"];
|
2007-03-29 20:08:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end /* UIxCalendarSelector */
|