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 * Zhiqiang Yang <zhiqiang.yang@nokia.com> |
|
14 * |
|
15 * Description: |
|
16 * The source file of the restore view of file manager |
|
17 */ |
|
18 |
|
19 #include "fmrestoreview.h" |
|
20 #include "fmrestorewidget.h" |
|
21 #include "fmviewmanager.h" |
|
22 #include "fmoperationbase.h" |
|
23 #include "fmdlgutils.h" |
|
24 |
|
25 #include <QApplication> |
|
26 |
|
27 #include <hbaction.h> |
|
28 #include <hbtoolbar.h> |
|
29 #include <hbmenu.h> |
|
30 #include <hbmainwindow.h> |
|
31 |
|
32 FmRestoreView::FmRestoreView(): FmViewBase( ERestoreView ) |
|
33 { |
|
34 setTitle( hbTrId( "Restore" ) ); |
|
35 |
|
36 initMainWidget(); |
|
37 initToolBar(); |
|
38 initMenu(); |
|
39 mOperationService = FmViewManager::viewManager()->operationService(); |
|
40 } |
|
41 |
|
42 FmRestoreView::~FmRestoreView() |
|
43 { |
|
44 removeToolBarAction(); |
|
45 } |
|
46 |
|
47 void FmRestoreView::initMenu() |
|
48 { |
|
49 #ifdef FM_CHANGE_ORIENT_ENABLE |
|
50 HbAction *action = 0; |
|
51 action = new HbAction( this ); |
|
52 action->setObjectName( "rotateAction" ); |
|
53 action->setText( hbTrId( "Change orientation" ) ); |
|
54 menu()->addAction( action ); |
|
55 connect( action, SIGNAL(triggered()), this, SLOT( on_rotateAction_triggered() ), Qt::QueuedConnection ); |
|
56 #endif |
|
57 |
|
58 mRestoreAction = new HbAction( this ); |
|
59 mRestoreAction->setObjectName( "restoreAction" ); |
|
60 mRestoreAction->setText( hbTrId( "Restore data" ) ); |
|
61 menu()->addAction( mRestoreAction ); |
|
62 mRestoreAction->setEnabled(false); |
|
63 connect( mRestoreAction, SIGNAL(triggered()), this, SLOT( on_restoreAction_triggered() ), Qt::QueuedConnection ); |
|
64 } |
|
65 |
|
66 void FmRestoreView::initMainWidget() |
|
67 { |
|
68 mRestoreWigdet = new FmRestoreWigdet( this ); |
|
69 |
|
70 setWidget( mRestoreWigdet ); |
|
71 connect(mRestoreWigdet, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxStateChange())); |
|
72 |
|
73 } |
|
74 |
|
75 void FmRestoreView::initToolBar() |
|
76 { |
|
77 mLeftAction = new HbAction( this ); |
|
78 mLeftAction->setObjectName( "leftAction" ); |
|
79 mLeftAction->setText( hbTrId( "Restore" ) ); |
|
80 toolBar()->addAction( mLeftAction ); |
|
81 connect( mLeftAction, SIGNAL(triggered()), this, SLOT( on_leftAction_triggered() ), Qt::QueuedConnection ); |
|
82 |
|
83 mLeftAction->setEnabled(false); |
|
84 toolBar()->setOrientation( Qt::Horizontal ); |
|
85 } |
|
86 |
|
87 void FmRestoreView::on_leftAction_triggered() |
|
88 { |
|
89 QList<int > items = mRestoreWigdet->selectionIndexes(); |
|
90 quint64 selection( 0 ); |
|
91 for ( int i( 0 ); i < items.count(); ++i ) |
|
92 { |
|
93 selection |= ( ( quint64 ) 1 ) << ( items[ i ] ); |
|
94 } |
|
95 |
|
96 int ret = mOperationService->asyncRestore( selection ); |
|
97 switch( ret ) |
|
98 { |
|
99 case FmErrNone: |
|
100 break; |
|
101 case FmErrWrongParam: |
|
102 FmDlgUtils::information( QString( hbTrId("Operation canceled with wrong param!") ) ); |
|
103 break; |
|
104 case FmErrAlreadyStarted: |
|
105 FmDlgUtils::information( QString( hbTrId("Operation canceled because already started!") ) ); |
|
106 break; |
|
107 default: |
|
108 FmDlgUtils::information(hbTrId("restore failed")); |
|
109 break; |
|
110 } |
|
111 } |
|
112 |
|
113 #ifdef FM_CHANGE_ORIENT_ENABLE |
|
114 void FmRestoreView::on_rotateAction_triggered() |
|
115 { |
|
116 if ( mainWindow()->orientation() == Qt::Vertical ) { |
|
117 mainWindow()->setOrientation( Qt::Horizontal ); |
|
118 } |
|
119 else { |
|
120 mainWindow()->setOrientation( Qt::Vertical ); |
|
121 } |
|
122 } |
|
123 #endif |
|
124 |
|
125 void FmRestoreView::on_restoreAction_triggered() |
|
126 { |
|
127 on_leftAction_triggered(); |
|
128 } |
|
129 |
|
130 void FmRestoreView::removeToolBarAction() |
|
131 { |
|
132 toolBar()->removeAction( mLeftAction ); |
|
133 } |
|
134 |
|
135 void FmRestoreView::onCheckBoxStateChange() |
|
136 { |
|
137 QList<int> items = mRestoreWigdet->selectionIndexes(); |
|
138 if (items.count() > 0) { |
|
139 mLeftAction->setEnabled(true); |
|
140 mRestoreAction->setEnabled(true); |
|
141 } else { |
|
142 mLeftAction->setEnabled(false); |
|
143 mRestoreAction->setEnabled(false); |
|
144 } |
|
145 } |
|
146 |
|
147 void FmRestoreView::refreshRestoreView() |
|
148 { |
|
149 mRestoreWigdet->refresh(); |
|
150 } |
|