Formatted all .cc and .h code in rtengine, rtexif and rtgui using astyle
This commit is contained in:
188
rtgui/rtimage.cc
188
rtgui/rtimage.cc
@@ -25,125 +25,145 @@ extern Glib::ustring argv0;
|
||||
extern Options options;
|
||||
|
||||
std::vector<Glib::ustring> imagesPaths;
|
||||
std::map<Glib::ustring,Glib::RefPtr<Gdk::Pixbuf> > pixBufMap; // List of image buffers in order to live update them on theme switch and to avoid a lot of file accesses
|
||||
std::map<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> > 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() {
|
||||
Glib::ustring mapKey;
|
||||
if (rtlFileName.length()) {
|
||||
if (get_direction() == Gtk::TEXT_DIR_RTL) {
|
||||
mapKey = rtlFileName;
|
||||
} else {
|
||||
mapKey = fileName;
|
||||
}
|
||||
} else {
|
||||
mapKey = fileName;
|
||||
}
|
||||
|
||||
std::map<Glib::ustring,Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
|
||||
RTImage::RTImage(Glib::ustring fileName, Glib::ustring rtlFileName) : Gtk::Image()
|
||||
{
|
||||
Glib::ustring mapKey;
|
||||
|
||||
if (rtlFileName.length()) {
|
||||
if (get_direction() == Gtk::TEXT_DIR_RTL) {
|
||||
mapKey = rtlFileName;
|
||||
} else {
|
||||
mapKey = fileName;
|
||||
}
|
||||
} else {
|
||||
mapKey = fileName;
|
||||
}
|
||||
|
||||
std::map<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
|
||||
it = pixBufMap.find(mapKey);
|
||||
|
||||
if (it != pixBufMap.end()) {
|
||||
set(it->second);
|
||||
} else {
|
||||
Glib::RefPtr<Gdk::Pixbuf> tempPixPuf = Gdk::Pixbuf::create_from_file(findIconAbsolutePath(mapKey));
|
||||
pixBufMap.insert(std::pair<Glib::ustring,Glib::RefPtr<Gdk::Pixbuf> >(mapKey, tempPixPuf));
|
||||
pixBufMap.insert(std::pair<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >(mapKey, tempPixPuf));
|
||||
set(tempPixPuf);
|
||||
}
|
||||
}
|
||||
|
||||
void RTImage::updateImages() {
|
||||
std::map<Glib::ustring,Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
|
||||
for (it=pixBufMap.begin(); it!=pixBufMap.end(); ++it) {
|
||||
void RTImage::updateImages()
|
||||
{
|
||||
std::map<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
|
||||
|
||||
for (it = pixBufMap.begin(); it != pixBufMap.end(); ++it) {
|
||||
Glib::ustring fullPath = findIconAbsolutePath(it->first);
|
||||
it->second = Gdk::Pixbuf::create_from_file(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
clear();
|
||||
std::map<Glib::ustring,Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
|
||||
void RTImage::changeImage(Glib::ustring &newImage)
|
||||
{
|
||||
clear();
|
||||
std::map<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
|
||||
it = pixBufMap.find(newImage);
|
||||
|
||||
if (it != pixBufMap.end()) {
|
||||
set(it->second);
|
||||
} else {
|
||||
Glib::ustring fullPath = findIconAbsolutePath(newImage);
|
||||
Glib::RefPtr<Gdk::Pixbuf> tempPixPuf = Gdk::Pixbuf::create_from_file(fullPath);
|
||||
pixBufMap.insert(std::pair<Glib::ustring,Glib::RefPtr<Gdk::Pixbuf> >(newImage, tempPixPuf));
|
||||
pixBufMap.insert(std::pair<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >(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 "";
|
||||
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;
|
||||
void RTImage::setPaths(Options &opt)
|
||||
{
|
||||
Glib::ustring configFilename;
|
||||
rtengine::SafeKeyFile keyFile;
|
||||
bool hasKeyFile = true;
|
||||
|
||||
imagesPaths.clear();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
// 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")));
|
||||
}
|
||||
|
||||
if (hasKeyFile && keyFile.has_group ("General")) {
|
||||
Glib::ustring iSet;
|
||||
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.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"))));
|
||||
}
|
||||
if (!keyFile.load_from_file (configFilename)) {
|
||||
hasKeyFile = false;
|
||||
}
|
||||
}
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
|
||||
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"));
|
||||
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"));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user