summaryrefslogtreecommitdiff
path: root/core/pim
Unidiff
Diffstat (limited to 'core/pim') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/addressbook/abeditor.cpp5
-rw-r--r--core/pim/addressbook/abeditor.h8
-rw-r--r--core/pim/addressbook/ablabel.cpp2
-rw-r--r--core/pim/addressbook/ablabel.h6
-rw-r--r--core/pim/addressbook/abtable.cpp444
-rw-r--r--core/pim/addressbook/abtable.h36
-rw-r--r--core/pim/addressbook/addressbook.cpp191
-rw-r--r--core/pim/addressbook/addressbook.h9
-rw-r--r--core/pim/addressbook/contacteditor.cpp4
-rw-r--r--core/pim/addressbook/contacteditor.h10
10 files changed, 295 insertions, 420 deletions
diff --git a/core/pim/addressbook/abeditor.cpp b/core/pim/addressbook/abeditor.cpp
index 6354db9..91e8722 100644
--- a/core/pim/addressbook/abeditor.cpp
+++ b/core/pim/addressbook/abeditor.cpp
@@ -48,13 +48,13 @@ void parseEmailFrom( const QString &txt, QString &strDefaultEmail,
48// helper convert from file format to comma delimited... 48// helper convert from file format to comma delimited...
49void parseEmailTo( const QString &strDefaultEmail, 49void parseEmailTo( const QString &strDefaultEmail,
50 const QString &strOtherEmail, QString &strBack ); 50 const QString &strOtherEmail, QString &strBack );
51 51
52 52
53 53
54AbEditor::AbEditor( const Contact &entry, const QValueList<int> *newOrdered, 54AbEditor::AbEditor( const OContact &entry, const QValueList<int> *newOrdered,
55 QStringList *slNewOrdered, 55 QStringList *slNewOrdered,
56 QWidget *parent = 0, const char *name = 0, WFlags fl = 0 ) 56 QWidget *parent = 0, const char *name = 0, WFlags fl = 0 )
57 : QDialog( parent, name, TRUE, fl ), 57 : QDialog( parent, name, TRUE, fl ),
58 orderedValues( newOrdered ), 58 orderedValues( newOrdered ),
59 slOrdered( slNewOrdered ) 59 slOrdered( slNewOrdered )
60{ 60{
@@ -179,13 +179,13 @@ void AbEditor::loadFields()
179 QListIterator<QLabel> lit( listName ); 179 QListIterator<QLabel> lit( listName );
180 for ( it = slOrdered->begin(); *lit; ++lit, ++it ) { 180 for ( it = slOrdered->begin(); *lit; ++lit, ++it ) {
181 (*lit)->setText( *it ); 181 (*lit)->setText( *it );
182 } 182 }
183} 183}
184 184
185void AbEditor::setEntry( const Contact &entry ) 185void AbEditor::setEntry( const OContact &entry )
186{ 186{
187 ent = entry; 187 ent = entry;
188 QListIterator<QLineEdit> it( listValue ); 188 QListIterator<QLineEdit> it( listValue );
189 firstEdit->setText( ent.firstName() ); 189 firstEdit->setText( ent.firstName() );
190 lastEdit->setText( ent.lastName() ); 190 lastEdit->setText( ent.lastName() );
191 cmbCat->setCategories( ent.categories(), "Contacts", tr("Contacts") ); 191 cmbCat->setCategories( ent.categories(), "Contacts", tr("Contacts") );
@@ -546,12 +546,13 @@ void parseEmailFrom( const QString &txt, QString &strDefaultEmail,
546 QString &strAll ) 546 QString &strAll )
547{ 547{
548 int where, 548 int where,
549 start; 549 start;
550 if ( txt.isEmpty() ) 550 if ( txt.isEmpty() )
551 return; 551 return;
552
552 // find the first 553 // find the first
553 where = txt.find( ',' ); 554 where = txt.find( ',' );
554 if ( where < 0 ) { 555 if ( where < 0 ) {
555 strDefaultEmail = txt; 556 strDefaultEmail = txt;
556 strAll = txt; 557 strAll = txt;
557 } else { 558 } else {
diff --git a/core/pim/addressbook/abeditor.h b/core/pim/addressbook/abeditor.h
index 9ce6704..a9c1c5f 100644
--- a/core/pim/addressbook/abeditor.h
+++ b/core/pim/addressbook/abeditor.h
@@ -35,23 +35,23 @@ class QComboBox;
35class CategorySelect; 35class CategorySelect;
36 36
37class AbEditor : public QDialog 37class AbEditor : public QDialog
38{ 38{
39 Q_OBJECT 39 Q_OBJECT
40public: 40public:
41 AbEditor( const Contact &entry, const QValueList<int> *newOrdedValues, 41 AbEditor( const OContact &entry, const QValueList<int> *newOrdedValues,
42 QStringList *slNewOrdered, 42 QStringList *slNewOrdered,
43 QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 43 QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
44 ~AbEditor(); 44 ~AbEditor();
45 void loadFields(); 45 void loadFields();
46 void setNameFocus(); 46 void setNameFocus();
47 Contact entry() const { return ent; } 47 OContact entry() const { return ent; }
48 48
49public slots: 49public slots:
50 void slotNote(); 50 void slotNote();
51 void setEntry( const Contact &entry ); 51 void setEntry( const OContact &entry );
52 52
53protected slots: 53protected slots:
54 void accept(); 54 void accept();
55 55
56private: 56private:
57 void init(); 57 void init();
@@ -60,13 +60,13 @@ private:
60 bool isEmpty(); 60 bool isEmpty();
61 61
62private: 62private:
63 QDialog *dlgNote; 63 QDialog *dlgNote;
64 QLabel *lblNote; 64 QLabel *lblNote;
65 QMultiLineEdit *txtNote; 65 QMultiLineEdit *txtNote;
66 Contact ent; 66 OContact ent;
67 QScrollView *svPage; 67 QScrollView *svPage;
68 QLineEdit *firstEdit; 68 QLineEdit *firstEdit;
69 QLineEdit *lastEdit; 69 QLineEdit *lastEdit;
70 QLineEdit *middleEdit; 70 QLineEdit *middleEdit;
71 QComboBox *genderCombo; 71 QComboBox *genderCombo;
72 QList<QLineEdit> listValue; 72 QList<QLineEdit> listValue;
diff --git a/core/pim/addressbook/ablabel.cpp b/core/pim/addressbook/ablabel.cpp
index 3bf3e12..cf1e39f 100644
--- a/core/pim/addressbook/ablabel.cpp
+++ b/core/pim/addressbook/ablabel.cpp
@@ -31,13 +31,13 @@ AbLabel::AbLabel( QWidget *parent, const char *name )
31} 31}
32 32
33AbLabel::~AbLabel() 33AbLabel::~AbLabel()
34{ 34{
35} 35}
36 36
37void AbLabel::init( const Contact &entry ) 37void AbLabel::init( const OContact &entry )
38{ 38{
39 ent = entry; 39 ent = entry;
40} 40}
41 41
42void AbLabel::sync() 42void AbLabel::sync()
43{ 43{
diff --git a/core/pim/addressbook/ablabel.h b/core/pim/addressbook/ablabel.h
index cfbd999..9086c4a 100644
--- a/core/pim/addressbook/ablabel.h
+++ b/core/pim/addressbook/ablabel.h
@@ -17,34 +17,34 @@
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef ABLABEL_H 20#ifndef ABLABEL_H
21#define ABLABEL_H 21#define ABLABEL_H
22 22
23#include <qpe/contact.h> 23#include <opie/ocontact.h>
24#include <qtextview.h> 24#include <qtextview.h>
25 25
26class AbLabel : public QTextView 26class AbLabel : public QTextView
27{ 27{
28 Q_OBJECT 28 Q_OBJECT
29 29
30public: 30public:
31 AbLabel( QWidget *parent, const char *name = 0 ); 31 AbLabel( QWidget *parent, const char *name = 0 );
32 ~AbLabel(); 32 ~AbLabel();
33 33
34public slots: 34public slots:
35 void init( const Contact &entry ); 35 void init( const OContact &entry );
36 void sync(); 36 void sync();
37 37
38signals: 38signals:
39 void okPressed(); 39 void okPressed();
40 40
41protected: 41protected:
42 void keyPressEvent( QKeyEvent * ); 42 void keyPressEvent( QKeyEvent * );
43 43
44private: 44private:
45 Contact ent; 45 OContact ent;
46 46
47}; 47};
48 48
49#endif // ABLABEL_H 49#endif // ABLABEL_H
50 50
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp
index 3fa1a7c..08c6d0a 100644
--- a/core/pim/addressbook/abtable.cpp
+++ b/core/pim/addressbook/abtable.cpp
@@ -22,36 +22,30 @@
22 22
23#include <qpe/categoryselect.h> 23#include <qpe/categoryselect.h>
24#include <qpe/config.h> 24#include <qpe/config.h>
25#include <qpe/stringutil.h> 25#include <qpe/stringutil.h>
26#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
27 27
28#include <opie/orecordlist.h>
29
28#include <qasciidict.h> 30#include <qasciidict.h>
29#include <qdatetime.h> 31#include <qdatetime.h>
30#include <qfile.h> 32#include <qfile.h>
31#include <qregexp.h> 33#include <qregexp.h>
34#include <qmessagebox.h>
32 35
33#include "abtable.h" 36#include "abtable.h"
34 37
35#include <errno.h> 38#include <errno.h>
36#include <fcntl.h> 39#include <fcntl.h>
37#include <unistd.h> 40#include <unistd.h>
38#include <stdlib.h> 41#include <stdlib.h>
39 42
40#include <ctype.h> //toupper() for key hack 43#include <ctype.h> //toupper() for key hack
41 44
42static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ); 45static bool contactCompare( const OContact &cnt, const QRegExp &r, int category );
43
44//### qtmail/addresslist.cpp hardcodes this filename as well
45static QString journalFileName()
46{
47 QString str = getenv("HOME");
48 str +="/.abjournal";
49 return str;
50}
51
52 46
53 47
54/*! 48/*!
55 \class AbTableItem abtable.h 49 \class AbTableItem abtable.h
56 50
57 \brief QTableItem based class for showing a field of an entry 51 \brief QTableItem based class for showing a field of an entry
@@ -132,13 +126,14 @@ AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *nam
132 : QTable( parent, name ), 126 : QTable( parent, name ),
133// #endif 127// #endif
134 lastSortCol( -1 ), 128 lastSortCol( -1 ),
135 asc( TRUE ), 129 asc( TRUE ),
136 intFields( order ), 130 intFields( order ),
137 currFindRow( -2 ), 131 currFindRow( -2 ),
138 mCat( 0 ) 132 mCat( 0 ),
133 m_contactdb ("addressbook")
139{ 134{
140 mCat.load( categoryFileName() ); 135 mCat.load( categoryFileName() );
141 setSelectionMode( NoSelection ); 136 setSelectionMode( NoSelection );
142 init(); 137 init();
143 setSorting( TRUE ); 138 setSorting( TRUE );
144 connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), 139 connect( this, SIGNAL(clicked(int,int,int,const QPoint &)),
@@ -156,12 +151,13 @@ void AbTable::init()
156 setNumCols( 2 ); 151 setNumCols( 2 );
157 152
158 horizontalHeader()->setLabel( 0, tr( "Full Name" )); 153 horizontalHeader()->setLabel( 0, tr( "Full Name" ));
159 horizontalHeader()->setLabel( 1, tr( "Contact" )); 154 horizontalHeader()->setLabel( 1, tr( "Contact" ));
160 setLeftMargin( 0 ); 155 setLeftMargin( 0 );
161 verticalHeader()->hide(); 156 verticalHeader()->hide();
157 columnVisible = true;
162} 158}
163 159
164void AbTable::columnClicked( int col ) 160void AbTable::columnClicked( int col )
165{ 161{
166 if ( !sorting() ) 162 if ( !sorting() )
167 return; 163 return;
@@ -172,61 +168,60 @@ void AbTable::columnClicked( int col )
172 if ( col == lastSortCol ) { 168 if ( col == lastSortCol ) {
173 asc = !asc; 169 asc = !asc;
174 } else { 170 } else {
175 lastSortCol = col; 171 lastSortCol = col;
176 asc = TRUE; 172 asc = TRUE;
177 } 173 }
174 //QMessageBox::information( this, "resort", "columnClicked" );
178 resort(); 175 resort();
179} 176}
180 177
181void AbTable::resort() 178void AbTable::resort()
182{ 179{
183 if ( sorting() ) { 180 if ( sorting() ) {
184 if ( lastSortCol == -1 ) 181 if ( lastSortCol == -1 )
185 lastSortCol = 0; 182 lastSortCol = 0;
186 sortColumn( lastSortCol, asc, TRUE ); 183 sortColumn( lastSortCol, asc, TRUE );
184 //QMessageBox::information( this, "resort", "resort" );
187 updateVisible(); 185 updateVisible();
188 } 186 }
189} 187}
190 188
191Contact AbTable::currentEntry() 189OContact AbTable::currentEntry()
192{ 190{
193 Contact cnt; 191 OContact cnt;
194 AbTableItem *abItem; 192 AbTableItem *abItem;
195 abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); 193 abItem = static_cast<AbTableItem*>(item( currentRow(), 0 ));
196 if ( abItem ) { 194 if ( abItem ) {
197 cnt = contactList[abItem]; 195 cnt = contactList[abItem];
196 //cnt = contactList[currentRow()];
198 } 197 }
199 return cnt; 198 return cnt;
200} 199}
201 200
202void AbTable::replaceCurrentEntry( const Contact &newContact ) 201void AbTable::replaceCurrentEntry( const OContact &newContact )
203{ 202{
204 int row = currentRow(); 203 int row = currentRow();
205 updateJournal( newContact, Contact::ACTION_REPLACE, row );
206 updateVisible(); 204 updateVisible();
207 205
208 journalFreeReplace( newContact, row ); 206 journalFreeReplace( newContact, row );
207
209} 208}
210 209
211void AbTable::deleteCurrentEntry() 210void AbTable::deleteCurrentEntry()
212{ 211{
213 int row = currentRow(); 212 int row = currentRow();
214 AbTableItem *abItem;
215 abItem = static_cast<AbTableItem*>(item( row, 0 ));
216 Contact oldContact;
217 oldContact = contactList[abItem];
218 updateJournal( oldContact, Contact::ACTION_REMOVE, row );
219 213
220 // a little wasteful, but it ensure's there is only one place 214 // a little wasteful, but it ensure's there is only one place
221 // where we delete. 215 // where we delete.
222 journalFreeRemove( row ); 216 journalFreeRemove( row );
223 updateVisible(); 217 updateVisible();
224 218
225 if ( numRows() == 0 ) 219 if ( numRows() == 0 )
226 emit empty( TRUE ); 220 emit empty( TRUE );
221
227} 222}
228 223
229void AbTable::clear() 224void AbTable::clear()
230{ 225{
231 contactList.clear(); 226 contactList.clear();
232 for ( int r = 0; r < numRows(); ++r ) { 227 for ( int r = 0; r < numRows(); ++r ) {
@@ -241,15 +236,21 @@ void AbTable::clear()
241 236
242void AbTable::refresh() 237void AbTable::refresh()
243{ 238{
244 int rows = numRows(); 239 int rows = numRows();
245 QString value; 240 QString value;
246 AbTableItem *abi; 241 AbTableItem *abi;
242
243 // hide columns so no flashing ?
244 if ( showBk == "Cards" ) {
245 hideColumn(0);
246 hideColumn(1);
247 }
247 for ( int r = 0; r < rows; ++r ) { 248 for ( int r = 0; r < rows; ++r ) {
248 abi = static_cast<AbTableItem*>( item(r, 0) ); 249 abi = static_cast<AbTableItem*>( item(r, 0) );
249 value = findContactContact( contactList[abi] ); 250 value = findContactContact( contactList[abi], r );
250 static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); 251 static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() );
251 } 252 }
252 resort(); 253 resort();
253} 254}
254 255
255void AbTable::keyPressEvent( QKeyEvent *e ) 256void AbTable::keyPressEvent( QKeyEvent *e )
@@ -300,13 +301,13 @@ void AbTable::moveTo( char c )
300 } 301 }
301 } 302 }
302 setCurrentCell( r, currentColumn() ); 303 setCurrentCell( r, currentColumn() );
303} 304}
304 305
305 306
306QString AbTable::findContactName( const Contact &entry ) 307QString AbTable::findContactName( const OContact &entry )
307{ 308{
308 // We use the fileAs, then company, defaultEmail 309 // We use the fileAs, then company, defaultEmail
309 QString str; 310 QString str;
310 str = entry.fileAs(); 311 str = entry.fileAs();
311 if ( str.isEmpty() ) { 312 if ( str.isEmpty() ) {
312 str = entry.company(); 313 str = entry.company();
@@ -314,13 +315,13 @@ QString AbTable::findContactName( const Contact &entry )
314 str = entry.defaultEmail(); 315 str = entry.defaultEmail();
315 } 316 }
316 } 317 }
317 return str; 318 return str;
318} 319}
319 320
320QString AbTable::findContactContact( const Contact &entry ) 321QString AbTable::findContactContact( const OContact &entry, int /* row */ )
321{ 322{
322 QString value; 323 QString value;
323 value = ""; 324 value = "";
324 for ( QValueList<int>::ConstIterator it = intFields->begin(); 325 for ( QValueList<int>::ConstIterator it = intFields->begin();
325 it != intFields->end(); ++it ) { 326 it != intFields->end(); ++it ) {
326 switch ( *it ) { 327 switch ( *it ) {
@@ -440,311 +441,71 @@ QString AbTable::findContactContact( const Contact &entry )
440 if ( !value.isEmpty() ) 441 if ( !value.isEmpty() )
441 break; 442 break;
442 } 443 }
443 return value; 444 return value;
444} 445}
445 446
446void AbTable::addEntry( const Contact &newCnt ) 447void AbTable::addEntry( const OContact &newCnt )
447{ 448{
448 int row = numRows(); 449 int row = numRows();
450
449 setNumRows( row + 1 ); 451 setNumRows( row + 1 );
450 updateJournal( newCnt, Contact::ACTION_ADD );
451 insertIntoTable( newCnt, row ); 452 insertIntoTable( newCnt, row );
453
454 qWarning("abtable:AddContact");
455 m_contactdb.add ( newCnt );
456
452 setCurrentCell( row, 0 ); 457 setCurrentCell( row, 0 );
453 updateVisible(); 458 // updateVisible();
454} 459}
455 460
456void AbTable::resizeRows( int size ) { 461void AbTable::resizeRows() {
457/* 462/*
458 if (numRows()) { 463 if (numRows()) {
459 for (int i = 0; i < numRows(); i++) { 464 for (int i = 0; i < numRows(); i++) {
460 setRowHeight( i, size ); 465 setRowHeight( i, size );
461 } 466 }
462 }*/ 467 }
463 updateVisible(); 468 updateVisible();
469 */
464} 470}
465 471
466void AbTable::updateJournal( const Contact &cnt, 472
467 Contact::journal_action action, int row ) 473bool AbTable::save( const QString& /* fn */ )
468{
469 QFile f( journalFileName() );
470 if ( !f.open(IO_WriteOnly|IO_Append) )
471 return;
472 QString buf;
473 QCString str;
474 buf = "<Contact ";
475 cnt.save( buf );
476 buf += " action=\"" + QString::number( (int)action ) + "\" ";
477 if ( action == Contact::ACTION_REMOVE || action == Contact::ACTION_REPLACE)
478 buf += " actionrow=\"" + QString::number(row) + "\" ";
479 buf += "/>\n";
480 QCString cstr = buf.utf8();
481 f.writeBlock( cstr.data(), cstr.length() );
482 QCopEnvelope( "QPE/PIM", "addressbookUpdated()" );
483}
484
485bool AbTable::save( const QString &fn )
486{ 474{
487// QTime t; 475// QTime t;
488// t.start(); 476// t.start();
477 qWarning("abtable:Save data");
478 m_contactdb.save();
489 479
490 QString strNewFile = fn + ".new";
491 QFile f( strNewFile );
492 if ( !f.open( IO_WriteOnly|IO_Raw ) )
493 return false;
494
495 int total_written;
496 QString out;
497 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
498 " <Groups>\n"
499 " </Groups>\n"
500 " <Contacts>\n";
501 QMapIterator<AbTableItem*, Contact> it;
502 for ( it = contactList.begin(); it != contactList.end(); ++it ) {
503 out += "<Contact ";
504 it.data().save( out );
505 out += "/>\n";
506 QCString cstr = out.utf8();
507 total_written = f.writeBlock( cstr.data(), cstr.length() );
508 if ( total_written != int(cstr.length()) ) {
509 f.close();
510 QFile::remove( strNewFile );
511 return false;
512 }
513 out = "";
514 }
515 out += " </Contacts>\n</AddressBook>\n";
516
517 QCString cstr = out.utf8();
518 total_written = f.writeBlock( cstr.data(), cstr.length() );
519 if ( total_written != int(cstr.length()) ) {
520 f.close();
521 QFile::remove( strNewFile );
522 return false;
523 }
524 f.close();
525
526// qDebug("saving: %d", t.elapsed() );
527
528 // move the file over, I'm just going to use the system call
529 // because, I don't feel like using QDir.
530 if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) {
531 qWarning( "problem renaming file %s to %s, errno: %d",
532 strNewFile.latin1(), fn.latin1(), errno );
533 // remove the tmp file...
534 QFile::remove( strNewFile );
535 }
536 // remove the journal...
537 QFile::remove( journalFileName() );
538 return true; 480 return true;
539} 481}
540 482
541void AbTable::load( const QString &fn ) 483void AbTable::load( const QString& /* fn */ )
542{ 484{
543 setSorting( false ); 485 setSorting( false );
544 loadFile( fn, false ); 486 setUpdatesEnabled( FALSE );
545 // merge in the journal
546 if ( QFile::exists( journalFileName() ) ) {
547 loadFile( journalFileName(), true );
548 save( fn );
549 }
550 setSorting( true );
551 resort();
552}
553 487
554void AbTable::loadFile( const QString &strFile, bool journalFile ) 488 qWarning("abtable:Load data");
555{
556// QTime t;
557// t.start();
558 QFile f( strFile );
559 if ( !f.open(IO_ReadOnly) )
560 return;
561 QList<Contact> list;
562 list.setAutoDelete( TRUE );
563 QByteArray ba = f.readAll();
564 f.close();
565 if (ba.isEmpty() )
566 return;
567 char *uc = ba.data();//(QChar *)data.unicode();
568 int len = ba.size();//data.length();
569 bool foundAction = false;
570 Contact::journal_action action;
571 bool foundKey = false;
572 int journalKey = 0;
573
574 const int JOURNALACTION = Qtopia::Notes + 1;
575 const int JOURNALROW = JOURNALACTION + 1;
576
577 // **********************************
578 // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!!
579 // **********************************
580 QAsciiDict<int> dict( 47 );
581 dict.setAutoDelete( TRUE );
582 dict.insert( "Uid", new int(Qtopia::AddressUid) );
583 dict.insert( "Title", new int(Qtopia::Title) );
584 dict.insert( "FirstName", new int(Qtopia::FirstName) );
585 dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
586 dict.insert( "LastName", new int(Qtopia::LastName) );
587 dict.insert( "Suffix", new int(Qtopia::Suffix) );
588 dict.insert( "FileAs", new int(Qtopia::FileAs) );
589 dict.insert( "Categories", new int(Qtopia::AddressCategory) );
590 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
591 dict.insert( "Emails", new int(Qtopia::Emails) );
592 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
593 dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
594 dict.insert( "HomeState", new int(Qtopia::HomeState) );
595 dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
596 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
597 dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
598 dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
599 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
600 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );
601 dict.insert( "Company", new int(Qtopia::Company) );
602 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) );
603 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) );
604 dict.insert( "BusinessState", new int(Qtopia::BusinessState) );
605 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) );
606 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) );
607 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) );
608 dict.insert( "JobTitle", new int(Qtopia::JobTitle) );
609 dict.insert( "Department", new int(Qtopia::Department) );
610 dict.insert( "Office", new int(Qtopia::Office) );
611 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) );
612 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) );
613 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) );
614 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) );
615 dict.insert( "Profession", new int(Qtopia::Profession) );
616 dict.insert( "Assistant", new int(Qtopia::Assistant) );
617 dict.insert( "Manager", new int(Qtopia::Manager) );
618 dict.insert( "Spouse", new int(Qtopia::Spouse) );
619 dict.insert( "Children", new int(Qtopia::Children) );
620 dict.insert( "Gender", new int(Qtopia::Gender) );
621 dict.insert( "Birthday", new int(Qtopia::Birthday) );
622 dict.insert( "Anniversary", new int(Qtopia::Anniversary) );
623 dict.insert( "Nickname", new int(Qtopia::Nickname) );
624 dict.insert( "Notes", new int(Qtopia::Notes) );
625 dict.insert( "action", new int(JOURNALACTION) );
626 dict.insert( "actionrow", new int(JOURNALROW) );
627
628 int i = 0;
629 int num = 0;
630 char *point;
631 while ( (point = strstr( uc+i, "<Contact " ) ) != NULL ) {
632 i = point - uc;
633 // if we are reading the standard file, we just need to
634 // insert info, so just say we'll do an insert...
635 action = Contact::ACTION_ADD;
636 // new Contact
637 Contact *cnt = new Contact;
638 i += 9;
639 while ( 1 ) {
640 while ( i < len && (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') )
641 i++;
642 if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') )
643 break;
644 // we have another attribute read it.
645 int j = i;
646 while ( j < len && uc[j] != '=' )
647 j++;
648 char *attr = uc+i;
649 uc[j] = '\0';
650 //qDebug("attr=%s", attr.latin1() );
651 i = ++j; // skip =
652 while ( i < len && uc[i] != '"' )
653 i++;
654 j = ++i;
655 bool haveEnt = FALSE;
656 bool haveUtf = FALSE;
657 while ( j < len && uc[j] != '"' ) {
658 if ( uc[j] == '&' )
659 haveEnt = TRUE;
660 if ( ((unsigned char)uc[j]) > 0x7f )
661 haveUtf = TRUE;
662 j++;
663 }
664
665 if ( j == i ) {
666 // empty value
667 i = j + 1;
668 continue;
669 }
670
671 QString value = haveUtf ? QString::fromUtf8( uc+i, j-i )
672 : QString::fromLatin1( uc+i, j-i );
673 if ( haveEnt )
674 value = Qtopia::plainString( value );
675 i = j + 1;
676
677 int *find = dict[ attr ];
678 if ( !find ) {
679 cnt->setCustomField(attr, value);
680 continue;
681 }
682#if 1
683 switch( *find ) {
684 case Qtopia::AddressUid:
685 cnt->setUid( value.toInt() );
686 break;
687 case Qtopia::AddressCategory:
688 cnt->setCategories( Qtopia::Record::idsFromString( value ));
689 break;
690 case JOURNALACTION:
691 action = Contact::journal_action(value.toInt());
692 break;
693 case JOURNALROW:
694 journalKey = value.toInt();
695 break;
696 489
697 default: 490 OContactAccess::List list = m_contactdb.allRecords();
698 cnt->insert( *find, value ); 491 OContactAccess::List::Iterator it;
699 break; 492 setNumRows( list.count() );
700 } 493 int row = 0;
701#endif 494 for ( it = list.begin(); it != list.end(); ++it )
702 } 495 insertIntoTable( *it, row++ );
703 496
704 // sadly we can't delay adding of items from the journal to get 497 resort();
705 // the proper effect, but then, the journal should _never_ be 498
706 // that huge, and recovering from a crash is not necessarily 499 setUpdatesEnabled( TRUE );
707 // a *fast* thing.
708 switch ( action ) {
709 case Contact::ACTION_ADD:
710 if ( journalFile ) {
711 int myrows = numRows();
712 setNumRows( myrows + 1 );
713 insertIntoTable( *cnt, myrows );
714 delete cnt;
715 }
716 else
717 list.append( cnt );
718 break;
719 case Contact::ACTION_REMOVE:
720 // yup, we don't use the entry to remove the object...
721 journalFreeRemove( journalKey );
722 delete cnt;
723 break;
724 case Contact::ACTION_REPLACE:
725 journalFreeReplace( *cnt, journalKey );
726 delete cnt;
727 break;
728 default:
729 break;
730 }
731 num++;
732 foundAction = false;
733 foundKey = false;
734 // if ( num % 100 == 0 ) {
735 // qDebug("loading file, num=%d, t=%d", num, t.elapsed() );
736 // }
737 }
738 if ( list.count() > 0 ) {
739 internalAddEntries( list );
740 }
741// qDebug("done loading %d, t=%d", num, t.elapsed() );
742 500
501 setSorting( true );
502 //resort();
743} 503}
744 504
505
745void AbTable::realignTable( int row ) 506void AbTable::realignTable( int row )
746{ 507{
747 QTableItem *ti1, 508 QTableItem *ti1,
748 *ti2; 509 *ti2;
749 int totalRows = numRows(); 510 int totalRows = numRows();
750 for ( int curr = row; curr < totalRows - 1; curr++ ) { 511 for ( int curr = row; curr < totalRows - 1; curr++ ) {
@@ -758,19 +519,20 @@ void AbTable::realignTable( int row )
758 setItem( curr, 1, ti2 ); 519 setItem( curr, 1, ti2 );
759 } 520 }
760 setNumRows( totalRows - 1 ); 521 setNumRows( totalRows - 1 );
761 resort(); 522 resort();
762} 523}
763 524
764void AbTable::insertIntoTable( const Contact &cnt, int row ) 525// Add contact into table.
526void AbTable::insertIntoTable( const OContact &cnt, int row )
765{ 527{
766 QString strName, 528 QString strName,
767 strContact; 529 strContact;
768 530
769 strName = findContactName( cnt ); 531 strName = findContactName( cnt );
770 strContact = findContactContact( cnt ); 532 strContact = findContactContact( cnt, row );
771 533
772 AbTableItem *ati; 534 AbTableItem *ati;
773 ati = new AbTableItem( this, QTableItem::Never, strName, strContact); 535 ati = new AbTableItem( this, QTableItem::Never, strName, strContact);
774 contactList.insert( ati, cnt ); 536 contactList.insert( ati, cnt );
775 setItem( row, 0, ati ); 537 setItem( row, 0, ati );
776 ati = new AbTableItem( this, QTableItem::Never, strContact, strName); 538 ati = new AbTableItem( this, QTableItem::Never, strContact, strName);
@@ -779,57 +541,65 @@ void AbTable::insertIntoTable( const Contact &cnt, int row )
779 //### cannot do this; table only has two columns at this point 541 //### cannot do this; table only has two columns at this point
780 // setItem( row, 2, new AbPickItem( this ) ); 542 // setItem( row, 2, new AbPickItem( this ) );
781 543
782 // resort at some point? 544 // resort at some point?
783} 545}
784 546
785void AbTable::internalAddEntries( QList<Contact> &list )
786{
787 setUpdatesEnabled( FALSE );
788 setNumRows( list.count() );
789 int row = 0;
790 Contact *it;
791 for ( it = list.first(); it; it = list.next() )
792 insertIntoTable( *it, row++ );
793 resort();
794 setUpdatesEnabled( TRUE );
795}
796
797 547
798void AbTable::journalFreeReplace( const Contact &cnt, int row ) 548// Replace or add an entry
549void AbTable::journalFreeReplace( const OContact &cnt, int row )
799{ 550{
800 QString strName, 551 QString strName,
801 strContact; 552 strContact;
802 AbTableItem *ati = 0l; 553 AbTableItem *ati = 0l;
803 554
804 strName = findContactName( cnt ); 555 strName = findContactName( cnt );
805 strContact = findContactContact( cnt ); 556 strContact = findContactContact( cnt, row );
806 ati = static_cast<AbTableItem*>(item(row, 0)); 557 ati = static_cast<AbTableItem*>(item(row, 0));
807 if ( ati != 0 ) { 558
559 // Replace element if found in row "row"
560 // or add this element if not.
561 if ( ati != 0 ) { // replace
562 // :SX db access -> replace
563 qWarning ("Replace Contact in DB ! UID: %d", contactList[ati].uid() );
564 m_contactdb.replace ( cnt );
565
808 contactList.remove( ati ); 566 contactList.remove( ati );
809 ati->setItem( strName, strContact ); 567 ati->setItem( strName, strContact );
810 contactList.insert( ati, cnt ); 568 contactList.insert( ati, cnt );
811 569
812 ati = static_cast<AbTableItem*>(item(row, 1)); 570 ati = static_cast<AbTableItem*>(item(row, 1));
813 ati->setItem( strContact, strName ); 571 ati->setItem( strContact, strName );
814 }else{ 572
573 }else{ // add
815 int myrows = numRows(); 574 int myrows = numRows();
816 setNumRows( myrows + 1 ); 575 setNumRows( myrows + 1 );
817 insertIntoTable( cnt, myrows ); 576 insertIntoTable( cnt, myrows );
818 // gets deleted when returning 577 // gets deleted when returning -- Why ? (se)
578 // :SX db access -> add
579 qWarning ("Are you sure to add to database ? -> Currently disabled !!");
580 // m_contactdb.add( cnt );
819 } 581 }
820} 582}
821 583
584// Remove entry
822void AbTable::journalFreeRemove( int row ) 585void AbTable::journalFreeRemove( int row )
823{ 586{
824 AbTableItem *ati; 587 AbTableItem *ati;
825 ati = static_cast<AbTableItem*>(item(row, 0)); 588 ati = static_cast<AbTableItem*>(item(row, 0));
826 if ( !ati ) 589 if ( !ati )
827 return; 590 return;
591
592 // :SX db access -> remove
593 qWarning ("Remove Contact from DB ! UID: %d",contactList[ati].uid() );
594 m_contactdb.remove( contactList[ati].uid() );
595
828 contactList.remove( ati ); 596 contactList.remove( ati );
597
829 realignTable( row ); 598 realignTable( row );
599
830} 600}
831 601
832#if QT_VERSION <= 230 602#if QT_VERSION <= 230
833#ifndef SINGLE_APP 603#ifndef SINGLE_APP
834void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) 604void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch )
835{ 605{
@@ -864,31 +634,31 @@ void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch )
864void AbTable::slotDoFind( const QString &findString, bool caseSensitive, 634void AbTable::slotDoFind( const QString &findString, bool caseSensitive,
865 bool backwards, int category ) 635 bool backwards, int category )
866{ 636{
867 if ( currFindRow < -1 ) 637 if ( currFindRow < -1 )
868 currFindRow = currentRow() - 1; 638 currFindRow = currentRow() - 1;
869 clearSelection( TRUE ); 639 clearSelection( TRUE );
870 int rows, 640 int rows, row;
871 row;
872 AbTableItem *ati; 641 AbTableItem *ati;
873 QRegExp r( findString ); 642 QRegExp r( findString );
874 r.setCaseSensitive( caseSensitive ); 643 r.setCaseSensitive( caseSensitive );
875 rows = numRows(); 644 rows = numRows();
876 static bool wrapAround = true; 645 static bool wrapAround = true;
877 646
878 if ( !backwards ) { 647 if ( !backwards ) {
879 for ( row = currFindRow + 1; row < rows; row++ ) { 648 for ( row = currFindRow + 1; row < rows; row++ ) {
880 ati = static_cast<AbTableItem*>( item(row, 0) ); 649 ati = static_cast<AbTableItem*>( item(row, 0) );
881 if ( contactCompare( contactList[ati], r, category ) ) 650 if ( contactCompare( contactList[ati], r, category ) )
651 //if ( contactCompare( contactList[row], r, category ) )
882 break; 652 break;
883
884 } 653 }
885 } else { 654 } else {
886 for ( row = currFindRow - 1; row > -1; row-- ) { 655 for ( row = currFindRow - 1; row > -1; row-- ) {
887 ati = static_cast<AbTableItem*>( item(row, 0) ); 656 ati = static_cast<AbTableItem*>( item(row, 0) );
888 if ( contactCompare( contactList[ati], r, category ) ) 657 if ( contactCompare( contactList[ati], r, category ) )
658 //if ( contactCompare( contactList[row], r, category ) )
889 break; 659 break;
890 } 660 }
891 } 661 }
892 if ( row >= rows || row < 0 ) { 662 if ( row >= rows || row < 0 ) {
893 if ( row < 0 ) 663 if ( row < 0 )
894 currFindRow = rows; 664 currFindRow = rows;
@@ -909,13 +679,13 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive,
909 addSelection( foundSelection ); 679 addSelection( foundSelection );
910 setCurrentCell( currFindRow, numCols() - 1 ); 680 setCurrentCell( currFindRow, numCols() - 1 );
911 wrapAround = true; 681 wrapAround = true;
912 } 682 }
913} 683}
914 684
915static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) 685static bool contactCompare( const OContact &cnt, const QRegExp &r, int category )
916{ 686{
917 bool returnMe; 687 bool returnMe;
918 QArray<int> cats; 688 QArray<int> cats;
919 cats = cnt.categories(); 689 cats = cnt.categories();
920 690
921 returnMe = false; 691 returnMe = false;
@@ -927,22 +697,35 @@ static bool contactCompare( const Contact &cnt, const QRegExp &r, int category )
927 if ( cats[i] == category ) { 697 if ( cats[i] == category ) {
928 returnMe = cnt.match( r ); 698 returnMe = cnt.match( r );
929 break; 699 break;
930 } 700 }
931 } 701 }
932 } 702 }
703
933 return returnMe; 704 return returnMe;
934} 705}
935 706
936void AbTable::fitColumns() 707void AbTable::fitColumns()
937{ 708{
938 int contentsWidth = visibleWidth(); 709 int contentsWidth = visibleWidth() / 2;
939 int n = numCols(); 710
940 int pw = n == 3 ? columnWidth(2) : 0; 711 if ( showBk == "Cards" ) {
941 setColumnWidth( 0, contentsWidth - contentsWidth / 2 ); 712 showColumn(1);
942 setColumnWidth( 1, contentsWidth / 2 - pw ); 713 //adjustColumn(1);
714 setColumnWidth( 1, visibleWidth() );
715 columnVisible = false;
716 } else {
717 if ( columnVisible == false ){
718 showColumn(0);
719 columnVisible = true;
720 }
721 setColumnWidth( 0, contentsWidth );
722 adjustColumn(1);
723 if ( columnWidth(1) < contentsWidth )
724 setColumnWidth( 1, contentsWidth );
725 }
943} 726}
944 727
945void AbTable::show() 728void AbTable::show()
946{ 729{
947 fitColumns(); 730 fitColumns();
948 QTable::show(); 731 QTable::show();
@@ -980,20 +763,20 @@ QStringList AbTable::choiceNames() const
980void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) 763void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/)
981{ 764{
982 /* ###### 765 /* ######
983 766
984 QString selname = choicenames.at(index); 767 QString selname = choicenames.at(index);
985 for (each row) { 768 for (each row) {
986 Contact *c = contactForRow(row); 769 OContact *c = contactForRow(row);
987 if ( list.contains(c->email) ) { 770 if ( list.contains(c->email) ) {
988 list.remove(c->email); 771 list.remove(c->email);
989 setText(row, 2, selname); 772 setText(row, 2, selname);
990 } 773 }
991 } 774 }
992 for (remaining list items) { 775 for (remaining list items) {
993 Contact *c = new contact(item); 776 OContact *c = new contact(item);
994 setText(newrow, 2, selname); 777 setText(newrow, 2, selname);
995 } 778 }
996 779
997 */ 780 */
998} 781}
999 782
@@ -1001,26 +784,31 @@ QStringList AbTable::choiceSelection(int /*index*/) const
1001{ 784{
1002 QStringList r; 785 QStringList r;
1003 /* ###### 786 /* ######
1004 787
1005 QString selname = choicenames.at(index); 788 QString selname = choicenames.at(index);
1006 for (each row) { 789 for (each row) {
1007 Contact *c = contactForRow(row); 790 OContact *c = contactForRow(row);
1008 if ( text(row,2) == selname ) { 791 if ( text(row,2) == selname ) {
1009 r.append(c->email); 792 r.append(c->email);
1010 } 793 }
1011 } 794 }
1012 795
1013 */ 796 */
1014 return r; 797 return r;
1015} 798}
1016 799
1017void AbTable::setShowCategory( const QString &c ) 800void AbTable::setShowCategory( const QString &b, const QString &c )
1018{ 801{
802 showBk = b;
1019 showCat = c; 803 showCat = c;
1020 updateVisible(); 804 //QMessageBox::information( this, "setShowCategory", "setShowCategory" );
805 //updateVisible();
806 refresh();
807 ensureCellVisible( currentRow(), 0 );
808 updateVisible(); // :SX
1021} 809}
1022 810
1023void AbTable::setShowByLetter( char c ) 811void AbTable::setShowByLetter( char c )
1024{ 812{
1025 showChar = tolower(c); 813 showChar = tolower(c);
1026 updateVisible(); 814 updateVisible();
@@ -1028,12 +816,16 @@ void AbTable::setShowByLetter( char c )
1028 816
1029QString AbTable::showCategory() const 817QString AbTable::showCategory() const
1030{ 818{
1031 return showCat; 819 return showCat;
1032} 820}
1033 821
822QString AbTable::showBook() const
823{
824 return showBk;
825}
1034 826
1035QStringList AbTable::categories() 827QStringList AbTable::categories()
1036{ 828{
1037 mCat.load( categoryFileName() ); 829 mCat.load( categoryFileName() );
1038 QStringList categoryList = mCat.labels( "Contacts" ); 830 QStringList categoryList = mCat.labels( "Contacts" );
1039 return categoryList; 831 return categoryList;
@@ -1046,13 +838,13 @@ void AbTable::updateVisible()
1046 id, 838 id,
1047 totalCats, 839 totalCats,
1048 it, 840 it,
1049 row; 841 row;
1050 bool hide; 842 bool hide;
1051 AbTableItem *ati; 843 AbTableItem *ati;
1052 Contact *cnt; 844 OContact *cnt;
1053 QString fileAsName; 845 QString fileAsName;
1054 QString tmpStr; 846 QString tmpStr;
1055 visible = 0; 847 visible = 0;
1056 848
1057 setPaintingEnabled( FALSE ); 849 setPaintingEnabled( FALSE );
1058 850
diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h
index d5ff279..84aef1e 100644
--- a/core/pim/addressbook/abtable.h
+++ b/core/pim/addressbook/abtable.h
@@ -19,19 +19,21 @@
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef ABTABLE_H 21#ifndef ABTABLE_H
22#define ABTABLE_H 22#define ABTABLE_H
23 23
24#include <qpe/categories.h> 24#include <qpe/categories.h>
25#include <qpe/contact.h> 25#include <opie/ocontact.h>
26 26
27#include <qmap.h> 27#include <qmap.h>
28#include <qtable.h> 28#include <qtable.h>
29#include <qstringlist.h> 29#include <qstringlist.h>
30#include <qcombobox.h> 30#include <qcombobox.h>
31 31
32#include <opie/ocontactaccess.h>
33
32class AbTableItem : public QTableItem 34class AbTableItem : public QTableItem
33{ 35{
34public: 36public:
35 AbTableItem( QTable *t, EditType et, const QString &s, 37 AbTableItem( QTable *t, EditType et, const QString &s,
36 const QString &secondSortKey); 38 const QString &secondSortKey);
37 QString entryKey() const; 39 QString entryKey() const;
@@ -61,15 +63,15 @@ class AbTable : public QTable
61 Q_OBJECT 63 Q_OBJECT
62 64
63public: 65public:
64 AbTable( const QValueList<int> *ordered, QWidget *parent, const char *name=0 ); 66 AbTable( const QValueList<int> *ordered, QWidget *parent, const char *name=0 );
65 ~AbTable(); 67 ~AbTable();
66 // NEW 68 // NEW
67 void addEntry( const Contact &newContact ); 69 void addEntry( const OContact &newContact );
68 Contact currentEntry(); 70 OContact currentEntry();
69 void replaceCurrentEntry( const Contact &newContact ); 71 void replaceCurrentEntry( const OContact &newContact );
70 72
71 void init(); 73 void init();
72 74
73 void deleteCurrentEntry(); 75 void deleteCurrentEntry();
74 void clear(); 76 void clear();
75 void clearFindRow() { currFindRow = -2; } 77 void clearFindRow() { currFindRow = -2; }
@@ -80,21 +82,24 @@ public:
80 82
81 // addresspicker mode 83 // addresspicker mode
82 void setChoiceNames( const QStringList& list); 84 void setChoiceNames( const QStringList& list);
83 QStringList choiceNames() const; 85 QStringList choiceNames() const;
84 void setChoiceSelection(int index, const QStringList& list); 86 void setChoiceSelection(int index, const QStringList& list);
85 QStringList choiceSelection(int index) const; 87 QStringList choiceSelection(int index) const;
86 void setShowCategory( const QString &c ); 88 void setShowCategory( const QString &b, const QString &c );
87 void setShowByLetter( char c ); 89 void setShowByLetter( char c );
88 QString showCategory() const; 90 QString showCategory() const;
89 QStringList categories(); 91 QStringList categories();
90 void resizeRows( int size ); 92
93 void resizeRows();
91 94
92 void show(); 95 void show();
93 void setPaintingEnabled( bool e ); 96 void setPaintingEnabled( bool e );
94 97
98 QString showBook() const;
99
95public slots: 100public slots:
96 void slotDoFind( const QString &str, bool caseSensitive, bool backwards, 101 void slotDoFind( const QString &str, bool caseSensitive, bool backwards,
97 int category ); 102 int category );
98signals: 103signals:
99 void empty( bool ); 104 void empty( bool );
100 void details(); 105 void details();
@@ -116,28 +121,33 @@ protected slots:
116 void rowHeightChanged( int row ); 121 void rowHeightChanged( int row );
117 122
118private: 123private:
119 void loadFile( const QString &strFile, bool journalFile ); 124 void loadFile( const QString &strFile, bool journalFile );
120 void fitColumns(); 125 void fitColumns();
121 void resort(); 126 void resort();
122 void updateJournal( const Contact &contact, Contact::journal_action action, 127 void updateJournal( const OContact &contact, OContact::journal_action action,
123 int row = -1 ); 128 int row = -1 );
124 void insertIntoTable( const Contact &contact, int row ); 129 void insertIntoTable( const OContact &contact, int row );
125 void internalAddEntries( QList<Contact> &list ); 130 QString findContactName( const OContact &entry );
126 QString findContactName( const Contact &entry ); 131 QString findContactContact( const OContact &entry, int row );
127 QString findContactContact( const Contact &entry ); 132 void journalFreeReplace( const OContact &cnt, int row );
128 void journalFreeReplace( const Contact &cnt, int row );
129 void journalFreeRemove( int row ); 133 void journalFreeRemove( int row );
130 void realignTable( int ); 134 void realignTable( int );
131 void updateVisible(); 135 void updateVisible();
132 int lastSortCol; 136 int lastSortCol;
133 bool asc; 137 bool asc;
134 char showChar; 138 char showChar;
135 QMap<AbTableItem*, Contact> contactList; 139 QMap<AbTableItem*, OContact> contactList;
136 const QValueList<int> *intFields; 140 const QValueList<int> *intFields;
137 int currFindRow; 141 int currFindRow;
138 QString showCat; 142 QString showCat;
139 QStringList choicenames; 143 QStringList choicenames;
140 bool enablePainting; 144 bool enablePainting;
141 Categories mCat; 145 Categories mCat;
146
147 QString showBk;
148 bool columnVisible;
149
150 OContactAccess m_contactdb;
151
142}; 152};
143#endif // ABTABLE_H 153#endif // ABTABLE_H
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp
index 3255269..cf2eddf 100644
--- a/core/pim/addressbook/addressbook.cpp
+++ b/core/pim/addressbook/addressbook.cpp
@@ -10,13 +10,13 @@
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** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** OContact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_FD 21#define QTOPIA_INTERNAL_FD
22 22
@@ -92,12 +92,14 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
92 WFlags f ) 92 WFlags f )
93 : QMainWindow( parent, name, f ), 93 : QMainWindow( parent, name, f ),
94 abEditor(0), 94 abEditor(0),
95 bAbEditFirstTime(TRUE), 95 bAbEditFirstTime(TRUE),
96 syncing(FALSE) 96 syncing(FALSE)
97{ 97{
98 isLoading = true;
99
98 initFields(); 100 initFields();
99 101
100 setCaption( tr("Contacts") ); 102 setCaption( tr("Contacts") );
101 setIcon( Resource::loadPixmap( "AddressBook" ) ); 103 setIcon( Resource::loadPixmap( "AddressBook" ) );
102 104
103 setToolBarsMovable( FALSE ); 105 setToolBarsMovable( FALSE );
@@ -184,13 +186,12 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
184 186
185 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE ); 187 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE );
186 actionPersonal = a; 188 actionPersonal = a;
187 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); 189 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) );
188 a->addTo( edit ); 190 a->addTo( edit );
189 191
190
191 edit->insertSeparator(); 192 edit->insertSeparator();
192 193
193 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); 194 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE );
194 actionPersonal = a; 195 actionPersonal = a;
195 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); 196 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) );
196 a->addTo( edit ); 197 a->addTo( edit );
@@ -204,32 +205,31 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
204 205
205 // This is safe to call without checking to see if it exists... 206 // This is safe to call without checking to see if it exists...
206 // not to mention it also does the necessary stuff for the 207 // not to mention it also does the necessary stuff for the
207 // journaling... 208 // journaling...
208 QString str = addressbookXMLFilename(); 209 QString str = addressbookXMLFilename();
209 if ( str.isNull() ) { 210 if ( str.isNull() ) {
210 QMessageBox::warning( this, tr("Out of Space"), 211 QMessageBox::warning(
212 this,
213 tr("Out of Space"),
211 tr("There is not enough space to create\n" 214 tr("There is not enough space to create\n"
212 "neccessary startup files.\n" 215 "neccessary startup files.\n"
213 "\nFree up some space before\nentering data!") 216 "\nFree up some space before\nentering data!")
214 ); 217 );
215 } 218 }
216 219
217 listContainer = new QWidget( this ); 220 listContainer = new QWidget( this );
218 221
219 QVBoxLayout *vb = new QVBoxLayout( listContainer ); 222 QVBoxLayout *vb = new QVBoxLayout( listContainer );
220 223
221 abList = new AbTable( &orderedFields, listContainer, "table" ); 224 abList = new AbTable( &orderedFields, listContainer, "table" );
222 vb->addWidget(abList); 225 vb->addWidget(abList);
223 abList->setHScrollBarMode( QScrollView::AlwaysOff ); 226 // abList->setHScrollBarMode( QScrollView::AlwaysOff );
224 connect( abList, SIGNAL( empty( bool ) ), 227 connect( abList, SIGNAL( empty( bool ) ), this, SLOT( listIsEmpty( bool ) ) );
225 this, SLOT( listIsEmpty( bool ) ) ); 228 connect( abList, SIGNAL( details() ), this, SLOT( slotListView() ) );
226 connect( abList, SIGNAL( details() ), 229 connect( abList, SIGNAL(currentChanged(int,int)), this, SLOT(slotUpdateToolbar()) );
227 this, SLOT( slotListView() ) );
228 connect( abList, SIGNAL(currentChanged(int,int)),
229 this, SLOT(slotUpdateToolbar()) );
230 230
231 mView = 0; 231 mView = 0;
232 232
233 abList->load( addressbookXMLFilename() ); 233 abList->load( addressbookXMLFilename() );
234 if ( QFile::exists(addressbookOldXMLFilename()) ) { 234 if ( QFile::exists(addressbookOldXMLFilename()) ) {
235 abList->load( addressbookOldXMLFilename() ); 235 abList->load( addressbookOldXMLFilename() );
@@ -242,13 +242,13 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
242 catMenu = new QPopupMenu( this ); 242 catMenu = new QPopupMenu( this );
243 catMenu->setCheckable( TRUE ); 243 catMenu->setCheckable( TRUE );
244 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); 244 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) );
245 populateCategories(); 245 populateCategories();
246 246
247 mbList->insertItem( tr("View"), catMenu ); 247 mbList->insertItem( tr("View"), catMenu );
248 setCentralWidget( listContainer ); 248 // setCentralWidget( listContainer );
249 249
250 fontMenu = new QPopupMenu(this); 250 fontMenu = new QPopupMenu(this);
251 fontMenu->setCheckable( true ); 251 fontMenu->setCheckable( true );
252 connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); 252 connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int)));
253 253
254 fontMenu->insertItem(tr( "Small" ), 0); 254 fontMenu->insertItem(tr( "Small" ), 0);
@@ -260,12 +260,16 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
260 slotSetFont(startFontSize); 260 slotSetFont(startFontSize);
261 261
262 mbList->insertItem( tr("Font"), fontMenu); 262 mbList->insertItem( tr("Font"), fontMenu);
263 setCentralWidget(listContainer); 263 setCentralWidget(listContainer);
264 264
265 // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); 265 // qDebug("adressbook contrsuction: t=%d", t.elapsed() );
266
267 abList->setCurrentCell( 0, 0 );
268
269 isLoading = false;
266} 270}
267 271
268 272
269void AddressbookWindow::slotSetFont( int size ) { 273void AddressbookWindow::slotSetFont( int size ) {
270 274
271 if (size > 2 || size < 0) 275 if (size > 2 || size < 0)
@@ -279,29 +283,32 @@ void AddressbookWindow::slotSetFont( int size ) {
279 case 0: 283 case 0:
280 fontMenu->setItemChecked(0, true); 284 fontMenu->setItemChecked(0, true);
281 fontMenu->setItemChecked(1, false); 285 fontMenu->setItemChecked(1, false);
282 fontMenu->setItemChecked(2, false); 286 fontMenu->setItemChecked(2, false);
283 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); 287 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) );
284 currentFont = new QFont (abList->font()); 288 currentFont = new QFont (abList->font());
285 abList->resizeRows(currentFont->pixelSize() + 7); 289 // abList->resizeRows(currentFont->pixelSize() + 7);
290 abList->resizeRows();
286 break; 291 break;
287 case 1: 292 case 1:
288 fontMenu->setItemChecked(0, false); 293 fontMenu->setItemChecked(0, false);
289 fontMenu->setItemChecked(1, true); 294 fontMenu->setItemChecked(1, true);
290 fontMenu->setItemChecked(2, false); 295 fontMenu->setItemChecked(2, false);
291 abList->setFont( *defaultFont ); 296 abList->setFont( *defaultFont );
292 currentFont = new QFont (abList->font()); 297 currentFont = new QFont (abList->font());
293 abList->resizeRows(currentFont->pixelSize() + 7); 298 // abList->resizeRows(currentFont->pixelSize() + 7);
299 abList->resizeRows();
294 break; 300 break;
295 case 2: 301 case 2:
296 fontMenu->setItemChecked(0, false); 302 fontMenu->setItemChecked(0, false);
297 fontMenu->setItemChecked(1, false); 303 fontMenu->setItemChecked(1, false);
298 fontMenu->setItemChecked(2, true); 304 fontMenu->setItemChecked(2, true);
299 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); 305 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) );
300 currentFont = new QFont (abList->font()); 306 currentFont = new QFont (abList->font());
301 abList->resizeRows(currentFont->pixelSize() + 7); 307 //abList->resizeRows(currentFont->pixelSize() + 7);
308 abList->resizeRows();
302 break; 309 break;
303 } 310 }
304} 311}
305 312
306 313
307 314
@@ -311,16 +318,17 @@ void AddressbookWindow::importvCard() {
311 setDocument((const QString&) str ); 318 setDocument((const QString&) str );
312 319
313} 320}
314 321
315void AddressbookWindow::setDocument( const QString &filename ) 322void AddressbookWindow::setDocument( const QString &filename )
316{ 323{
317 if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; 324 if ( filename.find(".vcf") != int(filename.length()) - 4 )
325 return;
318 326
319 QValueList<Contact> cl = Contact::readVCard( filename ); 327 QValueList<OContact> cl = OContact::readVCard( filename );
320 for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { 328 for( QValueList<OContact>::Iterator it = cl.begin(); it != cl.end(); ++it ) {
321// QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") 329// QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?")
322// .arg( (*it).fullName() ); 330// .arg( (*it).fullName() );
323// if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == 331// if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) ==
324// QMessageBox::Ok ) { 332// QMessageBox::Ok ) {
325 abList->addEntry( *it ); 333 abList->addEntry( *it );
326// } 334// }
@@ -344,23 +352,36 @@ AddressbookWindow::~AddressbookWindow()
344 cfg.setGroup("Font"); 352 cfg.setGroup("Font");
345 cfg.writeEntry("fontSize", startFontSize); 353 cfg.writeEntry("fontSize", startFontSize);
346} 354}
347 355
348void AddressbookWindow::slotUpdateToolbar() 356void AddressbookWindow::slotUpdateToolbar()
349{ 357{
350 Contact ce = abList->currentEntry(); 358 OContact ce = abList->currentEntry();
351 actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); 359 actionMail->setEnabled( !ce.defaultEmail().isEmpty() );
352} 360}
353 361
354void AddressbookWindow::showList() 362void AddressbookWindow::showList()
355{ 363{
356 if ( mView ) mView->hide(); 364 bool visiblemView;
365
366 visiblemView = false;
367 if ( mView ) {
368 mView->hide();
369 visiblemView = true;
370 }
357 setCentralWidget( listContainer ); 371 setCentralWidget( listContainer );
358 listContainer->show(); 372 listContainer->show();
359 // update our focues... (or use a stack widget!); 373 // update our focues... (or use a stack widget!);
360 abList->setFocus(); 374 abList->setFocus();
375
376 // This makes sure we are scrolled all the way to the left
377 abList->setContentsPos( 0, abList->contentsY() );
378
379 //if ( visiblemView && abList->showBook() == "Cards" )
380 //abList->setShowCategory( abList->showBook(), abList->showCategory() );
381
361} 382}
362 383
363void AddressbookWindow::showView() 384void AddressbookWindow::showView()
364{ 385{
365 if ( abList->numRows() > 0 ) { 386 if ( abList->numRows() > 0 ) {
366 listContainer->hide(); 387 listContainer->hide();
@@ -369,20 +390,20 @@ void AddressbookWindow::showView()
369 mView->setFocus(); 390 mView->setFocus();
370 } 391 }
371} 392}
372 393
373void AddressbookWindow::slotListNew() 394void AddressbookWindow::slotListNew()
374{ 395{
375 Contact cnt; 396 OContact cnt;
376 if( !syncing ) { 397 if( !syncing ) {
377 if ( abEditor ) 398 if ( abEditor )
378 abEditor->setEntry( cnt ); 399 abEditor->setEntry( cnt );
379 abView()->init( cnt ); 400 abView()->init( cnt );
380 editEntry( NewEntry ); 401 editEntry( NewEntry );
381 } else { 402 } else {
382 QMessageBox::warning(this, tr("Contacts"), 403 QMessageBox::warning(this, tr("OContacts"),
383 tr("Can not edit data, currently syncing")); 404 tr("Can not edit data, currently syncing"));
384 } 405 }
385} 406}
386 407
387void AddressbookWindow::slotListView() 408void AddressbookWindow::slotListView()
388{ 409{
@@ -391,13 +412,13 @@ void AddressbookWindow::slotListView()
391 showView(); 412 showView();
392} 413}
393 414
394void AddressbookWindow::slotListDelete() 415void AddressbookWindow::slotListDelete()
395{ 416{
396 if(!syncing) { 417 if(!syncing) {
397 Contact tmpEntry = abList->currentEntry(); 418 OContact tmpEntry = abList->currentEntry();
398 419
399 // get a name, do the best we can... 420 // get a name, do the best we can...
400 QString strName = tmpEntry.fullName(); 421 QString strName = tmpEntry.fullName();
401 if ( strName.isEmpty() ) { 422 if ( strName.isEmpty() ) {
402 strName = tmpEntry.company(); 423 strName = tmpEntry.company();
403 if ( strName.isEmpty() ) 424 if ( strName.isEmpty() )
@@ -438,38 +459,35 @@ void AddressbookWindow::slotViewEdit()
438} 459}
439 460
440 461
441 462
442void AddressbookWindow::writeMail() 463void AddressbookWindow::writeMail()
443{ 464{
444 Contact c = abList->currentEntry(); 465 OContact c = abList->currentEntry();
445 QString name = c.fileAs(); 466 QString name = c.fileAs();
446 QString email = c.defaultEmail(); 467 QString email = c.defaultEmail();
447 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); 468 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)");
448 e << name << email; 469 e << name << email;
449} 470}
450 471
451
452
453
454static const char * beamfile = "/tmp/obex/contact.vcf"; 472static const char * beamfile = "/tmp/obex/contact.vcf";
455 473
456void AddressbookWindow::slotBeam() 474void AddressbookWindow::slotBeam()
457{ 475{
458 QString filename; 476 QString filename;
459 Contact c; 477 OContact c;
460 if ( actionPersonal->isOn() ) { 478 if ( actionPersonal->isOn() ) {
461 filename = addressbookPersonalVCardName(); 479 filename = addressbookPersonalVCardName();
462 if (!QFile::exists(filename)) 480 if (!QFile::exists(filename))
463 return; // can't beam a non-existent file 481 return; // can't beam a non-existent file
464 c = Contact::readVCard( filename )[0]; 482 c = OContact::readVCard( filename )[0];
465 } else { 483 } else {
466 unlink( beamfile ); // delete if exists 484 unlink( beamfile ); // delete if exists
467 c = abList->currentEntry(); 485 c = abList->currentEntry();
468 mkdir("/tmp/obex/", 0755); 486 mkdir("/tmp/obex/", 0755);
469 Contact::writeVCard( beamfile, c ); 487 OContact::writeVCard( beamfile, c );
470 filename = beamfile; 488 filename = beamfile;
471 } 489 }
472 Ir *ir = new Ir( this ); 490 Ir *ir = new Ir( this );
473 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 491 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
474 QString description = c.fullName(); 492 QString description = c.fullName();
475 ir->send( filename, description, "text/x-vCard" ); 493 ir->send( filename, description, "text/x-vCard" );
@@ -519,13 +537,13 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
519 close(); 537 close();
520 } else if ( msg == "addContact(QString,QString)" ) { 538 } else if ( msg == "addContact(QString,QString)" ) {
521 QDataStream stream(data,IO_ReadOnly); 539 QDataStream stream(data,IO_ReadOnly);
522 QString name, email; 540 QString name, email;
523 stream >> name >> email; 541 stream >> name >> email;
524 542
525 Contact cnt; 543 OContact cnt;
526 QString fn, mn, ln; 544 QString fn, mn, ln;
527 parseName( name, &fn, &mn, &ln ); 545 parseName( name, &fn, &mn, &ln );
528 // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); 546 // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() );
529 cnt.setFirstName( fn ); 547 cnt.setFirstName( fn );
530 cnt.setMiddleName( mn ); 548 cnt.setMiddleName( mn );
531 cnt.setLastName( ln ); 549 cnt.setLastName( ln );
@@ -578,15 +596,15 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
578 596
579} 597}
580 598
581void AddressbookWindow::editPersonal() 599void AddressbookWindow::editPersonal()
582{ 600{
583 QString filename = addressbookPersonalVCardName(); 601 QString filename = addressbookPersonalVCardName();
584 Contact me; 602 OContact me;
585 if (QFile::exists(filename)) 603 if (QFile::exists(filename))
586 me = Contact::readVCard( filename )[0]; 604 me = OContact::readVCard( filename )[0];
587 if (bAbEditFirstTime) { 605 if (bAbEditFirstTime) {
588 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, 606 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields,
589 this, "editor" ); 607 this, "editor" );
590 // don't create a new editor every time 608 // don't create a new editor every time
591 bAbEditFirstTime = FALSE; 609 bAbEditFirstTime = FALSE;
592 } else 610 } else
@@ -596,15 +614,15 @@ void AddressbookWindow::editPersonal()
596 abEditor->showMaximized(); 614 abEditor->showMaximized();
597 615
598 // fix the foxus... 616 // fix the foxus...
599 abEditor->setNameFocus(); 617 abEditor->setNameFocus();
600 if ( abEditor->exec() ) { 618 if ( abEditor->exec() ) {
601 setFocus(); 619 setFocus();
602 Contact new_personal = abEditor->entry(); 620 OContact new_personal = abEditor->entry();
603 QString fname = addressbookPersonalVCardName(); 621 QString fname = addressbookPersonalVCardName();
604 Contact::writeVCard( fname, new_personal ); 622 OContact::writeVCard( fname, new_personal );
605 abView()->init(new_personal); 623 abView()->init(new_personal);
606 abView()->sync(); 624 abView()->sync();
607 } 625 }
608 abEditor->setCaption( tr("Edit Address") ); 626 abEditor->setCaption( tr("Edit Address") );
609} 627}
610 628
@@ -630,27 +648,27 @@ void AddressbookWindow::slotPersonalView()
630 actionFind->setEnabled(FALSE); 648 actionFind->setEnabled(FALSE);
631#endif 649#endif
632 actionMail->setEnabled(FALSE); 650 actionMail->setEnabled(FALSE);
633 651
634 setCaption( tr("Contacts - My Personal Details") ); 652 setCaption( tr("Contacts - My Personal Details") );
635 QString filename = addressbookPersonalVCardName(); 653 QString filename = addressbookPersonalVCardName();
636 Contact me; 654 OContact me;
637 if (QFile::exists(filename)) 655 if (QFile::exists(filename))
638 me = Contact::readVCard( filename )[0]; 656 me = OContact::readVCard( filename )[0];
639 657
640 abView()->init( me ); 658 abView()->init( me );
641 abView()->sync(); 659 abView()->sync();
642 listContainer->hide(); 660 listContainer->hide();
643 setCentralWidget( abView() ); 661 setCentralWidget( abView() );
644 mView->show(); 662 mView->show();
645 mView->setFocus(); 663 mView->setFocus();
646} 664}
647 665
648void AddressbookWindow::editEntry( EntryMode entryMode ) 666void AddressbookWindow::editEntry( EntryMode entryMode )
649{ 667{
650 Contact entry; 668 OContact entry;
651 if ( bAbEditFirstTime ) { 669 if ( bAbEditFirstTime ) {
652 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, 670 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields,
653 this, "editor" ); 671 this, "editor" );
654 bAbEditFirstTime = FALSE; 672 bAbEditFirstTime = FALSE;
655 if ( entryMode == EditEntry ) 673 if ( entryMode == EditEntry )
656 abEditor->setEntry( abList->currentEntry() ); 674 abEditor->setEntry( abList->currentEntry() );
@@ -663,17 +681,17 @@ void AddressbookWindow::editEntry( EntryMode entryMode )
663#endif 681#endif
664 // fix the foxus... 682 // fix the foxus...
665 abEditor->setNameFocus(); 683 abEditor->setNameFocus();
666 if ( abEditor->exec() ) { 684 if ( abEditor->exec() ) {
667 setFocus(); 685 setFocus();
668 if ( entryMode == NewEntry ) { 686 if ( entryMode == NewEntry ) {
669 Contact insertEntry = abEditor->entry(); 687 OContact insertEntry = abEditor->entry();
670 insertEntry.assignUid(); 688 insertEntry.assignUid();
671 abList->addEntry( insertEntry ); 689 abList->addEntry( insertEntry );
672 } else { 690 } else {
673 Contact replaceEntry = abEditor->entry(); 691 OContact replaceEntry = abEditor->entry();
674 if ( !replaceEntry.isValidUid() ) 692 if ( !replaceEntry.isValidUid() )
675 replaceEntry.assignUid(); 693 replaceEntry.assignUid();
676 abList->replaceCurrentEntry( replaceEntry ); 694 abList->replaceCurrentEntry( replaceEntry );
677 } 695 }
678 } 696 }
679 populateCategories(); 697 populateCategories();
@@ -721,12 +739,13 @@ void AddressbookWindow::closeEvent( QCloseEvent *e )
721 at the start of the sync, so there is no need to save 739 at the start of the sync, so there is no need to save
722 Saving however itself would cause problems. */ 740 Saving however itself would cause problems. */
723 e->accept(); 741 e->accept();
724 return; 742 return;
725 } 743 }
726//################## shouldn't always save 744//################## shouldn't always save
745 // True, but the database handles this automatically ! (se)
727 if ( save() ) 746 if ( save() )
728 e->accept(); 747 e->accept();
729 else 748 else
730 e->ignore(); 749 e->ignore();
731} 750}
732 751
@@ -789,20 +808,19 @@ void AddressbookWindow::slotSettings()
789void AddressbookWindow::initFields() 808void AddressbookWindow::initFields()
790{ 809{
791 // we really don't need the things from the configuration, anymore 810 // we really don't need the things from the configuration, anymore
792 // only thing that is important are the important categories. So, 811 // only thing that is important are the important categories. So,
793 // Call the contact functions that correspond to these old functions... 812 // Call the contact functions that correspond to these old functions...
794 813
795 QStringList xmlFields = Contact::fields(); 814 QStringList xmlFields = OContact::fields();
796 QStringList visibleFields = Contact::trfields(); 815 QStringList visibleFields = OContact::trfields();
797 xmlFields.remove( "Title" ); 816 xmlFields.remove( "Title" );
798 visibleFields.remove( tr("Name Title") ); 817 visibleFields.remove( tr("Name Title") );
799 visibleFields.remove( tr("Notes") ); 818 visibleFields.remove( tr("Notes") );
800 819
801 int i, 820 int i, version;
802 version;
803 Config cfg( "AddressBook" ); 821 Config cfg( "AddressBook" );
804 QString zn; 822 QString zn;
805 823
806 // ### Write a function to keep this from happening again... 824 // ### Write a function to keep this from happening again...
807 QStringList::ConstIterator it; 825 QStringList::ConstIterator it;
808 for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) { 826 for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) {
@@ -880,13 +898,13 @@ void AddressbookWindow::initFields()
880 898
881 899
882AbLabel *AddressbookWindow::abView() 900AbLabel *AddressbookWindow::abView()
883{ 901{
884 if ( !mView ) { 902 if ( !mView ) {
885 mView = new AbLabel( this, "viewer" ); 903 mView = new AbLabel( this, "viewer" );
886 mView->init( Contact() ); 904 mView->init( OContact() );
887 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); 905 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) );
888 } 906 }
889 return mView; 907 return mView;
890} 908}
891 909
892void AddressbookWindow::slotFind() 910void AddressbookWindow::slotFind()
@@ -908,52 +926,105 @@ void AddressbookWindow::slotFind()
908 abList->clearFindRow(); 926 abList->clearFindRow();
909#endif 927#endif
910} 928}
911 929
912void AddressbookWindow::slotSetCategory( int c ) 930void AddressbookWindow::slotSetCategory( int c )
913{ 931{
932
933 QString cat, book;
934
914 if ( c <= 0 ) 935 if ( c <= 0 )
915 return; 936 return;
916 for ( unsigned int i = 1; i < catMenu->count(); i++ ) 937
938 // Checkmark Book Menu Item Selected
939 if ( c < 6 )
940 for ( unsigned int i = 1; i < 6; i++ )
917 catMenu->setItemChecked( i, c == (int)i ); 941 catMenu->setItemChecked( i, c == (int)i );
918 if ( c == 1 ) { 942
919 abList->setShowCategory( QString::null ); 943 // Checkmark Category Menu Item Selected
920 setCaption( tr("Contacts") + " - " + tr ( "All" ) ); 944 else
921 } else if ( c == (int)catMenu->count() ) { 945 for ( unsigned int i = 6; i < catMenu->count(); i++ )
922 abList->setShowCategory( tr( "Unfiled" ) ); 946 catMenu->setItemChecked( i, c == (int)i );
923 setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) ); 947
924 } else { 948 for ( unsigned int i = 1; i < catMenu->count(); i++ ) {
925 QString cat = abList->categories()[c - 2]; 949 if (catMenu->isItemChecked( i )) {
926 abList->setShowCategory( cat ); 950 if ( i == 1 ) // default List view
927 setCaption( tr("Contacts") + " - " + cat ); 951 book = QString::null;
952 else if ( i == 2 )
953 book = "Phone";
954 else if ( i == 3 )
955 book = "Company";
956 else if ( i == 4 )
957 book = "Email";
958 else if ( i == 5 )
959 book = "Cards";
960 else if ( i == 6 ) // default All Categories
961 cat = QString::null;
962 else if ( i == (unsigned int)catMenu->count() ) // last menu option will be Unfiled
963 cat = "Unfiled";
964 else
965 cat = abList->categories()[i - 7];
928 } 966 }
929} 967}
930 968
969 abList->setShowCategory( book, cat );
970
971 if ( book.isEmpty() )
972 book = "List";
973 if ( cat.isEmpty() )
974 cat = "All";
975
976 setCaption( tr( "Contacts" ) + " - " + tr( book ) + " - " + tr( cat ) );
977}
978
931void AddressbookWindow::slotSetLetter( char c ) { 979void AddressbookWindow::slotSetLetter( char c ) {
932 980
933 abList->setShowByLetter( c ); 981 abList->setShowByLetter( c );
934 982
935} 983}
936 984
937void AddressbookWindow::populateCategories() 985void AddressbookWindow::populateCategories()
938{ 986{
939 catMenu->clear(); 987 catMenu->clear();
940 988
941 int id, 989 int id, rememberId;
942 rememberId;
943 id = 1; 990 id = 1;
944 rememberId = 0; 991 rememberId = 0;
992
993 catMenu->insertItem( tr( "List" ), id++ );
994 catMenu->insertItem( tr( "Phone Book" ), id++ );
995 catMenu->insertItem( tr( "Company Book" ), id++ );
996 catMenu->insertItem( tr( "Email Book" ), id++ );
997 catMenu->insertItem( tr( "Cards" ), id++ );
998 catMenu->insertSeparator();
999
945 catMenu->insertItem( tr( "All" ), id++ ); 1000 catMenu->insertItem( tr( "All" ), id++ );
946 QStringList categories = abList->categories(); 1001 QStringList categories = abList->categories();
947 categories.append( tr( "Unfiled" ) ); 1002 categories.append( tr( "Unfiled" ) );
948 for ( QStringList::Iterator it = categories.begin(); 1003 for ( QStringList::Iterator it = categories.begin();
949 it != categories.end(); ++it ) { 1004 it != categories.end(); ++it ) {
950 catMenu->insertItem( *it, id ); 1005 catMenu->insertItem( *it, id );
951 if ( *it == abList->showCategory() ) 1006 if ( *it == abList->showCategory() )
952 rememberId = id; 1007 rememberId = id;
953 ++id; 1008 ++id;
954 } 1009 }
955 if ( abList->showCategory().isEmpty() ) 1010
956 slotSetCategory( 1 ); 1011 if ( abList->showBook().isEmpty() ) {
957 else 1012 catMenu->setItemChecked( 1, true );
1013 } else if ( abList->showBook() == "Phone" ) {
1014 catMenu->setItemChecked( 2, true );
1015 } else if ( abList->showBook() == "Company" ) {
1016 catMenu->setItemChecked( 3, true );
1017 } else if ( abList->showBook() == "Email" ) {
1018 catMenu->setItemChecked( 4, true );
1019 } else if ( abList->showBook() == "Cards" ) {
1020 catMenu->setItemChecked( 5, true );
1021 }
1022
1023 if ( abList->showCategory().isEmpty() ) {
1024 slotSetCategory( 6 );
1025 }
1026 else {
958 slotSetCategory( rememberId ); 1027 slotSetCategory( rememberId );
959} 1028}
1029}
1030
diff --git a/core/pim/addressbook/addressbook.h b/core/pim/addressbook/addressbook.h
index 34ca85d..bf36407 100644
--- a/core/pim/addressbook/addressbook.h
+++ b/core/pim/addressbook/addressbook.h
@@ -73,36 +73,37 @@ private slots:
73 void beamDone( Ir * ); 73 void beamDone( Ir * );
74 void slotFind(); 74 void slotFind();
75 void slotSetCategory( int ); 75 void slotSetCategory( int );
76 void slotSetLetter( char ); 76 void slotSetLetter( char );
77 void slotUpdateToolbar(); 77 void slotUpdateToolbar();
78 void slotSetFont(int); 78 void slotSetFont(int);
79
79private: 80private:
80 void initFields(); // inititialize our fields... 81 void initFields(); // inititialize our fields...
81 AbLabel *abView(); 82 AbLabel *abView();
82 void populateCategories(); 83 void populateCategories();
83 84
84 QPopupMenu *catMenu, *fontMenu; 85 QPopupMenu *catMenu, *fontMenu;
85 QPEToolBar *listTools; 86 QPEToolBar *listTools;
86 QToolButton *deleteButton; 87 QToolButton *deleteButton;
87 QValueList<int> allFields, 88 QValueList<int> allFields, orderedFields;
88 orderedFields;
89 QStringList slOrderedFields; 89 QStringList slOrderedFields;
90 enum Panes { paneList=0, paneView, paneEdit }; 90 enum Panes { paneList=0, paneView, paneEdit };
91 ContactEditor *abEditor; 91 ContactEditor *abEditor;
92 AbLabel *mView; 92 AbLabel *mView;
93 LetterPicker *pLabel; 93 LetterPicker *pLabel;
94 AbTable *abList; 94 AbTable *abList;
95 QWidget *listContainer; 95 QWidget *listContainer;
96 96
97 QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, 97 QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, *actionPersonal, *actionMail;
98 *actionPersonal, *actionMail;
99 98
100 bool bAbEditFirstTime; 99 bool bAbEditFirstTime;
101 int viewMargin; 100 int viewMargin;
102 101
103 bool syncing; 102 bool syncing;
104 QFont *defaultFont; 103 QFont *defaultFont;
105 int startFontSize; 104 int startFontSize;
105
106 bool isLoading;
106}; 107};
107 108
108#endif 109#endif
diff --git a/core/pim/addressbook/contacteditor.cpp b/core/pim/addressbook/contacteditor.cpp
index ae86ed0..fd7f009 100644
--- a/core/pim/addressbook/contacteditor.cpp
+++ b/core/pim/addressbook/contacteditor.cpp
@@ -46,13 +46,13 @@ void parseEmailFrom( const QString &txt, QString &strDefaultEmail,
46 QString &strAll ); 46 QString &strAll );
47 47
48// helper convert from file format to comma delimited... 48// helper convert from file format to comma delimited...
49void parseEmailTo( const QString &strDefaultEmail, 49void parseEmailTo( const QString &strDefaultEmail,
50 const QString &strOtherEmail, QString &strBack ); 50 const QString &strOtherEmail, QString &strBack );
51 51
52 ContactEditor::ContactEditor(const Contact &entry, 52 ContactEditor::ContactEditor(const OContact &entry,
53 const QValueList<int> *newOrderedValues, 53 const QValueList<int> *newOrderedValues,
54 QStringList *slNewOrdered, 54 QStringList *slNewOrdered,
55 QWidget *parent, 55 QWidget *parent,
56 const char *name, 56 const char *name,
57 WFlags fl ) 57 WFlags fl )
58 : QDialog( parent, name, TRUE, fl ), 58 : QDialog( parent, name, TRUE, fl ),
@@ -1289,13 +1289,13 @@ void ContactEditor::cleanupFields() {
1289 txtTmp->setText(""); 1289 txtTmp->setText("");
1290 txtTmp = cmbFileAs->lineEdit(); 1290 txtTmp = cmbFileAs->lineEdit();
1291 txtTmp->setText(""); 1291 txtTmp->setText("");
1292 1292
1293} 1293}
1294 1294
1295void ContactEditor::setEntry( const Contact &entry ) { 1295void ContactEditor::setEntry( const OContact &entry ) {
1296 1296
1297 cleanupFields(); 1297 cleanupFields();
1298 1298
1299 1299
1300 ent = entry; 1300 ent = entry;
1301 1301
diff --git a/core/pim/addressbook/contacteditor.h b/core/pim/addressbook/contacteditor.h
index 4f3b56e..8ed8553 100644
--- a/core/pim/addressbook/contacteditor.h
+++ b/core/pim/addressbook/contacteditor.h
@@ -18,13 +18,13 @@
18 * 18 *
19 */ 19 */
20 20
21#ifndef CONTACTEDITOR_H 21#ifndef CONTACTEDITOR_H
22#define CONTACTEDITOR_H 22#define CONTACTEDITOR_H
23 23
24#include <qpe/contact.h> 24#include <opie/ocontact.h>
25 25
26#include <qdialog.h> 26#include <qdialog.h>
27#include <qlist.h> 27#include <qlist.h>
28#include <qmap.h> 28#include <qmap.h>
29#include <qstringlist.h> 29#include <qstringlist.h>
30 30
@@ -49,27 +49,27 @@ class CategorySelect;
49class QLabel; 49class QLabel;
50 50
51class ContactEditor : public QDialog { 51class ContactEditor : public QDialog {
52 Q_OBJECT 52 Q_OBJECT
53 53
54 public: 54 public:
55 ContactEditor(const Contact &entry, 55 ContactEditor(const OContact &entry,
56 const QValueList<int> *newOrderedValues, 56 const QValueList<int> *newOrderedValues,
57 QStringList *slNewOrdered, 57 QStringList *slNewOrdered,
58 QWidget *parent = 0, 58 QWidget *parent = 0,
59 const char *name = 0, 59 const char *name = 0,
60 WFlags fl = 0 ); 60 WFlags fl = 0 );
61 ~ContactEditor(); 61 ~ContactEditor();
62 void loadFields(); 62 void loadFields();
63 void setNameFocus(); 63 void setNameFocus();
64 Contact entry() const { return ent; } 64 OContact entry() const { return ent; }
65 65
66 public slots: 66 public slots:
67 void slotNote(); 67 void slotNote();
68 void slotName(); 68 void slotName();
69 void setEntry(const Contact &entry); 69 void setEntry(const OContact &entry);
70 70
71 protected slots: 71 protected slots:
72 void accept(); 72 void accept();
73 73
74 private: 74 private:
75 void init(); 75 void init();
@@ -98,13 +98,13 @@ class ContactEditor : public QDialog {
98 void slotCountryChange( const QString &textChanged ); 98 void slotCountryChange( const QString &textChanged );
99 void slotFullNameChange( const QString &textChanged ); 99 void slotFullNameChange( const QString &textChanged );
100 100
101 private: 101 private:
102 bool useFullName, hasGender, hasTitle, hasCompany, hasNotes, hasStreet, hasStreet2, hasPOBox, hasCity, hasState, hasZip, hasCountry; 102 bool useFullName, hasGender, hasTitle, hasCompany, hasNotes, hasStreet, hasStreet2, hasPOBox, hasCity, hasState, hasZip, hasCountry;
103 103
104 Contact ent; 104 OContact ent;
105 105
106 QDialog *dlgNote; 106 QDialog *dlgNote;
107 QDialog *dlgName; 107 QDialog *dlgName;
108 108
109 QList<QLineEdit> listValue; 109 QList<QLineEdit> listValue;
110 QList<QLabel> listName; 110 QList<QLabel> listName;