API Documentation
Loading...
Searching...
No Matches
FileChooserDialog.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: FileChooserDialog
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/QCustomStackedWidget.h>
35#include <NDEVR/File.h>
36#include <NDEVR/FileFormat.h>
37#include <NDEVR/Buffer.h>
38#include <NDEVR/UUID.h>
39#include <NDEVR/INIInterface.h>
40#include <QWidget>
41#include <functional>
42#include <QPointer>
43#include <QIcon>
44class QHBoxLayout;
45#if NDEVR_SUPPORTS_THREADING
46class QThread;
47#endif
48namespace NDEVR
49{
50
51 class INIFactory;
52 class Button;
53 class QCustomTableWidget;
54 class Thread;
55 class Toggle;
56 class ButtonGallery;
57 class QCustomLineEdit;
58 class QCustomComboBox;
59 class QCustomMessageBox;
60 class FolderCreatorWidget;
61 /**--------------------------------------------------------------------------------------------------
62 \brief A placeholder widget for Files displayed with FileChooserDialog until the actual icon can be
63 loaded from the disk, which may be a slow operation for large directories.
64 **/
66 {
67 QPointer<Button> button;
68 QPointer<QCustomTableWidget> table;
70 };
71 /**--------------------------------------------------------------------------------------------------
72 \brief A dialog designed to allow the user to navigate a filesytem and select or create one or more
73 files or folders that match a criteria.
74
75 Supports browsing the filesystem using a native dialog or in touch mode a touch-friendly dialog. Also
76 supports favorites and recents when available.
77 **/
78 class NDEVR_WIDGETS_API FileChooserDialog : public QWidget, public INIInterface
79 {
80 Q_OBJECT
81 public:
82#if NDEVR_SUPPORTS_THREADING
83 friend class ImageCacheThread;
84#endif
86 {
87 e_browser
88 , e_recents
89 , e_favorites
90 };
91 FileChooserDialog(bool save_dialog = false, QWidget *parent = nullptr);
92 FileChooserDialog(const File& ini_location, bool save_dialog = false, QWidget *parent = nullptr);
94 void setOptions(const Buffer<FileFormat>& extensions, bool save_dialog);
95 QSize sizeHint() const override;
97 //Should be used normally to correctly show the dialog in the most reasonable way
101 void setAllowAny(bool allow_any) { m_allow_any = allow_any; }
102 bool isSaveDialog() const { return m_save_dialog; }
103 void setCurrentDirectory(const File& current_directory);
104 void setFallbackDirectory(const File& file);
105 void setSaveContent(const Buffer<UUID>& save_content) { m_save_content = save_content; }
106 const Buffer<UUID>& saveContent() const { return m_save_content; }
107 void showModifiedTime(bool show_modified_time);
108 void showAccessedTime(bool show_accessed_time);
109 void showFileSize(bool show_modified_time);
110 void setShowRecents(bool show_recent);
111 void setCurrentFileName(const String& name);
112 void setCurrentFile(const File& file);
113 void setCurrentExtension(const String& extension, bool update_format_to_first_match);
114 bool event(QEvent* e) override;
115 bool isFolderBrowser() const;
116 bool showRecents() const { return m_show_recents; };
117 bool showFavorites() const;
118 void prepareForINI(INIFactory& factory) override;
119 void finishReadingINI(INIFactory& factory) override;
122 void browseFile(PopupInfo popup_origin = PopupInfo());
123 void setIconProvider(const std::function<String(const FileRequest&)>& icon_provider);
124 void setCanReadCallback(const std::function<bool(const FileFormat&, const File&)>& callback);
126 void setActionName(const TranslatedString& action_name);
127 void addToRecents(const Buffer<File>& files);
128 void addToRecents(const File& file);
131 const File& currentDirectory() const { return m_current_directory; };
132 void setNativeParent(QWidget* native_parent);
133 protected:
144 QWidget* createRequestWidget(File item);
148 QWidget* settingsDialog();
149 String extensionsString(const String& delimiter = ";;") const;
150 void addItem(ButtonGallery* gallery, QCustomTableWidget* table, uint04 index, const File& item);
154 void setup();
155 FileFormat getFileFormat(const QString& file, const QString& string) const;
158 Buffer<File> filterFiles(const Buffer<File>& all_files) const;
159 bool checkFileAgainstFilter(const File& file, const FileFormat& selected_format) const;
162 void setIsFileChooser(bool is_file_chooser);
163 void onFileChosen(File file);
164 private slots:
165 void contextMenu(const QPoint &pos);
166 void browsingFinished();
167 void updateFilesSlot();
168 signals:
172 private:
173 void _setDisplayMode(DisplayMode mode);
174 QIcon _getIconCallback(const File& file);
175 String _getIconID(const File& file);
176 void _setCurrentDirectory(const File& dir);
177 void onUserReadyToFinish(bool was_browsing);
178 void onUserFinish();
179 void setFileIcon(File file, QIcon icon);
180 void showFiles(ButtonGallery* gallery, QCustomTableWidget* table, const Buffer<File>& files);
181 QCustomTableWidget* createTable(bool is_favorites = false);
182 virtual void getINI(INIFactory& factory) override;
183 bool getSelectedFilters(QString & selected_filter, QString & default_suffix);
184 void resolveIcons();
185 void resolveIcon(const File& file);
186 private:
187 Buffer<File> m_recent_files;
188 Dictionary<File, FileCachedData> m_program_managed_data;
189 mutable Buffer<File> m_current_directory_files;
190 Buffer<File> m_additional_favorites;
191 Dictionary<File, QIcon> m_cached_icons;
192 Dictionary<File, IconCacheWidget> m_cached_icon_locations;
193 File m_current_directory;
194 File m_fallback_directory;
195 String m_current_file_name;
196 String m_current_file_extension;
197 Buffer<FileFormat> m_filter;
198
199 QHBoxLayout* m_top_layout;
200 String m_last_dir;
201 bool m_save_dialog;
202 bool m_show_recents = true;
203 bool m_touch_prefer_gallery = true;
204 bool m_desktop_prefer_gallery = false;
205 bool m_show_hidden = false;
206 bool m_show_extensions = true;
207 bool m_show_favorites;
208 DisplayMode m_display_mode;
209 FolderCreatorWidget* m_folder_creation_widget;
210 QCustomTableWidget* m_file_table;
211 QCustomTableWidget* m_favorites_table;
212 ButtonGallery* m_file_gallery;
213 QCustomStackedWidget* m_view_stack;
214 Button* m_browse_button;
215 Button* m_database_button;
216 Button* m_view_toggle;
217 Button* m_accept_button;
218 Button* m_new_folder_button;
219 Button* m_up_level_button;
220 Button* m_favorites_button;
221 QWidget* m_navigation_buttons;
222 QWidget* m_bottom_buttons;
223 QWidget* m_favorites_panel;
224 QCustomComboBox* m_file_types_combo;
225 QCustomLineEdit* m_location_label;
226
227 QCustomLineEdit* m_file_name_line_edit;
228 QCustomMessageBox* m_override_file_message_box;
229 QCustomMessageBox* m_invalid_file_message_box;
230 Buffer<UUID> m_save_content;
231 QIcon m_loading_icon;
232 QWidget* m_popup_dialog;
233 QWidget* m_settings_dialog;
234
235 TranslatedString m_action_name;
236
237 Buffer<File> m_pending_icons;
238#if NDEVR_SUPPORTS_THREADING
239 QThread* m_icon_thread = nullptr;
240#endif
241 QWidget* m_native_parent = nullptr;
242 std::function<String(const FileRequest&)> m_icon_provider;
243 std::function<bool(const FileFormat&, const File&)> m_can_read_callback;
244 protected:
248 bool m_neeeds_to_update = false;
249 };
250}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:59
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A core widget that allows the user to click one of many button types.
Definition Button.h:66
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
A dialog designed to allow the user to navigate a filesytem and select or create one or more files or...
Definition FileChooserDialog.h:79
void setAdditionalFavorites(Buffer< File > favorites)
void showFileSize(bool show_modified_time)
void setActionName(const TranslatedString &action_name)
void addToRecents(const Buffer< File > &files)
void removeFromRecents(File item)
void setSaveContent(const Buffer< UUID > &save_content)
Definition FileChooserDialog.h:105
FileFormat getFileFormat(const File &file)
TranslatedString windowTitle() const
void setCurrentFileName(const String &name)
void setAllowAny(bool allow_any)
Definition FileChooserDialog.h:101
QWidget * createRequestWidget(File item)
QSize sizeHint() const override
void addItem(ButtonGallery *gallery, QCustomTableWidget *table, uint04 index, const File &item)
const Buffer< FileRequest > & getSelectedRequests() const
void autoShowDialog(PopupInfo info=PopupInfo())
FileFormat currentSelectedFormat() const
bool isFolderBrowser() const
void updateGallery(Button *b)
bool showFavorites() const
bool isSaveDialog() const
Definition FileChooserDialog.h:102
void setCurrentFile(const File &file)
FileFormat getFileFormat(const QString &file, const QString &string) const
void onFileChosen(File file)
DisplayMode
Definition FileChooserDialog.h:86
TranslatedString actionName() const
void setIconProvider(const std::function< String(const FileRequest &)> &icon_provider)
FileChooserDialog(bool save_dialog=false, QWidget *parent=nullptr)
Buffer< File > getSelected() const
bool m_allow_any
Definition FileChooserDialog.h:246
void prepareForINI(INIFactory &factory) override
void finishReadingINI(INIFactory &factory) override
bool event(QEvent *e) override
void setCurrentExtension(const String &extension, bool update_format_to_first_match)
void updateTableIconSize(QCustomTableWidget *table)
QWidget * createBottomPanel()
String extensionsString(const String &delimiter=";;") const
void setFallbackDirectory(const File &file)
const Buffer< File > favoriteFiles() const
QWidget * createNavigationButtons()
void addToRecents(const File &file)
const File & currentDirectory() const
Definition FileChooserDialog.h:131
Buffer< FileRequest > m_selected_files
Definition FileChooserDialog.h:245
QWidget * createfavoritesPanel()
void setNativeParent(QWidget *native_parent)
void setIsFileChooser(bool is_file_chooser)
Buffer< File > filterFiles(const Buffer< File > &all_files) const
void browseFile(PopupInfo popup_origin=PopupInfo())
bool checkFileAgainstFilter(const File &file, const FileFormat &selected_format) const
void setCanReadCallback(const std::function< bool(const FileFormat &, const File &)> &callback)
void setCurrentDirectory(const File &current_directory)
void autoHideDialog(PopupInfo info=PopupInfo())
void setShowRecents(bool show_recent)
bool showRecents() const
Definition FileChooserDialog.h:116
const Buffer< UUID > & saveContent() const
Definition FileChooserDialog.h:106
const Buffer< File > & currentDirectoryFiles() const
void showAccessedTime(bool show_accessed_time)
FileChooserDialog(const File &ini_location, bool save_dialog=false, QWidget *parent=nullptr)
FileFormat getFileFormatFromExtension(const String &ext) const
void showModifiedTime(bool show_modified_time)
void setOptions(const Buffer< FileFormat > &extensions, bool save_dialog)
Data that describes a particular file format and how to use the format with the program....
Definition FileFormat.h:43
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:68
Contains methods for easily reading and writing to an INI file including.
Definition INIInterface.h:45
A compact way to present a list of options to the user.
Definition QCustomCombobox.h:53
A line edit allows users to enter and edit a single line of plain text with useful editing functions,...
Definition QCustomLineEdit.h:56
A message box displays a primary text to alert the user to a situation, an informative text to furthe...
Definition QCustomMessageBox.h:61
The main class for a layout where all widgets occupy the same same and only one widget is shown at a ...
Definition QCustomStackedWidget.h:149
Provides a standard way to show table data within the application.
Definition QCustomTableWidget.h:44
The core String class for the NDEVR API.
Definition String.h:69
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
A FileRequest bundles format data as well as a particular file.
Definition FileFormat.h:75
A placeholder widget for Files displayed with FileChooserDialog until the actual icon can be loaded f...
Definition FileChooserDialog.h:66
uint04 table_index
Definition FileChooserDialog.h:69
QPointer< Button > button
Definition FileChooserDialog.h:67
QPointer< QCustomTableWidget > table
Definition FileChooserDialog.h:68
Class which is used to pass arguments and requests for creating a popup dialog or widget....
Definition PopupInfo.h:15