From c71a557f10d8f7ffa4b732fcb357421904e982d0 Mon Sep 17 00:00:00 2001
From: Antoine Fontaine <antoine.fontaine@epfl.ch>
Date: Sat, 15 Jun 2019 16:31:48 +0200
Subject: [PATCH] Moved get_x_filename to moodle-provider.c

---
 src/moodle-provider.c | 56 +++++++++++++++++++++++++++++++++++++++++++
 src/utils.c           | 54 -----------------------------------------
 src/utils.h           |  4 ----
 3 files changed, 56 insertions(+), 58 deletions(-)

diff --git a/src/moodle-provider.c b/src/moodle-provider.c
index a19ead7..08e9923 100644
--- a/src/moodle-provider.c
+++ b/src/moodle-provider.c
@@ -24,6 +24,8 @@
 #include "utils.h"
 #include "config.h"
 
+#include <glib/gstdio.h> // g_mkdir
+
 typedef struct MoodleProviderState {
   SoupSession *session;
   SoupCookieJar *jar;
@@ -51,6 +53,60 @@ struct cb_data {
   gchar            *filename;  // the file we are looking for: when caching, the file should be accessible from here.
 };
 
+G_GNUC_CONST static const gchar *
+get_cache_dir (void)
+{
+  static const gchar *cache_dir;
+#ifdef CACHE_ROOT
+  cache_dir = CACHE_ROOT;
+#else
+  cache_dir = g_strconcat (g_get_user_cache_dir (), "/moodle", NULL);
+#endif
+  g_mkdir (cache_dir, 0700);
+  return cache_dir;
+}
+
+// get the canonical "file:///" url where a file should be accessible
+static gchar *
+get_resource_filename (gint res_type, guint id, const gchar *filename)
+{
+  gchar *filepath;
+  switch (res_type) {
+  case RESOURCE_FILE:
+    if (filename) // used when we have a file by id and we want to save it to his real name
+      filepath = g_strdup_printf ("file://%s/%s", get_cache_dir (), filename);
+    else
+      filepath = g_strdup_printf ("file://%s/file-%u", get_cache_dir (), id);
+    break;
+  case RESOURCE_FOLDERFILE:
+    filepath = g_strdup_printf ("file://%s/%s", get_cache_dir (), filename);
+    break;
+  case RESOURCE_FOLDER:
+    filepath = g_strdup_printf ("file://%s/folder-%u.html", get_cache_dir (), id);
+    break;
+  default:
+    filepath = NULL;
+    g_warning ("unsupported resource type %i\n", res_type);
+    break;
+  }
+  return filepath;
+}
+
+static gchar *
+get_course_filename (guint id)
+{
+  gchar *filepath = g_strdup_printf ("file://%s/course-%u.html", get_cache_dir (), id);
+  return filepath;
+}
+
+static gchar *
+get_index_filename (void)
+{
+  gchar *filepath = g_strdup_printf ("file://%s/index.html", get_cache_dir ());
+  return filepath;
+}
+
+
 static void
 request_url_cb (GObject      *unused,
                 GAsyncResult *res,
diff --git a/src/utils.c b/src/utils.c
index 3d5d496..2b23b30 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -17,66 +17,12 @@
  */
 
 #include <gio/gio.h>     // GInputStream stuff
-#include <glib/gstdio.h> // g_mkdir
 
 #include "utils.h"
 #include "data-struct.h"
 
 #define CHUNK_SIZE 100000
 
-G_GNUC_CONST static const gchar *
-get_cache_dir (void)
-{
-  static const gchar *cache_dir;
-#ifdef CACHE_ROOT
-  cache_dir = CACHE_ROOT;
-#else
-  cache_dir = g_strconcat (g_get_user_cache_dir (), "/moodle", NULL);
-#endif
-  g_mkdir (cache_dir, 0700);
-  return cache_dir;
-}
-
-// get the canonical "file:///" url where a file should be accessible
-gchar *
-get_resource_filename (gint res_type, guint id, const gchar *filename)
-{
-  gchar *filepath;
-  switch (res_type) {
-  case RESOURCE_FILE:
-    if (filename) // used when we have a file by id and we want to save it to his real name
-      filepath = g_strdup_printf ("file://%s/%s", get_cache_dir (), filename);
-    else
-      filepath = g_strdup_printf ("file://%s/file-%u", get_cache_dir (), id);
-    break;
-  case RESOURCE_FOLDERFILE:
-    filepath = g_strdup_printf ("file://%s/%s", get_cache_dir (), filename);
-    break;
-  case RESOURCE_FOLDER:
-    filepath = g_strdup_printf ("file://%s/folder-%u.html", get_cache_dir (), id);
-    break;
-  default:
-    filepath = NULL;
-    g_warning ("unsupported resource type %i\n", res_type);
-    break;
-  }
-  return filepath;
-}
-
-gchar *
-get_course_filename (guint id)
-{
-  gchar *filepath = g_strdup_printf ("file://%s/course-%u.html", get_cache_dir (), id);
-  return filepath;
-}
-
-gchar *
-get_index_filename (void)
-{
-  gchar *filepath = g_strdup_printf ("file://%s/index.html", get_cache_dir ());
-  return filepath;
-}
-
 void
 read_file (const char *name, char **content, size_t *size)
 {
diff --git a/src/utils.h b/src/utils.h
index 826ba63..e0070d9 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -19,10 +19,6 @@
 #pragma once
 #include <gio/gio.h>
 
-gchar *get_resource_filename (gint res_type, guint id, const gchar *filename); // takes either a filename or an id.
-gchar *get_course_filename (guint id);
-gchar *get_index_filename (void);
-
 void
 read_file (const char *name, char **content, size_t *size);
 
-- 
GitLab