2
Copyright 2010 Canonical Ltd.
5
Conor Curran <conor.curran@canonical.com>
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.
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.
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/>.
21
public class SettingsManager : GLib.Object
23
private Settings settings;
24
public signal void blacklist_updates ( string[] new_blacklist );
25
public signal void preferred_updates (Gee.ArrayList<string> new_preferred);
27
public SettingsManager ( ){
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);
35
public string[] fetch_blacklist()
37
return this.settings.get_strv ("blacklisted-media-players");
40
public ArrayList<string> fetch_preferred()
42
var list = new ArrayList<string>();
44
var preferred = this.settings.get_strv ("preferred-media-players");
45
var interested = fetch_interested ();
47
foreach (var s in preferred) {
48
if (!(s in list) && interested.contains (s))
55
public ArrayList<string> fetch_interested()
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"){
64
if (s in list) continue;
65
if (s in blacklisted) continue;
71
public void clear_list()
73
this.settings.reset("interested-media-players");
76
public void remove_interested (string app_desktop_name)
78
const string key = "interested-media-players";
79
var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings
81
foreach (var player in this.settings.get_strv (key)) {
82
if (player != app_desktop_name)
83
players.add ("s", player);
86
this.settings.set_value(key, players.end());
87
this.settings.apply();
90
public void add_interested (string app_desktop_name)
92
const string key = "interested-media-players";
93
var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings
95
foreach (var player in this.settings.get_strv (key)) {
96
if (player == app_desktop_name)
98
players.add ("s", player);
101
players.add ("s", app_desktop_name);
102
this.settings.set_value(key, players.end());
103
this.settings.apply();
106
private void on_blacklist_event()
108
this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players"));
111
private void on_preferred_event()
113
this.preferred_updates (this.fetch_preferred());
116
// Convenient debug method inorder to provide visability over
117
// the contents of both interested and blacklisted containers in its gsettings
119
private void reveal_contents()
121
var already_interested = this.settings.get_strv ("interested-media-players");
122
foreach (var s in already_interested)
124
debug ("client %s is in interested array", s);
126
var blacklisted = this.settings.get_strv ("blacklisted-media-players");
127
foreach (var s in blacklisted)
129
debug ("client %s is in blacklisted array", s);
132
debug ("interested array size = %i", already_interested.length);
133
debug ("blacklisted array size = %i", blacklisted.length);