Another mime patch
- From: Jonathan Blandford <jrb redhat com>
- To: gnome-vfs-list <gnome-vfs-list gnome org>
- Cc: ian danger net
- Subject: Another mime patch
- Date: 29 Apr 2002 18:54:27 -0400
This one forces a reload if there's a change in the dir. I feel like
there's some room for optimization here, but I'm not 100% sure how the
loading works. Note that this patch would be easier if there were a
_full variant to gnome_vfs_monitor_add (#80268)
Thanks,
-Jonathan
? autom4te-2.53.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.61
diff -u -r1.61 gnome-vfs-mime-info.c
--- libgnomevfs/gnome-vfs-mime-info.c 29 Apr 2002 19:55:20 -0000 1.61
+++ libgnomevfs/gnome-vfs-mime-info.c 29 Apr 2002 22:46:21 -0000
@@ -114,6 +114,7 @@
struct stat s;
unsigned int valid : 1;
unsigned int system_dir : 1;
+ unsigned int force_reload : 1;
} mime_dir_source_t;
@@ -163,6 +164,20 @@
static GnomeVFSResult write_back_keys_user_file (void);
static const char * gnome_vfs_mime_get_registered_mime_type_key (const char *mime_type,
const char *key);
+void _gnome_vfs_mime_info_mark_gnome_mime_dir_dirty (void);
+void _gnome_vfs_mime_info_mark_user_mime_dir_dirty (void);
+
+void
+_gnome_vfs_mime_info_mark_gnome_mime_dir_dirty (void)
+{
+ gnome_mime_dir.force_reload = TRUE;
+}
+
+void
+_gnome_vfs_mime_info_mark_user_mime_dir_dirty (void)
+{
+ user_mime_dir.force_reload = TRUE;
+}
static gboolean
does_string_contain_caps (const char *string)
@@ -670,8 +685,12 @@
gboolean need_reload = FALSE;
struct stat s;
- if (last_checked + 5 >= now)
- return;
+ if (now > last_checked + 5)
+ need_reload = TRUE;
+
+ if (gnome_mime_dir.force_reload ||
+ user_mime_dir.force_reload)
+ need_reload = TRUE;
if (stat (gnome_mime_dir.dirname, &s) != -1)
if (s.st_mtime != gnome_mime_dir.s.st_mtime)
@@ -740,6 +759,10 @@
/* 2. Reload */
load_mime_type_info ();
+
+ /* 3. clear our force flags */
+ gnome_mime_dir.force_reload = FALSE;
+ user_mime_dir.force_reload = FALSE;
/* 3. Tell anyone who cares */
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.8
diff -u -r1.8 gnome-vfs-mime-monitor.c
--- libgnomevfs/gnome-vfs-mime-monitor.c 29 Apr 2002 19:55:20 -0000 1.8
+++ libgnomevfs/gnome-vfs-mime-monitor.c 29 Apr 2002 22:46:21 -0000
@@ -32,28 +32,43 @@
LAST_SIGNAL
};
+enum {
+ LOCAL_MIME_DIR,
+ GNOME_MIME_DIR,
+};
static guint signals[LAST_SIGNAL];
static GnomeVFSMIMEMonitor *global_mime_monitor = NULL;
+typedef struct _MonitorCallbackData
+{
+ GnomeVFSMIMEMonitor *monitor;
+ gint type;
+} MonitorCallbackData;
+
struct _GnomeVFSMIMEMonitorPrivate
{
GnomeVFSMonitorHandle *global_handle;
GnomeVFSMonitorHandle *local_handle;
+
+ /* The hoops I jump through */
+ MonitorCallbackData *gnome_callback_data;
+ MonitorCallbackData *local_callback_data;
};
-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);
+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 void gnome_vfs_mime_monitor_finalize (GObject *object);
+extern void _gnome_vfs_mime_info_mark_gnome_mime_dir_dirty (void);
+extern void _gnome_vfs_mime_info_mark_user_mime_dir_dirty (void);
+
static void
@@ -79,15 +94,32 @@
gchar *mime_dir;
monitor->priv = g_new (GnomeVFSMIMEMonitorPrivate, 1);
-
+
+ monitor->priv->gnome_callback_data = g_new (MonitorCallbackData, 1);
+ monitor->priv->local_callback_data = g_new (MonitorCallbackData, 1);
+
+ /* FIXME: Bug #80268. These wouldn't be private members if we had a
+ * _full variant. However, if I want to clean them up, I need to keep
+ * them around. */
+ monitor->priv->gnome_callback_data->type = GNOME_MIME_DIR;
+ monitor->priv->gnome_callback_data->monitor = monitor;
+ monitor->priv->local_callback_data->type = LOCAL_MIME_DIR;
+ monitor->priv->local_callback_data->monitor = monitor;
+
mime_dir = g_strdup (DATADIR "/mime-info");
- monitor->priv->global_handle =
- gnome_vfs_mime_monitor_monitor_dir (mime_dir, monitor);
+ gnome_vfs_monitor_add (&monitor->priv->global_handle,
+ mime_dir,
+ GNOME_VFS_MONITOR_DIRECTORY,
+ mime_dir_changed_callback,
+ monitor->priv->gnome_callback_data);
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);
+ gnome_vfs_monitor_add (&monitor->priv->local_handle,
+ mime_dir,
+ GNOME_VFS_MONITOR_DIRECTORY,
+ mime_dir_changed_callback,
+ monitor->priv->local_callback_data);
g_free (mime_dir);
}
@@ -99,21 +131,14 @@
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;
+ MonitorCallbackData *monitor_callback_data = (MonitorCallbackData *)user_data;
- gnome_vfs_monitor_add (&retval,
- mime_dir,
- GNOME_VFS_MONITOR_DIRECTORY,
- mime_dir_changed_callback,
- monitor);
- return retval;
+ if (monitor_callback_data->type == GNOME_MIME_DIR)
+ _gnome_vfs_mime_info_mark_gnome_mime_dir_dirty ();
+ else if (monitor_callback_data->type == LOCAL_MIME_DIR)
+ _gnome_vfs_mime_info_mark_user_mime_dir_dirty ();
+
+ gnome_vfs_mime_monitor_emit_data_changed (monitor_callback_data->monitor);
}
static void
@@ -121,6 +146,8 @@
{
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->gnome_callback_data);
+ g_free (GNOME_VFS_MIME_MONITOR (object)->priv->local_callback_data);
g_free (GNOME_VFS_MIME_MONITOR (object)->priv);
}
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]