equal
deleted
inserted
replaced
20 #include "fmutils.h" |
20 #include "fmutils.h" |
21 |
21 |
22 #include <QDir> |
22 #include <QDir> |
23 #include <QFileInfo> |
23 #include <QFileInfo> |
24 |
24 |
25 FmDriveModel::FmDriveModel( QObject *parent, Options options ) : |
25 #include <hbglobal.h> |
26 QAbstractListModel( parent ), mOptions( options ) |
26 |
|
27 FmDriveModel::FmDriveModel( QObject *parent, Options options, |
|
28 FmDriveListProvider *driveListProvider ) : |
|
29 QAbstractListModel( parent ), mOptions( options ), mDriveListProvider( driveListProvider ) |
27 { |
30 { |
28 mIconProvider = new FmFileIconProvider(); |
31 mIconProvider = new FmFileIconProvider(); |
29 refresh(); |
32 refresh(); |
30 } |
33 } |
31 |
34 |
34 delete mIconProvider; |
37 delete mIconProvider; |
35 } |
38 } |
36 |
39 |
37 void FmDriveModel::refresh() |
40 void FmDriveModel::refresh() |
38 { |
41 { |
39 QFileInfoList infoList = QDir::drives(); |
42 emit layoutAboutToBeChanged(); |
|
43 mDriveList.clear(); |
|
44 |
|
45 // if mDriveListProvider existed, use it to fetch drive list |
|
46 // otherwise use FmUtils::getDriveList to fetch drive list. |
|
47 if( mDriveListProvider ) { |
|
48 mDriveListProvider->getDriveList( mDriveList ); |
|
49 } else { |
|
50 if( mOptions & HideUnAvailableDrive ) { |
|
51 FmLogger::log( QString( "FmDriveModel::refresh HideUnAvailableDrive_true" ) ); |
|
52 FmUtils::getDriveList( mDriveList, true ); |
|
53 } else { |
|
54 FmLogger::log( QString( "FmDriveModel::refresh HideUnAvailableDrive_false" ) ); |
|
55 FmUtils::getDriveList( mDriveList, false ); |
|
56 } |
|
57 } |
40 |
58 |
41 mDriveList.clear(); |
59 emit layoutChanged(); |
42 if( mOptions & HideUnAvailableDrive ) { |
60 for( int i=0; i<mDriveList.count(); i++ ) { |
43 FmLogger::log( QString( "FmDriveModel::refresh HideUnAvailableDrive_true" ) ); |
61 emit dataChanged(index( i, 0 ), index( i, 0 )); |
44 FmUtils::getDriveList( mDriveList, true ); |
62 } |
45 } else { |
|
46 FmLogger::log( QString( "FmDriveModel::refresh HideUnAvailableDrive_false" ) ); |
|
47 FmUtils::getDriveList( mDriveList, false ); |
|
48 } |
|
49 emit layoutChanged(); |
|
50 } |
63 } |
51 |
64 |
52 |
65 |
53 int FmDriveModel::rowCount( const QModelIndex &parent ) const |
66 int FmDriveModel::rowCount( const QModelIndex &parent ) const |
54 { |
67 { |
95 if (orientation == Qt::Horizontal) { |
108 if (orientation == Qt::Horizontal) { |
96 if (role != Qt::DisplayRole) |
109 if (role != Qt::DisplayRole) |
97 return QVariant(); |
110 return QVariant(); |
98 |
111 |
99 switch (section) { |
112 switch (section) { |
100 case 0: return tr("Name"); |
113 case 0: return hbTrId("Name"); |
101 case 1: return tr("Size"); |
114 case 1: return hbTrId("Size"); |
102 case 2: return tr("Type"); |
115 case 2: return hbTrId("Type"); |
103 case 3: return tr("Date Modified"); |
116 case 3: return hbTrId("Date Modified"); |
104 default: return QVariant(); |
117 default: return QVariant(); |
105 } |
118 } |
106 } |
119 } |
107 |
120 |
108 return QAbstractItemModel::headerData( section, orientation, role ); |
121 return QAbstractItemModel::headerData( section, orientation, role ); |