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 @@ -51,7 +51,7 @@ void parseEmailTo( const QString &strDefaultEmail, -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 ), @@ -182,7 +182,7 @@ void AbEditor::loadFields() } } -void AbEditor::setEntry( const Contact &entry ) +void AbEditor::setEntry( const OContact &entry ) { ent = entry; QListIterator<QLineEdit> it( listValue ); @@ -549,6 +549,7 @@ void parseEmailFrom( const QString &txt, QString &strDefaultEmail, start; if ( txt.isEmpty() ) return; + // find the first where = txt.find( ',' ); if ( where < 0 ) { 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 @@ -38,17 +38,17 @@ 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(); @@ -63,7 +63,7 @@ private: QDialog *dlgNote; QLabel *lblNote; QMultiLineEdit *txtNote; - Contact ent; + OContact ent; QScrollView *svPage; QLineEdit *firstEdit; QLineEdit *lastEdit; 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 @@ -34,7 +34,7 @@ AbLabel::~AbLabel() { } -void AbLabel::init( const Contact &entry ) +void AbLabel::init( const OContact &entry ) { ent = entry; } 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 @@ -20,7 +20,7 @@ #ifndef ABLABEL_H #define ABLABEL_H -#include <qpe/contact.h> +#include <opie/ocontact.h> #include <qtextview.h> class AbLabel : public QTextView @@ -32,7 +32,7 @@ public: ~AbLabel(); public slots: - void init( const Contact &entry ); + void init( const OContact &entry ); void sync(); signals: @@ -42,7 +42,7 @@ protected: void keyPressEvent( QKeyEvent * ); private: - Contact ent; + OContact ent; }; 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 @@ -25,10 +25,13 @@ #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" @@ -39,16 +42,7 @@ #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 ); /*! @@ -135,7 +129,8 @@ AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *nam asc( TRUE ), intFields( order ), currFindRow( -2 ), - mCat( 0 ) + mCat( 0 ), + m_contactdb ("addressbook") { mCat.load( categoryFileName() ); setSelectionMode( NoSelection ); @@ -159,6 +154,7 @@ void AbTable::init() horizontalHeader()->setLabel( 1, tr( "Contact" )); setLeftMargin( 0 ); verticalHeader()->hide(); + columnVisible = true; } void AbTable::columnClicked( int col ) @@ -175,6 +171,7 @@ void AbTable::columnClicked( int col ) lastSortCol = col; asc = TRUE; } + //QMessageBox::information( this, "resort", "columnClicked" ); resort(); } @@ -184,38 +181,35 @@ void AbTable::resort() 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. @@ -224,6 +218,7 @@ void AbTable::deleteCurrentEntry() if ( numRows() == 0 ) emit empty( TRUE ); + } void AbTable::clear() @@ -244,9 +239,15 @@ 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(); @@ -303,7 +304,7 @@ void AbTable::moveTo( char c ) } -QString AbTable::findContactName( const Contact &entry ) +QString AbTable::findContactName( const OContact &entry ) { // We use the fileAs, then company, defaultEmail QString str; @@ -317,7 +318,7 @@ QString AbTable::findContactName( const Contact &entry ) return str; } -QString AbTable::findContactContact( const Contact &entry ) +QString AbTable::findContactContact( const OContact &entry, int /* row */ ) { QString value; value = ""; @@ -443,305 +444,65 @@ QString AbTable::findContactContact( const Contact &entry ) 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, @@ -761,13 +522,14 @@ void AbTable::realignTable( int row ) 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); @@ -782,51 +544,59 @@ void AbTable::insertIntoTable( const Contact &cnt, int row ) // 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 @@ -867,8 +637,7 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, if ( currFindRow < -1 ) currFindRow = currentRow() - 1; clearSelection( TRUE ); - int rows, - row; + int rows, row; AbTableItem *ati; QRegExp r( findString ); r.setCaseSensitive( caseSensitive ); @@ -879,13 +648,14 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, 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; } } @@ -912,7 +682,7 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, } } -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; @@ -930,16 +700,29 @@ static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) } } } + 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() @@ -983,14 +766,14 @@ 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); } @@ -1004,7 +787,7 @@ QStringList AbTable::choiceSelection(int /*index*/) const 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); } @@ -1014,10 +797,15 @@ QStringList AbTable::choiceSelection(int /*index*/) const 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 ) @@ -1031,6 +819,10 @@ QString AbTable::showCategory() const return showCat; } +QString AbTable::showBook() const +{ + return showBk; +} QStringList AbTable::categories() { @@ -1049,7 +841,7 @@ void AbTable::updateVisible() row; bool hide; AbTableItem *ati; - Contact *cnt; + OContact *cnt; QString fileAsName; QString tmpStr; visible = 0; 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 @@ -22,13 +22,15 @@ #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: @@ -64,9 +66,9 @@ 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(); @@ -83,15 +85,18 @@ public: 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 ); @@ -119,25 +124,30 @@ 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 @@ -13,7 +13,7 @@ ** ** 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. ** **********************************************************************/ @@ -95,6 +95,8 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, bAbEditFirstTime(TRUE), syncing(FALSE) { + isLoading = true; + initFields(); setCaption( tr("Contacts") ); @@ -187,7 +189,6 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, 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 ); @@ -207,7 +208,9 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, // 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!") @@ -220,13 +223,10 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, 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; @@ -245,7 +245,7 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, populateCategories(); mbList->insertItem( tr("View"), catMenu ); - setCentralWidget( listContainer ); + // setCentralWidget( listContainer ); fontMenu = new QPopupMenu(this); fontMenu->setCheckable( true ); @@ -263,6 +263,10 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, setCentralWidget(listContainer); // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); + + abList->setCurrentCell( 0, 0 ); + + isLoading = false; } @@ -282,7 +286,8 @@ void AddressbookWindow::slotSetFont( int size ) { 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); @@ -290,7 +295,8 @@ void AddressbookWindow::slotSetFont( int size ) { 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); @@ -298,7 +304,8 @@ void AddressbookWindow::slotSetFont( int size ) { 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; } } @@ -314,10 +321,11 @@ void AddressbookWindow::importvCard() { 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 ) == @@ -347,17 +355,30 @@ AddressbookWindow::~AddressbookWindow() 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() @@ -372,14 +393,14 @@ void AddressbookWindow::showView() 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")); } } @@ -394,7 +415,7 @@ void AddressbookWindow::slotListView() 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(); @@ -441,32 +462,29 @@ 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 ); @@ -522,7 +540,7 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) 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() ); @@ -581,9 +599,9 @@ 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" ); @@ -599,9 +617,9 @@ void AddressbookWindow::editPersonal() 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(); } @@ -633,9 +651,9 @@ void AddressbookWindow::slotPersonalView() 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(); @@ -647,7 +665,7 @@ void AddressbookWindow::slotPersonalView() void AddressbookWindow::editEntry( EntryMode entryMode ) { - Contact entry; + OContact entry; if ( bAbEditFirstTime ) { abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, this, "editor" ); @@ -666,11 +684,11 @@ void AddressbookWindow::editEntry( EntryMode entryMode ) 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 ); @@ -724,6 +742,7 @@ void AddressbookWindow::closeEvent( QCloseEvent *e ) return; } //################## shouldn't always save + // True, but the database handles this automatically ! (se) if ( save() ) e->accept(); else @@ -792,14 +811,13 @@ void AddressbookWindow::initFields() // 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; @@ -883,7 +901,7 @@ 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; @@ -911,23 +929,53 @@ void AddressbookWindow::slotFind() 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 ); @@ -938,10 +986,17 @@ 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" ) ); @@ -952,8 +1007,24 @@ void AddressbookWindow::populateCategories() 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 @@ -76,6 +76,7 @@ private slots: void slotSetLetter( char ); void slotUpdateToolbar(); void slotSetFont(int); + private: void initFields(); // inititialize our fields... AbLabel *abView(); @@ -84,8 +85,7 @@ private: 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; @@ -94,8 +94,7 @@ private: AbTable *abList; QWidget *listContainer; - QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, - *actionPersonal, *actionMail; + QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, *actionPersonal, *actionMail; bool bAbEditFirstTime; int viewMargin; @@ -103,6 +102,8 @@ private: 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 @@ -49,7 +49,7 @@ void parseEmailFrom( const QString &txt, QString &strDefaultEmail, 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, @@ -1292,7 +1292,7 @@ void ContactEditor::cleanupFields() { } -void ContactEditor::setEntry( const Contact &entry ) { +void ContactEditor::setEntry( const OContact &entry ) { cleanupFields(); 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 @@ -21,7 +21,7 @@ #ifndef CONTACTEDITOR_H #define CONTACTEDITOR_H -#include <qpe/contact.h> +#include <opie/ocontact.h> #include <qdialog.h> #include <qlist.h> @@ -52,7 +52,7 @@ class ContactEditor : public QDialog { Q_OBJECT public: - ContactEditor( const Contact &entry, + ContactEditor( const OContact &entry, const QValueList<int> *newOrderedValues, QStringList *slNewOrdered, QWidget *parent = 0, @@ -61,12 +61,12 @@ class ContactEditor : public QDialog { ~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(); @@ -101,7 +101,7 @@ class ContactEditor : public QDialog { private: bool useFullName, hasGender, hasTitle, hasCompany, hasNotes, hasStreet, hasStreet2, hasPOBox, hasCity, hasState, hasZip, hasCountry; - Contact ent; + OContact ent; QDialog *dlgNote; QDialog *dlgName; |