]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailMainFrame.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1152 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/NSDictionary+URL.h>
30 #import <SoObjects/SOGo/NSArray+Utilities.h>
31 #import <SoObjects/SOGo/SOGoUser.h>
32 #import <SOGoUI/UIxComponent.h>
33
34 #import "UIxMailMainFrame.h"
35
36 @implementation UIxMailMainFrame
37
38 /* accessors */
39 - (NSString *) mailAccounts
40 {
41   NSArray *accounts, *accountNames;
42
43   accounts = [[context activeUser] mailAccounts];
44   accountNames = [accounts objectsForKey: @"name"];
45
46   return [accountNames jsonRepresentation];
47 }
48
49 - (NSString *) pageFormURL
50 {
51   NSString *u;
52   NSRange  r;
53   
54   u = [[[self context] request] uri];
55   if ((r = [u rangeOfString:@"?"]).length > 0) {
56     /* has query parameters */
57     // TODO: this is ugly, create reusable link facility in SOPE
58     // TODO: remove 'search' and 'filterpopup', preserve sorting
59     NSMutableString *ms;
60     NSArray  *qp;
61     unsigned i, count;
62     
63     qp    = [[u substringFromIndex:(r.location + r.length)] 
64                 componentsSeparatedByString:@"&"];
65     count = [qp count];
66     ms    = [NSMutableString stringWithCapacity:count * 12];
67     
68     for (i = 0; i < count; i++) {
69       NSString *s;
70       
71       s = [qp objectAtIndex:i];
72       
73       /* filter out */
74       if ([s hasPrefix:@"search="]) continue;
75       if ([s hasPrefix:@"filterpopup="]) continue;
76       
77       if ([ms length] > 0) [ms appendString:@"&"];
78       [ms appendString:s];
79     }
80     
81     if ([ms length] == 0) {
82       /* no other query params */
83       u = [u substringToIndex:r.location];
84     }
85     else {
86       u = [u substringToIndex:r.location + r.length];
87       u = [u stringByAppendingString:ms];
88     }
89     return u;
90   }
91   return [u hasSuffix:@"/"] ? @"view" : @"#";
92 }
93
94 - (id <WOActionResults>) composeAction
95 {
96   NSArray *accounts;
97   NSString *firstAccount, *newLocation;
98   SOGoMailAccounts *co;
99   NSDictionary *formValues;
100
101   co = [self clientObject];
102   accounts = [[context activeUser] mailAccounts];
103   firstAccount = [[accounts objectsForKey: @"name"] objectAtIndex: 0];
104   formValues = [[context request] formValues];
105   newLocation = [NSString stringWithFormat: @"%@/%@/compose%@",
106                           [co baseURLInContext: context],
107                           firstAccount,
108                           [formValues asURLParameters]];
109
110   return [self redirectToLocation: newLocation];
111 }
112
113 @end /* UIxMailMainFrame */