author | zautrix <zautrix> | 2004-09-18 18:46:29 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-18 18:46:29 (UTC) |
commit | ec8099bf369e5b8327ca6cfd78b34366353e3abf (patch) (side-by-side diff) | |
tree | 551c515124f7b1c47b2860803efa3922f494f938 | |
parent | 3f16c7aa0ab6badf304c537a6981ece743138821 (diff) | |
download | kdepimpi-ec8099bf369e5b8327ca6cfd78b34366353e3abf.zip kdepimpi-ec8099bf369e5b8327ca6cfd78b34366353e3abf.tar.gz kdepimpi-ec8099bf369e5b8327ca6cfd78b34366353e3abf.tar.bz2 |
More AB sync
-rw-r--r-- | kabc/addresseeview.cpp | 66 | ||||
-rw-r--r-- | kabc/addresseeview.h | 18 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 7 |
3 files changed, 89 insertions, 2 deletions
diff --git a/kabc/addresseeview.cpp b/kabc/addresseeview.cpp index b4717d7..487e8a5 100644 --- a/kabc/addresseeview.cpp +++ b/kabc/addresseeview.cpp @@ -1,129 +1,134 @@ /* This file is part of libkdepim. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <kabc/address.h> #include <kabc/addressee.h> #include <kabc/phonenumber.h> #include <kglobal.h> //US#include <kglobalsettings.h> #include <kiconloader.h> #include <klocale.h> //US #include <kstringhandler.h> #include <qscrollview.h> #include <qregexp.h> #include <qfile.h> +#include <qvbox.h> +#include <qlabel.h> +#include <qwidget.h> +#include <qlayout.h> #include <qapplication.h> +#include <qpushbutton.h> #include "externalapphandler.h" #include "addresseeview.h" //US #ifndef DESKTOP_VERSION //US #include <qtopia/qcopenvelope_qws.h> //US #include <qpe/qpeapplication.h> //US #endif //US static int kphoneInstalled = 0; using namespace KPIM; AddresseeView::AddresseeView( QWidget *parent, const char *name ) //US : KTextBrowser( parent, name ) : QTextBrowser( parent, name ) { //US setWrapPolicy( QTextEdit::AtWordBoundary ); setLinkUnderline( false ); // setVScrollBarMode( QScrollView::AlwaysOff ); //setHScrollBarMode( QScrollView::AlwaysOff ); //US QStyleSheet *sheet = styleSheet(); //US QStyleSheetItem *link = sheet->item( "a" ); //US link->setColor( KGlobalSettings::linkColor() ); } void AddresseeView::setSource(const QString& n) { //qDebug("********AddresseeView::setSource %s", n.latin1()); if ( n.left( 6 ) == "mailto" ) ExternalAppHandler::instance()->mailToOneContact( n.mid(7) ); else if ( n.left( 7 ) == "phoneto" ) ExternalAppHandler::instance()->callByPhone( n.mid(8) ); else if ( n.left( 5 ) == "faxto" ) ExternalAppHandler::instance()->callByFax( n.mid(6) ); else if ( n.left( 5 ) == "smsto" ) ExternalAppHandler::instance()->callBySMS( n.mid(6) ); else if ( n.left( 7 ) == "pagerto" ) ExternalAppHandler::instance()->callByPager( n.mid(8) ); else if ( n.left( 5 ) == "sipto" ) ExternalAppHandler::instance()->callBySIP( n.mid(6) ); } void AddresseeView::setAddressee( const KABC::Addressee& addr ) { ExternalAppHandler* eah = ExternalAppHandler::instance(); bool kemailAvail = eah->isEmailAppAvailable(); bool kphoneAvail = eah->isPhoneAppAvailable(); bool kfaxAvail = eah->isFaxAppAvailable(); bool ksmsAvail = eah->isSMSAppAvailable(); bool kpagerAvail = eah->isPagerAppAvailable(); bool ksipAvail = eah->isSIPAppAvailable(); mAddressee = addr; // clear view setText( QString::null ); if ( mAddressee.isEmpty() ) return; QString name = ( mAddressee.assembledName().isEmpty() ? mAddressee.formattedName() : mAddressee.assembledName() ); QString dynamicPart; QStringList emails = mAddressee.emails(); QStringList::ConstIterator emailIt; QString type = i18n( "Email" ); emailIt = emails.begin(); if ( emailIt != emails.end() ) { if ( kemailAvail ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) .arg( type ) .arg( name ) .arg( *emailIt ) .arg( *emailIt ); ++emailIt; } else { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( type ) .arg( *emailIt ); ++emailIt; } } @@ -306,96 +311,157 @@ void AddresseeView::setAddressee( const KABC::Addressee& addr ) "<td colspan=\"2\"> </td>" "%7" // dynamic part "%8" // notes "</table>" "</body>" "</html>") //US .arg( /*KGlobalSettings::textColor().name()*/ "black" ) //US .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) .arg( picString ) .arg( name ) .arg( aRole ) .arg( aOrga ) .arg( dynamicPart ) .arg( notes ); } else { // no picture! mText = "<table width=\"100%\">\n"; //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; #ifdef DESKTOP_VERSION mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; #else mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>"; #endif #ifdef DESKTOP_VERSION mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>"; #else mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>"; #endif mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; mText += "<table><td colspan=\"2\"> </td>"; /* mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>" "<td align=\"left\"><b>%2</b></td></tr>" ) .arg( i18n(" ") ) .arg( name ); */ if ( ! mAddressee.role().isEmpty() ) mText += QString("<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( i18n(" ") ) .arg( mAddressee.role()); if ( ! mAddressee.organization().isEmpty() ) mText += QString("<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( i18n(" ") ) .arg( mAddressee.organization()); mText += dynamicPart; mText += notes; mText += "</table>"; } // at last display it... setText( mText ); } KABC::Addressee AddresseeView::addressee() const { return mAddressee; } void AddresseeView::addTag(const QString & tag,const QString & text) { if ( text.isEmpty() ) return; int number=text.contains("\n"); QString str = "<" + tag + ">"; QString tmpText=text; QString tmpStr=str; if(number !=-1) { if (number > 0) { int pos=0; QString tmp; for(int i=0;i<=number;i++) { pos=tmpText.find("\n"); tmp=tmpText.left(pos); tmpText=tmpText.right(tmpText.length()-pos-1); tmpStr+=tmp+"<br>"; } } else tmpStr += tmpText; tmpStr+="</" + tag + ">"; mText.append(tmpStr); } else { str += text + "</" + tag + ">"; mText.append(str); } } + +AddresseeChooser::AddresseeChooser( KABC::Addressee loc, KABC::Addressee rem, bool takeloc, QWidget *parent, const char *name ) : KDialogBase(parent,name, + true ,i18n("Conflict! Please choose Adressee!"),Ok|User1|Close,Close, false) +{ + findButton( Close )->setText( i18n("Cancel Sync")); + findButton( Ok )->setText( i18n("Remote")); + findButton( User1 )->setText( i18n("Local")); + QWidget* topframe = new QWidget( this ); + //QVBox* topframe = new QVBox( this ); + setMainWidget( topframe ); + QBoxLayout* bl; + if ( QApplication::desktop()->width() < 640 ) { + bl = new QVBoxLayout( topframe ); + + } else { + bl = new QHBoxLayout( topframe ); + + } + QVBox* subframe = new QVBox( topframe ); + bl->addWidget(subframe ); + QLabel* lab = new QLabel( i18n("Local Addressee"), subframe ); + AddresseeView * av = new AddresseeView( subframe ); + av->setAddressee( loc ); + subframe = new QVBox( topframe ); + bl->addWidget(subframe ); + lab = new QLabel( i18n("Remote Addressee"), subframe ); + av = new AddresseeView( subframe ); + av->setAddressee( rem ); + + QObject::connect(findButton( Ok ),SIGNAL(clicked()), + SLOT(slot_remote())); + QObject::connect(this,SIGNAL(user1Clicked()), + SLOT(slot_local())); +#ifndef DESKTOP_VERSION + showMaximized(); +#else + resize ( 640, 400 ); +#endif +} + +int AddresseeChooser::executeD( bool local ) +{ + mSyncResult = 3; + if ( local ) + findButton( User1 )->setFocus(); + else + findButton( Ok )->setFocus(); + exec(); + qDebug("returning %d ",mSyncResult ); + return mSyncResult; +} +void AddresseeChooser::slot_remote() +{ + mSyncResult = 2; + accept(); +} +void AddresseeChooser::slot_local() +{ + mSyncResult = 1; + accept(); +} diff --git a/kabc/addresseeview.h b/kabc/addresseeview.h index 1865fc4..689d997 100644 --- a/kabc/addresseeview.h +++ b/kabc/addresseeview.h @@ -1,60 +1,78 @@ /* This file is part of libkdepim. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef KPIM_ADDRESSEEVIEW_H #define KPIM_ADDRESSEEVIEW_H #include <kabc/addressee.h> +#include <kdialogbase.h> //US #include <ktextbrowser.h> #include <qtextbrowser.h> namespace KPIM { //US class AddresseeView : public KTextBrowser class AddresseeView : public QTextBrowser { public: AddresseeView( QWidget *parent = 0, const char *name = 0 ); /** Sets the addressee object. The addressee is displayed immediately. @param addr The addressee object. */ void setAddressee( const KABC::Addressee& addr ); void setSource(const QString& n); /** Returns the current addressee object. */ KABC::Addressee addressee() const; private: KABC::Addressee mAddressee; QString mText; void addTag(const QString & tag,const QString & text); class AddresseeViewPrivate; AddresseeViewPrivate *d; }; +class AddresseeChooser : public KDialogBase +{ + Q_OBJECT + + public: + AddresseeChooser( KABC::Addressee loc, KABC::Addressee rem, bool takeloc, QWidget *parent = 0, const char *name = 0 ); + + int executeD( bool local ); + + private: + int mSyncResult; + + private slots: + void slot_remote(); + void slot_local(); + +}; } #endif diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 74c10d2..b1a951c 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2559,265 +2559,268 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i //qDebug("both not changed "); lastSync = local->revision().addDays(1); } else { if ( locCh ) { //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); lastSync = local->revision().addDays( -1 ); if ( !remCh ) remote->setRevision( lastSync.addDays( -1 ) ); } else { //qDebug(" not loc changed "); lastSync = local->revision().addDays( 1 ); if ( remCh ) remote->setRevision( lastSync.addDays( 1 ) ); } } full = true; if ( mode < SYNC_PREF_ASK ) mode = SYNC_PREF_ASK; } else { if ( local->revision() == remote->revision() ) return 0; } // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); //full = true; //debug only if ( full ) { bool equ = ( (*local) == (*remote) ); if ( equ ) { //qDebug("equal "); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); } if ( mode < SYNC_PREF_FORCE_LOCAL ) return 0; }//else //debug only //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); } int result; bool localIsNew; //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); if ( full && mode < SYNC_PREF_NEWEST ) mode = SYNC_PREF_ASK; switch( mode ) { case SYNC_PREF_LOCAL: if ( lastSync > remote->revision() ) return 1; if ( lastSync > local->revision() ) return 2; return 1; break; case SYNC_PREF_REMOTE: if ( lastSync > remote->revision() ) return 1; if ( lastSync > local->revision() ) return 2; return 2; break; case SYNC_PREF_NEWEST: if ( local->revision() > remote->revision() ) return 1; else return 2; break; case SYNC_PREF_ASK: qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); if ( lastSync > remote->revision() ) return 1; if ( lastSync > local->revision() ) return 2; //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); localIsNew = local->revision() >= remote->revision(); #if 0 if ( localIsNew ) getEventViewerDialog()->setColorMode( 1 ); else getEventViewerDialog()->setColorMode( 2 ); getEventViewerDialog()->setIncidence(local); if ( localIsNew ) getEventViewerDialog()->setColorMode( 2 ); else getEventViewerDialog()->setColorMode( 1 ); getEventViewerDialog()->addIncidence(remote); getEventViewerDialog()->setColorMode( 0 ); //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); getEventViewerDialog()->showMe(); result = getEventViewerDialog()->executeS( localIsNew ); #endif qDebug("conflict! ************************************** "); - result = 1; + { + KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); + result = acd.executeD(localIsNew); return result; - + } break; case SYNC_PREF_FORCE_LOCAL: return 1; break; case SYNC_PREF_FORCE_REMOTE: return 2; break; default: // SYNC_PREF_TAKE_BOTH not implemented break; } return 0; } bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) { bool syncOK = true; int addedAddressee = 0; int addedAddresseeR = 0; int deletedAddresseeR = 0; int deletedAddresseeL = 0; int changedLocal = 0; int changedRemote = 0; //QPtrList<Addressee> el = local->rawAddressees(); Addressee addresseeR; QString uid; int take; Addressee addresseeL; Addressee addresseeRSync; Addressee addresseeLSync; KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); bool fullDateRange = false; local->resetTempSyncStat(); mLastAddressbookSync = QDateTime::currentDateTime(); QDateTime modifiedCalendar = mLastAddressbookSync;; addresseeLSync = getLastSyncAddressee(); qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); if ( !addresseeR.isEmpty() ) { addresseeRSync = addresseeR; remote->removeAddressee(addresseeR ); } else { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { addresseeRSync = addresseeLSync ; } else { qDebug("FULLDATE 1"); fullDateRange = true; Addressee newAdd; addresseeRSync = newAdd; addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); addresseeRSync.setRevision( mLastAddressbookSync ); addresseeRSync.setCategories( i18n("SyncAddressee") ); } } if ( addresseeLSync.revision() == mLastAddressbookSync ) { qDebug("FULLDATE 2"); fullDateRange = true; } if ( ! fullDateRange ) { if ( addresseeLSync.revision() != addresseeRSync.revision() ) { // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); fullDateRange = true; qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); } } + fullDateRange = true; // debug only! if ( fullDateRange ) mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); else mLastAddressbookSync = addresseeLSync.revision(); // for resyncing if own file has changed // PENDING fixme later when implemented #if 0 if ( mCurrentSyncDevice == "deleteaftersync" ) { mLastAddressbookSync = loadedFileVersion; qDebug("setting mLastAddressbookSync "); } #endif //qDebug("*************************** "); qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); QStringList er = remote->uidList(); Addressee inR ;//= er.first(); Addressee inL; QProgressBar bar( er.count(),0 ); bar.setCaption (i18n("Syncing - close to abort!") ); int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar.sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar.show(); int modulo = (er.count()/10)+1; int incCounter = 0; while ( incCounter < er.count()) { if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); uid = er[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; QString idS; qApp->processEvents(); if ( !skipIncidence ) { inL = local->findByUid( uid ); inR = remote->findByUid( uid ); //inL.setResource( 0 ); //inR.setResource( 0 ); if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { //qDebug("take %d %s ", take, inL.summary().latin1()); if ( take == 3 ) return false; if ( take == 1 ) {// take local if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); local->insertAddressee( inL, false ); } else idS = inR.IDStr(); remote->removeAddressee( inR ); inR = inL; inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) inR.setIDStr( idS ); inR.setResource( 0 ); remote->insertAddressee( inR , false); ++changedRemote; } else { idS = inL.IDStr(); local->removeAddressee( inL ); inL = inR; inL.setIDStr( idS ); inL.setResource( 0 ); local->insertAddressee( inL , false ); ++changedLocal; } } } else { // no conflict if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { QString des = addresseeLSync.note(); QString pref = "a"; if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); ++deletedAddresseeR; } else { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); inL = inR; inL.setResource( 0 ); local->insertAddressee( inL , false); ++addedAddressee; } } else { if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); |