gnome-utils r7911 - in trunk/baobab: . src
- From: pborelli svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-utils r7911 - in trunk/baobab: . src
- Date: Sat, 3 May 2008 20:08:12 +0100 (BST)
Author: pborelli
Date: Sat May 3 19:08:11 2008
New Revision: 7911
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=7911&view=rev
Log:
2008-05-03 Paolo Borelli <pborelli katamail com>
* src/baobab.c:
* src/baobab.h:
* src/baobab-scan.c:
get the display name from gio instead of manually getting the basename.
Also be robust to the fact that remote files have no path, so that
needs to be checked before comparin with "/proc".
Modified:
trunk/baobab/ChangeLog
trunk/baobab/src/baobab-scan.c
trunk/baobab/src/baobab.c
trunk/baobab/src/baobab.h
Modified: trunk/baobab/src/baobab-scan.c
==============================================================================
--- trunk/baobab/src/baobab-scan.c (original)
+++ trunk/baobab/src/baobab-scan.c Sat May 3 19:08:11 2008
@@ -125,12 +125,33 @@
static const char *dir_attributes = \
G_FILE_ATTRIBUTE_STANDARD_NAME "," \
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," \
G_FILE_ATTRIBUTE_STANDARD_TYPE "," \
G_FILE_ATTRIBUTE_STANDARD_SIZE "," \
G_FILE_ATTRIBUTE_UNIX_BLOCKS "," \
G_FILE_ATTRIBUTE_UNIX_NLINK "," \
G_FILE_ATTRIBUTE_ACCESS_CAN_READ;
+static gboolean
+is_virtual_filesystem (GFile *file)
+{
+ gboolean ret = FALSE;
+ char *path;
+
+ path = g_file_get_path (file);
+
+ /* FIXME: we need a better way to check virtual FS */
+ if (path != NULL) {
+ if ((strcmp (path, "/proc") == 0) ||
+ (strcmp (path, "/sys") == 0))
+ ret = TRUE;
+ }
+
+ g_free (path);
+
+ return ret;
+}
+
static struct allsizes
loopdir (GFile *file,
GFileInfo *info,
@@ -145,7 +166,7 @@
GFileInfo *temp_info;
GFileEnumerator *file_enum;
gchar *dir_uri = NULL;
- gchar *dir_path = NULL;
+ gchar *display_name = NULL;
gchar *string_to_display = NULL;
GError *err = NULL;
@@ -153,15 +174,13 @@
retloop.size = 0;
retloop.alloc_size = 0;
dir_uri = g_file_get_uri (file);
- dir_path = g_file_get_path (file);
/* Skip the user excluded folders */
if (baobab_is_excluded_location (file))
goto exit;
/* Skip the virtual file systems */
- if ((strcmp (dir_path, "/proc") == 0) ||
- (strcmp (dir_path, "/sys") == 0))
+ if (is_virtual_filesystem (file))
goto exit;
string_to_display = g_file_get_parse_name (file);
@@ -177,7 +196,13 @@
retloop.alloc_size = BLOCK_SIZE *
g_file_info_get_attribute_uint64 (info,
G_FILE_ATTRIBUTE_UNIX_BLOCKS);
-
+
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME))
+ display_name = g_strdup (g_file_info_get_display_name (info));
+ else
+ /* paranoid fallback */
+ display_name = g_filename_display_basename (g_file_info_get_name (info));
+
/* load up the file enumerator */
file_enum = g_file_enumerate_children (file,
dir_attributes,
@@ -200,6 +225,7 @@
data.alloc_size = 1;
data.depth = count - 1;
data.elements = -1;
+ data.display_name = display_name;
data.dir = string_to_display;
data.tempHLsize = tempHLsize;
fill_model (&data);
@@ -260,9 +286,10 @@
/* won't be an error if we've finished normally */
if (err != NULL) {
g_warning ("error in dir %s: %s\n",
- dir_path, err->message);
+ string_to_display, err->message);
}
+ data.display_name = display_name;
data.dir = string_to_display;
data.size = retloop.size;
data.alloc_size = retloop.alloc_size;
@@ -274,7 +301,7 @@
exit:
g_free (dir_uri);
- g_free (dir_path);
+ g_free (display_name);
g_free (string_to_display);
if (err)
g_error_free (err);
Modified: trunk/baobab/src/baobab.c
==============================================================================
--- trunk/baobab/src/baobab.c (original)
+++ trunk/baobab/src/baobab.c Sat May 3 19:08:11 2008
@@ -43,8 +43,6 @@
static GVolumeMonitor *monitor_vol;
static GFileMonitor *monitor_home;
-static void check_UTF (GString *);
-
static void push_iter_in_stack (GtkTreeIter *);
static GtkTreeIter pop_iter_from_stack (void);
@@ -241,12 +239,9 @@
static void
prefill_model (struct chan_data *data)
{
- GString *cdir;
- char *basename;
GtkTreeIter iter, iterparent;
- gchar *str;
-
- cdir = g_string_new ("");
+ char *name;
+ char *str;
if (currentdepth == -1) {
gtk_tree_store_append (baobab.model, &iter, NULL);
@@ -282,30 +277,27 @@
}
gtk_tree_store_append (baobab.model, &iter, &tempiter);
}
+
currentdepth = data->depth;
push_iter_in_stack (&iter);
currentiter = iter;
- basename = g_filename_display_basename (data->dir);
- g_string_assign (cdir, basename);
- g_free (basename);
-
- /* check UTF-8 and locale */
- check_UTF (cdir);
+ /* in case filenames contains gmarkup */
+ name = g_markup_escape_text (data->display_name, -1);
str = g_strdup_printf ("<small><i>%s</i></small>", _("Scanning..."));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (baobab.tree_view), TRUE);
gtk_tree_store_set (baobab.model, &iter,
- COL_DIR_NAME, cdir->str,
+ COL_DIR_NAME, name,
COL_H_FULLPATH, "",
COL_H_ELEMENTS, -1,
COL_H_PERC, -1.0,
COL_DIR_SIZE, str,
COL_ELEMENTS, str, -1);
- g_string_free (cdir, TRUE);
- g_free(str);
+ g_free (name);
+ g_free (str);
while (gtk_events_pending ()) {
gtk_main_iteration ();
@@ -348,26 +340,21 @@
{
GtkTreeIter iter;
GString *hardlinks;
- GString *basename;
GString *elements;
+ char *name;
char *size;
char *alloc_size;
- char *basename_cstr;
if (data->elements == -1) {
prefill_model (data);
return;
}
- basename = g_string_new ("");
- basename_cstr = g_filename_display_basename (data->dir);
- g_string_assign (basename, basename_cstr);
- g_free (basename_cstr);
-
- check_UTF (basename);
-
iter = pop_iter_from_stack ();
+ /* in case filenames contains gmarkup */
+ name = g_markup_escape_text (data->display_name, -1);
+
hardlinks = g_string_new ("");
if (data->tempHLsize > 0) {
size = g_format_size_for_display (data->tempHLsize);
@@ -388,7 +375,7 @@
alloc_size = g_format_size_for_display (data->alloc_size);
gtk_tree_store_set (baobab.model, &iter,
- COL_DIR_NAME, basename->str,
+ COL_DIR_NAME, name,
COL_H_FULLPATH, data->dir,
COL_H_PERC, -1.0,
COL_DIR_SIZE,
@@ -405,8 +392,8 @@
}
g_string_free (hardlinks, TRUE);
- g_string_free (basename, TRUE);
g_string_free (elements, TRUE);
+ g_free (name);
g_free (size);
g_free (alloc_size);
}
@@ -434,34 +421,6 @@
}
void
-check_UTF (GString *name)
-{
- char *str;
- char *escaped_str;
-
- str = g_filename_to_utf8 (name->str, -1, NULL, NULL, NULL);
-
- if (!str) {
- str = g_locale_to_utf8 (name->str, -1, NULL, NULL, NULL);
-
- if (!str) {
- str = g_strjoin ("<i>",
- _("Invalid UTF-8 characters"),
- "</i>", NULL);
- }
- }
-
- g_assert (str);
-
- escaped_str = g_markup_escape_text (str, strlen (str));
-
- g_string_assign (name, escaped_str);
-
- g_free (str);
- g_free (escaped_str);
-}
-
-void
baobab_set_excluded_locations (GSList *excluded_uris)
{
GSList *l;
Modified: trunk/baobab/src/baobab.h
==============================================================================
--- trunk/baobab/src/baobab.h (original)
+++ trunk/baobab/src/baobab.h Sat May 3 19:08:11 2008
@@ -81,6 +81,7 @@
guint64 tempHLsize;
guint depth;
gint elements;
+ gchar *display_name;
gchar *dir;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]