summaryrefslogtreecommitdiff
authoreilers <eilers>2005-03-24 16:23:51 (UTC)
committer eilers <eilers>2005-03-24 16:23:51 (UTC)
commitb390bcd32e188fc3c9fd7067bfc41b60b5e84ad4 (patch) (unidiff)
tree38bc784605eb06a6669e8708c86cc9cebaa32b2a
parent29da9a4477210843435cbea3ede0d520775fe1a5 (diff)
downloadopie-b390bcd32e188fc3c9fd7067bfc41b60b5e84ad4.zip
opie-b390bcd32e188fc3c9fd7067bfc41b60b5e84ad4.tar.gz
opie-b390bcd32e188fc3c9fd7067bfc41b60b5e84ad4.tar.bz2
In table view: Clicking on column 0 changes the sortorder.
Version of ths app was changed to 1.2.0 Requested by #1591
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/abtable.cpp93
-rw-r--r--core/pim/addressbook/abtable.h1
-rw-r--r--core/pim/addressbook/abview.cpp14
-rw-r--r--core/pim/addressbook/abview.h2
-rw-r--r--core/pim/addressbook/version.h4
5 files changed, 23 insertions, 91 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp
index 49e66ad..60f3177 100644
--- a/core/pim/addressbook/abtable.cpp
+++ b/core/pim/addressbook/abtable.cpp
@@ -79,359 +79,280 @@ AbPickItem::AbPickItem( QTable *t ) :
79 QTableItem(t, WhenCurrent, "?") 79 QTableItem(t, WhenCurrent, "?")
80{ 80{
81} 81}
82 82
83QWidget *AbPickItem::createEditor() const 83QWidget *AbPickItem::createEditor() const
84{ 84{
85 QComboBox* combo = new QComboBox( table()->viewport() ); 85 QComboBox* combo = new QComboBox( table()->viewport() );
86 ( (AbPickItem*)this )->cb = combo; 86 ( (AbPickItem*)this )->cb = combo;
87 AbTable* t = static_cast<AbTable*>(table()); 87 AbTable* t = static_cast<AbTable*>(table());
88 QStringList c = t->choiceNames(); 88 QStringList c = t->choiceNames();
89 int cur = 0; 89 int cur = 0;
90 for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { 90 for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) {
91 if ( *it == text() ) 91 if ( *it == text() )
92 cur = combo->count(); 92 cur = combo->count();
93 combo->insertItem(*it); 93 combo->insertItem(*it);
94 } 94 }
95 combo->setCurrentItem(cur); 95 combo->setCurrentItem(cur);
96 return combo; 96 return combo;
97} 97}
98 98
99void AbPickItem::setContentFromEditor( QWidget *w ) 99void AbPickItem::setContentFromEditor( QWidget *w )
100{ 100{
101 if ( w->inherits("QComboBox") ) 101 if ( w->inherits("QComboBox") )
102 setText( ( (QComboBox*)w )->currentText() ); 102 setText( ( (QComboBox*)w )->currentText() );
103 else 103 else
104 QTableItem::setContentFromEditor( w ); 104 QTableItem::setContentFromEditor( w );
105} 105}
106 106
107#endif 107#endif
108 108
109/*! 109/*!
110 \class AbTable abtable.h 110 \class AbTable abtable.h
111 111
112 \brief QTable based class for showing a list of entries 112 \brief QTable based class for showing a list of entries
113*/ 113*/
114 114
115AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name ) 115AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name )
116 : QTable( parent, name ), 116 : QTable( parent, name ),
117 lastSortCol( -1 ), 117 lastSortCol( -1 ),
118 asc( TRUE ), 118 asc( TRUE ),
119 intFields( order ), 119 intFields( order ),
120 enablePainting( true ), 120 enablePainting( true ),
121 columnVisible( true ), 121 columnVisible( true ),
122 countNested( 0 ) 122 countNested( 0 )
123{ 123{
124 //odebug << "C'tor start" << oendl; 124 //odebug << "C'tor start" << oendl;
125 setSelectionMode( NoSelection ); 125 setSelectionMode( NoSelection );
126 init(); 126 init();
127 setSorting( TRUE ); 127 setSorting( false ); // The table should not sort by itself!
128
128 connect( this, SIGNAL(clicked(int,int,int,const QPoint&)), 129 connect( this, SIGNAL(clicked(int,int,int,const QPoint&)),
129 this, SLOT(itemClicked(int,int)) ); 130 this, SLOT(itemClicked(int,int)) );
130 131
131 // contactList.clear(); 132 // contactList.clear();
132 //odebug << "C'tor end" << oendl; 133 //odebug << "C'tor end" << oendl;
133} 134}
134 135
135AbTable::~AbTable() 136AbTable::~AbTable()
136{ 137{
137} 138}
138 139
139void AbTable::init() 140void AbTable::init()
140{ 141{
141 // :SX showChar = '\0'; 142 // :SX showChar = '\0';
142 setNumRows( 0 ); 143 setNumRows( 0 );
143 setNumCols( 2 ); 144 setNumCols( 2 );
144 145
145 horizontalHeader()->setLabel( 0, tr( "Full Name" )); 146 horizontalHeader()->setLabel( 0, tr( "Full Name" ));
146 horizontalHeader()->setLabel( 1, tr( "Contact" )); 147 horizontalHeader()->setLabel( 1, tr( "Contact" ));
147 setLeftMargin( 0 ); 148 setLeftMargin( 0 );
148 verticalHeader()->hide(); 149 verticalHeader()->hide();
149 columnVisible = true; 150 columnVisible = true;
150} 151}
151 152
152void AbTable::setContacts( const Opie::OPimContactAccess::List& viewList ) 153void AbTable::setContacts( const Opie::OPimContactAccess::List& viewList )
153{ 154{
154 odebug << "AbTable::setContacts()" << oendl; 155 odebug << "AbTable::setContacts()" << oendl;
155 156
156 clear(); 157 clear();
157 m_viewList = viewList; 158 m_viewList = viewList;
158 159
159 setSorting( false );
160 setPaintingEnabled( FALSE ); 160 setPaintingEnabled( FALSE );
161 161
162 setNumRows( m_viewList.count() ); 162 setNumRows( m_viewList.count() );
163 //int row = 0;
164 // for ( it = m_viewList.begin(); it != m_viewList.end(); ++it )
165 // insertIntoTable( *it, row++ );
166
167 // setSorting( true );
168 163
169 // resort();
170 164
171 updateVisible(); 165 updateVisible();
172 166
173 setPaintingEnabled( TRUE ); 167 setPaintingEnabled( TRUE );
174 168
175} 169}
176 170
177void AbTable::setOrderedList( const QValueList<int> ordered ) 171void AbTable::setOrderedList( const QValueList<int> ordered )
178{ 172{
179 intFields = ordered; 173 intFields = ordered;
180} 174}
181 175
182 176
183bool AbTable::selectContact( int UID ) 177bool AbTable::selectContact( int UID )
184{ 178{
185 odebug << "AbTable::selectContact( " << UID << " )" << oendl; 179 odebug << "AbTable::selectContact( " << UID << " )" << oendl;
186 int rows = numRows(); 180 int rows = numRows();
187 bool found = false; 181 bool found = false;
188 182
189 setPaintingEnabled( FALSE ); 183 setPaintingEnabled( FALSE );
190 odebug << "Search start" << oendl; 184 odebug << "Search start" << oendl;
191 for ( int r = 0; r < rows; ++r ) { 185 for ( int r = 0; r < rows; ++r ) {
192 if ( m_viewList.uidAt( r ) == UID ){ 186 if ( m_viewList.uidAt( r ) == UID ){
193 ensureCellVisible( r, 0 ); 187 ensureCellVisible( r, 0 );
194 setCurrentCell( r, 0 ); 188 setCurrentCell( r, 0 );
195 found = true; 189 found = true;
196 break; 190 break;
197 } 191 }
198 } 192 }
199 odebug << "Search end" << oendl; 193 odebug << "Search end" << oendl;
200 194
201 if ( !found ){ 195 if ( !found ){
202 ensureCellVisible( 0,0 ); 196 ensureCellVisible( 0,0 );
203 setCurrentCell( 0, 0 ); 197 setCurrentCell( 0, 0 );
204 } 198 }
205 199
206 setPaintingEnabled( TRUE ); 200 setPaintingEnabled( TRUE );
207 201
208 return true; 202 return true;
209} 203}
210 204
211#if 0
212void AbTable::insertIntoTable( const Opie::OPimContact& cnt, int row )
213{
214 odebug << "void AbTable::insertIntoTable( const Opie::OPimContact& cnt, "
215 << row << " )" << oendl;
216 QString strName;
217 ContactItem contactItem;
218
219 strName = findContactName( cnt );
220 contactItem = findContactContact( cnt, row );
221
222 AbTableItem *ati;
223 ati = new AbTableItem( this, QTableItem::Never, strName, contactItem.value );
224 contactList.insert( ati, cnt );
225 setItem( row, 0, ati );
226 ati = new AbTableItem( this, QTableItem::Never, contactItem.value, strName);
227 if ( !contactItem.icon.isNull() )
228 ati->setPixmap( contactItem.icon );
229 setItem( row, 1, ati );
230
231 //### cannot do this; table only has two columns at this point
232 // setItem( row, 2, new AbPickItem( this ) );
233
234}
235#endif
236
237 205
238void AbTable::columnClicked( int col ) 206void AbTable::columnClicked( int col )
239{ 207{
240 if ( !sorting() ) 208 odebug << "columClicked(" << col << ")" << oendl;
241 return;
242
243 if ( lastSortCol == -1 )
244 lastSortCol = col;
245 209
246 if ( col == lastSortCol ) { 210 if ( col == 0 ){
211 odebug << "Change sort order: " << asc << oendl;
247 asc = !asc; 212 asc = !asc;
248 } else { 213 emit signalSortOrderChanged( asc );
249 lastSortCol = col;
250 asc = TRUE;
251 } 214 }
252 //QMessageBox::information( this, "resort", "columnClicked" );
253 resort();
254} 215}
255 216
256void AbTable::resort() 217void AbTable::resort()
257{ 218{
258 owarn << "void AbTable::resort() NOT POSSIBLE !!" << oendl; 219 owarn << "void AbTable::resort() NOT POSSIBLE !!" << oendl;
259#if 0 220
260 setPaintingEnabled( FALSE );
261 if ( sorting() ) {
262 if ( lastSortCol == -1 )
263 lastSortCol = 0;
264 sortColumn( lastSortCol, asc, TRUE );
265 //QMessageBox::information( this, "resort", "resort" );
266 updateVisible();
267 }
268 setPaintingEnabled( TRUE );
269#endif
270} 221}
271 222
272Opie::OPimContact AbTable::currentEntry() 223Opie::OPimContact AbTable::currentEntry()
273{ 224{
274 return m_viewList[currentRow()]; 225 return m_viewList[currentRow()];
275} 226}
276 227
277int AbTable::currentEntry_UID() 228int AbTable::currentEntry_UID()
278{ 229{
279 return ( currentEntry().uid() ); 230 return ( currentEntry().uid() );
280} 231}
281 232
282void AbTable::clear() 233void AbTable::clear()
283{ 234{
284 odebug << "void AbTable::clear()" << oendl; 235 odebug << "void AbTable::clear()" << oendl;
285 // contactList.clear(); 236 // contactList.clear();
286 237
287 setPaintingEnabled( FALSE ); 238 setPaintingEnabled( FALSE );
288 for ( int r = 0; r < numRows(); ++r ) { 239 for ( int r = 0; r < numRows(); ++r ) {
289 for ( int c = 0; c < numCols(); ++c ) { 240 for ( int c = 0; c < numCols(); ++c ) {
290 if ( cellWidget( r, c ) ) 241 if ( cellWidget( r, c ) )
291 clearCellWidget( r, c ); 242 clearCellWidget( r, c );
292 clearCell( r, c ); 243 clearCell( r, c );
293 } 244 }
294 } 245 }
295 setNumRows( 0 ); 246 setNumRows( 0 );
296 setPaintingEnabled( TRUE ); 247 setPaintingEnabled( TRUE );
297} 248}
298 249
299// Refresh updates column 2 if the contactsettings changed 250// Refresh updates column 2 if the contactsettings changed
300void AbTable::refresh() 251void AbTable::refresh()
301{ 252{
302 owarn << "void AbTable::refresh() NOT IMPLEMENTED !!" << oendl; 253 owarn << "void AbTable::refresh() NOT IMPLEMENTED !!" << oendl;
303 254
304#if 0 255#if 0
305 int rows = numRows(); 256 int rows = numRows();
306 AbTableItem *abi; 257 AbTableItem *abi;
307 ContactItem contactItem; 258 ContactItem contactItem;
308 259
309 setPaintingEnabled( FALSE ); 260 setPaintingEnabled( FALSE );
310 for ( int r = 0; r < rows; ++r ) { 261 for ( int r = 0; r < rows; ++r ) {
311 abi = static_cast<AbTableItem*>( item(r, 0) ); 262 abi = static_cast<AbTableItem*>( item(r, 0) );
312 contactItem = findContactContact( contactList[abi], r ); 263 contactItem = findContactContact( contactList[abi], r );
313 static_cast<AbTableItem*>( item(r, 1) )->setItem( contactItem.value, abi->text() ); 264 static_cast<AbTableItem*>( item(r, 1) )->setItem( contactItem.value, abi->text() );
314 if ( !contactItem.icon.isNull() ){ 265 if ( !contactItem.icon.isNull() ){
315 static_cast<AbTableItem*>( item(r, 1) )-> 266 static_cast<AbTableItem*>( item(r, 1) )->
316 setPixmap( contactItem.icon ); 267 setPixmap( contactItem.icon );
317 }else{ 268 }else{
318 static_cast<AbTableItem*>( item(r, 1) )-> 269 static_cast<AbTableItem*>( item(r, 1) )->
319 setPixmap( QPixmap() ); 270 setPixmap( QPixmap() );
320 } 271 }
321 } 272 }
322 resort(); 273 resort();
323 setPaintingEnabled( TRUE ); 274 setPaintingEnabled( TRUE );
324 275
325#endif 276#endif
326} 277}
327 278
328void AbTable::keyPressEvent( QKeyEvent *e ) 279void AbTable::keyPressEvent( QKeyEvent *e )
329{ 280{
330 char key = toupper( e->ascii() ); 281 char key = toupper( e->ascii() );
331 282
332 if ( key >= 'A' && key <= 'Z' ) 283 if ( key >= 'A' && key <= 'Z' )
333 moveTo( key ); 284 moveTo( key );
334 285
335 // odebug << "Received key .." << oendl; 286 // odebug << "Received key .." << oendl;
336 switch( e->key() ) { 287 switch( e->key() ) {
337 case Qt::Key_Space: 288 case Qt::Key_Space:
338 case Qt::Key_Return: 289 case Qt::Key_Return:
339 case Qt::Key_Enter: 290 case Qt::Key_Enter:
340 emit signalSwitch(); 291 emit signalSwitch();
341 break; 292 break;
342 // case Qt::Key_Up: 293 // case Qt::Key_Up:
343 // odebug << "a" << oendl; 294 // odebug << "a" << oendl;
344 // emit signalKeyUp(); 295 // emit signalKeyUp();
345 // break; 296 // break;
346 // case Qt::Key_Down: 297 // case Qt::Key_Down:
347 // odebug << "b" << oendl; 298 // odebug << "b" << oendl;
348 // emit signalKeyDown(); 299 // emit signalKeyDown();
349 // break; 300 // break;
350 default: 301 default:
351 QTable::keyPressEvent( e ); 302 QTable::keyPressEvent( e );
352 } 303 }
353 304
354} 305}
355 306
356void AbTable::moveTo( char /*c*/ ) 307void AbTable::moveTo( char /*c*/ )
357{ 308{
358 odebug << "void AbTable::moveTo( char c ) NOT IMPLEMENTED !!" << oendl; 309 odebug << "void AbTable::moveTo( char c ) NOT IMPLEMENTED !!" << oendl;
359 310
360#if 0
361 int rows = numRows();
362 QString value;
363 AbTableItem *abi;
364 int r;
365 if ( asc ) {
366 r = 0;
367 while ( r < rows-1) {
368 abi = static_cast<AbTableItem*>( item(r, 0) );
369 QChar first = abi->key()[0];
370 //### is there a bug in QChar to char comparison???
371 if ( first.row() || first.cell() >= c )
372 break;
373 r++;
374 }
375 } else {
376 //### should probably disable reverse sorting instead
377 r = rows - 1;
378 while ( r > 0 ) {
379 abi = static_cast<AbTableItem*>( item(r, 0) );
380 QChar first = abi->key()[0];
381 //### is there a bug in QChar to char comparison???
382 if ( first.row() || first.cell() >= c )
383 break;
384 r--;
385 }
386 }
387 setCurrentCell( r, currentColumn() );
388
389#endif
390} 311}
391 312
392#if 0 313#if 0
393// Useless.. Nobody uses it .. (se) 314// Useless.. Nobody uses it .. (se)
394QString AbTable::findContactName( const Opie::OPimContact &entry ) 315QString AbTable::findContactName( const Opie::OPimContact &entry )
395{ 316{
396 // We use the fileAs, then company, defaultEmail 317 // We use the fileAs, then company, defaultEmail
397 QString str; 318 QString str;
398 str = entry.fileAs(); 319 str = entry.fileAs();
399 if ( str.isEmpty() ) { 320 if ( str.isEmpty() ) {
400 str = entry.company(); 321 str = entry.company();
401 if ( str.isEmpty() ) { 322 if ( str.isEmpty() ) {
402 str = entry.defaultEmail(); 323 str = entry.defaultEmail();
403 } 324 }
404 } 325 }
405 return str; 326 return str;
406} 327}
407#endif 328#endif
408 329
409 330
410void AbTable::resizeRows() { 331void AbTable::resizeRows() {
411 /* 332 /*
412 if (numRows()) { 333 if (numRows()) {
413 for (int i = 0; i < numRows(); i++) { 334 for (int i = 0; i < numRows(); i++) {
414 setRowHeight( i, size ); 335 setRowHeight( i, size );
415 } 336 }
416 } 337 }
417 updateVisible(); 338 updateVisible();
418 */ 339 */
419} 340}
420 341
421 342
422void AbTable::realignTable() 343void AbTable::realignTable()
423{ 344{
424 //odebug << "void AbTable::realignTable()" << oendl; 345 //odebug << "void AbTable::realignTable()" << oendl;
425 346
426 setPaintingEnabled( FALSE ); 347 setPaintingEnabled( FALSE );
427 348
428 resizeRows(); 349 resizeRows();
429 fitColumns(); 350 fitColumns();
430 351
431 setPaintingEnabled( TRUE ); 352 setPaintingEnabled( TRUE );
432 353
433} 354}
434 355
435 356
436 357
437 358
diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h
index 927a5a9..7d2818b 100644
--- a/core/pim/addressbook/abtable.h
+++ b/core/pim/addressbook/abtable.h
@@ -75,85 +75,86 @@ private:
75 75
76#endif 76#endif
77 77
78class AbTable : public QTable 78class AbTable : public QTable
79{ 79{
80 Q_OBJECT 80 Q_OBJECT
81 81
82public: 82public:
83 AbTable( const QValueList<int> ordered, QWidget *parent, const char *name=0 ); 83 AbTable( const QValueList<int> ordered, QWidget *parent, const char *name=0 );
84 ~AbTable(); 84 ~AbTable();
85 85
86 // Set the contacts shown in the table 86 // Set the contacts shown in the table
87 void setContacts( const Opie::OPimContactAccess::List& viewList ); 87 void setContacts( const Opie::OPimContactAccess::List& viewList );
88 88
89 // Set the list for primary contacts 89 // Set the list for primary contacts
90 void setOrderedList( const QValueList<int> ordered ); 90 void setOrderedList( const QValueList<int> ordered );
91 91
92 // Selects a contact of a specific UID 92 // Selects a contact of a specific UID
93 bool selectContact( int UID ); 93 bool selectContact( int UID );
94 94
95 // Get the current selected entry 95 // Get the current selected entry
96 Opie::OPimContact currentEntry(); 96 Opie::OPimContact currentEntry();
97 97
98 // Get the UID of the current selected Entry 98 // Get the UID of the current selected Entry
99 int currentEntry_UID(); 99 int currentEntry_UID();
100 100
101 // QString findContactName( const Opie::OPimContact &entry ); 101 // QString findContactName( const Opie::OPimContact &entry );
102 102
103 void init(); 103 void init();
104 void clear(); 104 void clear();
105 void refresh(); 105 void refresh();
106 106
107 void show(); 107 void show();
108 void setPaintingEnabled( bool e ); 108 void setPaintingEnabled( bool e );
109 void viewportPaintEvent( QPaintEvent* e); 109 void viewportPaintEvent( QPaintEvent* e);
110 void paintCell(QPainter* p, int row, int col, const QRect&, bool ); 110 void paintCell(QPainter* p, int row, int col, const QRect&, bool );
111 111
112 // addresspicker mode (What's that ? se) 112 // addresspicker mode (What's that ? se)
113 // void setChoiceNames( const QStringList& list); 113 // void setChoiceNames( const QStringList& list);
114 // QStringList choiceNames() const; 114 // QStringList choiceNames() const;
115 void setChoiceSelection( const QValueList<int>& list ); 115 void setChoiceSelection( const QValueList<int>& list );
116 QStringList choiceSelection(int index) const; 116 QStringList choiceSelection(int index) const;
117 117
118signals: 118signals:
119 void signalSwitch(); 119 void signalSwitch();
120 void signalEditor(); 120 void signalEditor();
121 void signalKeyDown(); 121 void signalKeyDown();
122 void signalKeyUp(); 122 void signalKeyUp();
123 void signalSortOrderChanged( bool order );
123 124
124protected: 125protected:
125 virtual void keyPressEvent( QKeyEvent *e ); 126 virtual void keyPressEvent( QKeyEvent *e );
126 127
127// int rowHeight( int ) const; 128// int rowHeight( int ) const;
128// int rowPos( int row ) const; 129// int rowPos( int row ) const;
129// virtual int rowAt( int pos ) const; 130// virtual int rowAt( int pos ) const;
130 131
131 132
132protected slots: 133protected slots:
133 void moveTo( char ); 134 void moveTo( char );
134 virtual void columnClicked( int col ); 135 virtual void columnClicked( int col );
135 void itemClicked(int,int col); 136 void itemClicked(int,int col);
136 void rowHeightChanged( int row ); 137 void rowHeightChanged( int row );
137 138
138private: 139private:
139 // void insertIntoTable( const Opie::OPimContact &cnt, int row ); 140 // void insertIntoTable( const Opie::OPimContact &cnt, int row );
140 ContactItem findContactContact( const Opie::OPimContact &entry, int row ); 141 ContactItem findContactContact( const Opie::OPimContact &entry, int row );
141 void fitColumns(); 142 void fitColumns();
142 void resizeRows(); 143 void resizeRows();
143 void realignTable(); 144 void realignTable();
144 void resort(); 145 void resort();
145 void updateVisible(); 146 void updateVisible();
146 147
147 int lastSortCol; 148 int lastSortCol;
148 bool asc; 149 bool asc;
149 // QMap<AbTableItem*, Opie::OPimContact> contactList; 150 // QMap<AbTableItem*, Opie::OPimContact> contactList;
150 QValueList<int> intFields; 151 QValueList<int> intFields;
151 QStringList choicenames; 152 QStringList choicenames;
152 bool enablePainting; 153 bool enablePainting;
153 bool columnVisible; 154 bool columnVisible;
154 int countNested; 155 int countNested;
155 156
156 Opie::OPimContactAccess::List m_viewList; 157 Opie::OPimContactAccess::List m_viewList;
157 158
158}; 159};
159#endif // ABTABLE_H 160#endif // ABTABLE_H
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
@@ -1,220 +1,223 @@
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 <opie2/ocontactaccessbackend_vcard.h> 19#include <opie2/ocontactaccessbackend_vcard.h>
20#include <opie2/odebug.h> 20#include <opie2/odebug.h>
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}
107 110
108void AbView::addEntry( const Opie::OPimContact &newContact ) 111void AbView::addEntry( const Opie::OPimContact &newContact )
109{ 112{
110 odebug << "AbView::AddContact" << oendl; 113 odebug << "AbView::AddContact" << oendl;
111 m_contactdb->add ( newContact ); 114 m_contactdb->add ( newContact );
112 load(); 115 load();
113 116
114} 117}
115void AbView::removeEntry( const int UID ) 118void AbView::removeEntry( const int UID )
116{ 119{
117 odebug << "AbView;:RemoveContact" << oendl; 120 odebug << "AbView;:RemoveContact" << oendl;
118 m_contactdb->remove( UID ); 121 m_contactdb->remove( UID );
119 load(); 122 load();
120} 123}
121 124
122void AbView::replaceEntry( const Opie::OPimContact &contact ) 125void AbView::replaceEntry( const Opie::OPimContact &contact )
123{ 126{
124 odebug << "AbView::ReplaceContact" << oendl; 127 odebug << "AbView::ReplaceContact" << oendl;
125 m_contactdb->replace( contact ); 128 m_contactdb->replace( contact );
126 load(); 129 load();
127 130
128} 131}
129 132
130Opie::OPimContact AbView::currentEntry() 133Opie::OPimContact AbView::currentEntry()
131{ 134{
132 Opie::OPimContact currentContact; 135 Opie::OPimContact currentContact;
133 136
134 switch ( (int) m_curr_View ) { 137 switch ( (int) m_curr_View ) {
135 case TableView: 138 case TableView:
136 currentContact = m_abTable -> currentEntry(); 139 currentContact = m_abTable -> currentEntry();
137 break; 140 break;
138 case CardView: 141 case CardView:
139 currentContact = m_ablabel -> currentEntry(); 142 currentContact = m_ablabel -> 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{
197 odebug << "AbView::setShowCategory( const QString& cat )" << oendl; 200 odebug << "AbView::setShowCategory( const QString& cat )" << oendl;
198 201
199 int intCat = 0; 202 int intCat = 0;
200 203
201 // Unfiled will be stored as -1 204 // Unfiled will be stored as -1
202 if ( cat == tr( "Unfiled" ) ) 205 if ( cat == tr( "Unfiled" ) )
203 intCat = -1; 206 intCat = -1;
204 else if ( cat.isNull() ) 207 else if ( cat.isNull() )
205 intCat = 0; 208 intCat = 0;
206 else 209 else
207 intCat = mCat.id("Contacts", cat ); 210 intCat = mCat.id("Contacts", cat );
208 211
209 // Just do anything if we really change the category 212 // Just do anything if we really change the category
210 if ( intCat != m_curr_category ){ 213 if ( intCat != m_curr_category ){
211 // odebug << "Categories: Selected " << cat << ".. Number: " 214 // odebug << "Categories: Selected " << cat << ".. Number: "
212 // << m_curr_category << oendl; 215 // << m_curr_category << oendl;
213 216
214 m_curr_category = intCat; 217 m_curr_category = intCat;
215 emit signalClearLetterPicker(); 218 emit signalClearLetterPicker();
216 load(); 219 load();
217 } 220 }
218 m_curr_category = intCat; 221 m_curr_category = intCat;
219 222
220} 223}
@@ -371,96 +374,101 @@ void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp,
371 QRegExp r( str ); 374 QRegExp r( str );
372 r.setCaseSensitive( caseSensitive ); 375 r.setCaseSensitive( caseSensitive );
373 r.setWildcard( !useRegExp ); 376 r.setWildcard( !useRegExp );
374 377
375 // Get all matching entries out of the database 378 // Get all matching entries out of the database
376 m_list = m_contactdb->matchRegexp( r ); 379 m_list = m_contactdb->matchRegexp( r );
377 380
378 //odebug << "Found: " << m_list.count() << oendl; 381 //odebug << "Found: " << m_list.count() << oendl;
379 if ( m_list.count() == 0 ){ 382 if ( m_list.count() == 0 ){
380 emit signalNotFound(); 383 emit signalNotFound();
381 return; 384 return;
382 } 385 }
383 386
384 // Now remove all contacts with wrong category (if any selected) 387 // Now remove all contacts with wrong category (if any selected)
385 // This algorithm is a litte bit ineffective, but 388 // This algorithm is a litte bit ineffective, but
386 // we will not have a lot of matching entries.. 389 // we will not have a lot of matching entries..
387 if ( m_curr_category != 0 ) 390 if ( m_curr_category != 0 )
388 clearForCategory(); 391 clearForCategory();
389 392
390 // Now show all found entries 393 // Now show all found entries
391 updateView( true ); 394 updateView( true );
392} 395}
393 396
394void AbView::offSearch() 397void 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
443 bool returnMe; 451 bool returnMe;
444 QArray<int> cats; 452 QArray<int> cats;
445 cats = cnt.categories(); 453 cats = cnt.categories();
446 454
447 //odebug << "Number of categories: " << cats.count() << oendl; 455 //odebug << "Number of categories: " << cats.count() << oendl;
448 456
449 returnMe = false; 457 returnMe = false;
450 if ( cats.count() == 0 && category == -1 ) 458 if ( cats.count() == 0 && category == -1 )
451 // Contacts with no category will just shown on "All" and "Unfiled" 459 // Contacts with no category will just shown on "All" and "Unfiled"
452 returnMe = true; 460 returnMe = true;
453 else { 461 else {
454 int i; 462 int i;
455 for ( i = 0; i < int(cats.count()); i++ ) { 463 for ( i = 0; i < int(cats.count()); i++ ) {
456 //odebug << "Comparing " << cats[i] << " with " << category << oendl; 464 //odebug << "Comparing " << cats[i] << " with " << category << oendl;
457 if ( cats[i] == category ) { 465 if ( cats[i] == category ) {
458 returnMe = true; 466 returnMe = true;
459 break; 467 break;
460 } 468 }
461 } 469 }
462 } 470 }
463 //odebug << "Return: " << returnMe << oendl; 471 //odebug << "Return: " << returnMe << oendl;
464 return returnMe; 472 return returnMe;
465} 473}
466 474
diff --git a/core/pim/addressbook/abview.h b/core/pim/addressbook/abview.h
index b8c8a08..07b6b28 100644
--- a/core/pim/addressbook/abview.h
+++ b/core/pim/addressbook/abview.h
@@ -13,78 +13,80 @@
13#include "abtable.h" 13#include "abtable.h"
14#include "ablabel.h" 14#include "ablabel.h"
15#include "abconfig.h" 15#include "abconfig.h"
16 16
17class AbView: public QWidget 17class AbView: public QWidget
18{ 18{
19 Q_OBJECT 19 Q_OBJECT
20 20
21public: 21public:
22 enum Views{ TableView=0, CardView, PersonalView }; 22 enum Views{ TableView=0, CardView, PersonalView };
23 23
24 AbView( QWidget* parent, const QValueList<int>& ordered ); 24 AbView( QWidget* parent, const QValueList<int>& ordered );
25 ~AbView(); 25 ~AbView();
26 26
27 bool save(); 27 bool save();
28 void load(); 28 void load();
29 void reload(); 29 void reload();
30 void clear(); 30 void clear();
31 31
32 void setView( Views view ); 32 void setView( Views view );
33 void showPersonal( bool personal ); 33 void showPersonal( bool personal );
34 void setCurrentUid( int uid ); 34 void setCurrentUid( int uid );
35 void setShowByCategory( const QString& cat ); 35 void setShowByCategory( const QString& cat );
36 void setShowToView( Views view ); 36 void setShowToView( Views view );
37 void setShowByLetter( char c, AbConfig::LPSearchMode mode = AbConfig::LastName ); 37 void setShowByLetter( char c, AbConfig::LPSearchMode mode = AbConfig::LastName );
38 void setListOrder( const QValueList<int>& ordered ); 38 void setListOrder( const QValueList<int>& ordered );
39 39
40 // Add Entry and put to current 40 // Add Entry and put to current
41 void addEntry( const Opie::OPimContact &newContact ); 41 void addEntry( const Opie::OPimContact &newContact );
42 void removeEntry( const int UID ); 42 void removeEntry( const int UID );
43 void replaceEntry( const Opie::OPimContact &contact ); 43 void replaceEntry( const Opie::OPimContact &contact );
44 Opie::OPimContact currentEntry(); 44 Opie::OPimContact currentEntry();
45 45
46 void inSearch() { m_inSearch = true; } 46 void inSearch() { m_inSearch = true; }
47 void offSearch(); 47 void offSearch();
48 48
49 QString showCategory() const; 49 QString showCategory() const;
50 QStringList categories(); 50 QStringList categories();
51 51
52signals: 52signals:
53 void signalNotFound(); 53 void signalNotFound();
54 void signalClearLetterPicker(); 54 void signalClearLetterPicker();
55 void signalViewSwitched ( int ); 55 void signalViewSwitched ( int );
56 56
57public slots: 57public slots:
58 void slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, 58 void slotDoFind( const QString &str, bool caseSensitive, bool useRegExp,
59 bool backwards, QString category = QString::null ); 59 bool backwards, QString category = QString::null );
60 void slotSwitch(); 60 void slotSwitch();
61 void slotSetSortOrder( bool order );
61 62
62private: 63private:
63 void updateListinViews(); 64 void updateListinViews();
64 void updateView( bool newdata = false ); 65 void updateView( bool newdata = false );
65 void clearForCategory(); 66 void clearForCategory();
66 bool contactCompare( const Opie::OPimContact &cnt, int category ); 67 bool contactCompare( const Opie::OPimContact &cnt, int category );
67 void parseName( const QString& name, QString *first, QString *middle, 68 void parseName( const QString& name, QString *first, QString *middle,
68 QString * last ); 69 QString * last );
69 70
70 Categories mCat; 71 Categories mCat;
71 bool m_inSearch; 72 bool m_inSearch;
72 bool m_inPersonal; 73 bool m_inPersonal;
74 bool m_sortOrder;
73 int m_curr_category; 75 int m_curr_category;
74 Views m_curr_View; 76 Views m_curr_View;
75 Views m_prev_View; 77 Views m_prev_View;
76 int m_curr_Contact; 78 int m_curr_Contact;
77 79
78 Opie::OPimContactAccess* m_contactdb; 80 Opie::OPimContactAccess* m_contactdb;
79 Opie::OPimContactAccess* m_storedDB; 81 Opie::OPimContactAccess* m_storedDB;
80 Opie::OPimContactAccess::List m_list; 82 Opie::OPimContactAccess::List m_list;
81 83
82 QWidgetStack* m_viewStack; 84 QWidgetStack* m_viewStack;
83 AbTable* m_abTable; 85 AbTable* m_abTable;
84 AbLabel* m_ablabel; 86 AbLabel* m_ablabel;
85 87
86 QValueList<int> m_orderedFields; 88 QValueList<int> m_orderedFields;
87}; 89};
88 90
89 91
90#endif 92#endif
diff --git a/core/pim/addressbook/version.h b/core/pim/addressbook/version.h
index 7ce9752..8aafc85 100644
--- a/core/pim/addressbook/version.h
+++ b/core/pim/addressbook/version.h
@@ -1,10 +1,10 @@
1#ifndef _VERSION_H_ 1#ifndef _VERSION_H_
2#define _VERSION_H_ 2#define _VERSION_H_
3 3
4#define MAINVERSION "1" 4#define MAINVERSION "1"
5#define SUBVERSION "1" 5#define SUBVERSION "2"
6#define PATCHVERSION "1" 6#define PATCHVERSION "0"
7 7
8#define APPNAME "OPIE_ADDRESSBOOK" 8#define APPNAME "OPIE_ADDRESSBOOK"
9 9
10#endif 10#endif