kpilot Library API Documentation

pilotDateEntry.cc

00001 /* pilotDateEntry.cc KPilot 00002 ** 00003 ** Copyright (C) 1998-2001 by Dan Pilone 00004 ** 00005 ** This is a C++ wrapper for the Pilot's datebook structures. 00006 */ 00007 00008 /* 00009 ** This program is free software; you can redistribute it and/or modify 00010 ** it under the terms of the GNU Lesser General Public License as published by 00011 ** the Free Software Foundation; either version 2.1 of the License, or 00012 ** (at your option) any later version. 00013 ** 00014 ** This program is distributed in the hope that it will be useful, 00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 ** GNU Lesser General Public License for more details. 00018 ** 00019 ** You should have received a copy of the GNU Lesser General Public License 00020 ** along with this program in a file called COPYING; if not, write to 00021 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00022 ** MA 02111-1307, USA. 00023 */ 00024 00025 /* 00026 ** Bug reports and questions can be sent to kde-pim@kde.org 00027 */ 00028 00029 #include "options.h" 00030 00031 #include <stdlib.h> 00032 00033 #include <qtextcodec.h> 00034 #include <qdatetime.h> 00035 00036 #ifndef _KDEBUG_H_ 00037 #include <kdebug.h> 00038 #endif 00039 00040 #include "pilotDateEntry.h" 00041 00042 static const char *pilotDateEntry_id = "$Id: pilotDateEntry.cc,v 1.14 2003/11/24 00:29:20 adridg Exp $"; 00043 00044 00045 PilotDateEntry::PilotDateEntry(void):PilotAppCategory() 00046 { 00047 ::memset(&fAppointmentInfo, 0, sizeof(struct Appointment)); 00048 } 00049 00050 /* initialize the entry from another one. If rec==NULL, this constructor does the same as PilotDateEntry() 00051 */ 00052 PilotDateEntry::PilotDateEntry(PilotRecord * rec):PilotAppCategory(rec) 00053 { 00054 ::memset(&fAppointmentInfo, 0, sizeof(fAppointmentInfo)); 00055 if (rec) 00056 { 00057 unpack_Appointment(&fAppointmentInfo, 00058 (unsigned char *) rec->getData(), rec->getLen()); 00059 } 00060 return; 00061 00062 /* NOTREACHED */ 00063 /* Included to avoid warning that id isn't used. */ 00064 (void) pilotDateEntry_id; 00065 } 00066 00067 void PilotDateEntry::_copyExceptions(const PilotDateEntry & e) 00068 { 00069 if (e.fAppointmentInfo.exceptions > 0) 00070 { 00071 size_t blocksize = e.fAppointmentInfo.exceptions * 00072 sizeof(struct tm); 00073 00074 fAppointmentInfo.exception = (struct tm *)::malloc(blocksize); 00075 00076 if (fAppointmentInfo.exception) 00077 { 00078 fAppointmentInfo.exceptions = 00079 e.fAppointmentInfo.exceptions; 00080 ::memcpy(fAppointmentInfo.exception, 00081 e.fAppointmentInfo.exception, blocksize); 00082 } 00083 else 00084 { 00085 kdError(LIBPILOTDB_AREA) << __FUNCTION__ 00086 << ": malloc() failed, exceptions not copied" 00087 << endl; 00088 fAppointmentInfo.exceptions = 0; 00089 } 00090 } 00091 else 00092 { 00093 fAppointmentInfo.exceptions = 0; 00094 fAppointmentInfo.exception = 0L; 00095 } 00096 } 00097 00098 00099 PilotDateEntry::PilotDateEntry(const PilotDateEntry & e):PilotAppCategory(e) 00100 { 00101 ::memcpy(&fAppointmentInfo, &e.fAppointmentInfo, 00102 sizeof(struct Appointment)); 00103 // See operator = for explanation 00104 fAppointmentInfo.exception = 0L; 00105 fAppointmentInfo.description = 0L; 00106 fAppointmentInfo.note = 0L; 00107 00108 _copyExceptions(e); 00109 setDescriptionP(e.fAppointmentInfo.description); 00110 setNoteP(e.fAppointmentInfo.note); 00111 } 00112 00113 00114 PilotDateEntry & PilotDateEntry::operator = (const PilotDateEntry & e) 00115 { 00116 if (this != &e) // Pointer equality! 00117 { 00118 KPILOT_FREE(fAppointmentInfo.exception); 00119 KPILOT_FREE(fAppointmentInfo.description); 00120 KPILOT_FREE(fAppointmentInfo.note); 00121 ::memcpy(&fAppointmentInfo, &e.fAppointmentInfo, 00122 sizeof(fAppointmentInfo)); 00123 00124 // The original pointers were already freed; since we're now 00125 // got the pointers from the new structure and we're going 00126 // to use the standard set functions make sure that 00127 // we don't free() the copies-of-pointers from e, which 00128 // would be disastrous. 00129 // 00130 // 00131 fAppointmentInfo.exception = 0L; 00132 fAppointmentInfo.description = 0L; 00133 fAppointmentInfo.note = 0L; 00134 00135 _copyExceptions(e); 00136 setDescriptionP(e.fAppointmentInfo.description); 00137 setNoteP(e.fAppointmentInfo.note); 00138 } 00139 00140 return *this; 00141 } // end of assignment operator 00142 00143 00144 QString PilotDateEntry::getTextRepresentation(bool richText) 00145 { 00146 QString text, tmp; 00147 QString par = richText?CSL1("<p>"):QString::null; 00148 QString ps = richText?CSL1("</p>"):CSL1("\n"); 00149 QString br = richText?CSL1("<br/>"):CSL1("\n"); 00150 00151 // title + name 00152 text += par; 00153 tmp=richText?CSL1("<b><big>%1</big></b>"):CSL1("%1"); 00154 text += tmp.arg(rtExpand(getDescription(), richText)); 00155 text += ps; 00156 00157 QDateTime dt(readTm(getEventStart())); 00158 QString startDate(dt.toString(Qt::LocalDate)); 00159 text+=par; 00160 text+=i18n("Start date: %1").arg(startDate); 00161 text+=ps; 00162 00163 if (isEvent()) 00164 { 00165 text+=par; 00166 text+=i18n("Whole-day event"); 00167 text+=ps; 00168 } 00169 else 00170 { 00171 dt=readTm(getEventEnd()); 00172 QString endDate(dt.toString(Qt::LocalDate)); 00173 text+=par; 00174 text+=i18n("End date: %1").arg(endDate); 00175 text+=ps; 00176 } 00177 00178 if (getAlarm()) 00179 { 00180 text+=par; 00181 tmp=i18n("%1 is the duration, %2 is the time unit", "Alarm: %1 %2 before event starts"). 00182 arg(getAdvance()); 00183 switch (getAdvanceUnits()) 00184 { 00185 case advMinutes: tmp=tmp.arg(i18n("minutes")); break; 00186 case advHours: tmp=tmp.arg(i18n("hours")); break; 00187 case advDays: tmp=tmp.arg(i18n("days")); break; 00188 default: tmp=tmp.arg(QString::null); break;; 00189 } 00190 text+=tmp; 00191 text+=ps; 00192 } 00193 00194 if (getRepeatType() != repeatNone) 00195 { 00196 text+=par; 00197 tmp=i18n("Recurrence: every %1 %2"); 00198 int freq = getRepeatFrequency(); 00199 tmp=tmp.arg(freq); 00200 00201 switch(getRepeatType()) 00202 { 00203 case repeatDaily: tmp=tmp.arg(i18n("day(s)")); break; 00204 case repeatWeekly: tmp=tmp.arg(i18n("week(s)")); break; 00205 case repeatMonthlyByDay: 00206 case repeatMonthlyByDate: tmp=tmp.arg(i18n("month(s)")); break; 00207 case repeatYearly: tmp=tmp.arg(i18n("year(s)")); break; 00208 default: tmp=tmp.arg(QString::null); break; 00209 } 00210 text+=tmp; 00211 text+=br; 00212 00213 bool repeatsForever = getRepeatForever(); 00214 if (repeatsForever) 00215 { 00216 text+=i18n("Repeats indefinitely"); 00217 } 00218 else 00219 { 00220 dt = readTm(getRepeatEnd()).date(); 00221 text+=i18n("Until %1").arg(dt.toString(Qt::LocalDate)); 00222 } 00223 text+=br; 00224 00225 if (getRepeatType()==repeatMonthlyByDay) text+=i18n("Repeating on the i-th day of week j")+br; 00226 if (getRepeatType()==repeatMonthlyByDate) text+=i18n("Repeating on the n-th day of the month")+br; 00227 // TODO: show the dayArray when repeating weekly 00228 /*QBitArray dayArray(7); 00229 if (getRepeatType()==repeatWeekly) text+=i18n("Repeat day flags: %1").arg(getRepeatDays 00230 const int *days = dateEntry->getRepeatDays(); 00231 // Rotate the days of the week, since day numbers on the Pilot and 00232 // in vCal / Events are different. 00233 if (days[0]) dayArray.setBit(6); 00234 for (int i = 1; i < 7; i++) 00235 { 00236 if (days[i]) dayArray.setBit(i-1); 00237 }*/ 00238 text+=ps; 00239 } 00240 00241 if (getExceptionCount()>0 ) 00242 { 00243 text+=par; 00244 text+=i18n("Exceptions:")+br; 00245 for (int i = 0; i < getExceptionCount(); i++) 00246 { 00247 QDate exdt=readTm(getExceptions()[i]).date(); 00248 text+=exdt.toString(Qt::LocalDate); 00249 text+=br; 00250 } 00251 text+=ps; 00252 } 00253 00254 if (!getNote().isEmpty()) 00255 { 00256 text += richText?CSL1("<hr/>"):CSL1("-------------------------\n"); 00257 text+=par; 00258 text+=richText?i18n("<b><em>Note:</em></b><br>"):i18n("Note:\n"); 00259 text+=rtExpand(getNote(), richText); 00260 text+=ps; 00261 } 00262 00263 return text; 00264 } 00265 00266 00267 void *PilotDateEntry::pack(void *buf, int *len) 00268 { 00269 int i; 00270 00271 i = pack_Appointment(&fAppointmentInfo, (unsigned char *) buf, *len); 00272 *len = i; 00273 return buf; 00274 } 00275 00276 /* setExceptions sets a new set of exceptions. Note that 00277 PilotDateEntry assumes ownership of the array and will 00278 delete the old one. */ 00279 void PilotDateEntry::setExceptions(struct tm *e) { 00280 if (fAppointmentInfo.exception != e) 00281 { 00282 KPILOT_FREE(fAppointmentInfo.exception); 00283 } 00284 fAppointmentInfo.exception=e; 00285 } 00286 00287 00288 void PilotDateEntry::setDescriptionP(const char *desc, int l) 00289 { 00290 FUNCTIONSETUP; 00291 KPILOT_FREE(fAppointmentInfo.description); 00292 00293 if (desc && *desc) 00294 { 00295 if (-1 == l) l=::strlen(desc); 00296 fAppointmentInfo.description = 00297 (char *) ::malloc(l + 1); 00298 if (fAppointmentInfo.description) 00299 { 00300 ::strcpy(fAppointmentInfo.description, desc); 00301 } 00302 else 00303 { 00304 kdError(LIBPILOTDB_AREA) << __FUNCTION__ 00305 << ": malloc() failed, description not set" 00306 << endl; 00307 } 00308 } 00309 else 00310 { 00311 fAppointmentInfo.description = 0L; 00312 } 00313 } 00314 00315 void PilotDateEntry::setNoteP(const char *note, int l) 00316 { 00317 FUNCTIONSETUP; 00318 KPILOT_FREE(fAppointmentInfo.note); 00319 00320 if (note && *note) 00321 { 00322 if (-1 == l) l=::strlen(note); 00323 fAppointmentInfo.note = (char *)::malloc(l + 1); 00324 if (fAppointmentInfo.note) 00325 { 00326 strcpy(fAppointmentInfo.note, note); 00327 } 00328 else 00329 { 00330 kdError(LIBPILOTDB_AREA) << __FUNCTION__ 00331 << ": malloc() failed, note not set" << endl; 00332 } 00333 } 00334 else 00335 { 00336 fAppointmentInfo.note = 0L; 00337 } 00338 } 00339 00340 void PilotDateEntry::setNote(const QString &s) 00341 { 00342 setNoteP(codec()->fromUnicode(s),s.length()); 00343 } 00344 00345 void PilotDateEntry::setDescription(const QString &s) 00346 { 00347 setDescriptionP(codec()->fromUnicode(s),s.length()); 00348 } 00349 00350 QString PilotDateEntry::getNote() const 00351 { 00352 return codec()->toUnicode(getNoteP()); 00353 } 00354 00355 QString PilotDateEntry::getDescription() const 00356 { 00357 return codec()->toUnicode(getDescriptionP()); 00358 } 00359
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:49 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003