-rw-r--r-- | libkcal/calendar.cpp | 5 | ||||
-rw-r--r-- | libkcal/calendar.h | 9 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 54 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 6 |
4 files changed, 70 insertions, 4 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index f4350d9..5092d1a 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp @@ -53,6 +53,7 @@ void Calendar::init() mObserver = 0; mNewObserver = false; mUndoIncidence = 0; + mDeleteIncidencesOnClose = true; mModified = false; mDefaultCalendar = 1; // Setup default filter, which does nothing @@ -112,6 +113,10 @@ Calendar::~Calendar() if ( mUndoIncidence ) delete mUndoIncidence; } +void Calendar::setDontDeleteIncidencesOnClose () +{ + mDeleteIncidencesOnClose = false; +} void Calendar::setDefaultCalendar( int d ) { mDefaultCalendar = d; diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4c6760f..73f82bb 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -74,6 +74,8 @@ public: 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. @@ -302,10 +304,13 @@ public: 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(); @@ -334,6 +339,7 @@ public: Incidence *mNextAlarmIncidence; Incidence *mUndoIncidence; int mDefaultCalendar; + bool mDeleteIncidencesOnClose; private: void init(); @@ -343,6 +349,7 @@ private: int mTimeZone; // timezone OFFSET from GMT (MINUTES) bool mLocalTime; // use local time, not UTC or a time zone + CalFilter *mFilter; CalFilter *mDefaultFilter; diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index c5500bf..e48122a 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -65,9 +65,47 @@ void CalendarLocal::init() CalendarLocal::~CalendarLocal() { + 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 ); @@ -756,6 +794,20 @@ void CalendarLocal::setCalendarEnabled( int id, bool enable ) 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() ) diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index b25fcbe..65f6aa7 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h @@ -43,7 +43,8 @@ class CalendarLocal : public Calendar */ 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. @@ -179,9 +180,10 @@ class CalendarLocal : public Calendar 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: |