author | eilers <eilers> | 2002-11-28 11:50:57 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-11-28 11:50:57 (UTC) |
commit | adc6c4f994dc38ff287cb03a73933816108ba47b (patch) (unidiff) | |
tree | 7a07bb017ec7a0db0888c48b3092904ffc39ba9b | |
parent | 0d508bf39ad43aa06c9cd395dd382d8e00dfbf3a (diff) | |
download | opie-adc6c4f994dc38ff287cb03a73933816108ba47b.zip opie-adc6c4f994dc38ff287cb03a73933816108ba47b.tar.gz opie-adc6c4f994dc38ff287cb03a73933816108ba47b.tar.bz2 |
Change of view caused jump to the first line of table->fixed
-rw-r--r-- | core/pim/addressbook/abview.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp index 3af7663..0f4bd5f 100644 --- a/core/pim/addressbook/abview.cpp +++ b/core/pim/addressbook/abview.cpp | |||
@@ -1,459 +1,459 @@ | |||
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 | switch ( (int) m_curr_View ) { | 127 | switch ( (int) m_curr_View ) { |
128 | case TableView: | 128 | case TableView: |
129 | return ( m_abTable -> currentEntry() ); | 129 | return ( m_abTable -> currentEntry() ); |
130 | break; | 130 | break; |
131 | case CardView: | 131 | case CardView: |
132 | return ( m_ablabel -> currentEntry() ); | 132 | return ( m_ablabel -> currentEntry() ); |
133 | break; | 133 | break; |
134 | } | 134 | } |
135 | return OContact(); | 135 | return OContact(); |
136 | } | 136 | } |
137 | 137 | ||
138 | bool AbView::save() | 138 | bool AbView::save() |
139 | { | 139 | { |
140 | qWarning("abView:Save data"); | 140 | qWarning("abView:Save data"); |
141 | 141 | ||
142 | return m_contactdb->save(); | 142 | return m_contactdb->save(); |
143 | } | 143 | } |
144 | 144 | ||
145 | void AbView::load() | 145 | void AbView::load() |
146 | { | 146 | { |
147 | qWarning("abView:Load data"); | 147 | qWarning("abView:Load data"); |
148 | 148 | ||
149 | if ( m_inPersonal ) | 149 | if ( m_inPersonal ) |
150 | m_list = m_contactdb->allRecords(); | 150 | m_list = m_contactdb->allRecords(); |
151 | else | 151 | else |
152 | m_list = m_contactdb->sorted( true, 0, 0, 0 ); | 152 | m_list = m_contactdb->sorted( true, 0, 0, 0 ); |
153 | 153 | ||
154 | clearForCategory(); | 154 | clearForCategory(); |
155 | 155 | ||
156 | qWarning ("Number of contacts: %d", m_list.count()); | 156 | qWarning ("Number of contacts: %d", m_list.count()); |
157 | 157 | ||
158 | updateView(); | 158 | updateView(); |
159 | 159 | ||
160 | } | 160 | } |
161 | 161 | ||
162 | void AbView::reload() | 162 | void AbView::reload() |
163 | { | 163 | { |
164 | qWarning( "void AbView::reload()" ); | 164 | qWarning( "void AbView::reload()" ); |
165 | 165 | ||
166 | m_contactdb->reload(); | 166 | m_contactdb->reload(); |
167 | load(); | 167 | load(); |
168 | } | 168 | } |
169 | 169 | ||
170 | void AbView::clear() | 170 | void AbView::clear() |
171 | { | 171 | { |
172 | // :SX | 172 | // :SX |
173 | } | 173 | } |
174 | 174 | ||
175 | void AbView::setShowByCategory( const QString& cat ) | 175 | void AbView::setShowByCategory( const QString& cat ) |
176 | { | 176 | { |
177 | qWarning("AbView::setShowCategory( const QString& cat )"); | 177 | qWarning("AbView::setShowCategory( const QString& cat )"); |
178 | 178 | ||
179 | int intCat = 0; | 179 | int intCat = 0; |
180 | 180 | ||
181 | // All (cat == NULL) will be stored as -1 | 181 | // All (cat == NULL) will be stored as -1 |
182 | if ( cat.isNull() ) | 182 | if ( cat.isNull() ) |
183 | intCat = -1; | 183 | intCat = -1; |
184 | else | 184 | else |
185 | intCat = mCat.id("Contacts", cat ); | 185 | intCat = mCat.id("Contacts", cat ); |
186 | 186 | ||
187 | // Just do anything if we really change the category | 187 | // Just do anything if we really change the category |
188 | if ( intCat != m_curr_category ){ | 188 | if ( intCat != m_curr_category ){ |
189 | qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); | 189 | qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); |
190 | 190 | ||
191 | m_curr_category = intCat; | 191 | m_curr_category = intCat; |
192 | emit signalClearLetterPicker(); | 192 | emit signalClearLetterPicker(); |
193 | 193 | ||
194 | load(); | 194 | load(); |
195 | } | 195 | } |
196 | 196 | ||
197 | } | 197 | } |
198 | 198 | ||
199 | void AbView::setShowToView( Views view ) | 199 | void AbView::setShowToView( Views view ) |
200 | { | 200 | { |
201 | qWarning("void AbView::setShowToView( View %d )", view); | 201 | qWarning("void AbView::setShowToView( View %d )", view); |
202 | 202 | ||
203 | qWarning ("Change the View (Category is: %d)", m_curr_category); | 203 | qWarning ("Change the View (Category is: %d)", m_curr_category); |
204 | 204 | ||
205 | if ( m_curr_View != view ){ | 205 | if ( m_curr_View != view ){ |
206 | m_prev_View = m_curr_View; | 206 | m_prev_View = m_curr_View; |
207 | m_curr_View = view; | 207 | m_curr_View = view; |
208 | 208 | ||
209 | updateView(); | 209 | updateView(); |
210 | } | 210 | } |
211 | 211 | ||
212 | } | 212 | } |
213 | 213 | ||
214 | void AbView::setShowByLetter( char c ) | 214 | void AbView::setShowByLetter( char c ) |
215 | { | 215 | { |
216 | qWarning("void AbView::setShowByLetter( %c )", c ); | 216 | qWarning("void AbView::setShowByLetter( %c )", c ); |
217 | OContact query; | 217 | OContact query; |
218 | if ( c == 0 ){ | 218 | if ( c == 0 ){ |
219 | load(); | 219 | load(); |
220 | return; | 220 | return; |
221 | }else{ | 221 | }else{ |
222 | query.setLastName( QString("%1*").arg(c) ); | 222 | query.setLastName( QString("%1*").arg(c) ); |
223 | m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards ); | 223 | m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards ); |
224 | clearForCategory(); | 224 | clearForCategory(); |
225 | m_curr_Contact = 0; | 225 | m_curr_Contact = 0; |
226 | } | 226 | } |
227 | updateView(); | 227 | updateView(); |
228 | } | 228 | } |
229 | 229 | ||
230 | void AbView::setListOrder( const QValueList<int>& ordered ) | 230 | void AbView::setListOrder( const QValueList<int>& ordered ) |
231 | { | 231 | { |
232 | m_orderedFields = ordered; | 232 | m_orderedFields = ordered; |
233 | updateView(); | 233 | updateView(); |
234 | } | 234 | } |
235 | 235 | ||
236 | 236 | ||
237 | QString AbView::showCategory() const | 237 | QString AbView::showCategory() const |
238 | { | 238 | { |
239 | return mCat.label( "Contacts", m_curr_category ); | 239 | return mCat.label( "Contacts", m_curr_category ); |
240 | } | 240 | } |
241 | 241 | ||
242 | void AbView::showPersonal( bool personal ) | 242 | void AbView::showPersonal( bool personal ) |
243 | { | 243 | { |
244 | qWarning ("void AbView::showPersonal( %d )", personal); | 244 | qWarning ("void AbView::showPersonal( %d )", personal); |
245 | 245 | ||
246 | if ( personal ){ | 246 | if ( personal ){ |
247 | 247 | ||
248 | if ( m_inPersonal ) | 248 | if ( m_inPersonal ) |
249 | return; | 249 | return; |
250 | 250 | ||
251 | // Now switch to vCard Backend and load data. | 251 | // Now switch to vCard Backend and load data. |
252 | // The current default backend will be stored | 252 | // The current default backend will be stored |
253 | // to avoid unneeded load/stores. | 253 | // to avoid unneeded load/stores. |
254 | m_storedDB = m_contactdb; | 254 | m_storedDB = m_contactdb; |
255 | 255 | ||
256 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 256 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
257 | addressbookPersonalVCardName() ); | 257 | addressbookPersonalVCardName() ); |
258 | m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 258 | m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
259 | 259 | ||
260 | m_inPersonal = true; | 260 | m_inPersonal = true; |
261 | m_curr_View = CardView; | 261 | m_curr_View = CardView; |
262 | 262 | ||
263 | }else{ | 263 | }else{ |
264 | 264 | ||
265 | if ( !m_inPersonal ) | 265 | if ( !m_inPersonal ) |
266 | return; | 266 | return; |
267 | 267 | ||
268 | // Remove vCard Backend and restore default | 268 | // Remove vCard Backend and restore default |
269 | m_contactdb->save(); | 269 | m_contactdb->save(); |
270 | delete m_contactdb; | 270 | delete m_contactdb; |
271 | 271 | ||
272 | m_contactdb = m_storedDB; | 272 | m_contactdb = m_storedDB; |
273 | m_storedDB = 0l; | 273 | m_storedDB = 0l; |
274 | 274 | ||
275 | m_curr_View = TableView; | 275 | m_curr_View = TableView; |
276 | m_inPersonal = false; | 276 | m_inPersonal = false; |
277 | 277 | ||
278 | } | 278 | } |
279 | load(); | 279 | load(); |
280 | } | 280 | } |
281 | 281 | ||
282 | QStringList AbView::categories() | 282 | QStringList AbView::categories() |
283 | { | 283 | { |
284 | mCat.load( categoryFileName() ); | 284 | mCat.load( categoryFileName() ); |
285 | QStringList categoryList = mCat.labels( "Contacts" ); | 285 | QStringList categoryList = mCat.labels( "Contacts" ); |
286 | return categoryList; | 286 | return categoryList; |
287 | } | 287 | } |
288 | 288 | ||
289 | // BEGIN: Slots | 289 | // BEGIN: Slots |
290 | void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, | 290 | void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, |
291 | bool , QString cat = QString::null ) | 291 | bool , QString cat = QString::null ) |
292 | { | 292 | { |
293 | qWarning( "void AbView::slotDoFind" ); | 293 | qWarning( "void AbView::slotDoFind" ); |
294 | 294 | ||
295 | // We reloading the data: Deselect Letterpicker | 295 | // We reloading the data: Deselect Letterpicker |
296 | emit signalClearLetterPicker(); | 296 | emit signalClearLetterPicker(); |
297 | 297 | ||
298 | // Use the current Category if nothing else selected | 298 | // Use the current Category if nothing else selected |
299 | int category = 0; | 299 | int category = 0; |
300 | 300 | ||
301 | if ( cat.isEmpty() ) | 301 | if ( cat.isEmpty() ) |
302 | category = m_curr_category; | 302 | category = m_curr_category; |
303 | else{ | 303 | else{ |
304 | category = mCat.id("Contacts", cat ); | 304 | category = mCat.id("Contacts", cat ); |
305 | } | 305 | } |
306 | 306 | ||
307 | qWarning ("Find in Category %d", category); | 307 | qWarning ("Find in Category %d", category); |
308 | 308 | ||
309 | QRegExp r( str ); | 309 | QRegExp r( str ); |
310 | r.setCaseSensitive( caseSensitive ); | 310 | r.setCaseSensitive( caseSensitive ); |
311 | r.setWildcard( !useRegExp ); | 311 | r.setWildcard( !useRegExp ); |
312 | 312 | ||
313 | // Get all matching entries out of the database | 313 | // Get all matching entries out of the database |
314 | m_list = m_contactdb->matchRegexp( r ); | 314 | m_list = m_contactdb->matchRegexp( r ); |
315 | 315 | ||
316 | qWarning( "found: %d", m_list.count() ); | 316 | qWarning( "found: %d", m_list.count() ); |
317 | if ( m_list.count() == 0 ){ | 317 | if ( m_list.count() == 0 ){ |
318 | emit signalNotFound(); | 318 | emit signalNotFound(); |
319 | return; | 319 | return; |
320 | } | 320 | } |
321 | 321 | ||
322 | // Now remove all contacts with wrong category (if any selected) | 322 | // Now remove all contacts with wrong category (if any selected) |
323 | // This algorithm is a litte bit ineffective, but | 323 | // This algorithm is a litte bit ineffective, but |
324 | // we will not have a lot of matching entries.. | 324 | // we will not have a lot of matching entries.. |
325 | clearForCategory(); | 325 | clearForCategory(); |
326 | 326 | ||
327 | // Now show all found entries | 327 | // Now show all found entries |
328 | updateView(); | 328 | updateView(); |
329 | } | 329 | } |
330 | 330 | ||
331 | void AbView::offSearch() | 331 | void AbView::offSearch() |
332 | { | 332 | { |
333 | m_inSearch = false; | 333 | m_inSearch = false; |
334 | 334 | ||
335 | load(); | 335 | load(); |
336 | } | 336 | } |
337 | 337 | ||
338 | void AbView::slotSwitch(){ | 338 | void AbView::slotSwitch(){ |
339 | qWarning("AbView::slotSwitch()"); | 339 | qWarning("AbView::slotSwitch()"); |
340 | 340 | ||
341 | m_prev_View = m_curr_View; | 341 | m_prev_View = m_curr_View; |
342 | switch ( (int) m_curr_View ){ | 342 | switch ( (int) m_curr_View ){ |
343 | case TableView: | 343 | case TableView: |
344 | qWarning("Switching to CardView"); | 344 | qWarning("Switching to CardView"); |
345 | m_curr_View = CardView; | 345 | m_curr_View = CardView; |
346 | break; | 346 | break; |
347 | case CardView: | 347 | case CardView: |
348 | qWarning("Switching to TableView"); | 348 | qWarning("Switching to TableView"); |
349 | m_curr_View = TableView; | 349 | m_curr_View = TableView; |
350 | break; | 350 | break; |
351 | } | 351 | } |
352 | updateView(); | 352 | updateView(); |
353 | 353 | ||
354 | } | 354 | } |
355 | 355 | ||
356 | // END: Slots | 356 | // END: Slots |
357 | 357 | ||
358 | void AbView::clearForCategory() | 358 | void AbView::clearForCategory() |
359 | { | 359 | { |
360 | OContactAccess::List::Iterator it; | 360 | OContactAccess::List::Iterator it; |
361 | // Now remove all contacts with wrong category if any category selected | 361 | // Now remove all contacts with wrong category if any category selected |
362 | 362 | ||
363 | OContactAccess::List allList = m_list; | 363 | OContactAccess::List allList = m_list; |
364 | if ( m_curr_category != -1 ){ | 364 | if ( m_curr_category != -1 ){ |
365 | for ( it = allList.begin(); it != allList.end(); ++it ){ | 365 | for ( it = allList.begin(); it != allList.end(); ++it ){ |
366 | if ( !contactCompare( *it, m_curr_category ) ){ | 366 | if ( !contactCompare( *it, m_curr_category ) ){ |
367 | qWarning("Removing %d", (*it).uid()); | 367 | qWarning("Removing %d", (*it).uid()); |
368 | m_list.remove( (*it).uid() ); | 368 | m_list.remove( (*it).uid() ); |
369 | } | 369 | } |
370 | } | 370 | } |
371 | } | 371 | } |
372 | 372 | ||
373 | } | 373 | } |
374 | 374 | ||
375 | bool AbView::contactCompare( const OContact &cnt, int category ) | 375 | bool AbView::contactCompare( const OContact &cnt, int category ) |
376 | { | 376 | { |
377 | qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); | 377 | qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); |
378 | 378 | ||
379 | bool returnMe; | 379 | bool returnMe; |
380 | QArray<int> cats; | 380 | QArray<int> cats; |
381 | cats = cnt.categories(); | 381 | cats = cnt.categories(); |
382 | 382 | ||
383 | qWarning ("Number of categories: %d", cats.count() ); | 383 | qWarning ("Number of categories: %d", cats.count() ); |
384 | 384 | ||
385 | returnMe = false; | 385 | returnMe = false; |
386 | if ( cats.count() == 0 && category == 0 ) | 386 | if ( cats.count() == 0 && category == 0 ) |
387 | // Contacts with no category will just shown on "All" and "Unfiled" | 387 | // Contacts with no category will just shown on "All" and "Unfiled" |
388 | returnMe = true; | 388 | returnMe = true; |
389 | else { | 389 | else { |
390 | int i; | 390 | int i; |
391 | for ( i = 0; i < int(cats.count()); i++ ) { | 391 | for ( i = 0; i < int(cats.count()); i++ ) { |
392 | qWarning("Comparing %d with %d",cats[i],category ); | 392 | qWarning("Comparing %d with %d",cats[i],category ); |
393 | if ( cats[i] == category ) { | 393 | if ( cats[i] == category ) { |
394 | returnMe = true; | 394 | returnMe = true; |
395 | break; | 395 | break; |
396 | } | 396 | } |
397 | } | 397 | } |
398 | } | 398 | } |
399 | qWarning ("Return: %d", returnMe); | 399 | qWarning ("Return: %d", returnMe); |
400 | return returnMe; | 400 | return returnMe; |
401 | } | 401 | } |
402 | 402 | ||
403 | // In Some rare cases we have to update all lists.. | 403 | // In Some rare cases we have to update all lists.. |
404 | void AbView::updateListinViews() | 404 | void AbView::updateListinViews() |
405 | { | 405 | { |
406 | m_abTable -> setContacts( m_list ); | 406 | m_abTable -> setContacts( m_list ); |
407 | m_ablabel -> setContacts( m_list ); | 407 | m_ablabel -> setContacts( m_list ); |
408 | } | 408 | } |
409 | 409 | ||
410 | void AbView::updateView() | 410 | void AbView::updateView() |
411 | { | 411 | { |
412 | qWarning("AbView::updateView()"); | 412 | qWarning("AbView::updateView()"); |
413 | 413 | ||
414 | // Feed all views with new lists | ||
415 | updateListinViews(); | ||
416 | |||
417 | if ( m_viewStack -> visibleWidget() ){ | 414 | if ( m_viewStack -> visibleWidget() ){ |
418 | m_viewStack -> visibleWidget() -> clearFocus(); | 415 | m_viewStack -> visibleWidget() -> clearFocus(); |
419 | } | 416 | } |
420 | 417 | ||
421 | // If we switching the view, we have to store some information | 418 | // If we switching the view, we have to store some information |
422 | if ( m_list.count() ){ | 419 | if ( m_list.count() ){ |
423 | switch ( (int) m_prev_View ) { | 420 | switch ( (int) m_prev_View ) { |
424 | case TableView: | 421 | case TableView: |
425 | m_curr_Contact = m_abTable -> currentEntry_UID(); | 422 | m_curr_Contact = m_abTable -> currentEntry_UID(); |
426 | break; | 423 | break; |
427 | case CardView: | 424 | case CardView: |
428 | m_curr_Contact = m_ablabel -> currentEntry_UID(); | 425 | m_curr_Contact = m_ablabel -> currentEntry_UID(); |
429 | break; | 426 | break; |
430 | } | 427 | } |
431 | }else | 428 | }else |
432 | m_curr_Contact = 0; | 429 | m_curr_Contact = 0; |
433 | 430 | ||
431 | // Feed all views with new lists | ||
432 | updateListinViews(); | ||
433 | |||
434 | // Inform the world that the view is changed | 434 | // Inform the world that the view is changed |
435 | if ( m_curr_View != m_prev_View ) | 435 | if ( m_curr_View != m_prev_View ) |
436 | emit signalViewSwitched ( (int) m_curr_View ); | 436 | emit signalViewSwitched ( (int) m_curr_View ); |
437 | 437 | ||
438 | m_prev_View = m_curr_View; | 438 | m_prev_View = m_curr_View; |
439 | 439 | ||
440 | // Switch to new View | 440 | // Switch to new View |
441 | switch ( (int) m_curr_View ) { | 441 | switch ( (int) m_curr_View ) { |
442 | case TableView: | 442 | case TableView: |
443 | m_abTable -> setChoiceSelection( m_orderedFields ); | 443 | m_abTable -> setChoiceSelection( m_orderedFields ); |
444 | if ( m_curr_Contact != 0 ) | 444 | if ( m_curr_Contact != 0 ) |
445 | m_abTable -> selectContact ( m_curr_Contact ); | 445 | m_abTable -> selectContact ( m_curr_Contact ); |
446 | m_abTable -> setFocus(); | 446 | m_abTable -> setFocus(); |
447 | break; | 447 | break; |
448 | case CardView: | 448 | case CardView: |
449 | if ( m_curr_Contact != 0 ) | 449 | if ( m_curr_Contact != 0 ) |
450 | m_ablabel -> selectContact( m_curr_Contact ); | 450 | m_ablabel -> selectContact( m_curr_Contact ); |
451 | m_ablabel -> setFocus(); | 451 | m_ablabel -> setFocus(); |
452 | break; | 452 | break; |
453 | } | 453 | } |
454 | 454 | ||
455 | // Raise the current View | 455 | // Raise the current View |
456 | m_viewStack -> raiseWidget( m_curr_View ); | 456 | m_viewStack -> raiseWidget( m_curr_View ); |
457 | } | 457 | } |
458 | 458 | ||
459 | 459 | ||