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