messagingapp/msgui/appengine/inc/conversationsmodel.h
branchRCL_3
changeset 26 ebe688cedc25
equal deleted inserted replaced
25:fa1df4b99609 26:ebe688cedc25
       
     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 
       
    18 #ifndef CONVERSATIONS_MODEL_H
       
    19 #define CONVERSATIONS_MODEL_H
       
    20 
       
    21 // INCLUDES
       
    22 #include <QObject>
       
    23 #include <QStandardItemModel>
       
    24 #include <ccsdefs.h>
       
    25 #include <sqldb.h>
       
    26 #include <QCache>
       
    27 #include <HbIcon>
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CCsConversationEntry;
       
    31 class ConversationMsgStoreHandler;
       
    32 class UniDataModelLoader;
       
    33 class UniDataModelPluginInterface;
       
    34 
       
    35 /**
       
    36  * This class implements the model of the model/view framework.
       
    37  * The model holds data for the conversations fetched from the
       
    38  * server.
       
    39  *
       
    40  * Data from server is mapped to UI via Model
       
    41  *
       
    42  */
       
    43 
       
    44 class ConversationsModel: public QStandardItemModel
       
    45 {
       
    46 Q_OBJECT
       
    47 
       
    48 public:
       
    49 
       
    50     /**
       
    51      * Constructor
       
    52      */
       
    53     explicit ConversationsModel(ConversationMsgStoreHandler* msgStoreHandler, QObject* parent = 0);
       
    54 
       
    55     /**
       
    56      * Destructor
       
    57      */
       
    58     virtual ~ConversationsModel();
       
    59 
       
    60     /**
       
    61      * Method for mapping the data in the Model to the UI
       
    62      * @param index index for which data needs to be fetched
       
    63      * @param role defined for the data
       
    64      * @return QVariant as the data
       
    65      */
       
    66     QVariant data(const QModelIndex& index, int role) const;
       
    67 
       
    68     /**
       
    69      * Add a new row to the conversations model.
       
    70      * Overwrite the row if the message already exists.
       
    71      * @param entry, CCsConversationEntry
       
    72      * @param dynamicUpdate , true if it is a dynamic update event
       
    73      */
       
    74     void addRow(const CCsConversationEntry& entry, bool dynamicUpdate = false);
       
    75 
       
    76     /**
       
    77      * Delete a row from conversations model.
       
    78      * @param msgId, Message Id
       
    79      */
       
    80     void deleteRow(int msgId);
       
    81     
       
    82     /*
       
    83      * Get SQL DB handle
       
    84      * @param isOpen, set to true if open, check this before using the handle
       
    85      */
       
    86     RSqlDatabase& getDBHandle(TBool& isOpen);
       
    87 
       
    88     /*
       
    89      * Clears the pixmap cache & model
       
    90      */
       
    91     void clearModel();
       
    92     
       
    93     void emitConversationViewEmpty();
       
    94 
       
    95 signals:
       
    96 
       
    97     /*
       
    98      * Signal emitted to retrieve the pixmap icon
       
    99      */
       
   100     void retrievePreviewIcon(int msgId, QString& filepath) const;
       
   101     
       
   102     void conversationViewEmpty();
       
   103 
       
   104 private slots:
       
   105 
       
   106     /*
       
   107      * Slot which handles retrievePreviewIcon signal
       
   108      */
       
   109     void updatePreviewIcon(int msgId, QString& filePath);
       
   110 
       
   111 private:
       
   112 
       
   113     /**
       
   114      * Populate an item in model from CCsConversationEntry.
       
   115      * @param item, QStandardItem
       
   116      * @param entry, CCsConversationEntry
       
   117      */
       
   118     void populateItem(QStandardItem& item, const CCsConversationEntry& entry);
       
   119 
       
   120     /**
       
   121      * Populate MMS related data into item.
       
   122      * @param item, QStandardItem
       
   123      * @param entry, CCsConversationEntry
       
   124      */
       
   125     void handleMMS(QStandardItem& item, const CCsConversationEntry& entry);
       
   126     
       
   127     /**
       
   128      * Populate MMS Notification related data into item.
       
   129      * @param item, QStandardItem
       
   130      * @param entry, CCsConversationEntry
       
   131      */
       
   132     void handleMMSNotification(QStandardItem& item, 
       
   133         const CCsConversationEntry& entry);
       
   134 
       
   135     /**
       
   136      * Populate BT message related data into item.
       
   137      * @param item, QStandardItem
       
   138      * @param entry, CCsConversationEntry
       
   139      */
       
   140     void handleBlueToothMessages(QStandardItem& item, 
       
   141         const CCsConversationEntry& entry);
       
   142 
       
   143     /**
       
   144      * Populate Bio message related data into item.
       
   145      * @param item, QStandardItem
       
   146      * @param entry, CCsConversationEntry
       
   147      */
       
   148     void handleBioMessages(QStandardItem& item, 
       
   149         const CCsConversationEntry& entry);
       
   150 
       
   151     /**
       
   152      * Populates preview icon into the previewicon cache
       
   153      * @param pixmap, QPixmap
       
   154      * @param filePath, filepath to be used if icon is not in Db
       
   155      * @param msgId, key to pixmap in previewicon cache
       
   156      * @param inDb, indicates if icon was available in Db (or) not
       
   157      */    
       
   158     void setPreviewIcon(QPixmap& pixmap, QString& filePath, int msgId,
       
   159         bool inDb);
       
   160 
       
   161     /**
       
   162      * Get the preview icon item if available in pixmap cache / create
       
   163      * and return the preview icon
       
   164      * @param msgId, key to pixmap in previewicon cache
       
   165      * @param filePath, filepath to be used if icon is not in cache
       
   166      */
       
   167     HbIcon* getPreviewIconItem(int msgId, QString& filepath) const;
       
   168     
       
   169     /**
       
   170      * Check if a MMS is forwardable or not
       
   171      * @param messageId, message id
       
   172      * @return true/false
       
   173      */
       
   174     bool validateMsgForForward(qint32 messageId);
       
   175     
       
   176     /*
       
   177      * Handle Vcard messages
       
   178      * @param item, QStandardItem
       
   179      * @param msgId
       
   180      */
       
   181     void handleVCard(QStandardItem& item, int msgId);
       
   182 
       
   183 private:
       
   184 
       
   185     /**
       
   186      * Msg Store Handler
       
   187      * Not Own
       
   188      */
       
   189     ConversationMsgStoreHandler* mMsgStoreHandler;
       
   190 
       
   191     /**
       
   192      * UniDataModelLoader object
       
   193      * Own
       
   194      */
       
   195     UniDataModelLoader* iDataModelPluginLoader;
       
   196 
       
   197     /**
       
   198      * Mms Data model plugin interface
       
   199      * Not Own
       
   200      */
       
   201     UniDataModelPluginInterface* iMmsDataPlugin;
       
   202 
       
   203     /**
       
   204      * BioMsg Data model plugin interface
       
   205      * Not Own
       
   206      */
       
   207     UniDataModelPluginInterface* iBioMsgPlugin;
       
   208     
       
   209     /*
       
   210      * SQL DB handle
       
   211      */
       
   212     RSqlDatabase iSqlDb;
       
   213 
       
   214     /*
       
   215      * DB open.
       
   216      */
       
   217     TBool iSqlDbOpen;
       
   218 
       
   219     /*
       
   220      *  preview-icon cache
       
   221      */
       
   222     QCache<int, HbIcon> previewIconCache;
       
   223 };
       
   224 
       
   225 #endif // CONVERSATIONS_MODEL_H