aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ephy-file-helpers.c
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2006-01-17 07:51:41 +0800
committerChristian Persch <chpe@src.gnome.org>2006-01-17 07:51:41 +0800
commit5a9945adda3cd770a0d72f13e55f11950fd66015 (patch)
tree5290aba17884b7d98a754aab198b597380b7fd0d /lib/ephy-file-helpers.c
parente469aef9ea4efd1098ad6982f0da77fed594faf1 (diff)
downloadgsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.tar
gsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.tar.gz
gsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.tar.bz2
gsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.tar.lz
gsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.tar.xz
gsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.tar.zst
gsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.zip
Fix number of /'s in URI.
2006-01-17 Christian Persch <chpe@cvs.gnome.org> * data/chrome/epiphany.manifest.in: Fix number of /'s in URI. * data/epiphany.schemas.in: Add new entries. * embed/mozilla/EphyAboutModule.cpp: Fix title. * data/glade/prefs-dialog.glade: * embed/ephy-embed-prefs.h: * embed/mozilla/mozilla-embed-single.cpp: * embed/mozilla/mozilla-notifiers.cpp: * embed/mozilla/mozilla-notifiers.h: * lib/eel-gconf-extensions.c: (eel_gconf_unset_key), (eel_gconf_notify): * lib/eel-gconf-extensions.h: * lib/egg/egg-editable-toolbar.c: (popup_context_menu_cb), (button_press_event_cb), (egg_editable_toolbar_set_ui_manager), (egg_editable_toolbar_set_selected): * lib/ephy-dialog.c: (set_value_from_pref), (set_pref_from_value), (set_value_from_togglebutton), (strcmp_with_null), (get_index_from_value), (compare_values), (set_togglebutton_from_value), (set_pref_from_info_and_emit), (spinbutton_changed_cb), (save_info): * lib/ephy-dialog.h: * lib/ephy-file-helpers.c: (ephy_file_monitor_timeout_cb), (ephy_file_monitor_cb), (ephy_file_monitor_add), (ephy_file_monitor_cancel): * lib/ephy-file-helpers.h: * src/ephy-extensions-manager.c: (ephy_extensions_manager_load_file): * src/ephy-window.c: * src/popup-commands.c: (popup_cmd_bookmark_link): * src/prefs-dialog.c: (prefs_dialog_finalize), (setup_font_combo), (fonts_language_changed_cb), (font_prefs_dialog_response_cb), (row_is_separator), (setup_fonts_dialog), (font_prefs_button_clicked_cb), (css_checkbox_toggled), (css_edit_button_clicked_cb), (prefs_dialog_init): Rework font prefs, and add user stylesheet setting. * src/bookmarks/ephy-bookmark-action-group.c: (node_added_cb): * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_get_local): * src/window-commands.c: (window_cmd_file_bookmark_page): Some build fixes.
Diffstat (limited to 'lib/ephy-file-helpers.c')
-rw-r--r--lib/ephy-file-helpers.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index a6db91d70..60d9a8790 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -954,3 +954,151 @@ ephy_file_launch_handler (const char *mime_type,
return ret;
}
+
+#define DELAY_MAX_TICKS 64
+
+struct _EphyFileMonitor
+{
+ GnomeVFSMonitorHandle *handle;
+ EphyFileMonitorFunc callback;
+ EphyFileMonitorDelayFunc delay_func;
+ gpointer user_data;
+ char *uri;
+ guint delay;
+ guint timeout_id;
+ guint ticks;
+};
+
+static gboolean
+ephy_file_monitor_timeout_cb (EphyFileMonitor *monitor)
+{
+ if (monitor->ticks > 0)
+ {
+ monitor->ticks--;
+
+ /* Run again */
+ return TRUE;
+ }
+
+ if (monitor->delay_func &&
+ monitor->delay_func (monitor, monitor->user_data))
+ {
+ monitor->ticks = DELAY_MAX_TICKS / 2;
+
+ /* Run again */
+ return TRUE;
+ }
+
+ monitor->timeout_id = 0;
+
+ monitor->callback (monitor, monitor->uri, monitor->user_data);
+
+ /* don't run again */
+ return FALSE;
+}
+
+static void
+ephy_file_monitor_cb (GnomeVFSMonitorHandle *handle,
+ const char *monitor_uri,
+ const char *info_uri,
+ GnomeVFSMonitorEventType event_type,
+ EphyFileMonitor *monitor)
+{
+ LOG ("File '%s' has changed, scheduling reload", monitor_uri);
+
+ switch (event_type)
+ {
+ case GNOME_VFS_MONITOR_EVENT_CHANGED:
+ case GNOME_VFS_MONITOR_EVENT_CREATED:
+ /* We make a lot of assumptions here, but basically we know
+ * that we just have to reload, by construction.
+ * Delay the reload a little bit so we don't endlessly
+ * reload while a file is written.
+ */
+ if (monitor->ticks == 0)
+ {
+ monitor->ticks = 1;
+ }
+ else
+ {
+ /* Exponential backoff */
+ monitor->ticks = MIN (monitor->ticks * 2,
+ DELAY_MAX_TICKS);
+ }
+
+ if (monitor->timeout_id == 0)
+ {
+ monitor->timeout_id =
+ g_timeout_add (monitor->delay,
+ (GSourceFunc) ephy_file_monitor_timeout_cb,
+ monitor);
+ }
+
+ break;
+
+ case GNOME_VFS_MONITOR_EVENT_DELETED:
+ case GNOME_VFS_MONITOR_EVENT_STARTEXECUTING:
+ case GNOME_VFS_MONITOR_EVENT_STOPEXECUTING:
+ case GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED:
+ default:
+ break;
+ }
+}
+
+EphyFileMonitor *
+ephy_file_monitor_add (const char *uri,
+ GnomeVFSMonitorType monitor_type,
+ guint delay,
+ EphyFileMonitorFunc callback,
+ EphyFileMonitorDelayFunc delay_func,
+ gpointer user_data)
+{
+ EphyFileMonitor *monitor;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (callback, NULL);
+
+ monitor = g_new (EphyFileMonitor, 1);
+ monitor->callback = callback;
+ monitor->delay_func = delay_func;
+ monitor->user_data = user_data;
+ monitor->uri = g_strdup (uri);
+ monitor->delay = delay;
+ monitor->ticks = 0;
+ monitor->timeout_id = 0;
+
+ if (gnome_vfs_monitor_add (&monitor->handle, uri, monitor_type,
+ (GnomeVFSMonitorCallback) ephy_file_monitor_cb,
+ monitor) != GNOME_VFS_OK)
+ {
+ LOG ("Failed to add file monitor for '%s'", uri);
+
+ g_free (monitor->uri);
+ g_free (monitor);
+ return NULL;
+ }
+
+ LOG ("File monitor for '%s' added", uri);
+
+ return monitor;
+}
+
+void
+ephy_file_monitor_cancel (EphyFileMonitor *monitor)
+{
+ g_return_if_fail (monitor != NULL);
+ g_return_if_fail (monitor->handle != NULL);
+ g_return_if_fail (monitor->uri != NULL);
+
+ LOG ("Cancelling file monitor for '%s'", monitor->uri);
+
+ gnome_vfs_monitor_cancel (monitor->handle);
+
+ if (monitor->timeout_id != 0)
+ {
+ g_source_remove (monitor->timeout_id);
+ }
+
+ g_free (monitor->uri);
+ g_free (monitor);
+}