Commit 24f10c8f authored by Tristan Van Berkom's avatar Tristan Van Berkom

Added glade_util_canonical_path ()


	* src/glade-utils.c: Added glade_util_canonical_path ()

	* src/glade-project-window.c: Use project->path instead of user
	  provided path in recent files.

	* src/glade-project.[ch]: Use glade_util_canonical_path () for
	  a clean project full path.
parent 990eb18b
2006-01-20 Tristan Van Berkom <tvb@gnome.org>
* src/glade-utils.c: Added glade_util_canonical_path ()
* src/glade-project-window.c: Use project->path instead of user
provided path in recent files.
* src/glade-project.[ch]: Use glade_util_canonical_path () for
a clean project full path.
2006-01-17 Tristan Van Berkom <tvb@gnome.org>
* src/glade-app.c: Fixed bug where widgets weren't selectable
......
......@@ -144,11 +144,8 @@ gpw_recent_project_delete (GtkAction *action, GladeProjectWindow *gpw)
guint merge_id = GPOINTER_TO_UINT(g_object_get_data (G_OBJECT (action), "merge_id"));
gtk_ui_manager_remove_ui(gpw->priv->ui, merge_id);
gtk_action_group_remove_action (gpw->priv->recent_actions, action);
g_queue_remove (gpw->priv->recent_projects, action);
gtk_ui_manager_ensure_update (gpw->priv->ui);
}
......@@ -356,7 +353,7 @@ gpw_save (GladeProjectWindow *gpw, GladeProject *project, const gchar *path)
glade_app_update_instance_count (GLADE_APP (gpw), project);
gpw_recent_project_add (gpw, path);
gpw_recent_project_add (gpw, project->path);
gpw_recent_project_config_save (gpw);
glade_app_config_save (GLADE_APP (gpw));
......@@ -1478,7 +1475,7 @@ glade_project_window_open_project (GladeProjectWindow *gpw, const gchar *path)
return;
}
gpw_recent_project_add (gpw, path);
gpw_recent_project_add (gpw, project->path);
gpw_recent_project_config_save (gpw);
glade_app_config_save (GLADE_APP (gpw));
......
......@@ -782,11 +782,7 @@ glade_project_new_from_interface (GladeInterface *interface, const gchar *path)
project = glade_project_new (FALSE);
if (g_path_is_absolute (path))
project->path = g_strdup (path);
else
project->path =
g_build_filename (g_get_current_dir (), path, NULL);
project->path = glade_util_canonical_path (path);
if (project->name) g_free (project->name);
......
......@@ -24,7 +24,7 @@ struct _GladeProject
gchar *name; /* The name of the project like network-conf */
gchar *path; /* The full path of the xml file for this project */
gchar *path; /* The full path of the glade file for this project */
gint instance; /* How many projects with this name */
......
......@@ -28,6 +28,9 @@
#include <gdk/gdkkeysyms.h>
#include <gmodule.h>
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
#include <errno.h>
#include "glade.h"
#include "glade-project.h"
#include "glade-project-window.h"
......@@ -1340,3 +1343,53 @@ glade_util_purify_list (GList *list)
return g_list_reverse (newlist);
}
/**
* glade_util_canonical_path:
*
* @path: any path that may contain ".." or "." components
*
* Returns: an absolute path to the specified file or directory
* that contains no ".." or "." components (this does
* not call readlink like realpath() does).
*
* Note: on some systems; I think its possible that we dont have
* permission to execute in the directory in which the glade
* file resides; I decided finally to do it this way anyway
* since libc's realpath() does exactly the same.
*/
gchar *
glade_util_canonical_path (const gchar *path)
{
gchar *orig_dir, *dirname, *basename, *direct_dir, *direct_name = NULL;
basename = g_path_get_basename (path);
if ((orig_dir = g_get_current_dir ()) != NULL)
{
if ((dirname = g_path_get_dirname (path)) != NULL)
{
if (g_chdir (dirname) == 0)
{
if ((direct_dir = g_get_current_dir ()) != NULL)
direct_name =
g_build_filename (direct_dir, basename, NULL);
else
g_warning ("g_path");
if (g_chdir (orig_dir) != 0)
g_warning ("Unable to chdir back to %s directory (%s)",
orig_dir, g_strerror (errno));
} else g_warning ("Unable to chdir to %s directory (%s)",
dirname, g_strerror (errno));
g_free (dirname);
} else g_warning ("Unable to get directory component of %s\n", path);
g_free (orig_dir);
}
if (basename) g_free (basename);
return direct_name;
}
......@@ -79,6 +79,8 @@ LIBGLADEUI_API gboolean glade_util_basenames_match (const gchar
LIBGLADEUI_API GList *glade_util_purify_list (GList *list);
LIBGLADEUI_API gchar *glade_util_direct_path (const gchar *path);
G_END_DECLS
#endif /* __GLADE_UTILS_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment