Skip to content

Commit 721621b

Browse files
committed
Modernize gnome setter to use GSettings
1 parent 66e13bd commit 721621b

File tree

1 file changed

+19
-60
lines changed

1 file changed

+19
-60
lines changed

src/SetBG.cc

+19-60
Original file line numberDiff line numberDiff line change
@@ -896,68 +896,29 @@ void SetBGXinerama::get_target_dimensions(Glib::ustring& disp, gint winx, gint w
896896
*
897897
* Simply calls gconftool-2 for now, until we find a better way to do it.
898898
*/
899-
bool SetBGGnome::set_bg(Glib::ustring &disp, Glib::ustring file, SetMode mode, Gdk::Color bgcolor) {
900-
901-
Glib::RefPtr<Gdk::Display> _display;
902-
Glib::RefPtr<Gdk::Screen> screen;
903-
904-
// open display and screen
905-
_display = (disp == "") ? Gdk::Display::open(Gdk::DisplayManager::get()->get_default_display()->get_name()) : Gdk::Display::open(disp);
906-
if (!_display) {
907-
std::cerr << _("Could not open display") << " " << disp << "\n";
908-
return false;
909-
}
910-
911-
// get the screen
912-
screen = _display->get_default_screen();
913-
914-
GError *error = NULL;
915-
916-
Glib::ustring strmode = "scaled"; // in case of more modes
917-
switch(mode) {
918-
case SetBG::SET_SCALE: strmode = "stretched"; break;
919-
case SetBG::SET_TILE: strmode = "wallpaper"; break;
920-
case SetBG::SET_CENTER: strmode = "centered"; break;
921-
case SetBG::SET_ZOOM: strmode = "scaled"; break;
922-
case SetBG::SET_ZOOM_FILL: strmode = "scaled"; break;
899+
bool SetBGGnome::set_bg(Glib::ustring &disp, Glib::ustring file, SetMode mode, Gdk::Color bgcolor)
900+
{
901+
Glib::ustring strmode;
902+
switch(mode) {
903+
case SetBG::SET_SCALE: strmode = "stretched"; break;
904+
case SetBG::SET_TILE: strmode = "wallpaper"; break;
905+
case SetBG::SET_CENTER: strmode = "centered"; break;
906+
case SetBG::SET_ZOOM: strmode = "scaled"; break;
907+
case SetBG::SET_ZOOM_FILL:
908+
default: strmode = "zoom"; break;
923909
};
924910

925-
std::vector<std::string> vecCmdLine;
926-
vecCmdLine.push_back(std::string("gconftool-2"));
927-
vecCmdLine.push_back(std::string("--type"));
928-
vecCmdLine.push_back(std::string("string"));
929-
vecCmdLine.push_back(std::string("--set"));
930-
vecCmdLine.push_back(std::string("/desktop/gnome/background/picture_options"));
931-
vecCmdLine.push_back(std::string(strmode));
932-
vecCmdLine.push_back(std::string("--set"));
933-
vecCmdLine.push_back(std::string("/desktop/gnome/background/picture_filename"));
934-
vecCmdLine.push_back(std::string(file));
935-
936-
std::string strcolor = std::string( bgcolor.to_string() );
937-
vecCmdLine.push_back(std::string("--set"));
938-
vecCmdLine.push_back(std::string("/desktop/gnome/background/primary_color"));
939-
vecCmdLine.push_back(strcolor);
940-
vecCmdLine.push_back(std::string("--set"));
941-
vecCmdLine.push_back(std::string("/desktop/gnome/background/secondary_color"));
942-
vecCmdLine.push_back(strcolor);
943-
944-
try
945-
{
946-
Glib::spawn_async("", vecCmdLine, Glib::SPAWN_SEARCH_PATH);
947-
}
948-
catch (Glib::SpawnError e)
949-
{
950-
std::cerr << _("ERROR") << "\n" << e.what() << "\n";
951-
952-
for (std::vector<std::string>::const_iterator i = vecCmdLine.begin(); i != vecCmdLine.end(); i++)
953-
std::cerr << *i << " ";
911+
Glib::RefPtr<Gio::Settings> settings = Gio::Settings::create("org.gnome.desktop.background");
954912

955-
std::cerr << "\n";
913+
Glib::RefPtr<Gio::File> iofile = Gio::File::create_for_commandline_arg(file);
956914

957-
return false;
958-
}
915+
settings->set_string("picture-uri", iofile->get_uri());
916+
settings->set_string("picture-options", strmode);
917+
settings->set_string("primary-color", bgcolor.to_string());
918+
settings->set_string("secondary-color", bgcolor.to_string());
919+
settings->set_boolean("draw-background", true);
959920

960-
return true;
921+
return true;
961922
}
962923

963924
Glib::ustring SetBGGnome::get_prefix()
@@ -979,11 +940,9 @@ Glib::ustring SetBGGnome::get_fullscreen_key()
979940
/**
980941
* Make a usable display key to pass to set_bg with a given head number.
981942
* If no head number given, returns the fullscreen key.
982-
*
983-
* This is N/A?
984943
*/
985944
Glib::ustring SetBGGnome::make_display_key(guint head)
986945
{
987-
return Glib::ustring("???");
946+
return Glib::ustring("");
988947
}
989948

0 commit comments

Comments
 (0)