summaryrefslogtreecommitdiff
path: root/src/totem-preferences-plugin-row.c
blob: f5fe8ad29396f8aba897cfa5752db195ed40599c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 *
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
 *
 * The Totem project hereby grant permission for non-GPL compatible GStreamer
 * plugins to be used and distributed together with GStreamer and Totem. This
 * permission are above and beyond the permissions granted by the GPL license
 * Totem is covered by.
 *
 * See license_change file for details.
 */

#include "totem-preferences-plugin-row.h"
#include "totem-plugins-engine.h"

struct _TotemPreferencesPluginRow {
	HdyExpanderRow      parent_instance;

	TotemPluginsEngine *plugins_engine;
	PeasPluginInfo     *plugin_info;

	GtkWidget          *plugin_switch;

	GtkWidget          *copyright;
	GtkWidget          *authors;
	GtkWidget          *version;
	GtkWidget          *website;

	gboolean            is_loaded;
};

enum {
	PROP_0,
	PROP_PLUGIN_INFO,
	N_PROPS
};

static GParamSpec *properties[N_PROPS];

G_DEFINE_FINAL_TYPE (TotemPreferencesPluginRow, totem_preferences_plugin_row, HDY_TYPE_EXPANDER_ROW)

static void
set_label_text (GtkLabel *label, const char *text)
{
	if (text != NULL)
		gtk_label_set_text (label, text);
	else
		gtk_widget_hide (GTK_WIDGET (label));

}

static void
totem_preferences_plugin_row_activate_plugin_cb (GtkWidget  *object,
						 GParamSpec *pspec,
						 gpointer    data)
{
	TotemPreferencesPluginRow *self = data;

	if (gtk_switch_get_active (GTK_SWITCH (object)))
		peas_engine_load_plugin (PEAS_ENGINE (self->plugins_engine), self->plugin_info);
	else
		peas_engine_unload_plugin (PEAS_ENGINE (self->plugins_engine), self->plugin_info);
}

static void
totem_preferences_plugin_display_plugin_info (TotemPreferencesPluginRow *self)
{
	g_autofree char *authors = NULL;
	const char  *plugin_copyright;
	const char **plugin_authors;
	const char  *plugin_version;
	const char  *plugin_website;

	plugin_copyright = peas_plugin_info_get_copyright (self->plugin_info);
	set_label_text (GTK_LABEL (self->copyright), plugin_copyright);

	plugin_authors = peas_plugin_info_get_authors (self->plugin_info);
	if (plugin_authors != NULL)
		authors = g_strjoinv (", ", (char**)plugin_authors);
	set_label_text (GTK_LABEL (self->authors), authors);

	plugin_version = peas_plugin_info_get_version (self->plugin_info);
	set_label_text (GTK_LABEL (self->version), plugin_version);

	plugin_website = peas_plugin_info_get_website (self->plugin_info);
	if (plugin_website != NULL)
		gtk_link_button_set_uri (GTK_LINK_BUTTON (self->website), plugin_website);
	else
		gtk_widget_hide (self->website);

	self->is_loaded = peas_plugin_info_is_loaded (self->plugin_info);

	gtk_switch_set_active (GTK_SWITCH (self->plugin_switch), self->is_loaded);
}

static void
totem_preferences_plugin_row_get_property (GObject    *object,
					   guint       prop_id,
					   GValue     *value,
					   GParamSpec *pspec)
{
	TotemPreferencesPluginRow *self = TOTEM_PREFERENCES_PLUGIN_ROW (object);

	switch (prop_id)
	{
	case PROP_PLUGIN_INFO:
		g_value_set_boxed (value, self->plugin_info);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
	}
}

static void
totem_preferences_plugin_row_set_property (GObject      *object,
					   guint         prop_id,
					   const GValue *value,
					   GParamSpec   *pspec)
{
	TotemPreferencesPluginRow *self = TOTEM_PREFERENCES_PLUGIN_ROW (object);

	switch (prop_id)
	{
	case PROP_PLUGIN_INFO:
		self->plugin_info = g_value_get_boxed (value);
		totem_preferences_plugin_display_plugin_info (self);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
	}
}

static void
totem_preferences_plugin_row_dispose (GObject *object)
{
	TotemPreferencesPluginRow *self = TOTEM_PREFERENCES_PLUGIN_ROW (object);

	g_clear_object (&self->plugins_engine);

	G_OBJECT_CLASS (totem_preferences_plugin_row_parent_class)->dispose (object);
}

static void
totem_preferences_plugin_row_class_init (TotemPreferencesPluginRowClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

	object_class->get_property = totem_preferences_plugin_row_get_property;
	object_class->set_property = totem_preferences_plugin_row_set_property;
	object_class->dispose = totem_preferences_plugin_row_dispose;

	properties[PROP_PLUGIN_INFO] = g_param_spec_boxed ("plugin-info",
							   "Plugin Info",
							   "",
							   PEAS_TYPE_PLUGIN_INFO,
							   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);

	g_object_class_install_properties (object_class, N_PROPS, properties);

	gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/totem/ui/totem-preferences-plugin-row.ui");

	gtk_widget_class_bind_template_child (widget_class, TotemPreferencesPluginRow, plugin_switch);
	gtk_widget_class_bind_template_child (widget_class, TotemPreferencesPluginRow, copyright);
	gtk_widget_class_bind_template_child (widget_class, TotemPreferencesPluginRow, authors);
	gtk_widget_class_bind_template_child (widget_class, TotemPreferencesPluginRow, version);
	gtk_widget_class_bind_template_child (widget_class, TotemPreferencesPluginRow, website);

	gtk_widget_class_bind_template_callback (widget_class, totem_preferences_plugin_row_activate_plugin_cb);
}

static void
totem_preferences_plugin_row_init (TotemPreferencesPluginRow *self)
{
	gtk_widget_init_template (GTK_WIDGET (self));

	self->plugins_engine = totem_plugins_engine_get_default (NULL);
}

GtkWidget *
totem_preferences_plugin_row_new (PeasPluginInfo *plugin_info)
{
	return g_object_new (TOTEM_TYPE_PREFERENCES_PLUGIN_ROW,
			     "plugin-info", plugin_info,
			     NULL);
}