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
@@ -2,2 +2,9 @@
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
@@ -5,5 +12,11 @@ extern 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),
@@ -11,3 +24,4 @@ AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringL
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 ),
@@ -15,8 +29,10 @@ AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringL
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() );
@@ -30,3 +46,3 @@ AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringL
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 );
@@ -51,2 +67,14 @@ AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringL
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 )
@@ -61,3 +89,3 @@ void AbView::addEntry( const OContact &newContact )
61 qWarning("abview:AddContact"); 89 qWarning("abview:AddContact");
62 m_contactdb.add ( newContact ); 90 m_contactdb->add ( newContact );
63 load(); 91 load();
@@ -68,3 +96,3 @@ void AbView::removeEntry( const int UID )
68 qWarning("abview:RemoveContact"); 96 qWarning("abview:RemoveContact");
69 m_contactdb.remove( UID ); 97 m_contactdb->remove( UID );
70 load(); 98 load();
@@ -75,3 +103,3 @@ void AbView::replaceEntry( const OContact &contact )
75 qWarning("abview:ReplaceContact"); 103 qWarning("abview:ReplaceContact");
76 m_contactdb.replace( contact ); 104 m_contactdb->replace( contact );
77 load(); 105 load();
@@ -97,6 +125,5 @@ bool AbView::save()
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()
@@ -105,5 +132,11 @@ void AbView::load()
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
@@ -117,3 +150,5 @@ void AbView::reload()
117{ 150{
118 m_contactdb.reload(); 151 qWarning( "void AbView::reload()" );
152
153 m_contactdb->reload();
119 load(); 154 load();
@@ -129,14 +164,39 @@ void AbView::setShowByCategory( Views view, const QString& cat )
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
@@ -152,3 +212,3 @@ void AbView::setShowByLetter( char c )
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();
@@ -159,2 +219,9 @@ void AbView::setShowByLetter( char c )
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
@@ -164,6 +231,40 @@ QString AbView::showCategory() const
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}
@@ -182,4 +283,7 @@ void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp,
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;
@@ -199,3 +303,3 @@ void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp,
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
@@ -247,5 +351,6 @@ void AbView::clearForCategory()
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 ) ){
@@ -253,3 +358,2 @@ void AbView::clearForCategory()
253 m_list.remove( (*it).uid() ); 358 m_list.remove( (*it).uid() );
254 it = m_list.begin();
255 } 359 }
@@ -257,2 +361,3 @@ void AbView::clearForCategory()
257 } 361 }
362
258} 363}
@@ -270,3 +375,4 @@ bool AbView::contactCompare( const OContact &cnt, int category )
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;
@@ -286,2 +392,9 @@ bool AbView::contactCompare( const OContact &cnt, int category )
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()
@@ -295,3 +408,3 @@ void AbView::updateView()
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 ) {
@@ -304,3 +417,5 @@ void AbView::updateView()
304 } 417 }
305 } 418 emit signalViewSwitched ( (int) m_curr_View );
419 }else
420 m_curr_Contact = 0;
306 421
@@ -311,2 +426,3 @@ void AbView::updateView()
311 case TableView: 426 case TableView:
427 m_abTable -> setChoiceSelection( m_orderedFields );
312 m_abTable -> setContacts( m_list ); 428 m_abTable -> setContacts( m_list );
@@ -315,3 +431,2 @@ void AbView::updateView()
315 m_abTable -> setFocus(); 431 m_abTable -> setFocus();
316 emit signalViewSwitched ( (int) m_curr_View );
317 break; 432 break;
@@ -322,3 +437,2 @@ void AbView::updateView()
322 m_ablabel -> setFocus(); 437 m_ablabel -> setFocus();
323 emit signalViewSwitched ( (int) m_curr_View );
324 break; 438 break;