kpilot

abbrowser-conduit.h

Go to the documentation of this file.
00001 #ifndef _ABBROWSER_CONDUIT_H
00002 #define _ABBROWSER_CONDUIT_H
00003 /* abbrowser-conduit.h                           KPilot
00004 **
00005 ** Copyright (C) 2000,2001 by Dan Pilone
00006 ** Copyright (C) 2000 Gregory Stern
00007 ** Copyright (C) 2002-2003 by Reinhold Kainhofer
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 General Public License as published by
00014 ** the Free Software Foundation; either version 2 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 General Public License for more details.
00021 **
00022 ** You should have received a copy of the GNU 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 
00033 #include <kabc/addressbook.h>
00034 
00035 #include <pilotAddress.h>
00036 #include <plugin.h>
00037 
00038 #include "kabcRecord.h"
00039 
00040 
00041 class ResolutionTable;
00042 namespace KABC
00043 {
00044 class Addressee;
00045 class Address;
00046 class PhoneNumber;
00047 class Ticket;
00048 }
00049 
00050 using namespace KABC;
00051 
00052 typedef QValueList<recordid_t> RecordIDList;
00053 
00054 class AbbrowserConduit : public ConduitAction
00055 {
00056 Q_OBJECT
00057 public:
00058     AbbrowserConduit(KPilotLink *o,const char *n = 0L,
00059         const QStringList &a = QStringList() );
00060     virtual ~AbbrowserConduit();
00061 
00062 /*********************************************************************
00063                 S Y N C   S T R U C T U R E
00064  *********************************************************************/
00065     virtual bool exec();
00066 protected slots:
00067     void slotPalmRecToPC();
00068     void slotPCRecToPalm();
00069     void slotDeletedRecord();
00070     void slotDeleteUnsyncedPCRecords();
00071     void slotDeleteUnsyncedHHRecords();
00072     void slotCleanup();
00073 
00074     void slotTestRecord();
00075 
00076 private:
00077 
00078     /********************************************************/
00079     /* Handle the configuration                             */
00080     /********************************************************/
00081 
00082     /* Read the global KPilot config file for settings
00083      * particular to the AbbrowserConduit conduit. */
00084     void readConfig();
00085 
00086     void showPilotAddress(const PilotAddress *pilotAddress);
00087     void showAddresses(
00088         const Addressee &pcAddr,
00089         const PilotAddress *backupAddr,
00090         const PilotAddress *palmAddr);
00091 
00092 
00093     /********************************************************/
00094     /* Loading and saving the addressbook and database      */
00095     /********************************************************/
00096 
00097 
00098     /* Given a list of contacts, creates the pilot id to contact key map
00099      * and a list of new contacts in O(n) time (single pass) */
00100     void _mapContactsToPilot( QMap < recordid_t, QString> &idContactMap);
00101     /* Do the preperations before doSync or doBackup.
00102      * Load contacts, set the pilot */
00103     bool _prepare();
00104     /* Load the contacts from the addressbook.
00105      * @return true if successful, false if not */
00106     bool _loadAddressBook();
00107     /* Save the contacts back to the addressbook.
00108      * @return true if successful, false if not */
00109     bool _saveAddressBook();
00110     void _getAppInfo();
00111     void _setAppInfo();
00112 
00113     void _cleanupAddressBookPointer();
00114 
00115 
00116 
00117 /*********************************************************************
00118               G E N E R A L   S Y N C   F U N C T I O N
00119          These functions modify the Handheld and the addressbook
00120  *********************************************************************/
00121     bool syncAddressee(Addressee &pcAddr, PilotAddress*backupAddr,
00122         PilotAddress*palmAddr);
00123     bool _copyToHH(Addressee &pcAddr, PilotAddress*backupAddr,
00124         PilotAddress*palmAddr);
00125     bool _copyToPC(Addressee &pcAddr, PilotAddress*backupAddr,
00126         PilotAddress*palmAddr);
00127     bool _writeBackup(PilotAddress *backup);
00128     bool _deleteAddressee(Addressee &pcAddr, PilotAddress*backupAddr,
00129         PilotAddress*palmAddr);
00130 
00131 
00132 /*********************************************************************
00133                  l o w - l e v e l   f u n c t i o n s   f o r
00134                    adding / removing palm/pc records
00135  *********************************************************************/
00136     bool _savePalmAddr(PilotAddress *palmAddr, Addressee &pcAddr);
00137     bool _savePCAddr(Addressee &pcAddr, PilotAddress*backupAddr,
00138         PilotAddress*palmAddr);
00139 
00140 
00141 /*********************************************************************
00142                    C O P Y   R E C O R D S
00143  *********************************************************************/
00144     inline bool _equal(const QString & str1, const QString & str2) const
00145     {
00146         return (str1.isEmpty() && str2.isEmpty()) || (str1 == str2);
00147     } ;
00148     typedef enum eqFlagsType
00149     {
00150         eqFlagsName=0x1,
00151         eqFlagsAdress=0x2,
00152         eqFlagsPhones=0x4,
00153         eqFlagsNote=0x8,
00154         eqFlagsCategory=0x10,
00155         eqFlagsFlags=0x20,
00156         eqFlagsCustom=0x40,
00157         eqFlagsAll=0xFFFF,
00158         eqFlagsAlmostAll=eqFlagsName|eqFlagsAdress|eqFlagsPhones|eqFlagsNote|eqFlagsCustom
00159     };
00160     bool _equal(const PilotAddress *piAddress, const Addressee &abEntry,
00161         enum eqFlagsType flags=eqFlagsAll) const;
00162 
00163 /*********************************************************************
00164  C O N F L I C T   R E S O L U T I O N   a n d   M E R G I N G
00165  *********************************************************************/
00171     QString _smartMergeString(const QString &pc, const QString & backup,
00172         const QString & palm, ConflictResolution confRes);
00173     bool _buildResolutionTable(ResolutionTable*tab, const Addressee &pcAddr,
00174         PilotAddress *backupAddr, PilotAddress *palmAddr);
00175     bool _applyResolutionTable(ResolutionTable*tab, Addressee &pcAddr,
00176         PilotAddress *backupAddr, PilotAddress *palmAddr);
00177     bool _smartMergeTable(ResolutionTable*tab);
00185     bool _smartMergeAddressee(Addressee &pcAddr, PilotAddress *backupAddr,
00186         PilotAddress *palmAddr);
00187     Addressee _findMatch(const PilotAddress & pilotAddress) const;
00188 
00189 
00190 /********************************************************/
00191 /*   D A T A   M E M B E R S ,   S E T T I N G S        */
00192 /********************************************************/
00193 
00194     AddressBook* aBook;
00195 
00196     PilotAddressInfo *fAddressAppInfo;
00197 
00198     KABCSync::Settings fSyncSettings;
00199 
00200     int pilotindex;
00201     bool abChanged;
00203     QMap < recordid_t, QString> addresseeMap;
00204     RecordIDList syncedIds, allIds;
00205     QString fABookFile;
00206     AddressBook::Iterator abiter;
00211     Ticket *fTicket;
00212     bool fCreatedBook;
00213 
00217     KABC::Resource *fBookResource;
00218 
00219 
00220 } ;
00221 
00222 #endif