phonebookengines/cntlistmodel/src/cntcache_p.cpp
changeset 61 d30183af6ca6
parent 47 7cbcb2896f0e
child 66 554fe4dbbb59
equal deleted inserted replaced
56:d508aa856878 61:d30183af6ca6
    13 *
    13 *
    14 * Description: Private data and helper classes used by class CntCache.
    14 * Description: Private data and helper classes used by class CntCache.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #include <QPluginLoader>
       
    19 #include <QDir>
       
    20 
    18 #include <qtcontacts.h>
    21 #include <qtcontacts.h>
    19 #include <qcontactmanager.h>
    22 #include <qcontactmanager.h>
    20 #include <hbapplication.h>
    23 #include <hbapplication.h>
    21 #include <thumbnailmanager_qt.h>
    24 #include <thumbnailmanager_qt.h>
    22 #include <hbicon.h>
    25 #include <hbicon.h>
    23 #include <QTimer>
    26 #include <QTimer>
    24 #include "cntcache.h"
    27 #include "cntcache.h"
    25 #include "cntcache_p.h"
    28 #include "cntcache_p.h"
    26 #include "cntinfoprovider.h"
    29 #include <cntinfoproviderfactory.h>
       
    30 #include <cntinfoprovider.h>
    27 #include "cntdefaultinfoprovider.h"
    31 #include "cntdefaultinfoprovider.h"
    28 #include "cntpresenceinfoprovider.h"
    32 #include "cntpresenceinfoprovider.h"
    29 #include <cntdebug.h>
    33 #include <cntdebug.h>
    30 
    34 
    31 // maximum amount of info and icon jobs respectively -- if there are more jobs,
    35 // maximum amount of info and icon jobs respectively -- if there are more jobs,
    39 static const QEvent::Type ProcessJobsEvent = QEvent::User;
    43 static const QEvent::Type ProcessJobsEvent = QEvent::User;
    40 // the id that states that no icon is currently pending from thumbnail manager
    44 // the id that states that no icon is currently pending from thumbnail manager
    41 static const int NoIconRequest = -1;
    45 static const int NoIconRequest = -1;
    42 // the id that states that there is no job with that key
    46 // the id that states that there is no job with that key
    43 static const int NoSuchJob = -1;
    47 static const int NoSuchJob = -1;
       
    48 
       
    49 const char *CNT_INFO_PROVIDER_EXTENSION_PLUGIN_DIRECTORY = "/resource/qt/plugins/contacts/infoproviders/";
    44     
    50     
    45 // TODO: Provide a way (cenrep keys?) for UI to set which provider to use for
    51 // TODO: Provide a way (cenrep keys?) for UI to set which provider to use for
    46 //       what info field (and what info fields are indeed even in use).
    52 //       what info field (and what info fields are indeed even in use).
    47 
    53 
    48 /*!
    54 /*!
    58     CNT_ENTRY
    64     CNT_ENTRY
    59 
    65 
    60     // create static provider plugins
    66     // create static provider plugins
    61     mDataProviders.insert(new CntDefaultInfoProvider(), ContactInfoAllFields);
    67     mDataProviders.insert(new CntDefaultInfoProvider(), ContactInfoAllFields);
    62     mDataProviders.insert(new CntPresenceInfoProvider(), ContactInfoIcon2Field);
    68     mDataProviders.insert(new CntPresenceInfoProvider(), ContactInfoIcon2Field);
    63     // TODO: create more static provider plugins
    69 
    64 
    70     // load dynamic provider plugins
    65     // TODO: load dynamic provider plugins using QPluginLoader
    71     QDir pluginsDir(CNT_INFO_PROVIDER_EXTENSION_PLUGIN_DIRECTORY);
    66 
    72     foreach (QString fileName, pluginsDir.entryList(QDir::Files))
       
    73     {
       
    74         // Create plugin loader
       
    75         QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
       
    76         if ( pluginLoader.load() )
       
    77         {
       
    78             CntInfoProviderFactory *factory = qobject_cast<CntInfoProviderFactory*>(pluginLoader.instance());
       
    79             
       
    80             if (factory)
       
    81             {
       
    82                 CntInfoProvider *provider = factory->infoProvider();
       
    83                 mDataProviders.insert(provider, provider->supportedFields());
       
    84             }
       
    85         }
       
    86     }
       
    87     
    67     // connect the providers
    88     // connect the providers
    68     QMapIterator<CntInfoProvider*, ContactInfoFields> i(mDataProviders);
    89     QMapIterator<CntInfoProvider*, ContactInfoFields> i(mDataProviders);
    69     while (i.hasNext()) {
    90     while (i.hasNext()) {
    70         i.next();
    91         i.next();
    71         connect(qobject_cast<CntInfoProvider*>(i.key()),
    92         connect(static_cast<CntInfoProvider*>(i.key()),
    72                 SIGNAL(infoFieldReady(CntInfoProvider*, int, ContactInfoField, const QString&)),
    93                 SIGNAL(infoFieldReady(CntInfoProvider*, int, ContactInfoField, const QString&)),
    73                 this,
    94                 this,
    74                 SLOT(onInfoFieldReady(CntInfoProvider*, int, ContactInfoField, const QString&)));
    95                 SLOT(onInfoFieldReady(CntInfoProvider*, int, ContactInfoField, const QString&)));
    75     }
    96     }
    76 
    97