kpilot/lib

pilot.h

00001 #ifndef _KPILOT_PILOT_H
00002 #define _KPILOT_PILOT_H
00003 /* pilot.h          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 ** These are the base class structures that reside on the
00010 ** handheld device -- databases and their parts.
00011 */
00012 
00013 /*
00014 ** This program is free software; you can redistribute it and/or modify
00015 ** it under the terms of the GNU Lesser General Public License as published by
00016 ** the Free Software Foundation; either version 2.1 of the License, or
00017 ** (at your option) any later version.
00018 **
00019 ** This program is distributed in the hope that it will be useful,
00020 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00022 ** GNU Lesser General Public License for more details.
00023 **
00024 ** You should have received a copy of the GNU Lesser General Public License
00025 ** along with this program in a file called COPYING; if not, write to
00026 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00027 ** MA 02110-1301, USA.
00028 */
00029 
00030 /*
00031 ** Bug reports and questions can be sent to kde-pim@kde.org
00032 */
00033 
00034 class QTextCodec;
00035 
00036 class PilotDatabase;     // A database
00037 class PilotRecord;       // ... has records
00038 class PilotCategoryInfo; // ... and category information
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     // No size enum, doesn't make sense
00261     // No append, use pi_buffer_append
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 
KDE Home | KDE Accessibility Home | Description of Access Keys