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 <pi-appinfo.h>
00033 #include <pi-buffer.h>
00034 #include <pi-dlp.h>
00035 
00036 #include <qstring.h>
00037 #include <qstringlist.h>
00038 #include <qvaluelist.h>
00039 
00040 #include "pilotLinkVersion.h"
00041 
00042 
00048 class PilotDatabase;     // A database
00049 class PilotRecord;       // ... has records
00050 class PilotCategoryInfo; // ... and category information
00051 
00052 
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 
00131     inline bool validCategory(int c)
00132     {
00133         if (c<0)
00134         {
00135             return false;
00136         }
00137         return ((unsigned int)c<CATEGORY_COUNT);
00138     }
00139 
00145     inline QString categoryName(const struct CategoryAppInfo *info, unsigned int i)
00146     {
00147         if ( ( i < CATEGORY_COUNT ) && ( info->name[i][0] ) )
00148         {
00149             return fromPilot( info->name[i], CATEGORY_SIZE );
00150         }
00151         else
00152         {
00153             return QString::null;
00154         }
00155     }
00156 
00162     inline QStringList categoryNames(const struct CategoryAppInfo *info)
00163     {
00164         QStringList l;
00165         if (!info)
00166         {
00167             return l;
00168         }
00169         for (unsigned int i=0; i<CATEGORY_COUNT; ++i)
00170         {
00171             QString s = categoryName(info,i);
00172             if (!s.isEmpty())
00173             {
00174                 l.append(s);
00175             }
00176         }
00177         return l;
00178     }
00179 
00194     int findCategory(const struct CategoryAppInfo *info, const QString &name, bool unknownIsUnfiled);
00195 
00214     int insertCategory(struct CategoryAppInfo *info, const QString &label, bool unknownIsUnfiled);
00215 
00220     static inline bool isResource(struct DBInfo *info)
00221     {
00222         return (info->flags & dlpDBFlagResource);
00223     }
00224 
00225 
00260 template<typename t> struct dlp { } ;
00261 
00262 template<> struct dlp<char>
00263 {
00264     enum { size = 1 };
00265 
00266     static void append(pi_buffer_t *b, char v)
00267     {
00268         pi_buffer_append(b,&v,size);
00269     }
00270 
00275     static char read(const pi_buffer_t *b, unsigned int &offset)
00276     {
00277         if (offset+size > b->used)
00278         {
00279             return 0;
00280         }
00281         char c = b->data[offset];
00282         offset+=size;
00283         return c;
00284     }
00285 } ;
00286 
00287 template<> struct dlp<short>
00288 {
00289     enum { size = 2 };
00290 
00291     static void append(pi_buffer_t *b, short v)
00292     {
00293         char buf[size];
00294         set_short(buf,v);
00295         pi_buffer_append(b,buf,size);
00296     }
00297 
00302     static int read(const pi_buffer_t *b, unsigned int &offset)
00303     {
00304         if (offset+size > b->used)
00305         {
00306             return -1;
00307         }
00308         else
00309         {
00310             int r = get_short(b->data + offset);
00311             offset+=size;
00312             return r;
00313         }
00314     }
00315 
00320     static int read(const unsigned char *b, unsigned int &offset)
00321     {
00322         int r = get_short(b+offset);
00323         offset+=size;
00324         return r;
00325     }
00326 } ;
00327 
00328 template<> struct dlp<long>
00329 {
00330     enum { size = 4 };
00331 
00332     static void append(pi_buffer_t *b, int v)
00333     {
00334         char buf[size];
00335         set_long(buf,v);
00336         pi_buffer_append(b,buf,size);
00337     }
00338 
00343     static int read(const pi_buffer_t *b, unsigned int &offset)
00344     {
00345         if (offset+size > b->used)
00346         {
00347             return -1;
00348         }
00349         else
00350         {
00351             int r = get_long(b->data + offset);
00352             offset+=size;
00353             return r;
00354         }
00355     }
00356 
00361     static int read(const unsigned char *b, unsigned int &offset)
00362     {
00363         int r = get_long(b+offset);
00364         offset+=size;
00365         return r;
00366     }
00367 } ;
00368 
00369 template<> struct dlp<char *>
00370 {
00371     // No size enum, doesn't make sense
00372     // No append, use pi_buffer_append
00379     static int read(const pi_buffer_t *b,
00380         unsigned int &offset,
00381         unsigned char *v,
00382         size_t s)
00383     {
00384         if ( s+offset > b->used )
00385         {
00386             s = b->allocated - offset;
00387         }
00388         memcpy(v, b->data + offset, s);
00389         offset+=s;
00390         return s;
00391     }
00392 
00394     inline static int read(const pi_buffer_t *b, unsigned int &offset, char *v, size_t s)
00395     {
00396         return read(b,offset,(unsigned char *)v,s);
00397     }
00398 } ;
00399 
00400 }
00401 
00402 #endif
00403 
KDE Home | KDE Accessibility Home | Description of Access Keys