29 #include <eikenv.h> |
29 #include <eikenv.h> |
30 #endif |
30 #endif |
31 #include <QString> |
31 #include <QString> |
32 #include <QCoreApplication> |
32 #include <QCoreApplication> |
33 #include <QFileInfo> |
33 #include <QFileInfo> |
34 |
|
35 #include <hbfindfile.h> |
34 #include <hbfindfile.h> |
|
35 #include <qbasicatomic.h> |
|
36 #include <QDir> |
36 |
37 |
37 /*! |
38 /*! |
38 @beta |
39 @beta |
39 @hbcore |
40 @hbcore |
40 \class HbFindFile |
41 \class HbFindFile |
41 \brief Checks from which drive a certain file is found. |
42 \brief Checks from which drive a certain file is found. |
42 Scans drives through and adds drive information to \a str if file is found. |
43 Scans drives through and adds drive information to \a str if file is found. |
|
44 |
|
45 \attention Cross-Platform API |
43 |
46 |
44 \param str is file and path beginning with "/" |
47 \param str is file and path beginning with "/" |
45 \param defaultDrive is drive letter which should be checked first. Default value is null. |
48 \param defaultDrive is drive letter which should be checked first. Default value is null. |
46 \return true if file is found. Otherwise return false. |
49 |
|
50 \return True if file is found. Otherwise return false. |
47 */ |
51 */ |
48 bool HbFindFile::hbFindFile(QString &str, const QChar &defaultDrive) |
52 bool HbFindFile::hbFindFile(QString &str, const QChar &defaultDrive) |
49 { |
53 { |
|
54 #ifdef Q_OS_SYMBIAN |
|
55 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
56 TFindFile ff(fs); |
|
57 TPtrC fName((ushort*)(str.constData()),str.length()); |
|
58 QString dNameString; |
|
59 |
|
60 if (!defaultDrive.isNull()) { |
|
61 dNameString.append(defaultDrive); |
|
62 dNameString += QString(":"); |
|
63 } |
|
64 dNameString += QString("\\"); |
|
65 TPtrC dName((ushort*)(dNameString.constData()),dNameString.length()); |
|
66 TInt err=ff.FindByDir(fName, dName); |
|
67 if (err==KErrNone) { |
|
68 TParse p; |
|
69 p.Set(ff.File(), 0,0); |
|
70 TPtrC ptrC = p.Drive(); |
|
71 QString str2 = QString::fromRawData((QChar*)(ushort*)ptrC.Ptr(),ptrC.Length()); |
|
72 str.prepend(str2); |
|
73 return true; |
|
74 } |
|
75 else { |
|
76 return false; |
|
77 } |
|
78 #else |
50 QString file = str; |
79 QString file = str; |
51 #if defined(Q_OS_WIN32) |
|
52 file = "C:" + str; |
|
53 #endif |
|
54 #if !defined(Q_OS_SYMBIAN) |
|
55 QFileInfo info(file); |
|
56 if (info.exists()) { |
|
57 str = file; |
|
58 return true; |
|
59 } |
|
60 return false; |
|
61 #endif |
|
62 |
|
63 if (!defaultDrive.isNull()) { |
80 if (!defaultDrive.isNull()) { |
64 file = defaultDrive + QString(":") + str; |
81 file = defaultDrive + QString(":") + str; |
65 QFileInfo info(file); |
82 QFileInfo info(file); |
66 if (info.exists()) { |
83 if (info.exists()) { |
67 str = file; |
84 str = file; |
80 str = file; |
97 str = file; |
81 return true; |
98 return true; |
82 } |
99 } |
83 } |
100 } |
84 return false; |
101 return false; |
|
102 #endif |
|
103 |
85 } |
104 } |
86 |
105 |
87 /*! |
106 class AvailableDrives : public QString |
88 Returns available drives in device (Symbian). Empty for other platforms. |
|
89 */ |
|
90 QString HbFindFile::availableDrives() |
|
91 { |
107 { |
92 QString drives = ""; |
108 public: |
93 #if defined(Q_OS_SYMBIAN) |
109 AvailableDrives(); |
|
110 }; |
|
111 |
|
112 AvailableDrives::AvailableDrives() { |
|
113 #ifdef Q_OS_SYMBIAN |
94 RFs& fs = CCoeEnv::Static()->FsSession(); |
114 RFs& fs = CCoeEnv::Static()->FsSession(); |
95 TDriveList driveList; |
115 TDriveList driveList; |
96 fs.DriveList(driveList); |
116 fs.DriveList(driveList); |
97 TChar driveLetter; |
117 TChar driveLetter; |
98 for (TInt driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++) { |
118 |
|
119 // add first C and then Y..A and then Z. |
|
120 TInt driveNumber; |
|
121 if (driveList[EDriveC]) { |
|
122 driveNumber = EDriveC; |
99 fs.DriveToChar(driveNumber, driveLetter); |
123 fs.DriveToChar(driveNumber, driveLetter); |
100 QChar c = static_cast<QChar>(driveLetter); |
124 QChar cC = static_cast<QChar>(driveLetter); |
101 drives.append(c); |
125 this->append(cC); |
102 } |
126 } |
103 #endif |
127 for (driveNumber = EDriveY; driveNumber >= EDriveA; driveNumber--) { |
104 return drives; |
128 if (driveNumber == EDriveC) { |
|
129 continue; |
|
130 } |
|
131 else { |
|
132 if (driveList[driveNumber]) { |
|
133 fs.DriveToChar(driveNumber, driveLetter); |
|
134 QChar c = static_cast<QChar>(driveLetter); |
|
135 this->append(c); |
|
136 } |
|
137 } |
|
138 } |
|
139 if (driveList[EDriveZ]) { |
|
140 driveNumber = EDriveZ; |
|
141 fs.DriveToChar(driveNumber, driveLetter); |
|
142 QChar cZ = static_cast<QChar>(driveLetter); |
|
143 this->append(cZ); |
|
144 } |
|
145 |
|
146 |
|
147 #else |
|
148 QFileInfoList fil = QDir::drives(); |
|
149 for (int j=0; j< fil.length(); j++) { |
|
150 QString fp = fil.at(j).filePath(); |
|
151 |
|
152 if ((!fp.isEmpty()) && (fp[0] != '/') && (fp[0] != '\\')) { |
|
153 this->append(fp[0]); |
|
154 } |
|
155 } |
|
156 #endif |
105 } |
157 } |
|
158 |
|
159 Q_GLOBAL_STATIC(AvailableDrives, gs_AvailableDrives) |
|
160 |
|
161 /*! |
|
162 \attention Cross-Platform API |
|
163 |
|
164 \returns Available drive(s) if platform supports (Eg. Symbian, Windows...). |
|
165 If platform doesn't support drive(s) (Eg. Linux) then empty QString is returned. |
|
166 */ |
|
167 QString HbFindFile::availableDrives() |
|
168 { |
|
169 QString *str = gs_AvailableDrives(); |
|
170 if (str) { |
|
171 return *str; |
|
172 } |
|
173 else { |
|
174 return QString(); |
|
175 } |
|
176 } |