[gtranslator/gtk4: 29/52] Subclass from AdwApplication and AdwApplicationWindow




commit e0b5a72c3af8bc3e9ae98f7e142048c75b7e0b52
Author: afshan ahmed khan <afshanahmeda2k gmail com>
Date:   Wed Jul 13 12:38:39 2022 +0530

    Subclass from AdwApplication and AdwApplicationWindow

 src/codeview/gtr-viewer.c           |  5 +++--
 src/gtr-application.c               | 20 +++++++++++---------
 src/gtr-application.h               |  6 +++---
 src/gtr-close-confirmation-dialog.c |  2 --
 src/gtr-search-bar.c                |  1 +
 src/gtr-window.c                    |  2 +-
 src/gtr-window.h                    |  6 +++---
 src/gtr-window.ui                   | 35 ++++++++++++++++++++---------------
 src/main.c                          |  2 +-
 9 files changed, 43 insertions(+), 36 deletions(-)
---
diff --git a/src/codeview/gtr-viewer.c b/src/codeview/gtr-viewer.c
index 58309a77..8757d0e9 100644
--- a/src/codeview/gtr-viewer.c
+++ b/src/codeview/gtr-viewer.c
@@ -409,8 +409,9 @@ static void
 gtr_viewer_destroy (GtkWidget *dlg , GtkWidget **dlg_ptr)
 {
   gtk_window_destroy(GTK_WINDOW(dlg));
-  *dlg_ptr = NULL;
+  g_free(*dlg_ptr);
 }
+
 void
 gtr_show_viewer (GtrWindow *window, const gchar *path, gint line)
 {
@@ -439,7 +440,7 @@ gtr_show_viewer (GtrWindow *window, const gchar *path, gint line)
       g_free (label);
 
       g_signal_connect (dlg,
-                        "destroy", G_CALLBACK (gtk_window_destroy), &dlg);
+                        "destroy", G_CALLBACK (gtr_viewer_destroy),&dlg );
       gtk_widget_show (GTK_WIDGET (dlg));
     }
 
diff --git a/src/gtr-application.c b/src/gtr-application.c
index 0ecb396c..a6f5461d 100644
--- a/src/gtr-application.c
+++ b/src/gtr-application.c
@@ -67,7 +67,7 @@ typedef struct
   guint first_run : 1;
 } GtrApplicationPrivate;
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtrApplication, gtr_application, GTK_TYPE_APPLICATION)
+G_DEFINE_TYPE_WITH_PRIVATE (GtrApplication, gtr_application, ADW_TYPE_APPLICATION)
 
 static gboolean
 ensure_user_config_dir (void)
@@ -659,16 +659,20 @@ gtr_application_startup (GApplication *application)
   GtrApplicationPrivate *priv = gtr_application_get_instance_private (app);
 
   G_APPLICATION_CLASS (gtr_application_parent_class)->startup (application);
-
-  adw_init();
   g_set_application_name (_("Translation Editor"));
   gtk_window_set_default_icon_name (PACKAGE_APPID);
 
+  load_accels ();
+
+  //CLEANUP: As we are now subclassing from AdwApplication thsese all are not needed
+  //adw_init();
+
   /* Custom css */
-  priv->provider = gtk_css_provider_new ();
-  gtk_css_provider_load_from_resource (priv->provider, "/org/gnome/translator/styles.css");
+  //priv->provider = gtk_css_provider_new ();
+  //gtk_css_provider_load_from_resource (priv->provider, "/org/gnome/translator/styles.css");
 
-  load_accels ();
+  //gtk_style_context_add_provider_for_display (gdk_display_get_default (),
+                                             //GTK_STYLE_PROVIDER (priv->provider), 600);
 
   /* TODO Remove in GTK 4 port */
   /*hdy_style_manager_set_color_scheme (hdy_style_manager_get_default (),
@@ -722,8 +726,6 @@ gtr_application_startup (GApplication *application)
   set_kb (application, "app.tm_8", "<Ctrl>8");
   set_kb (application, "app.tm_9", "<Ctrl>9");
 
-  gtk_style_context_add_provider_for_display (gdk_display_get_default (),
-                                             GTK_STYLE_PROVIDER (priv->provider), 600);
 }
 
 static void
@@ -810,7 +812,7 @@ gtr_application_class_init (GtrApplicationClass *klass)
 }
 
 GtrApplication *
-_gtr_application_new ()
+gtr_application_new ()
 {
   return GTR_APPLICATION (g_object_new (GTR_TYPE_APPLICATION,
                                         "application-id", PACKAGE_APPID,
diff --git a/src/gtr-application.h b/src/gtr-application.h
index 204da3bd..1322fce7 100644
--- a/src/gtr-application.h
+++ b/src/gtr-application.h
@@ -45,17 +45,17 @@ typedef struct _GtrApplicationClass   GtrApplicationClass;
 
 struct _GtrApplication
 {
-  GtkApplication base_instance;
+  AdwApplication base_instance;
 };
 
 struct _GtrApplicationClass
 {
-  GtkApplicationClass parent_class;
+  AdwApplicationClass parent_class;
 };
 
 GType             gtr_application_get_type               (void)G_GNUC_CONST;
 
-GtrApplication  *_gtr_application_new                    (void);
+GtrApplication  * gtr_application_new                    (void);
 
 GList *           gtr_application_get_views              (GtrApplication *app,
                                                           gboolean        original,
diff --git a/src/gtr-close-confirmation-dialog.c b/src/gtr-close-confirmation-dialog.c
index 82a85411..33475d9e 100644
--- a/src/gtr-close-confirmation-dialog.c
+++ b/src/gtr-close-confirmation-dialog.c
@@ -400,8 +400,6 @@ build_single_doc_dialog (GtrCloseConfirmationDialog * dlg)
 
   gtk_box_append (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
                   hbox);
-
-  gtk_widget_show (hbox);
 }
 
 static void
diff --git a/src/gtr-search-bar.c b/src/gtr-search-bar.c
index 79fccaa5..05727d99 100644
--- a/src/gtr-search-bar.c
+++ b/src/gtr-search-bar.c
@@ -299,6 +299,7 @@ insert_text_handler (GtkEditable * editable,
   gchar *escaped_text;
   gint new_len;
 
+//CLEANUP:May be this should be removed as it will always be false
   /* To avoid recursive behavior */
   if (insert_text)
     return;
diff --git a/src/gtr-window.c b/src/gtr-window.c
index e4b305d4..507cb7fb 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -92,7 +92,7 @@ typedef struct
   guint dispose_has_run : 1;
 } GtrWindowPrivate;
 
-G_DEFINE_FINAL_TYPE_WITH_PRIVATE(GtrWindow, gtr_window, GTK_TYPE_APPLICATION_WINDOW)
+G_DEFINE_FINAL_TYPE_WITH_PRIVATE(GtrWindow, gtr_window, ADW_TYPE_APPLICATION_WINDOW)
 
 enum
 {
diff --git a/src/gtr-window.h b/src/gtr-window.h
index dfd5822b..79ca2ffe 100644
--- a/src/gtr-window.h
+++ b/src/gtr-window.h
@@ -36,16 +36,16 @@ G_BEGIN_DECLS
 
 #define GTR_TYPE_WINDOW                (gtr_window_get_type ())
 
-G_DECLARE_FINAL_TYPE (GtrWindow, gtr_window, GTR, WINDOW, GtkApplicationWindow)
+G_DECLARE_FINAL_TYPE (GtrWindow, gtr_window, GTR, WINDOW, AdwApplicationWindow)
 
 struct _GtrWindow
 {
-  GtkApplicationWindow parent_instance;
+  AdwApplicationWindow parent_instance;
 };
 
 struct _GtrWindowClass
 {
-  GtkApplicationWindowClass parent_class;
+  AdwApplicationWindowClass parent_class;
 };
 
 GtrTab *gtr_window_create_tab (GtrWindow * window, GtrPo * po);
diff --git a/src/gtr-window.ui b/src/gtr-window.ui
index 3337a157..8fe44cc3 100644
--- a/src/gtr-window.ui
+++ b/src/gtr-window.ui
@@ -1,32 +1,37 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk" version="4.0"/>
-  <template class="GtrWindow" parent="GtkApplicationWindow">
+  <requires lib="gtk" version="4.0" />
+  <template class="GtrWindow" parent="AdwApplicationWindow">
     <property name="default_width">800</property>
     <property name="default_height">600</property>
-    <child type="titlebar">
-      <object class="GtkStack" id="header_stack">
-        <property name="vexpand">1</property>
+    <property name="content">
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
         <child>
-          <object class="GtkHeaderBar" id="header_bar">
-            <!--<child type="end">
+          <object class="GtkStack" id="header_stack">
+            <!--<property name="vexpand">1</property>-->
+            <child>
+              <object class="GtkHeaderBar" id="header_bar">
+                <!--<child type="end">
               <object class="GtkMenuButton" id="menu_button">
                 <property name="icon_name">open-menu-symbolic</property>
               </object>
             </child>-->
+              </object>
+            </child>
           </object>
         </child>
-      </object>
-    </child>
-    <child>
-      <object class="GtkBox" id="main_box">
-        <property name="orientation">vertical</property>
         <child>
-          <object class="GtkStack" id="stack">
-            <property name="vexpand">1</property>
+          <object class="GtkBox" id="main_box">
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkStack" id="stack">
+                <property name="vexpand">1</property>
+              </object>
+            </child>
           </object>
         </child>
       </object>
-    </child>
+    </property>
   </template>
 </interface>
diff --git a/src/main.c b/src/main.c
index 2323e282..4b19ba3d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -107,7 +107,7 @@ main (gint argc, gchar * argv[])
   g_option_context_free (context);
 #endif
 
-  app = _gtr_application_new ();
+  app = gtr_application_new ();
 
   status = g_application_run (G_APPLICATION (app), argc, argv);
 


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