2006-10-14 01:23:44 +02:00
|
|
|
/* UIxCalCalendarsListView.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 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>
|
2006-10-16 20:49:25 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2006-10-14 01:23:44 +02:00
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import <Foundation/NSUserDefaults.h>
|
|
|
|
|
|
|
|
#import <SOGo/AgenorUserManager.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
|
|
|
|
#import "UIxCalCalendarsListView.h"
|
|
|
|
|
|
|
|
@implementation UIxCalCalendarsListView
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
contacts = nil;
|
|
|
|
checkedContacts = nil;
|
2006-10-16 20:49:25 +02:00
|
|
|
currentContactPerson = nil;
|
|
|
|
colors = nil;
|
2006-10-14 01:23:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-10-16 20:49:25 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
if (currentContactPerson)
|
|
|
|
[currentContactPerson release];
|
|
|
|
if (contacts)
|
|
|
|
[contacts release];
|
|
|
|
if (checkedContacts)
|
|
|
|
[checkedContacts release];
|
|
|
|
if (colors)
|
|
|
|
[colors release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _colorForNumber: (unsigned int) number
|
|
|
|
{
|
|
|
|
unsigned int index, currentValue;
|
|
|
|
unsigned char colorTable[] = { 1, 1, 1 };
|
|
|
|
NSString *color;
|
|
|
|
|
2006-10-18 17:11:35 +02:00
|
|
|
if (number == 0)
|
|
|
|
color = @"#ccf";
|
|
|
|
else if (number == NSNotFound)
|
2006-10-16 20:49:25 +02:00
|
|
|
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",
|
2006-10-18 17:11:35 +02:00
|
|
|
(255 / colorTable[2]) - 1,
|
|
|
|
(255 / colorTable[1]) - 1,
|
|
|
|
(255 / colorTable[0]) - 1];
|
2006-10-16 20:49:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NSLog(@"color = '%@'", color);
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _addContactId: (NSString *) contactId
|
|
|
|
withUm: (AgenorUserManager *) um
|
|
|
|
andNumber: (unsigned int) count
|
|
|
|
{
|
|
|
|
NSString *contactRealId;
|
|
|
|
iCalPerson *currentContact;
|
|
|
|
|
|
|
|
if ([contactId hasPrefix: @"-"])
|
|
|
|
contactRealId = [contactId substringFromIndex: 1];
|
|
|
|
else
|
|
|
|
contactRealId = contactId;
|
|
|
|
|
|
|
|
currentContact = [um iCalPersonWithUid: contactRealId];
|
|
|
|
[contacts addObject: currentContact];
|
|
|
|
if (contactId == contactRealId)
|
|
|
|
[checkedContacts addObject: currentContact];
|
|
|
|
[colors setObject: [self _colorForNumber: count]
|
|
|
|
forKey: contactRealId];
|
|
|
|
}
|
|
|
|
|
2006-10-14 01:23:44 +02:00
|
|
|
- (void) _setupContacts
|
|
|
|
{
|
|
|
|
SOGoUser *user;
|
|
|
|
NSString *list, *currentId;
|
|
|
|
NSEnumerator *rawContacts;
|
2006-10-16 20:49:25 +02:00
|
|
|
AgenorUserManager *um;
|
|
|
|
unsigned int count;
|
2006-10-14 01:23:44 +02:00
|
|
|
|
2006-10-16 20:49:25 +02:00
|
|
|
contacts = [NSMutableArray new];
|
|
|
|
checkedContacts = [NSMutableArray new];
|
|
|
|
colors = [NSMutableDictionary new];
|
2006-10-14 01:23:44 +02:00
|
|
|
|
|
|
|
um = [AgenorUserManager sharedUserManager];
|
|
|
|
user = [context activeUser];
|
|
|
|
list = [[user userDefaults] stringForKey: @"calendaruids"];
|
|
|
|
if ([list length] == 0)
|
|
|
|
list = [self shortUserNameForDisplay];
|
|
|
|
|
|
|
|
rawContacts
|
|
|
|
= [[list componentsSeparatedByString: @","] objectEnumerator];
|
|
|
|
currentId = [rawContacts nextObject];
|
2006-10-16 20:49:25 +02:00
|
|
|
count = 0;
|
2006-10-14 01:23:44 +02:00
|
|
|
while (currentId)
|
|
|
|
{
|
2006-10-16 20:49:25 +02:00
|
|
|
[self _addContactId: currentId withUm: um andNumber: count];
|
2006-10-14 01:23:44 +02:00
|
|
|
currentId = [rawContacts nextObject];
|
2006-10-16 20:49:25 +02:00
|
|
|
count++;
|
2006-10-14 01:23:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) contacts
|
|
|
|
{
|
|
|
|
if (!contacts)
|
|
|
|
[self _setupContacts];
|
|
|
|
|
|
|
|
return contacts;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) checkedContacts
|
|
|
|
{
|
|
|
|
if (!checkedContacts)
|
|
|
|
[self _setupContacts];
|
|
|
|
|
|
|
|
return checkedContacts;
|
|
|
|
}
|
|
|
|
|
2006-10-16 20:49:25 +02:00
|
|
|
- (void) setCurrentContactPerson: (iCalPerson *) contact
|
|
|
|
{
|
|
|
|
if (currentContactPerson)
|
|
|
|
[currentContactPerson release];
|
|
|
|
currentContactPerson = contact;
|
|
|
|
if (currentContactPerson)
|
|
|
|
[currentContactPerson retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentContactLogin
|
|
|
|
{
|
|
|
|
return [currentContactPerson cn];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentContactSpanBG
|
|
|
|
{
|
|
|
|
return [colors objectForKey: [currentContactPerson cn]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) colors
|
|
|
|
{
|
|
|
|
return colors;
|
|
|
|
}
|
|
|
|
|
2006-10-14 01:23:44 +02:00
|
|
|
@end
|