[gthumb] Convert part of gth-monitor from paths to gfiles
- From: Michael J. Chudobiak <mjc src gnome org>
- To: svn-commits-list gnome org
- Subject: [gthumb] Convert part of gth-monitor from paths to gfiles
- Date: Wed, 10 Jun 2009 16:05:19 -0400 (EDT)
commit f99fe9593e3c961788b3f472727a6958474f7a2b
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date: Wed Jun 10 16:04:46 2009 -0400
Convert part of gth-monitor from paths to gfiles
---
libgthumb/gfile-utils.c | 12 +++++
libgthumb/gfile-utils.h | 2 +
libgthumb/gth-monitor.c | 106 ++++++++++++++++++++--------------------------
libgthumb/gth-monitor.h | 4 +-
src/gth-browser.c | 17 +++----
5 files changed, 69 insertions(+), 72 deletions(-)
diff --git a/libgthumb/gfile-utils.c b/libgthumb/gfile-utils.c
index 0af557e..f69004a 100644
--- a/libgthumb/gfile-utils.c
+++ b/libgthumb/gfile-utils.c
@@ -919,6 +919,18 @@ gfile_list_free (GList *list)
}
+GList *
+gfile_list_find_gfile (GList *list, GFile *gfile)
+{
+ GList *scan;
+
+ for (scan = list; scan; scan = scan->next)
+ if (g_file_equal ((GFile *) scan->data, gfile))
+ return scan;
+ return NULL;
+}
+
+
void
gfile_set_mtime (GFile *gfile,
time_t mtime)
diff --git a/libgthumb/gfile-utils.h b/libgthumb/gfile-utils.h
index 8043cca..adee090 100644
--- a/libgthumb/gfile-utils.h
+++ b/libgthumb/gfile-utils.h
@@ -119,5 +119,7 @@ gssize gfile_output_stream_write (GFileOutputStream *ostream,
/* lists */
void gfile_list_free (GList *list);
+GList * gfile_list_find_gfile (GList *list,
+ GFile *gfile);
#endif /* GFILE_UTILS_H */
diff --git a/libgthumb/gth-monitor.c b/libgthumb/gth-monitor.c
index 549adb7..237434e 100644
--- a/libgthumb/gth-monitor.c
+++ b/libgthumb/gth-monitor.c
@@ -59,24 +59,25 @@ enum {
typedef struct {
GFileMonitor *handle;
- char *uri;
- int ref;
+ GFile *gfile;
+ int ref;
} MonitorHandle;
static GthMonitor *instance = NULL;
MonitorHandle *
monitor_handle_new (GFileMonitor *monitor_handle,
- const char *uri)
+ GFile *gfile)
{
MonitorHandle *mh;
g_return_val_if_fail (monitor_handle != NULL, NULL);
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (gfile != NULL, NULL);
mh = g_new0 (MonitorHandle, 1);
mh->handle = monitor_handle;
- mh->uri = get_utf8_display_name_from_uri (uri);
+ mh->gfile = gfile;
+ g_object_ref (gfile);
mh->ref = 1;
return mh;
@@ -99,7 +100,7 @@ monitor_handle_destroy (MonitorHandle *mh)
return;
if (mh->handle != NULL)
g_file_monitor_cancel (mh->handle);
- g_free (mh->uri);
+ g_object_unref (mh->gfile);
g_free (mh);
}
@@ -116,24 +117,18 @@ monitor_handle_unref (MonitorHandle *mh)
static GList *
-find_monitor_from_uri (GList *gfile_monitors,
- const char *uri)
+find_monitor_from_gfile (GList *gfile_monitors,
+ GFile *gfile)
{
GList *scan;
- char *utf8_uri;
-
- utf8_uri = get_utf8_display_name_from_uri (uri);
for (scan = gfile_monitors; scan; scan = scan->next) {
MonitorHandle *mh = scan->data;
- if (same_uri (mh->uri, utf8_uri)) {
- g_free (utf8_uri);
+ if (g_file_equal (mh->gfile, gfile)) {
return scan;
}
}
- g_free (utf8_uri);
-
return NULL;
}
@@ -167,7 +162,7 @@ gth_monitor_finalize (GObject *object)
}
for (i = 0; i < MONITOR_EVENT_NUM; i++)
- path_list_free (priv->monitor_events[i]);
+ gfile_list_free (priv->monitor_events[i]);
/**/
@@ -233,7 +228,8 @@ proc_monitor_events (gpointer data)
/**/
for (scan = dir_created_list; scan; scan = scan->next) {
- char *path = scan->data;
+ GFile *gfile = scan->data;
+ char *path = g_file_get_parse_name (gfile);
const char *name = file_name_from_path (path);
/* ignore hidden directories. */
@@ -241,32 +237,35 @@ proc_monitor_events (gpointer data)
continue;
gth_monitor_notify_update_directory (path, GTH_MONITOR_EVENT_CREATED);
+ g_free (path);
}
- path_list_free (dir_created_list);
+ gfile_list_free (dir_created_list);
/**/
for (scan = dir_deleted_list; scan; scan = scan->next) {
- char *path = scan->data;
+ GFile *gfile = scan->data;
+ char *path = g_file_get_parse_name (gfile);
gth_monitor_notify_update_directory (path, GTH_MONITOR_EVENT_DELETED);
+ g_free (path);
}
- path_list_free (dir_deleted_list);
+ gfile_list_free (dir_deleted_list);
/**/
if (file_created_list != NULL) {
gth_monitor_notify_update_files (GTH_MONITOR_EVENT_CREATED, file_created_list);
- path_list_free (file_created_list);
+ gfile_list_free (file_created_list);
}
if (file_deleted_list != NULL) {
gth_monitor_notify_update_files (GTH_MONITOR_EVENT_DELETED, file_deleted_list);
- path_list_free (file_deleted_list);
+ gfile_list_free (file_deleted_list);
}
if (file_changed_list != NULL) {
gth_monitor_notify_update_files (GTH_MONITOR_EVENT_CHANGED, file_changed_list);
- path_list_free (file_changed_list);
+ gfile_list_free (file_changed_list);
}
return FALSE;
@@ -276,15 +275,15 @@ proc_monitor_events (gpointer data)
static gboolean
remove_if_present (GList **monitor_events,
MonitorEventType type,
- const char *path)
+ GFile *gfile)
{
GList *list, *link;
list = monitor_events[type];
- link = path_list_find_path (list, path);
+ link = gfile_list_find_gfile (list, gfile);
if (link != NULL) {
monitor_events[type] = g_list_remove_link (list, link);
- path_list_free (link);
+ g_object_unref (link);
return TRUE;
}
@@ -295,7 +294,7 @@ remove_if_present (GList **monitor_events,
static void
add_monitor_event (GthMonitor *monitor,
GFileMonitorEvent event_type,
- const char *path,
+ GFile *gfile,
GList **monitor_events)
{
MonitorEventType type;
@@ -311,24 +310,22 @@ add_monitor_event (GthMonitor *monitor,
else
op = "CHANGED";
- debug (DEBUG_INFO, "[%s] %s", op, path);
-
if (event_type == G_FILE_MONITOR_EVENT_CREATED) {
- if (path_is_file (path))
+ if (gfile_is_file (gfile))
type = MONITOR_EVENT_FILE_CREATED;
- else if (path_is_dir (path))
+ else if (gfile_is_dir (gfile))
type = MONITOR_EVENT_DIR_CREATED;
else
return;
} else if (event_type == G_FILE_MONITOR_EVENT_DELETED) {
- if (file_is_image_video_or_audio (path, TRUE))
+ if (gfile_is_file (gfile))
type = MONITOR_EVENT_FILE_DELETED;
else
type = MONITOR_EVENT_DIR_DELETED;
} else {
- if (path_is_file (path))
+ if (gfile_is_file (gfile))
type = MONITOR_EVENT_FILE_CHANGED;
else
return;
@@ -337,33 +334,34 @@ add_monitor_event (GthMonitor *monitor,
if (type == MONITOR_EVENT_FILE_CREATED) {
if (remove_if_present (monitor_events,
MONITOR_EVENT_FILE_DELETED,
- path))
+ gfile))
type = MONITOR_EVENT_FILE_CHANGED;
} else if (type == MONITOR_EVENT_FILE_DELETED) {
remove_if_present (monitor_events,
MONITOR_EVENT_FILE_CREATED,
- path);
+ gfile);
remove_if_present (monitor_events,
MONITOR_EVENT_FILE_CHANGED,
- path);
+ gfile);
} else if (type == MONITOR_EVENT_FILE_CHANGED) {
remove_if_present (monitor_events,
MONITOR_EVENT_FILE_CHANGED,
- path);
+ gfile);
} else if (type == MONITOR_EVENT_DIR_CREATED) {
remove_if_present (monitor_events,
MONITOR_EVENT_DIR_DELETED,
- path);
+ gfile);
} else if (type == MONITOR_EVENT_DIR_DELETED)
remove_if_present (monitor_events,
MONITOR_EVENT_DIR_CREATED,
- path);
+ gfile);
- monitor_events[type] = g_list_append (monitor_events[type], g_strdup (path));
+ monitor_events[type] = g_list_append (monitor_events[type], gfile);
+ g_object_ref (gfile);
}
@@ -377,9 +375,7 @@ directory_changed (GFileMonitor *handle,
GthMonitor *monitor = user_data;
GthMonitorPrivateData *priv = monitor->priv;
- char *uri = g_file_get_parse_name (gfile);
- add_monitor_event (monitor, event_type, uri, priv->monitor_events);
- g_free (uri);
+ add_monitor_event (monitor, event_type, gfile, priv->monitor_events);
if (priv->update_changes_timeout != 0)
g_source_remove (priv->update_changes_timeout);
@@ -390,31 +386,23 @@ directory_changed (GFileMonitor *handle,
void
-gth_monitor_add_uri (const char *uri)
+gth_monitor_add_gfile (GFile *gfile)
{
GthMonitorPrivateData *priv = instance->priv;
GFileMonitor *monitor_handle;
GList *item;
- GFile *gfile;
- if (uri == NULL)
- return;
-
- item = find_monitor_from_uri (priv->gfile_monitors, uri);
+ item = find_monitor_from_gfile (priv->gfile_monitors, gfile);
if (item != NULL) {
MonitorHandle *mh = item->data;
monitor_handle_ref (mh);
return;
}
- debug (DEBUG_INFO, "MONITOR URI: %s", uri);
-
- gfile = gfile_new (uri);
monitor_handle = g_file_monitor_directory (gfile, G_FILE_MONITOR_NONE, NULL, NULL);
- g_object_unref (gfile);
if (monitor_handle != NULL) {
- MonitorHandle *mh = monitor_handle_new (monitor_handle, uri);
+ MonitorHandle *mh = monitor_handle_new (monitor_handle, gfile);
priv->gfile_monitors = g_list_prepend (priv->gfile_monitors, mh);
g_signal_connect (G_OBJECT (monitor_handle),
@@ -428,21 +416,19 @@ gth_monitor_add_uri (const char *uri)
void
-gth_monitor_remove_uri (const char *uri)
+gth_monitor_remove_gfile (GFile *gfile)
{
GthMonitorPrivateData *priv = instance->priv;
GList *item;
MonitorHandle *mh;
- if (uri == NULL)
+ if (gfile == NULL)
return;
- item = find_monitor_from_uri (priv->gfile_monitors, uri);
+ item = find_monitor_from_gfile (priv->gfile_monitors, gfile);
if (item == NULL)
return;
- debug (DEBUG_INFO, "REMOVE MONITOR URI: %s", uri);
-
mh = item->data;
if (mh->ref == 1)
priv->gfile_monitors = g_list_remove_link (priv->gfile_monitors, item);
@@ -559,7 +545,7 @@ gth_monitor_notify_update_catalog (const char *catalog_path,
void
-gth_monitor_notify_update_metadata (const char *path)
+gth_monitor_notify_update_metadata (const char *path)
{
g_return_if_fail (GTH_IS_MONITOR (instance));
g_signal_emit (G_OBJECT (instance),
diff --git a/libgthumb/gth-monitor.h b/libgthumb/gth-monitor.h
index 5b3b255..a851a9a 100644
--- a/libgthumb/gth-monitor.h
+++ b/libgthumb/gth-monitor.h
@@ -79,8 +79,8 @@ struct _GthMonitorClass
GType gth_monitor_get_type (void);
GthMonitor* gth_monitor_get_instance (void);
-void gth_monitor_add_uri (const char *uri);
-void gth_monitor_remove_uri (const char *uri);
+void gth_monitor_add_gfile (GFile *gfile);
+void gth_monitor_remove_gfile (GFile *gfile);
void gth_monitor_pause (void);
gboolean gth_monitor_resume (void);
void gth_monitor_notify_update_icon_theme (void);
diff --git a/src/gth-browser.c b/src/gth-browser.c
index 2fa0ff3..8107de8 100644
--- a/src/gth-browser.c
+++ b/src/gth-browser.c
@@ -231,7 +231,7 @@ struct _GthBrowserPrivateData {
*/
/* misc */
- char *monitor_uri;
+ GFile *monitor_gfile;
guint cnxn_id[GCONF_NOTIFICATIONS];
GthPixbufOp *pixop;
@@ -4295,12 +4295,12 @@ gth_browser_remove_monitor (GthBrowser *browser)
{
GthBrowserPrivateData *priv = browser->priv;
- if (priv->monitor_uri == NULL)
+ if (priv->monitor_gfile == NULL)
return;
- gth_monitor_remove_uri (priv->monitor_uri);
- g_free (priv->monitor_uri);
- priv->monitor_uri = NULL;
+ gth_monitor_remove_gfile (priv->monitor_gfile);
+ g_object_unref (priv->monitor_gfile);
+ priv->monitor_gfile = NULL;
}
@@ -4317,11 +4317,8 @@ gth_browser_add_monitor (GthBrowser *browser)
if (priv->dir_list->path == NULL)
return;
- if (priv->dir_list->path[0] == '/')
- priv->monitor_uri = add_scheme_if_absent (priv->dir_list->path);
- else
- priv->monitor_uri = g_strdup (priv->dir_list->path);
- gth_monitor_add_uri (priv->monitor_uri);
+ priv->monitor_gfile = gfile_new (priv->dir_list->path);
+ gth_monitor_add_gfile (priv->monitor_gfile);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]