summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/abview.cpp
Unidiff
Diffstat (limited to 'core/pim/addressbook/abview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/addressbook/abview.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp
index 8a2db96..9f7f71f 100644
--- a/core/pim/addressbook/abview.cpp
+++ b/core/pim/addressbook/abview.cpp
@@ -21,86 +21,89 @@
21 21
22#include <qpe/global.h> 22#include <qpe/global.h>
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25 25
26#include <assert.h> 26#include <assert.h>
27 27
28 28
29// Is defined in LibQPE 29// Is defined in LibQPE
30extern QString categoryFileName(); 30extern QString categoryFileName();
31 31
32QString addressbookPersonalVCardName() 32QString addressbookPersonalVCardName()
33{ 33{
34 QString filename = Global::applicationFileName("addressbook", 34 QString filename = Global::applicationFileName("addressbook",
35 "businesscard.vcf"); 35 "businesscard.vcf");
36 return filename; 36 return filename;
37} 37}
38 38
39 39
40AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): 40AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ):
41 QWidget(parent), 41 QWidget(parent),
42 mCat(0), 42 mCat(0),
43 m_inSearch( false ), 43 m_inSearch( false ),
44 m_inPersonal( false ), 44 m_inPersonal( false ),
45 m_sortOrder( true ),
45 m_curr_category( 0 ), 46 m_curr_category( 0 ),
46 m_curr_View( TableView ), 47 m_curr_View( TableView ),
47 m_prev_View( TableView ), 48 m_prev_View( TableView ),
48 m_curr_Contact ( 0 ), 49 m_curr_Contact ( 0 ),
49 m_contactdb ( 0l ), 50 m_contactdb ( 0l ),
50 m_storedDB ( 0l ), 51 m_storedDB ( 0l ),
51 m_viewStack( 0l ), 52 m_viewStack( 0l ),
52 m_abTable( 0l ), 53 m_abTable( 0l ),
53 m_orderedFields( ordered ) 54 m_orderedFields( ordered )
54{ 55{
55 odebug << "AbView::c'tor" << oendl; 56 odebug << "AbView::c'tor" << oendl;
56 // Load default database and handle syncing myself.. ! 57 // Load default database and handle syncing myself.. !
57 m_contactdb = new Opie::OPimContactAccess ( "addressbook", 0l, 0l, false ); 58 m_contactdb = new Opie::OPimContactAccess ( "addressbook", 0l, 0l, false );
58 m_contactdb -> setReadAhead( 16 ); // Use ReadAhead-Cache if available 59 m_contactdb -> setReadAhead( 16 ); // Use ReadAhead-Cache if available
59 mCat.load( categoryFileName() ); 60 mCat.load( categoryFileName() );
60 61
61 // Create Layout and put WidgetStack into it. 62 // Create Layout and put WidgetStack into it.
62 QVBoxLayout *vb = new QVBoxLayout( this ); 63 QVBoxLayout *vb = new QVBoxLayout( this );
63 m_viewStack = new QWidgetStack( this ); 64 m_viewStack = new QWidgetStack( this );
64 vb->addWidget( m_viewStack ); 65 vb->addWidget( m_viewStack );
65 66
66 // Creat TableView 67 // Creat TableView
67 QVBox* tableBox = new QVBox( m_viewStack ); 68 QVBox* tableBox = new QVBox( m_viewStack );
68 m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); 69 m_abTable = new AbTable( m_orderedFields, tableBox, "table" );
69 m_abTable->setCurrentCell( 0, 0 ); 70 m_abTable->setCurrentCell( 0, 0 );
70 m_abTable->setFocus(); 71 m_abTable->setFocus();
71 72
72 // Add TableView to WidgetStack and raise it 73 // Add TableView to WidgetStack and raise it
73 m_viewStack -> addWidget( tableBox , TableView ); 74 m_viewStack -> addWidget( tableBox , TableView );
74 75
75 // Create CardView and add it to WidgetStack 76 // Create CardView and add it to WidgetStack
76 QVBox* cardBox = new QVBox( m_viewStack ); 77 QVBox* cardBox = new QVBox( m_viewStack );
77 m_ablabel = new AbLabel( cardBox, "CardView"); 78 m_ablabel = new AbLabel( cardBox, "CardView");
78 m_viewStack -> addWidget( cardBox , CardView ); 79 m_viewStack -> addWidget( cardBox , CardView );
79 80
80 // Connect views to me 81 // Connect views to me
81 connect ( m_abTable, SIGNAL( signalSwitch(void) ), 82 connect ( m_abTable, SIGNAL( signalSwitch(void) ),
82 this, SLOT( slotSwitch(void) ) ); 83 this, SLOT( slotSwitch(void) ) );
84 connect ( m_abTable, SIGNAL( signalSortOrderChanged( bool ) ),
85 this, SLOT( slotSetSortOrder( bool ) ) );
83 connect ( m_ablabel, SIGNAL( signalOkPressed(void) ), 86 connect ( m_ablabel, SIGNAL( signalOkPressed(void) ),
84 this, SLOT( slotSwitch(void) ) ); 87 this, SLOT( slotSwitch(void) ) );
85 88
86 load(); 89 load();
87} 90}
88 91
89AbView::~AbView() 92AbView::~AbView()
90{ 93{
91 m_contactdb -> save(); 94 m_contactdb -> save();
92 delete m_contactdb; 95 delete m_contactdb;
93 96
94 if ( m_storedDB ){ 97 if ( m_storedDB ){
95 m_storedDB -> save(); 98 m_storedDB -> save();
96 delete m_storedDB; 99 delete m_storedDB;
97 } 100 }
98} 101}
99 102
100 103
101void AbView::setView( Views view ) 104void AbView::setView( Views view )
102{ 105{
103 odebug << "AbView::setView( Views view )" << oendl; 106 odebug << "AbView::setView( Views view )" << oendl;
104 m_curr_View = view; 107 m_curr_View = view;
105 load(); 108 load();
106} 109}
@@ -140,57 +143,57 @@ Opie::OPimContact AbView::currentEntry()
140 break; 143 break;
141 } 144 }
142 m_curr_Contact = currentContact.uid(); 145 m_curr_Contact = currentContact.uid();
143 return currentContact; 146 return currentContact;
144} 147}
145 148
146bool AbView::save() 149bool AbView::save()
147{ 150{
148 //odebug << "AbView::Save data" << oendl; 151 //odebug << "AbView::Save data" << oendl;
149 152
150 return m_contactdb->save(); 153 return m_contactdb->save();
151} 154}
152 155
153void AbView::load() 156void AbView::load()
154{ 157{
155 odebug << "AbView::Load data" << oendl; 158 odebug << "AbView::Load data" << oendl;
156 159
157 // Letter Search is stopped at this place 160 // Letter Search is stopped at this place
158 emit signalClearLetterPicker(); 161 emit signalClearLetterPicker();
159 162
160 odebug << "selected Category: " << m_curr_category << oendl; 163 odebug << "selected Category: " << m_curr_category << oendl;
161 164
162 if ( m_curr_category == -1 ) { 165 if ( m_curr_category == -1 ) {
163 // Show just unfiled contacts 166 // Show just unfiled contacts
164 m_list = m_contactdb->sorted( true, Opie::OPimContactAccess::SortFileAsName, 167 m_list = m_contactdb->sorted( m_sortOrder, Opie::OPimContactAccess::SortFileAsName,
165 Opie::OPimContactAccess::DoNotShowWithCategory, 0 ); 168 Opie::OPimContactAccess::DoNotShowWithCategory, 0 );
166 } elseif ( m_curr_category == 0 ){ 169 } elseif ( m_curr_category == 0 ){
167 // Just show all contacts 170 // Just show all contacts
168 m_list = m_contactdb->sorted( true, Opie::OPimContactAccess::SortFileAsName, 171 m_list = m_contactdb->sorted( m_sortOrder, Opie::OPimContactAccess::SortFileAsName,
169 Opie::OPimBase::FilterOff, 0 ); 172 Opie::OPimBase::FilterOff, 0 );
170 } else { 173 } else {
171 // Show contacts with given categories 174 // Show contacts with given categories
172 m_list = m_contactdb->sorted( true, Opie::OPimContactAccess::SortFileAsName, 175 m_list = m_contactdb->sorted( m_sortOrder, Opie::OPimContactAccess::SortFileAsName,
173 Opie::OPimBase::FilterCategory, m_curr_category ); 176 Opie::OPimBase::FilterCategory, m_curr_category );
174 } 177 }
175 178
176 odebug << "Number of contacts: " << m_list.count() << oendl; 179 odebug << "Number of contacts: " << m_list.count() << oendl;
177 180
178 updateView( true ); 181 updateView( true );
179 182
180} 183}
181 184
182void AbView::reload() 185void AbView::reload()
183{ 186{
184 odebug << "AbView::::reload()" << oendl; 187 odebug << "AbView::::reload()" << oendl;
185 188
186 m_contactdb->reload(); 189 m_contactdb->reload();
187 load(); 190 load();
188} 191}
189 192
190void AbView::clear() 193void AbView::clear()
191{ 194{
192 // :SX 195 // :SX
193} 196}
194 197
195void AbView::setShowByCategory( const QString& cat ) 198void AbView::setShowByCategory( const QString& cat )
196{ 199{
@@ -395,48 +398,53 @@ void AbView::offSearch()
395{ 398{
396 m_inSearch = false; 399 m_inSearch = false;
397 400
398 load(); 401 load();
399} 402}
400 403
401void AbView::slotSwitch(){ 404void AbView::slotSwitch(){
402 //odebug << "AbView::slotSwitch()" << oendl; 405 //odebug << "AbView::slotSwitch()" << oendl;
403 406
404 m_prev_View = m_curr_View; 407 m_prev_View = m_curr_View;
405 switch ( (int) m_curr_View ){ 408 switch ( (int) m_curr_View ){
406 case TableView: 409 case TableView:
407 odebug << "Switching to CardView" << oendl; 410 odebug << "Switching to CardView" << oendl;
408 m_curr_View = CardView; 411 m_curr_View = CardView;
409 break; 412 break;
410 case CardView: 413 case CardView:
411 odebug << "Switching to TableView" << oendl; 414 odebug << "Switching to TableView" << oendl;
412 m_curr_View = TableView; 415 m_curr_View = TableView;
413 break; 416 break;
414 } 417 }
415 updateView(); 418 updateView();
416 419
417} 420}
418 421
422void AbView::slotSetSortOrder( bool order ){
423 m_sortOrder = order;
424 reload();
425}
426
419// END: Slots 427// END: Slots
420 428
421void AbView::clearForCategory() 429void AbView::clearForCategory()
422{ 430{
423 Opie::OPimContactAccess::List::Iterator it; 431 Opie::OPimContactAccess::List::Iterator it;
424 // Now remove all contacts with wrong category if any category selected 432 // Now remove all contacts with wrong category if any category selected
425 433
426 Opie::OPimContactAccess::List allList = m_list; 434 Opie::OPimContactAccess::List allList = m_list;
427 if ( m_curr_category != 0 ){ 435 if ( m_curr_category != 0 ){
428 for ( it = allList.begin(); it != allList.end(); ++it ){ 436 for ( it = allList.begin(); it != allList.end(); ++it ){
429 if ( !contactCompare( *it, m_curr_category ) ){ 437 if ( !contactCompare( *it, m_curr_category ) ){
430 //odebug << "Removing " << (*it).uid() << oendl; 438 //odebug << "Removing " << (*it).uid() << oendl;
431 m_list.remove( (*it).uid() ); 439 m_list.remove( (*it).uid() );
432 } 440 }
433 } 441 }
434 } 442 }
435 443
436} 444}
437 445
438bool AbView::contactCompare( const Opie::OPimContact &cnt, int category ) 446bool AbView::contactCompare( const Opie::OPimContact &cnt, int category )
439{ 447{
440 //odebug << "bool AbView::contactCompare( const Opie::OPimContact &cnt, " 448 //odebug << "bool AbView::contactCompare( const Opie::OPimContact &cnt, "
441 // << category << " )" << oendl; 449 // << category << " )" << oendl;
442 450