summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2015-03-18 12:59:28 +0100
committerShawn Rutledge <shawn.rutledge@digia.com>2015-03-18 15:13:43 +0000
commit32e297a03fc9823b894a7d1c0c11b082abc662b0 (patch)
tree316c187e0a40ce35e86f704d53f9e2e7ea248e5d
parentc9e558a64833a7f74e9c0423c35a73ed5229f112 (diff)
downloadqtquickcontrols-32e297a03fc9823b894a7d1c0c11b082abc662b0.tar.gz
FileDialog: make the save/load distinction function properly
- shortcuts need to be different: use QStandardPaths::writableLocation if it's a "save" dialog - that means shortcuts need to change dynamically, because the same dialog instance can be reused for both purposes - DefaultFileDialog.qml changes its button labels accordingly Change-Id: Ie90d96cc686caf30e86669a79e613585f8fb3704 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com>
-rw-r--r--src/dialogs/DefaultFileDialog.qml2
-rw-r--r--src/dialogs/qquickabstractfiledialog_p.h2
-rw-r--r--src/dialogs/qquickfiledialog.cpp48
-rw-r--r--src/dialogs/qquickfiledialog_p.h8
4 files changed, 43 insertions, 17 deletions
diff --git a/src/dialogs/DefaultFileDialog.qml b/src/dialogs/DefaultFileDialog.qml
index 0336695a..bcfafb41 100644
--- a/src/dialogs/DefaultFileDialog.qml
+++ b/src/dialogs/DefaultFileDialog.qml
@@ -445,7 +445,7 @@ AbstractFileDialog {
}
Button {
id: okButton
- text: qsTr("OK")
+ text: selectExisting ? qsTr("Open") : qsTr("Save")
onClicked: {
if (view.model.isFolder(view.currentIndex) && !selectFolder)
dirDown(view.model.get(view.currentIndex, "filePath"))
diff --git a/src/dialogs/qquickabstractfiledialog_p.h b/src/dialogs/qquickabstractfiledialog_p.h
index c7320fd1..9275c1da 100644
--- a/src/dialogs/qquickabstractfiledialog_p.h
+++ b/src/dialogs/qquickabstractfiledialog_p.h
@@ -108,7 +108,7 @@ Q_SIGNALS:
void sidebarVisibleChanged();
protected:
- void updateModes();
+ virtual void updateModes();
protected:
QPlatformFileDialogHelper *m_dlgHelper;
diff --git a/src/dialogs/qquickfiledialog.cpp b/src/dialogs/qquickfiledialog.cpp
index f2325a53..0e58a094 100644
--- a/src/dialogs/qquickfiledialog.cpp
+++ b/src/dialogs/qquickfiledialog.cpp
@@ -125,11 +125,27 @@ void QQuickFileDialog::addShortcut(uint &i, const QString &name, const QString &
++i;
}
-void QQuickFileDialog::addIfReadable(uint &i, const QString &name, const QString &visibleName, QStandardPaths::StandardLocation loc)
+void QQuickFileDialog::maybeAdd(uint &i, const QString &name, const QString &visibleName, QStandardPaths::StandardLocation loc)
{
- QStringList paths = QStandardPaths::standardLocations(loc);
- if (!paths.isEmpty() && QDir(paths.first()).isReadable())
- addShortcut(i, name, visibleName, paths.first());
+ if (name.isEmpty() || visibleName.isEmpty())
+ return;
+ QString path;
+ bool usable = false;
+ if (m_selectExisting) {
+ QStringList readPaths = QStandardPaths::standardLocations(loc);
+ if (!readPaths.isEmpty()) {
+ path = readPaths.first();
+ usable = QDir(path).isReadable();
+ }
+ } else {
+ path = QStandardPaths::writableLocation(loc);
+ // There is no QDir::isWritable(), but we can assume that if you don't have
+ // permission to read, you can't write either. When you actually try to write,
+ // other things can go wrong anyway, and we cannot know until we try.
+ usable = QDir(path).isReadable();
+ }
+ if (usable)
+ addShortcut(i, name, visibleName, path);
}
void QQuickFileDialog::populateShortcuts()
@@ -139,17 +155,18 @@ void QQuickFileDialog::populateShortcuts()
m_shortcuts = engine->newObject();
uint i = 0;
- addIfReadable(i, QLatin1String("desktop"), QStandardPaths::displayName(QStandardPaths::DesktopLocation), QStandardPaths::DesktopLocation);
- addIfReadable(i, QLatin1String("documents"), QStandardPaths::displayName(QStandardPaths::DocumentsLocation), QStandardPaths::DocumentsLocation);
- addIfReadable(i, QLatin1String("music"), QStandardPaths::displayName(QStandardPaths::MusicLocation), QStandardPaths::MusicLocation);
- addIfReadable(i, QLatin1String("movies"), QStandardPaths::displayName(QStandardPaths::MoviesLocation), QStandardPaths::MoviesLocation);
- addIfReadable(i, QLatin1String("pictures"), QStandardPaths::displayName(QStandardPaths::PicturesLocation), QStandardPaths::PicturesLocation);
- addIfReadable(i, QLatin1String("home"), QStandardPaths::displayName(QStandardPaths::HomeLocation), QStandardPaths::HomeLocation);
+ maybeAdd(i, QLatin1String("desktop"), QStandardPaths::displayName(QStandardPaths::DesktopLocation), QStandardPaths::DesktopLocation);
+ maybeAdd(i, QLatin1String("documents"), QStandardPaths::displayName(QStandardPaths::DocumentsLocation), QStandardPaths::DocumentsLocation);
+ maybeAdd(i, QLatin1String("music"), QStandardPaths::displayName(QStandardPaths::MusicLocation), QStandardPaths::MusicLocation);
+ maybeAdd(i, QLatin1String("movies"), QStandardPaths::displayName(QStandardPaths::MoviesLocation), QStandardPaths::MoviesLocation);
+ maybeAdd(i, QLatin1String("pictures"), QStandardPaths::displayName(QStandardPaths::PicturesLocation), QStandardPaths::PicturesLocation);
+ maybeAdd(i, QLatin1String("home"), QStandardPaths::displayName(QStandardPaths::HomeLocation), QStandardPaths::HomeLocation);
#ifdef Q_OS_IOS
// PicturesLocation is a special URL, which we cannot check with QDir::isReadable()
- addShortcut(i, QLatin1String("pictures"), tr("Pictures"),
- QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last());
+ if (m_selectExisting)
+ addShortcut(i, QLatin1String("pictures"), QStandardPaths::displayName(QStandardPaths::PicturesLocation),
+ QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last());
#else
// on iOS, this returns only "/", which is never a useful path to read or write anything
QFileInfoList drives = QDir::drives();
@@ -158,6 +175,13 @@ void QQuickFileDialog::populateShortcuts()
#endif
m_shortcutDetails.setProperty(QLatin1String("length"), i);
+ emit shortcutsChanged();
+}
+
+void QQuickFileDialog::updateModes()
+{
+ QQuickAbstractFileDialog::updateModes();
+ populateShortcuts();
}
QJSValue QQuickFileDialog::shortcuts()
diff --git a/src/dialogs/qquickfiledialog_p.h b/src/dialogs/qquickfiledialog_p.h
index c0ad09a3..59a64dee 100644
--- a/src/dialogs/qquickfiledialog_p.h
+++ b/src/dialogs/qquickfiledialog_p.h
@@ -58,8 +58,8 @@ class QQuickFileDialog : public QQuickAbstractFileDialog
{
Q_OBJECT
Q_PROPERTY(QQuickItem* contentItem READ contentItem WRITE setContentItem DESIGNABLE false)
- Q_PROPERTY(QJSValue shortcuts READ shortcuts CONSTANT) // map of QStandardDirectory names to QUrls
- Q_PROPERTY(QJSValue __shortcuts READ __shortcuts CONSTANT) // map of details for QML dialog implementations
+ Q_PROPERTY(QJSValue shortcuts READ shortcuts NOTIFY shortcutsChanged) // map of QStandardDirectory names to QUrls
+ Q_PROPERTY(QJSValue __shortcuts READ __shortcuts NOTIFY shortcutsChanged) // map of details for QML dialog implementations
Q_CLASSINFO("DefaultProperty", "contentItem") // AbstractFileDialog in QML can have only one child
public:
@@ -71,6 +71,7 @@ public:
QJSValue __shortcuts();
Q_SIGNALS:
+ void shortcutsChanged();
public Q_SLOTS:
void clearSelection();
@@ -83,8 +84,9 @@ protected:
Q_INVOKABLE QUrl pathFolder(const QString &path);
void addShortcut(uint &i, const QString &name, const QString &visibleName, const QString &path);
- void addIfReadable(uint &i, const QString &name, const QString &visibleName, QStandardPaths::StandardLocation loc);
+ void maybeAdd(uint &i, const QString &name, const QString &visibleName, QStandardPaths::StandardLocation loc);
void populateShortcuts();
+ void updateModes() Q_DECL_OVERRIDE;
private:
QList<QUrl> m_selections;