phonebookengines/cntlistmodel/inc/cntlistmodel.h
changeset 81 640d30f4fb64
parent 77 c18f9fa7f42e
child 84 63017c97b1d6
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 #ifndef CNTLISTMODEL_H
       
    18 #define CNTLISTMODEL_H
       
    19 
       
    20 #include <QAbstractListModel>
       
    21 #include <QSharedData>
       
    22 #include <HbIcon>
       
    23 
       
    24 #include "cntlistmodelglobal.h"
       
    25 #include <qcontactmanager.h>
       
    26 #include <qcontactfilter.h>
       
    27 #include <qcontactsortorder.h>
       
    28 
       
    29 QTM_USE_NAMESPACE
       
    30 
       
    31 class CntListModelData;
       
    32 class XQSettingsKey;
       
    33 class CntDisplayTextFormatter;
       
    34 
       
    35 /*!
       
    36  * CntListModel is a list model view for contacts database
       
    37  * content. It will cache contacts database entries to be
       
    38  * displayed on the screen.
       
    39  *
       
    40  * Note that that this is a prototype implementation and does
       
    41  * not yet support more advanced features, such as automatic
       
    42  * update and lazy fetching from contacts database.
       
    43  */
       
    44 class CNTLISTMODEL_EXPORT CntListModel : public QAbstractListModel
       
    45 {
       
    46     Q_OBJECT
       
    47     friend class TestCntListModel;
       
    48 
       
    49 public:
       
    50     CntListModel(QContactManager* manager,
       
    51                 const QContactFilter& contactFilter = QContactFilter(),
       
    52                 bool showMyCard = true,
       
    53                 QObject *parent = 0);
       
    54     ~CntListModel();
       
    55 
       
    56 public: // from QAbstractTableModel/QAbstractItemModel
       
    57     QVariant data(const QModelIndex &index, int role) const;
       
    58     int rowCount(const QModelIndex &parent = QModelIndex()) const;
       
    59 
       
    60 public:
       
    61 	QContact contact(const QModelIndex &index) const;
       
    62     QContactLocalId contactId(const QModelIndex &index) const;
       
    63 	QModelIndex indexOfContact(const QContact &contact) const;
       
    64 	QModelIndex indexOfContactId(const QContactLocalId &contactId) const;
       
    65 	void setFilter(const QContactFilter& contactFilter = QContactFilter());
       
    66 	void showMyCard(bool enabled);
       
    67 	bool myCardStatus() const;
       
    68 	QContactLocalId myCardId() const;
       
    69 		
       
    70 private:
       
    71     void updateContactIdsArray();
       
    72     QContact contact(int row) const;
       
    73     bool validRowId(int row) const;
       
    74     int rowId(const QContactLocalId &contactId) const;
       
    75     QVariant dataForRole(int row, int role) const;
       
    76     void updateRelationships();
       
    77 
       
    78 private slots:
       
    79     void handleAdded(const QList<QContactLocalId>& contactIds);
       
    80     void handleChanged(const QList<QContactLocalId>& contactIds);
       
    81     void handleRemoved(const QList<QContactLocalId>& contactIds);
       
    82     void handleMyCardChanged(const QContactLocalId& oldId, const QContactLocalId& newId);
       
    83     void handleContactInfoUpdated(QContactLocalId contactId);
       
    84     void handleAddedRelationship(const QList<QContactLocalId>& contactIds);
       
    85     void handleRemovedRelationship(const QList<QContactLocalId>& contactIds);
       
    86     void handleRowSettingChanged(const XQSettingsKey& key, const QVariant& value);
       
    87     void refreshModel();
       
    88 
       
    89 private:
       
    90     QSharedDataPointer<CntListModelData>  d;
       
    91     HbIcon                               m_defaultIcon;
       
    92     HbIcon                               m_defaultMyCardIcon;
       
    93 };
       
    94 
       
    95 #endif