]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailMainFrame.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1147 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxMailMainFrame.m
1 /*
2   Copyright (C) 2004-2005 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/NSUserDefaults.h>
23 #import <NGObjWeb/WORequest.h>
24 #import <NGObjWeb/SoComponent.h>
25 #import <NGExtensions/NSString+misc.h>
26
27 #import <SoObjects/Mailer/SOGoMailObject.h>
28 #import <SoObjects/Mailer/SOGoMailAccounts.h>
29 #import <SoObjects/SOGo/NSArray+Utilities.h>
30 #import <SoObjects/SOGo/SOGoUser.h>
31 #import <SOGoUI/UIxComponent.h>
32
33 #import "UIxMailMainFrame.h"
34
35 @implementation UIxMailMainFrame
36
37 /* accessors */
38 - (NSString *) mailAccounts
39 {
40   NSArray *accounts, *accountNames;
41
42   accounts = [[context activeUser] mailAccounts];
43   accountNames = [accounts objectsForKey: @"name"];
44
45   return [accountNames jsonRepresentation];
46 }
47
48 - (NSString *) pageFormURL
49 {
50   NSString *u;
51   NSRange  r;
52   
53   u = [[[self context] request] uri];
54   if ((r = [u rangeOfString:@"?"]).length > 0) {
55     /* has query parameters */
56     // TODO: this is ugly, create reusable link facility in SOPE
57     // TODO: remove 'search' and 'filterpopup', preserve sorting
58     NSMutableString *ms;
59     NSArray  *qp;
60     unsigned i, count;
61     
62     qp    = [[u substringFromIndex:(r.location + r.length)] 
63                 componentsSeparatedByString:@"&"];
64     count = [qp count];
65     ms    = [NSMutableString stringWithCapacity:count * 12];
66     
67     for (i = 0; i < count; i++) {
68       NSString *s;
69       
70       s = [qp objectAtIndex:i];
71       
72       /* filter out */
73       if ([s hasPrefix:@"search="]) continue;
74       if ([s hasPrefix:@"filterpopup="]) continue;
75       
76       if ([ms length] > 0) [ms appendString:@"&"];
77       [ms appendString:s];
78     }
79     
80     if ([ms length] == 0) {
81       /* no other query params */
82       u = [u substringToIndex:r.location];
83     }
84     else {
85       u = [u substringToIndex:r.location + r.length];
86       u = [u stringByAppendingString:ms];
87     }
88     return u;
89   }
90   return [u hasSuffix:@"/"] ? @"view" : @"#";
91 }
92
93 @end /* UIxMailMainFrame */