kpilot/lib

pilot.h

Go to the documentation of this file.
00001 #ifndef _KPILOT_PILOT_H
00002 #define _KPILOT_PILOT_H
00003 /* KPilot
00004 **
00005 ** Copyright (C) 1998-2001 by Dan Pilone
00006 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00007 ** Copyright (C) 2003-2006 Adriaan de Groot <groot@kde.org>
00008 **
00009 */
00010 
00011 /*
00012 ** This program is free software; you can redistribute it and/or modify
00013 ** it under the terms of the GNU Lesser General Public License as published by
00014 ** the Free Software Foundation; either version 2.1 of the License, or
00015 ** (at your option) any later version.
00016 **
00017 ** This program is distributed in the hope that it will be useful,
00018 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 ** GNU Lesser General Public License for more details.
00021 **
00022 ** You should have received a copy of the GNU Lesser General Public License
00023 ** along with this program in a file called COPYING; if not, write to
00024 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 ** MA 02110-1301, USA.
00026 */
00027 
00028 /*
00029 ** Bug reports and questions can be sent to kde-pim@kde.org
00030 */
00031 
00032 #include <sys/types.h>
00033 
00034 #include <pi-appinfo.h>
00035 #include <pi-buffer.h>
00036 #include <pi-dlp.h>
00037 
00038 #include <qstring.h>
00039 #include <qstringlist.h>
00040 #include <qvaluelist.h>
00041 
00042 #include "pilotLinkVersion.h"
00043 
00044 
00050 class PilotDatabase;     // A database
00051 class PilotRecord;       // ... has records
00052 class PilotCategoryInfo; // ... and category information
00053 
00054 
00062 namespace Pilot
00063 {
00065     static const int MAX_APPINFO_SIZE=8192;
00066 
00068     static const unsigned int CATEGORY_COUNT=16;
00069 
00071     static const unsigned int CATEGORY_SIZE=16;
00072 
00074     static const int Unfiled = 0;
00075 
00077     static const int MAX_RECORD_SIZE = 65535;
00078 
00079     typedef QValueList<recordid_t> RecordIDList;
00080 
00086     QString fromPilot( const char *c, int len );
00087 
00094     QString fromPilot( const char *c );
00095 
00101     int toPilot( const QString &s, char *buf, int len);
00102     int toPilot( const QString &s, unsigned char *buf, int len);
00103 
00110     QCString toPilot( const QString &s );
00111 
00119     bool setupPilotCodec(const QString &name);
00120 
00122     QString codecName();
00123 
00127     void dumpCategories(const struct CategoryAppInfo *info);
00128 
00133     inline bool validCategory(int c)
00134     {
00135         if (c<0)
00136         {
00137             return false;
00138         }
00139         return ((unsigned int)c<CATEGORY_COUNT);
00140     }
00141 
00147     inline QString categoryName(const struct CategoryAppInfo *info, unsigned int i)
00148     {
00149         if ( ( i < CATEGORY_COUNT ) && ( info->name[i][0] ) )
00150         {
00151             return fromPilot( info->name[i], CATEGORY_SIZE );
00152         }
00153         else
00154         {
00155             return QString::null;
00156         }
00157     }
00158 
00164     inline QStringList categoryNames(const struct CategoryAppInfo *info)
00165     {
00166         QStringList l;
00167         if (!info)
00168         {
00169             return l;
00170         }
00171         for (unsigned int i=0; i<CATEGORY_COUNT; ++i)
00172         {
00173             QString s = categoryName(info,i);
00174             if (!s.isEmpty())
00175             {
00176                 l.append(s);
00177             }
00178         }
00179         return l;
00180     }
00181 
00196     int findCategory(const struct CategoryAppInfo *info, const QString &name, bool unknownIsUnfiled);
00197 
00216     int insertCategory(struct CategoryAppInfo *info, const QString &label, bool unknownIsUnfiled);
00217 
00222     static inline bool isResource(struct DBInfo *info)
00223     {
00224         return (info->flags & dlpDBFlagResource);
00225     }
00226 
00227 
00262 template<typename t> struct dlp { } ;
00263 
00264 template<> struct dlp<char>
00265 {
00266     enum { size = 1 };
00267 
00268     static void append(pi_buffer_t *b, char v)
00269     {
00270         pi_buffer_append(b,&v,size);
00271     }
00272 
00277     static char read(const pi_buffer_t *b, unsigned int &offset)
00278     {
00279         if (offset+size > b->used)
00280         {
00281             return 0;
00282         }
00283         char c = b->data[offset];
00284         offset+=size;
00285         return c;
00286     }
00287 } ;
00288 
00289 template<> struct dlp<short>
00290 {
00291     enum { size = 2 };
00292 
00293     static void append(pi_buffer_t *b, short v)
00294     {
00295         char buf[size];
00296         set_short(buf,v);
00297         pi_buffer_append(b,buf,size);
00298     }
00299 
00304     static int read(const pi_buffer_t *b, unsigned int &offset)
00305     {
00306         if (offset+size > b->used)
00307         {
00308             return -1;
00309         }
00310         else
00311         {
00312             int r = get_short(b->data + offset);
00313             offset+=size;
00314             return r;
00315         }
00316     }
00317 
00322     static int read(const unsigned char *b, unsigned int &offset)
00323     {
00324         int r = get_short(b+offset);
00325         offset+=size;
00326         return r;
00327     }
00328 } ;
00329 
00330 template<> struct dlp<long>
00331 {
00332     enum { size = 4 };
00333 
00334     static void append(pi_buffer_t *b, int v)
00335     {
00336         char buf[size];
00337         set_long(buf,v);
00338         pi_buffer_append(b,buf,size);
00339     }
00340 
00345     static int read(const pi_buffer_t *b, unsigned int &offset)
00346     {
00347         if (offset+size > b->used)
00348         {
00349             return -1;
00350         }
00351         else
00352         {
00353             int r = get_long(b->data + offset);
00354             offset+=size;
00355             return r;
00356         }
00357     }
00358 
00363     static int read(const unsigned char *b, unsigned int &offset)
00364     {
00365         int r = get_long(b+offset);
00366         offset+=size;
00367         return r;
00368     }
00369 } ;
00370 
00371 template<> struct dlp<char *>
00372 {
00373     // No size enum, doesn't make sense
00374     // No append, use pi_buffer_append
00381     static int read(const pi_buffer_t *b,
00382         unsigned int &offset,
00383         unsigned char *v,
00384         size_t s)
00385     {
00386         if ( s+offset > b->used )
00387         {
00388             s = b->allocated - offset;
00389         }
00390         memcpy(v, b->data + offset, s);
00391         offset+=s;
00392         return s;
00393     }
00394 
00396     inline static int read(const pi_buffer_t *b, unsigned int &offset, char *v, size_t s)
00397     {
00398         return read(b,offset,(unsigned char *)v,s);
00399     }
00400 } ;
00401 
00402 }
00403 
00404 #endif
00405 
KDE Home | KDE Accessibility Home | Description of Access Keys