summaryrefslogtreecommitdiffabout
path: root/libkabcwrap/koaddresspluginloader.cpp
blob: d3292629beefeaa991fb6dcabdd81ab39f720fcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <qtopia/qlibrary.h>
#include <qpe/qpeapplication.h>
#include "koaddressbookpluginloader.h"
#include "kabcaddressbookplugin.h"

KOAddressBookInterface *KOAddressBookPluginLoader::iface = 0;
KABC::Addressee::List KOAddressBookPluginLoader::addresseeList;

KOAddressBookInterface *KOAddressBookPluginLoader::getInterface() {

  qDebug("Start: KOAddressBookPluginLoader::getInterface");

  if (!iface) {

    const QString & qpeDir = QPEApplication::qpeDir();
    QLibrary *lib = new QLibrary( qpeDir + "/plugins/korganizer/libopiekabc.so", QLibrary::Immediately );
    QRESULT q = lib->queryInterface( IID_QUnknown, (QUnknownInterface**)&iface );
    if ( q != QS_OK ) {
      lib = new QLibrary( qpeDir + "/plugins/korganizer/libqtopiakabc.so", QLibrary::Immediately ); 
      QRESULT q = lib->queryInterface( IID_QUnknown, (QUnknownInterface**)&iface );
      // we checked now for all known external interfaces. If no were found, use the default KABC interface
      if ( q != QS_OK ) {
        iface = new KABCAddressBookPlugin();
      }
    }
  }
  
  qDebug("End: KOAddressBookPluginLoader::getInterface");
  return iface;
  
}

KABC::Addressee::List KOAddressBookPluginLoader::getAddresseesFromPlugin() {

  qDebug("Start: KOAddressBookPluginLoader::getAddresseesFromPlugin");
  addresseeList.clear();
  if (!(addresseeList.count() > 0)) {
    qDebug("KOAddressBookPluginLoader::getAddresseesFromPlugin: no addresses loaded. Loading...");
    if (!iface) {
    qDebug("KOAddressBookPluginLoader::getAddresseesFromPlugin: no interface loaded. Loading...");
      iface = getInterface();
    }
    if (iface) {
      qDebug("KOAddressBookPluginLoader::getAddresseesFromPlugin: interface is " + iface->name());
      addresseeList = iface->getAddressees();
    } else {
      qDebug("KOAddressBookPluginLoader::getAddresseesFromPlugin: No interface found!");
    }
  }


  qDebug("End: KOAddressBookPluginLoader::getAddresseesFromPlugin");
  return addresseeList;

}