[gtranslator: 1/2] Replace g_file_get_contents with load_contents




commit 44d81e6fcec2f559add268a933ba89606f58dc60
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Mon Mar 14 13:22:23 2022 +0100

    Replace g_file_get_contents with load_contents

 src/codeview/gtr-codeview.c |  5 ++++-
 src/codeview/gtr-viewer.c   | 16 +++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/src/codeview/gtr-codeview.c b/src/codeview/gtr-codeview.c
index 16075c53..9590f2ca 100644
--- a/src/codeview/gtr-codeview.c
+++ b/src/codeview/gtr-codeview.c
@@ -157,14 +157,17 @@ real_path (const gchar *path)
 static int
 get_line_for_text (const gchar *path, const gchar *msgid)
 {
+  GFile *file;
   gchar *content, *str_found, *i, *escaped;
   int result;
 
+  file = g_file_new_for_path (path);
+
   content = NULL;
   result = 1;
   escaped = g_markup_escape_text (msgid, -1);
 
-  if (!g_file_get_contents (path, &content, NULL, NULL))
+  if (!g_file_load_contents (file, NULL, &content, NULL, NULL, NULL))
     goto out;
 
   i = content;
diff --git a/src/codeview/gtr-viewer.c b/src/codeview/gtr-viewer.c
index 101b3282..01432853 100644
--- a/src/codeview/gtr-viewer.c
+++ b/src/codeview/gtr-viewer.c
@@ -152,17 +152,20 @@ error_dialog (GtkWindow *parent, const gchar *msg, ...)
 
 static gboolean
 gtk_source_buffer_load_file (GtkSourceBuffer *source_buffer,
-                             const gchar     *filename,
+                             GFile           *file,
                              GError         **error)
 {
   GtkTextIter iter;
   gchar *buffer;
   GError *error_here = NULL;
+  g_autofree char *filename = NULL;
 
   g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (source_buffer), FALSE);
-  g_return_val_if_fail (filename != NULL, FALSE);
+  g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
-  if (!g_file_get_contents (filename, &buffer, NULL, &error_here))
+  filename = g_file_get_basename (file);
+
+  if (!g_file_load_contents (file, NULL, &buffer, NULL, NULL, &error_here))
     {
       error_dialog (NULL, "%s\nFile %s", error_here->message, filename);
       g_propagate_error (error, error_here);
@@ -313,15 +316,14 @@ open_file (GtkSourceBuffer *buffer, const gchar *filename)
   gchar *freeme = NULL;
   gboolean success = FALSE;
   GFile *file;
-  gchar *path;
 
   file = g_file_new_for_path (filename);
-  path = g_file_get_path (file);
-  g_object_unref (file);
 
   remove_all_marks (buffer);
 
-  success = gtk_source_buffer_load_file (buffer, path, NULL);
+  success = gtk_source_buffer_load_file (buffer, file, NULL);
+
+  g_object_unref (file);
 
   if (!success)
     goto out;


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