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:
00062     PilotRecordBase(int attrib=0, int cat=0, recordid_t id=0) :
00063         fAttrib(attrib),fCat(0),fID(id)
00064     {
00065         setCategory(cat);
00066     }
00067 
00075     PilotRecordBase( const PilotRecordBase *b ) :
00076         fAttrib( b ? b->attributes() : 0 ),
00077         fCat( 0 ),
00078         fID( b ? b->id() : 0 )
00079     {
00080         if (b)
00081         {
00082             setCategory( b->category() );
00083         }
00084     }
00085 
00087     virtual ~PilotRecordBase() { } ;
00088 
00092     inline int attributes() const 
00093     {
00094         return fAttrib;
00095     }
00096 
00098     inline void  setAttributes(int attrib)
00099     {
00100         fAttrib = attrib;
00101     }
00102 
00106     inline int   category() const
00107     {
00108         return fCat;
00109     }
00110 
00116     inline void  setCategory(int cat)
00117     {
00118         if ( (cat<0) || (cat>=(int)Pilot::CATEGORY_COUNT))
00119         {
00120             cat=0;
00121         }
00122         fCat = cat;
00123     }
00124 
00135     bool setCategory(const struct CategoryAppInfo *info, const QString &label)
00136     {
00137         if (!info)
00138         {
00139             return false;
00140         }
00141 
00142         int cat = Pilot::findCategory( info, label, false );
00143         if ( (cat<0) || (cat>=(int)Pilot::CATEGORY_COUNT) )
00144         {
00145             return false;
00146         }
00147         else
00148         {
00149             setCategory( cat );
00150             return true;
00151         }
00152     }
00153 
00157     inline recordid_t id() const
00158     {
00159         return fID;
00160     }
00161 
00165     void setID(recordid_t id)
00166     {
00167         fID = id;
00168     }
00169 
00175     inline bool isDeleted() const
00176     {
00177         return fAttrib & dlpRecAttrDeleted;
00178     }
00179 
00183     inline bool isSecret() const
00184     {
00185         return fAttrib & dlpRecAttrSecret;
00186     }
00187 
00194     inline bool isArchived() const
00195     {
00196         return fAttrib & dlpRecAttrArchived;
00197     }
00198 
00202     inline bool isModified() const
00203     {
00204         return fAttrib & dlpRecAttrDirty;
00205     }
00206 
00207 #define SETTER(a) {\
00208         if (d) { fAttrib |= a; } \
00209         else   { fAttrib &= ~a; } }
00210 
00212     inline void setDeleted(bool d=true) SETTER(dlpRecAttrDeleted)
00213 
00215     inline void setSecret(bool d=true) SETTER(dlpRecAttrSecret)
00216 
00218     inline void setArchived(bool d=true) SETTER(dlpRecAttrArchived)
00219 
00221     inline void setModified(bool d=true) SETTER(dlpRecAttrDirty)
00222 
00223 #undef SETTER
00224 
00226     virtual QString textRepresentation() const;
00227 
00228 private:
00229     int fAttrib, fCat;
00230     recordid_t fID;
00231 } ;
00232 
00237 class KDE_EXPORT PilotRecord : public PilotRecordBase
00238 {
00239 public:
00246     PilotRecord(void* data, int length, int attrib, int cat, recordid_t uid) KDE_DEPRECATED;
00247 
00254     PilotRecord(pi_buffer_t *buf, int attrib, int cat, recordid_t uid) :
00255         PilotRecordBase(attrib,cat,uid),
00256         fData((char *)buf->data),
00257         fLen(buf->used),
00258         fBuffer(buf)
00259     {
00260         fAllocated++;
00261     }
00262 
00266     PilotRecord( pi_buffer_t *buf, const PilotRecordBase *entry ) :
00267         PilotRecordBase( entry ),
00268         fData((char *)buf->data),
00269         fLen(buf->used),
00270         fBuffer(buf)
00271     {
00272         fAllocated++;
00273     }
00274 
00276     virtual ~PilotRecord()
00277     {
00278         if (fBuffer)
00279         {
00280             pi_buffer_free(fBuffer);
00281         }
00282         else
00283         {
00284             delete [] fData;
00285         }
00286         fDeleted++;
00287     }
00288 
00290     PilotRecord(PilotRecord* orig);
00291 
00298     char *data() const
00299     {
00300         if (fBuffer)
00301         {
00302             return (char *)(fBuffer->data);
00303         }
00304         else
00305         {
00306             return fData;
00307         }
00308     }
00309 
00311     int size() const
00312     {
00313         if (fBuffer) return fBuffer->used; else
00314         return fLen;
00315     }
00316 
00318     const pi_buffer_t *buffer() const { return fBuffer; }
00319 
00323     void setData(pi_buffer_t *b)
00324     {
00325         if (fBuffer) { pi_buffer_free(fBuffer); }
00326         else { delete[] fData; } ;
00327         fData = (char *)b->data;
00328         fLen = b->used;
00329         fBuffer = b;
00330     }
00331 
00333     PilotRecord& operator=(PilotRecord& orig);
00334 
00336     void setData(const char* data, int len);
00337 
00339     virtual QString textRepresentation() const;
00340 
00341 private:
00342     char* fData;
00343     int   fLen;
00344     pi_buffer_t *fBuffer;
00345 
00346 public:
00352     static void allocationInfo();
00353 private:
00354     static int fAllocated,fDeleted;
00355 };
00356 
00357 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys