[gnome-control-center] user-accounts: Convert UmHistoryDialog to GtkTemplate
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] user-accounts: Convert UmHistoryDialog to GtkTemplate
- Date: Thu, 8 Nov 2018 20:01:28 +0000 (UTC)
commit c2940dd426075f964ef6b5f61f05b5eef9af4640
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Nov 6 14:16:45 2018 +1300
user-accounts: Convert UmHistoryDialog to GtkTemplate
panels/user-accounts/cc-user-panel.c | 17 +-
panels/user-accounts/meson.build | 2 +-
panels/user-accounts/um-history-dialog.c | 188 ++++++++-------------
panels/user-accounts/um-history-dialog.h | 10 +-
.../history-dialog.ui => um-history-dialog.ui} | 31 ++--
panels/user-accounts/user-accounts.gresource.xml | 2 +-
po/POTFILES.in | 2 +-
7 files changed, 104 insertions(+), 148 deletions(-)
---
diff --git a/panels/user-accounts/cc-user-panel.c b/panels/user-accounts/cc-user-panel.c
index 984aeb559..3802335a2 100644
--- a/panels/user-accounts/cc-user-panel.c
+++ b/panels/user-accounts/cc-user-panel.c
@@ -100,7 +100,6 @@ struct _CcUserPanel {
CcLanguageChooser *language_chooser;
UmPhotoDialog *photo_dialog;
- UmHistoryDialog *history_dialog;
gint other_accounts;
@@ -1071,12 +1070,22 @@ change_fingerprint (CcUserPanel *self)
static void
show_history (CcUserPanel *self)
{
+ UmHistoryDialog *dialog;
ActUser *user;
+ GtkWindow *parent;
+ gint parent_width;
user = get_selected_user (self);
+ dialog = um_history_dialog_new (user);
+
+ parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
+ gtk_window_get_size (parent, &parent_width, NULL);
+ gtk_window_set_default_size (GTK_WINDOW (dialog), parent_width * 0.6, -1);
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
- um_history_dialog_set_user (self->history_dialog, user);
- um_history_dialog_show (self->history_dialog, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET
(self))));
+ gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
@@ -1377,7 +1386,6 @@ cc_user_panel_init (CcUserPanel *self)
self->login_screen_settings = settings_or_null ("org.gnome.login-screen");
self->photo_dialog = um_photo_dialog_new (GTK_WIDGET (self->user_icon_button));
- self->history_dialog = um_history_dialog_new ();
setup_main_window (self);
}
@@ -1391,7 +1399,6 @@ cc_user_panel_dispose (GObject *object)
g_clear_object (&self->login_screen_settings);
- g_clear_pointer (&self->history_dialog, um_history_dialog_free);
if (self->account_dialog) {
gtk_dialog_response (GTK_DIALOG (self->account_dialog), GTK_RESPONSE_DELETE_EVENT);
self->account_dialog = NULL;
diff --git a/panels/user-accounts/meson.build b/panels/user-accounts/meson.build
index 6059aae45..a08469f7f 100644
--- a/panels/user-accounts/meson.build
+++ b/panels/user-accounts/meson.build
@@ -119,9 +119,9 @@ resource_data = files(
'data/account-fingerprint.ui',
'data/carousel.css',
'data/carousel.ui',
- 'data/history-dialog.ui',
'data/join-dialog.ui',
'data/user-accounts-dialog.css',
+ 'um-history-dialog.ui',
)
common_sources += gnome.compile_resources(
diff --git a/panels/user-accounts/um-history-dialog.c b/panels/user-accounts/um-history-dialog.c
index 15d6acf3b..8f434b7b9 100644
--- a/panels/user-accounts/um-history-dialog.c
+++ b/panels/user-accounts/um-history-dialog.c
@@ -33,31 +33,32 @@
#include "cc-util.h"
#include "um-history-dialog.h"
+#include "um-resources.h"
#include "um-utils.h"
-struct _UmHistoryDialog {
- GtkWidget *dialog;
- GtkBuilder *builder;
+struct _UmHistoryDialog
+{
+ GtkDialog parent_instance;
+
+ GtkHeaderBar *header_bar;
+ GtkListBox *history_box;
+ GtkButton *next_button;
+ GtkButton *previous_button;
- GDateTime *week;
- GDateTime *current_week;
+ GDateTime *week;
+ GDateTime *current_week;
- ActUser *user;
+ ActUser *user;
};
+G_DEFINE_TYPE (UmHistoryDialog, um_history_dialog, GTK_TYPE_DIALOG)
+
typedef struct {
gint64 login_time;
gint64 logout_time;
const gchar *type;
} UmLoginHistory;
-static GtkWidget *
-get_widget (UmHistoryDialog *um,
- const char *name)
-{
- return (GtkWidget *)gtk_builder_get_object (um->builder, name);
-}
-
static void
show_week_label (UmHistoryDialog *um)
{
@@ -97,7 +98,7 @@ show_week_label (UmHistoryDialog *um)
g_free (to);
}
- gtk_header_bar_set_subtitle (GTK_HEADER_BAR (get_widget (um, "dialog-header-bar")), label);
+ gtk_header_bar_set_subtitle (um->header_bar, label);
g_free (label);
}
@@ -105,13 +106,11 @@ show_week_label (UmHistoryDialog *um)
static void
clear_history (UmHistoryDialog *um)
{
- GtkWidget *box;
GList *list, *it;
- box = get_widget (um, "history-box");
- list = gtk_container_get_children (GTK_CONTAINER (box));
- for (it = list; it != NULL; it = it->next) {
- gtk_container_remove (GTK_CONTAINER (box), GTK_WIDGET (it->data));
+ list = gtk_container_get_children (GTK_CONTAINER (um->history_box));
+ for (it = list; it != NULL; it = it->next) {
+ gtk_container_remove (GTK_CONTAINER (um->history_box), GTK_WIDGET (it->data));
}
g_list_free (list);
}
@@ -159,14 +158,14 @@ set_sensitivity (UmHistoryDialog *um)
sensitive = g_date_time_to_unix (um->week) > history.login_time;
g_array_free (login_history, TRUE);
}
- gtk_widget_set_sensitive (get_widget (um, "previous-button"), sensitive);
+ gtk_widget_set_sensitive (GTK_WIDGET (um->previous_button), sensitive);
sensitive = (g_date_time_compare (um->current_week, um->week) == 1);
- gtk_widget_set_sensitive (get_widget (um, "next-button"), sensitive);
+ gtk_widget_set_sensitive (GTK_WIDGET (um->next_button), sensitive);
}
static void
-add_record (GtkWidget *box, GDateTime *datetime, gchar *record_string, gint line)
+add_record (UmHistoryDialog *um, GDateTime *datetime, gchar *record_string, gint line)
{
gchar *date, *time, *str;
GtkWidget *label, *row;
@@ -198,7 +197,7 @@ add_record (GtkWidget *box, GDateTime *datetime, gchar *record_string, gint line
g_free (time);
g_date_time_unref (datetime);
- gtk_list_box_insert (GTK_LIST_BOX (box), row, line);
+ gtk_list_box_insert (um->history_box, row, line);
}
static void
@@ -208,7 +207,6 @@ show_week (UmHistoryDialog *um)
GDateTime *datetime, *temp;
gint64 from, to;
gint i, line;
- GtkWidget *box;
UmLoginHistory history;
show_week_label (um);
@@ -233,8 +231,6 @@ show_week (UmHistoryDialog *um)
}
/* Add new session records */
- box = get_widget (um, "history-box");
- gtk_widget_show (box);
line = 0;
for (;i >= 0; i--) {
history = g_array_index (login_history, UmLoginHistory, i);
@@ -251,13 +247,13 @@ show_week (UmHistoryDialog *um)
if (history.logout_time > 0 && history.logout_time < to) {
datetime = g_date_time_new_from_unix_local (history.logout_time);
- add_record (box, datetime, _("Session Ended"), line);
+ add_record (um, datetime, _("Session Ended"), line);
line++;
}
if (history.login_time >= from) {
datetime = g_date_time_new_from_unix_local (history.login_time);
- add_record (box, datetime, _("Session Started"), line);
+ add_record (um, datetime, _("Session Started"), line);
line++;
}
}
@@ -266,8 +262,7 @@ show_week (UmHistoryDialog *um)
}
static void
-show_previous (GtkButton *button,
- UmHistoryDialog *um)
+previous_button_clicked_cb (UmHistoryDialog *um)
{
GDateTime *temp;
@@ -279,8 +274,7 @@ show_previous (GtkButton *button,
}
static void
-show_next (GtkButton *button,
- UmHistoryDialog *um)
+next_button_clicked_cb (UmHistoryDialog *um)
{
GDateTime *temp;
@@ -292,46 +286,58 @@ show_next (GtkButton *button,
}
static void
-update_dialog_title (UmHistoryDialog *um)
+um_history_dialog_dispose (GObject *object)
{
- gchar *title;
-
- /* Translators: This is the title of the "Account Activity" dialog.
- The %s is the user real name. */
- title = g_strdup_printf (_("%s — Account Activity"),
- act_user_get_real_name (um->user));
+ UmHistoryDialog *um = UM_HISTORY_DIALOG (object);
- gtk_window_set_title (GTK_WINDOW (um->dialog), title);
+ g_clear_object (&um->user);
+ g_clear_pointer (&um->week, g_date_time_unref);
+ g_clear_pointer (&um->current_week, g_date_time_unref);
- g_free (title);
+ G_OBJECT_CLASS (um_history_dialog_parent_class)->dispose (object);
}
void
-um_history_dialog_set_user (UmHistoryDialog *um,
- ActUser *user)
+um_history_dialog_class_init (UmHistoryDialogClass *klass)
{
- if (um->user) {
- g_clear_object (&um->user);
- }
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- if (user) {
- um->user = g_object_ref (user);
- }
+ object_class->dispose = um_history_dialog_dispose;
- update_dialog_title (um);
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/user-accounts/um-history-dialog.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, UmHistoryDialog, header_bar);
+ gtk_widget_class_bind_template_child (widget_class, UmHistoryDialog, history_box);
+ gtk_widget_class_bind_template_child (widget_class, UmHistoryDialog, next_button);
+ gtk_widget_class_bind_template_child (widget_class, UmHistoryDialog, previous_button);
+
+ gtk_widget_class_bind_template_callback (widget_class, next_button_clicked_cb);
+ gtk_widget_class_bind_template_callback (widget_class, previous_button_clicked_cb);
}
void
-um_history_dialog_show (UmHistoryDialog *um,
- GtkWindow *parent)
+um_history_dialog_init (UmHistoryDialog *um)
+{
+ g_resources_register (um_get_resource ());
+
+ gtk_widget_init_template (GTK_WIDGET (um));
+}
+
+UmHistoryDialog *
+um_history_dialog_new (ActUser *user)
{
+ UmHistoryDialog *um;
GDateTime *temp, *local;
- gint parent_width;
+ g_autofree gchar *title = NULL;
+
+ g_return_val_if_fail (ACT_IS_USER (user), NULL);
- if (um->week)
- g_date_time_unref (um->week);
- if (um->current_week)
- g_date_time_unref (um->current_week);
+ um = g_object_new (UM_TYPE_HISTORY_DIALOG,
+ "use-header-bar", 1,
+ NULL);
+
+ um->user = g_object_ref (user);
/* Set the first day of this week */
local = g_date_time_new_now_local ();
@@ -344,69 +350,13 @@ um_history_dialog_show (UmHistoryDialog *um,
g_date_time_unref (local);
g_date_time_unref (temp);
- show_week (um);
-
- gtk_window_get_size (parent, &parent_width, NULL);
- gtk_window_set_default_size (GTK_WINDOW (um->dialog), parent_width * 0.6, -1);
- gtk_window_set_transient_for (GTK_WINDOW (um->dialog), parent);
- gtk_window_present (GTK_WINDOW (um->dialog));
-}
-
-UmHistoryDialog *
-um_history_dialog_new (void)
-{
- GError *error = NULL;
- UmHistoryDialog *um;
- GtkWidget *widget;
-
- um = g_new0 (UmHistoryDialog, 1);
- um->builder = gtk_builder_new ();
-
- if (!gtk_builder_add_from_resource (um->builder,
"/org/gnome/control-center/user-accounts/history-dialog.ui", &error)) {
- g_error ("%s", error->message);
- g_error_free (error);
- g_free (um);
-
- return NULL;
- }
-
- um->dialog = get_widget (um, "dialog");
- g_signal_connect (um->dialog, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
-
- widget = get_widget (um, "next-button");
- g_signal_connect (widget, "clicked", G_CALLBACK (show_next), um);
-
- widget = get_widget (um, "previous-button");
- g_signal_connect (widget, "clicked", G_CALLBACK (show_previous), um);
-
- widget = get_widget (um, "next-image");
- gtk_image_set_from_icon_name (GTK_IMAGE (widget),
- "go-next-symbolic",
- GTK_ICON_SIZE_MENU);
+ /* Translators: This is the title of the "Account Activity" dialog.
+ The %s is the user real name. */
+ title = g_strdup_printf (_("%s — Account Activity"),
+ act_user_get_real_name (um->user));
+ gtk_header_bar_set_title (um->header_bar, title);
- widget = get_widget (um, "previous-image");
- gtk_image_set_from_icon_name (GTK_IMAGE (widget),
- "go-previous-symbolic",
- GTK_ICON_SIZE_MENU);
+ show_week (um);
return um;
}
-
-void
-um_history_dialog_free (UmHistoryDialog *um)
-{
- gtk_widget_destroy (um->dialog);
-
- g_clear_object (&um->user);
- g_clear_object (&um->builder);
-
- if (um->week) {
- g_date_time_unref (um->week);
- }
-
- if (um->current_week) {
- g_date_time_unref (um->current_week);
- }
-
- g_free (um);
-}
diff --git a/panels/user-accounts/um-history-dialog.h b/panels/user-accounts/um-history-dialog.h
index 403f62431..4873078b3 100644
--- a/panels/user-accounts/um-history-dialog.h
+++ b/panels/user-accounts/um-history-dialog.h
@@ -25,13 +25,9 @@
G_BEGIN_DECLS
-typedef struct _UmHistoryDialog UmHistoryDialog;
+#define UM_TYPE_HISTORY_DIALOG (um_history_dialog_get_type ())
+G_DECLARE_FINAL_TYPE (UmHistoryDialog, um_history_dialog, UM, HISTORY_DIALOG, GtkDialog)
-UmHistoryDialog *um_history_dialog_new (void);
-void um_history_dialog_free (UmHistoryDialog *dialog);
-void um_history_dialog_set_user (UmHistoryDialog *dialog,
- ActUser *user);
-void um_history_dialog_show (UmHistoryDialog *dialog,
- GtkWindow *parent);
+UmHistoryDialog *um_history_dialog_new (ActUser *user);
G_END_DECLS
diff --git a/panels/user-accounts/data/history-dialog.ui b/panels/user-accounts/um-history-dialog.ui
similarity index 79%
rename from panels/user-accounts/data/history-dialog.ui
rename to panels/user-accounts/um-history-dialog.ui
index a1b5f8a3b..673fe5672 100644
--- a/panels/user-accounts/data/history-dialog.ui
+++ b/panels/user-accounts/um-history-dialog.ui
@@ -1,16 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.8 -->
- <object class="GtkDialog" id="dialog">
+ <template class="UmHistoryDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
- <property name="window_position">center-on-parent</property>
<property name="icon_name">system-users</property>
- <property name="type_hint">dialog</property>
- <property name="use_header_bar">1</property>
<child internal-child="headerbar">
- <object class="GtkHeaderBar" id="dialog-header-bar">
+ <object class="GtkHeaderBar" id="header_bar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_close_button">True</property>
@@ -22,18 +19,21 @@
<class name="linked"/>
</style>
<child>
- <object class="GtkButton" id="previous-button">
+ <object class="GtkButton" id="previous_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="valign">center</property>
+ <signal name="clicked" handler="previous_button_clicked_cb" object="UmHistoryDialog"
swapped="yes"/>
<style>
<class name="image-button"/>
</style>
<child>
- <object class="GtkImage" id="previous-image">
+ <object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="icon_name">go-previous-symbolic</property>
+ <property name="pixel_size">16</property>
</object>
</child>
</object>
@@ -42,18 +42,21 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="next-button">
+ <object class="GtkButton" id="next_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="valign">center</property>
+ <signal name="clicked" handler="next_button_clicked_cb" object="UmHistoryDialog"
swapped="yes"/>
<style>
<class name="image-button"/>
</style>
<child>
- <object class="GtkImage" id="next-image">
+ <object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="icon_name">go-next-symbolic</property>
+ <property name="pixel_size">16</property>
</object>
</child>
</object>
@@ -66,17 +69,17 @@
</object>
</child>
<child internal-child="vbox">
- <object class="GtkBox" id="dialog-vbox1">
+ <object class="GtkBox">
<property name="border_width">0</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkBox" id="box1">
+ <object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <object class="GtkScrolledWindow">
<property name="width_request">350</property>
<property name="height_request">300</property>
<property name="visible">True</property>
@@ -86,7 +89,7 @@
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">none</property>
<child>
- <object class="GtkListBox" id="history-box">
+ <object class="GtkListBox" id="history_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
@@ -110,5 +113,5 @@
</child>
</object>
</child>
- </object>
+ </template>
</interface>
diff --git a/panels/user-accounts/user-accounts.gresource.xml
b/panels/user-accounts/user-accounts.gresource.xml
index 7dd85e684..acef38ed8 100644
--- a/panels/user-accounts/user-accounts.gresource.xml
+++ b/panels/user-accounts/user-accounts.gresource.xml
@@ -7,7 +7,6 @@
<file alias="avatar-chooser.ui" preprocess="xml-stripblanks">data/avatar-chooser.ui</file>
<file alias="join-dialog.ui" preprocess="xml-stripblanks">data/join-dialog.ui</file>
<file alias="account-fingerprint.ui" preprocess="xml-stripblanks">data/account-fingerprint.ui</file>
- <file alias="history-dialog.ui" preprocess="xml-stripblanks">data/history-dialog.ui</file>
<file alias="user-accounts-dialog.css">data/user-accounts-dialog.css</file>
<file alias="carousel.ui" preprocess="xml-stripblanks">data/carousel.ui</file>
<file alias="carousel.css">data/carousel.css</file>
@@ -23,5 +22,6 @@
<file alias="right-little-finger.png">data/icons/right-little-finger.png</file>
<file alias="right-ring-finger.png">data/icons/right-ring-finger.png</file>
<file alias="right-thumb.png">data/icons/right-thumb.png</file>
+ <file preprocess="xml-stripblanks">um-history-dialog.ui</file>
</gresource>
</gresources>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c4dcd0422..7ffdf9dce 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -201,7 +201,6 @@ panels/user-accounts/data/account-dialog.ui
panels/user-accounts/data/account-fingerprint.ui
panels/user-accounts/data/avatar-chooser.ui
panels/user-accounts/data/gnome-user-accounts-panel.desktop.in.in
-panels/user-accounts/data/history-dialog.ui
panels/user-accounts/data/join-dialog.ui
panels/user-accounts/org.gnome.controlcenter.user-accounts.policy.in
panels/user-accounts/pw-utils.c
@@ -209,6 +208,7 @@ panels/user-accounts/run-passwd.c
panels/user-accounts/um-account-dialog.c
panels/user-accounts/um-fingerprint-dialog.c
panels/user-accounts/um-history-dialog.c
+panels/user-accounts/um-history-dialog.ui
panels/user-accounts/um-photo-dialog.c
panels/user-accounts/um-realm-manager.c
panels/user-accounts/um-utils.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]