hythmbox-2.98/plugins/iradio/rb-iradio-plugin.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  * rb-iradio-plugin.c
  4  *
  5  * Copyright (C) 2006  Jonathan Matthew
  6  *
  7  * This program is free software; you can redistribute it and/or modify
  8  * it under the terms of the GNU General Public License as published by
  9  * the Free Software Foundation; either version 2, or (at your option)
 10  * any later version.
 11  *
 12  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 13  *  GStreamer plugins to be used and distributed together with GStreamer
 14  *  and Rhythmbox. This permission is above and beyond the permissions granted
 15  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 16  *  you may extend this exception to your version of the code, but you are not
 17  *  obligated to do so. If you do not wish to do so, delete this exception
 18  *  statement from your version.
 19  *
 20  * This program is distributed in the hope that it will be useful,
 21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 23  * GNU General Public License for more details.
 24  *
 25  * You should have received a copy of the GNU General Public License
 26  * along with this program; if not, write to the Free Software
 27  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 28  */
 29 
 30 #ifdef HAVE_CONFIG_H
 31 #include <config.h>
 32 #endif
 33 
 34 #include <string.h>
 35 #include <glib/gi18n-lib.h>
 36 #include <gmodule.h>
 37 #include <gtk/gtk.h>
 38 #include <glib.h>
 39 #include <glib-object.h>
 40 
 41 #include "rb-plugin-macros.h"
 42 #include "rb-debug.h"
 43 #include "rb-shell.h"
 44 #include "rb-dialog.h"
 45 #include "rb-iradio-source.h"
 46 #include "rb-iradio-source-search.h"
 47 #include "rb-station-properties-dialog.h"
 48 #include "rb-file-helpers.h"
 49 #include "rb-display-page-group.h"
 50 
 51 
 52 #define RB_TYPE_IRADIO_PLUGIN		(rb_iradio_plugin_get_type ())
 53 #define RB_IRADIO_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_IRADIO_PLUGIN, RBIRadioPlugin))
 54 #define RB_IRADIO_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), RB_TYPE_IRADIO_PLUGIN, RBIRadioPluginClass))
 55 #define RB_IS_IRADIO_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), RB_TYPE_IRADIO_PLUGIN))
 56 #define RB_IS_IRADIO_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), RB_TYPE_IRADIO_PLUGIN))
 57 #define RB_IRADIO_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), RB_TYPE_IRADIO_PLUGIN, RBIRadioPluginClass))
 58 
 59 typedef struct
 60 {
 61 	PeasExtensionBase parent;
 62 
 63 	RBSource *source;
 64 	guint ui_merge_id;
 65 } RBIRadioPlugin;
 66 
 67 typedef struct
 68 {
 69 	PeasExtensionBaseClass parent_class;
 70 } RBIRadioPluginClass;
 71 
 72 
 73 G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
 74 
 75 RB_DEFINE_PLUGIN(RB_TYPE_IRADIO_PLUGIN, RBIRadioPlugin, rb_iradio_plugin,)
 76 
 77 static void
 78 rb_iradio_plugin_init (RBIRadioPlugin *plugin)
 79 {
 80 	rb_debug ("RBIRadioPlugin initialising");
 81 }
 82 
 83 static void
 84 impl_activate (PeasActivatable *plugin)
 85 {
 86 	RBIRadioPlugin *pi = RB_IRADIO_PLUGIN (plugin);
 87 	GtkUIManager *uimanager;
 88 	char *filename;
 89 	RBShell *shell;
 90 
 91 	g_object_get (pi, "object", &shell, NULL);
 92 	pi->source = rb_iradio_source_new (shell, G_OBJECT (plugin));
 93 	rb_shell_append_display_page (shell, RB_DISPLAY_PAGE (pi->source), RB_DISPLAY_PAGE_GROUP_LIBRARY);
 94 
 95 	g_object_get (shell, "ui-manager", &uimanager, NULL);
 96 	filename = rb_find_plugin_data_file (G_OBJECT (plugin), "iradio-ui.xml");
 97 	if (filename != NULL) {
 98 		pi->ui_merge_id = gtk_ui_manager_add_ui_from_file (uimanager,
 99                                                              filename,
100                                                              NULL);
101 	} else {
102 		g_warning ("Unable to find file: iradio-ui.xml");
103 	}
104 
105 	g_free (filename);
106 	g_object_unref (uimanager);
107 	g_object_unref (shell);
108 }
109 
110 static void
111 impl_deactivate	(PeasActivatable *plugin)
112 {
113 	RBIRadioPlugin *pi = RB_IRADIO_PLUGIN (plugin);
114 	GtkUIManager *uimanager;
115 	RBShell *shell;
116 
117 	g_object_get (pi, "object", &shell, NULL);
118 
119 	g_object_get (shell, "ui-manager", &uimanager, NULL);
120 	gtk_ui_manager_remove_ui (uimanager, pi->ui_merge_id);
121 	g_object_unref (uimanager);
122 
123 	rb_display_page_delete_thyself (RB_DISPLAY_PAGE (pi->source));
124 	pi->source = NULL;
125 
126 	g_object_unref (shell);
127 }
128 
129 G_MODULE_EXPORT void
130 peas_register_types (PeasObjectModule *module)
131 {
132 	rb_iradio_plugin_register_type (G_TYPE_MODULE (module));
133 	_rb_iradio_source_register_type (G_TYPE_MODULE (module));
134 	_rb_iradio_source_search_register_type (G_TYPE_MODULE (module));
135 	_rb_station_properties_dialog_register_type (G_TYPE_MODULE (module));
136 	peas_object_module_register_extension_type (module,
137 						    PEAS_TYPE_ACTIVATABLE,
138 						    RB_TYPE_IRADIO_PLUGIN);
139 }