restrict-applications: Use HdyPreferencesWindow

HdyPreferencesWindow provides a neat API we can use for
windows like this.
This commit is contained in:
Christopher Davis 2021-02-08 05:53:18 -08:00 committed by Georges Basile Stavracas Neto
parent 358cad3a24
commit c68058f0f3
6 changed files with 28 additions and 73 deletions

View File

@ -26,6 +26,7 @@
#include <glib-object.h> #include <glib-object.h>
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libhandy-1/handy.h>
#include "restrict-applications-dialog.h" #include "restrict-applications-dialog.h"
#include "restrict-applications-selector.h" #include "restrict-applications-selector.h"
@ -53,13 +54,13 @@ struct _MctRestrictApplicationsDialog
GtkDialog parent_instance; GtkDialog parent_instance;
MctRestrictApplicationsSelector *selector; MctRestrictApplicationsSelector *selector;
GtkLabel *description; HdyPreferencesGroup *group;
MctAppFilter *app_filter; /* (owned) (not nullable) */ MctAppFilter *app_filter; /* (owned) (not nullable) */
gchar *user_display_name; /* (owned) (nullable) */ gchar *user_display_name; /* (owned) (nullable) */
}; };
G_DEFINE_TYPE (MctRestrictApplicationsDialog, mct_restrict_applications_dialog, GTK_TYPE_DIALOG) G_DEFINE_TYPE (MctRestrictApplicationsDialog, mct_restrict_applications_dialog, HDY_TYPE_PREFERENCES_WINDOW)
typedef enum typedef enum
{ {
@ -195,7 +196,7 @@ mct_restrict_applications_dialog_class_init (MctRestrictApplicationsDialogClass
gtk_widget_class_set_template_from_resource (widget_class, "/org/freedesktop/MalcontentUi/ui/restrict-applications-dialog.ui"); gtk_widget_class_set_template_from_resource (widget_class, "/org/freedesktop/MalcontentUi/ui/restrict-applications-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, MctRestrictApplicationsDialog, selector); gtk_widget_class_bind_template_child (widget_class, MctRestrictApplicationsDialog, selector);
gtk_widget_class_bind_template_child (widget_class, MctRestrictApplicationsDialog, description); gtk_widget_class_bind_template_child (widget_class, MctRestrictApplicationsDialog, group);
} }
static void static void
@ -214,15 +215,14 @@ update_description (MctRestrictApplicationsDialog *self)
if (self->user_display_name == NULL) if (self->user_display_name == NULL)
{ {
gtk_widget_hide (GTK_WIDGET (self->description)); hdy_preferences_group_set_description (self->group, NULL);
return; return;
} }
/* Translators: the placeholder is a users full name */ /* Translators: the placeholder is a users full name */
description = g_strdup_printf (_("Restrict %s from using the following installed applications."), description = g_strdup_printf (_("Restrict %s from using the following installed applications."),
self->user_display_name); self->user_display_name);
gtk_label_set_text (self->description, description); hdy_preferences_group_set_description (self->group, description);
gtk_widget_show (GTK_WIDGET (self->description));
} }
/** /**

View File

@ -24,13 +24,14 @@
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libhandy-1/handy.h>
#include <libmalcontent/manager.h> #include <libmalcontent/manager.h>
G_BEGIN_DECLS G_BEGIN_DECLS
#define MCT_TYPE_RESTRICT_APPLICATIONS_DIALOG (mct_restrict_applications_dialog_get_type ()) #define MCT_TYPE_RESTRICT_APPLICATIONS_DIALOG (mct_restrict_applications_dialog_get_type ())
G_DECLARE_FINAL_TYPE (MctRestrictApplicationsDialog, mct_restrict_applications_dialog, MCT, RESTRICT_APPLICATIONS_DIALOG, GtkDialog) G_DECLARE_FINAL_TYPE (MctRestrictApplicationsDialog, mct_restrict_applications_dialog, MCT, RESTRICT_APPLICATIONS_DIALOG, HdyPreferencesWindow)
MctRestrictApplicationsDialog *mct_restrict_applications_dialog_new (MctAppFilter *app_filter, MctRestrictApplicationsDialog *mct_restrict_applications_dialog_new (MctAppFilter *app_filter,
const gchar *user_display_name); const gchar *user_display_name);

View File

@ -2,47 +2,26 @@
<!-- Copyright © 2020 Endless, Inc. --> <!-- Copyright © 2020 Endless, Inc. -->
<interface domain="malcontent"> <interface domain="malcontent">
<requires lib="gtk+" version="3.12"/> <requires lib="gtk+" version="3.12"/>
<template class="MctRestrictApplicationsDialog" parent="GtkDialog"> <template class="MctRestrictApplicationsDialog" parent="HdyPreferencesWindow">
<property name="title" translatable="yes">Restrict Applications</property> <property name="title" translatable="yes">Restrict Applications</property>
<property name="skip-taskbar-hint">True</property> <property name="skip-taskbar-hint">True</property>
<property name="default-width">300</property> <property name="default-width">500</property>
<property name="default-height">500</property> <property name="default-height">500</property>
<child internal-child="headerbar"> <property name="search-enabled">False</property>
<object class="GtkHeaderBar">
<property name="title" translatable="yes">Restrict Applications</property>
<property name="show-close-button">True</property>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="visible">True</property>
<property name="margin">18</property>
<property name="spacing">12</property>
<child> <child>
<object class="GtkLabel" id="description"> <object class="HdyPreferencesPage">
<property name="visible">True</property>
<child>
<object class="HdyPreferencesGroup" id="group">
<property name="visible">True</property>
<!-- Translated dynamically: --> <!-- Translated dynamically: -->
<property name="label">Restrict {username} from using the following installed applications.</property> <property name="description">Restrict {username} from using the following installed applications.</property>
<property name="visible">False</property>
<property name="ellipsize">none</property>
<property name="wrap">True</property>
<property name="halign">start</property>
<property name="xalign">0</property>
<property name="hexpand">True</property>
<child internal-child="accessible">
<object class="AtkObject">
<property name="accessible-role">static</property>
</object>
</child>
</object>
</child>
<child> <child>
<object class="MctRestrictApplicationsSelector" id="selector"> <object class="MctRestrictApplicationsSelector" id="selector">
<property name="visible">True</property> <property name="visible">True</property>
</object> </object>
<packing> </child>
<property name="expand">True</property> </object>
</packing>
</child> </child>
</object> </object>
</child> </child>

View File

@ -3,16 +3,6 @@
<interface domain="malcontent"> <interface domain="malcontent">
<requires lib="gtk+" version="3.12"/> <requires lib="gtk+" version="3.12"/>
<template class="MctRestrictApplicationsSelector" parent="GtkBox"> <template class="MctRestrictApplicationsSelector" parent="GtkBox">
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="hscrollbar-policy">never</property>
<property name="min-content-height">100</property>
<property name="max-content-height">400</property>
<property name="propagate-natural-height">True</property>
<property name="shadow-type">etched-in</property>
<child> <child>
<object class="GtkListBox" id="listbox"> <object class="GtkListBox" id="listbox">
<property name="visible">True</property> <property name="visible">True</property>
@ -24,8 +14,10 @@
<property name="label" translatable="yes">No applications found to restrict.</property> <property name="label" translatable="yes">No applications found to restrict.</property>
</object> </object>
</child> </child>
</object>
</child> <style>
<class name="content"/>
</style>
</object> </object>
</child> </child>
</template> </template>

View File

@ -130,10 +130,6 @@ static gboolean on_restrict_applications_dialog_delete_event_cb (GtkWidget *widg
GdkEvent *event, GdkEvent *event,
gpointer user_data); gpointer user_data);
static void on_restrict_applications_dialog_response_cb (GtkDialog *dialog,
gint response_id,
gpointer user_data);
static void on_set_age_action_activated (GSimpleAction *action, static void on_set_age_action_activated (GSimpleAction *action,
GVariant *param, GVariant *param,
gpointer user_data); gpointer user_data);
@ -623,16 +619,6 @@ on_restrict_applications_dialog_delete_event_cb (GtkWidget *widget,
return TRUE; return TRUE;
} }
static void
on_restrict_applications_dialog_response_cb (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
MctUserControls *self = MCT_USER_CONTROLS (user_data);
on_restrict_applications_dialog_delete_event_cb (GTK_WIDGET (dialog), NULL, self);
}
static void static void
on_set_age_action_activated (GSimpleAction *action, on_set_age_action_activated (GSimpleAction *action,
GVariant *param, GVariant *param,
@ -1020,7 +1006,6 @@ mct_user_controls_class_init (MctUserControlsClass *klass)
gtk_widget_class_bind_template_callback (widget_class, on_restrict_installation_switch_active_changed_cb); gtk_widget_class_bind_template_callback (widget_class, on_restrict_installation_switch_active_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, on_restrict_web_browsers_switch_active_changed_cb); gtk_widget_class_bind_template_callback (widget_class, on_restrict_web_browsers_switch_active_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, on_restrict_applications_dialog_delete_event_cb); gtk_widget_class_bind_template_callback (widget_class, on_restrict_applications_dialog_delete_event_cb);
gtk_widget_class_bind_template_callback (widget_class, on_restrict_applications_dialog_response_cb);
} }
static void static void

View File

@ -178,8 +178,6 @@
<property name="visible">False</property> <property name="visible">False</property>
<property name="modal">True</property> <property name="modal">True</property>
<property name="destroy-with-parent">False</property> <property name="destroy-with-parent">False</property>
<property name="use-header-bar">1</property>
<signal name="delete-event" handler="on_restrict_applications_dialog_delete_event_cb" /> <signal name="delete-event" handler="on_restrict_applications_dialog_delete_event_cb" />
<signal name="response" handler="on_restrict_applications_dialog_response_cb" />
</object> </object>
</interface> </interface>