kpilot

pilotLocalDatabase.h

Go to the documentation of this file.
00001 #ifndef _KPILOT_PILOTLOCALDATABASE_H
00002 #define _KPILOT_PILOTLOCALDATABASE_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) 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 "pilotDatabase.h"
00033 
00043 class KDE_EXPORT PilotLocalDatabase : public PilotDatabase
00044 {
00045 public:
00057     PilotLocalDatabase( const QString& path,
00058         const QString& name, bool useDefaultPath=true);
00059 
00064     PilotLocalDatabase(const QString &name);
00065 
00066     virtual ~PilotLocalDatabase();
00067 
00072     virtual bool createDatabase(long creator=0,
00073         long type=0, int cardno=0, int flags=0, int version=0);
00074 
00075 
00076 
00080     virtual int deleteDatabase();
00081 
00082     // Reads the application block info
00083     virtual int readAppBlock(unsigned char* buffer, int maxLen);
00084     // Writes the application block info.
00085     virtual int writeAppBlock(unsigned char* buffer, int len);
00086     // returns the number of records in the database, 0 if not open
00087     virtual unsigned int recordCount() const;
00088     // Returns a QValueList of all record ids in the database.
00089     virtual QValueList<recordid_t> idList();
00090     // Reads a record from database by id, returns record
00091     virtual PilotRecord* readRecordById(recordid_t id);
00092     // Reads a record from database, returns the record
00093     virtual PilotRecord* readRecordByIndex(int index);
00094     // Reads the next record from database in category 'category'
00095     virtual PilotRecord* readNextRecInCategory(int category);
00105     const PilotRecord *findNextNewRecord();
00106 
00112     virtual PilotRecord* readNextModifiedRec(int *ind=0L);
00113     // Writes a new record to database (if 'id' == 0, none is assigned, either)
00114     virtual recordid_t writeRecord(PilotRecord* newRecord);
00120     virtual int deleteRecord(recordid_t id, bool all=false);
00121     // Resets all records in the database to not dirty.
00122     virtual int resetSyncFlags();
00123     // Resets next record index to beginning
00124     virtual int resetDBIndex();
00125     // Purges all Archived/Deleted records from Palm Pilot database
00126     virtual int cleanup();
00127 
00128 
00133     virtual recordid_t  updateID(recordid_t id);
00134 
00135 
00137     QString getDBName() const { return fDBName; }
00138 
00144     virtual QString dbPathName() const;
00145 
00149     int appInfoSize() const
00150         { if (isOpen()) return fAppLen; else return -1; } ;
00151     char *appInfo() { return fAppInfo; } ;
00152 
00153     const struct DBInfo &getDBInfo() const { return fDBInfo; }
00154     void setDBInfo(const struct DBInfo &dbi) {fDBInfo=dbi; }
00155 
00156     virtual DBType dbType() const;
00157 
00169     static bool infoFromFile( const QString &path, DBInfo *d );
00170 
00171 protected:
00172     // Changes any forward slashes to underscores
00173     void fixupDBName();
00174     virtual void openDatabase();
00175     virtual void closeDatabase();
00176 
00177 private:
00178     struct DBInfo fDBInfo;
00179     QString fPathName,fDBName;
00180     char*       fAppInfo;
00181     size_t      fAppLen;
00182 
00183     class Private;
00184     Private *d;
00185 
00186 public:
00192     static void setDBPath(const QString &);
00196     static const QString &getDBPath() { return *fPathBase; } ;
00197 private:
00198     static QString *fPathBase;
00199 };
00200 
00201 #endif