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