24 #include <tqtextstream.h>
25 #include <tqstringlist.h>
27 #include <tdeapplication.h>
28 #include <tdeaboutdata.h>
35 #include "preferences.h"
36 #include "calendarcompat.h"
46 void CalendarCompat::fix(
KCal::Calendar& calendar,
const TQString& localFile)
48 bool version057_UTC =
false;
50 int version = readKAlarmVersion(calendar, subVersion);
57 if (version == KAlarm::Version(0,5,7) && !localFile.isEmpty())
61 version057_UTC = isUTC(localFile);
62 kdDebug(5950) <<
"CalendarCompat::fix(): KAlarm version 0.5.7 (" << (version057_UTC ?
"" :
"non-") <<
"UTC)\n";
65 kdDebug(5950) <<
"CalendarCompat::fix(): KAlarm version " << version << endl;
68 KAEvent::convertKCalEvents(calendar, version, version057_UTC);
77 int CalendarCompat::readKAlarmVersion(
KCal::Calendar& calendar, TQString& subVersion)
79 subVersion = TQString();
80 const TQString& prodid = calendar.
productId();
83 TQString progname = TQString::fromLatin1(
" KAlarm ");
84 int i = prodid.find(progname, 0,
false);
89 progname = TQString(
" ") + kapp->aboutData()->programName() +
' ';
90 i = prodid.find(progname, 0,
false);
96 TQString ver = prodid.mid(i + progname.length()).stripWhiteSpace();
98 int j = ver.find(
' ');
104 if (ver == KAlarm::currentCalendarVersionString())
106 return KAlarm::getVersionNumber(ver, &subVersion);
115 bool CalendarCompat::isUTC(
const TQString& localFile)
118 TQFile file(localFile);
119 if (!file.open(IO_ReadOnly))
121 TQTextStream ts(&file);
122 ts.setEncoding(TQTextStream::Latin1);
123 TQString text = ts.read();
127 TQString VCALENDAR = TQString::fromLatin1(
"BEGIN:VCALENDAR");
128 TQString VEVENT = TQString::fromLatin1(
"BEGIN:VEVENT");
129 TQString CREATED = TQString::fromLatin1(
"CREATED:");
130 TQStringList lines = TQStringList::split(TQChar(
'\n'), text);
131 for (TQStringList::ConstIterator it = lines.begin(); it != lines.end(); ++it)
133 if ((*it).startsWith(VCALENDAR))
135 while (++it != lines.end())
137 if ((*it).startsWith(VEVENT))
139 while (++it != lines.end())
141 if ((*it).startsWith(CREATED))
142 return (*it).endsWith(
"Z");
represents calendar alarms and events