2007-03-29 20:08:40 +02:00
|
|
|
/* UIxCalendarSelector.m - this file is part of SOGo
|
|
|
|
*
|
2011-07-08 17:48:55 +02:00
|
|
|
* Copyright (C) 2007-2011 Inverse inc.
|
2007-03-29 20:08:40 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2008-01-15 22:45:48 +01:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
2007-11-12 22:20:18 +01:00
|
|
|
|
2008-01-15 22:45:48 +01:00
|
|
|
#import <SoObjects/SOGo/NSArray+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"
|
|
|
|
|
2008-04-22 19:16:37 +02:00
|
|
|
static inline unsigned int
|
|
|
|
_intValueFromHexChar (unichar hexChar)
|
|
|
|
{
|
|
|
|
unichar base;
|
|
|
|
|
|
|
|
if (hexChar >= '0' && hexChar <= '9')
|
|
|
|
base = '0';
|
|
|
|
else if (hexChar >= 'A' && hexChar <= 'F')
|
|
|
|
base = 'A' - 10;
|
|
|
|
else
|
|
|
|
base = 'a' - 10;
|
|
|
|
|
|
|
|
return (hexChar - base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
_intValueFromHex (NSString *hexString)
|
|
|
|
{
|
|
|
|
unsigned int value, count, max;
|
|
|
|
|
|
|
|
value = 0;
|
|
|
|
max = [hexString length];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
value = (value * 16
|
|
|
|
+ _intValueFromHexChar([hexString characterAtIndex: count]));
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:08:40 +02:00
|
|
|
@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
|
|
|
{
|
2008-08-25 21:13:18 +02:00
|
|
|
NSArray *folders;
|
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;
|
2014-06-11 16:24:04 +02:00
|
|
|
NSString *folderName, *fDisplayName;
|
|
|
|
NSNumber *isActive, *fActiveTasks;
|
2014-06-10 22:18:12 +02:00
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
if (!calendars)
|
2014-06-10 22:18:12 +02:00
|
|
|
{
|
|
|
|
co = [self clientObject];
|
|
|
|
folders = [co subFolders];
|
|
|
|
max = [folders count];
|
|
|
|
calendars = [[NSMutableArray alloc] initWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
2007-03-29 20:08:40 +02:00
|
|
|
{
|
2014-06-10 22:18:12 +02:00
|
|
|
folder = [folders objectAtIndex: count];
|
|
|
|
calendar = [NSMutableDictionary dictionary];
|
|
|
|
folderName = [folder nameInContainer];
|
|
|
|
fDisplayName = [folder displayName];
|
|
|
|
if (fDisplayName == nil)
|
|
|
|
fDisplayName = @"";
|
|
|
|
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: [folder calendarColor] forKey: @"color"];
|
|
|
|
isActive = [NSNumber numberWithBool: [folder isActive]];
|
|
|
|
[calendar setObject: isActive forKey: @"active"];
|
|
|
|
[calendar setObject: [folder ownerInContext: context]
|
|
|
|
forKey: @"owner"];
|
|
|
|
fActiveTasks = [folder activeTasks];
|
2014-07-08 23:19:55 +02:00
|
|
|
if (fActiveTasks > 0)
|
|
|
|
[calendar setObject: fActiveTasks forKey:@"activeTasks" ];
|
2014-06-10 22:18:12 +02:00
|
|
|
[calendars addObject: calendar];
|
2007-03-29 20:08:40 +02:00
|
|
|
}
|
2014-06-10 22:18:12 +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
|
|
|
}
|
|
|
|
|
2008-04-22 19:16:37 +02:00
|
|
|
/* code taken from Lightning 0.7 */
|
|
|
|
- (NSString *) contrastingTextColor
|
|
|
|
{
|
|
|
|
NSString *bgColor;
|
|
|
|
unsigned int red, green, blue;
|
|
|
|
float brightness;
|
|
|
|
|
|
|
|
bgColor = [[currentCalendar objectForKey: @"color"] substringFromIndex: 1];
|
|
|
|
red = _intValueFromHex ([bgColor substringFromRange: NSMakeRange (0, 2)]);
|
|
|
|
green = _intValueFromHex ([bgColor substringFromRange: NSMakeRange (2, 2)]);
|
|
|
|
blue = _intValueFromHex ([bgColor substringFromRange: NSMakeRange (4, 2)]);
|
|
|
|
brightness = (0.299 * red) + (0.587 * green) + (0.114 * blue);
|
|
|
|
|
|
|
|
return ((brightness < 144) ? @"white" : @"black");
|
|
|
|
}
|
|
|
|
|
2008-01-15 22:45:48 +01:00
|
|
|
- (WOResponse *) calendarsListAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [self responseWithStatus: 200];
|
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
|
|
|
forKey: @"content-type"];
|
|
|
|
[response appendContentString: [[self calendars] jsonRepresentation]];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:08:40 +02:00
|
|
|
@end /* UIxCalendarSelector */
|