kpilot Library API Documentation

pilotTodoEntry.cc

00001 /* pilotTodoEntry.cc            KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 **
00005 ** This is a C++ wrapper for the todo-list entry structures.
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU Lesser General Public License as published by
00011 ** the Free Software Foundation; either version 2.1 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU Lesser General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU Lesser General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00022 ** MA 02111-1307, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
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 /* initialize the entry from another one. If rec==NULL, this constructor does the same as PilotTodoEntry()
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     // See PilotDateEntry::operator = for details
00068     fTodoInfo.description = 0L;
00069     fTodoInfo.note = 0L;
00070 
00071     setDescriptionP(e.getDescriptionP());
00072     setNoteP(e.getNoteP());
00073 
00074 }               // end of copy constructor
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         // See PilotDateEntry::operator = for details
00086         fTodoInfo.description = 0L;
00087         fTodoInfo.note = 0L;
00088 
00089         setDescriptionP(e.getDescriptionP());
00090         setNoteP(e.getNoteP());
00091 
00092     }
00093 
00094     return *this;
00095 }               // end of assignment operator
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     // title + name
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             // if empty, then no more labels; add it
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     // if got here, the category slots were full
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 &note)
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 
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:49 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003