qtcontactsmobility/examples/incomingcalls/qcontactlistmodel.h
changeset 25 76a2435edfd4
parent 24 0ba2181d7c28
child 27 de1630741fbe
equal deleted inserted replaced
24:0ba2181d7c28 25:76a2435edfd4
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #ifndef QCONTACTLISTMODEL_H
       
    44 #define QCONTACTLISTMODEL_H
       
    45 
       
    46 //
       
    47 //  W A R N I N G
       
    48 //  -------------
       
    49 //
       
    50 // This file is not part of the Qt API.  It exists purely as an
       
    51 // implementation detail.  This header file may change from version to
       
    52 // version without notice, or even be removed.
       
    53 //
       
    54 // We mean it.
       
    55 //
       
    56 
       
    57 #include "qtcontactsglobal.h"
       
    58 #include "qcontact.h"
       
    59 #include "qcontactphonenumber.h"
       
    60 
       
    61 #include <QAbstractListModel>
       
    62 #include <QSharedData>
       
    63 
       
    64 QTM_BEGIN_NAMESPACE
       
    65 class QContactManager;
       
    66 class QContactFetchRequest;
       
    67 class QContactLocalIdFetchRequest;
       
    68 QTM_END_NAMESPACE
       
    69 
       
    70 QTM_USE_NAMESPACE
       
    71 
       
    72 class QContactListModelPrivate;
       
    73 class QContactListModel : public QAbstractListModel
       
    74 {
       
    75     Q_OBJECT
       
    76 
       
    77 public:
       
    78     QContactListModel(QContactManager* manager = 0, int cacheSize = 50);
       
    79     QContactListModel(const QContactListModel& other);
       
    80     QContactListModel& operator=(const QContactListModel& other);
       
    81     ~QContactListModel();
       
    82 
       
    83     QContactManager* manager() const;
       
    84     void setManager(QContactManager* manager);
       
    85 
       
    86     int cacheSize() const;
       
    87     bool setCacheSize(int size);
       
    88 
       
    89     enum AsynchronousRequestPolicy {
       
    90         CancelOnCacheUpdatePolicy = 0,      // cancel old requests whenever a cache update should occur
       
    91         CancelOnCacheMissPolicy,            // cancel if old centrepoint outside current cache window
       
    92         CancelOnCompleteCacheMissPolicy,    // cancel if no overlap between request and current cache windows
       
    93         NeverCancelPolicy                   // never cancel old requests
       
    94     };
       
    95 
       
    96     AsynchronousRequestPolicy requestPolicy() const;
       
    97     void setRequestPolicy(AsynchronousRequestPolicy policy = CancelOnCacheMissPolicy);
       
    98 
       
    99     QString relevantDefinitionName() const;
       
   100     QString relevantFieldName() const;
       
   101     bool setRelevantDetailDefinitionAndFieldNames(const QString& definitionName = QContactPhoneNumber::DefinitionName, const QString& fieldName = QContactPhoneNumber::FieldNumber);
       
   102 
       
   103     enum ContactDataRole {
       
   104         DisplayLabelRole = Qt::DisplayRole,
       
   105         IdRole = Qt::UserRole,
       
   106         AvatarRole = Qt::UserRole+1,
       
   107         PresenceRole = Qt::UserRole+2,
       
   108         RelevantDataRole = Qt::UserRole+3
       
   109     };
       
   110 
       
   111     int rowCount (const QModelIndex& parent = QModelIndex()) const;
       
   112     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
       
   113     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
       
   114 
       
   115     bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
       
   116     bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
       
   117 
       
   118     int contactRow(const QContactLocalId& contactId) const;
       
   119     QContact contact(const QModelIndex& index) const;
       
   120 
       
   121 private slots:
       
   122     void contactFetchRequestProgress(QContactFetchRequest* request, bool appendOnly);
       
   123     void contactIdFetchRequestProgress(QContactLocalIdFetchRequest* request, bool appendOnly);
       
   124     void backendChanged();
       
   125 
       
   126 private:
       
   127     QSharedDataPointer<QContactListModelPrivate> d;
       
   128 };
       
   129 
       
   130 #endif