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 @@ -42,25 +42,25 @@ static inline bool constainsWhiteSpace( const QString &str ); // helper functions, convert our comma delimited list to proper // file format... 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 ); -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 ) { init(); initMap(); setEntry( entry ); } AbEditor::~AbEditor() @@ -173,25 +173,25 @@ void AbEditor::initMap() */ } void AbEditor::loadFields() { QStringList::ConstIterator it; 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") ); // ### Fix... QValueList<int>::ConstIterator itVl; for ( itVl = orderedValues->begin(); *it && itVl != orderedValues->end(); ++itVl, ++it ) { switch( *itVl ) { @@ -540,24 +540,25 @@ void AbEditor::slotNote() void AbEditor::setNameFocus() { firstEdit->setFocus(); } 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 { strDefaultEmail = txt.left( where ).stripWhiteSpace(); strAll = strDefaultEmail; while ( where > -1 ) { strAll.append(" "); start = where; where = txt.find( ',', where + 1 ); 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 @@ -29,50 +29,50 @@ class QScrollView; class QMultiLineEdit; class QLineEdit; class QLabel; 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(); void initMap(); void saveEntry(); 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; QList<QLabel> listName; const QValueList<int> *orderedValues; QStringList *slOrdered; CategorySelect *cmbCat; }; 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 @@ -25,25 +25,25 @@ #include <qregexp.h> #include <qstylesheet.h> AbLabel::AbLabel( QWidget *parent, const char *name ) : QTextView( parent, name ) { } AbLabel::~AbLabel() { } -void AbLabel::init( const Contact &entry ) +void AbLabel::init( const OContact &entry ) { ent = entry; } void AbLabel::sync() { QString text = ent.toRichText(); setText( text ); } void AbLabel::keyPressEvent( QKeyEvent *e ) { 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 @@ -11,40 +11,40 @@ ** 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 ** 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 @@ -16,48 +16,42 @@ ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #define QTOPIA_INTERNAL_CONTACT_MRE #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 */ AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, const QString &secondSortKey) : QTableItem( t, et, s ) { @@ -126,136 +120,143 @@ void AbPickItem::setContentFromEditor( QWidget *w ) */ AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *name ) // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR // : QTable( 0, 0, parent, name, TRUE ), // #else : 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 &)), this, SLOT(itemClicked(int,int)) ); } AbTable::~AbTable() { } void AbTable::init() { showChar = '\0'; setNumRows( 0 ); 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; if ( lastSortCol == -1 ) lastSortCol = 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 ) { for ( int c = 0; c < numCols(); ++c ) { if ( cellWidget( r, c ) ) clearCellWidget( r, c ); clearCell( r, c ); } } setNumRows( 0 ); } 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 ) { char key = toupper( e->ascii() ); if ( key >= 'A' && key <= 'Z' ) moveTo( key ); @@ -294,39 +295,39 @@ void AbTable::moveTo( char c ) abi = static_cast<AbTableItem*>( item(r, 0) ); QChar first = abi->key()[0]; //### is there a bug in QChar to char comparison??? if ( first.row() || first.cell() >= c ) break; r--; } } 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(); if ( str.isEmpty() ) { 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 ) { default: break; case Qtopia::Title: value = entry.title(); break; case Qtopia::Suffix: @@ -434,408 +435,177 @@ QString AbTable::findContactContact( const Contact &entry ) value = entry.children(); break; case Qtopia::Notes: value = entry.notes(); break; } 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++ ) { // the same info from the todo list still applies, but I // don't think it is _too_ bad. ti1 = item( curr + 1, 0 ); ti2 = item( curr + 1, 1 ); takeItem( ti1 ); takeItem( ti2 ); setItem( curr, 0, ti1 ); 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); setItem( row, 1, ati ); //### 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 ) { // Region of the rect we should draw QRegion reg( QRect( cx, cy, cw, ch ) ); // Subtract the table from it reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); // And draw the rectangles (transformed as needed) QArray<QRect> r = reg.rects(); @@ -858,43 +628,43 @@ void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) // int AbTable::rowAt( int pos ) const // { // return QMIN( pos/18, numRows()-1 ); // } 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; else currFindRow = -1; if ( wrapAround ) emit signalWrapAround(); else @@ -903,52 +673,65 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, wrapAround = !wrapAround; } else { currFindRow = row; QTableSelection foundSelection; foundSelection.init( currFindRow, 0 ); foundSelection.expandTo( currFindRow, numCols() - 1 ); 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; if ( (category == -1 && cats.count() == 0) || category == -2 ) returnMe = cnt.match( r ); else { int i; for ( i = 0; i < int(cats.count()); i++ ) { 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(); } void AbTable::setChoiceNames( const QStringList& list) { choicenames = list; if ( choicenames.isEmpty() ) { @@ -974,91 +757,100 @@ void AbTable::itemClicked(int,int col) QStringList AbTable::choiceNames() const { return choicenames; } 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); } */ } 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(); } 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; } void AbTable::updateVisible() { int visible, totalRows, id, totalCats, it, row; bool hide; AbTableItem *ati; - Contact *cnt; + OContact *cnt; QString fileAsName; QString tmpStr; visible = 0; setPaintingEnabled( FALSE ); totalRows = numRows(); id = mCat.id( "Contacts", showCat ); QArray<int> cats; for ( row = 0; row < totalRows; row++ ) { ati = static_cast<AbTableItem*>( item(row, 0) ); cnt = &contactList[ati]; 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 @@ -13,31 +13,33 @@ ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #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; void setEntryKey( const QString & k ); virtual int alignment() const; virtual QString key() const; void setItem( const QString &txt, const QString &secondKey ); private: @@ -55,52 +57,55 @@ public: private: QGuardedPtr<QComboBox> cb; }; 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; } void loadFields(); void refresh(); bool save( const QString &fn ); void load( const QString &fn ); // 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(); void signalNotFound(); void signalWrapAround(); protected: virtual void keyPressEvent( QKeyEvent *e ); @@ -110,34 +115,39 @@ protected: protected slots: void moveTo( char ); virtual void columnClicked( int col ); void itemClicked(int,int col); 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 @@ -4,25 +4,25 @@ ** This file is part of Qt Palmtop Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** 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 #include "contacteditor.h" #include "ablabel.h" #include "abtable.h" #include "addresssettings.h" #include "addressbook.h" @@ -86,24 +86,26 @@ static QString addressbookPersonalVCardName() "businesscard.vcf"); return filename; } 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 ); // Create Toolbars QPEToolBar *bar = new QPEToolBar( this ); bar->setHorizontalStretchable( TRUE ); @@ -178,155 +180,161 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); a->addTo( edit ); a->addTo( listTools ); } edit->insertSeparator(); 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 ); a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); a->addTo( edit ); // Create Views // 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() ); QFile::remove(addressbookOldXMLFilename()); } pLabel = new LetterPicker( listContainer ); connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); vb->addWidget(pLabel); 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); fontMenu->insertItem(tr( "Normal" ), 1); fontMenu->insertItem(tr( "Large" ), 2); defaultFont = new QFont( abList->font() ); 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) size = 1; startFontSize = size; QFont *currentFont; switch (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; } } void AddressbookWindow::importvCard() { QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); if(!str.isEmpty() ) 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 ); // } } } void AddressbookWindow::resizeEvent( QResizeEvent *e ) { @@ -338,72 +346,85 @@ void AddressbookWindow::resizeEvent( QResizeEvent *e ) showView(); } AddressbookWindow::~AddressbookWindow() { Config cfg("AddressBook"); 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(); setCentralWidget( abView() ); mView->show(); 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() { abView()->init( abList->currentEntry() ); mView->sync(); 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() ) strName = "No Name"; } if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), strName ) ) { @@ -432,50 +453,47 @@ void AddressbookWindow::slotViewEdit() editEntry( EditEntry ); } } else { QMessageBox::warning( this, tr("Contacts"), tr("Can not edit data, currently syncing") ); } } 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" ); } void AddressbookWindow::beamDone( Ir *ir ) { delete ir; unlink( beamfile ); @@ -513,25 +531,25 @@ static void parseName( const QString& name, QString *first, QString *middle, void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) { if (msg == "editPersonal()") { editPersonal(); } else if (msg == "editPersonalAndClose()") { editPersonal(); 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 ); cnt.insertEmails( email ); cnt.setDefaultEmail( email ); cnt.setFileAs(); if ( bAbEditFirstTime ) { abEditor = new ContactEditor( cnt, &orderedFields, &slOrderedFields, @@ -572,45 +590,45 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { QStringList sel = picker.selection(i++); e << sel; } } #endif } 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 abEditor->setEntry( me ); abEditor->setCaption(tr("Edit My Personal Details")); 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") ); } void AddressbookWindow::slotPersonalView() { if (!actionPersonal->isOn()) { // we just turned it off setCaption( tr("Contacts") ); actionNew->setEnabled(TRUE); @@ -624,62 +642,62 @@ void AddressbookWindow::slotPersonalView() } // XXX need to disable some QActions. actionNew->setEnabled(FALSE); actionTrash->setEnabled(FALSE); #ifndef MAKE_FOR_SHARP_ROM 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() ); } // other things may chane the caption. abEditor->setCaption( tr("Edit Address") ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) abEditor->showMaximized(); #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(); showList(); } void AddressbookWindow::listIsEmpty( bool empty ) { if ( !empty ) { @@ -715,24 +733,25 @@ void AddressbookWindow::closeEvent( QCloseEvent *e ) return; } if(syncing) { /* shouldn't we save, I hear you say? well its already been set so that an edit can not occur during a sync, and we flushed 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(); } /* Returns TRUE if it is OK to exit */ bool AddressbookWindow::save() { @@ -783,32 +802,31 @@ void AddressbookWindow::slotSettings() abEditor->loadFields(); abList->refresh(); } } 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++ ) { allFields.append( i + 3 ); } cfg.setGroup( "Version" ); version = cfg.readNumEntry( "version" ); i = 0; @@ -874,25 +892,25 @@ void AddressbookWindow::initFields() slOrderedFields.remove( tr("Default Email") ); slOrderedFields.remove( tr("Notes") ); slOrderedFields.remove( tr("Gender") ); } } 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() { #ifndef MAKE_FOR_SHARP_ROM if ( centralWidget() == abView() ) showList(); FindDialog frmFind( "Contacts", this ); @@ -902,58 +920,111 @@ void AddressbookWindow::slotFind() frmFind.exec(); if ( abList->numSelections() ) abList->clearSelection(); 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 @@ -67,42 +67,43 @@ private slots: void slotViewEdit(); void slotPersonalView(); void listIsEmpty( bool ); void slotSettings(); void writeMail(); void slotBeam(); 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 @@ -40,25 +40,25 @@ static inline bool containsAlphaNum( const QString &str ); static inline bool constainsWhiteSpace( const QString &str ); // helper functions, convert our comma delimited list to proper // file format... 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 ), orderedValues( newOrderedValues ), slOrdered( *slNewOrdered ) { init(); initMap(); @@ -1283,25 +1283,25 @@ void ContactEditor::cleanupFields() { //txtAddress2->setText(""); txtCity->setText(""); //txtPOBox->setText(""); txtState->setText(""); txtZip->setText(""); QLineEdit *txtTmp = cmbCountry->lineEdit(); txtTmp->setText(""); txtTmp = cmbFileAs->lineEdit(); txtTmp->setText(""); } -void ContactEditor::setEntry( const Contact &entry ) { +void ContactEditor::setEntry( const OContact &entry ) { cleanupFields(); ent = entry; useFullName = FALSE; txtFirstName->setText( ent.firstName() ); txtMiddleName->setText( ent.middleName() ); txtLastName->setText( ent.lastName() ); txtSuffix->setText( ent.suffix() ); 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 @@ -12,25 +12,25 @@ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * * This is a rewrite of the abeditor.h file, modified to provide a more * intuitive interface to TrollTech's original Address Book editor. This * is made to operate exactly in interface with the exception of name. * */ #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> const int NAME_LF = 0; const int NAME_LFM = 1; const int NAME_FL = 2; const int NAME_FMLS = 3; const int NAME_F = 4; @@ -43,39 +43,39 @@ class QScrollView; class QTabWidget; class QMultiLineEdit; class QLineEdit; class QComboBox; class QPushButton; 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(); void initMap(); void saveEntry(); bool isEmpty(); void cleanupFields(); QString parseName( QString fullName, int type ); @@ -92,25 +92,25 @@ class ContactEditor : public QDialog { void slotAddressChange( const QString &textChanged ); void slotAddress2Change( const QString &textChanged ); void slotPOBoxChange( const QString &textChanged ); void slotCityChange( const QString &textChanged ); void slotStateChange( const QString &textChanged ); void slotZipChange( const QString &textChanged ); 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; const QValueList<int> *orderedValues; QStringList slOrdered; QStringList slDynamicEntries; QStringList slHomeAddress; QStringList slBusinessAddress; |