Overte C++ Documentation
FileDialogHelper.h
1 //
2 // Created by Bradley Austin Davis on 2016-01-21
3 // Copyright 2015 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 #pragma once
9 #ifndef hifi_ui_FileDialogHelper_h
10 #define hifi_ui_FileDialogHelper_h
11 
12 #include <QtCore/QFileSystemWatcher>
13 #include <QtCore/QObject>
14 #include <QtCore/QStandardPaths>
15 #include <QtCore/QString>
16 #include <QtCore/QStringList>
17 #include <QtCore/QUrl>
18 
19 #include <functional>
20 
21 class FileDialogHelper : public QObject {
22  Q_OBJECT
23  Q_ENUMS(StandardLocation)
24 
25 public:
26  // Do not re-order, must match QDesktopServices
27  enum StandardLocation {
28  DesktopLocation,
29  DocumentsLocation,
30  FontsLocation,
31  ApplicationsLocation,
32  MusicLocation,
33  MoviesLocation,
34  PicturesLocation,
35  TempLocation,
36  HomeLocation,
37  DataLocation,
38  CacheLocation,
39  GenericDataLocation,
40  RuntimeLocation,
41  ConfigLocation,
42  DownloadLocation,
43  GenericCacheLocation,
44  GenericConfigLocation,
45  AppDataLocation,
46  AppConfigLocation,
47  AppLocalDataLocation = DataLocation
48  };
49 
50  Q_INVOKABLE QUrl home();
51  Q_INVOKABLE QStringList standardPath(StandardLocation location);
52  Q_INVOKABLE QString writableLocation(StandardLocation location);
53  Q_INVOKABLE QStringList drives();
54  Q_INVOKABLE QString urlToPath(const QUrl& url);
55  Q_INVOKABLE bool urlIsDir(const QUrl& url);
56  Q_INVOKABLE bool urlIsFile(const QUrl& url);
57  Q_INVOKABLE bool urlExists(const QUrl& url);
58  Q_INVOKABLE bool urlIsWritable(const QUrl& url);
59  Q_INVOKABLE bool fileExists(const QString& path);
60  Q_INVOKABLE bool validPath(const QString& path);
61  Q_INVOKABLE bool validFolder(const QString& path);
62  Q_INVOKABLE QUrl pathToUrl(const QString& path);
63  Q_INVOKABLE QUrl saveHelper(const QString& saveText, const QUrl& currentFolder, const QStringList& selectionFilters);
64  Q_INVOKABLE QList<QUrl> urlToList(const QUrl& url);
65 
66  static void setOpenDirectoryOperator(std::function<void(const QString&)> openDirectoryOperator) { _openDirectoryOperator = openDirectoryOperator; }
67  Q_INVOKABLE void openDirectory(const QString& path);
68 
69  Q_INVOKABLE void monitorDirectory(const QString& path);
70 
71 signals:
72  void contentsChanged();
73 
74 private:
75  QFileSystemWatcher _fsWatcher;
76  QString _fsWatcherPath;
77  static std::function<void(const QString&)> _openDirectoryOperator;
78 };
79 
80 
81 #endif