[gnac/devel] Cleaned gnac-playlist.[ch]



commit 270f18b93023c54d53599eb912257ea5f503247d
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Fri Nov 18 22:21:46 2011 +0000

    Cleaned gnac-playlist.[ch]

 src/gnac-playlist.c |  140 +++++++++++++++++++++++---------------------------
 src/gnac-playlist.h |   10 +---
 2 files changed, 65 insertions(+), 85 deletions(-)
---
diff --git a/src/gnac-playlist.c b/src/gnac-playlist.c
index 4c0dec4..59daded 100755
--- a/src/gnac-playlist.c
+++ b/src/gnac-playlist.c
@@ -27,8 +27,6 @@
 #include "config.h"
 #endif
 
-#include <gio/gio.h>
-#include <glib.h>
 #include <glib/gi18n.h>
 
 #include "gnac-main.h"
@@ -40,6 +38,9 @@ typedef struct {
   void        (*handler)(GFile *file);
 } GnacPlaylistMimeHandler;
 
+static void gnac_playlist_parse_m3u(GFile *file);
+static void gnac_playlist_parse_pls(GFile *file);
+static void gnac_playlist_parse_xspf(GFile *file);
 
 static GnacPlaylistMimeHandler mime_playlist[] = {
   { "audio/x-mpegurl"     , &gnac_playlist_parse_m3u  },
@@ -50,16 +51,20 @@ static GnacPlaylistMimeHandler mime_playlist[] = {
 
 
 static void
-gnac_playlist_resolve_uri_and_add(GFile       *parent,
-                                  const gchar *filename)
+gnac_playlist_resolve_uri_and_add(GFile *parent,
+                                  gchar *filename)
 {
-  GFile *file;
+  g_return_if_fail(filename);
+
+  g_strstrip(filename);
 
   if (!g_utf8_validate(filename, -1, NULL)) {
     g_printerr("%s: %s\n", _("Invalid UTF-8 filename"), filename);
     return;
   }
 
+  GFile *file;
+
   if (g_str_has_prefix(filename, "file://")) {
     file = g_file_new_for_uri(filename);
   } else {
@@ -113,104 +118,87 @@ gnac_playlist_parse(GFile       *file,
   for (i = 0; mime_playlist[i].mime; i++) {
     if (g_ascii_strcasecmp(mime, mime_playlist[i].mime) == 0) {
       mime_playlist[i].handler(file);
+      return;
     }
   }
 }
 
 
-void
+static void
 gnac_playlist_parse_m3u(GFile *file)
 {
-  GFile *parent;
-  gchar *contents;
-
-  parent = g_file_get_parent(file);
-  contents = gnac_playlist_read_file(file);
+  GFile *parent = g_file_get_parent(file);
+  gchar *contents = gnac_playlist_read_file(file);
+  if (!contents) return;
 
-  if (contents) {
+  gchar **lines = g_strsplit(contents, "\n", -1);
 
-    guint i;
-    gchar **lines;
-    lines = g_strsplit(contents, "\n", -1);
-
-    for (i = 0; lines[i]; i++) {
-      /* skip comments and empty lines */
-      if (!*lines[i] || *lines[i] == '#') continue;
-      g_strchomp(lines[i]);
-      gnac_playlist_resolve_uri_and_add(parent, lines[i]);
-    }
+  guint i;
+  for (i = 0; lines[i]; i++) {
+    /* skip comments and empty lines */
+    if (!*lines[i] || *lines[i] == '#') continue;
 
-    g_strfreev(lines);
-    g_free(contents);
+    gnac_playlist_resolve_uri_and_add(parent, lines[i]);
   }
+
+  g_strfreev(lines);
+  g_free(contents);
 }
 
 
-void
+static void
 gnac_playlist_parse_pls(GFile *file)
 {
-  GFile *parent;
-  gchar *contents;
+  GFile *parent = g_file_get_parent(file);
+  gchar *contents = gnac_playlist_read_file(file);
+  if (!contents) return;
 
-  parent = g_file_get_parent(file);
-  contents = gnac_playlist_read_file(file);
+  gchar **lines = g_strsplit(contents, "\n", -1);
 
-  if (contents) {
-  
-    guint i;
-    gchar **lines;
-    lines = g_strsplit(contents, "\n", -1);
-
-    for (i = 0; lines[i]; i++) {
-      /* skip empty lines */
-      if (!*lines[i]) continue;
-      gchar  *key;
-      gchar **pair;
-      pair = g_strsplit(lines[i], "=", 2);
-      key = g_utf8_strdown(pair[0], -1);
-      if (pair[1] && g_str_has_prefix(key, "file")) {
-        g_strchomp(pair[1]);
-        gnac_playlist_resolve_uri_and_add(parent, pair[1]);
-      }
-
-      g_free(key);
-      g_strfreev(pair);
+  guint i;
+  for (i = 0; lines[i]; i++) {
+    /* skip empty lines */
+    if (!*lines[i]) continue;
+
+    gchar **pair = g_strsplit(lines[i], "=", 2);
+    gchar *key = g_utf8_strdown(pair[0], -1);
+
+    if (pair[1] && g_str_has_prefix(key, "file")) {
+      gnac_playlist_resolve_uri_and_add(parent, pair[1]);
     }
 
-    g_strfreev(lines);
-    g_free(contents);
+    g_free(key);
+    g_strfreev(pair);
   }
+
+  g_strfreev(lines);
+  g_free(contents);
 }
 
 
-void
+static void
 gnac_playlist_parse_xspf(GFile *file)
 {
-  GFile *parent;
-  gchar *contents;
+  GFile *parent = g_file_get_parent(file);
+  gchar *contents = gnac_playlist_read_file(file);
+  if (!contents) return;
 
-  parent = g_file_get_parent(file);
-  contents = gnac_playlist_read_file(file);
-
-  if (contents) {
-
-    guint i;
-    gchar **lines;
-    lines = g_strsplit(contents, "\n", -1);
-
-    for (i = 0; lines[i]; i++) {
-      /* skip empty lines */
-      if (!*lines[i]) continue;
-      gchar *line = g_strstrip(lines[i]);
-      if (g_str_has_prefix(line, "<location>")) {
-        line = g_strsplit(line, ">", 2)[1];
-        line = g_strsplit(line, "<", 2)[0];
-        g_strchomp(line);
-        gnac_playlist_resolve_uri_and_add(parent, line);
-      }
-    }
+  gchar **lines = g_strsplit(contents, "\n", -1);
 
-    g_strfreev(lines);
-    g_free(contents);
+  guint i;
+  for (i = 0; lines[i]; i++) {
+    /* skip empty lines */
+    if (!*lines[i]) continue;
+
+    gchar *line = g_strstrip(lines[i]);
+
+    if (g_str_has_prefix(line, "<location>")) {
+      line = g_strsplit(line, ">", 2)[1];
+      line = g_strsplit(line, "<", 2)[0];
+      gnac_playlist_resolve_uri_and_add(parent, line);
+    }
   }
+
+  g_strfreev(lines);
+  g_free(contents);
 }
diff --git a/src/gnac-playlist.h b/src/gnac-playlist.h
index c676151..76605d5 100755
--- a/src/gnac-playlist.h
+++ b/src/gnac-playlist.h
@@ -26,6 +26,7 @@
 #ifndef GNAC_PLAYLIST_H
 #define GNAC_PLAYLIST_H
 
+#include <gio/gio.h>
 #include <glib.h>
 
 G_BEGIN_DECLS
@@ -37,15 +38,6 @@ void
 gnac_playlist_parse(GFile       *file,
                     const gchar *mime);
 
-void
-gnac_playlist_parse_m3u(GFile *file);
-
-void
-gnac_playlist_parse_pls(GFile *file);
-
-void
-gnac_playlist_parse_xspf(GFile *file);
-
 G_END_DECLS
 
 #endif /* GNAC_PLAYLIST_H */



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