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