diff --git a/rtengine/safegtk.cc b/rtengine/safegtk.cc index 5588cfe18..1aee0e0d5 100644 --- a/rtengine/safegtk.cc +++ b/rtengine/safegtk.cc @@ -20,23 +20,14 @@ */ #include "safegtk.h" -#include "../rtgui/guiutils.h" -#include + #include -#ifdef WIN32 -#include -// for GCC32 -#ifndef _WIN32_IE -#define _WIN32_IE 0x0600 -#endif -#include -#include -#else #include -#endif -#include "../rtgui/rtimage.h" #include +#include + +#include "../rtgui/guiutils.h" Glib::RefPtr safe_query_file_info (Glib::RefPtr &file) { @@ -285,97 +276,3 @@ int safe_g_mkdir_with_parents(const Glib::ustring& dirName, int mode) { return ::g_mkdir_with_parents(dirName.c_str(), mode); } - -Glib::ustring safe_get_user_picture_dir() -{ -#ifdef WIN32 - // get_user_special_dir/pictures crashes on some Windows configurations. - // so we use the safe native functions here - WCHAR pathW[MAX_PATH] = {0}; - - if (SHGetSpecialFolderPathW(NULL, pathW, CSIDL_MYPICTURES, false)) { - char pathA[MAX_PATH]; - WideCharToMultiByte(CP_UTF8, 0, pathW, -1, pathA, MAX_PATH, 0, 0); - return Glib::ustring(pathA); - } else { - return Glib::ustring("C:\\"); - } - -#else - - return Glib::get_user_special_dir (G_USER_DIRECTORY_PICTURES); - -#endif -} - -Glib::ustring safe_get_user_home_dir() -{ -#ifdef WIN32 - // get_user_special_dir/pictures crashes on some Windows configurations. - // so we use the safe native functions here - WCHAR pathW[MAX_PATH] = {0}; - - if (SHGetSpecialFolderPathW(NULL, pathW, CSIDL_PERSONAL, false)) { - char pathA[MAX_PATH]; - WideCharToMultiByte(CP_UTF8, 0, pathW, -1, pathA, MAX_PATH, 0, 0); - return Glib::ustring(pathA); - } else { - return Glib::ustring("C:\\"); - } - -#else - - return Glib::get_home_dir(); - -#endif -} - -#ifdef WIN32 -Glib::ustring safe_get_user_profile_dir() -{ - WCHAR pathW[MAX_PATH] = {0}; - - if (SHGetSpecialFolderPathW(NULL, pathW, CSIDL_PROFILE, false)) { - char pathA[MAX_PATH]; - WideCharToMultiByte(CP_UTF8, 0, pathW, -1, pathA, MAX_PATH, 0, 0); - return Glib::ustring(pathA); - } else { - return Glib::ustring("C:\\"); - } -} -#endif - - -Glib::ustring safe_get_user_desktop_dir() -{ -#ifdef WIN32 - // get_user_special_dir/pictures crashes on some Windows configurations. - // so we use the safe native functions here - WCHAR pathW[MAX_PATH] = {0}; - - if (SHGetSpecialFolderPathW(NULL, pathW, CSIDL_DESKTOP, false)) { - char pathA[MAX_PATH]; - WideCharToMultiByte(CP_UTF8, 0, pathW, -1, pathA, MAX_PATH, 0, 0); - return Glib::ustring(pathA); - } else { - return Glib::ustring("C:\\"); - } - -#else - - return Glib::get_user_special_dir (G_USER_DIRECTORY_DESKTOP); - -#endif -} - -#ifdef WIN32 -/* - * Test if the path is a root path based on the content of the string - * - * Warning: this function is a workaround for Windows platform, and not necessarily bullet proof - */ -bool safe_is_shortcut_dir (const Glib::ustring& path) -{ - return PathIsRootA(path.c_str()) || safe_get_user_home_dir() == path || safe_get_user_desktop_dir() == path || safe_get_user_profile_dir() == path; // || safe_get_user_picture_dir() == path; -} -#endif diff --git a/rtengine/safegtk.h b/rtengine/safegtk.h index 6cf6944de..9bb3baedf 100644 --- a/rtengine/safegtk.h +++ b/rtengine/safegtk.h @@ -25,13 +25,4 @@ int safe_g_remove(const Glib::ustring& filename); int safe_g_rename(const Glib::ustring& oldFilename, const Glib::ustring& newFilename); int safe_g_mkdir_with_parents(const Glib::ustring& dirName, int mode); -Glib::ustring safe_get_user_picture_dir(); -Glib::ustring safe_get_user_home_dir(); -Glib::ustring safe_get_user_desktop_dir(); - -#ifdef WIN32 -Glib::ustring safe_get_user_profile_dir(); -bool safe_is_shortcut_dir (const Glib::ustring& filename); -#endif - #endif diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index b9f123ac5..e033c3ebb 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -18,18 +18,21 @@ * along with RawTherapee. If not, see . */ #include "editorpanel.h" -#include "options.h" -#include "progressconnector.h" -#include "rtwindow.h" -#include "guiutils.h" -#include "procparamchangers.h" + +#include + #include "../rtengine/safegtk.h" #include "../rtengine/imagesource.h" #include "../rtengine/iccstore.h" #include "soundman.h" #include "rtimage.h" -#include +#include "rtwindow.h" +#include "guiutils.h" #include "popupbutton.h" +#include "options.h" +#include "progressconnector.h" +#include "procparamchangers.h" +#include "placesbrowser.h" using namespace rtengine::procparams; @@ -1543,7 +1546,7 @@ void EditorPanel::saveAsPressed () if (safe_file_test (options.lastSaveAsPath, Glib::FILE_TEST_IS_DIR)) { saveAsDialog = new SaveAsDialog (options.lastSaveAsPath); } else { - saveAsDialog = new SaveAsDialog (safe_get_user_picture_dir()); + saveAsDialog = new SaveAsDialog (PlacesBrowser::userPicturesDir ()); } saveAsDialog->set_default_size (options.saveAsDialogWidth, options.saveAsDialogHeight); diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 8b9f299d8..2e6ef82b4 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -17,22 +17,26 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ -#include +#include "filecatalog.h" + #include #include -#include "../rtengine/rt_math.h" -#include "filecatalog.h" -#include "filepanel.h" +#include + +#include "../rtengine/rt_math.h" +#include "../rtengine/safegtk.h" + +#include "guiutils.h" #include "options.h" +#include "rtimage.h" #include "cachemanager.h" #include "multilangmgr.h" -#include "guiutils.h" +#include "filepanel.h" #include "renamedlg.h" #include "thumbimageupdater.h" -#include "../rtengine/safegtk.h" #include "batchqueue.h" -#include "rtimage.h" +#include "placesbrowser.h" using namespace std; @@ -2027,10 +2031,9 @@ void FileCatalog::buttonBrowsePathPressed () FirstChar = BrowsePathValue.substr (0, 1); if (FirstChar == "~") { // home directory - DecodedPathPrefix = Glib::get_home_dir(); + DecodedPathPrefix = PlacesBrowser::userHomeDir (); } else if (FirstChar == "!") { // user's pictures directory - //DecodedPathPrefix = g_get_user_special_dir(G_USER_DIRECTORY_PICTURES); - DecodedPathPrefix = safe_get_user_picture_dir(); + DecodedPathPrefix = PlacesBrowser::userPicturesDir (); } if (!DecodedPathPrefix.empty()) { diff --git a/rtgui/filepanel.cc b/rtgui/filepanel.cc index 0069a6dbd..f13c3f451 100644 --- a/rtgui/filepanel.cc +++ b/rtgui/filepanel.cc @@ -1,4 +1,3 @@ - /* * This file is part of RawTherapee. * @@ -18,9 +17,12 @@ * along with RawTherapee. If not, see . */ #include "filepanel.h" -#include "rtwindow.h" + #include "../rtengine/safegtk.h" + +#include "rtwindow.h" #include "inspector.h" +#include "placesbrowser.h" int FilePanelInitUI (void* data) { @@ -181,7 +183,7 @@ void FilePanel::init () dirBrowser->open (argv1); } else { if (options.startupDir == STARTUPDIR_HOME) { - dirBrowser->open (safe_get_user_picture_dir()); + dirBrowser->open (PlacesBrowser::userPicturesDir ()); } else if (options.startupDir == STARTUPDIR_CURRENT) { dirBrowser->open (argv0); } else if (options.startupDir == STARTUPDIR_CUSTOM || options.startupDir == STARTUPDIR_LAST) { @@ -189,7 +191,7 @@ void FilePanel::init () dirBrowser->open (options.startupPath); } else { // Fallback option if the path is empty or the folder doesn't exist - dirBrowser->open (safe_get_user_picture_dir()); + dirBrowser->open (PlacesBrowser::userPicturesDir ()); } } } diff --git a/rtgui/flatfield.cc b/rtgui/flatfield.cc index 8609bea73..f23c58adf 100644 --- a/rtgui/flatfield.cc +++ b/rtgui/flatfield.cc @@ -392,28 +392,21 @@ void FlatField::flatFieldAutoSelectChanged() } -void FlatField::setShortcutPath(Glib::ustring path) +void FlatField::setShortcutPath(const Glib::ustring& path) { - if (path == "") { + if (path.empty ()) { return; } -#ifdef WIN32 + try { - // Dirty workaround, waiting for a clean solution by using exceptions! - if (!safe_is_shortcut_dir(path)) -#endif - { - if (lastShortcutPath != "") { - try { - flatFieldFile->remove_shortcut_folder(lastShortcutPath); - } catch (Glib::Error &err) {} + if (!lastShortcutPath.empty ()) { + flatFieldFile->remove_shortcut_folder (lastShortcutPath); } + flatFieldFile->add_shortcut_folder (path); + lastShortcutPath = path; - try { - flatFieldFile->add_shortcut_folder(path); - } catch (Glib::Error &err) {} - } + } catch (Glib::Error&) {} } diff --git a/rtgui/flatfield.h b/rtgui/flatfield.h index 162360b9a..b85b154da 100644 --- a/rtgui/flatfield.h +++ b/rtgui/flatfield.h @@ -75,7 +75,7 @@ public: void flatFieldFile_Reset (); void flatFieldAutoSelectChanged (); void flatFieldBlurTypeChanged (); - void setShortcutPath(Glib::ustring path); + void setShortcutPath (const Glib::ustring& path); void setFFProvider (FFProvider* p) { ffp = p; diff --git a/rtgui/placesbrowser.cc b/rtgui/placesbrowser.cc index bb92fab0d..acceb73e2 100644 --- a/rtgui/placesbrowser.cc +++ b/rtgui/placesbrowser.cc @@ -17,11 +17,17 @@ * along with RawTherapee. If not, see . */ #include "placesbrowser.h" -#include "options.h" -#include "toolpanel.h" -#include "../rtengine/safegtk.h" + +#ifdef WIN32 +#include +#include +#include +#endif + #include "guiutils.h" #include "rtimage.h" +#include "options.h" +#include "toolpanel.h" PlacesBrowser::PlacesBrowser () { @@ -86,17 +92,14 @@ bool compareMountByRoot (Glib::RefPtr a, Glib::RefPtr b) void PlacesBrowser::refreshPlacesList () { - placesModel->clear (); // append home directory - Glib::RefPtr hfile = Gio::File::create_for_path (safe_get_user_home_dir()); // Will send back "My documents" on Windows now, which has no restricted access + Glib::RefPtr hfile = Gio::File::create_for_path (userHomeDir()); // Will send back "My documents" on Windows now, which has no restricted access if (hfile && hfile->query_exists()) { try { - Glib::RefPtr info = safe_query_file_info (hfile); - - if (info) { + if (auto info = hfile->query_info ()) { Gtk::TreeModel::Row newrow = *(placesModel->append()); newrow[placesColumns.label] = info->get_display_name (); newrow[placesColumns.icon] = info->get_icon (); @@ -104,19 +107,15 @@ void PlacesBrowser::refreshPlacesList () newrow[placesColumns.type] = 4; newrow[placesColumns.rowSeparator] = false; } - } catch (Gio::Error&) { - /* This will be thrown if the path doesn't exist */ - } + } catch (Gio::Error&) {} } // append pictures directory - hfile = Gio::File::create_for_path (safe_get_user_picture_dir()); + hfile = Gio::File::create_for_path (userPicturesDir()); if (hfile && hfile->query_exists()) { try { - Glib::RefPtr info = safe_query_file_info (hfile); - - if (info) { + if (auto info = hfile->query_info ()) { Gtk::TreeModel::Row newrow = *(placesModel->append()); newrow[placesColumns.label] = info->get_display_name (); newrow[placesColumns.icon] = info->get_icon (); @@ -124,9 +123,7 @@ void PlacesBrowser::refreshPlacesList () newrow[placesColumns.type] = 4; newrow[placesColumns.rowSeparator] = false; } - } catch (Gio::Error&) { - /* This will be thrown if the path doesn't exist */ - } + } catch (Gio::Error&) {} } if (!placesModel->children().empty()) { @@ -225,16 +222,16 @@ void PlacesBrowser::refreshPlacesList () Glib::RefPtr hfile = Gio::File::create_for_path (options.favoriteDirs[i]); if (hfile && hfile->query_exists()) { - Glib::RefPtr info = safe_query_file_info (hfile); - - if (info) { - Gtk::TreeModel::Row newrow = *(placesModel->append()); - newrow[placesColumns.label] = info->get_display_name (); - newrow[placesColumns.icon] = info->get_icon (); - newrow[placesColumns.root] = hfile->get_parse_name (); - newrow[placesColumns.type] = 5; - newrow[placesColumns.rowSeparator] = false; - } + try { + if (auto info = hfile->query_info ()) { + Gtk::TreeModel::Row newrow = *(placesModel->append()); + newrow[placesColumns.label] = info->get_display_name (); + newrow[placesColumns.icon] = info->get_icon (); + newrow[placesColumns.root] = hfile->get_parse_name (); + newrow[placesColumns.type] = 5; + newrow[placesColumns.rowSeparator] = false; + } + } catch(Gio::Error&) {} } } } @@ -315,12 +312,12 @@ void PlacesBrowser::addPressed () Glib::RefPtr hfile = Gio::File::create_for_path (lastSelectedDir); if (hfile && hfile->query_exists()) { - Glib::RefPtr info = safe_query_file_info (hfile); - - if (info) { - options.favoriteDirs.push_back (hfile->get_parse_name ()); - refreshPlacesList (); - } + try { + if (auto info = hfile->query_info ()) { + options.favoriteDirs.push_back (hfile->get_parse_name ()); + refreshPlacesList (); + } + } catch(Gio::Error&) {} } } @@ -342,3 +339,52 @@ void PlacesBrowser::delPressed () refreshPlacesList (); } +Glib::ustring PlacesBrowser::userHomeDir () +{ +#ifdef WIN32 + + // get_home_dir crashes on some Windows configurations, + // so we rather use the safe native functions here. + WCHAR pathW[MAX_PATH]; + if (SHGetSpecialFolderPathW (NULL, pathW, CSIDL_PERSONAL, false)) { + + char pathA[MAX_PATH]; + if (WideCharToMultiByte (CP_UTF8, 0, pathW, -1, pathA, MAX_PATH, 0, 0)) { + + return Glib::ustring (pathA); + } + } + + return Glib::ustring ("C:\\"); + +#else + + return Glib::get_home_dir (); + +#endif +} + +Glib::ustring PlacesBrowser::userPicturesDir () +{ +#ifdef WIN32 + + // get_user_special_dir crashes on some Windows configurations, + // so we rather use the safe native functions here. + WCHAR pathW[MAX_PATH]; + if (SHGetSpecialFolderPathW (NULL, pathW, CSIDL_MYPICTURES, false)) { + + char pathA[MAX_PATH]; + if (WideCharToMultiByte (CP_UTF8, 0, pathW, -1, pathA, MAX_PATH, 0, 0)) { + + return Glib::ustring (pathA); + } + } + + return Glib::ustring ("C:\\"); + +#else + + return Glib::get_user_special_dir (G_USER_DIRECTORY_PICTURES); + +#endif +} diff --git a/rtgui/placesbrowser.h b/rtgui/placesbrowser.h index b9d74648b..b3bed867c 100644 --- a/rtgui/placesbrowser.h +++ b/rtgui/placesbrowser.h @@ -72,6 +72,12 @@ public: void selectionChanged (); void addPressed (); void delPressed (); + +public: + + static Glib::ustring userHomeDir (); + static Glib::ustring userPicturesDir (); + }; inline void PlacesBrowser::setDirSelector (const PlacesBrowser::DirSelectionSlot& selectDir) diff --git a/rtgui/profilepanel.cc b/rtgui/profilepanel.cc index ca667c4d9..d99ffb4b3 100644 --- a/rtgui/profilepanel.cc +++ b/rtgui/profilepanel.cc @@ -293,24 +293,14 @@ void ProfilePanel::save_clicked (GdkEventButton* event) dialog.set_current_name (lastFilename); //Add the user's default (or global if multiuser=false) profile path to the Shortcut list -#ifdef WIN32 - - // Dirty workaround, waiting for a clean solution by using exceptions! - if (!safe_is_shortcut_dir(options.getPreferredProfilePath())) -#endif - try { - dialog.add_shortcut_folder(options.getPreferredProfilePath()); - } catch (Glib::Error &err) {} + try { + dialog.add_shortcut_folder(options.getPreferredProfilePath()); + } catch (Glib::Error&) {} //Add the image's path to the Shortcut list -#ifdef WIN32 - - // Dirty workaround, waiting for a clean solution by using exceptions! - if (!safe_is_shortcut_dir(imagePath)) -#endif - try { - dialog.add_shortcut_folder(imagePath); - } catch (Glib::Error &err) {} + try { + dialog.add_shortcut_folder(imagePath); + } catch (Glib::Error&) {} //Add response buttons the the dialog: dialog.add_button(Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL); @@ -468,24 +458,14 @@ void ProfilePanel::load_clicked (GdkEventButton* event) bindCurrentFolder (dialog, options.loadSaveProfilePath); //Add the user's default (or global if multiuser=false) profile path to the Shortcut list -#ifdef WIN32 - - // Dirty workaround, waiting for a clean solution by using exceptions! - if (!safe_is_shortcut_dir(options.getPreferredProfilePath())) -#endif - try { - dialog.add_shortcut_folder(options.getPreferredProfilePath()); - } catch (Glib::Error &err) {} + try { + dialog.add_shortcut_folder(options.getPreferredProfilePath()); + } catch (Glib::Error&) {} //Add the image's path to the Shortcut list -#ifdef WIN32 - - // Dirty workaround, waiting for a clean solution by using exceptions! - if (!safe_is_shortcut_dir(imagePath)) -#endif - try { - dialog.add_shortcut_folder(imagePath); - } catch (Glib::Error &err) {} + try { + dialog.add_shortcut_folder(imagePath); + } catch (Glib::Error&) {} //Add response buttons the the dialog: dialog.add_button(Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL); diff --git a/rtgui/saveasdlg.cc b/rtgui/saveasdlg.cc index 47957bc80..8a4f69445 100644 --- a/rtgui/saveasdlg.cc +++ b/rtgui/saveasdlg.cc @@ -286,20 +286,13 @@ void SaveAsDialog::setInitialFileName (Glib::ustring fname) fchooser->set_current_name(fname); } -void SaveAsDialog::setImagePath (Glib::ustring ipath) +void SaveAsDialog::setImagePath (const Glib::ustring& imagePath) { + const auto dirName = Glib::path_get_dirname (imagePath); - Glib::ustring path = Glib::path_get_dirname(ipath); - - //Add the image's path to the Shortcut list -#ifdef WIN32 - - // Dirty workaround, waiting for a clean solution by using exceptions! - if (!safe_is_shortcut_dir(path)) -#endif - try { - fchooser->add_shortcut_folder(path); - } catch (Glib::Error &err) {} + try { + fchooser->add_shortcut_folder (dirName); + } catch (Glib::Error&) {} } diff --git a/rtgui/saveasdlg.h b/rtgui/saveasdlg.h index db307e4b8..4727b574c 100644 --- a/rtgui/saveasdlg.h +++ b/rtgui/saveasdlg.h @@ -58,7 +58,7 @@ public: int getSaveMethodNum (); void setInitialFileName (Glib::ustring iname); - void setImagePath (Glib::ustring ipath); + void setImagePath (const Glib::ustring& imagePath); void okPressed (); void cancelPressed ();