hythmbox-2.98/plugins/fmradio/rb-fm-radio-plugin.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  Copyright (C) 2007  James Henstridge <james@jamesh.id.au>
  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 of the License, or
  8  *  (at your option) any later version.
  9  *
 10  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 11  *  GStreamer plugins to be used and distributed together with GStreamer
 12  *  and Rhythmbox. This permission is above and beyond the permissions granted
 13  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 14  *  you may extend this exception to your version of the code, but you are not
 15  *  obligated to do so. If you do not wish to do so, delete this exception
 16  *  statement from your version.
 17  *
 18  *  This program is distributed in the hope that it will be useful,
 19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21  *  GNU General Public License for more details.
 22  *
 23  *  You should have received a copy of the GNU General Public License
 24  *  along with this program; if not, write to the Free Software
 25  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 26  *
 27  */
 28 
 29 
 30 #include <config.h>
 31 
 32 #include <glib/gi18n-lib.h>
 33 
 34 #include "rb-debug.h"
 35 
 36 #include "rb-plugin-macros.h"
 37 #include "rb-fm-radio-source.h"
 38 #include "rb-radio-tuner.h"
 39 #include "rb-display-page-group.h"
 40 #include "rb-file-helpers.h"
 41 
 42 #define RB_TYPE_FM_RADIO_PLUGIN         (rb_fm_radio_plugin_get_type ())
 43 #define RB_FM_RADIO_PLUGIN(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_FM_RADIO_PLUGIN, RBFMRadioPlugin))
 44 #define RB_FM_RADIO_PLUGIN_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), RB_TYPE_FM_RADIO_PLUGIN, RBFMRadioPluginClass))
 45 #define RB_IS_FM_RADIO_PLUGIN(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), RB_TYPE_FM_RADIO_PLUGIN))
 46 #define RB_IS_FM_RADIO_PLUGIN_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), RB_TYPE_FM_RADIO_PLUGIN))
 47 #define RB_FM_RADIO_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), RB_TYPE_FM_RADIO_PLUGIN, RBFMRadioPluginClass))
 48 
 49 typedef struct _RBFMRadioPlugin RBFMRadioPlugin;
 50 typedef struct _RBFMRadioPluginClass RBFMRadioPluginClass;
 51 
 52 struct _RBFMRadioPlugin {
 53 	PeasExtensionBase parent;
 54 	RBSource *source;
 55 	guint ui_merge_id;
 56 };
 57 
 58 struct _RBFMRadioPluginClass {
 59 	PeasExtensionBaseClass parent_class;
 60 };
 61 
 62 G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
 63 GType rb_fm_radio_plugin_get_type (void) G_GNUC_CONST;
 64 
 65 RB_DEFINE_PLUGIN (RB_TYPE_FM_RADIO_PLUGIN, RBFMRadioPlugin, rb_fm_radio_plugin,)
 66 
 67 static void
 68 rb_fm_radio_plugin_init (RBFMRadioPlugin *plugin)
 69 {
 70 	rb_debug ("RBFMRadioPlugin initialising");
 71 }
 72 
 73 static void
 74 impl_activate (PeasActivatable *plugin)
 75 {
 76 	RBFMRadioPlugin *pi = RB_FM_RADIO_PLUGIN (plugin);
 77 	RBRadioTuner *tuner;
 78 	GtkUIManager *uimanager;
 79 	RBShell *shell;
 80 	char *filename;
 81 
 82 	tuner = rb_radio_tuner_new (NULL, NULL);
 83 	if (tuner == NULL)
 84 		return;
 85 
 86 	rb_radio_tuner_set_mute (tuner, TRUE);
 87 	rb_radio_tuner_update (tuner);
 88 
 89 	g_object_get (plugin, "object", &shell, NULL);
 90 	pi->source = rb_fm_radio_source_new (shell, tuner);
 91 	rb_shell_append_display_page (shell, RB_DISPLAY_PAGE (pi->source), RB_DISPLAY_PAGE_GROUP_LIBRARY);	/* devices? */
 92 
 93 	g_object_unref (tuner);
 94 
 95 	filename = rb_find_plugin_data_file (G_OBJECT (plugin), "fmradio-ui.xml");
 96 	if (filename != NULL) {
 97 		g_object_get (shell, "ui-manager", &uimanager, NULL);
 98 		pi->ui_merge_id = gtk_ui_manager_add_ui_from_file (uimanager,
 99 								   filename,
100 								   NULL);
101 		g_object_unref (uimanager);
102 		g_free(filename);
103 	} else {
104 		g_warning ("Unable to find file: fmradio-ui.xml");
105 	}
106 
107 	g_object_unref (shell);
108 }
109 
110 static void
111 impl_deactivate (PeasActivatable *plugin)
112 {
113 	RBFMRadioPlugin *pi = RB_FM_RADIO_PLUGIN (plugin);
114 	GtkUIManager *uimanager;
115 	RBShell *shell;
116 
117 	if (pi->source) {
118 		rb_display_page_delete_thyself (RB_DISPLAY_PAGE (pi->source));
119 		pi->source = NULL;
120 	}
121 
122 	if (pi->ui_merge_id) {
123 		g_object_get (plugin, "object", &shell, NULL);
124 		g_object_get (shell, "ui-manager", &uimanager, NULL);
125 		g_object_unref (shell);
126 
127 		gtk_ui_manager_remove_ui (uimanager, pi->ui_merge_id);
128 		g_object_unref (uimanager);
129 		pi->ui_merge_id = 0;
130 	}
131 }
132 
133 G_MODULE_EXPORT void
134 peas_register_types (PeasObjectModule *module)
135 {
136 	rb_fm_radio_plugin_register_type (G_TYPE_MODULE (module));
137 	_rb_fm_radio_source_register_type (G_TYPE_MODULE (module));
138 	_rb_radio_tuner_register_type (G_TYPE_MODULE (module));
139 
140 	peas_object_module_register_extension_type (module,
141 						    PEAS_TYPE_ACTIVATABLE,
142 						    RB_TYPE_FM_RADIO_PLUGIN);
143 }