summaryrefslogtreecommitdiffabout
path: root/libkcal/icalformat.cpp
Unidiff
Diffstat (limited to 'libkcal/icalformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformat.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp
index 6f3a799..3829bc1 100644
--- a/libkcal/icalformat.cpp
+++ b/libkcal/icalformat.cpp
@@ -11,29 +11,29 @@
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qdatetime.h> 21#include <qdatetime.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qptrlist.h> 23#include <q3ptrlist.h>
24#include <qregexp.h> 24#include <qregexp.h>
25#include <qclipboard.h> 25#include <qclipboard.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qtextstream.h> 27#include <q3textstream.h>
28#include <qtextcodec.h> 28#include <qtextcodec.h>
29#include <stdlib.h> 29#include <stdlib.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35extern "C" { 35extern "C" {
36 #include <ical.h> 36 #include <ical.h>
37 #include <icalss.h> 37 #include <icalss.h>
38 #include <icalparser.h> 38 #include <icalparser.h>
39 #include <icalrestriction.h> 39 #include <icalrestriction.h>
@@ -61,60 +61,60 @@ ICalFormat::ICalFormat( bool pe )
61ICalFormat::~ICalFormat() 61ICalFormat::~ICalFormat()
62{ 62{
63 delete mImpl; 63 delete mImpl;
64 //qDebug("delete ICalFormat "); 64 //qDebug("delete ICalFormat ");
65} 65}
66 66
67bool ICalFormat::load( Calendar *calendar, const QString &fileName) 67bool ICalFormat::load( Calendar *calendar, const QString &fileName)
68{ 68{
69 69
70 clearException(); 70 clearException();
71 71
72 QFile file( fileName ); 72 QFile file( fileName );
73 if (!file.open( IO_ReadOnly ) ) { 73 if (!file.open( QIODevice::ReadOnly ) ) {
74 setException(new ErrorFormat(ErrorFormat::LoadError)); 74 setException(new ErrorFormat(ErrorFormat::LoadError));
75 return false; 75 return false;
76 } 76 }
77 QTextStream ts( &file ); 77 Q3TextStream ts( &file );
78 QString text; 78 QString text;
79 79
80 ts.setEncoding( QTextStream::Latin1 ); 80 ts.setEncoding( Q3TextStream::Latin1 );
81 text = ts.read(); 81 text = ts.read();
82 file.close(); 82 file.close();
83 83
84 return fromString( calendar, text ); 84 return fromString( calendar, text );
85} 85}
86 86
87//#include <qdatetime.h> 87//#include <qdatetime.h>
88bool ICalFormat::save( Calendar *calendar, const QString &fileName ) 88bool ICalFormat::save( Calendar *calendar, const QString &fileName )
89{ 89{
90 //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; 90 //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl;
91 //qDebug("ICalFormat::save "); 91 //qDebug("ICalFormat::save ");
92 clearException(); 92 clearException();
93 QString text = toString( calendar ); 93 QString text = toString( calendar );
94 //return false; 94 //return false;
95 // qDebug("to string takes ms: %d ",is.elapsed() ); 95 // qDebug("to string takes ms: %d ",is.elapsed() );
96 if ( text.isNull() ) return false; 96 if ( text.isNull() ) return false;
97 97
98 // TODO: write backup file 98 // TODO: write backup file
99 //is.restart(); 99 //is.restart();
100 QFile file( fileName ); 100 QFile file( fileName );
101 if (!file.open( IO_WriteOnly ) ) { 101 if (!file.open( QIODevice::WriteOnly ) ) {
102 setException(new ErrorFormat(ErrorFormat::SaveError, 102 setException(new ErrorFormat(ErrorFormat::SaveError,
103 i18n("Could not open file '%1'").arg(fileName))); 103 i18n("Could not open file '%1'").arg(fileName)));
104 return false; 104 return false;
105 } 105 }
106 QTextStream ts( &file ); 106 Q3TextStream ts( &file );
107 107
108 ts.setEncoding( QTextStream::Latin1 ); 108 ts.setEncoding( Q3TextStream::Latin1 );
109 ts << text; 109 ts << text;
110 file.close(); 110 file.close();
111 //qDebug("saving file takes ms: %d ", is.elapsed() ); 111 //qDebug("saving file takes ms: %d ", is.elapsed() );
112 return true; 112 return true;
113} 113}
114 114
115bool ICalFormat::fromString( Calendar *cal, const QString &text ) 115bool ICalFormat::fromString( Calendar *cal, const QString &text )
116{ 116{
117 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); 117 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
118 // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); 118 // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1());
119 // Get first VCALENDAR component. 119 // Get first VCALENDAR component.
120 // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components 120 // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components
@@ -147,76 +147,76 @@ bool ICalFormat::fromString( Calendar *cal, const QString &text )
147 icalcomponent_free( calendar ); 147 icalcomponent_free( calendar );
148 icalmemory_free_ring(); 148 icalmemory_free_ring();
149 149
150 return success; 150 return success;
151} 151}
152 152
153Incidence *ICalFormat::fromString( const QString &text ) 153Incidence *ICalFormat::fromString( const QString &text )
154{ 154{
155 CalendarLocal cal( mTimeZoneId ); 155 CalendarLocal cal( mTimeZoneId );
156 fromString(&cal, text); 156 fromString(&cal, text);
157 157
158 Incidence *ical = 0; 158 Incidence *ical = 0;
159 QPtrList<Event> elist = cal.events(); 159 Q3PtrList<Event> elist = cal.events();
160 if ( elist.count() > 0 ) { 160 if ( elist.count() > 0 ) {
161 ical = elist.first(); 161 ical = elist.first();
162 } else { 162 } else {
163 QPtrList<Todo> tlist = cal.todos(); 163 Q3PtrList<Todo> tlist = cal.todos();
164 if ( tlist.count() > 0 ) { 164 if ( tlist.count() > 0 ) {
165 ical = tlist.first(); 165 ical = tlist.first();
166 } else { 166 } else {
167 QPtrList<Journal> jlist = cal.journals(); 167 Q3PtrList<Journal> jlist = cal.journals();
168 if ( jlist.count() > 0 ) { 168 if ( jlist.count() > 0 ) {
169 ical = jlist.first(); 169 ical = jlist.first();
170 } 170 }
171 } 171 }
172 } 172 }
173 return ical; 173 return ical;
174} 174}
175#include <qapp.h> 175#include <qapplication.h>
176 176
177QString ICalFormat::toString( Calendar *cal ) 177QString ICalFormat::toString( Calendar *cal )
178{ 178{
179 179
180 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); 180 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
181 181
182 icalcomponent *calendar = mImpl->createCalendarComponent(cal); 182 icalcomponent *calendar = mImpl->createCalendarComponent(cal);
183 183
184 icalcomponent *component; 184 icalcomponent *component;
185 185
186 // todos 186 // todos
187 QPtrList<Todo> todoList = cal->rawTodos(); 187 Q3PtrList<Todo> todoList = cal->rawTodos();
188 QPtrListIterator<Todo> qlt(todoList); 188 Q3PtrListIterator<Todo> qlt(todoList);
189 for (; qlt.current(); ++qlt) { 189 for (; qlt.current(); ++qlt) {
190 component = mImpl->writeTodo(qlt.current()); 190 component = mImpl->writeTodo(qlt.current());
191 icalcomponent_add_component(calendar,component); 191 icalcomponent_add_component(calendar,component);
192 //qDebug(" todos "); 192 //qDebug(" todos ");
193 if ( mProcessEvents ) { 193 if ( mProcessEvents ) {
194 //qDebug("mProcessEvents "); 194 //qDebug("mProcessEvents ");
195 qApp->processEvents(); 195 qApp->processEvents();
196 } 196 }
197 } 197 }
198 // events 198 // events
199 QPtrList<Event> events = cal->rawEvents(); 199 Q3PtrList<Event> events = cal->rawEvents();
200 Event *ev; 200 Event *ev;
201 for(ev=events.first();ev;ev=events.next()) { 201 for(ev=events.first();ev;ev=events.next()) {
202 component = mImpl->writeEvent(ev); 202 component = mImpl->writeEvent(ev);
203 icalcomponent_add_component(calendar,component); 203 icalcomponent_add_component(calendar,component);
204 //qDebug("events "); 204 //qDebug("events ");
205 if ( mProcessEvents ) 205 if ( mProcessEvents )
206 qApp->processEvents(); 206 qApp->processEvents();
207 } 207 }
208 208
209 // journals 209 // journals
210 QPtrList<Journal> journals = cal->journals(); 210 Q3PtrList<Journal> journals = cal->journals();
211 Journal *j; 211 Journal *j;
212 for(j=journals.first();j;j=journals.next()) { 212 for(j=journals.first();j;j=journals.next()) {
213 component = mImpl->writeJournal(j); 213 component = mImpl->writeJournal(j);
214 icalcomponent_add_component(calendar,component); 214 icalcomponent_add_component(calendar,component);
215 //qDebug("journals "); 215 //qDebug("journals ");
216 if ( mProcessEvents ) 216 if ( mProcessEvents )
217 qApp->processEvents(); 217 qApp->processEvents();
218 } 218 }
219 const char *text; 219 const char *text;
220 QString ret =""; 220 QString ret ="";
221 text = icalcomponent_as_ical_string( calendar ); 221 text = icalcomponent_as_ical_string( calendar );
222 if ( mProcessEvents ) 222 if ( mProcessEvents )