[Xfce4-commits] <garcon:master> Drop public GIO helpers and move them in the private file.

Nick Schermer nick at xfce.org
Sat Aug 29 19:58:01 CEST 2009


Updating branch refs/heads/master
         to e2a4d5fb5c86ce85f877fc365dde33f75699a800 (commit)
       from 587ad35c6dd88779bac6f76ab0e6b34859e2de3b (commit)

commit e2a4d5fb5c86ce85f877fc365dde33f75699a800
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Aug 29 19:57:16 2009 +0200

    Drop public GIO helpers and move them in the private file.

 garcon/Makefile.am          |    2 -
 garcon/garcon-gio.c         |  121 -------------------------------------------
 garcon/garcon-gio.h         |   41 ---------------
 garcon/garcon-menu-merger.c |   12 ++--
 garcon/garcon-menu.c        |   10 ++--
 garcon/garcon-private.c     |   85 ++++++++++++++++++++++++++++++-
 garcon/garcon-private.h     |   13 ++++-
 7 files changed, 106 insertions(+), 178 deletions(-)

diff --git a/garcon/Makefile.am b/garcon/Makefile.am
index 1081b56..ec147a3 100644
--- a/garcon/Makefile.am
+++ b/garcon/Makefile.am
@@ -30,7 +30,6 @@ lib_LTLIBRARIES = 							\
 libgarcon_headers =							\
 	garcon.h							\
 	garcon-config.h							\
-	garcon-gio.h							\
 	garcon-menu-element.h						\
 	garcon-menu-separator.h						\
 	garcon-menu-directory.h						\
@@ -46,7 +45,6 @@ libgarcon_headers =							\
 
 libgarcon_sources =							\
 	garcon-config.c							\
-	garcon-gio.c							\
 	garcon-menu-element.c						\
 	garcon-menu-separator.c						\
 	garcon-menu-directory.c						\
diff --git a/garcon/garcon-gio.c b/garcon/garcon-gio.c
deleted file mode 100644
index 0e9b74d..0000000
--- a/garcon/garcon-gio.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/* vi:set et ai sw=2 sts=2 ts=2: */
-/*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <gio/gio.h>
-
-#include <garcon/garcon-gio.h>
-
-
-
-static gboolean
-is_valid_scheme_character (char c)
-{
-  return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
-}
-
-
-
-/* Following RFC 2396, valid schemes are built like:
- *       scheme        = alpha *( alpha | digit | "+" | "-" | "." )
- */
-static gboolean
-has_valid_scheme (const char *uri)
-{
-  const char *p;
-
-  p = uri;
-
-  if (!g_ascii_isalpha (*p))
-    return FALSE;
-
-  do
-    {
-      p++;
-    }
-  while (is_valid_scheme_character (*p));
-
-  return *p == ':';
-}
-
-
-
-GFile *
-g_file_new_for_unknown_input (const gchar *path,
-                              GFile       *parent)
-{
-  g_return_val_if_fail (path != NULL, NULL);
-
-  if (g_path_is_absolute (path))
-    return g_file_new_for_path (path);
-
-  if (has_valid_scheme (path))
-    return g_file_new_for_uri (path);
-
-  if (G_LIKELY (parent != NULL))
-    return g_file_resolve_relative_path (parent, path);
-  else
-    return g_file_new_for_path (path);
-}
-
-
-
-GFile *
-g_file_new_relative_to_file (const gchar *path,
-                             GFile       *file)
-{
-  GFileType type;
-  GFile    *result;
-  GFile    *dir;
-
-  g_return_val_if_fail (path != NULL, NULL);
-  g_return_val_if_fail (G_IS_FILE (file), NULL);
-
-  type = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL);
-
-  if (G_UNLIKELY (type == G_FILE_TYPE_DIRECTORY))
-    dir = g_object_ref (file);
-  else
-    dir = g_file_get_parent (file);
-
-  result = g_file_new_for_unknown_input (path, dir);
-  g_object_unref (dir);
-
-  return result;
-}
-
-
-
-gchar *
-g_file_get_uri_relative_to_file (const gchar *path,
-                                 GFile       *file)
-{
-  GFile *absolute_file;
-  gchar *uri;
-
-  absolute_file = g_file_new_relative_to_file (path, file);
-  uri = g_file_get_uri (absolute_file);
-  g_object_unref (absolute_file);
-
-  return uri;
-}
diff --git a/garcon/garcon-gio.h b/garcon/garcon-gio.h
deleted file mode 100644
index 2908e1d..0000000
--- a/garcon/garcon-gio.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* vi:set et ai sw=2 sts=2 ts=2: */
-/*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#if !defined(GARCON_INSIDE_GARCON_H) && !defined(GARCON_COMPILATION)
-#error "Only <garcon/garcon.h> can be included directly. This file may disappear or change contents."
-#endif
-
-#ifndef __GARCON_GIO_H__
-#define __GARCON_GIO_H__
-
-#include <gio/gio.h>
-
-G_BEGIN_DECLS
-
-GFile *g_file_new_for_unknown_input    (const gchar *path,
-                                        GFile       *parent);
-GFile *g_file_new_relative_to_file     (const gchar *path,
-                                        GFile       *file);
-gchar *g_file_get_uri_relative_to_file (const gchar *path,
-                                        GFile       *file);
-
-G_END_DECLS
-
-#endif /* !__GARCON_GIO_H__ */
diff --git a/garcon/garcon-menu-merger.c b/garcon/garcon-menu-merger.c
index 360a11d..ad58639 100644
--- a/garcon/garcon-menu-merger.c
+++ b/garcon/garcon-menu-merger.c
@@ -29,7 +29,7 @@
 #include <garcon/garcon-menu-tree-provider.h>
 #include <garcon/garcon-menu-parser.h>
 #include <garcon/garcon-menu-merger.h>
-#include <garcon/garcon-gio.h>
+#include <garcon/garcon-private.h>
 
 
 
@@ -525,7 +525,7 @@ garcon_menu_merger_resolve_relative_paths (GNode                   *node,
       garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_MERGE_DIR)
     {
       relative_path = (gchar *)garcon_menu_node_tree_get_string (node);
-      absolute_path = g_file_get_uri_relative_to_file (relative_path, source_file);
+      absolute_path = _garcon_file_get_uri_relative_to_file (relative_path, source_file);
       garcon_menu_node_tree_set_string (node, absolute_path);
       g_free (absolute_path);
     }
@@ -534,7 +534,7 @@ garcon_menu_merger_resolve_relative_paths (GNode                   *node,
       if (garcon_menu_node_tree_get_merge_file_type (node) == GARCON_MENU_MERGE_FILE_PATH)
         {
           relative_path = (gchar *)garcon_menu_node_tree_get_merge_file_filename (node);
-          absolute_path = g_file_get_uri_relative_to_file (relative_path, source_file);
+          absolute_path = _garcon_file_get_uri_relative_to_file (relative_path, source_file);
           garcon_menu_node_tree_set_merge_file_filename (node, absolute_path);
           g_free (absolute_path);
         }
@@ -553,7 +553,7 @@ garcon_menu_merger_resolve_relative_paths (GNode                   *node,
           /* Find the parent XDG_CONFIG_DIRS entry for the current menu file */
           for (i = 0; relative_path == NULL && config_dirs[i] != NULL; ++i)
             {
-              GFile *config_dir = g_file_new_for_unknown_input (config_dirs[i], NULL);
+              GFile *config_dir = _garcon_file_new_for_unknown_input (config_dirs[i], NULL);
               relative_path = g_file_get_relative_path (config_dir, source_file);
               g_object_unref (config_dir);
             }
@@ -562,7 +562,7 @@ garcon_menu_merger_resolve_relative_paths (GNode                   *node,
            * of the current menu file */
           for (; relative_path != NULL && config_dirs[i] != NULL; ++i)
             {
-              GFile *config_dir = g_file_new_for_unknown_input (config_dirs[i], NULL);
+              GFile *config_dir = _garcon_file_new_for_unknown_input (config_dirs[i], NULL);
               GFile *absolute = g_file_resolve_relative_path (config_dir, relative_path);
 
               if (G_LIKELY (absolute != NULL))
@@ -748,7 +748,7 @@ garcon_menu_merger_resolve_merge_dirs (GNode                   *node,
   if (garcon_menu_node_tree_get_node_type (node) != GARCON_MENU_NODE_TYPE_MERGE_DIR)
     return FALSE;
 
-  dir = g_file_new_for_unknown_input (garcon_menu_node_tree_get_string (node), NULL);
+  dir = _garcon_file_new_for_unknown_input (garcon_menu_node_tree_get_string (node), NULL);
 
   enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME,
                                           G_FILE_QUERY_INFO_NONE, NULL, NULL);
diff --git a/garcon/garcon-menu.c b/garcon/garcon-menu.c
index a23bfe8..5b1933c 100644
--- a/garcon/garcon-menu.c
+++ b/garcon/garcon-menu.c
@@ -37,7 +37,7 @@
 #include <garcon/garcon-menu-node.h>
 #include <garcon/garcon-menu-parser.h>
 #include <garcon/garcon-menu-merger.h>
-#include <garcon/garcon-gio.h>
+#include <garcon/garcon-private.h>
 #include <garcon/garcon.h>
 
 
@@ -383,7 +383,7 @@ garcon_menu_new_for_path (const gchar *filename)
   g_return_val_if_fail (filename != NULL, NULL);
 
   /* Create new menu */
-  file = g_file_new_for_unknown_input (filename, NULL);
+  file = _garcon_file_new_for_unknown_input (filename, NULL);
   menu = g_object_new (GARCON_TYPE_MENU, "file", file, NULL);
   g_object_unref (file);
 
@@ -419,7 +419,7 @@ garcon_menu_new_applications (void)
       /* Create menu if the file exists */
       if (G_UNLIKELY (filename != NULL))
         {
-          file = g_file_new_for_unknown_input (filename, NULL);
+          file = _garcon_file_new_for_unknown_input (filename, NULL);
           menu = garcon_menu_new (file);
           g_object_unref (file);
         }
@@ -778,8 +778,8 @@ garcon_menu_lookup_directory (GarconMenu  *menu,
   /* Iterate through all directories */
   for (iter = dirs; !found && iter != NULL; iter = g_list_next (iter))
     {
-      dir = g_file_new_relative_to_file (iter->data, menu->priv->file);
-      file = g_file_new_relative_to_file (filename, dir);
+      dir = _garcon_file_new_relative_to_file (iter->data, menu->priv->file);
+      file = _garcon_file_new_relative_to_file (filename, dir);
 
       /* Check if the file exists and is readable */
       if (G_LIKELY (g_file_query_exists (file, NULL)))
diff --git a/garcon/garcon-private.c b/garcon/garcon-private.c
index bf5b04b..536f08e 100644
--- a/garcon/garcon-private.c
+++ b/garcon/garcon-private.c
@@ -25,12 +25,95 @@
 
 #include <garcon/garcon-private.h>
 
+
+
+static gboolean
+garcon_looks_like_an_uri (const gchar *string)
+{
+  const gchar *s = string;
+
+  /* <scheme> starts with an alpha character */
+  if (g_ascii_isalpha (*s))
+    {
+      /* <scheme> continues with (alpha | digit | "+" | "-" | ".")* */
+      for (++s; g_ascii_isalnum (*s) || *s == '+' || *s == '-' || *s == '.'; ++s);
+
+      /* <scheme> must be followed by ":" */
+      return (*s == ':');
+    }
+
+  return FALSE;
+}
+
+
+
+GFile *
+_garcon_file_new_for_unknown_input (const gchar *path,
+                                    GFile       *parent)
+{
+  g_return_val_if_fail (path != NULL, NULL);
+
+  if (g_path_is_absolute (path))
+    return g_file_new_for_path (path);
+
+  if (garcon_looks_like_an_uri (path))
+    return g_file_new_for_uri (path);
+
+  if (G_LIKELY (parent != NULL))
+    return g_file_resolve_relative_path (parent, path);
+  else
+    return g_file_new_for_path (path);
+}
+
+
+
+GFile *
+_garcon_file_new_relative_to_file (const gchar *path,
+                                   GFile       *file)
+{
+  GFileType type;
+  GFile    *result;
+  GFile    *dir;
+
+  g_return_val_if_fail (path != NULL, NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
+
+  type = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL);
+
+  if (G_UNLIKELY (type == G_FILE_TYPE_DIRECTORY))
+    dir = g_object_ref (file);
+  else
+    dir = g_file_get_parent (file);
+
+  result = _garcon_file_new_for_unknown_input (path, dir);
+  g_object_unref (dir);
+
+  return result;
+}
+
+
+
+gchar *
+_garcon_file_get_uri_relative_to_file (const gchar *path,
+                                       GFile       *file)
+{
+  GFile *absolute_file;
+  gchar *uri;
+
+  absolute_file = _garcon_file_new_relative_to_file (path, file);
+  uri = g_file_get_uri (absolute_file);
+  g_object_unref (absolute_file);
+
+  return uri;
+}
+
+
 gboolean
 _garcon_str_is_equal (const gchar *a,
                       const gchar *b)
 {
   if (a == NULL || b == NULL)
     return (a == b);
-  
+
   return (g_utf8_collate (a, b) == 0);
 }
diff --git a/garcon/garcon-private.h b/garcon/garcon-private.h
index 4f38440..f6e0850 100644
--- a/garcon/garcon-private.h
+++ b/garcon/garcon-private.h
@@ -28,8 +28,17 @@
 
 G_BEGIN_DECLS
 
-gboolean _garcon_str_is_equal (const gchar *a,
-                               const gchar *b);
+GFile    *_garcon_file_new_for_unknown_input    (const gchar *path,
+                                                 GFile       *parent);
+
+GFile    *_garcon_file_new_relative_to_file     (const gchar *path,
+                                                 GFile       *file);
+
+gchar    *_garcon_file_get_uri_relative_to_file (const gchar *path,
+                                                 GFile       *file);
+
+gboolean  _garcon_str_is_equal                  (const gchar *a,
+                                                 const gchar *b);
 
 G_END_DECLS
 



More information about the Xfce4-commits mailing list