From 3fb1c1dca1ca29e6cd0a3f59e476e3bbaeeff24a Mon Sep 17 00:00:00 2001 From: Felipe Borges Date: Tue, 9 Jan 2018 16:00:41 +0100 Subject: [PATCH] user-accounts: Turn UmPhotoDialog in a full GObject For the new avatar-chooser implementation we will use Gtk+ widget composite templates. https://bugzilla.gnome.org/show_bug.cgi?id=766670 --- panels/user-accounts/um-photo-dialog.c | 38 ++++++++++++++++++-------- panels/user-accounts/um-photo-dialog.h | 4 +++ panels/user-accounts/um-user-panel.c | 4 --- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/panels/user-accounts/um-photo-dialog.c b/panels/user-accounts/um-photo-dialog.c index 600c58342..dc1e7599e 100644 --- a/panels/user-accounts/um-photo-dialog.c +++ b/panels/user-accounts/um-photo-dialog.c @@ -43,6 +43,8 @@ #define AVATAR_PIXEL_SIZE 72 struct _UmPhotoDialog { + GtkPopover parent; + GtkWidget *photo_popup; GtkWidget *popup_button; GtkWidget *crop_area; @@ -58,6 +60,8 @@ struct _UmPhotoDialog { ActUser *user; }; +G_DEFINE_TYPE (UmPhotoDialog, um_photo_dialog, GTK_TYPE_POPOVER) + static void crop_dialog_response (GtkWidget *dialog, gint response_id, @@ -569,7 +573,9 @@ um_photo_dialog_new (GtkWidget *button) { UmPhotoDialog *um; - um = g_new0 (UmPhotoDialog, 1); + um = g_object_new (UM_TYPE_PHOTO_DIALOG, + "relative-to", button, + NULL); um->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL); @@ -591,21 +597,31 @@ um_photo_dialog_new (GtkWidget *button) return um; } -void -um_photo_dialog_free (UmPhotoDialog *um) +static void +um_photo_dialog_dispose (GObject *object) { - gtk_widget_destroy (um->photo_popup); + UmPhotoDialog *um = UM_PHOTO_DIALOG (object); - if (um->thumb_factory) - g_object_unref (um->thumb_factory); + g_clear_object (&um->thumb_factory); #ifdef HAVE_CHEESE - if (um->monitor) - g_object_unref (um->monitor); + g_clear_object (&um->monitor); #endif - if (um->user) - g_object_unref (um->user); + g_clear_object (&um->user); - g_free (um); + G_OBJECT_CLASS (um_photo_dialog_parent_class)->dispose (object); +} + +static void +um_photo_dialog_init (UmPhotoDialog *um) +{ +} + +static void +um_photo_dialog_class_init (UmPhotoDialogClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + + oclass->dispose = um_photo_dialog_dispose; } static void diff --git a/panels/user-accounts/um-photo-dialog.h b/panels/user-accounts/um-photo-dialog.h index 4555c6ae7..fc74a2ed6 100644 --- a/panels/user-accounts/um-photo-dialog.h +++ b/panels/user-accounts/um-photo-dialog.h @@ -26,6 +26,10 @@ G_BEGIN_DECLS +#define UM_TYPE_PHOTO_DIALOG (um_photo_dialog_get_type()) + +G_DECLARE_FINAL_TYPE (UmPhotoDialog, um_photo_dialog, UM, PHOTO_DIALOG, GtkPopover) + typedef struct _UmPhotoDialog UmPhotoDialog; UmPhotoDialog *um_photo_dialog_new (GtkWidget *button); diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c index fd8d5b558..b52fe376b 100644 --- a/panels/user-accounts/um-user-panel.c +++ b/panels/user-accounts/um-user-panel.c @@ -1498,10 +1498,6 @@ cc_user_panel_dispose (GObject *object) um_password_dialog_free (priv->password_dialog); priv->password_dialog = NULL; } - if (priv->photo_dialog) { - um_photo_dialog_free (priv->photo_dialog); - priv->photo_dialog = NULL; - } if (priv->history_dialog) { um_history_dialog_free (priv->history_dialog); priv->history_dialog = NULL;