summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2007-10-19 13:43:31 +0000
committerAlexander Larsson <alexl@src.gnome.org>2007-10-19 13:43:31 +0000
commitbce5a407a49844f287951742ac6a0f048352a821 (patch)
treecc6b62c5ff9e226260ad7c14b03db8e0792aa349 /daemon
parentab832dd1c5b60aee63cb1c4516ffd1906396ae8b (diff)
downloadgvfs-bce5a407a49844f287951742ac6a0f048352a821.tar.gz
Faster hash, since mount_spec is unique (g_daemon_file_equal): Compare
2007-10-19 Alexander Larsson <alexl@redhat.com> * client/gdaemonfile.c: (g_daemon_file_hash): Faster hash, since mount_spec is unique (g_daemon_file_equal): Compare mount spec too * daemon/gvfsbackendsmb.c: * daemon/gvfsbackendsmbbrowse.c: Set volume display names and icons Set content type and icon for files svn path=/trunk/; revision=986
Diffstat (limited to 'daemon')
-rw-r--r--daemon/gvfsbackendsmb.c83
-rw-r--r--daemon/gvfsbackendsmbbrowse.c28
2 files changed, 103 insertions, 8 deletions
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
index 30404850..c3eb62fc 100644
--- a/daemon/gvfsbackendsmb.c
+++ b/daemon/gvfsbackendsmb.c
@@ -11,6 +11,8 @@
#include <glib/gi18n.h>
#include <gio/gioerror.h>
#include <gio/gfile.h>
+#include <gio/gcontenttype.h>
+#include <gio/gthemedicon.h>
#include "gvfsbackendsmb.h"
#include "gvfsjobopenforread.h"
@@ -446,9 +448,10 @@ do_mount (GVfsBackend *backend,
op_backend->smb_context = smb_context;
- display_name = g_strdup_printf ("%s on %s", op_backend->share, op_backend->server);
+ display_name = g_strdup_printf (_("%s on %s"), op_backend->share, op_backend->server);
g_vfs_backend_set_display_name (backend, display_name);
g_free (display_name);
+ g_vfs_backend_set_icon (backend, "folder-remote");
smb_mount_spec = g_mount_spec_new ("smb-share");
g_mount_spec_set (smb_mount_spec, "share", op_backend->share);
@@ -1107,12 +1110,16 @@ do_close_write (GVfsBackend *backend,
}
static void
-set_info_from_stat (GFileInfo *info, struct stat *statbuf,
+set_info_from_stat (GFileInfo *info,
+ struct stat *statbuf,
+ const char *basename,
GFileAttributeMatcher *matcher)
{
GFileType file_type;
GTimeVal t;
-
+ GIcon *icon;
+ char *content_type;
+
file_type = G_FILE_TYPE_UNKNOWN;
if (S_ISREG (statbuf->st_mode))
@@ -1143,6 +1150,69 @@ set_info_from_stat (GFileInfo *info, struct stat *statbuf,
#endif
g_file_info_set_modification_time (info, &t);
+
+ if (g_file_attribute_matcher_matches (matcher,
+ G_FILE_ATTRIBUTE_STD_CONTENT_TYPE) ||
+ g_file_attribute_matcher_matches (matcher,
+ G_FILE_ATTRIBUTE_STD_ICON))
+ {
+ icon = NULL;
+ if (S_ISDIR(statbuf->st_mode))
+ {
+ content_type = g_strdup ("inode/directory");
+ icon = g_themed_icon_new ("folder");
+ }
+ else
+ {
+ content_type = g_content_type_guess (basename, NULL, 0, NULL);
+
+ if (content_type)
+ {
+ char *mimetype_icon, *generic_mimetype_icon, *type_icon, *p;
+ char *icon_names[3];
+ int i;
+
+ mimetype_icon = g_strdup (content_type);
+ g_strdelimit (mimetype_icon, "/", '-');
+
+ p = strchr (content_type, '/');
+ if (p == NULL)
+ p = content_type + strlen (content_type);
+
+ generic_mimetype_icon = g_malloc (p - content_type + strlen ("-x-generic") + 1);
+ memcpy (generic_mimetype_icon, content_type, p - content_type);
+ memcpy (generic_mimetype_icon + (p - content_type), "-x-generic", strlen ("-x-generic"));
+ generic_mimetype_icon[(p - content_type) + strlen ("-x-generic")] = 0;
+
+ type_icon = "text-x-generic";
+
+ i = 0;
+ icon_names[i++] = mimetype_icon;
+ icon_names[i++] = generic_mimetype_icon;
+ if (strcmp (generic_mimetype_icon, type_icon) != 0 &&
+ strcmp (mimetype_icon, type_icon) != 0)
+ icon_names[i++] = type_icon;
+
+ icon = g_themed_icon_new_from_names (icon_names, i);
+
+ g_free (mimetype_icon);
+ g_free (generic_mimetype_icon);
+ }
+ }
+
+ if (content_type)
+ {
+ g_file_info_set_content_type (info, content_type);
+ g_free (content_type);
+ }
+
+ if (icon)
+ {
+ g_file_info_set_icon (info, icon);
+ g_object_unref (icon);
+ }
+ }
+
/* Don't trust n_link, uid, gid, etc returned from libsmb, its just made up.
These are ok though: */
@@ -1200,6 +1270,7 @@ do_query_info (GVfsBackend *backend,
struct stat st = {0};
char *uri;
int res, saved_errno;
+ char *basename;
uri = create_smb_uri (op_backend->server, op_backend->share, filename);
res = op_backend->smb_context->stat (op_backend->smb_context, uri, &st);
@@ -1208,7 +1279,9 @@ do_query_info (GVfsBackend *backend,
if (res == 0)
{
- set_info_from_stat (info, &st, matcher);
+ basename = g_path_get_basename (filename);
+ set_info_from_stat (info, &st, basename, matcher);
+ g_free (basename);
g_vfs_job_succeeded (G_VFS_JOB (job));
}
@@ -1333,7 +1406,7 @@ do_enumerate (GVfsBackend *backend,
info = g_file_info_new ();
g_file_info_set_name (info, dirp->name);
- set_info_from_stat (info, &st, matcher);
+ set_info_from_stat (info, &st, dirp->name, matcher);
files = g_list_prepend (files, info);
}
}
diff --git a/daemon/gvfsbackendsmbbrowse.c b/daemon/gvfsbackendsmbbrowse.c
index 2c80317e..62a619d7 100644
--- a/daemon/gvfsbackendsmbbrowse.c
+++ b/daemon/gvfsbackendsmbbrowse.c
@@ -10,6 +10,7 @@
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <gio/gioerror.h>
+#include <gio/gthemedicon.h>
#include <gio/gfile.h>
#include "gvfsbackendsmbbrowse.h"
@@ -597,6 +598,7 @@ do_mount (GVfsBackend *backend,
GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend);
SMBCCTX *smb_context;
char *display_name;
+ char *icon;
GMountSpec *browse_mount_spec;
g_print ("do_mount\n");
@@ -647,17 +649,20 @@ do_mount (GVfsBackend *backend,
}
op_backend->smb_context = smb_context;
-
+
+ icon = NULL;
if (op_backend->server == NULL)
{
- display_name = g_strdup ("smb network");
+ display_name = g_strdup (_("Windows Network"));
browse_mount_spec = g_mount_spec_new ("smb-network");
+ icon = "network-workgroup";
}
else
{
- display_name = g_strdup_printf ("smb share %s", op_backend->server);
+ display_name = g_strdup_printf (_("Windows shares on %s"), op_backend->server);
browse_mount_spec = g_mount_spec_new ("smb-server");
g_mount_spec_set (browse_mount_spec, "server", op_backend->server);
+ icon = "network-server";
}
if (op_backend->user)
@@ -667,6 +672,8 @@ do_mount (GVfsBackend *backend,
g_vfs_backend_set_display_name (backend, display_name);
g_free (display_name);
+ if (icon)
+ g_vfs_backend_set_icon (backend, icon);
g_vfs_backend_set_mount_spec (backend, browse_mount_spec);
g_mount_spec_unref (browse_mount_spec);
@@ -893,6 +900,7 @@ get_file_info_from_entry (GVfsBackendSmbBrowse *backend, BrowseEntry *entry, GFi
{
GMountSpec *mount_spec;
GString *uri;
+ GIcon *icon;
g_file_info_set_name (info, entry->name);
g_file_info_set_display_name (info, entry->name_utf8);
@@ -900,6 +908,20 @@ get_file_info_from_entry (GVfsBackendSmbBrowse *backend, BrowseEntry *entry, GFi
g_file_info_set_attribute_string (info, "smb:comment", entry->comment);
g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_STD_IS_VIRTUAL, TRUE);
+ icon = NULL;
+ if (entry->smbc_type == SMBC_WORKGROUP)
+ icon = g_themed_icon_new ("network-workgroup");
+ else if (entry->smbc_type == SMBC_SERVER)
+ icon = g_themed_icon_new ("network-server");
+ else
+ icon = g_themed_icon_new ("folder-remote");
+
+ if (icon)
+ {
+ g_file_info_set_icon (info, icon);
+ g_object_unref (icon);
+ }
+
mount_spec = NULL;
if (backend->server)
{