summaryrefslogtreecommitdiffabout
path: root/libkcal
Side-by-side diff
Diffstat (limited to 'libkcal') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/calendar.cpp1
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/calendarlocal.cpp75
-rw-r--r--libkcal/calendarlocal.h3
4 files changed, 80 insertions, 0 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index a662eeb..b7990d4 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -315,96 +315,97 @@ QPtrList<Incidence> Calendar::rawIncidences()
QPtrList<Journal> j = journals();
for( i = j.first(); i; i = j.next() ) incidences.append( i );
return incidences;
}
QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
{
QPtrList<Event> el = rawEventsForDate(date,sorted);
mFilter->apply(&el);
return el;
}
QPtrList<Event> Calendar::events( const QDateTime &qdt )
{
QPtrList<Event> el = rawEventsForDate(qdt);
mFilter->apply(&el);
return el;
}
QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
bool inclusive)
{
QPtrList<Event> el = rawEvents(start,end,inclusive);
mFilter->apply(&el);
return el;
}
QPtrList<Event> Calendar::events()
{
QPtrList<Event> el = rawEvents();
mFilter->apply(&el);
return el;
}
void Calendar::addIncidenceBranch(Incidence *i)
{
addIncidence( i );
Incidence * inc;
QPtrList<Incidence> Relations = i->relations();
for (inc=Relations.first();inc;inc=Relations.next()) {
addIncidenceBranch( inc );
}
}
bool Calendar::addIncidence(Incidence *i)
{
Incidence::AddVisitor<Calendar> v(this);
+ if ( i->calID() == 0 )
i->setCalID( mDefaultCalendar );
i->setCalEnabled( true );
return i->accept(v);
}
void Calendar::deleteIncidence(Incidence *in)
{
if ( in->typeID() == eventID )
deleteEvent( (Event*) in );
else if ( in->typeID() == todoID )
deleteTodo( (Todo*) in);
else if ( in->typeID() == journalID )
deleteJournal( (Journal*) in );
}
Incidence* Calendar::incidence( const QString& uid )
{
Incidence* i;
if( (i = todo( uid )) != 0 )
return i;
if( (i = event( uid )) != 0 )
return i;
if( (i = journal( uid )) != 0 )
return i;
return 0;
}
QPtrList<Todo> Calendar::todos()
{
QPtrList<Todo> tl = rawTodos();
mFilter->apply( &tl );
return tl;
}
// When this is called, the todo have already been added to the calendar.
// This method is only about linking related todos
void Calendar::setupRelations( Incidence *incidence )
{
QString uid = incidence->uid();
//qDebug("Calendar::setupRelations ");
// First, go over the list of orphans and see if this is their parent
while( Incidence* i = mOrphans[ uid ] ) {
mOrphans.remove( uid );
i->setRelatedTo( incidence );
incidence->addRelation( i );
mOrphanUids.remove( i->uid() );
}
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 4652fe5..14a1a45 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -31,96 +31,97 @@
#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();
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;
+ virtual bool mergeCalendarFile( QString name ) = 0;
virtual void setSyncEventsReadOnly() = 0;
virtual void stopAllTodos() = 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).
*/
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index cce798f..3e42ec0 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -23,96 +23,171 @@
#include <qdatetime.h>
#include <qstring.h>
#include <qptrlist.h>
#include <kdebug.h>
#include <kconfig.h>
#include <kglobal.h>
#include <klocale.h>
#include "vcaldrag.h"
#include "vcalformat.h"
#include "icalformat.h"
#include "exceptions.h"
#include "incidence.h"
#include "journal.h"
#include "filestorage.h"
#include "calfilter.h"
#include "calendarlocal.h"
// #ifndef DESKTOP_VERSION
// #include <qtopia/alarmserver.h>
// #endif
using namespace KCal;
CalendarLocal::CalendarLocal()
: Calendar()
{
init();
}
CalendarLocal::CalendarLocal(const QString &timeZoneId)
: Calendar(timeZoneId)
{
init();
}
void CalendarLocal::init()
{
mNextAlarmIncidence = 0;
}
CalendarLocal::~CalendarLocal()
{
if ( mDeleteIncidencesOnClose )
close();
}
+bool CalendarLocal::mergeCalendarFile( QString name )
+{
+ CalendarLocal calendar( timeZoneId() );
+ calendar.setDefaultCalendar( 1 );
+ if ( calendar.load( name ) ) {
+ mergeCalendar( &calendar );
+ return true;
+ }
+ return false;
+}
+
+Incidence* CalendarLocal::incidenceForUid( const QString& uid )
+{
+ Todo *todo;;
+ Incidence *retVal = 0;
+ for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
+ if ( todo->uid() == uid ) {
+ if ( retVal ) {
+ if ( retVal->calID() > todo->calID() ) {
+ retVal = todo;
+ }
+ } else {
+ retVal = todo;
+ }
+ }
+ }
+ if ( retVal ) return retVal;
+ Event *event;
+ for ( event = mEventList.first(); event; event = mEventList.next() ) {
+ if ( event->uid() == uid ) {
+ if ( retVal ) {
+ if ( retVal->calID() > event->calID() ) {
+ retVal = event;
+ }
+ } else {
+ retVal = event;
+ }
+ }
+ }
+ if ( retVal ) return retVal;
+ for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
+ if ( it->uid() == uid ) {
+ if ( retVal ) {
+ if ( retVal->calID() > it->calID() ) {
+ retVal = it;
+ }
+ } else {
+ retVal = it;
+ }
+ }
+ return retVal;
+}
+
+bool CalendarLocal::mergeCalendar( Calendar* remote )
+{
+ QPtrList<Incidence> er = remote->rawIncidences();
+ Incidence* inR = er.first();
+ Incidence* inL;
+ while ( inR ) {
+ inL = incidenceForUid( inR->uid() );
+ if ( inL ) {
+ int calID = inL->calID();
+ deleteIncidence( inL );
+ inL = inR->clone();
+ inL->setCalID( calID );
+ addIncidence( inL );
+ } else {
+ inL = inR->clone();
+ inL->setCalID( 0 );// add to default cal
+ addIncidence( inL );
+ }
+ inR = er.next();
+ }
+ return true;
+}
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::setSyncEventsReadOnly()
{
Event * ev;
ev = mEventList.first();
while ( ev ) {
if ( ev->uid().left(15) == QString("last-syncEvent-") )
ev->setReadOnly( true );
ev = mEventList.next();
}
}
void CalendarLocal::addCalendar( Calendar* cal )
{
cal->setDontDeleteIncidencesOnClose();
{
QPtrList<Event> EventList = cal->rawEvents();
Event * ev = EventList.first();
while ( ev ) {
ev->unRegisterObserver( cal );
ev->registerObserver( this );
mEventList.append( ev );
ev = EventList.next();
}
}
{
QPtrList<Todo> TodoList = cal->rawTodos();
Todo * ev = TodoList.first();
while ( ev ) {
QString rel = ev->relatedToUid();
if ( !rel.isEmpty() ){
ev->setRelatedTo ( 0 );
ev->setRelatedToUid( rel );
}
ev = TodoList.next();
}
//TodoList = cal->rawTodos();
ev = TodoList.first();
while ( ev ) {
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index 98d16a3..23b0542 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -1,95 +1,98 @@
/*
This file is part of libkcal.
Copyright (c) 1998 Preston Brown
Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@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 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();
void addCalendar( Calendar* );
bool addCalendarFile( QString name, int id );
+ bool mergeCalendarFile( QString name );
+ bool mergeCalendar( Calendar* cal );
+ Incidence* incidenceForUid( const QString& uid );
void setSyncEventsReadOnly();
void stopAllTodos();
/**
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.
*/