diff options
author | Robin Gareus <robin@gareus.org> | 2015-10-16 19:06:21 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2015-10-16 19:06:21 +0200 |
commit | 2c9666e0ee21666b98fced055d75400f41ec5d0b (patch) | |
tree | 708befca1fb6e70b780ea8025411bc704a13145c | |
parent | 09e0acfccd85f2e2fa9a064c9912368ea342030a (diff) |
API to add system-specific file chooser shortcuts
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/utils.h | 3 | ||||
-rw-r--r-- | libs/gtkmm2ext/utils.cc | 28 |
2 files changed, 31 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/utils.h b/libs/gtkmm2ext/gtkmm2ext/utils.h index 688f4431c6..43baf5980b 100644 --- a/libs/gtkmm2ext/gtkmm2ext/utils.h +++ b/libs/gtkmm2ext/gtkmm2ext/utils.h @@ -28,6 +28,7 @@ #include <pangomm/fontdescription.h> #include <gtkmm/container.h> +#include <gtkmm/filechooser.h> #include <gtkmm/treeview.h> #include <gdkmm/window.h> /* for WMDecoration */ #include <gdkmm/pixbuf.h> @@ -170,6 +171,8 @@ namespace Gtkmm2ext { * use a std::string */ LIBGTKMM2EXT_API std::string markup_escape_text (std::string const& s); + + LIBGTKMM2EXT_API void add_volume_shortcuts (Gtk::FileChooser& c); }; #endif /* __gtkmm2ext_utils_h__ */ diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc index 3762f88dd6..a7790e6775 100644 --- a/libs/gtkmm2ext/utils.cc +++ b/libs/gtkmm2ext/utils.cc @@ -973,3 +973,31 @@ Gtkmm2ext::markup_escape_text (std::string const& s) { return Glib::Markup::escape_text (s); } + +void +Gtkmm2ext::add_volume_shortcuts (Gtk::FileChooser& c) +{ +#ifdef __APPLE__ + try { + /* This is a first order approach, listing all mounted volumes (incl network). + * One could use `diskutil` or `mount` to query local disks only, or + * something even fancier if deemed appropriate. + */ + Glib::Dir dir("/Volumes"); + for (Glib::DirIterator di = dir.begin(); di != dir.end(); di++) { + string fullpath = Glib::build_filename ("/Volumes", *di); + if (!Glib::file_test (fullpath, Glib::FILE_TEST_IS_DIR)) continue; + + try { /* add_shortcut_folder throws an exception if the folder being added already has a shortcut */ + c.add_shortcut_folder (fullpath); + } + catch (Glib::Error& e) { + std::cerr << "add_shortcut_folder() threw Glib::Error: " << e.what() << std::endl; + } + } + } + catch (Glib::FileError& e) { + std::cerr << "listing /Volumnes failed: " << e.what() << std::endl; + } +#endif +} |