22 #include <tqdatetime.h>
24 #include <tqptrlist.h>
26 #include <tqclipboard.h>
28 #include <tqtextstream.h>
32 #include <tdelocale.h>
35 #include "calendarlocal.h"
37 #include "qtopiaformat.h"
41 class TQtopiaParser :
public TQXmlDefaultHandler
44 TQtopiaParser(
Calendar *calendar ) : mCalendar( calendar ) {}
46 bool startElement(
const TQString &,
const TQString &,
const TQString & qName,
47 const TQXmlAttributes &attributes )
49 if ( qName ==
"event" ) {
51 TQString uid =
"TQtopia" + attributes.value(
"uid" );
54 event->setSummary( attributes.value(
"description" ) );
55 event->setLocation( attributes.value(
"location" ) );
56 event->setDescription( attributes.value(
"note" ) );
57 event->setDtStart( toDateTime( attributes.value(
"start" ) ) );
58 event->setDtEnd( toDateTime( attributes.value(
"end" ) ) );
60 if ( attributes.value(
"type" ) ==
"AllDay" ) {
61 event->setFloats(
true );
63 event->setFloats(
false );
66 TQString rtype = attributes.value(
"rtype" );
67 if ( !rtype.isEmpty() ) {
68 TQDate startDate =
event->dtStart().date();
70 TQString freqStr = attributes.value(
"rfreq" );
71 int freq = freqStr.toInt();
73 TQString hasEndDateStr = attributes.value(
"rhasenddate" );
74 bool hasEndDate = hasEndDateStr ==
"1";
76 TQString endDateStr = attributes.value(
"enddt" );
77 TQDate endDate = toDateTime( endDateStr ).date();
79 TQString weekDaysStr = attributes.value(
"rweekdays" );
80 int weekDaysNum = weekDaysStr.toInt();
81 TQBitArray weekDays( 7 );
83 for( i = 1; i <= 7; ++i ) {
84 weekDays.setBit( i - 1, ( 2 << i ) & weekDaysNum );
87 TQString posStr = attributes.value(
"rposition" );
88 int pos = posStr.toInt();
92 if ( rtype ==
"Daily" ) {
95 }
else if ( rtype ==
"Weekly" ) {
98 }
else if ( rtype ==
"MonthlyDate" ) {
103 }
else if ( rtype ==
"MonthlyDay" ) {
107 TQBitArray days( 7 );
109 days.setBit( startDate.dayOfWeek() - 1 );
111 }
else if ( rtype ==
"Yearly" ) {
118 TQString categoryList = attributes.value(
"categories" );
119 event->setCategories( lookupCategories( categoryList ) );
121 TQString alarmStr = attributes.value(
"alarm" );
122 if ( !alarmStr.isEmpty() ) {
123 kdDebug(5800) <<
"Alarm: " << alarmStr << endl;
125 alarm->
setType( Alarm::Display );
127 int alarmOffset = alarmStr.toInt();
129 event->addAlarm( alarm );
132 Event *oldEvent = mCalendar->event( uid );
133 if ( oldEvent ) mCalendar->deleteEvent( oldEvent );
135 mCalendar->addEvent( event );
136 }
else if ( qName ==
"Task" ) {
139 TQString uid =
"TQtopia" + attributes.value(
"Uid" );
142 TQString description = attributes.value(
"Description" );
143 int pos = description.find(
'\n' );
145 TQString summary = description.left( pos );
152 int priority = attributes.value(
"Priority" ).toInt();
156 TQString categoryList = attributes.value(
"Categories" );
159 TQString completedStr = attributes.value(
"Completed" );
162 TQString hasDateStr = attributes.value(
"HasDate" );
163 if ( hasDateStr ==
"1" ) {
164 int year = attributes.value(
"DateYear" ).toInt();
165 int month = attributes.value(
"DateMonth" ).toInt();
166 int day = attributes.value(
"DateDay" ).toInt();
168 todo->
setDtDue( TQDateTime( TQDate( year, month, day ) ) );
172 Todo *oldTodo = mCalendar->todo( uid );
173 if ( oldTodo ) mCalendar->deleteTodo( oldTodo );
175 mCalendar->addTodo( todo );
176 }
else if ( qName ==
"Category" ) {
177 TQString
id = attributes.value(
"id" );
178 TQString name = attributes.value(
"name" );
179 setCategory(
id, name );
185 bool warning (
const TQXmlParseException &exception )
187 kdDebug(5800) <<
"WARNING" << endl;
188 printException( exception );
192 bool error (
const TQXmlParseException &exception )
194 kdDebug(5800) <<
"ERROR" << endl;
195 printException( exception );
199 bool fatalError (
const TQXmlParseException &exception )
201 kdDebug(5800) <<
"FATALERROR" << endl;
202 printException( exception );
206 TQString errorString ()
208 return "TQtopiaParser: Error!";
212 void printException(
const TQXmlParseException &exception )
214 kdError() <<
"XML Parse Error (line " << exception.lineNumber()
215 <<
", col " << exception.columnNumber() <<
"): "
216 << exception.message() <<
"(public ID: '"
217 << exception.publicId() <<
"' system ID: '"
218 << exception.systemId() <<
"')" << endl;
221 TQDateTime toDateTime(
const TQString &value )
224 dt.setTime_t( value.toUInt() );
229 TQStringList lookupCategories(
const TQString &categoryList )
231 TQStringList categoryIds = TQStringList::split(
";", categoryList );
232 TQStringList categories;
233 TQStringList::ConstIterator it;
234 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
235 categories.append( category( *it ) );
243 static TQString category(
const TQString &
id )
245 TQMap<TQString,TQString>::ConstIterator it = mCategoriesMap.find(
id );
246 if ( it == mCategoriesMap.end() )
return id;
250 static void setCategory(
const TQString &
id,
const TQString &name )
252 mCategoriesMap.insert(
id, name );
255 static TQMap<TQString,TQString> mCategoriesMap;
258 TQMap<TQString,TQString> TQtopiaParser::mCategoriesMap;
260 TQtopiaFormat::TQtopiaFormat()
264 TQtopiaFormat::~TQtopiaFormat()
270 kdDebug(5800) <<
"TQtopiaFormat::load() " << fileName << endl;
274 TQtopiaParser handler( calendar );
275 TQFile xmlFile( fileName );
276 TQXmlInputSource source( xmlFile );
277 TQXmlSimpleReader reader;
278 reader.setContentHandler( &handler );
279 return reader.parse( source );
284 kdDebug(5800) <<
"TQtopiaFormat::save(): " << fileName << endl;
288 TQString text =
toString( calendar );
290 if ( text.isNull() )
return false;
294 TQFile file( fileName );
295 if (!file.open( IO_WriteOnly ) ) {
297 i18n(
"Could not open file '%1'").arg(fileName)));
300 TQTextStream ts( &file );
309 kdDebug(5800) <<
"TQtopiaFormat::fromString() not yet implemented." << endl;
Provides the main "calendar" object class.
This class represents an alarm notification.
void setEnabled(bool enable)
Set the alarm enabled status.
void setStartOffset(const Duration &)
Set offset of alarm in time relative to the start of the event.
void setType(Type type)
Set the type of the alarm.
This is the main "calendar" object class.
This class provides an Event in the sense of RFC2445.
void setUid(const TQString &)
Set the unique id for the event.
void setSummary(const TQString &summary)
Set short summary.
void setPriority(int priority)
Set the incidences priority.
void setDescription(const TQString &description)
Set the long description.
void setCategories(const TQStringList &categories)
Set categories.
This class represents a recurrence rule for a calendar incidence.
void setYearly(int freq)
Sets an event to recur yearly.
void setWeekly(int freq, int weekStart=1)
Sets an event to recur weekly.
void setMonthly(int freq)
Sets an event to recur monthly.
void addMonthlyPos(short pos, const TQBitArray &days)
Adds a position (e.g.
void setDaily(int freq)
Sets an event to recur daily.
void addMonthlyDate(short day)
Adds a date (e.g.
void setEndDate(const TQDate &endDate)
Sets the date of the last recurrence.
This class provides a Todo in the sense of RFC2445.
void setDtDue(const TQDateTime &dtDue, bool first=false)
Sets due date and time.
void setCompleted(bool completed)
Set completed state.
void setHasDueDate(bool hasDueDate)
Set if the todo has a due date.
Namespace KCal is for global classes, objects and/or functions in libkcal.