[gnome-latex] Use tepl_utils_get_file_extension() and get_file_shortname()



commit 8f08c46193885dee7e65a6ef15c563eb0ad63dae
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Nov 18 11:02:32 2019 +0100

    Use tepl_utils_get_file_extension() and get_file_shortname()

 README                                  |  2 +-
 configure.ac                            |  2 +-
 docs/reference/gnome-latex-sections.txt |  2 --
 src/clean_build_files.vala              |  2 +-
 src/file_browser.vala                   |  4 +--
 src/liblatexila/latexila-build-job.c    |  3 +-
 src/liblatexila/latexila-build-tool.c   |  5 +--
 src/liblatexila/latexila-synctex.c      |  5 +--
 src/liblatexila/latexila-utils.c        | 63 ++-------------------------------
 src/liblatexila/latexila-utils.h        |  4 ---
 src/main_window_build_tools.vala        |  4 +--
 tests/test-utils.c                      | 42 ----------------------
 12 files changed, 17 insertions(+), 121 deletions(-)
---
diff --git a/README b/README
index f8f134f..97e305e 100644
--- a/README
+++ b/README
@@ -21,7 +21,7 @@ Dependencies
 * GLib >= 2.56
 * GTK+ >= 3.22
 * GtkSourceView >= 4.0
-* Tepl >= 4.2 - https://wiki.gnome.org/Projects/Tepl
+* Tepl >= 4.3 - https://wiki.gnome.org/Projects/Tepl
 * gspell >= 1.8
 * gee-0.8 >= 0.10
 * gsettings-desktop-schemas
diff --git a/configure.ac b/configure.ac
index 3dfcd36..fc77e52 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,7 +31,7 @@ LT_INIT
 GLIB_REQUIRED_VERSION="2.56"
 GTK_REQUIRED_VERSION="3.22"
 GTKSOURCEVIEW_REQUIRED_VERSION="4.0"
-TEPL_REQUIRED_VERSION="4.2"
+TEPL_REQUIRED_VERSION="4.3"
 GSPELL_REQUIRED_VERSION="1.8"
 VALA_REQUIRED_VERSION="0.34"
 GEE_REQUIRED_VERSION="0.10"
diff --git a/docs/reference/gnome-latex-sections.txt b/docs/reference/gnome-latex-sections.txt
index 74dcae7..bb76537 100644
--- a/docs/reference/gnome-latex-sections.txt
+++ b/docs/reference/gnome-latex-sections.txt
@@ -267,8 +267,6 @@ LATEXILA_TYPE_TEMPLATES_PERSONAL
 
 <SECTION>
 <FILE>utils</FILE>
-latexila_utils_get_shortname
-latexila_utils_get_extension
 latexila_utils_replace_home_dir_with_tilde
 latexila_utils_file_query_exists_async
 latexila_utils_file_query_exists_finish
diff --git a/src/clean_build_files.vala b/src/clean_build_files.vala
index 681f3e3..b9e7193 100644
--- a/src/clean_build_files.vala
+++ b/src/clean_build_files.vala
@@ -89,7 +89,7 @@ public class CleanBuildFiles : GLib.Object
         string exts = _settings.get_string ("clean-extensions");
         string[] extensions = exts.split (" ");
 
-        string shortname = Latexila.utils_get_shortname (location.get_basename ());
+        string shortname = Tepl.utils_get_file_shortname (location.get_basename ());
 
         Gee.ArrayList<File> files_to_delete = new Gee.ArrayList<File> ();
 
diff --git a/src/file_browser.vala b/src/file_browser.vala
index 9faabb2..0ece95b 100644
--- a/src/file_browser.vala
+++ b/src/file_browser.vala
@@ -176,7 +176,7 @@ public class FileBrowser : Grid
                 return;
             }
 
-            string extension = Latexila.utils_get_extension (basename);
+            string extension = Tepl.utils_get_file_extension (basename);
             if (extension != ".dvi" &&
                 extension != ".pdf" &&
                 extension != ".ps")
@@ -504,7 +504,7 @@ public class FileBrowser : Grid
                     continue;
             }
 
-            string extension = Latexila.utils_get_extension (basename);
+            string extension = Tepl.utils_get_file_extension (basename);
             string icon_name = get_extension_icon_name (extension);
             insert_file (false, icon_name, basename);
         }
diff --git a/src/liblatexila/latexila-build-job.c b/src/liblatexila/latexila-build-job.c
index 892a689..116bcbb 100644
--- a/src/liblatexila/latexila-build-job.c
+++ b/src/liblatexila/latexila-build-job.c
@@ -28,6 +28,7 @@
 #include "latexila-build-job.h"
 #include <string.h>
 #include <glib/gi18n.h>
+#include <tepl/tepl.h>
 #include "latexila-build-view.h"
 #include "latexila-post-processor-all-output.h"
 #include "latexila-post-processor-latex.h"
@@ -271,7 +272,7 @@ get_command_argv (GTask     *task,
 
        /* Replace placeholders */
        base_filename = g_file_get_basename (data->file);
-       base_shortname = latexila_utils_get_shortname (base_filename);
+       base_shortname = tepl_utils_get_file_shortname (base_filename);
 
        for (i = 0; argv[i] != NULL; i++)
        {
diff --git a/src/liblatexila/latexila-build-tool.c b/src/liblatexila/latexila-build-tool.c
index 3c526a9..177ffda 100644
--- a/src/liblatexila/latexila-build-tool.c
+++ b/src/liblatexila/latexila-build-tool.c
@@ -31,6 +31,7 @@
 #include "latexila-build-tool.h"
 #include <string.h>
 #include <glib/gi18n.h>
+#include <tepl/tepl.h>
 #include "latexila-build-job.h"
 #include "latexila-build-view.h"
 #include "latexila-utils.h"
@@ -664,8 +665,8 @@ open_file (GTask *task)
        filename = g_file_get_uri (data->file);
        filename_for_display = g_file_get_parse_name (data->file);
 
-       shortname = latexila_utils_get_shortname (filename);
-       shortname_for_display = latexila_utils_get_shortname (filename_for_display);
+       shortname = tepl_utils_get_file_shortname (filename);
+       shortname_for_display = tepl_utils_get_file_shortname (filename_for_display);
 
        if (strstr (file_to_open, "$filename") != NULL)
        {
diff --git a/src/liblatexila/latexila-synctex.c b/src/liblatexila/latexila-synctex.c
index 7120f28..cd56850 100644
--- a/src/liblatexila/latexila-synctex.c
+++ b/src/liblatexila/latexila-synctex.c
@@ -40,6 +40,7 @@
 
 #include "latexila-synctex.h"
 #include <glib/gi18n.h>
+#include <tepl/tepl.h>
 #include "evince-gdbus-generated.h"
 #include "latexila-utils.h"
 
@@ -208,7 +209,7 @@ get_pdf_uri (GFile *main_tex_file)
        gchar *pdf_uri;
 
        tex_uri = g_file_get_uri (main_tex_file);
-       short_uri = latexila_utils_get_shortname (tex_uri);
+       short_uri = tepl_utils_get_file_shortname (tex_uri);
        pdf_uri = g_strdup_printf ("%s.pdf", short_uri);
 
        g_free (tex_uri);
@@ -605,7 +606,7 @@ pdf_file_query_exists_cb (GFile             *pdf_file,
                return;
        }
 
-       short_uri = latexila_utils_get_shortname (data->pdf_uri);
+       short_uri = tepl_utils_get_file_shortname (data->pdf_uri);
        synctex_uri = g_strdup_printf ("%s.synctex.gz", short_uri);
        synctex_file = g_file_new_for_uri (synctex_uri);
        g_free (short_uri);
diff --git a/src/liblatexila/latexila-utils.c b/src/liblatexila/latexila-utils.c
index af9dbd4..abb51a2 100644
--- a/src/liblatexila/latexila-utils.c
+++ b/src/liblatexila/latexila-utils.c
@@ -33,72 +33,13 @@
 #include "config.h"
 #include "latexila-utils.h"
 #include <string.h>
+#include <tepl/tepl.h>
 #include "latexila-synctex.h"
 
 #if HAVE_DCONF_MIGRATION
 #include "dh-dconf-migration.h"
 #endif
 
-static gint
-get_extension_position (const gchar *filename)
-{
-       const gchar *pos;
-       gint length;
-
-       if (filename == NULL)
-       {
-               return 0;
-       }
-
-       length = strlen (filename);
-       pos = filename + length;
-       g_assert (pos[0] == '\0');
-
-       while (TRUE)
-       {
-               pos = g_utf8_find_prev_char (filename, pos);
-
-               if (pos == NULL || pos[0] == '/')
-               {
-                       break;
-               }
-
-               if (pos[0] == '.')
-               {
-                       return pos - filename;
-               }
-       }
-
-       return length;
-}
-
-/**
- * latexila_utils_get_shortname:
- * @filename: a filename.
- *
- * Returns: the @filename without its extension. Free with g_free().
- */
-gchar *
-latexila_utils_get_shortname (const gchar *filename)
-{
-       return g_strndup (filename, get_extension_position (filename));
-}
-
-/**
- * latexila_utils_get_extension:
- * @filename: a filename.
- *
- * Returns: the @filename's extension with the dot, in lowercase. Free with
- * g_free().
- */
-gchar *
-latexila_utils_get_extension (const gchar *filename)
-{
-       gint pos = get_extension_position (filename);
-
-       return g_ascii_strdown (filename + pos, -1);
-}
-
 /**
  * latexila_utils_replace_home_dir_with_tilde:
  * @filename: the filename.
@@ -359,7 +300,7 @@ latexila_utils_show_uri (GtkWidget    *widget,
 
        if (gtk_show_uri_on_window (parent, uri, timestamp, error))
        {
-               gchar *extension = latexila_utils_get_extension (uri);
+               gchar *extension = tepl_utils_get_file_extension (uri);
 
                if (g_strcmp0 (extension, ".pdf") == 0 &&
                    default_document_viewer_is_evince (uri))
diff --git a/src/liblatexila/latexila-utils.h b/src/liblatexila/latexila-utils.h
index 3b49aa4..ab70fac 100644
--- a/src/liblatexila/latexila-utils.h
+++ b/src/liblatexila/latexila-utils.h
@@ -26,10 +26,6 @@ G_BEGIN_DECLS
 
 /* File utilities */
 
-gchar *                latexila_utils_get_shortname                    (const gchar *filename);
-
-gchar *                latexila_utils_get_extension                    (const gchar *filename);
-
 gchar *                latexila_utils_replace_home_dir_with_tilde      (const gchar *filename);
 
 void           latexila_utils_file_query_exists_async          (GFile               *file,
diff --git a/src/main_window_build_tools.vala b/src/main_window_build_tools.vala
index d06c710..9e33696 100644
--- a/src/main_window_build_tools.vala
+++ b/src/main_window_build_tools.vala
@@ -229,7 +229,7 @@ public class MainWindowBuildTools
         }
 
         string path = active_doc.get_main_file ().get_parse_name ();
-        string ext = Latexila.utils_get_extension (path);
+        string ext = Tepl.utils_get_file_extension (path);
 
         string[] extensions = tool.extensions.split (" ");
         bool sensitive = tool.extensions.length == 0 || ext in extensions;
@@ -475,7 +475,7 @@ public class MainWindowBuildTools
         File mainfile = _main_window.active_document.get_main_file ();
         File directory = mainfile.get_parent ();
 
-        string basename = Latexila.utils_get_shortname (mainfile.get_basename ()) + ".log";
+        string basename = Tepl.utils_get_file_shortname (mainfile.get_basename ()) + ".log";
         File file = directory.get_child (basename);
         DocumentTab? tab = _main_window.open_document (file);
 
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 68809d5..f0386ca 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -19,46 +19,6 @@
 
 #include "latexila.h"
 
-static void
-test_get_shortname (void)
-{
-       gchar *shortname;
-
-       shortname = latexila_utils_get_shortname ("file.txt");
-       g_assert_cmpstr (shortname, ==, "file");
-       g_free (shortname);
-
-       shortname = latexila_utils_get_shortname ("file.tar.gz");
-       g_assert_cmpstr (shortname, ==, "file.tar");
-       g_free (shortname);
-
-       shortname = latexila_utils_get_shortname ("file");
-       g_assert_cmpstr (shortname, ==, "file");
-       g_free (shortname);
-
-       shortname = latexila_utils_get_shortname ("dir.ext/blah");
-       g_assert_cmpstr (shortname, ==, "dir.ext/blah");
-       g_free (shortname);
-}
-
-static void
-test_get_extension (void)
-{
-       gchar *extension;
-
-       extension = latexila_utils_get_extension ("file.pdf");
-       g_assert_cmpstr (extension, ==, ".pdf");
-       g_free (extension);
-
-       extension = latexila_utils_get_extension ("file.tar.gz");
-       g_assert_cmpstr (extension, ==, ".gz");
-       g_free (extension);
-
-       extension = latexila_utils_get_extension ("file");
-       g_assert_cmpstr (extension, ==, "");
-       g_free (extension);
-}
-
 static void
 test_replace_home_dir_with_tilde (void)
 {
@@ -109,8 +69,6 @@ main (gint    argc,
 {
        g_test_init (&argc, &argv, NULL);
 
-       g_test_add_func ("/utils/get-shortname", test_get_shortname);
-       g_test_add_func ("/utils/get-extension", test_get_extension);
        g_test_add_func ("/utils/replace-home-dir-with-tilde", test_replace_home_dir_with_tilde);
        g_test_add_func ("/utils/str-replace", test_str_replace);
 


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