kpilot Library API Documentation

pilotDateEntry.cc

00001 /* pilotDateEntry.cc                    KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 **
00005 ** This is a C++ wrapper for the Pilot's datebook 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 
00029 #include "options.h"
00030 
00031 #include <stdlib.h>
00032 
00033 #include <qtextcodec.h>
00034 
00035 #ifndef _KDEBUG_H_
00036 #include <kdebug.h>
00037 #endif
00038 
00039 #include "pilotDateEntry.h"
00040 
00041 static const char *pilotDateEntry_id = "$Id: pilotDateEntry.cc,v 1.6.4.4 2003/03/12 23:31:15 adridg Exp $";
00042 
00043 
00044 PilotDateEntry::PilotDateEntry(void):PilotAppCategory()
00045 {
00046         ::memset(&fAppointmentInfo, 0, sizeof(struct Appointment));
00047 }
00048 
00049 /* initialize the entry from another one. If rec==NULL, this constructor does the same as PilotDateEntry()
00050 */
00051 PilotDateEntry::PilotDateEntry(PilotRecord * rec):PilotAppCategory(rec)
00052 {
00053         ::memset(&fAppointmentInfo, 0, sizeof(fAppointmentInfo));
00054         if (rec)
00055         {
00056                  unpack_Appointment(&fAppointmentInfo,
00057                         (unsigned char *) rec->getData(), rec->getLen());
00058         }
00059         return;
00060 
00061         /* NOTREACHED */
00062         /* Included to avoid warning that id isn't used. */
00063         (void) pilotDateEntry_id;
00064 }
00065 
00066 void PilotDateEntry::_copyExceptions(const PilotDateEntry & e)
00067 {
00068         if (e.fAppointmentInfo.exceptions > 0)
00069         {
00070                 size_t blocksize = e.fAppointmentInfo.exceptions * 
00071                         sizeof(struct tm);
00072 
00073                 fAppointmentInfo.exception = (struct tm *)::malloc(blocksize);
00074 
00075                 if (fAppointmentInfo.exception)
00076                 {
00077                         fAppointmentInfo.exceptions = 
00078                                 e.fAppointmentInfo.exceptions;
00079                         ::memcpy(fAppointmentInfo.exception,
00080                                 e.fAppointmentInfo.exception, blocksize);
00081                 }
00082                 else
00083                 {
00084                         kdError(LIBPILOTDB_AREA) << __FUNCTION__
00085                                 << ": malloc() failed, exceptions not copied"
00086                                 << endl;
00087                         fAppointmentInfo.exceptions = 0;
00088                 }
00089         }
00090         else
00091         {
00092                 fAppointmentInfo.exceptions = 0;
00093                 fAppointmentInfo.exception = 0L;
00094         }
00095 }
00096 
00097 
00098 PilotDateEntry::PilotDateEntry(const PilotDateEntry & e):PilotAppCategory(e)
00099 {
00100         ::memcpy(&fAppointmentInfo, &e.fAppointmentInfo,
00101                 sizeof(struct Appointment));
00102         // See operator = for explanation
00103         fAppointmentInfo.exception = 0L;
00104         fAppointmentInfo.description = 0L;
00105         fAppointmentInfo.note = 0L;
00106 
00107         _copyExceptions(e);
00108         setDescriptionP(e.fAppointmentInfo.description);
00109         setNoteP(e.fAppointmentInfo.note);
00110 }
00111 
00112 
00113 PilotDateEntry & PilotDateEntry::operator = (const PilotDateEntry & e)
00114 {
00115         if (this != &e)         // Pointer equality!
00116         {
00117                 KPILOT_FREE(fAppointmentInfo.exception);
00118                 KPILOT_FREE(fAppointmentInfo.description);
00119                 KPILOT_FREE(fAppointmentInfo.note);
00120                 ::memcpy(&fAppointmentInfo, &e.fAppointmentInfo,
00121                         sizeof(fAppointmentInfo));
00122 
00123                 // The original pointers were already freed; since we're now 
00124                 // got the pointers from the new structure and we're going
00125                 // to use the standard set functions make sure that
00126                 // we don't free() the copies-of-pointers from e, which
00127                 // would be disastrous.
00128                 //
00129                 //
00130                 fAppointmentInfo.exception = 0L;
00131                 fAppointmentInfo.description = 0L;
00132                 fAppointmentInfo.note = 0L;
00133 
00134                 _copyExceptions(e);
00135                 setDescriptionP(e.fAppointmentInfo.description);
00136                 setNoteP(e.fAppointmentInfo.note);
00137         }
00138 
00139         return *this;
00140 }                               // end of assignment operator
00141 
00142 
00143 void *PilotDateEntry::pack(void *buf, int *len)
00144 {
00145         int i;
00146 
00147         i = pack_Appointment(&fAppointmentInfo, (unsigned char *) buf, *len);
00148         *len = i;
00149         return buf;
00150 }
00151 
00152 /* setExceptions sets a new set of exceptions. Note that 
00153         PilotDateEntry assumes ownership of the array and will
00154         delete the old one. */
00155 void PilotDateEntry::setExceptions(struct tm *e) {
00156         if (fAppointmentInfo.exception != e)
00157         {
00158                 KPILOT_FREE(fAppointmentInfo.exception);
00159         }
00160         fAppointmentInfo.exception=e;
00161 }
00162 
00163 
00164 void PilotDateEntry::setDescriptionP(const char *desc, int l)
00165 {
00166         FUNCTIONSETUP;
00167         KPILOT_FREE(fAppointmentInfo.description);
00168 
00169         if (desc && *desc)
00170         {
00171                 if (-1 == l) l=::strlen(desc);
00172                 fAppointmentInfo.description =
00173                         (char *) ::malloc(l + 1);
00174                 if (fAppointmentInfo.description)
00175                 {
00176                         ::strcpy(fAppointmentInfo.description, desc);
00177                 }
00178                 else
00179                 {
00180                         kdError(LIBPILOTDB_AREA) << __FUNCTION__
00181                                 << ": malloc() failed, description not set"
00182                                 << endl;
00183                 }
00184         }
00185         else
00186         {
00187                 fAppointmentInfo.description = 0L;
00188         }
00189 }
00190 
00191 void PilotDateEntry::setNoteP(const char *note, int l)
00192 {
00193         FUNCTIONSETUP;
00194         KPILOT_FREE(fAppointmentInfo.note);
00195 
00196         if (note && *note)
00197         {
00198                 if (-1 == l) l=::strlen(note);
00199                 fAppointmentInfo.note = (char *)::malloc(l + 1);
00200                 if (fAppointmentInfo.note)
00201                 {
00202                         strcpy(fAppointmentInfo.note, note);
00203                 }
00204                 else
00205                 {
00206                         kdError(LIBPILOTDB_AREA) << __FUNCTION__
00207                                 << ": malloc() failed, note not set" << endl;
00208                 }
00209         }
00210         else
00211         {
00212                 fAppointmentInfo.note = 0L;
00213         }
00214 }
00215 
00216 void PilotDateEntry::setNote(const QString &s)
00217 {
00218         setNoteP(codec()->fromUnicode(s),s.length());
00219 }
00220 
00221 void PilotDateEntry::setDescription(const QString &s)
00222 {
00223         setDescriptionP(codec()->fromUnicode(s),s.length());
00224 }
00225 
00226 QString PilotDateEntry::getNote() const
00227 {
00228         return codec()->toUnicode(getNoteP());
00229 }
00230 
00231 QString PilotDateEntry::getDescription() const
00232 {
00233         return codec()->toUnicode(getDescriptionP());
00234 }
00235 
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