summaryrefslogtreecommitdiffabout
path: root/libkcal
Side-by-side diff
Diffstat (limited to 'libkcal') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp1
-rw-r--r--libkcal/icalformat.cpp9
-rw-r--r--libkcal/icalformat.h3
-rw-r--r--libkcal/todo.cpp5
4 files changed, 14 insertions, 4 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index e37a7ad..eef8327 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -44,48 +44,49 @@
// #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()
{
+ registerObserver( 0 );
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 , bool doNotCheckDuplicates)
{
Todo *todo;;
Incidence *retVal = 0;
for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
if ( todo->uid() == uid ) {
if ( doNotCheckDuplicates ) return todo;
if ( retVal ) {
if ( retVal->calID() > todo->calID() ) {
retVal = todo;
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp
index 5877406..6f3a799 100644
--- a/libkcal/icalformat.cpp
+++ b/libkcal/icalformat.cpp
@@ -29,50 +29,51 @@
#include <stdlib.h>
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
extern "C" {
#include <ical.h>
#include <icalss.h>
#include <icalparser.h>
#include <icalrestriction.h>
}
#include "calendar.h"
#include "calendarlocal.h"
#include "journal.h"
#include "icalformat.h"
#include "icalformatimpl.h"
#define _ICAL_VERSION "2.0"
using namespace KCal;
-ICalFormat::ICalFormat( )
+ICalFormat::ICalFormat( bool pe )
{
+ mProcessEvents = pe;
mImpl = new ICalFormatImpl( this );
tzOffsetMin = 0;
//qDebug("new ICalFormat() ");
}
ICalFormat::~ICalFormat()
{
delete mImpl;
//qDebug("delete ICalFormat ");
}
bool ICalFormat::load( Calendar *calendar, const QString &fileName)
{
clearException();
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
setException(new ErrorFormat(ErrorFormat::LoadError));
return false;
}
QTextStream ts( &file );
QString text;
@@ -168,72 +169,78 @@ Incidence *ICalFormat::fromString( const QString &text )
ical = jlist.first();
}
}
}
return ical;
}
#include <qapp.h>
QString ICalFormat::toString( Calendar *cal )
{
setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
icalcomponent *calendar = mImpl->createCalendarComponent(cal);
icalcomponent *component;
// todos
QPtrList<Todo> todoList = cal->rawTodos();
QPtrListIterator<Todo> qlt(todoList);
for (; qlt.current(); ++qlt) {
component = mImpl->writeTodo(qlt.current());
icalcomponent_add_component(calendar,component);
//qDebug(" todos ");
+ if ( mProcessEvents ) {
+ //qDebug("mProcessEvents ");
qApp->processEvents();
}
+ }
// events
QPtrList<Event> events = cal->rawEvents();
Event *ev;
for(ev=events.first();ev;ev=events.next()) {
component = mImpl->writeEvent(ev);
icalcomponent_add_component(calendar,component);
//qDebug("events ");
+ if ( mProcessEvents )
qApp->processEvents();
}
// journals
QPtrList<Journal> journals = cal->journals();
Journal *j;
for(j=journals.first();j;j=journals.next()) {
component = mImpl->writeJournal(j);
icalcomponent_add_component(calendar,component);
//qDebug("journals ");
+ if ( mProcessEvents )
qApp->processEvents();
}
const char *text;
QString ret ="";
text = icalcomponent_as_ical_string( calendar );
+ if ( mProcessEvents )
qApp->processEvents();
// text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n";
if ( text ) {
ret = QString ( text );
}
icalcomponent_free( calendar );
if (!text) {
setException(new ErrorFormat(ErrorFormat::SaveError,
i18n("libical error")));
icalmemory_free_ring();
return QString::null;
}
icalmemory_free_ring();
return ret;
}
QString ICalFormat::toICalString( Incidence *incidence )
{
CalendarLocal cal( mTimeZoneId );
cal.addIncidence( incidence->clone() );
diff --git a/libkcal/icalformat.h b/libkcal/icalformat.h
index 485ab6e..a770dbb 100644
--- a/libkcal/icalformat.h
+++ b/libkcal/icalformat.h
@@ -19,49 +19,49 @@
*/
#ifndef ICALFORMAT_H
#define ICALFORMAT_H
#include <qstring.h>
#include "scheduler.h"
#include "calformat.h"
namespace KCal {
class ICalFormatImpl;
/**
This class implements the iCalendar format. It provides methods for
loading/saving/converting iCalendar format data into the internal KOrganizer
representation as Calendar and Events.
@short iCalendar format implementation
*/
class ICalFormat : public CalFormat {
public:
/** Create new iCalendar format. */
- ICalFormat( );
+ ICalFormat( bool pe = true);
virtual ~ICalFormat();
/**
Loads a calendar on disk in iCalendar format into calendar.
Returns true if successful, else returns false. Provides more error
information by exception().
@param calendar Calendar object to be filled.
@param fileName The name of the calendar file on disk.
*/
bool load( Calendar *, const QString &fileName );
/**
Writes out the calendar to disk in iCalendar format. Returns true if
successful and false on error.
@param calendar The Calendar object to be written.
@param fileName The name of the calendar file on disk.
*/
bool save( Calendar *, const QString &fileName );
/**
Parse string and populate calendar with that information.
*/
bool fromString( Calendar *, const QString & );
/**
@@ -82,34 +82,35 @@ class ICalFormat : public CalFormat {
QString toString( Incidence * );
/**
Return recurrence as iCalendar formatted text.
*/
QString toString( Recurrence * );
/**
Parse string and fill recurrence object with
that information
*/
//bool fromString ( Recurrence *, const QString& );
/** Create a scheduling message for event \a e using method \m */
QString createScheduleMessage(IncidenceBase *e,Scheduler::Method m);
/** Parse scheduling message provided as string \s */
ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s);
/** Set id of used time zone and whether this time zone is UTC or not. */
void setTimeZone( const QString &id, bool utc );
QString timeZoneId() const;
int timeOffset();
const char * tzString();
bool utc() const;
private:
+ bool mProcessEvents;
ICalFormatImpl *mImpl;
QString mTimeZoneId;
QCString mTzString;
int tzOffsetMin;
bool mUtc;
};
}
#endif
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 4ada2d8..7bf756a 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -45,48 +45,49 @@ Todo::Todo(): QObject(), Incidence()
}
Todo::Todo(const Todo &t) : QObject(),Incidence(t)
{
mDtDue = t.mDtDue;
mHasDueDate = t.mHasDueDate;
mCompleted = t.mCompleted;
mHasCompletedDate = t.mHasCompletedDate;
mPercentComplete = t.mPercentComplete;
mRunning = false;
mRunSaveTimer = 0;
}
Todo::~Todo()
{
setRunning( false );
//qDebug("Todo::~Todo() ");
}
void Todo::setRunningFalse( QString s )
{
if ( ! mRunning )
return;
mRunning = false;
+ if ( mRunSaveTimer )
mRunSaveTimer->stop();
saveRunningInfoToFile( s );
}
void Todo::stopRunning()
{
if ( !mRunning )
return;
if ( mRunSaveTimer )
mRunSaveTimer->stop();
mRunning = false;
}
void Todo::setRunning( bool run )
{
if ( run == mRunning )
return;
//qDebug("Todo::setRunning %d ", run);
if ( !mRunSaveTimer ) {
mRunSaveTimer = new QTimer ( this );
connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
}
mRunning = run;
if ( mRunning ) {
mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
mRunStart = QDateTime::currentDateTime();
@@ -118,77 +119,77 @@ void Todo::saveRunningInfoToFile( QString comment )
QString dir = KGlobalSettings::timeTrackerDir();
//qDebug("%s ", dir.latin1());
QString file = "%1%2%3-%4%5%6-";
file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 );
file.replace ( QRegExp (" "), "0" );
file += uid();
//qDebug("File %s ",file.latin1() );
CalendarLocal cal;
cal.setLocalTime();
Todo * to = (Todo*) clone();
to->setFloats( false );
to->setDtStart( mRunStart );
to->setHasStartDate( true );
to->setDtDue( mRunEnd );
to->setHasDueDate( true );
to->setUid( file );
if ( !comment.isEmpty() ) {
QString des = to->description();
if ( des.isEmpty () )
to->setDescription( "TT-Note: " + comment );
else
to->setDescription( "TT-Note: " + comment +"\n" + des );
}
cal.addIncidence( to );
- ICalFormat format;
+ ICalFormat format( false );
file = dir +"/" +file +".ics";
format.save( &cal, file );
saveParents();
}
void Todo::saveParents()
{
if (!relatedTo() )
return;
Incidence * inc = relatedTo();
if ( inc->typeID() != todoID )
return;
Todo* to = (Todo*)inc;
bool saveTodo = false;
QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
QFileInfo fi ( file );
if ( fi.exists() ) {
if ( fi.lastModified () < to->lastModified ())
saveTodo = true;
} else {
saveTodo = true;
}
if ( saveTodo ) {
CalendarLocal cal;
cal.setLocalTime();
Todo * par = (Todo *) to->clone();
cal.addIncidence( par );
- ICalFormat format;
+ ICalFormat format( false );
format.save( &cal, file );
}
to->saveParents();
}
int Todo::runTime()
{
if ( !mRunning )
return 0;
return mRunStart.secsTo( QDateTime::currentDateTime() );
}
bool Todo::hasRunningSub()
{
if ( mRunning )
return true;
Incidence *aTodo;
for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
if ( ((Todo*)aTodo)->hasRunningSub() )
return true;
}
return false;
}
Incidence *Todo::clone()
{