summaryrefslogtreecommitdiffabout
path: root/libkcal
Side-by-side diff
Diffstat (limited to 'libkcal') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/calendar.cpp5
-rw-r--r--libkcal/calendar.h9
-rw-r--r--libkcal/calendarlocal.cpp54
-rw-r--r--libkcal/calendarlocal.h6
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
@@ -44,24 +44,25 @@ Calendar::Calendar()
Calendar::Calendar( const QString &timeZoneId )
{
init();
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
// even that good of one at that.
// srandom(time(0));
// user information...
@@ -103,24 +104,28 @@ void Calendar::init()
setTimeZone(tzStr);
#endif
// KOPrefs::instance()->writeConfig();
}
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;
}
const QString &Calendar::getOwner() const
{
return mOwner;
}
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 4c6760f..73f82bb 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -65,24 +65,26 @@ public:
Calendar();
Calendar(const QString &timeZoneId);
virtual ~Calendar();
Incidence * undoIncidence() { return mUndoIncidence; };
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; }
/**
Return the owner of the calendar's full name.
*/
@@ -293,28 +295,31 @@ public:
void setModified( bool );
/**
Set product id returned by loadedProductId(). This function is only
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 &noti );
void removeAlarm(const QDateTime &qdt, const QString &noti );
protected:
/**
Get unfiltered events, which occur on the given date.
*/
@@ -325,33 +330,35 @@ public:
virtual QPtrList<Event> rawEventsForDate( const QDate &date,
bool sorted = false ) = 0;
/**
Get events in a range of dates. If inclusive is set to true, only events
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;
bool mModified;
QString mLoadedProductId;
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index c5500bf..e48122a 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -56,27 +56,65 @@ CalendarLocal::CalendarLocal(const QString &timeZoneId)
{
init();
}
void CalendarLocal::init()
{
mNextAlarmIncidence = 0;
}
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 );
return storage.load();
}
bool CalendarLocal::save( const QString &fileName, CalFormat *format )
{
FileStorage storage( this, fileName, format );
return storage.save();
}
@@ -747,24 +785,38 @@ QPtrList<Journal> CalendarLocal::journals()
void CalendarLocal::setCalendarEnabled( int id, bool enable )
{
for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
if ( it->calID() == id ) it->setCalEnabled( 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 );
for ( Todo *it = mTodoList.first(); it; it = mTodoList.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
@@ -34,25 +34,26 @@ class CalFormat;
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();
-
+ 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 );
/**
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
@@ -170,27 +171,28 @@ class CalendarLocal : public Calendar
Get unfiltered events for date \a qdt.
*/
QPtrList<Event> rawEventsForDate( const QDateTime &qdt );
/**
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;
QDateTime mNextAlarmEventDateTime;
QDateTime mNextAlarmDateTime;
void reInitAlarmSettings();