kpilot/lib

pilotTodoEntry.cc

00001 /* KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 **
00006 ** This is a C++ wrapper for the todo-list entry structures.
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU Lesser General Public License as published by
00012 ** the Free Software Foundation; either version 2.1 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU Lesser General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU Lesser General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 ** MA 02110-1301, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 #include "options.h"
00030 
00031 #include <stdlib.h>
00032 
00033 #include <qtextcodec.h>
00034 #include <qdatetime.h>
00035 
00036 #include <kglobal.h>
00037 #include <kdebug.h>
00038 
00039 
00040 #include "pilotTodoEntry.h"
00041 
00042 static const char *pilotTodoEntry_id = "$Id: pilotTodoEntry.cc 450724 2005-08-18 22:12:19Z adridg $";
00043 
00044 
00045 PilotTodoEntry::PilotTodoEntry(struct ToDoAppInfo &appInfo):PilotAppCategory(), fAppInfo(appInfo)
00046 {
00047     FUNCTIONSETUP;
00048     ::memset(&fTodoInfo, 0, sizeof(struct ToDo));
00049 }
00050 
00051 /* initialize the entry from another one. If rec==NULL, this constructor does the same as PilotTodoEntry()
00052 */
00053 PilotTodoEntry::PilotTodoEntry(struct ToDoAppInfo &appInfo, PilotRecord * rec):PilotAppCategory(rec), fAppInfo(appInfo)
00054 {
00055     ::memset(&fTodoInfo, 0, sizeof(struct ToDo));
00056     if (rec)
00057     {
00058 #if PILOT_LINK_NUMBER >= PILOT_LINK_0_12_0
00059         pi_buffer_t b;
00060         b.data = (unsigned char *) rec->getData();
00061         b.allocated = b.used = rec->size();
00062         unpack_ToDo(&fTodoInfo, &b, todo_v1);
00063 #else
00064         unpack_ToDo(&fTodoInfo, (unsigned char *) rec->data(),
00065             rec->size());
00066 #endif
00067     }
00068 
00069     (void) pilotTodoEntry_id;
00070 }
00071 
00072 
00073 PilotTodoEntry::PilotTodoEntry(const PilotTodoEntry & e):PilotAppCategory(e), fAppInfo(e.fAppInfo)
00074 {
00075     FUNCTIONSETUP;
00076     ::memcpy(&fTodoInfo, &e.fTodoInfo, sizeof(fTodoInfo));
00077     // See PilotDateEntry::operator = for details
00078     fTodoInfo.description = 0L;
00079     fTodoInfo.note = 0L;
00080 
00081     setDescriptionP(e.getDescriptionP());
00082     setNoteP(e.getNoteP());
00083 
00084 }               // end of copy constructor
00085 
00086 
00087 PilotTodoEntry & PilotTodoEntry::operator = (const PilotTodoEntry & e)
00088 {
00089     if (this != &e)
00090     {
00091         KPILOT_FREE(fTodoInfo.description);
00092         KPILOT_FREE(fTodoInfo.note);
00093 
00094         ::memcpy(&fTodoInfo, &e.fTodoInfo, sizeof(fTodoInfo));
00095         // See PilotDateEntry::operator = for details
00096         fTodoInfo.description = 0L;
00097         fTodoInfo.note = 0L;
00098 
00099         setDescriptionP(e.getDescriptionP());
00100         setNoteP(e.getNoteP());
00101 
00102     }
00103 
00104     return *this;
00105 }               // end of assignment operator
00106 
00107 QString PilotTodoEntry::getTextRepresentation(bool richText)
00108 {
00109     QString text, tmp;
00110     QString par = richText?CSL1("<p>"):CSL1("");
00111     QString ps = richText?CSL1("</p>"):CSL1("\n");
00112     QString br = richText?CSL1("<br/>"):CSL1("\n");
00113 
00114     // title + name
00115     text += par;
00116     tmp=richText?CSL1("<b><big>%1</big></b>"):CSL1("%1");
00117     text += tmp.arg(rtExpand(getDescription(), richText));
00118     text += ps;
00119 
00120     text += par;
00121     if (getComplete())
00122         text += i18n("Completed");
00123     else
00124         text += i18n("Not completed");
00125     text += ps;
00126 
00127     if (!getIndefinite())
00128     {
00129         QDate dt(readTm(getDueDate()).date());
00130         QString dueDate(dt.toString(Qt::LocalDate));
00131         text+=par;
00132         text+=i18n("Due date: %1").arg(dueDate);
00133         text+=ps;
00134     }
00135 
00136     text+=par;
00137     text+=ps;
00138 
00139     text+=par;
00140     text+=i18n("Priority: %1").arg(getPriority());
00141     text+=ps;
00142 
00143     if (!getNote().isEmpty())
00144     {
00145         text += richText?CSL1("<hr/>"):CSL1("-------------------------\n");
00146         text+=par;
00147         text+=richText?i18n("<b><em>Note:</em></b><br>"):i18n("Note:\n");
00148         text+=rtExpand(getNote(), richText);
00149         text+=ps;
00150     }
00151 
00152     return text;
00153 }
00154 
00155 QString PilotTodoEntry::getCategoryLabel() const
00156 {
00157     return codec()->toUnicode(fAppInfo.category.name[category()]);
00158 }
00159 
00160 void *PilotTodoEntry::pack_(void *buf, int *len)
00161 {
00162     int i;
00163 
00164 #if PILOT_LINK_NUMBER >= PILOT_LINK_0_12_0
00165     pi_buffer_t b = { 0,0,0 } ;
00166     i = pack_ToDo(&fTodoInfo, &b, todo_v1);
00167     memcpy(buf,b.data,kMin(i,*len));
00168     *len = kMin(i,*len);
00169 #else
00170     i = pack_ToDo(&fTodoInfo, (unsigned char *) buf, *len);
00171     *len = i;
00172 #endif
00173     return buf;
00174 }
00175 
00176 void PilotTodoEntry::setDescription(const QString &desc)
00177 {
00178     setDescriptionP(codec()->fromUnicode(desc),desc.length());
00179 }
00180 
00181 void PilotTodoEntry::setDescriptionP(const char *desc, int len)
00182 {
00183     KPILOT_FREE(fTodoInfo.description);
00184     if (desc && *desc)
00185     {
00186         if (-1 == len) len=::strlen(desc);
00187 
00188         fTodoInfo.description = (char *)::malloc(len + 1);
00189         if (fTodoInfo.description)
00190         {
00191             strlcpy(fTodoInfo.description, desc, len+1);
00192         }
00193         else
00194         {
00195             kdError() << __FUNCTION__
00196                 << ": malloc() failed, description not set"
00197                 << endl;
00198         }
00199     }
00200     else
00201     {
00202         fTodoInfo.description = 0L;
00203     }
00204 }
00205 
00206 QString PilotTodoEntry::getDescription() const
00207 {
00208     return codec()->toUnicode(getDescriptionP());
00209 }
00210 
00211 void PilotTodoEntry::setNote(const QString &note)
00212 {
00213     setNoteP(codec()->fromUnicode(note),note.length());
00214 }
00215 
00216 void PilotTodoEntry::setNoteP(const char *note, int len)
00217 {
00218     KPILOT_FREE(fTodoInfo.note);
00219     if (note && *note)
00220       {
00221         if (-1 == len) len=::strlen(note);
00222         fTodoInfo.note = (char *)::malloc(len + 1);
00223         if (fTodoInfo.note)
00224         {
00225             strlcpy(fTodoInfo.note, note, len+1);
00226         }
00227         else
00228         {
00229             kdError() << __FUNCTION__
00230                 << ": malloc() failed, note not set" << endl;
00231         }
00232     }
00233     else
00234     {
00235         fTodoInfo.note = 0L;
00236     }
00237 }
00238 
00239 QString PilotTodoEntry::getNote() const
00240 {
00241     return codec()->toUnicode(getNoteP());
00242 }
00243 
KDE Home | KDE Accessibility Home | Description of Access Keys