phonebookengines/mobcntmodel/inc/cntcache_p.h
changeset 37 fd64c38c277d
equal deleted inserted replaced
31:2a11b5b00470 37:fd64c38c277d
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Private data and helper classes used by class CntCache.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CNTCACHE_P_H
       
    19 #define CNTCACHE_P_H
       
    20 
       
    21 #include <QThread>
       
    22 #include <QSharedData>
       
    23 #include <QMutex>
       
    24 #include <QSet>
       
    25 #include <HbIcon>
       
    26 #include <qcontactmanager.h>
       
    27 #include "cntinfoprovider.h"
       
    28 
       
    29 #define DP( s );
       
    30 #define DP_IN( s );
       
    31 #define DP_OUT( s );
       
    32 
       
    33 class ThumbnailManager;
       
    34 
       
    35 QTM_USE_NAMESPACE
       
    36 
       
    37 /*!
       
    38     Private shared data for the CntContactInfo class.
       
    39  */
       
    40 class CntContactInfoData : public QSharedData
       
    41 {
       
    42 public:
       
    43      CntContactInfoData() : id(-1), fields(0) { }
       
    44      ~CntContactInfoData() { }
       
    45 
       
    46 public:
       
    47     int id;
       
    48     int fields;
       
    49     QString name;
       
    50     QString text;
       
    51     HbIcon icon1;
       
    52     HbIcon icon2;
       
    53 };
       
    54 
       
    55 /*!
       
    56     Cache item that holds info for one contact: name, text and two icon names.
       
    57  */
       
    58 class CntInfoCacheItem
       
    59 {
       
    60 public:
       
    61     int cacheOrder;
       
    62     int contactId;
       
    63     QString name;
       
    64     QString text;
       
    65     QString icons[2];
       
    66 };
       
    67 
       
    68 /*!
       
    69     Cache item that holds one icon. Data member isFetched is false until the
       
    70     icon has been fetched asynchronously.
       
    71  */
       
    72 class CntIconCacheItem
       
    73 {
       
    74 public:
       
    75     int cacheOrder;
       
    76     QString iconName;
       
    77     bool isFetched;
       
    78     QSet<int> contactIds;
       
    79     HbIcon icon;
       
    80 };
       
    81 
       
    82 /*!
       
    83     Low priority thread that fetches contact info and icons in the background.
       
    84     CntCacheThread uses data provider plugins and thumbnail manager to retrieve
       
    85     the actual data. This class' responsibilities are 1) fetch the requested
       
    86     data in a timely manner and 2) interfere with the UI as little as possible.
       
    87     This is mainly orchestrated by the client, who calls postponeJobs() when
       
    88     the UI is active, and who only requests urgent jobs.
       
    89     
       
    90     If the client sends too many requests (e.g. during a long scrolling operation
       
    91     in the UI), then the oldest jobs will be cancelled. However, the cancelled jobs
       
    92     will be informed back to the client later so that it can choose to reschedule
       
    93     the jobs.
       
    94  */
       
    95 class CntCacheThread : public QThread
       
    96 {
       
    97     Q_OBJECT
       
    98 public:
       
    99     CntCacheThread();
       
   100     ~CntCacheThread();
       
   101 
       
   102     void run();
       
   103     void scheduleInfoJob(int contactId);
       
   104     void scheduleIconJob(const QString& iconName);
       
   105     void postponeJobs();
       
   106     bool event(QEvent *event);
       
   107 
       
   108 signals:
       
   109     void infoFieldUpdated(int contactId, ContactInfoField infoField, const QString& infoValue);
       
   110     void infoCancelled(int contactId);
       
   111     void iconUpdated(const QString& iconName, const HbIcon& icon);
       
   112     void iconCancelled(const QString& iconName);
       
   113     void allJobsDone();
       
   114     
       
   115 private slots:
       
   116     void onInfoFieldReady(CntInfoProvider* sender, int contactId,
       
   117                           ContactInfoField field, const QString& text);
       
   118     void onIconReady(const QPixmap& pixmap, void *data, int id, int error);
       
   119     void doAllJobs();
       
   120 
       
   121 private:
       
   122     QContactManager* mContactManager;       // for fetching QContact objects
       
   123     ThumbnailManager* mThumbnailManager;    // for fetching icons
       
   124 
       
   125     // maps info providers to their responsibilities
       
   126     QMap<CntInfoProvider*, ContactInfoFields> mDataProviders;
       
   127 
       
   128     QMutex mJobMutex;                       // guards access to the job lists
       
   129     bool mJobLoopRunning;                   // true from when job loop event has been posted until job loop exits
       
   130     int mPostponeJobs;                      // set to true by client if it needs the CPU
       
   131     QList<int> mInfoJobs;                   // list of all info jobs
       
   132     QList<int> mCancelledInfoJobs;          // list of all cancelled info jobs
       
   133     QList<QString> mIconJobs;               // list of all icon jobs
       
   134     QList<QString> mCancelledIconJobs;      // list of all cancelled icon jobs
       
   135     int mIconRequestId;                     // the id for the last request to thumbnail manager
       
   136     QString mIconRequestName;               // the name of the icon last requested from thumbnail manager
       
   137 };
       
   138 
       
   139 #endif