1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qfiledialog.h"
|
---|
43 |
|
---|
44 | #ifndef QT_NO_FILEDIALOG
|
---|
45 |
|
---|
46 | #include <private/qfiledialog_p.h>
|
---|
47 | #if defined(Q_WS_S60) && defined(SYMBIAN_VERSION_SYMBIAN3)
|
---|
48 | #include <driveinfo.h>
|
---|
49 | #include <AknCommonDialogsDynMem.h>
|
---|
50 | #include <CAknMemorySelectionDialogMultiDrive.h>
|
---|
51 | #include <MAknFileFilter.h>
|
---|
52 | #endif
|
---|
53 | #include "private/qcore_symbian_p.h"
|
---|
54 |
|
---|
55 | QT_BEGIN_NAMESPACE
|
---|
56 |
|
---|
57 | extern QStringList qt_make_filter_list(const QString &filter); // defined in qfiledialog.cpp
|
---|
58 | extern QStringList qt_clean_filter_list(const QString &filter); // defined in qfiledialog.cpp
|
---|
59 |
|
---|
60 | enum DialogMode { DialogOpen, DialogSave, DialogFolder };
|
---|
61 | #if defined(Q_WS_S60) && defined(SYMBIAN_VERSION_SYMBIAN3)
|
---|
62 | class CExtensionFilter : public MAknFileFilter
|
---|
63 | {
|
---|
64 | public:
|
---|
65 | void setFilter(const QString filter)
|
---|
66 | {
|
---|
67 | QStringList unparsedFiltersList = qt_make_filter_list(filter);
|
---|
68 | QStringList filterList;
|
---|
69 | filterRxList.clear();
|
---|
70 |
|
---|
71 | foreach (QString unparsedFilter, unparsedFiltersList) {
|
---|
72 | filterList << qt_clean_filter_list(unparsedFilter);
|
---|
73 | }
|
---|
74 | foreach (QString currentFilter, filterList) {
|
---|
75 | QRegExp filterRx(currentFilter, Qt::CaseInsensitive, QRegExp::Wildcard);
|
---|
76 | filterRxList << filterRx;
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | TBool Accept(const TDesC &/*aDriveAndPath*/, const TEntry &aEntry) const
|
---|
81 | {
|
---|
82 | //If no filter for files, all can be accepted
|
---|
83 | if (filterRxList.isEmpty())
|
---|
84 | return ETrue;
|
---|
85 |
|
---|
86 | if (aEntry.IsDir())
|
---|
87 | return ETrue;
|
---|
88 |
|
---|
89 | foreach (QRegExp rx, filterRxList) {
|
---|
90 | QString fileName = qt_TDesC2QString(aEntry.iName);
|
---|
91 | if (rx.exactMatch(fileName))
|
---|
92 | return ETrue;
|
---|
93 | }
|
---|
94 |
|
---|
95 | return EFalse;
|
---|
96 | }
|
---|
97 |
|
---|
98 | private:
|
---|
99 | QList<QRegExp> filterRxList;
|
---|
100 | };
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | static QString launchSymbianDialog(const QString dialogCaption, const QString startDirectory,
|
---|
104 | const QString filter, DialogMode dialogMode)
|
---|
105 | {
|
---|
106 | QString selection;
|
---|
107 | #if defined(Q_WS_S60) && defined(SYMBIAN_VERSION_SYMBIAN3)
|
---|
108 | TFileName startFolder;
|
---|
109 | if (!startDirectory.isEmpty()) {
|
---|
110 | QString dir = QDir::toNativeSeparators(QFileDialogPrivate::workingDirectory(startDirectory));
|
---|
111 | startFolder = qt_QString2TPtrC(dir);
|
---|
112 | }
|
---|
113 | TInt types = AknCommonDialogsDynMem::EMemoryTypeMMCExternal|
|
---|
114 | AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage|
|
---|
115 | AknCommonDialogsDynMem::EMemoryTypePhone;
|
---|
116 |
|
---|
117 | TPtrC titlePtr(qt_QString2TPtrC(dialogCaption));
|
---|
118 | TFileName target;
|
---|
119 | bool select = false;
|
---|
120 | int tryCount = 2;
|
---|
121 | while (tryCount--) {
|
---|
122 | TInt err(KErrNone);
|
---|
123 | TRAP(err,
|
---|
124 | if (dialogMode == DialogOpen) {
|
---|
125 | CExtensionFilter* extensionFilter = new (ELeave) CExtensionFilter;
|
---|
126 | CleanupStack::PushL(extensionFilter);
|
---|
127 | extensionFilter->setFilter(filter);
|
---|
128 | select = AknCommonDialogsDynMem::RunSelectDlgLD(types, target,
|
---|
129 | startFolder, 0, 0, titlePtr, extensionFilter);
|
---|
130 | CleanupStack::Pop(extensionFilter);
|
---|
131 | } else if (dialogMode == DialogSave) {
|
---|
132 | QString defaultFileName = QFileDialogPrivate::initialSelection(startDirectory);
|
---|
133 | target = qt_QString2TPtrC(defaultFileName);
|
---|
134 | select = AknCommonDialogsDynMem::RunSaveDlgLD(types, target,
|
---|
135 | startFolder, 0, 0, titlePtr);
|
---|
136 | } else if (dialogMode == DialogFolder) {
|
---|
137 | select = AknCommonDialogsDynMem::RunFolderSelectDlgLD(types, target, startFolder,
|
---|
138 | 0, 0, titlePtr, NULL, NULL);
|
---|
139 | }
|
---|
140 | );
|
---|
141 |
|
---|
142 | if (err == KErrNone) {
|
---|
143 | tryCount = 0;
|
---|
144 | } else {
|
---|
145 | // Symbian native file dialog doesn't allow accessing files outside C:/Data
|
---|
146 | // It will always leave in that case, so default into QDir::rootPath() in error cases.
|
---|
147 | QString dir = QDir::toNativeSeparators(QDir::rootPath());
|
---|
148 | startFolder = qt_QString2TPtrC(dir);
|
---|
149 | }
|
---|
150 | }
|
---|
151 | if (select) {
|
---|
152 | QFileInfo fi(qt_TDesC2QString(target));
|
---|
153 | selection = fi.absoluteFilePath();
|
---|
154 | }
|
---|
155 | #endif
|
---|
156 | return selection;
|
---|
157 | }
|
---|
158 |
|
---|
159 | QString qtSymbianGetOpenFileName(const QString &caption,
|
---|
160 | const QString &dir,
|
---|
161 | const QString &filter)
|
---|
162 | {
|
---|
163 | return launchSymbianDialog(caption, dir, filter, DialogOpen);
|
---|
164 | }
|
---|
165 |
|
---|
166 | QStringList qtSymbianGetOpenFileNames(const QString &caption,
|
---|
167 | const QString &dir,
|
---|
168 | const QString &filter)
|
---|
169 | {
|
---|
170 | QString fileName;
|
---|
171 | fileName.append(launchSymbianDialog(caption, dir, filter, DialogOpen));
|
---|
172 | QStringList fileList;
|
---|
173 | fileList << fileName;
|
---|
174 |
|
---|
175 | return fileList;
|
---|
176 | }
|
---|
177 |
|
---|
178 | QString qtSymbianGetSaveFileName(const QString &caption,
|
---|
179 | const QString &dir)
|
---|
180 | {
|
---|
181 | return launchSymbianDialog(caption, dir, QString(), DialogSave);
|
---|
182 | }
|
---|
183 |
|
---|
184 | QString qtSymbianGetExistingDirectory(const QString &caption,
|
---|
185 | const QString &dir)
|
---|
186 | {
|
---|
187 | QString folderCaption;
|
---|
188 | if (!caption.isEmpty()) {
|
---|
189 | folderCaption.append(caption);
|
---|
190 | } else {
|
---|
191 | // Title for folder selection dialog is mandatory
|
---|
192 | folderCaption.append(QFileDialog::tr("Find Directory"));
|
---|
193 | }
|
---|
194 | return launchSymbianDialog(folderCaption, dir, QString(), DialogFolder);
|
---|
195 | }
|
---|
196 |
|
---|
197 | QT_END_NAMESPACE
|
---|
198 |
|
---|
199 | #endif
|
---|