|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include <qglobal.h> |
|
27 #if defined(Q_OS_SYMBIAN) |
|
28 #include <f32file.h> |
|
29 #include <eikenv.h> |
|
30 #endif |
|
31 #include <QString> |
|
32 #include <QCoreApplication> |
|
33 #include <QFileInfo> |
|
34 |
|
35 #include <hbfindfile.h> |
|
36 |
|
37 /*! |
|
38 @beta |
|
39 @hbcore |
|
40 \class HbFindFile |
|
41 \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 |
|
44 \param str is file and path beginning with "/" |
|
45 \param defaultDrive is drive letter which should be checked first. Default value is null. |
|
46 \return true if file is found. Otherwise return false. |
|
47 */ |
|
48 bool HbFindFile::hbFindFile(QString &str, const QChar &defaultDrive) |
|
49 { |
|
50 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()) { |
|
64 file = defaultDrive + QString(":") + str; |
|
65 QFileInfo info(file); |
|
66 if (info.exists()) { |
|
67 str = file; |
|
68 return true; |
|
69 } |
|
70 } |
|
71 |
|
72 QString drives = availableDrives(); |
|
73 for (int i = 0; i < drives.size(); i++) { |
|
74 if (drives.at(i) == defaultDrive) { |
|
75 continue; |
|
76 } |
|
77 file = drives.at(i) + QString(":") + str; |
|
78 QFileInfo info(file); |
|
79 if (info.exists()) { |
|
80 str = file; |
|
81 return true; |
|
82 } |
|
83 } |
|
84 return false; |
|
85 } |
|
86 |
|
87 /*! |
|
88 Returns available drives in device (Symbian). Empty for other platforms. |
|
89 */ |
|
90 QString HbFindFile::availableDrives() |
|
91 { |
|
92 QString drives = ""; |
|
93 #if defined(Q_OS_SYMBIAN) |
|
94 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
95 TDriveList driveList; |
|
96 fs.DriveList(driveList); |
|
97 TChar driveLetter; |
|
98 for (TInt driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++) { |
|
99 fs.DriveToChar(driveNumber, driveLetter); |
|
100 QChar c = static_cast<QChar>(driveLetter); |
|
101 drives.append(c); |
|
102 } |
|
103 #endif |
|
104 return drives; |
|
105 } |