|
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 <QString.h> |
|
19 |
|
20 #include "cntimportsview.h" |
|
21 #include "cntglobal.h" |
|
22 |
|
23 #include "cntsimengine.h" |
|
24 |
|
25 #include <hbpushbutton.h> |
|
26 #include <hbaction.h> |
|
27 #include <hbview.h> |
|
28 #include <hbmenu.h> |
|
29 #include <hbframebackground.h> |
|
30 #include <QStandardItemModel> |
|
31 #include <hbmainwindow.h> |
|
32 #include <hblabel.h> |
|
33 #include <hblistview.h> |
|
34 #include <QTimer> |
|
35 #include <hbnotificationdialog.h> |
|
36 #include <hbmessagebox.h> |
|
37 #include <hbprogressbar.h> |
|
38 #include <QGraphicsLinearLayout> |
|
39 #include <hbframebackground.h> |
|
40 #include <hbabstractviewitem.h> |
|
41 #include <hbextendedlocale.h> |
|
42 #include <hbparameterlengthlimiter.h> |
|
43 #include <hblistviewitem.h> |
|
44 #include <hbstringutil.h> |
|
45 #include <QCoreApplication> |
|
46 #include <hbdevicenotificationdialog.h> |
|
47 #include <cntdebug.h> |
|
48 |
|
49 const char *CNT_IMPORT_UI_XML = ":/xml/contacts_sim.docml"; |
|
50 |
|
51 CntImportsView::CntImportsView() : mViewManager(0), |
|
52 mSimEngine(0), |
|
53 mListView(0), |
|
54 mView(0), |
|
55 mSoftkey(0), |
|
56 mModel(0), |
|
57 mImportSimPopup(0), |
|
58 mEngine(0) |
|
59 { |
|
60 CNT_ENTRY |
|
61 CNT_LOG_ARGS(QString("All bools reset")); |
|
62 bool ok = false; |
|
63 mDocumentLoader.load(CNT_IMPORT_UI_XML, &ok); |
|
64 |
|
65 if (ok) |
|
66 { |
|
67 mView = static_cast<HbView*>(mDocumentLoader.findWidget(QString("view"))); |
|
68 } |
|
69 else |
|
70 { |
|
71 qFatal("Unable to read :/xml/contacts_sim.docml"); |
|
72 } |
|
73 |
|
74 mSimEngine = new CntSimEngine(*this, *mView); |
|
75 |
|
76 //back button |
|
77 mSoftkey = new HbAction(Hb::BackNaviAction, mView); |
|
78 connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView())); |
|
79 connect(mSimEngine, SIGNAL(showNamesView()), this, SLOT(showPreviousView())); |
|
80 connect(mSimEngine, SIGNAL(closePopup()), this, SLOT(closeImportPopup())); |
|
81 CNT_EXIT |
|
82 |
|
83 } |
|
84 |
|
85 void CntImportsView::deactivate() |
|
86 { |
|
87 } |
|
88 |
|
89 |
|
90 CntImportsView::~CntImportsView() |
|
91 { |
|
92 CNT_ENTRY |
|
93 mView->deleteLater(); |
|
94 delete mModel; |
|
95 delete mSimEngine; |
|
96 CNT_EXIT |
|
97 } |
|
98 |
|
99 /*! |
|
100 Activates a previous view |
|
101 */ |
|
102 void CntImportsView::showPreviousView() |
|
103 { |
|
104 CNT_ENTRY |
|
105 CntViewParameters args; |
|
106 mViewManager->back(args); |
|
107 CNT_EXIT |
|
108 } |
|
109 |
|
110 void CntImportsView::closeImportPopup() |
|
111 { |
|
112 CNT_ENTRY |
|
113 if (mImportSimPopup != NULL) |
|
114 { |
|
115 mImportSimPopup->close(); |
|
116 mImportSimPopup = NULL; // Dilaog is deleted on close() |
|
117 } |
|
118 CNT_EXIT |
|
119 } |
|
120 |
|
121 /* |
|
122 Activates a default view |
|
123 */ |
|
124 void CntImportsView::activate(const CntViewParameters aArgs) |
|
125 { |
|
126 CNT_ENTRY |
|
127 Q_UNUSED(aArgs); |
|
128 //back button |
|
129 |
|
130 if (mView->navigationAction() != mSoftkey) |
|
131 { |
|
132 mView->setNavigationAction(mSoftkey); |
|
133 } |
|
134 |
|
135 mViewManager = &mEngine->viewManager(); |
|
136 QContactManager *ContactSymbianManager = &mEngine->contactManager(SYMBIAN_BACKEND); |
|
137 |
|
138 mModel = new QStandardItemModel(); |
|
139 |
|
140 mSimEngine->init(*mEngine); |
|
141 |
|
142 mListView = static_cast<HbListView*>(mDocumentLoader.findWidget(QString("listView"))); |
|
143 |
|
144 HbFrameBackground frame; |
|
145 frame.setFrameGraphicsName("qtg_fr_list_normal"); |
|
146 frame.setFrameType(HbFrameDrawer::NinePieces); |
|
147 mListView->itemPrototypes().first()->setDefaultFrame(frame); |
|
148 mListView->listItemPrototype()->setStretchingStyle(HbListViewItem::StretchLandscape); |
|
149 mListView->setUniformItemSizes(true); |
|
150 |
|
151 connect(mListView, SIGNAL(activated (const QModelIndex&)), |
|
152 this, SLOT(onListViewActivated(const QModelIndex&))); |
|
153 |
|
154 |
|
155 QStandardItem *importItem = new QStandardItem(); |
|
156 QStringList simList; |
|
157 |
|
158 mSimEngine->checkEntries(simList, *importItem); |
|
159 |
|
160 importItem->setData(simList, Qt::DisplayRole); |
|
161 importItem->setData(HbIcon("qtg_large_sim"), Qt::DecorationRole); |
|
162 |
|
163 mModel->insertRow(0,importItem); |
|
164 |
|
165 mListView->setModel(mModel); |
|
166 mListView->setSelectionMode(HbAbstractItemView::NoSelection); |
|
167 connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(userCancelsImport())); |
|
168 CNT_EXIT |
|
169 } |
|
170 |
|
171 |
|
172 void CntImportsView::onListViewActivated(const QModelIndex &index) |
|
173 { |
|
174 CNT_ENTRY |
|
175 int row = index.row(); |
|
176 if ( row == 0 ) // row 0 has "Imports from SIM" |
|
177 { |
|
178 if (!mSimEngine->startSimImport()) |
|
179 { |
|
180 //show error note |
|
181 mSimEngine->simInfoErrorMessage(KErrAccessDenied); |
|
182 } |
|
183 else |
|
184 { |
|
185 //start popup and progress |
|
186 showWaitNote(); |
|
187 } |
|
188 } |
|
189 CNT_EXIT |
|
190 |
|
191 } |
|
192 |
|
193 void CntImportsView::showWaitNote() |
|
194 { |
|
195 CNT_ENTRY |
|
196 mImportSimPopup = new HbDialog(); |
|
197 mImportSimPopup->setDismissPolicy(HbPopup::NoDismiss); |
|
198 mImportSimPopup->setTimeout(HbPopup::NoTimeout); |
|
199 mImportSimPopup->setBackgroundFaded(true); |
|
200 mImportSimPopup->setAttribute(Qt::WA_DeleteOnClose, true); |
|
201 |
|
202 HbLabel *headingLabel = new HbLabel(mImportSimPopup); |
|
203 headingLabel->setPlainText(hbTrId("txt_phob_title_import_contacts")); |
|
204 mImportSimPopup->setHeadingWidget(headingLabel); |
|
205 |
|
206 QGraphicsLinearLayout *containerLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
207 containerLayout->setContentsMargins(0, 0, 0, 0); |
|
208 containerLayout->setSpacing(10); |
|
209 |
|
210 HbLabel *icon = new HbLabel(mImportSimPopup); |
|
211 icon->setIcon(HbIcon("qtg_large_sim")); |
|
212 |
|
213 HbLabel *simText= new HbLabel(mImportSimPopup); |
|
214 simText->setPlainText(hbTrId("txt_phob_info_importing_contacts_from_sim")); |
|
215 simText->setTextWrapping(Hb::TextWordWrap); |
|
216 simText->setElideMode(Qt::ElideNone); |
|
217 |
|
218 HbProgressBar *progressBar = new HbProgressBar(mImportSimPopup); |
|
219 progressBar->setRange(0,0); |
|
220 |
|
221 HbPushButton *stopButton = new HbPushButton(mImportSimPopup); |
|
222 stopButton->setText(hbTrId("txt_phob_button_cancel")); |
|
223 connect(stopButton, SIGNAL(clicked()), mSimEngine, SLOT(stopSimImport())); |
|
224 |
|
225 QGraphicsLinearLayout *containerLayout1 = new QGraphicsLinearLayout(Qt::Horizontal); |
|
226 containerLayout1->addItem(icon); |
|
227 containerLayout1->addItem(simText); |
|
228 |
|
229 QGraphicsWidget *containerWidget = new QGraphicsWidget; |
|
230 containerLayout->addItem(containerLayout1); |
|
231 containerLayout->addItem(progressBar); |
|
232 containerLayout->addItem(stopButton); |
|
233 containerWidget->setLayout(containerLayout); |
|
234 mImportSimPopup->setContentWidget(containerWidget); |
|
235 mImportSimPopup->open(); |
|
236 CNT_EXIT |
|
237 } |
|
238 |
|
239 void CntImportsView::setPreferredDetails( QContact *aContact ) |
|
240 { |
|
241 CNT_ENTRY |
|
242 mSimEngine->setPreferredDetails(*aContact); |
|
243 CNT_EXIT |
|
244 } |
|
245 |
|
246 |
|
247 void CntImportsView::userCancelsImport() |
|
248 { |
|
249 CNT_ENTRY |
|
250 QString results; |
|
251 |
|
252 if(mSimEngine->userCancelsImport(results)) |
|
253 { |
|
254 HbDeviceNotificationDialog::notification(QString(),results); |
|
255 } |
|
256 CNT_EXIT |
|
257 } |
|
258 |
|
259 |
|
260 void CntImportsView::setListBoxItemText(QString& aPrimary, QString& aSecondary) |
|
261 { |
|
262 CNT_ENTRY |
|
263 QList<QStandardItem*> importItems = mModel->takeRow(0); |
|
264 QStandardItem* importItem = NULL; |
|
265 if (importItems.count() > 0) { |
|
266 importItem = importItems.at(0); |
|
267 } |
|
268 |
|
269 if (importItem != NULL) |
|
270 { |
|
271 QStringList simList; |
|
272 |
|
273 simList << aPrimary; |
|
274 simList << aSecondary; |
|
275 |
|
276 importItem->setData(simList, Qt::DisplayRole); |
|
277 importItem->setData(HbIcon("qtg_large_sim"), Qt::DecorationRole); |
|
278 mModel->insertRow(0, importItem); |
|
279 mListView->reset(); |
|
280 } |
|
281 CNT_EXIT |
|
282 } |
|
283 |
|
284 void CntImportsView::setListBoxItemEnabled(bool aEnabled) |
|
285 { |
|
286 CNT_ENTRY |
|
287 QList<QStandardItem*> importItems = mModel->takeRow(0); |
|
288 QStandardItem* importItem = NULL; |
|
289 if ( !importItems.isEmpty() ) |
|
290 { |
|
291 importItem = importItems.first(); |
|
292 } |
|
293 |
|
294 if (importItem != NULL) |
|
295 { |
|
296 importItem->setEnabled(aEnabled); |
|
297 } |
|
298 CNT_EXIT |
|
299 } |
|
300 |
|
301 QContactManager *CntImportsView::contactSymbianManager() |
|
302 { |
|
303 if (mSimEngine) |
|
304 { |
|
305 return mSimEngine->contactSymbianManager(); |
|
306 } |
|
307 |
|
308 return NULL; |
|
309 } |
|
310 |
|
311 // EOF |