[file-roller/wip/jtojnar/gobject-modernization: 1/3] window: Use declare type macro




commit b1e9453b99b9696d55597a96544ef5c5d4ec572e
Author: Jan Tojnar <jtojnar gmail com>
Date:   Fri Aug 5 11:43:55 2022 +0200

    window: Use declare type macro
    
    Let’s make the class final. That will require getting rid of the class properties.
    While at it, switch to g_signal_newv.
    
    https://blogs.gnome.org/desrt/2015/01/27/g_declare_finalderivable_type/

 src/fr-window.c | 31 ++++++++++++++++---------------
 src/fr-window.h | 27 ++-------------------------
 2 files changed, 18 insertions(+), 40 deletions(-)
---
diff --git a/src/fr-window.c b/src/fr-window.c
index 6791697a..0d30f378 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -211,10 +211,6 @@ fr_clipboard_data_set_password (FrClipboardData *clipboard_data,
 
 /**/
 
-
-G_DEFINE_TYPE (FrWindow, fr_window, GTK_TYPE_APPLICATION_WINDOW)
-
-
 enum {
        ARCHIVE_LOADED,
        PROGRESS,
@@ -378,6 +374,9 @@ struct _FrWindowPrivate {
 };
 
 
+G_DEFINE_TYPE_WITH_PRIVATE (FrWindow, fr_window, GTK_TYPE_APPLICATION_WINDOW)
+
+
 /* -- fr_window_free_private_data -- */
 
 
@@ -841,34 +840,36 @@ fr_window_class_init (FrWindowClass *klass)
 
        fr_window_parent_class = g_type_class_peek_parent (klass);
 
+       GType archive_loaded_types[] = { G_TYPE_BOOLEAN };
+       GType progress_types[] = { G_TYPE_DOUBLE, G_TYPE_STRING };
+       GType ready_types[] = { G_TYPE_POINTER };
        fr_window_signals[ARCHIVE_LOADED] =
-               g_signal_new ("archive-loaded",
+               g_signal_newv ("archive-loaded",
                              G_TYPE_FROM_CLASS (klass),
                              G_SIGNAL_RUN_LAST,
-                             G_STRUCT_OFFSET (FrWindowClass, archive_loaded),
+                              /* class_closure = */ NULL,
                              NULL, NULL,
                              fr_marshal_VOID__BOOLEAN,
                              G_TYPE_NONE, 1,
-                             G_TYPE_BOOLEAN);
+                             archive_loaded_types);
        fr_window_signals[PROGRESS] =
-               g_signal_new ("progress",
+               g_signal_newv ("progress",
                              G_TYPE_FROM_CLASS (klass),
                              G_SIGNAL_RUN_LAST,
-                             G_STRUCT_OFFSET (FrWindowClass, progress),
+                             /* class_closure = */ NULL,
                              NULL, NULL,
                              fr_marshal_VOID__DOUBLE_STRING,
                              G_TYPE_NONE, 2,
-                             G_TYPE_DOUBLE,
-                             G_TYPE_STRING);
+                             progress_types);
        fr_window_signals[READY] =
-               g_signal_new ("ready",
+               g_signal_newv ("ready",
                              G_TYPE_FROM_CLASS (klass),
                              G_SIGNAL_RUN_LAST,
-                             G_STRUCT_OFFSET (FrWindowClass, ready),
+                             /* class_closure = */ NULL,
                              NULL, NULL,
                              fr_marshal_VOID__POINTER,
                              G_TYPE_NONE, 1,
-                             G_TYPE_POINTER);
+                             ready_types);
 
        gobject_class = G_OBJECT_CLASS (klass);
        gobject_class->finalize = fr_window_finalize;
@@ -883,7 +884,7 @@ fr_window_class_init (FrWindowClass *klass)
 static void
 fr_window_init (FrWindow *window)
 {
-       window->priv = g_new0 (FrWindowPrivate, 1);
+       window->priv = fr_window_get_instance_private (window);
        window->priv->update_dropped_files = FALSE;
        window->priv->dnd_extract_is_running = FALSE;
        window->priv->dnd_extract_finished_with_error = FALSE;
diff --git a/src/fr-window.h b/src/fr-window.h
index 7bbffec5..fae40619 100644
--- a/src/fr-window.h
+++ b/src/fr-window.h
@@ -70,15 +70,9 @@ typedef enum {
 
 /* -- FrWindow -- */
 
-#define FR_TYPE_WINDOW              (fr_window_get_type ())
-#define FR_WINDOW(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), FR_TYPE_WINDOW, FrWindow))
-#define FR_WINDOW_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), FR_WINDOW_TYPE, FrWindowClass))
-#define FR_IS_WINDOW(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FR_TYPE_WINDOW))
-#define FR_IS_WINDOW_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), FR_TYPE_WINDOW))
-#define FR_WINDOW_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), FR_TYPE_WINDOW, FrWindowClass))
+#define FR_TYPE_WINDOW (fr_window_get_type ())
+G_DECLARE_FINAL_TYPE (FrWindow, fr_window, FR, WINDOW, GtkApplicationWindow)
 
-typedef struct _FrWindow        FrWindow;
-typedef struct _FrWindowClass   FrWindowClass;
 typedef struct _FrWindowPrivate FrWindowPrivate;
 
 struct _FrWindow
@@ -87,23 +81,6 @@ struct _FrWindow
        FrWindowPrivate *priv;
        FrArchive *archive;
 };
-
-struct _FrWindowClass
-{
-       GtkApplicationWindowClass __parent_class;
-
-       /*<signals>*/
-
-       void (*archive_loaded) (FrWindow   *window,
-                               gboolean    success);
-       void (*progress)       (FrWindow   *window,
-                               double      fraction,
-                               const char *msg);
-       void (*ready)          (FrWindow   *window,
-                               GError     *error);
-};
-
-GType           fr_window_get_type                     (void);
 GtkWidget *     fr_window_new                          (void);
 void            fr_window_close                        (FrWindow      *window);
 void            fr_window_set_dialog                  (FrWindow      *window,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]