[gnome-robots] Introduce Vala



commit f87f94542247d53950ede78ea9b751fa55915559
Author: Andrey Kutejko <andy128k gmail com>
Date:   Sun Aug 23 12:27:22 2020 +0200

    Introduce Vala

 meson.build                |  4 +++-
 src/games-file-list.c      | 53 ++--------------------------------------------
 src/image-suffix-list.vala | 44 ++++++++++++++++++++++++++++++++++++++
 src/meson.build            | 25 ++++++++++++++++++++++
 4 files changed, 74 insertions(+), 52 deletions(-)
---
diff --git a/meson.build b/meson.build
index 123531e..db53890 100644
--- a/meson.build
+++ b/meson.build
@@ -1,4 +1,4 @@
-project('gnome-robots', 'c',
+project('gnome-robots', ['vala', 'c'],
     version: '3.38.0')
 
 python3 = import('python3')
@@ -7,11 +7,13 @@ i18n = import('i18n')
 
 application_id = 'org.gnome.Robots'
 
+gee_dependency = dependency('gee-0.8')
 gio_dependency = dependency('gio-2.0', version: '>= 2.32')
 glib_dependency = dependency('glib-2.0', version: '>= 2.32')
 gnome_games_dependency = dependency('libgnome-games-support-1', version: '>= 1.7.1')
 gsound_dependency = dependency('gsound', version: '>= 1.0.2')
 gtk_dependency = dependency('gtk+-3.0', version: '>= 3.24.0')
+gdk_dependency = dependency('gdk-3.0')
 rsvg_dependency = dependency('librsvg-2.0', version: '>= 2.36.2')
 
 bindir      = join_paths(get_option('prefix'), get_option('bindir'))
diff --git a/src/games-file-list.c b/src/games-file-list.c
index 0d2b586..8e1c28c 100644
--- a/src/games-file-list.c
+++ b/src/games-file-list.c
@@ -30,6 +30,7 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include "games-file-list.h"
+#include "riiv.h"
 
 struct GamesFileListPrivate
 {
@@ -145,54 +146,6 @@ games_file_list_transform_basename (GamesFileList * filelist)
   games_file_list_remove_duplicates (filelist);
 }
 
-static GSList *image_suffix_list = NULL;
-static GMutex image_suffix_mutex;
-
-/* We only want to initilise the list of suffixes once, this is
- * the function that does it. It might even be thread safe, not that
- * this has been tested ... */
-static void
-games_image_suffix_list_init (void)
-{
-  GSList *pixbuf_formats;
-  GSList *element;
-  GdkPixbufFormat *formats;
-  gchar **suffices;
-  gchar **suffix;
-
-  g_mutex_lock (&image_suffix_mutex);
-
-  /* This check needs to be inside the lock to make sure that another
-   * thread haasn't half-completed the list. */
-  if (image_suffix_list) {
-    g_mutex_unlock (&image_suffix_mutex);
-    return;
-  }
-
-  pixbuf_formats = gdk_pixbuf_get_formats ();
-
-  /* Search through the list of formats for the suffices. */
-  element = pixbuf_formats;
-  while (element) {
-    formats = element->data;
-    suffices = gdk_pixbuf_format_get_extensions (formats);
-
-    suffix = suffices;
-    while (*suffix) {
-      image_suffix_list = g_slist_append (image_suffix_list, g_strdup_printf (".%s", *suffix));
-      suffix++;
-    }
-
-    g_strfreev (suffices);
-
-    element = g_slist_next (element);
-  }
-
-  g_slist_free (pixbuf_formats);
-
-  g_mutex_unlock (&image_suffix_mutex);
-}
-
 static GList *
 games_file_list_new_images_single (const gchar * directory)
 {
@@ -206,10 +159,8 @@ games_file_list_new_images_single (const gchar * directory)
   if (!dir)
     return NULL;
 
-  games_image_suffix_list_init ();
-
   while ((filename = g_dir_read_name (dir)) != NULL) {
-    suffix = image_suffix_list;
+    suffix = image_suffix_list_get ();
     while (suffix) {
       if (g_str_has_suffix (filename, suffix->data)) {
         fullname = g_build_filename (directory, filename, NULL);
diff --git a/src/image-suffix-list.vala b/src/image-suffix-list.vala
new file mode 100644
index 0000000..e898b38
--- /dev/null
+++ b/src/image-suffix-list.vala
@@ -0,0 +1,44 @@
+/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* image-suffix-list.vala
+    Copyright © 2020 Andrii Kuteiko
+
+    This library is free software; you can redistribute it and'or modify
+    it under the terms of the GNU Library General Public License as published
+    by the Free Software Foundation; either version 3, or (at your option)
+    any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; if not, see <http://www.gnu.org/licenses/>.  */
+
+using Gdk;
+
+namespace ImageSuffixList
+{
+    private static SList<string> list = null;
+    private static Mutex mutex;
+
+    public unowned SList<string> get()
+    {
+        mutex.lock ();
+
+        if (list == null)
+        {
+            Pixbuf.get_formats ().@foreach ((formats) => {
+                var suffices = formats.get_extensions ();
+
+                foreach (var suffix in suffices) {
+                    list.append (".%s".printf (suffix));
+                }
+            });
+        }
+
+        mutex.unlock ();
+
+        return list;
+    }
+}
diff --git a/src/meson.build b/src/meson.build
index 0675107..aebd553 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,3 +1,25 @@
+vala_sources = files(
+    'image-suffix-list.vala'
+)
+
+vala_lib = static_library('riiv',
+    vala_sources,
+    dependencies: [
+        gee_dependency,
+        gio_dependency,
+        glib_dependency,
+        gnome_games_dependency,
+        gsound_dependency,
+        gtk_dependency,
+        gdk_dependency,
+        rsvg_dependency
+    ]
+)
+
+riiv_dependency = declare_dependency(
+    link_with: vala_lib,
+)
+
 sources = files(
     'cursors.c',
     'find-file.c',
@@ -28,11 +50,14 @@ executable(
     sources + resources,
     config_header,
     dependencies: [
+        riiv_dependency,
+        gee_dependency,
         gio_dependency,
         glib_dependency,
         gnome_games_dependency,
         gsound_dependency,
         gtk_dependency,
+        gdk_dependency,
         rsvg_dependency
     ],
     c_args: [


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