/loggerouter/trunk

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

« back to all changes in this revision

Viewing changes to src/settings.vala

  • Committer: Gustav Hartvigsson
  • Date: 2025-06-03 21:28:25 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20250603212825-d99acf3s4b1qktk3
spellingĀ error

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
  private static GLib.Once<LO.Settings?> instance;
26
26
 
27
27
  public bool? dark_theme;
28
 
  
29
 
  //TODO: Timer countdown setting.
30
 
 
31
 
  string to_string () {
32
 
    var builder = new StringBuilder ();
33
 
    builder.append_printf ("key_file: %px\n", key_file);
34
 
    builder.append_printf ("config_path: %s", config_path);
35
 
    builder.append_printf ("dark_theme: %s", dark_theme.to_string ());
36
 
    return builder.str;
37
 
  }
38
28
 
39
29
  public static unowned LO.Settings? get_instance () {
40
30
    return instance.once (() => {
45
35
  private Settings () {}
46
36
 
47
37
  public void load_settings (string config_path) {
48
 
    print ("path\n");
49
38
    key_file = new GLib.KeyFile ();
50
 
    this.config_path = config_path;
 
39
  this.config_path = config_path;
51
40
    parse_key_file ();
52
41
  }
53
42
 
54
43
  public void load_setting_from_xdg () {
55
 
    print ("xdg\n");
56
44
    key_file = new GLib.KeyFile ();
57
45
    this.config_path = LO_XDG_CONFIG_PATH;
58
 
    if (GLib.File.new_for_path (this.config_path).query_exists ()) {
59
 
      parse_key_file ();
60
 
    } else {
61
 
      stderr.printf ("Colud not find file: %s", this.config_path);
62
 
      this.dark_theme = false;
63
 
    }
64
46
  }
65
47
 
66
48
  private void parse_key_file ()
67
49
  requires (key_file != null) {
68
 
    print ("Hello!\n");
69
50
    try {
70
51
      key_file.load_from_file (this.config_path, GLib.KeyFileFlags.NONE);
71
52
    } catch (GLib.FileError e) {
72
53
      string message = @"ERROR: $(e.message)\n";
73
54
      stderr.printf (message);
74
 
      GLib.Process.exit (41);
75
55
    } catch (GLib.KeyFileError e) {
76
56
      string message = @"ERROR: $(e.message)\n";
77
57
      stderr.printf (message);
78
 
      GLib.Process.exit (42);
79
58
    }
80
59
 
81
60
    try {
82
61
      if( key_file.has_key (CONFIG_INI_NAMESPACE_MAIN, "DarkTheme") ) {
83
62
        this.dark_theme = key_file.get_boolean (CONFIG_INI_NAMESPACE_MAIN, "DarkTheme");
84
 
      } else {
85
 
        this.dark_theme = true;
86
63
      }
87
64
    } catch (GLib.KeyFileError e) {
88
65
      string message = @"ERROR: $(e.message)\n";
89
66
      stderr.printf (message);
90
 
      GLib.Process.exit (43);
91
67
    }
92
68
  }
93
69
}