14 * |
14 * |
15 * Description: |
15 * Description: |
16 * The driver model file for file manager |
16 * The driver model file for file manager |
17 */ |
17 */ |
18 #include "fmdriverlistwidget.h" |
18 #include "fmdriverlistwidget.h" |
19 #include "listviewitems.h" |
|
20 #include "fmutils.h" |
19 #include "fmutils.h" |
21 #include "fmdlgutils.h" |
20 #include "fmdlgutils.h" |
22 #include "fmviewmanager.h" |
21 #include "fmviewmanager.h" |
23 #include "fmviewdetailsdialog.h" |
22 #include "fmviewdetailsdialog.h" |
24 #include "fmoperationbase.h" |
23 #include "fmoperationbase.h" |
25 #include "fmdrivemodel.h" |
24 #include "fmdrivemodel.h" |
26 #include "fmfiledialog.h" |
25 #include "fmfiledialog.h" |
27 |
26 #include "fmoperationservice.h" |
28 #include <QDirModel> |
27 #include <hbabstractviewitem.h> |
|
28 #include <QDir> |
29 #include <QGraphicsLinearLayout> |
29 #include <QGraphicsLinearLayout> |
30 #include <QFileSystemWatcher> |
30 #include <QFileSystemWatcher> |
31 |
31 |
32 #include <hblistview.h> |
32 #include <hblistview.h> |
33 #include <hbmenu.h> |
33 #include <hbmenu.h> |
34 #include <hbaction.h> |
34 #include <hbaction.h> |
35 #include <hbmessagebox.h> |
|
36 #include <hbsearchpanel.h> |
35 #include <hbsearchpanel.h> |
37 |
36 |
38 FmDriverListWidget::FmDriverListWidget( QGraphicsItem *parent ) |
37 FmDriverListWidget::FmDriverListWidget( QGraphicsItem *parent ) |
39 : HbWidget( parent ), |
38 : HbWidget( parent ), mListView(0), mModel(0), |
40 mCurrentItem( 0 ), |
39 mCurrentItem(0), mSearchPanel(0), |
41 mOperationService( 0 ) |
40 mFileSystemWatcher(0), mLayout(0), mContextMenu(0), mListLongPressed( false ) |
42 { |
41 { |
43 init(); |
42 init(); |
44 mOperationService = FmViewManager::viewManager()->operationService(); |
|
45 |
|
46 mFileSystemWatcher = new QFileSystemWatcher( this ); |
43 mFileSystemWatcher = new QFileSystemWatcher( this ); |
47 connect( mFileSystemWatcher, SIGNAL( directoryChanged ( const QString & ) ), |
44 connect( mFileSystemWatcher, SIGNAL( directoryChanged ( const QString & ) ), |
48 this, SLOT( on_directoryChanged( const QString & ) ) ); |
45 this, SLOT( on_directoryChanged( const QString & ) ) ); |
49 |
46 |
50 QMetaObject::connectSlotsByName( this ); |
47 QMetaObject::connectSlotsByName( this ); |
51 } |
48 } |
52 |
49 |
53 FmDriverListWidget::~FmDriverListWidget() |
50 FmDriverListWidget::~FmDriverListWidget() |
54 { |
51 { |
|
52 if (mContextMenu) { |
|
53 mContextMenu->deleteLater(); |
|
54 } |
55 } |
55 } |
56 |
56 |
57 void FmDriverListWidget::on_list_activated( const QModelIndex &index ) |
57 void FmDriverListWidget::on_list_activated( const QModelIndex &index ) |
58 { |
58 { |
59 emit activated( mModel->driveName( index ) ); |
59 FM_LOG("FmDriverListWidget::on_list_activated"); |
|
60 if( mListLongPressed ) { |
|
61 FM_LOG("FmDriverListWidget::on_list_activated return because long pressed"); |
|
62 return; |
|
63 } |
|
64 FM_LOG("FmDriverListWidget::on_list_activated emit activate to open drive"); |
|
65 emit activated( mModel->driveName( index ) ); |
60 } |
66 } |
61 |
67 |
62 void FmDriverListWidget::init() |
68 void FmDriverListWidget::init() |
63 { |
69 { |
64 mLayout = new QGraphicsLinearLayout( this ); |
70 mLayout = new QGraphicsLinearLayout( this ); |
65 mLayout->setOrientation( Qt::Vertical ); |
71 mLayout->setOrientation( Qt::Vertical ); |
66 |
72 |
67 mListView = new HbListView( this ); |
73 mListView = new HbListView( this ); |
68 mListView->setSelectionMode( HbAbstractItemView::SingleSelection ); |
74 mListView->setLayoutName( "drive" ); |
69 |
|
70 mModel = new FmDriveModel( this, |
75 mModel = new FmDriveModel( this, |
71 FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume ); |
76 FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume | |
|
77 FmDriveModel::FillWithTotalSize | FmDriveModel::FillWithFreeSize ); |
72 mListView->setModel( mModel ); |
78 mListView->setModel( mModel ); |
73 |
79 mLayout->addItem( mListView ); |
74 mLayout->addItem( mListView ); |
|
75 |
|
76 mSearchPanel = new HbSearchPanel( this ); |
80 mSearchPanel = new HbSearchPanel( this ); |
77 mSearchPanel->setObjectName( "searchPanel" ); |
81 mSearchPanel->setObjectName( "searchPanel" ); |
78 mSearchPanel->setSearchOptionsEnabled( true ); |
82 mSearchPanel->setSearchOptionsEnabled( true ); |
79 mSearchPanel->setProgressive( false ); |
83 mSearchPanel->setProgressive( false ); |
80 mSearchPanel->hide(); |
84 mSearchPanel->hide(); |
81 // mLayout->addItem( mSearchPanel ); |
|
82 |
|
83 mListView->setItemPrototype( new DiskListViewItem( mListView ) ); |
|
84 connect( mListView, SIGNAL( activated( const QModelIndex & ) ), |
85 connect( mListView, SIGNAL( activated( const QModelIndex & ) ), |
85 this, SLOT( on_list_activated( const QModelIndex & ) ) ); |
86 this, SLOT( on_list_activated( const QModelIndex & ) ) ); |
|
87 connect( mListView, SIGNAL( pressed( const QModelIndex & ) ), |
|
88 this, SLOT( on_list_pressed( const QModelIndex & ) ) ); |
86 |
89 |
87 connect( mListView, SIGNAL( longPressed( HbAbstractViewItem *, const QPointF & ) ), |
90 connect( mListView, SIGNAL( longPressed( HbAbstractViewItem *, const QPointF & ) ), |
88 this, SLOT( on_list_longPressed( HbAbstractViewItem *, const QPointF & ) ) ); |
91 this, SLOT( on_list_longPressed( HbAbstractViewItem *, const QPointF & ) ) ); |
89 |
92 |
90 connect( mSearchPanel, SIGNAL( searchOptionsClicked() ), |
93 connect( mSearchPanel, SIGNAL( searchOptionsClicked() ), |
91 this, SLOT( on_searchPanel_searchOptionsClicked() ) ); |
94 this, SLOT( on_searchPanel_searchOptionsClicked() ), Qt::QueuedConnection ); |
92 |
95 |
93 connect( mSearchPanel, SIGNAL( criteriaChanged( const QString & ) ), |
96 connect( mSearchPanel, SIGNAL( criteriaChanged( const QString & ) ), |
94 this, SLOT( on_searchPanel_criteriaChanged( const QString & ) ) ); |
97 this, SLOT( on_searchPanel_criteriaChanged( const QString & ) ) ); |
95 |
98 |
96 connect( mSearchPanel, SIGNAL( exitClicked() ), |
99 connect( mSearchPanel, SIGNAL( exitClicked() ), |
97 this, SLOT( on_searchPanel_exitClicked() ) ); |
100 this, SLOT( on_searchPanel_exitClicked() ) ); |
98 |
101 |
99 setLayout( mLayout ); |
102 setLayout( mLayout ); |
100 } |
103 } |
101 |
104 |
102 void FmDriverListWidget::refreshModel( const QString &path ) |
105 void FmDriverListWidget::refreshDrive() |
103 { |
106 { |
104 Q_UNUSED( path ); |
|
105 mModel->refresh(); |
107 mModel->refresh(); |
106 } |
108 } |
107 |
109 |
108 void FmDriverListWidget::on_list_longPressed( HbAbstractViewItem *item, const QPointF &coords ) |
110 void FmDriverListWidget::on_list_longPressed( HbAbstractViewItem *item, const QPointF &coords ) |
109 { |
111 { |
110 HbMenu *contextMenu = new HbMenu(); |
112 FM_LOG("FmDriverListWidget::on_list_longPressed"); |
111 |
113 mListLongPressed = true; |
112 mCurrentItem = item; |
114 mCurrentItem = item; |
113 QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); |
115 QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); |
114 |
116 |
115 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); |
117 if( !mContextMenu ) { |
|
118 mContextMenu = new HbMenu(); |
|
119 } else { |
|
120 mContextMenu->clearActions(); |
|
121 } |
|
122 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); |
|
123 FmDriverInfo::DriveType driveType = driverInfo.driveType(); |
116 FmDriverInfo::DriveState state = driverInfo.driveState(); |
124 FmDriverInfo::DriveState state = driverInfo.driveState(); |
117 |
125 if( !( state & FmDriverInfo::EDriveNotPresent ) ) { |
118 if( !( state & FmDriverInfo::EDriveNotPresent ) && !( state & FmDriverInfo::EDriveLocked ) && |
126 if( state & FmDriverInfo::EDriveAvailable ) { |
119 !( state & FmDriverInfo::EDriveCorrupted ) ) { |
127 HbAction *viewAction = new HbAction(); |
120 HbAction *viewAction = new HbAction(); |
128 viewAction->setObjectName( "viewAction" ); |
121 viewAction->setObjectName( "viewAction" ); |
129 viewAction->setText( hbTrId( "txt_fmgr_menu_view_details_memory" ) ); |
122 viewAction->setText( hbTrId( "txt_fmgr_menu_view_details_memory" ) ); |
130 mContextMenu->addAction( viewAction ); |
123 contextMenu->addAction( viewAction ); |
131 connect( viewAction, SIGNAL( triggered() ), |
124 |
132 this, SLOT( on_viewAction_triggered() ), Qt::QueuedConnection ); |
125 //state = 0x210; |
133 |
126 |
134 if( driveType == FmDriverInfo::EDriveTypeMemoryCard || driveType == FmDriverInfo::EDriveTypeUsbMemory ) { |
127 connect( viewAction, SIGNAL( triggered() ), |
135 // MMC or Usb memory |
128 this, SLOT( on_viewAction_triggered() ) ); |
136 |
129 } |
137 // Name/Rename action |
130 |
138 if ( driverInfo.volumeName().length() ){ |
131 if( ( state & FmDriverInfo::EDriveRemovable ) && !( state & FmDriverInfo::EDriveMassStorage ) ){ |
139 HbAction *renameAction = new HbAction(); |
132 if ( driverInfo.volumeName().length() ){ |
140 renameAction->setObjectName( "renameAction" ); |
133 HbAction *renameAction = new HbAction(); |
141 renameAction->setText( hbTrId( "txt_fmgr_menu_rename" ) ); |
134 renameAction->setObjectName( "renameAction" ); |
142 mContextMenu->addAction( renameAction ); |
135 renameAction->setText( hbTrId( "txt_fmgr_menu_rename" ) ); |
143 |
136 contextMenu->addAction( renameAction ); |
144 connect( renameAction, SIGNAL( triggered() ), |
137 |
145 this, SLOT( on_renameAction_triggered() ), Qt::QueuedConnection ); |
138 connect( renameAction, SIGNAL( triggered() ), |
146 } else { |
139 this, SLOT( on_renameAction_triggered() ) ); |
147 HbAction *nameAction = new HbAction(); |
140 } |
148 nameAction->setObjectName( "nameAction" ); |
141 else{ |
149 nameAction->setText( hbTrId( "txt_fmgr_menu_name" ) ); |
142 HbAction *nameAction = new HbAction(); |
150 mContextMenu->addAction( nameAction ); |
143 nameAction->setObjectName( "nameAction" ); |
151 |
144 nameAction->setText( hbTrId( "txt_fmgr_menu_name" ) ); |
152 connect( nameAction, SIGNAL( triggered() ), |
145 contextMenu->addAction( nameAction ); |
153 this, SLOT( on_nameAction_triggered() ), Qt::QueuedConnection ); |
146 |
154 } |
147 connect( nameAction, SIGNAL( triggered() ), |
155 |
148 this, SLOT( on_nameAction_triggered() ) ); |
156 // Set/Change/Remove password action |
149 } |
157 if( driveType == FmDriverInfo::EDriveTypeMemoryCard ) { // MMC |
150 |
158 if( state & FmDriverInfo::EDrivePasswordProtected ){ |
151 if( state & FmDriverInfo::EDrivePasswordProtected ){ |
159 HbAction *changePwdAction = new HbAction(); |
152 HbAction *changePwdAction = new HbAction(); |
160 changePwdAction->setObjectName( "changePwdAction" ); |
153 changePwdAction->setObjectName( "changePwdAction" ); |
161 changePwdAction->setText( hbTrId( "txt_fmgr_menu_change_password" ) ); |
154 changePwdAction->setText( hbTrId( "txt_fmgr_menu_change_password" ) ); |
162 mContextMenu->addAction( changePwdAction ); |
155 contextMenu->addAction( changePwdAction ); |
163 |
156 |
164 HbAction *removePwdAction = new HbAction(); |
157 HbAction *removePwdAction = new HbAction(); |
165 removePwdAction->setObjectName( "removePwdAction" ); |
158 removePwdAction->setObjectName( "removePwdAction" ); |
166 removePwdAction->setText( hbTrId( "txt_fmgr_menu_remove_password" ) ); |
159 removePwdAction->setText( hbTrId( "txt_fmgr_menu_remove_password" ) ); |
167 mContextMenu->addAction( removePwdAction ); |
160 contextMenu->addAction( removePwdAction ); |
168 |
161 |
169 connect( changePwdAction, SIGNAL( triggered() ), |
162 connect( changePwdAction, SIGNAL( triggered() ), |
170 this, SLOT( on_changePwdAction_triggered() ), Qt::QueuedConnection ); |
163 this, SLOT( on_changePwdAction_triggered() ) ); |
171 connect( removePwdAction, SIGNAL( triggered() ), |
164 connect( removePwdAction, SIGNAL( triggered() ), |
172 this, SLOT( on_removePwdAction_triggered() ), Qt::QueuedConnection ); |
165 this, SLOT( on_removePwdAction_triggered() ) ); |
173 } |
166 } |
174 else{ |
167 else{ |
175 HbAction *setPwdAction = new HbAction(); |
168 HbAction *setPwdAction = new HbAction(); |
176 setPwdAction->setObjectName( "setPwdAction" ); |
169 setPwdAction->setObjectName( "setPwdAction" ); |
177 setPwdAction->setText( hbTrId( "txt_fmgr_menu_set_password" ) ); |
170 setPwdAction->setText( hbTrId( "txt_fmgr_menu_set_password" ) ); |
178 mContextMenu->addAction( setPwdAction ); |
171 contextMenu->addAction( setPwdAction ); |
179 |
172 |
180 connect( setPwdAction, SIGNAL( triggered() ), |
173 connect( setPwdAction, SIGNAL( triggered() ), |
181 this, SLOT( on_setPwdAction_triggered() ), Qt::QueuedConnection ); |
174 this, SLOT( on_setPwdAction_triggered() ) ); |
182 } |
175 } |
183 } |
176 |
184 } //if( driveType == FmDriverInfo::EDriveTypeMemoryCard || driveType == FmDriverInfo::EDriveTypeUsbMemory ) |
|
185 } //if( state & FmDriverInfo::EDriveAvailable ) |
|
186 |
|
187 // Eject action |
|
188 // put outside of EDriveAvailable so that removable drive which is corrupted or locked can be removed |
177 if( state & FmDriverInfo::EDriveEjectable ){ |
189 if( state & FmDriverInfo::EDriveEjectable ){ |
178 HbAction *ejectAction = new HbAction(); |
190 HbAction *ejectAction = new HbAction(); |
179 ejectAction->setObjectName( "ejectAction" ); |
191 ejectAction->setObjectName( "ejectAction" ); |
180 ejectAction->setText( hbTrId( "txt_fmgr_menu_eject" ) ); |
192 ejectAction->setText( hbTrId( "txt_fmgr_menu_eject" ) ); |
181 contextMenu->addAction( ejectAction ); |
193 mContextMenu->addAction( ejectAction ); |
182 |
194 |
183 connect( ejectAction, SIGNAL( triggered() ), |
195 connect( ejectAction, SIGNAL( triggered() ), |
184 this, SLOT( on_ejectAction_triggered() ) ); |
196 this, SLOT( on_ejectAction_triggered() ), Qt::QueuedConnection ); |
185 } |
197 } |
186 } |
198 |
187 #ifndef _DEBUG_ENABLE_FORMATMENU_ |
199 // Format action |
188 if ( ( state & FmDriverInfo::EDriveRemovable ) || ( state & FmDriverInfo::EDriveCorrupted ) |
200 if ( ( state & FmDriverInfo::EDriveRemovable ) || ( state & FmDriverInfo::EDriveCorrupted ) |
189 || ( state & FmDriverInfo::EDriveLocked ) ){ |
201 || ( state & FmDriverInfo::EDriveLocked ) ){ |
190 if( !( state & FmDriverInfo::EDriveNotPresent ) ){ |
202 HbAction *formatAction = new HbAction(); |
191 #endif |
203 formatAction->setObjectName( "formatAction" ); |
192 HbAction *formatAction = new HbAction(); |
204 formatAction->setText( hbTrId( "txt_fmgr_menu_format" ) ); |
193 formatAction->setObjectName( "formatAction" ); |
205 mContextMenu->addAction( formatAction ); |
194 formatAction->setText( hbTrId( "txt_fmgr_menu_format" ) ); |
206 |
195 contextMenu->addAction( formatAction ); |
207 connect( formatAction, SIGNAL( triggered() ), |
196 |
208 this, SLOT( on_formatAction_triggered() ), Qt::QueuedConnection ); |
197 connect( formatAction, SIGNAL( triggered() ), |
209 } |
198 this, SLOT( on_formatAction_triggered() ) ); |
210 } //if( !( state & FmDriverInfo::EDriveNotPresent ) ) |
199 #ifndef _DEBUG_ENABLE_FORMATMENU_ |
211 |
200 } |
212 // Unlock action |
201 } |
213 // put ouside of !EDriveNotPresent judgment so that |
202 #endif |
214 // user could unlock drive if connected to PC with mass storage mode |
203 |
|
204 if( state & FmDriverInfo::EDriveLocked ){ |
215 if( state & FmDriverInfo::EDriveLocked ){ |
205 HbAction *unLockedAction = new HbAction(); |
216 HbAction *unLockedAction = new HbAction(); |
206 unLockedAction->setObjectName( "unLockedAction" ); |
217 unLockedAction->setObjectName( "unLockedAction" ); |
207 unLockedAction->setText( hbTrId( "Unlock" ) ); |
218 unLockedAction->setText( hbTrId( "Unlock" ) ); |
208 contextMenu->addAction( unLockedAction ); |
219 mContextMenu->addAction( unLockedAction ); |
209 |
220 |
210 connect( unLockedAction, SIGNAL( triggered() ), |
221 connect( unLockedAction, SIGNAL( triggered() ), |
211 this, SLOT( on_unLockedAction_triggered() ) ); |
222 this, SLOT( on_unLockedAction_triggered() ), Qt::QueuedConnection ); |
212 } |
223 } |
213 |
224 |
214 contextMenu->exec( coords ); |
225 // Pop up menu or open drive |
|
226 if( mContextMenu->actions().count() > 0 ) { |
|
227 mContextMenu->setPreferredPos( coords ); |
|
228 mContextMenu->open(); |
|
229 } else { |
|
230 emit activated( diskName ); |
|
231 } |
|
232 } |
|
233 |
|
234 void FmDriverListWidget::on_list_pressed( const QModelIndex & index ) |
|
235 { |
|
236 Q_UNUSED( index ); |
|
237 mListLongPressed = false; |
215 } |
238 } |
216 |
239 |
217 void FmDriverListWidget::on_viewAction_triggered() |
240 void FmDriverListWidget::on_viewAction_triggered() |
218 { |
241 { |
219 QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); |
242 QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); |
220 mOperationService->asyncViewDriveDetails( diskName ); |
243 FmViewManager::viewManager()->operationService()->asyncViewDriveDetails( diskName ); |
221 } |
244 } |
222 |
245 |
223 void FmDriverListWidget::on_renameAction_triggered() |
246 void FmDriverListWidget::on_renameAction_triggered() |
224 { |
247 { |
225 QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); |
248 QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); |
226 |
249 |
227 FmDriverInfo::DriveState state = FmUtils::queryDriverInfo( diskName ).driveState(); |
250 FmDriverInfo::DriveState state = FmUtils::queryDriverInfo( diskName ).driveState(); |
228 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); |
251 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); |
229 |
252 |
230 if ( state & FmDriverInfo::EDriveWriteProtected ){ |
253 if ( state & FmDriverInfo::EDriveWriteProtected ){ |
231 HbMessageBox::information( hbTrId( "Unable to perform operation. Memory card is read only." ) ); |
254 FmDlgUtils::information( hbTrId( "Unable to perform operation. Memory card is read only." ) ); |
232 return; |
255 return; |
233 } |
256 } |
234 |
257 |
235 QString title( tr( "Drive name ") ); |
258 QString title( hbTrId( "Drive name ") ); |
236 QString volumeName = driverInfo.volumeName(); |
259 //save the volume status, empty or set |
237 |
260 bool needToSetVolume = false; |
|
261 QString volumeName = FmUtils::getVolumeNameWithDefaultNameIfNull( diskName, needToSetVolume ); |
|
262 QString oldVolumeName( volumeName ); |
238 QString associatedDrives( FmUtils::getDriveLetterFromPath( diskName ) ); |
263 QString associatedDrives( FmUtils::getDriveLetterFromPath( diskName ) ); |
239 while( FmDlgUtils::showTextQuery( title, volumeName, false, FmMaxLengthofDriveName, associatedDrives ) ){ |
264 //use isReturnFalseWhenNoTextChanged = false in order that FmUtils::renameDrive( driveName, volumeName ) will |
|
265 //be excuted at lease once to set the volume name. |
|
266 while( FmDlgUtils::showTextQuery( title, volumeName, QStringList(), FmMaxLengthofDriveName, associatedDrives, false ) ){ |
|
267 //if volume is not set or oldVolumeName != volumeName , FmUtils::renameDrive will be called |
|
268 if ( oldVolumeName == volumeName && !needToSetVolume ) { |
|
269 break; |
|
270 } |
240 int err = FmUtils::renameDrive( diskName, volumeName ); |
271 int err = FmUtils::renameDrive( diskName, volumeName ); |
241 if ( err == FmErrNone ){ |
272 if ( err == FmErrNone ) { |
242 HbMessageBox::information( hbTrId( "The name has been changed!" ) ); |
273 FmDlgUtils::information( hbTrId( "The name has been changed!" ) ); |
243 mModel->refresh(); |
274 mModel->refresh(); |
244 break; |
275 break; |
245 } else if( err == FmErrBadName ) { |
276 } else if( err == FmErrBadName ) { |
246 HbMessageBox::information( hbTrId( "Illegal characters! Use only letters and numbers." ) ); |
277 FmDlgUtils::information( hbTrId( "Illegal characters! Use only letters and numbers." ) ); |
247 } else{ |
278 } else{ |
248 HbMessageBox::information( hbTrId( "Error occurred, operation cancelled!" ) ); |
279 FmDlgUtils::information( hbTrId( "Error occurred, operation cancelled!" ) ); |
249 break; |
280 break; |
250 } |
281 } |
251 } |
282 } |
252 } |
283 } |
253 |
284 |