]> www.fi.muni.cz Git - evince.git/blobdiff - cut-n-paste/recent-files/egg-recent-model.c
Make frontends depend on just libev. Rework and group CFLAGS/LIBS
[evince.git] / cut-n-paste / recent-files / egg-recent-model.c
index f36053bc2585e03b2317d0a4615a3daaf47ca03c..067a6353f88ee1ae84af31973ecc6782b55e4df0 100644 (file)
@@ -1,5 +1,5 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/**
+/*
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as
  * published by the Free Software Foundation; either version 2 of the
@@ -193,7 +193,9 @@ egg_recent_model_write_raw (EggRecentModel *model, FILE *file,
        if (fputs (content, file) == EOF)
                return FALSE;
 
+#ifndef G_OS_WIN32
        fsync (fd);
+#endif
        rewind (file);
 
        return TRUE;
@@ -643,6 +645,8 @@ egg_recent_model_monitor_list (EggRecentModel *model, GList *list)
 static gboolean
 egg_recent_model_changed_timeout (EggRecentModel *model)
 {
+       model->priv->changed_timeout = 0;
+
        egg_recent_model_changed (model);
 
        return FALSE;
@@ -677,12 +681,17 @@ static void
 egg_recent_model_monitor (EggRecentModel *model, gboolean should_monitor)
 {
        if (should_monitor && model->priv->monitor == NULL) {
+               char *uri;
+
+               uri = gnome_vfs_get_uri_from_local_path (model->priv->path);
 
                gnome_vfs_monitor_add (&model->priv->monitor,
-                                            model->priv->path,
-                                            GNOME_VFS_MONITOR_FILE,
-                                            egg_recent_model_monitor_cb,
-                                            model);
+                                      uri,
+                                      GNOME_VFS_MONITOR_FILE,
+                                      egg_recent_model_monitor_cb,
+                                      model);
+
+               g_free (uri);
 
                /* if the above fails, don't worry about it.
                 * local notifications will still happen
@@ -877,6 +886,7 @@ egg_recent_model_open_file (EggRecentModel *model)
 static gboolean
 egg_recent_model_lock_file (FILE *file)
 {
+#ifdef F_TLOCK
        int fd;
        gint    try = 5;
 
@@ -906,17 +916,24 @@ egg_recent_model_lock_file (FILE *file)
        }
 
        return FALSE;
+#else
+       return TRUE;
+#endif
 }
 
 static gboolean
 egg_recent_model_unlock_file (FILE *file)
 {
+#ifdef F_TLOCK
        int fd;
 
        rewind (file);
        fd = fileno (file);
 
        return (lockf (fd, F_ULOCK, 0) == 0) ? TRUE : FALSE;
+#else
+       return TRUE;
+#endif
 }
 
 static void
@@ -924,6 +941,10 @@ egg_recent_model_finalize (GObject *object)
 {
        EggRecentModel *model = EGG_RECENT_MODEL (object);
 
+       if (model->priv->changed_timeout > 0) {
+               g_source_remove (model->priv->changed_timeout);
+       }
+
        egg_recent_model_monitor (model, FALSE);
 
 
@@ -1286,6 +1307,7 @@ egg_recent_model_add_full (EggRecentModel * model, EggRecentItem *item)
                ret = TRUE;
        } else {
                g_warning ("Failed to lock:  %s", strerror (errno));
+               fclose (file);
                return FALSE;
        }