gnome-vfs-mime-monitor patch
- From: Jonathan Blandford <jrb redhat com>
- To: gnome-vfs-list <gnome-vfs-list gnome org>
- Cc: nautilus-list gnome org
- Subject: gnome-vfs-mime-monitor patch
- Date: 28 Apr 2002 12:15:36 -0400
Hi,
This is a simple patch that listens for changes in the mime settings in
gnome-vfs. A couple comments:
1) It now over reports changes. I don't know what this will do for
nautilus.
2) people calling gnome_vfs_mime_info_reload will explicitly trigger the
data_changed signal. I don't know if this is a problem, but it shows
that this function shouldn't be called.
3) we are keeping local mime files in ~/.gnome/mime-info. Shouldn't we
store it in ~/.gnome2/mime-info ?
4) There's a function called gnome_vfs_mime_monitor_emit_data_changed
that (unsurprisingly) emits the "data_changed" signal on the
GnomeVFSMIMEMonitor object. Traditionally in gtk/gobject land, such
a function would be called gnome_vfs_mime_monitor_data_changed.
Does anyone mind if I deprecate the "emit_" variant and change this?
Thanks,
-Jonathan
? autom4te.cache
? stamp-h1
Index: libgnomevfs/gnome-vfs-mime-info.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-mime-info.c,v
retrieving revision 1.60
diff -u -p -r1.60 gnome-vfs-mime-info.c
--- libgnomevfs/gnome-vfs-mime-info.c 12 Apr 2002 18:23:09 -0000 1.60
+++ libgnomevfs/gnome-vfs-mime-info.c 28 Apr 2002 15:35:18 -0000
@@ -742,16 +742,6 @@ gnome_vfs_mime_info_reload (void)
load_mime_type_info ();
/* 3. Tell anyone who cares */
- /* FIXME bugzilla.eazel.com 5459:
- * This is called only when some client asks for data, so changes made
- * to the MIME data via (e.g.) the File Types and Programs capplet
- * won't be reflected in clients (e.g. Nautilus) until the next time
- * some client asks for MIME data. One way to fix this is to implement
- * the gconf solution mentioned in bug 5460. Another possibility is to
- * use file-node monitoring to notice when the contents of the data
- * directory have changed, but file-node monitoring is only a pipe
- * dream at the moment.
- */
gnome_vfs_mime_monitor_emit_data_changed (gnome_vfs_mime_monitor_get ());
}
Index: libgnomevfs/gnome-vfs-mime-monitor.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-mime-monitor.c,v
retrieving revision 1.7
diff -u -p -r1.7 gnome-vfs-mime-monitor.c
--- libgnomevfs/gnome-vfs-mime-monitor.c 21 Nov 2001 00:36:20 -0000 1.7
+++ libgnomevfs/gnome-vfs-mime-monitor.c 28 Apr 2002 15:35:18 -0000
@@ -25,29 +25,44 @@
#include <config.h>
#include "gnome-vfs-mime-monitor.h"
#include "gnome-vfs-mime-private.h"
+#include "gnome-vfs-ops.h"
enum {
DATA_CHANGED,
LAST_SIGNAL
};
+
+
static guint signals[LAST_SIGNAL];
static GnomeVFSMIMEMonitor *global_mime_monitor = NULL;
-/* Return a pointer to the single global monitor. */
-GnomeVFSMIMEMonitor *
-gnome_vfs_mime_monitor_get (void)
+struct _GnomeVFSMIMEMonitorPrivate
{
- if (global_mime_monitor == NULL) {
- global_mime_monitor = GNOME_VFS_MIME_MONITOR
- (g_object_new (gnome_vfs_mime_monitor_get_type (), NULL));
- }
- return global_mime_monitor;
-}
+ GnomeVFSMonitorHandle *global_handle;
+ GnomeVFSMonitorHandle *local_handle;
+};
+
+
+static void gnome_vfs_mime_monitor_class_init (GnomeVFSMIMEMonitorClass *klass);
+static void gnome_vfs_mime_monitor_init (GnomeVFSMIMEMonitor *monitor);
+static void mime_dir_changed_callback (GnomeVFSMonitorHandle *handle,
+ const gchar *monitor_uri,
+ const gchar *info_uri,
+ GnomeVFSMonitorEventType event_type,
+ gpointer user_data);
+static GnomeVFSMonitorHandle *gnome_vfs_mime_monitor_monitor_dir (const gchar *mime_dir,
+ GnomeVFSMIMEMonitor *monitor);
+static void gnome_vfs_mime_monitor_finalize (GObject *object);
+
static void
gnome_vfs_mime_monitor_class_init (GnomeVFSMIMEMonitorClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gnome_vfs_mime_monitor_finalize;
+
signals [DATA_CHANGED] =
g_signal_new ("data_changed",
G_TYPE_FROM_CLASS (klass),
@@ -58,6 +73,69 @@ gnome_vfs_mime_monitor_class_init (Gnome
G_TYPE_NONE, 0);
}
+static void
+gnome_vfs_mime_monitor_init (GnomeVFSMIMEMonitor *monitor)
+{
+ gchar *mime_dir;
+
+ monitor->priv = g_new (GnomeVFSMIMEMonitorPrivate, 1);
+
+ mime_dir = g_strdup (DATADIR "/mime-info");
+ monitor->priv->global_handle =
+ gnome_vfs_mime_monitor_monitor_dir (mime_dir, monitor);
+ g_free (mime_dir);
+
+ mime_dir = g_strconcat (g_get_home_dir (), "/.gnome/mime-info", NULL);
+ monitor->priv->local_handle =
+ gnome_vfs_mime_monitor_monitor_dir (mime_dir, monitor);
+ g_free (mime_dir);
+}
+
+
+static void
+mime_dir_changed_callback (GnomeVFSMonitorHandle *handle,
+ const gchar *monitor_uri,
+ const gchar *info_uri,
+ GnomeVFSMonitorEventType event_type,
+ gpointer user_data)
+{
+ gnome_vfs_mime_monitor_emit_data_changed (GNOME_VFS_MIME_MONITOR (user_data));
+}
+
+static GnomeVFSMonitorHandle *
+gnome_vfs_mime_monitor_monitor_dir (const gchar *mime_dir,
+ GnomeVFSMIMEMonitor *monitor)
+{
+ GnomeVFSMonitorHandle *retval = NULL;
+
+ gnome_vfs_monitor_add (&retval,
+ mime_dir,
+ GNOME_VFS_MONITOR_DIRECTORY,
+ mime_dir_changed_callback,
+ monitor);
+ return retval;
+}
+
+static void
+gnome_vfs_mime_monitor_finalize (GObject *object)
+{
+ gnome_vfs_monitor_cancel (GNOME_VFS_MIME_MONITOR (object)->priv->global_handle);
+ gnome_vfs_monitor_cancel (GNOME_VFS_MIME_MONITOR (object)->priv->local_handle);
+ g_free (GNOME_VFS_MIME_MONITOR (object)->priv);
+}
+
+/* Return a pointer to the single global monitor. */
+GnomeVFSMIMEMonitor *
+gnome_vfs_mime_monitor_get (void)
+{
+ if (global_mime_monitor == NULL) {
+ global_mime_monitor = GNOME_VFS_MIME_MONITOR
+ (g_object_new (gnome_vfs_mime_monitor_get_type (), NULL));
+ }
+ return global_mime_monitor;
+}
+
+
void
gnome_vfs_mime_monitor_emit_data_changed (GnomeVFSMIMEMonitor *monitor)
{
@@ -82,7 +160,7 @@ gnome_vfs_mime_monitor_get_type (void)
NULL, /* class_data */
sizeof (GnomeVFSMIMEMonitor),
0, /* n_preallocs */
- (GInstanceInitFunc) NULL
+ (GInstanceInitFunc) gnome_vfs_mime_monitor_init
};
type = g_type_register_static (
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]