Gio.Settings. In the methods section, notice that there is a function called
set_string. We can use this method to set the picture-uri property. To understand what is the schema name we need to modify the settings for, click on the Picture URI and you can see the Schema mentioned there
wallpaper_servicewhich first downloads a file from a URL to a pre defined file path. And then another function which modifies the GSettings for the desktop background to change the wallpaper.
servicesand create a file called
splash_wallpaper_file_pathwhich is a constant path at which we will be saving the wallpaper. Another class variable called
background_settingswhich holds GSettings for the schema which we got from exploring DConf (
~/Pictures. GLib provides a bunch of utility functions which can point us to the right path. Why don't we hardcode? To understand that, think in terms of a person who is using his system in japanese. He/She would not have a
~/Picturesfolder at all. It will be named something else. This abstraction makes sure that apps don't break in such scenario.
set_wallpaper_from_file_urijust takes in a URI and set's the GSetting accordingly.
set_wallpaper_from_file_uridownloads an image from the URL and saves in a given path. The final function
set_wallpaper_from_urlcombines both these functions, it takes in a
image_url, downloads the file and places it in the desired file path and then changes the GSetting. Great!
access keyfor making a request which you can easily obtain by registering as a developer with Unsplash. Join us back once you have the API key!
srcfolder, create a file called