-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 @@ -52,5 +52,5 @@ 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 ) @@ -183,5 +183,5 @@ void AbEditor::loadFields() } -void AbEditor::setEntry( const Contact &entry ) +void AbEditor::setEntry( const OContact &entry ) { ent = entry; @@ -550,4 +550,5 @@ void parseEmailFrom( const QString &txt, QString &strDefaultEmail, if ( txt.isEmpty() ) return; + // find the first where = txt.find( ',' ); 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 @@ -39,5 +39,5 @@ 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 ); @@ -45,9 +45,9 @@ public: 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: @@ -64,5 +64,5 @@ private: QLabel *lblNote; QMultiLineEdit *txtNote; - Contact ent; + OContact ent; QScrollView *svPage; QLineEdit *firstEdit; 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 @@ -35,5 +35,5 @@ 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 @@ -21,5 +21,5 @@ #define ABLABEL_H -#include <qpe/contact.h> +#include <opie/ocontact.h> #include <qtextview.h> @@ -33,5 +33,5 @@ public: public slots: - void init( const Contact &entry ); + void init( const OContact &entry ); void sync(); @@ -43,5 +43,5 @@ protected: 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 @@ -26,8 +26,11 @@ #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" @@ -40,14 +43,5 @@ #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 ); @@ -136,5 +130,6 @@ AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *nam intFields( order ), currFindRow( -2 ), - mCat( 0 ) + mCat( 0 ), + m_contactdb ("addressbook") { mCat.load( categoryFileName() ); @@ -160,4 +155,5 @@ void AbTable::init() setLeftMargin( 0 ); verticalHeader()->hide(); + columnVisible = true; } @@ -176,4 +172,5 @@ void AbTable::columnClicked( int col ) asc = TRUE; } + //QMessageBox::information( this, "resort", "columnClicked" ); resort(); } @@ -185,26 +182,28 @@ void AbTable::resort() 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 ); + } @@ -212,9 +211,4 @@ 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 @@ -225,4 +219,5 @@ void AbTable::deleteCurrentEntry() if ( numRows() == 0 ) emit empty( TRUE ); + } @@ -245,7 +240,13 @@ void AbTable::refresh() 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() ); } @@ -304,5 +305,5 @@ void AbTable::moveTo( char c ) -QString AbTable::findContactName( const Contact &entry ) +QString AbTable::findContactName( const OContact &entry ) { // We use the fileAs, then company, defaultEmail @@ -318,5 +319,5 @@ QString AbTable::findContactName( const Contact &entry ) } -QString AbTable::findContactContact( const Contact &entry ) +QString AbTable::findContactContact( const OContact &entry, int /* row */ ) { QString value; @@ -444,15 +445,19 @@ QString AbTable::findContactContact( const Contact &entry ) } -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()) { @@ -460,287 +465,43 @@ void AbTable::resizeRows( int size ) { 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 ) { @@ -762,5 +523,6 @@ void AbTable::realignTable( int row ) } -void AbTable::insertIntoTable( const Contact &cnt, int row ) +// Add contact into table. +void AbTable::insertIntoTable( const OContact &cnt, int row ) { QString strName, @@ -768,5 +530,5 @@ void AbTable::insertIntoTable( const Contact &cnt, int row ) strName = findContactName( cnt ); - strContact = findContactContact( cnt ); + strContact = findContactContact( cnt, row ); AbTableItem *ati; @@ -783,18 +545,7 @@ void AbTable::insertIntoTable( const Contact &cnt, int row ) } -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, @@ -803,7 +554,14 @@ void AbTable::journalFreeReplace( const Contact &cnt, int row ) 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 ); @@ -812,12 +570,17 @@ void AbTable::journalFreeReplace( const Contact &cnt, int row ) 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 ) { @@ -826,6 +589,13 @@ void AbTable::journalFreeRemove( int row ) 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 ); + } @@ -868,6 +638,5 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, currFindRow = currentRow() - 1; clearSelection( TRUE ); - int rows, - row; + int rows, row; AbTableItem *ati; QRegExp r( findString ); @@ -880,6 +649,6 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, ati = static_cast<AbTableItem*>( item(row, 0) ); if ( contactCompare( contactList[ati], r, category ) ) + //if ( contactCompare( contactList[row], r, category ) ) break; - } } else { @@ -887,4 +656,5 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, ati = static_cast<AbTableItem*>( item(row, 0) ); if ( contactCompare( contactList[ati], r, category ) ) + //if ( contactCompare( contactList[row], r, category ) ) break; } @@ -913,5 +683,5 @@ 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; @@ -931,4 +701,5 @@ static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) } } + return returnMe; } @@ -936,9 +707,21 @@ static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) 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 ); + } } @@ -984,5 +767,5 @@ 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); @@ -991,5 +774,5 @@ void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) } for (remaining list items) { - Contact *c = new contact(item); + OContact *c = new contact(item); setText(newrow, 2, selname); } @@ -1005,5 +788,5 @@ 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); @@ -1015,8 +798,13 @@ QStringList AbTable::choiceSelection(int /*index*/) const } -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 } @@ -1032,4 +820,8 @@ QString AbTable::showCategory() const } +QString AbTable::showBook() const +{ + return showBk; +} QStringList AbTable::categories() @@ -1050,5 +842,5 @@ void AbTable::updateVisible() bool hide; AbTableItem *ati; - Contact *cnt; + OContact *cnt; QString fileAsName; QString tmpStr; 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 @@ -23,5 +23,5 @@ #include <qpe/categories.h> -#include <qpe/contact.h> +#include <opie/ocontact.h> #include <qmap.h> @@ -30,4 +30,6 @@ #include <qcombobox.h> +#include <opie/ocontactaccess.h> + class AbTableItem : public QTableItem { @@ -65,7 +67,7 @@ public: ~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(); @@ -84,13 +86,16 @@ public: 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, @@ -120,11 +125,10 @@ private: 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 ); @@ -133,5 +137,5 @@ private: bool asc; char showChar; - QMap<AbTableItem*, Contact> contactList; + QMap<AbTableItem*, OContact> contactList; const QValueList<int> *intFields; int currFindRow; @@ -140,4 +144,10 @@ private: 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 @@ -14,5 +14,5 @@ ** 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. ** @@ -96,4 +96,6 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, syncing(FALSE) { + isLoading = true; + initFields(); @@ -188,5 +190,4 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, a->addTo( edit ); - edit->insertSeparator(); @@ -208,5 +209,7 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, 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" @@ -221,11 +224,8 @@ 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; @@ -246,5 +246,5 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, mbList->insertItem( tr("View"), catMenu ); - setCentralWidget( listContainer ); + // setCentralWidget( listContainer ); fontMenu = new QPopupMenu(this); @@ -264,4 +264,8 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); + + abList->setCurrentCell( 0, 0 ); + + isLoading = false; } @@ -283,5 +287,6 @@ void AddressbookWindow::slotSetFont( int size ) { 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: @@ -291,5 +296,6 @@ void AddressbookWindow::slotSetFont( int size ) { abList->setFont( *defaultFont ); currentFont = new QFont (abList->font()); - abList->resizeRows(currentFont->pixelSize() + 7); + // abList->resizeRows(currentFont->pixelSize() + 7); + abList->resizeRows(); break; case 2: @@ -299,5 +305,6 @@ void AddressbookWindow::slotSetFont( int size ) { 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; } @@ -315,8 +322,9 @@ 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() ); @@ -348,5 +356,5 @@ AddressbookWindow::~AddressbookWindow() void AddressbookWindow::slotUpdateToolbar() { - Contact ce = abList->currentEntry(); + OContact ce = abList->currentEntry(); actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); } @@ -354,9 +362,22 @@ void AddressbookWindow::slotUpdateToolbar() 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() ); + } @@ -373,5 +394,5 @@ void AddressbookWindow::showView() void AddressbookWindow::slotListNew() { - Contact cnt; + OContact cnt; if( !syncing ) { if ( abEditor ) @@ -380,5 +401,5 @@ void AddressbookWindow::slotListNew() editEntry( NewEntry ); } else { - QMessageBox::warning(this, tr("Contacts"), + QMessageBox::warning(this, tr("OContacts"), tr("Can not edit data, currently syncing")); } @@ -395,5 +416,5 @@ void AddressbookWindow::slotListDelete() { if(!syncing) { - Contact tmpEntry = abList->currentEntry(); + OContact tmpEntry = abList->currentEntry(); // get a name, do the best we can... @@ -442,5 +463,5 @@ void AddressbookWindow::slotViewEdit() void AddressbookWindow::writeMail() { - Contact c = abList->currentEntry(); + OContact c = abList->currentEntry(); QString name = c.fileAs(); QString email = c.defaultEmail(); @@ -449,7 +470,4 @@ void AddressbookWindow::writeMail() } - - - static const char * beamfile = "/tmp/obex/contact.vcf"; @@ -457,15 +475,15 @@ 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; } @@ -523,5 +541,5 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) stream >> name >> email; - Contact cnt; + OContact cnt; QString fn, mn, ln; parseName( name, &fn, &mn, &ln ); @@ -582,7 +600,7 @@ 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, @@ -600,7 +618,7 @@ void AddressbookWindow::editPersonal() 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(); @@ -634,7 +652,7 @@ 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 ); @@ -648,5 +666,5 @@ void AddressbookWindow::slotPersonalView() void AddressbookWindow::editEntry( EntryMode entryMode ) { - Contact entry; + OContact entry; if ( bAbEditFirstTime ) { abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, @@ -667,9 +685,9 @@ void AddressbookWindow::editEntry( EntryMode entryMode ) 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(); @@ -725,4 +743,5 @@ void AddressbookWindow::closeEvent( QCloseEvent *e ) } //################## shouldn't always save + // True, but the database handles this automatically ! (se) if ( save() ) e->accept(); @@ -793,12 +812,11 @@ void AddressbookWindow::initFields() // 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; @@ -884,5 +902,5 @@ AbLabel *AddressbookWindow::abView() if ( !mView ) { mView = new AbLabel( this, "viewer" ); - mView->init( Contact() ); + mView->init( OContact() ); connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); } @@ -912,21 +930,51 @@ 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 ) { @@ -939,8 +987,15 @@ 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(); @@ -953,7 +1008,23 @@ void AddressbookWindow::populateCategories() ++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 @@ -77,4 +77,5 @@ private slots: void slotUpdateToolbar(); void slotSetFont(int); + private: void initFields(); // inititialize our fields... @@ -85,6 +86,5 @@ private: QPEToolBar *listTools; QToolButton *deleteButton; - QValueList<int> allFields, - orderedFields; + QValueList<int> allFields, orderedFields; QStringList slOrderedFields; enum Panes { paneList=0, paneView, paneEdit }; @@ -95,6 +95,5 @@ private: QWidget *listContainer; - QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, - *actionPersonal, *actionMail; + QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, *actionPersonal, *actionMail; bool bAbEditFirstTime; @@ -104,4 +103,6 @@ private: QFont *defaultFont; int startFontSize; + + bool isLoading; }; 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 @@ -50,5 +50,5 @@ 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, @@ -1293,5 +1293,5 @@ 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 @@ -22,5 +22,5 @@ #define CONTACTEDITOR_H -#include <qpe/contact.h> +#include <opie/ocontact.h> #include <qdialog.h> @@ -53,5 +53,5 @@ class ContactEditor : public QDialog { public: - ContactEditor( const Contact &entry, + ContactEditor( const OContact &entry, const QValueList<int> *newOrderedValues, QStringList *slNewOrdered, @@ -62,10 +62,10 @@ class ContactEditor : public QDialog { 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: @@ -102,5 +102,5 @@ class ContactEditor : public QDialog { bool useFullName, hasGender, hasTitle, hasCompany, hasNotes, hasStreet, hasStreet2, hasPOBox, hasCity, hasState, hasZip, hasCountry; - Contact ent; + OContact ent; QDialog *dlgNote; |