kpilot

kabcRecord.h

Go to the documentation of this file.
00001 #ifndef _KPILOT_KABCRECORD_H
00002 #define _KPILOT_KABCRECORD_H
00003 /* KPilot
00004 **
00005 ** Copyright (C) 2000,2001 by Dan Pilone
00006 ** Copyright (C) 2002-2003 by Reinhold Kainhofer
00007 ** Copyright (C) 2007 by Adriaan de Groot <groot@kde.org>
00008 **
00009 ** The abbrowser conduit copies addresses from the Pilot's address book to
00010 ** the KDE addressbook maintained via the kabc library. This file
00011 ** deals with the actual copying of HH addresses to KABC addresses
00012 ** and back again.
00013 */
00014 
00015 /*
00016 ** This program is free software; you can redistribute it and/or modify
00017 ** it under the terms of the GNU General Public License as published by
00018 ** the Free Software Foundation; either version 2 of the License, or
00019 ** (at your option) any later version.
00020 **
00021 ** This program is distributed in the hope that it will be useful,
00022 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00024 ** GNU General Public License for more details.
00025 **
00026 ** You should have received a copy of the GNU General Public License
00027 ** along with this program in a file called COPYING; if not, write to
00028 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00029 ** MA 02110-1301, USA.
00030 */
00031 
00032 /*
00033 ** Bug reports and questions can be sent to kde-pim@kde.org.
00034 */
00035 
00036 #include <qvaluevector.h>
00037 
00038 #include <kabc/phonenumber.h>
00039 
00040 #include "pilotAddress.h"
00041 
00042 #define SYNCNONE 0
00043 #define SYNCMOD 1
00044 #define SYNCDEL 3
00045 
00046 namespace KABCSync
00047 {
00048     // This duplicates values from the config settings,
00049     // and must be kept in sync if new settings are added
00050     // -- there are compile time checks for this in the
00051     // abbrowser conduit code.
00052     enum MappingForOtherPhone {
00053         eOtherPhone=0,
00054         eAssistant,
00055         eBusinessFax,
00056         eCarPhone,
00057         eEmail2,
00058         eHomeFax,
00059         eTelex,
00060         eTTYTTDPhone
00061     } ;
00062 
00063     enum MappingForCustomField {
00064         eCustomField=0,
00065         eCustomBirthdate,
00066         eCustomURL,
00067         eCustomIM
00068     } ;
00069 
00070     class Settings
00071     {
00072     public:
00073         Settings();
00074         QString dateFormat() const
00075         {
00076             return fDateFormat;
00077         }
00078         void setDateFormat(const QString& s)
00079         {
00080             fDateFormat = s;
00081         }
00082 
00083         const QValueVector<int> &customMapping() const
00084         {
00085             return fCustomMapping;
00086         }
00087         void setCustomMapping(const QValueVector<int> &v)
00088         {
00089             if (v.count()==4)
00090             {
00091                 fCustomMapping = v;
00092             }
00093         }
00094         int custom(int index) const
00095         {
00096             if ( (index<0) || (index>3) )
00097             {
00098                 return 0;
00099             }
00100             else
00101             {
00102                 return fCustomMapping[index];
00103             }
00104         }
00105 
00106         int fieldForOtherPhone() const
00107         {
00108             return fOtherPhone;
00109         }
00110         void setFieldForOtherPhone(int v)
00111         {
00112             fOtherPhone = v;
00113         }
00114 
00115         bool preferHome() const
00116         {
00117             return fPreferHome;
00118         }
00119         void setPreferHome(bool v)
00120         {
00121             fPreferHome = v;
00122         }
00123 
00124         int faxTypeOnPC() const
00125         {
00126             return fFaxTypeOnPC;
00127         }
00128         void setFaxTypeOnPC(int v)
00129         {
00130             fFaxTypeOnPC = v;
00131         }
00132     private:
00133         QString fDateFormat;
00134         QValueVector<int> fCustomMapping;
00135         int fOtherPhone;
00136         bool fPreferHome;
00137         int fFaxTypeOnPC;
00138     } ;
00139 
00140 
00144     KABC::PhoneNumber::List getPhoneNumbers(const PilotAddress &a);
00145 
00152     void setPhoneNumbers(const PilotAddressInfo &info,
00153         PilotAddress &a,
00154         const KABC::PhoneNumber::List &list);
00155 
00168     unsigned int bestMatchedCategory(const QStringList &categorynames,
00169         const PilotAddressInfo &info,
00170         unsigned int category);
00171 
00173     inline QString bestMatchedCategoryName(const QStringList &categorynames,
00174         const PilotAddressInfo &info,
00175         unsigned int category)
00176     {
00177         return info.categoryName(
00178             bestMatchedCategory(categorynames, info, category));
00179     }
00180 
00184     void setCategory(KABC::Addressee &abEntry, const QString &cat);
00185 
00186     /* These are string identifiers used for custom properties in the addressees,
00187     *  used to store KPilot-specific settings.
00188     */
00189     const QString appString=CSL1("KPILOT"); 
00190     const QString flagString=CSL1("Flag"); 
00191     const QString idString=CSL1("RecordID"); 
00192 
00193 
00204     QString getFieldForHHCustom(
00205         unsigned int index,
00206         const KABC::Addressee &abEntry,
00207         const Settings &settings);
00208 
00215     void setFieldFromHHCustom(
00216         const unsigned int index,
00217         KABC::Addressee &abEntry,
00218         const QString &value,
00219         const Settings &settings);
00220 
00226     QString getFieldForHHOtherPhone(const KABC::Addressee &abEntry, const Settings &s);
00227 
00234     void setFieldFromHHOtherPhone(KABC::Addressee &abEntry, const QString &nr, const Settings &s);
00235 
00242     KABC::Address getAddress(const KABC::Addressee &abEntry, const Settings &);
00243 
00245     void setAddress(PilotAddress &toPilotAddr, const KABC::Address &abAddress);
00246 
00247     bool isArchived(const KABC::Addressee &);
00248     void makeArchived(KABC::Addressee &);
00249 
00250     void copy(PilotAddress &toPilotAddr,
00251         const KABC::Addressee &fromAbEntry,
00252         const PilotAddressInfo &appInfo,
00253         const Settings &syncSettings);
00254     void copy(KABC::Addressee &toAbEntry,
00255         const PilotAddress &fromPiAddr,
00256         const PilotAddressInfo &appInfo,
00257         const Settings &syncSettings);
00258 
00259     void showAddressee(const KABC::Addressee &);
00260 }
00261 
00262 #endif
00263