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 #include "cnthistorymodel_p.h" |
|
19 #include "cnthistorymodel.h" |
|
20 #include "cntdebug.h" |
|
21 |
|
22 /*! |
|
23 * Construct a new CntHistoryModel object to communicate |
|
24 * with the conversations and logs databases. |
|
25 * |
|
26 * \param contactId History specific to this contact is cached. |
|
27 * If no contact is specified all the call logs and conversation |
|
28 * history from all contacts will be cached. |
|
29 */ |
|
30 CntHistoryModel::CntHistoryModel(QContactLocalId contactId, |
|
31 QContactManager* manager, |
|
32 QObject *parent) |
|
33 : QAbstractListModel(parent), |
|
34 d_ptr(new CntHistoryModelPrivate(contactId, manager)) |
|
35 { |
|
36 CNT_ENTRY |
|
37 |
|
38 Q_D(CntHistoryModel); |
|
39 d->q_ptr = this; |
|
40 |
|
41 CNT_EXIT |
|
42 } |
|
43 |
|
44 CntHistoryModel::~CntHistoryModel() |
|
45 { |
|
46 CNT_ENTRY |
|
47 |
|
48 Q_D(CntHistoryModel); |
|
49 delete d; |
|
50 |
|
51 CNT_EXIT |
|
52 } |
|
53 |
|
54 /*! |
|
55 * Return the data to be used by the view or delegates for a particular |
|
56 * item and role. |
|
57 * |
|
58 * \param index The index of the item to return data about. |
|
59 * \param role The data should be relevant to this particular purpose. |
|
60 * \return QVariant The data for the specified index and role. |
|
61 */ |
|
62 QVariant CntHistoryModel::data(const QModelIndex& index, int role) const |
|
63 { |
|
64 Q_D(const CntHistoryModel); |
|
65 return d->data(index, role); |
|
66 } |
|
67 |
|
68 /*! |
|
69 * Get the number of rows (conversations) in this model. |
|
70 * |
|
71 * \param parent Optional parent index value. |
|
72 * \return Number of rows in this model. |
|
73 */ |
|
74 int CntHistoryModel::rowCount(const QModelIndex& parent) const |
|
75 { |
|
76 Q_D(const CntHistoryModel); |
|
77 return d->rowCount(parent); |
|
78 } |
|
79 |
|
80 /*! |
|
81 * Clear history from the database. If the history cached |
|
82 * is specific to one contact, only that history is cleared. |
|
83 * |
|
84 */ |
|
85 void CntHistoryModel::clearHistory() |
|
86 { |
|
87 CNT_ENTRY |
|
88 |
|
89 Q_D(CntHistoryModel); |
|
90 d->clearHistory(); |
|
91 |
|
92 CNT_EXIT |
|
93 } |
|
94 |
|
95 /*! |
|
96 * Mark all the conversations in the view as seen. |
|
97 * |
|
98 */ |
|
99 void CntHistoryModel::markAllAsSeen() |
|
100 { |
|
101 CNT_ENTRY |
|
102 |
|
103 Q_D(CntHistoryModel); |
|
104 d->markAllAsSeen(); |
|
105 |
|
106 CNT_EXIT |
|
107 } |
|
108 |
|
109 /*! |
|
110 * Sort items in the model and refresh the view |
|
111 * |
|
112 * \param order Order to sort the list items. |
|
113 */ |
|
114 void CntHistoryModel::sortAndRefresh(Qt::SortOrder order) |
|
115 { |
|
116 CNT_ENTRY_ARGS(order) |
|
117 |
|
118 Q_D(CntHistoryModel); |
|
119 |
|
120 doBeginResetModel(); |
|
121 d->sort(order); |
|
122 doEndResetModel(); |
|
123 |
|
124 CNT_EXIT |
|
125 } |
|
126 |
|
127 void CntHistoryModel::doBeginInsertRows(const QModelIndex &parent, int first, int last) |
|
128 { |
|
129 CNT_ENTRY_ARGS(parent << first << last) |
|
130 |
|
131 beginInsertRows(parent, first, last); |
|
132 |
|
133 CNT_EXIT |
|
134 } |
|
135 |
|
136 void CntHistoryModel::doEndInsertRows() |
|
137 { |
|
138 CNT_ENTRY |
|
139 |
|
140 endInsertRows(); |
|
141 |
|
142 CNT_EXIT |
|
143 } |
|
144 |
|
145 void CntHistoryModel::doBeginRemoveRows(const QModelIndex &parent, int first, int last) |
|
146 { |
|
147 CNT_ENTRY_ARGS(parent << first << last) |
|
148 |
|
149 beginRemoveRows(parent, first, last); |
|
150 |
|
151 CNT_EXIT |
|
152 } |
|
153 |
|
154 void CntHistoryModel::doEndRemoveRows() |
|
155 { |
|
156 CNT_ENTRY |
|
157 |
|
158 endRemoveRows(); |
|
159 |
|
160 CNT_EXIT |
|
161 } |
|
162 |
|
163 void CntHistoryModel::doBeginResetModel() |
|
164 { |
|
165 CNT_ENTRY |
|
166 |
|
167 beginResetModel(); |
|
168 |
|
169 CNT_EXIT |
|
170 } |
|
171 |
|
172 void CntHistoryModel::doEndResetModel() |
|
173 { |
|
174 CNT_ENTRY |
|
175 |
|
176 endResetModel(); |
|
177 |
|
178 CNT_EXIT |
|
179 } |
|
180 |
|
181 void CntHistoryModel::doDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) |
|
182 { |
|
183 CNT_ENTRY_ARGS(topLeft << bottomRight) |
|
184 |
|
185 emit dataChanged(topLeft, bottomRight); |
|
186 |
|
187 CNT_EXIT |
|
188 } |
|