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/gi18n-lib.h>
#include <gtk/gtk.h>
#include <libhandy-1/handy.h>
#include "restrict-applications-dialog.h"
#include "restrict-applications-selector.h"
@ -53,13 +54,13 @@ struct _MctRestrictApplicationsDialog
GtkDialog parent_instance;
MctRestrictApplicationsSelector *selector;
GtkLabel *description;
HdyPreferencesGroup *group;
MctAppFilter *app_filter; /* (owned) (not 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
{
@ -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_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
@ -214,15 +215,14 @@ update_description (MctRestrictApplicationsDialog *self)
if (self->user_display_name == NULL)
{
gtk_widget_hide (GTK_WIDGET (self->description));
hdy_preferences_group_set_description (self->group, NULL);
return;
}
/* Translators: the placeholder is a users full name */
description = g_strdup_printf (_("Restrict %s from using the following installed applications."),
self->user_display_name);
gtk_label_set_text (self->description, description);
gtk_widget_show (GTK_WIDGET (self->description));
hdy_preferences_group_set_description (self->group, description);
}
/**

View File

@ -24,13 +24,14 @@
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <libhandy-1/handy.h>
#include <libmalcontent/manager.h>
G_BEGIN_DECLS
#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,
const gchar *user_display_name);

View File

@ -2,47 +2,26 @@
<!-- Copyright © 2020 Endless, Inc. -->
<interface domain="malcontent">
<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="skip-taskbar-hint">True</property>
<property name="default-width">300</property>
<property name="default-width">500</property>
<property name="default-height">500</property>
<child internal-child="headerbar">
<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>
<property name="search-enabled">False</property>
<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: -->
<property name="label">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>
<property name="description">Restrict {username} from using the following installed applications.</property>
<child>
<object class="MctRestrictApplicationsSelector" id="selector">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">True</property>
</packing>
</child>
</object>
</child>
</object>
</child>

View File

@ -3,16 +3,6 @@
<interface domain="malcontent">
<requires lib="gtk+" version="3.12"/>
<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>
<object class="GtkListBox" id="listbox">
<property name="visible">True</property>
@ -24,8 +14,10 @@
<property name="label" translatable="yes">No applications found to restrict.</property>
</object>
</child>
</object>
</child>
<style>
<class name="content"/>
</style>
</object>
</child>
</template>

View File

@ -130,10 +130,6 @@ static gboolean on_restrict_applications_dialog_delete_event_cb (GtkWidget *widg
GdkEvent *event,
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,
GVariant *param,
gpointer user_data);
@ -623,16 +619,6 @@ on_restrict_applications_dialog_delete_event_cb (GtkWidget *widget,
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
on_set_age_action_activated (GSimpleAction *action,
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_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_response_cb);
}
static void

View File

@ -178,8 +178,6 @@
<property name="visible">False</property>
<property name="modal">True</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="response" handler="on_restrict_applications_dialog_response_cb" />
</object>
</interface>