|
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 implementation of Contact History Model API |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QList> |
|
19 |
|
20 #include "nmcontacthistorymodel.h" |
|
21 #include "nmcontacthistorymodel_p.h" |
|
22 |
|
23 // -------------------------------------------------------------------------- |
|
24 // Start of implementation (NmContactHistoryModel) |
|
25 // -------------------------------------------------------------------------- |
|
26 /*! |
|
27 Constructor for NmContactHistoryModel |
|
28 |
|
29 \param modelType ModelType to be used, Email / Messaging |
|
30 */ |
|
31 NmContactHistoryModel::NmContactHistoryModel( |
|
32 const NmContactHistoryModelType modelType) |
|
33 { |
|
34 d_ptr = new NmContactHistoryModelPrivate(modelType); |
|
35 Q_CHECK_PTR(d_ptr); |
|
36 |
|
37 QObject::connect(d_ptr, SIGNAL(queryCompleted(int)), this, |
|
38 SLOT(handleQueryCompleted(int))); |
|
39 } |
|
40 |
|
41 /*! |
|
42 Destructor of NmContactHistoryModel |
|
43 */ |
|
44 NmContactHistoryModel::~NmContactHistoryModel() |
|
45 { |
|
46 delete d_ptr; |
|
47 } |
|
48 |
|
49 /*! |
|
50 Queries contact databases from private implementation |
|
51 |
|
52 \param query String to be queried. |
|
53 */ |
|
54 void NmContactHistoryModel::query(const QString &query) |
|
55 { |
|
56 d_ptr->queryDatabases(query); |
|
57 } |
|
58 |
|
59 /*! |
|
60 Signaled once query is completed, emits modelCompleted. |
|
61 Private Slot. |
|
62 |
|
63 \param err, 0 if building model was success |
|
64 */ |
|
65 void NmContactHistoryModel::handleQueryCompleted(int err) |
|
66 { |
|
67 |
|
68 int lastUpdateIndex = (d_ptr->mPrivateItemList.count())-1; |
|
69 |
|
70 if (lastUpdateIndex != -1) |
|
71 { |
|
72 // Notify views that we are about to change model data. |
|
73 beginInsertRows(QModelIndex(),0,lastUpdateIndex); |
|
74 d_ptr->refreshDataModel(); |
|
75 endInsertRows(); |
|
76 |
|
77 // Emit dataChanged(); |
|
78 bool validIndex = hasIndex ( lastUpdateIndex, 0 ); |
|
79 |
|
80 if (validIndex) |
|
81 { |
|
82 dataChanged(index(0,0), index(lastUpdateIndex,0)); |
|
83 } |
|
84 } |
|
85 |
|
86 emit modelCompleted(err); |
|
87 } |
|
88 |
|
89 /*! |
|
90 Returns the number of rows under the given parent. |
|
91 |
|
92 From QAbstractItemModel |
|
93 */ |
|
94 int NmContactHistoryModel::rowCount(const QModelIndex &parent) const |
|
95 { |
|
96 return d_ptr->rowCount(parent); |
|
97 } |
|
98 |
|
99 /*! |
|
100 Returns the data stored under the given role for the item referred |
|
101 to by the index. |
|
102 |
|
103 From QAbstractItemModel |
|
104 */ |
|
105 QVariant NmContactHistoryModel::data(const QModelIndex &index, int role) const |
|
106 { |
|
107 return d_ptr->data(index, role); |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // End of implementation (NmContactHistoryModel) |
|
112 // -------------------------------------------------------------------------- |
|
113 |