usage: Port to GTK4

This commit is contained in:
Georges Basile Stavracas Neto 2021-10-21 12:12:05 -03:00
parent 696ed350bb
commit 2d762680d2
4 changed files with 81 additions and 78 deletions

View file

@ -26,7 +26,7 @@ panels = [
# 'sharing', # 'sharing',
'sound', 'sound',
'universal-access', 'universal-access',
# 'usage', 'usage',
# 'user-accounts', # 'user-accounts',
# 'wwan', # 'wwan',
] ]

View file

@ -18,7 +18,6 @@
* Author: Matthias Clasen <mclasen@redhat.com> * Author: Matthias Clasen <mclasen@redhat.com>
*/ */
#include "list-box-helper.h"
#include "cc-usage-panel.h" #include "cc-usage-panel.h"
#include "cc-usage-resources.h" #include "cc-usage-resources.h"
#include "cc-util.h" #include "cc-util.h"
@ -108,7 +107,7 @@ set_purge_after_value_for_combo (GtkComboBox *combo_box,
gtk_combo_box_set_active (combo_box, i - 1); gtk_combo_box_set_active (combo_box, i - 1);
} }
static gboolean static GtkDialog *
run_warning (CcUsagePanel *self, run_warning (CcUsagePanel *self,
const gchar *prompt, const gchar *prompt,
const gchar *text, const gchar *text,
@ -117,12 +116,13 @@ run_warning (CcUsagePanel *self,
GtkWindow *parent; GtkWindow *parent;
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *button; GtkWidget *button;
int result; CcShell *shell;
parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))); shell = cc_panel_get_shell (CC_PANEL (self));
parent = GTK_WINDOW (cc_shell_get_toplevel (shell));
dialog = gtk_message_dialog_new (parent, dialog = gtk_message_dialog_new (parent,
0, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING, GTK_MESSAGE_WARNING,
GTK_BUTTONS_NONE, GTK_BUTTONS_NONE,
NULL); NULL);
@ -138,25 +138,20 @@ run_warning (CcUsagePanel *self,
button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
gtk_style_context_add_class (gtk_widget_get_style_context (button), "destructive-action"); gtk_style_context_add_class (gtk_widget_get_style_context (button), "destructive-action");
result = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_window_present (GTK_WINDOW (dialog));
gtk_widget_destroy (dialog);
return result == GTK_RESPONSE_OK; return GTK_DIALOG (dialog);
} }
static void static void
empty_trash (CcUsagePanel *self) on_empty_trash_warning_response_cb (GtkDialog *dialog,
gint response,
CcUsagePanel *self)
{ {
g_autoptr(GDBusConnection) bus = NULL; g_autoptr(GDBusConnection) bus = NULL;
gboolean result;
result = run_warning (self, if (response != GTK_RESPONSE_OK)
_("Empty all items from Trash?"), goto out;
_("All items in the Trash will be permanently deleted."),
_("_Empty Trash"));
if (!result)
return;
bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
g_dbus_connection_call (bus, g_dbus_connection_call (bus,
@ -165,21 +160,37 @@ empty_trash (CcUsagePanel *self)
"org.gnome.SettingsDaemon.Housekeeping", "org.gnome.SettingsDaemon.Housekeeping",
"EmptyTrash", "EmptyTrash",
NULL, NULL, 0, -1, NULL, NULL, NULL); NULL, NULL, 0, -1, NULL, NULL, NULL);
out:
gtk_window_destroy (GTK_WINDOW (dialog));
} }
static void static void
purge_temp (CcUsagePanel *self) empty_trash (CcUsagePanel *self)
{
GtkDialog *dialog;
dialog = run_warning (self,
_("Empty all items from Trash?"),
_("All items in the Trash will be permanently deleted."),
_("_Empty Trash"));
g_signal_connect_object (dialog,
"response",
G_CALLBACK (on_empty_trash_warning_response_cb),
self,
0);
}
static void
on_purge_temp_warning_response_cb (GtkDialog *dialog,
gint response,
CcUsagePanel *self)
{ {
g_autoptr(GDBusConnection) bus = NULL; g_autoptr(GDBusConnection) bus = NULL;
gboolean result;
result = run_warning (self, if (response != GTK_RESPONSE_OK)
_("Delete all the temporary files?"), goto out;
_("All the temporary files will be permanently deleted."),
_("_Purge Temporary Files"));
if (!result)
return;
bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
g_dbus_connection_call (bus, g_dbus_connection_call (bus,
@ -188,6 +199,25 @@ purge_temp (CcUsagePanel *self)
"org.gnome.SettingsDaemon.Housekeeping", "org.gnome.SettingsDaemon.Housekeeping",
"RemoveTempFiles", "RemoveTempFiles",
NULL, NULL, 0, -1, NULL, NULL, NULL); NULL, NULL, 0, -1, NULL, NULL, NULL);
out:
gtk_window_destroy (GTK_WINDOW (dialog));
}
static void
purge_temp (CcUsagePanel *self)
{
GtkDialog *dialog;
dialog = run_warning (self,
_("Delete all the temporary files?"),
_("All the temporary files will be permanently deleted."),
_("_Purge Temporary Files"));
g_signal_connect_object (dialog,
"response",
G_CALLBACK (on_purge_temp_warning_response_cb),
self,
0);
} }
static void static void
@ -264,14 +294,6 @@ cc_usage_panel_init (CcUsagePanel *self)
gtk_widget_init_template (GTK_WIDGET (self)); gtk_widget_init_template (GTK_WIDGET (self));
gtk_list_box_set_header_func (self->usage_list_box,
cc_list_box_update_header_func,
NULL, NULL);
gtk_list_box_set_header_func (self->trash_list_box,
cc_list_box_update_header_func,
NULL, NULL);
self->privacy_settings = g_settings_new ("org.gnome.desktop.privacy"); self->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
g_settings_bind (self->privacy_settings, g_settings_bind (self->privacy_settings,

View file

@ -2,14 +2,11 @@
<!-- Generated with glade 3.18.1 --> <!-- Generated with glade 3.18.1 -->
<interface> <interface>
<template class="CcUsagePanel" parent="CcPanel"> <template class="CcUsagePanel" parent="CcPanel">
<property name="visible">True</property>
<child> <child>
<object class="GtkScrolledWindow"> <object class="GtkScrolledWindow">
<property name="visible">true</property>
<property name="hscrollbar-policy">never</property> <property name="hscrollbar-policy">never</property>
<child> <child>
<object class="HdyClamp"> <object class="AdwClamp">
<property name="visible">True</property>
<property name="margin_top">32</property> <property name="margin_top">32</property>
<property name="margin_bottom">32</property> <property name="margin_bottom">32</property>
<property name="margin_start">12</property> <property name="margin_start">12</property>
@ -18,14 +15,12 @@
<!-- File History --> <!-- File History -->
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">true</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="hexpand">1</property> <property name="hexpand">1</property>
<property name="spacing">12</property> <property name="spacing">12</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="visible">true</property>
<property name="label" translatable="yes">File History</property> <property name="label" translatable="yes">File History</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<attributes> <attributes>
@ -36,7 +31,6 @@
<child> <child>
<object class="GtkLabel" id="usage_description_label"> <object class="GtkLabel" id="usage_description_label">
<property name="visible">true</property>
<property name="margin-bottom">12</property> <property name="margin-bottom">12</property>
<property name="label" translatable="yes">File history keeps a record of files that you have used. This information is shared between applications, and makes it easier to find files that you might want to use.</property> <property name="label" translatable="yes">File history keeps a record of files that you have used. This information is shared between applications, and makes it easier to find files that you might want to use.</property>
<property name="wrap">1</property> <property name="wrap">1</property>
@ -47,18 +41,18 @@
<child> <child>
<object class="GtkListBox" id="usage_list_box"> <object class="GtkListBox" id="usage_list_box">
<property name="visible">true</property>
<property name="can-focus">1</property> <property name="can-focus">1</property>
<property name="selection-mode">none</property> <property name="selection-mode">none</property>
<style>
<class name="content" />
</style>
<child> <child>
<object class="HdyActionRow"> <object class="AdwActionRow">
<property name="visible">true</property>
<property name="title" translatable="yes">File H_istory</property> <property name="title" translatable="yes">File H_istory</property>
<property name="activatable-widget">recently_used_switch</property> <property name="activatable-widget">recently_used_switch</property>
<property name="use-underline">true</property> <property name="use-underline">true</property>
<child> <child>
<object class="GtkSwitch" id="recently_used_switch"> <object class="GtkSwitch" id="recently_used_switch">
<property name="visible">true</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property> <property name="valign">center</property>
</object> </object>
@ -67,28 +61,26 @@
</child> </child>
<child> <child>
<object class="GtkListBoxRow"> <object class="GtkListBoxRow">
<property name="visible">true</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">true</property> <property name="margin-top">12</property>
<property name="margin">12</property> <property name="margin-bottom">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="visible">true</property>
<property name="label" translatable="yes">File _History Duration</property> <property name="label" translatable="yes">File _History Duration</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="use_underline">1</property> <property name="use_underline">1</property>
<property name="mnemonic_widget">retain_history_combo</property> <property name="mnemonic_widget">retain_history_combo</property>
<property name="sensitive" bind-source="retain_history_combo" bind-property="sensitive"/> <property name="sensitive" bind-source="retain_history_combo" bind-property="sensitive"/>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="valign">center</property> <property name="valign">center</property>
</object> </object>
<packing>
<property name="expand">1</property>
</packing>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="retain_history_combo"> <object class="GtkComboBoxText" id="retain_history_combo">
<property name="visible">true</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="entry_text_column">0</property> <property name="entry_text_column">0</property>
<property name="model">retain_history_model</property> <property name="model">retain_history_model</property>
@ -107,14 +99,12 @@
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">true</property>
<property name="hexpand">true</property> <property name="hexpand">true</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="homogeneous">true</property> <property name="homogeneous">true</property>
<property name="spacing">12</property> <property name="spacing">12</property>
<child> <child>
<object class="GtkButton" id="clear_recent_button"> <object class="GtkButton" id="clear_recent_button">
<property name="visible">true</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="label" translatable="yes">_Clear History…</property> <property name="label" translatable="yes">_Clear History…</property>
<property name="use_underline">1</property> <property name="use_underline">1</property>
@ -130,7 +120,6 @@
<!-- Trash & Temporary Files --> <!-- Trash & Temporary Files -->
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="visible">true</property>
<property name="margin-top">18</property> <property name="margin-top">18</property>
<property name="label" translatable="yes">Trash &amp; Temporary Files</property> <property name="label" translatable="yes">Trash &amp; Temporary Files</property>
<property name="xalign">0</property> <property name="xalign">0</property>
@ -141,7 +130,6 @@
</child> </child>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="visible">true</property>
<property name="label" translatable="yes">Trash and temporary files can sometimes include personal or sensitive information. Automatically deleting them can help to protect privacy.</property> <property name="label" translatable="yes">Trash and temporary files can sometimes include personal or sensitive information. Automatically deleting them can help to protect privacy.</property>
<property name="wrap">1</property> <property name="wrap">1</property>
<property name="max-width-chars">50</property> <property name="max-width-chars">50</property>
@ -150,18 +138,18 @@
</child> </child>
<child> <child>
<object class="GtkListBox" id="trash_list_box"> <object class="GtkListBox" id="trash_list_box">
<property name="visible">true</property>
<property name="can-focus">1</property> <property name="can-focus">1</property>
<property name="selection-mode">none</property> <property name="selection-mode">none</property>
<style>
<class name="content" />
</style>
<child> <child>
<object class="HdyActionRow"> <object class="AdwActionRow">
<property name="visible">true</property>
<property name="title" translatable="yes">Automatically Delete _Trash Content</property> <property name="title" translatable="yes">Automatically Delete _Trash Content</property>
<property name="activatable-widget">purge_trash_switch</property> <property name="activatable-widget">purge_trash_switch</property>
<property name="use-underline">true</property> <property name="use-underline">true</property>
<child> <child>
<object class="GtkSwitch" id="purge_trash_switch"> <object class="GtkSwitch" id="purge_trash_switch">
<property name="visible">true</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property> <property name="valign">center</property>
</object> </object>
@ -169,14 +157,12 @@
</object> </object>
</child> </child>
<child> <child>
<object class="HdyActionRow"> <object class="AdwActionRow">
<property name="visible">true</property>
<property name="title" translatable="yes">Automatically Delete Temporary _Files</property> <property name="title" translatable="yes">Automatically Delete Temporary _Files</property>
<property name="activatable-widget">purge_temp_switch</property> <property name="activatable-widget">purge_temp_switch</property>
<property name="use-underline">true</property> <property name="use-underline">true</property>
<child> <child>
<object class="GtkSwitch" id="purge_temp_switch"> <object class="GtkSwitch" id="purge_temp_switch">
<property name="visible">true</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property> <property name="valign">center</property>
</object> </object>
@ -185,28 +171,26 @@
</child> </child>
<child> <child>
<object class="GtkListBoxRow"> <object class="GtkListBoxRow">
<property name="visible">true</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">true</property> <property name="margin-top">12</property>
<property name="margin">12</property> <property name="margin-bottom">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="visible">true</property>
<property name="label" translatable="yes">Automatically Delete _Period</property> <property name="label" translatable="yes">Automatically Delete _Period</property>
<property name="use_underline">1</property> <property name="use_underline">1</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="mnemonic_widget">purge_after_combo</property> <property name="mnemonic_widget">purge_after_combo</property>
<property name="sensitive" bind-source="purge_after_combo" bind-property="sensitive"/> <property name="sensitive" bind-source="purge_after_combo" bind-property="sensitive"/>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="valign">center</property> <property name="valign">center</property>
</object> </object>
<packing>
<property name="expand">1</property>
</packing>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="purge_after_combo"> <object class="GtkComboBoxText" id="purge_after_combo">
<property name="visible">true</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="entry_text_column">0</property> <property name="entry_text_column">0</property>
<property name="model">purge_after_model</property> <property name="model">purge_after_model</property>
@ -225,14 +209,12 @@
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">true</property>
<property name="hexpand">true</property> <property name="hexpand">true</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="homogeneous">true</property> <property name="homogeneous">true</property>
<property name="spacing">12</property> <property name="spacing">12</property>
<child> <child>
<object class="GtkButton" id="purge_trash_button"> <object class="GtkButton" id="purge_trash_button">
<property name="visible">true</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="label" translatable="yes">_Empty Trash…</property> <property name="label" translatable="yes">_Empty Trash…</property>
@ -244,7 +226,6 @@
</child> </child>
<child> <child>
<object class="GtkButton" id="purge_temp_button"> <object class="GtkButton" id="purge_temp_button">
<property name="visible">true</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="label" translatable="yes">_Delete Temporary Files…</property> <property name="label" translatable="yes">_Delete Temporary Files…</property>

View file

@ -71,7 +71,7 @@ extern GType cc_ua_panel_get_type (void);
extern GType cc_location_panel_get_type (void); extern GType cc_location_panel_get_type (void);
extern GType cc_camera_panel_get_type (void); extern GType cc_camera_panel_get_type (void);
extern GType cc_microphone_panel_get_type (void); extern GType cc_microphone_panel_get_type (void);
//extern GType cc_usage_panel_get_type (void); extern GType cc_usage_panel_get_type (void);
extern GType cc_lock_panel_get_type (void); extern GType cc_lock_panel_get_type (void);
//extern GType cc_diagnostics_panel_get_type (void); //extern GType cc_diagnostics_panel_get_type (void);
@ -132,7 +132,7 @@ static CcPanelLoaderVtable default_panels[] =
//PANEL_TYPE("thunderbolt", cc_bolt_panel_get_type, NULL), //PANEL_TYPE("thunderbolt", cc_bolt_panel_get_type, NULL),
#endif #endif
PANEL_TYPE("universal-access", cc_ua_panel_get_type, NULL), PANEL_TYPE("universal-access", cc_ua_panel_get_type, NULL),
//PANEL_TYPE("usage", cc_usage_panel_get_type, NULL), PANEL_TYPE("usage", cc_usage_panel_get_type, NULL),
//PANEL_TYPE("user-accounts", cc_user_panel_get_type, NULL), //PANEL_TYPE("user-accounts", cc_user_panel_get_type, NULL),
#ifdef BUILD_WACOM #ifdef BUILD_WACOM
//PANEL_TYPE("wacom", cc_wacom_panel_get_type, cc_wacom_panel_static_init_func), //PANEL_TYPE("wacom", cc_wacom_panel_get_type, cc_wacom_panel_static_init_func),