phonebookengines/cntlistmodel/inc/cntlistmodel.h
changeset 46 efe85016a067
parent 40 b46a585f6909
child 47 7cbcb2896f0e
equal deleted inserted replaced
40:b46a585f6909 46:efe85016a067
    27 #include <qcontactsortorder.h>
    27 #include <qcontactsortorder.h>
    28 
    28 
    29 QTM_USE_NAMESPACE
    29 QTM_USE_NAMESPACE
    30 
    30 
    31 class CntListModelData;
    31 class CntListModelData;
    32 class CntListModel;
       
    33 
    32 
    34 /*!
    33 /*!
    35  * MobCntModel is a list model view for contacts database
    34  * CntListModel is a list model view for contacts database
    36  * content. It will cache contacts database entries to be
    35  * content. It will cache contacts database entries to be
    37  * displayed on the screen.
    36  * displayed on the screen.
    38  *
    37  *
    39  * Note that that this is a prototype implementation and does
    38  * Note that that this is a prototype implementation and does
    40  * not yet support more advanced features, such as automatic
    39  * not yet support more advanced features, such as automatic
    41  * update and lazy fetching from contacts database.
    40  * update and lazy fetching from contacts database.
    42  */
    41  */
    43 class CNTLISTMODEL_EXPORT CntListModel : public QAbstractListModel
    42 class CNTLISTMODEL_EXPORT CntListModel : public QAbstractListModel
    44 {
    43 {
    45     Q_OBJECT
    44     Q_OBJECT
    46     friend class TestMobCntModel;
    45     friend class TestCntListModel;
    47 
    46 
    48 public:
    47 public:
    49     CntListModel(const QContactFilter& contactFilter = QContactFilter(),
    48     CntListModel(const QContactFilter& contactFilter = QContactFilter(),
    50                 const QList<QContactSortOrder>& contactSortOrders = QList<QContactSortOrder>(),
       
    51                 bool showMyCard = true,
    49                 bool showMyCard = true,
    52                 QObject *parent = 0);
    50                 QObject *parent = 0);
    53     CntListModel(QContactManager* manager,
    51     CntListModel(QContactManager* manager,
    54                 const QContactFilter& contactFilter = QContactFilter(),
    52                 const QContactFilter& contactFilter = QContactFilter(),
    55                 const QList<QContactSortOrder>& contactSortOrders = QList<QContactSortOrder>(),
       
    56                 bool showMyCard = true,
    53                 bool showMyCard = true,
    57                 QObject *parent = 0);
    54                 QObject *parent = 0);
    58     ~CntListModel();
    55     ~CntListModel();
    59 
    56 
    60 public: // from QAbstractTableModel/QAbstractItemModel
    57 public: // from QAbstractTableModel/QAbstractItemModel
    61     QVariant data(const QModelIndex &index, int role) const;
    58     QVariant data(const QModelIndex &index, int role) const;
    62     int rowCount(const QModelIndex &parent = QModelIndex()) const;
    59     int rowCount(const QModelIndex &parent = QModelIndex()) const;
    63 
    60 
    64 public:
    61 public:
    65     QContact contact(const QModelIndex &index) const;
    62 	QContact contact(const QModelIndex &index) const;
    66     QModelIndex indexOfContact(const QContact &contact) const;
    63 	QModelIndex indexOfContact(const QContact &contact) const;
    67     QContactManager& contactManager() const;
    64 	QContactManager& contactManager() const;
    68     void setFilterAndSortOrder(const QContactFilter& contactFilter = QContactFilter(),
    65 	void setFilter(const QContactFilter& contactFilter = QContactFilter());
    69                                const QList<QContactSortOrder>& contactSortOrders = QList<QContactSortOrder>());
    66 	void showMyCard(bool enabled);
    70     void showMyCard(bool enabled);
    67 	bool myCardStatus() const;
    71     bool myCardStatus() const;
    68 	QContactLocalId myCardId() const;
    72     QContactLocalId myCardId() const;
       
    73 	
    69 	
    74 private:
    70 private:
    75     // Construction helpers
    71     // Construction helpers
    76     int doConstruct();
    72     int doConstruct();
    77     int initializeData();
    73     int initializeData();
    78     void updateContactIdsArray();
    74     void updateContactIdsArray();
       
    75     void setSortOrder();
    79 
    76 
    80     // Data manipulation
    77     // Data manipulation
    81     QContact contact(int row) const;
    78     QContact contact(int row) const;
    82 
    79 
    83     // Utility
    80     // Utility
    84     bool validRowId(int row) const;
    81     bool validRowId(int row) const;
    85     int rowId(const QContactLocalId &contactId) const;
    82     int rowId(const QContactLocalId &contactId) const;
    86     QVariant dataForDisplayRole(int row) const;
    83     QVariant dataForDisplayRole(int row) const;
    87 
    84 
    88 protected slots:
    85 private slots:
    89     void handleAdded(const QList<QContactLocalId>& contactIds);
    86     void handleAdded(const QList<QContactLocalId>& contactIds);
    90     void handleChanged(const QList<QContactLocalId>& contactIds);
    87     void handleChanged(const QList<QContactLocalId>& contactIds);
    91     void handleRemoved(const QList<QContactLocalId>& contactIds);
    88     void handleRemoved(const QList<QContactLocalId>& contactIds);
    92     void handleMyCardChanged(const QContactLocalId& oldId, const QContactLocalId& newId);
    89     void handleMyCardChanged(const QContactLocalId& oldId, const QContactLocalId& newId);
    93     void handleContactInfoUpdated(QContactLocalId contactId);
    90     void handleContactInfoUpdated(QContactLocalId contactId);
       
    91     void refreshModel();
    94 
    92 
    95 private:
    93 private:
    96     QSharedDataPointer<CntListModelData>  d;
    94     QSharedDataPointer<CntListModelData>  d;
    97     HbIcon                               mDefaultIcon;
    95     HbIcon                               m_defaultIcon;
    98     HbIcon                               mDefaultMyCardIcon;
    96     HbIcon                               m_defaultMyCardIcon;
    99 };
    97 };
   100 
    98 
   101 #endif
    99 #endif