kpilot/lib

pilotAppInfo.h

00001 #ifndef _KPILOT_PILOTAPPINFO_H
00002 #define _KPILOT_PILOTAPPINFO_H
00003 /* pilotAppInfo.h           KPilot
00004 **
00005 ** Copyright (C) 2005-2006 Adriaan de Groot <groot@kde.org>
00006 **
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU Lesser General Public License as published by
00012 ** the Free Software Foundation; either version 2.1 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU Lesser General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU Lesser General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 ** MA 02110-1301, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 #include "pilotLinkVersion.h"
00031 
00032 #include "pilot.h"
00033 #include "pilotDatabase.h"
00034 
00050 class KDE_EXPORT PilotAppInfoBase
00051 {
00052 protected:
00057     PilotAppInfoBase() : fC(0L), fLen(0), fOwn(false) { } ;
00058 
00062     void init(struct CategoryAppInfo *c, int len)
00063     {
00064         fC = c;
00065         fLen = len ;
00066     } ;
00067 
00068 public:
00073     PilotAppInfoBase(PilotDatabase *d);
00074 
00076     virtual ~PilotAppInfoBase();
00077 
00082     struct CategoryAppInfo *categoryInfo()
00083     {
00084         return fC;
00085     } ;
00086 
00088     inline const struct CategoryAppInfo *categoryInfo() const
00089     {
00090         return fC;
00091     } ;
00092 
00094     inline PI_SIZE_T length() const
00095     {
00096         return fLen;
00097     } ;
00098 
00100     inline int findCategory(const QString &name, bool unknownIsUnfiled = false)
00101     {
00102         return Pilot::findCategory(fC,name,unknownIsUnfiled);
00103     } ;
00104 
00107     inline QString categoryName(unsigned int i) const
00108     {
00109         return Pilot::categoryName(fC,i);
00110     }
00111 
00116     bool setCategoryName(unsigned int i, const QString &s);
00117 
00119     inline void dump() const
00120     {
00121         Pilot::dumpCategories(fC);
00122     };
00123 
00124 protected:
00125     struct CategoryAppInfo *fC;
00126     PI_SIZE_T fLen;
00127 
00128     bool fOwn;
00129 } ;
00130 
00138 template <typename appinfo,
00139     int(*unpack)(appinfo *, unsigned char *, PI_SIZE_T),
00140     int(*pack)(appinfo *, unsigned char *, PI_SIZE_T)>
00141 class PilotAppInfo : public PilotAppInfoBase
00142 {
00143 public:
00147     PilotAppInfo(PilotDatabase *d) : PilotAppInfoBase()
00148     {
00149         int appLen = Pilot::MAX_APPINFO_SIZE;
00150         unsigned char buffer[Pilot::MAX_APPINFO_SIZE];
00151 
00152         memset(&fInfo,0,sizeof(fInfo));
00153         if (d && d->isOpen())
00154         {
00155             appLen = d->readAppBlock(buffer,appLen);
00156             (*unpack)(&fInfo, buffer, appLen);
00157             // fInfo is just a struct, so we can point to it anyway.
00158             init(&fInfo.category,appLen);
00159         }
00160         else
00161         {
00162             delete fC;
00163             fC = 0L;
00164             fLen = 0;
00165         }
00166     } ;
00167 
00168     PilotAppInfo()
00169     {
00170         memset(&fInfo,0,sizeof(fInfo));
00171     }
00172 
00173 
00178     int writeTo(PilotDatabase *d)
00179     {
00180         unsigned char buffer[Pilot::MAX_APPINFO_SIZE];
00181         if (!d || !d->isOpen())
00182         {
00183             return -1;
00184         }
00185         int appLen = (*pack)(&fInfo, buffer, length());
00186         if (appLen > 0)
00187         {
00188             d->writeAppBlock(buffer,appLen);
00189         }
00190         return appLen;
00191     } ;
00192 
00196     appinfo *info() { return &fInfo; } ;
00200     const appinfo *info() const { return &fInfo; } ;
00201 
00202 protected:
00203     appinfo fInfo;
00204 } ;
00205 
00206 
00207 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys