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
00032 #include <stdlib.h>
00033
00034 #include <qdatetime.h>
00035
00036 #include <kglobal.h>
00037 #include <kdebug.h>
00038
00039
00040 #include "pilotTodoEntry.h"
00041
00042
00043 PilotTodoEntry::PilotTodoEntry(struct ToDoAppInfo &appInfo) :
00044 fAppInfo(appInfo),
00045 fDescriptionSize(0),
00046 fNoteSize(0)
00047 {
00048 FUNCTIONSETUP;
00049 ::memset(&fTodoInfo, 0, sizeof(struct ToDo));
00050 }
00051
00052
00053
00054 PilotTodoEntry::PilotTodoEntry(struct ToDoAppInfo &appInfo, PilotRecord * rec) :
00055 PilotRecordBase(rec),
00056 fAppInfo(appInfo),
00057 fDescriptionSize(0),
00058 fNoteSize(0)
00059 {
00060 ::memset(&fTodoInfo, 0, sizeof(struct ToDo));
00061 if (rec)
00062 {
00063 pi_buffer_t b;
00064 b.data = (unsigned char *) rec->data();
00065 b.allocated = b.used = rec->size();
00066 unpack_ToDo(&fTodoInfo, &b, todo_v1);
00067 if (fTodoInfo.description)
00068 {
00069
00070
00071 fDescriptionSize = strlen(fTodoInfo.description)+1;
00072 }
00073 if (fTodoInfo.note)
00074 {
00075
00076 fNoteSize = strlen(fTodoInfo.note)+1;
00077 }
00078 }
00079
00080 }
00081
00082
00083 PilotTodoEntry::PilotTodoEntry(const PilotTodoEntry & e) :
00084 PilotRecordBase( &e ),
00085 fAppInfo(e.fAppInfo),
00086 fDescriptionSize(0),
00087 fNoteSize(0)
00088 {
00089 FUNCTIONSETUP;
00090 ::memcpy(&fTodoInfo, &e.fTodoInfo, sizeof(fTodoInfo));
00091
00092 fTodoInfo.description = 0L;
00093 fTodoInfo.note = 0L;
00094
00095 setDescriptionP(e.getDescriptionP());
00096 setNoteP(e.getNoteP());
00097 }
00098
00099
00100 PilotTodoEntry & PilotTodoEntry::operator = (const PilotTodoEntry & e)
00101 {
00102 if (this != &e)
00103 {
00104 KPILOT_FREE(fTodoInfo.description);
00105 KPILOT_FREE(fTodoInfo.note);
00106
00107 ::memcpy(&fTodoInfo, &e.fTodoInfo, sizeof(fTodoInfo));
00108
00109 fTodoInfo.description = 0L;
00110 fTodoInfo.note = 0L;
00111 fDescriptionSize = 0;
00112 fNoteSize = 0;
00113
00114 setDescriptionP(e.getDescriptionP());
00115 setNoteP(e.getNoteP());
00116
00117 }
00118
00119 return *this;
00120 }
00121
00122 QString PilotTodoEntry::getTextRepresentation(bool richText)
00123 {
00124 QString text, tmp;
00125 QString par = richText?CSL1("<p>"):CSL1("");
00126 QString ps = richText?CSL1("</p>"):CSL1("\n");
00127 QString br = richText?CSL1("<br/>"):CSL1("\n");
00128
00129
00130 text += par;
00131 tmp=richText?CSL1("<b><big>%1</big></b>"):CSL1("%1");
00132 text += tmp.arg(rtExpand(getDescription(), richText));
00133 text += ps;
00134
00135 text += par;
00136 if (getComplete())
00137 text += i18n("Completed");
00138 else
00139 text += i18n("Not completed");
00140 text += ps;
00141
00142 if (!getIndefinite())
00143 {
00144 QDate dt(readTm(getDueDate()).date());
00145 QString dueDate(dt.toString(Qt::LocalDate));
00146 text+=par;
00147 text+=i18n("Due date: %1").arg(dueDate);
00148 text+=ps;
00149 }
00150
00151 text+=par;
00152 text+=ps;
00153
00154 text+=par;
00155 text+=i18n("Priority: %1").arg(getPriority());
00156 text+=ps;
00157
00158 if (!getNote().isEmpty())
00159 {
00160 text += richText?CSL1("<hr/>"):CSL1("-------------------------\n");
00161 text+=par;
00162 text+=richText?i18n("<b><em>Note:</em></b><br>"):i18n("Note:\n");
00163 text+=rtExpand(getNote(), richText);
00164 text+=ps;
00165 }
00166
00167 return text;
00168 }
00169
00170 QString PilotTodoEntry::getCategoryLabel() const
00171 {
00172 return Pilot::fromPilot(fAppInfo.category.name[category()]);
00173 }
00174
00175 PilotRecord *PilotTodoEntry::pack() const
00176 {
00177 int i;
00178
00179 pi_buffer_t *b = pi_buffer_new( sizeof(fTodoInfo) );
00180 i = pack_ToDo(const_cast<ToDo_t *>(&fTodoInfo), b, todo_v1);
00181 if (i<0)
00182 {
00183 return 0;
00184 }
00185
00186 return new PilotRecord( b, this );
00187 }
00188
00189 void PilotTodoEntry::setDescription(const QString &desc)
00190 {
00191 if (desc.length() < fDescriptionSize)
00192 {
00193 Pilot::toPilot(desc, fTodoInfo.description, fDescriptionSize);
00194 }
00195 else
00196 {
00197 setDescriptionP(Pilot::toPilot(desc),desc.length());
00198 }
00199 }
00200
00201 void PilotTodoEntry::setDescriptionP(const char *desc, int len)
00202 {
00203 KPILOT_FREE(fTodoInfo.description);
00204 if (desc && *desc)
00205 {
00206 if (-1 == len)
00207 {
00208 len=::strlen(desc);
00209 }
00210
00211 fDescriptionSize = len+1;
00212 fTodoInfo.description = (char *)::malloc(len + 1);
00213 if (fTodoInfo.description)
00214 {
00215 strncpy(fTodoInfo.description, desc, len);
00216 fTodoInfo.description[len] = 0;
00217 }
00218 else
00219 {
00220 kdError() << __FUNCTION__
00221 << ": malloc() failed, description not set"
00222 << endl;
00223 }
00224 }
00225 else
00226 {
00227 fTodoInfo.description = 0L;
00228 }
00229 }
00230
00231 QString PilotTodoEntry::getDescription() const
00232 {
00233 return Pilot::fromPilot(getDescriptionP());
00234 }
00235
00236 void PilotTodoEntry::setNote(const QString ¬e)
00237 {
00238 if (note.length() < fNoteSize)
00239 {
00240 Pilot::toPilot(note, fTodoInfo.note, fNoteSize);
00241 }
00242 else
00243 {
00244 setNoteP(Pilot::toPilot(note),note.length());
00245 }
00246 }
00247
00248 void PilotTodoEntry::setNoteP(const char *note, int len)
00249 {
00250 KPILOT_FREE(fTodoInfo.note);
00251 if (note && *note)
00252 {
00253 if (-1 == len)
00254 {
00255 len=::strlen(note);
00256 }
00257
00258 fNoteSize = len+1;
00259 fTodoInfo.note = (char *)::malloc(len + 1);
00260 if (fTodoInfo.note)
00261 {
00262 strncpy(fTodoInfo.note, note, len);
00263 fTodoInfo.note[len] = 0;
00264 }
00265 else
00266 {
00267 kdError() << __FUNCTION__
00268 << ": malloc() failed, note not set" << endl;
00269 }
00270 }
00271 else
00272 {
00273 fTodoInfo.note = 0L;
00274 }
00275 }
00276
00277 QString PilotTodoEntry::getNote() const
00278 {
00279 return Pilot::fromPilot(getNoteP());
00280 }
00281