Updated Finnish translation
[rhythmbox.git] / plugins / iradio / rb-iradio-plugin.c
blob74ac33e3d597ffb70b2aa8bb8e13d3482d2070ca
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * rb-iradio-plugin.c
5 * Copyright (C) 2006 Jonathan Matthew
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.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #include <string.h>
27 #include <glib/gi18n-lib.h>
28 #include <gmodule.h>
29 #include <gtk/gtk.h>
30 #include <glib.h>
31 #include <glib-object.h>
33 #include "rb-plugin.h"
34 #include "rb-debug.h"
35 #include "rb-shell.h"
36 #include "rb-dialog.h"
37 #include "rb-iradio-source.h"
38 #include "rb-file-helpers.h"
41 #define RB_TYPE_IRADIO_PLUGIN (rb_iradio_plugin_get_type ())
42 #define RB_IRADIO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_IRADIO_PLUGIN, RBIRadioPlugin))
43 #define RB_IRADIO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), RB_TYPE_IRADIO_PLUGIN, RBIRadioPluginClass))
44 #define RB_IS_IRADIO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), RB_TYPE_IRADIO_PLUGIN))
45 #define RB_IS_IRADIO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), RB_TYPE_IRADIO_PLUGIN))
46 #define RB_IRADIO_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), RB_TYPE_IRADIO_PLUGIN, RBIRadioPluginClass))
48 typedef struct
50 RBPlugin parent;
51 RBSource *source;
52 guint ui_merge_id;
53 } RBIRadioPlugin;
55 typedef struct
57 RBPluginClass parent_class;
58 } RBIRadioPluginClass;
61 G_MODULE_EXPORT GType register_rb_plugin (GTypeModule *module);
62 GType rb_iradio_plugin_get_type (void) G_GNUC_CONST;
65 static void impl_activate (RBPlugin *plugin, RBShell *shell);
66 static void impl_deactivate (RBPlugin *plugin, RBShell *shell);
68 RB_PLUGIN_REGISTER(RBIRadioPlugin, rb_iradio_plugin)
70 static void
71 rb_iradio_plugin_init (RBIRadioPlugin *plugin)
73 rb_debug ("RBIRadioPlugin initialising");
76 static void
77 rb_iradio_plugin_finalize (GObject *object)
80 RBIRadioPlugin *plugin = RB_IRADIO_PLUGIN (object);
82 rb_debug ("RBIRadioPlugin finalising");
84 G_OBJECT_CLASS (rb_iradio_plugin_parent_class)->finalize (object);
89 static void
90 impl_activate (RBPlugin *plugin,
91 RBShell *shell)
93 RBIRadioPlugin *pi = RB_IRADIO_PLUGIN (plugin);
94 GtkUIManager *uimanager;
95 char *filename;
97 pi->source = rb_iradio_source_new (shell);
98 rb_shell_append_source (shell, pi->source, NULL);
100 g_object_get (shell, "ui-manager", &uimanager, NULL);
101 filename = rb_plugin_find_file (plugin, "iradio-ui.xml");
102 if (filename != NULL) {
103 pi->ui_merge_id = gtk_ui_manager_add_ui_from_file (uimanager,
104 filename,
105 NULL);
106 } else {
107 g_warning ("Unable to find file: iradio-ui.xml");
110 g_free (filename);
111 g_object_unref (uimanager);
114 static void
115 impl_deactivate (RBPlugin *plugin,
116 RBShell *shell)
118 RBIRadioPlugin *pi = RB_IRADIO_PLUGIN (plugin);
119 GtkUIManager *uimanager;
121 g_object_get (shell, "ui-manager", &uimanager, NULL);
122 gtk_ui_manager_remove_ui (uimanager, pi->ui_merge_id);
123 g_object_unref (uimanager);
125 rb_source_delete_thyself (pi->source);
126 pi->source = NULL;
130 static void
131 rb_iradio_plugin_class_init (RBIRadioPluginClass *klass)
133 GObjectClass *object_class = G_OBJECT_CLASS (klass);
134 RBPluginClass *plugin_class = RB_PLUGIN_CLASS (klass);
136 object_class->finalize = rb_iradio_plugin_finalize;
138 plugin_class->activate = impl_activate;
139 plugin_class->deactivate = impl_deactivate;