[Goodies-commits] r2673 - in xfce4-places-plugin/trunk: . panel-plugin
Diego Ongaro
ongardie at xfce.org
Fri Apr 6 11:13:34 CEST 2007
Author: ongardie
Date: 2007-04-06 09:13:34 +0000 (Fri, 06 Apr 2007)
New Revision: 2673
Added:
xfce4-places-plugin/trunk/panel-plugin/model_system.h
Removed:
xfce4-places-plugin/trunk/panel-plugin/unescape_uri.c
Modified:
xfce4-places-plugin/trunk/ChangeLog
xfce4-places-plugin/trunk/panel-plugin/Makefile.am
xfce4-places-plugin/trunk/panel-plugin/model.c
xfce4-places-plugin/trunk/panel-plugin/model.h
xfce4-places-plugin/trunk/panel-plugin/model_system.c
xfce4-places-plugin/trunk/panel-plugin/model_user.c
Log:
2007-04-06 Diego Ongaro <ongardie at gmail.com>
* Improved consistency with Thunar for user bookmarks
(reading and display)
* Dropped unescape_uri.c
* Fixed bug 3030 (Places shows missing menu items)
Modified: xfce4-places-plugin/trunk/ChangeLog
===================================================================
--- xfce4-places-plugin/trunk/ChangeLog 2007-04-05 19:15:24 UTC (rev 2672)
+++ xfce4-places-plugin/trunk/ChangeLog 2007-04-06 09:13:34 UTC (rev 2673)
@@ -1,3 +1,10 @@
+2007-04-06 Diego Ongaro <ongardie at gmail.com>
+
+ * Improved consistency with Thunar for user bookmarks
+ (reading and display)
+ * Dropped unescape_uri.c
+ * Fixed bug 3030 (Places shows missing menu items)
+
2007-04-05 Diego Ongaro <ongardie at gmail.com>
* Merged in volumes branch
Modified: xfce4-places-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/Makefile.am 2007-04-05 19:15:24 UTC (rev 2672)
+++ xfce4-places-plugin/trunk/panel-plugin/Makefile.am 2007-04-06 09:13:34 UTC (rev 2673)
@@ -9,9 +9,9 @@
model.c \
model.h \
model_system.c \
+ model_system.h \
model_volumes.c \
- model_user.c \
- unescape_uri.c
+ model_user.c
xfce4_places_plugin_CFLAGS = \
Modified: xfce4-places-plugin/trunk/panel-plugin/model.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model.c 2007-04-05 19:15:24 UTC (rev 2672)
+++ xfce4-places-plugin/trunk/panel-plugin/model.c 2007-04-06 09:13:34 UTC (rev 2673)
@@ -28,6 +28,7 @@
BookmarksUser *user;
} Bookmarks;
+
static Bookmarks*
places_bookmarks_init()
{
@@ -37,7 +38,9 @@
b->system = places_bookmarks_system_init();
b->volumes = places_bookmarks_volumes_init();
- b->user = places_bookmarks_user_init();
+ b->user = places_bookmarks_user_init(b->system); // user depends on system for
+ // places_bookmarks_system_bi_system_mod().
+ // It's a sucky aspect of this design...
return b;
}
Modified: xfce4-places-plugin/trunk/panel-plugin/model.h
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model.h 2007-04-05 19:15:24 UTC (rev 2672)
+++ xfce4-places-plugin/trunk/panel-plugin/model.h 2007-04-06 09:13:34 UTC (rev 2673)
@@ -30,6 +30,7 @@
gchar *label;
gchar *uri;
gchar *icon;
+ gboolean show;
gpointer *data;
} BookmarkInfo;
Modified: xfce4-places-plugin/trunk/panel-plugin/model_system.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model_system.c 2007-04-05 19:15:24 UTC (rev 2672)
+++ xfce4-places-plugin/trunk/panel-plugin/model_system.c 2007-04-06 09:13:34 UTC (rev 2673)
@@ -18,12 +18,16 @@
*/
#include "model.h"
+#include "model_system.h"
#include <libxfce4util/libxfce4util.h>
+#include <string.h>
-typedef struct
+#define check_existence data
+
+struct _BookmarksSystem
{
GPtrArray *bookmarks;
-} BookmarksSystem;
+};
static BookmarksSystem*
places_bookmarks_system_init()
@@ -42,6 +46,8 @@
bookmark->label = g_strdup(g_get_user_name());
bookmark->uri = g_strdup(home_dir);
bookmark->icon = "gnome-fs-home";
+ bookmark->show = TRUE;
+ bookmark->check_existence = NULL;
g_ptr_array_add(b->bookmarks, bookmark);
// Trash
@@ -49,13 +55,17 @@
bookmark->label = _("Trash");
bookmark->uri = "trash:///";
bookmark->icon = "gnome-fs-trash-full";
+ bookmark->show = TRUE;
+ bookmark->check_existence = NULL;
g_ptr_array_add(b->bookmarks, bookmark);
// Desktop
bookmark = g_new0(BookmarkInfo, 1);
+ bookmark->uri = g_build_filename(home_dir, "Desktop", NULL);
bookmark->label = _("Desktop");
- bookmark->uri = g_build_filename(home_dir, "Desktop", NULL);
bookmark->icon = "gnome-fs-desktop";
+ bookmark->show = g_file_test(bookmark->uri, G_FILE_TEST_IS_DIR);
+ bookmark->check_existence = (gpointer) 1;
g_ptr_array_add(b->bookmarks, bookmark);
// File System (/)
@@ -63,6 +73,8 @@
bookmark->label = _("File System");
bookmark->uri = "/";
bookmark->icon = "gnome-dev-harddisk";
+ bookmark->show = TRUE;
+ bookmark->check_existence = NULL;
g_ptr_array_add(b->bookmarks, bookmark);
return b;
@@ -71,7 +83,19 @@
static gboolean
places_bookmarks_system_changed(BookmarksSystem *b)
{
- return FALSE;
+ guint k;
+ BookmarkInfo *bi;
+ gboolean ret = FALSE;
+
+ for(k=0; k < b->bookmarks->len; k++){
+ bi = g_ptr_array_index(b->bookmarks, k);
+ if(bi->check_existence && bi->show != g_file_test(bi->uri, G_FILE_TEST_IS_DIR)){
+ bi->show = !bi->show;
+ ret = TRUE;
+ }
+ }
+
+ return ret;
}
static void
@@ -85,7 +109,8 @@
for(k=0; k < b->bookmarks->len; k++){
bi = g_ptr_array_index(b->bookmarks, k);
- item_func(pass_thru, bi->label, bi->uri, bi->icon);
+ if(bi->show)
+ item_func(pass_thru, bi->label, bi->uri, bi->icon);
}
}
@@ -96,4 +121,41 @@
g_free(b);
}
+/*
+ * A bookmark with the same path as a system path should have the system icon.
+ * Such a bookmark with its default label should also use the system label.
+ */
+static void
+places_bookmarks_system_bi_system_mod(BookmarksSystem *b, BookmarkInfo *other){
+ g_assert(b != NULL);
+ g_assert(other != NULL);
+ g_assert(other->icon != NULL);
+ g_assert(other->label != NULL);
+
+ gboolean label_is_default;
+ gchar *default_label;
+
+ default_label = g_filename_display_basename(other->uri);
+ label_is_default = (strcmp(default_label, other->label) == 0);
+ g_free(default_label);
+
+ BookmarkInfo *bi;
+ guint k;
+ for(k=0; k < b->bookmarks->len; k++){
+ bi = g_ptr_array_index(b->bookmarks, k);
+
+ if(G_UNLIKELY(strcmp(other->uri, bi->uri) == 0)){
+ g_free(other->icon);
+ other->icon = g_strdup(bi->icon);
+
+ if(label_is_default && strcmp(other->label, bi->label) != 0){
+ g_free(other->label);
+ other->label = g_strdup(bi->label);
+ }
+
+ return;
+ }
+ }
+}
+
// vim: ai et tabstop=4
Added: xfce4-places-plugin/trunk/panel-plugin/model_system.h
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model_system.h (rev 0)
+++ xfce4-places-plugin/trunk/panel-plugin/model_system.h 2007-04-06 09:13:34 UTC (rev 2673)
@@ -0,0 +1,27 @@
+/* xfce4-places-plugin
+ *
+ * Copyright (c) 2007 Diego Ongaro <ongardie at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _XFCE_PANEL_PLACES_MODEL_SYSTEM_H
+#define _XFCE_PANEL_PLACES_MODEL_SYSTEM_H
+
+typedef struct _BookmarksSystem BookmarksSystem;
+static void places_bookmarks_system_bi_system_mod(BookmarksSystem*, BookmarkInfo*);
+
+#endif
+// vim: ai et tabstop=4
Modified: xfce4-places-plugin/trunk/panel-plugin/model_user.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model_user.c 2007-04-05 19:15:24 UTC (rev 2672)
+++ xfce4-places-plugin/trunk/panel-plugin/model_user.c 2007-04-06 09:13:34 UTC (rev 2673)
@@ -18,14 +18,24 @@
*/
#include "model.h"
+#include "model_system.h"
#include <glib/gstdio.h>
-#include "unescape_uri.c"
+#define dir_exists(path) g_file_test(path, G_FILE_TEST_IS_DIR)
+
typedef struct
{
GPtrArray *bookmarks;
gchar *filename;
time_t loaded;
+
+ const gchar *home;
+ gchar *trash;
+ gchar *desktop;
+ gchar *file_system;
+
+ BookmarksSystem *system;
+
} BookmarksUser;
@@ -35,43 +45,66 @@
places_bookmarks_user_reinit(BookmarksUser *b)
{
DBG("initializing");
+ // As of 2007-04-06, this is pretty much taken from/analogous to Thunar
+
BookmarkInfo *bi;
+ gchar *name;
+ gchar *path;
+ gchar line[2048];
+ FILE *fp;
+
+ fp = fopen(b->filename, "r");
- gchar *contents;
- gchar **split;
- gchar **lines;
- int i;
-
- if (!g_file_get_contents(b->filename, &contents, NULL, NULL)) {
+ if(G_UNLIKELY(fp == NULL)){
DBG("Error opening gtk bookmarks file");
- }else{
-
- lines = g_strsplit (contents, "\n", -1);
- g_free(contents);
-
- for (i = 0; lines[i]; i++) {
- if(!lines[i][0])
+ return;
+ }
+
+ while( fgets(line, sizeof(line), fp) != NULL )
+ {
+ /* strip leading/trailing whitespace */
+ g_strstrip(line);
+
+ /* skip over the URI */
+ for (name = line; *name != '\0' && !g_ascii_isspace (*name); ++name)
+ /* pass */;
+
+ /* zero-terminate the URI */
+ *name++ = '\0';
+
+ /* check if we have a name */
+ for (; g_ascii_isspace (*name); ++name)
+ /* pass */;
+
+ /* parse the URI */ // TODO: trash:// URI's
+ path = g_filename_from_uri(line, NULL, NULL);
+ if (G_UNLIKELY(path == NULL || *path == '\0'))
+ continue;
+
+ /* if we don't have a name, find it in the path */
+ if(*name == '\0'){
+ name = g_filename_display_basename(path);
+ if(*name == '\0'){
+ g_free(path);
continue;
-
- bi = g_new0(BookmarkInfo, 1);
- bi->icon = "gnome-fs-directory";
-
- // See if the line is in the form "file:///path" or "file:///path friendly-name"
- split = g_strsplit(lines[i], " ", 2);
- if(split[1]){
- bi->label = g_strdup(split[1]);
- bi->uri = g_strdup(split[0]);
- }else{
- bi->label = places_unescape_uri_string(g_strrstr(lines[i], "/") + sizeof(gchar));
- bi->uri = g_strdup(lines[i]);
}
-
- g_ptr_array_add(b->bookmarks, bi);
- g_free(split);
+ }else{
+ name = g_strdup(name);
}
- g_strfreev(lines);
+ /* create the BookmarkInfo container */
+ bi = g_new0(BookmarkInfo, 1);
+ bi->uri = path;
+ bi->label = name;
+ bi->show = dir_exists(bi->uri);
+ bi->icon = g_strdup("gnome-fs-directory");
+
+ places_bookmarks_system_bi_system_mod(b->system, bi);
+
+ g_ptr_array_add(b->bookmarks, bi);
}
+
+ fclose(fp);
}
static time_t
@@ -86,11 +119,12 @@
// external
static BookmarksUser*
-places_bookmarks_user_init()
+places_bookmarks_user_init(BookmarksSystem *system)
{
BookmarksUser *b = g_new0(BookmarksUser, 1);
+ b->system = system;
- b->filename = g_build_filename(xfce_get_homedir(), ".gtk-bookmarks", NULL);
+ b->filename = xfce_get_homefile(".gtk-bookmarks", NULL);
b->bookmarks = g_ptr_array_new();
b->loaded = places_bookmarks_user_get_mtime(b);
@@ -101,6 +135,7 @@
static gboolean
places_bookmarks_user_changed(BookmarksUser *b)
{
+ // see if the file has changed
time_t mtime = places_bookmarks_user_get_mtime(b);
if(mtime > b->loaded){
@@ -111,7 +146,20 @@
return TRUE;
}
- return FALSE;
+ // see if any directories have been created or removed
+ guint k;
+ BookmarkInfo *bi;
+ gboolean ret = FALSE;
+
+ for(k=0; k < b->bookmarks->len; k++){
+ bi = g_ptr_array_index(b->bookmarks, k);
+ if(bi->show != dir_exists(bi->uri)){
+ bi->show = !bi->show;
+ ret = TRUE;
+ }
+ }
+
+ return ret;
}
static void
@@ -125,7 +173,8 @@
for(k=0; k < b->bookmarks->len; k++){
bi = g_ptr_array_index(b->bookmarks, k);
- item_func(pass_thru, bi->label, bi->uri, bi->icon);
+ if(bi->show)
+ item_func(pass_thru, bi->label, bi->uri, bi->icon);
}
}
@@ -137,5 +186,4 @@
g_free(b);
}
-
// vim: ai et tabstop=4
Deleted: xfce4-places-plugin/trunk/panel-plugin/unescape_uri.c
More information about the Goodies-commits
mailing list