]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrecentmanager.c
Fix typos
[~andy/gtk] / gtk / gtkrecentmanager.c
index 6b727a8f84b146239c4420d8c441364a1dc4e67b..aadeb60418647df16e6abf6daa2045769cfc5e22 100644 (file)
@@ -48,8 +48,8 @@
 /* the file where we store the recently used items */
 #define GTK_RECENTLY_USED_FILE ".recently-used.xbel"
 
-/* a poll per second should be enough */
-#define POLL_DELTA     1000
+/* a poll every two seconds should be enough */
+#define POLL_DELTA     2000
 
 /* return all items by default */
 #define DEFAULT_LIMIT  -1
@@ -150,23 +150,44 @@ static void           gtk_recent_info_free            (GtkRecentInfo         *re
 
 static guint signal_changed = 0;
 
-G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT);
+G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
 
-void
-filename_warning (const char *format, const char *filename, const char *message)
+static void
+filename_warning (const gchar *format, 
+                  const gchar *filename, 
+                  const gchar *message)
 {
-  char *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
+  gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
   g_warning (format, utf8 ? utf8 : "(invalid filename)", message);
   g_free (utf8);
 }
 
+/* Test of haystack has the needle prefix, comparing case
+ * insensitive. haystack may be UTF-8, but needle must
+ * contain only lowercase ascii. */
+static gboolean
+has_case_prefix (const gchar *haystack, 
+                 const gchar *needle)
+{
+  const gchar *h, *n;
+
+  /* Eat one character at a time. */
+  h = haystack;
+  n = needle;
+
+  while (*n && *h && *n == g_ascii_tolower (*h))
+    {
+      n++;
+      h++;
+    }
+
+  return *n == '\0';
+}
+
 GQuark
 gtk_recent_manager_error_quark (void)
 {
-  static GQuark quark = 0;
-  if (quark == 0)
-    quark = g_quark_from_static_string ("gtk-recent-manager-error-quark");
-  return quark;
+  return g_quark_from_static_string ("gtk-recent-manager-error-quark");
 }
 
 
@@ -262,10 +283,6 @@ gtk_recent_manager_init (GtkRecentManager *manager)
                                      GTK_TYPE_RECENT_MANAGER);
   manager->priv = priv;
   
-  priv->filename = g_build_filename (g_get_home_dir (),
-                                    GTK_RECENTLY_USED_FILE,
-                                    NULL);
-  
   priv->limit = DEFAULT_LIMIT;
   priv->size = 0;
   
@@ -275,6 +292,15 @@ gtk_recent_manager_init (GtkRecentManager *manager)
   priv->read_in_progress = FALSE;
 
   priv->screen = NULL;
+
+  priv->filename = g_build_filename (g_get_home_dir (),
+                                    GTK_RECENTLY_USED_FILE,
+                                    NULL);
+  priv->poll_timeout = g_timeout_add (POLL_DELTA,
+                                     gtk_recent_manager_poll_timeout,
+                                     manager);
+
+  build_recent_items_list (manager);
 }
 
 static void
@@ -376,6 +402,7 @@ gtk_recent_manager_real_changed (GtkRecentManager *manager)
       g_bookmark_file_to_file (priv->recent_items,
                               priv->filename,
                               &write_error);
+
       if (write_error)
         {
           filename_warning ("Attempting to store changes into `%s', "
@@ -385,6 +412,8 @@ gtk_recent_manager_real_changed (GtkRecentManager *manager)
          g_error_free (write_error);
        }
 
+      priv->write_in_progress = FALSE;
+         
       /* we have sync'ed our list with the storage file, so we
        * update the file mtime in order to skip the timed check
        * and spare us from a re-read.
@@ -396,8 +425,6 @@ gtk_recent_manager_real_changed (GtkRecentManager *manager)
                            priv->filename,
                            g_strerror (errno));
 
-         priv->write_in_progress = FALSE;
-         
          g_object_thaw_notify (G_OBJECT (manager));
 
          return;
@@ -480,19 +507,22 @@ gtk_recent_manager_set_filename (GtkRecentManager *manager,
       manager->priv->poll_timeout = 0;
     }
 
-  build_recent_items_list (manager);
-  
   priv->filename = g_strdup (filename);
   priv->poll_timeout = g_timeout_add (POLL_DELTA,
                                      gtk_recent_manager_poll_timeout,
                                      manager);
 
+  /* mark us clean, so that we can re-read the list
+   * of recently used resources
+   */
   priv->is_dirty = FALSE;
+  build_recent_items_list (manager);
 }
 
 /* reads the recently used resources file and builds the items list.
  * we keep the items list inside the parser object, and build the
  * RecentInfo object only on user's demand to avoid useless replication.
+ * this function resets the dirty bit of the manager.
  */
 static void
 build_recent_items_list (GtkRecentManager *manager)
@@ -567,6 +597,7 @@ build_recent_items_list (GtkRecentManager *manager)
     }
 
   priv->read_in_progress = FALSE;
+  priv->is_dirty = FALSE;
 }
 
 
@@ -594,20 +625,7 @@ build_recent_items_list (GtkRecentManager *manager)
 GtkRecentManager *
 gtk_recent_manager_new (void)
 {
-  GtkRecentManager *retval;
-  gchar *filename;
-
-  filename = g_build_filename (g_get_home_dir (),
-                               GTK_RECENTLY_USED_FILE,
-                              NULL);
-  
-  retval = g_object_new (GTK_TYPE_RECENT_MANAGER,
-                         "filename", filename,
-                        NULL);
-  
-  g_free (filename);
-
-  return retval;
+  return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
 }
 
 /**
@@ -685,7 +703,7 @@ display_closed (GdkDisplay       *display,
 
   if (was_screen_singleton)
     {
-      g_object_set_data (G_OBJECT (screen), I_("gtk-recent-manager-error-quark"), NULL);
+      g_object_set_data (G_OBJECT (screen), I_("gtk-recent-manager-default"), NULL);
       priv->is_screen_singleton = FALSE;
     }
 
@@ -798,7 +816,6 @@ gtk_recent_manager_get_limit (GtkRecentManager *manager)
  * gtk_recent_manager_add_item:
  * @manager: a #GtkRecentManager
  * @uri: a valid URI
- * @error: return location for a #GError, or %NULL
  *
  * Adds a new resource, pointed by @uri, into the recently used
  * resources list.
@@ -817,8 +834,7 @@ gtk_recent_manager_get_limit (GtkRecentManager *manager)
  */
 gboolean
 gtk_recent_manager_add_item (GtkRecentManager  *manager,
-                            const gchar       *uri,
-                            GError           **error)
+                            const gchar       *uri)
 {
   GtkRecentData *recent_data;
   GError *add_error;
@@ -833,7 +849,7 @@ gtk_recent_manager_add_item (GtkRecentManager  *manager,
   recent_data->description = NULL;
   
 #ifdef G_OS_UNIX
-  if (g_str_has_prefix (uri, "file://"))
+  if (has_case_prefix (uri, "file:/"))
     {
       gchar *filename;
       const gchar *mime_type;
@@ -859,7 +875,7 @@ gtk_recent_manager_add_item (GtkRecentManager  *manager,
   recent_data->is_private = FALSE;
   
   add_error = NULL;
-  retval = gtk_recent_manager_add_full (manager, uri, recent_data, &add_error);
+  retval = gtk_recent_manager_add_full (manager, uri, recent_data);
   
   g_free (recent_data->mime_type);
   g_free (recent_data->app_name);
@@ -867,13 +883,6 @@ gtk_recent_manager_add_item (GtkRecentManager  *manager,
 
   g_slice_free (GtkRecentData, recent_data);
   
-  if (!retval)
-    {
-      g_propagate_error (error, add_error);
-      
-      return FALSE;
-    }
-  
   return retval;
 }
 
@@ -882,7 +891,6 @@ gtk_recent_manager_add_item (GtkRecentManager  *manager,
  * @manager: a #GtkRecentManager
  * @uri: a valid URI
  * @recent_data: metadata of the resource
- * @error: return location for a #GError, or %NULL
  *
  * Adds a new resource, pointed by @uri, into the recently used
  * resources list, using the metadata specified inside the #GtkRecentData
@@ -912,8 +920,7 @@ gtk_recent_manager_add_item (GtkRecentManager  *manager,
 gboolean
 gtk_recent_manager_add_full (GtkRecentManager     *manager,
                             const gchar          *uri,
-                            const GtkRecentData  *data,
-                            GError              **error)
+                            const GtkRecentData  *data)
 {
   GtkRecentManagerPrivate *priv;
   
@@ -925,53 +932,47 @@ gtk_recent_manager_add_full (GtkRecentManager     *manager,
   if ((data->display_name) &&
       (!g_utf8_validate (data->display_name, -1, NULL)))
     {
-      g_set_error  (error, GTK_RECENT_MANAGER_ERROR,
-                   GTK_RECENT_MANAGER_ERROR_INVALID_ENCODING,
-                   _("The display name of the recently used resource "
-                     "must be a valid UTF-8 encoded string."));
+      g_warning ("Attempting to add `%s' to the list of recently used "
+                "resources, but the display name is not a valid UTF-8 "
+                "encoded string",
+                uri);
       return FALSE;
     }
   
   if ((data->description) &&
       (!g_utf8_validate (data->description, -1, NULL)))
     {
-      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
-                  GTK_RECENT_MANAGER_ERROR_INVALID_ENCODING,
-                  _("The description of the recently used resource "
-                    "must by a valid UTF-8 encoded string."));
+      g_warning ("Attempting to add `%s' to the list of recently used "
+                "resources, but the description is not a valid UTF-8 "
+                "encoded string",
+                uri);
       return FALSE;
     }
 
  
   if (!data->mime_type)
     {
-      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
-                   GTK_RECENT_MANAGER_ERROR_INVALID_MIME,
-                  _("You must specify the MIME type of the "
-                    "resource pointed by `%s'"),
-                  uri);
+      g_warning ("Attempting to add `%s' to the list of recently used "
+                "resources, but not MIME type was defined",
+                uri);
       return FALSE;
     }
   
   if (!data->app_name)
     {
-      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
-                  GTK_RECENT_MANAGER_ERROR_NOT_REGISTERED,
-                  _("You must specify the name of the application "
-                    "that is registering the recently used resource "
-                    "pointed by `%s'"),
-                  uri);
+      g_warning ("Attempting to add `%s' to the list of recently used "
+                "resources, but no name of the application that is "
+                "registering it was defined",
+                uri);
       return FALSE;
     }
   
   if (!data->app_exec)
     {
-      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
-                   GTK_RECENT_MANAGER_ERROR_BAD_EXEC_STRING,
-                  _("You must specify a command line to "
-                    "be used when launching the resource "
-                    "pointed by `%s'"),
-                  uri);
+      g_warning ("Attempting to add `%s' to the list of recently used "
+                "resources, but no command line for the application "
+                "that is registering it was defined",
+                uri);
       return FALSE;
     }
   
@@ -1181,7 +1182,9 @@ build_recent_info (GBookmarkFile  *bookmarks,
  *   about the resource pointed by @uri, or %NULL if the URI was
  *   not registered in the recently used resources list.  Free with
  *   gtk_recent_info_unref().
- **/
+ *
+ * Since: 2.10
+ */
 GtkRecentInfo *
 gtk_recent_manager_lookup_item (GtkRecentManager  *manager,
                                const gchar       *uri,
@@ -1746,7 +1749,7 @@ recent_app_info_free (RecentAppInfo *app_info)
  * @app_name: the name of the application that has registered this item
  * @app_exec: return location for the string containing the command line
  * @count: return location for the number of times this item was registered
- * @time: return location for the timestamp this item was last registered
+ * @time_: return location for the timestamp this item was last registered
  *    for this application
  *
  * Gets the data regarding the application that has registered the resource
@@ -1766,7 +1769,7 @@ gtk_recent_info_get_application_info (GtkRecentInfo  *info,
                                      const gchar    *app_name,
                                      gchar         **app_exec,
                                      guint          *count,
-                                     time_t         *time)
+                                     time_t         *time_)
 {
   RecentAppInfo *ai;
   
@@ -1790,8 +1793,8 @@ gtk_recent_info_get_application_info (GtkRecentInfo  *info,
   if (count)
     *count = ai->count;
   
-  if (time)
-    *time = ai->stamp;
+  if (time_)
+    *time_ = ai->stamp;
 
   return TRUE;
 }
@@ -2072,7 +2075,7 @@ gtk_recent_info_is_local (GtkRecentInfo *info)
 {
   g_return_val_if_fail (info != NULL, FALSE);
   
-  return g_str_has_prefix (info->uri, "file://");
+  return has_case_prefix (info->uri, "file:/");
 }
 
 /**
@@ -2213,7 +2216,7 @@ get_uri_shortname_for_display (const gchar *uri)
   gchar *name = NULL;
   gboolean validated = FALSE;
 
-  if (g_str_has_prefix (uri, "file://"))
+  if (has_case_prefix (uri, "file:/"))
     {
       gchar *local_file;