Advertisement
Guest User

Untitled

a guest
Aug 4th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 2.12 KB | None | 0 0
  1. // compile with valac --pkg gio-2.0 daemon.vala
  2. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3.  
  4.  
  5. // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
  6. /***
  7.     BEGIN LICENSE
  8.  
  9.     Copyright (C) 2011-2014 elementary Developers
  10.  
  11.     This program is free software: you can redistribute it and/or modify it
  12.     under the terms of the GNU Lesser General Public License version 3, as published
  13.     by the Free Software Foundation.
  14.  
  15.     This program is distributed in the hope that it will be useful, but
  16.     WITHOUT ANY WARRANTY; without even the implied warranties of
  17.     MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
  18.     PURPOSE.  See the GNU General Public License for more details.
  19.  
  20.     You should have received a copy of the GNU General Public License along
  21.     with this program.  If not, see <http://www.gnu.org/licenses/>
  22.  
  23.     END LICENSE
  24. ***/
  25.  
  26. void main () {
  27.     var settings = new Settings ("org.gnome.desktop.background");
  28.  
  29.     write_settings (settings);
  30.  
  31.     settings.changed.connect (() => {
  32.         write_settings (settings);
  33.     });
  34.  
  35.     new MainLoop ().run ();
  36. }
  37.  
  38. void write_settings (Settings settings) {
  39.     try {
  40.         string settings_path = Path.build_path ("/", Environment.get_home_dir (), ".greeter-settings");
  41.         var settings_file = File.new_for_path (settings_path);
  42.  
  43.         if (settings_file.query_exists ()) {
  44.             settings_file.delete ();
  45.         }
  46.  
  47.         var dos = new DataOutputStream (
  48.             new BufferedOutputStream.sized (settings_file.create (
  49.                 FileCreateFlags.REPLACE_DESTINATION), 65536));
  50.  
  51.         dos.put_string ("picture-uri=" + settings.get_string ("picture-uri") + "\n");
  52.         dos.put_string ("picture-option=" + settings.get_string ("picture-options") + "\n");
  53.         dos.put_string ("primary-color=" + settings.get_string ("primary-color") + "\n");
  54.         dos.put_string ("secondary-color=" + settings.get_string ("secondary-color") + "\n");
  55.         if (!dos.close ()) {
  56.             warning ("Failed to close the output-stream");
  57.         }
  58.     } catch (Error e) {
  59.         warning ("%s", e.message);
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement