/plugins/background/gsd-background-plugin.c

https://github.com/lcp/gnome-settings-daemon · C · 110 lines · 65 code · 26 blank · 19 comment · 5 complexity · 326ea7c3be7d3dc3f9f8abc5edce1ab1 MD5 · raw file

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  2. *
  3. * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. *
  19. */
  20. #include "config.h"
  21. #include <glib/gi18n-lib.h>
  22. #include <gmodule.h>
  23. #include "gnome-settings-plugin.h"
  24. #include "gsd-background-plugin.h"
  25. #include "gsd-background-manager.h"
  26. struct GsdBackgroundPluginPrivate {
  27. GsdBackgroundManager *manager;
  28. };
  29. #define GSD_BACKGROUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_BACKGROUND_PLUGIN, GsdBackgroundPluginPrivate))
  30. GNOME_SETTINGS_PLUGIN_REGISTER (GsdBackgroundPlugin, gsd_background_plugin)
  31. static void
  32. gsd_background_plugin_init (GsdBackgroundPlugin *plugin)
  33. {
  34. plugin->priv = GSD_BACKGROUND_PLUGIN_GET_PRIVATE (plugin);
  35. g_debug ("GsdBackgroundPlugin initializing");
  36. plugin->priv->manager = gsd_background_manager_new ();
  37. }
  38. static void
  39. gsd_background_plugin_finalize (GObject *object)
  40. {
  41. GsdBackgroundPlugin *plugin;
  42. g_return_if_fail (object != NULL);
  43. g_return_if_fail (GSD_IS_BACKGROUND_PLUGIN (object));
  44. g_debug ("GsdBackgroundPlugin finalizing");
  45. plugin = GSD_BACKGROUND_PLUGIN (object);
  46. g_return_if_fail (plugin->priv != NULL);
  47. if (plugin->priv->manager != NULL) {
  48. g_object_unref (plugin->priv->manager);
  49. }
  50. G_OBJECT_CLASS (gsd_background_plugin_parent_class)->finalize (object);
  51. }
  52. static void
  53. impl_activate (GnomeSettingsPlugin *plugin)
  54. {
  55. gboolean res;
  56. GError *error;
  57. g_debug ("Activating background plugin");
  58. error = NULL;
  59. res = gsd_background_manager_start (GSD_BACKGROUND_PLUGIN (plugin)->priv->manager, &error);
  60. if (! res) {
  61. g_warning ("Unable to start background manager: %s", error->message);
  62. g_error_free (error);
  63. }
  64. }
  65. static void
  66. impl_deactivate (GnomeSettingsPlugin *plugin)
  67. {
  68. g_debug ("Deactivating background plugin");
  69. gsd_background_manager_stop (GSD_BACKGROUND_PLUGIN (plugin)->priv->manager);
  70. }
  71. static void
  72. gsd_background_plugin_class_init (GsdBackgroundPluginClass *klass)
  73. {
  74. GObjectClass *object_class = G_OBJECT_CLASS (klass);
  75. GnomeSettingsPluginClass *plugin_class = GNOME_SETTINGS_PLUGIN_CLASS (klass);
  76. object_class->finalize = gsd_background_plugin_finalize;
  77. plugin_class->activate = impl_activate;
  78. plugin_class->deactivate = impl_deactivate;
  79. g_type_class_add_private (klass, sizeof (GsdBackgroundPluginPrivate));
  80. }
  81. static void
  82. gsd_background_plugin_class_finalize (GsdBackgroundPluginClass *klass)
  83. {
  84. }