diff options
Diffstat (limited to 'src/settings-manager.c')
-rw-r--r-- | src/settings-manager.c | 424 |
1 files changed, 424 insertions, 0 deletions
diff --git a/src/settings-manager.c b/src/settings-manager.c new file mode 100644 index 0000000..898e983 --- /dev/null +++ b/src/settings-manager.c @@ -0,0 +1,424 @@ +/* settings-manager.c generated by valac 0.14.0, the Vala compiler + * generated from settings-manager.vala, do not modify */ + +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <glib.h> +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <gee.h> + + +#define TYPE_SETTINGS_MANAGER (settings_manager_get_type ()) +#define SETTINGS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SETTINGS_MANAGER, SettingsManager)) +#define SETTINGS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SETTINGS_MANAGER, SettingsManagerClass)) +#define IS_SETTINGS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SETTINGS_MANAGER)) +#define IS_SETTINGS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SETTINGS_MANAGER)) +#define SETTINGS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SETTINGS_MANAGER, SettingsManagerClass)) + +typedef struct _SettingsManager SettingsManager; +typedef struct _SettingsManagerClass SettingsManagerClass; +typedef struct _SettingsManagerPrivate SettingsManagerPrivate; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_free0(var) (var = (g_free (var), NULL)) + +struct _SettingsManager { + GObject parent_instance; + SettingsManagerPrivate * priv; +}; + +struct _SettingsManagerClass { + GObjectClass parent_class; +}; + +struct _SettingsManagerPrivate { + GSettings* settings; +}; + + +static gpointer settings_manager_parent_class = NULL; + +GType settings_manager_get_type (void) G_GNUC_CONST; +#define SETTINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_SETTINGS_MANAGER, SettingsManagerPrivate)) +enum { + SETTINGS_MANAGER_DUMMY_PROPERTY +}; +SettingsManager* settings_manager_new (void); +SettingsManager* settings_manager_construct (GType object_type); +gchar** settings_manager_fetch_blacklist (SettingsManager* self, int* result_length1); +GeeArrayList* settings_manager_fetch_interested (SettingsManager* self); +static gboolean _vala_string_array_contains (gchar** stack, int stack_length, gchar* needle); +void settings_manager_clear_list (SettingsManager* self); +void settings_manager_add_interested (SettingsManager* self, const gchar* app_desktop_name); +static void _vala_array_add1 (gchar*** array, int* length, int* size, gchar* value); +static void settings_manager_on_blacklist_event (SettingsManager* self); +static void g_cclosure_user_marshal_VOID__BOXED_INT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data); +static GObject * settings_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties); +static void _settings_manager_on_blacklist_event_g_settings_changed (GSettings* _sender, const gchar* key, gpointer self); +static void settings_manager_finalize (GObject* obj); +static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func); +static gint _vala_array_length (gpointer array); + + +SettingsManager* settings_manager_construct (GType object_type) { + SettingsManager * self = NULL; + self = (SettingsManager*) g_object_new (object_type, NULL); + return self; +} + + +SettingsManager* settings_manager_new (void) { + return settings_manager_construct (TYPE_SETTINGS_MANAGER); +} + + +gchar** settings_manager_fetch_blacklist (SettingsManager* self, int* result_length1) { + gchar** result = NULL; + GSettings* _tmp0_; + gchar** _tmp1_; + gchar** _tmp2_ = NULL; + gchar** _tmp3_; + gint _tmp3__length1; + g_return_val_if_fail (self != NULL, NULL); + _tmp0_ = self->priv->settings; + _tmp2_ = _tmp1_ = g_settings_get_strv (_tmp0_, "blacklisted-media-players"); + _tmp3_ = _tmp2_; + _tmp3__length1 = _vala_array_length (_tmp1_); + if (result_length1) { + *result_length1 = _tmp3__length1; + } + result = _tmp3_; + return result; +} + + +static gboolean _vala_string_array_contains (gchar** stack, int stack_length, gchar* needle) { + int i; + for (i = 0; i < stack_length; i++) { + if (g_strcmp0 (stack[i], needle) == 0) { + return TRUE; + } + } + return FALSE; +} + + +GeeArrayList* settings_manager_fetch_interested (SettingsManager* self) { + GeeArrayList* result = NULL; + GSettings* _tmp0_; + gchar** _tmp1_; + gchar** _tmp2_ = NULL; + gchar** blacklisted; + gint blacklisted_length1; + gint _blacklisted_size_; + GSettings* _tmp3_; + gchar** _tmp4_; + gchar** _tmp5_ = NULL; + gchar** interested; + gint interested_length1; + gint _interested_size_; + GeeArrayList* _tmp6_; + GeeArrayList* list; + gchar** _tmp7_; + gint _tmp7__length1; + g_return_val_if_fail (self != NULL, NULL); + _tmp0_ = self->priv->settings; + _tmp2_ = _tmp1_ = g_settings_get_strv (_tmp0_, "blacklisted-media-players"); + blacklisted = _tmp2_; + blacklisted_length1 = _vala_array_length (_tmp1_); + _blacklisted_size_ = blacklisted_length1; + _tmp3_ = self->priv->settings; + _tmp5_ = _tmp4_ = g_settings_get_strv (_tmp3_, "interested-media-players"); + interested = _tmp5_; + interested_length1 = _vala_array_length (_tmp4_); + _interested_size_ = interested_length1; + _tmp6_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL); + list = _tmp6_; + _tmp7_ = interested; + _tmp7__length1 = interested_length1; + { + gchar** s_collection = NULL; + gint s_collection_length1 = 0; + gint _s_collection_size_ = 0; + gint s_it = 0; + s_collection = _tmp7_; + s_collection_length1 = _tmp7__length1; + for (s_it = 0; s_it < _tmp7__length1; s_it = s_it + 1) { + gchar* _tmp8_; + gchar* s = NULL; + _tmp8_ = g_strdup (s_collection[s_it]); + s = _tmp8_; + { + const gchar* _tmp9_; + GeeArrayList* _tmp11_; + const gchar* _tmp12_; + gboolean _tmp13_ = FALSE; + const gchar* _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GeeArrayList* _tmp16_; + const gchar* _tmp17_; + _tmp9_ = s; + if (g_strcmp0 (_tmp9_, "banshee-1") == 0) { + gchar* _tmp10_; + _tmp10_ = g_strdup ("banshee"); + _g_free0 (s); + s = _tmp10_; + } + _tmp11_ = list; + _tmp12_ = s; + _tmp13_ = gee_abstract_collection_contains ((GeeAbstractCollection*) _tmp11_, _tmp12_); + if (_tmp13_) { + _g_free0 (s); + continue; + } + _tmp14_ = s; + _tmp15_ = blacklisted; + _tmp15__length1 = blacklisted_length1; + if (_vala_string_array_contains (_tmp15_, _tmp15__length1, _tmp14_)) { + _g_free0 (s); + continue; + } + _tmp16_ = list; + _tmp17_ = s; + gee_abstract_collection_add ((GeeAbstractCollection*) _tmp16_, _tmp17_); + _g_free0 (s); + } + } + } + result = list; + interested = (_vala_array_free (interested, interested_length1, (GDestroyNotify) g_free), NULL); + blacklisted = (_vala_array_free (blacklisted, blacklisted_length1, (GDestroyNotify) g_free), NULL); + return result; +} + + +void settings_manager_clear_list (SettingsManager* self) { + GSettings* _tmp0_; + g_return_if_fail (self != NULL); + _tmp0_ = self->priv->settings; + g_settings_reset (_tmp0_, "interested-media-players"); +} + + +static void _vala_array_add1 (gchar*** array, int* length, int* size, gchar* value) { + if ((*length) == (*size)) { + *size = (*size) ? (2 * (*size)) : 4; + *array = g_renew (gchar*, *array, (*size) + 1); + } + (*array)[(*length)++] = value; + (*array)[*length] = NULL; +} + + +void settings_manager_add_interested (SettingsManager* self, const gchar* app_desktop_name) { + GSettings* _tmp0_; + gchar** _tmp1_; + gchar** _tmp2_ = NULL; + gchar** already_interested; + gint already_interested_length1; + gint _already_interested_size_; + gchar** _tmp3_; + gint _tmp3__length1; + gchar** _tmp7_; + gint _tmp7__length1; + const gchar* _tmp8_; + gchar* _tmp9_; + GSettings* _tmp10_; + gchar** _tmp11_; + gint _tmp11__length1; + GSettings* _tmp12_; + g_return_if_fail (self != NULL); + g_return_if_fail (app_desktop_name != NULL); + _tmp0_ = self->priv->settings; + _tmp2_ = _tmp1_ = g_settings_get_strv (_tmp0_, "interested-media-players"); + already_interested = _tmp2_; + already_interested_length1 = _vala_array_length (_tmp1_); + _already_interested_size_ = already_interested_length1; + _tmp3_ = already_interested; + _tmp3__length1 = already_interested_length1; + { + gchar** s_collection = NULL; + gint s_collection_length1 = 0; + gint _s_collection_size_ = 0; + gint s_it = 0; + s_collection = _tmp3_; + s_collection_length1 = _tmp3__length1; + for (s_it = 0; s_it < _tmp3__length1; s_it = s_it + 1) { + gchar* _tmp4_; + gchar* s = NULL; + _tmp4_ = g_strdup (s_collection[s_it]); + s = _tmp4_; + { + const gchar* _tmp5_; + const gchar* _tmp6_; + _tmp5_ = s; + _tmp6_ = app_desktop_name; + if (g_strcmp0 (_tmp5_, _tmp6_) == 0) { + _g_free0 (s); + already_interested = (_vala_array_free (already_interested, already_interested_length1, (GDestroyNotify) g_free), NULL); + return; + } + _g_free0 (s); + } + } + } + _tmp7_ = already_interested; + _tmp7__length1 = already_interested_length1; + _tmp8_ = app_desktop_name; + _tmp9_ = g_strdup (_tmp8_); + _vala_array_add1 (&already_interested, &already_interested_length1, &_already_interested_size_, _tmp9_); + _tmp10_ = self->priv->settings; + _tmp11_ = already_interested; + _tmp11__length1 = already_interested_length1; + g_settings_set_strv (_tmp10_, "interested-media-players", _tmp11_); + _tmp12_ = self->priv->settings; + g_settings_apply (_tmp12_); + already_interested = (_vala_array_free (already_interested, already_interested_length1, (GDestroyNotify) g_free), NULL); +} + + +static void settings_manager_on_blacklist_event (SettingsManager* self) { + GSettings* _tmp0_; + gchar** _tmp1_; + gchar** _tmp2_ = NULL; + gchar** _tmp3_; + gint _tmp3__length1; + g_return_if_fail (self != NULL); + _tmp0_ = self->priv->settings; + _tmp2_ = _tmp1_ = g_settings_get_strv (_tmp0_, "blacklisted-media-players"); + _tmp3_ = _tmp2_; + _tmp3__length1 = _vala_array_length (_tmp1_); + g_signal_emit_by_name (self, "blacklist-updates", _tmp3_, _vala_array_length (_tmp1_)); + _tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL); +} + + +static void g_cclosure_user_marshal_VOID__BOXED_INT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) { + typedef void (*GMarshalFunc_VOID__BOXED_INT) (gpointer data1, gpointer arg_1, gint arg_2, gpointer data2); + register GMarshalFunc_VOID__BOXED_INT callback; + register GCClosure * cc; + register gpointer data1; + register gpointer data2; + cc = (GCClosure *) closure; + g_return_if_fail (n_param_values == 3); + if (G_CCLOSURE_SWAP_DATA (closure)) { + data1 = closure->data; + data2 = param_values->data[0].v_pointer; + } else { + data1 = param_values->data[0].v_pointer; + data2 = closure->data; + } + callback = (GMarshalFunc_VOID__BOXED_INT) (marshal_data ? marshal_data : cc->callback); + callback (data1, g_value_get_boxed (param_values + 1), g_value_get_int (param_values + 2), data2); +} + + +static void _settings_manager_on_blacklist_event_g_settings_changed (GSettings* _sender, const gchar* key, gpointer self) { + settings_manager_on_blacklist_event (self); +} + + +static GObject * settings_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) { + GObject * obj; + GObjectClass * parent_class; + SettingsManager * self; + GSettings* _tmp0_; + GSettings* _tmp1_; + parent_class = G_OBJECT_CLASS (settings_manager_parent_class); + obj = parent_class->constructor (type, n_construct_properties, construct_properties); + self = SETTINGS_MANAGER (obj); + _tmp0_ = g_settings_new ("com.canonical.indicators.sound"); + _g_object_unref0 (self->priv->settings); + self->priv->settings = _tmp0_; + _tmp1_ = self->priv->settings; + g_signal_connect_object (_tmp1_, "changed::blacklisted-media-players", (GCallback) _settings_manager_on_blacklist_event_g_settings_changed, self, 0); + return obj; +} + + +static void settings_manager_class_init (SettingsManagerClass * klass) { + settings_manager_parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (klass, sizeof (SettingsManagerPrivate)); + G_OBJECT_CLASS (klass)->constructor = settings_manager_constructor; + G_OBJECT_CLASS (klass)->finalize = settings_manager_finalize; + g_signal_new ("blacklist_updates", TYPE_SETTINGS_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__BOXED_INT, G_TYPE_NONE, 2, G_TYPE_STRV, G_TYPE_INT); +} + + +static void settings_manager_instance_init (SettingsManager * self) { + self->priv = SETTINGS_MANAGER_GET_PRIVATE (self); +} + + +static void settings_manager_finalize (GObject* obj) { + SettingsManager * self; + self = SETTINGS_MANAGER (obj); + _g_object_unref0 (self->priv->settings); + G_OBJECT_CLASS (settings_manager_parent_class)->finalize (obj); +} + + +GType settings_manager_get_type (void) { + static volatile gsize settings_manager_type_id__volatile = 0; + if (g_once_init_enter (&settings_manager_type_id__volatile)) { + static const GTypeInfo g_define_type_info = { sizeof (SettingsManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) settings_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SettingsManager), 0, (GInstanceInitFunc) settings_manager_instance_init, NULL }; + GType settings_manager_type_id; + settings_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "SettingsManager", &g_define_type_info, 0); + g_once_init_leave (&settings_manager_type_id__volatile, settings_manager_type_id); + } + return settings_manager_type_id__volatile; +} + + +static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) { + if ((array != NULL) && (destroy_func != NULL)) { + int i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + + +static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) { + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + + +static gint _vala_array_length (gpointer array) { + int length; + length = 0; + if (array) { + while (((gpointer*) array)[length]) { + length++; + } + } + return length; +} + + + |