pilotDateEntry.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "options.h"
00030
00031 #include <stdlib.h>
00032
00033 #include <qtextcodec.h>
00034
00035 #ifndef _KDEBUG_H_
00036 #include <kdebug.h>
00037 #endif
00038
00039 #include "pilotDateEntry.h"
00040
00041 static const char *pilotDateEntry_id = "$Id: pilotDateEntry.cc,v 1.6.4.4 2003/03/12 23:31:15 adridg Exp $";
00042
00043
00044 PilotDateEntry::PilotDateEntry(void):PilotAppCategory()
00045 {
00046 ::memset(&fAppointmentInfo, 0, sizeof(struct Appointment));
00047 }
00048
00049
00050
00051 PilotDateEntry::PilotDateEntry(PilotRecord * rec):PilotAppCategory(rec)
00052 {
00053 ::memset(&fAppointmentInfo, 0, sizeof(fAppointmentInfo));
00054 if (rec)
00055 {
00056 unpack_Appointment(&fAppointmentInfo,
00057 (unsigned char *) rec->getData(), rec->getLen());
00058 }
00059 return;
00060
00061
00062
00063 (void) pilotDateEntry_id;
00064 }
00065
00066 void PilotDateEntry::_copyExceptions(const PilotDateEntry & e)
00067 {
00068 if (e.fAppointmentInfo.exceptions > 0)
00069 {
00070 size_t blocksize = e.fAppointmentInfo.exceptions *
00071 sizeof(struct tm);
00072
00073 fAppointmentInfo.exception = (struct tm *)::malloc(blocksize);
00074
00075 if (fAppointmentInfo.exception)
00076 {
00077 fAppointmentInfo.exceptions =
00078 e.fAppointmentInfo.exceptions;
00079 ::memcpy(fAppointmentInfo.exception,
00080 e.fAppointmentInfo.exception, blocksize);
00081 }
00082 else
00083 {
00084 kdError(LIBPILOTDB_AREA) << __FUNCTION__
00085 << ": malloc() failed, exceptions not copied"
00086 << endl;
00087 fAppointmentInfo.exceptions = 0;
00088 }
00089 }
00090 else
00091 {
00092 fAppointmentInfo.exceptions = 0;
00093 fAppointmentInfo.exception = 0L;
00094 }
00095 }
00096
00097
00098 PilotDateEntry::PilotDateEntry(const PilotDateEntry & e):PilotAppCategory(e)
00099 {
00100 ::memcpy(&fAppointmentInfo, &e.fAppointmentInfo,
00101 sizeof(struct Appointment));
00102
00103 fAppointmentInfo.exception = 0L;
00104 fAppointmentInfo.description = 0L;
00105 fAppointmentInfo.note = 0L;
00106
00107 _copyExceptions(e);
00108 setDescriptionP(e.fAppointmentInfo.description);
00109 setNoteP(e.fAppointmentInfo.note);
00110 }
00111
00112
00113 PilotDateEntry & PilotDateEntry::operator = (const PilotDateEntry & e)
00114 {
00115 if (this != &e)
00116 {
00117 KPILOT_FREE(fAppointmentInfo.exception);
00118 KPILOT_FREE(fAppointmentInfo.description);
00119 KPILOT_FREE(fAppointmentInfo.note);
00120 ::memcpy(&fAppointmentInfo, &e.fAppointmentInfo,
00121 sizeof(fAppointmentInfo));
00122
00123
00124
00125
00126
00127
00128
00129
00130 fAppointmentInfo.exception = 0L;
00131 fAppointmentInfo.description = 0L;
00132 fAppointmentInfo.note = 0L;
00133
00134 _copyExceptions(e);
00135 setDescriptionP(e.fAppointmentInfo.description);
00136 setNoteP(e.fAppointmentInfo.note);
00137 }
00138
00139 return *this;
00140 }
00141
00142
00143 void *PilotDateEntry::pack(void *buf, int *len)
00144 {
00145 int i;
00146
00147 i = pack_Appointment(&fAppointmentInfo, (unsigned char *) buf, *len);
00148 *len = i;
00149 return buf;
00150 }
00151
00152
00153
00154
00155 void PilotDateEntry::setExceptions(struct tm *e) {
00156 if (fAppointmentInfo.exception != e)
00157 {
00158 KPILOT_FREE(fAppointmentInfo.exception);
00159 }
00160 fAppointmentInfo.exception=e;
00161 }
00162
00163
00164 void PilotDateEntry::setDescriptionP(const char *desc, int l)
00165 {
00166 FUNCTIONSETUP;
00167 KPILOT_FREE(fAppointmentInfo.description);
00168
00169 if (desc && *desc)
00170 {
00171 if (-1 == l) l=::strlen(desc);
00172 fAppointmentInfo.description =
00173 (char *) ::malloc(l + 1);
00174 if (fAppointmentInfo.description)
00175 {
00176 ::strcpy(fAppointmentInfo.description, desc);
00177 }
00178 else
00179 {
00180 kdError(LIBPILOTDB_AREA) << __FUNCTION__
00181 << ": malloc() failed, description not set"
00182 << endl;
00183 }
00184 }
00185 else
00186 {
00187 fAppointmentInfo.description = 0L;
00188 }
00189 }
00190
00191 void PilotDateEntry::setNoteP(const char *note, int l)
00192 {
00193 FUNCTIONSETUP;
00194 KPILOT_FREE(fAppointmentInfo.note);
00195
00196 if (note && *note)
00197 {
00198 if (-1 == l) l=::strlen(note);
00199 fAppointmentInfo.note = (char *)::malloc(l + 1);
00200 if (fAppointmentInfo.note)
00201 {
00202 strcpy(fAppointmentInfo.note, note);
00203 }
00204 else
00205 {
00206 kdError(LIBPILOTDB_AREA) << __FUNCTION__
00207 << ": malloc() failed, note not set" << endl;
00208 }
00209 }
00210 else
00211 {
00212 fAppointmentInfo.note = 0L;
00213 }
00214 }
00215
00216 void PilotDateEntry::setNote(const QString &s)
00217 {
00218 setNoteP(codec()->fromUnicode(s),s.length());
00219 }
00220
00221 void PilotDateEntry::setDescription(const QString &s)
00222 {
00223 setDescriptionP(codec()->fromUnicode(s),s.length());
00224 }
00225
00226 QString PilotDateEntry::getNote() const
00227 {
00228 return codec()->toUnicode(getNoteP());
00229 }
00230
00231 QString PilotDateEntry::getDescription() const
00232 {
00233 return codec()->toUnicode(getDescriptionP());
00234 }
00235
This file is part of the documentation for kdelibs Version 3.1.5.