pilotTodoEntry.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 #include "options.h"
00029
00030 #include <stdlib.h>
00031
00032 #include <qtextcodec.h>
00033 #include <qdatetime.h>
00034 #include <kdebug.h>
00035
00036
00037 #include "pilotTodoEntry.h"
00038
00039 static const char *pilotTodoEntry_id = "$Id: pilotTodoEntry.cc,v 1.15 2003/10/01 10:13:39 kainhofe Exp $";
00040 const int PilotTodoEntry::APP_BUFFER_SIZE = 0xffff;
00041
00042
00043 PilotTodoEntry::PilotTodoEntry(struct ToDoAppInfo &appInfo):PilotAppCategory(), fAppInfo(appInfo)
00044 {
00045 FUNCTIONSETUP;
00046 ::memset(&fTodoInfo, 0, sizeof(struct ToDo));
00047 }
00048
00049
00050
00051 PilotTodoEntry::PilotTodoEntry(struct ToDoAppInfo &appInfo, PilotRecord * rec):PilotAppCategory(rec), fAppInfo(appInfo)
00052 {
00053 ::memset(&fTodoInfo, 0, sizeof(struct ToDo));
00054 if (rec)
00055 {
00056 unpack_ToDo(&fTodoInfo, (unsigned char *) rec->getData(),
00057 rec->getLen());
00058 }
00059 (void) pilotTodoEntry_id;
00060 }
00061
00062
00063 PilotTodoEntry::PilotTodoEntry(const PilotTodoEntry & e):PilotAppCategory(e), fAppInfo(e.fAppInfo)
00064 {
00065 FUNCTIONSETUP;
00066 ::memcpy(&fTodoInfo, &e.fTodoInfo, sizeof(fTodoInfo));
00067
00068 fTodoInfo.description = 0L;
00069 fTodoInfo.note = 0L;
00070
00071 setDescriptionP(e.getDescriptionP());
00072 setNoteP(e.getNoteP());
00073
00074 }
00075
00076
00077 PilotTodoEntry & PilotTodoEntry::operator = (const PilotTodoEntry & e)
00078 {
00079 if (this != &e)
00080 {
00081 KPILOT_FREE(fTodoInfo.description);
00082 KPILOT_FREE(fTodoInfo.note);
00083
00084 ::memcpy(&fTodoInfo, &e.fTodoInfo, sizeof(fTodoInfo));
00085
00086 fTodoInfo.description = 0L;
00087 fTodoInfo.note = 0L;
00088
00089 setDescriptionP(e.getDescriptionP());
00090 setNoteP(e.getNoteP());
00091
00092 }
00093
00094 return *this;
00095 }
00096
00097 QString PilotTodoEntry::getTextRepresentation(bool richText)
00098 {
00099 QString text, tmp;
00100 QString par = richText?CSL1("<p>"):CSL1("");
00101 QString ps = richText?CSL1("</p>"):CSL1("\n");
00102 QString br = richText?CSL1("<br/>"):CSL1("\n");
00103
00104
00105 text += par;
00106 tmp=richText?CSL1("<b><big>%1</big></b>"):CSL1("%1");
00107 text += tmp.arg(rtExpand(getDescription(), richText));
00108 text += ps;
00109
00110 text += par;
00111 if (getComplete())
00112 text += i18n("Completed");
00113 else
00114 text += i18n("Not completed");
00115 text += ps;
00116
00117 if (!getIndefinite())
00118 {
00119 QDate dt(readTm(getDueDate()).date());
00120 QString dueDate(dt.toString(Qt::LocalDate));
00121 text+=par;
00122 text+=i18n("Due date: %1").arg(dueDate);
00123 text+=ps;
00124 }
00125
00126 text+=par;
00127 text+=ps;
00128
00129 text+=par;
00130 text+=i18n("Priority: %1").arg(getPriority());
00131 text+=ps;
00132
00133 if (!getNote().isEmpty())
00134 {
00135 text += richText?CSL1("<hr/>"):CSL1("-------------------------\n");
00136 text+=par;
00137 text+=richText?i18n("<b><em>Note:</em></b><br>"):i18n("Note:\n");
00138 text+=rtExpand(getNote(), richText);
00139 text+=ps;
00140 }
00141
00142 return text;
00143 }
00144
00145 bool PilotTodoEntry::setCategory(const QString &label)
00146 {
00147 FUNCTIONSETUP;
00148 if (label.isEmpty())
00149 {
00150 setCat(0);
00151 return true;
00152 }
00153 for (int catId = 0; catId < 16; catId++)
00154 {
00155 QString aCat = codec()->toUnicode(fAppInfo.category.name[catId]);
00156
00157 if (label == aCat)
00158 {
00159 setCat(catId);
00160 return true;
00161 }
00162 else
00163
00164 if (aCat.isEmpty())
00165 {
00166 qstrncpy(fAppInfo.category.name[catId],
00167 codec()->fromUnicode(label), 16);
00168 setCat(catId);
00169 return true;
00170 }
00171 }
00172
00173 return false;
00174 }
00175
00176 QString PilotTodoEntry::getCategoryLabel() const
00177 {
00178 return codec()->toUnicode(fAppInfo.category.name[getCat()]);
00179 }
00180
00181 void *PilotTodoEntry::pack(void *buf, int *len)
00182 {
00183 int i;
00184
00185 i = pack_ToDo(&fTodoInfo, (unsigned char *) buf, *len);
00186 *len = i;
00187 return buf;
00188 }
00189
00190 void PilotTodoEntry::setDescription(const QString &desc)
00191 {
00192 setDescriptionP(codec()->fromUnicode(desc),desc.length());
00193 }
00194
00195 void PilotTodoEntry::setDescriptionP(const char *desc, int len)
00196 {
00197 KPILOT_FREE(fTodoInfo.description);
00198 if (desc && *desc)
00199 {
00200 if (-1 == len) len=::strlen(desc);
00201
00202 fTodoInfo.description = (char *)::malloc(len + 1);
00203 if (fTodoInfo.description)
00204 {
00205 ::strcpy(fTodoInfo.description, desc);
00206 }
00207 else
00208 {
00209 kdError(LIBPILOTDB_AREA) << __FUNCTION__
00210 << ": malloc() failed, description not set"
00211 << endl;
00212 }
00213 }
00214 else
00215 {
00216 fTodoInfo.description = 0L;
00217 }
00218 }
00219
00220 QString PilotTodoEntry::getDescription() const
00221 {
00222 return codec()->toUnicode(getDescriptionP());
00223 }
00224
00225 void PilotTodoEntry::setNote(const QString ¬e)
00226 {
00227 setNoteP(codec()->fromUnicode(note),note.length());
00228 }
00229
00230 void PilotTodoEntry::setNoteP(const char *note, int len)
00231 {
00232 KPILOT_FREE(fTodoInfo.note);
00233 if (note && *note)
00234 {
00235 if (-1 == len) len=::strlen(note);
00236 fTodoInfo.note = (char *)::malloc(len + 1);
00237 if (fTodoInfo.note)
00238 {
00239 ::strcpy(fTodoInfo.note, note);
00240 }
00241 else
00242 {
00243 kdError(LIBPILOTDB_AREA) << __FUNCTION__
00244 << ": malloc() failed, note not set" << endl;
00245 }
00246 }
00247 else
00248 {
00249 fTodoInfo.note = 0L;
00250 }
00251 }
00252
00253 QString PilotTodoEntry::getNote() const
00254 {
00255 return codec()->toUnicode(getNoteP());
00256 }
00257
This file is part of the documentation for kpilot Library Version 3.2.2.