Changeset 2277

Show
Ignore:
Timestamp:
07/06/07 07:24:53 (1 year ago)
Author:
abaumann
Message:

First pass at cleaning up the kdepim plugin:

  • create common class for all data sources (datasource.{cpp,h})
  • put sink creation and callback functions here, removing all the
    call-passing that was in src/kdepim_impl.cpp and src/kdepim_sync.cpp
  • convert existing code to use this class and do some other cleanup

This works for me, but has the same limited support as before (ie. only
the address book is implemented). The next step is to port the other
data sources to the new class model.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/kdepim/Makefile.am

    r2049 r2277  
    4747#       dcopidl2cpp KNotesIface.kidl 
    4848 
    49 dist_kdepim_lib_la_SOURCES = src/kdepim_impl.cpp src/kaddrbook.cpp 
    50 #       src/kdepim_impl.cpp \ 
    51 #       src/kcal.cpp \ 
    52 #       src/knotes.cpp \ 
    53 #       src/kaddrbook.cpp  
     49dist_kdepim_lib_la_SOURCES = \ 
     50        src/kdepim_impl.cpp \ 
     51        src/datasource.cpp \ 
     52        src/kaddrbook.cpp 
     53#       src/kcal.cpp 
     54#       src/knotes.cpp 
    5455#nodist_kdepim_lib_la_SOURCES = KNotesIface_stub.cpp 
    5556kdepim_lib_la_CXXFLAGS = -DPLUGINDIR=\"$(plugindir)\" -DKDEPIM_LIBDIR=\"$(plugindir)\" -Wall 
  • plugins/kdepim/src/kaddrbook.cpp

    r1767 r2277  
    3131#include <qdeepcopy.h> 
    3232 
    33 KContactDataSource::KContactDataSource(OSyncHashTable *hashtable) : hashtable(hashtable) 
    34 
    35         connected = false; 
     33bool KContactDataSource::initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) 
     34
     35        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, plugin, info); 
     36 
     37        if (!OSyncDataSource::initialize(plugin, info, error)) { 
     38                osync_trace(TRACE_EXIT_ERROR, "%s", __PRETTY_FUNCTION__); 
     39                return false; 
     40        } 
     41 
     42        osync_objtype_sink_add_objformat(sink, "vcard30"); 
     43 
     44        osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 
     45        return true; 
    3646} 
    3747 
     
    5565} 
    5666 
    57 bool KContactDataSource::connect(OSyncPluginInfo *info, OSyncContext *ctx) 
    58 { 
    59         osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, info, ctx); 
     67void KContactDataSource::connect(OSyncPluginInfo *info, OSyncContext *ctx) 
     68{ 
     69        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, info, ctx); 
    6070 
    6171        DCOPClient *dcopc = KApplication::kApplication()->dcopClient(); 
    6272        if (!dcopc) { 
    6373                osync_context_report_error(ctx, OSYNC_ERROR_INITIALIZATION, "Unable to initialize dcop client"); 
    64                 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to initialize dcop client", __func__); 
    65                 return false
     74                osync_trace(TRACE_EXIT_ERROR, "%s: Unable to initialize dcop client", __PRETTY_FUNCTION__); 
     75                return
    6676        } 
    6777 
     
    7181        //is running 
    7282        if (dcopc->isApplicationRegistered("kaddressbook")) { 
    73                 osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, "KAddressBook is running. Please finish it"); 
    74                 osync_trace(TRACE_EXIT_ERROR, "%s: KAddressBook is running", __func__); 
    75                 return false
     83                osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, "KAddressBook is running. Please terminate it"); 
     84                osync_trace(TRACE_EXIT_ERROR, "%s: KAddressBook is running", __PRETTY_FUNCTION__); 
     85                return
    7686        } 
    7787 
    7888        //get a handle to the standard KDE addressbook 
    7989        addressbookptr = KABC::StdAddressBook::self(); 
    80  
    81         OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); 
    82  
    83         //Detection mechanismn if this is the first sync 
    84         QString anchorpath = QString("%1/anchor.db").arg(osync_plugin_info_get_configdir(info)); 
    85         if (!osync_anchor_compare(anchorpath, "contact", "true")) { 
    86                 osync_trace(TRACE_INTERNAL, "Setting slow-sync contact"); 
    87                 osync_objtype_sink_set_slowsync(sink, TRUE); 
    88         } 
    89  
    90         connected = true; 
    91         osync_trace(TRACE_EXIT, "%s", __func__); 
    92         return TRUE; 
    93 
    94  
    95 bool KContactDataSource::disconnect(OSyncPluginInfo *info, OSyncContext *ctx) 
    96 
    97         osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, info, ctx); 
     90         
     91        OSyncDataSource::connect(info, ctx); 
     92         
     93        osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 
     94        return; 
     95
     96 
     97void KContactDataSource::disconnect(OSyncPluginInfo *info, OSyncContext *ctx) 
     98
     99        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, info, ctx); 
    98100 
    99101        KABC::Ticket *ticket = addressbookptr->requestSaveTicket(); 
    100102        if ( !ticket ) { 
    101103                osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Unable to get save ticket"); 
    102                 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to get save ticket", __func__); 
    103                 return FALSE
     104                osync_trace(TRACE_EXIT_ERROR, "%s: Unable to get save ticket", __PRETTY_FUNCTION__); 
     105                return
    104106        } 
    105107 
    106108        if ( !addressbookptr->save( ticket ) ) { 
    107109                osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Unable to use ticket"); 
    108                 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to save", __func__); 
    109                 return FALSE; 
    110         } 
    111  
    112         connected = false; 
    113         osync_trace(TRACE_EXIT, "%s", __func__); 
    114         return TRUE; 
    115 
    116  
    117  
    118 bool KContactDataSource::contact_get_changeinfo(OSyncPluginInfo *info, OSyncContext *ctx) 
    119 
    120         osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, info, ctx); 
     110                osync_trace(TRACE_EXIT_ERROR, "%s: Unable to save", __PRETTY_FUNCTION__); 
     111                return; 
     112        } 
     113 
     114        osync_context_report_success(ctx); 
     115        osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 
     116        return; 
     117
     118 
     119void KContactDataSource::get_changes(OSyncPluginInfo *info, OSyncContext *ctx) 
     120
     121        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, info, ctx); 
    121122 
    122123        OSyncError *error = NULL; 
     
    131132        if (!addressbookptr->load()) { 
    132133                osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Couldn't reload KDE addressbook"); 
    133                 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to reload addrbook", __func__); 
    134                 return false
     134                osync_trace(TRACE_EXIT_ERROR, "%s: Unable to reload addrbook", __PRETTY_FUNCTION__); 
     135                return
    135136        } 
    136137 
     
    222223        g_free(uids); 
    223224 
    224         osync_trace(TRACE_EXIT, "%s", __func__); 
    225         return true; 
     225        osync_context_report_success(ctx); 
     226        osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 
     227        return; 
    226228} 
    227229 
     
    235237bool KContactDataSource::__vcard_access(OSyncContext *ctx, OSyncChange *chg) 
    236238{ 
    237         osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, chg); 
     239        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, ctx, chg); 
    238240        KABC::VCardConverter converter; 
    239241 
     
    285287                        if (uid.isEmpty()) { 
    286288                                osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Trying to delete entry with empty UID"); 
    287                                 osync_trace(TRACE_EXIT_ERROR, "%s: Trying to delete but uid is empty", __func__); 
     289                                osync_trace(TRACE_EXIT_ERROR, "%s: Trying to delete but uid is empty", __PRETTY_FUNCTION__); 
    288290                                return FALSE; 
    289291                        } 
     
    300302                default: { 
    301303                        osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "Operation not supported"); 
    302                         osync_trace(TRACE_EXIT_ERROR, "%s: Operation not supported", __func__); 
     304                        osync_trace(TRACE_EXIT_ERROR, "%s: Operation not supported", __PRETTY_FUNCTION__); 
    303305                        return FALSE; 
    304306                } 
    305307        } 
    306308 
    307         osync_trace(TRACE_EXIT, "%s", __func__); 
     309        osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 
    308310        return TRUE; 
    309311} 
    310312 
    311 bool KContactDataSource::vcard_access(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg) 
     313bool KContactDataSource::read(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg) 
    312314{ 
    313315        if (!__vcard_access(ctx, chg)) 
     
    318320} 
    319321 
    320 bool KContactDataSource::vcard_commit_change(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg) 
    321 
    322         if ( !__vcard_access(ctx, chg) ) 
    323                 return false; 
    324  
    325         osync_context_report_success(ctx); 
    326         return true; 
    327 
     322void KContactDataSource::commit(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg) 
     323
     324        if (__vcard_access(ctx, chg)) 
     325                osync_context_report_success(ctx); 
     326        return; 
     327
  • plugins/kdepim/src/kaddrbook.h

    r1764 r2277  
    2929 
    3030#include "osyncbase.h" 
     31#include "datasource.h" 
    3132 
    32 class KContactDataSource 
     33class KContactDataSource : public OSyncDataSource 
    3334{ 
    3435        private: 
    3536                KABC::AddressBook* addressbookptr; 
    36                 OSyncHashTable *hashtable; 
    3737 
    3838                bool __vcard_access(OSyncContext *ctx, OSyncChange *chg); 
    39  
     39                QString calc_hash(KABC::Addressee &e); 
    4040 
    4141        public: 
    42                 KContactDataSource(OSyncHashTable *hashtable)
     42                KContactDataSource() : OSyncDataSource("contact") {}
    4343 
    44                 QString calc_hash(KABC::Addressee &e); 
    45                 bool connect(OSyncPluginInfo *info, OSyncContext *ctx); 
    46                 bool disconnect(OSyncPluginInfo *info, OSyncContext *ctx); 
    47                 bool contact_get_changeinfo(OSyncPluginInfo *info, OSyncContext *ctx); 
    48                 bool vcard_access(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg); 
    49                 bool vcard_commit_change(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg); 
    50                 bool connected; 
     44                virtual bool initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error); 
     45                virtual void connect(OSyncPluginInfo *info, OSyncContext *ctx); 
     46                virtual void disconnect(OSyncPluginInfo *info, OSyncContext *ctx); 
     47                virtual void get_changes(OSyncPluginInfo *info, OSyncContext *ctx); 
     48                virtual bool read(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg); 
     49                virtual void commit(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg); 
    5150}; 
    5251 
  • plugins/kdepim/src/kdepim_impl.cpp

    r1765 r2277  
    2525 */ 
    2626 
    27  
    28  
    29  
    3027#include <libkcal/resourcecalendar.h> 
    3128#include <kinstance.h> 
     
    3633 
    3734#include <qsignal.h> 
    38  
    39  
    4035#include <qfile.h> 
    4136#include <dlfcn.h> 
     
    4540//#include "kcal.h" 
    4641//#include "knotes.h" 
    47 static bool sentinal = false; 
     42 
     43static bool sentinel = false; 
    4844 
    4945class KdePluginImplementation: public KdePluginImplementationBase 
    5046{ 
    51         public: 
    52                 KdePluginImplementation(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) 
    53                                 : mApplication( 0 ), 
    54                                 mNewApplication( false ) 
    55                 {} 
     47        private: 
     48                KContactDataSource *kaddrbook; 
     49                //KCalDataSource *kcal; 
     50 
     51                KApplication *application; 
     52                bool newApplication; 
    5653 
    5754                void initKDE() 
    5855                { 
    59                         if (sentinal) 
     56                        if (sentinel) 
    6057                                return; 
    6158 
     
    6360                            "libopensync-kdepim-plugin",         // internal program name 
    6461                            "OpenSync-KDE-plugin",               // displayable program name. 
    65                             "0.2",                               // version string 
     62                            "0.3",                               // version string 
    6663                            "OpenSync KDEPIM plugin",            // short porgram description 
    6764                            KAboutData::License_GPL,             // license type 
     
    7370 
    7471                        KCmdLineArgs::init( &aboutData ); 
    75                         if ( kapp ) 
    76                                 mApplication = kapp; 
    77                         else { 
    78                                 mApplication = new KApplication( true, true ); 
    79                                 mNewApplication = true; 
     72                        if ( kapp ) { 
     73                                application = kapp; 
     74                                newApplication = false; 
     75                        } else { 
     76                                application = new KApplication( true, true ); 
     77                                newApplication = true; 
    8078                        } 
    8179 
    82                         sentinal = true; 
     80                        sentinel = true; 
    8381                } 
    8482 
    85                 bool init(OSyncPluginInfo *info, OSyncError **error) 
     83        public: 
     84                KdePluginImplementation() : application(NULL), newApplication(false) 
    8685                { 
    87                         osync_trace(TRACE_ENTRY, "%s(%p)", __func__, error); 
     86                        kaddrbook = new KContactDataSource(); 
     87                        //kcal = new KCalDataSource(); 
     88                } 
     89 
     90                bool initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) 
     91                { 
     92                        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, plugin, info); 
    8893 
    8994                        initKDE(); 
    9095 
    91                         contact_sink = osync_objtype_sink_new("contact", error); 
     96                        if (!kaddrbook->initialize(plugin, info, error)) 
     97                                goto error; 
     98                         
     99                        //if (!kcal->initialize(plugin, info, error)) 
     100                        //      goto error; 
    92101 
    93                         QString tablepath = QString("%1/hashtable.db").arg(osync_plugin_info_get_configdir(info)); 
    94                         mHashtable = osync_hashtable_new(tablepath, osync_objtype_sink_get_name(contact_sink), error)
     102                        osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); 
     103                        return true
    95104 
    96                         mKaddrbook = new KContactDataSource(mHashtable); 
    97  
    98                         osync_trace(TRACE_EXIT, "%s", __func__); 
    99                         return true; 
     105                error: 
     106                        osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(error)); 
     107                        return false; 
    100108                } 
    101109 
    102110                virtual ~KdePluginImplementation() 
    103111                { 
    104                         if ( mNewApplication ) { 
    105                                 delete mApplication; 
    106                                 mApplication = 0
     112                        if ( newApplication ) { 
     113                                delete application; 
     114                                application = NULL
    107115                        } 
    108  
    109                         if ( mHashtable ) 
    110                                 osync_hashtable_free(mHashtable); 
    111116                } 
    112  
    113                 virtual void connect(OSyncPluginInfo *info, OSyncContext *ctx) 
    114                 { 
    115                         osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); 
    116  
    117 //                      OSyncError *error = NULL; 
    118  
    119                         if (mKaddrbook && \ 
    120                                 !mKaddrbook->connect(info, ctx)) { 
    121                                 osync_trace(TRACE_EXIT_ERROR, "%s: Unable to open addressbook", __func__); 
    122                                 return; 
    123                         } 
    124  
    125                         osync_context_report_success(ctx); 
    126                         osync_trace(TRACE_EXIT, "%s", __func__); 
    127                 } 
    128  
    129                 virtual void disconnect(OSyncPluginInfo *info, OSyncContext *ctx) 
    130                 { 
    131                         if (mKaddrbook && mKaddrbook->connected && !mKaddrbook->disconnect(info, ctx)) 
    132                                 return; 
    133  
    134                         osync_context_report_success(ctx); 
    135                 } 
    136  
    137  
    138                 virtual void sync_done(OSyncPluginInfo *info, OSyncContext *ctx) 
    139                 { 
    140                         if (mKaddrbook && mKaddrbook->connected) 
    141                         { 
    142                                 QString anchorpath = QString("%1/anchor.db").arg(osync_plugin_info_get_configdir(info)); 
    143                                 osync_anchor_update(anchorpath, "contact", "true"); 
    144                         } 
    145                         osync_context_report_success(ctx); 
    146                 } 
    147  
    148                 virtual void get_changeinfo(OSyncPluginInfo *info, OSyncContext *ctx) 
    149                 { 
    150                         if (mKaddrbook && mKaddrbook->connected && !mKaddrbook->contact_get_changeinfo(info, ctx)) 
    151                                 return; 
    152                         osync_context_report_success(ctx); 
    153                 } 
    154  
    155                 virtual bool vcard_access(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg) 
    156                 { 
    157                         if (mKaddrbook) 
    158                                 return mKaddrbook->vcard_access(info, ctx, chg); 
    159                         else { 
    160                                 osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No addressbook loaded"); 
    161                                 return false; 
    162                         } 
    163                         return true; 
    164                 } 
    165  
    166                 virtual bool vcard_commit_change(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg) 
    167                 { 
    168                         if (mKaddrbook) 
    169                                 return mKaddrbook->vcard_commit_change(info, ctx, chg); 
    170                         else { 
    171                                 osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No addressbook loaded"); 
    172                                 return false; 
    173                         } 
    174                         return true; 
    175                 } 
    176         private: 
    177                 KContactDataSource *mKaddrbook; 
    178  
    179                 OSyncHashTable *mHashtable; 
    180                 OSyncMember *mMember; 
    181  
    182                 KApplication *mApplication; 
    183                 bool mNewApplication; 
    184117}; 
    185118 
     
    187120extern "C" 
    188121{ 
    189  
    190122        KdePluginImplementationBase *new_KdePluginImplementation(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) { 
    191                 KdePluginImplementation *imp = new KdePluginImplementation(plugin, info, error); 
    192                 if (!imp->init(info, error)) { 
     123                KdePluginImplementation *imp = new KdePluginImplementation(); 
     124                if (!imp->initialize(plugin, info, error)) { 
    193125                        delete imp; 
    194                         return 0
     126                        return NULL
    195127                } 
    196128 
    197129                return imp; 
    198130        } 
    199  
    200131} 
  • plugins/kdepim/src/kdepim_sync.cpp

    r1765 r2277  
    3030#include "osyncbase.h" 
    3131 
    32  
    33 static void kde_finalize(void *userdata) 
     32extern "C" 
    3433{ 
    35         osync_trace(TRACE_ENTRY, "%s(%p)", __func__, userdata); 
    36         KdePluginImplementationBase *impl_object = (KdePluginImplementationBase *)userdata; 
    37         delete impl_object; 
    38         osync_trace(TRACE_EXIT, "%s(%p)", __func__, userdata); 
    39 } 
    40  
    41 static void kde_connect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) 
    42 { 
    43         osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, userdata, info, ctx); 
    44         KdePluginImplementationBase *impl_object = (KdePluginImplementationBase*)userdata; 
    45         impl_object->connect(info, ctx); 
    46         osync_trace(TRACE_EXIT, "%s", __func__); 
    47 } 
    48  
    49  
    50 static void kde_disconnect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) 
    51 { 
    52         KdePluginImplementationBase *impl_object = (KdePluginImplementationBase *)userdata; 
    53         impl_object->disconnect(info, ctx); 
    54 } 
    55  
    56 static void kde_get_changeinfo(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) 
    57 { 
    58         KdePluginImplementationBase *impl_object = (KdePluginImplementationBase*)userdata; 
    59 //      osync_debug("kde", 3, "%s",__FUNCTION__); 
    60  
    61         impl_object->get_changeinfo(info, ctx); 
    62 } 
    63  
    64 static void kde_sync_done(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) 
    65 { 
    66         KdePluginImplementationBase *impl_object = (KdePluginImplementationBase *)userdata; 
    67  
    68 //      osync_debug("kde", 3, "%s()",__FUNCTION__); 
    69  
    70         impl_object->sync_done(info, ctx); 
    71 } 
    72  
    73 static void kde_vcard_commit_change(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change) 
    74 { 
    75         KdePluginImplementationBase *impl_object = (KdePluginImplementationBase *)userdata;  
    76  
    77 //      osync_debug("kde", 3, "%s()",__FUNCTION__); 
    78  
    79         impl_object->vcard_commit_change(info, ctx, change); 
    80 } 
    81  
    82 static osync_bool kde_vcard_access(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change) 
    83 { 
    84         KdePluginImplementationBase *impl_object = (KdePluginImplementationBase *)userdata; 
    85  
    86 //      osync_debug("kde", 3, "%s()",__FUNCTION__); 
    87  
    88         impl_object->vcard_access(info, ctx, change); 
    89 } 
    9034 
    9135/** Load actual plugin implementation 
    9236 * 
    93  * Loads kde_impl.so and create a new KdePluginImplementation object, 
     37 * Loads kdepim_lib.so and create a new KdePluginImplementation object, 
    9438 * that is linked against the KDE libraries, and implements the plugin 
    9539 * functions 
     
    9741 * @see KdePluginImplementationBase 
    9842 */ 
    99 static void *kde_initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) 
     43static void * 
     44kde_initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) 
    10045{ 
    10146        osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, plugin, info, error); 
     
    10550        void *module; 
    10651 
    107 //      osync_debug("kde", 3, "%s", __FUNCTION__); 
    108  
    109 //      osync_debug("kde", 3, "Loading implementation module"); 
    11052        module = dlopen(KDEPIM_LIBDIR"/kdepim_lib.so", RTLD_NOW); 
    11153        if (!module) { 
     
    11456                goto error; 
    11557        } 
    116 //      osync_debug("kde", 3, "Getting initialization function"); 
     58         
    11759        init_func = (KdeImplInitFunc)dlsym(module, "new_KdePluginImplementation"); 
    11860        if (!init_func) { 
     
    12163        } 
    12264 
    123 //      osync_debug("kde", 3, "Initializing implementation module"); 
    12465        impl_object = init_func(plugin, info, error); 
    12566        if (!impl_object) 
    12667                goto error; 
    12768 
    128         do { 
    129                 impl_object->contact_sink = osync_objtype_sink_new("contact", error); 
    130                 if (!impl_object->contact_sink) 
    131                         goto error; 
    132  
    133                 osync_objtype_sink_add_objformat(impl_object->contact_sink, "vcard30"); 
    134  
    135                 /* Every sink can have different functions ... */ 
    136                 OSyncObjTypeSinkFunctions functions; 
    137                 memset(&functions, 0, sizeof(functions)); 
    138                 functions.connect = kde_connect; 
    139                 functions.disconnect = kde_disconnect; 
    140                 functions.get_changes = kde_get_changeinfo; 
    141                 functions.commit = kde_vcard_commit_change; 
    142                 functions.sync_done = kde_sync_done; 
    143  
    144                 /* We pass the OSyncFileDir object to the sink, so we dont have to look it up 
    145                  * again once the functions are called */ 
    146                 osync_objtype_sink_set_functions(impl_object->contact_sink, functions, impl_object); 
    147                 osync_plugin_info_add_objtype(info, impl_object->contact_sink); 
    148  
    149         } while(0); 
    150  
    151  
    15269        /* Return the created object to the sync engine */ 
     70        osync_trace(TRACE_EXIT, "%s: %p", __func__, impl_object); 
    15371        return (void*)impl_object; 
    154         osync_trace(TRACE_EXIT, "%s: %p", __func__, impl_object); 
    15572 
    15673error: 
     
    15976} 
    16077 
    161 extern "C" 
    162 { 
    163  
    16478/* Here we actually tell opensync which sinks are available. For this plugin, we 
    165  * go through the list of directories and enable all, since all have been configured */ 
     79 * go through and enable all the sinks */ 
    16680static osync_bool kde_discover(void *userdata, OSyncPluginInfo *info, OSyncError **error) 
    16781{ 
    16882        osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, userdata, info, error); 
    169          
    170         KdePluginImplementationBase *impl_object = (KdePluginImplementationBase *)userdata; 
    17183 
    172         osync_objtype_sink_set_available(impl_object->contact_sink, TRUE); 
     84        int n, num_objtypes; 
     85        num_objtypes = osync_plugin_info_num_objtypes(info); 
     86        for (n = 0; n < num_objtypes; n++) 
     87                osync_objtype_sink_set_available(osync_plugin_info_nth_objtype(info, n), TRUE); 
    17388 
    17489        osync_trace(TRACE_EXIT, "%s", __func__); 
     
    17691} 
    17792 
    178 osync_bool get_sync_info(OSyncPluginEnv *env, OSyncError **error) { 
     93static void kde_finalize(void *userdata) 
     94
     95        osync_trace(TRACE_ENTRY, "%s(%p)", __func__, userdata); 
     96        KdePluginImplementationBase *impl_object = (KdePluginImplementationBase *)userdata; 
     97        delete impl_object; 
     98        osync_trace(TRACE_EXIT, "%s", __func__); 
     99
     100 
     101osync_bool get_sync_info(OSyncPluginEnv *env, OSyncError **error) 
     102
     103        osync_trace(TRACE_ENTRY, "%s(%p)", __func__, env); 
    179104 
    180105        OSyncPlugin *plugin = osync_plugin_new(error); 
     
    185110        osync_plugin_set_longname(plugin, "KDE Desktop"); 
    186111        osync_plugin_set_description(plugin, "Plugin for the KDE 3.5 Desktop"); 
    187  
    188112        osync_plugin_set_config_type(plugin, OSYNC_PLUGIN_NO_CONFIGURATION); 
    189113 
     
    192116        osync_plugin_set_discover(plugin, kde_discover); 
    193117 
    194  
    195118        osync_plugin_env_register_plugin(env, plugin); 
    196119        osync_plugin_unref(plugin); 
     120 
     121        osync_trace(TRACE_EXIT, "%s", __func__); 
    197122        return TRUE; 
    198123 
    199124error: 
    200         osync_trace(TRACE_ERROR, "Unable to register: %s", osync_error_print(error)); 
    201         osync_error_unref(error); 
     125        osync_trace(TRACE_EXIT_ERROR, "%s: Unable to register: %s", __func__, osync_error_print(error)); 
    202126        return FALSE; 
    203127} 
  • plugins/kdepim/src/osyncbase.h

    r1765 r2277  
    2121{ 
    2222        public: 
    23                 virtual void connect(OSyncPluginInfo *info, OSyncContext *ctx) = 0; 
    24                 virtual void disconnect(OSyncPluginInfo *info, OSyncContext *ctx) = 0; 
    25  
    26                 virtual void get_changeinfo(OSyncPluginInfo *info, OSyncContext *ctx) = 0; 
    27  
    28                 virtual void sync_done(OSyncPluginInfo *info, OSyncContext *ctx) = 0; 
    29  
    30                 virtual bool vcard_access(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg) = 0; 
    31                 virtual bool vcard_commit_change(OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg) = 0; 
    32  
    33  
    34                 /* The declaration above seemed to be necessary just because the 
    35                  * KdePluginImplementation destructor wasn't being called 
    36                  */ 
    37                 virtual ~KdePluginImplementationBase() { }; 
    38  
    39                 OSyncObjTypeSink *contact_sink; 
    40  
     23                virtual ~KdePluginImplementationBase() {}; 
    4124}; 
    4225