From e46b4adef5c6c6805b3ca6dbfbe99a4299252514 Mon Sep 17 00:00:00 2001 From: haxar Date: Tue, 21 Feb 2012 20:14:01 -0800 Subject: gsd to msd complete rename patch by NiceandGently; file rename commit --- plugins/sound/gsd-sound-manager.c | 433 -------------------------------------- plugins/sound/gsd-sound-manager.h | 61 ------ plugins/sound/gsd-sound-plugin.c | 100 --------- plugins/sound/gsd-sound-plugin.h | 63 ------ plugins/sound/msd-sound-manager.c | 433 ++++++++++++++++++++++++++++++++++++++ plugins/sound/msd-sound-manager.h | 61 ++++++ plugins/sound/msd-sound-plugin.c | 100 +++++++++ plugins/sound/msd-sound-plugin.h | 63 ++++++ 8 files changed, 657 insertions(+), 657 deletions(-) delete mode 100644 plugins/sound/gsd-sound-manager.c delete mode 100644 plugins/sound/gsd-sound-manager.h delete mode 100644 plugins/sound/gsd-sound-plugin.c delete mode 100644 plugins/sound/gsd-sound-plugin.h create mode 100644 plugins/sound/msd-sound-manager.c create mode 100644 plugins/sound/msd-sound-manager.h create mode 100644 plugins/sound/msd-sound-plugin.c create mode 100644 plugins/sound/msd-sound-plugin.h (limited to 'plugins/sound') diff --git a/plugins/sound/gsd-sound-manager.c b/plugins/sound/gsd-sound-manager.c deleted file mode 100644 index 23fb240..0000000 --- a/plugins/sound/gsd-sound-manager.c +++ /dev/null @@ -1,433 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Lennart Poettering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#ifdef HAVE_PULSE -#include -#endif - -#include "msd-sound-manager.h" -#include "mate-settings-profile.h" - -#define MSD_SOUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerPrivate)) - -struct MsdSoundManagerPrivate -{ - guint mateconf_notify; - GList* monitors; - guint timeout; -}; - -#define MATECONF_SOUND_DIR "/desktop/mate/sound" - -static void msd_sound_manager_class_init (MsdSoundManagerClass *klass); -static void msd_sound_manager_init (MsdSoundManager *sound_manager); -static void msd_sound_manager_finalize (GObject *object); - -G_DEFINE_TYPE (MsdSoundManager, msd_sound_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -#ifdef HAVE_PULSE - -static void -sample_info_cb (pa_context *c, const pa_sample_info *i, int eol, void *userdata) -{ - pa_operation *o; - - if (!i) - return; - - g_debug ("Found sample %s", i->name); - - /* We only flush those samples which have an XDG sound name - * attached, because only those originate from themeing */ - if (!(pa_proplist_gets (i->proplist, PA_PROP_EVENT_ID))) - return; - - g_debug ("Dropping sample %s from cache", i->name); - - if (!(o = pa_context_remove_sample (c, i->name, NULL, NULL))) { - g_debug ("pa_context_remove_sample (): %s", pa_strerror (pa_context_errno (c))); - return; - } - - pa_operation_unref (o); - - /* We won't wait until the operation is actually executed to - * speed things up a bit.*/ -} - -static void -flush_cache (void) -{ - pa_mainloop *ml = NULL; - pa_context *c = NULL; - pa_proplist *pl = NULL; - pa_operation *o = NULL; - - g_debug ("Flushing sample cache"); - - if (!(ml = pa_mainloop_new ())) { - g_debug ("Failed to allocate pa_mainloop"); - goto fail; - } - - if (!(pl = pa_proplist_new ())) { - g_debug ("Failed to allocate pa_proplist"); - goto fail; - } - - pa_proplist_sets (pl, PA_PROP_APPLICATION_NAME, PACKAGE_NAME); - pa_proplist_sets (pl, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION); - pa_proplist_sets (pl, PA_PROP_APPLICATION_ID, "org.mate.SettingsDaemon"); - - if (!(c = pa_context_new_with_proplist (pa_mainloop_get_api (ml), PACKAGE_NAME, pl))) { - g_debug ("Failed to allocate pa_context"); - goto fail; - } - - pa_proplist_free (pl); - pl = NULL; - - if (pa_context_connect (c, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) { - g_debug ("pa_context_connect(): %s", pa_strerror (pa_context_errno (c))); - goto fail; - } - - /* Wait until the connection is established */ - while (pa_context_get_state (c) != PA_CONTEXT_READY) { - - if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { - g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); - goto fail; - } - - if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { - g_debug ("pa_mainloop_iterate() failed"); - goto fail; - } - } - - /* Enumerate all cached samples */ - if (!(o = pa_context_get_sample_info_list (c, sample_info_cb, NULL))) { - g_debug ("pa_context_get_sample_info_list(): %s", pa_strerror (pa_context_errno (c))); - goto fail; - } - - /* Wait until our operation is finished and there's nothing - * more queued to send to the server */ - while (pa_operation_get_state (o) == PA_OPERATION_RUNNING || pa_context_is_pending (c)) { - - if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { - g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); - goto fail; - } - - if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { - g_debug ("pa_mainloop_iterate() failed"); - goto fail; - } - } - - g_debug ("Sample cache flushed"); - -fail: - if (o) { - pa_operation_cancel (o); - pa_operation_unref (o); - } - - if (c) { - pa_context_disconnect (c); - pa_context_unref (c); - } - - if (pl) - pa_proplist_free (pl); - - if (ml) - pa_mainloop_free (ml); -} - -static gboolean -flush_cb (MsdSoundManager *manager) -{ - flush_cache (); - manager->priv->timeout = 0; - return FALSE; -} - -static void -trigger_flush (MsdSoundManager *manager) -{ - - if (manager->priv->timeout) - g_source_remove (manager->priv->timeout); - - /* We delay the flushing a bit so that we can coalesce - * multiple changes into a single cache flush */ - manager->priv->timeout = g_timeout_add (500, (GSourceFunc) flush_cb, manager); -} - -static void -mateconf_client_notify_cb (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdSoundManager *manager) -{ - trigger_flush (manager); -} - -static gboolean -register_config_callback (MsdSoundManager *manager, GError **error) -{ - MateConfClient *client; - gboolean succ; - - client = mateconf_client_get_default (); - - mateconf_client_add_dir (client, MATECONF_SOUND_DIR, MATECONF_CLIENT_PRELOAD_NONE, error); - succ = !error || !*error; - - if (!error) { - manager->priv->mateconf_notify = mateconf_client_notify_add (client, MATECONF_SOUND_DIR, (MateConfClientNotifyFunc) mateconf_client_notify_cb, manager, NULL, error); - succ = !error || !*error; - } - - g_object_unref (client); - - return succ; -} - -static void -file_monitor_changed_cb (GFileMonitor *monitor, - GFile *file, - GFile *other_file, - GFileMonitorEvent event, - MsdSoundManager *manager) -{ - g_debug ("Theme dir changed"); - trigger_flush (manager); -} - -static gboolean -register_directory_callback (MsdSoundManager *manager, - const char *path, - GError **error) -{ - GFile *f; - GFileMonitor *m; - gboolean succ = FALSE; - - g_debug ("Registering directory monitor for %s", path); - - f = g_file_new_for_path (path); - - m = g_file_monitor_directory (f, 0, NULL, error); - - if (m != NULL) { - g_signal_connect (m, "changed", G_CALLBACK (file_monitor_changed_cb), manager); - - manager->priv->monitors = g_list_prepend (manager->priv->monitors, m); - - succ = TRUE; - } - - g_object_unref (f); - - return succ; -} - -#endif - -gboolean -msd_sound_manager_start (MsdSoundManager *manager, - GError **error) -{ - -#ifdef HAVE_PULSE - char *p, **ps, **k; - const char *env, *dd; -#endif - - g_debug ("Starting sound manager"); - mate_settings_profile_start (NULL); - -#ifdef HAVE_PULSE - - /* We listen for change of the selected theme ... */ - register_config_callback (manager, NULL); - - /* ... and we listen to changes of the theme base directories - * in $HOME ...*/ - - if ((env = g_getenv ("XDG_DATA_HOME")) && *env == '/') - p = g_build_filename (env, "sounds", NULL); - else if (((env = g_getenv ("HOME")) && *env == '/') || (env = g_get_home_dir ())) - p = g_build_filename (env, ".local", "share", "sounds", NULL); - else - p = NULL; - - if (p) { - register_directory_callback (manager, p, NULL); - g_free (p); - } - - /* ... and globally. */ - if (!(dd = g_getenv ("XDG_DATA_DIRS")) || *dd == 0) - dd = "/usr/local/share:/usr/share"; - - ps = g_strsplit (dd, ":", 0); - - for (k = ps; *k; ++k) - register_directory_callback (manager, *k, NULL); - - g_strfreev (ps); -#endif - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_sound_manager_stop (MsdSoundManager *manager) -{ - g_debug ("Stopping sound manager"); - -#ifdef HAVE_PULSE - if (manager->priv->mateconf_notify != 0) { - MateConfClient *client = mateconf_client_get_default (); - - mateconf_client_remove_dir (client, MATECONF_SOUND_DIR, NULL); - - mateconf_client_notify_remove (client, manager->priv->mateconf_notify); - manager->priv->mateconf_notify = 0; - - g_object_unref (client); - } - - if (manager->priv->timeout) { - g_source_remove (manager->priv->timeout); - manager->priv->timeout = 0; - } - - while (manager->priv->monitors) { - g_file_monitor_cancel (G_FILE_MONITOR (manager->priv->monitors->data)); - g_object_unref (manager->priv->monitors->data); - manager->priv->monitors = g_list_delete_link (manager->priv->monitors, manager->priv->monitors); - } -#endif -} - -static GObject * -msd_sound_manager_constructor ( - GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdSoundManager *m; - MsdSoundManagerClass *klass; - - klass = MSD_SOUND_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_SOUND_MANAGER)); - - m = MSD_SOUND_MANAGER (G_OBJECT_CLASS (msd_sound_manager_parent_class)->constructor ( - type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (m); -} - -static void -msd_sound_manager_dispose (GObject *object) -{ - MsdSoundManager *manager; - - manager = MSD_SOUND_MANAGER (object); - - msd_sound_manager_stop (manager); - - G_OBJECT_CLASS (msd_sound_manager_parent_class)->dispose (object); -} - -static void -msd_sound_manager_class_init (MsdSoundManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->constructor = msd_sound_manager_constructor; - object_class->dispose = msd_sound_manager_dispose; - object_class->finalize = msd_sound_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdSoundManagerPrivate)); -} - -static void -msd_sound_manager_init (MsdSoundManager *manager) -{ - manager->priv = MSD_SOUND_MANAGER_GET_PRIVATE (manager); -} - -static void -msd_sound_manager_finalize (GObject *object) -{ - MsdSoundManager *sound_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_SOUND_MANAGER (object)); - - sound_manager = MSD_SOUND_MANAGER (object); - - g_return_if_fail (sound_manager->priv); - - G_OBJECT_CLASS (msd_sound_manager_parent_class)->finalize (object); -} - -MsdSoundManager * -msd_sound_manager_new (void) -{ - if (manager_object) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_SOUND_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); - } - - return MSD_SOUND_MANAGER (manager_object); -} diff --git a/plugins/sound/gsd-sound-manager.h b/plugins/sound/gsd-sound-manager.h deleted file mode 100644 index ee4f6f5..0000000 --- a/plugins/sound/gsd-sound-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Lennart Poettering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_SOUND_MANAGER_H -#define __MSD_SOUND_MANAGER_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_SOUND_MANAGER (msd_sound_manager_get_type ()) -#define MSD_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManager)) -#define MSD_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) -#define MSD_IS_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_MANAGER)) -#define MSD_IS_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_MANAGER)) -#define MSD_SOUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) - -typedef struct MsdSoundManagerPrivate MsdSoundManagerPrivate; - -typedef struct -{ - GObject parent; - MsdSoundManagerPrivate *priv; -} MsdSoundManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdSoundManagerClass; - -GType msd_sound_manager_get_type (void) G_GNUC_CONST; - -MsdSoundManager *msd_sound_manager_new (void); -gboolean msd_sound_manager_start (MsdSoundManager *manager, GError **error); -void msd_sound_manager_stop (MsdSoundManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_SOUND_MANAGER_H */ diff --git a/plugins/sound/gsd-sound-plugin.c b/plugins/sound/gsd-sound-plugin.c deleted file mode 100644 index 28a2c85..0000000 --- a/plugins/sound/gsd-sound-plugin.c +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Lennart Poettering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-sound-plugin.h" -#include "msd-sound-manager.h" - -struct MsdSoundPluginPrivate { - MsdSoundManager *manager; -}; - -#define MSD_SOUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdSoundPlugin, msd_sound_plugin) - -static void -msd_sound_plugin_init (MsdSoundPlugin *plugin) -{ - plugin->priv = MSD_SOUND_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdSoundPlugin initializing"); - - plugin->priv->manager = msd_sound_manager_new (); -} - -static void -msd_sound_plugin_finalize (GObject *object) -{ - MsdSoundPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_SOUND_PLUGIN (object)); - - g_debug ("MsdSoundPlugin finalizing"); - - plugin = MSD_SOUND_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) - g_object_unref (plugin->priv->manager); - - G_OBJECT_CLASS (msd_sound_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - GError *error = NULL; - - g_debug ("Activating sound plugin"); - - if (!msd_sound_manager_start (MSD_SOUND_PLUGIN (plugin)->priv->manager, &error)) { - g_warning ("Unable to start sound manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating sound plugin"); - msd_sound_manager_stop (MSD_SOUND_PLUGIN (plugin)->priv->manager); -} - -static void -msd_sound_plugin_class_init (MsdSoundPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_sound_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdSoundPluginPrivate)); -} diff --git a/plugins/sound/gsd-sound-plugin.h b/plugins/sound/gsd-sound-plugin.h deleted file mode 100644 index b1dac8a..0000000 --- a/plugins/sound/gsd-sound-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Lennart Poettering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_SOUND_PLUGIN_H__ -#define __MSD_SOUND_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_SOUND_PLUGIN (msd_sound_plugin_get_type ()) -#define MSD_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPlugin)) -#define MSD_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) -#define MSD_IS_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_PLUGIN)) -#define MSD_IS_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_PLUGIN)) -#define MSD_SOUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) - -typedef struct MsdSoundPluginPrivate MsdSoundPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdSoundPluginPrivate *priv; -} MsdSoundPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdSoundPluginClass; - -GType msd_sound_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_SOUND_PLUGIN_H__ */ diff --git a/plugins/sound/msd-sound-manager.c b/plugins/sound/msd-sound-manager.c new file mode 100644 index 0000000..23fb240 --- /dev/null +++ b/plugins/sound/msd-sound-manager.c @@ -0,0 +1,433 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Lennart Poettering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#ifdef HAVE_PULSE +#include +#endif + +#include "msd-sound-manager.h" +#include "mate-settings-profile.h" + +#define MSD_SOUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerPrivate)) + +struct MsdSoundManagerPrivate +{ + guint mateconf_notify; + GList* monitors; + guint timeout; +}; + +#define MATECONF_SOUND_DIR "/desktop/mate/sound" + +static void msd_sound_manager_class_init (MsdSoundManagerClass *klass); +static void msd_sound_manager_init (MsdSoundManager *sound_manager); +static void msd_sound_manager_finalize (GObject *object); + +G_DEFINE_TYPE (MsdSoundManager, msd_sound_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +#ifdef HAVE_PULSE + +static void +sample_info_cb (pa_context *c, const pa_sample_info *i, int eol, void *userdata) +{ + pa_operation *o; + + if (!i) + return; + + g_debug ("Found sample %s", i->name); + + /* We only flush those samples which have an XDG sound name + * attached, because only those originate from themeing */ + if (!(pa_proplist_gets (i->proplist, PA_PROP_EVENT_ID))) + return; + + g_debug ("Dropping sample %s from cache", i->name); + + if (!(o = pa_context_remove_sample (c, i->name, NULL, NULL))) { + g_debug ("pa_context_remove_sample (): %s", pa_strerror (pa_context_errno (c))); + return; + } + + pa_operation_unref (o); + + /* We won't wait until the operation is actually executed to + * speed things up a bit.*/ +} + +static void +flush_cache (void) +{ + pa_mainloop *ml = NULL; + pa_context *c = NULL; + pa_proplist *pl = NULL; + pa_operation *o = NULL; + + g_debug ("Flushing sample cache"); + + if (!(ml = pa_mainloop_new ())) { + g_debug ("Failed to allocate pa_mainloop"); + goto fail; + } + + if (!(pl = pa_proplist_new ())) { + g_debug ("Failed to allocate pa_proplist"); + goto fail; + } + + pa_proplist_sets (pl, PA_PROP_APPLICATION_NAME, PACKAGE_NAME); + pa_proplist_sets (pl, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION); + pa_proplist_sets (pl, PA_PROP_APPLICATION_ID, "org.mate.SettingsDaemon"); + + if (!(c = pa_context_new_with_proplist (pa_mainloop_get_api (ml), PACKAGE_NAME, pl))) { + g_debug ("Failed to allocate pa_context"); + goto fail; + } + + pa_proplist_free (pl); + pl = NULL; + + if (pa_context_connect (c, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) { + g_debug ("pa_context_connect(): %s", pa_strerror (pa_context_errno (c))); + goto fail; + } + + /* Wait until the connection is established */ + while (pa_context_get_state (c) != PA_CONTEXT_READY) { + + if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { + g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); + goto fail; + } + + if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { + g_debug ("pa_mainloop_iterate() failed"); + goto fail; + } + } + + /* Enumerate all cached samples */ + if (!(o = pa_context_get_sample_info_list (c, sample_info_cb, NULL))) { + g_debug ("pa_context_get_sample_info_list(): %s", pa_strerror (pa_context_errno (c))); + goto fail; + } + + /* Wait until our operation is finished and there's nothing + * more queued to send to the server */ + while (pa_operation_get_state (o) == PA_OPERATION_RUNNING || pa_context_is_pending (c)) { + + if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { + g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); + goto fail; + } + + if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { + g_debug ("pa_mainloop_iterate() failed"); + goto fail; + } + } + + g_debug ("Sample cache flushed"); + +fail: + if (o) { + pa_operation_cancel (o); + pa_operation_unref (o); + } + + if (c) { + pa_context_disconnect (c); + pa_context_unref (c); + } + + if (pl) + pa_proplist_free (pl); + + if (ml) + pa_mainloop_free (ml); +} + +static gboolean +flush_cb (MsdSoundManager *manager) +{ + flush_cache (); + manager->priv->timeout = 0; + return FALSE; +} + +static void +trigger_flush (MsdSoundManager *manager) +{ + + if (manager->priv->timeout) + g_source_remove (manager->priv->timeout); + + /* We delay the flushing a bit so that we can coalesce + * multiple changes into a single cache flush */ + manager->priv->timeout = g_timeout_add (500, (GSourceFunc) flush_cb, manager); +} + +static void +mateconf_client_notify_cb (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdSoundManager *manager) +{ + trigger_flush (manager); +} + +static gboolean +register_config_callback (MsdSoundManager *manager, GError **error) +{ + MateConfClient *client; + gboolean succ; + + client = mateconf_client_get_default (); + + mateconf_client_add_dir (client, MATECONF_SOUND_DIR, MATECONF_CLIENT_PRELOAD_NONE, error); + succ = !error || !*error; + + if (!error) { + manager->priv->mateconf_notify = mateconf_client_notify_add (client, MATECONF_SOUND_DIR, (MateConfClientNotifyFunc) mateconf_client_notify_cb, manager, NULL, error); + succ = !error || !*error; + } + + g_object_unref (client); + + return succ; +} + +static void +file_monitor_changed_cb (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event, + MsdSoundManager *manager) +{ + g_debug ("Theme dir changed"); + trigger_flush (manager); +} + +static gboolean +register_directory_callback (MsdSoundManager *manager, + const char *path, + GError **error) +{ + GFile *f; + GFileMonitor *m; + gboolean succ = FALSE; + + g_debug ("Registering directory monitor for %s", path); + + f = g_file_new_for_path (path); + + m = g_file_monitor_directory (f, 0, NULL, error); + + if (m != NULL) { + g_signal_connect (m, "changed", G_CALLBACK (file_monitor_changed_cb), manager); + + manager->priv->monitors = g_list_prepend (manager->priv->monitors, m); + + succ = TRUE; + } + + g_object_unref (f); + + return succ; +} + +#endif + +gboolean +msd_sound_manager_start (MsdSoundManager *manager, + GError **error) +{ + +#ifdef HAVE_PULSE + char *p, **ps, **k; + const char *env, *dd; +#endif + + g_debug ("Starting sound manager"); + mate_settings_profile_start (NULL); + +#ifdef HAVE_PULSE + + /* We listen for change of the selected theme ... */ + register_config_callback (manager, NULL); + + /* ... and we listen to changes of the theme base directories + * in $HOME ...*/ + + if ((env = g_getenv ("XDG_DATA_HOME")) && *env == '/') + p = g_build_filename (env, "sounds", NULL); + else if (((env = g_getenv ("HOME")) && *env == '/') || (env = g_get_home_dir ())) + p = g_build_filename (env, ".local", "share", "sounds", NULL); + else + p = NULL; + + if (p) { + register_directory_callback (manager, p, NULL); + g_free (p); + } + + /* ... and globally. */ + if (!(dd = g_getenv ("XDG_DATA_DIRS")) || *dd == 0) + dd = "/usr/local/share:/usr/share"; + + ps = g_strsplit (dd, ":", 0); + + for (k = ps; *k; ++k) + register_directory_callback (manager, *k, NULL); + + g_strfreev (ps); +#endif + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_sound_manager_stop (MsdSoundManager *manager) +{ + g_debug ("Stopping sound manager"); + +#ifdef HAVE_PULSE + if (manager->priv->mateconf_notify != 0) { + MateConfClient *client = mateconf_client_get_default (); + + mateconf_client_remove_dir (client, MATECONF_SOUND_DIR, NULL); + + mateconf_client_notify_remove (client, manager->priv->mateconf_notify); + manager->priv->mateconf_notify = 0; + + g_object_unref (client); + } + + if (manager->priv->timeout) { + g_source_remove (manager->priv->timeout); + manager->priv->timeout = 0; + } + + while (manager->priv->monitors) { + g_file_monitor_cancel (G_FILE_MONITOR (manager->priv->monitors->data)); + g_object_unref (manager->priv->monitors->data); + manager->priv->monitors = g_list_delete_link (manager->priv->monitors, manager->priv->monitors); + } +#endif +} + +static GObject * +msd_sound_manager_constructor ( + GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdSoundManager *m; + MsdSoundManagerClass *klass; + + klass = MSD_SOUND_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_SOUND_MANAGER)); + + m = MSD_SOUND_MANAGER (G_OBJECT_CLASS (msd_sound_manager_parent_class)->constructor ( + type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (m); +} + +static void +msd_sound_manager_dispose (GObject *object) +{ + MsdSoundManager *manager; + + manager = MSD_SOUND_MANAGER (object); + + msd_sound_manager_stop (manager); + + G_OBJECT_CLASS (msd_sound_manager_parent_class)->dispose (object); +} + +static void +msd_sound_manager_class_init (MsdSoundManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructor = msd_sound_manager_constructor; + object_class->dispose = msd_sound_manager_dispose; + object_class->finalize = msd_sound_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdSoundManagerPrivate)); +} + +static void +msd_sound_manager_init (MsdSoundManager *manager) +{ + manager->priv = MSD_SOUND_MANAGER_GET_PRIVATE (manager); +} + +static void +msd_sound_manager_finalize (GObject *object) +{ + MsdSoundManager *sound_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_SOUND_MANAGER (object)); + + sound_manager = MSD_SOUND_MANAGER (object); + + g_return_if_fail (sound_manager->priv); + + G_OBJECT_CLASS (msd_sound_manager_parent_class)->finalize (object); +} + +MsdSoundManager * +msd_sound_manager_new (void) +{ + if (manager_object) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_SOUND_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); + } + + return MSD_SOUND_MANAGER (manager_object); +} diff --git a/plugins/sound/msd-sound-manager.h b/plugins/sound/msd-sound-manager.h new file mode 100644 index 0000000..ee4f6f5 --- /dev/null +++ b/plugins/sound/msd-sound-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Lennart Poettering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_SOUND_MANAGER_H +#define __MSD_SOUND_MANAGER_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_SOUND_MANAGER (msd_sound_manager_get_type ()) +#define MSD_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManager)) +#define MSD_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) +#define MSD_IS_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_MANAGER)) +#define MSD_IS_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_MANAGER)) +#define MSD_SOUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) + +typedef struct MsdSoundManagerPrivate MsdSoundManagerPrivate; + +typedef struct +{ + GObject parent; + MsdSoundManagerPrivate *priv; +} MsdSoundManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdSoundManagerClass; + +GType msd_sound_manager_get_type (void) G_GNUC_CONST; + +MsdSoundManager *msd_sound_manager_new (void); +gboolean msd_sound_manager_start (MsdSoundManager *manager, GError **error); +void msd_sound_manager_stop (MsdSoundManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_SOUND_MANAGER_H */ diff --git a/plugins/sound/msd-sound-plugin.c b/plugins/sound/msd-sound-plugin.c new file mode 100644 index 0000000..28a2c85 --- /dev/null +++ b/plugins/sound/msd-sound-plugin.c @@ -0,0 +1,100 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Lennart Poettering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-sound-plugin.h" +#include "msd-sound-manager.h" + +struct MsdSoundPluginPrivate { + MsdSoundManager *manager; +}; + +#define MSD_SOUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdSoundPlugin, msd_sound_plugin) + +static void +msd_sound_plugin_init (MsdSoundPlugin *plugin) +{ + plugin->priv = MSD_SOUND_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdSoundPlugin initializing"); + + plugin->priv->manager = msd_sound_manager_new (); +} + +static void +msd_sound_plugin_finalize (GObject *object) +{ + MsdSoundPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_SOUND_PLUGIN (object)); + + g_debug ("MsdSoundPlugin finalizing"); + + plugin = MSD_SOUND_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) + g_object_unref (plugin->priv->manager); + + G_OBJECT_CLASS (msd_sound_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + GError *error = NULL; + + g_debug ("Activating sound plugin"); + + if (!msd_sound_manager_start (MSD_SOUND_PLUGIN (plugin)->priv->manager, &error)) { + g_warning ("Unable to start sound manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating sound plugin"); + msd_sound_manager_stop (MSD_SOUND_PLUGIN (plugin)->priv->manager); +} + +static void +msd_sound_plugin_class_init (MsdSoundPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_sound_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdSoundPluginPrivate)); +} diff --git a/plugins/sound/msd-sound-plugin.h b/plugins/sound/msd-sound-plugin.h new file mode 100644 index 0000000..b1dac8a --- /dev/null +++ b/plugins/sound/msd-sound-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Lennart Poettering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_SOUND_PLUGIN_H__ +#define __MSD_SOUND_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_SOUND_PLUGIN (msd_sound_plugin_get_type ()) +#define MSD_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPlugin)) +#define MSD_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) +#define MSD_IS_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_PLUGIN)) +#define MSD_IS_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_PLUGIN)) +#define MSD_SOUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) + +typedef struct MsdSoundPluginPrivate MsdSoundPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdSoundPluginPrivate *priv; +} MsdSoundPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdSoundPluginClass; + +GType msd_sound_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_SOUND_PLUGIN_H__ */ -- cgit v1.2.1