00001
00002
00003
00004 #ifndef _SLZDTM_H_INCLUDED
00005 #define _SLZDTM_H_INCLUDED
00006
00007
00008 #include <qobject.h>
00009 #include <qstring.h>
00010 #include <qstringlist.h>
00011 #include <qdatetime.h>
00012
00013 class QWidget;
00014
00015 namespace SlZDtm {
00016
00017 #define SLZDTM_CARDID_32BIT
00018
00019 #if defined(SLZDTM_CARDID_32BIT)
00020 typedef ulong CardId;
00021 #else
00022 typedef ushort CardId;
00023 #endif
00024 typedef CardId IndexNo;
00025 typedef int CategoryId;
00026 typedef uchar DataType;
00027 typedef ulong APLID;
00028 typedef void **BoxHandle;
00029 typedef enum FileStatus {
00030 Ready,
00031 Retry,
00032 Fatal
00033 } FileStatus;
00034
00035 extern bool FilerCheckCategoryId(CategoryId);
00036 extern const QCString SjisString(const QString &s);
00037
00038 struct ItemData;
00039 class SlZDataManagerItemInfo : public QValueList<ItemData> {
00040 public:
00041 SlZDataManagerItemInfo();
00042 ~SlZDataManagerItemInfo();
00043 bool addTextItem(const char *itemName,const QString &title);
00044 bool addUcharItem(const char *itemName,const QString &title);
00045 bool addBitItem(const char *itemName,const QString &title);
00046 bool addUshortItem(const char *itemName,const QString &title,bool isGSearch=false);
00047 bool addUlongItem(const char *itemName,const QString &title);
00048 bool addColorItem(const char *itemName,const QString &title);
00049 bool addCategoryItem();
00050 bool addTimeItem(const char *itemName,const QString &title);
00051 bool addBinaryItem(const char *itemName,const QString &title);
00052 };
00053
00054 struct SortKey;
00055 class SlZDataManagerSortKey : public QValueList<SortKey> {
00056 public:
00057 SlZDataManagerSortKey();
00058 ~SlZDataManagerSortKey();
00059 void addSortKey(const char *itemName,bool isString=false,
00060 bool isAscendent=true);
00061 ulong createSortExp(char *buf,ulong bufLen) const;
00062 };
00063
00064 struct IndexFileInfo;
00065 class SlZDataManagerIndexInfo : public QValueList<IndexFileInfo> {
00066 public:
00067 SlZDataManagerIndexInfo();
00068 ~SlZDataManagerIndexInfo();
00069 void addIndexInfo(const char *indexFName,
00070 const char *searchExp,ulong searchExpLen,
00071 const char *sortExp,ulong sortExpLen);
00072 };
00073
00074 class SlZDataManagerPrivate;
00075 class SlZDataManager : public QObject {
00076 Q_OBJECT
00077 public:
00078 static bool createFile(const char *boxFName,
00079 const char *masterIdxFName,
00080 APLID aplId,
00081 bool isEasyMode,
00082 const SlZDataManagerItemInfo &items,
00083 const SlZDataManagerSortKey &keys,
00084 const SlZDataManagerIndexInfo &indexes);
00085 static bool createFile(const char *boxFName,
00086 const char *masterIdxFName,
00087 APLID aplId,
00088 bool isEasyMode,
00089 const SlZDataManagerItemInfo &items,
00090 const char *sortExp,int sortLen,
00091 const SlZDataManagerIndexInfo &indexes);
00092 static bool createZTime(void *zTime,const QDateTime &date);
00093 static bool createZTime(void *zTime,
00094 int y,int mon,int d,int h=0,int m=0,int sec=0);
00095 static void getAttrValues(uchar *mask,uchar *cond,uchar *flag);
00096 static bool deleteFile(const char *boxFName);
00097 static bool checkGarbageAlert(const char *boxFName,QWidget *parent=NULL);
00098
00099 static bool checkFile(const char *fName);
00100 static void checkDtmGlobal();
00101
00102 SlZDataManager(const char *boxFName,QWidget *parent=NULL,bool isReadOnly=false);
00103 ~SlZDataManager();
00104
00105
00106 enum DeleteMode {
00107
00108 OneCard,
00109
00110 CurrentIndex,
00111
00112 AllCard
00113 };
00114
00115
00116 enum FilterFor {
00117
00118 ForCurrentIndex,
00119
00120 ForMasterIndex,
00121
00122 ForSuspendedIndex
00123 };
00124 bool open(bool isReadOnly=false);
00125 bool close();
00126 bool isOpened();
00127 int count(const char *idxName=NULL);
00128 QString readItem(const char *itemName,CardId cardId=0);
00129 QDateTime readTimeItem(const char *itemName,CardId cardId=0,bool isUtc=false);
00130 QDate readDateItem(const char *itemName,CardId cardId=0);
00131 int readUcharItem(const char* itemName,CardId cardId=0);
00132 int readUshortItem(const char* itemName,CardId cardId=0);
00133 bool readUlongItem(const char* itemName,ulong *data,CardId cardId=0);
00134 QArray<int> readCategories(CardId cardId=0);
00135 bool first(const char *idxName=NULL);
00136 bool last(const char *idxName=NULL);
00137 bool next(CardId cardId=0,const char *idxName=NULL);
00138 bool prev(CardId cardId=0,const char *idxName=NULL);
00139 CardId firstCard(const char *idxName=NULL);
00140 CardId lastCard(const char *idxName=NULL);
00141 CardId nextCard(CardId cardId=0,const char *idxName=NULL);
00142 CardId prevCard(CardId cardId=0,const char *idxName=NULL);
00143 CardId cardId() const;
00144 CardId cardIdFromNumber(IndexNo number);
00145 IndexNo numberFromCardId(CardId cardId=0);
00146
00147 bool writeItem(const char* itemName,const char *data,ulong len);
00148 bool writeItem(const char* itemName,const QDateTime &time);
00149 bool writeItem(const char* itemName,const QDate &time);
00150 bool writeItem(const char* itemName,const QString &data);
00151
00152
00153 bool writeItem(const char* itemName,uchar value){
00154 return writeItem(itemName,(const char*)&value,1);
00155 }
00156
00157
00158 bool writeItem(const char* itemName,ushort value){
00159 return writeItem(itemName,(const char*)&value,2);
00160 }
00161
00162
00163 bool writeItem(const char* itemName,ulong value){
00164 return writeItem(itemName,(const char*)&value,4);
00165 }
00166 bool writeCurrentTime(const char* itemName,bool isUtc);
00167
00168
00169 bool clearItem(const char* itemName){
00170 return writeItem(itemName,(const char*)NULL,(ulong)0);
00171 }
00172 bool writeAttribute(CardId cardId,uchar bitData,bool isSet);
00173 bool startEditCard(CardId cardId);
00174 bool cancelEditCard();
00175 bool finishEditCard(CardId *cardId);
00176 bool editNewCard();
00177
00178 bool deleteCard(CardId *cardId,DeleteMode mode=OneCard);
00179
00180 bool sort(const char* itemName,bool isAscendent);
00181 bool sort(int keyItemNo,bool isAscendent);
00182 bool sort(const char *sortExp,int sortExpLen,bool isAscendent);
00183 void sort(bool isAscendent);
00184 bool search(CardId *cardId,const char *serCond,bool isNext,
00185 uchar attrMask,uchar attrCond,uchar attrFlag,
00186 const char *idxName=NULL);
00187 bool search(CardId *cardId,const char *serCond,bool isNext,
00188 const char *idxName=NULL);
00189 bool search(CardId *cardId,const QString &string,
00190 const char *item,uchar searchMode,bool isNext=true);
00191 bool filter(const char *searchExp,ulong searchExpLen,
00192 const char *sortExp,ulong sortExpLen,
00193 FilterFor mode,bool isSuspendIndex=false);
00194 bool unfilter(bool isResumeIndex=true);
00195 void killIdxResume();
00196 bool isFiltered() const;
00197 bool enableFilter(CategoryId categoryId);
00198 bool disableFilter(bool isIdxDelete);
00199 bool addCardToCtgr(CardId cardId,
00200 CategoryId categoryId,DeleteMode mode=OneCard,
00201 bool isAlert=false);
00202 bool removeCardFromCtgr(CardId cardId,
00203 CategoryId categoryId,DeleteMode mode=OneCard,
00204 bool isAlert=false);
00205 bool updateCategories(CardId cardId,QArray<int> ids,
00206 DeleteMode mode=OneCard,bool isAlert=false);
00207 DataType readItemType(const char *itemName) const;
00208 int nameToItemId(const char *itemName) const;
00209 int sortItem() const;
00210 bool ascendent() const;
00211 bool setCurrentIndex(const char* indexFName,bool isMasterIdx=false);
00212
00213 bool count(int *countNo,const char *serCond,CardId cardId,
00214 uchar attrMask,uchar attrCond,uchar attrFlag,
00215 const char *idxName=NULL);
00216 bool count(int *countNo,const char *serCond,CardId cardId,
00217 const char *idxName=NULL);
00218
00219 ulong garbageSize();
00220 CardId expectedCardId();
00221 CardId resumeCardId() const;
00222
00223 bool setInternalUtc(const char* itemName);
00224
00225 bool categoryRemoved(CategoryId id);
00226 static void updateForCategoryRemoved(CategoryId id);
00227
00228 QString current1stSortKey() const;
00229 BoxHandle boxHandle() const;
00230 const SlZDataManagerItemInfo items() const;
00231 void dumpIndexStatus() const;
00232 private slots:
00233 void systemMessage(const QCString &msg,const QByteArray &data);
00234 private:
00235 SlZDataManagerPrivate *p;
00236 };
00237
00238 }
00239 #endif