-rw-r--r-- | kabc/addressbook.cpp | 8 | ||||
-rw-r--r-- | kabc/addressbook.h | 1 | ||||
-rw-r--r-- | kabc/addressee.cpp | 3 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 4 | ||||
-rw-r--r-- | korganizer/calendarview.cpp | 1 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 23 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkcal/incidencebase.cpp | 3 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 40 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 1 |
11 files changed, 82 insertions, 4 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 3641c0c..2785131 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -492,128 +492,136 @@ int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool remo data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); data.replace ( QRegExp("LABEL") , "ADR" ); data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); } else data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); KABC::VCardTool tool; list = tool.parseVCards( data ); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); if ( !id.isEmpty() ) (*it).setIDStr(id ); (*it).setResource( 0 ); if ( replaceLabel ) (*it).removeVoice(); if ( removeOld ) (*it).setTagged( true ); insertAddressee( (*it), false, true ); } if ( removeOld ) removeUntagged(); return list.count(); } void AddressBook::setUntagged(bool setNonSyncTagged) // = false) { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { if ( setNonSyncTagged ) { if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { (*ait).setTagged( true ); } else (*ait).setTagged( false ); } else (*ait).setTagged( false ); } } void AddressBook::removeUntagged() { Iterator ait; bool todelete = false; Iterator todel; for ( ait = begin(); ait != end(); ++ait ) { if ( todelete ) removeAddressee( todel ); if (!(*ait).tagged()) { todelete = true; todel = ait; } else todelete = false; } if ( todelete ) removeAddressee( todel ); deleteRemovedAddressees(); } void AddressBook::smplifyAddressees() { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { (*ait).simplifyEmails(); (*ait).simplifyPhoneNumbers(); (*ait).simplifyPhoneNumberTypes(); (*ait).simplifyAddresses(); } } +void AddressBook::removeSyncInfo( QString syncProfile) +{ + Iterator ait; + for ( ait = begin(); ait != end(); ++ait ) { + (*ait).removeID( syncProfile ); + } + +} void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { QString id = (*ait).IDStr(); (*ait).setIDStr( ":"); (*ait).setExternalUID( id ); (*ait).setOriginalExternalUID( id ); if ( isPreSync ) (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); else { (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); (*ait).setID( currentSyncDevice,id ); } } } void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) { setUntagged(); KABC::Addressee::List list; QFile file( fileName ); file.open( IO_ReadOnly ); QByteArray rawData = file.readAll(); file.close(); QString data; data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); KABC::VCardTool tool; list = tool.parseVCards( data ); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { if ( !(*ait).tagged() ) { if ( (*ait).containsAdr(*it)) { (*ait).setTagged(true); QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); (*it).setIDStr( ":"); (*it).setID( currentSyncDevice,id ); (*it).setExternalUID( id ); (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); (*it).setUid( ( (*ait).uid() )); break; } } } if ( ait == end() ) qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); } clear(); for ( it = list.begin(); it != list.end(); ++it ) { insertAddressee( (*it) ); } } bool AddressBook::saveABphone( QString fileName ) { //smplifyAddressees(); qDebug("saveABphone:: saving AB... "); if ( ! export2PhoneFormat( QStringList() ,fileName ) ) return false; diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 5edca06..f124dc9 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -83,128 +83,129 @@ class AddressBook : public QObject IteratorData *d; }; /** @short Address Book Const Iterator This class provides a const iterator for address book entries. */ class ConstIterator { public: ConstIterator(); ConstIterator( const ConstIterator & ); ~ConstIterator(); ConstIterator &operator=( const ConstIterator & ); const Addressee &operator*() const; const Addressee* operator->() const; ConstIterator &operator++(); ConstIterator &operator++(int); ConstIterator &operator--(); ConstIterator &operator--(int); bool operator==( const ConstIterator &it ); bool operator!=( const ConstIterator &it ); struct ConstIteratorData; ConstIteratorData *d; }; /** Constructs a address book object. @param format File format class. */ AddressBook(); AddressBook( const QString &config ); AddressBook( const QString &config, const QString &family ); virtual ~AddressBook(); /** Requests a ticket for saving the addressbook. Calling this function locks the addressbook for all other processes. If the address book is already locked the function returns 0. You need the returned @ref Ticket object for calling the @ref save() function. @see save() */ Ticket *requestSaveTicket( Resource *resource=0 ); /** Load address book from file. */ bool load(); /** Save address book. The address book is saved to the file, the Ticket object has been requested for by @ref requestSaveTicket(). @param ticket a ticket object returned by @ref requestSaveTicket() */ bool save( Ticket *ticket ); bool saveAB( ); bool saveABphone( QString fileName ); void smplifyAddressees(); + void removeSyncInfo( QString syncProfile); void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); void export2File( QString fileName ); bool export2PhoneFormat( QStringList uids ,QString fileName ); int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); void setUntagged( bool setNonSyncTagged = false ); void removeUntagged(); void findNewExtIds( QString fileName, QString currentSyncDevice ); /** Returns a iterator for first entry of address book. */ Iterator begin(); /** Returns a const iterator for first entry of address book. */ ConstIterator begin() const; /** Returns a iterator for first entry of address book. */ Iterator end(); /** Returns a const iterator for first entry of address book. */ ConstIterator end() const; /** Removes all entries from address book. */ void clear(); /** Insert an Addressee object into address book. If an object with the same unique id already exists in the address book it it replaced by the new one. If not the new object is appended to the address book. */ void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); /** Removes entry from the address book. */ void removeAddressee( const Addressee & ); /** This is like @ref removeAddressee() just above, with the difference that the first element is a iterator, returned by @ref begin(). */ void removeAddressee( const Iterator & ); /** Find the specified entry in address book. Returns end(), if the entry couldn't be found. */ Iterator find( const Addressee & ); /** Find the entry specified by an unique id. Returns an empty Addressee object, if the address book does not contain an entry with this id. */ Addressee findByUid( const QString & ); /** diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 40877ef..a660a9d 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -492,128 +492,131 @@ void Addressee::simplifyEmails() detach(); mData->emails.clear(); mData->emails.append( email ); } void Addressee::simplifyPhoneNumbers() { int max = 4; int inList = mData->phoneNumbers.count(); KABC::PhoneNumber::List removeNumbers; KABC::PhoneNumber::List::Iterator phoneIter; if ( inList > max ) { // delete non-preferred numbers for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) { if ( inList > max ) { if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { removeNumbers.append( ( *phoneIter ) ); --inList; } } else break; } for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); ++phoneIter ) { removePhoneNumber(( *phoneIter )); } // delete preferred numbers if ( inList > max ) { for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) { if ( inList > max ) { removeNumbers.append( ( *phoneIter ) ); --inList; } else break; } for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); ++phoneIter ) { removePhoneNumber(( *phoneIter )); } } } // remove non-numeric characters for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) { if ( ! ( *phoneIter ).simplifyNumber() ) removeNumbers.append( ( *phoneIter ) ); } for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); ++phoneIter ) { removePhoneNumber(( *phoneIter )); } } void Addressee::simplifyPhoneNumberTypes() { KABC::PhoneNumber::List::Iterator phoneIter; for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) ( *phoneIter ).simplifyType(); } void Addressee::removeID(const QString &prof) { detach(); + if ( prof.isEmpty() ) + mData->mExternalId = ":"; + else mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); } void Addressee::setID( const QString & prof , const QString & id ) { detach(); mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); } void Addressee::setTempSyncStat( int id ) { if ( mData->mTempSyncStat == id ) return; detach(); mData->mTempSyncStat = id; } int Addressee::tempSyncStat() const { return mData->mTempSyncStat; } QString Addressee::getID( const QString & prof) { return KIdManager::getId ( mData->mExternalId, prof ); } void Addressee::setCsum( const QString & prof , const QString & id ) { detach(); //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); } QString Addressee::getCsum( const QString & prof) { return KIdManager::getCsum ( mData->mExternalId, prof ); } void Addressee::setIDStr( const QString & s ) { detach(); mData->mExternalId = s; } QString Addressee::IDStr() const { return mData->mExternalId; } void Addressee::setExternalUID( const QString &id ) { if ( id == mData->externalUID ) return; detach(); mData->empty = false; mData->externalUID = id; } QString Addressee::externalUID() const { return mData->externalUID; } void Addressee::setOriginalExternalUID( const QString &id ) { if ( id == mData->originalExternalUID ) return; diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index efae874..e56e46a 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2751,130 +2751,130 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo } //this is a overwritten callbackmethods from the syncinterface bool KABCore::sync(KSyncManager* manager, QString filename, int mode) { //pending prepare addresseeview for output //pending detect, if remote file has REV field. if not switch to external sync mGlobalSyncMode = SYNC_MODE_NORMAL; QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); AddressBook abLocal(filename,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); bool external = false; bool isXML = false; if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; isXML = true; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); } else { external = !manager->mIsKapiFile; if ( external ) { qDebug("Setting vcf mode to external "); mGlobalSyncMode = SYNC_MODE_EXTERNAL; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { (*it).setID( mCurrentSyncDevice, (*it).uid() ); (*it).computeCsum( mCurrentSyncDevice ); } } } //AddressBook::Iterator it; //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { if ( external ) abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); if ( ! abLocal.saveAB()) qDebug("Error writing back AB to file "); if ( isXML ) { // afterwrite processing abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; } void KABCore::removeSyncInfo( QString syncProfile) { - qDebug("removeSyncInfo for profile %s ", syncProfile.latin1()); - + qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); + mAddressBook->removeSyncInfo( syncProfile ); } //this is a overwritten callbackmethods from the syncinterface bool KABCore::syncExternal(KSyncManager* manager, QString resource) { if ( resource == "phone" ) return syncPhone(); disableBR( true ); QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); AddressBook abLocal( resource,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { abLocal.removeSyncAddressees( false ); abLocal.saveAB(); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } setModified(); } if ( syncOK ) mViewManager->refreshView(); disableBR( false ); return syncOK; } void KABCore::message( QString m ) { topLevelWidget()->setCaption( m ); mMessageTimer->start( 15000, true ); } bool KABCore::syncPhone() { QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); QString fileName = getPhoneFile(); if ( !PhoneAccess::readFromPhone( fileName) ) { message(i18n("Phone access failed!")); return false; } AddressBook abLocal( fileName,"syncContact"); bool syncOK = false; { abLocal.importFromFile( fileName ); qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preparePhoneSync( mCurrentSyncDevice, true ); abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { abLocal.removeSyncAddressees( true ); abLocal.saveABphone( fileName ); abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index af01625..a08f243 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -3707,66 +3707,67 @@ void CalendarView::purgeCompleted() for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { if ( !aTodo->relatedTo() ) rootTodos.append( aTodo ); } for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { removeCompletedSubTodos( aTodo ); } updateView(); } } void CalendarView::slotCalendarChanged() { ; } NavigatorBar *CalendarView::navigatorBar() { return mNavigatorBar; } void CalendarView::keyPressEvent ( QKeyEvent *e) { //qDebug(" alendarView::keyPressEvent "); e->ignore(); } bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) { // mSyncManager = manager; mSyncKDE = false; if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { qDebug("SyncKDE request detected!"); mSyncKDE = true; } mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); mCurrentSyncName = mSyncManager->getCurrentSyncName(); return syncCalendar( filename, mode ); } bool CalendarView::syncExternal(KSyncManager* manager, QString resource) { mSyncKDE = false; //mSyncManager = manager; mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); mCurrentSyncName = mSyncManager->getCurrentSyncName(); if ( resource == "sharp" ) syncExternal( 0 ); if ( resource == "phone" ) syncExternal( 1 ); // pending setmodified return true; } void CalendarView::setSyncManager(KSyncManager* manager) { mSyncManager = manager; } void CalendarView::removeSyncInfo( QString syncProfile) { qDebug("removeSyncInfo for profile %s ", syncProfile.latin1()); + mCalendar->removeSyncInfo( syncProfile ); } diff --git a/libkcal/calendar.h b/libkcal/calendar.h index b801186..b7d6a1f 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -17,128 +17,129 @@ 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 CALENDAR_H #define CALENDAR_H #include <qobject.h> #include <qstring.h> #include <qdatetime.h> #include <qptrlist.h> #include <qdict.h> #include "customproperties.h" #include "event.h" #include "todo.h" #include "journal.h" #include "calfilter.h" //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ class KConfig; namespace KCal { /** This is the main "calendar" object class for KOrganizer. It holds information like all appointments/events, user information, etc. etc. one calendar is associated with each CalendarView (@see calendarview.h). This is an abstract base class defining the interface to a calendar. It is implemented by subclasses like @see CalendarLocal, which use different methods to store and access the data. Ownership of events etc. is handled by the following policy: As soon as an event (or any other subclass of IncidenceBase) object is added to the Calendar by addEvent() it is owned by the Calendar object. The Calendar takes care of deleting it. All Events returned by the query functions are returned as pointers, that means all changes to the returned events are immediately visible in the Calendar. You shouldn't delete any Event object you get from Calendar. */ class Calendar : public QObject, public CustomProperties, public IncidenceBase::Observer { Q_OBJECT public: Calendar(); Calendar(const QString &timeZoneId); virtual ~Calendar(); void deleteIncidence(Incidence *in); void resetTempSyncStat(); void resetPilotStat(int id); /** Clears out the current calendar, freeing all used memory etc. */ virtual void close() = 0; /** Sync changes in memory to persistant storage. */ virtual void save() = 0; virtual QPtrList<Event> getExternLastSyncEvents() = 0; + virtual void removeSyncInfo( QString syncProfile) = 0; virtual bool isSaving() { return false; } /** Return the owner of the calendar's full name. */ const QString &getOwner() const; /** Set the owner of the calendar. Should be owner's full name. */ void setOwner( const QString &os ); /** Return the email address of the calendar owner. */ const QString &getEmail(); /** Set the email address of the calendar owner. */ void setEmail( const QString & ); /** Set time zone from a timezone string (e.g. -2:00) */ void setTimeZone( const QString &tz ); /** Set time zone from a minutes value (e.g. -60) */ void setTimeZone( int tz ); /** Return time zone as offest in minutes. */ int getTimeZone() const; /** Compute an ISO 8601 format string from the time zone. */ QString getTimeZoneStr() const; /** Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal values). */ void setTimeZoneId( const QString & ); /** Return time zone id. */ QString timeZoneId() const; /** Use local time, not UTC or a time zone. */ void setLocalTime(); /** Return whether local time is being used. */ bool isLocalTime() const; /** Add an incidence to calendar. @return true on success, false on error. */ virtual bool addIncidence( Incidence * ); /** Return filtered list of all incidences of this calendar. */ virtual QPtrList<Incidence> incidences(); diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 21b4aaf..3f46d53 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -160,129 +160,150 @@ void CalendarLocal::deleteEvent( Event *event ) } Event *CalendarLocal::event( const QString &uid ) { Event *event; for ( event = mEventList.first(); event; event = mEventList.next() ) { if ( event->uid() == uid ) { return event; } } return 0; } bool CalendarLocal::addTodoNoDup( Todo *todo ) { Todo * eve; for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { if ( *eve == *todo ) { //qDebug("duplicate todo found! not inserted! "); return false; } } return addTodo( todo ); } bool CalendarLocal::addTodo( Todo *todo ) { mTodoList.append( todo ); todo->registerObserver( this ); // Set up subtask relations setupRelations( todo ); setModified( true ); return true; } void CalendarLocal::deleteTodo( Todo *todo ) { // Handle orphaned children removeRelations( todo ); if ( mTodoList.removeRef( todo ) ) { setModified( true ); } } QPtrList<Todo> CalendarLocal::rawTodos() { return mTodoList; } Todo *CalendarLocal::todo( QString syncProf, QString id ) { Todo *todo; for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { if ( todo->getID( syncProf ) == id ) return todo; } return 0; } - +void CalendarLocal::removeSyncInfo( QString syncProfile) +{ + QPtrList<Incidence> all = rawIncidences() ; + Incidence *inc; + for ( inc = all.first(); inc; inc = all.next() ) { + inc->removeID( syncProfile ); + } + if ( syncProfile.isEmpty() ) { + QPtrList<Event> el; + Event *todo; + for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { + if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) + el.append( todo ); + } + for ( todo = el.first(); todo; todo = el.next() ) { + deleteIncidence ( todo ); + } + } else { + Event *lse = event( "last-syncEvent-"+ syncProfile); + deleteIncidence ( lse ); + } +} QPtrList<Event> CalendarLocal::getExternLastSyncEvents() { QPtrList<Event> el; Event *todo; for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) if ( todo->summary().left(3) == "E: " ) el.append( todo ); } return el; } Event *CalendarLocal::event( QString syncProf, QString id ) { Event *todo; for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { if ( todo->getID( syncProf ) == id ) return todo; } return 0; } Todo *CalendarLocal::todo( const QString &uid ) { Todo *todo; for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { if ( todo->uid() == uid ) return todo; } return 0; } QString CalendarLocal::nextSummary() const { return mNextSummary; } QDateTime CalendarLocal::nextAlarmEventDateTime() const { return mNextAlarmEventDateTime; } void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) { //mNextAlarmIncidence //mNextAlarmDateTime //return mNextSummary; //return mNextAlarmEventDateTime; bool newNextAlarm = false; bool computeNextAlarm = false; bool ok; int offset; QDateTime nextA; // QString nextSum; //QDateTime nextEvent; if ( mNextAlarmIncidence == 0 || incidence == 0 ) { computeNextAlarm = true; } else { if ( ! deleted ) { nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; if ( ok ) { if ( nextA < mNextAlarmDateTime ) { deRegisterAlarm(); mNextAlarmDateTime = nextA; mNextSummary = incidence->summary(); mNextAlarmEventDateTime = nextA.addSecs(offset ) ; mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 5b6c64c..98ec710 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h @@ -8,128 +8,129 @@ 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 KCAL_CALENDARLOCAL_H #define KCAL_CALENDARLOCAL_H #include "calendar.h" namespace KCal { class CalFormat; /** This class provides a calendar stored as a local file. */ class CalendarLocal : public Calendar { public: /** Constructs a new calendar, with variables initialized to sane values. */ CalendarLocal(); /** Constructs a new calendar, with variables initialized to sane values. */ CalendarLocal( const QString &timeZoneId ); ~CalendarLocal(); /** Loads a calendar on disk in vCalendar or iCalendar format into the current calendar. Any information already present is lost. @return true, if successfull, false on error. @param fileName the name of the calendar on disk. */ bool load( const QString &fileName ); /** Writes out the calendar to disk in the specified \a format. CalendarLocal takes ownership of the CalFormat object. @return true, if successfull, false on error. @param fileName the name of the file */ bool save( const QString &fileName, CalFormat *format = 0 ); /** Clears out the current calendar, freeing all used memory etc. etc. */ void close(); void save() {} /** Add Event to calendar. */ + void removeSyncInfo( QString syncProfile); bool addAnniversaryNoDup( Event *event ); bool addEventNoDup( Event *event ); bool addEvent( Event *event ); /** Deletes an event from this calendar. */ void deleteEvent( Event *event ); /** Retrieves an event on the basis of the unique string ID. */ Event *event( const QString &uid ); /** Return unfiltered list of all events in calendar. */ QPtrList<Event> rawEvents(); QPtrList<Event> getExternLastSyncEvents(); /** Add a todo to the todolist. */ bool addTodo( Todo *todo ); bool addTodoNoDup( Todo *todo ); /** Remove a todo from the todolist. */ void deleteTodo( Todo * ); /** Searches todolist for an event with this unique string identifier, returns a pointer or null. */ Todo *todo( const QString &uid ); /** Return list of all todos. */ QPtrList<Todo> rawTodos(); /** Returns list of todos due on the specified date. */ QPtrList<Todo> todos( const QDate &date ); /** Return list of all todos. Workaround because compiler does not recognize function of base class. */ QPtrList<Todo> todos() { return Calendar::todos(); } /** Add a Journal entry to calendar. */ bool addJournal( Journal * ); /** Remove a Journal from the calendar. */ void deleteJournal( Journal * ); /** Return Journal for given date. */ Journal *journal( const QDate & ); /** Return Journal with given UID. */ Journal *journal( const QString &uid ); /** Return list of all Journals stored in calendar. diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index b36dc1a..9aa517c 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp @@ -292,116 +292,119 @@ Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QStrin if (qli.current()->email().lower() == (*it).lower()) return qli.current(); } ++qli; } return 0L; } void IncidenceBase::setDuration(int seconds) { mDuration = seconds; setHasDuration(true); } int IncidenceBase::duration() const { return mDuration; } void IncidenceBase::setHasDuration(bool b) { mHasDuration = b; } bool IncidenceBase::hasDuration() const { return mHasDuration; } void IncidenceBase::setSyncStatus(int stat) { if (mReadOnly) return; mSyncStatus = stat; } int IncidenceBase::syncStatus() const { return mSyncStatus; } void IncidenceBase::setPilotId( int id ) { if (mReadOnly) return; mPilotId = id; } int IncidenceBase::pilotId() const { return mPilotId; } int IncidenceBase::tempSyncStat() const { return mTempSyncStat; } void IncidenceBase::setTempSyncStat( int id ) { if (mReadOnly) return; mTempSyncStat = id; } void IncidenceBase::removeID(const QString &prof) { + if ( prof.isEmpty() ) + mExternalId = ":"; + else mExternalId = KIdManager::removeId ( mExternalId, prof); } void IncidenceBase::setID( const QString & prof , const QString & id ) { mExternalId = KIdManager::setId ( mExternalId, prof, id ); } QString IncidenceBase::getID( const QString & prof) { return KIdManager::getId ( mExternalId, prof ); } // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 void IncidenceBase::setCsum( const QString & prof , const QString & id ) { mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); } QString IncidenceBase::getCsum( const QString & prof) { return KIdManager::getCsum ( mExternalId, prof ); } void IncidenceBase::setIDStr( const QString & s ) { if (mReadOnly) return; mExternalId = s; } QString IncidenceBase::IDStr() const { return mExternalId ; } void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) { if( !mObservers.contains(observer) ) mObservers.append( observer ); } void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) { mObservers.remove( observer ); } void IncidenceBase::updated() { QPtrListIterator<Observer> it(mObservers); while( it.current() ) { Observer *o = it.current(); ++it; o->incidenceUpdated( this ); } } diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 4390a06..feb184b 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -26,193 +26,225 @@ #ifndef _WIN32_ #include <unistd.h> #endif #include "ksyncprofile.h" #include "ksyncprefsdialog.h" #include "kpimprefs.h" #include <kmessagebox.h> #include <qdir.h> #include <qprogressbar.h> #include <qpopupmenu.h> #include <qpushbutton.h> #include <qradiobutton.h> #include <qbuttongroup.h> #include <qtimer.h> #include <qmessagebox.h> #include <qapplication.h> #include <qlineedit.h> #include <qdialog.h> #include <qlayout.h> #include <qtextcodec.h> #include <qlabel.h> #include <qcheckbox.h> #include <klocale.h> #include <kglobal.h> #include <kconfig.h> #include <kfiledialog.h> KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) { mServerSocket = 0; bar = new QProgressBar ( 1, 0 ); bar->setCaption (""); 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 ); if ( mPrefs->mPassiveSyncAutoStart ) enableQuick( false ); } KSyncManager::~KSyncManager() { delete bar; } void KSyncManager::fillSyncMenu() { if ( mSyncMenu->count() ) mSyncMenu->clear(); mSyncMenu->insertItem( i18n("Configure..."), 0 ); mSyncMenu->insertSeparator(); + QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); + mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); + clearMenu->insertItem( i18n("For all profiles"), 1 ); + clearMenu->insertSeparator(); + connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); + mSyncMenu->insertSeparator(); if ( mServerSocket == 0 ) { mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); } else { mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); } mSyncMenu->insertSeparator(); mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); mSyncMenu->insertSeparator(); - KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); config.setGroup("General"); QStringList prof = config.readListEntry("SyncProfileNames"); mLocalMachineName = config.readEntry("LocalMachineName","undefined"); if ( prof.count() < 2 ) { prof.clear(); QString externalName; #ifdef DESKTOP_VERSION #ifdef _WIN32_ externalName = "OutLook(not_implemented)"; #else externalName = "KDE_Desktop"; #endif #else externalName = "Sharp_DTM"; #endif prof << externalName; prof << i18n("Local_file"); prof << i18n("Last_file"); KSyncProfile* temp = new KSyncProfile (); temp->setName( prof[0] ); temp->writeConfig(&config); temp->setName( prof[1] ); temp->writeConfig(&config); temp->setName( prof[2] ); temp->writeConfig(&config); config.setGroup("General"); config.writeEntry("SyncProfileNames",prof); config.writeEntry("ExternSyncProfiles",externalName); config.sync(); delete temp; } mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); mSyncProfileNames = prof; unsigned int i; for ( i = 0; i < prof.count(); ++i ) { mSyncMenu->insertItem( prof[i], 1000+i ); + clearMenu->insertItem( prof[i], 1000+i ); if ( i == 2 ) mSyncMenu->insertSeparator(); } QDir app_dir; //US do not display SharpDTM if app is pwmpi, or no sharpfiles available if ( mTargetApp == PWMPI) { mSyncMenu->removeItem( 1000 ); + clearMenu->removeItem( 1000 ); } #ifndef DESKTOP_VERSION else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { mSyncMenu->removeItem( 1000 ); + clearMenu->removeItem( 1000 ); } #endif mSyncMenu->removeItem( 1002 ); + clearMenu->removeItem( 1002 ); +} +void KSyncManager::slotClearMenu( int action ) +{ + QString syncDevice; + if ( action > 999 ) { + syncDevice = mSyncProfileNames[action - 1000] ; } + + + int result = 0; + QString sd; + if ( syncDevice.isEmpty() ) + sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); + else + sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); + + result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, + 0, 1 ); + if ( result ) + return; + mImplementation->removeSyncInfo( syncDevice ); +} void KSyncManager::slotSyncMenu( int action ) { qDebug("syncaction %d ", action); + if ( action == 5000 ) + return; if ( action == 0 ) { // seems to be a Qt2 event handling bug // syncmenu.clear causes a segfault at first time // when we call it after the main event loop, it is ok // same behaviour when calling OM/Pi via QCOP for the first time QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); //confSync(); return; } if ( action == 1 ) { multiSync( true ); return; } if ( action == 2 ) { enableQuick(); QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); return; } if ( action == 3 ) { delete mServerSocket; mServerSocket = 0; QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); return; } if (blockSave()) return; setBlockSave(true); bool silent = false; if ( action == 999 ) { //special mode for silent syncing action = 1000; silent = true; } mCurrentSyncProfile = action - 1000 ; mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; mCurrentSyncName = mLocalMachineName ; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); KSyncProfile* temp = new KSyncProfile (); temp->setName(mSyncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); if (silent) { mAskForPreferences = false; mShowSyncSummary = false; mWriteBackFile = true; mSyncAlgoPrefs = 2;// take newest } else { mAskForPreferences = temp->getAskForPreferences(); mShowSyncSummary = temp->getShowSummaryAfterSync(); mWriteBackFile = temp->getWriteBackFile(); mSyncAlgoPrefs = temp->getSyncPrefs(); } mWriteBackExistingOnly = temp->getWriteBackExisting(); mIsKapiFile = temp->getIsKapiFile(); mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); if ( action == 1000 ) { @@ -774,130 +806,136 @@ bool KSyncManager::edit_sync_options() case 2: newest.setChecked( true); break; case 3: ask.setChecked( true); break; case 4: f_loc.setChecked( true); break; case 5: f_rem.setChecked( true); break; case 6: // both.setChecked( true); break; default: break; } if ( dia.exec() ) { mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; return true; } return false; } QString KSyncManager::getPassword( ) { QString retfile = ""; QDialog dia ( mParent, "input-dialog", true ); QLineEdit lab ( &dia ); lab.setEchoMode( QLineEdit::Password ); QVBoxLayout lay( &dia ); lay.setMargin(7); lay.setSpacing(7); lay.addWidget( &lab); dia.setFixedSize( 230,50 ); dia.setCaption( i18n("Enter password") ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); dia.show(); int res = dia.exec(); if ( res ) retfile = lab.text(); dia.hide(); qApp->processEvents(); return retfile; } void KSyncManager::confSync() { static KSyncPrefsDialog* sp = 0; if ( ! sp ) { sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); } sp->usrReadConfig(); #ifndef DESKTOP_VERSION sp->showMaximized(); #else sp->show(); #endif sp->exec(); + QStringList oldSyncProfileNames = mSyncProfileNames; mSyncProfileNames = sp->getSyncProfileNames(); mLocalMachineName = sp->getLocalMachineName (); + int ii; + for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { + if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) + mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); + } QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); } void KSyncManager::syncKDE() { emit save(); switch(mTargetApp) { case (KAPI): break; case (KOPI): { #ifdef DESKTOP_VERSION QString command = qApp->applicationDirPath () + "/kdecaldump"; #else QString command = "kdecaldump"; #endif if ( ! QFile::exists ( command ) ) command = "kdecaldump"; QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; system ( command.latin1()); if ( syncWithFile( fileName,true ) ) { if ( mWriteBackFile ) { command += " --read"; system ( command.latin1()); } } } break; case (PWMPI): break; default: qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); break; } } void KSyncManager::syncSharp() { if ( ! syncExternalApplication("sharp") ) qDebug("ERROR sync sharp "); } bool KSyncManager::syncExternalApplication(QString resource) { emit save(); if ( mAskForPreferences ) if ( !edit_sync_options()) { mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); return false; } qDebug("Sync extern %s", resource.latin1()); bool syncOK = mImplementation->syncExternal(this, resource); return syncOK; diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index af4f1ab..aa32e28 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h @@ -93,120 +93,121 @@ class KCommandSocket : public QObject Q_UINT16 mPort; QString mHost; QString mFileName; QTimer* mTimerSocket; int mRetVal; QTime mTime; QString mFileString; bool mFirst; }; class KSyncManager : public QObject { Q_OBJECT public: enum TargetApp { KOPI = 0, KAPI = 1, PWMPI = 2 }; KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); ~KSyncManager() ; void multiSync( bool askforPrefs ); bool blockSave() { return mBlockSaveFlag; } void setBlockSave(bool sa) { mBlockSaveFlag = sa; } void setDefaultFileName( QString s) { mDefFileName = s ;} QString defaultFileName() { return mDefFileName ;} QString syncFileName(); void enableQuick( bool ask = true); QString getCurrentSyncDevice() { return mCurrentSyncDevice; } QString getCurrentSyncName() { return mCurrentSyncName; } void showProgressBar(int percentage, QString caption = QString::null, int total=100); void hideProgressBar(); bool isProgressBarCanceled(); // sync stuff QString mLocalMachineName; QStringList mExternSyncProfiles; QStringList mSyncProfileNames; bool mAskForPreferences; bool mShowSyncSummary; bool mIsKapiFile; bool mWriteBackExistingOnly; int mSyncAlgoPrefs; bool mWriteBackFile; int mWriteBackInFuture; QString mPhoneDevice; QString mPhoneConnection; QString mPhoneModel; QString mPassWordPiSync; QString mActiveSyncPort; QString mActiveSyncIP ; signals: void save(); void request_file(); void getFile( bool ); public slots: void slotSyncMenu( int ); + void slotClearMenu( int action ); void deleteCommandSocket(KCommandSocket*s, int state); void readFileFromSocket(); void fillSyncMenu(); private: void syncPi(); KServerSocket * mServerSocket; KPimPrefs* mPrefs; QString mDefFileName; QString mCurrentSyncDevice; QString mCurrentSyncName; void quickSyncLocalFile(); bool syncWithFile( QString fn , bool quick ); void syncLocalFile(); void syncPhone(); void syncSharp(); void syncKDE(); bool syncExternalApplication(QString); int mCurrentSyncProfile ; void syncRemote( KSyncProfile* prof, bool ask = true); bool edit_sync_options(); bool edit_pisync_options(); int ringSync(); QString getPassword( ); bool mPisyncFinished; bool mBlockSaveFlag; QWidget* mParent; KSyncInterface* mImplementation; TargetApp mTargetApp; QPopupMenu* mSyncMenu; QProgressBar* bar; private slots: void confSync(); }; class KSyncInterface { public : virtual void removeSyncInfo( QString syncProfile) = 0; virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; virtual bool syncExternal(KSyncManager* manager, QString resource) { // empty implementation, because some syncable applications do not // have an external(sharpdtm) syncmode, like pwmanager. return false; } }; #endif |