00001 #ifndef _ABBROWSER_CONDUIT_H
00002 #define _ABBROWSER_CONDUIT_H
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
00031
00032
00033 #include <qmap.h>
00034
00035 #include <kabc/addressbook.h>
00036 #include <kabc/addressee.h>
00037 #include <kabc/address.h>
00038
00039 #include <pilotAddress.h>
00040 #include <plugin.h>
00041 #include <kcrash.h>
00042
00043
00044 #define SYNCNONE 0
00045 #define SYNCMOD 1
00046 #define SYNCDEL 3
00047
00048 using namespace KABC;
00049 class ResolutionTable;
00050
00051 typedef QValueList<recordid_t> RecordIDList;
00052
00053 class AbbrowserConduit : public ConduitAction
00054 {
00055 Q_OBJECT
00056 public:
00057 AbbrowserConduit(KPilotDeviceLink *o,const char *n = 0L,
00058 const QStringList &a = QStringList() );
00059 virtual ~AbbrowserConduit();
00060
00061
00062
00063
00064 virtual bool exec();
00065 protected slots:
00066 void slotPalmRecToPC();
00067 void slotPCRecToPalm();
00068 void slotDeletedRecord();
00069 void slotDeleteUnsyncedPCRecords();
00070 void slotDeleteUnsyncedHHRecords();
00071 void slotCleanup();
00072
00073 private:
00074
00075
00076
00077
00078
00079
00080
00081 void readConfig();
00086 static bool isPilotStreetHome() { return fPilotStreetHome; };
00087 static bool isPilotFaxHome() { return fPilotFaxHome; };
00088 static bool isDeleted(const PilotAddress*addr);
00089 static bool isArchived(const PilotAddress*addr);
00090 static bool isArchived(const Addressee &addr);
00091 static bool makeArchived(Addressee &addr);
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 void _mapContactsToPilot( QMap < recordid_t, QString> &idContactMap) const;
00103
00104
00105 bool _prepare();
00106
00107
00108 bool _loadAddressBook();
00109
00110
00111 bool _saveAddressBook();
00112 void _getAppInfo();
00113 void _setAppInfo();
00114
00115
00116
00117
00118
00119
00120 static QString getCustomField(const Addressee &abEntry, const int index);
00121 static void setCustomField(Addressee &abEntry, int index, QString cust);
00122 static QString getOtherField(const Addressee&abEntry);
00123 static void setOtherField(Addressee&abEntry, QString nr);
00124 static PhoneNumber getFax(const Addressee &abEntry);
00125 static void setFax(Addressee &abEntry, QString fax);
00126 static KABC::Address getAddress(const Addressee &abEntry);
00127 QString _getCatForHH(const QStringList cats, const QString curr) const;
00128 void _setCategory(Addressee &abEntry, QString cat);
00129
00130
00131
00132
00133
00134
00135 #ifdef DEBUG
00136
00139 static void showAddressee(const Addressee &abAddress);
00143 static void showPilotAddress(PilotAddress *pilotAddress);
00144 #endif
00145 void showAdresses(Addressee &pcAddr, PilotAddress *backupAddr,
00146 PilotAddress *palmAddr);
00147
00148
00149
00150
00151
00152
00153
00154 bool syncAddressee(Addressee &pcAddr, PilotAddress*backupAddr,
00155 PilotAddress*palmAddr);
00156 bool _copyToHH(Addressee &pcAddr, PilotAddress*backupAddr,
00157 PilotAddress*palmAddr);
00158 bool _copyToPC(Addressee &pcAddr, PilotAddress*backupAddr,
00159 PilotAddress*palmAddr);
00160 bool _writeBackup(PilotAddress *backup);
00161 bool _deleteAddressee(Addressee &pcAddr, PilotAddress*backupAddr,
00162 PilotAddress*palmAddr);
00163
00164
00165
00166
00167
00168
00169 bool _savePalmAddr(PilotAddress *palmAddr, Addressee &pcAddr);
00170 bool _savePCAddr(Addressee &pcAddr, PilotAddress*backupAddr,
00171 PilotAddress*palmAddr);
00172
00173
00174
00175
00176
00177 int _compare(const QString & str1, const QString & str2) const;
00178 typedef enum eqFlagsType
00179 {
00180 eqFlagsName=0x1,
00181 eqFlagsAdress=0x2,
00182 eqFlagsPhones=0x4,
00183 eqFlagsNote=0x8,
00184 eqFlagsCategory=0x10,
00185 eqFlagsFlags=0x20,
00186 eqFlagsCustom=0x40,
00187 eqFlagsAll=0xFFFF,
00188 eqFlagsAlmostAll=eqFlagsName|eqFlagsAdress|eqFlagsPhones|eqFlagsNote|eqFlagsCustom
00189 };
00190 bool _equal(const PilotAddress *piAddress, const Addressee &abEntry,
00191 enum eqFlagsType flags=eqFlagsAll) const;
00192 void _copy(PilotAddress *toPilotAddr, Addressee &fromAbEntry);
00193 void _setPilotAddress(PilotAddress *toPilotAddr, const KABC::Address & abAddress);
00194 void _copyPhone(Addressee &toAbEntry, PhoneNumber phone, QString palmphone);
00195 void _copy(Addressee &toAbEntry, PilotAddress *fromPiAddr);
00196
00197
00198
00199
00205 QString _smartMergeString(const QString &pc, const QString & backup,
00206 const QString & palm, eConflictResolution confRes);
00207 bool _buildResolutionTable(ResolutionTable*tab, const Addressee &pcAddr,
00208 PilotAddress *backupAddr, PilotAddress *palmAddr);
00209 bool _applyResolutionTable(ResolutionTable*tab, Addressee &pcAddr,
00210 PilotAddress *backupAddr, PilotAddress *palmAddr);
00211 bool _smartMergeTable(ResolutionTable*tab);
00219 bool _smartMergeAddressee(Addressee &pcAddr, PilotAddress *backupAddr,
00220 PilotAddress *palmAddr);
00221 Addressee _findMatch(const PilotAddress & pilotAddress) const;
00222
00223
00224
00225
00226
00227
00228 struct AddressAppInfo fAddressAppInfo;
00229
00230
00231 static bool fPilotStreetHome, fPilotFaxHome;
00232 static bool fArchive;
00233 static enum ePilotOtherEnum
00234 {
00235 eOtherPhone,
00236 eAssistant,
00237 eBusinessFax,
00238 eCarPhone,
00239 eEmail2,
00240 eHomeFax,
00241 eTelex,
00242 eTTYTTDPhone
00243 } ePilotOther;
00244 int pilotindex;
00245 bool abChanged;
00246 static const QString appString;
00247 static const QString flagString;
00248 static const QString idString;
00250 QMap < recordid_t, QString> addresseeMap;
00251 RecordIDList syncedIds, allIds;
00252 static AddressBook* aBook;
00253 AddressBook::Iterator abiter;
00254
00255 Ticket*ticket;
00256
00257 QString fAbookFile;
00258 enum eAbookTypeEnum {
00259 eAbookResource=0,
00260 eAbookLocal
00261 } fAbookType;
00262
00263 static enum eCustomEnum {
00264 eCustomField,
00265 eCustomBirthdate,
00266 eCustomURL,
00267 eCustomIM
00268 } eCustom[4];
00269 static QString fCustomFmt;
00270
00271 } ;
00272
00273 #endif