Commit dc7e64f8 authored by Melroy van den Berg's avatar Melroy van den Berg

Merge branch 'use_xdg_for_images' into 'master'

Use XDG_DATA_DIRS for image resources

See merge request !3
parents c0b1edf1 c0977d8c
Pipeline #2510 passed with stages
in 2 minutes
......@@ -27,12 +27,6 @@
// Use major.minor.patch syntax, don't forget to update CMakeLists.txt file as well!
static const std::string VERSION = "v1.6.0";
#if defined(PRODUCTION)
#define IMAGE_LOCATION "/usr/share/winegui/images/" /*!< Image location */
#else
#define IMAGE_LOCATION "../images/" /*!< Image location */
#endif
/**
* \class AboutDialog
* \brief The About dialog
......
......@@ -24,12 +24,6 @@
#include <string>
#include "bottle_types.h"
#if defined(PRODUCTION)
#define IMAGE_LOCATION "/usr/share/winegui/images/" /*!< Image location */
#else
#define IMAGE_LOCATION "../images/" /*!< Image location */
#endif
/**
* \class BottleItem
* \brief Class object definition for a wine bottle item
......@@ -151,4 +145,4 @@ private:
void CreateUI();
static std::string str_tolower(std::string s);
};
\ No newline at end of file
};
......@@ -77,6 +77,7 @@ public:
static bool GetDLLOverride(const string prefix_path, const string dll_name, DLLOverride::LoadOrder load_order = DLLOverride::LoadOrder::Native);
static string GetUninstaller(const string prefix_path, const string uninstallerKey);
static string GetFontFilename(const string prefix_path, BottleTypes::Bit bit, const string fontName);
static string GetImageLocation(const string filename);
private:
Helper();
~Helper();
......
......@@ -32,12 +32,6 @@ using std::string;
using std::cout;
using std::endl;
#if defined(PRODUCTION)
#define IMAGE_LOCATION "/usr/share/winegui/images/" /*!< Image location */
#else
#define IMAGE_LOCATION "../images/" /*!< Image location */
#endif
/**
* \class MainWindow
* \brief Main GTK+ Window class
......
......@@ -19,13 +19,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "about_dialog.h"
#include "helper.h"
/**
* \brief Contructor
*/
AboutDialog::AboutDialog(Gtk::Window& parent) {
// Set logo
logo.set(IMAGE_LOCATION "logo.png");
logo.set(Helper::GetImageLocation("logo.png"));
// Set version
std::vector<Glib::ustring> devs;
devs.push_back("Melroy van den Berg <melroy@melroy.org>");
......@@ -59,4 +60,4 @@ void AboutDialog::hide_dialog(__attribute__((unused)) int response)
*/
std::string AboutDialog::GetVersion() {
return VERSION;
}
\ No newline at end of file
}
......@@ -20,6 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bottle_item.h"
#include "helper.h"
/**
* \brief Default contructor
......@@ -115,7 +116,7 @@ void BottleItem::CreateUI()
bool status = this->status();
// Set left side of the GUI
image.set(IMAGE_LOCATION "windows/" + filename);
image.set(Helper::GetImageLocation("windows/" + filename));
image.set_margin_top(8);
image.set_margin_end(8);
image.set_margin_bottom(8);
......@@ -126,10 +127,10 @@ void BottleItem::CreateUI()
Glib::ustring status_text = "Ready";
if (status) {
status_icon.set(IMAGE_LOCATION "ready.png");
status_icon.set(Helper::GetImageLocation("ready.png"));
} else {
status_text = "Not Ready";
status_icon.set(IMAGE_LOCATION "not_ready.png");
status_icon.set(Helper::GetImageLocation("not_ready.png"));
}
status_icon.set_size_request(2, -1);
status_icon.set_halign(Gtk::Align::ALIGN_START);
......
......@@ -870,6 +870,32 @@ string Helper::GetFontFilename(const string prefix_path, BottleTypes::Bit bit, c
return Helper::GetRegValue(filename, keyName, fontName);
}
/**
* \brief Get path to an image resource located in a global data directory (like /usr/share)
* \param[in] filename - name of image
* \return Path to the requested image (or empty string if not found)
*/
string Helper::GetImageLocation(const string filename)
{
for (string data_dir : Glib::get_system_data_dirs())
{
std::vector<std::string> path_builder{data_dir, "winegui", "images", filename};
string file_path = Glib::build_path(G_DIR_SEPARATOR_S, path_builder);
if (FileExists(file_path)) {
return file_path;
}
}
// try local path if the images are not installed
string file_path = Glib::build_filename("../images/", filename);
if (FileExists(file_path)) {
return file_path;
}
else
{
return "";
}
}
/****************************************************************************
* Private methods *
......
......@@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "main_window.h"
#include "helper.h"
#include "signal_dispatcher.h"
#include <locale>
......@@ -43,7 +43,7 @@ MainWindow::MainWindow(Menu& menu)
set_position(Gtk::WIN_POS_CENTER_ALWAYS);
try {
set_icon_from_file(IMAGE_LOCATION "logo.png");
set_icon_from_file(Helper::GetImageLocation("logo.png"));
}
catch (Glib::FileError& e) {
cout << "Catched " << e.what() << endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment