]> err.no Git - scalable-opengroupware.org/blob - UI/Contacts/UIxContactsListViewContainer.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1035 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Contacts / UIxContactsListViewContainer.m
1 /* UIxContactsListViewContainer.m - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSString.h>
26
27 #import <NGObjWeb/SoObjects.h>
28 #import <NGExtensions/NSObject+Values.h>
29
30 #import <SoObjects/SOGo/AgenorUserManager.h>
31 #import <SoObjects/SOGo/SOGoUser.h>
32 #import <SoObjects/Contacts/SOGoContactFolder.h>
33
34 #import "UIxContactsListViewContainer.h"
35
36 @class SOGoContactFolders;
37
38 @implementation UIxContactsListViewContainer
39
40 - (id) init
41 {
42   if ((self = [super init]))
43     {
44       foldersPrefix = nil;
45       selectorComponentClass = nil;
46       additionalFolders = nil;
47     }
48
49   return self;
50 }
51
52 - (void) dealloc
53 {
54   [additionalFolders release];
55   [super dealloc];
56 }
57
58 - (void) setSelectorComponentClass: (NSString *) aComponentClass
59 {
60   selectorComponentClass = aComponentClass;
61 }
62
63 - (NSString *) selectorComponentName
64 {
65   return selectorComponentClass;
66 }
67
68 - (WOElement *) selectorComponent
69 {
70   WOElement *newComponent;
71 //   Class componentClass;
72
73 //   componentClass = NSClassFromString(selectorComponentClass);
74 //   if (componentClass)
75 //     {
76   newComponent = [self pageWithName: selectorComponentClass];
77 //     }
78 //   else
79 //     newComponent = nil;
80
81   return newComponent;
82 }
83
84 - (void) setCurrentFolder: (id) folder
85 {
86   currentFolder = folder;
87 }
88
89 - (NSString *) foldersPrefix
90 {
91   NSMutableArray *folders;
92   SOGoObject *currentObject;
93
94   if (!foldersPrefix)
95     {
96       folders = [NSMutableArray new];
97       [folders autorelease];
98
99       currentObject = [[self clientObject] container];
100       while (![currentObject isKindOfClass: [SOGoContactFolders class]])
101         {
102           [folders insertObject: [currentObject nameInContainer] atIndex: 0];
103           currentObject = [currentObject container];
104         }
105
106       foldersPrefix = [folders componentsJoinedByString: @"/"];
107       [foldersPrefix retain];
108     }
109
110   return foldersPrefix;
111 }
112
113 - (NSArray *) contactFolders
114 {
115   SOGoContactFolders *folderContainer;
116
117   folderContainer = [[self clientObject] container];
118
119   return [folderContainer contactFolders];
120 }
121
122 - (NSString *) currentContactFolderId
123 {
124   return [NSString stringWithFormat: @"%@/%@",
125                    [self foldersPrefix],
126                    [currentFolder nameInContainer]];
127 }
128
129 - (NSString *) currentContactFolderName
130 {
131   return [self labelForKey: [currentFolder displayName]];
132 }
133
134 - (NSArray *) additionalFolders
135 {
136   AgenorUserManager *um;
137   NSUserDefaults *ud;
138   NSString *login;
139
140   if (!additionalFolders)
141     {
142       um = [AgenorUserManager sharedUserManager];
143       login = [[context activeUser] login];
144       ud = [um getUserSettingsForUID: login];
145       additionalFolders
146         = [[ud objectForKey: @"Contacts"] objectForKey: @"SubscribedFolders"];
147       [additionalFolders retain];
148     }
149
150   return [additionalFolders allKeys];
151 }
152
153 - (void) setCurrentAdditionalFolder: (NSString *) newCurrentAdditionalFolder
154 {
155   currentAdditionalFolder = newCurrentAdditionalFolder;
156 }
157
158 - (NSString *) currentAdditionalFolder
159 {
160   return currentAdditionalFolder;
161 }
162
163 - (NSString *) currentAdditionalFolderName
164 {
165   return [[additionalFolders objectForKey: currentAdditionalFolder]
166            objectForKey: @"displayName"];
167 }
168
169 - (BOOL) hasContactSelectionButtons
170 {
171   return (selectorComponentClass != nil);
172 }
173
174 - (BOOL) isPopup
175 {
176   return [[self queryParameterForKey: @"popup"] boolValue];
177 }
178
179 @end