kpilot/lib
pilotDatabase.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "options.h"
00031
00032 #include <time.h>
00033 #include <pi-appinfo.h>
00034
00035 #include <qstringlist.h>
00036 #include <qtextcodec.h>
00037
00038 #include <kglobal.h>
00039
00040 #include "pilotDatabase.h"
00041 #include "pilotAppCategory.h"
00042
00043 static int creationCount = 0;
00044 static QStringList *createdNames = 0L;
00045
00046 PilotDatabase::PilotDatabase(const QString &s) :
00047 fDBOpen(false),
00048 fName(s)
00049 {
00050 FUNCTIONSETUP;
00051 creationCount++;
00052 if (!createdNames)
00053 {
00054 createdNames = new QStringList();
00055 }
00056 createdNames->append(s.isEmpty() ? CSL1("<empty>") : s);
00057 }
00058
00059 PilotDatabase::~PilotDatabase()
00060 {
00061 FUNCTIONSETUP;
00062 creationCount--;
00063 if (createdNames)
00064 {
00065 createdNames->remove(fName.isEmpty() ? CSL1("<empty>") : fName);
00066 }
00067 }
00068
00069 int PilotDatabase::count()
00070 {
00071 FUNCTIONSETUP;
00072 #ifdef DEBUG
00073 DEBUGDAEMON << fname << ": " << creationCount << " databases." << endl;
00074 if (createdNames)
00075 {
00076 DEBUGDAEMON << fname << ": "
00077 << createdNames->join(CSL1(",")) << endl;
00078 }
00079 #endif
00080 return creationCount;
00081 }
00082
00083 RecordIDList PilotDatabase::idList()
00084 {
00085 RecordIDList l;
00086
00087 for (unsigned int i = 0 ; ; i++)
00088 {
00089 PilotRecord *r = readRecordByIndex(i);
00090 if (!r) break;
00091 l.append(r->id());
00092 delete r;
00093 }
00094
00095 return l;
00096 }
00097
00098 RecordIDList PilotDatabase::modifiedIDList()
00099 {
00100 RecordIDList l;
00101
00102 resetDBIndex();
00103 while(1)
00104 {
00105 PilotRecord *r = readNextModifiedRec();
00106 if (!r) break;
00107 l.append(r->id());
00108 delete r;
00109 }
00110
00111 return l;
00112 }
00113
00114 PilotAppInfoBase::PilotAppInfoBase(PilotDatabase *d) : fC(new struct CategoryAppInfo), fLen(0), fOwn(true)
00115 {
00116 FUNCTIONSETUP;
00117 int appLen = MAX_APPINFO_SIZE;
00118 unsigned char buffer[MAX_APPINFO_SIZE];
00119
00120 fLen = appLen = d->readAppBlock(buffer,appLen);
00121 unpack_CategoryAppInfo(fC, buffer, appLen);
00122 }
00123
00124 PilotAppInfoBase::~PilotAppInfoBase()
00125 {
00126 if (fOwn) delete fC;
00127 }
00128
00129
00130 int PilotAppInfoBase::findCategory(const QString &selectedCategory,
00131 bool unknownIsUnfiled, struct CategoryAppInfo *info)
00132 {
00133 FUNCTIONSETUP;
00134
00135 int currentCatID = -1;
00136 for (int i=0; i<PILOT_CATEGORY_MAX; i++)
00137 {
00138 if (!info->name[i][0]) continue;
00139 if (selectedCategory ==
00140 PilotAppCategory::codec()->toUnicode(info->name[i]))
00141 {
00142 currentCatID = i;
00143 break;
00144 }
00145 }
00146
00147 #ifdef DEBUG
00148 if (-1 == currentCatID)
00149 {
00150 DEBUGKPILOT << fname << ": Category name "
00151 << selectedCategory << " not found." << endl;
00152 }
00153 else
00154 {
00155 DEBUGKPILOT << fname << ": Matched category " << currentCatID << endl;
00156 }
00157 #endif
00158
00159 if ((currentCatID == -1) && unknownIsUnfiled)
00160 currentCatID = 0;
00161 return currentCatID;
00162 }
00163
00164 void PilotAppInfoBase::dumpCategories(const struct CategoryAppInfo &info)
00165 {
00166 #ifdef DEBUG
00167 FUNCTIONSETUP;
00168 DEBUGCONDUIT << fname << " lastUniqueId"
00169 << info.lastUniqueID << endl;
00170 for (int i = 0; i < PILOT_CATEGORY_MAX; i++)
00171 {
00172 if (!info.name[i][0]) continue;
00173 DEBUGCONDUIT << fname << ": " << i << " = "
00174 << info.ID[i] << " <"
00175 << info.name[i] << ">" << endl;
00176 }
00177 #else
00178 Q_UNUSED(info);
00179 #endif
00180 }
00181
00182 void PilotAppInfoBase::dump() const
00183 {
00184 dumpCategories(*categoryInfo());
00185 }
00186
00187
00188 QString PilotAppInfoBase::category(unsigned int i)
00189 {
00190 if (i>=PILOT_CATEGORY_MAX) return QString::null;
00191 return PilotAppCategory::codec()->toUnicode(categoryInfo()->name[i],PILOT_CATEGORY_SIZE-1);
00192 }
00193
00194 bool PilotAppInfoBase::setCategoryName(unsigned int i, const QString &s)
00195 {
00196 if (i>=PILOT_CATEGORY_MAX) return false;
00197 int len = PILOT_CATEGORY_SIZE - 1;
00198 QCString t = PilotAppCategory::codec()->fromUnicode(s,len);
00199 memset(categoryInfo()->name[i],0,PILOT_CATEGORY_SIZE);
00200 qstrncpy(categoryInfo()->name[i],t,PILOT_CATEGORY_SIZE);
00201 return true;
00202 }
00203
00204
|