]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailFilterPanel.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1200 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxMailFilterPanel.m
1 /*
2  Copyright (C) 2000-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 <NGObjWeb/WOContext.h>
23 #import <NGObjWeb/WORequest.h>
24 #import <EOControl/EOQualifier.h>
25 #import <NGObjWeb/WOComponent.h>
26
27 @interface UIxMailFilterPanel : WOComponent
28 {
29   NSString *searchText;
30   NSString *searchCriteria;
31 }
32
33 @end
34
35 @implementation UIxMailFilterPanel
36
37 static NSArray *filters = nil;
38 // static NSDictionary *filterToQualifier = nil;
39
40 + (void)initialize {
41   // TODO: also available: answered, draft [custom: NotJunk and Junk]
42   // Note: we currently cannot use: "flags != 'deleted'"
43   static NSString *quals[] = {
44     @"all", nil,
45     @"read", @"flags = 'seen' AND NOT (flags = 'deleted')",
46     @"unread", @"flags = 'unseen' AND NOT (flags = 'deleted')",
47     @"deleted", @"flags = 'deleted'",
48     @"flagged", @"flags = 'flagged'",
49     nil, nil
50   };
51   NSMutableDictionary *md;
52   NSMutableArray *ma;
53   unsigned i;
54   
55   md = [[NSMutableDictionary alloc] initWithCapacity:8];
56   ma = [[NSMutableArray alloc] initWithCapacity:4];
57
58   for (i = 0; quals[i] != nil; i += 2) {
59     [ma addObject:quals[i]];
60     if (quals[i + 1] != nil) {
61       [md setObject:[EOQualifier qualifierWithQualifierFormat:quals[i + 1]]
62           forKey:quals[i]];
63     }
64   }
65   
66 //   filterToQualifier = [md copy];
67   filters           = [ma copy];
68   [md release]; md = nil;
69   [ma release]; ma = nil;
70 }
71
72 - (id) init
73 {
74   if ((self = [super init]))
75     {
76       searchText = nil;
77       searchCriteria = nil;
78     }
79
80   return self;
81 }
82
83 - (void) dealloc
84 {
85   [searchCriteria release];
86   [searchText release];
87   [super dealloc];
88 }
89
90 /* accessors */
91
92 - (void) setSearchText: (NSString *) _txt
93 {
94   ASSIGN (searchText, _txt);
95 }
96
97 - (void) setSearchCriteria: (NSString *) _txt
98 {
99   ASSIGN (searchText, _txt);
100 }
101
102 - (NSString *) searchText
103 {
104   if (!searchText)
105     {
106       searchText = [[context request] formValueForKey: @"value"];
107       [searchText retain];
108     }
109
110   return searchText;
111 }
112
113 - (NSString *) searchCriteria
114 {
115   if (!searchCriteria)
116     {
117       searchCriteria = [[context request] formValueForKey: @"criteria"];
118       [searchCriteria retain];
119     }
120
121   return searchCriteria;
122 }
123
124 /* filters */
125
126 - (NSArray *) filters
127 {
128   return filters;
129 }
130
131 /* qualifiers */
132
133 // - (EOQualifier *) searchTextQualifier
134 // {
135 //   EOQualifier *q;
136 //   NSString *s;
137   
138 //   s = [self searchText];
139 //   if ([s length] == 0)
140 //     return nil;
141   
142 //   q = [EOQualifier qualifierWithQualifierFormat:
143 //                   @"(subject doesContain: %@) OR "
144 //                   @"(from doesContain: %@)",
145 //                   s, s];
146 //   return q;
147 // }
148
149 // - (NSString *) filterLabel
150 // {
151 // #if 1
152 //   return [[context page] labelForKey:[self valueForKey:@"filter"]];
153 // #else
154 //   return [self valueForKey:@"filter"];
155 // #endif
156 // }
157
158 // - (NSString *) selectedFilter
159 // {
160 //   return  [[context request] formValueForKey: @"filterpopup"];
161 // }
162
163 // - (EOQualifier *) filterQualifier
164 // {
165 //   NSString *selectedFilter;
166   
167 //   selectedFilter = [self selectedFilter];
168   
169 //   return [selectedFilter length] > 0
170 //     ? [filterToQualifier objectForKey:selectedFilter] : nil;
171 // }
172
173 // - (EOQualifier *) qualifier
174 // {
175 //   EOQualifier *sq, *fq;
176 //   NSArray *qa;
177   
178 //   sq = [self searchTextQualifier];
179 //   fq = [self filterQualifier];
180   
181 //   if (fq == nil) return sq;
182 //   if (sq == nil) return fq;
183   
184 //   qa = [NSArray arrayWithObjects:fq, sq, nil];
185
186 //   return [[[EOAndQualifier alloc] initWithQualifierArray:qa] autorelease];
187 // }
188
189 @end /* UIxMailFilterPanel */