phonebookengines/cntlistmodel/inc/cntcache_p.h
branchRCL_3
changeset 62 5b6f26637ad3
equal deleted inserted replaced
58:d4f567ce2e7c 62:5b6f26637ad3
       
     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 class ThumbnailManager;
       
    30 
       
    31 QTM_USE_NAMESPACE
       
    32 
       
    33 /*!
       
    34     Private shared data for the CntContactInfo class.
       
    35  */
       
    36 class CntContactInfoData : public QSharedData
       
    37 {
       
    38 public:
       
    39      CntContactInfoData() : id(-1), fields(0) { }
       
    40      ~CntContactInfoData() { }
       
    41 
       
    42 public:
       
    43     int id;
       
    44     int fields;
       
    45     QString name;
       
    46     QString text;
       
    47     HbIcon icon1;
       
    48     HbIcon icon2;
       
    49 };
       
    50 
       
    51 /*!
       
    52     Cache item that holds info for one contact: name, text and two icon names.
       
    53  */
       
    54 class CntInfoCacheItem
       
    55 {
       
    56 public:
       
    57     int cacheOrder;
       
    58     int contactId;
       
    59     int latestRow;
       
    60     QString name;
       
    61     QString text;
       
    62     QString icons[2];
       
    63 };
       
    64 
       
    65 /*!
       
    66     Cache item that holds one icon. Data member isFetched is false until the
       
    67     icon has been fetched asynchronously.
       
    68  */
       
    69 class CntIconCacheItem
       
    70 {
       
    71 public:
       
    72     int cacheOrder;
       
    73     QString iconName;
       
    74     bool isFetched;
       
    75     QSet<int> contactIds;
       
    76     HbIcon icon;
       
    77 };
       
    78 
       
    79 /*!
       
    80     Low priority thread that fetches contact info and icons in the background.
       
    81     CntCacheThread uses data provider plugins and thumbnail manager to retrieve
       
    82     the actual data. This class' responsibilities are 1) fetch the requested
       
    83     data in a timely manner and 2) interfere with the UI as little as possible.
       
    84     This is mainly orchestrated by the client, who calls postponeJobs() when
       
    85     the UI is active, and who only requests urgent jobs.
       
    86     
       
    87     If the client sends too many requests (e.g. during a long scrolling operation
       
    88     in the UI), then the oldest jobs will be cancelled. However, the cancelled jobs
       
    89     will be informed back to the client later so that it can choose to reschedule
       
    90     the jobs.
       
    91  */
       
    92 class CntCacheThread : public QThread
       
    93 {
       
    94     friend class TestCntCache;
       
    95     Q_OBJECT
       
    96 public:
       
    97     CntCacheThread();
       
    98     ~CntCacheThread();
       
    99 
       
   100     void run();
       
   101     void scheduleInfoJob(int contactId, int priority);
       
   102     void scheduleIconJob(const QString& iconName, int priority);
       
   103     void postponeJobs();
       
   104     bool event(QEvent *event);
       
   105 
       
   106 signals:
       
   107     void infoFieldUpdated(int contactId, ContactInfoField infoField, const QString& infoValue);
       
   108     void infoCancelled(int contactId);
       
   109     void iconUpdated(const QString& iconName, const HbIcon& icon);
       
   110     void iconCancelled(const QString& iconName);
       
   111     void allJobsDone();
       
   112     
       
   113 private slots:
       
   114     void onInfoFieldReady(CntInfoProvider* sender, int contactId,
       
   115                           ContactInfoField field, const QString& text);
       
   116     void onIconReady(const QPixmap& pixmap, void *data, int id, int error);
       
   117     void processJobs();
       
   118 
       
   119 private:
       
   120     int infoJobIndex(int contactId);
       
   121     int takeNextInfoJob();
       
   122     int iconJobIndex(QString iconName);
       
   123     QString takeNextIconJob();
       
   124 
       
   125 private:
       
   126     QContactManager* mContactManager;       // for fetching QContact objects
       
   127     ThumbnailManager* mThumbnailManager;    // for fetching icons
       
   128 
       
   129     // maps info providers to their responsibilities
       
   130     QMap<CntInfoProvider*, ContactInfoFields> mDataProviders;
       
   131 
       
   132     QMutex mJobMutex;                       // guards access to the job lists
       
   133     bool mStarted;                          // true when thread has been started
       
   134     bool mProcessingJobs;                   // true from when job loop event has been posted until job loop exits
       
   135     int mPostponeJobs;                      // set to true by client if it needs the CPU
       
   136     QList< QPair<int,int> > mInfoJobs;      // list of all info jobs and their priorities
       
   137     QList<int> mCancelledInfoJobs;          // list of all cancelled info jobs
       
   138     QList< QPair<QString,int> > mIconJobs;  // list of all icon jobs and their priorities
       
   139     QList<QString> mCancelledIconJobs;      // list of all cancelled icon jobs
       
   140     int mIconRequestId;                     // the id for the last request to thumbnail manager
       
   141     QString mIconRequestName;               // the name of the icon last requested from thumbnail manager
       
   142 };
       
   143 
       
   144 #endif