phonebookui/cnthistorymodel/inc/cnthistorymodel.h
changeset 47 7cbcb2896f0e
parent 46 efe85016a067
child 66 554fe4dbbb59
equal deleted inserted replaced
46:efe85016a067 47:7cbcb2896f0e
    19 
    19 
    20 #include <QAbstractListModel>
    20 #include <QAbstractListModel>
    21 #include <QSharedData>
    21 #include <QSharedData>
    22 #include <qmobilityglobal.h>
    22 #include <qmobilityglobal.h>
    23 #include <qcontactid.h>
    23 #include <qcontactid.h>
       
    24 #include "cntglobal.h"
    24 
    25 
       
    26 #include "cnthistorymodelconsts.h"
    25 #include "cnthistorymodelglobal.h"
    27 #include "cnthistorymodelglobal.h"
    26 
    28 
    27 QTM_BEGIN_NAMESPACE
    29 QTM_BEGIN_NAMESPACE
    28 class QContactManager;
    30 class QContactManager;
    29 QTM_END_NAMESPACE
    31 QTM_END_NAMESPACE
    30 
    32 
    31 QTM_USE_NAMESPACE
    33 QTM_USE_NAMESPACE
    32 
    34 
    33 class CntHistoryModelData;
    35 class CntHistoryModelPrivate;
    34 class LogsEvent;
       
    35 class HistoryItem;
       
    36 class MsgItem;
       
    37 
    36 
    38 /*!
    37 /*!
    39  * CntHistoryModel is a model used to fetch conversation history
    38  * CntHistoryModel is a model used to fetch conversation history
    40  * (SMS & call logs) from databases. It will 
    39  * (SMS & call logs) from databases. It will 
    41  * cache content from the databases to be displayed on the screen
    40  * cache content from the databases to be displayed on the screen
    47 class CNTHISTORYMODEL_EXPORT CntHistoryModel : public QAbstractListModel
    46 class CNTHISTORYMODEL_EXPORT CntHistoryModel : public QAbstractListModel
    48 {    
    47 {    
    49     Q_OBJECT
    48     Q_OBJECT
    50     
    49     
    51 public:
    50 public:
    52     enum Attributes
       
    53         {
       
    54         Incoming = 1,
       
    55         Outgoing = 2,
       
    56         Unseen = 4,
       
    57         Seen = 8,
       
    58         Attachment = 16
       
    59         };
       
    60     
       
    61     enum ItemType
       
    62         {
       
    63         CallLog = 32,
       
    64         Message = 64
       
    65         };
       
    66     enum Icon
       
    67         {
       
    68         MissedCall = 128,
       
    69         ReceivedCall = 256,
       
    70         DialledCall = 512
       
    71         };
       
    72     
       
    73     enum CustomRoles
       
    74         {
       
    75         FlagsRole = Qt::UserRole + 1,
       
    76         PhoneNumberRole
       
    77         };
       
    78     
       
    79 public:
       
    80     CntHistoryModel(QContactLocalId contactId,
    51     CntHistoryModel(QContactLocalId contactId,
    81                     QContactManager* manager,
    52                     QContactManager* manager,
    82                     QObject *parent = 0);
    53                     QObject *parent = 0);
    83     ~CntHistoryModel();
    54     ~CntHistoryModel();
    84     
    55     
    85 public: // from QAbstractTableModel/QAbstractItemModel
    56 public: // from QAbstractTableModel/QAbstractItemModel
    86     QVariant data(const QModelIndex& index, int role) const;
    57     QVariant data(const QModelIndex& index, int role) const;
    87     int rowCount(const QModelIndex& parent = QModelIndex()) const;
    58     int rowCount(const QModelIndex& parent = QModelIndex()) const;
    88     void sort(int column = 0, Qt::SortOrder order = Qt::AscendingOrder);
    59     void sort(int column = 0, Qt::SortOrder order = Qt::AscendingOrder);
       
    60 
       
    61 public:
    89     void clearHistory();
    62     void clearHistory();
    90     void markAllAsSeen();
    63     void markAllAsSeen();
    91     void sortAndRefresh(Qt::SortOrder order = Qt::AscendingOrder);
    64     void sortAndRefresh(Qt::SortOrder order = Qt::AscendingOrder);
       
    65 
       
    66 private:
       
    67     void doBeginInsertRows(const QModelIndex &parent, int first, int last);
       
    68     void doEndInsertRows();
       
    69     void doBeginRemoveRows(const QModelIndex &parent, int first, int last);
       
    70     void doEndRemoveRows();
       
    71     void doDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
    92     
    72     
    93 private:
    73 private:
    94     void initializeModel();
    74 	CntHistoryModelPrivate* const d_ptr;
    95     QVariant displayRoleData(const HistoryItem& item) const;
    75     Q_DECLARE_PRIVATE_D(d_ptr, CntHistoryModel)
    96     QVariant decorationRoleData(const HistoryItem& item) const;
    76     Q_DISABLE_COPY(CntHistoryModel)
    97     QVariant backgroundRoleData(const HistoryItem& item) const;
       
    98     
    77     
    99     // Utility finctions
    78     // Testing related friend definitions
   100     void readLogEvent(LogsEvent* event, HistoryItem& item);
       
   101     void readMsgEvent(MsgItem& event, HistoryItem& item);
       
   102     void initializeLogsModel();
       
   103     void initializeMsgModel();
       
   104     bool validateRowIndex(const int index) const;
       
   105     QList< QList<int> > findIndices( const QList< int >& indices );
       
   106 
       
   107 private slots:
       
   108     // Logs model slots
       
   109     void logsRowsInserted(const QModelIndex& parent, int first, int last);
       
   110     void logsRowsRemoved(const QModelIndex& parent, int first, int last);
       
   111     void logsDataChanged(const QModelIndex& first, const QModelIndex& last);
       
   112     void handleLogsReset();
       
   113     
       
   114     // Messaging model slots
       
   115     void messagesReady(QList<MsgItem>& msgs);
       
   116     void messageAdded(MsgItem& msg);
       
   117     void messageChanged(MsgItem& msg);
       
   118     void messageDeleted(MsgItem& msg);
       
   119     
       
   120 private:
       
   121 	QSharedDataPointer<CntHistoryModelData> d;
       
   122     
       
   123     // Testing related friend definitions    
       
   124     friend class TestCntHistoryModel;
    79     friend class TestCntHistoryModel;
   125 };
    80 };
       
    81 
   126 #endif
    82 #endif