diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2016-02-16 07:02:56 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2016-02-16 07:02:56 +0100 |
commit | 1d61e0052b6a94546f264c3a37a19db09003d7c8 (patch) | |
tree | 9311e07960d5b08e9948b615f992c36e7bce1cf9 /src/dialogs/qquickabstractfiledialog.cpp | |
parent | 571a44a4dde8f047773f4e91a4a6941cb4cdf212 (diff) | |
parent | 67041bbc667a10ae14a15ed8755b2b1bbf91b686 (diff) | |
download | qtquickcontrols-1d61e0052b6a94546f264c3a37a19db09003d7c8.tar.gz |
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
.qmake.conf
src/dialogs/qquickabstractfiledialog.cpp
src/dialogs/qquickfiledialog.cpp
Change-Id: I60aab7c7e819f82f82fc30f473b36a7a57d9a91a
Diffstat (limited to 'src/dialogs/qquickabstractfiledialog.cpp')
-rw-r--r-- | src/dialogs/qquickabstractfiledialog.cpp | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/src/dialogs/qquickabstractfiledialog.cpp b/src/dialogs/qquickabstractfiledialog.cpp index 3a0d4229..3bc79570 100644 --- a/src/dialogs/qquickabstractfiledialog.cpp +++ b/src/dialogs/qquickabstractfiledialog.cpp @@ -41,9 +41,10 @@ #include "qquickitem.h" #include <private/qguiapplication_p.h> +#include <QQmlEngine> +#include <QQuickWindow> #include <QRegularExpression> #include <QWindow> -#include <QQuickWindow> QT_BEGIN_NAMESPACE @@ -224,4 +225,83 @@ void QQuickAbstractFileDialog::updateModes() emit fileModeChanged(); } +void QQuickAbstractFileDialog::addShortcut(const QString &name, const QString &visibleName, const QString &path) +{ + QQmlEngine *engine = qmlEngine(this); + QUrl url = QUrl::fromLocalFile(path); + + // Since the app can have bindings to the shortcut, we always add it + // to the public API, even if the directory doesn't (yet) exist. + m_shortcuts.setProperty(name, url.toString()); + + // ...but we are more strict about showing it as a clickable link inside the dialog + if (visibleName.isEmpty() || !QDir(path).exists()) + return; + + QJSValue o = engine->newObject(); + o.setProperty("name", visibleName); + // TODO maybe some day QJSValue could directly store a QUrl + o.setProperty("url", url.toString()); + + int length = m_shortcutDetails.property(QLatin1String("length")).toInt(); + m_shortcutDetails.setProperty(length, o); +} + +void QQuickAbstractFileDialog::addShortcutFromStandardLocation(const QString &name, QStandardPaths::StandardLocation loc, bool local) +{ + if (m_selectExisting) { + QStringList readPaths = QStandardPaths::standardLocations(loc); + QString path = readPaths.isEmpty() ? QString() : local ? readPaths.first() : readPaths.last(); + addShortcut(name, QStandardPaths::displayName(loc), path); + } else { + QString path = QStandardPaths::writableLocation(loc); + addShortcut(name, QStandardPaths::displayName(loc), path); + } +} + +void QQuickAbstractFileDialog::populateShortcuts() +{ + QJSEngine *engine = qmlEngine(this); + m_shortcutDetails = engine->newArray(); + m_shortcuts = engine->newObject(); + + addShortcutFromStandardLocation(QLatin1String("desktop"), QStandardPaths::DesktopLocation); + addShortcutFromStandardLocation(QLatin1String("documents"), QStandardPaths::DocumentsLocation); + addShortcutFromStandardLocation(QLatin1String("music"), QStandardPaths::MusicLocation); + addShortcutFromStandardLocation(QLatin1String("movies"), QStandardPaths::MoviesLocation); + addShortcutFromStandardLocation(QLatin1String("home"), QStandardPaths::HomeLocation); + +#ifndef Q_OS_IOS + addShortcutFromStandardLocation(QLatin1String("pictures"), QStandardPaths::PicturesLocation); +#else + // On iOS we point pictures to the system picture folder when loading + addShortcutFromStandardLocation(QLatin1String("pictures"), QStandardPaths::PicturesLocation, !m_selectExisting); +#endif + +#ifndef Q_OS_IOS + // on iOS, this returns only "/", which is never a useful path to read or write anything + const QFileInfoList drives = QDir::drives(); + for (const QFileInfo &fi : drives) + addShortcut(fi.absoluteFilePath(), fi.absoluteFilePath(), fi.absoluteFilePath()); +#endif + + emit shortcutsChanged(); +} + +QJSValue QQuickAbstractFileDialog::shortcuts() +{ + if (m_shortcuts.isUndefined()) + populateShortcuts(); + + return m_shortcuts; +} + +QJSValue QQuickAbstractFileDialog::__shortcuts() +{ + if (m_shortcutDetails.isUndefined()) + populateShortcuts(); + + return m_shortcutDetails; +} + QT_END_NAMESPACE |