kpilot/lib
pilot.h00001 #ifndef _KPILOT_PILOT_H
00002 #define _KPILOT_PILOT_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
00031
00032
00033
00034 class QTextCodec;
00035
00036 class PilotDatabase;
00037 class PilotRecord;
00038 class PilotCategoryInfo;
00039
00040 #include "pilotLinkVersion.h"
00041
00042 #include <stdio.h>
00043
00044 #include <pi-dlp.h>
00045 #include <pi-file.h>
00046 #include <pi-appinfo.h>
00047 #include <pi-buffer.h>
00048
00049 #include <qstring.h>
00050 #include <qvaluelist.h>
00051
00060 namespace Pilot
00061 {
00063 static const int MAX_APPINFO_SIZE=8192;
00064
00066 static const unsigned int CATEGORY_COUNT=16;
00067
00069 static const unsigned int CATEGORY_SIZE=16;
00070
00072 static const int Unfiled = 0;
00073
00075 static const int MAX_RECORD_SIZE = 65535;
00076
00077 typedef QValueList<recordid_t> RecordIDList;
00078
00084 QString fromPilot( const char *c, int len );
00085
00092 QString fromPilot( const char *c );
00093
00099 int toPilot( const QString &s, char *buf, int len);
00100 int toPilot( const QString &s, unsigned char *buf, int len);
00101
00108 QCString toPilot( const QString &s );
00109
00117 bool setupPilotCodec(const QString &name);
00118
00120 QString codecName();
00121
00125 void dumpCategories(const struct CategoryAppInfo *info);
00126
00132 inline QString categoryName(const struct CategoryAppInfo *info, unsigned int i)
00133 {
00134 if ( i < CATEGORY_COUNT )
00135 {
00136 return fromPilot( info->name[i], CATEGORY_SIZE );
00137 }
00138 else
00139 {
00140 return QString::null;
00141 }
00142 }
00143
00144
00159 int findCategory(const struct CategoryAppInfo *info, const QString &name, bool unknownIsUnfiled);
00160
00179 int insertCategory(struct CategoryAppInfo *info, const QString &label, bool unknownIsUnfiled);
00180
00185 static inline bool isResource(struct DBInfo *info)
00186 {
00187 return (info->flags & dlpDBFlagResource);
00188 }
00189 }
00190
00191
00192 template<typename t> struct dlp { } ;
00193 template<> struct dlp<short>
00194 {
00195 enum { size = 2 };
00196
00197 static void append(pi_buffer_t *b, short v)
00198 {
00199 char buf[size];
00200 set_short(buf,v);
00201 pi_buffer_append(b,buf,size);
00202 }
00203
00204 static int read(const pi_buffer_t *b, unsigned int &offset)
00205 {
00206 if ((offset>=b->used) || (offset>=b->allocated))
00207 {
00208 return -1;
00209 }
00210 else
00211 {
00212 int r = get_short(b->data + offset);
00213 offset+=size;
00214 return r;
00215 }
00216 }
00217
00218 static int read(const unsigned char *b, unsigned int &offset)
00219 {
00220 int r = get_short(b+offset);
00221 offset+=size;
00222 return r;
00223 }
00224 } ;
00225 template<> struct dlp<long>
00226 {
00227 enum { size = 4 };
00228
00229 static void append(pi_buffer_t *b, int v)
00230 {
00231 char buf[size];
00232 set_long(buf,v);
00233 pi_buffer_append(b,buf,size);
00234 }
00235
00236 static int read(const pi_buffer_t *b, unsigned int &offset)
00237 {
00238 if ((offset>=b->used) || (offset>=b->allocated))
00239 {
00240 return -1;
00241 }
00242 else
00243 {
00244 int r = get_long(b->data + offset);
00245 offset+=size;
00246 return r;
00247 }
00248 }
00249
00250 static int read(const unsigned char *b, unsigned int &offset)
00251 {
00252 int r = get_long(b+offset);
00253 offset+=size;
00254 return r;
00255 }
00256 } ;
00257
00258 template<> struct dlp<char *>
00259 {
00260
00261
00262 static int read(const pi_buffer_t *b, unsigned int &offset, unsigned char *v, size_t s)
00263 {
00264 if ( s+offset > b->allocated )
00265 {
00266 s = b->allocated - offset;
00267 }
00268 memcpy(v, b->data + offset, s);
00269 offset+=s;
00270 return s;
00271 }
00272
00273 inline static int read(const pi_buffer_t *b, unsigned int &offset, char *v, size_t s)
00274 {
00275 return read(b,offset,(unsigned char *)v,s);
00276 }
00277 } ;
00278
00279 #endif
00280
|