Diffstat (limited to 'core/pim/addressbook/abview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/addressbook/abview.cpp | 186 |
1 files changed, 150 insertions, 36 deletions
diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp index d35e392..8d22129 100644 --- a/core/pim/addressbook/abview.cpp +++ b/core/pim/addressbook/abview.cpp | |||
@@ -1,25 +1,41 @@ | |||
1 | #include "abview.h" | 1 | #include "abview.h" |
2 | 2 | ||
3 | #include <qlayout.h> | ||
4 | |||
5 | #include <qpe/global.h> | ||
6 | |||
7 | #include <opie/ocontactaccessbackend_vcard.h> | ||
8 | |||
9 | |||
3 | // Is defined in LibQPE | 10 | // Is defined in LibQPE |
4 | extern QString categoryFileName(); | 11 | extern QString categoryFileName(); |
5 | 12 | ||
6 | #include <qlayout.h> | 13 | QString addressbookPersonalVCardName() |
14 | { | ||
15 | QString filename = Global::applicationFileName("addressbook", | ||
16 | "businesscard.vcf"); | ||
17 | return filename; | ||
18 | } | ||
7 | 19 | ||
8 | AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringList& slOrderedFields ): | 20 | |
21 | AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): | ||
9 | QWidget(parent), | 22 | QWidget(parent), |
10 | mCat(0), | 23 | mCat(0), |
11 | m_inSearch( false ), | 24 | m_inSearch( false ), |
12 | m_curr_category( 0 ), | 25 | m_inPersonal( false ), |
26 | m_curr_category( -1 ), | ||
13 | m_curr_View( TableView ), | 27 | m_curr_View( TableView ), |
14 | m_prev_View( TableView ), | 28 | m_prev_View( TableView ), |
15 | m_curr_Contact ( 0 ), | 29 | m_curr_Contact ( 0 ), |
16 | m_contactdb ( "addressbook", 0l, 0l, false ), // Handle syncing myself.. ! | 30 | m_contactdb ( 0l ), |
31 | m_storedDB ( 0l ), | ||
17 | m_viewStack( 0l ), | 32 | m_viewStack( 0l ), |
18 | m_abTable( 0l ), | 33 | m_abTable( 0l ), |
19 | m_orderedFields( ordered ), | 34 | m_orderedFields( ordered ) |
20 | m_slOrderedFields( slOrderedFields ) | ||
21 | { | 35 | { |
36 | // Load default database and handle syncing myself.. ! | ||
37 | m_contactdb = new OContactAccess ( "addressbook", 0l, 0l, false ), | ||
22 | mCat.load( categoryFileName() ); | 38 | mCat.load( categoryFileName() ); |
23 | 39 | ||
24 | // Create Layout and put WidgetStack into it. | 40 | // Create Layout and put WidgetStack into it. |
25 | QVBoxLayout *vb = new QVBoxLayout( this ); | 41 | QVBoxLayout *vb = new QVBoxLayout( this ); |
@@ -27,9 +43,9 @@ AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringL | |||
27 | vb->addWidget( m_viewStack ); | 43 | vb->addWidget( m_viewStack ); |
28 | 44 | ||
29 | // Creat TableView | 45 | // Creat TableView |
30 | QVBox* tableBox = new QVBox( m_viewStack ); | 46 | QVBox* tableBox = new QVBox( m_viewStack ); |
31 | m_abTable = new AbTable( &m_orderedFields, tableBox, "table" ); | 47 | m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); |
32 | m_abTable->setCurrentCell( 0, 0 ); | 48 | m_abTable->setCurrentCell( 0, 0 ); |
33 | m_abTable->setFocus(); | 49 | m_abTable->setFocus(); |
34 | 50 | ||
35 | // Add TableView to WidgetStack and raise it | 51 | // Add TableView to WidgetStack and raise it |
@@ -48,8 +64,20 @@ AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringL | |||
48 | 64 | ||
49 | load(); | 65 | load(); |
50 | } | 66 | } |
51 | 67 | ||
68 | AbView::~AbView() | ||
69 | { | ||
70 | m_contactdb -> save(); | ||
71 | delete m_contactdb; | ||
72 | |||
73 | if ( m_storedDB ){ | ||
74 | m_storedDB -> save(); | ||
75 | delete m_storedDB; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | |||
52 | void AbView::setView( Views view ) | 80 | void AbView::setView( Views view ) |
53 | { | 81 | { |
54 | qWarning("AbView::setView( Views view )"); | 82 | qWarning("AbView::setView( Views view )"); |
55 | m_curr_View = view; | 83 | m_curr_View = view; |
@@ -58,23 +86,23 @@ void AbView::setView( Views view ) | |||
58 | 86 | ||
59 | void AbView::addEntry( const OContact &newContact ) | 87 | void AbView::addEntry( const OContact &newContact ) |
60 | { | 88 | { |
61 | qWarning("abview:AddContact"); | 89 | qWarning("abview:AddContact"); |
62 | m_contactdb.add ( newContact ); | 90 | m_contactdb->add ( newContact ); |
63 | load(); | 91 | load(); |
64 | 92 | ||
65 | } | 93 | } |
66 | void AbView::removeEntry( const int UID ) | 94 | void AbView::removeEntry( const int UID ) |
67 | { | 95 | { |
68 | qWarning("abview:RemoveContact"); | 96 | qWarning("abview:RemoveContact"); |
69 | m_contactdb.remove( UID ); | 97 | m_contactdb->remove( UID ); |
70 | load(); | 98 | load(); |
71 | } | 99 | } |
72 | 100 | ||
73 | void AbView::replaceEntry( const OContact &contact ) | 101 | void AbView::replaceEntry( const OContact &contact ) |
74 | { | 102 | { |
75 | qWarning("abview:ReplaceContact"); | 103 | qWarning("abview:ReplaceContact"); |
76 | m_contactdb.replace( contact ); | 104 | m_contactdb->replace( contact ); |
77 | load(); | 105 | load(); |
78 | 106 | ||
79 | } | 107 | } |
80 | 108 | ||
@@ -94,19 +122,24 @@ OContact AbView::currentEntry() | |||
94 | bool AbView::save() | 122 | bool AbView::save() |
95 | { | 123 | { |
96 | qWarning("abView:Save data"); | 124 | qWarning("abView:Save data"); |
97 | 125 | ||
98 | return m_contactdb.save(); | 126 | return m_contactdb->save(); |
99 | } | 127 | } |
100 | 128 | ||
101 | // :SX Add: Just load for specific Category | ||
102 | void AbView::load() | 129 | void AbView::load() |
103 | { | 130 | { |
104 | qWarning("abView:Load data"); | 131 | qWarning("abView:Load data"); |
105 | 132 | ||
106 | m_list = m_contactdb.allRecords(); | 133 | if ( m_inPersonal ) |
134 | m_list = m_contactdb->allRecords(); | ||
135 | else | ||
136 | m_list = m_contactdb->sorted( true, 0, 0, 0 ); | ||
137 | |||
107 | clearForCategory(); | 138 | clearForCategory(); |
108 | m_curr_Contact = 0; | 139 | |
140 | // Feed all views with new lists | ||
141 | updateListinViews(); | ||
109 | 142 | ||
110 | qWarning ("Number of contacts: %d", m_list.count()); | 143 | qWarning ("Number of contacts: %d", m_list.count()); |
111 | 144 | ||
112 | updateView(); | 145 | updateView(); |
@@ -114,9 +147,11 @@ void AbView::load() | |||
114 | } | 147 | } |
115 | 148 | ||
116 | void AbView::reload() | 149 | void AbView::reload() |
117 | { | 150 | { |
118 | m_contactdb.reload(); | 151 | qWarning( "void AbView::reload()" ); |
152 | |||
153 | m_contactdb->reload(); | ||
119 | load(); | 154 | load(); |
120 | } | 155 | } |
121 | 156 | ||
122 | void AbView::clear() | 157 | void AbView::clear() |
@@ -126,20 +161,45 @@ void AbView::clear() | |||
126 | 161 | ||
127 | void AbView::setShowByCategory( Views view, const QString& cat ) | 162 | void AbView::setShowByCategory( Views view, const QString& cat ) |
128 | { | 163 | { |
129 | qWarning("AbView::setShowCategory( Views view, const QString& cat )"); | 164 | qWarning("AbView::setShowCategory( Views view, const QString& cat )"); |
130 | m_curr_View = view; | ||
131 | 165 | ||
132 | emit signalClearLetterPicker(); | 166 | // if ( view == PersonalView ){ |
167 | // if ( ! m_inPersonal ) | ||
168 | // showPersonal( true ); | ||
169 | |||
170 | // }else{ | ||
171 | // if ( m_inPersonal ) | ||
172 | // showPersonal( false ); | ||
133 | 173 | ||
134 | if ( !cat.isNull() ) | 174 | // m_curr_View = view; |
135 | m_curr_category = mCat.id("Contacts", cat ); | 175 | // } |
176 | |||
177 | int intCat = 0; | ||
178 | |||
179 | // All (cat == NULL) will be stored as -1 | ||
180 | if ( cat.isNull() ) | ||
181 | intCat = -1; | ||
136 | else | 182 | else |
137 | m_curr_category = -1; // Set to all | 183 | intCat = mCat.id("Contacts", cat ); |
138 | 184 | ||
139 | qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); | 185 | // If we just change the view, we don't have to reload any data.. |
186 | // This speeds up a lot of things ! | ||
187 | if ( intCat == m_curr_category ){ | ||
188 | qWarning ("Just change the View (Category is: %d)", m_curr_category); | ||
189 | m_prev_View = m_curr_View; | ||
190 | m_curr_View = view; | ||
140 | 191 | ||
141 | load(); | 192 | updateView(); |
193 | }else{ | ||
194 | qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); | ||
195 | |||
196 | m_curr_View = view; | ||
197 | m_curr_category = intCat; | ||
198 | emit signalClearLetterPicker(); | ||
199 | |||
200 | load(); | ||
201 | } | ||
142 | 202 | ||
143 | } | 203 | } |
144 | void AbView::setShowByLetter( char c ) | 204 | void AbView::setShowByLetter( char c ) |
145 | { | 205 | { |
@@ -149,24 +209,65 @@ void AbView::setShowByLetter( char c ) | |||
149 | load(); | 209 | load(); |
150 | return; | 210 | return; |
151 | }else{ | 211 | }else{ |
152 | query.setLastName( QString("%1*").arg(c) ); | 212 | query.setLastName( QString("%1*").arg(c) ); |
153 | m_list = m_contactdb.queryByExample( query, OContactAccess::WildCards ); | 213 | m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards ); |
154 | clearForCategory(); | 214 | clearForCategory(); |
155 | m_curr_Contact = 0; | 215 | m_curr_Contact = 0; |
156 | } | 216 | } |
157 | updateView(); | 217 | updateView(); |
158 | } | 218 | } |
159 | 219 | ||
220 | void AbView::setListOrder( const QValueList<int>& ordered ) | ||
221 | { | ||
222 | m_orderedFields = ordered; | ||
223 | updateView(); | ||
224 | } | ||
225 | |||
226 | |||
160 | QString AbView::showCategory() const | 227 | QString AbView::showCategory() const |
161 | { | 228 | { |
162 | return mCat.label( "Contacts", m_curr_category ); | 229 | return mCat.label( "Contacts", m_curr_category ); |
163 | } | 230 | } |
164 | 231 | ||
165 | void AbView::showContact( const OContact& cnt ) | 232 | void AbView::showPersonal( bool personal ) |
166 | { | 233 | { |
167 | qWarning ("void AbView::showContact( const OContact& cnt )"); | 234 | qWarning ("void AbView::showPersonal( %d )", personal); |
168 | // :SX | 235 | |
236 | if ( personal ){ | ||
237 | |||
238 | if ( m_inPersonal ) | ||
239 | return; | ||
240 | |||
241 | // Now switch to vCard Backend and load data. | ||
242 | // The current default backend will be stored | ||
243 | // to avoid unneeded load/stores. | ||
244 | m_storedDB = m_contactdb; | ||
245 | |||
246 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | ||
247 | addressbookPersonalVCardName() ); | ||
248 | m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | ||
249 | |||
250 | m_inPersonal = true; | ||
251 | m_curr_View = CardView; | ||
252 | |||
253 | }else{ | ||
254 | |||
255 | if ( !m_inPersonal ) | ||
256 | return; | ||
257 | |||
258 | // Remove vCard Backend and restore default | ||
259 | m_contactdb->save(); | ||
260 | delete m_contactdb; | ||
261 | |||
262 | m_contactdb = m_storedDB; | ||
263 | m_storedDB = 0l; | ||
264 | |||
265 | m_curr_View = TableView; | ||
266 | m_inPersonal = false; | ||
267 | |||
268 | } | ||
269 | load(); | ||
169 | } | 270 | } |
170 | 271 | ||
171 | QStringList AbView::categories() | 272 | QStringList AbView::categories() |
172 | { | 273 | { |
@@ -179,10 +280,13 @@ QStringList AbView::categories() | |||
179 | void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, | 280 | void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, |
180 | bool , QString cat = QString::null ) | 281 | bool , QString cat = QString::null ) |
181 | { | 282 | { |
182 | qWarning( "void AbView::slotDoFind" ); | 283 | qWarning( "void AbView::slotDoFind" ); |
183 | // Use the current Category if nothing else selected | ||
184 | 284 | ||
285 | // We reloading the data: Deselect Letterpicker | ||
286 | emit signalClearLetterPicker(); | ||
287 | |||
288 | // Use the current Category if nothing else selected | ||
185 | int category = 0; | 289 | int category = 0; |
186 | 290 | ||
187 | if ( cat.isEmpty() ) | 291 | if ( cat.isEmpty() ) |
188 | category = m_curr_category; | 292 | category = m_curr_category; |
@@ -196,9 +300,9 @@ void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, | |||
196 | r.setCaseSensitive( caseSensitive ); | 300 | r.setCaseSensitive( caseSensitive ); |
197 | r.setWildcard( !useRegExp ); | 301 | r.setWildcard( !useRegExp ); |
198 | 302 | ||
199 | // Get all matching entries out of the database | 303 | // Get all matching entries out of the database |
200 | m_list = m_contactdb.matchRegexp( r ); | 304 | m_list = m_contactdb->matchRegexp( r ); |
201 | 305 | ||
202 | qWarning( "found: %d", m_list.count() ); | 306 | qWarning( "found: %d", m_list.count() ); |
203 | if ( m_list.count() == 0 ){ | 307 | if ( m_list.count() == 0 ){ |
204 | emit signalNotFound(); | 308 | emit signalNotFound(); |
@@ -244,18 +348,19 @@ void AbView::slotSwitch(){ | |||
244 | void AbView::clearForCategory() | 348 | void AbView::clearForCategory() |
245 | { | 349 | { |
246 | OContactAccess::List::Iterator it; | 350 | OContactAccess::List::Iterator it; |
247 | // Now remove all contacts with wrong category if any category selected | 351 | // Now remove all contacts with wrong category if any category selected |
248 | // This algorithm is a litte bit ineffective | 352 | |
353 | OContactAccess::List allList = m_list; | ||
249 | if ( m_curr_category != -1 ){ | 354 | if ( m_curr_category != -1 ){ |
250 | for ( it = m_list.begin(); it != m_list.end(); ++it ){ | 355 | for ( it = allList.begin(); it != allList.end(); ++it ){ |
251 | if ( !contactCompare( *it, m_curr_category ) ){ | 356 | if ( !contactCompare( *it, m_curr_category ) ){ |
252 | qWarning("Removing %d", (*it).uid()); | 357 | qWarning("Removing %d", (*it).uid()); |
253 | m_list.remove( (*it).uid() ); | 358 | m_list.remove( (*it).uid() ); |
254 | it = m_list.begin(); | ||
255 | } | 359 | } |
256 | } | 360 | } |
257 | } | 361 | } |
362 | |||
258 | } | 363 | } |
259 | 364 | ||
260 | bool AbView::contactCompare( const OContact &cnt, int category ) | 365 | bool AbView::contactCompare( const OContact &cnt, int category ) |
261 | { | 366 | { |
@@ -267,9 +372,10 @@ bool AbView::contactCompare( const OContact &cnt, int category ) | |||
267 | 372 | ||
268 | qWarning ("Number of categories: %d", cats.count() ); | 373 | qWarning ("Number of categories: %d", cats.count() ); |
269 | 374 | ||
270 | returnMe = false; | 375 | returnMe = false; |
271 | if ( cats.count() == 0 ) | 376 | if ( cats.count() == 0 && category == 0 ) |
377 | // Contacts with no category will just shown on "All" and "Unfiled" | ||
272 | returnMe = true; | 378 | returnMe = true; |
273 | else { | 379 | else { |
274 | int i; | 380 | int i; |
275 | for ( i = 0; i < int(cats.count()); i++ ) { | 381 | for ( i = 0; i < int(cats.count()); i++ ) { |
@@ -283,8 +389,15 @@ bool AbView::contactCompare( const OContact &cnt, int category ) | |||
283 | qWarning ("Return: %d", returnMe); | 389 | qWarning ("Return: %d", returnMe); |
284 | return returnMe; | 390 | return returnMe; |
285 | } | 391 | } |
286 | 392 | ||
393 | // In Some rare cases we have to update all lists.. | ||
394 | void AbView::updateListinViews() | ||
395 | { | ||
396 | m_abTable -> setContacts( m_list ); | ||
397 | m_ablabel -> setContacts( m_list ); | ||
398 | } | ||
399 | |||
287 | void AbView::updateView() | 400 | void AbView::updateView() |
288 | { | 401 | { |
289 | qWarning("AbView::updateView()"); | 402 | qWarning("AbView::updateView()"); |
290 | 403 | ||
@@ -292,36 +405,37 @@ void AbView::updateView() | |||
292 | m_viewStack -> visibleWidget() -> clearFocus(); | 405 | m_viewStack -> visibleWidget() -> clearFocus(); |
293 | } | 406 | } |
294 | 407 | ||
295 | // If we switching the view, we have to store some information | 408 | // If we switching the view, we have to store some information |
296 | if ( m_prev_View != m_curr_View ){ | 409 | if ( m_list.count() ){ |
297 | switch ( (int) m_prev_View ) { | 410 | switch ( (int) m_prev_View ) { |
298 | case TableView: | 411 | case TableView: |
299 | m_curr_Contact = m_abTable -> currentEntry_UID(); | 412 | m_curr_Contact = m_abTable -> currentEntry_UID(); |
300 | break; | 413 | break; |
301 | case CardView: | 414 | case CardView: |
302 | m_curr_Contact = m_ablabel -> currentEntry_UID(); | 415 | m_curr_Contact = m_ablabel -> currentEntry_UID(); |
303 | break; | 416 | break; |
304 | } | 417 | } |
305 | } | 418 | emit signalViewSwitched ( (int) m_curr_View ); |
419 | }else | ||
420 | m_curr_Contact = 0; | ||
306 | 421 | ||
307 | m_prev_View = m_curr_View; | 422 | m_prev_View = m_curr_View; |
308 | 423 | ||
309 | // Switch to new View | 424 | // Switch to new View |
310 | switch ( (int) m_curr_View ) { | 425 | switch ( (int) m_curr_View ) { |
311 | case TableView: | 426 | case TableView: |
427 | m_abTable -> setChoiceSelection( m_orderedFields ); | ||
312 | m_abTable -> setContacts( m_list ); | 428 | m_abTable -> setContacts( m_list ); |
313 | if ( m_curr_Contact != 0 ) | 429 | if ( m_curr_Contact != 0 ) |
314 | m_abTable -> selectContact ( m_curr_Contact ); | 430 | m_abTable -> selectContact ( m_curr_Contact ); |
315 | m_abTable -> setFocus(); | 431 | m_abTable -> setFocus(); |
316 | emit signalViewSwitched ( (int) m_curr_View ); | ||
317 | break; | 432 | break; |
318 | case CardView: | 433 | case CardView: |
319 | m_ablabel -> setContacts( m_list ); | 434 | m_ablabel -> setContacts( m_list ); |
320 | if ( m_curr_Contact != 0 ) | 435 | if ( m_curr_Contact != 0 ) |
321 | m_ablabel -> selectContact( m_curr_Contact ); | 436 | m_ablabel -> selectContact( m_curr_Contact ); |
322 | m_ablabel -> setFocus(); | 437 | m_ablabel -> setFocus(); |
323 | emit signalViewSwitched ( (int) m_curr_View ); | ||
324 | break; | 438 | break; |
325 | } | 439 | } |
326 | 440 | ||
327 | // Raise the current View | 441 | // Raise the current View |