Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
file_manager.h
1// SPDX-FileCopyrightText: © 2019-2023 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#ifndef __GUI_BACKEND_FILE_MANAGER_H__
5#define __GUI_BACKEND_FILE_MANAGER_H__
6
7#include <memory>
8#include <utility>
9#include <vector>
10
11#include "gui/backend/io/file_descriptor.h"
12#include "utils/app_settings.h"
13
14#include <QString>
15
21
26{
27 FILE_MANAGER_NONE,
28 FILE_MANAGER_HOME,
29 FILE_MANAGER_DESKTOP,
30 FILE_MANAGER_DRIVE,
31};
32
44struct FileBrowserLocation
45{
46 FileBrowserLocation (
47 QString label,
48 std::filesystem::path path,
49 FileManagerSpecialLocation special_location)
50 : label_ (std::move (label)), path_ (std::move (path)),
51 special_location_ (special_location)
52 {
53 }
54 FileBrowserLocation () = default;
55
56 const char * get_icon_name () const
57 {
58 switch (special_location_)
59 {
60 case FileManagerSpecialLocation::FILE_MANAGER_NONE:
61 return "folder";
62 case FileManagerSpecialLocation::FILE_MANAGER_HOME:
63 return "user-home";
64 case FileManagerSpecialLocation::FILE_MANAGER_DESKTOP:
65 return "desktop";
66 case FileManagerSpecialLocation::FILE_MANAGER_DRIVE:
67 return "drive-harddisk-symbolic";
68 }
69 return "folder";
70 }
71
72 void print () const;
73
74 // GMenuModel * generate_context_menu () const;
75
77 QString label_;
78
80 std::filesystem::path path_;
81
84};
85
90{
91 FB_SELECTION_TYPE_COLLECTIONS,
92 FB_SELECTION_TYPE_LOCATIONS,
93};
94
100class FileManager
101{
102public:
103 FileManager (utils::AppSettings &app_settings);
104
108 void load_files ();
109
118 void
119 set_selection (FileBrowserLocation &sel, bool load_files, bool save_to_settings);
120
127 void add_location_and_save (const std::filesystem::path &abs_path);
128
138 const std::filesystem::path &location,
139 bool skip_if_standard);
140
141private:
145 void save_locations ();
146
152 void load_files_from_location (FileBrowserLocation &location);
153
154 // void add_volume (GVolume * vol);
155
156public:
161 std::vector<FileDescriptor> files;
162
166 std::vector<FileBrowserLocation> locations;
167
171 std::unique_ptr<FileBrowserLocation> selection;
172
173private:
174 utils::AppSettings &app_settings_;
175};
176
180
181#endif
std::unique_ptr< FileBrowserLocation > selection
The current selection in the top window.
void set_selection(FileBrowserLocation &sel, bool load_files, bool save_to_settings)
Sets the current selection and optionally loads the files and saves the location to the settings.
std::vector< FileDescriptor > files
The file descriptors for the files under the current collection/location.
void load_files()
Loads the files under the current selection.
void remove_location_and_save(const std::filesystem::path &location, bool skip_if_standard)
Removes the given location (bookmark) from the saved locations and saves the settings.
std::vector< FileBrowserLocation > locations
The default and user-defined locations (bookmarks).
void add_location_and_save(const std::filesystem::path &abs_path)
Adds a new location (bookmark) to the saved locations and saves the settings.
FileManagerSpecialLocation
Special location type.
FileBrowserSelectionType
Current selection in the top window.
Locations to be used in the file browser.
FileManagerSpecialLocation special_location_
Whether this is a standard (undeletable) location.
QString label_
Human readable label.
std::filesystem::path path_
Absolute path.