summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/abview.cpp
Unidiff
Diffstat (limited to 'core/pim/addressbook/abview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/abview.cpp186
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,23 +1,39 @@
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
4extern QString categoryFileName(); 11extern QString categoryFileName();
5 12
6#include <qlayout.h> 13QString addressbookPersonalVCardName()
14{
15 QString filename = Global::applicationFileName("addressbook",
16 "businesscard.vcf");
17 return filename;
18}
7 19
8AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringList& slOrderedFields ): 20
21AbView::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
@@ -29,5 +45,5 @@ AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringL
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();
@@ -50,4 +66,16 @@ AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringL
50} 66}
51 67
68AbView::~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
52void AbView::setView( Views view ) 80void AbView::setView( Views view )
53{ 81{
@@ -60,5 +88,5 @@ 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
@@ -67,5 +95,5 @@ 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}
@@ -74,5 +102,5 @@ 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
@@ -96,15 +124,20 @@ bool AbView::save()
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
102void AbView::load() 129void 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());
@@ -116,5 +149,7 @@ void AbView::load()
116void AbView::reload() 149void AbView::reload()
117{ 150{
118 m_contactdb.reload(); 151 qWarning( "void AbView::reload()" );
152
153 m_contactdb->reload();
119 load(); 154 load();
120} 155}
@@ -128,16 +163,41 @@ 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}
@@ -151,5 +211,5 @@ void AbView::setShowByLetter( char c )
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;
@@ -158,4 +218,11 @@ void AbView::setShowByLetter( char c )
158} 218}
159 219
220void AbView::setListOrder( const QValueList<int>& ordered )
221{
222 m_orderedFields = ordered;
223 updateView();
224}
225
226
160QString AbView::showCategory() const 227QString AbView::showCategory() const
161{ 228{
@@ -163,8 +230,42 @@ QString AbView::showCategory() const
163} 230}
164 231
165void AbView::showContact( const OContact& cnt ) 232void 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
@@ -181,6 +282,9 @@ void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp,
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
@@ -198,5 +302,5 @@ void AbView::slotDoFind( const QString &str, bool caseSensitive, bool 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() );
@@ -246,14 +350,15 @@ void AbView::clearForCategory()
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
@@ -269,5 +374,6 @@ bool AbView::contactCompare( const OContact &cnt, int category )
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 {
@@ -285,4 +391,11 @@ bool AbView::contactCompare( const OContact &cnt, int category )
285} 391}
286 392
393// In Some rare cases we have to update all lists..
394void AbView::updateListinViews()
395{
396 m_abTable -> setContacts( m_list );
397 m_ablabel -> setContacts( m_list );
398}
399
287void AbView::updateView() 400void AbView::updateView()
288{ 401{
@@ -294,5 +407,5 @@ void AbView::updateView()
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:
@@ -303,5 +416,7 @@ void AbView::updateView()
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;
@@ -310,9 +425,9 @@ void AbView::updateView()
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:
@@ -321,5 +436,4 @@ void AbView::updateView()
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 }