gnome-panel r10793 - trunk/gnome-panel
- From: vuntz svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-panel r10793 - trunk/gnome-panel
- Date: Sun, 10 Feb 2008 19:59:14 +0000 (GMT)
Author: vuntz
Date: Sun Feb 10 19:59:14 2008
New Revision: 10793
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=10793&view=rev
Log:
2008-02-10 Vincent Untz <vuntz gnome org>
I wonder what this commit is about. Maybe some gio port work? Oh,
right, it is about this. Cool.
* gnome-desktop-item-edit.c: (panel_gconf_get_client): add sucky
symbols for linking with panel-util.o
* launcher.c: (panel_launcher_get_gfile): new, get a GFile of the
location of the launcher
(panel_launcher_get_uri): gio port
(launch_url): we don't need to make the url canonical
(drag_data_received_cb): get rid of gnome-vfs
(panel_launcher_delete): gio port
(setup_button): get rid of gnome-vfs
(panel_launcher_find_writable_uri): ditto
(panel_launcher_create_with_id): ditto
(panel_launcher_create_copy): gio port
* panel-ditem-editor.c: (panel_ditem_editor_constructor): gio port
* panel-icon-names.h: add two icons
* panel-recent.c: (show_uri): port to gio. We'll need to use
GdkAppLaunchContext when we can depend on the new gtk+, though.
* panel-run-dialog.c: (panel_run_dialog_set_default_icon): use the
launcher icon as a default icon for drag and drop
(command_is_executable): trivial gio port
(panel_run_dialog_execute): trivial gio port, thanks to
panel_util_get_file_optional_homedir()
(entry_drag_data_received): trivial gio port
(panel_run_dialog_create_desktop_file): trivial gio port, thanks to
panel_util_get_file_optional_homedir()
Also fix a crash when dragging the icon for a command without an icon
by setting the .desktop icon to the launcher one
(pixmap_drag_data_get): we want an URI here, not a path
* panel-util.c: (internal_panel_is_uri_writable): kill
(panel_is_uri_writable): gio port
(panel_uri_exists): ditto
(panel_make_unique_desktop_uri): ditto
(panel_util_key_file_load_from_uri): ditto
(panel_util_get_vfs_method_display_name): killed
(panel_util_get_icon_for_uri_method): killed
(panel_util_get_gfile_root): new, get the root parent of a GFile
(panel_util_get_icon_name_from_g_icon): new, get an icon name that
exists in the default icon theme from a GIcon
(panel_util_get_file_display_name_if_mount): new, get name of a GFile
if it's the root of a GMount
(panel_util_get_file_display_for_common_files): new, get name of
GFiles that are common
(panel_util_get_file_display_name): new, utility to easily get the
display name
(panel_util_get_file_icon_name_if_mount): new, get icon name of a
GFile if it's the root of a GMount
(panel_util_get_icon_for_uri_known_folders): updated, port to gio and
add icon for /
(panel_util_get_label_for_uri): gio port. Explicitly mention the
algorithm. There's a bug for hostnames, though.
(panel_util_get_icon_for_uri): gio port. Explicitly mention the
algorithm.
(panel_util_get_file_optional_homedir): new, get a GFile from a
location which might be relative to $HOME
* panel-util.h: updated
* panel.c: (drop_urilist): use the content-type, not the
fast-content-type. It's okay. This is a rarely used operation anyway.
Modified:
trunk/gnome-panel/ChangeLog
trunk/gnome-panel/gnome-desktop-item-edit.c
trunk/gnome-panel/launcher.c
trunk/gnome-panel/panel-ditem-editor.c
trunk/gnome-panel/panel-icon-names.h
trunk/gnome-panel/panel-recent.c
trunk/gnome-panel/panel-run-dialog.c
trunk/gnome-panel/panel-util.c
trunk/gnome-panel/panel-util.h
trunk/gnome-panel/panel.c
Modified: trunk/gnome-panel/gnome-desktop-item-edit.c
==============================================================================
--- trunk/gnome-panel/gnome-desktop-item-edit.c (original)
+++ trunk/gnome-panel/gnome-desktop-item-edit.c Sun Feb 10 19:59:14 2008
@@ -11,9 +11,11 @@
#include "nothing.cP"
-/* FIXME Symbol needed by panel-util.c - sucky */
+/* FIXME Symbols needed by panel-util.c - sucky */
#include "applet.h"
GSList *panel_applet_list_applets (void) { return NULL; }
+#include "panel-gconf.h"
+GConfClient *panel_gconf_get_client (void) { return NULL; }
#include "panel-config-global.h"
gboolean panel_global_config_get_tooltips_enabled (void) { return FALSE; }
Modified: trunk/gnome-panel/launcher.c
==============================================================================
--- trunk/gnome-panel/launcher.c (original)
+++ trunk/gnome-panel/launcher.c Sun Feb 10 19:59:14 2008
@@ -19,8 +19,9 @@
#include <string.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <libgnome/gnome-util.h>
#include <libgnomeui/gnome-url.h>
-#include <libgnomevfs/gnome-vfs.h>
#include <gdk/gdkx.h>
#include "launcher.h"
@@ -91,6 +92,25 @@
launcher);
}
+static GFile *
+panel_launcher_get_gfile (const char *location)
+{
+ char *path;
+ GFile *file;
+
+ if (!g_ascii_strncasecmp (location, "file:", strlen ("file:")))
+ return g_file_new_for_uri (location);
+
+ if (g_path_is_absolute (location))
+ return g_file_new_for_path (location);
+
+ path = panel_make_full_path (NULL, location);
+ file = g_file_new_for_path (path);
+ g_free (path);
+
+ return file;
+}
+
static char *
panel_launcher_get_uri (const char *location)
{
@@ -105,7 +125,7 @@
else
path = g_strdup (location);
- uri = gnome_vfs_get_uri_from_local_path (path);
+ uri = g_filename_to_uri (path, NULL, NULL);
g_free (path);
return uri;
@@ -131,7 +151,6 @@
launch_url (Launcher *launcher)
{
char *url;
- char *canonical_url;
GError *error = NULL;
GdkScreen *screen;
@@ -155,15 +174,13 @@
return;
}
- canonical_url = gnome_vfs_make_uri_canonical (url);
- gnome_url_show_on_screen (canonical_url, screen, &error);
+ gnome_url_show_on_screen (url, screen, &error);
if (error) {
GtkWidget *error_dialog;
char *primary;
- primary = g_strdup_printf (_("Could not show '%s'"),
- canonical_url);
+ primary = g_strdup_printf (_("Could not show '%s'"), url);
error_dialog = panel_error_dialog (NULL, screen,
"cannot_show_url_dialog",
TRUE,
@@ -174,7 +191,6 @@
}
g_free (url);
- g_free (canonical_url);
}
void
@@ -244,27 +260,27 @@
guint time,
Launcher *launcher)
{
- GError *error = NULL;
- GList *li;
- GList *list;
+ GError *error = NULL;
+ char **uris;
+ int i;
+ GList *file_list;
if (panel_global_config_get_enable_animations ())
xstuff_zoom_animate (widget, NULL);
- list = gnome_vfs_uri_list_parse ((const char*) selection_data->data);
- for (li = list; li != NULL; li = li->next) {
- GnomeVFSURI *uri = li->data;
- li->data = gnome_vfs_uri_to_string (uri, 0 /* hide_options */);
- gnome_vfs_uri_unref (uri);
- }
+ file_list = NULL;
+ uris = g_uri_list_extract_uris ((const char *) selection_data->data);
+ for (i = 0; uris[i]; i++)
+ file_list = g_list_prepend (file_list, uris[i]);
+ file_list = g_list_reverse (file_list);
panel_util_launch_from_key_file (launcher->key_file,
- list,
+ file_list,
launcher_get_screen (launcher),
&error);
- g_list_foreach (list, (GFunc)g_free, NULL);
- g_list_free (list);
+ g_list_free (file_list);
+ g_strfreev (uris);
if (error) {
GtkWidget *error_dialog;
@@ -320,29 +336,37 @@
void
panel_launcher_delete (Launcher *launcher)
{
- char *location;
- char *p;
+ GFile *file;
+ GFile *launchers;
+ char *launchers_path;
if (!launcher->location)
return;
- p = NULL;
+ launchers_path = gnome_util_home_file (PANEL_LAUNCHERS_PATH);
+ launchers = g_file_new_for_path (launchers_path);
+ g_free (launchers_path);
- location = panel_launcher_get_uri (launcher->location);
- if (location)
- p = strstr (location, PANEL_LAUNCHERS_PATH);
+ file = panel_launcher_get_gfile (launcher->location);
/* do not remove the file if it's not in the user's launchers path */
- if (p) {
- GnomeVFSResult result;
+ if (g_file_contains_file (launchers, file)) {
+ GError *error;
- result = gnome_vfs_unlink (location);
- if (result != GNOME_VFS_OK)
- g_warning ("Error unlinking '%s': %s\n", location,
- gnome_vfs_result_to_string (result));
+ error = NULL;
+ if (!g_file_delete (file, NULL, &error)) {
+ char *path;
+
+ path = g_file_get_path (file);
+ g_warning ("Error deleting '%s': %s\n",
+ path, error->message);
+ g_free (path);
+ g_error_free (error);
+ }
}
- g_free (location);
+ g_object_unref (file);
+ g_object_unref (launchers);
}
static gboolean
@@ -599,7 +623,7 @@
* string (a location e.g.). If we can't, then it most probably means
* we have a % that is not here to encode a character, and we don't
* want to unescape in this case. See bug #170516 for details. */
- unescaped_str = gnome_vfs_unescape_string (str, NULL);
+ unescaped_str = g_uri_unescape_string (str, NULL);
if (unescaped_str) {
g_free (str);
str = unescaped_str;
@@ -642,16 +666,18 @@
if (!strchr (launcher_location, G_DIR_SEPARATOR)) {
path = panel_make_full_path (NULL, launcher_location);
- uri = gnome_vfs_get_uri_from_local_path (path);
+ uri = g_filename_to_uri (path, NULL, NULL);
g_free (path);
return uri;
}
if (panel_launcher_get_filename (launcher_location) != NULL) {
- if (g_path_is_absolute (launcher_location)) {
- uri = gnome_vfs_get_uri_from_local_path (launcher_location);
- return uri;
- } else
+ /* we have a file in the user directory. We either have a path
+ * or an URI */
+ if (g_path_is_absolute (launcher_location))
+ return g_filename_to_uri (launcher_location,
+ NULL, NULL);
+ else
return g_strdup (launcher_location);
}
@@ -1045,7 +1071,7 @@
/* if we have an URI, it might contain escaped characters (? : etc)
* that might get unescaped on disk */
if (!g_ascii_strncasecmp (location, "file:", strlen ("file:")))
- no_uri = gnome_vfs_get_local_path_from_uri (location);
+ no_uri = g_filename_from_uri (location, NULL, NULL);
if (!no_uri)
no_uri = g_strdup (location);
@@ -1079,33 +1105,21 @@
int position,
const char *location)
{
- GnomeVFSResult vfs_result;
- GnomeVFSURI *source_uri;
- GnomeVFSURI *dest_uri;
- char *old_location;
- char *new_location;
- const char *filename;
+ char *new_location;
+ GFile *source;
+ GFile *dest;
+ gboolean copied;
+ const char *filename;
new_location = panel_make_unique_desktop_uri (NULL, location);
-
- old_location = panel_launcher_get_uri (location);
-
- source_uri = gnome_vfs_uri_new (old_location);
- dest_uri = gnome_vfs_uri_new (new_location);
-
- g_free (old_location);
- vfs_result = gnome_vfs_xfer_uri (source_uri,
- dest_uri,
- GNOME_VFS_XFER_FOLLOW_LINKS,
- GNOME_VFS_XFER_ERROR_MODE_ABORT,
- GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
- NULL, NULL);
+ source = panel_launcher_get_gfile (location);
+ dest = g_file_new_for_uri (new_location);
- gnome_vfs_uri_unref (source_uri);
- gnome_vfs_uri_unref (dest_uri);
-
- if (vfs_result != GNOME_VFS_OK) {
+ copied = g_file_copy (source, dest, G_FILE_COPY_OVERWRITE,
+ NULL, NULL, NULL, NULL);
+
+ if (!copied) {
g_free (new_location);
return FALSE;
}
Modified: trunk/gnome-panel/panel-ditem-editor.c
==============================================================================
--- trunk/gnome-panel/panel-ditem-editor.c (original)
+++ trunk/gnome-panel/panel-ditem-editor.c Sun Feb 10 19:59:14 2008
@@ -26,12 +26,12 @@
#include <string.h>
-#include <glib/gi18n-lib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
#include <libgnomeui/gnome-icon-entry.h>
#include <libgnomeui/gnome-help.h>
-#include <libgnomevfs/gnome-vfs.h>
#include "panel-ditem-editor.h"
#include "panel-icon-names.h"
#include "panel-util.h"
@@ -221,7 +221,7 @@
{
GObject *obj;
PanelDItemEditor *dialog;
- GnomeVFSURI *vfs_uri;
+ GFile *file;
gboolean loaded;
char *desktop_type;
@@ -246,15 +246,15 @@
}
if (!loaded && dialog->priv->uri) {
- vfs_uri = gnome_vfs_uri_new (dialog->priv->uri);
- if (gnome_vfs_uri_exists (vfs_uri)) {
+ file = g_file_new_for_uri (dialog->priv->uri);
+ if (g_file_query_exists (file, NULL)) {
//FIXME what if there's an error?
panel_ditem_editor_load_uri (dialog, NULL);
dialog->priv->new_file = FALSE;
} else {
dialog->priv->new_file = TRUE;
}
- gnome_vfs_uri_unref (vfs_uri);
+ g_object_unref (file);
} else {
dialog->priv->new_file = !loaded;
}
Modified: trunk/gnome-panel/panel-icon-names.h
==============================================================================
--- trunk/gnome-panel/panel-icon-names.h (original)
+++ trunk/gnome-panel/panel-icon-names.h Sun Feb 10 19:59:14 2008
@@ -6,6 +6,7 @@
#define PANEL_ICON_COMPUTER "computer"
#define PANEL_ICON_DESKTOP "user-desktop"
#define PANEL_ICON_DRAWER "gnome-panel-drawer"
+#define PANEL_ICON_FILESYSTEM "drive-harddisk"
#define PANEL_ICON_FOLDER "folder"
#define PANEL_ICON_FONTS "preferences-desktop-font"
#define PANEL_ICON_FORCE_QUIT "gnome-panel-force-quit"
@@ -22,6 +23,7 @@
#define PANEL_ICON_REMOVABLE_MEDIA "drive-removable-media"
#define PANEL_ICON_RUN "system-run"
#define PANEL_ICON_SEPARATOR "gnome-panel-separator"
+#define PANEL_ICON_SAVED_SEARCH "folder-saved-search"
#define PANEL_ICON_SEARCHTOOL "system-search"
#define PANEL_ICON_SHUTDOWN "gnome-shutdown"
#define PANEL_ICON_THEME "preferences-desktop-theme"
Modified: trunk/gnome-panel/panel-recent.c
==============================================================================
--- trunk/gnome-panel/panel-recent.c (original)
+++ trunk/gnome-panel/panel-recent.c Sun Feb 10 19:59:14 2008
@@ -27,8 +27,7 @@
#include <string.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
+#include <gio/gio.h>
#include "menu.h"
#include "panel-util.h"
#include "panel-globals.h"
@@ -42,31 +41,28 @@
GError **error)
{
char **env;
- GnomeVFSResult result;
- GnomeVFSMimeApplication *app;
+ GAppInfo *app;
GList *uris = NULL;
+ gboolean ret;
- app = gnome_vfs_mime_get_default_application_for_uri (uri, mime_type);
+ app = g_app_info_get_default_for_type (mime_type, TRUE);
if (app == NULL) {
- g_set_error (error, 0, 0, _("Could not find a suitable application."));
+ g_set_error (error, 0, 0,
+ _("Could not find a suitable application."));
return FALSE;
}
env = panel_make_environment_for_screen (screen, NULL);
uris = g_list_append (uris, (gpointer)uri);
- result = gnome_vfs_mime_application_launch_with_env (app, uris, env);
+ //FIXME: use GdkAppLaunchContext
+ ret = g_app_info_launch_uris (app, uris, NULL, error);
g_list_free (uris);
g_strfreev (env);
- gnome_vfs_mime_application_free (app);
+ g_object_unref (app);
- if (result != GNOME_VFS_OK) {
- g_set_error (error, 0, 0, gnome_vfs_result_to_string (result));
- return FALSE;
- }
-
- return TRUE;
+ return ret;
}
Modified: trunk/gnome-panel/panel-run-dialog.c
==============================================================================
--- trunk/gnome-panel/panel-run-dialog.c (original)
+++ trunk/gnome-panel/panel-run-dialog.c Sun Feb 10 19:59:14 2008
@@ -38,13 +38,13 @@
#include <unistd.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gdk/gdkkeysyms.h>
#include <glade/glade-xml.h>
#include <libgnome/gnome-exec.h>
#include <libgnome/gnome-util.h>
#include <libgnomeui/gnome-entry.h>
#include <libgnomeui/gnome-url.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
#include <gconf/gconf-client.h>
#include <gmenu-tree.h>
@@ -186,7 +186,7 @@
if (set_drag)
gtk_drag_source_set_icon_name (dialog->run_dialog,
- PANEL_ICON_RUN);
+ PANEL_ICON_LAUNCHER);
}
static void
@@ -249,7 +249,7 @@
char *path;
int argc;
- path = gnome_vfs_get_local_path_from_uri (command);
+ path = g_filename_from_uri (command, NULL, NULL);
if (!path)
path = g_strdup (command);
@@ -370,6 +370,7 @@
gboolean result;
char *command;
char *escaped;
+ GFile *file;
char *disk, *url;
char *scheme;
@@ -414,20 +415,21 @@
return;
}
- url = gnome_vfs_make_uri_from_input_with_dirs (command,
- GNOME_VFS_MAKE_URI_DIR_HOMEDIR);
+ file = panel_util_get_file_optional_homedir (command);
+ url = g_file_get_uri (file);
+ scheme = g_file_get_uri_scheme (file);
+ g_object_unref (file);
+
escaped = g_markup_escape_text (url, -1);
- scheme = gnome_vfs_get_uri_scheme (url);
result = FALSE;
if (!g_ascii_strcasecmp (scheme, "http") ||
!g_ascii_strcasecmp (scheme, "file"))
- /* If this returns an http or file url, the url might refer to a
- * command that is somewhere in the path or an executable file.
- * So try executing it before displaying it. We execute the
- * command in the user's shell so that it can do all the parameter
- * expansion and other magic for us.
- */
+ /* If this returns an http or file url, the url might refer to
+ * a command that is somewhere in the path or an executable
+ * file. So try executing it before displaying it. We execute
+ * the command in the user's shell so that it can do all the
+ * parameter expansion and other magic for us. */
result = panel_run_dialog_launch_command (dialog, disk, escaped);
if (!result)
@@ -439,7 +441,8 @@
TRUE, /* save item in history */
command);
- /* only close the dialog if we successfully showed or launched something */
+ /* only close the dialog if we successfully showed or launched
+ * something */
gtk_widget_destroy (dialog->run_dialog);
}
@@ -1671,7 +1674,7 @@
if (!uris [i] || !uris [i][0])
continue;
- file = gnome_vfs_get_local_path_from_uri (uris [i]);
+ file = g_filename_from_uri (uris [i], NULL, NULL);
/* FIXME: I assume the file is in utf8 encoding if coming from a URI? */
if (file) {
@@ -1728,10 +1731,11 @@
GKeyFile *key_file;
gboolean exec = FALSE;
const char *text;
- char *uri;
+ GFile *file;
char *name;
char *disk;
char *scheme;
+ char *save_uri;
text = gtk_entry_get_text (GTK_ENTRY (dialog->gtk_entry));
@@ -1741,11 +1745,10 @@
key_file = panel_util_key_file_new_desktop ();
disk = g_locale_from_utf8 (text, -1, NULL, NULL, NULL);
- uri = gnome_vfs_make_uri_from_input_with_dirs (disk,
- GNOME_VFS_MAKE_URI_DIR_HOMEDIR);
+ file = panel_util_get_file_optional_homedir (disk);
g_free (disk);
- scheme = gnome_vfs_get_uri_scheme (uri);
+ scheme = g_file_get_uri_scheme (file);
if (!g_ascii_strcasecmp (scheme, "http"))
exec = command_is_executable (text);
else if (!g_ascii_strcasecmp (scheme, "file"))
@@ -1759,13 +1762,18 @@
"Exec", text);
name = g_strdup (text);
} else {
+ char *uri;
+
+ uri = g_file_get_uri (file);
+
panel_util_key_file_set_string (key_file,
"Type", "Link");
panel_util_key_file_set_string (key_file,
"URL", uri);
- name = g_strdup (uri);
+ name = uri;
}
- g_free (uri);
+
+ g_object_unref (file);
panel_util_key_file_set_locale_string (key_file, "Name",
(dialog->item_name) ?
@@ -1774,22 +1782,26 @@
panel_util_key_file_set_boolean (key_file, "Terminal",
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->terminal_checkbox)));
- panel_util_key_file_set_locale_string (key_file, "Icon",
- dialog->icon_path);
+ if (dialog->icon_path)
+ panel_util_key_file_set_locale_string (key_file, "Icon",
+ dialog->icon_path);
+ else
+ panel_util_key_file_set_locale_string (key_file, "Icon",
+ PANEL_ICON_LAUNCHER);
- uri = panel_make_unique_desktop_uri (g_get_tmp_dir (), name);
- disk = g_filename_from_uri (uri, NULL, NULL);
+ save_uri = panel_make_unique_desktop_uri (g_get_tmp_dir (), name);
+ disk = g_filename_from_uri (save_uri, NULL, NULL);
if (!disk || !panel_util_key_file_to_file (key_file, disk, NULL)) {
- g_free (uri);
- uri = NULL;
+ g_free (save_uri);
+ save_uri = NULL;
}
g_key_file_free (key_file);
g_free (disk);
g_free (name);
- return uri;
+ return save_uri;
}
static void
@@ -1803,7 +1815,7 @@
char *uri;
if (dialog->use_program_list && dialog->desktop_path)
- uri = g_strdup (dialog->desktop_path);
+ uri = g_filename_to_uri (dialog->desktop_path, NULL, NULL);
else
uri = panel_run_dialog_create_desktop_file (dialog);
Modified: trunk/gnome-panel/panel-util.c
==============================================================================
--- trunk/gnome-panel/panel-util.c (original)
+++ trunk/gnome-panel/panel-util.c Sun Feb 10 19:59:14 2008
@@ -22,19 +22,17 @@
#include <sys/types.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
+
#include <libgnome/gnome-desktop-item.h>
#include <libgnome/gnome-util.h>
-#include <libgnomeui/gnome-icon-lookup.h>
#include <libgnomeui/gnome-help.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-
#include "applet.h"
#include "nothing.h"
#include "xstuff.h"
#include "panel-config-global.h"
+#include "panel-gconf.h"
#include "panel-globals.h"
#include "launcher.h"
#include "panel-icon-names.h"
@@ -521,112 +519,57 @@
return TRUE;
}
-static gboolean
-internal_panel_is_uri_writable (const char *uri, gboolean recurse)
+gboolean
+panel_is_uri_writable (const char *uri)
{
- GnomeVFSFileInfo *info = gnome_vfs_file_info_new ();
-
- if (gnome_vfs_get_file_info
- (uri, info, GNOME_VFS_FILE_INFO_DEFAULT) != GNOME_VFS_OK) {
- char *dir;
- gboolean ret;
-
- gnome_vfs_file_info_unref (info);
-
- if ( ! recurse)
- return FALSE;
+ GFile *file;
+ GFileInfo *info;
+ gboolean retval;
- dir = g_path_get_dirname (uri);
- ret = internal_panel_is_uri_writable (dir, FALSE);
- g_free (dir);
+ g_return_val_if_fail (uri != NULL, FALSE);
- return ret;
- }
+ retval = FALSE;
- if ( ! (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)) {
- gnome_vfs_file_info_unref (info);
- /* assume writable, if no permissions */
- return TRUE;
- }
+ file = g_file_new_for_uri (uri);
- if (info->permissions & GNOME_VFS_PERM_OTHER_WRITE) {
- gnome_vfs_file_info_unref (info);
- return TRUE;
- }
+ if (!g_file_query_exists (file, NULL)) {
+ GFile *parent;
- if (info->gid == getgid () &&
- info->permissions & GNOME_VFS_PERM_GROUP_WRITE) {
- gnome_vfs_file_info_unref (info);
- return TRUE;
- }
+ parent = g_file_get_parent (file);
+ g_object_unref (file);
- if (info->uid == getuid () &&
- info->permissions & GNOME_VFS_PERM_USER_WRITE) {
- gnome_vfs_file_info_unref (info);
- return TRUE;
- }
-
- if (info->gid == getgid () &&
- info->permissions & GNOME_VFS_PERM_GROUP_WRITE) {
- gnome_vfs_file_info_unref (info);
- return TRUE;
- }
-
- if (info->permissions & GNOME_VFS_PERM_GROUP_WRITE) {
- gid_t *groups;
- int i, n;
-
- /* get size */
- n = getgroups (0, NULL);
-
- if (n == 0) {
- /* no more groups */
- gnome_vfs_file_info_unref (info);
+ if (!g_file_query_exists (parent, NULL)) {
+ g_object_unref (parent);
return FALSE;
}
- groups = g_new0 (gid_t, n);
-
- n = getgroups (n, groups);
- for (i = 0; i < n; i++) {
- if (info->gid == groups[i]) {
- /* ok */
- gnome_vfs_file_info_unref (info);
- return TRUE;
- }
- }
+ file = parent;
}
- /* no more perimission stuff to try */
- gnome_vfs_file_info_unref (info);
- return FALSE;
-}
+ info = g_file_query_info (file, "access::*",
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ g_object_unref (file);
-gboolean
-panel_is_uri_writable (const char *uri)
-{
- g_return_val_if_fail (uri != NULL, FALSE);
+ if (info) {
+ retval = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+ g_object_unref (info);
+ }
- return internal_panel_is_uri_writable (uri, TRUE /* recurse */);
+ return retval;
}
gboolean
panel_uri_exists (const char *uri)
{
- GnomeVFSURI *suri;
+ GFile *suri;
gboolean ret;
g_return_val_if_fail (uri != NULL, FALSE);
- suri = gnome_vfs_uri_new (uri);
-
- if (!suri) {
- return FALSE;
- }
-
- ret = gnome_vfs_uri_exists (suri);
-
- gnome_vfs_uri_unref (suri);
+ suri = g_file_new_for_uri (uri);
+ ret = g_file_query_exists (suri, NULL);
+ g_object_unref (suri);
return ret;
}
@@ -940,7 +883,7 @@
path = panel_make_unique_desktop_path_from_name (dir, name);
g_free (name);
- uri = gnome_vfs_get_uri_from_local_path (path);
+ uri = g_filename_to_uri (path, NULL, NULL);
g_free (path);
return uri;
@@ -1170,7 +1113,7 @@
g_return_val_if_fail (uri != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- scheme = gnome_vfs_get_uri_scheme (uri);
+ scheme = g_uri_get_scheme (uri);
is_local = (scheme == NULL) || !g_ascii_strcasecmp (scheme, "file");
g_free (scheme);
@@ -1185,12 +1128,17 @@
flags, error);
g_free (path);
} else {
- GnomeVFSResult vfs_result;
- int size;
- char *contents;
+ GFile *file;
+ char *contents;
+ gsize size;
+ gboolean ret;
- vfs_result = gnome_vfs_read_entire_file (uri, &size, &contents);
- if (vfs_result != GNOME_VFS_OK)
+ file = g_file_new_for_uri (uri);
+ ret = g_file_load_contents (file, NULL, &contents, &size,
+ NULL, NULL);
+ g_object_unref (file);
+
+ if (!ret)
return FALSE;
result = g_key_file_load_from_data (keyfile, contents, size,
@@ -1361,54 +1309,168 @@
return icon_name;
}
-/* This is nautilus_get_vfs_method_display_name() */
-const char *
-panel_util_get_vfs_method_display_name (const char *method)
+static GFile *
+panel_util_get_gfile_root (GFile *file)
{
- //FIXME: /apps/nautilus/desktop/computer_icon_visible (same for trash and network)
- if (g_ascii_strcasecmp (method, "computer") == 0 ) {
- return _("Computer");
- } else if (g_ascii_strcasecmp (method, "network") == 0 ) {
- return _("Network");
- } else if (g_ascii_strcasecmp (method, "fonts") == 0 ) {
- return _("Fonts");
- } else if (g_ascii_strcasecmp (method, "themes") == 0 ) {
- return _("Themes");
- } else if (g_ascii_strcasecmp (method, "burn") == 0 ) {
- return _("CD/DVD Creator");
- } else if (g_ascii_strcasecmp (method, "smb") == 0 ) {
- return _("Windows Network");
- } else if (g_ascii_strcasecmp (method, "dns-sd") == 0 ) {
- /* translators: this is the title of the "dns-sd:///" location */
- return _("Services in");
+ GFile *parent;
+ GFile *parent_old;
+
+ /* search for the root on the URI */
+ parent_old = g_object_ref (file);
+ parent = g_file_get_parent (file);
+ while (parent != NULL) {
+ g_object_unref (parent_old);
+ parent_old = parent;
+ parent = g_file_get_parent (parent);
}
- return NULL;
+
+ return parent_old;
}
-static const char *
-panel_util_get_icon_for_uri_method (const char *uri)
+static char *
+panel_util_get_icon_name_from_g_icon (GIcon *gicon)
{
- if (g_str_has_prefix (uri, "computer:")) {
- return PANEL_ICON_COMPUTER;
- } else if (g_str_has_prefix (uri, "network:")) {
- return PANEL_ICON_NETWORK;
- } else if (g_str_has_prefix (uri, "fonts:")) {
- return PANEL_ICON_FONTS;
- } else if (g_str_has_prefix (uri, "themes:")) {
- return PANEL_ICON_THEME;
- } else if (g_str_has_prefix (uri, "burn:")) {
- return PANEL_ICON_BURNER;
- } else if (g_str_has_prefix (uri, "smb:")) {
- return PANEL_ICON_NETWORK;
- } else if (g_str_has_prefix (uri, "dns-sd:")) {
- return PANEL_ICON_NETWORK;
- } else if (g_str_has_prefix (uri, "trash:")) {
- //FIXME: we should look if the trash is empty or not
- return PANEL_ICON_TRASH;
- } else if (g_str_has_prefix (uri, "x-nautilus-search:")) {
- return PANEL_ICON_SEARCHTOOL;
- } else
+ const char * const *names;
+ GtkIconTheme *icon_theme;
+ int i;
+
+ if (!G_IS_THEMED_ICON (gicon))
return NULL;
+
+ names = g_themed_icon_get_names (G_THEMED_ICON (gicon));
+ icon_theme = gtk_icon_theme_get_default ();
+
+ for (i = 0; names[i] != NULL; i++) {
+ if (gtk_icon_theme_has_icon (icon_theme, names[i]))
+ return g_strdup (names[i]);
+ }
+
+ return NULL;
+}
+
+static char *
+panel_util_get_file_display_name_if_mount (GFile *file)
+{
+ GFile *compare;
+ GVolumeMonitor *monitor;
+ GList *mounts, *l;
+ char *ret;
+
+ ret = NULL;
+
+ /* compare with all mounts */
+ monitor = g_volume_monitor_get ();
+ mounts = g_volume_monitor_get_mounts (monitor);
+ for (l = mounts; l != NULL; l = l->next) {
+ GMount *mount;
+ mount = G_MOUNT (l->data);
+ compare = g_mount_get_root (mount);
+ if (g_file_equal (file, compare)) {
+ ret = g_mount_get_name (mount);
+ break;
+ }
+ }
+ g_list_free (mounts);
+ g_object_unref (monitor);
+
+ return ret;
+}
+
+#define HOME_NAME_KEY "/apps/nautilus/desktop/home_icon_name"
+static char *
+panel_util_get_file_display_for_common_files (GFile *file)
+{
+ GFile *compare;
+
+ compare = g_file_new_for_path (g_get_home_dir ());
+ if (g_file_equal (file, compare)) {
+ char *gconf_name;
+
+ g_object_unref (compare);
+
+ gconf_name = gconf_client_get_string (panel_gconf_get_client (),
+ HOME_NAME_KEY,
+ NULL);
+ if (string_empty (gconf_name)) {
+ g_free (gconf_name);
+ return g_strdup (_("Home Folder"));
+ } else {
+ return gconf_name;
+ }
+ }
+ g_object_unref (compare);
+
+ compare = g_file_new_for_path ("/");
+ if (g_file_equal (file, compare)) {
+ g_object_unref (compare);
+ /* Translators: this is the same string as the one found in
+ * nautilus */
+ return g_strdup (_("File System"));
+ }
+ g_object_unref (compare);
+
+ return NULL;
+}
+
+static char *
+panel_util_get_file_display_name (GFile *file,
+ gboolean use_fallback)
+{
+ GFileInfo *info;
+ char *ret;
+
+ ret = NULL;
+
+ info = g_file_query_info (file, "standard::display-name",
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+
+ if (info) {
+ ret = g_strdup (g_file_info_get_display_name (info));
+ g_object_unref (info);
+ }
+
+ if (!ret && use_fallback) {
+ /* can happen with URI schemes non supported by gvfs */
+ char *basename;
+
+ basename = g_file_get_basename (file);
+ ret = g_filename_display_name (basename);
+ g_free (basename);
+ }
+
+ return ret;
+}
+
+static char *
+panel_util_get_file_icon_name_if_mount (GFile *file)
+{
+ GFile *compare;
+ GVolumeMonitor *monitor;
+ GList *mounts, *l;
+ char *ret;
+
+ ret = NULL;
+
+ /* compare with all mounts */
+ monitor = g_volume_monitor_get ();
+ mounts = g_volume_monitor_get_mounts (monitor);
+ for (l = mounts; l != NULL; l = l->next) {
+ GMount *mount;
+ mount = G_MOUNT (l->data);
+ compare = g_mount_get_root (mount);
+ if (g_file_equal (file, compare)) {
+ GIcon *gicon;
+ gicon = g_mount_get_icon (mount);
+ ret = panel_util_get_icon_name_from_g_icon (gicon);
+ g_object_unref (gicon);
+ break;
+ }
+ }
+ g_list_free (mounts);
+ g_object_unref (monitor);
+
+ return ret;
}
static const char *
@@ -1419,13 +1481,19 @@
int len;
icon = NULL;
- path = gnome_vfs_get_local_path_from_uri (uri);
+
+ if (!g_str_has_prefix (uri, "file:"))
+ return NULL;
+
+ path = g_filename_from_uri (uri, NULL, NULL);
len = strlen (path);
if (path[len] == '/')
path[len] = '\0';
- if (strcmp (path, g_get_home_dir ()) == 0)
+ if (strcmp (path, "/") == 0)
+ icon = PANEL_ICON_FILESYSTEM;
+ else if (strcmp (path, g_get_home_dir ()) == 0)
icon = PANEL_ICON_HOME;
else if (strcmp (path,
g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP)) == 0)
@@ -1441,83 +1509,85 @@
char *
panel_util_get_label_for_uri (const char *text_uri)
{
- GnomeVFSURI *uri;
- const char *hostname;
- const char *method;
- char *displayname;
- char *label;
- char *buffer;
+ GFile *file;
+ char *label;
+ char *hostname;
+ char *displayname;
+
+ /* Here's what we do:
+ * + x-nautilus-search: URI
+ * + check if the URI is a mount
+ * + if file: URI:
+ * - check for known file: URI
+ * - use display name of the GFile
+ * + else:
+ * - if we have a hostname: "displayname on hostname"
+ * - if the URI is a root: "root displayname"
+ * - else: "root displayname: displayname"
+ */
- //FIXME: we're not handling $HOME and $Desktop
- hostname = NULL;
label = NULL;
- //FIXME: nautilus uses nautilus_query_to_readable_string() to have a nice name
+ //FIXME: see nautilus_query_to_readable_string() to have a nice name
if (g_str_has_prefix (text_uri, "x-nautilus-search:"))
return g_strdup (_("Search"));
- if (g_str_has_prefix (text_uri, "trash:"))
- return g_strdup (_("Trash"));
-
- if (g_str_has_prefix (text_uri, "file:")) {
- buffer = gnome_vfs_get_local_path_from_uri (text_uri);
- if (!buffer)
- return NULL;
-
- label = g_filename_display_basename (buffer);
- g_free (buffer);
+ file = g_file_new_for_uri (text_uri);
+ label = panel_util_get_file_display_name_if_mount (file);
+ if (label) {
+ g_object_unref (file);
return label;
}
- uri = gnome_vfs_uri_new (text_uri);
- if (uri) {
- char *short_name;
-
- hostname = gnome_vfs_uri_get_host_name (uri);
-
- buffer = gnome_vfs_uri_extract_short_path_name (uri);
- short_name = gnome_vfs_unescape_string_for_display (buffer);
- g_free (buffer);
-
- if (strcmp (short_name, GNOME_VFS_URI_PATH_STR) != 0) {
- displayname = short_name;
- } else {
- g_free (short_name);
- method = panel_util_get_vfs_method_display_name (uri->method_string);
- if (method == NULL)
- method = uri->method_string;
-
- buffer = gnome_vfs_uri_extract_short_name (uri);
- short_name = gnome_vfs_unescape_string_for_display (buffer);
- g_free (buffer);
+ if (g_str_has_prefix (text_uri, "file:")) {
+ label = panel_util_get_file_display_for_common_files (file);
+ if (!label)
+ label = panel_util_get_file_display_name (file, TRUE);
+ g_object_unref (file);
- if (short_name == NULL ||
- strcmp (short_name, GNOME_VFS_URI_PATH_STR) == 0) {
- displayname = g_strdup (method);
- } else {
- displayname = g_strdup_printf ("%s: %s",
- method,
- short_name);
- }
- g_free (short_name);
- }
- } else {
- displayname = gnome_vfs_format_uri_for_display (text_uri);
+ return label;
}
+ g_filename_from_uri (text_uri, &hostname, NULL);
+ displayname = panel_util_get_file_display_name (file, TRUE);
+
+ //FIXME: bah, doesn't work
if (hostname) {
/* Translators: the first string is a path and the second
* string is a hostname. nautilus contains the same string to
* translate. */
- label = g_strdup_printf (_("%1$s on %2$s"), displayname, hostname);
- g_free (displayname);
+ label = g_strdup_printf (_("%1$s on %2$s"),
+ displayname, hostname);
+ g_free (hostname);
} else {
- label = displayname;
+ GFile *root;
+ char *root_display;
+
+ root = panel_util_get_gfile_root (file);
+ root_display = panel_util_get_file_display_name (root, FALSE);
+ if (!root_display)
+ /* can happen with URI schemes non supported by gvfs */
+ root_display = g_file_get_uri_scheme (root);
+
+ if (g_file_equal (file, root))
+ label = root_display;
+ else {
+ /* Translators: the first string is the name of a gvfs
+ * method, and the second string is a path. For
+ * example, "Trash: some-directory". In means that the
+ * directory called "some-directory" is in the trash.
+ */
+ label = g_strdup_printf (_("%1$s: %2$s"),
+ root_display, displayname);
+ g_free (root_display);
+ }
+
+ g_object_unref (root);
}
- if (uri)
- gnome_vfs_uri_unref (uri);
+ g_free (displayname);
+ g_object_unref (file);
return label;
}
@@ -1526,22 +1596,72 @@
panel_util_get_icon_for_uri (const char *text_uri)
{
const char *icon;
+ GFile *file;
+ GFileInfo *info;
+ const char *content;
+ GIcon *gicon;
+ char *retval;
+
+ /* Here's what we do:
+ * + check for known file: URI
+ * + x-nautilus-search: URI
+ * + override burn: URI icon
+ * + check if the URI is a mount
+ * + override trash: URI icon for subfolders
+ * + check for application/x-gnome-saved-search mime type and override
+ * icon of the GFile
+ * + use icon of the GFile
+ */
- icon = panel_util_get_icon_for_uri_method (text_uri);
+ /* this only checks file: URI */
+ icon = panel_util_get_icon_for_uri_known_folders (text_uri);
if (icon)
return g_strdup (icon);
- if (!g_str_has_prefix (text_uri, "file:"))
+ if (g_str_has_prefix (text_uri, "x-nautilus-search:"))
+ return g_strdup (PANEL_ICON_SAVED_SEARCH);
+ /* gvfs doesn't give us a nice icon, so overriding */
+ if (g_str_has_prefix (text_uri, "burn:"))
+ return g_strdup (PANEL_ICON_BURNER);
+
+ file = g_file_new_for_uri (text_uri);
+
+ retval = panel_util_get_file_icon_name_if_mount (file);
+ if (retval)
+ return retval;
+
+ /* gvfs doesn't give us a nice icon for subfolders of the trash, so
+ * overriding */
+ if (g_str_has_prefix (text_uri, "trash:")) {
+ GFile *root;
+
+ root = panel_util_get_gfile_root (file);
+ g_object_unref (file);
+ file = root;
+ }
+
+ info = g_file_query_info (file,
+ "standard::icon,standard::fast-content-type",
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ g_object_unref (file);
+
+ if (!info)
return NULL;
- icon = panel_util_get_icon_for_uri_known_folders (text_uri);
- if (icon)
- return g_strdup (icon);
+ /* FIXME: weird that we don't get the right icon without this */
+ content = g_file_info_get_attribute_string (info,
+ G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
+ if (content &&
+ strcmp (content, "application/x-gnome-saved-search") == 0) {
+ g_object_unref (info);
+ return g_strdup (PANEL_ICON_SAVED_SEARCH);
+ }
- return gnome_icon_lookup_sync (gtk_icon_theme_get_default (),
- NULL, text_uri, NULL,
- GNOME_ICON_LOOKUP_FLAGS_NONE,
- GNOME_ICON_LOOKUP_RESULT_FLAGS_NONE);
+ gicon = g_file_info_get_icon (info);
+ retval = panel_util_get_icon_name_from_g_icon (gicon);
+ g_object_unref (info);
+
+ return retval;
}
static gboolean
@@ -1579,3 +1699,30 @@
G_CALLBACK (panel_util_query_tooltip_cb),
g_strdup (text), (GClosureNotify) g_free, 0);
}
+
+/* This is similar to what g_file_new_for_commandline_arg() does, but
+ * we end up with something relative to $HOME instead of the current working
+ * directory */
+GFile *
+panel_util_get_file_optional_homedir (const char *location)
+{
+ GFile *file;
+ char *path;
+ char *scheme;
+
+ if (g_path_is_absolute (location))
+ return g_file_new_for_path (location);
+
+ scheme = g_uri_get_scheme (location);
+ if (scheme) {
+ file = g_file_new_for_uri (location);
+ g_free (scheme);
+ return file;
+ }
+
+ path = g_build_filename (g_get_home_dir (), location, NULL);
+ file = g_file_new_for_path (path);
+ g_free (path);
+
+ return file;
+}
Modified: trunk/gnome-panel/panel-util.h
==============================================================================
--- trunk/gnome-panel/panel-util.h (original)
+++ trunk/gnome-panel/panel-util.h Sun Feb 10 19:59:14 2008
@@ -1,6 +1,7 @@
#ifndef PANEL_UTIL_H
#define PANEL_UTIL_H
+#include <gio/gio.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
@@ -134,6 +135,8 @@
void panel_util_set_tooltip_text (GtkWidget *widget,
const char *text);
+GFile *panel_util_get_file_optional_homedir (const char *location);
+
G_END_DECLS
#endif /* PANEL_UTIL_H */
Modified: trunk/gnome-panel/panel.c
==============================================================================
--- trunk/gnome-panel/panel.c (original)
+++ trunk/gnome-panel/panel.c Sun Feb 10 19:59:14 2008
@@ -619,7 +619,7 @@
file = g_file_new_for_uri (uri);
info = g_file_query_info (file,
"standard::type,"
- "standard::fast-content-type,"
+ "standard::content-type,"
"access::can-execute",
G_FILE_QUERY_INFO_NONE,
NULL, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]