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 * |
|
15 * Description: |
|
16 * The header file of the back up widget of file manager |
|
17 */ |
|
18 |
|
19 #include "fmbackupwidget.h" |
|
20 #include "fmbackupsettings.h" |
|
21 #include "fmdlgutils.h" |
|
22 #include "fmviewmanager.h" |
|
23 #include "fmoperationservice.h" |
|
24 #include "fmbkupengine.h" |
|
25 #include "fmbackuprestorehandler.h" |
|
26 #include "fmutils.h" |
|
27 |
|
28 |
|
29 #include <QGraphicsLinearLayout> |
|
30 #include <QDir> |
|
31 |
|
32 #include <hbdataform.h> |
|
33 #include <hbdataformmodel.h> |
|
34 #include <hbdataformmodelitem.h> |
|
35 #include <hbdataformviewitem.h> |
|
36 |
|
37 |
|
38 FmBackupWidget::FmBackupWidget( QGraphicsItem *parent ) |
|
39 : HbWidget( parent ) |
|
40 { |
|
41 init(); |
|
42 } |
|
43 |
|
44 FmBackupWidget::~FmBackupWidget() |
|
45 { |
|
46 mDataForm->setModel( 0 ); |
|
47 delete mModel; |
|
48 } |
|
49 |
|
50 |
|
51 void FmBackupWidget::on_list_activated( const QModelIndex &index ) |
|
52 { |
|
53 // change item data when receive activated signal |
|
54 HbDataFormModelItem *item = mModel->itemFromIndex(index); |
|
55 if( item == mContentsItem ){ |
|
56 emit changeContents(); |
|
57 } else if( item == mTargetItem ){ |
|
58 emit changeTargetDrive(); |
|
59 } else if( item == mSchedulingItem ){ |
|
60 emit changeScheduling(); |
|
61 } else if( item == mWeekdayItem ){ |
|
62 emit changeWeekday(); |
|
63 } else if( item == mTimeItem ){ |
|
64 emit changeTime(); |
|
65 } |
|
66 } |
|
67 |
|
68 void FmBackupWidget::init() |
|
69 { |
|
70 QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout( this ); |
|
71 vLayout->setOrientation( Qt::Vertical ); |
|
72 |
|
73 |
|
74 mModel = new HbDataFormModel(); |
|
75 initModel(); |
|
76 |
|
77 mDataForm = new HbDataForm( this ); |
|
78 mDataForm->setModel( mModel ); |
|
79 vLayout->addItem( mDataForm ); |
|
80 |
|
81 connect( mDataForm, SIGNAL( activated( const QModelIndex & ) ), |
|
82 this, SLOT( on_list_activated( const QModelIndex & ) ) ); |
|
83 |
|
84 connect( this, SIGNAL( doModelRefresh() ), |
|
85 this, SLOT( refreshModel() ), Qt::QueuedConnection ); |
|
86 |
|
87 connect( this, SIGNAL(changeContents()), this, SLOT(on_changeContents()), Qt::QueuedConnection); |
|
88 connect( this, SIGNAL(changeScheduling()), this, SLOT(on_changeScheduling()), Qt::QueuedConnection); |
|
89 connect( this, SIGNAL(changeWeekday()), this, SLOT(on_changeWeekday()), Qt::QueuedConnection); |
|
90 connect( this, SIGNAL(changeTime()), this, SLOT(on_changeTime()), Qt::QueuedConnection); |
|
91 connect( this, SIGNAL(changeTargetDrive()), this, SLOT(on_changeTargetDrive()), Qt::QueuedConnection); |
|
92 |
|
93 //mBackupSettings = new FmBackupSettings(); |
|
94 mBackupSettings = FmViewManager::viewManager()->operationService()->backupRestoreHandler()->bkupEngine()->BackupSettingsL(); |
|
95 mBackupSettings->load(); |
|
96 |
|
97 emit doModelRefresh(); |
|
98 |
|
99 } |
|
100 |
|
101 void FmBackupWidget::expandAllGroup() |
|
102 { |
|
103 FM_LOG( QString( "function expandAllGroup start" ) ); |
|
104 |
|
105 mDataForm->setModel( 0 ); |
|
106 mDataForm->setModel( mModel ); |
|
107 |
|
108 HbDataFormViewItem *itemScheduling = |
|
109 (HbDataFormViewItem *)(mDataForm->itemByIndex(mModel->indexFromItem(mSchedulingGroup))); |
|
110 if( itemScheduling ){ |
|
111 FM_LOG( QString( "expand itemScheduling start" ) ); |
|
112 itemScheduling->setExpanded( true ); |
|
113 FM_LOG( QString( "expand itemScheduling end" ) ); |
|
114 } |
|
115 |
|
116 HbDataFormViewItem *itemGroup = |
|
117 (HbDataFormViewItem *)(mDataForm->itemByIndex(mModel->indexFromItem(mContentsGroup))); |
|
118 if( itemGroup ){ |
|
119 FM_LOG( QString( "expand itemGroup start" ) ); |
|
120 itemGroup->setExpanded( true ); |
|
121 FM_LOG( QString( "expand itemGroup end" ) ); |
|
122 } |
|
123 FM_LOG( QString( "function expandAllGroup end" ) ); |
|
124 } |
|
125 |
|
126 void FmBackupWidget::initModel() |
|
127 { |
|
128 mContentsGroup = mModel->appendDataFormGroup( |
|
129 QString( hbTrId( "Contents" ) ), mModel->invisibleRootItem()); |
|
130 |
|
131 mContentsItem = mModel->appendDataFormItem( |
|
132 HbDataFormModelItem::TextItem, QString( "" ), mContentsGroup ); |
|
133 mContentsItem->setContentWidgetData( QString("readOnly"), QString("true") ); |
|
134 mContentsItem->setContentWidgetData( QString("objectName"), QString("backupContentItem") ); |
|
135 |
|
136 mTargetItem = mModel->appendDataFormItem( |
|
137 HbDataFormModelItem::TextItem, QString( "" ), mContentsGroup ); |
|
138 mTargetItem->setContentWidgetData( QString("readOnly"), QString("true") ); |
|
139 mTargetItem->setContentWidgetData( QString("objectName"), QString("backupTargetItem") ); |
|
140 |
|
141 mSchedulingGroup = mModel->appendDataFormGroup( |
|
142 QString( hbTrId( "Scheduling" ) ), mModel->invisibleRootItem()); |
|
143 |
|
144 mSchedulingItem = mModel->appendDataFormItem( |
|
145 HbDataFormModelItem::TextItem, QString( "" ), mSchedulingGroup ); |
|
146 mSchedulingItem->setContentWidgetData( QString("readOnly"), QString("true") ); |
|
147 mSchedulingItem->setContentWidgetData( QString("objectName"), QString("backupSchedulingItem") ); |
|
148 |
|
149 mWeekdayItem = mModel->appendDataFormItem( |
|
150 HbDataFormModelItem::TextItem, QString( "" ), mSchedulingGroup ); |
|
151 mWeekdayItem->setContentWidgetData( QString("readOnly"), QString("true") ); |
|
152 mWeekdayItem->setContentWidgetData( QString("objectName"), QString("backupWeekdayItem") ); |
|
153 |
|
154 mTimeItem = mModel->appendDataFormItem( |
|
155 HbDataFormModelItem::TextItem, QString( "" ), mSchedulingGroup ); |
|
156 mTimeItem->setContentWidgetData( QString("readOnly"), QString("true") ); |
|
157 mTimeItem->setContentWidgetData( QString("objectName"), QString("backupTimeItem") ); |
|
158 |
|
159 mLastBackupDateItem = mModel->appendDataFormItem( |
|
160 HbDataFormModelItem::TextItem, QString( ( "" )), mModel->invisibleRootItem() ); |
|
161 mLastBackupDateItem->setContentWidgetData( QString("readOnly"), QString("true") ); |
|
162 mLastBackupDateItem->setContentWidgetData( QString("objectName"), QString("backupLastBackupDateItem") ); |
|
163 } |
|
164 |
|
165 |
|
166 |
|
167 void FmBackupWidget::refreshModel() |
|
168 { |
|
169 mDataForm->setModel( 0 ); |
|
170 |
|
171 mBackupSettings->load(); |
|
172 |
|
173 int index = 0; |
|
174 |
|
175 index = mSchedulingGroup->indexOf( mWeekdayItem ); |
|
176 if( index >=0 ){ |
|
177 mSchedulingGroup->removeChild( index ); |
|
178 mWeekdayItem = 0; |
|
179 } |
|
180 |
|
181 index = mSchedulingGroup->indexOf( mTimeItem ); |
|
182 if( index >=0 ){ |
|
183 mSchedulingGroup->removeChild( index ); |
|
184 mTimeItem = 0; |
|
185 } |
|
186 |
|
187 index = mContentsGroup->indexOf( mTargetItem ); |
|
188 if( index >=0 ){ |
|
189 mContentsGroup->removeChild( index ); |
|
190 mTargetItem = 0; |
|
191 } |
|
192 |
|
193 QList< FmBackupEntry* > backupEntryList = mBackupSettings->backupEntryList(); |
|
194 |
|
195 QList< FmBackupEntry* >::iterator it; |
|
196 |
|
197 for ( it = backupEntryList.begin(); it != backupEntryList.end(); ++it ){ |
|
198 |
|
199 int type = ( *it )->type(); |
|
200 |
|
201 QString title = ( *it )->title(); |
|
202 QString tips = ( *it )->tips(); |
|
203 |
|
204 switch ( type ) |
|
205 { |
|
206 case FmBackupEntry::EContents: |
|
207 { |
|
208 mContentsItem->setLabel(title); |
|
209 mContentsItem->setContentWidgetData( QString("text"), tips ); |
|
210 break; |
|
211 } |
|
212 case FmBackupEntry::ETarget: |
|
213 { |
|
214 mTargetItem = mModel->appendDataFormItem( |
|
215 HbDataFormModelItem::TextItem, QString( "" ), mContentsGroup ); |
|
216 mTargetItem->setContentWidgetData( QString("readOnly"), QString("true") ); |
|
217 mTargetItem->setLabel(title); |
|
218 mTargetItem->setContentWidgetData( QString("text"), tips ); |
|
219 break; |
|
220 } |
|
221 case FmBackupEntry::EScheduling: |
|
222 { |
|
223 mSchedulingItem->setLabel(title); |
|
224 mSchedulingItem->setContentWidgetData( QString("text"), tips ); |
|
225 break; |
|
226 } |
|
227 case FmBackupEntry::EWeekday: |
|
228 { |
|
229 mWeekdayItem = mModel->appendDataFormItem( |
|
230 HbDataFormModelItem::TextItem, QString( "" ), mSchedulingGroup ); |
|
231 mWeekdayItem->setContentWidgetData( QString("readOnly"), QString("true") ); |
|
232 mWeekdayItem->setLabel(title); |
|
233 mWeekdayItem->setContentWidgetData( QString("text"), tips ); |
|
234 break; |
|
235 } |
|
236 case FmBackupEntry::ETime: |
|
237 { |
|
238 mTimeItem = mModel->appendDataFormItem( |
|
239 HbDataFormModelItem::TextItem, QString( "" ), mSchedulingGroup ); |
|
240 mTimeItem->setContentWidgetData( QString("readOnly"), QString("true") ); |
|
241 mTimeItem->setLabel(title); |
|
242 mTimeItem->setContentWidgetData( QString("text"), tips ); |
|
243 break; |
|
244 } |
|
245 case FmBackupEntry::EBackupdate: |
|
246 { |
|
247 mLastBackupDateItem->setContentWidgetData( QString("text"), tips ); |
|
248 break; |
|
249 } |
|
250 } |
|
251 } |
|
252 |
|
253 mDataForm->setModel( mModel ); |
|
254 |
|
255 expandAllGroup(); |
|
256 } |
|
257 |
|
258 void FmBackupWidget::on_changeContents() |
|
259 { |
|
260 |
|
261 QString title = mContentsItem->label(); |
|
262 QStringList queryStringList; |
|
263 quint32 contentMask = FmBackupSettings::EFileManagerBackupContentAll; |
|
264 while ( contentMask <= FmBackupSettings::EFileManagerBackupContentLast) |
|
265 { |
|
266 queryStringList.push_back( mBackupSettings->contentToString( contentMask ) ); |
|
267 contentMask = contentMask << 1; |
|
268 } |
|
269 quint32 select = mBackupSettings->content(); |
|
270 if( FmDlgUtils::showMultiSettingQuery( title, queryStringList, select, 0 ) ) |
|
271 { |
|
272 mBackupSettings->setContent( select ); |
|
273 emit doModelRefresh(); |
|
274 } |
|
275 |
|
276 } |
|
277 |
|
278 |
|
279 void FmBackupWidget::on_changeScheduling() |
|
280 { |
|
281 QString title = mSchedulingItem->label(); |
|
282 QStringList queryStringList; |
|
283 |
|
284 FmBackupSettings::TFileManagerBackupSchedule schedule = FmBackupSettings::EFileManagerBackupScheduleNever; |
|
285 while ( schedule <= FmBackupSettings::EFileManagerBackupScheduleWeekly ) |
|
286 { |
|
287 queryStringList.push_back( mBackupSettings->schedulingToString( schedule ) ); |
|
288 schedule = FmBackupSettings::TFileManagerBackupSchedule(((int)schedule)+1); |
|
289 } |
|
290 |
|
291 // adjust index offset against monday. |
|
292 int selectIndex = mBackupSettings->scheduling() - FmBackupSettings::EFileManagerBackupScheduleNever; |
|
293 if( FmDlgUtils::showSingleSettingQuery( title, queryStringList, selectIndex ) ) |
|
294 { |
|
295 selectIndex += FmBackupSettings::EFileManagerBackupScheduleNever; |
|
296 mBackupSettings->setScheduling( ( FmBackupSettings::TFileManagerBackupSchedule )selectIndex ); |
|
297 emit doModelRefresh(); |
|
298 } |
|
299 } |
|
300 |
|
301 void FmBackupWidget::on_changeWeekday() |
|
302 { |
|
303 QString title = mWeekdayItem->label(); |
|
304 QStringList queryStringList; |
|
305 |
|
306 FmBackupSettings::TFileManagerBackupWeekday weekday = FmBackupSettings::EFileManagerBackupWeekdayMonday; |
|
307 while ( weekday <= FmBackupSettings::EFileManagerBackupWeekdaySunday ) |
|
308 { |
|
309 queryStringList.push_back( mBackupSettings->weekdayToString( weekday ) ); |
|
310 weekday = FmBackupSettings::TFileManagerBackupWeekday(((int)weekday)+1); |
|
311 } |
|
312 |
|
313 // adjust index offset against monday. |
|
314 int selectIndex = mBackupSettings->weekday() - FmBackupSettings::EFileManagerBackupWeekdayMonday; |
|
315 if( FmDlgUtils::showSingleSettingQuery( title, queryStringList, selectIndex ) ) |
|
316 { |
|
317 selectIndex += FmBackupSettings::EFileManagerBackupWeekdayMonday; |
|
318 mBackupSettings->setWeekday( (FmBackupSettings::TFileManagerBackupWeekday)selectIndex ); |
|
319 emit doModelRefresh(); |
|
320 } |
|
321 } |
|
322 |
|
323 void FmBackupWidget::on_changeTime() |
|
324 { |
|
325 QString title = mTimeItem->label(); |
|
326 QTime queryTime = mBackupSettings->time(); |
|
327 |
|
328 if( FmDlgUtils::showTimeSettingQuery( title, queryTime ) ) |
|
329 { |
|
330 mBackupSettings->setTime( queryTime ); |
|
331 emit doModelRefresh(); |
|
332 } |
|
333 } |
|
334 |
|
335 |
|
336 void FmBackupWidget::on_changeTargetDrive() |
|
337 { |
|
338 QString title = mTargetItem->label(); |
|
339 QString drive = FmDlgUtils::showBackupDriveQuery( title ); |
|
340 if( ( !drive.isEmpty() ) && |
|
341 ( mBackupSettings->targetDrive().compare( drive, Qt::CaseInsensitive ) != 0 ) ) { |
|
342 mBackupSettings->setTargetDrive( drive ); |
|
343 emit doModelRefresh(); |
|
344 } |
|
345 } |
|
346 |
|
347 void FmBackupWidget::updateBackupDate() |
|
348 { |
|
349 mBackupSettings->updateBackupDate(); |
|
350 emit doModelRefresh(); |
|
351 } |
|