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,81 +1,86 @@ /* 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) ); @@ -354,48 +359,109 @@ mText = "<table width=\"100%\">\n"; "<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 @@ -2607,169 +2607,172 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i 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 |