author | eilers <eilers> | 2002-10-08 12:33:52 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-10-08 12:33:52 (UTC) |
commit | a194611bf645fe7e2e9e83733ababc587fd42f1d (patch) (side-by-side diff) | |
tree | 2c21a5576bce48dba2fe83f6c849c0d16025a848 | |
parent | 333fec32d47ea32de9fb4c8cd378a519785a1ff8 (diff) | |
download | opie-a194611bf645fe7e2e9e83733ababc587fd42f1d.zip opie-a194611bf645fe7e2e9e83733ababc587fd42f1d.tar.gz opie-a194611bf645fe7e2e9e83733ababc587fd42f1d.tar.bz2 |
Joined development branch: It uses the new PIM API
Some features in "View" added by Darwin Zins, but they are
not finished..
-rw-r--r-- | core/pim/addressbook/abeditor.cpp | 5 | ||||
-rw-r--r-- | core/pim/addressbook/abeditor.h | 8 | ||||
-rw-r--r-- | core/pim/addressbook/ablabel.cpp | 2 | ||||
-rw-r--r-- | core/pim/addressbook/ablabel.h | 6 | ||||
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 444 | ||||
-rw-r--r-- | core/pim/addressbook/abtable.h | 36 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.cpp | 191 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.h | 9 | ||||
-rw-r--r-- | core/pim/addressbook/contacteditor.cpp | 4 | ||||
-rw-r--r-- | core/pim/addressbook/contacteditor.h | 10 |
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, // helper convert from file format to comma delimited... void parseEmailTo( const QString &strDefaultEmail, const QString &strOtherEmail, QString &strBack ); -AbEditor::AbEditor( const Contact &entry, const QValueList<int> *newOrdered, +AbEditor::AbEditor( const OContact &entry, const QValueList<int> *newOrdered, QStringList *slNewOrdered, QWidget *parent = 0, const char *name = 0, WFlags fl = 0 ) : QDialog( parent, name, TRUE, fl ), orderedValues( newOrdered ), slOrdered( slNewOrdered ) { @@ -179,13 +179,13 @@ void AbEditor::loadFields() QListIterator<QLabel> lit( listName ); for ( it = slOrdered->begin(); *lit; ++lit, ++it ) { (*lit)->setText( *it ); } } -void AbEditor::setEntry( const Contact &entry ) +void AbEditor::setEntry( const OContact &entry ) { ent = entry; QListIterator<QLineEdit> it( listValue ); firstEdit->setText( ent.firstName() ); lastEdit->setText( ent.lastName() ); cmbCat->setCategories( ent.categories(), "Contacts", tr("Contacts") ); @@ -546,12 +546,13 @@ void parseEmailFrom( const QString &txt, QString &strDefaultEmail, QString &strAll ) { int where, start; if ( txt.isEmpty() ) return; + // find the first where = txt.find( ',' ); if ( where < 0 ) { strDefaultEmail = txt; strAll = txt; } 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; class CategorySelect; class AbEditor : public QDialog { Q_OBJECT public: - AbEditor( const Contact &entry, const QValueList<int> *newOrdedValues, + AbEditor( const OContact &entry, const QValueList<int> *newOrdedValues, QStringList *slNewOrdered, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~AbEditor(); void loadFields(); void setNameFocus(); - Contact entry() const { return ent; } + OContact entry() const { return ent; } public slots: void slotNote(); - void setEntry( const Contact &entry ); + void setEntry( const OContact &entry ); protected slots: void accept(); private: void init(); @@ -60,13 +60,13 @@ private: bool isEmpty(); private: QDialog *dlgNote; QLabel *lblNote; QMultiLineEdit *txtNote; - Contact ent; + OContact ent; QScrollView *svPage; QLineEdit *firstEdit; QLineEdit *lastEdit; QLineEdit *middleEdit; QComboBox *genderCombo; 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 ) } AbLabel::~AbLabel() { } -void AbLabel::init( const Contact &entry ) +void AbLabel::init( const OContact &entry ) { ent = entry; } void AbLabel::sync() { 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 @@ ** not clear to you. ** **********************************************************************/ #ifndef ABLABEL_H #define ABLABEL_H -#include <qpe/contact.h> +#include <opie/ocontact.h> #include <qtextview.h> class AbLabel : public QTextView { Q_OBJECT public: AbLabel( QWidget *parent, const char *name = 0 ); ~AbLabel(); public slots: - void init( const Contact &entry ); + void init( const OContact &entry ); void sync(); signals: void okPressed(); protected: void keyPressEvent( QKeyEvent * ); private: - Contact ent; + OContact ent; }; #endif // ABLABEL_H 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 @@ #include <qpe/categoryselect.h> #include <qpe/config.h> #include <qpe/stringutil.h> #include <qpe/qcopenvelope_qws.h> +#include <opie/orecordlist.h> + #include <qasciidict.h> #include <qdatetime.h> #include <qfile.h> #include <qregexp.h> +#include <qmessagebox.h> #include "abtable.h" #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <ctype.h> //toupper() for key hack -static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ); - -//### qtmail/addresslist.cpp hardcodes this filename as well -static QString journalFileName() -{ - QString str = getenv("HOME"); - str +="/.abjournal"; - return str; -} - +static bool contactCompare( const OContact &cnt, const QRegExp &r, int category ); /*! \class AbTableItem abtable.h \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 : QTable( parent, name ), // #endif lastSortCol( -1 ), asc( TRUE ), intFields( order ), currFindRow( -2 ), - mCat( 0 ) + mCat( 0 ), + m_contactdb ("addressbook") { mCat.load( categoryFileName() ); setSelectionMode( NoSelection ); init(); setSorting( TRUE ); connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), @@ -156,12 +151,13 @@ void AbTable::init() setNumCols( 2 ); horizontalHeader()->setLabel( 0, tr( "Full Name" )); horizontalHeader()->setLabel( 1, tr( "Contact" )); setLeftMargin( 0 ); verticalHeader()->hide(); + columnVisible = true; } void AbTable::columnClicked( int col ) { if ( !sorting() ) return; @@ -172,61 +168,60 @@ void AbTable::columnClicked( int col ) if ( col == lastSortCol ) { asc = !asc; } else { lastSortCol = col; asc = TRUE; } + //QMessageBox::information( this, "resort", "columnClicked" ); resort(); } void AbTable::resort() { if ( sorting() ) { if ( lastSortCol == -1 ) lastSortCol = 0; sortColumn( lastSortCol, asc, TRUE ); + //QMessageBox::information( this, "resort", "resort" ); updateVisible(); } } -Contact AbTable::currentEntry() +OContact AbTable::currentEntry() { - Contact cnt; + OContact cnt; AbTableItem *abItem; abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); if ( abItem ) { cnt = contactList[abItem]; + //cnt = contactList[currentRow()]; } return cnt; } -void AbTable::replaceCurrentEntry( const Contact &newContact ) +void AbTable::replaceCurrentEntry( const OContact &newContact ) { int row = currentRow(); - updateJournal( newContact, Contact::ACTION_REPLACE, row ); updateVisible(); journalFreeReplace( newContact, row ); + } void AbTable::deleteCurrentEntry() { int row = currentRow(); - AbTableItem *abItem; - abItem = static_cast<AbTableItem*>(item( row, 0 )); - Contact oldContact; - oldContact = contactList[abItem]; - updateJournal( oldContact, Contact::ACTION_REMOVE, row ); // a little wasteful, but it ensure's there is only one place // where we delete. journalFreeRemove( row ); updateVisible(); if ( numRows() == 0 ) emit empty( TRUE ); + } void AbTable::clear() { contactList.clear(); for ( int r = 0; r < numRows(); ++r ) { @@ -241,15 +236,21 @@ void AbTable::clear() void AbTable::refresh() { int rows = numRows(); QString value; AbTableItem *abi; + + // hide columns so no flashing ? + if ( showBk == "Cards" ) { + hideColumn(0); + hideColumn(1); + } for ( int r = 0; r < rows; ++r ) { abi = static_cast<AbTableItem*>( item(r, 0) ); - value = findContactContact( contactList[abi] ); + value = findContactContact( contactList[abi], r ); static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); } resort(); } void AbTable::keyPressEvent( QKeyEvent *e ) @@ -300,13 +301,13 @@ void AbTable::moveTo( char c ) } } setCurrentCell( r, currentColumn() ); } -QString AbTable::findContactName( const Contact &entry ) +QString AbTable::findContactName( const OContact &entry ) { // We use the fileAs, then company, defaultEmail QString str; str = entry.fileAs(); if ( str.isEmpty() ) { str = entry.company(); @@ -314,13 +315,13 @@ QString AbTable::findContactName( const Contact &entry ) str = entry.defaultEmail(); } } return str; } -QString AbTable::findContactContact( const Contact &entry ) +QString AbTable::findContactContact( const OContact &entry, int /* row */ ) { QString value; value = ""; for ( QValueList<int>::ConstIterator it = intFields->begin(); it != intFields->end(); ++it ) { switch ( *it ) { @@ -440,311 +441,71 @@ QString AbTable::findContactContact( const Contact &entry ) if ( !value.isEmpty() ) break; } return value; } -void AbTable::addEntry( const Contact &newCnt ) +void AbTable::addEntry( const OContact &newCnt ) { int row = numRows(); + setNumRows( row + 1 ); - updateJournal( newCnt, Contact::ACTION_ADD ); insertIntoTable( newCnt, row ); + + qWarning("abtable:AddContact"); + m_contactdb.add ( newCnt ); + setCurrentCell( row, 0 ); - updateVisible(); + // updateVisible(); } -void AbTable::resizeRows( int size ) { +void AbTable::resizeRows() { /* if (numRows()) { for (int i = 0; i < numRows(); i++) { setRowHeight( i, size ); } - }*/ + } updateVisible(); + */ } -void AbTable::updateJournal( const Contact &cnt, - Contact::journal_action action, int row ) -{ - QFile f( journalFileName() ); - if ( !f.open(IO_WriteOnly|IO_Append) ) - return; - QString buf; - QCString str; - buf = "<Contact "; - cnt.save( buf ); - buf += " action=\"" + QString::number( (int)action ) + "\" "; - if ( action == Contact::ACTION_REMOVE || action == Contact::ACTION_REPLACE) - buf += " actionrow=\"" + QString::number(row) + "\" "; - buf += "/>\n"; - QCString cstr = buf.utf8(); - f.writeBlock( cstr.data(), cstr.length() ); - QCopEnvelope( "QPE/PIM", "addressbookUpdated()" ); -} - -bool AbTable::save( const QString &fn ) + +bool AbTable::save( const QString& /* fn */ ) { // QTime t; // t.start(); + qWarning("abtable:Save data"); + m_contactdb.save(); - QString strNewFile = fn + ".new"; - QFile f( strNewFile ); - if ( !f.open( IO_WriteOnly|IO_Raw ) ) - return false; - - int total_written; - QString out; - out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" - " <Groups>\n" - " </Groups>\n" - " <Contacts>\n"; - QMapIterator<AbTableItem*, Contact> it; - for ( it = contactList.begin(); it != contactList.end(); ++it ) { - out += "<Contact "; - it.data().save( out ); - out += "/>\n"; - QCString cstr = out.utf8(); - total_written = f.writeBlock( cstr.data(), cstr.length() ); - if ( total_written != int(cstr.length()) ) { - f.close(); - QFile::remove( strNewFile ); - return false; - } - out = ""; - } - out += " </Contacts>\n</AddressBook>\n"; - - QCString cstr = out.utf8(); - total_written = f.writeBlock( cstr.data(), cstr.length() ); - if ( total_written != int(cstr.length()) ) { - f.close(); - QFile::remove( strNewFile ); - return false; - } - f.close(); - -// qDebug("saving: %d", t.elapsed() ); - - // move the file over, I'm just going to use the system call - // because, I don't feel like using QDir. - if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) { - qWarning( "problem renaming file %s to %s, errno: %d", - strNewFile.latin1(), fn.latin1(), errno ); - // remove the tmp file... - QFile::remove( strNewFile ); - } - // remove the journal... - QFile::remove( journalFileName() ); return true; } -void AbTable::load( const QString &fn ) +void AbTable::load( const QString& /* fn */ ) { setSorting( false ); - loadFile( fn, false ); - // merge in the journal - if ( QFile::exists( journalFileName() ) ) { - loadFile( journalFileName(), true ); - save( fn ); - } - setSorting( true ); - resort(); -} + setUpdatesEnabled( FALSE ); -void AbTable::loadFile( const QString &strFile, bool journalFile ) -{ -// QTime t; -// t.start(); - QFile f( strFile ); - if ( !f.open(IO_ReadOnly) ) - return; - QList<Contact> list; - list.setAutoDelete( TRUE ); - QByteArray ba = f.readAll(); - f.close(); - if (ba.isEmpty() ) - return; - char *uc = ba.data();//(QChar *)data.unicode(); - int len = ba.size();//data.length(); - bool foundAction = false; - Contact::journal_action action; - bool foundKey = false; - int journalKey = 0; - - const int JOURNALACTION = Qtopia::Notes + 1; - const int JOURNALROW = JOURNALACTION + 1; - - // ********************************** - // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!! - // ********************************** - QAsciiDict<int> dict( 47 ); - dict.setAutoDelete( TRUE ); - dict.insert( "Uid", new int(Qtopia::AddressUid) ); - dict.insert( "Title", new int(Qtopia::Title) ); - dict.insert( "FirstName", new int(Qtopia::FirstName) ); - dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); - dict.insert( "LastName", new int(Qtopia::LastName) ); - dict.insert( "Suffix", new int(Qtopia::Suffix) ); - dict.insert( "FileAs", new int(Qtopia::FileAs) ); - dict.insert( "Categories", new int(Qtopia::AddressCategory) ); - dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); - dict.insert( "Emails", new int(Qtopia::Emails) ); - dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); - dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); - dict.insert( "HomeState", new int(Qtopia::HomeState) ); - dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); - dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); - dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); - dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); - dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); - dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); - dict.insert( "Company", new int(Qtopia::Company) ); - dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); - dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); - dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); - dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); - dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); - dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); - dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); - dict.insert( "Department", new int(Qtopia::Department) ); - dict.insert( "Office", new int(Qtopia::Office) ); - dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); - dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); - dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); - dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); - dict.insert( "Profession", new int(Qtopia::Profession) ); - dict.insert( "Assistant", new int(Qtopia::Assistant) ); - dict.insert( "Manager", new int(Qtopia::Manager) ); - dict.insert( "Spouse", new int(Qtopia::Spouse) ); - dict.insert( "Children", new int(Qtopia::Children) ); - dict.insert( "Gender", new int(Qtopia::Gender) ); - dict.insert( "Birthday", new int(Qtopia::Birthday) ); - dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); - dict.insert( "Nickname", new int(Qtopia::Nickname) ); - dict.insert( "Notes", new int(Qtopia::Notes) ); - dict.insert( "action", new int(JOURNALACTION) ); - dict.insert( "actionrow", new int(JOURNALROW) ); - - int i = 0; - int num = 0; - char *point; - while ( (point = strstr( uc+i, "<Contact " ) ) != NULL ) { - i = point - uc; - // if we are reading the standard file, we just need to - // insert info, so just say we'll do an insert... - action = Contact::ACTION_ADD; - // new Contact - Contact *cnt = new Contact; - i += 9; - while ( 1 ) { - while ( i < len && (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) - i++; - if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) - break; - // we have another attribute read it. - int j = i; - while ( j < len && uc[j] != '=' ) - j++; - char *attr = uc+i; - uc[j] = '\0'; - //qDebug("attr=%s", attr.latin1() ); - i = ++j; // skip = - while ( i < len && uc[i] != '"' ) - i++; - j = ++i; - bool haveEnt = FALSE; - bool haveUtf = FALSE; - while ( j < len && uc[j] != '"' ) { - if ( uc[j] == '&' ) - haveEnt = TRUE; - if ( ((unsigned char)uc[j]) > 0x7f ) - haveUtf = TRUE; - j++; - } - - if ( j == i ) { - // empty value - i = j + 1; - continue; - } - - QString value = haveUtf ? QString::fromUtf8( uc+i, j-i ) - : QString::fromLatin1( uc+i, j-i ); - if ( haveEnt ) - value = Qtopia::plainString( value ); - i = j + 1; - - int *find = dict[ attr ]; - if ( !find ) { - cnt->setCustomField(attr, value); - continue; - } -#if 1 - switch( *find ) { - case Qtopia::AddressUid: - cnt->setUid( value.toInt() ); - break; - case Qtopia::AddressCategory: - cnt->setCategories( Qtopia::Record::idsFromString( value )); - break; - case JOURNALACTION: - action = Contact::journal_action(value.toInt()); - break; - case JOURNALROW: - journalKey = value.toInt(); - break; + qWarning("abtable:Load data"); - default: - cnt->insert( *find, value ); - break; - } -#endif - } + OContactAccess::List list = m_contactdb.allRecords(); + OContactAccess::List::Iterator it; + setNumRows( list.count() ); + int row = 0; + for ( it = list.begin(); it != list.end(); ++it ) + insertIntoTable( *it, row++ ); - // sadly we can't delay adding of items from the journal to get - // the proper effect, but then, the journal should _never_ be - // that huge, and recovering from a crash is not necessarily - // a *fast* thing. - switch ( action ) { - case Contact::ACTION_ADD: - if ( journalFile ) { - int myrows = numRows(); - setNumRows( myrows + 1 ); - insertIntoTable( *cnt, myrows ); - delete cnt; - } - else - list.append( cnt ); - break; - case Contact::ACTION_REMOVE: - // yup, we don't use the entry to remove the object... - journalFreeRemove( journalKey ); - delete cnt; - break; - case Contact::ACTION_REPLACE: - journalFreeReplace( *cnt, journalKey ); - delete cnt; - break; - default: - break; - } - num++; - foundAction = false; - foundKey = false; -// if ( num % 100 == 0 ) { -// qDebug("loading file, num=%d, t=%d", num, t.elapsed() ); -// } - } - if ( list.count() > 0 ) { - internalAddEntries( list ); - } -// qDebug("done loading %d, t=%d", num, t.elapsed() ); + resort(); + + setUpdatesEnabled( TRUE ); + setSorting( true ); + //resort(); } + void AbTable::realignTable( int row ) { QTableItem *ti1, *ti2; int totalRows = numRows(); for ( int curr = row; curr < totalRows - 1; curr++ ) { @@ -758,19 +519,20 @@ void AbTable::realignTable( int row ) setItem( curr, 1, ti2 ); } setNumRows( totalRows - 1 ); resort(); } -void AbTable::insertIntoTable( const Contact &cnt, int row ) +// Add contact into table. +void AbTable::insertIntoTable( const OContact &cnt, int row ) { QString strName, strContact; strName = findContactName( cnt ); - strContact = findContactContact( cnt ); + strContact = findContactContact( cnt, row ); AbTableItem *ati; ati = new AbTableItem( this, QTableItem::Never, strName, strContact); contactList.insert( ati, cnt ); setItem( row, 0, ati ); ati = new AbTableItem( this, QTableItem::Never, strContact, strName); @@ -779,57 +541,65 @@ void AbTable::insertIntoTable( const Contact &cnt, int row ) //### cannot do this; table only has two columns at this point // setItem( row, 2, new AbPickItem( this ) ); // resort at some point? } -void AbTable::internalAddEntries( QList<Contact> &list ) -{ - setUpdatesEnabled( FALSE ); - setNumRows( list.count() ); - int row = 0; - Contact *it; - for ( it = list.first(); it; it = list.next() ) - insertIntoTable( *it, row++ ); - resort(); - setUpdatesEnabled( TRUE ); -} - -void AbTable::journalFreeReplace( const Contact &cnt, int row ) +// Replace or add an entry +void AbTable::journalFreeReplace( const OContact &cnt, int row ) { QString strName, strContact; AbTableItem *ati = 0l; strName = findContactName( cnt ); - strContact = findContactContact( cnt ); + strContact = findContactContact( cnt, row ); ati = static_cast<AbTableItem*>(item(row, 0)); - if ( ati != 0 ) { + + // Replace element if found in row "row" + // or add this element if not. + if ( ati != 0 ) { // replace + // :SX db access -> replace + qWarning ("Replace Contact in DB ! UID: %d", contactList[ati].uid() ); + m_contactdb.replace ( cnt ); + contactList.remove( ati ); ati->setItem( strName, strContact ); contactList.insert( ati, cnt ); ati = static_cast<AbTableItem*>(item(row, 1)); ati->setItem( strContact, strName ); - }else{ + + }else{ // add int myrows = numRows(); setNumRows( myrows + 1 ); insertIntoTable( cnt, myrows ); - // gets deleted when returning + // gets deleted when returning -- Why ? (se) + // :SX db access -> add + qWarning ("Are you sure to add to database ? -> Currently disabled !!"); + // m_contactdb.add( cnt ); } } +// Remove entry void AbTable::journalFreeRemove( int row ) { AbTableItem *ati; ati = static_cast<AbTableItem*>(item(row, 0)); if ( !ati ) return; + + // :SX db access -> remove + qWarning ("Remove Contact from DB ! UID: %d",contactList[ati].uid() ); + m_contactdb.remove( contactList[ati].uid() ); + contactList.remove( ati ); + realignTable( row ); + } #if QT_VERSION <= 230 #ifndef SINGLE_APP void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) { @@ -864,31 +634,31 @@ void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) void AbTable::slotDoFind( const QString &findString, bool caseSensitive, bool backwards, int category ) { if ( currFindRow < -1 ) currFindRow = currentRow() - 1; clearSelection( TRUE ); - int rows, - row; + int rows, row; AbTableItem *ati; QRegExp r( findString ); r.setCaseSensitive( caseSensitive ); rows = numRows(); static bool wrapAround = true; if ( !backwards ) { for ( row = currFindRow + 1; row < rows; row++ ) { ati = static_cast<AbTableItem*>( item(row, 0) ); if ( contactCompare( contactList[ati], r, category ) ) + //if ( contactCompare( contactList[row], r, category ) ) break; - } } else { for ( row = currFindRow - 1; row > -1; row-- ) { ati = static_cast<AbTableItem*>( item(row, 0) ); if ( contactCompare( contactList[ati], r, category ) ) + //if ( contactCompare( contactList[row], r, category ) ) break; } } if ( row >= rows || row < 0 ) { if ( row < 0 ) currFindRow = rows; @@ -909,13 +679,13 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, addSelection( foundSelection ); setCurrentCell( currFindRow, numCols() - 1 ); wrapAround = true; } } -static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) +static bool contactCompare( const OContact &cnt, const QRegExp &r, int category ) { bool returnMe; QArray<int> cats; cats = cnt.categories(); returnMe = false; @@ -927,22 +697,35 @@ static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) if ( cats[i] == category ) { returnMe = cnt.match( r ); break; } } } + return returnMe; } void AbTable::fitColumns() { - int contentsWidth = visibleWidth(); - int n = numCols(); - int pw = n == 3 ? columnWidth(2) : 0; - setColumnWidth( 0, contentsWidth - contentsWidth / 2 ); - setColumnWidth( 1, contentsWidth / 2 - pw ); + int contentsWidth = visibleWidth() / 2; + + if ( showBk == "Cards" ) { + showColumn(1); + //adjustColumn(1); + setColumnWidth( 1, visibleWidth() ); + columnVisible = false; + } else { + if ( columnVisible == false ){ + showColumn(0); + columnVisible = true; + } + setColumnWidth( 0, contentsWidth ); + adjustColumn(1); + if ( columnWidth(1) < contentsWidth ) + setColumnWidth( 1, contentsWidth ); + } } void AbTable::show() { fitColumns(); QTable::show(); @@ -980,20 +763,20 @@ QStringList AbTable::choiceNames() const void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) { /* ###### QString selname = choicenames.at(index); for (each row) { - Contact *c = contactForRow(row); + OContact *c = contactForRow(row); if ( list.contains(c->email) ) { list.remove(c->email); setText(row, 2, selname); } } for (remaining list items) { - Contact *c = new contact(item); + OContact *c = new contact(item); setText(newrow, 2, selname); } */ } @@ -1001,26 +784,31 @@ QStringList AbTable::choiceSelection(int /*index*/) const { QStringList r; /* ###### QString selname = choicenames.at(index); for (each row) { - Contact *c = contactForRow(row); + OContact *c = contactForRow(row); if ( text(row,2) == selname ) { r.append(c->email); } } */ return r; } -void AbTable::setShowCategory( const QString &c ) +void AbTable::setShowCategory( const QString &b, const QString &c ) { + showBk = b; showCat = c; - updateVisible(); + //QMessageBox::information( this, "setShowCategory", "setShowCategory" ); + //updateVisible(); + refresh(); + ensureCellVisible( currentRow(), 0 ); + updateVisible(); // :SX } void AbTable::setShowByLetter( char c ) { showChar = tolower(c); updateVisible(); @@ -1028,12 +816,16 @@ void AbTable::setShowByLetter( char c ) QString AbTable::showCategory() const { return showCat; } +QString AbTable::showBook() const +{ + return showBk; +} QStringList AbTable::categories() { mCat.load( categoryFileName() ); QStringList categoryList = mCat.labels( "Contacts" ); return categoryList; @@ -1046,13 +838,13 @@ void AbTable::updateVisible() id, totalCats, it, row; bool hide; AbTableItem *ati; - Contact *cnt; + OContact *cnt; QString fileAsName; QString tmpStr; visible = 0; setPaintingEnabled( FALSE ); 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 @@ **********************************************************************/ #ifndef ABTABLE_H #define ABTABLE_H #include <qpe/categories.h> -#include <qpe/contact.h> +#include <opie/ocontact.h> #include <qmap.h> #include <qtable.h> #include <qstringlist.h> #include <qcombobox.h> +#include <opie/ocontactaccess.h> + class AbTableItem : public QTableItem { public: AbTableItem( QTable *t, EditType et, const QString &s, const QString &secondSortKey); QString entryKey() const; @@ -61,15 +63,15 @@ class AbTable : public QTable Q_OBJECT public: AbTable( const QValueList<int> *ordered, QWidget *parent, const char *name=0 ); ~AbTable(); // NEW - void addEntry( const Contact &newContact ); - Contact currentEntry(); - void replaceCurrentEntry( const Contact &newContact ); + void addEntry( const OContact &newContact ); + OContact currentEntry(); + void replaceCurrentEntry( const OContact &newContact ); void init(); void deleteCurrentEntry(); void clear(); void clearFindRow() { currFindRow = -2; } @@ -80,21 +82,24 @@ public: // addresspicker mode void setChoiceNames( const QStringList& list); QStringList choiceNames() const; void setChoiceSelection(int index, const QStringList& list); QStringList choiceSelection(int index) const; - void setShowCategory( const QString &c ); + void setShowCategory( const QString &b, const QString &c ); void setShowByLetter( char c ); QString showCategory() const; QStringList categories(); - void resizeRows( int size ); + + void resizeRows(); void show(); void setPaintingEnabled( bool e ); + QString showBook() const; + public slots: void slotDoFind( const QString &str, bool caseSensitive, bool backwards, int category ); signals: void empty( bool ); void details(); @@ -116,28 +121,33 @@ protected slots: void rowHeightChanged( int row ); private: void loadFile( const QString &strFile, bool journalFile ); void fitColumns(); void resort(); - void updateJournal( const Contact &contact, Contact::journal_action action, + void updateJournal( const OContact &contact, OContact::journal_action action, int row = -1 ); - void insertIntoTable( const Contact &contact, int row ); - void internalAddEntries( QList<Contact> &list ); - QString findContactName( const Contact &entry ); - QString findContactContact( const Contact &entry ); - void journalFreeReplace( const Contact &cnt, int row ); + void insertIntoTable( const OContact &contact, int row ); + QString findContactName( const OContact &entry ); + QString findContactContact( const OContact &entry, int row ); + void journalFreeReplace( const OContact &cnt, int row ); void journalFreeRemove( int row ); void realignTable( int ); void updateVisible(); int lastSortCol; bool asc; char showChar; - QMap<AbTableItem*, Contact> contactList; + QMap<AbTableItem*, OContact> contactList; const QValueList<int> *intFields; int currFindRow; QString showCat; QStringList choicenames; bool enablePainting; Categories mCat; + + QString showBk; + bool columnVisible; + + OContactAccess m_contactdb; + }; #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 @@ ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** -** Contact info@trolltech.com if any conditions of this licensing are +** OContact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #define QTOPIA_INTERNAL_FD @@ -92,12 +92,14 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, WFlags f ) : QMainWindow( parent, name, f ), abEditor(0), bAbEditFirstTime(TRUE), syncing(FALSE) { + isLoading = true; + initFields(); setCaption( tr("Contacts") ); setIcon( Resource::loadPixmap( "AddressBook" ) ); setToolBarsMovable( FALSE ); @@ -184,13 +186,12 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE ); actionPersonal = a; connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); a->addTo( edit ); - edit->insertSeparator(); a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); actionPersonal = a; connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); a->addTo( edit ); @@ -204,32 +205,31 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, // This is safe to call without checking to see if it exists... // not to mention it also does the necessary stuff for the // journaling... QString str = addressbookXMLFilename(); if ( str.isNull() ) { - QMessageBox::warning( this, tr("Out of Space"), + QMessageBox::warning( + this, + tr("Out of Space"), tr("There is not enough space to create\n" "neccessary startup files.\n" "\nFree up some space before\nentering data!") ); } listContainer = new QWidget( this ); QVBoxLayout *vb = new QVBoxLayout( listContainer ); abList = new AbTable( &orderedFields, listContainer, "table" ); vb->addWidget(abList); - abList->setHScrollBarMode( QScrollView::AlwaysOff ); - connect( abList, SIGNAL( empty( bool ) ), - this, SLOT( listIsEmpty( bool ) ) ); - connect( abList, SIGNAL( details() ), - this, SLOT( slotListView() ) ); - connect( abList, SIGNAL(currentChanged(int,int)), - this, SLOT(slotUpdateToolbar()) ); + // abList->setHScrollBarMode( QScrollView::AlwaysOff ); + connect( abList, SIGNAL( empty( bool ) ), this, SLOT( listIsEmpty( bool ) ) ); + connect( abList, SIGNAL( details() ), this, SLOT( slotListView() ) ); + connect( abList, SIGNAL(currentChanged(int,int)), this, SLOT(slotUpdateToolbar()) ); mView = 0; abList->load( addressbookXMLFilename() ); if ( QFile::exists(addressbookOldXMLFilename()) ) { abList->load( addressbookOldXMLFilename() ); @@ -242,13 +242,13 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, catMenu = new QPopupMenu( this ); catMenu->setCheckable( TRUE ); connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); populateCategories(); mbList->insertItem( tr("View"), catMenu ); - setCentralWidget( listContainer ); + // setCentralWidget( listContainer ); fontMenu = new QPopupMenu(this); fontMenu->setCheckable( true ); connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); fontMenu->insertItem(tr( "Small" ), 0); @@ -260,12 +260,16 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, slotSetFont(startFontSize); mbList->insertItem( tr("Font"), fontMenu); setCentralWidget(listContainer); // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); + + abList->setCurrentCell( 0, 0 ); + + isLoading = false; } void AddressbookWindow::slotSetFont( int size ) { if (size > 2 || size < 0) @@ -279,29 +283,32 @@ void AddressbookWindow::slotSetFont( int size ) { case 0: fontMenu->setItemChecked(0, true); fontMenu->setItemChecked(1, false); fontMenu->setItemChecked(2, false); abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); currentFont = new QFont (abList->font()); - abList->resizeRows(currentFont->pixelSize() + 7); + // abList->resizeRows(currentFont->pixelSize() + 7); + abList->resizeRows(); break; case 1: fontMenu->setItemChecked(0, false); fontMenu->setItemChecked(1, true); fontMenu->setItemChecked(2, false); abList->setFont( *defaultFont ); currentFont = new QFont (abList->font()); - abList->resizeRows(currentFont->pixelSize() + 7); + // abList->resizeRows(currentFont->pixelSize() + 7); + abList->resizeRows(); break; case 2: fontMenu->setItemChecked(0, false); fontMenu->setItemChecked(1, false); fontMenu->setItemChecked(2, true); abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); currentFont = new QFont (abList->font()); - abList->resizeRows(currentFont->pixelSize() + 7); + //abList->resizeRows(currentFont->pixelSize() + 7); + abList->resizeRows(); break; } } @@ -311,16 +318,17 @@ void AddressbookWindow::importvCard() { setDocument((const QString&) str ); } void AddressbookWindow::setDocument( const QString &filename ) { - if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; + if ( filename.find(".vcf") != int(filename.length()) - 4 ) + return; - QValueList<Contact> cl = Contact::readVCard( filename ); - for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { + QValueList<OContact> cl = OContact::readVCard( filename ); + for( QValueList<OContact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") // .arg( (*it).fullName() ); // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == // QMessageBox::Ok ) { abList->addEntry( *it ); // } @@ -344,23 +352,36 @@ AddressbookWindow::~AddressbookWindow() cfg.setGroup("Font"); cfg.writeEntry("fontSize", startFontSize); } void AddressbookWindow::slotUpdateToolbar() { - Contact ce = abList->currentEntry(); + OContact ce = abList->currentEntry(); actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); } void AddressbookWindow::showList() { - if ( mView ) mView->hide(); + bool visiblemView; + + visiblemView = false; + if ( mView ) { + mView->hide(); + visiblemView = true; + } setCentralWidget( listContainer ); listContainer->show(); // update our focues... (or use a stack widget!); abList->setFocus(); + + // This makes sure we are scrolled all the way to the left + abList->setContentsPos( 0, abList->contentsY() ); + + //if ( visiblemView && abList->showBook() == "Cards" ) + // abList->setShowCategory( abList->showBook(), abList->showCategory() ); + } void AddressbookWindow::showView() { if ( abList->numRows() > 0 ) { listContainer->hide(); @@ -369,20 +390,20 @@ void AddressbookWindow::showView() mView->setFocus(); } } void AddressbookWindow::slotListNew() { - Contact cnt; + OContact cnt; if( !syncing ) { if ( abEditor ) abEditor->setEntry( cnt ); abView()->init( cnt ); editEntry( NewEntry ); } else { - QMessageBox::warning(this, tr("Contacts"), + QMessageBox::warning(this, tr("OContacts"), tr("Can not edit data, currently syncing")); } } void AddressbookWindow::slotListView() { @@ -391,13 +412,13 @@ void AddressbookWindow::slotListView() showView(); } void AddressbookWindow::slotListDelete() { if(!syncing) { - Contact tmpEntry = abList->currentEntry(); + OContact tmpEntry = abList->currentEntry(); // get a name, do the best we can... QString strName = tmpEntry.fullName(); if ( strName.isEmpty() ) { strName = tmpEntry.company(); if ( strName.isEmpty() ) @@ -438,38 +459,35 @@ void AddressbookWindow::slotViewEdit() } void AddressbookWindow::writeMail() { - Contact c = abList->currentEntry(); + OContact c = abList->currentEntry(); QString name = c.fileAs(); QString email = c.defaultEmail(); QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); e << name << email; } - - - static const char * beamfile = "/tmp/obex/contact.vcf"; void AddressbookWindow::slotBeam() { QString filename; - Contact c; + OContact c; if ( actionPersonal->isOn() ) { filename = addressbookPersonalVCardName(); if (!QFile::exists(filename)) return; // can't beam a non-existent file - c = Contact::readVCard( filename )[0]; + c = OContact::readVCard( filename )[0]; } else { unlink( beamfile ); // delete if exists c = abList->currentEntry(); mkdir("/tmp/obex/", 0755); - Contact::writeVCard( beamfile, c ); + OContact::writeVCard( beamfile, c ); filename = beamfile; } Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); QString description = c.fullName(); ir->send( filename, description, "text/x-vCard" ); @@ -519,13 +537,13 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) close(); } else if ( msg == "addContact(QString,QString)" ) { QDataStream stream(data,IO_ReadOnly); QString name, email; stream >> name >> email; - Contact cnt; + OContact cnt; QString fn, mn, ln; parseName( name, &fn, &mn, &ln ); // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); cnt.setFirstName( fn ); cnt.setMiddleName( mn ); cnt.setLastName( ln ); @@ -578,15 +596,15 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) } void AddressbookWindow::editPersonal() { QString filename = addressbookPersonalVCardName(); - Contact me; + OContact me; if (QFile::exists(filename)) - me = Contact::readVCard( filename )[0]; + me = OContact::readVCard( filename )[0]; if (bAbEditFirstTime) { abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, this, "editor" ); // don't create a new editor every time bAbEditFirstTime = FALSE; } else @@ -596,15 +614,15 @@ void AddressbookWindow::editPersonal() abEditor->showMaximized(); // fix the foxus... abEditor->setNameFocus(); if ( abEditor->exec() ) { setFocus(); - Contact new_personal = abEditor->entry(); + OContact new_personal = abEditor->entry(); QString fname = addressbookPersonalVCardName(); - Contact::writeVCard( fname, new_personal ); + OContact::writeVCard( fname, new_personal ); abView()->init(new_personal); abView()->sync(); } abEditor->setCaption( tr("Edit Address") ); } @@ -630,27 +648,27 @@ void AddressbookWindow::slotPersonalView() actionFind->setEnabled(FALSE); #endif actionMail->setEnabled(FALSE); setCaption( tr("Contacts - My Personal Details") ); QString filename = addressbookPersonalVCardName(); - Contact me; + OContact me; if (QFile::exists(filename)) - me = Contact::readVCard( filename )[0]; + me = OContact::readVCard( filename )[0]; abView()->init( me ); abView()->sync(); listContainer->hide(); setCentralWidget( abView() ); mView->show(); mView->setFocus(); } void AddressbookWindow::editEntry( EntryMode entryMode ) { - Contact entry; + OContact entry; if ( bAbEditFirstTime ) { abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, this, "editor" ); bAbEditFirstTime = FALSE; if ( entryMode == EditEntry ) abEditor->setEntry( abList->currentEntry() ); @@ -663,17 +681,17 @@ void AddressbookWindow::editEntry( EntryMode entryMode ) #endif // fix the foxus... abEditor->setNameFocus(); if ( abEditor->exec() ) { setFocus(); if ( entryMode == NewEntry ) { - Contact insertEntry = abEditor->entry(); + OContact insertEntry = abEditor->entry(); insertEntry.assignUid(); abList->addEntry( insertEntry ); } else { - Contact replaceEntry = abEditor->entry(); + OContact replaceEntry = abEditor->entry(); if ( !replaceEntry.isValidUid() ) replaceEntry.assignUid(); abList->replaceCurrentEntry( replaceEntry ); } } populateCategories(); @@ -721,12 +739,13 @@ void AddressbookWindow::closeEvent( QCloseEvent *e ) at the start of the sync, so there is no need to save Saving however itself would cause problems. */ e->accept(); return; } //################## shouldn't always save + // True, but the database handles this automatically ! (se) if ( save() ) e->accept(); else e->ignore(); } @@ -789,20 +808,19 @@ void AddressbookWindow::slotSettings() void AddressbookWindow::initFields() { // we really don't need the things from the configuration, anymore // only thing that is important are the important categories. So, // Call the contact functions that correspond to these old functions... - QStringList xmlFields = Contact::fields(); - QStringList visibleFields = Contact::trfields(); + QStringList xmlFields = OContact::fields(); + QStringList visibleFields = OContact::trfields(); xmlFields.remove( "Title" ); visibleFields.remove( tr("Name Title") ); visibleFields.remove( tr("Notes") ); - int i, - version; + int i, version; Config cfg( "AddressBook" ); QString zn; // ### Write a function to keep this from happening again... QStringList::ConstIterator it; for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) { @@ -880,13 +898,13 @@ void AddressbookWindow::initFields() AbLabel *AddressbookWindow::abView() { if ( !mView ) { mView = new AbLabel( this, "viewer" ); - mView->init( Contact() ); + mView->init( OContact() ); connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); } return mView; } void AddressbookWindow::slotFind() @@ -908,52 +926,105 @@ void AddressbookWindow::slotFind() abList->clearFindRow(); #endif } void AddressbookWindow::slotSetCategory( int c ) { + + QString cat, book; + if ( c <= 0 ) return; - for ( unsigned int i = 1; i < catMenu->count(); i++ ) + + // Checkmark Book Menu Item Selected + if ( c < 6 ) + for ( unsigned int i = 1; i < 6; i++ ) catMenu->setItemChecked( i, c == (int)i ); - if ( c == 1 ) { - abList->setShowCategory( QString::null ); - setCaption( tr("Contacts") + " - " + tr ( "All" ) ); - } else if ( c == (int)catMenu->count() ) { - abList->setShowCategory( tr( "Unfiled" ) ); - setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) ); - } else { - QString cat = abList->categories()[c - 2]; - abList->setShowCategory( cat ); - setCaption( tr("Contacts") + " - " + cat ); + + // Checkmark Category Menu Item Selected + else + for ( unsigned int i = 6; i < catMenu->count(); i++ ) + catMenu->setItemChecked( i, c == (int)i ); + + for ( unsigned int i = 1; i < catMenu->count(); i++ ) { + if (catMenu->isItemChecked( i )) { + if ( i == 1 ) // default List view + book = QString::null; + else if ( i == 2 ) + book = "Phone"; + else if ( i == 3 ) + book = "Company"; + else if ( i == 4 ) + book = "Email"; + else if ( i == 5 ) + book = "Cards"; + else if ( i == 6 ) // default All Categories + cat = QString::null; + else if ( i == (unsigned int)catMenu->count() ) // last menu option will be Unfiled + cat = "Unfiled"; + else + cat = abList->categories()[i - 7]; } } + abList->setShowCategory( book, cat ); + + if ( book.isEmpty() ) + book = "List"; + if ( cat.isEmpty() ) + cat = "All"; + + setCaption( tr( "Contacts" ) + " - " + tr( book ) + " - " + tr( cat ) ); +} + void AddressbookWindow::slotSetLetter( char c ) { abList->setShowByLetter( c ); } void AddressbookWindow::populateCategories() { catMenu->clear(); - int id, - rememberId; + int id, rememberId; id = 1; rememberId = 0; + + catMenu->insertItem( tr( "List" ), id++ ); + catMenu->insertItem( tr( "Phone Book" ), id++ ); + catMenu->insertItem( tr( "Company Book" ), id++ ); + catMenu->insertItem( tr( "Email Book" ), id++ ); + catMenu->insertItem( tr( "Cards" ), id++ ); + catMenu->insertSeparator(); + catMenu->insertItem( tr( "All" ), id++ ); QStringList categories = abList->categories(); categories.append( tr( "Unfiled" ) ); for ( QStringList::Iterator it = categories.begin(); it != categories.end(); ++it ) { catMenu->insertItem( *it, id ); if ( *it == abList->showCategory() ) rememberId = id; ++id; } - if ( abList->showCategory().isEmpty() ) - slotSetCategory( 1 ); - else + + if ( abList->showBook().isEmpty() ) { + catMenu->setItemChecked( 1, true ); + } else if ( abList->showBook() == "Phone" ) { + catMenu->setItemChecked( 2, true ); + } else if ( abList->showBook() == "Company" ) { + catMenu->setItemChecked( 3, true ); + } else if ( abList->showBook() == "Email" ) { + catMenu->setItemChecked( 4, true ); + } else if ( abList->showBook() == "Cards" ) { + catMenu->setItemChecked( 5, true ); + } + + if ( abList->showCategory().isEmpty() ) { + slotSetCategory( 6 ); + } + else { slotSetCategory( rememberId ); } +} + 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: void beamDone( Ir * ); void slotFind(); void slotSetCategory( int ); void slotSetLetter( char ); void slotUpdateToolbar(); void slotSetFont(int); + private: void initFields(); // inititialize our fields... AbLabel *abView(); void populateCategories(); QPopupMenu *catMenu, *fontMenu; QPEToolBar *listTools; QToolButton *deleteButton; - QValueList<int> allFields, - orderedFields; + QValueList<int> allFields, orderedFields; QStringList slOrderedFields; enum Panes { paneList=0, paneView, paneEdit }; ContactEditor *abEditor; AbLabel *mView; LetterPicker *pLabel; AbTable *abList; QWidget *listContainer; - QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, - *actionPersonal, *actionMail; + QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, *actionPersonal, *actionMail; bool bAbEditFirstTime; int viewMargin; bool syncing; QFont *defaultFont; int startFontSize; + + bool isLoading; }; #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, QString &strAll ); // helper convert from file format to comma delimited... void parseEmailTo( const QString &strDefaultEmail, const QString &strOtherEmail, QString &strBack ); -ContactEditor::ContactEditor( const Contact &entry, +ContactEditor::ContactEditor( const OContact &entry, const QValueList<int> *newOrderedValues, QStringList *slNewOrdered, QWidget *parent, const char *name, WFlags fl ) : QDialog( parent, name, TRUE, fl ), @@ -1289,13 +1289,13 @@ void ContactEditor::cleanupFields() { txtTmp->setText(""); txtTmp = cmbFileAs->lineEdit(); txtTmp->setText(""); } -void ContactEditor::setEntry( const Contact &entry ) { +void ContactEditor::setEntry( const OContact &entry ) { cleanupFields(); ent = entry; 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 @@ * */ #ifndef CONTACTEDITOR_H #define CONTACTEDITOR_H -#include <qpe/contact.h> +#include <opie/ocontact.h> #include <qdialog.h> #include <qlist.h> #include <qmap.h> #include <qstringlist.h> @@ -49,27 +49,27 @@ class CategorySelect; class QLabel; class ContactEditor : public QDialog { Q_OBJECT public: - ContactEditor( const Contact &entry, + ContactEditor( const OContact &entry, const QValueList<int> *newOrderedValues, QStringList *slNewOrdered, QWidget *parent = 0, const char *name = 0, WFlags fl = 0 ); ~ContactEditor(); void loadFields(); void setNameFocus(); - Contact entry() const { return ent; } + OContact entry() const { return ent; } public slots: void slotNote(); void slotName(); - void setEntry(const Contact &entry); + void setEntry(const OContact &entry); protected slots: void accept(); private: void init(); @@ -98,13 +98,13 @@ class ContactEditor : public QDialog { void slotCountryChange( const QString &textChanged ); void slotFullNameChange( const QString &textChanged ); private: bool useFullName, hasGender, hasTitle, hasCompany, hasNotes, hasStreet, hasStreet2, hasPOBox, hasCity, hasState, hasZip, hasCountry; - Contact ent; + OContact ent; QDialog *dlgNote; QDialog *dlgName; QList<QLineEdit> listValue; QList<QLabel> listName; |