phonebookui/cnthistorymodel/inc/cnthistorymodel.h
changeset 27 de1630741fbe
child 31 2a11b5b00470
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/phonebookui/cnthistorymodel/inc/cnthistorymodel.h	Mon May 03 12:24:20 2010 +0300
@@ -0,0 +1,116 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+#ifndef CNTHISTORYMODEL_H
+#define CNTHISTORYMODEL_H
+
+#include <QAbstractListModel>
+#include <QSharedData>
+#include <qtcontacts.h>
+
+#include "cnthistorymodelglobal.h"
+
+QTM_USE_NAMESPACE
+
+class CntHistoryModelData;
+class LogsEvent;
+class HistoryItem;
+class MsgItem;
+
+/*!
+ * CntHistoryModel is a model used to fetch conversation history
+ * (SMS & call logs) from databases. It will 
+ * cache content from the databases to be displayed on the screen
+ * by the conversation view.
+ * 
+ * Note that that this is a prototype implementation and does
+ * not yet support more advanced features.
+ */
+class CNTHISTORYMODEL_EXPORT CntHistoryModel : public QAbstractListModel
+{    
+    Q_OBJECT
+    
+public:
+    enum ConversationDirection
+        {
+        Incoming = 0,
+        Outgoing,
+        Missed
+        };
+    
+    enum ReadStatus
+        {
+        Unseen = 3,
+        Seen
+        };
+    
+    enum ItemType
+        {
+        CallLog = 5,
+        Message
+        };
+    
+    enum CustomRoles
+        {
+        SeenStatusRole = Qt::UserRole + 1,
+        DirectionRole,
+        ItemTypeRole,
+        PhoneNumberRole
+        };
+    
+public:
+    CntHistoryModel(QContactLocalId contactId,
+                    QContactManager* manager,
+                    QObject *parent = 0);
+    ~CntHistoryModel();
+    
+public: // from QAbstractTableModel/QAbstractItemModel
+    QVariant data(const QModelIndex& index, int role) const;
+    int rowCount(const QModelIndex& parent = QModelIndex()) const;
+    void sort(int column = 0, Qt::SortOrder order = Qt::AscendingOrder);
+    void clearHistory();
+    void markAllAsSeen();
+    void sortAndRefresh(Qt::SortOrder order = Qt::AscendingOrder);
+    
+private:
+    void initializeModel();
+    QVariant displayRoleData(const HistoryItem& item) const;
+    
+    // Utility finctions
+    void readLogEvent(LogsEvent* event, HistoryItem& item);
+    void readMsgEvent(MsgItem& event, HistoryItem& item);
+    void initializeLogsModel();
+    void initializeMsgModel();
+    bool validateRowIndex(const int index) const;
+    QList< QList<int> > findIndices( const QList< int >& indices );
+
+private slots:
+    // Logs model slots
+    void logsRowsInserted(const QModelIndex& parent, int first, int last);
+    void logsRowsRemoved(const QModelIndex& parent, int first, int last);
+    void logsDataChanged(const QModelIndex& first, const QModelIndex& last);
+    void clearedCallLogs(int err);
+    void markingCompleted(int err);
+    // Messaging model slots
+    void messagesReady(QList<MsgItem>& msgs);
+    void messageAdded(MsgItem& msg);
+    void messageChanged(MsgItem& msg);
+    void messageDeleted(MsgItem& msg);
+    
+private:
+	QSharedDataPointer<CntHistoryModelData> d;
+};
+#endif