/* 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
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)
{
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;
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);
}
g_bookmark_file_to_file (priv->recent_items,
priv->filename,
&write_error);
+
if (write_error)
{
filename_warning ("Attempting to store changes into `%s', "
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.
priv->filename,
g_strerror (errno));
- priv->write_in_progress = FALSE;
-
g_object_thaw_notify (G_OBJECT (manager));
return;
* 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.
*/
gboolean
gtk_recent_manager_add_item (GtkRecentManager *manager,
- const gchar *uri,
- GError **error)
+ const gchar *uri)
{
GtkRecentData *recent_data;
GError *add_error;
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;
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);
g_slice_free (GtkRecentData, recent_data);
- if (!retval)
- {
- g_propagate_error (error, add_error);
-
- return FALSE;
- }
-
return retval;
}
* @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
gboolean
gtk_recent_manager_add_full (GtkRecentManager *manager,
const gchar *uri,
- const GtkRecentData *data,
- GError **error)
+ const GtkRecentData *data)
{
GtkRecentManagerPrivate *priv;
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;
}
* 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,
* @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
const gchar *app_name,
gchar **app_exec,
guint *count,
- time_t *time)
+ time_t *time_)
{
RecentAppInfo *ai;
if (count)
*count = ai->count;
- if (time)
- *time = ai->stamp;
+ if (time_)
+ *time_ = ai->stamp;
return TRUE;
}
{
g_return_val_if_fail (info != NULL, FALSE);
- return g_str_has_prefix (info->uri, "file://");
+ return has_case_prefix (info->uri, "file:/");
}
/**
gchar *name = NULL;
gboolean validated = FALSE;
- if (g_str_has_prefix (uri, "file://"))
+ if (has_case_prefix (uri, "file:/"))
{
gchar *local_file;