-rw-r--r-- | core/pim/addressbook/abview.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp index 7226e82..161b163 100644 --- a/core/pim/addressbook/abview.cpp +++ b/core/pim/addressbook/abview.cpp | |||
@@ -1,468 +1,468 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) | 2 | ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** | 14 | ** |
15 | **********************************************************************/ | 15 | **********************************************************************/ |
16 | 16 | ||
17 | #include "abview.h" | 17 | #include "abview.h" |
18 | 18 | ||
19 | #include <qlayout.h> | 19 | #include <qlayout.h> |
20 | 20 | ||
21 | #include <qpe/global.h> | 21 | #include <qpe/global.h> |
22 | 22 | ||
23 | #include <opie/ocontactaccessbackend_vcard.h> | 23 | #include <opie/ocontactaccessbackend_vcard.h> |
24 | 24 | ||
25 | 25 | ||
26 | // Is defined in LibQPE | 26 | // Is defined in LibQPE |
27 | extern QString categoryFileName(); | 27 | extern QString categoryFileName(); |
28 | 28 | ||
29 | QString addressbookPersonalVCardName() | 29 | QString addressbookPersonalVCardName() |
30 | { | 30 | { |
31 | QString filename = Global::applicationFileName("addressbook", | 31 | QString filename = Global::applicationFileName("addressbook", |
32 | "businesscard.vcf"); | 32 | "businesscard.vcf"); |
33 | return filename; | 33 | return filename; |
34 | } | 34 | } |
35 | 35 | ||
36 | 36 | ||
37 | AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): | 37 | AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): |
38 | QWidget(parent), | 38 | QWidget(parent), |
39 | mCat(0), | 39 | mCat(0), |
40 | m_inSearch( false ), | 40 | m_inSearch( false ), |
41 | m_inPersonal( false ), | 41 | m_inPersonal( false ), |
42 | m_curr_category( -1 ), | 42 | m_curr_category( -1 ), |
43 | m_curr_View( TableView ), | 43 | m_curr_View( TableView ), |
44 | m_prev_View( TableView ), | 44 | m_prev_View( TableView ), |
45 | m_curr_Contact ( 0 ), | 45 | m_curr_Contact ( 0 ), |
46 | m_contactdb ( 0l ), | 46 | m_contactdb ( 0l ), |
47 | m_storedDB ( 0l ), | 47 | m_storedDB ( 0l ), |
48 | m_viewStack( 0l ), | 48 | m_viewStack( 0l ), |
49 | m_abTable( 0l ), | 49 | m_abTable( 0l ), |
50 | m_orderedFields( ordered ) | 50 | m_orderedFields( ordered ) |
51 | { | 51 | { |
52 | // Load default database and handle syncing myself.. ! | 52 | // Load default database and handle syncing myself.. ! |
53 | m_contactdb = new OContactAccess ( "addressbook", 0l, 0l, false ), | 53 | m_contactdb = new OContactAccess ( "addressbook", 0l, 0l, false ), |
54 | mCat.load( categoryFileName() ); | 54 | mCat.load( categoryFileName() ); |
55 | 55 | ||
56 | // Create Layout and put WidgetStack into it. | 56 | // Create Layout and put WidgetStack into it. |
57 | QVBoxLayout *vb = new QVBoxLayout( this ); | 57 | QVBoxLayout *vb = new QVBoxLayout( this ); |
58 | m_viewStack = new QWidgetStack( this ); | 58 | m_viewStack = new QWidgetStack( this ); |
59 | vb->addWidget( m_viewStack ); | 59 | vb->addWidget( m_viewStack ); |
60 | 60 | ||
61 | // Creat TableView | 61 | // Creat TableView |
62 | QVBox* tableBox = new QVBox( m_viewStack ); | 62 | QVBox* tableBox = new QVBox( m_viewStack ); |
63 | m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); | 63 | m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); |
64 | m_abTable->setCurrentCell( 0, 0 ); | 64 | m_abTable->setCurrentCell( 0, 0 ); |
65 | m_abTable->setFocus(); | 65 | m_abTable->setFocus(); |
66 | 66 | ||
67 | // Add TableView to WidgetStack and raise it | 67 | // Add TableView to WidgetStack and raise it |
68 | m_viewStack -> addWidget( tableBox , TableView ); | 68 | m_viewStack -> addWidget( tableBox , TableView ); |
69 | 69 | ||
70 | // Create CardView and add it to WidgetStack | 70 | // Create CardView and add it to WidgetStack |
71 | QVBox* cardBox = new QVBox( m_viewStack ); | 71 | QVBox* cardBox = new QVBox( m_viewStack ); |
72 | m_ablabel = new AbLabel( cardBox, "CardView"); | 72 | m_ablabel = new AbLabel( cardBox, "CardView"); |
73 | m_viewStack -> addWidget( cardBox , CardView ); | 73 | m_viewStack -> addWidget( cardBox , CardView ); |
74 | 74 | ||
75 | // Connect views to me | 75 | // Connect views to me |
76 | connect ( m_abTable, SIGNAL( signalSwitch( void ) ), | 76 | connect ( m_abTable, SIGNAL( signalSwitch( void ) ), |
77 | this, SLOT( slotSwitch( void ) ) ); | 77 | this, SLOT( slotSwitch( void ) ) ); |
78 | connect ( m_ablabel, SIGNAL( signalOkPressed( void ) ), | 78 | connect ( m_ablabel, SIGNAL( signalOkPressed( void ) ), |
79 | this, SLOT( slotSwitch( void ) ) ); | 79 | this, SLOT( slotSwitch( void ) ) ); |
80 | 80 | ||
81 | load(); | 81 | load(); |
82 | } | 82 | } |
83 | 83 | ||
84 | AbView::~AbView() | 84 | AbView::~AbView() |
85 | { | 85 | { |
86 | m_contactdb -> save(); | 86 | m_contactdb -> save(); |
87 | delete m_contactdb; | 87 | delete m_contactdb; |
88 | 88 | ||
89 | if ( m_storedDB ){ | 89 | if ( m_storedDB ){ |
90 | m_storedDB -> save(); | 90 | m_storedDB -> save(); |
91 | delete m_storedDB; | 91 | delete m_storedDB; |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | void AbView::setView( Views view ) | 96 | void AbView::setView( Views view ) |
97 | { | 97 | { |
98 | qWarning("AbView::setView( Views view )"); | 98 | qWarning("AbView::setView( Views view )"); |
99 | m_curr_View = view; | 99 | m_curr_View = view; |
100 | load(); | 100 | load(); |
101 | } | 101 | } |
102 | 102 | ||
103 | void AbView::addEntry( const OContact &newContact ) | 103 | void AbView::addEntry( const OContact &newContact ) |
104 | { | 104 | { |
105 | qWarning("abview:AddContact"); | 105 | qWarning("abview:AddContact"); |
106 | m_contactdb->add ( newContact ); | 106 | m_contactdb->add ( newContact ); |
107 | load(); | 107 | load(); |
108 | 108 | ||
109 | } | 109 | } |
110 | void AbView::removeEntry( const int UID ) | 110 | void AbView::removeEntry( const int UID ) |
111 | { | 111 | { |
112 | qWarning("abview:RemoveContact"); | 112 | qWarning("abview:RemoveContact"); |
113 | m_contactdb->remove( UID ); | 113 | m_contactdb->remove( UID ); |
114 | load(); | 114 | load(); |
115 | } | 115 | } |
116 | 116 | ||
117 | void AbView::replaceEntry( const OContact &contact ) | 117 | void AbView::replaceEntry( const OContact &contact ) |
118 | { | 118 | { |
119 | qWarning("abview:ReplaceContact"); | 119 | qWarning("abview:ReplaceContact"); |
120 | m_contactdb->replace( contact ); | 120 | m_contactdb->replace( contact ); |
121 | load(); | 121 | load(); |
122 | 122 | ||
123 | } | 123 | } |
124 | 124 | ||
125 | OContact AbView::currentEntry() | 125 | OContact AbView::currentEntry() |
126 | { | 126 | { |
127 | OContact currentContact; | 127 | OContact currentContact; |
128 | 128 | ||
129 | switch ( (int) m_curr_View ) { | 129 | switch ( (int) m_curr_View ) { |
130 | case TableView: | 130 | case TableView: |
131 | currentContact = m_abTable -> currentEntry(); | 131 | currentContact = m_abTable -> currentEntry(); |
132 | break; | 132 | break; |
133 | case CardView: | 133 | case CardView: |
134 | currentContact = m_ablabel -> currentEntry(); | 134 | currentContact = m_ablabel -> currentEntry(); |
135 | break; | 135 | break; |
136 | } | 136 | } |
137 | m_curr_Contact = currentContact.uid(); | 137 | m_curr_Contact = currentContact.uid(); |
138 | return currentContact; | 138 | return currentContact; |
139 | } | 139 | } |
140 | 140 | ||
141 | bool AbView::save() | 141 | bool AbView::save() |
142 | { | 142 | { |
143 | qWarning("abView:Save data"); | 143 | qWarning("abView:Save data"); |
144 | 144 | ||
145 | return m_contactdb->save(); | 145 | return m_contactdb->save(); |
146 | } | 146 | } |
147 | 147 | ||
148 | void AbView::load() | 148 | void AbView::load() |
149 | { | 149 | { |
150 | qWarning("abView:Load data"); | 150 | qWarning("abView:Load data"); |
151 | 151 | ||
152 | // Letter Search is stopped at this place | 152 | // Letter Search is stopped at this place |
153 | emit signalClearLetterPicker(); | 153 | emit signalClearLetterPicker(); |
154 | 154 | ||
155 | if ( m_inPersonal ) | 155 | if ( m_inPersonal ) |
156 | m_list = m_contactdb->allRecords(); | 156 | m_list = m_contactdb->allRecords(); |
157 | else{ | 157 | else{ |
158 | m_list = m_contactdb->sorted( true, 0, 0, 0 ); | 158 | m_list = m_contactdb->sorted( true, 0, 0, 0 ); |
159 | clearForCategory(); | 159 | clearForCategory(); |
160 | } | 160 | } |
161 | 161 | ||
162 | qWarning ("Number of contacts: %d", m_list.count()); | 162 | qWarning ("Number of contacts: %d", m_list.count()); |
163 | 163 | ||
164 | updateView( true ); | 164 | updateView( true ); |
165 | 165 | ||
166 | } | 166 | } |
167 | 167 | ||
168 | void AbView::reload() | 168 | void AbView::reload() |
169 | { | 169 | { |
170 | qWarning( "void AbView::reload()" ); | 170 | qWarning( "void AbView::reload()" ); |
171 | 171 | ||
172 | m_contactdb->reload(); | 172 | m_contactdb->reload(); |
173 | load(); | 173 | load(); |
174 | } | 174 | } |
175 | 175 | ||
176 | void AbView::clear() | 176 | void AbView::clear() |
177 | { | 177 | { |
178 | // :SX | 178 | // :SX |
179 | } | 179 | } |
180 | 180 | ||
181 | void AbView::setShowByCategory( const QString& cat ) | 181 | void AbView::setShowByCategory( const QString& cat ) |
182 | { | 182 | { |
183 | qWarning("AbView::setShowCategory( const QString& cat )"); | 183 | qWarning("AbView::setShowCategory( const QString& cat )"); |
184 | 184 | ||
185 | int intCat = 0; | 185 | int intCat = 0; |
186 | 186 | ||
187 | // All (cat == NULL) will be stored as -1 | 187 | // All (cat == NULL) will be stored as -1 |
188 | if ( cat.isNull() ) | 188 | if ( cat.isNull() ) |
189 | intCat = -1; | 189 | intCat = -1; |
190 | else | 190 | else |
191 | intCat = mCat.id("Contacts", cat ); | 191 | intCat = mCat.id("Contacts", cat ); |
192 | 192 | ||
193 | // Just do anything if we really change the category | 193 | // Just do anything if we really change the category |
194 | if ( intCat != m_curr_category ){ | 194 | if ( intCat != m_curr_category ){ |
195 | qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); | 195 | qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); |
196 | 196 | ||
197 | m_curr_category = intCat; | 197 | m_curr_category = intCat; |
198 | emit signalClearLetterPicker(); | 198 | emit signalClearLetterPicker(); |
199 | 199 | ||
200 | load(); | 200 | load(); |
201 | } | 201 | } |
202 | 202 | ||
203 | } | 203 | } |
204 | 204 | ||
205 | void AbView::setShowToView( Views view ) | 205 | void AbView::setShowToView( Views view ) |
206 | { | 206 | { |
207 | qWarning("void AbView::setShowToView( View %d )", view); | 207 | qWarning("void AbView::setShowToView( View %d )", view); |
208 | 208 | ||
209 | qWarning ("Change the View (Category is: %d)", m_curr_category); | 209 | qWarning ("Change the View (Category is: %d)", m_curr_category); |
210 | 210 | ||
211 | if ( m_curr_View != view ){ | 211 | if ( m_curr_View != view ){ |
212 | m_prev_View = m_curr_View; | 212 | m_prev_View = m_curr_View; |
213 | m_curr_View = view; | 213 | m_curr_View = view; |
214 | 214 | ||
215 | updateView(); | 215 | updateView(); |
216 | } | 216 | } |
217 | 217 | ||
218 | } | 218 | } |
219 | 219 | ||
220 | void AbView::setShowByLetter( char c ) | 220 | void AbView::setShowByLetter( char c ) |
221 | { | 221 | { |
222 | qWarning("void AbView::setShowByLetter( %c )", c ); | 222 | qWarning("void AbView::setShowByLetter( %c )", c ); |
223 | OContact query; | 223 | OContact query; |
224 | if ( c == 0 ){ | 224 | if ( c == 0 ){ |
225 | load(); | 225 | load(); |
226 | return; | 226 | return; |
227 | }else{ | 227 | }else{ |
228 | query.setLastName( QString("%1*").arg(c) ); | 228 | query.setLastName( QString("%1*").arg(c) ); |
229 | m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards ); | 229 | m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards ); |
230 | clearForCategory(); | 230 | clearForCategory(); |
231 | m_curr_Contact = 0; | 231 | m_curr_Contact = 0; |
232 | } | 232 | } |
233 | updateView( true ); | 233 | updateView( true ); |
234 | } | 234 | } |
235 | 235 | ||
236 | void AbView::setListOrder( const QValueList<int>& ordered ) | 236 | void AbView::setListOrder( const QValueList<int>& ordered ) |
237 | { | 237 | { |
238 | m_orderedFields = ordered; | 238 | m_orderedFields = ordered; |
239 | updateView(); | 239 | updateView(); |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | QString AbView::showCategory() const | 243 | QString AbView::showCategory() const |
244 | { | 244 | { |
245 | return mCat.label( "Contacts", m_curr_category ); | 245 | return mCat.label( "Contacts", m_curr_category ); |
246 | } | 246 | } |
247 | 247 | ||
248 | void AbView::showPersonal( bool personal ) | 248 | void AbView::showPersonal( bool personal ) |
249 | { | 249 | { |
250 | qWarning ("void AbView::showPersonal( %d )", personal); | 250 | qWarning ("void AbView::showPersonal( %d )", personal); |
251 | 251 | ||
252 | if ( personal ){ | 252 | if ( personal ){ |
253 | 253 | ||
254 | if ( m_inPersonal ) | 254 | if ( m_inPersonal ) |
255 | return; | 255 | return; |
256 | 256 | ||
257 | // Now switch to vCard Backend and load data. | 257 | // Now switch to vCard Backend and load data. |
258 | // The current default backend will be stored | 258 | // The current default backend will be stored |
259 | // to avoid unneeded load/stores. | 259 | // to avoid unneeded load/stores. |
260 | m_storedDB = m_contactdb; | 260 | m_storedDB = m_contactdb; |
261 | 261 | ||
262 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 262 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
263 | addressbookPersonalVCardName() ); | 263 | addressbookPersonalVCardName() ); |
264 | m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 264 | m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
265 | 265 | ||
266 | m_inPersonal = true; | 266 | m_inPersonal = true; |
267 | m_curr_View = CardView; | 267 | m_curr_View = CardView; |
268 | 268 | ||
269 | }else{ | 269 | }else{ |
270 | 270 | ||
271 | if ( !m_inPersonal ) | 271 | if ( !m_inPersonal ) |
272 | return; | 272 | return; |
273 | 273 | ||
274 | // Remove vCard Backend and restore default | 274 | // Remove vCard Backend and restore default |
275 | m_contactdb->save(); | 275 | m_contactdb->save(); |
276 | delete m_contactdb; | 276 | delete m_contactdb; |
277 | 277 | ||
278 | m_contactdb = m_storedDB; | 278 | m_contactdb = m_storedDB; |
279 | m_storedDB = 0l; | 279 | m_storedDB = 0l; |
280 | 280 | ||
281 | m_curr_View = TableView; | 281 | m_curr_View = TableView; |
282 | m_inPersonal = false; | 282 | m_inPersonal = false; |
283 | 283 | ||
284 | } | 284 | } |
285 | load(); | 285 | load(); |
286 | } | 286 | } |
287 | 287 | ||
288 | QStringList AbView::categories() | 288 | QStringList AbView::categories() |
289 | { | 289 | { |
290 | mCat.load( categoryFileName() ); | 290 | mCat.load( categoryFileName() ); |
291 | QStringList categoryList = mCat.labels( "Contacts" ); | 291 | QStringList categoryList = mCat.labels( "Contacts" ); |
292 | return categoryList; | 292 | return categoryList; |
293 | } | 293 | } |
294 | 294 | ||
295 | // BEGIN: Slots | 295 | // BEGIN: Slots |
296 | void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, | 296 | void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, |
297 | bool , QString cat = QString::null ) | 297 | bool , QString cat ) |
298 | { | 298 | { |
299 | qWarning( "void AbView::slotDoFind" ); | 299 | qWarning( "void AbView::slotDoFind" ); |
300 | 300 | ||
301 | // We reloading the data: Deselect Letterpicker | 301 | // We reloading the data: Deselect Letterpicker |
302 | emit signalClearLetterPicker(); | 302 | emit signalClearLetterPicker(); |
303 | 303 | ||
304 | // Use the current Category if nothing else selected | 304 | // Use the current Category if nothing else selected |
305 | int category = 0; | 305 | int category = 0; |
306 | 306 | ||
307 | if ( cat.isEmpty() ) | 307 | if ( cat.isEmpty() ) |
308 | category = m_curr_category; | 308 | category = m_curr_category; |
309 | else{ | 309 | else{ |
310 | category = mCat.id("Contacts", cat ); | 310 | category = mCat.id("Contacts", cat ); |
311 | } | 311 | } |
312 | 312 | ||
313 | qWarning ("Find in Category %d", category); | 313 | qWarning ("Find in Category %d", category); |
314 | 314 | ||
315 | QRegExp r( str ); | 315 | QRegExp r( str ); |
316 | r.setCaseSensitive( caseSensitive ); | 316 | r.setCaseSensitive( caseSensitive ); |
317 | r.setWildcard( !useRegExp ); | 317 | r.setWildcard( !useRegExp ); |
318 | 318 | ||
319 | // Get all matching entries out of the database | 319 | // Get all matching entries out of the database |
320 | m_list = m_contactdb->matchRegexp( r ); | 320 | m_list = m_contactdb->matchRegexp( r ); |
321 | 321 | ||
322 | qWarning( "found: %d", m_list.count() ); | 322 | qWarning( "found: %d", m_list.count() ); |
323 | if ( m_list.count() == 0 ){ | 323 | if ( m_list.count() == 0 ){ |
324 | emit signalNotFound(); | 324 | emit signalNotFound(); |
325 | return; | 325 | return; |
326 | } | 326 | } |
327 | 327 | ||
328 | // Now remove all contacts with wrong category (if any selected) | 328 | // Now remove all contacts with wrong category (if any selected) |
329 | // This algorithm is a litte bit ineffective, but | 329 | // This algorithm is a litte bit ineffective, but |
330 | // we will not have a lot of matching entries.. | 330 | // we will not have a lot of matching entries.. |
331 | clearForCategory(); | 331 | clearForCategory(); |
332 | 332 | ||
333 | // Now show all found entries | 333 | // Now show all found entries |
334 | updateView( true ); | 334 | updateView( true ); |
335 | } | 335 | } |
336 | 336 | ||
337 | void AbView::offSearch() | 337 | void AbView::offSearch() |
338 | { | 338 | { |
339 | m_inSearch = false; | 339 | m_inSearch = false; |
340 | 340 | ||
341 | load(); | 341 | load(); |
342 | } | 342 | } |
343 | 343 | ||
344 | void AbView::slotSwitch(){ | 344 | void AbView::slotSwitch(){ |
345 | qWarning("AbView::slotSwitch()"); | 345 | qWarning("AbView::slotSwitch()"); |
346 | 346 | ||
347 | m_prev_View = m_curr_View; | 347 | m_prev_View = m_curr_View; |
348 | switch ( (int) m_curr_View ){ | 348 | switch ( (int) m_curr_View ){ |
349 | case TableView: | 349 | case TableView: |
350 | qWarning("Switching to CardView"); | 350 | qWarning("Switching to CardView"); |
351 | m_curr_View = CardView; | 351 | m_curr_View = CardView; |
352 | break; | 352 | break; |
353 | case CardView: | 353 | case CardView: |
354 | qWarning("Switching to TableView"); | 354 | qWarning("Switching to TableView"); |
355 | m_curr_View = TableView; | 355 | m_curr_View = TableView; |
356 | break; | 356 | break; |
357 | } | 357 | } |
358 | updateView(); | 358 | updateView(); |
359 | 359 | ||
360 | } | 360 | } |
361 | 361 | ||
362 | // END: Slots | 362 | // END: Slots |
363 | 363 | ||
364 | void AbView::clearForCategory() | 364 | void AbView::clearForCategory() |
365 | { | 365 | { |
366 | OContactAccess::List::Iterator it; | 366 | OContactAccess::List::Iterator it; |
367 | // Now remove all contacts with wrong category if any category selected | 367 | // Now remove all contacts with wrong category if any category selected |
368 | 368 | ||
369 | OContactAccess::List allList = m_list; | 369 | OContactAccess::List allList = m_list; |
370 | if ( m_curr_category != -1 ){ | 370 | if ( m_curr_category != -1 ){ |
371 | for ( it = allList.begin(); it != allList.end(); ++it ){ | 371 | for ( it = allList.begin(); it != allList.end(); ++it ){ |
372 | if ( !contactCompare( *it, m_curr_category ) ){ | 372 | if ( !contactCompare( *it, m_curr_category ) ){ |
373 | qWarning("Removing %d", (*it).uid()); | 373 | qWarning("Removing %d", (*it).uid()); |
374 | m_list.remove( (*it).uid() ); | 374 | m_list.remove( (*it).uid() ); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | } | 377 | } |
378 | 378 | ||
379 | } | 379 | } |
380 | 380 | ||
381 | bool AbView::contactCompare( const OContact &cnt, int category ) | 381 | bool AbView::contactCompare( const OContact &cnt, int category ) |
382 | { | 382 | { |
383 | qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); | 383 | qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); |
384 | 384 | ||
385 | bool returnMe; | 385 | bool returnMe; |
386 | QArray<int> cats; | 386 | QArray<int> cats; |
387 | cats = cnt.categories(); | 387 | cats = cnt.categories(); |
388 | 388 | ||
389 | qWarning ("Number of categories: %d", cats.count() ); | 389 | qWarning ("Number of categories: %d", cats.count() ); |
390 | 390 | ||
391 | returnMe = false; | 391 | returnMe = false; |
392 | if ( cats.count() == 0 && category == 0 ) | 392 | if ( cats.count() == 0 && category == 0 ) |
393 | // Contacts with no category will just shown on "All" and "Unfiled" | 393 | // Contacts with no category will just shown on "All" and "Unfiled" |
394 | returnMe = true; | 394 | returnMe = true; |
395 | else { | 395 | else { |
396 | int i; | 396 | int i; |
397 | for ( i = 0; i < int(cats.count()); i++ ) { | 397 | for ( i = 0; i < int(cats.count()); i++ ) { |
398 | qWarning("Comparing %d with %d",cats[i],category ); | 398 | qWarning("Comparing %d with %d",cats[i],category ); |
399 | if ( cats[i] == category ) { | 399 | if ( cats[i] == category ) { |
400 | returnMe = true; | 400 | returnMe = true; |
401 | break; | 401 | break; |
402 | } | 402 | } |
403 | } | 403 | } |
404 | } | 404 | } |
405 | qWarning ("Return: %d", returnMe); | 405 | qWarning ("Return: %d", returnMe); |
406 | return returnMe; | 406 | return returnMe; |
407 | } | 407 | } |
408 | 408 | ||
409 | // In Some rare cases we have to update all lists.. | 409 | // In Some rare cases we have to update all lists.. |
410 | void AbView::updateListinViews() | 410 | void AbView::updateListinViews() |
411 | { | 411 | { |
412 | m_abTable -> setContacts( m_list ); | 412 | m_abTable -> setContacts( m_list ); |
413 | m_ablabel -> setContacts( m_list ); | 413 | m_ablabel -> setContacts( m_list ); |
414 | } | 414 | } |
415 | 415 | ||
416 | void AbView::updateView( bool newdata ) | 416 | void AbView::updateView( bool newdata ) |
417 | { | 417 | { |
418 | qWarning("AbView::updateView()"); | 418 | qWarning("AbView::updateView()"); |
419 | 419 | ||
420 | if ( m_viewStack -> visibleWidget() ){ | 420 | if ( m_viewStack -> visibleWidget() ){ |
421 | m_viewStack -> visibleWidget() -> clearFocus(); | 421 | m_viewStack -> visibleWidget() -> clearFocus(); |
422 | } | 422 | } |
423 | 423 | ||
424 | // If we switching the view, we have to store some information | 424 | // If we switching the view, we have to store some information |
425 | if ( !newdata ){ | 425 | if ( !newdata ){ |
426 | if ( m_list.count() ){ | 426 | if ( m_list.count() ){ |
427 | switch ( (int) m_prev_View ) { | 427 | switch ( (int) m_prev_View ) { |
428 | case TableView: | 428 | case TableView: |
429 | m_curr_Contact = m_abTable -> currentEntry_UID(); | 429 | m_curr_Contact = m_abTable -> currentEntry_UID(); |
430 | break; | 430 | break; |
431 | case CardView: | 431 | case CardView: |
432 | m_curr_Contact = m_ablabel -> currentEntry_UID(); | 432 | m_curr_Contact = m_ablabel -> currentEntry_UID(); |
433 | break; | 433 | break; |
434 | } | 434 | } |
435 | }else | 435 | }else |
436 | m_curr_Contact = 0; | 436 | m_curr_Contact = 0; |
437 | } | 437 | } |
438 | 438 | ||
439 | // Feed all views with new lists | 439 | // Feed all views with new lists |
440 | if ( newdata ) | 440 | if ( newdata ) |
441 | updateListinViews(); | 441 | updateListinViews(); |
442 | 442 | ||
443 | // Tell the world that the view is changed | 443 | // Tell the world that the view is changed |
444 | if ( m_curr_View != m_prev_View ) | 444 | if ( m_curr_View != m_prev_View ) |
445 | emit signalViewSwitched ( (int) m_curr_View ); | 445 | emit signalViewSwitched ( (int) m_curr_View ); |
446 | 446 | ||
447 | m_prev_View = m_curr_View; | 447 | m_prev_View = m_curr_View; |
448 | 448 | ||
449 | // Switch to new View | 449 | // Switch to new View |
450 | switch ( (int) m_curr_View ) { | 450 | switch ( (int) m_curr_View ) { |
451 | case TableView: | 451 | case TableView: |
452 | m_abTable -> setChoiceSelection( m_orderedFields ); | 452 | m_abTable -> setChoiceSelection( m_orderedFields ); |
453 | if ( m_curr_Contact != 0 ) | 453 | if ( m_curr_Contact != 0 ) |
454 | m_abTable -> selectContact ( m_curr_Contact ); | 454 | m_abTable -> selectContact ( m_curr_Contact ); |
455 | m_abTable -> setFocus(); | 455 | m_abTable -> setFocus(); |
456 | break; | 456 | break; |
457 | case CardView: | 457 | case CardView: |
458 | if ( m_curr_Contact != 0 ) | 458 | if ( m_curr_Contact != 0 ) |
459 | m_ablabel -> selectContact( m_curr_Contact ); | 459 | m_ablabel -> selectContact( m_curr_Contact ); |
460 | m_ablabel -> setFocus(); | 460 | m_ablabel -> setFocus(); |
461 | break; | 461 | break; |
462 | } | 462 | } |
463 | 463 | ||
464 | // Raise the current View | 464 | // Raise the current View |
465 | m_viewStack -> raiseWidget( m_curr_View ); | 465 | m_viewStack -> raiseWidget( m_curr_View ); |
466 | } | 466 | } |
467 | 467 | ||
468 | 468 | ||