summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-08-01 12:02:39 (UTC)
committer zautrix <zautrix>2004-08-01 12:02:39 (UTC)
commitc31e99f265dbe8762efca20667f8ccd973840f8f (patch) (side-by-side diff)
tree29e7fd6845d187f41f9d80e756611dc8bc182bdc /libkcal
parente954cc1e29b129982e4d07c4f490d7e881597374 (diff)
downloadkdepimpi-c31e99f265dbe8762efca20667f8ccd973840f8f.zip
kdepimpi-c31e99f265dbe8762efca20667f8ccd973840f8f.tar.gz
kdepimpi-c31e99f265dbe8762efca20667f8ccd973840f8f.tar.bz2
Changed zaurusstat to tempsyncstat
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp8
-rw-r--r--libkcal/incidencebase.cpp12
-rw-r--r--libkcal/incidencebase.h6
-rw-r--r--libkcal/sharpformat.cpp14
4 files changed, 16 insertions, 24 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index 3437f45..df05ab3 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -181,195 +181,192 @@ icalcomponent *ICalFormatImpl::writeEvent(Event *event)
// resources
tmpStrList = anEvent->resources();
tmpStr = tmpStrList.join(";");
if (!tmpStr.isEmpty())
addPropValue(vevent, VCResourcesProp, tmpStr.utf8());
#endif
// Transparency
switch( event->transparency() ) {
case Event::Transparent:
icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT));
break;
case Event::Opaque:
icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE));
break;
}
return vevent;
}
icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy,
Scheduler::Method method)
{
#if QT_VERSION >= 300
kdDebug(5800) << "icalformatimpl: writeFreeBusy: startDate: "
<< freebusy->dtStart().toString("ddd MMMM d yyyy: h:m:s ap") << " End Date: "
<< freebusy->dtEnd().toString("ddd MMMM d yyyy: h:m:s ap") << endl;
#endif
icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
writeIncidenceBase(vfreebusy,freebusy);
icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
writeICalDateTime(freebusy->dtStart())));
icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
writeICalDateTime(freebusy->dtEnd())));
if (method == Scheduler::Request) {
icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
freebusy->uid().utf8()));
}
//Loops through all the periods in the freebusy object
QValueList<Period> list = freebusy->busyPeriods();
QValueList<Period>::Iterator it;
icalperiodtype period;
for (it = list.begin(); it!= list.end(); ++it) {
period.start = writeICalDateTime((*it).start());
period.end = writeICalDateTime((*it).end());
icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
}
return vfreebusy;
}
icalcomponent *ICalFormatImpl::writeJournal(Journal *journal)
{
icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
writeIncidence(vjournal,journal);
// start time
if (journal->dtStart().isValid()) {
icaltimetype start;
if (journal->doesFloat()) {
// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
start = writeICalDate(journal->dtStart().date());
} else {
// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
start = writeICalDateTime(journal->dtStart());
}
icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
}
return vjournal;
}
void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
{
// pilot sync stuff
// TODO: move this application-specific code to kpilot
if (incidence->pilotId()) {
incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId()));
incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus()));
}
if (incidence->zaurusId() >= 0) {
incidence->setNonKDECustomProperty("X-ZAURUSID", QString::number(incidence->zaurusId()));
}
if (incidence->zaurusUid() > 0) {
incidence->setNonKDECustomProperty("X-ZAURUSUID", QString::number(incidence->zaurusUid()));
}
- if (incidence->zaurusStat() > 0) {
- incidence->setNonKDECustomProperty("X-ZAURUSSTAT", QString::number(incidence->zaurusStat()));
- }
writeIncidenceBase(parent,incidence);
if (incidence->cancelled()) {
icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED));
}
// creation date
icalcomponent_add_property(parent,icalproperty_new_created(
writeICalDateTime(incidence->created())));
// unique id
icalcomponent_add_property(parent,icalproperty_new_uid(
incidence->uid().utf8()));
// revision
icalcomponent_add_property(parent,icalproperty_new_sequence(
incidence->revision()));
// last modification date
icalcomponent_add_property(parent,icalproperty_new_lastmodified(
writeICalDateTime(incidence->lastModified())));
// description
if (!incidence->description().isEmpty()) {
icalcomponent_add_property(parent,icalproperty_new_description(
incidence->description().utf8()));
}
// summary
if (!incidence->summary().isEmpty()) {
icalcomponent_add_property(parent,icalproperty_new_summary(
incidence->summary().utf8()));
}
// location
if (!incidence->location().isEmpty()) {
icalcomponent_add_property(parent,icalproperty_new_location(
incidence->location().utf8()));
}
// TODO:
// status
// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8());
// secrecy
enum icalproperty_class classInt;
switch (incidence->secrecy()) {
case Incidence::SecrecyPublic:
classInt = ICAL_CLASS_PUBLIC;
break;
case Incidence::SecrecyConfidential:
classInt = ICAL_CLASS_CONFIDENTIAL;
break;
case Incidence::SecrecyPrivate:
classInt =ICAL_CLASS_PRIVATE ;
default:
classInt =ICAL_CLASS_PRIVATE ;
break;
}
icalcomponent_add_property(parent,icalproperty_new_class(classInt));
// priority
icalcomponent_add_property(parent,icalproperty_new_priority(
incidence->priority()));
// categories
QStringList categories = incidence->categories();
QStringList::Iterator it;
for(it = categories.begin(); it != categories.end(); ++it ) {
icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
}
// TODO: Ensure correct concatenation of categories properties.
/*
// categories
tmpStrList = incidence->getCategories();
tmpStr = "";
QString catStr;
for ( QStringList::Iterator it = tmpStrList.begin();
it != tmpStrList.end();
++it ) {
catStr = *it;
if (catStr[0] == ' ')
tmpStr += catStr.mid(1);
else
tmpStr += catStr;
// this must be a ';' character as the vCalendar specification requires!
// vcc.y has been hacked to translate the ';' to a ',' when the vcal is
// read in.
tmpStr += ";";
}
if (!tmpStr.isEmpty()) {
tmpStr.truncate(tmpStr.length()-1);
icalcomponent_add_property(parent,icalproperty_new_categories(
writeText(incidence->getCategories().join(";"))));
}
@@ -1200,197 +1197,192 @@ void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
{
text = icalproperty_get_summary(p);
incidence->setSummary(QString::fromUtf8(text));
}
break;
case ICAL_STATUS_PROPERTY: // summary
{
if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) )
incidence->setCancelled( true );
}
break;
case ICAL_LOCATION_PROPERTY: // location
text = icalproperty_get_location(p);
incidence->setLocation(QString::fromUtf8(text));
break;
#if 0
// status
if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) {
incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo)));
deleteStr(s);
}
else
incidence->setStatus("NEEDS ACTION");
#endif
case ICAL_PRIORITY_PROPERTY: // priority
intvalue = icalproperty_get_priority(p);
incidence->setPriority(intvalue);
break;
case ICAL_CATEGORIES_PROPERTY: // categories
text = icalproperty_get_categories(p);
categories.append(QString::fromUtf8(text));
break;
//*******************************************
case ICAL_RRULE_PROPERTY:
// we do need (maybe )start datetime of incidence for recurrence
// such that we can read recurrence only after we read incidence completely
readrec = true;
rectype = icalproperty_get_rrule(p);
break;
case ICAL_EXDATE_PROPERTY:
icaltime = icalproperty_get_exdate(p);
incidence->addExDate(readICalDate(icaltime));
break;
case ICAL_CLASS_PROPERTY: {
int inttext = icalproperty_get_class(p);
if (inttext == ICAL_CLASS_PUBLIC ) {
incidence->setSecrecy(Incidence::SecrecyPublic);
} else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
incidence->setSecrecy(Incidence::SecrecyConfidential);
} else {
incidence->setSecrecy(Incidence::SecrecyPrivate);
}
}
break;
case ICAL_ATTACH_PROPERTY: // attachments
incidence->addAttachment(readAttachment(p));
break;
default:
// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
// << endl;
break;
}
p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
}
if ( readrec ) {
readRecurrenceRule(rectype,incidence);
}
// kpilot stuff
// TODO: move this application-specific code to kpilot
QString kp = incidence->nonKDECustomProperty("X-PILOTID");
if (!kp.isNull()) {
incidence->setPilotId(kp.toInt());
}
kp = incidence->nonKDECustomProperty("X-PILOTSTAT");
if (!kp.isNull()) {
incidence->setSyncStatus(kp.toInt());
}
kp = incidence->nonKDECustomProperty("X-ZAURUSID");
if (!kp.isNull()) {
incidence->setZaurusId(kp.toInt());
}
kp = incidence->nonKDECustomProperty("X-ZAURUSUID");
if (!kp.isNull()) {
incidence->setZaurusUid(kp.toInt());
}
- kp = incidence->nonKDECustomProperty("X-ZAURUSSTAT");
- if (!kp.isNull()) {
- incidence->setZaurusStat(kp.toInt());
- }
-
// Cancel backwards compatibility mode for subsequent changes by the application
incidence->recurrence()->setCompatVersion();
// add categories
incidence->setCategories(categories);
// iterate through all alarms
for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
alarm;
alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
readAlarm(alarm,incidence);
}
}
void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
{
icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
while (p) {
icalproperty_kind kind = icalproperty_isa(p);
switch (kind) {
case ICAL_UID_PROPERTY: // unique id
incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
break;
case ICAL_ORGANIZER_PROPERTY: // organizer
incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p)));
break;
case ICAL_ATTENDEE_PROPERTY: // attendee
incidenceBase->addAttendee(readAttendee(p));
break;
default:
break;
}
p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
}
// custom properties
readCustomProperties(parent, incidenceBase);
}
void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
{
QMap<QCString, QString> customProperties;
icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
while (p) {
QString value = QString::fromUtf8(icalproperty_get_x(p));
customProperties[icalproperty_get_x_name(p)] = value;
//qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
}
properties->setCustomProperties(customProperties);
}
void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
{
// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl;
Recurrence *recur = incidence->recurrence();
recur->setCompatVersion(mCalendarVersion);
recur->unsetRecurs();
struct icalrecurrencetype r = rrule;
dumpIcalRecurrence(r);
readRecurrence( r, recur, incidence);
}
void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
{
int wkst;
int index = 0;
short day = 0;
QBitArray qba(7);
int frequ = r.freq;
int interv = r.interval;
// preprocessing for odd recurrence definitions
if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
interv = 12;
}
}
if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
frequ = ICAL_MONTHLY_RECURRENCE;
interv = 12* r.interval;
}
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 9479048..707d666 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,162 +1,162 @@
/*
This file is part of libkcal.
Copyright (c) 2001 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.
*/
#include <kglobal.h>
#include <klocale.h>
#include <kdebug.h>
#include "calformat.h"
#include "incidencebase.h"
using namespace KCal;
IncidenceBase::IncidenceBase() :
mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
mPilotId(0), mSyncStatus(SYNCMOD)
{
setUid(CalFormat::createUniqueId());
mOrganizer = "";
mFloats = false;
mDuration = 0;
mHasDuration = false;
mPilotId = 0;
mZaurusId = -1;
mZaurusUid = 0;
- mZaurusStat = 0;
+ mTempSyncStat = 0;
mSyncStatus = 0;
mAttendees.setAutoDelete( true );
}
IncidenceBase::IncidenceBase(const IncidenceBase &i) :
CustomProperties( i )
{
mReadOnly = i.mReadOnly;
mDtStart = i.mDtStart;
mDuration = i.mDuration;
mHasDuration = i.mHasDuration;
mOrganizer = i.mOrganizer;
mUid = i.mUid;
QPtrList<Attendee> attendees = i.attendees();
for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
mAttendees.append( new Attendee( *a ) );
}
mFloats = i.mFloats;
mLastModified = i.mLastModified;
mPilotId = i.mPilotId;
mZaurusId = i.mZaurusId;
mZaurusUid = i.mZaurusUid;
- mZaurusStat = i.mZaurusStat;
+ mTempSyncStat = i.mTempSyncStat;
mSyncStatus = i.mSyncStatus;
// The copied object is a new one, so it isn't observed by the observer
// of the original object.
mObservers.clear();
mAttendees.setAutoDelete( true );
}
IncidenceBase::~IncidenceBase()
{
}
bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
{
if( i1.attendees().count() != i2.attendees().count() ) {
return false; // no need to check further
}
if ( i1.attendees().count() > 0 ) {
Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
while ( a1 ) {
if ( !( (*a1) == (*a2)) )
{
//qDebug("Attendee not equal ");
return false;
}
a1 = i1.attendees().next();
a2 = i2.attendees().next();
}
}
//if ( i1.dtStart() != i2.dtStart() )
// return false;
#if 0
qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
qDebug("1 %d ",i1.duration() == i2.duration() );
qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
qDebug("6 %d ",i1.organizer() == i2.organizer() );
#endif
return ( i1.organizer() == i2.organizer() &&
// i1.uid() == i2.uid() &&
// Don't compare lastModified, otherwise the operator is not
// of much use. We are not comparing for identity, after all.
i1.doesFloat() == i2.doesFloat() &&
i1.duration() == i2.duration() &&
i1.hasDuration() == i2.hasDuration() &&
i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
// no need to compare mObserver
}
QDateTime IncidenceBase::getEvenTime( QDateTime dt )
{
QTime t = dt.time();
dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
return dt;
}
void IncidenceBase::setUid(const QString &uid)
{
mUid = uid;
updated();
}
QString IncidenceBase::uid() const
{
return mUid;
}
void IncidenceBase::setLastModified(const QDateTime &lm)
{
// DON'T! updated() because we call this from
// Calendar::updateEvent().
mLastModified = getEvenTime(lm);
//qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
}
QDateTime IncidenceBase::lastModified() const
{
return mLastModified;
}
void IncidenceBase::setOrganizer(const QString &o)
{
// we don't check for readonly here, because it is
// possible that by setting the organizer we are changing
// the event's readonly status...
mOrganizer = o;
if (mOrganizer.left(7).upper() == "MAILTO:")
mOrganizer = mOrganizer.remove(0,7);
@@ -269,125 +269,125 @@ Attendee *IncidenceBase::getAttendee(const char *n) const
Attendee *IncidenceBase::attendeeByMail(const QString &email)
{
QPtrListIterator<Attendee> qli(mAttendees);
qli.toFirst();
while (qli) {
if (qli.current()->email() == email)
return qli.current();
++qli;
}
return 0L;
}
Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
{
QPtrListIterator<Attendee> qli(mAttendees);
QStringList mails = emails;
if (!email.isEmpty()) {
mails.append(email);
}
qli.toFirst();
while (qli) {
for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
if (qli.current()->email() == *it)
return qli.current();
}
++qli;
}
return 0L;
}
void IncidenceBase::setDuration(int seconds)
{
mDuration = seconds;
setHasDuration(true);
}
int IncidenceBase::duration() const
{
return mDuration;
}
void IncidenceBase::setHasDuration(bool b)
{
mHasDuration = b;
}
bool IncidenceBase::hasDuration() const
{
return mHasDuration;
}
void IncidenceBase::setSyncStatus(int stat)
{
if (mReadOnly) return;
mSyncStatus = stat;
}
int IncidenceBase::syncStatus() const
{
return mSyncStatus;
}
void IncidenceBase::setPilotId( int id )
{
if (mReadOnly) return;
mPilotId = id;
}
int IncidenceBase::pilotId() const
{
return mPilotId;
}
void IncidenceBase::setZaurusId( int id )
{
if (mReadOnly) return;
mZaurusId = id;
}
int IncidenceBase::zaurusId() const
{
return mZaurusId;
}
int IncidenceBase::zaurusUid() const
{
return mZaurusUid;
}
void IncidenceBase::setZaurusUid( int id )
{
if (mReadOnly) return;
mZaurusUid = id;
}
-int IncidenceBase::zaurusStat() const
+int IncidenceBase::tempSyncStat() const
{
- return mZaurusStat;
+ return mTempSyncStat;
}
-void IncidenceBase::setZaurusStat( int id )
+void IncidenceBase::setTempSyncStat( int id )
{
if (mReadOnly) return;
- mZaurusStat = id;
+ mTempSyncStat = id;
}
void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
{
if( !mObservers.contains(observer) ) mObservers.append( observer );
}
void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
{
mObservers.remove( observer );
}
void IncidenceBase::updated()
{
QPtrListIterator<Observer> it(mObservers);
while( it.current() ) {
Observer *o = it.current();
++it;
o->incidenceUpdated( this );
}
}
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index 0ab7eef..ce6e254 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -37,134 +37,134 @@ typedef QValueList<QDate> DateList;
/**
This class provides the base class common to all calendar components.
*/
class IncidenceBase : public CustomProperties
{
public:
class Observer {
public:
virtual void incidenceUpdated( IncidenceBase * ) = 0;
};
IncidenceBase();
IncidenceBase(const IncidenceBase &);
virtual ~IncidenceBase();
virtual QCString type() const = 0;
/** Set the unique id for the event */
void setUid(const QString &);
/** Return the unique id for the event */
QString uid() const;
/** Sets the time the incidence was last modified. */
void setLastModified(const QDateTime &lm);
/** Return the time the incidence was last modified. */
QDateTime lastModified() const;
/** sets the organizer for the event */
void setOrganizer(const QString &o);
QString organizer() const;
/** Set readonly status. */
virtual void setReadOnly( bool );
/** Return if the object is read-only. */
bool isReadOnly() const { return mReadOnly; }
/** for setting the event's starting date/time with a QDateTime. */
virtual void setDtStart(const QDateTime &dtStart);
/** returns an event's starting date/time as a QDateTime. */
QDateTime dtStart() const;
/** returns an event's starting time as a string formatted according to the
users locale settings */
QString dtStartTimeStr() const;
/** returns an event's starting date as a string formatted according to the
users locale settings */
QString dtStartDateStr(bool shortfmt=true) const;
/** returns an event's starting date and time as a string formatted according
to the users locale settings */
QString dtStartStr(bool shortfmt=true) const;
virtual void setDuration(int seconds);
int duration() const;
void setHasDuration(bool);
bool hasDuration() const;
/** Return true or false depending on whether the incidence "floats,"
* i.e. has a date but no time attached to it. */
bool doesFloat() const;
/** Set whether the incidence floats, i.e. has a date but no time attached to it. */
void setFloats(bool f);
/**
Add Attendee to this incidence. IncidenceBase takes ownership of the
Attendee object.
*/
void addAttendee(Attendee *a, bool doupdate=true );
// void removeAttendee(Attendee *a);
// void removeAttendee(const char *n);
/** Remove all Attendees. */
void clearAttendees();
/** Return list of attendees. */
QPtrList<Attendee> attendees() const { return mAttendees; };
/** Return number of attendees. */
int attendeeCount() const { return mAttendees.count(); };
/** Return the Attendee with this email */
Attendee* attendeeByMail(const QString &);
/** Return first Attendee with one of this emails */
Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null);
/** pilot syncronization states */
enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
/** Set synchronisation satus. */
void setSyncStatus(int stat);
/** Return synchronisation status. */
int syncStatus() const;
/** Set Pilot Id. */
void setPilotId(int id);
/** Return Pilot Id. */
int pilotId() const;
void setZaurusId(int id);
int zaurusId() const;
void setZaurusUid(int id);
int zaurusUid() const;
- void setZaurusStat(int id);
- int zaurusStat() const;
+ void setTempSyncStat(int id);
+ int tempSyncStat() const;
void registerObserver( Observer * );
void unRegisterObserver( Observer * );
void updated();
protected:
bool mReadOnly;
QDateTime getEvenTime( QDateTime );
private:
// base components
QDateTime mDtStart;
QString mOrganizer;
QString mUid;
QDateTime mLastModified;
QPtrList<Attendee> mAttendees;
bool mFloats;
int mDuration;
bool mHasDuration;
int mZaurusId;
int mZaurusUid;
- int mZaurusStat;
+ int mTempSyncStat;
// PILOT SYNCHRONIZATION STUFF
int mPilotId; // unique id for pilot sync
int mSyncStatus; // status (for sync)
QPtrList<Observer> mObservers;
};
bool operator==( const IncidenceBase&, const IncidenceBase& );
}
#endif
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index 973f19d..d39d2dd 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -1,302 +1,302 @@
/*
This file is part of libkcal.
Copyright (c) 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.
*/
#include <qdatetime.h>
#include <qstring.h>
#include <qapplication.h>
#include <qptrlist.h>
#include <qregexp.h>
#include <qmessagebox.h>
#include <qclipboard.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qtextcodec.h>
#include <qxml.h>
#include <qlabel.h>
#include <kdebug.h>
#include <klocale.h>
#include <kglobal.h>
#include "calendar.h"
#include "alarm.h"
#include "recurrence.h"
#include "calendarlocal.h"
#include "sharpformat.h"
#include "syncdefines.h"
using namespace KCal;
//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//ARSD silentalarm = 0
// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly
// 12 RFRQ
// 13 RPOS pos = 4. monday in month
// 14 RDYS days: 1 mon/ 2 tue .. 64 sun
// 15 REND 0 = no end/ 1 = end
// 16 REDT rec end dt
//ALSD
//ALED
//MDAY
class SharpParser : public QObject
{
public:
SharpParser( Calendar *calendar ) : mCalendar( calendar ) {
oldCategories = 0;
}
bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
{
int i = 1;
bool skip = true;
int max = attList.count() -2;
while ( i < max ) {
if ( !attList[i].isEmpty() ) {
skip = false;
break;
}
++i ;
}
if ( skip )
return false;
ulong cSum = SharpFormat::getCsum(attList );
if ( qName == "Event" ) {
Event *event;
event = existingCalendar->event( attList[0].toInt() );
if ( event )
event = (Event*)event->clone();
else
event = new Event;
event->setZaurusId( attList[0].toInt() );
event->setZaurusUid( cSum );
- event->setZaurusStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
+ event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
event->setSummary( attList[2] );
event->setLocation( attList[3] );
event->setDescription( attList[4] );
if ( attList[7] == "1" ) {
event->setDtStart( QDateTime(fromString( attList[17]+"000000", false ).date(),QTime(0,0,0 ) ));
event->setDtEnd( QDateTime(fromString( attList[18]+"000000", false ).date(),QTime(0,0,0 )));
event->setFloats( true );
} else {
event->setFloats( false );
event->setDtStart( fromString( attList[5] ) );
event->setDtEnd( fromString( attList[6] ));
}
QString rtype = attList[11];
if ( rtype != "255" ) {
// qDebug("recurs ");
QDate startDate = event->dtStart().date();
QString freqStr = attList[12];
int freq = freqStr.toInt();
QString hasEndDateStr = attList[15] ;
bool hasEndDate = hasEndDateStr == "1";
QString endDateStr = attList[16];
QDate endDate = fromString( endDateStr ).date();
QString weekDaysStr = attList[14];
uint weekDaysNum = weekDaysStr.toInt();
QBitArray weekDays( 7 );
int i;
int bb = 1;
for( i = 1; i <= 7; ++i ) {
weekDays.setBit( i - 1, ( bb & weekDaysNum ));
bb = 2 << (i-1);
//qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
}
// qDebug("next ");
QString posStr = attList[13];
int pos = posStr.toInt();
Recurrence *r = event->recurrence();
if ( rtype == "0" ) {
if ( hasEndDate ) r->setDaily( freq, endDate );
else r->setDaily( freq, -1 );
} else if ( rtype == "1" ) {
if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
else r->setWeekly( freq, weekDays, -1 );
} else if ( rtype == "3" ) {
if ( hasEndDate )
r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
else
r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
r->addMonthlyDay( startDate.day() );
} else if ( rtype == "2" ) {
if ( hasEndDate )
r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
else
r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
QBitArray days( 7 );
days.fill( false );
days.setBit( startDate.dayOfWeek() - 1 );
r->addMonthlyPos( pos, days );
} else if ( rtype == "4" ) {
if ( hasEndDate )
r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
else
r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
r->addYearlyNum( startDate.month() );
}
}
QString categoryList = attList[1] ;
event->setCategories( lookupCategories( categoryList ) );
// strange 0 semms to mean: alarm enabled
if ( attList[8] == "0" ) {
Alarm *alarm;
if ( event->alarms().count() > 0 )
alarm = event->alarms().first();
else {
alarm = new Alarm( event );
event->addAlarm( alarm );
}
alarm->setType( Alarm::Audio );
alarm->setEnabled( true );
int alarmOffset = attList[9].toInt();
alarm->setStartOffset( alarmOffset * -60 );
}
mCalendar->addEvent( event);
} else if ( qName == "Todo" ) {
Todo *todo;
todo = existingCalendar->todo( attList[0].toInt() );
if (todo )
todo = (Todo*)todo->clone();
else
todo = new Todo;
//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1
// 0 1 2 3 4 5 6 7 8
//1,,,,,1,4,Loch zumachen,""
//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" "
//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes
todo->setZaurusId( attList[0].toInt() );
todo->setZaurusUid( cSum );
- todo->setZaurusStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
+ todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
todo->setSummary( attList[7] );
todo->setDescription( attList[8]);
int priority = attList[6].toInt();
if ( priority == 0 ) priority = 3;
todo->setPriority( priority );
QString categoryList = attList[1];
todo->setCategories( lookupCategories( categoryList ) );
QString hasDateStr = attList[3]; // due
if ( !hasDateStr.isEmpty() ) {
if ( hasDateStr.right(6) == "000000" ) {
todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
todo->setFloats( true );
}
else {
todo->setDtDue( fromString( hasDateStr ) );
todo->setFloats( false );
}
todo->setHasDueDate( true );
}
hasDateStr = attList[2];//start
if ( !hasDateStr.isEmpty() ) {
todo->setDtStart( fromString( hasDateStr ) );
todo->setHasStartDate( true);
} else
todo->setHasStartDate( false );
hasDateStr = attList[4];//completed
if ( !hasDateStr.isEmpty() ) {
todo->setCompleted(fromString( hasDateStr ) );
}
QString completedStr = attList[5];
if ( completedStr == "0" )
todo->setCompleted( true );
else
todo->setCompleted( false );
mCalendar->addTodo( todo );
} else if ( qName == "Category" ) {
/*
QString id = attributes.value( "id" );
QString name = attributes.value( "name" );
setCategory( id, name );
*/
}
//qDebug("end ");
return true;
}
void setCategoriesList ( QStringList * c )
{
oldCategories = c;
}
QDateTime fromString ( QString s, bool useTz = true ) {
QDateTime dt;
int y,m,t,h,min,sec;
y = s.mid(0,4).toInt();
m = s.mid(4,2).toInt();
t = s.mid(6,2).toInt();
h = s.mid(9,2).toInt();
min = s.mid(11,2).toInt();
sec = s.mid(13,2).toInt();
dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
int offset = KGlobal::locale()->localTimeOffset( dt );
if ( useTz )
dt = dt.addSecs ( offset*60);
return dt;
}
protected:
QDateTime toDateTime( const QString &value )
{
QDateTime dt;
dt.setTime_t( value.toUInt() );
return dt;
}
QStringList lookupCategories( const QString &categoryList )
{
QStringList categoryIds = QStringList::split( ";", categoryList );
QStringList categories;
QStringList::ConstIterator it;
for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
QString cate = category( *it );
if ( oldCategories ) {
if ( ! oldCategories->contains( cate ) )
oldCategories->append( cate );
@@ -375,322 +375,322 @@ bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
status.setCaption(i18n("Reading DTM Data") );
status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
status.show();
status.raise();
qApp->processEvents();
QString fileName;
if ( ! debug ) {
fileName = "/tmp/kopitempout";
QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
system ( command.latin1() );
} else {
fileName = "/tmp/events.txt";
}
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
return false;
}
QTextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
text = ts.read();
file.close();
status.setText( i18n("Processing events ...") );
status.raise();
qApp->processEvents();
fromString2Cal( calendar, existngCal, text, "Event" );
status.setText( i18n("Reading todos ...") );
qApp->processEvents();
if ( ! debug ) {
fileName = "/tmp/kopitempout";
QString command = "db2file todo -r -c " + codec+ " > " + fileName;
system ( command.latin1() );
} else {
fileName = "/tmp/todo.txt";
}
file.setName( fileName );
if (!file.open( IO_ReadOnly ) ) {
return false;
}
ts.setDevice( &file );
text = ts.read();
file.close();
status.setText( i18n("Processing todos ...") );
status.raise();
qApp->processEvents();
fromString2Cal( calendar, existngCal, text, "Todo" );
return true;
}
int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
{
int retval = -1;
QStringList templist;
QString tempString;
int start = 0;
int len = answer.length();
int end = answer.find ("\n",start)+1;
bool ok = true;
start = end;
int ccc = 0;
while ( start > 0 ) {
templist.clear();
ok = true;
int loopCount = 0;
while ( ok ) {
++loopCount;
if ( loopCount > 25 ) {
qDebug("KO: Error in while loop");
ok = false;
start = 0;
break;
}
if ( ok )
tempString = getPart( answer, ok, start );
if ( start >= len || start == 0 ) {
start = 0;
ok = false;
}
if ( tempString.right(1) =="\n" )
tempString = tempString.left( tempString.length()-1);
templist.append( tempString );
}
++ccc;
if ( ccc == 2 && loopCount < 25 ) {
start = 0;
bool ok;
int newnum = templist[0].toInt( &ok );
if ( ok && newnum > 0) {
retval = newnum;
inc->setZaurusId( newnum );
inc->setZaurusUid( getCsum( templist ) );
- inc->setZaurusStat( SYNC_TEMPSTATE_NEW_ID );
+ inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
}
}
}
//qDebug("getNumFromRecord returning : %d ", retval);
return retval;
}
bool SharpFormat::save( Calendar *calendar)
{
QLabel status ( i18n("Processing/adding events ..."), 0 );
int w = status.sizeHint().width()+20 ;
if ( w < 200 ) w = 200;
int h = status.sizeHint().height()+20 ;
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
status.setCaption(i18n("Writing DTM Data") );
status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
status.show();
status.raise();
qApp->processEvents();
bool debug = DEBUGMODE;
QString codec = "utf8";
QString answer;
QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
QString command;
QPtrList<Event> er = calendar->rawEvents();
Event* ev = er.first();
QString fileName = "/tmp/kopitempout";
int i = 0;
QString changeString = ePrefix;
QString deleteString = ePrefix;
bool deleteEnt = false;
bool changeEnt = false;
QString message = i18n("Processing event # ");
int procCount = 0;
while ( ev ) {
//qDebug("i %d ", ++i);
- if ( ev->zaurusStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
+ if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
QString eString = getEventString( ev );
- if ( ev->zaurusStat() == SYNC_TEMPSTATE_DELETE ) { // delete
+ if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
// deleting empty strings does not work.
// we write first and x and then delete the record with the x
eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
changeString += eString + "\n";
deleteString += eString + "\n";
deleteEnt = true;
changeEnt = true;
}
else if ( ev->zaurusId() == -1 ) { // add new
command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
system ( command.utf8() );
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
return false;
}
QTextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
answer = ts.read();
file.close();
//qDebug("answer \n%s ", answer.latin1());
getNumFromRecord( answer, ev ) ;
}
else { // change existing
//qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
//command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
changeString += eString + "\n";
changeEnt = true;
}
}
ev = er.next();
}
status.setText ( i18n("Changing events ...") );
qApp->processEvents();
//qDebug("changing... ");
if ( changeEnt ) {
QFile file( fileName );
if (!file.open( IO_WriteOnly ) ) {
return false;
}
QTextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
ts << changeString ;
file.close();
command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
system ( command.latin1() );
//qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
}
status.setText ( i18n("Deleting events ...") );
qApp->processEvents();
//qDebug("deleting... ");
if ( deleteEnt ) {
QFile file( fileName );
if (!file.open( IO_WriteOnly ) ) {
return false;
}
QTextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
ts << deleteString;
file.close();
command = "db2file datebook -d -c " + codec+ " < "+ fileName;
system ( command.latin1() );
// qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
}
changeString = tPrefix;
deleteString = tPrefix;
status.setText ( i18n("Processing todos ...") );
qApp->processEvents();
QPtrList<Todo> tl = calendar->rawTodos();
Todo* to = tl.first();
i = 0;
message = i18n("Processing todo # ");
procCount = 0;
while ( to ) {
- if ( to->zaurusStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
+ if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
QString eString = getTodoString( to );
- if ( to->zaurusStat() == SYNC_TEMPSTATE_DELETE ) { // delete
+ if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
// deleting empty strings does not work.
// we write first and x and then delete the record with the x
eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
changeString += eString + "\n";
deleteString += eString + "\n";
deleteEnt = true;
changeEnt = true;
}
else if ( to->zaurusId() == -1 ) { // add new
command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName;
system ( command.utf8() );
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
return false;
}
QTextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
answer = ts.read();
file.close();
//qDebug("answer \n%s ", answer.latin1());
getNumFromRecord( answer, to ) ;
}
else { // change existing
//qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
//command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
changeString += eString + "\n";
changeEnt = true;
}
}
to = tl.next();
}
status.setText ( i18n("Changing todos ...") );
qApp->processEvents();
//qDebug("changing... ");
if ( changeEnt ) {
QFile file( fileName );
if (!file.open( IO_WriteOnly ) ) {
return false;
}
QTextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
ts << changeString ;
file.close();
command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
system ( command.latin1() );
//qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
}
status.setText ( i18n("Deleting todos ...") );
qApp->processEvents();
//qDebug("deleting... ");
if ( deleteEnt ) {
QFile file( fileName );
if (!file.open( IO_WriteOnly ) ) {
return false;
}
QTextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
ts << deleteString;
file.close();
command = "db2file todo -d -c " + codec+ " < "+ fileName;
system ( command.latin1() );
// qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
}
return true;
}
QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
{
QString datestr;
QString timestr;
int offset = KGlobal::locale()->localTimeOffset( dti );
QDateTime dt;
if (useTZ)
dt = dti.addSecs ( -(offset*60));
else
dt = dti;
if(dt.date().isValid()){
const QDate& date = dt.date();
datestr.sprintf("%04d%02d%02d",
date.year(), date.month(), date.day());
}
if(dt.time().isValid()){
const QTime& time = dt.time();
timestr.sprintf("T%02d%02d%02d",
time.hour(), time.minute(), time.second());
}
return datestr + timestr;
}
QString SharpFormat::getEventString( Event* event )