/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk

« back to all changes in this revision

Viewing changes to src/settings_data.js

  • Committer: Gustav Hartvigsson
  • Date: 2014-06-08 20:47:30 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140608204730-kwk8e14kzc9zax5w
* finnihed the construction of the settings file.
* Next is loading of the settings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 */
7
7
 
8
8
const Gio = imports.gi.Gio;
 
9
const GLib = imports.gi.GLib;
9
10
const Lang = imports.lang;
10
11
 
11
12
 
 
13
let _default_settings_object = null;
 
14
function get_settings () {
 
15
  if (!_default_settings_object) {
 
16
    _default_settings_object = new SettingsData ();
 
17
  }
 
18
  return _default_settings_object;
 
19
}
 
20
 
12
21
const SettingsData = new Lang.Class ({
13
22
  Name: 'SettingsData',
14
23
  
 
24
  /* Member definitions */
 
25
  _settings_file_path: String,
 
26
  _settings: Array,
 
27
  _settings_file: Gio.File,
 
28
  
15
29
  _init: function () {
16
 
    
 
30
    /* First we construct the path for where to store the settings file. */
 
31
    this._settings_file_path = "";
 
32
    this._settings_file_path += GLib.get_user_config_dir ();
 
33
    this._settings_file_path += "/gpump/gpump.json";
 
34
    print ("Config file is: " + this._settings_file_path);
 
35
    
 
36
    this._settings_file = Gio.File.new_for_path (this._settings_file_path);
 
37
    
 
38
    /* Then we check that the file exists. If the file doen not ekist we
 
39
     * construct some sane default values.
 
40
     */
 
41
    if (!GLib.file_test (this._settings_file_path, GLib.FileTest.EXISTS)) {
 
42
      /* -1 is undefined, and will be set at construction of the window */
 
43
      this._settings = {
 
44
        ui: {
 
45
          x: -1,
 
46
          y: -1,
 
47
          h: 500,
 
48
          w: 500
 
49
        },
 
50
        main: {
 
51
          privacy: {
 
52
            show_full_name: true,
 
53
            only_show_avatar: false
 
54
          },
 
55
          use_dark: false,
 
56
          first_run: true
 
57
        }
 
58
      };
 
59
      // DEBUG:
 
60
      print (JSON.stringify (this._settings, null, 2).toString () );
 
61
      
 
62
      
 
63
      let file_stream = this._settings_file.create (Gio.FileCreateFlags.PRIVATE,
 
64
                                                    null);
 
65
      file_stream.write_all (JSON.stringify (
 
66
          this._settings, null, 2).toString (), null);
 
67
      
 
68
      file_stream.close (null);
 
69
      
 
70
    } else {
 
71
      /* The file exists, we load the settings data into memory */
 
72
    }
17
73
  }
18
74
  
19
75
});