]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoCustomGroupFolder.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1163 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
22 #import <Foundation/NSArray.h>
23 #import <Foundation/NSString.h>
24
25 #import <NGExtensions/NSObject+Logs.h>
26
27 #import "SOGoCustomGroupFolder.h"
28
29 @implementation SOGoCustomGroupFolder
30
31 static NSString *SOGoUIDSeparator = @",";
32
33 - (id)initWithUIDs:(NSArray *)_uids inContainer:(id)_container {
34   if ((self = [self initWithName:nil inContainer:_container])) {
35     self->uids = [_uids copy];
36   }
37   return self;
38 }
39
40 - (void)dealloc {
41   [self->uids release];
42   [super dealloc];
43 }
44
45 /* accessors */
46
47 - (NSArray *)unescapeURLComponents:(NSArray *)_parts {
48 // #warning TODO: implement URL UID unescaping if necessary
49   // TODO: who calls this for what?
50   // Note: remember URL encoding!
51   return _parts;
52 }
53
54 - (NSArray *)uids {
55   NSArray  *a;
56   NSString *s;
57   
58   if (self->uids != nil)
59     return self->uids;
60   
61   s = [self nameInContainer];
62   if (![s hasPrefix:@"_custom_"]) {
63     [self logWithFormat:@"WARNING: incorrect custom group folder name: '%@'",
64             s];
65     return nil;
66   }
67   
68   s = [s substringFromIndex:8];
69   a = [s componentsSeparatedByString:SOGoUIDSeparator];
70   a = [self unescapeURLComponents:a];
71   self->uids = [a copy];
72   
73   if ([self->uids count] < 2)
74     [self debugWithFormat:@"Note: less than two custom group members!"];
75   
76   return self->uids;
77 }
78
79 /* display name */
80
81 - (NSString *)davDisplayName {
82   NSArray  *a;
83   unsigned count;
84   
85   a = [self uids];
86   if ((count = [a count]) == 0)
87     return @"empty";
88   if (count == 1)
89     return [a objectAtIndex:0];
90   
91   if (count < 6) {
92     NSMutableString *ms;
93     unsigned i;
94     
95     ms = [NSMutableString stringWithCapacity:64];
96     for (i = 0; i < count; i++) {
97       if (i != 0) [ms appendString:@"|"];
98       [ms appendString:[a objectAtIndex:i]];
99       if ([ms length] > 60) {
100         ms = nil;
101         break;
102       }
103     }
104     if (ms != nil) return ms;
105   }
106   
107   // TODO: localize 'members' (UI component task?)
108   return [NSString stringWithFormat:@"Members: %d", count];
109 }
110
111 @end /* SOGoCustomGroupFolder */