]> err.no Git - scalable-opengroupware.org/blob - UI/Contacts/UIxContactsListViewContainer.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1065 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/SOGoUser.h>
31 #import <SoObjects/Contacts/SOGoContactFolder.h>
32
33 #import "UIxContactsListViewContainer.h"
34
35 @class SOGoContactFolders;
36
37 @implementation UIxContactsListViewContainer
38
39 - (id) init
40 {
41   if ((self = [super init]))
42     {
43       foldersPrefix = nil;
44       selectorComponentClass = nil;
45       additionalFolders = nil;
46     }
47
48   return self;
49 }
50
51 - (void) dealloc
52 {
53   [additionalFolders release];
54   [super dealloc];
55 }
56
57 - (void) setSelectorComponentClass: (NSString *) aComponentClass
58 {
59   selectorComponentClass = aComponentClass;
60 }
61
62 - (NSString *) selectorComponentName
63 {
64   return selectorComponentClass;
65 }
66
67 - (WOElement *) selectorComponent
68 {
69   WOElement *newComponent;
70 //   Class componentClass;
71
72 //   componentClass = NSClassFromString(selectorComponentClass);
73 //   if (componentClass)
74 //     {
75   newComponent = [self pageWithName: selectorComponentClass];
76 //     }
77 //   else
78 //     newComponent = nil;
79
80   return newComponent;
81 }
82
83 - (void) setCurrentFolder: (id) folder
84 {
85   currentFolder = folder;
86 }
87
88 - (NSString *) foldersPrefix
89 {
90   NSMutableArray *folders;
91   SOGoObject *currentObject;
92
93   if (!foldersPrefix)
94     {
95       folders = [NSMutableArray new];
96       [folders autorelease];
97
98       currentObject = [[self clientObject] container];
99       while (![currentObject isKindOfClass: [SOGoContactFolders class]])
100         {
101           [folders insertObject: [currentObject nameInContainer] atIndex: 0];
102           currentObject = [currentObject container];
103         }
104
105       foldersPrefix = [folders componentsJoinedByString: @"/"];
106       [foldersPrefix retain];
107     }
108
109   return foldersPrefix;
110 }
111
112 - (NSArray *) contactFolders
113 {
114   SOGoContactFolders *folderContainer;
115
116   folderContainer = [[self clientObject] container];
117
118   return [folderContainer contactFolders];
119 }
120
121 - (NSString *) currentContactFolderId
122 {
123   return [NSString stringWithFormat: @"%@/%@",
124                    [self foldersPrefix],
125                    [currentFolder nameInContainer]];
126 }
127
128 - (NSString *) currentContactFolderName
129 {
130   return [currentFolder displayName];
131 }
132
133 - (NSArray *) additionalFolders
134 {
135   NSUserDefaults *ud;
136
137   if (!additionalFolders)
138     {
139       ud = [[context activeUser] userSettings];
140       additionalFolders
141         = [[ud objectForKey: @"Contacts"] objectForKey: @"SubscribedFolders"];
142       [additionalFolders retain];
143     }
144
145   return [additionalFolders allKeys];
146 }
147
148 - (void) setCurrentAdditionalFolder: (NSString *) newCurrentAdditionalFolder
149 {
150   currentAdditionalFolder = newCurrentAdditionalFolder;
151 }
152
153 - (NSString *) currentAdditionalFolder
154 {
155   return currentAdditionalFolder;
156 }
157
158 - (NSString *) currentAdditionalFolderName
159 {
160   return [[additionalFolders objectForKey: currentAdditionalFolder]
161            objectForKey: @"displayName"];
162 }
163
164 - (BOOL) hasContactSelectionButtons
165 {
166   return (selectorComponentClass != nil);
167 }
168
169 - (BOOL) isPopup
170 {
171   return [[self queryParameterForKey: @"popup"] boolValue];
172 }
173
174 @end