summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-13 00:09:20 (UTC)
committer zautrix <zautrix>2004-10-13 00:09:20 (UTC)
commitd56ca1073ce493afdeb54e33425638f7147d4bca (patch) (unidiff)
tree03b21c9d7a875c7f7dd46d936d834570d211ae42
parent0dab27179ee6b1e0a052ab589a27e31ffb887912 (diff)
downloadkdepimpi-d56ca1073ce493afdeb54e33425638f7147d4bca.zip
kdepimpi-d56ca1073ce493afdeb54e33425638f7147d4bca.tar.gz
kdepimpi-d56ca1073ce493afdeb54e33425638f7147d4bca.tar.bz2
fix in save vcal as local time
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/vcalformat.cpp10
1 files changed, 3 insertions, 7 deletions
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 309c699..a6ae1bc 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -17,196 +17,192 @@
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qclipboard.h> 27#include <qclipboard.h>
28#include <qdialog.h> 28#include <qdialog.h>
29#include <qfile.h> 29#include <qfile.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <kmessagebox.h> 33#include <kmessagebox.h>
34#include <kiconloader.h> 34#include <kiconloader.h>
35#include <klocale.h> 35#include <klocale.h>
36 36
37#include "vcc.h" 37#include "vcc.h"
38#include "vobject.h" 38#include "vobject.h"
39 39
40#include "vcaldrag.h" 40#include "vcaldrag.h"
41#include "calendar.h" 41#include "calendar.h"
42 42
43#include "vcalformat.h" 43#include "vcalformat.h"
44 44
45using namespace KCal; 45using namespace KCal;
46 46
47VCalFormat::VCalFormat() 47VCalFormat::VCalFormat()
48{ 48{
49 mCalendar = 0; 49 mCalendar = 0;
50 useLocalTime = false; 50 useLocalTime = false;
51} 51}
52 52
53VCalFormat::~VCalFormat() 53VCalFormat::~VCalFormat()
54{ 54{
55} 55}
56 56
57void VCalFormat::setLocalTime ( bool b ) 57void VCalFormat::setLocalTime ( bool b )
58{ 58{
59 useLocalTime = b; 59 useLocalTime = b;
60} 60}
61bool VCalFormat::load(Calendar *calendar, const QString &fileName) 61bool VCalFormat::load(Calendar *calendar, const QString &fileName)
62{ 62{
63 mCalendar = calendar; 63 mCalendar = calendar;
64 clearException(); 64 clearException();
65 65 useLocalTime = mCalendar->isLocalTime();
66 kdDebug(5800) << "VCalFormat::load() " << fileName << endl;
67
68 VObject *vcal = 0; 66 VObject *vcal = 0;
69 67
70 // this is not necessarily only 1 vcal. Could be many vcals, or include 68 // this is not necessarily only 1 vcal. Could be many vcals, or include
71 // a vcard... 69 // a vcard...
72 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); 70 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
73 71
74 if (!vcal) { 72 if (!vcal) {
75 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 73 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
76 return FALSE; 74 return FALSE;
77 } 75 }
78 76
79 // any other top-level calendar stuff should be added/initialized here 77 // any other top-level calendar stuff should be added/initialized here
80 78
81 // put all vobjects into their proper places 79 // put all vobjects into their proper places
82 populate(vcal); 80 populate(vcal);
83 81
84 // clean up from vcal API stuff 82 // clean up from vcal API stuff
85 cleanVObjects(vcal); 83 cleanVObjects(vcal);
86 cleanStrTbl(); 84 cleanStrTbl();
87 85
88 return true; 86 return true;
89} 87}
90 88
91 89
92bool VCalFormat::save(Calendar *calendar, const QString &fileName) 90bool VCalFormat::save(Calendar *calendar, const QString &fileName)
93{ 91{
94 mCalendar = calendar; 92 mCalendar = calendar;
93 useLocalTime = mCalendar->isLocalTime();
95 94
96 QString tmpStr; 95 QString tmpStr;
97 VObject *vcal, *vo; 96 VObject *vcal, *vo;
98 97
99 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl;
100 98
101 vcal = newVObject(VCCalProp); 99 vcal = newVObject(VCCalProp);
102 100
103 // addPropValue(vcal,VCLocationProp, "0.0"); 101 // addPropValue(vcal,VCLocationProp, "0.0");
104 addPropValue(vcal,VCProdIdProp, productId()); 102 addPropValue(vcal,VCProdIdProp, productId());
105 tmpStr = mCalendar->getTimeZoneStr(); 103 tmpStr = mCalendar->getTimeZoneStr();
106 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); 104 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() );
107 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); 105 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit());
108 addPropValue(vcal,VCVersionProp, _VCAL_VERSION); 106 addPropValue(vcal,VCVersionProp, _VCAL_VERSION);
109 107
110 // TODO STUFF 108 // TODO STUFF
111 QPtrList<Todo> todoList = mCalendar->rawTodos(); 109 QPtrList<Todo> todoList = mCalendar->rawTodos();
112 QPtrListIterator<Todo> qlt(todoList); 110 QPtrListIterator<Todo> qlt(todoList);
113 for (; qlt.current(); ++qlt) { 111 for (; qlt.current(); ++qlt) {
114 vo = eventToVTodo(qlt.current()); 112 vo = eventToVTodo(qlt.current());
115 addVObjectProp(vcal, vo); 113 addVObjectProp(vcal, vo);
116 } 114 }
117 115
118 // EVENT STUFF 116 // EVENT STUFF
119 QPtrList<Event> events = mCalendar->rawEvents(); 117 QPtrList<Event> events = mCalendar->rawEvents();
120 Event *ev; 118 Event *ev;
121 for(ev=events.first();ev;ev=events.next()) { 119 for(ev=events.first();ev;ev=events.next()) {
122 vo = eventToVEvent(ev); 120 vo = eventToVEvent(ev);
123 addVObjectProp(vcal, vo); 121 addVObjectProp(vcal, vo);
124 } 122 }
125 123
126 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); 124 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal);
127 cleanVObjects(vcal); 125 cleanVObjects(vcal);
128 cleanStrTbl(); 126 cleanStrTbl();
129 127
130 if (QFile::exists(fileName)) { 128 if (QFile::exists(fileName)) {
131 kdDebug(5800) << "No error" << endl;
132 return true; 129 return true;
133 } else { 130 } else {
134 kdDebug(5800) << "Error" << endl;
135 return false; // error 131 return false; // error
136 } 132 }
137} 133}
138 134
139bool VCalFormat::fromString( Calendar *calendar, const QString &text ) 135bool VCalFormat::fromString( Calendar *calendar, const QString &text )
140{ 136{
141 // TODO: Factor out VCalFormat::fromString() 137 // TODO: Factor out VCalFormat::fromString()
142 138
143 QCString data = text.utf8(); 139 QCString data = text.utf8();
144 140
145 if ( !data.size() ) return false; 141 if ( !data.size() ) return false;
146 142
147 VObject *vcal = Parse_MIME( data.data(), data.size()); 143 VObject *vcal = Parse_MIME( data.data(), data.size());
148 if ( !vcal ) return false; 144 if ( !vcal ) return false;
149 145
150 VObjectIterator i; 146 VObjectIterator i;
151 VObject *curvo; 147 VObject *curvo;
152 initPropIterator( &i, vcal ); 148 initPropIterator( &i, vcal );
153 149
154 // we only take the first object. TODO: parse all incidences. 150 // we only take the first object. TODO: parse all incidences.
155 do { 151 do {
156 curvo = nextVObject( &i ); 152 curvo = nextVObject( &i );
157 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 153 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
158 strcmp( vObjectName( curvo ), VCTodoProp ) ); 154 strcmp( vObjectName( curvo ), VCTodoProp ) );
159 155
160 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 156 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
161 Event *event = VEventToEvent( curvo ); 157 Event *event = VEventToEvent( curvo );
162 calendar->addEvent( event ); 158 calendar->addEvent( event );
163 } else { 159 } else {
164 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; 160 qDebug("VCalFormat::fromString(): Unknown object type. ");
165 deleteVObject( vcal ); 161 deleteVObject( vcal );
166 return false; 162 return false;
167 } 163 }
168 164
169 deleteVObject( vcal ); 165 deleteVObject( vcal );
170 166
171 return true; 167 return true;
172} 168}
173 169
174QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal) 170QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal)
175{ 171{
176 172
177 if ( !event ) return QString::null; 173 if ( !event ) return QString::null;
178 bool useL = useLocalTime; 174 bool useL = useLocalTime;
179 useLocalTime = useLocal; 175 useLocalTime = useLocal;
180 mCalendar = calendar; 176 mCalendar = calendar;
181 VObject *vevent = eventToVEvent( event ); 177 VObject *vevent = eventToVEvent( event );
182 char *buf = writeMemVObject( 0, 0, vevent ); 178 char *buf = writeMemVObject( 0, 0, vevent );
183 QString result( buf ); 179 QString result( buf );
184 cleanVObject( vevent ); 180 cleanVObject( vevent );
185 useLocalTime = useL; 181 useLocalTime = useL;
186 return result; 182 return result;
187} 183}
188QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal ) 184QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal )
189{ 185{
190 186
191 if ( !todo ) return QString::null; 187 if ( !todo ) return QString::null;
192 bool useL = useLocalTime; 188 bool useL = useLocalTime;
193 useLocalTime = useLocal; 189 useLocalTime = useLocal;
194 mCalendar = calendar; 190 mCalendar = calendar;
195 VObject *vevent = eventToVTodo( todo ); 191 VObject *vevent = eventToVTodo( todo );
196 char *buf = writeMemVObject( 0, 0, vevent ); 192 char *buf = writeMemVObject( 0, 0, vevent );
197 QString result( buf ); 193 QString result( buf );
198 cleanVObject( vevent ); 194 cleanVObject( vevent );
199 useLocalTime = useL; 195 useLocalTime = useL;
200 return result; 196 return result;
201} 197}
202 198
203QString VCalFormat::toString( Calendar *calendar ) 199QString VCalFormat::toString( Calendar *calendar )
204{ 200{
205 // TODO: Factor out VCalFormat::asString() 201 // TODO: Factor out VCalFormat::asString()
206 202
207 VObject *vcal = newVObject(VCCalProp); 203 VObject *vcal = newVObject(VCCalProp);
208 204
209 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 205 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
210 QString tmpStr = mCalendar->getTimeZoneStr(); 206 QString tmpStr = mCalendar->getTimeZoneStr();
211 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 207 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
212 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 208 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );