summaryrefslogtreecommitdiffabout
path: root/libkcal
Side-by-side diff
Diffstat (limited to 'libkcal') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/calendar.cpp15
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/incidencebase.cpp3
-rw-r--r--libkcal/phoneformat.cpp223
-rw-r--r--libkcal/phoneformat.h4
-rw-r--r--libkcal/vcalformat.cpp7
-rw-r--r--libkcal/vcalformat.h4
7 files changed, 219 insertions, 38 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 32aac7a..a3977d7 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,128 +1,129 @@
/*
This file is part of libkcal.
Copyright (c) 1998 Preston Brown
Copyright (c) 2000,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 <stdlib.h>
#include <time.h>
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
#include "exceptions.h"
#include "calfilter.h"
#include "calendar.h"
+#include "syncdefines.h"
using namespace KCal;
Calendar::Calendar()
{
init();
setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") );
}
Calendar::Calendar( const QString &timeZoneId )
{
init();
setTimeZoneId(timeZoneId);
}
void Calendar::init()
{
mObserver = 0;
mNewObserver = false;
mModified = false;
// 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...
setOwner(i18n("Unknown Name"));
setEmail(i18n("unknown@nowhere"));
#if 0
tmpStr = KOPrefs::instance()->mTimeZone;
// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
int dstSetting = KOPrefs::instance()->mDaylightSavings;
extern long int timezone;
struct tm *now;
time_t curtime;
curtime = time(0);
now = localtime(&curtime);
int hourOff = - ((timezone / 60) / 60);
if (now->tm_isdst)
hourOff += 1;
QString tzStr;
tzStr.sprintf("%.2d%.2d",
hourOff,
abs((timezone / 60) % 60));
// if no time zone was in the config file, write what we just discovered.
if (tmpStr.isEmpty()) {
// KOPrefs::instance()->mTimeZone = tzStr;
} else {
tzStr = tmpStr;
}
// if daylight savings has changed since last load time, we need
// to rewrite these settings to the config file.
if ((now->tm_isdst && !dstSetting) ||
(!now->tm_isdst && dstSetting)) {
KOPrefs::instance()->mTimeZone = tzStr;
KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
}
setTimeZone(tzStr);
#endif
// KOPrefs::instance()->writeConfig();
}
Calendar::~Calendar()
{
delete mDefaultFilter;
}
const QString &Calendar::getOwner() const
{
return mOwner;
}
void Calendar::setOwner(const QString &os)
{
int i;
mOwner = os;
i = mOwner.find(',');
if (i != -1)
mOwner = mOwner.left(i);
setModified( true );
}
@@ -154,193 +155,207 @@ QString Calendar::getTimeZoneStr() const
if (mLocalTime)
return "";
QString tmpStr;
int hours = abs(mTimeZone / 60);
int minutes = abs(mTimeZone % 60);
bool neg = mTimeZone < 0;
tmpStr.sprintf("%c%.2d%.2d",
(neg ? '-' : '+'),
hours, minutes);
return tmpStr;
}
void Calendar::setTimeZone(int tz)
{
mTimeZone = tz;
mLocalTime = false;
setModified( true );
}
int Calendar::getTimeZone() const
{
return mTimeZone;
}
void Calendar::setTimeZoneId(const QString &id)
{
mTimeZoneId = id;
mLocalTime = false;
mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
if ( mTimeZone > 1000)
setLocalTime();
//qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
setModified( true );
}
QString Calendar::timeZoneId() const
{
return mTimeZoneId;
}
void Calendar::setLocalTime()
{
//qDebug("Calendar::setLocalTime() ");
mLocalTime = true;
mTimeZone = 0;
mTimeZoneId = "";
setModified( true );
}
bool Calendar::isLocalTime() const
{
return mLocalTime;
}
const QString &Calendar::getEmail()
{
return mOwnerEmail;
}
void Calendar::setEmail(const QString &e)
{
mOwnerEmail = e;
setModified( true );
}
void Calendar::setFilter(CalFilter *filter)
{
mFilter = filter;
}
CalFilter *Calendar::filter()
{
return mFilter;
}
QPtrList<Incidence> Calendar::incidences()
{
QPtrList<Incidence> incidences;
Incidence *i;
QPtrList<Event> e = events();
for( i = e.first(); i; i = e.next() ) incidences.append( i );
QPtrList<Todo> t = todos();
for( i = t.first(); i; i = t.next() ) incidences.append( i );
QPtrList<Journal> j = journals();
for( i = j.first(); i; i = j.next() ) incidences.append( i );
return incidences;
}
+void Calendar::resetTempSyncStat()
+{
+ QPtrList<Incidence> incidences;
+
+ Incidence *i;
+
+ QPtrList<Event> e = rawEvents();
+ for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+
+ QPtrList<Todo> t = rawTodos();
+ for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+ QPtrList<Journal> j = journals();
+ for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+}
QPtrList<Incidence> Calendar::rawIncidences()
{
QPtrList<Incidence> incidences;
Incidence *i;
QPtrList<Event> e = rawEvents();
for( i = e.first(); i; i = e.next() ) incidences.append( i );
QPtrList<Todo> t = rawTodos();
for( i = t.first(); i; i = t.next() ) incidences.append( i );
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;
}
bool Calendar::addIncidence(Incidence *i)
{
Incidence::AddVisitor<Calendar> v(this);
return i->accept(v);
}
void Calendar::deleteIncidence(Incidence *in)
{
if ( in->type() == "Event" )
deleteEvent( (Event*) in );
else if ( in->type() =="Todo" )
deleteTodo( (Todo*) in);
else if ( in->type() =="Journal" )
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 );
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 4a3223c..06a911c 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,164 +1,165 @@
/*
This file is part of libkcal.
Copyright (c) 1998 Preston Brown
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.
*/
#ifndef CALENDAR_H
#define CALENDAR_H
#include <qobject.h>
#include <qstring.h>
#include <qdatetime.h>
#include <qptrlist.h>
#include <qdict.h>
#include "customproperties.h"
#include "event.h"
#include "todo.h"
#include "journal.h"
#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */
class KConfig;
namespace KCal {
class CalFilter;
/**
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();
void deleteIncidence(Incidence *in);
+ void resetTempSyncStat();
/**
Clears out the current calendar, freeing all used memory etc.
*/
virtual void close() = 0;
/**
Sync changes in memory to persistant storage.
*/
virtual void save() = 0;
virtual QPtrList<Event> getExternLastSyncEvents() = 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).
*/
void setTimeZoneId( const QString & );
/**
Return time zone id.
*/
QString timeZoneId() const;
/**
Use local time, not UTC or a time zone.
*/
void setLocalTime();
/**
Return whether local time is being used.
*/
bool isLocalTime() const;
/**
Add an incidence to calendar.
@return true on success, false on error.
*/
virtual bool addIncidence( Incidence * );
/**
Return filtered list of all incidences of this calendar.
*/
virtual QPtrList<Incidence> incidences();
/**
Return unfiltered list of all incidences of this calendar.
*/
virtual QPtrList<Incidence> rawIncidences();
/**
Adds a Event to this calendar object.
@param anEvent a pointer to the event to add
@return true on success, false on error.
*/
virtual bool addEventNoDup( Event *event ) = 0;
virtual bool addAnniversaryNoDup( Event *event ) = 0;
virtual bool addEvent( Event *anEvent ) = 0;
/**
Delete event from calendar.
*/
virtual void deleteEvent( Event * ) = 0;
/**
Retrieves an event on the basis of the unique string ID.
*/
virtual Event *event( const QString &UniqueStr ) = 0;
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 15c4fa8..64a343c 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,139 +1,140 @@
/*
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 <kidmanager.h>
#include "calformat.h"
+#include "syncdefines.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;
mExternalId = ":";
- mTempSyncStat = 0;
+ mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
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;
mTempSyncStat = i.mTempSyncStat;
mSyncStatus = i.mSyncStatus;
mExternalId = i.mExternalId;
// 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 )
{
// do not compare mSyncStatus and mExternalId
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)
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index e6d4879..6bbc0a3 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,328 +1,329 @@
/*
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 "phoneformat.h"
#include "syncdefines.h"
using namespace KCal;
class PhoneParser : public QObject
{
public:
PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) {
;
}
bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s)
{
int id = ToDo->Location;
Todo *todo;
todo = existingCalendar->todo( mProfileName ,QString::number( id ) );
if (todo )
todo = (Todo *)todo->clone();
else
todo = new Todo;
todo->setID( mProfileName,QString::number( id ) );
todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
int priority;
switch (ToDo->Priority) {
- case GSM_Priority_Low : priority = 1; break;
+ case GSM_Priority_Low : priority = 5; break;
case GSM_Priority_Medium : priority = 3; break;
- case GSM_Priority_High : priority = 5; break;
+ case GSM_Priority_High : priority = 1; break;
default :priority = 3 ; break;
}
todo->setPriority( priority );
GSM_Phone_Functions *Phone;
Phone=s->Phone.Functions;
int j;
GSM_DateTime* dtp;
bool alarm = false;
QDateTime alarmDt;
GSM_Category Category;
int error;
for (j=0;j<ToDo->EntriesNum;j++) {
//qDebug(" for todo %d",ToDo->Location );
switch (ToDo->Entries[j].EntryType) {
case TODO_END_DATETIME:
dtp = &ToDo->Entries[j].Date ;
todo->setDtDue (fromGSM ( dtp ));
break;
case TODO_COMPLETED:
if ( ToDo->Entries[j].Number == 1 ) {
todo->setCompleted( true );
}
else {
todo->setCompleted( false );
}
break;
case TODO_ALARM_DATETIME:
dtp = &ToDo->Entries[j].Date ;
alarm = true;
alarmDt = fromGSM ( dtp );
break;
case TODO_SILENT_ALARM_DATETIME:
dtp = &ToDo->Entries[j].Date ;
alarm = true;
alarmDt = fromGSM ( dtp );
break;
case TODO_TEXT:
//qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text ));
todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text )));
break;
case TODO_PRIVATE:
if ( ToDo->Entries[j].Number == 1 )
todo->setSecrecy( Incidence::SecrecyPrivate );
else
todo->setSecrecy( Incidence::SecrecyPublic );
break;
case TODO_CATEGORY:
Category.Location = ToDo->Entries[j].Number;
Category.Type = Category_ToDo;
error=Phone->GetCategory(s, &Category);
if (error == ERR_NONE) {
QStringList cat = todo->categories();
QString nCat = QString ( (const char*)Category.Name );
if ( !nCat.isEmpty() )
if ( !cat.contains( nCat )) {
cat << nCat;
todo->setCategories( cat );
}
}
break;
case TODO_CONTACTID:
#if 0
// not supported
entry.Location = ToDo->Entries[j].Number;
entry.MemoryType = MEM_ME;
error=Phone->GetMemory(s, &entry);
if (error == ERR_NONE) {
name = GSM_PhonebookGetEntryName(&entry);
if (name != NULL) {
printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number);
} else {
printmsg("Contact ID : %d\n",ToDo->Entries[j].Number);
}
} else {
printmsg("Contact : %d\n",ToDo->Entries[j].Number);
}
#endif
break;
case TODO_PHONE:
#if 0
// not supported
printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
#endif
break;
}
}
QString alarmString = "na";
if ( alarm ) {
Alarm *alarm;
if ( todo->alarms().count() > 0 )
alarm = todo->alarms().first();
else {
alarm = new Alarm( todo );
todo->addAlarm( alarm );
}
alarm->setType( Alarm::Audio );
alarm->setEnabled( true );
int alarmOffset = alarmDt.secsTo( todo->dtStart() );
alarm->setStartOffset( -alarmOffset );
alarmString = QString::number( alarmOffset );
} else {
Alarm *alarm;
if ( todo->alarms().count() > 0 ) {
alarm = todo->alarms().first();
alarm->setType( Alarm::Audio );
alarm->setStartOffset( -60*15 );
alarm->setEnabled( false );
}
}
// csum *****************************************
uint cSum;
cSum = PhoneFormat::getCsumTodo( todo );
todo->setCsum( mProfileName, QString::number( cSum ));
todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
mCalendar->addTodo( todo);
return true;
}
bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry* Note)
{
int id = Note->Location;
Event *event;
event = existingCalendar->event( mProfileName ,QString::number( id ) );
if ( event )
event = (Event*)event->clone();
else
event = new Event;
event->setID( mProfileName,QString::number( id ) );
event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
int i = 0;
bool repeating = false;
int repeat_dayofweek = -1;
int repeat_day = -1;
int repeat_weekofmonth = -1;
int repeat_month = -1;
int repeat_frequency = -1;
int rec_type = -1;
GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
GSM_DateTime* dtp;
bool alarm = false;
QDateTime alarmDt;
repeat_startdate.Day = 0;
repeat_stopdate.Day = 0;
for (i=0;i<Note->EntriesNum;i++) {
//qDebug(" for ev");
switch (Note->Entries[i].EntryType) {
case CAL_START_DATETIME:
dtp = &Note->Entries[i].Date ;
if ( dtp->Hour > 24 ) {
event->setFloats( true );
event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
} else {
event->setDtStart (fromGSM ( dtp ));
}
+ //Note->Entries[i].Date.Hour = 5;
break;
case CAL_END_DATETIME:
dtp = &Note->Entries[i].Date ;
if ( dtp->Hour > 24 ) {
event->setFloats( true );
event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
} else {
event->setDtEnd (fromGSM ( dtp ));
}
break;
case CAL_ALARM_DATETIME:
dtp = &Note->Entries[i].Date ;
alarm = true;
alarmDt = fromGSM ( dtp );
break;
case CAL_SILENT_ALARM_DATETIME:
dtp = &Note->Entries[i].Date ;
alarm = true;
alarmDt = fromGSM ( dtp );
break;
case CAL_RECURRANCE:
rec_type = Note->Entries[i].Number;
//printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" );
break;
case CAL_TEXT:
//qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) );
event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text )));
break;
case CAL_LOCATION:
event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) ));
break;
case CAL_PHONE:
//printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
break;
case CAL_PRIVATE:
if ( Note->Entries[i].Number == 1 )
event->setSecrecy( Incidence::SecrecyPrivate );
else
event->setSecrecy( Incidence::SecrecyPublic );
break;
case CAL_CONTACTID:
#if 0
entry.Location = Note->Entries[i].Number;
entry.MemoryType = MEM_ME;
error=Phone->GetMemory(&s, &entry);
if (error == ERR_NONE) {
name = GSM_PhonebookGetEntryName(&entry);
if (name != NULL) {
//printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
} else {
//printmsg("Contact ID : %d\n",Note->Entries[i].Number);
}
} else {
//printmsg("Contact ID : %d\n",Note->Entries[i].Number);
}
#endif
break;
case CAL_REPEAT_DAYOFWEEK:
repeat_dayofweek = Note->Entries[i].Number;
repeating = true;
break;
case CAL_REPEAT_DAY:
repeat_day = Note->Entries[i].Number;
repeating = true;
break;
case CAL_REPEAT_WEEKOFMONTH:
repeat_weekofmonth = Note->Entries[i].Number;
repeating = true;
break;
case CAL_REPEAT_MONTH:
repeat_month = Note->Entries[i].Number;
repeating = true;
break;
case CAL_REPEAT_FREQUENCY:
repeat_frequency = Note->Entries[i].Number;
repeating = true;
break;
case CAL_REPEAT_STARTDATE:
repeat_startdate = Note->Entries[i].Date;
repeating = true;
break;
case CAL_REPEAT_STOPDATE:
repeat_stopdate = Note->Entries[i].Date;
repeating = true;
break;
}
}
#if 0
event->setDescription( attList[4] );
bool repeating = false;
int repeat_dayofweek = -1;
int repeat_day = -1;
int repeat_weekofmonth = -1;
int repeat_month = -1;
int repeat_frequency = -1;
@@ -677,433 +678,593 @@ ulong PhoneFormat::getCsumEvent( Event* event )
//pending weekdays
writeEndDate = true;
break;
case Recurrence::rMonthlyPos:// 2
list.append( "2" );
list.append( QString::number( rec->frequency()) );//12
writeEndDate = true;
{
int count = 1;
QPtrList<Recurrence::rMonthPos> rmp;
rmp = rec->monthPositions();
if ( rmp.first()->negative )
count = 5 - rmp.first()->rPos - 1;
else
count = rmp.first()->rPos - 1;
list.append( QString::number( count ) );
}
list.append( "0" );
break;
case Recurrence::rMonthlyDay:// 3
list.append( "3" );
list.append( QString::number( rec->frequency()) );//12
list.append( "0" );
list.append( "0" );
writeEndDate = true;
break;
case Recurrence::rYearlyMonth://4
list.append( "4" );
list.append( QString::number( rec->frequency()) );//12
list.append( "0" );
list.append( "0" );
writeEndDate = true;
break;
default:
list.append( "255" );
list.append( QString() );
list.append( "0" );
list.append( QString() );
list.append( "0" );
list.append( "20991231T000000" );
break;
}
if ( writeEndDate ) {
if ( rec->endDate().isValid() ) { // 15 + 16
list.append( "1" );
list.append( PhoneParser::dtToString( rec->endDate()) );
} else {
list.append( "0" );
list.append( "20991231T000000" );
}
}
attList << list.join("");
attList << event->categoriesStr();
attList << event->secrecyStr();
return PhoneFormat::getCsum(attList );
}
ulong PhoneFormat::getCsum( const QStringList & attList)
{
int max = attList.count() -1;
ulong cSum = 0;
int j,k,i;
int add;
for ( i = 1; i < max ; ++i ) {
QString s = attList[i];
if ( ! s.isEmpty() ){
j = s.length();
for ( k = 0; k < j; ++k ) {
int mul = k +1;
add = s[k].unicode ();
if ( k < 16 )
mul = mul * mul;
add = add * mul *i*i*i;
cSum += add;
}
}
}
return cSum;
}
//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
#include <stdlib.h>
#define DEBUGMODE false
bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
{
GSM_StateMachine s;
qDebug(" load ");
s.opened = false;
s.msg = NULL;
s.ConfigNum = 0;
- QLabel status ( i18n("Reading data. Opening device ..."), 0 );
+ QLabel status ( i18n("Opening device ..."), 0 );
int w = status.sizeHint().width()+20 ;
- if ( w < 200 ) w = 200;
+ if ( w < 200 ) w = 230;
int h = status.sizeHint().height()+20 ;
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
- status.setCaption(i18n("Reading Phone Data") );
+ status.setCaption(i18n("Reading phone...") );
status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
status.show();
status.raise();
qApp->processEvents();
#if 0
static char *cp;
static INI_Section *cfg = NULL;
cfg=GSM_FindGammuRC();
int i;
for (i = 0; i <= MAX_CONFIG_NUM; i++) {
if (cfg!=NULL) {
cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false);
if (cp) di.coding = cp;
s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false);
if (s.Config[i].Localize) {
s.msg=INI_ReadFile(s.Config[i].Localize, true);
} else {
#if !defined(WIN32) && defined(LOCALE_PATH)
locale = setlocale(LC_MESSAGES, NULL);
if (locale != NULL) {
snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
LOCALE_PATH,
tolower(locale[0]),
tolower(locale[1]));
s.msg = INI_ReadFile(locale_file, true);
}
#endif
}
}
/* Wanted user specific configuration? */
if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
s.ConfigNum++;
/* We want to use only one file descriptor for global and state machine debug output */
s.Config[i].UseGlobalDebugFile = true;
/* We wanted to read just user specified configuration. */
{break;}
}
#endif
int error=initDevice(&s);
qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
if ( error != ERR_NONE )
return false;
GSM_Phone_Functions *Phone;
GSM_CalendarEntry note;
bool start = true;
Phone=s.Phone.Functions;
bool gshutdown = false;
PhoneParser handler( calendar, mProfileName );
int ccc = 0;
- QString message = i18n("Processing event # ");
+ QString message = i18n(" Reading event # ");
int procCount = 0;
qDebug("Debug: only 10 calender items are downloaded ");
while (!gshutdown && ccc++ < 10) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
qDebug("readEvent %d ", ccc);
error=Phone->GetNextCalendar(&s,&note,start);
if (error == ERR_EMPTY) break;
start = false;
handler.readEvent( existingCal, &note );
+ qDebug("Org loc %d ",note.Location);
+ //note.Location = 0;
+ error=Phone->SetCalendar(&s,&note);
+ qDebug("new loc %d ",note.Location);
}
start = true;
GSM_ToDoEntry ToDo;
ccc = 0;
- message = i18n("Processing todo # ");
+ message = i18n(" Reading todo # ");
procCount = 0;
- while (!gshutdown) {
+ while (!gshutdown && ccc++ < 10) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
error = Phone->GetNextToDo(&s, &ToDo, start);
if (error == ERR_EMPTY) break;
start = false;
- qDebug("ReadTodo %d ", ++ccc);
+ qDebug("ReadTodo %d ", ccc);
handler.readTodo( existingCal, &ToDo, &s);
}
error=GSM_TerminateConnection(&s);
return true;
}
-void PhoneFormat::event2GSM( Event* ev, GSM_CalendarEntry*Note )
+#include <qcstring.h>
+void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note )
{
- QString eText = vfconverter.eventToString( ev );
+ QString eText = vfconverter.eventToString( ev, cal );
int pos = 0;
GSM_ToDoEntry dummy;
- GSM_DecodeVCALENDAR_VTODO( (unsigned char*)eText.latin1(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo );
+ qDebug( "Convert event");
+ QByteArray ba;
+ QDataStream s ( ba, IO_WriteOnly );
+ s << eText.utf8();
+ GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo );
+ qDebug( "Convert event done");
+ Note->Location = 0;
+ QString loc = ev->getID(mProfileName);
+ if ( !loc.isEmpty() ){
+ Note->Location = loc.toInt();
}
-void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsmTodo )
+
+}
+void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo )
{
- QString tText = vfconverter.todoToString( todo );
+ qDebug( "Convert todo1");
+ QString tText = vfconverter.todoToString( todo, cal );
int pos = 0;
GSM_CalendarEntry dummy;
- GSM_DecodeVCALENDAR_VTODO( (unsigned char*)tText.latin1(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo );
+ QByteArray ba;
+ QDataStream s ( ba, IO_WriteOnly );
+ s << tText.utf8();
+ GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo );
+ qDebug( "Convert todo done ");
+ gsmTodo->Location = 0;
+ QString loc = todo->getID(mProfileName);
+ if ( !loc.isEmpty() ){
+ gsmTodo->Location = loc.toInt();
+ }
+
}
void PhoneFormat::afterSave( Incidence* inc)
{
uint csum;
if ( inc->type() == "Event")
csum = PhoneFormat::getCsumEvent( (Event*) inc );
else
csum = PhoneFormat::getCsumTodo( (Todo*) inc );
inc->setCsum( mProfileName, QString::number( csum ));
inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
}
bool PhoneFormat::save( Calendar *calendar)
{
+ return true;
GSM_StateMachine s;
qDebug(" save ");
s.opened = false;
s.msg = NULL;
s.ConfigNum = 0;
- QLabel status ( i18n("Writing data. Opening device ..."), 0 );
+ QLabel status ( i18n(" Opening device ..."), 0 );
int w = status.sizeHint().width()+20 ;
- if ( w < 200 ) w = 200;
+ if ( w < 200 ) w = 230;
int h = status.sizeHint().height()+20 ;
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
- status.setCaption(i18n("Writing Phone Data") );
+ status.setCaption(i18n("Writing to phone...") );
status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
status.show();
status.raise();
qApp->processEvents();
int error=initDevice(&s);
qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
if ( error != ERR_NONE )
return false;
GSM_Phone_Functions *Phone;
GSM_CalendarEntry Note;
bool start = true;
Phone=s.Phone.Functions;
bool gshutdown = false;
QPtrList<Event> er = calendar->rawEvents();
Event* ev = er.first();
QString message = i18n("Processing event # ");
int procCount = 0;
- while ( ev ) {
- //qDebug("i %d ", ++i);
+ bool planB = true;// false;
+ while ( ev && ! planB) {
if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
- event2GSM( ev, &Note );
+ qDebug("event1 %d ", procCount);
+ event2GSM( calendar, ev, &Note );
if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
error = Phone->DeleteCalendar(&s, &Note);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug(" e delete planB %d ", error);
+ break;
+ }
}
else if ( ev->getID(mProfileName).isEmpty() ) { // add new
// we have to do this later after deleting
}
else { // change existing
error = Phone->SetCalendar(&s, &Note);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug(" e change planB %d ", error);
+ break;
+ }
+ qDebug("Change Calendar. Location %d status: %d",Note.Location, error );
}
}
ev = er.next();
}
ev = er.first();
// pending get empty slots
- while ( ev ) {
+ int loc = 0;
+ while ( ev && ! planB) {
if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
+ qDebug("event2 %d ", procCount);
if ( ev->getID(mProfileName).isEmpty() ) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
//int newID ;//= pending
//ev->setID(mProfileName, QString::number( newID ));
- event2GSM( ev, &Note );
- Note.Location = 0;
+ event2GSM( calendar, ev, &Note );
+ ++loc;
+ Note.Location = loc;
error = Phone->AddCalendar(&s, &Note);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug(" e add planB %d ", error);
+ break;
+ }
ev->setID( mProfileName, QString::number( Note.Location ) );
- qDebug("New Calendar. Location %d ",Note.Location );
+ qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN);
afterSave( ev );
} else {
afterSave( ev ); // setting temp sync stat for changed items
}
}
ev = er.next();
}
+
+
+ if ( planB ) {
+ qDebug("delete all calendar...");
+ status.setText ( i18n("Deleting all calendar..."));
+ qApp->processEvents();
+ error=Phone->DeleteAllCalendar(&s);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ message = i18n(" Deleting event # ");
+ procCount = 0;
+ while (1) {
+ status.setText ( message + QString::number ( ++procCount ) );
+ qApp->processEvents();
+ qDebug("deleting event ... %d", procCount);
+ error = Phone->GetNextCalendar(&s,&Note,true);
+ if (error != ERR_NONE) break;
+ error = Phone->DeleteCalendar(&s,&Note);
+ }
+ qDebug("deleting calendar ... finished");
+ } else {
+ status.setText ( i18n("All calendar deleted!"));
+ qDebug("all cal deleted");
+ }
+ bool planC = false;
+ ev = er.first();
+ procCount = 0;
+ message = i18n(" Writing event # ");
+ while ( ev && ! planC) {
+ status.setText ( message + QString::number ( ++procCount ) );
+ qApp->processEvents();
+ event2GSM( calendar, ev, &Note );
+ Note.Location = procCount;
+ error=Phone->AddCalendar(&s,&Note);
+ if (error != ERR_NONE ) {
+ // we have currently no planC :-(
+ // planC = true;
+ //qDebug("add planC %d ", error);
+ //break;
+ // we remove the ID such that this todo is not deleted after next sync
+ ev->removeID(mProfileName);
+ ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
+ qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error);
+ } else {
+ qDebug("cal adding loc %d planB stat %d ", Note.Location ,error);
+ ev->setID(mProfileName, QString::number( Note.Location ));
+ afterSave( ev );
+ }
+ ev = er.next();
+ }
+ if ( planC ) {
+ qDebug("writing cal went wrong...");
+
+ // we have currently no planC :-(
+ }
+ }
GSM_ToDoEntry ToDoEntry;
QPtrList<Todo> tl = calendar->rawTodos();
Todo* to = tl.first();
message = i18n("Processing todo # ");
procCount = 0;
- while ( to ) {
+ planB = false;
+ while ( to && ! planB ) {
if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
+ qDebug("todo3 %d ", procCount);
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
- todo2GSM( to, &ToDoEntry );
+ qDebug("todo5 %d ", procCount);
+ todo2GSM( calendar, to, &ToDoEntry );
if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
error=Phone->DeleteToDo(&s,&ToDoEntry);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug("delete planB %d ", error);
+ }
}
- else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
+ else if ( to->getID(mProfileName).isEmpty() ) { // add new
;
}
else { // change existing
error=Phone->SetToDo(&s,&ToDoEntry);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug("set planB %d ", error);
+ }
+ qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error );
}
}
to = tl.next();
}
// pending get empty slots
to = tl.first();
- while ( to ) {
+ while ( to && ! planB ) {
+ qDebug("todo2 %d ", procCount);
if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
+ qDebug("todo4 %d ", procCount);
if ( to->getID(mProfileName).isEmpty() ) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
//int newID ;//= pending
//to->setID(mProfileName, QString::number( newID ));
- todo2GSM( to, &ToDoEntry );
+ todo2GSM( calendar,to, &ToDoEntry );
ToDoEntry.Location = 0;
error=Phone->AddToDo(&s,&ToDoEntry);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug("new planB %d ", error);
+ }
to->setID(mProfileName, QString::number( ToDoEntry.Location ));
afterSave( to );
- qDebug("New Todo. Location %d ",ToDoEntry.Location );
+ qDebug("New Todo. Location %d %d",ToDoEntry.Location, error );
} else {
afterSave( to );
}
}
to = tl.next();
}
+ if ( planB ) {
+ qDebug("delete all ...");
+ error=Phone->DeleteAllToDo(&s);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ while (1) {
+ qDebug("deleting todo ...");
+ error = Phone->GetNextToDo(&s,&ToDoEntry,true);
+ if (error != ERR_NONE) break;
+ error = Phone->DeleteToDo(&s,&ToDoEntry);
+ }
+ qDebug("deleting todo ... finished");
+ } else {
+ qDebug("all todo deleted");
+ }
+ bool planC = false;
+ to = tl.first();
+ while ( to && ! planC ) {
+ todo2GSM( calendar,to, &ToDoEntry );
+ ToDoEntry.Location = 0;
+ error=Phone->AddToDo(&s,&ToDoEntry);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ // we have currently no planC :-(
+ // planC = true;
+ //qDebug("add planC %d ", error);
+ //break;
+ // we remove the ID such that this todo is not deleted after next sync
+ to->removeID(mProfileName);
+ to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
+ } else {
+ qDebug("adding %d planB %d ", ToDoEntry.Location ,error);
+ to->setID(mProfileName, QString::number( ToDoEntry.Location ));
+ afterSave( to );
+ }
+ to = tl.next();
+ }
+ if ( planC ) {
+ // we have currently no planC :-(
+ }
+ }
return true;
}
QString PhoneFormat::dtToGSM( 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 PhoneFormat::getEventString( Event* event )
{
#if 0
QStringList list;
list.append( QString::number(event->zaurusId() ) );
list.append( event->categories().join(",") );
if ( !event->summary().isEmpty() )
list.append( event->summary() );
else
list.append("" );
if ( !event->location().isEmpty() )
list.append( event->location() );
else
list.append("" );
if ( !event->description().isEmpty() )
list.append( event->description() );
else
list.append( "" );
if ( event->doesFloat () ) {
list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
list.append( "1" );
}
else {
list.append( dtToString( event->dtStart()) );
list.append( dtToString( event->dtEnd()) ); //6
list.append( "0" );
}
bool noAlarm = true;
if ( event->alarms().count() > 0 ) {
Alarm * al = event->alarms().first();
if ( al->enabled() ) {
noAlarm = false;
list.append( "0" ); // yes, 0 == alarm
list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
if ( al->type() == Alarm::Audio )
list.append( "1" ); // type audio
else
list.append( "0" ); // type silent
}
}
if ( noAlarm ) {
list.append( "1" ); // yes, 1 == no alarm
list.append( "0" ); // no alarm offset
list.append( "1" ); // type
}
// next is: 11
// next is: 11-16 are recurrence
Recurrence* rec = event->recurrence();
bool writeEndDate = false;
switch ( rec->doesRecur() )
{
case Recurrence::rDaily: // 0
list.append( "0" );
list.append( QString::number( rec->frequency() ));//12
list.append( "0" );
list.append( "0" );
writeEndDate = true;
break;
case Recurrence::rWeekly:// 1
list.append( "1" );
list.append( QString::number( rec->frequency()) );//12
list.append( "0" );
{
int days = 0;
QBitArray weekDays = rec->days();
int i;
for( i = 1; i <= 7; ++i ) {
if ( weekDays[i-1] ) {
days += 1 << (i-1);
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 33b2091..2c2e51c 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -1,67 +1,67 @@
/*
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.
*/
#ifndef PHONEFORMAT_H
#define PHONEFORMAT_H
#include <qstring.h>
#include "scheduler.h"
#include "vcalformat.h"
#include "calformat.h"
extern "C" {
#include "../gammu/emb/common/gammu.h"
}
namespace KCal {
/**
This class implements the calendar format used by Phone.
*/
class Event;
class Todo;
class PhoneFormat : public QObject {
public:
/** Create new iCalendar format. */
PhoneFormat(QString profileName, QString device,QString connection, QString model);
virtual ~PhoneFormat();
bool load( Calendar * ,Calendar * );
bool save( Calendar * );
bool fromString( Calendar *, const QString & );
QString toString( Calendar * );
static ulong getCsum( const QStringList & );
static ulong getCsumTodo( Todo* to );
static ulong getCsumEvent( Event* ev );
private:
VCalFormat vfconverter;
- void event2GSM( Event* ev, GSM_CalendarEntry*Note );
- void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo );
+ void event2GSM( Calendar *, Event* ev, GSM_CalendarEntry*Note );
+ void todo2GSM( Calendar *, Todo* ev, GSM_ToDoEntry *ToDo );
int initDevice(GSM_StateMachine *s);
QString getEventString( Event* );
QString getTodoString( Todo* );
QString dtToGSM( const QDateTime& dt, bool useTZ = true );
QString mProfileName, mDevice, mConnection, mModel;
void afterSave( Incidence* );
};
}
#endif
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 1167e58..076cd3f 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -1,275 +1,278 @@
/*
This file is part of libkcal.
Copyright (c) 1998 Preston Brwon
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 <qapplication.h>
#include <qdatetime.h>
#include <qstring.h>
#include <qptrlist.h>
#include <qregexp.h>
#include <qclipboard.h>
#include <qdialog.h>
#include <qfile.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kiconloader.h>
#include <klocale.h>
#include "vcc.h"
#include "vobject.h"
#include "vcaldrag.h"
#include "calendar.h"
#include "vcalformat.h"
using namespace KCal;
VCalFormat::VCalFormat()
{
+ mCalendar = 0;
}
VCalFormat::~VCalFormat()
{
}
bool VCalFormat::load(Calendar *calendar, const QString &fileName)
{
mCalendar = calendar;
clearException();
kdDebug(5800) << "VCalFormat::load() " << fileName << endl;
VObject *vcal = 0;
// this is not necessarily only 1 vcal. Could be many vcals, or include
// a vcard...
vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
if (!vcal) {
setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
return FALSE;
}
// any other top-level calendar stuff should be added/initialized here
// put all vobjects into their proper places
populate(vcal);
// clean up from vcal API stuff
cleanVObjects(vcal);
cleanStrTbl();
return true;
}
bool VCalFormat::save(Calendar *calendar, const QString &fileName)
{
mCalendar = calendar;
QString tmpStr;
VObject *vcal, *vo;
kdDebug(5800) << "VCalFormat::save(): " << fileName << endl;
vcal = newVObject(VCCalProp);
// addPropValue(vcal,VCLocationProp, "0.0");
addPropValue(vcal,VCProdIdProp, productId());
tmpStr = mCalendar->getTimeZoneStr();
//qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() );
addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit());
addPropValue(vcal,VCVersionProp, _VCAL_VERSION);
// TODO STUFF
QPtrList<Todo> todoList = mCalendar->rawTodos();
QPtrListIterator<Todo> qlt(todoList);
for (; qlt.current(); ++qlt) {
vo = eventToVTodo(qlt.current());
addVObjectProp(vcal, vo);
}
// EVENT STUFF
QPtrList<Event> events = mCalendar->rawEvents();
Event *ev;
for(ev=events.first();ev;ev=events.next()) {
vo = eventToVEvent(ev);
addVObjectProp(vcal, vo);
}
writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal);
cleanVObjects(vcal);
cleanStrTbl();
if (QFile::exists(fileName)) {
kdDebug(5800) << "No error" << endl;
return true;
} else {
kdDebug(5800) << "Error" << endl;
return false; // error
}
}
bool VCalFormat::fromString( Calendar *calendar, const QString &text )
{
// TODO: Factor out VCalFormat::fromString()
QCString data = text.utf8();
if ( !data.size() ) return false;
VObject *vcal = Parse_MIME( data.data(), data.size());
if ( !vcal ) return false;
VObjectIterator i;
VObject *curvo;
initPropIterator( &i, vcal );
// we only take the first object. TODO: parse all incidences.
do {
curvo = nextVObject( &i );
} while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
strcmp( vObjectName( curvo ), VCTodoProp ) );
if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
Event *event = VEventToEvent( curvo );
calendar->addEvent( event );
} else {
kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl;
deleteVObject( vcal );
return false;
}
deleteVObject( vcal );
return true;
}
-QString VCalFormat::eventToString( Event * event)
+QString VCalFormat::eventToString( Event * event, Calendar *calendar)
{
if ( !event ) return QString::null;
+ mCalendar = calendar;
VObject *vevent = eventToVEvent( event );
char *buf = writeMemVObject( 0, 0, vevent );
QString result( buf );
cleanVObject( vevent );
return result;
}
-QString VCalFormat::todoToString( Todo * todo )
+QString VCalFormat::todoToString( Todo * todo, Calendar *calendar )
{
if ( !todo ) return QString::null;
+ mCalendar = calendar;
VObject *vevent = eventToVTodo( todo );
char *buf = writeMemVObject( 0, 0, vevent );
QString result( buf );
cleanVObject( vevent );
return result;
}
QString VCalFormat::toString( Calendar *calendar )
{
// TODO: Factor out VCalFormat::asString()
VObject *vcal = newVObject(VCCalProp);
addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
QString tmpStr = mCalendar->getTimeZoneStr();
addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
// TODO: Use all data.
QPtrList<Event> events = calendar->events();
Event *event = events.first();
if ( !event ) return QString::null;
VObject *vevent = eventToVEvent( event );
addVObjectProp( vcal, vevent );
char *buf = writeMemVObject( 0, 0, vcal );
QString result( buf );
cleanVObject( vcal );
return result;
}
VObject *VCalFormat::eventToVTodo(const Todo *anEvent)
{
VObject *vtodo;
QString tmpStr;
QStringList tmpStrList;
vtodo = newVObject(VCTodoProp);
// due date
if (anEvent->hasDueDate()) {
tmpStr = qDateTimeToISO(anEvent->dtDue(),
!anEvent->doesFloat());
addPropValue(vtodo, VCDueProp, tmpStr.local8Bit());
}
// start date
if (anEvent->hasStartDate()) {
tmpStr = qDateTimeToISO(anEvent->dtStart(),
!anEvent->doesFloat());
addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit());
}
// creation date
tmpStr = qDateTimeToISO(anEvent->created());
addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit());
// unique id
addPropValue(vtodo, VCUniqueStringProp,
anEvent->uid().local8Bit());
// revision
tmpStr.sprintf("%i", anEvent->revision());
addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit());
// last modification date
tmpStr = qDateTimeToISO(anEvent->lastModified());
addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
// organizer stuff
tmpStr = "MAILTO:" + anEvent->organizer();
addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
// attendees
if (anEvent->attendeeCount() != 0) {
QPtrList<Attendee> al = anEvent->attendees();
QPtrListIterator<Attendee> ai(al);
Attendee *curAttendee;
for (; ai.current(); ++ai) {
curAttendee = ai.current();
if (!curAttendee->email().isEmpty() &&
!curAttendee->name().isEmpty())
tmpStr = "MAILTO:" + curAttendee->name() + " <" +
curAttendee->email() + ">";
else if (curAttendee->name().isEmpty())
tmpStr = "MAILTO: " + curAttendee->email();
else if (curAttendee->email().isEmpty())
tmpStr = "MAILTO: " + curAttendee->name();
else if (curAttendee->name().isEmpty() &&
curAttendee->email().isEmpty())
diff --git a/libkcal/vcalformat.h b/libkcal/vcalformat.h
index 8490125..7b9ca26 100644
--- a/libkcal/vcalformat.h
+++ b/libkcal/vcalformat.h
@@ -1,110 +1,110 @@
/*
This file is part of libkcal.
Copyright (c) 1998 Preston Brown
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.
*/
#ifndef _VCALFORMAT_H
#define _VCALFORMAT_H
#include "calformat.h"
#define _VCAL_VERSION "1.0"
class VObject;
namespace KCal {
/**
This class implements the vCalendar format. It provides methods for
loading/saving/converting vCalendar format data into the internal KOrganizer
representation as Calendar and Events.
@short vCalendar format implementation
*/
class VCalFormat : public CalFormat {
public:
VCalFormat();
virtual ~VCalFormat();
/** loads a calendar on disk in vCalendar format into the current calendar.
* any information already present is lost. Returns TRUE if successful,
* else returns FALSE.
* @param fileName the name of the calendar on disk.
*/
bool load(Calendar *,const QString &fileName);
/** writes out the calendar to disk in vCalendar format. Returns true if
* successful and false on error.
* @param fileName the name of the file
*/
bool save(Calendar *,const QString &fileName);
/**
Parse string and populate calendar with that information.
*/
bool fromString( Calendar *, const QString & );
/**
Return calendar information as string.
*/
QString toString( Calendar * );
- QString eventToString( Event * );
- QString todoToString( Todo * );
+ QString eventToString( Event *, Calendar *calendar );
+ QString todoToString( Todo * ,Calendar *calendar );
protected:
/** translates a VObject of the TODO type into a Event */
Todo *VTodoToEvent(VObject *vtodo);
/** translates a VObject into a Event and returns a pointer to it. */
Event *VEventToEvent(VObject *vevent);
/** translate a Event into a VTodo-type VObject and return pointer */
VObject *eventToVTodo(const Todo *anEvent);
/** translate a Event into a VObject and returns a pointer to it. */
VObject* eventToVEvent(const Event *anEvent);
/** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */
QString qDateToISO(const QDate &);
/** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */
QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE);
/** takes a string in the format YYYYMMDDTHHMMSS and returns a
* valid QDateTime. */
QDateTime ISOToQDateTime(const QString & dtStr);
/** takes a string in the format YYYYMMDD and returns a
* valid QDate. */
QDate ISOToQDate(const QString & dtStr);
/** takes a vCalendar tree of VObjects, and puts all of them that have
* the "event" property into the dictionary, todos in the todo-list, etc. */
void populate(VObject *vcal);
/** takes a number 0 - 6 and returns the two letter string of that day,
* i.e. MO, TU, WE, etc. */
const char *dayFromNum(int day);
/** the reverse of the above function. */
int numFromDay(const QString &day);
Attendee::PartStat readStatus(const char *s) const;
QCString writeStatus(Attendee::PartStat status) const;
private:
Calendar *mCalendar;
QPtrList<Event> mEventsRelate; // events with relations
QPtrList<Todo> mTodosRelate; // todos with relations
};
}
#endif