0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 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 test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
|
|
45 |
#include <qcoreapplication.h>
|
|
46 |
#include <qdebug.h>
|
|
47 |
#include <qfiledialog.h>
|
|
48 |
#include <qabstractitemdelegate.h>
|
|
49 |
#include <qdirmodel.h>
|
|
50 |
#include <qitemdelegate.h>
|
|
51 |
#include <qlistview.h>
|
|
52 |
#include <qcombobox.h>
|
|
53 |
#include <qpushbutton.h>
|
|
54 |
#include <qtoolbutton.h>
|
|
55 |
#include <qtreeview.h>
|
|
56 |
#include <qheaderview.h>
|
|
57 |
#include <qcompleter.h>
|
|
58 |
#include <qaction.h>
|
|
59 |
#include <qdialogbuttonbox.h>
|
|
60 |
#include <qsortfilterproxymodel.h>
|
|
61 |
#include <qlineedit.h>
|
|
62 |
#include <qlayout.h>
|
|
63 |
#include "../../shared/util.h"
|
|
64 |
#include "../../../src/gui/dialogs/qsidebar_p.h"
|
|
65 |
#include "../../../src/gui/dialogs/qfilesystemmodel_p.h"
|
|
66 |
#include "../../../src/gui/dialogs/qfiledialog_p.h"
|
|
67 |
|
|
68 |
#include "../network-settings.h"
|
|
69 |
|
|
70 |
//TESTED_CLASS=
|
|
71 |
//TESTED_FILES=
|
|
72 |
|
|
73 |
#if defined(Q_OS_SYMBIAN)
|
|
74 |
# define STRINGIFY(x) #x
|
|
75 |
# define TOSTRING(x) STRINGIFY(x)
|
|
76 |
# define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) "/"
|
|
77 |
#endif
|
|
78 |
|
|
79 |
class QNonNativeFileDialog : public QFileDialog
|
|
80 |
{
|
|
81 |
Q_OBJECT
|
|
82 |
public:
|
|
83 |
QNonNativeFileDialog(QWidget *parent = 0, const QString &caption = QString(), const QString &directory = QString(), const QString &filter = QString())
|
|
84 |
: QFileDialog(parent, caption, directory, filter)
|
|
85 |
{
|
|
86 |
setOption(QFileDialog::DontUseNativeDialog, true);
|
|
87 |
}
|
|
88 |
};
|
|
89 |
|
|
90 |
class tst_QFiledialog : public QObject
|
|
91 |
{
|
|
92 |
Q_OBJECT
|
|
93 |
|
|
94 |
public:
|
|
95 |
tst_QFiledialog();
|
|
96 |
virtual ~tst_QFiledialog();
|
|
97 |
|
|
98 |
public slots:
|
|
99 |
void init();
|
|
100 |
void cleanup();
|
|
101 |
|
|
102 |
private slots:
|
|
103 |
void listRoot();
|
|
104 |
void heapCorruption();
|
|
105 |
void deleteDirAndFiles();
|
|
106 |
void filter();
|
|
107 |
void showNameFilterDetails();
|
|
108 |
void unc();
|
|
109 |
void emptyUncPath();
|
|
110 |
|
|
111 |
void task178897_minimumSize();
|
|
112 |
void task180459_lastDirectory_data();
|
|
113 |
void task180459_lastDirectory();
|
|
114 |
void task227304_proxyOnFileDialog();
|
|
115 |
void task227930_correctNavigationKeyboardBehavior();
|
|
116 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
|
|
117 |
void task226366_lowerCaseHardDriveWindows();
|
|
118 |
#endif
|
|
119 |
void task233037_selectingDirectory();
|
|
120 |
void task235069_hideOnEscape();
|
|
121 |
void task236402_dontWatchDeletedDir();
|
|
122 |
void task203703_returnProperSeparator();
|
|
123 |
void task228844_ensurePreviousSorting();
|
|
124 |
void task239706_editableFilterCombo();
|
|
125 |
void task218353_relativePaths();
|
|
126 |
void task251321_sideBarHiddenEntries();
|
|
127 |
void task251341_sideBarRemoveEntries();
|
|
128 |
void task254490_selectFileMultipleTimes();
|
|
129 |
void task257579_sideBarWithNonCleanUrls();
|
|
130 |
void task259105_filtersCornerCases();
|
|
131 |
|
|
132 |
void QTBUG4419_lineEditSelectAll();
|
|
133 |
|
|
134 |
private:
|
|
135 |
QByteArray userSettings;
|
|
136 |
};
|
|
137 |
|
|
138 |
tst_QFiledialog::tst_QFiledialog()
|
|
139 |
{
|
|
140 |
#if defined(Q_OS_WINCE)
|
|
141 |
qApp->setAutoMaximizeThreshold(-1);
|
|
142 |
#endif
|
|
143 |
}
|
|
144 |
|
|
145 |
tst_QFiledialog::~tst_QFiledialog()
|
|
146 |
{
|
|
147 |
}
|
|
148 |
|
|
149 |
void tst_QFiledialog::init()
|
|
150 |
{
|
|
151 |
// Save the developers settings so they don't get mad when their sidebar folders are gone.
|
|
152 |
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
|
|
153 |
settings.beginGroup(QLatin1String("Qt"));
|
|
154 |
userSettings = settings.value(QLatin1String("filedialog")).toByteArray();
|
|
155 |
settings.remove(QLatin1String("filedialog"));
|
|
156 |
|
|
157 |
// populate it with some default settings
|
|
158 |
QNonNativeFileDialog fd;
|
|
159 |
#if defined(Q_OS_WINCE)
|
|
160 |
QTest::qWait(1000);
|
|
161 |
#endif
|
|
162 |
}
|
|
163 |
|
|
164 |
void tst_QFiledialog::cleanup()
|
|
165 |
{
|
|
166 |
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
|
|
167 |
settings.beginGroup(QLatin1String("Qt"));
|
|
168 |
settings.setValue(QLatin1String("filedialog"), userSettings);
|
|
169 |
}
|
|
170 |
|
|
171 |
void tst_QFiledialog::listRoot()
|
|
172 |
{
|
|
173 |
#if defined QT_BUILD_INTERNAL
|
|
174 |
QFileInfoGatherer fileInfoGatherer;
|
|
175 |
fileInfoGatherer.start();
|
|
176 |
QTest::qWait(1500);
|
|
177 |
|
|
178 |
QFileInfoGatherer::fetchedRoot = false;
|
|
179 |
QString dir(QDir::currentPath());
|
|
180 |
QNonNativeFileDialog fd(0, QString(), dir);
|
|
181 |
fd.show();
|
|
182 |
QCOMPARE(QFileInfoGatherer::fetchedRoot,false);
|
|
183 |
fd.setDirectory("");
|
|
184 |
#ifdef Q_OS_WINCE
|
|
185 |
QTest::qWait(1500);
|
|
186 |
#else
|
|
187 |
QTest::qWait(500);
|
|
188 |
#endif
|
|
189 |
QCOMPARE(QFileInfoGatherer::fetchedRoot,true);
|
|
190 |
#endif
|
|
191 |
}
|
|
192 |
|
|
193 |
void tst_QFiledialog::heapCorruption()
|
|
194 |
{
|
|
195 |
QVector<QNonNativeFileDialog*> dialogs;
|
|
196 |
for (int i=0; i < 10; i++) {
|
|
197 |
QNonNativeFileDialog *f = new QNonNativeFileDialog(NULL);
|
|
198 |
dialogs << f;
|
|
199 |
}
|
|
200 |
qDeleteAll(dialogs);
|
|
201 |
}
|
|
202 |
|
|
203 |
struct FriendlyQFileDialog : public QFileDialog
|
|
204 |
{
|
|
205 |
friend class tst_QFileDialog;
|
|
206 |
Q_DECLARE_PRIVATE(QFileDialog)
|
|
207 |
};
|
|
208 |
|
|
209 |
|
|
210 |
void tst_QFiledialog::deleteDirAndFiles()
|
|
211 |
{
|
|
212 |
#if defined QT_BUILD_INTERNAL
|
|
213 |
QString tempPath = QDir::tempPath() + '/' + "QFileDialogTestDir4FullDelete";
|
|
214 |
QDir dir;
|
|
215 |
QVERIFY(dir.mkpath(tempPath + "/foo"));
|
|
216 |
QVERIFY(dir.mkpath(tempPath + "/foo/B"));
|
|
217 |
QVERIFY(dir.mkpath(tempPath + "/foo/B"));
|
|
218 |
QVERIFY(dir.mkpath(tempPath + "/foo/c"));
|
|
219 |
QVERIFY(dir.mkpath(tempPath + "/bar"));
|
|
220 |
QFile(tempPath + "/foo/a");
|
|
221 |
QTemporaryFile *t;
|
|
222 |
t = new QTemporaryFile(tempPath + "/foo/aXXXXXX");
|
|
223 |
t->setAutoRemove(false);
|
|
224 |
t->open();
|
|
225 |
t->close();
|
|
226 |
delete t;
|
|
227 |
|
|
228 |
t = new QTemporaryFile(tempPath + "/foo/B/yXXXXXX");
|
|
229 |
t->setAutoRemove(false);
|
|
230 |
t->open();
|
|
231 |
t->close();
|
|
232 |
delete t;
|
|
233 |
FriendlyQFileDialog fd;
|
|
234 |
fd.setOption(QFileDialog::DontUseNativeDialog);
|
|
235 |
fd.d_func()->removeDirectory(tempPath);
|
|
236 |
QFileInfo info(tempPath);
|
|
237 |
QTest::qWait(2000);
|
|
238 |
QVERIFY(!info.exists());
|
|
239 |
#endif
|
|
240 |
}
|
|
241 |
|
|
242 |
void tst_QFiledialog::filter()
|
|
243 |
{
|
|
244 |
QNonNativeFileDialog fd;
|
|
245 |
QAction *hiddenAction = qFindChild<QAction*>(&fd, "qt_show_hidden_action");
|
|
246 |
QVERIFY(hiddenAction);
|
|
247 |
QVERIFY(hiddenAction->isEnabled());
|
|
248 |
QVERIFY(!hiddenAction->isChecked());
|
|
249 |
QDir::Filters filter = fd.filter();
|
|
250 |
filter |= QDir::Hidden;
|
|
251 |
fd.setFilter(filter);
|
|
252 |
QVERIFY(hiddenAction->isChecked());
|
|
253 |
}
|
|
254 |
|
|
255 |
void tst_QFiledialog::showNameFilterDetails()
|
|
256 |
{
|
|
257 |
QNonNativeFileDialog fd;
|
|
258 |
QComboBox *filters = qFindChild<QComboBox*>(&fd, "fileTypeCombo");
|
|
259 |
QVERIFY(filters);
|
|
260 |
QVERIFY(fd.isNameFilterDetailsVisible());
|
|
261 |
|
|
262 |
|
|
263 |
QStringList filterChoices;
|
|
264 |
filterChoices << "Image files (*.png *.xpm *.jpg)"
|
|
265 |
<< "Text files (*.txt)"
|
|
266 |
<< "Any files (*.*)";
|
|
267 |
fd.setFilters(filterChoices);
|
|
268 |
|
|
269 |
fd.setNameFilterDetailsVisible(false);
|
|
270 |
QCOMPARE(filters->itemText(0), QString("Image files"));
|
|
271 |
QCOMPARE(filters->itemText(1), QString("Text files"));
|
|
272 |
QCOMPARE(filters->itemText(2), QString("Any files"));
|
|
273 |
|
|
274 |
fd.setNameFilterDetailsVisible(true);
|
|
275 |
QCOMPARE(filters->itemText(0), filterChoices.at(0));
|
|
276 |
QCOMPARE(filters->itemText(1), filterChoices.at(1));
|
|
277 |
QCOMPARE(filters->itemText(2), filterChoices.at(2));
|
|
278 |
}
|
|
279 |
|
|
280 |
void tst_QFiledialog::unc()
|
|
281 |
{
|
|
282 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
|
|
283 |
// Only test UNC on Windows./
|
|
284 |
QString dir("\\\\" + QtNetworkSettings::winServerName() + "\\testsharewritable");
|
|
285 |
#else
|
|
286 |
QString dir(QDir::currentPath());
|
|
287 |
#endif
|
|
288 |
QVERIFY(QFile::exists(dir));
|
|
289 |
QNonNativeFileDialog fd(0, QString(), dir);
|
|
290 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model");
|
|
291 |
QVERIFY(model);
|
|
292 |
QCOMPARE(model->index(fd.directory().absolutePath()), model->index(dir));
|
|
293 |
}
|
|
294 |
|
|
295 |
void tst_QFiledialog::emptyUncPath()
|
|
296 |
{
|
|
297 |
QNonNativeFileDialog fd;
|
|
298 |
fd.show();
|
|
299 |
QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit");
|
|
300 |
QVERIFY(lineEdit);
|
|
301 |
// press 'keys' for the input
|
|
302 |
for (int i = 0; i < 3 ; ++i)
|
|
303 |
QTest::keyPress(lineEdit, Qt::Key_Backslash);
|
|
304 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model");
|
|
305 |
QVERIFY(model);
|
|
306 |
}
|
|
307 |
|
|
308 |
void tst_QFiledialog::task178897_minimumSize()
|
|
309 |
{
|
|
310 |
QNonNativeFileDialog fd;
|
|
311 |
QSize oldMs = fd.layout()->minimumSize();
|
|
312 |
QStringList history = fd.history();
|
|
313 |
history << QDir::toNativeSeparators("/verylongdirectory/"
|
|
314 |
"aaaaaaaaaabbbbbbbbcccccccccccddddddddddddddeeeeeeeeeeeeffffffffffgggtggggggggghhhhhhhhiiiiiijjjk");
|
|
315 |
fd.setHistory(history);
|
|
316 |
fd.show();
|
|
317 |
|
|
318 |
QSize ms = fd.layout()->minimumSize();
|
|
319 |
QVERIFY(ms.width() <= oldMs.width());
|
|
320 |
}
|
|
321 |
|
|
322 |
void tst_QFiledialog::task180459_lastDirectory_data()
|
|
323 |
{
|
|
324 |
QTest::addColumn<QString>("path");
|
|
325 |
QTest::addColumn<QString>("directory");
|
|
326 |
QTest::addColumn<bool>("isEnabled");
|
|
327 |
QTest::addColumn<QString>("result");
|
|
328 |
|
|
329 |
QTest::newRow("path+file") << QDir::homePath() + QDir::separator() + "foo"
|
|
330 |
<< QDir::homePath() << true
|
|
331 |
<< QDir::homePath() + QDir::separator() + "foo" ;
|
|
332 |
QTest::newRow("no path") << ""
|
|
333 |
<< QDir::tempPath() << false << QString();
|
|
334 |
QTest::newRow("file") << "foo"
|
|
335 |
<< QDir::currentPath() << true
|
|
336 |
<< QDir::currentPath() + QDir::separator() + "foo" ;
|
|
337 |
QTest::newRow("path") << QDir::homePath()
|
|
338 |
<< QDir::homePath() << false << QString();
|
|
339 |
QTest::newRow("path not existing") << "/usr/bin/foo/bar/foo/foo.txt"
|
|
340 |
<< QDir::tempPath() << true
|
|
341 |
<< QDir::tempPath() + QDir::separator() + "foo.txt";
|
|
342 |
|
|
343 |
}
|
|
344 |
|
|
345 |
void tst_QFiledialog::task180459_lastDirectory()
|
|
346 |
{
|
|
347 |
//first visit the temp directory and close the dialog
|
|
348 |
QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", QDir::tempPath());
|
|
349 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(dlg, "qt_filesystem_model");
|
|
350 |
QVERIFY(model);
|
|
351 |
QCOMPARE(model->index(QDir::tempPath()), model->index(dlg->directory().absolutePath()));
|
|
352 |
delete dlg;
|
|
353 |
|
|
354 |
QFETCH(QString, path);
|
|
355 |
QFETCH(QString, directory);
|
|
356 |
QFETCH(bool, isEnabled);
|
|
357 |
QFETCH(QString, result);
|
|
358 |
|
|
359 |
dlg = new QNonNativeFileDialog(0, "", path);
|
|
360 |
model = qFindChild<QFileSystemModel*>(dlg, "qt_filesystem_model");
|
|
361 |
QVERIFY(model);
|
|
362 |
dlg->setAcceptMode(QFileDialog::AcceptSave);
|
|
363 |
QCOMPARE(model->index(dlg->directory().absolutePath()), model->index(directory));
|
|
364 |
|
|
365 |
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(dlg, "buttonBox");
|
|
366 |
QPushButton *button = buttonBox->button(QDialogButtonBox::Save);
|
|
367 |
QVERIFY(button);
|
|
368 |
QCOMPARE(button->isEnabled(), isEnabled);
|
|
369 |
if (isEnabled)
|
|
370 |
QCOMPARE(model->index(result), model->index(dlg->selectedFiles().first()));
|
|
371 |
|
|
372 |
delete dlg;
|
|
373 |
}
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
class FilterDirModel : public QSortFilterProxyModel
|
|
378 |
{
|
|
379 |
|
|
380 |
public:
|
|
381 |
FilterDirModel(QString root, QObject* parent=0):QSortFilterProxyModel(parent), m_root(root)
|
|
382 |
{}
|
|
383 |
~FilterDirModel()
|
|
384 |
{};
|
|
385 |
|
|
386 |
protected:
|
|
387 |
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
|
|
388 |
{
|
|
389 |
QModelIndex parentIndex;
|
|
390 |
parentIndex = source_parent;
|
|
391 |
|
|
392 |
QString path;
|
|
393 |
path = parentIndex.child(source_row,0).data(Qt::DisplayRole).toString();
|
|
394 |
|
|
395 |
do {
|
|
396 |
path = parentIndex.data(Qt::DisplayRole).toString() + "/" + path;
|
|
397 |
parentIndex = parentIndex.parent();
|
|
398 |
} while(parentIndex.isValid());
|
|
399 |
|
|
400 |
QFileInfo info(path);
|
|
401 |
if (info.isDir() && (QDir(path) != m_root))
|
|
402 |
return false;
|
|
403 |
return true;
|
|
404 |
}
|
|
405 |
|
|
406 |
|
|
407 |
private:
|
|
408 |
QDir m_root;
|
|
409 |
|
|
410 |
|
|
411 |
};
|
|
412 |
|
|
413 |
class sortProxy : public QSortFilterProxyModel
|
|
414 |
{
|
|
415 |
public:
|
|
416 |
sortProxy(QObject *parent) : QSortFilterProxyModel(parent)
|
|
417 |
{
|
|
418 |
}
|
|
419 |
protected:
|
|
420 |
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
421 |
{
|
|
422 |
QFileSystemModel * const model = qobject_cast<QFileSystemModel *>(sourceModel());
|
|
423 |
const QFileInfo leftInfo(model->fileInfo(left));
|
|
424 |
const QFileInfo rightInfo(model->fileInfo(right));
|
|
425 |
|
|
426 |
if (leftInfo.isDir() == rightInfo.isDir())
|
|
427 |
return(leftInfo.filePath().compare(rightInfo.filePath(),Qt::CaseInsensitive) < 0);
|
|
428 |
else if (leftInfo.isDir())
|
|
429 |
return(false);
|
|
430 |
else
|
|
431 |
return(true);
|
|
432 |
}
|
|
433 |
};
|
|
434 |
|
|
435 |
class CrashDialog : public QNonNativeFileDialog
|
|
436 |
{
|
|
437 |
Q_OBJECT
|
|
438 |
|
|
439 |
public:
|
|
440 |
CrashDialog(QWidget *parent, const QString &caption, const
|
|
441 |
QString &dir, const QString &filter)
|
|
442 |
: QNonNativeFileDialog(parent, caption, dir, filter)
|
|
443 |
{
|
|
444 |
sortProxy *proxyModel = new sortProxy(this);
|
|
445 |
setProxyModel(proxyModel);
|
|
446 |
}
|
|
447 |
};
|
|
448 |
|
|
449 |
void tst_QFiledialog::task227304_proxyOnFileDialog()
|
|
450 |
{
|
|
451 |
#if defined QT_BUILD_INTERNAL
|
|
452 |
QNonNativeFileDialog fd(0, "", QDir::currentPath(), 0);
|
|
453 |
fd.setProxyModel(new FilterDirModel(QDir::currentPath()));
|
|
454 |
fd.show();
|
|
455 |
QLineEdit *edit = qFindChild<QLineEdit*>(&fd, "fileNameEdit");
|
|
456 |
QTest::qWait(200);
|
|
457 |
QTest::keyClick(edit, Qt::Key_T);
|
|
458 |
QTest::keyClick(edit, Qt::Key_S);
|
|
459 |
QTest::qWait(200);
|
|
460 |
QTest::keyClick(edit->completer()->popup(), Qt::Key_Down);
|
|
461 |
|
|
462 |
CrashDialog *dialog = new CrashDialog(0, QString("crash dialog test"), QDir::homePath(), QString("*") );
|
|
463 |
dialog->setFileMode(QFileDialog::ExistingFile);
|
|
464 |
dialog->show();
|
|
465 |
|
|
466 |
QListView *list = qFindChild<QListView*>(dialog, "listView");
|
|
467 |
QTest::qWait(200);
|
|
468 |
QTest::keyClick(list, Qt::Key_Down);
|
|
469 |
QTest::keyClick(list, Qt::Key_Return);
|
|
470 |
QTest::qWait(200);
|
|
471 |
|
|
472 |
dialog->close();
|
|
473 |
fd.close();
|
|
474 |
|
|
475 |
QNonNativeFileDialog fd2(0, "I should not crash with a proxy", QDir::tempPath(), 0);
|
|
476 |
QSortFilterProxyModel *pm = new QSortFilterProxyModel;
|
|
477 |
fd2.setProxyModel(pm);
|
|
478 |
fd2.show();
|
|
479 |
QSidebar *sidebar = qFindChild<QSidebar*>(&fd2, "sidebar");
|
|
480 |
sidebar->setFocus();
|
|
481 |
sidebar->selectUrl(QUrl::fromLocalFile(QDir::homePath()));
|
|
482 |
QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center());
|
|
483 |
QTest::qWait(250);
|
|
484 |
//We shouldn't crash
|
|
485 |
#endif
|
|
486 |
}
|
|
487 |
|
|
488 |
void tst_QFiledialog::task227930_correctNavigationKeyboardBehavior()
|
|
489 |
{
|
|
490 |
QDir current = QDir::currentPath();
|
|
491 |
current.mkdir("test");
|
|
492 |
current.cd("test");
|
|
493 |
QFile file("test/out.txt");
|
|
494 |
QFile file2("test/out2.txt");
|
|
495 |
QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text));
|
|
496 |
QVERIFY(file2.open(QIODevice::WriteOnly | QIODevice::Text));
|
|
497 |
current.cdUp();
|
|
498 |
current.mkdir("test2");
|
|
499 |
QNonNativeFileDialog fd;
|
|
500 |
fd.setViewMode(QFileDialog::List);
|
|
501 |
fd.setDirectory(current.absolutePath());
|
|
502 |
fd.show();
|
|
503 |
QListView *list = qFindChild<QListView*>(&fd, "listView");
|
|
504 |
QTest::qWait(200);
|
|
505 |
QTest::keyClick(list, Qt::Key_Down);
|
|
506 |
QTest::keyClick(list, Qt::Key_Return);
|
|
507 |
QTest::qWait(200);
|
|
508 |
QTest::mouseClick(list->viewport(), Qt::LeftButton,0);
|
|
509 |
QTest::keyClick(list, Qt::Key_Down);
|
|
510 |
QTest::keyClick(list, Qt::Key_Backspace);
|
|
511 |
QTest::qWait(200);
|
|
512 |
QTest::keyClick(list, Qt::Key_Down);
|
|
513 |
QTest::keyClick(list, Qt::Key_Down);
|
|
514 |
QTest::keyClick(list, Qt::Key_Return);
|
|
515 |
QTest::qWait(200);
|
|
516 |
QCOMPARE(fd.isVisible(), true);
|
|
517 |
QTest::qWait(200);
|
|
518 |
file.close();
|
|
519 |
file2.close();
|
|
520 |
file.remove();
|
|
521 |
file2.remove();
|
|
522 |
current.rmdir("test");
|
|
523 |
current.rmdir("test2");
|
|
524 |
}
|
|
525 |
|
|
526 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
|
|
527 |
void tst_QFiledialog::task226366_lowerCaseHardDriveWindows()
|
|
528 |
{
|
|
529 |
QNonNativeFileDialog fd;
|
|
530 |
fd.setDirectory(QDir::root().path());
|
|
531 |
fd.show();
|
|
532 |
QLineEdit *edit = qFindChild<QLineEdit*>(&fd, "fileNameEdit");
|
|
533 |
QToolButton *buttonParent = qFindChild<QToolButton*>(&fd, "toParentButton");
|
|
534 |
QTest::qWait(200);
|
|
535 |
QTest::mouseClick(buttonParent, Qt::LeftButton,0,QPoint(0,0));
|
|
536 |
QTest::qWait(2000);
|
|
537 |
QTest::keyClick(edit, Qt::Key_C);
|
|
538 |
QTest::qWait(200);
|
|
539 |
QTest::keyClick(edit->completer()->popup(), Qt::Key_Down);
|
|
540 |
QTest::qWait(200);
|
|
541 |
QCOMPARE(edit->text(), QString("C:"));
|
|
542 |
QTest::qWait(2000);
|
|
543 |
//i clear my previous selection in the completer
|
|
544 |
QTest::keyClick(edit->completer()->popup(), Qt::Key_Down);
|
|
545 |
edit->clear();
|
|
546 |
QTest::keyClick(edit, (char)(Qt::Key_C | Qt::SHIFT));
|
|
547 |
QTest::qWait(200);
|
|
548 |
QTest::keyClick(edit->completer()->popup(), Qt::Key_Down);
|
|
549 |
QCOMPARE(edit->text(), QString("C:"));
|
|
550 |
}
|
|
551 |
#endif
|
|
552 |
|
|
553 |
void tst_QFiledialog::task233037_selectingDirectory()
|
|
554 |
{
|
|
555 |
QDir current = QDir::currentPath();
|
|
556 |
current.mkdir("test");
|
|
557 |
QNonNativeFileDialog fd;
|
|
558 |
fd.setViewMode(QFileDialog::List);
|
|
559 |
fd.setDirectory(current.absolutePath());
|
|
560 |
fd.setAcceptMode( QFileDialog::AcceptSave);
|
|
561 |
fd.show();
|
|
562 |
QListView *list = qFindChild<QListView*>(&fd, "listView");
|
|
563 |
QTest::qWait(3000); // Wait for sort to settle (I need a signal).
|
|
564 |
#ifdef QT_KEYPAD_NAVIGATION
|
|
565 |
list->setEditFocus(true);
|
|
566 |
#endif
|
|
567 |
QTest::keyClick(list, Qt::Key_Down);
|
|
568 |
QTest::qWait(100);
|
|
569 |
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox");
|
|
570 |
QPushButton *button = buttonBox->button(QDialogButtonBox::Save);
|
|
571 |
QVERIFY(button);
|
|
572 |
QCOMPARE(button->isEnabled(), true);
|
|
573 |
current.rmdir("test");
|
|
574 |
}
|
|
575 |
|
|
576 |
void tst_QFiledialog::task235069_hideOnEscape()
|
|
577 |
{
|
|
578 |
QDir current = QDir::currentPath();
|
|
579 |
QNonNativeFileDialog fd;
|
|
580 |
fd.setViewMode(QFileDialog::List);
|
|
581 |
fd.setDirectory(current.absolutePath());
|
|
582 |
fd.setAcceptMode( QFileDialog::AcceptSave);
|
|
583 |
fd.show();
|
|
584 |
QListView *list = qFindChild<QListView*>(&fd, "listView");
|
|
585 |
list->setFocus();
|
|
586 |
QTest::qWait(200);
|
|
587 |
QTest::keyClick(list, Qt::Key_Escape);
|
|
588 |
QCOMPARE(fd.isVisible(), false);
|
|
589 |
QNonNativeFileDialog fd2;
|
|
590 |
fd2.setDirectory(current.absolutePath());
|
|
591 |
fd2.setAcceptMode( QFileDialog::AcceptSave);
|
|
592 |
fd2.show();
|
|
593 |
QLineEdit *edit = qFindChild<QLineEdit*>(&fd2, "fileNameEdit");
|
|
594 |
QTest::keyClick(edit, Qt::Key_Escape);
|
|
595 |
QCOMPARE(fd2.isVisible(), false);
|
|
596 |
}
|
|
597 |
|
|
598 |
void tst_QFiledialog::task236402_dontWatchDeletedDir()
|
|
599 |
{
|
|
600 |
#if defined QT_BUILD_INTERNAL
|
|
601 |
//THIS TEST SHOULD NOT DISPLAY WARNINGS
|
|
602 |
QDir current = QDir::currentPath();
|
|
603 |
//make sure it is the first on the list
|
|
604 |
current.mkdir("aaaaaaaaaa");
|
|
605 |
FriendlyQFileDialog fd;
|
|
606 |
fd.setViewMode(QFileDialog::List);
|
|
607 |
fd.setDirectory(current.absolutePath());
|
|
608 |
fd.setAcceptMode( QFileDialog::AcceptSave);
|
|
609 |
fd.show();
|
|
610 |
QListView *list = qFindChild<QListView*>(&fd, "listView");
|
|
611 |
list->setFocus();
|
|
612 |
QTest::qWait(200);
|
|
613 |
QTest::keyClick(list, Qt::Key_Return);
|
|
614 |
QTest::qWait(200);
|
|
615 |
QTest::keyClick(list, Qt::Key_Backspace);
|
|
616 |
QTest::keyClick(list, Qt::Key_Down);
|
|
617 |
QTest::qWait(200);
|
|
618 |
fd.d_func()->removeDirectory(current.absolutePath() + "/aaaaaaaaaa/");
|
|
619 |
QTest::qWait(1000);
|
|
620 |
#endif
|
|
621 |
}
|
|
622 |
|
|
623 |
void tst_QFiledialog::task203703_returnProperSeparator()
|
|
624 |
{
|
|
625 |
QDir current = QDir::currentPath();
|
|
626 |
current.mkdir("aaaaaaaaaaaaaaaaaa");
|
|
627 |
QNonNativeFileDialog fd;
|
|
628 |
fd.setDirectory(current.absolutePath());
|
|
629 |
fd.setViewMode(QFileDialog::List);
|
|
630 |
fd.setFileMode(QFileDialog::Directory);
|
|
631 |
fd.show();
|
|
632 |
QTest::qWait(500);
|
|
633 |
QListView *list = qFindChild<QListView*>(&fd, "listView");
|
|
634 |
list->setFocus();
|
|
635 |
QTest::qWait(200);
|
|
636 |
QTest::keyClick(list, Qt::Key_Return);
|
|
637 |
QTest::qWait(1000);
|
|
638 |
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox");
|
|
639 |
QPushButton *button = buttonBox->button(QDialogButtonBox::Cancel);
|
|
640 |
QTest::keyClick(button, Qt::Key_Return);
|
|
641 |
QTest::qWait(500);
|
|
642 |
QString result = fd.selectedFiles().first();
|
|
643 |
QVERIFY(result.at(result.count() - 1) != '/');
|
|
644 |
QVERIFY(!result.contains('\\'));
|
|
645 |
current.rmdir("aaaaaaaaaaaaaaaaaa");
|
|
646 |
}
|
|
647 |
|
|
648 |
void tst_QFiledialog::task228844_ensurePreviousSorting()
|
|
649 |
{
|
|
650 |
QDir current = QDir::currentPath();
|
|
651 |
current.mkdir("aaaaaaaaaaaaaaaaaa");
|
|
652 |
current.cd("aaaaaaaaaaaaaaaaaa");
|
|
653 |
current.mkdir("a");
|
|
654 |
current.mkdir("b");
|
|
655 |
current.mkdir("c");
|
|
656 |
current.mkdir("d");
|
|
657 |
current.mkdir("e");
|
|
658 |
current.mkdir("f");
|
|
659 |
current.mkdir("g");
|
|
660 |
QTemporaryFile *tempFile = new QTemporaryFile(current.absolutePath() + "/rXXXXXX");
|
|
661 |
tempFile->open();
|
|
662 |
current.cdUp();
|
|
663 |
|
|
664 |
QNonNativeFileDialog fd;
|
|
665 |
fd.setDirectory(current.absolutePath());
|
|
666 |
fd.setViewMode(QFileDialog::Detail);
|
|
667 |
fd.show();
|
|
668 |
#if defined(Q_OS_WINCE)
|
|
669 |
QTest::qWait(1500);
|
|
670 |
#else
|
|
671 |
QTest::qWait(500);
|
|
672 |
#endif
|
|
673 |
QTreeView *tree = qFindChild<QTreeView*>(&fd, "treeView");
|
|
674 |
tree->header()->setSortIndicator(3,Qt::DescendingOrder);
|
|
675 |
QTest::qWait(200);
|
|
676 |
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox");
|
|
677 |
QPushButton *button = buttonBox->button(QDialogButtonBox::Open);
|
|
678 |
QTest::mouseClick(button, Qt::LeftButton);
|
|
679 |
#if defined(Q_OS_WINCE)
|
|
680 |
QTest::qWait(1500);
|
|
681 |
#else
|
|
682 |
QTest::qWait(500);
|
|
683 |
#endif
|
|
684 |
QNonNativeFileDialog fd2;
|
|
685 |
fd2.setFileMode(QFileDialog::Directory);
|
|
686 |
fd2.restoreState(fd.saveState());
|
|
687 |
current.cd("aaaaaaaaaaaaaaaaaa");
|
|
688 |
fd2.setDirectory(current.absolutePath());
|
|
689 |
fd2.show();
|
|
690 |
#if defined(Q_OS_WINCE)
|
|
691 |
QTest::qWait(1500);
|
|
692 |
#else
|
|
693 |
QTest::qWait(500);
|
|
694 |
#endif
|
|
695 |
QTreeView *tree2 = qFindChild<QTreeView*>(&fd2, "treeView");
|
|
696 |
tree2->setFocus();
|
|
697 |
|
|
698 |
QCOMPARE(tree2->rootIndex().data(QFileSystemModel::FilePathRole).toString(),current.absolutePath());
|
|
699 |
|
|
700 |
QDialogButtonBox *buttonBox2 = qFindChild<QDialogButtonBox*>(&fd2, "buttonBox");
|
|
701 |
QPushButton *button2 = buttonBox2->button(QDialogButtonBox::Open);
|
|
702 |
fd2.selectFile("g");
|
|
703 |
QTest::mouseClick(button2, Qt::LeftButton);
|
|
704 |
#if defined(Q_OS_WINCE)
|
|
705 |
QTest::qWait(1500);
|
|
706 |
#else
|
|
707 |
QTest::qWait(500);
|
|
708 |
#endif
|
|
709 |
QCOMPARE(fd2.selectedFiles().first(), current.absolutePath() + QChar('/') + QLatin1String("g"));
|
|
710 |
|
|
711 |
QNonNativeFileDialog fd3(0, "This is a third file dialog", tempFile->fileName());
|
|
712 |
fd3.restoreState(fd.saveState());
|
|
713 |
fd3.setFileMode(QFileDialog::Directory);
|
|
714 |
fd3.show();
|
|
715 |
#if defined(Q_OS_WINCE)
|
|
716 |
QTest::qWait(1500);
|
|
717 |
#else
|
|
718 |
QTest::qWait(500);
|
|
719 |
#endif
|
|
720 |
QTreeView *tree3 = qFindChild<QTreeView*>(&fd3, "treeView");
|
|
721 |
tree3->setFocus();
|
|
722 |
|
|
723 |
QCOMPARE(tree3->rootIndex().data(QFileSystemModel::FilePathRole).toString(), current.absolutePath());
|
|
724 |
|
|
725 |
QDialogButtonBox *buttonBox3 = qFindChild<QDialogButtonBox*>(&fd3, "buttonBox");
|
|
726 |
QPushButton *button3 = buttonBox3->button(QDialogButtonBox::Open);
|
|
727 |
QTest::mouseClick(button3, Qt::LeftButton);
|
|
728 |
#if defined(Q_OS_WINCE)
|
|
729 |
QTest::qWait(1500);
|
|
730 |
#else
|
|
731 |
QTest::qWait(500);
|
|
732 |
#endif
|
|
733 |
QCOMPARE(fd3.selectedFiles().first(), tempFile->fileName());
|
|
734 |
|
|
735 |
current.cd("aaaaaaaaaaaaaaaaaa");
|
|
736 |
current.rmdir("a");
|
|
737 |
current.rmdir("b");
|
|
738 |
current.rmdir("c");
|
|
739 |
current.rmdir("d");
|
|
740 |
current.rmdir("e");
|
|
741 |
current.rmdir("f");
|
|
742 |
current.rmdir("g");
|
|
743 |
tempFile->close();
|
|
744 |
delete tempFile;
|
|
745 |
current.cdUp();
|
|
746 |
current.rmdir("aaaaaaaaaaaaaaaaaa");
|
|
747 |
}
|
|
748 |
|
|
749 |
|
|
750 |
void tst_QFiledialog::task239706_editableFilterCombo()
|
|
751 |
{
|
|
752 |
QNonNativeFileDialog d;
|
|
753 |
d.setNameFilter("*.cpp *.h");
|
|
754 |
|
|
755 |
d.show();
|
|
756 |
QTest::qWait(500);
|
|
757 |
|
|
758 |
QList<QComboBox *> comboList = d.findChildren<QComboBox *>();
|
|
759 |
QComboBox *filterCombo = 0;
|
|
760 |
foreach (QComboBox *combo, comboList) {
|
|
761 |
if (combo->objectName() == QString("fileTypeCombo")) {
|
|
762 |
filterCombo = combo;
|
|
763 |
break;
|
|
764 |
}
|
|
765 |
}
|
|
766 |
Q_ASSERT(filterCombo);
|
|
767 |
filterCombo->setEditable(true);
|
|
768 |
QTest::mouseClick(filterCombo, Qt::LeftButton);
|
|
769 |
QTest::keyPress(filterCombo, Qt::Key_X);
|
|
770 |
QTest::keyPress(filterCombo, Qt::Key_Enter); // should not trigger assertion failure
|
|
771 |
}
|
|
772 |
|
|
773 |
void tst_QFiledialog::task218353_relativePaths()
|
|
774 |
{
|
|
775 |
QDir appDir = QDir::current();
|
|
776 |
QVERIFY(appDir.cdUp() != false);
|
|
777 |
QNonNativeFileDialog d(0, "TestDialog", "..");
|
|
778 |
QCOMPARE(d.directory().absolutePath(), appDir.absolutePath());
|
|
779 |
|
|
780 |
d.setDirectory(appDir.absolutePath() + QLatin1String("/non-existing-directory/../another-non-existing-dir/../"));
|
|
781 |
QCOMPARE(d.directory().absolutePath(), appDir.absolutePath());
|
|
782 |
|
|
783 |
QDir::current().mkdir("test");
|
|
784 |
appDir = QDir::current();
|
|
785 |
d.setDirectory(appDir.absolutePath() + QLatin1String("/test/../test/../"));
|
|
786 |
QCOMPARE(d.directory().absolutePath(), appDir.absolutePath());
|
|
787 |
appDir.rmdir("test");
|
|
788 |
}
|
|
789 |
|
|
790 |
void tst_QFiledialog::task251321_sideBarHiddenEntries()
|
|
791 |
{
|
|
792 |
#if defined QT_BUILD_INTERNAL
|
|
793 |
QNonNativeFileDialog fd;
|
|
794 |
|
|
795 |
QDir current = QDir::currentPath();
|
|
796 |
current.mkdir(".hidden");
|
|
797 |
QDir hiddenDir = QDir(".hidden");
|
|
798 |
hiddenDir.mkdir("subdir");
|
|
799 |
QDir hiddenSubDir = QDir(".hidden/subdir");
|
|
800 |
hiddenSubDir.mkdir("happy");
|
|
801 |
hiddenSubDir.mkdir("happy2");
|
|
802 |
|
|
803 |
QList<QUrl> urls;
|
|
804 |
urls << QUrl::fromLocalFile(hiddenSubDir.absolutePath());
|
|
805 |
fd.setSidebarUrls(urls);
|
|
806 |
fd.show();
|
|
807 |
QTest::qWait(250);
|
|
808 |
|
|
809 |
QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar");
|
|
810 |
sidebar->setFocus();
|
|
811 |
sidebar->selectUrl(QUrl::fromLocalFile(hiddenSubDir.absolutePath()));
|
|
812 |
QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center());
|
|
813 |
// give the background processes more time on windows mobile
|
|
814 |
#ifdef Q_OS_WINCE
|
|
815 |
QTest::qWait(1000);
|
|
816 |
#else
|
|
817 |
QTest::qWait(250);
|
|
818 |
#endif
|
|
819 |
|
|
820 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model");
|
|
821 |
QCOMPARE(model->rowCount(model->index(hiddenSubDir.absolutePath())), 2);
|
|
822 |
|
|
823 |
hiddenSubDir.rmdir("happy2");
|
|
824 |
hiddenSubDir.rmdir("happy");
|
|
825 |
hiddenDir.rmdir("subdir");
|
|
826 |
current.rmdir(".hidden");
|
|
827 |
#endif
|
|
828 |
}
|
|
829 |
|
|
830 |
#if defined QT_BUILD_INTERNAL
|
|
831 |
class MyQSideBar : public QSidebar
|
|
832 |
{
|
|
833 |
public :
|
|
834 |
MyQSideBar(QWidget *parent = 0) : QSidebar(parent)
|
|
835 |
{}
|
|
836 |
|
|
837 |
void removeSelection() {
|
|
838 |
QList<QModelIndex> idxs = selectionModel()->selectedIndexes();
|
|
839 |
QList<QPersistentModelIndex> indexes;
|
|
840 |
for (int i = 0; i < idxs.count(); i++)
|
|
841 |
indexes.append(idxs.at(i));
|
|
842 |
|
|
843 |
for (int i = 0; i < indexes.count(); ++i)
|
|
844 |
if (!indexes.at(i).data(Qt::UserRole + 1).toUrl().path().isEmpty())
|
|
845 |
model()->removeRow(indexes.at(i).row());
|
|
846 |
}
|
|
847 |
};
|
|
848 |
#endif
|
|
849 |
|
|
850 |
void tst_QFiledialog::task251341_sideBarRemoveEntries()
|
|
851 |
{
|
|
852 |
#if defined QT_BUILD_INTERNAL
|
|
853 |
QNonNativeFileDialog fd;
|
|
854 |
|
|
855 |
QDir current = QDir::currentPath();
|
|
856 |
current.mkdir("testDir");
|
|
857 |
QDir testSubDir = QDir("testDir");
|
|
858 |
|
|
859 |
QList<QUrl> urls;
|
|
860 |
urls << QUrl::fromLocalFile(testSubDir.absolutePath());
|
|
861 |
urls << QUrl::fromLocalFile("NotFound");
|
|
862 |
fd.setSidebarUrls(urls);
|
|
863 |
fd.show();
|
|
864 |
QTest::qWait(250);
|
|
865 |
|
|
866 |
QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar");
|
|
867 |
sidebar->setFocus();
|
|
868 |
//We enter in the first bookmark
|
|
869 |
sidebar->selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath()));
|
|
870 |
QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center());
|
|
871 |
QTest::qWait(250);
|
|
872 |
|
|
873 |
QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model");
|
|
874 |
//There is no file
|
|
875 |
QCOMPARE(model->rowCount(model->index(testSubDir.absolutePath())), 0);
|
|
876 |
//Icon is not enabled QUrlModel::EnabledRole
|
|
877 |
QVariant value = sidebar->model()->index(0, 0).data(Qt::UserRole + 2);
|
|
878 |
QCOMPARE(qvariant_cast<bool>(value), true);
|
|
879 |
|
|
880 |
sidebar->setFocus();
|
|
881 |
//We enter in the second bookmark which is invalid
|
|
882 |
sidebar->selectUrl(QUrl::fromLocalFile("NotFound"));
|
|
883 |
QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center());
|
|
884 |
QTest::qWait(250);
|
|
885 |
|
|
886 |
//We fallback to root because the entry in the bookmark is invalid
|
|
887 |
QCOMPARE(model->rowCount(model->index("NotFound")), model->rowCount(model->index(model->rootPath())));
|
|
888 |
//Icon is not enabled QUrlModel::EnabledRole
|
|
889 |
value = sidebar->model()->index(1, 0).data(Qt::UserRole + 2);
|
|
890 |
QCOMPARE(qvariant_cast<bool>(value), false);
|
|
891 |
|
|
892 |
MyQSideBar mySideBar;
|
|
893 |
mySideBar.init(model, urls);
|
|
894 |
mySideBar.show();
|
|
895 |
mySideBar.selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath()));
|
|
896 |
QTest::qWait(1000);
|
|
897 |
mySideBar.removeSelection();
|
|
898 |
|
|
899 |
//We remove the first entry
|
|
900 |
QList<QUrl> expected;
|
|
901 |
expected << QUrl::fromLocalFile("NotFound");
|
|
902 |
QCOMPARE(mySideBar.urls(), expected);
|
|
903 |
|
|
904 |
mySideBar.selectUrl(QUrl::fromLocalFile("NotFound"));
|
|
905 |
mySideBar.removeSelection();
|
|
906 |
|
|
907 |
//We remove the second entry
|
|
908 |
expected.clear();
|
|
909 |
QCOMPARE(mySideBar.urls(), expected);
|
|
910 |
|
|
911 |
current.rmdir("testDir");
|
|
912 |
#endif
|
|
913 |
}
|
|
914 |
|
|
915 |
void tst_QFiledialog::task254490_selectFileMultipleTimes()
|
|
916 |
{
|
|
917 |
QString tempPath = QDir::tempPath();
|
|
918 |
QTemporaryFile *t;
|
|
919 |
t = new QTemporaryFile;
|
|
920 |
t->open();
|
|
921 |
QNonNativeFileDialog fd(0, "TestFileDialog");
|
|
922 |
|
|
923 |
fd.setDirectory(tempPath);
|
|
924 |
fd.setViewMode(QFileDialog::List);
|
|
925 |
fd.setAcceptMode(QFileDialog::AcceptSave);
|
|
926 |
fd.setFileMode(QFileDialog::AnyFile);
|
|
927 |
|
|
928 |
//This should select the file in the QFileDialog
|
|
929 |
fd.selectFile(t->fileName());
|
|
930 |
|
|
931 |
//This should clear the selection and write it into the filename line edit
|
|
932 |
fd.selectFile("new_file.txt");
|
|
933 |
|
|
934 |
fd.show();
|
|
935 |
QTest::qWait(250);
|
|
936 |
|
|
937 |
QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit");
|
|
938 |
QVERIFY(lineEdit);
|
|
939 |
QCOMPARE(lineEdit->text(),QLatin1String("new_file.txt"));
|
|
940 |
QListView *list = qFindChild<QListView*>(&fd, "listView");
|
|
941 |
QVERIFY(list);
|
|
942 |
QCOMPARE(list->selectionModel()->selectedRows(0).count(), 0);
|
|
943 |
|
|
944 |
t->deleteLater();
|
|
945 |
}
|
|
946 |
|
|
947 |
void tst_QFiledialog::task257579_sideBarWithNonCleanUrls()
|
|
948 |
{
|
|
949 |
#if defined QT_BUILD_INTERNAL
|
|
950 |
QDir tempDir = QDir::temp();
|
|
951 |
QLatin1String dirname("autotest_task257579");
|
|
952 |
tempDir.rmdir(dirname); //makes sure it doesn't exist any more
|
|
953 |
QVERIFY(tempDir.mkdir(dirname));
|
|
954 |
QString url = QString::fromLatin1("%1/%2/..").arg(tempDir.absolutePath()).arg(dirname);
|
|
955 |
QNonNativeFileDialog fd;
|
|
956 |
fd.setSidebarUrls(QList<QUrl>() << QUrl::fromLocalFile(url));
|
|
957 |
QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar");
|
|
958 |
QCOMPARE(sidebar->urls().count(), 1);
|
|
959 |
QVERIFY(sidebar->urls().first().toLocalFile() != url);
|
|
960 |
QCOMPARE(sidebar->urls().first().toLocalFile(), QDir::cleanPath(url));
|
|
961 |
|
|
962 |
#ifdef Q_OS_WIN
|
|
963 |
QCOMPARE(sidebar->model()->index(0,0).data().toString().toLower(), tempDir.dirName().toLower());
|
|
964 |
#else
|
|
965 |
QCOMPARE(sidebar->model()->index(0,0).data().toString(), tempDir.dirName());
|
|
966 |
#endif
|
|
967 |
|
|
968 |
//all tests are finished, we can remove the temporary dir
|
|
969 |
QVERIFY(tempDir.rmdir(dirname));
|
|
970 |
#endif
|
|
971 |
}
|
|
972 |
|
|
973 |
void tst_QFiledialog::task259105_filtersCornerCases()
|
|
974 |
{
|
|
975 |
QNonNativeFileDialog fd(0, "TestFileDialog");
|
|
976 |
fd.setNameFilter(QLatin1String("All Files! (*);;Text Files (*.txt)"));
|
|
977 |
fd.setOption(QFileDialog::HideNameFilterDetails, true);
|
|
978 |
fd.show();
|
|
979 |
QTest::qWait(250);
|
|
980 |
|
|
981 |
//Extensions are hidden
|
|
982 |
QComboBox *filters = qFindChild<QComboBox*>(&fd, "fileTypeCombo");
|
|
983 |
QVERIFY(filters);
|
|
984 |
QCOMPARE(filters->currentText(), QLatin1String("All Files!"));
|
|
985 |
filters->setCurrentIndex(1);
|
|
986 |
QCOMPARE(filters->currentText(), QLatin1String("Text Files"));
|
|
987 |
|
|
988 |
//We should have the full names
|
|
989 |
fd.setOption(QFileDialog::HideNameFilterDetails, false);
|
|
990 |
QTest::qWait(250);
|
|
991 |
filters->setCurrentIndex(0);
|
|
992 |
QCOMPARE(filters->currentText(), QLatin1String("All Files! (*)"));
|
|
993 |
filters->setCurrentIndex(1);
|
|
994 |
QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)"));
|
|
995 |
|
|
996 |
//Corner case undocumented of the task
|
|
997 |
fd.setNameFilter(QLatin1String("\352 (I like cheese) All Files! (*);;Text Files (*.txt)"));
|
|
998 |
QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files! (*)"));
|
|
999 |
filters->setCurrentIndex(1);
|
|
1000 |
QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)"));
|
|
1001 |
|
|
1002 |
fd.setOption(QFileDialog::HideNameFilterDetails, true);
|
|
1003 |
filters->setCurrentIndex(0);
|
|
1004 |
QTest::qWait(500);
|
|
1005 |
QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!"));
|
|
1006 |
filters->setCurrentIndex(1);
|
|
1007 |
QCOMPARE(filters->currentText(), QLatin1String("Text Files"));
|
|
1008 |
|
|
1009 |
fd.setOption(QFileDialog::HideNameFilterDetails, true);
|
|
1010 |
filters->setCurrentIndex(0);
|
|
1011 |
QTest::qWait(500);
|
|
1012 |
QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!"));
|
|
1013 |
filters->setCurrentIndex(1);
|
|
1014 |
QCOMPARE(filters->currentText(), QLatin1String("Text Files"));
|
|
1015 |
}
|
|
1016 |
|
|
1017 |
void tst_QFiledialog::QTBUG4419_lineEditSelectAll()
|
|
1018 |
{
|
|
1019 |
QString tempPath = QDir::tempPath();
|
|
1020 |
QTemporaryFile *t;
|
|
1021 |
t = new QTemporaryFile;
|
|
1022 |
t->open();
|
|
1023 |
QNonNativeFileDialog fd(0, "TestFileDialog", t->fileName());
|
|
1024 |
|
|
1025 |
fd.setDirectory(tempPath);
|
|
1026 |
fd.setViewMode(QFileDialog::List);
|
|
1027 |
fd.setAcceptMode(QFileDialog::AcceptSave);
|
|
1028 |
fd.setFileMode(QFileDialog::AnyFile);
|
|
1029 |
|
|
1030 |
fd.show();
|
|
1031 |
QApplication::setActiveWindow(&fd);
|
|
1032 |
QTest::qWaitForWindowShown(&fd);
|
|
1033 |
QTRY_COMPARE(fd.isVisible(), true);
|
|
1034 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&fd));
|
|
1035 |
|
|
1036 |
QTest::qWait(250);
|
|
1037 |
QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit");
|
|
1038 |
|
|
1039 |
QCOMPARE(tempPath + QChar('/') + lineEdit->text(), t->fileName());
|
|
1040 |
QCOMPARE(tempPath + QChar('/') + lineEdit->selectedText(), t->fileName());
|
|
1041 |
}
|
|
1042 |
|
|
1043 |
QTEST_MAIN(tst_QFiledialog)
|
|
1044 |
#include "tst_qfiledialog2.moc"
|