kpilot/lib

pilotRecord.h

00001 #ifndef _KPILOT_PILOTRECORD_H
00002 #define _KPILOT_PILOTRECORD_H
00003 /* pilotRecord.h            KPilot
00004 **
00005 ** Copyright (C) 1998-2001 by Dan Pilone
00006 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00007 **
00008 */
00009 
00010 /*
00011 ** This program is free software; you can redistribute it and/or modify
00012 ** it under the terms of the GNU Lesser General Public License as published by
00013 ** the Free Software Foundation; either version 2.1 of the License, or
00014 ** (at your option) any later version.
00015 **
00016 ** This program is distributed in the hope that it will be useful,
00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 ** GNU Lesser General Public License for more details.
00020 **
00021 ** You should have received a copy of the GNU Lesser General Public License
00022 ** along with this program in a file called COPYING; if not, write to
00023 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 ** MA 02110-1301, USA.
00025 */
00026 
00027 /*
00028 ** Bug reports and questions can be sent to kde-pim@kde.org
00029 */
00030 
00037 #include <time.h>
00038 #include <unistd.h>
00039 #include <stdio.h>
00040 #include <kdemacros.h>
00041 
00042 #include "pilotLinkVersion.h"
00043 
00044 struct pi_buffer_t;
00045 
00046 #include <pi-dlp.h>
00047 #include <pi-file.h>
00048 
00049 #define PILOT_CATEGORY_SIZE 16 // (sizeof(((struct CategoryAppInfo *)0)->name[0]))
00050 #define PILOT_CATEGORY_MAX 16 // ( (sizeof(((struct CategoryAppInfo *)0)->name)) / PILOT_CATEGORY_SIZE )
00051 
00052 
00059 class KDE_EXPORT PilotRecordBase
00060 {
00061 public:
00070     PilotRecordBase(int attrib=0, int cat=0, recordid_t id=0) :
00071         fAttrib(attrib),fCat(cat),fID(id) 
00072     { 
00073         if ( !( (0<=cat) && (cat<PILOT_CATEGORY_MAX) ) ) fCat=0; 
00074     }
00075 
00077     inline int attributes() const { return fAttrib; }
00079     inline void  setAttributes(int attrib) { fAttrib = attrib; }
00080     int KDE_DEPRECATED getAttrib() const { return attributes(); }
00081     void KDE_DEPRECATED setAttrib(int attrib) { setAttributes(attrib); }
00082 
00084     int   category() const { return fCat; }
00089     void  setCategory(int cat) { if ( (cat<0) || (cat>=PILOT_CATEGORY_MAX)) cat=0; fCat = cat; }
00090     int  KDE_DEPRECATED  getCat() const { return category(); }
00091     void KDE_DEPRECATED  setCat(int cat) { return setCategory(cat); }
00092 
00096     inline recordid_t id() const { return fID; }
00100     void setID(recordid_t id) { fID = id; }
00101     recordid_t KDE_DEPRECATED getID() const { return id(); }
00102 
00108     inline bool isDeleted() const { return fAttrib & dlpRecAttrDeleted; };
00112     inline bool isSecret() const { return fAttrib & dlpRecAttrSecret; } ;
00119     inline bool isArchived() const { return fAttrib & dlpRecAttrArchived; } ;
00123     inline bool isModified() const { return fAttrib & dlpRecAttrDirty; }
00124     inline bool KDE_DEPRECATED isDirty() const { return isModified(); } ;
00125 
00126 #define SETTER(a) {\
00127         if (d) { fAttrib |= a; } \
00128         else   { fAttrib &= ~a; } }
00129 
00131     inline void setDeleted(bool d=true) SETTER(dlpRecAttrDeleted)
00132 
00134     inline void setSecret(bool d=true) SETTER(dlpRecAttrSecret)
00135 
00137     inline void setArchived(bool d=true) SETTER(dlpRecAttrArchived)
00138 
00140     inline void setModified(bool d=true) SETTER(dlpRecAttrDirty)
00141 
00142     void KDE_DEPRECATED makeDeleted() { setDeleted(true); }
00143     void KDE_DEPRECATED makeSecret() { setSecret(true); }
00144     void KDE_DEPRECATED makeArchived() { setArchived(true); }
00145 #undef SETTER
00146 
00147 private:
00148     int fAttrib, fCat;
00149     recordid_t fID;
00150 } ;
00151 
00156 class KDE_EXPORT PilotRecord : public PilotRecordBase
00157 {
00158 public:
00165     PilotRecord(void* data, int length, int attrib, int cat, recordid_t uid);
00166 
00167 #if PILOT_LINK_NUMBER >= PILOT_LINK_0_12_0
00168 
00174     PilotRecord(pi_buffer_t *buf, int attrib, int cat, recordid_t uid) :
00175         PilotRecordBase(attrib,cat,uid),
00176         fData((char *)buf->data),
00177         fLen(buf->used),
00178         fBuffer(buf)
00179     { fAllocated++; }
00180 #endif
00181 
00183     ~PilotRecord()
00184     {
00185 #if PILOT_LINK_NUMBER >= PILOT_LINK_0_12_0
00186         if (fBuffer) { pi_buffer_free(fBuffer); } else
00187 #endif
00188         { delete [] fData; }
00189         fDeleted++;
00190     }
00191 
00193     PilotRecord(PilotRecord* orig);
00194 
00201     char *data() const
00202     {
00203 #if PILOT_LINK_NUMBER >= PILOT_LINK_0_12_0
00204         if (fBuffer) return (char *)(fBuffer->data); else
00205 #endif
00206         return fData;
00207     }
00208     char *KDE_DEPRECATED getData() const { return data(); }
00209 
00211     int size() const
00212     {
00213 #if PILOT_LINK_NUMBER >= PILOT_LINK_0_12_0
00214         if (fBuffer) return fBuffer->used; else
00215 #endif
00216         return fLen;
00217     }
00218     int KDE_DEPRECATED getLen() const { return size(); }
00219 
00220 #if PILOT_LINK_NUMBER >= PILOT_LINK_0_12_0
00221 
00222     const pi_buffer_t *buffer() const { return fBuffer; }
00223 
00227     void setData(pi_buffer_t *b)
00228     {
00229         if (fBuffer) { pi_buffer_free(fBuffer); }
00230         else { delete[] fData; } ;
00231         fData = (char *)b->data;
00232         fLen = b->used;
00233         fBuffer = b;
00234     }
00235 #endif
00236 
00241     enum { APP_BUFFER_SIZE = 0xffff } ;
00242 
00244     PilotRecord& operator=(PilotRecord& orig);
00245 
00247     void setData(const char* data, int len);
00248 
00249 private:
00250     char* fData;
00251     int   fLen;
00252 #if PILOT_LINK_NUMBER >= PILOT_LINK_0_12_0
00253     pi_buffer_t *fBuffer;
00254 #endif
00255 
00256 public:
00262     static void allocationInfo();
00263 private:
00264     static int fAllocated,fDeleted;
00265 };
00266 
00267 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys