[gnome-screenshot/wip/exalm/cleanups: 3/16] dialog: Make a GObject
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-screenshot/wip/exalm/cleanups: 3/16] dialog: Make a GObject
- Date: Fri, 3 Apr 2020 02:14:04 +0000 (UTC)
commit 3a1daaed9b24ab39ea4119b2cf6e5e28c46ebd14
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri Apr 3 04:05:44 2020 +0500
dialog: Make a GObject
src/screenshot-application.c | 3 +--
src/screenshot-dialog.c | 41 +++++++++++++++++++++++++++++++++++------
src/screenshot-dialog.h | 10 ++++++++--
3 files changed, 44 insertions(+), 10 deletions(-)
---
diff --git a/src/screenshot-application.c b/src/screenshot-application.c
index 54a2afd..d979220 100644
--- a/src/screenshot-application.c
+++ b/src/screenshot-application.c
@@ -104,8 +104,7 @@ screenshot_close_interactive_dialog (ScreenshotApplication *self)
{
ScreenshotDialog *dialog = self->priv->dialog;
save_folder_to_settings (self);
- gtk_widget_destroy (screenshot_dialog_get_dialog (dialog));
- g_free (dialog);
+ g_object_unref (dialog);
}
static void
diff --git a/src/screenshot-dialog.c b/src/screenshot-dialog.c
index a9ca538..4a1b4e8 100644
--- a/src/screenshot-dialog.c
+++ b/src/screenshot-dialog.c
@@ -27,12 +27,10 @@
#include <string.h>
#include <stdlib.h>
-enum {
- TYPE_IMAGE_PNG,
- LAST_TYPE
-};
+struct _ScreenshotDialog
+{
+ GObject parent_instance;
-struct _ScreenshotDialog {
GdkPixbuf *screenshot;
GdkPixbuf *preview_image;
@@ -50,6 +48,13 @@ struct _ScreenshotDialog {
gpointer user_data;
};
+G_DEFINE_TYPE (ScreenshotDialog, screenshot_dialog, G_TYPE_OBJECT)
+
+enum {
+ TYPE_IMAGE_PNG,
+ LAST_TYPE
+};
+
static GtkTargetEntry drag_types[] =
{
{ "image/png", 0, TYPE_IMAGE_PNG },
@@ -207,6 +212,29 @@ setup_drawing_area (ScreenshotDialog *dialog, GtkBuilder *ui)
G_CALLBACK (drag_data_get), dialog);
}
+static void
+screenshot_dialog_finalize (GObject *object)
+{
+ ScreenshotDialog *self = (ScreenshotDialog *)object;
+
+ gtk_widget_destroy (self->dialog);
+
+ G_OBJECT_CLASS (screenshot_dialog_parent_class)->finalize (object);
+}
+
+static void
+screenshot_dialog_class_init (ScreenshotDialogClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = screenshot_dialog_finalize;
+}
+
+static void
+screenshot_dialog_init (ScreenshotDialog *self)
+{
+}
+
ScreenshotDialog *
screenshot_dialog_new (GdkPixbuf *screenshot,
char *initial_uri,
@@ -227,7 +255,7 @@ screenshot_dialog_new (GdkPixbuf *screenshot,
current_name = g_file_get_basename (tmp_file);
current_folder = g_file_get_uri (parent_file);
- dialog = g_new0 (ScreenshotDialog, 1);
+ dialog = g_object_new (SCREENSHOT_TYPE_DIALOG, NULL);
dialog->screenshot = screenshot;
dialog->callback = f;
dialog->user_data = user_data;
@@ -354,3 +382,4 @@ screenshot_dialog_get_filename_entry (ScreenshotDialog *dialog)
{
return dialog->filename_entry;
}
+
diff --git a/src/screenshot-dialog.h b/src/screenshot-dialog.h
index 8ad83f7..26a917a 100644
--- a/src/screenshot-dialog.h
+++ b/src/screenshot-dialog.h
@@ -21,6 +21,12 @@
#include <gtk/gtk.h>
+G_BEGIN_DECLS
+
+#define SCREENSHOT_TYPE_DIALOG (screenshot_dialog_get_type())
+
+G_DECLARE_FINAL_TYPE (ScreenshotDialog, screenshot_dialog, SCREENSHOT, DIALOG, GObject)
+
typedef enum {
SCREENSHOT_RESPONSE_SAVE,
SCREENSHOT_RESPONSE_COPY,
@@ -30,8 +36,6 @@ typedef enum {
typedef void (*SaveScreenshotCallback) (ScreenshotResponse response, gpointer *user_data);
-typedef struct _ScreenshotDialog ScreenshotDialog;
-
ScreenshotDialog *screenshot_dialog_new (GdkPixbuf *screenshot,
char *initial_uri,
SaveScreenshotCallback f,
@@ -44,3 +48,5 @@ void screenshot_dialog_set_busy (ScreenshotDialog *dialog,
gboolean busy);
GtkWidget *screenshot_dialog_get_dialog (ScreenshotDialog *dialog);
GtkWidget *screenshot_dialog_get_filename_entry (ScreenshotDialog *dialog);
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]