]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailFilterPanel.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1065 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 #include <NGObjWeb/WOComponent.h>
23
24 @interface UIxMailFilterPanel : WOComponent
25 {
26   NSString *searchText;
27   NSString *searchCriteria;
28 }
29
30 @end
31
32 #include <SOGoUI/UIxComponent.h>
33 #include "common.h"
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   [self->searchCriteria release];
85   [self->searchText release];
86   [super dealloc];
87 }
88
89 /* accessors */
90
91 - (void)setSearchText: (NSString *)_txt
92 {
93   ASSIGNCOPY(self->searchText, _txt);
94 }
95
96 - (void)setSearchCriteria: (NSString *)_txt
97 {
98   ASSIGNCOPY(self->searchText, _txt);
99 }
100
101 - (NSString *)searchText
102 {
103   if (self->searchText == nil)
104     {
105       self->searchText = 
106         [[[[self context] request] formValueForKey:@"search"] copy];
107     }
108   return self->searchText;
109 }
110
111 - (NSString *)searchCriteria
112 {
113   if (self->searchCriteria == nil)
114     {
115       self->searchCriteria = 
116         [[[[self context] request] formValueForKey:@"criteria"] copy];
117     }
118   return self->searchCriteria;
119 }
120
121 /* filters */
122
123 - (NSArray *)filters
124 {
125   return filters;
126 }
127
128 /* qualifiers */
129
130 - (EOQualifier *) searchTextQualifier
131 {
132   EOQualifier *q;
133   NSString *s;
134   
135   s = [self searchText];
136   if ([s length] == 0)
137     return nil;
138   
139   q = [EOQualifier qualifierWithQualifierFormat:
140                      @"(subject doesContain: %@) OR "
141                      @"(from doesContain: %@)",
142                      s, s];
143   return q;
144 }
145
146 - (NSString *)filterLabel
147 {
148 #if 1
149   return [[[self context] page] labelForKey:[self valueForKey:@"filter"]];
150 #else
151   return [self valueForKey:@"filter"];
152 #endif
153 }
154
155 - (NSString *)selectedFilter
156 {
157   return  [[[self context] request] formValueForKey:@"filterpopup"];
158 }
159
160 - (EOQualifier *)filterQualifier
161 {
162   NSString *selectedFilter;
163   
164   selectedFilter = [self selectedFilter];
165   
166   return [selectedFilter length] > 0
167     ? [filterToQualifier objectForKey:selectedFilter] : nil;
168 }
169
170 - (EOQualifier *) qualifier
171 {
172   EOQualifier *sq, *fq;
173   NSArray *qa;
174   
175   sq = [self searchTextQualifier];
176   fq = [self filterQualifier];
177   
178   if (fq == nil) return sq;
179   if (sq == nil) return fq;
180   
181   qa = [NSArray arrayWithObjects:fq, sq, nil];
182   return [[[EOAndQualifier alloc] initWithQualifierArray:qa] autorelease];
183 }
184
185 @end /* UIxMailFilterPanel */