summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/abtable.cpp
Side-by-side diff
Diffstat (limited to 'core/pim/addressbook/abtable.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/addressbook/abtable.cpp444
1 files changed, 118 insertions, 326 deletions
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
@@ -27,2 +27,4 @@
+#include <opie/orecordlist.h>
+
#include <qasciidict.h>
@@ -31,2 +33,3 @@
#include <qregexp.h>
+#include <qmessagebox.h>
@@ -41,12 +44,3 @@
-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 );
@@ -137,3 +131,4 @@ AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *nam
currFindRow( -2 ),
- mCat( 0 )
+ mCat( 0 ),
+ m_contactdb ("addressbook")
{
@@ -161,2 +156,3 @@ void AbTable::init()
verticalHeader()->hide();
+ columnVisible = true;
}
@@ -177,2 +173,3 @@ void AbTable::columnClicked( int col )
}
+ //QMessageBox::information( this, "resort", "columnClicked" );
resort();
@@ -186,2 +183,3 @@ void AbTable::resort()
sortColumn( lastSortCol, asc, TRUE );
+ //QMessageBox::information( this, "resort", "resort" );
updateVisible();
@@ -190,5 +188,5 @@ void AbTable::resort()
-Contact AbTable::currentEntry()
+OContact AbTable::currentEntry()
{
- Contact cnt;
+ OContact cnt;
AbTableItem *abItem;
@@ -197,2 +195,3 @@ Contact AbTable::currentEntry()
cnt = contactList[abItem];
+ //cnt = contactList[currentRow()];
}
@@ -201,6 +200,5 @@ Contact AbTable::currentEntry()
-void AbTable::replaceCurrentEntry( const Contact &newContact )
+void AbTable::replaceCurrentEntry( const OContact &newContact )
{
int row = currentRow();
- updateJournal( newContact, Contact::ACTION_REPLACE, row );
updateVisible();
@@ -208,2 +206,3 @@ void AbTable::replaceCurrentEntry( const Contact &newContact )
journalFreeReplace( newContact, row );
+
}
@@ -213,7 +212,2 @@ 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 );
@@ -226,2 +220,3 @@ void AbTable::deleteCurrentEntry()
emit empty( TRUE );
+
}
@@ -246,5 +241,11 @@ void AbTable::refresh()
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() );
@@ -305,3 +306,3 @@ void AbTable::moveTo( char c )
-QString AbTable::findContactName( const Contact &entry )
+QString AbTable::findContactName( const OContact &entry )
{
@@ -319,3 +320,3 @@ QString AbTable::findContactName( const Contact &entry )
-QString AbTable::findContactContact( const Contact &entry )
+QString AbTable::findContactContact( const OContact &entry, int /* row */ )
{
@@ -445,13 +446,17 @@ 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() {
/*
@@ -461,26 +466,9 @@ void AbTable::resizeRows( int 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 */ )
{
@@ -488,51 +476,5 @@ bool AbTable::save( const QString &fn )
// 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;
@@ -540,206 +482,25 @@ bool AbTable::save( const QString &fn )
-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 )
@@ -763,3 +524,4 @@ 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 )
{
@@ -769,3 +531,3 @@ void AbTable::insertIntoTable( const Contact &cnt, int row )
strName = findContactName( cnt );
- strContact = findContactContact( cnt );
+ strContact = findContactContact( cnt, row );
@@ -784,16 +546,5 @@ 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 )
{
@@ -804,5 +555,12 @@ 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 );
@@ -813,3 +571,4 @@ void AbTable::journalFreeReplace( const Contact &cnt, int row )
ati->setItem( strContact, strName );
- }else{
+
+ }else{ // add
int myrows = numRows();
@@ -817,3 +576,6 @@ void AbTable::journalFreeReplace( const Contact &cnt, int row )
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 );
}
@@ -821,2 +583,3 @@ void AbTable::journalFreeReplace( const Contact &cnt, int row )
+// Remove entry
void AbTable::journalFreeRemove( int row )
@@ -827,4 +590,11 @@ void AbTable::journalFreeRemove( int row )
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 );
+
}
@@ -869,4 +639,3 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive,
clearSelection( TRUE );
- int rows,
- row;
+ int rows, row;
AbTableItem *ati;
@@ -881,4 +650,4 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive,
if ( contactCompare( contactList[ati], r, category ) )
+ //if ( contactCompare( contactList[row], r, category ) )
break;
-
}
@@ -888,2 +657,3 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive,
if ( contactCompare( contactList[ati], r, category ) )
+ //if ( contactCompare( contactList[row], r, category ) )
break;
@@ -914,3 +684,3 @@ 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 )
{
@@ -932,2 +702,3 @@ static bool contactCompare( const Contact &cnt, const QRegExp &r, int category )
}
+
return returnMe;
@@ -937,7 +708,19 @@ 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 );
+ }
}
@@ -985,3 +768,3 @@ void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/)
for (each row) {
- Contact *c = contactForRow(row);
+ OContact *c = contactForRow(row);
if ( list.contains(c->email) ) {
@@ -992,3 +775,3 @@ 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);
@@ -1006,3 +789,3 @@ QStringList AbTable::choiceSelection(int /*index*/) const
for (each row) {
- Contact *c = contactForRow(row);
+ OContact *c = contactForRow(row);
if ( text(row,2) == selname ) {
@@ -1016,6 +799,11 @@ 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
}
@@ -1033,2 +821,6 @@ QString AbTable::showCategory() const
+QString AbTable::showBook() const
+{
+ return showBk;
+}
@@ -1051,3 +843,3 @@ void AbTable::updateVisible()
AbTableItem *ati;
- Contact *cnt;
+ OContact *cnt;
QString fileAsName;