1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2011 Qball Cow <qball@sarine.nl>
3 * Project homepage: http://gmpc.wikia.com/
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "playlist3.h"
28 #define LOG_DOMAIN "Preferences"
29 #define PLUGIN_STATS -200
30 void preferences_show_pref_window(int plugin_id
);
31 static void plugin_stats_construct(GtkWidget
*);
32 static void plugin_stats_destroy(GtkWidget
*);
33 GtkBuilder
*plugin_stat_xml
= NULL
;
37 GtkListStore
*plugin_store
= NULL
;
38 GtkBuilder
*xml_preferences_window
= NULL
;
41 /* Glade Prototypes, without glade these would be static */
42 void preferences_window_connect(GtkWidget
* but
);
43 void preferences_window_disconnect(GtkWidget
* but
);
44 void auth_enable_toggled(GtkToggleButton
* but
);
45 void entry_auth_changed(GtkEntry
* entry
);
46 void create_preferences_window(void);
47 void preferences_window_destroy(void);
51 gboolean
preferences_window_expose_event_cb(GtkWidget
*widget
, GdkEventExpose
*event
, gpointer data
)
58 static void pref_plugin_changed(void)
60 GtkTreeSelection
*sel
=
61 gtk_tree_view_get_selection(GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window
, "plugin_tree")));
62 GtkTreeModel
*model
= GTK_TREE_MODEL(plugin_store
);
67 gmpc_plugin_preferences_destroy(plugins
[plugin_last
],
68 (GtkWidget
*) gtk_builder_get_object(xml_preferences_window
,
72 } else if (plugin_last
== PLUGIN_STATS
)
74 plugin_stats_destroy((GtkWidget
*) gtk_builder_get_object(xml_preferences_window
, "plugin_container"));
76 if (gtk_tree_selection_get_selected(sel
, &model
, &iter
))
78 gtk_tree_model_get(GTK_TREE_MODEL(plugin_store
), &iter
, 0, &id
, -1);
79 if (id
>= 0 && gmpc_plugin_has_preferences(plugins
[id
]))
82 const gchar
*translation_domain
= gmpc_plugin_get_translation_domain(plugins
[id
]);
83 if (!gmpc_plugin_is_internal(plugins
[id
]))
85 const int *version
= gmpc_plugin_get_version(plugins
[id
]);
88 buf
= g_strdup_printf("<span size=\"xx-large\"><b>%s</b></span>\n<i>%s: %i.%i.%i</i>",
89 #if defined(ENABLE_NLS) && GLIB_CHECK_VERSION(2,18,0)
90 g_dgettext(translation_domain
, gmpc_plugin_get_name(plugins
[id
])),
92 gmpc_plugin_get_name(plugins
[id
]),
94 _("Plugin version"), version
[0], version
[1], version
[2]);
96 buf
= g_strdup_printf("<span size=\"xx-large\"><b>%s</b></span>",
97 gmpc_plugin_get_name(plugins
[id
]));
101 buf
= g_strdup_printf("<span size=\"xx-large\"><b>%s</b></span>",
102 N_(gmpc_plugin_get_name(plugins
[id
])));
105 gmpc_plugin_preferences_construct(plugins
[id
],
106 (GtkWidget
*) gtk_builder_get_object(xml_preferences_window
,
107 "plugin_container"));
109 gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(xml_preferences_window
, "plugin_label")), buf
);
112 } else if (id
== PLUGIN_STATS
)
114 gchar
*value
= g_markup_printf_escaped("<span size=\"xx-large\" weight=\"bold\">%s</span>", _("Plugins"));
115 gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(xml_preferences_window
, "plugin_label")), value
);
118 plugin_stats_construct((GtkWidget
*) gtk_builder_get_object(xml_preferences_window
, "plugin_container"));
123 gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(xml_preferences_window
, "plugin_label")),
124 "<span size=\"xx-large\"><b>Nothing Selected</b></span>");
128 void create_preferences_window(void)
130 GError
*error
= NULL
;
131 GtkWidget
*pl3_win
= playlist3_get_window();
133 GtkCellRenderer
*renderer
;
134 GtkTreeViewColumn
*column
;
142 if (xml_preferences_window
== NULL
)
147 dialog
= (GtkWidget
*) gtk_builder_get_object(xml_preferences_window
, "preferences_window");
148 gtk_window_present(GTK_WINDOW(dialog
));
153 string
= gmpc_get_full_glade_path("preferences.ui");
154 xml_preferences_window
= gtk_builder_new();
155 gtk_builder_add_from_file(xml_preferences_window
, string
, &error
);
159 g_log(LOG_DOMAIN
, G_LOG_LEVEL_ERROR
, "Failed to load preferences.ui: %s", error
->message
);
162 /* set info from struct */
164 dialog
= (GtkWidget
*) gtk_builder_get_object(xml_preferences_window
, "preferences_window");
165 gtk_window_set_transient_for(GTK_WINDOW(dialog
), GTK_WINDOW(pl3_win
));
166 gtk_widget_show_all(GTK_WIDGET(dialog
));
169 plugin_store
= gtk_list_store_new(2, G_TYPE_INT
, G_TYPE_STRING
);
170 column
= gtk_tree_view_column_new();
171 gtk_tree_view_column_set_title(column
, _("Plugins:"));
172 renderer
= gtk_cell_renderer_text_new();
173 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
174 gtk_tree_view_column_set_attributes(column
, renderer
, "markup", 1, NULL
);
175 gtk_tree_view_append_column(GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window
, "plugin_tree")), column
);
177 g_signal_connect(G_OBJECT
178 (gtk_tree_view_get_selection
179 (GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window
, "plugin_tree")))), "changed",
180 G_CALLBACK(pref_plugin_changed
), NULL
);
181 gtk_tree_view_set_model(GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window
, "plugin_tree")),
182 GTK_TREE_MODEL(plugin_store
));
185 for (i
= 0; i
< num_plugins
; i
++)
187 if (gmpc_plugin_has_preferences(plugins
[i
]))
189 if (gmpc_plugin_is_internal(plugins
[i
]))
192 const gchar
*translation_domain
= gmpc_plugin_get_translation_domain(plugins
[i
]);
193 gtk_list_store_append(GTK_LIST_STORE(plugin_store
), &iter
);
194 gtk_list_store_set(GTK_LIST_STORE(plugin_store
), &iter
, 0, i
,
195 #if defined(ENABLE_NLS) && GLIB_CHECK_VERSION(2,18,0)
196 1, g_dgettext(translation_domain
, gmpc_plugin_get_name(plugins
[i
])),
198 1, gmpc_plugin_get_name(plugins
[i
]),
201 if (gtk_tree_selection_count_selected_rows
202 (gtk_tree_view_get_selection
203 (GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window
, "plugin_tree")))) == 0)
205 gtk_tree_selection_select_iter(gtk_tree_view_get_selection
207 (gtk_builder_get_object(xml_preferences_window
, "plugin_tree"))),
219 gchar
*value
= g_markup_printf_escaped("<b>%s:</b>", _("Plugins"));
221 gtk_list_store_append(GTK_LIST_STORE(plugin_store
), &iter
);
222 gtk_list_store_set(GTK_LIST_STORE(plugin_store
), &iter
, 0, PLUGIN_STATS
, 1, value
, -1);
224 for (i
= 0; i
< num_plugins
; i
++)
226 if (gmpc_plugin_has_preferences(plugins
[i
]) && !gmpc_plugin_is_internal(plugins
[i
])
227 && gmpc_plugin_get_enabled(plugins
[i
]))
229 const gchar
*translation_domain
= gmpc_plugin_get_translation_domain(plugins
[i
]);
230 gtk_list_store_append(GTK_LIST_STORE(plugin_store
), &iter
);
231 gtk_list_store_set(GTK_LIST_STORE(plugin_store
), &iter
, 0, i
,
232 #if defined(ENABLE_NLS) && GLIB_CHECK_VERSION(2,18,0)
233 1, g_dgettext(translation_domain
, gmpc_plugin_get_name(plugins
[i
])),
235 1, gmpc_plugin_get_name(plugins
[i
]),
243 GtkWidget
*widget
= (GtkWidget
*) gtk_builder_get_object(xml_preferences_window
,
244 "eventbox_background");
246 gtk_widget_modify_bg(widget
, GTK_STATE_NORMAL
, &(dialog
->style
->base
[GTK_STATE_NORMAL
]));
249 label
= (GtkWidget
*) gtk_builder_get_object(xml_preferences_window
, "plugin_label_box");
250 gtk_widget_set_app_paintable(label
, TRUE
);
251 g_signal_connect(G_OBJECT(label
), "expose-event", G_CALLBACK(misc_header_expose_event
), NULL
);
252 gtk_widget_set_state(GTK_WIDGET(label
), GTK_STATE_SELECTED
);
254 gtk_widget_show(dialog
);
255 gtk_builder_connect_signals(xml_preferences_window
, NULL
);
259 /* destory the preferences window */
260 G_MODULE_EXPORT
void preferences_window_destroy(void)
262 GtkWidget
*dialog
= (GtkWidget
*) gtk_builder_get_object(xml_preferences_window
, "preferences_window");
263 if (plugin_last
>= 0)
265 gmpc_plugin_preferences_destroy(plugins
[plugin_last
],
266 (GtkWidget
*) gtk_builder_get_object(xml_preferences_window
,
267 "plugin_container"));
270 } else if (plugin_last
== PLUGIN_STATS
)
272 plugin_stats_destroy((GtkWidget
*) gtk_builder_get_object(xml_preferences_window
, "plugin_container"));
274 gtk_widget_destroy(dialog
);
275 g_object_unref(xml_preferences_window
);
276 g_object_unref(plugin_store
);
278 xml_preferences_window
= NULL
;
283 static void pref_plugin_enabled(GtkCellRendererToggle
* rend
, gchar
* path
, GtkListStore
* store
)
286 if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store
), &iter
, path
))
289 gmpcPluginParent
*plug
= NULL
;
290 gtk_tree_model_get(GTK_TREE_MODEL(store
), &iter
, 0, &toggled
, 3, &plug
, -1);
292 gmpc_plugin_set_enabled(plug
, !toggled
);
293 gtk_list_store_set(store
, &iter
, 0, gmpc_plugin_get_enabled(plug
), -1);
294 if (gmpc_plugin_has_preferences(plug
))
298 const gchar
*translation_domain
= gmpc_plugin_get_translation_domain(plug
);
299 gtk_list_store_append(GTK_LIST_STORE(plugin_store
), &iter
);
300 gtk_list_store_set(GTK_LIST_STORE(plugin_store
), &iter
, 0, plugin_get_pos(gmpc_plugin_get_id(plug
)),
301 #if defined(ENABLE_NLS) && GLIB_CHECK_VERSION(2,18,0)
302 1, g_dgettext(translation_domain
, gmpc_plugin_get_name(plug
)),
304 1, gmpc_plugin_get_name(plug
),
310 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(plugin_store
), &piter
))
315 gtk_tree_model_get(GTK_TREE_MODEL(plugin_store
), &piter
, 0, &i
, -1);
316 if (i
== plugin_get_pos(gmpc_plugin_get_id(plug
)))
318 gtk_list_store_remove(plugin_store
, &piter
);
321 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(plugin_store
), &piter
));
330 static void plugin_stats_construct(GtkWidget
* container
)
332 gchar
*path
= gmpc_get_full_glade_path("preferences-plugins.ui");
333 plugin_stat_xml
= gtk_builder_new();
334 gtk_builder_add_from_file(plugin_stat_xml
, path
, NULL
);
338 GtkWidget
*tree
= (GtkWidget
*) gtk_builder_get_object(plugin_stat_xml
, "plugin_stats_tree");
339 GtkListStore
*store
= NULL
;
341 GtkCellRenderer
*renderer
= NULL
;
343 GtkWidget
*vbox
= (GtkWidget
*) gtk_builder_get_object(plugin_stat_xml
, "plugin_stats_vbox");
348 store
= gtk_list_store_new(5, G_TYPE_BOOLEAN
, G_TYPE_STRING
, G_TYPE_STRING
, G_TYPE_POINTER
, G_TYPE_STRING
);
350 gtk_tree_view_set_model(GTK_TREE_VIEW(tree
), GTK_TREE_MODEL(store
));
351 renderer
= gtk_cell_renderer_toggle_new();
352 g_object_set_data(G_OBJECT(renderer
), "editable", GINT_TO_POINTER(1));
353 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree
), -1, _("Enabled"), renderer
, "active", 0, NULL
);
354 g_signal_connect(G_OBJECT(renderer
), "toggled", G_CALLBACK(pref_plugin_enabled
), store
);
355 renderer
= gtk_cell_renderer_text_new();
356 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree
), -1, _("Name"), renderer
, "text", 1, NULL
);
357 renderer
= gtk_cell_renderer_text_new();
358 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree
), -1, _("Function"), renderer
, "text", 2, NULL
);
359 renderer
= gtk_cell_renderer_text_new();
360 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree
), -1, _("Version"), renderer
, "text", 4, NULL
);
361 for (i
= 0; i
< num_plugins
; i
++)
363 if (!gmpc_plugin_is_internal(plugins
[i
]))
365 const gchar
*translation_domain
= gmpc_plugin_get_translation_domain(plugins
[i
]);
366 const int *ver
= gmpc_plugin_get_version(plugins
[i
]);
367 gchar
*version
= (ver
) ? g_strdup_printf("%i.%i.%i", ver
[0], ver
[1], ver
[2]) : g_strdup("n/a");
368 gtk_list_store_append(store
, &iter
);
369 gtk_list_store_set(store
, &iter
, 0, TRUE
,
370 #if defined(ENABLE_NLS) && GLIB_CHECK_VERSION(2,18,0)
371 1, g_dgettext(translation_domain
, gmpc_plugin_get_name(plugins
[i
])),
373 1, gmpc_plugin_get_name(plugins
[i
]),
375 3, (plugins
[i
]), 4, version
, -1);
377 if (gmpc_plugin_get_enabled(plugins
[i
]))
379 gtk_list_store_set(store
, &iter
, 0, TRUE
, -1);
381 gtk_list_store_set(store
, &iter
, 0, FALSE
, -1);
382 switch (gmpc_plugin_get_type(plugins
[i
]))
384 case GMPC_PLUGIN_DUMMY
:
385 gtk_list_store_set(store
, &iter
, 2, _("Dummy"), -1);
387 case GMPC_PLUGIN_PL_BROWSER
:
388 gtk_list_store_set(store
, &iter
, 2, _("Browser Extension"), -1);
390 case GMPC_PLUGIN_META_DATA
:
391 gtk_list_store_set(store
, &iter
, 2, _("Metadata Provider"), -1);
393 case GMPC_PLUGIN_PL_BROWSER
| GMPC_PLUGIN_META_DATA
:
394 gtk_list_store_set(store
, &iter
, 2, _("Metadata Provider and Browser Extension"), -1);
396 case GMPC_PLUGIN_NO_GUI
:
397 gtk_list_store_set(store
, &iter
, 2, _("Misc."), -1);
400 case GMPC_DEPRECATED
:
402 gtk_list_store_set(store
, &iter
, 2, _("Unknown"), -1);
410 gtk_container_add(GTK_CONTAINER(container
), vbox
);
416 static void plugin_stats_destroy(GtkWidget
* container
)
420 GtkWidget
*vbox
= (GtkWidget
*) gtk_builder_get_object(plugin_stat_xml
, "plugin_stats_vbox");
421 GtkTreeModel
*model
=
422 gtk_tree_view_get_model(GTK_TREE_VIEW(gtk_builder_get_object(plugin_stat_xml
, "plugin_stats_tree")));
423 gtk_container_remove(GTK_CONTAINER(container
), vbox
);
425 g_object_unref(model
);
426 g_object_unref(plugin_stat_xml
);
427 plugin_stat_xml
= NULL
;
432 void preferences_show_pref_window(int plugin_id
)
435 if (xml_preferences_window
== NULL
)
436 create_preferences_window();
439 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(plugin_store
), &iter
))
444 gtk_tree_model_get(GTK_TREE_MODEL(plugin_store
), &iter
, 0, &pos
, -1);
445 if (pos
== plugin_get_pos(plugin_id
))
447 GtkTreeSelection
*sel
=
448 gtk_tree_view_get_selection(GTK_TREE_VIEW
449 (gtk_builder_get_object(xml_preferences_window
, "plugin_tree")));
450 gtk_tree_selection_select_iter(sel
, &iter
);
453 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(plugin_store
), &iter
));