email_plat/contact_history_model_api/inc/nmcontacthistorymodel.h
changeset 75 47d84de1c893
child 74 6c59112cfd31
equal deleted inserted replaced
72:64e38f08e49c 75:47d84de1c893
       
     1 /*
       
     2 * Copyright (c) 2010 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: Public declaration of Contact History Model API
       
    15 *
       
    16 */
       
    17 #ifndef NMCONTACTHISTORYMODEL_H
       
    18 #define NMCONTACTHISTORYMODEL_H
       
    19 
       
    20 #include <QAbstractListModel>
       
    21 #include <QSharedDataPointer>
       
    22 
       
    23 #include "nmcontacthistorymodelcommon.h"
       
    24 
       
    25 // NmContactHistoryModelSubItem - display name is one item, email address/phone number another
       
    26 class NmContactHistoryModelSubItem
       
    27 {
       
    28 public:
       
    29 
       
    30 inline NmContactHistoryModelSubItem()
       
    31 {
       
    32 }
       
    33 
       
    34 inline ~NmContactHistoryModelSubItem()
       
    35 {
       
    36 }
       
    37     // email address, or concatenated firstName+' '+lastName.
       
    38     QString mItemText;
       
    39     // amount of items in mMatchingRanges is 2*mItemTexts.length() because for each text there is begin/end index
       
    40     // TODO: Fix above^ always two indeces
       
    41     // for example "Ville Virtanen" with query "vi" returns indeces 0,1,6,7
       
    42     QList<int> mMatchingRanges;
       
    43 };
       
    44 
       
    45 class NmContactHistoryModelPrivate;
       
    46 class NmContactHistoryModelItemData;
       
    47 
       
    48 class NMCHMAPI_EXPORT NmContactHistoryModelItem
       
    49 {
       
    50 public:
       
    51     NmContactHistoryModelItem();
       
    52     NmContactHistoryModelItem(const NmContactHistoryModelItem &other);
       
    53     ~NmContactHistoryModelItem();
       
    54 
       
    55 public:
       
    56     // contact id is 0xDEAD if not associated with a contact item
       
    57     unsigned int contactId() const;
       
    58 
       
    59     void setContactId(unsigned int contactId);
       
    60 
       
    61     int subItemCount() const;
       
    62 
       
    63     NmContactHistoryModelSubItem subItemAt(int index) const;
       
    64 
       
    65     // First entry is display name, second email address.
       
    66     QList<NmContactHistoryModelSubItem> subEntries() const;
       
    67 
       
    68     void appendSubItem(NmContactHistoryModelSubItem entry);
       
    69 
       
    70 private:
       
    71      //
       
    72     QSharedDataPointer<NmContactHistoryModelItemData> d;
       
    73 };
       
    74 Q_DECLARE_METATYPE(NmContactHistoryModelItem)
       
    75 
       
    76 /**
       
    77  * Model for contact history queries.
       
    78  *
       
    79  */
       
    80 class NMCHMAPI_EXPORT NmContactHistoryModel : public QAbstractListModel
       
    81 {
       
    82     Q_OBJECT
       
    83 
       
    84 public: // The exported API
       
    85 
       
    86     /**
       
    87      * Constructor
       
    88      * @param modelType
       
    89      */
       
    90     explicit NmContactHistoryModel(
       
    91         const NmContactHistoryModelType modelType);
       
    92 
       
    93     /**
       
    94      * Destructor
       
    95      */
       
    96     ~NmContactHistoryModel();
       
    97 
       
    98 public: // From QAbstractItemModel
       
    99 
       
   100     /**
       
   101      * Get number of rows currently in the model.
       
   102      * @return number of rows
       
   103      */
       
   104     virtual int rowCount(const QModelIndex &parent) const;
       
   105 
       
   106     /**
       
   107      * Get various data from the model. Fetched data type is defined
       
   108      * by role input parameter. Only Qt::DisplayRole is supported.
       
   109      */
       
   110     virtual QVariant data(const QModelIndex &index, int role) const;
       
   111 
       
   112 signals:
       
   113 
       
   114     /**
       
   115      * Signaled once model is ready.
       
   116      * @param err, 0 if building model was success
       
   117      */
       
   118     void modelCompleted(int err);
       
   119 
       
   120 public slots:
       
   121 
       
   122     // TODO: query could keep previous query in order to check if results will only get narrowed (a char is appended)
       
   123     void query(const QString &query);
       
   124 
       
   125 private slots:
       
   126 
       
   127     /**
       
   128      * Signaled once query is completed, emits modelCompleted.
       
   129      * @param err, 0 if building model was success
       
   130      */
       
   131     void handleQueryCompleted(int err);
       
   132 
       
   133 private:
       
   134     /*
       
   135      * Private Implementation
       
   136      * Own
       
   137      */
       
   138     NmContactHistoryModelPrivate *d_ptr;
       
   139 
       
   140 };
       
   141 
       
   142 #endif //NMCONTACTHISTORYMODEL_H