From b75e6c2a9e514746159db28412df2db3c939de01 Mon Sep 17 00:00:00 2001 From: Krifa75 Date: Tue, 22 Nov 2022 21:38:02 +0100 Subject: preferences: Move the plugins settings Libpeas-gtk will not be ported to Gtk4, so let's remove the dependency and build the list of plugins ourselves. Closes: #548 --- data/totem-preferences-dialog.ui | 47 ++++----- data/totem-preferences-plugin-row.ui | 135 ++++++++++++++++++++++++ data/totem.gresource.xml | 1 + meson.build | 1 - po/POTFILES.in | 1 + src/meson.build | 2 +- src/plugins/totem-plugin.h | 1 - src/totem-preferences-dialog.c | 102 ++++++++---------- src/totem-preferences-plugin-row.c | 199 +++++++++++++++++++++++++++++++++++ src/totem-preferences-plugin-row.h | 36 +++++++ 10 files changed, 441 insertions(+), 84 deletions(-) create mode 100644 data/totem-preferences-plugin-row.ui create mode 100644 src/totem-preferences-plugin-row.c create mode 100644 src/totem-preferences-plugin-row.h diff --git a/data/totem-preferences-dialog.ui b/data/totem-preferences-dialog.ui index 775093478..bb831efcf 100644 --- a/data/totem-preferences-dialog.ui +++ b/data/totem-preferences-dialog.ui @@ -155,30 +155,6 @@ - - - True - Plugins - - - - True - Plugins - True - - - - go-next-symbolic - True - - - - - - - - - @@ -501,6 +477,29 @@ Disable it if you encounter video playback problems. + + + + True + True + Plugins + + + + True + + + + True + + + + + + + + + horizontal diff --git a/data/totem-preferences-plugin-row.ui b/data/totem-preferences-plugin-row.ui new file mode 100644 index 000000000..0acbb095e --- /dev/null +++ b/data/totem-preferences-plugin-row.ui @@ -0,0 +1,135 @@ + + + + \ No newline at end of file diff --git a/data/totem.gresource.xml b/data/totem.gresource.xml index aeb11ac02..6341197ec 100644 --- a/data/totem.gresource.xml +++ b/data/totem.gresource.xml @@ -2,6 +2,7 @@ totem-preferences-dialog.ui + totem-preferences-plugin-row.ui playlist.ui uri.ui shortcuts.ui diff --git a/meson.build b/meson.build index ea3b198fc..f1332bebb 100644 --- a/meson.build +++ b/meson.build @@ -148,7 +148,6 @@ gst_tag_dep = dependency('gstreamer-tag-1.0', version: '>= 0.11.93') gst_video_dep = dependency('gstreamer-video-1.0') gst_pbutils_dep = dependency('gstreamer-pbutils-1.0') peas_dep = dependency('libpeas-1.0', version: peas_req_version) -peas_gtk_dep = dependency('libpeas-gtk-1.0', version: peas_req_version) totem_plparser_dep = dependency('totem-plparser', version: totem_plparser_req_version) m_dep = cc.find_library('m', required: true) diff --git a/po/POTFILES.in b/po/POTFILES.in index d73eefd9e..3ff402228 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,6 +5,7 @@ data/org.gnome.Totem.desktop.in.in data/org.gnome.totem.gschema.xml.in data/playlist.ui data/totem-preferences-dialog.ui +data/totem-preferences-plugin-row.ui data/shortcuts.ui data/totem.ui data/uri.ui diff --git a/src/meson.build b/src/meson.build index 0eeb807a4..ca2286093 100644 --- a/src/meson.build +++ b/src/meson.build @@ -55,7 +55,6 @@ totem_common_deps = libbacon_video_widget_deps + python_deps + [ totem_plparser_dep, gir_dep, peas_dep, - peas_gtk_dep, dependency('grilo-0.3', version: grilo_req_version), dependency('grilo-pls-0.3', version: grilo_req_version), dependency('gnome-desktop-3.0') @@ -120,6 +119,7 @@ libtotem_sources = files( 'totem-playlist.c', 'totem-playlist-inspector-page.c', 'totem-preferences-dialog.c', + 'totem-preferences-plugin-row.c', 'totem-search-entry.c', 'totem-selection-toolbar.c', 'totem-session.c', diff --git a/src/plugins/totem-plugin.h b/src/plugins/totem-plugin.h index 4689a3b67..456490d79 100644 --- a/src/plugins/totem-plugin.h +++ b/src/plugins/totem-plugin.h @@ -32,7 +32,6 @@ #include #include #include -#include #include /** diff --git a/src/totem-preferences-dialog.c b/src/totem-preferences-dialog.c index d21b0e09f..a3892193e 100644 --- a/src/totem-preferences-dialog.c +++ b/src/totem-preferences-dialog.c @@ -34,7 +34,6 @@ #include #include #include -#include #include "bacon-video-widget-enums.h" #include "totem.h" @@ -43,6 +42,7 @@ #include "totem-interface.h" #include "totem-subtitle-encoding.h" #include "totem-plugins-engine.h" +#include "totem-preferences-plugin-row.h" struct _TotemPreferencesDialog { HdyPreferencesWindow parent_instance; @@ -63,9 +63,10 @@ struct _TotemPreferencesDialog { GtkWidget *tpw_bright_contr_vbox; GtkCheckButton *tpw_no_deinterlace_checkbutton; GtkCheckButton *tpw_no_hardware_acceleration; - GtkButton *tpw_plugins_button; GtkComboBox *tpw_sound_output_combobox; GtkComboBox *subtitle_encoding_combo; + + GtkListBox *tpw_plugins_list; }; G_DEFINE_TYPE (TotemPreferencesDialog, totem_preferences_dialog, HDY_TYPE_PREFERENCES_WINDOW) @@ -165,58 +166,15 @@ int_enum_set_mapping (const GValue *value, const GVariantType *expected_type, GE return g_variant_new_string (enum_value->value_nick); } -static gboolean -totem_plugins_window_delete_cb (GtkWidget *window, - GdkEventAny *event, - gpointer data) +static int +totems_plugins_sort_cb (GtkListBoxRow *row_a, + GtkListBoxRow *row_b, + gpointer data) { - gtk_widget_hide (window); - - return TRUE; -} - -static void -totem_plugins_response_cb (GtkDialog *dialog, - int response_id, - gpointer data) -{ - gtk_widget_hide (GTK_WIDGET (dialog)); -} - -static void -plugin_button_clicked_cb (GtkButton *button, - Totem *totem) -{ - if (totem->plugins == NULL) { - GtkWidget *manager; - - totem->plugins = gtk_dialog_new_with_buttons (_("Configure Plugins"), - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (button))), - GTK_DIALOG_DESTROY_WITH_PARENT, - _("_Close"), - GTK_RESPONSE_CLOSE, - NULL); - gtk_window_set_modal (GTK_WINDOW (totem->plugins), TRUE); - gtk_container_set_border_width (GTK_CONTAINER (totem->plugins), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (totem->plugins))), 2); - - g_signal_connect_object (G_OBJECT (totem->plugins), - "delete_event", - G_CALLBACK (totem_plugins_window_delete_cb), - NULL, 0); - g_signal_connect_object (G_OBJECT (totem->plugins), - "response", - G_CALLBACK (totem_plugins_response_cb), - NULL, 0); - - manager = peas_gtk_plugin_manager_new (NULL); - gtk_widget_show_all (GTK_WIDGET (manager)); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (totem->plugins))), - manager, TRUE, TRUE, 0); - gtk_window_set_default_size (GTK_WINDOW (totem->plugins), 600, 400); - } + const char *name_a = hdy_preferences_row_get_title (HDY_PREFERENCES_ROW (row_a)); + const char *name_b = hdy_preferences_row_get_title (HDY_PREFERENCES_ROW (row_b)); - gtk_window_present (GTK_WINDOW (totem->plugins)); + return g_utf8_collate (name_a, name_b); } enum { @@ -268,10 +226,12 @@ static void totem_preferences_dialog_constructed (GObject *object) { TotemPreferencesDialog *prefs = TOTEM_PREFERENCES_DIALOG (object); + g_autoptr(TotemPluginsEngine) engine = NULL; TotemObject *totem; GtkWidget *bvw; guint i, hidden; char *font, *encoding; + const GList *plugin_infos, *l; G_OBJECT_CLASS (totem_preferences_dialog_parent_class)->constructed (object); @@ -296,10 +256,6 @@ totem_preferences_dialog_constructed (GObject *object) g_settings_bind (totem->settings, "autoload-subtitles", prefs->tpw_auto_subtitles_checkbutton, "active", G_SETTINGS_BIND_DEFAULT); - /* Plugins button */ - g_signal_connect (prefs->tpw_plugins_button, "activated", - G_CALLBACK (plugin_button_clicked_cb), totem); - /* Brightness and all */ struct { GtkRange *range; @@ -368,6 +324,38 @@ totem_preferences_dialog_constructed (GObject *object) totem->disable_kbd_shortcuts = g_settings_get_boolean (totem->settings, "disable-keyboard-shortcuts"); g_signal_connect (totem->settings, "changed::disable-keyboard-shortcuts", (GCallback) disable_kbd_shortcuts_changed_cb, totem); + /* Plugins */ + gtk_list_box_set_sort_func (prefs->tpw_plugins_list, totems_plugins_sort_cb, NULL, NULL); + + engine = totem_plugins_engine_get_default (totem); + plugin_infos = peas_engine_get_plugin_list (PEAS_ENGINE (engine)); + + for (l = plugin_infos; l != NULL; l = l->next) { + g_autoptr(GError) error = NULL; + PeasPluginInfo *plugin_info; + const char *plugin_name; + GtkWidget *plugin_row; + + plugin_info = PEAS_PLUGIN_INFO (l->data); + plugin_name = peas_plugin_info_get_name (plugin_info); + + if (!peas_plugin_info_is_available (plugin_info, &error)) { + g_warning ("The plugin %s is not available : %s", plugin_name, error ? error->message : "no message error"); + continue; + } + + if (peas_plugin_info_is_hidden (plugin_info) || + peas_plugin_info_is_builtin (plugin_info)) + continue; + + plugin_row = totem_preferences_plugin_row_new (plugin_info); + + hdy_preferences_row_set_title (HDY_PREFERENCES_ROW (plugin_row), plugin_name); + hdy_expander_row_set_subtitle (HDY_EXPANDER_ROW (plugin_row), peas_plugin_info_get_description (plugin_info)); + + gtk_container_add (GTK_CONTAINER (prefs->tpw_plugins_list), plugin_row); + } + g_object_unref (bvw); } @@ -402,11 +390,11 @@ totem_preferences_dialog_class_init (TotemPreferencesDialogClass *klass) gtk_widget_class_bind_template_child (widget_class, TotemPreferencesDialog, tpw_hue_scale); gtk_widget_class_bind_template_child (widget_class, TotemPreferencesDialog, tpw_no_deinterlace_checkbutton); gtk_widget_class_bind_template_child (widget_class, TotemPreferencesDialog, tpw_no_hardware_acceleration); - gtk_widget_class_bind_template_child (widget_class, TotemPreferencesDialog, tpw_plugins_button); gtk_widget_class_bind_template_child (widget_class, TotemPreferencesDialog, tpw_saturation_adjustment); gtk_widget_class_bind_template_child (widget_class, TotemPreferencesDialog, tpw_saturation_scale); gtk_widget_class_bind_template_child (widget_class, TotemPreferencesDialog, tpw_sound_output_combobox); gtk_widget_class_bind_template_child (widget_class, TotemPreferencesDialog, subtitle_encoding_combo); + gtk_widget_class_bind_template_child (widget_class, TotemPreferencesDialog, tpw_plugins_list); gtk_widget_class_bind_template_callback (widget_class, encoding_set_cb); gtk_widget_class_bind_template_callback (widget_class, font_set_cb); diff --git a/src/totem-preferences-plugin-row.c b/src/totem-preferences-plugin-row.c new file mode 100644 index 000000000..f5fe8ad29 --- /dev/null +++ b/src/totem-preferences-plugin-row.c @@ -0,0 +1,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); +} diff --git a/src/totem-preferences-plugin-row.h b/src/totem-preferences-plugin-row.h new file mode 100644 index 000000000..52bb97b6e --- /dev/null +++ b/src/totem-preferences-plugin-row.h @@ -0,0 +1,36 @@ +/* + * + * + * 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. + */ + +#pragma once + +#include +#include + +#define TOTEM_TYPE_PREFERENCES_PLUGIN_ROW (totem_preferences_plugin_row_get_type ()) +G_DECLARE_FINAL_TYPE(TotemPreferencesPluginRow, totem_preferences_plugin_row, TOTEM, PREFERENCES_PLUGIN_ROW, HdyExpanderRow) + +GType totem_preferences_plugins_engine_get_type (void) G_GNUC_CONST; + +GtkWidget *totem_preferences_plugin_row_new (PeasPluginInfo *plugin_info); -- cgit v1.2.1