From 13ebcb0dd090c9bba967be044695efdb5f58fc51 Mon Sep 17 00:00:00 2001 From: Adam Reichold Date: Fri, 25 Dec 2015 22:39:53 +0100 Subject: [PATCH] Move image loader helper functions from safegtk to RTImage module. --- rtengine/safegtk.cc | 35 ---- rtengine/safegtk.h | 3 - rtgui/batchqueuebuttonset.cc | 9 +- rtgui/batchqueueentry.cc | 7 +- rtgui/cropwindow.cc | 26 +-- rtgui/cursormanager.cc | 18 +-- rtgui/dirbrowser.cc | 14 +- rtgui/exifpanel.cc | 8 +- rtgui/filebrowserentry.cc | 17 +- rtgui/filethumbnailbuttonset.cc | 27 ++-- rtgui/rtimage.cc | 272 ++++++++++++++++++-------------- rtgui/rtimage.h | 23 ++- rtgui/splash.cc | 9 +- rtgui/whitebalance.cc | 29 ++-- 14 files changed, 253 insertions(+), 244 deletions(-) diff --git a/rtengine/safegtk.cc b/rtengine/safegtk.cc index 053507c3e..05ad14efd 100644 --- a/rtengine/safegtk.cc +++ b/rtengine/safegtk.cc @@ -38,41 +38,6 @@ #include -Glib::RefPtr safe_create_from_file(const Glib::ustring& filename) -{ - Glib::RefPtr res; - Glib::ustring path = RTImage::findIconAbsolutePath(filename); - - if (path.length()) { - try { - res = Gdk::Pixbuf::create_from_file (path); - } catch (Glib::Exception& ex) { - printf ("ERROR: (ustring) File \"%s\" not found.\n", ex.what().c_str()); - } - } - - return res; -} - -Cairo::RefPtr safe_create_from_png(const Glib::ustring& filename) -{ - Cairo::RefPtr res; - Glib::ustring path = RTImage::findIconAbsolutePath(filename); - - if (path.length()) { - // files_test need a std::string which (as stated in its proto) but will only work if - // we use the Glib::ustring filename !? - try { - // create_from_png need a std::string converted from UTF8 with safe_locale_from_utf8 - res = Cairo::ImageSurface::create_from_png (safe_locale_from_utf8(path)); - } catch (...) { - printf("ERROR: (ustring) File \"%s\" not found.\n", path.c_str()); - } - } - - return res; -} - Glib::RefPtr safe_query_file_info (Glib::RefPtr &file) { Glib::RefPtr info; diff --git a/rtengine/safegtk.h b/rtengine/safegtk.h index 768d55148..a30195290 100644 --- a/rtengine/safegtk.h +++ b/rtengine/safegtk.h @@ -5,9 +5,6 @@ #include #include -Glib::RefPtr safe_create_from_file(const Glib::ustring& filename); -Cairo::RefPtr safe_create_from_png(const Glib::ustring& filename); - Glib::RefPtr safe_query_file_info (Glib::RefPtr &file); void safe_build_file_list (Glib::RefPtr &dir, std::vector &names, const Glib::ustring &directory = "", const std::vector *extensions = NULL); void safe_build_subdir_list (Glib::RefPtr &dir, std::vector &subDirs, bool add_hidden); diff --git a/rtgui/batchqueuebuttonset.cc b/rtgui/batchqueuebuttonset.cc index 380c4abe3..1f8bc7ac8 100644 --- a/rtgui/batchqueuebuttonset.cc +++ b/rtgui/batchqueuebuttonset.cc @@ -17,8 +17,9 @@ * along with RawTherapee. If not, see . */ #include "batchqueuebuttonset.h" + #include "multilangmgr.h" -#include "../rtengine/safegtk.h" +#include "rtimage.h" extern Glib::ustring argv0; @@ -32,9 +33,9 @@ BatchQueueButtonSet::BatchQueueButtonSet (BatchQueueEntry* myEntry) { if (!iconsLoaded) { - cancelIcon = safe_create_from_png ("gtk-close.png"); - headIcon = safe_create_from_png ("toleftend.png"); - tailIcon = safe_create_from_png ("torightend.png"); + cancelIcon = RTImage::createFromPng ("gtk-close.png"); + headIcon = RTImage::createFromPng ("toleftend.png"); + tailIcon = RTImage::createFromPng ("torightend.png"); iconsLoaded = true; } diff --git a/rtgui/batchqueueentry.cc b/rtgui/batchqueueentry.cc index 94117252d..0e8b66136 100644 --- a/rtgui/batchqueueentry.cc +++ b/rtgui/batchqueueentry.cc @@ -17,13 +17,14 @@ * along with RawTherapee. If not, see . */ #include "batchqueueentry.h" -#include "thumbbrowserbase.h" #include + #include "guiutils.h" #include "threadutils.h" -#include "../rtengine/safegtk.h" +#include "rtimage.h" #include "multilangmgr.h" +#include "thumbbrowserbase.h" bool BatchQueueEntry::iconsLoaded(false); Glib::RefPtr BatchQueueEntry::savedAsIcon; @@ -46,7 +47,7 @@ BatchQueueEntry::BatchQueueEntry (rtengine::ProcessingJob* pjob, const rtengine: #endif if (!iconsLoaded) { - savedAsIcon = safe_create_from_file ("gtk-save.png"); + savedAsIcon = RTImage::createFromFile ("gtk-save.png"); iconsLoaded = true; } diff --git a/rtgui/cropwindow.cc b/rtgui/cropwindow.cc index 33d700c3a..dcb06792e 100644 --- a/rtgui/cropwindow.cc +++ b/rtgui/cropwindow.cc @@ -16,19 +16,21 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ +#include "cropwindow.h" + #include -#include "cropwindow.h" -#include "options.h" -#include "guiutils.h" -#include "threadutils.h" #include "../rtengine/mytime.h" -#include "imagearea.h" -#include "cursormanager.h" -#include "../rtengine/safegtk.h" #include "../rtengine/rt_math.h" #include "../rtengine/dcrop.h" +#include "guiutils.h" +#include "threadutils.h" +#include "rtimage.h" +#include "cursormanager.h" +#include "options.h" +#include "imagearea.h" + using namespace rtengine; struct ZoomStep { @@ -84,11 +86,11 @@ CropWindow::CropWindow (ImageArea* parent, rtengine::StagedImageProcessor* ipc_, titleHeight = ih; - bZoomOut = new LWButton (safe_create_from_png ("gtk-zoom-out-small.png"), 0, NULL, LWButton::Left, LWButton::Center, "Zoom Out"); - bZoomIn = new LWButton (safe_create_from_png ("gtk-zoom-in-small.png"), 1, NULL, LWButton::Left, LWButton::Center, "Zoom In"); - bZoom100 = new LWButton (safe_create_from_png ("gtk-zoom-100-small.png"), 2, NULL, LWButton::Left, LWButton::Center, "Zoom 100/%"); - //bZoomFit = new LWButton (safe_create_from_png ("gtk-zoom-fit.png"), 3, NULL, LWButton::Left, LWButton::Center, "Zoom Fit"); - bClose = new LWButton (safe_create_from_png ("gtk-close-small.png"), 4, NULL, LWButton::Right, LWButton::Center, "Close"); + bZoomOut = new LWButton (RTImage::createFromPng ("gtk-zoom-out-small.png"), 0, NULL, LWButton::Left, LWButton::Center, "Zoom Out"); + bZoomIn = new LWButton (RTImage::createFromPng ("gtk-zoom-in-small.png"), 1, NULL, LWButton::Left, LWButton::Center, "Zoom In"); + bZoom100 = new LWButton (RTImage::createFromPng ("gtk-zoom-100-small.png"), 2, NULL, LWButton::Left, LWButton::Center, "Zoom 100/%"); + //bZoomFit = new LWButton (RTImage::createFromPng ("gtk-zoom-fit.png"), 3, NULL, LWButton::Left, LWButton::Center, "Zoom Fit"); + bClose = new LWButton (RTImage::createFromPng ("gtk-close-small.png"), 4, NULL, LWButton::Right, LWButton::Center, "Close"); buttonSet.add (bZoomOut); buttonSet.add (bZoomIn); diff --git a/rtgui/cursormanager.cc b/rtgui/cursormanager.cc index 45426a557..e011fd969 100644 --- a/rtgui/cursormanager.cc +++ b/rtgui/cursormanager.cc @@ -17,8 +17,8 @@ * along with RawTherapee. If not, see . */ #include "cursormanager.h" + #include "options.h" -#include "../rtengine/safegtk.h" #include "rtimage.h" CursorManager cursorManager; @@ -41,14 +41,14 @@ void CursorManager::init (Glib::RefPtr mainWin) cAdd = new Gdk::Cursor (Gdk::PLUS); cWait = new Gdk::Cursor (Gdk::CLOCK); - Glib::RefPtr hand = safe_create_from_file("cross.png"); - Glib::RefPtr close_hand = safe_create_from_file("closedhand.png"); - Glib::RefPtr wbpick = safe_create_from_file("gtk-color-picker-small.png"); - Glib::RefPtr empty = safe_create_from_file("empty.png"); - Glib::RefPtr move2D = safe_create_from_file("move-2D.png"); - Glib::RefPtr move1DH = safe_create_from_file("move-1D-h.png"); - Glib::RefPtr move1DV = safe_create_from_file("move-1D-v.png"); - Glib::RefPtr moveRotate = safe_create_from_file("move-rotate.png"); + Glib::RefPtr hand = RTImage::createFromFile ("cross.png"); + Glib::RefPtr close_hand = RTImage::createFromFile ("closedhand.png"); + Glib::RefPtr wbpick = RTImage::createFromFile ("gtk-color-picker-small.png"); + Glib::RefPtr empty = RTImage::createFromFile ("empty.png"); + Glib::RefPtr move2D = RTImage::createFromFile ("move-2D.png"); + Glib::RefPtr move1DH = RTImage::createFromFile ("move-1D-h.png"); + Glib::RefPtr move1DV = RTImage::createFromFile ("move-1D-v.png"); + Glib::RefPtr moveRotate = RTImage::createFromFile ("move-rotate.png"); cHand = hand ? new Gdk::Cursor (cAdd->get_display(), hand, 10, 10) : new Gdk::Cursor (Gdk::HAND2); cClosedHand = close_hand ? new Gdk::Cursor (cAdd->get_display(), close_hand, 10, 10) : new Gdk::Cursor (Gdk::HAND2); diff --git a/rtgui/dirbrowser.cc b/rtgui/dirbrowser.cc index b79bb2c0f..263f695b3 100644 --- a/rtgui/dirbrowser.cc +++ b/rtgui/dirbrowser.cc @@ -72,13 +72,13 @@ DirBrowser::DirBrowser () : dirTreeModel(), void DirBrowser::fillDirTree () { - openfolder = safe_create_from_file ("gtk-open.png"); - closedfolder = safe_create_from_file ("folder.png"); - icdrom = safe_create_from_file ("drive-optical.png"); - ifloppy = safe_create_from_file ("drive-removable-media.png"); - ihdd = safe_create_from_file ("drive-harddisk.png"); - iremovable = safe_create_from_file ("media-usb.png"); - inetwork = safe_create_from_file ("network.png"); + openfolder = RTImage::createFromFile ("gtk-open.png"); + closedfolder = RTImage::createFromFile ("folder.png"); + icdrom = RTImage::createFromFile ("drive-optical.png"); + ifloppy = RTImage::createFromFile ("drive-removable-media.png"); + ihdd = RTImage::createFromFile ("drive-harddisk.png"); + iremovable = RTImage::createFromFile ("media-usb.png"); + inetwork = RTImage::createFromFile ("network.png"); //Create the Tree model: dirTreeModel = Gtk::TreeStore::create(dtColumns); diff --git a/rtgui/exifpanel.cc b/rtgui/exifpanel.cc index 987cd42d7..8c39edc02 100644 --- a/rtgui/exifpanel.cc +++ b/rtgui/exifpanel.cc @@ -17,7 +17,7 @@ * along with RawTherapee. If not, see . */ #include "exifpanel.h" -#include "../rtengine/safegtk.h" + #include "guiutils.h" #include "rtimage.h" @@ -47,9 +47,9 @@ ExifPanel::ExifPanel () : idata(NULL) exifTreeModel = Gtk::TreeStore::create(exifColumns); exifTree->set_model (exifTreeModel); - delicon = safe_create_from_file ("gtk-close.png"); - keepicon = safe_create_from_file ("gtk-apply.png"); - editicon = safe_create_from_file ("gtk-add.png"); + delicon = RTImage::createFromFile ("gtk-close.png"); + keepicon = RTImage::createFromFile ("gtk-apply.png"); + editicon = RTImage::createFromFile ("gtk-add.png"); Gtk::TreeView::Column *viewcol = Gtk::manage(new Gtk::TreeView::Column ("Field Name")); Gtk::CellRendererPixbuf* render_pb = Gtk::manage(new Gtk::CellRendererPixbuf ()); diff --git a/rtgui/filebrowserentry.cc b/rtgui/filebrowserentry.cc index 2e2b0ccb1..f2977b742 100644 --- a/rtgui/filebrowserentry.cc +++ b/rtgui/filebrowserentry.cc @@ -17,16 +17,17 @@ * along with RawTherapee. If not, see . */ #include "filebrowserentry.h" -#include "thumbbrowserbase.h" -#include "cursormanager.h" + #include +#include + #include "guiutils.h" #include "threadutils.h" -#include "../rtengine/safegtk.h" +#include "rtimage.h" +#include "cursormanager.h" +#include "thumbbrowserbase.h" #include "inspector.h" -#include - #define CROPRESIZEBORDER 4 bool FileBrowserEntry::iconsLoaded(false); @@ -51,9 +52,9 @@ FileBrowserEntry::FileBrowserEntry (Thumbnail* thm, const Glib::ustring& fname) scale = 1; if (!iconsLoaded) { - editedIcon = safe_create_from_file ("edited.png"); - recentlySavedIcon = safe_create_from_file ("recent-save.png"); - enqueuedIcon = safe_create_from_file ("processing.png"); + editedIcon = RTImage::createFromFile ("edited.png"); + recentlySavedIcon = RTImage::createFromFile ("recent-save.png"); + enqueuedIcon = RTImage::createFromFile ("processing.png"); iconsLoaded = true; } diff --git a/rtgui/filethumbnailbuttonset.cc b/rtgui/filethumbnailbuttonset.cc index e9970b177..286324bdf 100644 --- a/rtgui/filethumbnailbuttonset.cc +++ b/rtgui/filethumbnailbuttonset.cc @@ -17,8 +17,9 @@ * along with RawTherapee. If not, see . */ #include "filethumbnailbuttonset.h" + +#include "rtimage.h" #include "multilangmgr.h" -#include "../rtengine/safegtk.h" extern Glib::ustring argv0; @@ -41,19 +42,19 @@ FileThumbnailButtonSet::FileThumbnailButtonSet (FileBrowserEntry* myEntry) { if (!iconsLoaded) { - unRankIcon = safe_create_from_png ("ratednotg.png"); - rankIcon = safe_create_from_png ("rated.png"); - gRankIcon = safe_create_from_png ("grayrated.png"); - trashIcon = safe_create_from_png ("trash-thumbnail.png"); - unTrashIcon = safe_create_from_png ("undelete-thumbnail.png"); - processIcon = safe_create_from_png ("processing-thumbnail.png"); + unRankIcon = RTImage::createFromPng ("ratednotg.png"); + rankIcon = RTImage::createFromPng ("rated.png"); + gRankIcon = RTImage::createFromPng ("grayrated.png"); + trashIcon = RTImage::createFromPng ("trash-thumbnail.png"); + unTrashIcon = RTImage::createFromPng ("undelete-thumbnail.png"); + processIcon = RTImage::createFromPng ("processing-thumbnail.png"); - colorLabelIcon_0 = safe_create_from_png ("cglabel0.png"); //("nocolorlabel.png"); - colorLabelIcon_1 = safe_create_from_png ("clabel1.png"); - colorLabelIcon_2 = safe_create_from_png ("clabel2.png"); - colorLabelIcon_3 = safe_create_from_png ("clabel3.png"); - colorLabelIcon_4 = safe_create_from_png ("clabel4.png"); - colorLabelIcon_5 = safe_create_from_png ("clabel5.png"); + colorLabelIcon_0 = RTImage::createFromPng ("cglabel0.png"); //("nocolorlabel.png"); + colorLabelIcon_1 = RTImage::createFromPng ("clabel1.png"); + colorLabelIcon_2 = RTImage::createFromPng ("clabel2.png"); + colorLabelIcon_3 = RTImage::createFromPng ("clabel3.png"); + colorLabelIcon_4 = RTImage::createFromPng ("clabel4.png"); + colorLabelIcon_5 = RTImage::createFromPng ("clabel5.png"); iconsLoaded = true; } diff --git a/rtgui/rtimage.cc b/rtgui/rtimage.cc index 6472467e6..3136b52c5 100644 --- a/rtgui/rtimage.cc +++ b/rtgui/rtimage.cc @@ -19,151 +19,179 @@ */ #include "rtimage.h" -#include "../rtengine/safegtk.h" -extern Glib::ustring argv0; -extern Options options; +#include "options.h" -std::vector imagesPaths; -std::map > pixBufMap; // List of image buffers in order to live update them on theme switch and to avoid a lot of file accesses - -/* - * RTImage is a derived class of Gtk::Image, in order to handle theme related iconsets - */ -RTImage::RTImage(Glib::ustring fileName, Glib::ustring rtlFileName) : Gtk::Image() +namespace { - Glib::ustring mapKey; - if (rtlFileName.length()) { - if (get_direction() == Gtk::TEXT_DIR_RTL) { - mapKey = rtlFileName; - } else { - mapKey = fileName; +std::vector imagePaths; +std::map> pixbufCache; + +bool loadIconSet(const Glib::ustring& iconSet) +{ + try { + + Glib::KeyFile keyFile; + keyFile.load_from_file (iconSet); + + auto iconSetDir = keyFile.get_string ("General", "Iconset"); + + if (!iconSetDir.empty ()) { + imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "actions")); + imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir)); + imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "devices")); + imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "places")); } + + iconSetDir = keyFile.get_string ("General", "FallbackIconset"); + + if (!iconSetDir.empty ()) { + imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "actions")); + imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir)); + imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "devices")); + imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "places")); + } + + return true; + + } catch (const Glib::Exception& exception) { + + if (options.rtSettings.verbose) { + std::cerr << "Failed to load icon set \"" << iconSet << "\": " << exception.what() << std::endl; + } + + return false; + + } +} + +} + +RTImage::RTImage (const Glib::ustring& fileName, const Glib::ustring& rtlFileName) : Gtk::Image() +{ + Glib::ustring imageName; + + if (!rtlFileName.empty () && get_direction () == Gtk::TEXT_DIR_RTL) { + imageName = rtlFileName; } else { - mapKey = fileName; + imageName = fileName; } - std::map >::iterator it; - it = pixBufMap.find(mapKey); + changeImage (imageName); +} - if (it != pixBufMap.end()) { - set(it->second); - } else { - Glib::RefPtr tempPixPuf = Gdk::Pixbuf::create_from_file(findIconAbsolutePath(mapKey)); - pixBufMap.insert(std::pair >(mapKey, tempPixPuf)); - set(tempPixPuf); +void RTImage::changeImage (const Glib::ustring& imageName) +{ + clear (); + + auto iterator = pixbufCache.find (imageName); + + if (iterator == pixbufCache.end ()) { + const auto imagePath = findIconAbsolutePath (imageName); + const auto pixbuf = Gdk::Pixbuf::create_from_file (imagePath); + + iterator = pixbufCache.emplace (imageName, pixbuf).first; } + + set(iterator->second); } void RTImage::updateImages() { - std::map >::iterator it; - - for (it = pixBufMap.begin(); it != pixBufMap.end(); ++it) { - Glib::ustring fullPath = findIconAbsolutePath(it->first); - it->second = Gdk::Pixbuf::create_from_file(fullPath); + for (auto& entry : pixbufCache) { + const auto imagePath = findIconAbsolutePath (entry.first); + entry.second = Gdk::Pixbuf::create_from_file (imagePath); } } -// DONE (was TODO: Maybe this could be optimized: in order to avoid looking up for an icon file in the filesystem on each popupmenu selection, maybe we could find a way to copy the image data from another RTImage) -void RTImage::changeImage(Glib::ustring &newImage) +Glib::ustring RTImage::findIconAbsolutePath (const Glib::ustring& iconName) { - clear(); - std::map >::iterator it; - it = pixBufMap.find(newImage); - - if (it != pixBufMap.end()) { - set(it->second); - } else { - Glib::ustring fullPath = findIconAbsolutePath(newImage); - Glib::RefPtr tempPixPuf = Gdk::Pixbuf::create_from_file(fullPath); - pixBufMap.insert(std::pair >(newImage, tempPixPuf)); - set(tempPixPuf); - } -} - -Glib::ustring RTImage::findIconAbsolutePath(const Glib::ustring &iconFName) -{ - Glib::ustring path; - - for (unsigned int i = 0; i < imagesPaths.size(); i++) { - path = Glib::build_filename(imagesPaths[i], iconFName); - - if (safe_file_test(path, Glib::FILE_TEST_EXISTS)) { - return path; - } - } - - printf("\"%s\" not found!\n", iconFName.c_str()); - return ""; -} - -void RTImage::setPaths(Options &opt) -{ - Glib::ustring configFilename; - rtengine::SafeKeyFile keyFile; - bool hasKeyFile = true; - - imagesPaths.clear(); - - // system theme will use the theme set in system.iconset - if (opt.useSystemTheme) { - configFilename = Glib::build_filename(argv0, Glib::build_filename("themes", "system.iconset")); - } - // Gtk theme will use the theme set in it's *.iconset fiel, if it exists - else { - configFilename = Glib::build_filename(argv0, Glib::build_filename("themes", Glib::ustring::format(opt.theme, ".iconset"))); - } - try { - if (!safe_file_test(configFilename, Glib::FILE_TEST_EXISTS) || !keyFile.load_from_file (configFilename)) { - // ...otherwise fallback to the iconset set in default.iconset - configFilename = Glib::build_filename(argv0, Glib::build_filename("themes", "Default.iconset")); - if (!keyFile.load_from_file (configFilename)) { - hasKeyFile = false; + for (const auto& imagePath : imagePaths) { + const auto iconPath = Glib::build_filename(imagePath, iconName); + + if (Glib::file_test(iconPath, Glib::FILE_TEST_IS_REGULAR)) { + return iconPath; } } - } catch (Glib::Error &err) { - if (options.rtSettings.verbose) { - printf("RTImage::setPaths / Error code %d while reading values from \"%s\":\n%s\n", err.code(), configFilename.c_str(), err.what().c_str()); - } - } catch (...) { - if (options.rtSettings.verbose) { - printf("RTImage::setPaths / Unknown exception while trying to load \"%s\"!\n", configFilename.c_str()); - } + + } catch(const Glib::Exception&) {} + + if (options.rtSettings.verbose) { + std::cerr << "Icon \"" << iconName << "\" could not be found!" << std::endl; } - if (hasKeyFile && keyFile.has_group ("General")) { - Glib::ustring iSet; - - if (keyFile.has_key ("General", "Iconset")) { - iSet = keyFile.get_string ("General", "Iconset"); - } - - if (iSet.length()) { - imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "actions")))); - imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", iSet))); - imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "devices")))); - imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "places")))); - } - - iSet.clear(); - - if (keyFile.has_key ("General", "FallbackIconset")) { - iSet = keyFile.get_string ("General", "FallbackIconset"); - } - - if (iSet.length()) { - imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "actions")))); - imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", iSet))); - imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "devices")))); - imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "places")))); - } - } - - // The images/ folder is the second fallback solution - imagesPaths.push_back (Glib::build_filename(argv0, "images")); + return Glib::ustring(); } +void RTImage::setPaths (const Options& options) +{ + Glib::ustring iconSet; + + // Either use the system icon set or the one specified in the options. + if (options.useSystemTheme) { + iconSet = Glib::build_filename (argv0, "themes", "system.iconset"); + } else { + iconSet = Glib::build_filename (argv0, "themes", options.theme + ".iconset"); + } + + imagePaths.clear (); + + if (!loadIconSet (iconSet)) { + // If the preferred icon set is unavailable, fall back to the default icon set. + loadIconSet (Glib::build_filename (argv0, "themes", "Default.iconset")); + } + + // The images folder is the second fallback solution. + imagePaths.push_back (Glib::build_filename(argv0, "images")); +} + +Glib::RefPtr RTImage::createFromFile (const Glib::ustring& fileName) +{ + Glib::RefPtr pixbuf; + + try { + + const auto filePath = findIconAbsolutePath (fileName); + + if (!filePath.empty ()) { + pixbuf = Gdk::Pixbuf::create_from_file (filePath); + } + + } catch (const Glib::Exception& exception) { + + if (options.rtSettings.verbose) { + std::cerr << "Failed to load image \"" << fileName << "\": " << exception.what() << std::endl; + } + + } + + return pixbuf; +} + +Cairo::RefPtr RTImage::createFromPng (const Glib::ustring& fileName) +{ + Cairo::RefPtr surface; + + try { + + const auto filePath = findIconAbsolutePath (fileName); + + if (!filePath.empty()) { + surface = Cairo::ImageSurface::create_from_png (Glib::locale_from_utf8 (filePath)); + } + + } catch (const Glib::Exception& exception) { + + if (options.rtSettings.verbose) { + std::cerr << "Failed to load PNG \"" << fileName << "\": " << exception.what() << std::endl; + } + + } + + return surface; +} + + diff --git a/rtgui/rtimage.h b/rtgui/rtimage.h index de5ef9334..cfc7a5fa1 100644 --- a/rtgui/rtimage.h +++ b/rtgui/rtimage.h @@ -19,17 +19,26 @@ #ifndef _RTIMAGE_ #define _RTIMAGE_ -#include -#include "options.h" +#include +class Options; + +/** + * @brief A derived class of Gtk::Image in order to handle theme-related icon sets. + */ class RTImage : public Gtk::Image { public: - RTImage(Glib::ustring fileName, Glib::ustring rtlFileName = ""); - static void setPaths(Options &opt); - static void updateImages(); - void changeImage(Glib::ustring &newImage); - static Glib::ustring findIconAbsolutePath(const Glib::ustring &iconFName); + RTImage (const Glib::ustring& fileName, const Glib::ustring& rtlFileName = Glib::ustring()); + + void changeImage (const Glib::ustring& imageName); + static void updateImages (); + + static Glib::ustring findIconAbsolutePath (const Glib::ustring& iconName); + static void setPaths (const Options& options); + + static Glib::RefPtr createFromFile (const Glib::ustring& fileName); + static Cairo::RefPtr createFromPng (const Glib::ustring& fileName); }; #endif diff --git a/rtgui/splash.cc b/rtgui/splash.cc index b385ca460..6e0849b99 100644 --- a/rtgui/splash.cc +++ b/rtgui/splash.cc @@ -17,10 +17,14 @@ * along with RawTherapee. If not, see . */ #include "splash.h" -#include "multilangmgr.h" + #include + #include "../rtengine/safegtk.h" +#include "multilangmgr.h" +#include "rtimage.h" + extern Glib::ustring argv0; extern Glib::ustring creditsPath; extern Glib::ustring licensePath; @@ -29,8 +33,7 @@ extern Glib::ustring versionSuffixString; SplashImage::SplashImage () { - - pixbuf = safe_create_from_file ("splash.png"); + pixbuf = RTImage::createFromFile ("splash.png"); set_size_request (pixbuf->get_width(), pixbuf->get_height()); } diff --git a/rtgui/whitebalance.cc b/rtgui/whitebalance.cc index 914c59956..4c4321650 100644 --- a/rtgui/whitebalance.cc +++ b/rtgui/whitebalance.cc @@ -17,10 +17,11 @@ * along with RawTherapee. If not, see . */ #include "whitebalance.h" + #include + #include "rtimage.h" #include "options.h" -#include "../rtengine/safegtk.h" #define MINTEMP 1500 //1200 #define MAXTEMP 60000 //12000 @@ -42,19 +43,19 @@ Glib::RefPtr WhiteBalance::wbCameraPB, WhiteBalance::wbAutoPB, Whit void WhiteBalance::init () { - wbPixbufs[WBT_CAMERA] = safe_create_from_file("wb-camera.png"); - wbPixbufs[WBT_AUTO] = safe_create_from_file("wb-auto.png"); - wbPixbufs[WBT_DAYLIGHT] = safe_create_from_file("wb-sun.png"); - wbPixbufs[WBT_CLOUDY] = safe_create_from_file("wb-cloudy.png"); - wbPixbufs[WBT_SHADE] = safe_create_from_file("wb-shade.png"); - wbPixbufs[WBT_WATER] = safe_create_from_file("wb-water.png"); -// wbPixbufs[WBT_WATER2] = safe_create_from_file("wb-water.png"); - wbPixbufs[WBT_TUNGSTEN] = safe_create_from_file("wb-tungsten.png"); - wbPixbufs[WBT_FLUORESCENT] = safe_create_from_file("wb-fluorescent.png"); - wbPixbufs[WBT_LAMP] = safe_create_from_file("wb-lamp.png"); - wbPixbufs[WBT_FLASH] = safe_create_from_file("wb-flash.png"); - wbPixbufs[WBT_LED] = safe_create_from_file("wb-led.png"); - wbPixbufs[WBT_CUSTOM] = safe_create_from_file("wb-custom.png"); + wbPixbufs[WBT_CAMERA] = RTImage::createFromFile ("wb-camera.png"); + wbPixbufs[WBT_AUTO] = RTImage::createFromFile ("wb-auto.png"); + wbPixbufs[WBT_DAYLIGHT] = RTImage::createFromFile ("wb-sun.png"); + wbPixbufs[WBT_CLOUDY] = RTImage::createFromFile ("wb-cloudy.png"); + wbPixbufs[WBT_SHADE] = RTImage::createFromFile ("wb-shade.png"); + wbPixbufs[WBT_WATER] = RTImage::createFromFile ("wb-water.png"); +// wbPixbufs[WBT_WATER2] = RTImage::createFromFile ("wb-water.png"); + wbPixbufs[WBT_TUNGSTEN] = RTImage::createFromFile ("wb-tungsten.png"); + wbPixbufs[WBT_FLUORESCENT] = RTImage::createFromFile ("wb-fluorescent.png"); + wbPixbufs[WBT_LAMP] = RTImage::createFromFile ("wb-lamp.png"); + wbPixbufs[WBT_FLASH] = RTImage::createFromFile ("wb-flash.png"); + wbPixbufs[WBT_LED] = RTImage::createFromFile ("wb-led.png"); + wbPixbufs[WBT_CUSTOM] = RTImage::createFromFile ("wb-custom.png"); } void WhiteBalance::cleanup ()