-rw-r--r-- | libkcal/calendar.cpp | 5 | ||||
-rw-r--r-- | libkcal/calendar.h | 9 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 56 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 6 |
4 files changed, 71 insertions, 5 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index f4350d9..5092d1a 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp @@ -48,16 +48,17 @@ Calendar::Calendar( const QString &timeZoneId ) setTimeZoneId(timeZoneId); } void Calendar::init() { mObserver = 0; mNewObserver = false; mUndoIncidence = 0; + mDeleteIncidencesOnClose = true; mModified = false; mDefaultCalendar = 1; // Setup default filter, which does nothing mDefaultFilter = new CalFilter; mFilter = mDefaultFilter; mFilter->setEnabled(false); // initialize random numbers. This is a hack, and not @@ -107,16 +108,20 @@ void Calendar::init() } Calendar::~Calendar() { delete mDefaultFilter; if ( mUndoIncidence ) delete mUndoIncidence; } +void Calendar::setDontDeleteIncidencesOnClose () +{ + mDeleteIncidencesOnClose = false; +} void Calendar::setDefaultCalendar( int d ) { mDefaultCalendar = d; } int Calendar::defaultCalendar() { return mDefaultCalendar; } diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4c6760f..73f82bb 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -69,16 +69,18 @@ public: bool undoDeleteIncidence(); void deleteIncidence(Incidence *in); void resetTempSyncStat(); void resetPilotStat(int id); /** Clears out the current calendar, freeing all used memory etc. */ virtual void close() = 0; + virtual void addCalendar( Calendar* ) = 0; + virtual bool addCalendarFile( QString name, int id ) = 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; } @@ -297,20 +299,23 @@ public: useful for the calendar loading code. */ void setLoadedProductId( const QString & ); /** Return product id taken from file that has been loaded. Returns QString::null, if no calendar has been loaded. */ QString loadedProductId(); - void setDefaultCalendar( int ); int defaultCalendar(); + void setDontDeleteIncidencesOnClose (); + public slots: + void setDefaultCalendar( int ); virtual void setCalendarEnabled( int id, bool enable ) = 0; virtual void setAlarmEnabled( int id, bool enable ) = 0; + virtual void setReadOnly( int id, bool enable ) = 0; virtual void setDefaultCalendarEnabledOnly() = 0; signals: void calendarChanged(); void calendarSaved(); void calendarLoaded(); void addAlarm(const QDateTime &qdt, const QString ¬i ); void removeAlarm(const QDateTime &qdt, const QString ¬i ); @@ -329,25 +334,27 @@ public: are returned, which are completely included in the range. */ virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, bool inclusive = false ) = 0; Incidence *mNextAlarmIncidence; Incidence *mUndoIncidence; int mDefaultCalendar; + bool mDeleteIncidencesOnClose; private: void init(); QString mOwner; // who the calendar belongs to QString mOwnerEmail; // email address of the owner int mTimeZone; // timezone OFFSET from GMT (MINUTES) bool mLocalTime; // use local time, not UTC or a time zone + CalFilter *mFilter; CalFilter *mDefaultFilter; QString mTimeZoneId; Observer *mObserver; bool mNewObserver; diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index c5500bf..e48122a 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -60,19 +60,57 @@ CalendarLocal::CalendarLocal(const QString &timeZoneId) void CalendarLocal::init() { mNextAlarmIncidence = 0; } CalendarLocal::~CalendarLocal() { - close(); + if ( mDeleteIncidencesOnClose ) + close(); +} +bool CalendarLocal::addCalendarFile( QString name, int id ) +{ + CalendarLocal calendar( timeZoneId() ); + calendar.setDefaultCalendar( id ); + if ( calendar.load( name ) ) { + addCalendar( &calendar ); + return true; + } + return false; +} +void CalendarLocal::addCalendar( Calendar* cal ) +{ + cal->setDontDeleteIncidencesOnClose(); + { + QPtrList<Event> EventList = cal->rawEvents(); + Event * ev = EventList.first(); + while ( ev ) { + mEventList.append( ev ); + ev = EventList.next(); + } + } + { + QPtrList<Todo> TodoList = cal->rawTodos(); + Todo * ev = TodoList.first(); + while ( ev ) { + mTodoList.append( ev ); + ev = TodoList.next(); + } + } + { + QPtrList<Journal> JournalList = cal->journals(); + Journal * ev = JournalList.first(); + while ( ev ) { + mJournalList.append( ev ); + ev = JournalList.next(); + } + } } - bool CalendarLocal::load( const QString &fileName ) { FileStorage storage( this, fileName ); return storage.load(); } bool CalendarLocal::save( const QString &fileName, CalFormat *format ) { @@ -751,16 +789,30 @@ void CalendarLocal::setCalendarEnabled( int id, bool enable ) for ( Event *it = mEventList.first(); it; it = mEventList.next() ) if ( it->calID() == id ) it->setCalEnabled( enable ); for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) if ( it->calID() == id ) it->setCalEnabled( enable ); } + +void CalendarLocal::setReadOnly( int id, bool enable ) +{ + for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) + if ( it->calID() == id ) it->setReadOnly( enable ); + + for ( Event *it = mEventList.first(); it; it = mEventList.next() ) + if ( it->calID() == id ) it->setReadOnly( enable ); + + for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) + if ( it->calID() == id ) it->setReadOnly( enable ); + +} + void CalendarLocal::setAlarmEnabled( int id, bool enable ) { for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) if ( it->calID() == id ) it->setAlarmEnabled( enable ); for ( Event *it = mEventList.first(); it; it = mEventList.next() ) if ( it->calID() == id ) it->setAlarmEnabled( enable ); diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index b25fcbe..65f6aa7 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h @@ -38,17 +38,18 @@ class CalendarLocal : public Calendar 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(); - + void addCalendar( Calendar* ); + bool addCalendarFile( QString name, int id ); /** 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 ); /** @@ -174,19 +175,20 @@ class CalendarLocal : public Calendar Get unfiltered events in a range of dates. If inclusive is set to true, only events are returned, which are completely included in the range. */ QPtrList<Event> rawEvents( const QDate &start, const QDate &end, bool inclusive = false ); Todo *todo( QString, QString ); Event *event( QString, QString ); - +public slots: void setCalendarEnabled( int id, bool enable ); void setAlarmEnabled( int id, bool enable ); + void setReadOnly( int id, bool enable ); void setDefaultCalendarEnabledOnly(); protected: // Event* mNextAlarmEvent; QString mNextSummary; QString mNextAlarmEventDateTimeString; QString mLastAlarmNotificationString; |