| 1 |
/* Copyright (C) 2003 The gtkmm Development Team |
| 2 |
* |
| 3 |
* This library is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU Lesser General Public |
| 5 |
* License as published by the Free Software Foundation; either |
| 6 |
* version 2.1 of the License, or (at your option) any later version. |
| 7 |
* |
| 8 |
* This library is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
* Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public |
| 14 |
* License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <vector> |
| 18 |
|
| 19 |
#include <gtkmm/widget.h> |
| 20 |
#include <gtkmm/filefilter.h> |
| 21 |
#include <giomm/file.h> |
| 22 |
|
| 23 |
_DEFS(gtkmm,gtk) |
| 24 |
_PINCLUDE(glibmm/private/interface_p.h) |
| 25 |
|
| 26 |
namespace Gtk |
| 27 |
{ |
| 28 |
|
| 29 |
_WRAP_ENUM(FileChooserAction, GtkFileChooserAction, decl_prefix GTKMM_API) |
| 30 |
_WRAP_ENUM(FileChooserConfirmation, GtkFileChooserConfirmation, decl_prefix GTKMM_API) |
| 31 |
|
| 32 |
//Note that GTK_FILE_SYSTEM_ERROR is not currently public GTK+ API and should |
| 33 |
//never be instantiated by the GTK+ C API. |
| 34 |
|
| 35 |
/** Exception class for Gdk::FileChooser errors. |
| 36 |
*/ |
| 37 |
_WRAP_GERROR(FileChooserError,GtkFileChooserError,GTK_FILE_CHOOSER_ERROR,decl_prefix GTKMM_API) |
| 38 |
|
| 39 |
/** |
| 40 |
* Gtk::FileChooser is an interface that can be implemented by file selection |
| 41 |
* widgets. In gtkmm, the main objects that implement this interface are |
| 42 |
* FileChooserWidget and FileChooserDialog. You do not need to write an |
| 43 |
* object that implements the FileChooser interface unless you are trying to |
| 44 |
* adapt an existing file selector to expose a standard programming interface. |
| 45 |
* |
| 46 |
* @par File Names and Encodings |
| 47 |
* When the user is finished selecting files in a FileChooser, your program |
| 48 |
* can get the selected names either as filenames or as URIs. For URIs, the |
| 49 |
* normal escaping rules are applied if the URI contains non-ASCII characters. |
| 50 |
* However, filenames are always returned in the character set specified by the |
| 51 |
* G_FILENAME_ENCODING environment variable. Please see the Glib documentation |
| 52 |
* for more details about this variable. |
| 53 |
* |
| 54 |
* @par Important |
| 55 |
* This means that while you can pass the result of FileChooser::get_filename() |
| 56 |
* to <tt>open(2)</tt> or <tt>fopen(3)</tt>, you may not be able to directly |
| 57 |
* set it as the text of a Gtk::Label widget unless you convert it first to |
| 58 |
* UTF-8, which all gtkmm widgets expect. You should use |
| 59 |
* Glib::filename_to_utf8() to convert filenames into strings that can be |
| 60 |
* passed to gtkmm widgets. |
| 61 |
*/ |
| 62 |
class GTKMM_API FileChooser : public Glib::Interface |
| 63 |
{ |
| 64 |
_CLASS_INTERFACE(FileChooser, GtkFileChooser, GTK_FILE_CHOOSER, GtkFileChooserClass, , , GTKMM_API) |
| 65 |
public: |
| 66 |
|
| 67 |
_WRAP_METHOD(void set_action(FileChooserAction action), gtk_file_chooser_set_action) |
| 68 |
_WRAP_METHOD(FileChooserAction get_action() const, gtk_file_chooser_get_action) |
| 69 |
_WRAP_METHOD(void set_local_only(bool local_only = true), gtk_file_chooser_set_local_only) |
| 70 |
_WRAP_METHOD(bool get_local_only() const, gtk_file_chooser_get_local_only) |
| 71 |
_WRAP_METHOD(void set_select_multiple(bool select_multiple = true), gtk_file_chooser_set_select_multiple) |
| 72 |
_WRAP_METHOD(bool get_select_multiple() const, gtk_file_chooser_get_select_multiple) |
| 73 |
|
| 74 |
_WRAP_METHOD(void set_show_hidden(bool show_hidden = true), gtk_file_chooser_set_show_hidden) |
| 75 |
_WRAP_METHOD(bool get_show_hidden() const, gtk_file_chooser_get_show_hidden) |
| 76 |
|
| 77 |
_WRAP_METHOD(void set_do_overwrite_confirmation(bool do_overwrite_confirmation = true), gtk_file_chooser_set_do_overwrite_confirmation) |
| 78 |
_WRAP_METHOD(bool get_do_overwrite_confirmation() const, gtk_file_chooser_get_do_overwrite_confirmation) |
| 79 |
|
| 80 |
_WRAP_METHOD(void set_create_folders(bool create_folders = true), gtk_file_chooser_set_create_folders) |
| 81 |
_WRAP_METHOD(bool get_create_folders() const, gtk_file_chooser_get_create_folders) |
| 82 |
|
| 83 |
_WRAP_METHOD(void set_current_name(const Glib::ustring& name), gtk_file_chooser_set_current_name) |
| 84 |
_WRAP_METHOD(Glib::ustring get_current_name() const, gtk_file_chooser_get_current_name) |
| 85 |
|
| 86 |
_WRAP_METHOD(std::string get_filename() const, gtk_file_chooser_get_filename) |
| 87 |
_WRAP_METHOD(bool set_filename(const std::string& filename), gtk_file_chooser_set_filename) |
| 88 |
_WRAP_METHOD(bool select_filename(const std::string& filename), gtk_file_chooser_select_filename) |
| 89 |
_WRAP_METHOD(void unselect_filename(const std::string& filename), gtk_file_chooser_unselect_filename) |
| 90 |
_WRAP_METHOD(void select_all(), gtk_file_chooser_select_all) |
| 91 |
_WRAP_METHOD(void unselect_all(), gtk_file_chooser_unselect_all) |
| 92 |
|
| 93 |
#m4 _CONVERSION(`GSList*',`std::vector<std::string>',`Glib::SListHandler<std::string>::slist_to_vector($3, Glib::OWNERSHIP_DEEP)') |
| 94 |
_WRAP_METHOD(std::vector<std::string> get_filenames() const, gtk_file_chooser_get_filenames) |
| 95 |
|
| 96 |
_WRAP_METHOD(bool set_current_folder(const std::string& filename), gtk_file_chooser_set_current_folder) |
| 97 |
_WRAP_METHOD(std::string get_current_folder() const, gtk_file_chooser_get_current_folder) |
| 98 |
|
| 99 |
|
| 100 |
/* URI manipulation |
| 101 |
*/ |
| 102 |
_WRAP_METHOD(Glib::ustring get_uri() const, gtk_file_chooser_get_uri) |
| 103 |
_WRAP_METHOD(bool set_uri(const Glib::ustring& uri), gtk_file_chooser_set_uri) |
| 104 |
_WRAP_METHOD(bool select_uri(const Glib::ustring& uri), gtk_file_chooser_select_uri) |
| 105 |
_WRAP_METHOD(void unselect_uri(const Glib::ustring& uri), gtk_file_chooser_unselect_uri) |
| 106 |
#m4 _CONVERSION(`GSList*',`std::vector<Glib::ustring>',`Glib::SListHandler<Glib::ustring>::slist_to_vector($3, Glib::OWNERSHIP_DEEP)') |
| 107 |
_WRAP_METHOD(std::vector<Glib::ustring> get_uris() const, gtk_file_chooser_get_uris) |
| 108 |
|
| 109 |
_WRAP_METHOD(bool set_current_folder_uri(const Glib::ustring& uri), gtk_file_chooser_set_current_folder_uri) |
| 110 |
_WRAP_METHOD(Glib::ustring get_current_folder_uri() const, gtk_file_chooser_get_current_folder_uri) |
| 111 |
|
| 112 |
_WRAP_METHOD(bool set_file(const Glib::RefPtr<const Gio::File>& file), gtk_file_chooser_set_file, errthrow) |
| 113 |
|
| 114 |
_WRAP_METHOD(bool select_file(const Glib::RefPtr<const Gio::File>& file), gtk_file_chooser_select_file, errthrow) |
| 115 |
_WRAP_METHOD(void unselect_file(const Glib::RefPtr<const Gio::File>& file), gtk_file_chooser_unselect_file) |
| 116 |
|
| 117 |
#m4 _CONVERSION(`GSList*',`std::vector< Glib::RefPtr<Gio::File> >',`Glib::SListHandler< Glib::RefPtr<Gio::File> >::slist_to_vector($3, Glib::OWNERSHIP_DEEP)') |
| 118 |
_WRAP_METHOD(std::vector< Glib::RefPtr<Gio::File> > get_files(), gtk_file_chooser_get_files) |
| 119 |
|
| 120 |
_WRAP_METHOD(bool set_current_folder_file(const Glib::RefPtr<const Gio::File>& file), gtk_file_chooser_set_current_folder_file, errthrow) |
| 121 |
|
| 122 |
//No refreturn is needed here, because the C function provides a reference: |
| 123 |
_WRAP_METHOD(Glib::RefPtr<Gio::File> get_current_folder_file(), gtk_file_chooser_get_current_folder_file) |
| 124 |
|
| 125 |
//No refreturn is needed here, because the C function provides a reference: |
| 126 |
_WRAP_METHOD(Glib::RefPtr<Gio::File> get_file(), gtk_file_chooser_get_file) |
| 127 |
_WRAP_METHOD(Glib::RefPtr<const Gio::File> get_file() const, gtk_file_chooser_get_file, constversion) |
| 128 |
|
| 129 |
/* Preview widget |
| 130 |
*/ |
| 131 |
_WRAP_METHOD(void set_preview_widget(Gtk::Widget& preview_widget), gtk_file_chooser_set_preview_widget) |
| 132 |
|
| 133 |
_WRAP_METHOD(Gtk::Widget* get_preview_widget(), gtk_file_chooser_get_preview_widget) |
| 134 |
_WRAP_METHOD(const Gtk::Widget* get_preview_widget() const, gtk_file_chooser_get_preview_widget, constversion) |
| 135 |
|
| 136 |
_WRAP_METHOD(void set_preview_widget_active(bool active = true), gtk_file_chooser_set_preview_widget_active) |
| 137 |
_WRAP_METHOD(bool get_preview_widget_active() const, gtk_file_chooser_get_preview_widget_active) |
| 138 |
|
| 139 |
_WRAP_METHOD(void set_use_preview_label(bool use_label = true), gtk_file_chooser_set_use_preview_label) |
| 140 |
_WRAP_METHOD(bool get_use_preview_label() const, gtk_file_chooser_get_use_preview_label) |
| 141 |
|
| 142 |
#m4 _CONVERSION(`return-char*',`std::string',`Glib::convert_return_gchar_ptr_to_stdstring($3)') |
| 143 |
_WRAP_METHOD(std::string get_preview_filename() const, gtk_file_chooser_get_preview_filename) |
| 144 |
_WRAP_METHOD(Glib::ustring get_preview_uri() const, gtk_file_chooser_get_preview_uri) |
| 145 |
|
| 146 |
//No refreturn is needed here, because the C function provides a reference: |
| 147 |
_WRAP_METHOD(Glib::RefPtr<Gio::File> get_preview_file(), gtk_file_chooser_get_preview_file) |
| 148 |
_WRAP_METHOD(Glib::RefPtr<const Gio::File> get_preview_file() const, gtk_file_chooser_get_preview_file, constversion) |
| 149 |
|
| 150 |
/* Extra widget |
| 151 |
*/ |
| 152 |
_WRAP_METHOD(void set_extra_widget(Gtk::Widget& extra_widget), gtk_file_chooser_set_extra_widget) |
| 153 |
_WRAP_METHOD(Gtk::Widget* get_extra_widget(), gtk_file_chooser_get_extra_widget) |
| 154 |
_WRAP_METHOD(const Gtk::Widget* get_extra_widget() const, gtk_file_chooser_get_extra_widget, constversion) |
| 155 |
|
| 156 |
/* List of user selectable filters |
| 157 |
*/ |
| 158 |
_WRAP_METHOD(void add_filter(const Glib::RefPtr<FileFilter>& filter), gtk_file_chooser_add_filter) |
| 159 |
_WRAP_METHOD(void remove_filter (const Glib::RefPtr<FileFilter>& filter), gtk_file_chooser_remove_filter) |
| 160 |
|
| 161 |
#m4 _CONVERSION(`GSList*',`std::vector< Glib::RefPtr<FileFilter> >',`Glib::SListHandler< Glib::RefPtr<FileFilter> >::slist_to_vector($3, Glib::OWNERSHIP_SHALLOW)') |
| 162 |
#m4 _CONVERSION(`GSList*',`std::vector< Glib::RefPtr<const FileFilter> >',`Glib::SListHandler< Glib::RefPtr<const FileFilter> >::slist_to_vector($3, Glib::OWNERSHIP_SHALLOW)') |
| 163 |
_WRAP_METHOD(std::vector< Glib::RefPtr<FileFilter> > list_filters(), gtk_file_chooser_list_filters) |
| 164 |
_WRAP_METHOD(std::vector< Glib::RefPtr<const FileFilter> > list_filters() const, gtk_file_chooser_list_filters) |
| 165 |
|
| 166 |
/* Current filter |
| 167 |
*/ |
| 168 |
_WRAP_METHOD(void set_filter(const Glib::RefPtr<FileFilter>& filter), gtk_file_chooser_set_filter) |
| 169 |
_WRAP_METHOD(Glib::RefPtr<FileFilter> get_filter(), gtk_file_chooser_get_filter, refreturn) |
| 170 |
_WRAP_METHOD(Glib::RefPtr<const FileFilter> get_filter() const, gtk_file_chooser_get_filter, refreturn, constversion) |
| 171 |
|
| 172 |
/* Per-application shortcut folders */ |
| 173 |
|
| 174 |
_WRAP_METHOD(bool add_shortcut_folder(const std::string& folder), gtk_file_chooser_add_shortcut_folder, errthrow) |
| 175 |
_WRAP_METHOD(bool remove_shortcut_folder(const std::string& folder), gtk_file_chooser_remove_shortcut_folder, errthrow) |
| 176 |
|
| 177 |
_WRAP_METHOD(std::vector<std::string> list_shortcut_folders() const, gtk_file_chooser_list_shortcut_folders) |
| 178 |
|
| 179 |
_WRAP_METHOD(bool add_shortcut_folder_uri(const Glib::ustring& uri), gtk_file_chooser_add_shortcut_folder_uri, errthrow) |
| 180 |
_WRAP_METHOD(bool remove_shortcut_folder_uri(const Glib::ustring& uri), gtk_file_chooser_remove_shortcut_folder_uri, errthrow) |
| 181 |
_WRAP_METHOD(std::vector<Glib::ustring> list_shortcut_folder_uris() const, gtk_file_chooser_list_shortcut_folder_uris) |
| 182 |
|
| 183 |
#m4 _CONVERSION(`const std::vector<Glib::ustring>&',`const char**',`Glib::ArrayHandler<Glib::ustring>::vector_to_array($3).data ()') |
| 184 |
_WRAP_METHOD(void add_choice(const Glib::ustring& id, const Glib::ustring& label, const std::vector<Glib::ustring>& options, const std::vector<Glib::ustring>& option_labels), gtk_file_chooser_add_choice) |
| 185 |
|
| 186 |
/** Adds a boolean 'choice' to the file chooser. |
| 187 |
* This is typically implemented as a checkbutton. You can select |
| 188 |
* a value using set_boolean_choice() before the dialog is shown, |
| 189 |
* and you can obtain the user-selected value in the signal_response() signal handler |
| 190 |
* using get_choice(). |
| 191 |
* |
| 192 |
* Compare set_extra_widget(). |
| 193 |
* |
| 194 |
* @newin{3,22} |
| 195 |
* |
| 196 |
* @param id Id for the added choice. |
| 197 |
* @param label User-visible label for the added choice. |
| 198 |
*/ |
| 199 |
void add_choice(const Glib::ustring& id, const Glib::ustring& label); |
| 200 |
|
| 201 |
_WRAP_METHOD(void remove_choice(const Glib::ustring& id), gtk_file_chooser_remove_choice) |
| 202 |
_WRAP_METHOD(void set_choice(const Glib::ustring& id, const Glib::ustring& option), gtk_file_chooser_set_choice) |
| 203 |
_WRAP_METHOD(Glib::ustring get_choice(const Glib::ustring& id) const, gtk_file_chooser_get_choice) |
| 204 |
|
| 205 |
_WRAP_SIGNAL(void current_folder_changed(), "current_folder_changed", no_default_handler) |
| 206 |
_WRAP_SIGNAL(void selection_changed(), "selection_changed", no_default_handler) |
| 207 |
_WRAP_SIGNAL(void update_preview(), "update_preview", no_default_handler) |
| 208 |
_WRAP_SIGNAL(void file_activated(), "file_activated", no_default_handler) |
| 209 |
_WRAP_SIGNAL(FileChooserConfirmation confirm_overwrite(), "confirm-overwrite", no_default_handler) |
| 210 |
|
| 211 |
_WRAP_PROPERTY("action", FileChooserAction) |
| 212 |
_WRAP_PROPERTY("filter", Glib::RefPtr<FileFilter>) |
| 213 |
_WRAP_PROPERTY("local-only", bool) |
| 214 |
_WRAP_PROPERTY("preview-widget", Widget*) |
| 215 |
_WRAP_PROPERTY("preview-widget-active", bool) |
| 216 |
_WRAP_PROPERTY("use-preview-label", bool) |
| 217 |
_WRAP_PROPERTY("extra-widget", Widget*) |
| 218 |
_WRAP_PROPERTY("select-multiple", bool) |
| 219 |
_WRAP_PROPERTY("show-hidden", bool) |
| 220 |
_WRAP_PROPERTY("do-overwrite-confirmation", bool) |
| 221 |
_WRAP_PROPERTY("create-folders", bool) |
| 222 |
}; |
| 223 |
|
| 224 |
} // namespace Gtk |