[gtranslator: 1/2] Use GFile instead of GMappedFile




commit 9fbbc6846fc031f4057afd5c15a5e3d12f178e69
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Sat Mar 12 16:29:09 2022 +0100

    Use GFile instead of GMappedFile

 src/gtr-actions-file.c | 10 ++++------
 src/gtr-po.c           | 30 ++++++------------------------
 2 files changed, 10 insertions(+), 30 deletions(-)
---
diff --git a/src/gtr-actions-file.c b/src/gtr-actions-file.c
index da381213..908359d7 100644
--- a/src/gtr-actions-file.c
+++ b/src/gtr-actions-file.c
@@ -407,7 +407,6 @@ gtr_upload_file (GtkWidget *upload_dialog,
 {
   GtrTab *tab;
   GtrPo *po;
-  GMappedFile *mapped;
   GError *error = NULL;
   GtrProfileManager *pmanager = NULL;
   GtrProfile *profile;
@@ -418,7 +417,7 @@ gtr_upload_file (GtkWidget *upload_dialog,
   SoupMessage *msg = NULL;
   static SoupSession *session = NULL;
 
-  const gchar *content = NULL;
+  g_autofree gchar *content = NULL;
   g_autofree gchar *mime_type = NULL;
   g_autofree gchar *filename = NULL;
   g_autofree gchar *upload_endpoint = NULL;
@@ -444,13 +443,12 @@ gtr_upload_file (GtkWidget *upload_dialog,
   /* Get file content */
   tab = gtr_window_get_active_tab (window);
   po = gtr_tab_get_po (tab);
-  filename = g_file_get_path (gtr_po_get_location (po));
-  mapped = g_mapped_file_new (filename, FALSE, &error);
+  g_file_load_contents (gtr_po_get_location (po), NULL, &content, &size, NULL,
+                        &error);
   if (error != NULL) {
     g_warning ("Error opening file %s: %s", filename, (error)->message);
+    g_error_free (error);
   }
-  content = g_mapped_file_get_contents (mapped);
-  size = g_mapped_file_get_length (mapped);
   header = gtr_po_get_header (po);
 
   /* Check mimetype */
diff --git a/src/gtr-po.c b/src/gtr-po.c
index 6b8be9b7..a1ef77f6 100644
--- a/src/gtr-po.c
+++ b/src/gtr-po.c
@@ -526,30 +526,20 @@ _gtr_po_load (GtrPo * po, GFile * location, GError ** error)
 static gboolean
 _gtr_po_load_ensure_utf8 (GtrPo * po, GError ** error)
 {
-  GMappedFile *mapped;
-  const gchar *content;
+  g_autofree gchar *content = NULL;
   gboolean utf8_valid;
-  gchar *filename;
   gsize size;
+  g_autoptr (GError) err = NULL;
   GtrPoPrivate *priv = gtr_po_get_instance_private (po);
 
-  filename = g_file_get_path (priv->location);
-  mapped = g_mapped_file_new (filename, FALSE, error);
-  g_free (filename);
-
-  if (!mapped)
+  g_file_load_contents (priv->location, NULL, &content, &size, NULL, &err);
+  if (err != NULL)
     return FALSE;
 
-  content = g_mapped_file_get_contents (mapped);
-  size = g_mapped_file_get_length (mapped);
-
   utf8_valid = g_utf8_validate (content, size, NULL);
 
   if (!_gtr_po_load (po, priv->location, error))
-    {
-      g_mapped_file_unref (mapped);
-      return FALSE;
-    }
+    return FALSE;
 
   if (!utf8_valid &&
       priv->header)
@@ -576,7 +566,6 @@ _gtr_po_load_ensure_utf8 (GtrPo * po, GError ** error)
                            GTR_PO_ERROR_ENCODING,
                            _("Could not convert from charset ā€œ%sā€ to UTF-8"),
                            charset);
-              g_mapped_file_unref (mapped);
               g_free (charset);
               return FALSE;
             }
@@ -593,7 +582,6 @@ _gtr_po_load_ensure_utf8 (GtrPo * po, GError ** error)
                            GTR_PO_ERROR_ENCODING,
                            _("Could not store temporary "
                              "file for encoding conversion"));
-              g_mapped_file_unref (mapped);
               g_object_unref (converter);
               return FALSE;
             }
@@ -616,7 +604,6 @@ _gtr_po_load_ensure_utf8 (GtrPo * po, GError ** error)
               g_object_unref (converter_stream);
               g_object_unref (iostream);
               g_object_unref (converter);
-              g_mapped_file_unref (mapped);
               return FALSE;
             }
 
@@ -626,10 +613,7 @@ _gtr_po_load_ensure_utf8 (GtrPo * po, GError ** error)
 
           /* Now load again the converted file */
           if (!_gtr_po_load (po, tmp, error))
-            {
-              g_mapped_file_unref (mapped);
-              return FALSE;
-            }
+            return FALSE;
 
           /* Ensure Content-Type is set correctly
            * in the header as per the content
@@ -641,8 +625,6 @@ _gtr_po_load_ensure_utf8 (GtrPo * po, GError ** error)
         }
     }
 
-  g_mapped_file_unref (mapped);
-
   if (!utf8_valid)
     {
       g_set_error (error,


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