~ubuntu-branches/ubuntu/trusty/indicator-sound-gtk2/trusty-proposed

« back to all changes in this revision

Viewing changes to src/settings-manager.vala

  • Committer: Package Import Robot
  • Author(s): Lionel Le Folgoc
  • Date: 2012-09-10 00:09:01 UTC
  • Revision ID: package-import@ubuntu.com-20120910000901-q6469svv5d3pmn0y
Tags: upstream-12.10.0.1
ImportĀ upstreamĀ versionĀ 12.10.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2010 Canonical Ltd.
 
3
 
 
4
Authors:
 
5
    Conor Curran <conor.curran@canonical.com>
 
6
 
 
7
This program is free software: you can redistribute it and/or modify it 
 
8
under the terms of the GNU General Public License version 3, as published 
 
9
by the Free Software Foundation.
 
10
 
 
11
This program is distributed in the hope that it will be useful, but 
 
12
WITHOUT ANY WARRANTY; without even the implied warranties of 
 
13
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
14
PURPOSE.  See the GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License along 
 
17
with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
using Gee;
 
20
 
 
21
public class SettingsManager : GLib.Object
 
22
{
 
23
  private Settings settings;
 
24
  public signal void blacklist_updates ( string[] new_blacklist );
 
25
  public signal void preferred_updates (Gee.ArrayList<string> new_preferred);
 
26
  
 
27
  public SettingsManager ( ){
 
28
  }
 
29
  construct{
 
30
    this.settings = new Settings ("com.canonical.indicator.sound");
 
31
    this.settings.changed["blacklisted-media-players"].connect (on_blacklist_event);
 
32
    this.settings.changed["preferred-media-players"].connect (on_preferred_event);
 
33
  }
 
34
   
 
35
  public string[] fetch_blacklist()
 
36
  {
 
37
    return this.settings.get_strv ("blacklisted-media-players");
 
38
  }
 
39
 
 
40
  public ArrayList<string> fetch_preferred()
 
41
  {
 
42
    var list = new ArrayList<string>();
 
43
 
 
44
    var preferred = this.settings.get_strv ("preferred-media-players");
 
45
    var interested = fetch_interested ();
 
46
 
 
47
    foreach (var s in preferred) {
 
48
      if (!(s in list) && interested.contains (s))
 
49
        list.add (s);
 
50
    }
 
51
 
 
52
    return list;
 
53
  }
 
54
 
 
55
  public ArrayList<string> fetch_interested()
 
56
  {
 
57
    var blacklisted = fetch_blacklist ();
 
58
    var interested = this.settings.get_strv ("interested-media-players");
 
59
    var list = new ArrayList<string>();
 
60
    foreach(var s in interested){
 
61
      if (s == "banshee-1"){
 
62
        s = "banshee";
 
63
      }
 
64
      if (s in list) continue;
 
65
      if (s in blacklisted) continue;
 
66
      list.add(s);
 
67
    }
 
68
    return list;
 
69
  }
 
70
 
 
71
  public void clear_list()
 
72
  {
 
73
    this.settings.reset("interested-media-players");
 
74
  }
 
75
  
 
76
  public void remove_interested (string app_desktop_name)
 
77
  {
 
78
    const string key = "interested-media-players";
 
79
    var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings
 
80
 
 
81
    foreach (var player in this.settings.get_strv (key)) {
 
82
      if (player != app_desktop_name)
 
83
        players.add ("s", player);
 
84
    }
 
85
 
 
86
    this.settings.set_value(key, players.end());
 
87
    this.settings.apply();
 
88
  }
 
89
  
 
90
  public void add_interested (string app_desktop_name)
 
91
  {
 
92
    const string key = "interested-media-players";
 
93
    var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings
 
94
 
 
95
    foreach (var player in this.settings.get_strv (key)) {
 
96
      if (player == app_desktop_name)
 
97
        return;
 
98
      players.add ("s", player);
 
99
    }
 
100
 
 
101
    players.add ("s", app_desktop_name);
 
102
    this.settings.set_value(key, players.end());
 
103
    this.settings.apply();
 
104
  }
 
105
 
 
106
  private void on_blacklist_event()
 
107
  {
 
108
    this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players"));        
 
109
  }
 
110
 
 
111
  private void on_preferred_event()
 
112
  {
 
113
    this.preferred_updates (this.fetch_preferred());
 
114
  }
 
115
 
 
116
  // Convenient debug method inorder to provide visability over 
 
117
  // the contents of both interested and blacklisted containers in its gsettings
 
118
/**
 
119
  private void reveal_contents()
 
120
  {
 
121
    var already_interested = this.settings.get_strv ("interested-media-players");
 
122
    foreach (var s in already_interested)
 
123
    {
 
124
      debug ("client %s is in interested array", s);      
 
125
    }
 
126
    var blacklisted = this.settings.get_strv ("blacklisted-media-players");
 
127
    foreach (var s in blacklisted)
 
128
    {
 
129
      debug ("client %s is in blacklisted array", s);      
 
130
    }
 
131
 
 
132
    debug ("interested array size = %i", already_interested.length);
 
133
    debug ("blacklisted array size = %i", blacklisted.length);
 
134
  }
 
135
**/
 
136
}