kpilot/lib
pilotAppInfo.h00001 #ifndef _KPILOT_PILOTAPPINFO_H
00002 #define _KPILOT_PILOTAPPINFO_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
|