Switch from giomm to gio

Seems that gio has more documentation than giomm.
This commit is contained in:
Vinyl Darkscratch 2018-06-01 22:43:36 -07:00
parent e31229d405
commit 7f4f9ff5a5

View file

@ -23,7 +23,7 @@
#include "mac-desktop.h" #include "mac-desktop.h"
static bool isCached = false; static bool isCached = false;
#else #else
#include <giomm/settings.h> #include <gio/gio.h>
#include <xfconf/xfconf.h> #include <xfconf/xfconf.h>
#include <unistd.h> #include <unistd.h>
#include <algorithm> #include <algorithm>
@ -32,7 +32,7 @@
#include <sstream> #include <sstream>
static std::string desktop = "uninitialized"; static std::string desktop = "uninitialized";
// GNOME settings // GNOME settings
static Glib::RefPtr<Gio::Settings> bgsetting; static GSettings *bgsetting;
static std::string defPictureURI, defPictureOptions, defPrimaryColor, defColorShading; static std::string defPictureURI, defPictureOptions, defPrimaryColor, defColorShading;
// XFCE settings // XFCE settings
static XfconfChannel* bgchannel; static XfconfChannel* bgchannel;
@ -45,43 +45,44 @@
#endif #endif
#ifdef __linux__ #ifdef __linux__
void desktopEnvironmentInit() void desktopEnvironmentInit()
{ {
if (desktop != "uninitialized") { if (desktop != "uninitialized") {
return; return;
}
desktop = shState->oneshot().desktopEnv;
if (desktop == "gnome" || desktop == "mate") {
if (desktop == "gnome") {
bgsetting = Gio::Settings::create("org.gnome.desktop.background");
defPictureURI = bgsetting->get_string("picture-uri");
} else {
bgsetting = Gio::Settings::create("org.mate.background");
defPictureURI = bgsetting->get_string("picture-filename");
} }
defPictureOptions = bgsetting->get_string("picture-options"); desktop = shState->oneshot().desktopEnv;
defPrimaryColor = bgsetting->get_string("primary-color"); if (desktop == "gnome" || desktop == "mate") {
defColorShading = bgsetting->get_string("color-shading-type"); if (desktop == "gnome") {
} else if (desktop == "xfce") { bgsetting = g_settings_new("org.gnome.desktop.background");
GError *xferror = NULL; defPictureURI = g_settings_get_string(bgsetting, "picture-uri");
if (xfconf_init(&xferror)) { std::cout << defPictureURI << std::endl;
bgchannel = xfconf_channel_get("xfce4-desktop"); } else {
std::string optionPrefix = "/backdrop/screen0/monitor0/workspace0/"; bgsetting = g_settings_new("org.mate.background");
optionImage = optionPrefix + "last-image"; defPictureURI = g_settings_get_string(bgsetting, "picture-filename");
optionColor = optionPrefix + "color1"; }
optionImageStyle = optionPrefix + "image-style"; defPictureOptions = g_settings_get_string(bgsetting, "picture-options");
optionColorStyle = optionPrefix + "color-style"; defPrimaryColor = g_settings_get_string(bgsetting, "primary-color");
defPictureURI = xfconf_channel_get_string(bgchannel, optionImage.c_str(), ""); defColorShading = g_settings_get_string(bgsetting, "color-shading-type");
defPictureStyle = xfconf_channel_get_int(bgchannel, optionImageStyle.c_str(), -1); } else if (desktop == "xfce") {
defColorExists = xfconf_channel_get_property(bgchannel, optionColor.c_str(), &defColor); GError *xferror = NULL;
defColorStyle = xfconf_channel_get_int(bgchannel, optionColorStyle.c_str(), -1); if (xfconf_init(&xferror)) {
} else { bgchannel = xfconf_channel_get("xfce4-desktop");
// Configuration failed to initialize, we won't set the wallpaper std::string optionPrefix = "/backdrop/screen0/monitor0/workspace0/";
desktop = "xfce_error"; optionImage = optionPrefix + "last-image";
g_error_free(xferror); optionColor = optionPrefix + "color1";
optionImageStyle = optionPrefix + "image-style";
optionColorStyle = optionPrefix + "color-style";
defPictureURI = xfconf_channel_get_string(bgchannel, optionImage.c_str(), "");
defPictureStyle = xfconf_channel_get_int(bgchannel, optionImageStyle.c_str(), -1);
defColorExists = xfconf_channel_get_property(bgchannel, optionColor.c_str(), &defColor);
defColorStyle = xfconf_channel_get_int(bgchannel, optionColorStyle.c_str(), -1);
} else {
// Configuration failed to initialize, we won't set the wallpaper
desktop = "xfce_error";
g_error_free(xferror);
}
} }
} }
}
#endif #endif
RB_METHOD(wallpaperSet) RB_METHOD(wallpaperSet)
@ -187,13 +188,13 @@ end:
std::stringstream hexColor; std::stringstream hexColor;
hexColor << "#" << std::hex << color; hexColor << "#" << std::hex << color;
if (desktop == "gnome") { if (desktop == "gnome") {
bgsetting->set_string("picture-uri", "file://" + gameDirStr + path); g_settings_set_string(bgsetting, "picture-uri", ("file://" + gameDirStr + path).c_str());
} else { } else {
bgsetting->set_string("picture-filename", gameDirStr + path); g_settings_set_string(bgsetting, "picture-filename", (gameDirStr + path).c_str());
} }
bgsetting->set_string("picture-options", "scaled"); g_settings_set_string(bgsetting, "picture-options", "scaled");
bgsetting->set_string("primary-color", hexColor.str()); g_settings_set_string(bgsetting, "primary-color", hexColor.str().c_str());
bgsetting->set_string("color-shading-type", "solid"); g_settings_set_string(bgsetting, "color-shading-type", "solid");
} else if (desktop == "xfce") { } else if (desktop == "xfce") {
int r = (color >> 16) & 0xFF; int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF; int g = (color >> 8) & 0xFF;
@ -283,13 +284,13 @@ RB_METHOD(wallpaperReset)
desktopEnvironmentInit(); desktopEnvironmentInit();
if (desktop == "gnome" || desktop == "mate") { if (desktop == "gnome" || desktop == "mate") {
if (desktop == "gnome") { if (desktop == "gnome") {
bgsetting->set_string("picture-uri", defPictureURI); g_settings_set_string(bgsetting, "picture-uri", defPictureURI.c_str());
} else { } else {
bgsetting->set_string("picture-filename", defPictureURI); g_settings_set_string(bgsetting, "picture-filename", defPictureURI.c_str());
} }
bgsetting->set_string("picture-options", defPictureOptions); g_settings_set_string(bgsetting, "picture-options", defPictureOptions.c_str());
bgsetting->set_string("primary-color", defPrimaryColor); g_settings_set_string(bgsetting, "primary-color", defPrimaryColor.c_str());
bgsetting->set_string("color-shading-type", defColorShading); g_settings_set_string(bgsetting, "color-shading-type", defColorShading.c_str());
} else if (desktop == "xfce") { } else if (desktop == "xfce") {
if (defColorExists) { if (defColorExists) {
xfconf_channel_set_property(bgchannel, optionColor.c_str(), &defColor); xfconf_channel_set_property(bgchannel, optionColor.c_str(), &defColor);