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 #if PILOT_LINK_IS(0,12,2)
00140     int(*unpack)(appinfo *, const unsigned char *, PI_SIZE_T),
00141     int(*pack)(const appinfo *, unsigned char *, PI_SIZE_T)
00142 #else
00143     int(*unpack)(appinfo *, unsigned char *, PI_SIZE_T),
00144     int(*pack)(appinfo *, unsigned char *, PI_SIZE_T)
00145 #endif
00146     >
00147 class PilotAppInfo : public PilotAppInfoBase
00148 {
00149 public:
00153     PilotAppInfo(PilotDatabase *d) : PilotAppInfoBase()
00154     {
00155         int appLen = Pilot::MAX_APPINFO_SIZE;
00156         unsigned char buffer[Pilot::MAX_APPINFO_SIZE];
00157 
00158         memset(&fInfo,0,sizeof(fInfo));
00159         if (d && d->isOpen())
00160         {
00161             appLen = d->readAppBlock(buffer,appLen);
00162             (*unpack)(&fInfo, buffer, appLen);
00163             // fInfo is just a struct, so we can point to it anyway.
00164             init(&fInfo.category,appLen);
00165         }
00166         else
00167         {
00168             delete fC;
00169             fC = 0L;
00170             fLen = 0;
00171         }
00172     } ;
00173 
00174     PilotAppInfo()
00175     {
00176         memset(&fInfo,0,sizeof(fInfo));
00177     }
00178 
00179 
00184     int writeTo(PilotDatabase *d)
00185     {
00186         unsigned char buffer[Pilot::MAX_APPINFO_SIZE];
00187         if (!d || !d->isOpen())
00188         {
00189             return -1;
00190         }
00191         int appLen = (*pack)(&fInfo, buffer, length());
00192         if (appLen > 0)
00193         {
00194             d->writeAppBlock(buffer,appLen);
00195         }
00196         return appLen;
00197     } ;
00198 
00202     appinfo *info() { return &fInfo; } ;
00206     const appinfo *info() const { return &fInfo; } ;
00207 
00208 protected:
00209     appinfo fInfo;
00210 } ;
00211 
00212 
00213 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys