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 <qstringlist.h>
00051 #include <qvaluelist.h>
00052
00061 namespace Pilot
00062 {
00064 static const int MAX_APPINFO_SIZE=8192;
00065
00067 static const unsigned int CATEGORY_COUNT=16;
00068
00070 static const unsigned int CATEGORY_SIZE=16;
00071
00073 static const int Unfiled = 0;
00074
00076 static const int MAX_RECORD_SIZE = 65535;
00077
00078 typedef QValueList<recordid_t> RecordIDList;
00079
00085 QString fromPilot( const char *c, int len );
00086
00093 QString fromPilot( const char *c );
00094
00100 int toPilot( const QString &s, char *buf, int len);
00101 int toPilot( const QString &s, unsigned char *buf, int len);
00102
00109 QCString toPilot( const QString &s );
00110
00118 bool setupPilotCodec(const QString &name);
00119
00121 QString codecName();
00122
00126 void dumpCategories(const struct CategoryAppInfo *info);
00127
00133 inline QString categoryName(const struct CategoryAppInfo *info, unsigned int i)
00134 {
00135 if ( ( i < CATEGORY_COUNT ) && ( info->name[i][0] ) )
00136 {
00137 return fromPilot( info->name[i], CATEGORY_SIZE );
00138 }
00139 else
00140 {
00141 return QString::null;
00142 }
00143 }
00144
00150 inline QStringList categoryNames(const struct CategoryAppInfo *info)
00151 {
00152 QStringList l;
00153 if (!info)
00154 {
00155 return l;
00156 }
00157 for (unsigned int i=0; i<CATEGORY_COUNT; ++i)
00158 {
00159 QString s = categoryName(info,i);
00160 if (!s.isEmpty())
00161 {
00162 l.append(s);
00163 }
00164 }
00165 return l;
00166 }
00167
00182 int findCategory(const struct CategoryAppInfo *info, const QString &name, bool unknownIsUnfiled);
00183
00202 int insertCategory(struct CategoryAppInfo *info, const QString &label, bool unknownIsUnfiled);
00203
00208 static inline bool isResource(struct DBInfo *info)
00209 {
00210 return (info->flags & dlpDBFlagResource);
00211 }
00212 }
00213
00214
00215 template<typename t> struct dlp { } ;
00216 template<> struct dlp<short>
00217 {
00218 enum { size = 2 };
00219
00220 static void append(pi_buffer_t *b, short v)
00221 {
00222 char buf[size];
00223 set_short(buf,v);
00224 pi_buffer_append(b,buf,size);
00225 }
00226
00227 static int read(const pi_buffer_t *b, unsigned int &offset)
00228 {
00229 if ((offset>=b->used) || (offset>=b->allocated))
00230 {
00231 return -1;
00232 }
00233 else
00234 {
00235 int r = get_short(b->data + offset);
00236 offset+=size;
00237 return r;
00238 }
00239 }
00240
00241 static int read(const unsigned char *b, unsigned int &offset)
00242 {
00243 int r = get_short(b+offset);
00244 offset+=size;
00245 return r;
00246 }
00247 } ;
00248 template<> struct dlp<long>
00249 {
00250 enum { size = 4 };
00251
00252 static void append(pi_buffer_t *b, int v)
00253 {
00254 char buf[size];
00255 set_long(buf,v);
00256 pi_buffer_append(b,buf,size);
00257 }
00258
00259 static int read(const pi_buffer_t *b, unsigned int &offset)
00260 {
00261 if ((offset>=b->used) || (offset>=b->allocated))
00262 {
00263 return -1;
00264 }
00265 else
00266 {
00267 int r = get_long(b->data + offset);
00268 offset+=size;
00269 return r;
00270 }
00271 }
00272
00273 static int read(const unsigned char *b, unsigned int &offset)
00274 {
00275 int r = get_long(b+offset);
00276 offset+=size;
00277 return r;
00278 }
00279 } ;
00280
00281 template<> struct dlp<char *>
00282 {
00283
00284
00285 static int read(const pi_buffer_t *b, unsigned int &offset, unsigned char *v, size_t s)
00286 {
00287 if ( s+offset > b->allocated )
00288 {
00289 s = b->allocated - offset;
00290 }
00291 memcpy(v, b->data + offset, s);
00292 offset+=s;
00293 return s;
00294 }
00295
00296 inline static int read(const pi_buffer_t *b, unsigned int &offset, char *v, size_t s)
00297 {
00298 return read(b,offset,(unsigned char *)v,s);
00299 }
00300 } ;
00301
00302 #endif
00303
|