]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Contacts/UIxContactsListView.m
improved fb.view on contacts
[scalable-opengroupware.org] / SOGo / UI / Contacts / UIxContactsListView.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 #include "UIxContactsListView.h"
23 #include <Contacts/SOGoContactFolder.h>
24 #include "common.h"
25
26 @implementation UIxContactsListView
27
28 - (void)dealloc {
29   [self->allRecords      release];
30   [self->filteredRecords release];
31   [self->searchText release];
32   [self->contact    release];
33   [super dealloc];
34 }
35
36 /* accessors */
37
38 - (void)setContact:(id)_contact {
39   ASSIGN(self->contact, _contact);
40 }
41 - (id)contact {
42   return self->contact;
43 }
44
45 - (void)setSearchText:(NSString *)_txt {
46   ASSIGNCOPY(self->searchText, _txt);
47 }
48 - (id)searchText {
49   return self->searchText;
50 }
51
52 - (EOQualifier *)qualifier {
53   NSString *qs, *s;
54   
55   s = [self searchText];
56   if ([s length] == 0)
57     return nil;
58   
59   qs = [NSString stringWithFormat:
60                    @"(sn isCaseInsensitiveLike: '%@*') OR "
61                    @"(givenname isCaseInsensitiveLike: '%@*') OR "
62                    @"(mail isCaseInsensitiveLike: '*%@*') OR "
63                    @"(telephonenumber isCaseInsensitiveLike: '*%@*')",
64                    s, s, s, s];
65   return [EOQualifier qualifierWithQualifierFormat:qs];
66 }
67
68 - (NSString *)defaultSortKey {
69   return @"sn";
70 }
71 - (NSString *)sortKey {
72   NSString *s;
73   
74   s = [[[self context] request] formValueForKey:@"sort"];
75   return [s length] > 0 ? s : [self defaultSortKey];
76 }
77 - (EOSortOrdering *)sortOrdering {
78   SEL sel;
79
80   sel = [[[[self context] request] formValueForKey:@"desc"] boolValue]
81     ? EOCompareCaseInsensitiveDescending
82     : EOCompareCaseInsensitiveAscending;
83   
84   return [EOSortOrdering sortOrderingWithKey:[self sortKey] selector:sel];
85 }
86 - (NSArray *)sortOrderings {
87   return [NSArray arrayWithObjects:[self sortOrdering], nil];
88 }
89
90 - (NSArray *)contactInfos {
91   // TODO: should be done in the backend, but for Agenor AB its OK here
92   NSArray     *records;
93   EOQualifier *q;
94   
95   if (self->filteredRecords)
96     return self->filteredRecords;
97   
98   records = [[self clientObject] fetchCoreInfos];
99   self->allRecords = 
100     [[records sortedArrayUsingKeyOrderArray:[self sortOrderings]] retain];
101   
102   if ((q = [self qualifier]) != nil) {
103   [self logWithFormat:@"qs: %@", q];
104     self->filteredRecords = 
105       [[self->allRecords filteredArrayUsingQualifier:q] retain];
106   }
107   else
108     self->filteredRecords = [self->allRecords retain];
109   
110   return self->filteredRecords;
111 }
112
113 /* notifications */
114
115 - (void)sleep {
116   [self->contact         release]; self->contact         = nil;
117   [self->allRecords      release]; self->allRecords      = nil;
118   [self->filteredRecords release]; self->filteredRecords = nil;
119   [super sleep];
120 }
121
122 /* actions */
123
124 - (BOOL)shouldTakeValuesFromRequest:(WORequest *)_rq inContext:(WOContext*)_c{
125   return YES;
126 }
127
128 @end /* UIxContactsListView */