]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoCustomGroupFolder.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1045 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / SOGoCustomGroupFolder.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id: SOGoCustomGroupFolder.m 115 2004-06-30 11:57:37Z helge $
22
23 #include "SOGoCustomGroupFolder.h"
24 #include "common.h"
25
26 @implementation SOGoCustomGroupFolder
27
28 static NSString *SOGoUIDSeparator = @",";
29
30 - (id)initWithUIDs:(NSArray *)_uids inContainer:(id)_container {
31   if ((self = [self initWithName:nil inContainer:_container])) {
32     self->uids = [_uids copy];
33   }
34   return self;
35 }
36
37 - (void)dealloc {
38   [self->uids release];
39   [super dealloc];
40 }
41
42 /* accessors */
43
44 - (NSArray *)unescapeURLComponents:(NSArray *)_parts {
45 // #warning TODO: implement URL UID unescaping if necessary
46   // TODO: who calls this for what?
47   // Note: remember URL encoding!
48   return _parts;
49 }
50
51 - (NSArray *)uids {
52   NSArray  *a;
53   NSString *s;
54   
55   if (self->uids != nil)
56     return self->uids;
57   
58   s = [self nameInContainer];
59   if (![s hasPrefix:@"_custom_"]) {
60     [self logWithFormat:@"WARNING: incorrect custom group folder name: '%@'",
61             s];
62     return nil;
63   }
64   
65   s = [s substringFromIndex:8];
66   a = [s componentsSeparatedByString:SOGoUIDSeparator];
67   a = [self unescapeURLComponents:a];
68   self->uids = [a copy];
69   
70   if ([self->uids count] < 2)
71     [self debugWithFormat:@"Note: less than two custom group members!"];
72   
73   return self->uids;
74 }
75
76 /* display name */
77
78 - (NSString *)davDisplayName {
79   NSArray  *a;
80   unsigned count;
81   
82   a = [self uids];
83   if ((count = [a count]) == 0)
84     return @"empty";
85   if (count == 1)
86     return [a objectAtIndex:0];
87   
88   if (count < 6) {
89     NSMutableString *ms;
90     unsigned i;
91     
92     ms = [NSMutableString stringWithCapacity:64];
93     for (i = 0; i < count; i++) {
94       if (i != 0) [ms appendString:@"|"];
95       [ms appendString:[a objectAtIndex:i]];
96       if ([ms length] > 60) {
97         ms = nil;
98         break;
99       }
100     }
101     if (ms != nil) return ms;
102   }
103   
104   // TODO: localize 'members' (UI component task?)
105   return [NSString stringWithFormat:@"Members: %d", count];
106 }
107
108 @end /* SOGoCustomGroupFolder */