[gtksourceview/wip/chergert/gsv-gtk4: 32/259] language: modernize GtkSourceLanguageManager




commit 7d9008a110665911a99d3c2d049314dad628271c
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 9 09:22:40 2020 -0800

    language: modernize GtkSourceLanguageManager
    
     - Use G_DECLARE_ macros
     - Make object final
     - Fix spacing style for multi-line functions

 gtksourceview/gtksourceautocleanups.h    |   1 -
 gtksourceview/gtksourcelanguagemanager.c | 116 ++++++++++++++++---------------
 gtksourceview/gtksourcelanguagemanager.h |  59 ++++------------
 3 files changed, 73 insertions(+), 103 deletions(-)
---
diff --git a/gtksourceview/gtksourceautocleanups.h b/gtksourceview/gtksourceautocleanups.h
index 67d113ac..fe3d5e0a 100644
--- a/gtksourceview/gtksourceautocleanups.h
+++ b/gtksourceview/gtksourceautocleanups.h
@@ -28,7 +28,6 @@ G_BEGIN_DECLS
 
 #ifndef __GI_SCANNER__
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceLanguageManager, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceMark, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceMap, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourcePrintCompositor, g_object_unref)
diff --git a/gtksourceview/gtksourcelanguagemanager.c b/gtksourceview/gtksourcelanguagemanager.c
index 030ec99d..a3745d1b 100644
--- a/gtksourceview/gtksourcelanguagemanager.c
+++ b/gtksourceview/gtksourcelanguagemanager.c
@@ -44,9 +44,9 @@
  * given file name and content type.
  */
 
-#define RNG_SCHEMA_FILE                "language2.rng"
-#define LANGUAGE_DIR           "language-specs"
-#define LANG_FILE_SUFFIX       ".lang"
+#define RNG_SCHEMA_FILE   "language2.rng"
+#define LANGUAGE_DIR      "language-specs"
+#define LANG_FILE_SUFFIX  ".lang"
 
 enum {
        PROP_0,
@@ -54,8 +54,10 @@ enum {
        PROP_LANGUAGE_IDS
 };
 
-struct _GtkSourceLanguageManagerPrivate
+struct _GtkSourceLanguageManager
 {
+       GObject          parent_instance;
+
        GHashTable      *language_ids;
 
        gchar          **lang_dirs;
@@ -66,13 +68,13 @@ struct _GtkSourceLanguageManagerPrivate
 
 static GtkSourceLanguageManager *default_instance;
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceLanguageManager, gtk_source_language_manager, G_TYPE_OBJECT)
+G_DEFINE_TYPE (GtkSourceLanguageManager, gtk_source_language_manager, G_TYPE_OBJECT)
 
 static void
-gtk_source_language_manager_set_property (GObject      *object,
-                                         guint          prop_id,
-                                         const GValue *value,
-                                         GParamSpec    *pspec)
+gtk_source_language_manager_set_property (GObject      *object,
+                                          guint         prop_id,
+                                          const GValue *value,
+                                          GParamSpec   *pspec)
 {
        GtkSourceLanguageManager *lm;
 
@@ -91,10 +93,10 @@ gtk_source_language_manager_set_property (GObject   *object,
 }
 
 static void
-gtk_source_language_manager_get_property (GObject      *object,
-                                         guint          prop_id,
-                                         GValue        *value,
-                                         GParamSpec    *pspec)
+gtk_source_language_manager_get_property (GObject    *object,
+                                          guint       prop_id,
+                                          GValue     *value,
+                                          GParamSpec *pspec)
 {
        GtkSourceLanguageManager *lm;
 
@@ -119,17 +121,15 @@ gtk_source_language_manager_get_property (GObject         *object,
 static void
 gtk_source_language_manager_finalize (GObject *object)
 {
-       GtkSourceLanguageManager *lm;
-
-       lm = GTK_SOURCE_LANGUAGE_MANAGER (object);
+       GtkSourceLanguageManager *lm = GTK_SOURCE_LANGUAGE_MANAGER (object);
 
-       if (lm->priv->language_ids)
-               g_hash_table_destroy (lm->priv->language_ids);
+       if (lm->language_ids)
+               g_hash_table_destroy (lm->language_ids);
 
-       g_strfreev (lm->priv->ids);
+       g_strfreev (lm->ids);
 
-       g_strfreev (lm->priv->lang_dirs);
-       g_free (lm->priv->rng_file);
+       g_strfreev (lm->lang_dirs);
+       g_free (lm->rng_file);
 
        G_OBJECT_CLASS (gtk_source_language_manager_parent_class)->finalize (object);
 }
@@ -168,11 +168,11 @@ gtk_source_language_manager_class_init (GtkSourceLanguageManagerClass *klass)
 static void
 gtk_source_language_manager_init (GtkSourceLanguageManager *lm)
 {
-       lm->priv = gtk_source_language_manager_get_instance_private (lm);
-       lm->priv->language_ids = NULL;
-       lm->priv->ids = NULL;
-       lm->priv->lang_dirs = NULL;
-       lm->priv->rng_file = NULL;
+       lm = gtk_source_language_manager_get_instance_private (lm);
+       lm->language_ids = NULL;
+       lm->ids = NULL;
+       lm->lang_dirs = NULL;
+       lm->rng_file = NULL;
 }
 
 /**
@@ -244,8 +244,8 @@ notify_search_path (GtkSourceLanguageManager *mgr)
  * </note>
  */
 void
-gtk_source_language_manager_set_search_path (GtkSourceLanguageManager *lm,
-                                            gchar                   **dirs)
+gtk_source_language_manager_set_search_path (GtkSourceLanguageManager  *lm,
+                                             gchar                    **dirs)
 {
        gchar **tmp;
 
@@ -253,14 +253,14 @@ gtk_source_language_manager_set_search_path (GtkSourceLanguageManager *lm,
 
        /* Search path cannot be changed in the list of available languages
         * as been already computed */
-       g_return_if_fail (lm->priv->ids == NULL);
+       g_return_if_fail (lm->ids == NULL);
 
-       tmp = lm->priv->lang_dirs;
+       tmp = lm->lang_dirs;
 
        if (dirs == NULL)
-               lm->priv->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
+               lm->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
        else
-               lm->priv->lang_dirs = g_strdupv (dirs);
+               lm->lang_dirs = g_strdupv (dirs);
 
        g_strfreev (tmp);
 
@@ -282,10 +282,10 @@ gtk_source_language_manager_get_search_path (GtkSourceLanguageManager *lm)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE_MANAGER (lm), NULL);
 
-       if (lm->priv->lang_dirs == NULL)
-               lm->priv->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
+       if (lm->lang_dirs == NULL)
+               lm->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
 
-       return (const gchar * const *)lm->priv->lang_dirs;
+       return (const gchar * const *)lm->lang_dirs;
 }
 
 /**
@@ -301,7 +301,7 @@ _gtk_source_language_manager_get_rng_file (GtkSourceLanguageManager *lm)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE_MANAGER (lm), NULL);
 
-       if (lm->priv->rng_file == NULL)
+       if (lm->rng_file == NULL)
        {
                const gchar * const *dirs;
 
@@ -314,7 +314,7 @@ _gtk_source_language_manager_get_rng_file (GtkSourceLanguageManager *lm)
                        file = g_build_filename (*dirs, RNG_SCHEMA_FILE, NULL);
                        if (g_file_test (file, G_FILE_TEST_EXISTS))
                        {
-                               lm->priv->rng_file = file;
+                               lm->rng_file = file;
                                break;
                        }
 
@@ -322,11 +322,13 @@ _gtk_source_language_manager_get_rng_file (GtkSourceLanguageManager *lm)
                }
        }
 
-       return lm->priv->rng_file;
+       return lm->rng_file;
 }
 
 static gint
-language_compare (const gchar **id1, const gchar **id2, GHashTable *language_ids)
+language_compare (const gchar **id1,
+                  const gchar **id2,
+                  GHashTable   *language_ids)
 {
        GtkSourceLanguage *lang1, *lang2;
        const gchar *name1, *name2;
@@ -346,10 +348,10 @@ ensure_languages (GtkSourceLanguageManager *lm)
        GSList *filenames, *l;
        GPtrArray *ids_array = NULL;
 
-       if (lm->priv->language_ids != NULL)
+       if (lm->language_ids != NULL)
                return;
 
-       lm->priv->language_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
+       lm->language_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                        g_free, g_object_unref);
 
        filenames = _gtk_source_utils_get_file_list ((gchar **)gtk_source_language_manager_get_search_path 
(lm),
@@ -374,9 +376,9 @@ ensure_languages (GtkSourceLanguageManager *lm)
 
                id = gtk_source_language_get_id (lang);
 
-               if (g_hash_table_lookup (lm->priv->language_ids, id) == NULL)
+               if (g_hash_table_lookup (lm->language_ids, id) == NULL)
                {
-                       g_hash_table_insert (lm->priv->language_ids,
+                       g_hash_table_insert (lm->language_ids,
                                             g_strdup (id),
                                             lang);
 
@@ -397,12 +399,12 @@ ensure_languages (GtkSourceLanguageManager *lm)
                 * is ready to use in a list of a GUI */
                g_ptr_array_sort_with_data (ids_array,
                                            (GCompareDataFunc)language_compare,
-                                           lm->priv->language_ids);
+                                           lm->language_ids);
 
                /* Ensure the array is NULL terminated */
                g_ptr_array_add (ids_array, NULL);
 
-               lm->priv->ids = (gchar **)g_ptr_array_free (ids_array, FALSE);
+               lm->ids = (gchar **)g_ptr_array_free (ids_array, FALSE);
        }
 
        g_slist_free_full (filenames, g_free);
@@ -427,7 +429,7 @@ gtk_source_language_manager_get_language_ids (GtkSourceLanguageManager *lm)
 
        ensure_languages (lm);
 
-       return (const gchar * const *)lm->priv->ids;
+       return (const gchar * const *)lm->ids;
 }
 
 /**
@@ -444,19 +446,19 @@ gtk_source_language_manager_get_language_ids (GtkSourceLanguageManager *lm)
  */
 GtkSourceLanguage *
 gtk_source_language_manager_get_language (GtkSourceLanguageManager *lm,
-                                         const gchar              *id)
+                                          const gchar              *id)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE_MANAGER (lm), NULL);
        g_return_val_if_fail (id != NULL, NULL);
 
        ensure_languages (lm);
 
-       return g_hash_table_lookup (lm->priv->language_ids, id);
+       return g_hash_table_lookup (lm->language_ids, id);
 }
 
 static GSList *
 pick_langs_for_filename (GtkSourceLanguageManager *lm,
-                        const gchar              *filename)
+                         const gchar              *filename)
 {
        char *filename_utf8;
        const gchar* const * p;
@@ -498,8 +500,8 @@ pick_langs_for_filename (GtkSourceLanguageManager *lm,
 
 static GtkSourceLanguage *
 pick_lang_for_mime_type_pass (GtkSourceLanguageManager *lm,
-                             const char               *mime_type,
-                             gboolean                  exact_match)
+                              const char               *mime_type,
+                              gboolean                  exact_match)
 {
        const gchar* const * id_ptr;
 
@@ -537,7 +539,7 @@ pick_lang_for_mime_type_pass (GtkSourceLanguageManager *lm,
 
 static GtkSourceLanguage *
 pick_lang_for_mime_type_real (GtkSourceLanguageManager *lm,
-                             const char               *mime_type)
+                              const char               *mime_type)
 {
        GtkSourceLanguage *lang;
        lang = pick_lang_for_mime_type_pass (lm, mime_type, TRUE);
@@ -549,8 +551,8 @@ pick_lang_for_mime_type_real (GtkSourceLanguageManager *lm,
 #ifdef G_OS_WIN32
 static void
 grok_win32_content_type (const gchar  *content_type,
-                        gchar       **alt_filename,
-                        gchar       **mime_type)
+                         gchar       **alt_filename,
+                         gchar       **mime_type)
 {
        *alt_filename = NULL;
        *mime_type = NULL;
@@ -566,7 +568,7 @@ grok_win32_content_type (const gchar  *content_type,
 
 static GtkSourceLanguage *
 pick_lang_for_mime_type (GtkSourceLanguageManager *lm,
-                        const gchar              *content_type)
+                         const gchar              *content_type)
 {
        GtkSourceLanguage *lang = NULL;
 
@@ -646,8 +648,8 @@ pick_lang_for_mime_type (GtkSourceLanguageManager *lm,
  */
 GtkSourceLanguage *
 gtk_source_language_manager_guess_language (GtkSourceLanguageManager *lm,
-                                           const gchar              *filename,
-                                           const gchar              *content_type)
+                                            const gchar              *filename,
+                                            const gchar              *content_type)
 {
        GtkSourceLanguage *lang = NULL;
        GSList *langs = NULL;
diff --git a/gtksourceview/gtksourcelanguagemanager.h b/gtksourceview/gtksourcelanguagemanager.h
index 90609fe3..e1f2f741 100644
--- a/gtksourceview/gtksourcelanguagemanager.h
+++ b/gtksourceview/gtksourcelanguagemanager.h
@@ -29,61 +29,30 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_LANGUAGE_MANAGER               (gtk_source_language_manager_get_type ())
-#define GTK_SOURCE_LANGUAGE_MANAGER(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER, GtkSourceLanguageManager))
-#define GTK_SOURCE_LANGUAGE_MANAGER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER, GtkSourceLanguageManagerClass))
-#define GTK_SOURCE_IS_LANGUAGE_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER))
-#define GTK_SOURCE_IS_LANGUAGE_MANAGER_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER))
-#define GTK_SOURCE_LANGUAGE_MANAGER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER, GtkSourceLanguageManagerClass))
-
-
-typedef struct _GtkSourceLanguageManagerClass  GtkSourceLanguageManagerClass;
-typedef struct _GtkSourceLanguageManagerPrivate GtkSourceLanguageManagerPrivate;
-
-struct _GtkSourceLanguageManager
-{
-       GObject parent_instance;
-
-       GtkSourceLanguageManagerPrivate *priv;
-};
-
-struct _GtkSourceLanguageManagerClass
-{
-       GObjectClass parent_class;
-
-       /* Padding for future expansion */
-       gpointer padding[10];
-};
+#define GTK_SOURCE_TYPE_LANGUAGE_MANAGER (gtk_source_language_manager_get_type())
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GType                    gtk_source_language_manager_get_type                  (void) G_GNUC_CONST;
+G_DECLARE_FINAL_TYPE (GtkSourceLanguageManager, gtk_source_language_manager, GTK_SOURCE, LANGUAGE_MANAGER, 
GObject)
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguageManager *gtk_source_language_manager_new                      (void);
-
+GtkSourceLanguageManager *gtk_source_language_manager_new              (void);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguageManager *gtk_source_language_manager_get_default              (void);
-
+GtkSourceLanguageManager *gtk_source_language_manager_get_default      (void);
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const *    gtk_source_language_manager_get_search_path           (GtkSourceLanguageManager 
*lm);
-
+const gchar * const      *gtk_source_language_manager_get_search_path  (GtkSourceLanguageManager  *lm);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_language_manager_set_search_path           (GtkSourceLanguageManager *lm,
-                                                                                gchar                   
**dirs);
-
+void                      gtk_source_language_manager_set_search_path  (GtkSourceLanguageManager  *lm,
+                                                                        gchar                    **dirs);
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const *    gtk_source_language_manager_get_language_ids          (GtkSourceLanguageManager 
*lm);
-
+const gchar * const      *gtk_source_language_manager_get_language_ids (GtkSourceLanguageManager  *lm);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguage       *gtk_source_language_manager_get_language              (GtkSourceLanguageManager *lm,
-                                                                                const gchar              
*id);
-
+GtkSourceLanguage        *gtk_source_language_manager_get_language     (GtkSourceLanguageManager  *lm,
+                                                                        const gchar               *id);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguage       *gtk_source_language_manager_guess_language            (GtkSourceLanguageManager *lm,
-                                                                                const gchar              
*filename,
-                                                                                const gchar              
*content_type);
-
+GtkSourceLanguage        *gtk_source_language_manager_guess_language   (GtkSourceLanguageManager  *lm,
+                                                                        const gchar               *filename,
+                                                                        const gchar               
*content_type);
 G_GNUC_INTERNAL
-GtkSourceLanguageManager *_gtk_source_language_manager_peek_default            (void);
+GtkSourceLanguageManager *_gtk_source_language_manager_peek_default    (void);
 
 G_END_DECLS


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