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 "pilotLinkVersion.h"
00038 
00039 #include "pilot.h"
00040 
00041 #include <pi-buffer.h>
00042 
00043 
00050 class KDE_EXPORT PilotRecordBase
00051 {
00052 public:
00061     PilotRecordBase(int attrib=0, int cat=0, recordid_t id=0) :
00062         fAttrib(attrib),fCat(0),fID(id)
00063     {
00064         setCategory(cat);
00065     }
00066 
00067     PilotRecordBase( const PilotRecordBase *b ) :
00068         fAttrib( b ? b->attributes() : 0 ),
00069         fCat( 0 ),
00070         fID( b ? b->id() : 0 )
00071     {
00072         if (b)
00073         {
00074             setCategory( b->category() );
00075         }
00076     }
00077 
00079     virtual ~PilotRecordBase() { } ;
00080 
00084     inline int attributes() const { return fAttrib; }
00085 
00087     inline void  setAttributes(int attrib) { fAttrib = attrib; }
00088 
00092     inline int   category() const { return fCat; }
00093 
00099     inline void  setCategory(int cat) { if ( (cat<0) || (cat>=(int)Pilot::CATEGORY_COUNT)) cat=0; fCat = cat; }
00100 
00111     bool setCategory(const struct CategoryAppInfo *info, const QString &label)
00112     {
00113         if (!info)
00114         {
00115             return false;
00116         }
00117 
00118         int cat = Pilot::findCategory( info, label, false );
00119         if ( (cat<0) || (cat>=(int)Pilot::CATEGORY_COUNT) )
00120         {
00121             return false;
00122         }
00123         else
00124         {
00125             setCategory( cat );
00126             return true;
00127         }
00128     }
00129 
00133     inline recordid_t id() const { return fID; }
00134 
00138     void setID(recordid_t id) { fID = id; }
00139 
00145     inline bool isDeleted() const { return fAttrib & dlpRecAttrDeleted; };
00146 
00150     inline bool isSecret() const { return fAttrib & dlpRecAttrSecret; } ;
00151 
00158     inline bool isArchived() const { return fAttrib & dlpRecAttrArchived; } ;
00159 
00163     inline bool isModified() const { return fAttrib & dlpRecAttrDirty; }
00164 
00165 #define SETTER(a) {\
00166         if (d) { fAttrib |= a; } \
00167         else   { fAttrib &= ~a; } }
00168 
00170     inline void setDeleted(bool d=true) SETTER(dlpRecAttrDeleted)
00171 
00173     inline void setSecret(bool d=true) SETTER(dlpRecAttrSecret)
00174 
00176     inline void setArchived(bool d=true) SETTER(dlpRecAttrArchived)
00177 
00179     inline void setModified(bool d=true) SETTER(dlpRecAttrDirty)
00180 
00181 #undef SETTER
00182 
00184     virtual QString textRepresentation() const;
00185 
00186 private:
00187     int fAttrib, fCat;
00188     recordid_t fID;
00189 } ;
00190 
00195 class KDE_EXPORT PilotRecord : public PilotRecordBase
00196 {
00197 public:
00204     PilotRecord(void* data, int length, int attrib, int cat, recordid_t uid) KDE_DEPRECATED;
00205 
00212     PilotRecord(pi_buffer_t *buf, int attrib, int cat, recordid_t uid) :
00213         PilotRecordBase(attrib,cat,uid),
00214         fData((char *)buf->data),
00215         fLen(buf->used),
00216         fBuffer(buf)
00217     {
00218         fAllocated++;
00219     }
00220 
00224     PilotRecord( pi_buffer_t *buf, const PilotRecordBase *entry ) :
00225         PilotRecordBase( entry ),
00226         fData((char *)buf->data),
00227         fLen(buf->used),
00228         fBuffer(buf)
00229     {
00230         fAllocated++;
00231     }
00232 
00234     virtual ~PilotRecord()
00235     {
00236         if (fBuffer)
00237         {
00238             pi_buffer_free(fBuffer);
00239         }
00240         else
00241         {
00242             delete [] fData;
00243         }
00244         fDeleted++;
00245     }
00246 
00248     PilotRecord(PilotRecord* orig);
00249 
00256     char *data() const
00257     {
00258         if (fBuffer)
00259         {
00260             return (char *)(fBuffer->data);
00261         }
00262         else
00263         {
00264             return fData;
00265         }
00266     }
00267 
00269     int size() const
00270     {
00271         if (fBuffer) return fBuffer->used; else
00272         return fLen;
00273     }
00274 
00276     const pi_buffer_t *buffer() const { return fBuffer; }
00277 
00281     void setData(pi_buffer_t *b)
00282     {
00283         if (fBuffer) { pi_buffer_free(fBuffer); }
00284         else { delete[] fData; } ;
00285         fData = (char *)b->data;
00286         fLen = b->used;
00287         fBuffer = b;
00288     }
00289 
00291     PilotRecord& operator=(PilotRecord& orig);
00292 
00294     void setData(const char* data, int len);
00295 
00297     virtual QString textRepresentation() const;
00298 
00299 private:
00300     char* fData;
00301     int   fLen;
00302     pi_buffer_t *fBuffer;
00303 
00304 public:
00310     static void allocationInfo();
00311 private:
00312     static int fAllocated,fDeleted;
00313 };
00314 
00315 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys