pilotAddress.cc
00001
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 static const char *pilotadress_id =
00031 "$Id: pilotAddress.cc,v 1.4.4.3 2003/03/12 23:31:15 adridg Exp $";
00032
00033 #ifndef _KPILOT_OPTIONS_H
00034 #include "options.h"
00035 #endif
00036
00037 #include <stdlib.h>
00038 #include <assert.h>
00039
00040 #include <qtextcodec.h>
00041
00042 #ifndef _KPILOT_PILOTADDRESS_H
00043 #include "pilotAddress.h"
00044 #endif
00045
00046
00047 const int PilotAddress::APP_BUFFER_SIZE = 0xffff;
00048 #define MAXFIELDS 19
00049
00050 PilotAddress::PilotAddress(struct AddressAppInfo &appInfo,
00051 PilotRecord * rec) :
00052 PilotAppCategory(rec),
00053 fAppInfo(appInfo),
00054 fAddressInfo()
00055 {
00056 FUNCTIONSETUPL(4);
00057 if (rec) unpack_Address(&fAddressInfo, (unsigned char *) rec->getData(), rec->getLen());
00058 (void) pilotadress_id;
00059 }
00060
00061 PilotAddress::PilotAddress(struct AddressAppInfo &appInfo) :
00062 PilotAppCategory(),
00063 fAppInfo(appInfo)
00064 {
00065 FUNCTIONSETUPL(4);
00066 reset();
00067
00068
00069
00070 fAddressInfo.phoneLabel[0] = (int) eWork;
00071 fAddressInfo.phoneLabel[1] = (int) eHome;
00072 fAddressInfo.phoneLabel[2] = (int) eOther;
00073 fAddressInfo.phoneLabel[3] = (int) eMobile;
00074 fAddressInfo.phoneLabel[4] = (int) eEmail;
00075 }
00076
00077 PilotAddress::PilotAddress(const PilotAddress & copyFrom) :
00078 PilotAppCategory(copyFrom),
00079 fAppInfo(copyFrom.fAppInfo),
00080 fAddressInfo()
00081 {
00082 FUNCTIONSETUPL(4);
00083 _copyAddressInfo(copyFrom.fAddressInfo);
00084 }
00085
00086 PilotAddress & PilotAddress::operator = (const PilotAddress & copyFrom)
00087 {
00088 FUNCTIONSETUPL(4);
00089 PilotAppCategory::operator = (copyFrom);
00090 _copyAddressInfo(copyFrom.fAddressInfo);
00091 return *this;
00092 }
00093
00094 bool PilotAddress::operator==(const PilotAddress &compareTo)
00095 {
00096 FUNCTIONSETUPL(4);
00097
00098
00099
00100
00101 for (int i=0; i<MAXFIELDS; i++) {
00102
00103 if ( !getFieldP(i) && compareTo.getFieldP(i)) return false;
00104 if ( getFieldP(i) && !compareTo.getFieldP(i)) return false;
00105
00106 if ( (getFieldP(i) != compareTo.getFieldP(i)) && ( strcmp(getFieldP(i), compareTo.getFieldP(i)) ) ) return false;
00107 }
00108 return true;
00109 }
00110
00111
00112 void PilotAddress::_copyAddressInfo(const struct Address ©From)
00113 {
00114 FUNCTIONSETUPL(4);
00115 fAddressInfo.showPhone = copyFrom.showPhone;
00116
00117 for (int labelLp = 0; labelLp < 5; labelLp++)
00118 {
00119 fAddressInfo.phoneLabel[labelLp] =
00120 copyFrom.phoneLabel[labelLp];
00121 }
00122
00123 for (int entryLp = 0; entryLp < 19; entryLp++)
00124 {
00125 if (copyFrom.entry[entryLp])
00126 fAddressInfo.entry[entryLp] =
00127 qstrdup(copyFrom.entry[entryLp]);
00128 else
00129 fAddressInfo.entry[entryLp] = 0L;
00130 }
00131 }
00132
00133
00134 PilotAddress::~PilotAddress()
00135 {
00136 FUNCTIONSETUPL(4);
00137 free_Address(&fAddressInfo);
00138 }
00139
00140 bool PilotAddress::setCategory(const QString &label)
00141 {
00142 FUNCTIONSETUPL(4);
00143 for (int catId = 0; catId < 16; catId++)
00144 {
00145 QString aCat = codec()->toUnicode(fAppInfo.category.name[catId]);
00146
00147 if (label == aCat)
00148 {
00149 setCat(catId);
00150 return true;
00151 }
00152 else
00153
00154 if (aCat.isEmpty())
00155 {
00156 qstrncpy(fAppInfo.category.name[catId],
00157 codec()->fromUnicode(label), 16);
00158 setCat(catId);
00159 return true;
00160 }
00161 }
00162
00163 return false;
00164 }
00165
00166 QString PilotAddress::getCategoryLabel() const
00167 {
00168 return codec()->toUnicode(fAppInfo.category.name[getCat()]);
00169 }
00170
00171 QString PilotAddress::getField(int field) const
00172 {
00173 return codec()->toUnicode(fAddressInfo.entry[field]);
00174 }
00175
00176 int PilotAddress::_getNextEmptyPhoneSlot() const
00177 {
00178 FUNCTIONSETUPL(4);
00179 for (int phoneSlot = entryPhone1; phoneSlot <= entryPhone5;
00180 phoneSlot++)
00181 {
00182 QString phoneField = getField(phoneSlot);
00183
00184 if (phoneField.isEmpty())
00185 return phoneSlot;
00186 }
00187 return entryCustom4;
00188 }
00189
00190 void PilotAddress::setPhoneField(EPhoneType type, const QString &field,
00191 bool overflowCustom)
00192 {
00193 FUNCTIONSETUPL(4);
00194
00195
00196
00197 int appPhoneLabelNum = (int) type;
00198 QString fieldStr(field);
00199 int fieldSlot = _findPhoneFieldSlot(appPhoneLabelNum);
00200
00201 if (fieldSlot == -1)
00202 fieldSlot = _getNextEmptyPhoneSlot();
00203
00204
00205 if (fieldSlot == entryCustom4)
00206 {
00207 if (!fieldStr.isEmpty() && overflowCustom)
00208 {
00209 QString custom4Field = getField(entryCustom4);
00210 QString typeStr(
00211 codec()->toUnicode(fAppInfo.phoneLabels[appPhoneLabelNum]));
00212
00213 custom4Field += typeStr + CSL1(" ") + fieldStr;
00214 setField(entryCustom4, custom4Field);
00215 }
00216 }
00217 else
00218 {
00219 setField(fieldSlot, field);
00220 int labelIndex = fieldSlot - entryPhone1;
00221
00222 fAddressInfo.phoneLabel[labelIndex] = appPhoneLabelNum;
00223 }
00224 }
00225
00226 int PilotAddress::_findPhoneFieldSlot(int appTypeNum) const
00227 {
00228 FUNCTIONSETUPL(4);
00229 for (int index = 0; index < 5; index++)
00230 {
00231 if (fAddressInfo.phoneLabel[index] == appTypeNum)
00232 return index + entryPhone1;
00233 }
00234
00235 return -1;
00236 }
00237
00238 QString PilotAddress::getPhoneField(EPhoneType type, bool checkCustom4) const
00239 {
00240 FUNCTIONSETUPL(4);
00241
00242
00243
00244 int appTypeNum = (int) type;
00245
00246 int fieldSlot = _findPhoneFieldSlot(appTypeNum);
00247
00248 if (fieldSlot != -1)
00249 return getField(fieldSlot);
00250
00251
00252 if (!checkCustom4)
00253 return QString::null;
00254
00255
00256 QString typeToStr(codec()->toUnicode(fAppInfo.phoneLabels[appTypeNum]));
00257 QString customField(getField(entryCustom4));
00258 int foundField = customField.find(typeToStr);
00259
00260 if (foundField == -1)
00261 return QString::null;
00262
00263
00264 int startPos = foundField + typeToStr.length() + 1;
00265 int endPos = customField.find(' ', startPos);
00266
00267 if (endPos == -1)
00268 endPos = customField.length();
00269 QString field = customField.mid(startPos, endPos);
00270
00271 field = field.simplifyWhiteSpace();
00272
00273
00274 return field;
00275 }
00276
00277
00278 int PilotAddress::_getAppPhoneLabelNum(const QString & phoneType) const
00279 {
00280 FUNCTIONSETUPL(4);
00281 for (int index = 0; index < 8; index++)
00282 {
00283 if (phoneType == codec()->toUnicode(fAppInfo.phoneLabels[index]))
00284 return index;
00285 }
00286
00287 return -1;
00288 }
00289
00290 void PilotAddress::setShownPhone(EPhoneType type)
00291 {
00292 FUNCTIONSETUPL(4);
00293 int appPhoneLabelNum = (int) type;
00294 int fieldSlot = _findPhoneFieldSlot(appPhoneLabelNum);
00295
00296 if (fieldSlot == -1)
00297 {
00298 if (type != eHome)
00299 {
00300 setShownPhone(eHome);
00301 return;
00302 }
00303 fieldSlot = entryPhone1;
00304 }
00305 fAddressInfo.showPhone = fieldSlot - entryPhone1;
00306 }
00307
00308 void PilotAddress::setField(int field, const QString &text)
00309 {
00310 FUNCTIONSETUPL(4);
00311
00312
00313 if (fAddressInfo.entry[field])
00314 {
00315 free(fAddressInfo.entry[field]);
00316 }
00317 if (!text.isEmpty())
00318 {
00319 fAddressInfo.entry[field] = (char *) malloc(text.length() + 1);
00320 strcpy(fAddressInfo.entry[field], codec()->fromUnicode(text));
00321 }
00322 else
00323 {
00324 fAddressInfo.entry[field] = 0L;
00325 }
00326 }
00327
00328 void *PilotAddress::pack(void *buf, int *len)
00329 {
00330 FUNCTIONSETUPL(4);
00331 int i;
00332
00333 i = pack_Address(&fAddressInfo, (unsigned char *) buf, *len);
00334 *len = i;
00335 return buf;
00336 }
00337
This file is part of the documentation for kdelibs Version 3.1.5.