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 
00034 #include <kdebug.h>
00035 
00036 
00037 #include "pilotTodoEntry.h"
00038 
00039 static const char *pilotTodoEntry_id = "$Id: pilotTodoEntry.cc,v 1.7.4.4 2003/03/12 23:31:16 adridg 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 bool PilotTodoEntry::setCategory(const QString &label)
00098 {
00099         FUNCTIONSETUP;
00100         for (int catId = 0; catId < 16; catId++)
00101         {
00102                 QString aCat = codec()->toUnicode(fAppInfo.category.name[catId]);
00103 
00104                 if (label == aCat)
00105                 {
00106                         setCat(catId);
00107                         return true;
00108                 }
00109                 else
00110                         // if empty, then no more labels; add it 
00111                 if (aCat.isEmpty())
00112                 {
00113                         qstrncpy(fAppInfo.category.name[catId], 
00114                                 codec()->fromUnicode(label), 16);
00115                         setCat(catId);
00116                         return true;
00117                 }
00118         }
00119         // if got here, the category slots were full
00120         return false;
00121 }
00122 
00123 QString PilotTodoEntry::getCategoryLabel() const
00124 {
00125         return codec()->toUnicode(fAppInfo.category.name[getCat()]);
00126 }
00127 
00128 void *PilotTodoEntry::pack(void *buf, int *len)
00129 {
00130         int i;
00131 
00132         i = pack_ToDo(&fTodoInfo, (unsigned char *) buf, *len);
00133         *len = i;
00134         return buf;
00135 }
00136 
00137 void PilotTodoEntry::setDescription(const QString &desc)
00138 {
00139         setDescriptionP(codec()->fromUnicode(desc),desc.length());
00140 }
00141 
00142 void PilotTodoEntry::setDescriptionP(const char *desc, int len)
00143 {
00144         KPILOT_FREE(fTodoInfo.description);
00145         if (desc && *desc)
00146         {
00147                 if (-1 == len) len=::strlen(desc);
00148 
00149                 fTodoInfo.description = (char *)::malloc(len + 1);
00150                 if (fTodoInfo.description)
00151                 {
00152                         ::strcpy(fTodoInfo.description, desc);
00153                 }
00154                 else
00155                 {
00156                         kdError(LIBPILOTDB_AREA) << __FUNCTION__
00157                                 << ": malloc() failed, description not set"
00158                                 << endl;
00159                 }
00160         }
00161         else
00162         {
00163                 fTodoInfo.description = 0L;
00164         }
00165 }
00166 
00167 QString PilotTodoEntry::getDescription() const
00168 {
00169         return codec()->toUnicode(getDescriptionP());
00170 }
00171 
00172 void PilotTodoEntry::setNote(const QString &note)
00173 {
00174         setNoteP(codec()->fromUnicode(note),note.length());
00175 }
00176 
00177 void PilotTodoEntry::setNoteP(const char *note, int len)
00178 {
00179         KPILOT_FREE(fTodoInfo.note);
00180         if (note && *note)
00181           {
00182             if (-1 == len) len=::strlen(note);
00183                 fTodoInfo.note = (char *)::malloc(len + 1);
00184                 if (fTodoInfo.note)
00185                 {
00186                     ::strcpy(fTodoInfo.note, note);
00187                 }
00188                 else
00189                 {
00190                         kdError(LIBPILOTDB_AREA) << __FUNCTION__
00191                                 << ": malloc() failed, note not set" << endl;
00192                 }
00193         }
00194         else
00195         {
00196                 fTodoInfo.note = 0L;
00197         }
00198 }
00199 
00200 QString PilotTodoEntry::getNote() const
00201 {
00202         return codec()->toUnicode(getNoteP());
00203 }
00204 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:14 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001