|
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 <QModelIndex> |
|
19 #include <QDateTime> |
|
20 #include <QDir> |
|
21 #include <hbdataform.h> |
|
22 #include <hbdataformmodel.h> |
|
23 #include <hbmainwindow.h> |
|
24 //#include <hbstyleoptioncommonnote.h> //<hbcommonnote.h> this new header compensate oldone ?? |
|
25 #include <HbDataFormModelItem.h> |
|
26 #include <hbdataformviewitem.h> |
|
27 #include <hblineedit.h> |
|
28 #include <HbComboBox.h> |
|
29 #include <HbPushButton.h> |
|
30 #include <HbAbstractButton.h> |
|
31 #include <HbLineEdit.h> |
|
32 #include <xqsettingsmanager.h> |
|
33 #include <xqsettingskey.h> |
|
34 #include <XQServiceUtil.h> |
|
35 |
|
36 #include <nsmloperatorerrorcrkeys.h> |
|
37 #include <DataSyncInternalPSKeys.h> |
|
38 #include "qtsyncstatusmodel.h" |
|
39 #include "qtsyncstatuslog.h" |
|
40 |
|
41 QtSyncStatusModel::QtSyncStatusModel(QtSyncStatusLog& log, HbDataForm *form, QObject *parent) |
|
42 :QObject(parent), |
|
43 mSettingsForm(form), |
|
44 mSettingsModel(0), |
|
45 mSyncLog(log) |
|
46 { |
|
47 connect(mSettingsForm, SIGNAL(activated(const QModelIndex)), |
|
48 this, SLOT(itemDisplayed(const QModelIndex))); |
|
49 |
|
50 mSettingsManager = new XQSettingsManager(this); |
|
51 mNsmlOpDsSyncErrorCode = new XQSettingsKey(XQSettingsKey::TargetCentralRepository, |
|
52 KCRUidOperatorDatasyncErrorKeys.iUid, KNsmlOpDsSyncErrorCode); |
|
53 mSettingsManager->startMonitoring(*mNsmlOpDsSyncErrorCode); |
|
54 mNsmlOpDsSyncProfUid = new XQSettingsKey(XQSettingsKey::TargetCentralRepository, |
|
55 KCRUidOperatorDatasyncErrorKeys.iUid, KNsmlOpDsSyncProfId); |
|
56 mSettingsManager->startMonitoring(*mNsmlOpDsSyncProfUid); |
|
57 mNsmlOpDsSyncType = new XQSettingsKey(XQSettingsKey::TargetCentralRepository, |
|
58 KCRUidOperatorDatasyncErrorKeys.iUid, KNsmlOpDsSyncType); |
|
59 mSettingsManager->startMonitoring(*mNsmlOpDsSyncType); |
|
60 mNsmlOpDsSyncInitiation = new XQSettingsKey(XQSettingsKey::TargetCentralRepository, |
|
61 KCRUidOperatorDatasyncErrorKeys.iUid, KNsmlOpDsSyncInitiation); |
|
62 mSettingsManager->startMonitoring(*mNsmlOpDsSyncInitiation); |
|
63 |
|
64 mDataSyncStatusKey = new XQSettingsKey(XQSettingsKey::TargetPublishAndSubscribe, |
|
65 KPSUidDataSynchronizationInternalKeys.iUid, KDataSyncStatus); |
|
66 |
|
67 connect(mSettingsManager, SIGNAL(valueChanged(const XQSettingsKey&, const QVariant&)), |
|
68 this, SLOT(valueChanged(const XQSettingsKey&, const QVariant&))); |
|
69 |
|
70 // Read the initial values from the cenrep |
|
71 QVariant value = mSettingsManager->readItemValue(*mNsmlOpDsSyncErrorCode); |
|
72 mSyncErrorCode = value.toUInt(); |
|
73 value = mSettingsManager->readItemValue(*mNsmlOpDsSyncProfUid); |
|
74 mSyncProfileUid = value.toUInt(); |
|
75 value = mSettingsManager->readItemValue(*mNsmlOpDsSyncType); |
|
76 mSyncType = value.toUInt(); |
|
77 value = mSettingsManager->readItemValue(*mNsmlOpDsSyncInitiation); |
|
78 mSyncInitiation = value.toUInt(); |
|
79 } |
|
80 |
|
81 QtSyncStatusModel::~QtSyncStatusModel() |
|
82 { |
|
83 delete mSettingsModel; |
|
84 delete mSettingsManager; |
|
85 delete mNsmlOpDsSyncErrorCode; |
|
86 delete mNsmlOpDsSyncProfUid; |
|
87 delete mNsmlOpDsSyncType; |
|
88 delete mNsmlOpDsSyncInitiation; |
|
89 delete mDataSyncStatusKey; |
|
90 } |
|
91 |
|
92 void QtSyncStatusModel::initModel() |
|
93 { |
|
94 // Remove the model. |
|
95 if (mSettingsForm->model()) { |
|
96 delete mSettingsForm->model(); |
|
97 mSettingsForm->setModel(0); |
|
98 mSettingsModel = 0; |
|
99 } |
|
100 |
|
101 mSettingsModel = new HbDataFormModel(); |
|
102 |
|
103 mNsmlOpDsSyncErrorCodeItem = new HbDataFormModelItem( |
|
104 HbDataFormModelItem::TextItem, QString( tr("Sync error code") ), 0); |
|
105 QString errorCode; |
|
106 errorCode.setNum(mSyncErrorCode); |
|
107 mNsmlOpDsSyncErrorCodeItem->setContentWidgetData( "text", errorCode ); |
|
108 mNsmlOpDsSyncErrorCodeItem->setContentWidgetData( QString("readOnly"), QString("false") ); |
|
109 mSettingsModel->appendDataFormItem(mNsmlOpDsSyncErrorCodeItem); |
|
110 |
|
111 mNsmlOpDsSyncProfUidItem = new HbDataFormModelItem( |
|
112 HbDataFormModelItem::TextItem, QString(tr("Sync profile ID")), 0); |
|
113 //HbDataFormModelItem::TextItem, QString(tr("Sync profile ID")), mSettingsModel->invisibleRootItem()); |
|
114 QString profileUId; |
|
115 profileUId.setNum(mSyncProfileUid); |
|
116 mNsmlOpDsSyncProfUidItem->setContentWidgetData( "text", profileUId ); |
|
117 mNsmlOpDsSyncProfUidItem->setContentWidgetData( QString("readOnly"), QString("false") ); |
|
118 mSettingsModel->appendDataFormItem(mNsmlOpDsSyncProfUidItem); |
|
119 |
|
120 QStringList syncTypes; |
|
121 syncTypes << tr("ESmlTwoWay") |
|
122 << tr("ESmlOneWayFromServer") |
|
123 << tr("ESmlOneWayFromClient") |
|
124 << tr("ESmlSlowSync") |
|
125 << tr("ESmlRefreshFromServer") |
|
126 << tr("ESmlRefreshFromClient"); |
|
127 |
|
128 mNsmlOpDsSyncTypeItem = new HbDataFormModelItem(); |
|
129 mNsmlOpDsSyncTypeItem->setType(HbDataFormModelItem::ComboBoxItem); |
|
130 mNsmlOpDsSyncTypeItem->setData(HbDataFormModelItem::LabelRole, QString(tr("Sync type"))); |
|
131 mNsmlOpDsSyncTypeItem->setContentWidgetData(QString("items"), syncTypes); |
|
132 mNsmlOpDsSyncTypeItem->setContentWidgetData(QString("currentIndex"), mSyncType); |
|
133 mSettingsModel->appendDataFormItem(mNsmlOpDsSyncTypeItem); |
|
134 |
|
135 QStringList syncInitiation; |
|
136 syncInitiation << tr("No sync ongoing") |
|
137 << tr("Client initiated") |
|
138 << tr("Server alerted"); |
|
139 |
|
140 mNsmlOpDsSyncInitiationItem = new HbDataFormModelItem(); |
|
141 mNsmlOpDsSyncInitiationItem->setType(HbDataFormModelItem::ComboBoxItem); |
|
142 mNsmlOpDsSyncInitiationItem->setData(HbDataFormModelItem::LabelRole, QString(tr("Sync initiation"))); |
|
143 mNsmlOpDsSyncInitiationItem->setContentWidgetData(QString("items"), syncInitiation); |
|
144 mNsmlOpDsSyncInitiationItem->setContentWidgetData(QString("currentIndex"), mSyncInitiation); |
|
145 mSettingsModel->appendDataFormItem(mNsmlOpDsSyncInitiationItem); |
|
146 |
|
147 mSettingsForm->setModel(mSettingsModel); |
|
148 } |
|
149 |
|
150 void QtSyncStatusModel::itemDisplayed(const QModelIndex &index) |
|
151 { |
|
152 //HbDataFormModelItem *data = static_cast<HbDataFormModelItem*>(index.internalPointer()); |
|
153 HbDataFormViewItem *viewItem = static_cast<HbDataFormViewItem*>( mSettingsForm->itemByIndex(index) ); |
|
154 |
|
155 switch (index.row()) |
|
156 { |
|
157 case 0: |
|
158 { |
|
159 HbWidget* contentWidget = viewItem->dataItemContentWidget(); |
|
160 mSyncErrorCodeEdit = static_cast<HbLineEdit *>(contentWidget); |
|
161 mSyncErrorCodeEdit->setInputMethodHints(Qt::ImhPreferNumbers); |
|
162 connect(mSyncErrorCodeEdit, SIGNAL(editingFinished()), |
|
163 this, SLOT(handleSyncMLErrorCodeChangeFinished())); |
|
164 break; |
|
165 } |
|
166 |
|
167 case 1: |
|
168 { |
|
169 HbWidget* contentWidget = viewItem->dataItemContentWidget(); |
|
170 mSyncProfileUidEdit = static_cast<HbLineEdit *>(contentWidget); |
|
171 mSyncProfileUidEdit->setInputMethodHints(Qt::ImhPreferNumbers); |
|
172 connect(mSyncProfileUidEdit, SIGNAL(editingFinished()), |
|
173 this, SLOT(handleProfileUidChangeFinished())); |
|
174 break; |
|
175 } |
|
176 |
|
177 case 2: |
|
178 { |
|
179 HbWidget* contentWidget = viewItem->dataItemContentWidget(); |
|
180 mmSyncTypeComboBox = static_cast<HbComboBox *>(contentWidget); |
|
181 connect(mmSyncTypeComboBox, SIGNAL(currentIndexChanged(int)), |
|
182 this, SLOT(handleSyncTypeChange(int))); |
|
183 break; |
|
184 } |
|
185 |
|
186 case 3: |
|
187 { |
|
188 HbWidget* contentWidget = viewItem->dataItemContentWidget(); |
|
189 mSyncInitiationComboBox = static_cast<HbComboBox *>(contentWidget); |
|
190 connect(mSyncInitiationComboBox, SIGNAL(currentIndexChanged(int)), |
|
191 this, SLOT(handleSyncInitiationChange(int))); |
|
192 break; |
|
193 } |
|
194 |
|
195 default: |
|
196 break; |
|
197 } |
|
198 } |
|
199 |
|
200 void QtSyncStatusModel::handleSyncErrorCodeChangeFinished() |
|
201 { |
|
202 mSettingsManager->writeItemValue(*mNsmlOpDsSyncErrorCode, mSyncErrorCodeEdit->text().toInt()); |
|
203 } |
|
204 |
|
205 void QtSyncStatusModel::handleProfileUidChangeFinished() |
|
206 { |
|
207 mSettingsManager->writeItemValue(*mNsmlOpDsSyncProfUid, mSyncProfileUidEdit->text().toInt()); |
|
208 } |
|
209 |
|
210 void QtSyncStatusModel::handleSyncTypeChange(int index) |
|
211 { |
|
212 mSettingsManager->writeItemValue(*mNsmlOpDsSyncType, index); |
|
213 } |
|
214 |
|
215 void QtSyncStatusModel::handleSyncInitiationChange(int index) |
|
216 { |
|
217 mSettingsManager->writeItemValue(*mNsmlOpDsSyncInitiation, index); |
|
218 } |
|
219 |
|
220 void QtSyncStatusModel::valueChanged(const XQSettingsKey& key, const QVariant& value) |
|
221 { |
|
222 QDateTime dt = QDateTime::currentDateTime(); |
|
223 QString logLine; |
|
224 |
|
225 unsigned long int crKey = key.key(); |
|
226 if (crKey == mNsmlOpDsSyncErrorCode->key()) { |
|
227 mSyncErrorCode = value.toUInt(); |
|
228 QString errorCode; |
|
229 errorCode.setNum(mSyncErrorCode); |
|
230 mNsmlOpDsSyncErrorCodeItem->setContentWidgetData( "text", errorCode ); |
|
231 logLine.append("[" + dt.toString("dd.MM.yyyy hh:mm:ss") + "] [SyncErrCode: " + errorCode + "]\r\n"); |
|
232 } |
|
233 else if (crKey == mNsmlOpDsSyncProfUid->key()) { |
|
234 mSyncProfileUid = value.toUInt(); |
|
235 QString profileUId; |
|
236 profileUId.setNum(mSyncProfileUid); |
|
237 mNsmlOpDsSyncProfUidItem->setContentWidgetData( "text", profileUId ); |
|
238 logLine.append("[" + dt.toString("dd.MM.yyyy hh:mm:ss") + "] [SyncProfileId: " + profileUId + "]\r\n"); |
|
239 } |
|
240 else if (crKey == mNsmlOpDsSyncType->key()) { |
|
241 mSyncType = value.toUInt(); |
|
242 QString syncType; |
|
243 syncType.setNum(mSyncType); |
|
244 mNsmlOpDsSyncTypeItem->setContentWidgetData(QString("currentIndex"), mSyncType); |
|
245 logLine.append("[" + dt.toString("dd.MM.yyyy hh:mm:ss") + "] [SyncType: " + syncType + "]\r\n"); |
|
246 } |
|
247 else if (crKey == mNsmlOpDsSyncInitiation->key()) { |
|
248 mSyncInitiation = value.toUInt(); |
|
249 QString syncInitiation; |
|
250 syncInitiation.setNum(mSyncInitiation); |
|
251 mNsmlOpDsSyncInitiationItem->setContentWidgetData(QString("currentIndex"), mSyncInitiation); |
|
252 logLine.append("[" + dt.toString("dd.MM.yyyy hh:mm:ss") + "] [SyncInitiation: " + syncInitiation + "]\r\n"); |
|
253 } |
|
254 mSyncLog.write(logLine); |
|
255 XQServiceUtil::toBackground( false ); |
|
256 } |
|
257 |
|
258 void QtSyncStatusModel::clearSyncLog() |
|
259 { |
|
260 mSyncLog.clear(); |
|
261 } |
|
262 |
|
263 |
|
264 void QtSyncStatusModel::publishSyncStatusKey() |
|
265 { |
|
266 mSettingsManager->writeItemValue(*mDataSyncStatusKey,EDataSyncRunning12); |
|
267 mSettingsManager->writeItemValue(*mDataSyncStatusKey,EDataSyncNotRunning); |
|
268 } |
|
269 |
|
270 // End of file |