Blame gtk/gtkrecentmanager.c

Packit Service fb6fa5
/* GTK - The GIMP Toolkit
Packit Service fb6fa5
 * gtkrecentmanager.c: a manager for the recently used resources
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Copyright (C) 2006 Emmanuele Bassi
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is free software; you can redistribute it and/or
Packit Service fb6fa5
 * modify it under the terms of the GNU Library General Public
Packit Service fb6fa5
 * License as published by the Free Software Foundation; either
Packit Service fb6fa5
 * version 2 of the License, or (at your option) any later version.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is distributed in the hope that it will be useful,
Packit Service fb6fa5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fb6fa5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fb6fa5
 * Library General Public License for more details.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You should have received a copy of the GNU Library General Public
Packit Service fb6fa5
 * License along with this library; if not, write to the
Packit Service fb6fa5
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
#include "config.h"
Packit Service fb6fa5
Packit Service fb6fa5
#include <sys/types.h>
Packit Service fb6fa5
#include <sys/stat.h>
Packit Service fb6fa5
#ifdef HAVE_UNISTD_H
Packit Service fb6fa5
#include <unistd.h>
Packit Service fb6fa5
#endif
Packit Service fb6fa5
#include <errno.h>
Packit Service fb6fa5
#include <string.h>
Packit Service fb6fa5
#include <stdlib.h>
Packit Service fb6fa5
#include <glib.h>
Packit Service fb6fa5
#include <glib/gstdio.h>
Packit Service fb6fa5
#include <gio/gio.h>
Packit Service fb6fa5
Packit Service fb6fa5
#include "gtkrecentmanager.h"
Packit Service fb6fa5
#include "gtkintl.h"
Packit Service fb6fa5
#include "gtkstock.h"
Packit Service fb6fa5
#include "gtkicontheme.h"
Packit Service fb6fa5
#include "gtktypebuiltins.h"
Packit Service fb6fa5
#include "gtkprivate.h"
Packit Service fb6fa5
#include "gtkmarshalers.h"
Packit Service fb6fa5
#include "gtkalias.h"
Packit Service fb6fa5
Packit Service fb6fa5
/* the file where we store the recently used items */
Packit Service fb6fa5
#define GTK_RECENTLY_USED_FILE	"recently-used.xbel"
Packit Service fb6fa5
Packit Service fb6fa5
/* return all items by default */
Packit Service fb6fa5
#define DEFAULT_LIMIT	-1
Packit Service fb6fa5
Packit Service fb6fa5
/* limit the size of the list */
Packit Service fb6fa5
#define MAX_LIST_SIZE 1000
Packit Service fb6fa5
Packit Service fb6fa5
/* keep in sync with xdgmime */
Packit Service fb6fa5
#define GTK_RECENT_DEFAULT_MIME	"application/octet-stream"
Packit Service fb6fa5
Packit Service fb6fa5
typedef struct
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *name;
Packit Service fb6fa5
  gchar *exec;
Packit Service fb6fa5
  
Packit Service fb6fa5
  guint count;
Packit Service fb6fa5
  
Packit Service fb6fa5
  time_t stamp;
Packit Service fb6fa5
} RecentAppInfo;
Packit Service fb6fa5
Packit Service fb6fa5
struct _GtkRecentInfo
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *uri;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gchar *display_name;
Packit Service fb6fa5
  gchar *description;
Packit Service fb6fa5
  
Packit Service fb6fa5
  time_t added;
Packit Service fb6fa5
  time_t modified;
Packit Service fb6fa5
  time_t visited;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gchar *mime_type;
Packit Service fb6fa5
  
Packit Service fb6fa5
  GSList *applications;
Packit Service fb6fa5
  GHashTable *apps_lookup;
Packit Service fb6fa5
  
Packit Service fb6fa5
  GSList *groups;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gboolean is_private;
Packit Service fb6fa5
  
Packit Service fb6fa5
  GdkPixbuf *icon;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gint ref_count;
Packit Service fb6fa5
};
Packit Service fb6fa5
Packit Service fb6fa5
#define GTK_RECENT_MANAGER_GET_PRIVATE(obj)     (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RECENT_MANAGER, GtkRecentManagerPrivate))
Packit Service fb6fa5
Packit Service fb6fa5
struct _GtkRecentManagerPrivate
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *filename;
Packit Service fb6fa5
Packit Service fb6fa5
  guint is_dirty : 1;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gint limit;
Packit Service fb6fa5
  gint size;
Packit Service fb6fa5
Packit Service fb6fa5
  GBookmarkFile *recent_items;
Packit Service fb6fa5
Packit Service fb6fa5
  GFileMonitor *monitor;
Packit Service fb6fa5
Packit Service fb6fa5
  guint changed_timeout;
Packit Service fb6fa5
  guint changed_age;
Packit Service fb6fa5
};
Packit Service fb6fa5
Packit Service fb6fa5
enum
Packit Service fb6fa5
{
Packit Service fb6fa5
  PROP_0,
Packit Service fb6fa5
Packit Service fb6fa5
  PROP_FILENAME,  
Packit Service fb6fa5
  PROP_LIMIT,
Packit Service fb6fa5
  PROP_SIZE
Packit Service fb6fa5
};
Packit Service fb6fa5
Packit Service fb6fa5
static void     gtk_recent_manager_dispose             (GObject           *object);
Packit Service fb6fa5
static void     gtk_recent_manager_finalize            (GObject           *object);
Packit Service fb6fa5
static void     gtk_recent_manager_set_property        (GObject           *object,
Packit Service fb6fa5
						        guint              prop_id,
Packit Service fb6fa5
						        const GValue      *value,
Packit Service fb6fa5
						        GParamSpec        *pspec);
Packit Service fb6fa5
static void     gtk_recent_manager_get_property        (GObject           *object,
Packit Service fb6fa5
						        guint              prop_id,
Packit Service fb6fa5
						        GValue            *value,
Packit Service fb6fa5
						        GParamSpec        *pspec);
Packit Service fb6fa5
static void     gtk_recent_manager_add_item_query_info (GObject           *source_object,
Packit Service fb6fa5
                                                        GAsyncResult      *res,
Packit Service fb6fa5
                                                        gpointer           user_data);
Packit Service fb6fa5
static void     gtk_recent_manager_monitor_changed     (GFileMonitor      *monitor,
Packit Service fb6fa5
                                                        GFile             *file,
Packit Service fb6fa5
                                                        GFile             *other_file,
Packit Service fb6fa5
                                                        GFileMonitorEvent  event_type,
Packit Service fb6fa5
                                                        gpointer           user_data);
Packit Service fb6fa5
static void     gtk_recent_manager_changed             (GtkRecentManager  *manager);
Packit Service fb6fa5
static void     gtk_recent_manager_real_changed        (GtkRecentManager  *manager);
Packit Service fb6fa5
static void     gtk_recent_manager_set_filename        (GtkRecentManager  *manager,
Packit Service fb6fa5
                                                        const gchar       *filename);
Packit Service fb6fa5
static void     gtk_recent_manager_clamp_to_age        (GtkRecentManager  *manager,
Packit Service fb6fa5
                                                        gint               age);
Packit Service fb6fa5
static void     gtk_recent_manager_clamp_to_size       (GtkRecentManager  *manager,
Packit Service fb6fa5
                                                        const gint         size);
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
static void build_recent_items_list (GtkRecentManager  *manager);
Packit Service fb6fa5
static void purge_recent_items_list (GtkRecentManager  *manager,
Packit Service fb6fa5
                                     GError           **error);
Packit Service fb6fa5
Packit Service fb6fa5
static RecentAppInfo *recent_app_info_new  (const gchar   *app_name);
Packit Service fb6fa5
static void           recent_app_info_free (RecentAppInfo *app_info);
Packit Service fb6fa5
Packit Service fb6fa5
static GtkRecentInfo *gtk_recent_info_new  (const gchar   *uri);
Packit Service fb6fa5
static void           gtk_recent_info_free (GtkRecentInfo *recent_info);
Packit Service fb6fa5
Packit Service fb6fa5
static guint signal_changed = 0;
Packit Service fb6fa5
Packit Service fb6fa5
static GtkRecentManager *recent_manager_singleton = NULL;
Packit Service fb6fa5
Packit Service fb6fa5
G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
filename_warning (const gchar *format, 
Packit Service fb6fa5
                  const gchar *filename, 
Packit Service fb6fa5
                  const gchar *message)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
Packit Service fb6fa5
  g_warning (format, utf8 ? utf8 : "(invalid filename)", message);
Packit Service fb6fa5
  g_free (utf8);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* Test of haystack has the needle prefix, comparing case
Packit Service fb6fa5
 * insensitive. haystack may be UTF-8, but needle must
Packit Service fb6fa5
 * contain only lowercase ascii. */
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
has_case_prefix (const gchar *haystack, 
Packit Service fb6fa5
                 const gchar *needle)
Packit Service fb6fa5
{
Packit Service fb6fa5
  const gchar *h, *n;
Packit Service fb6fa5
Packit Service fb6fa5
  /* Eat one character at a time. */
Packit Service fb6fa5
  h = haystack;
Packit Service fb6fa5
  n = needle;
Packit Service fb6fa5
Packit Service fb6fa5
  while (*n && *h && *n == g_ascii_tolower (*h))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      n++;
Packit Service fb6fa5
      h++;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return *n == '\0';
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
GQuark
Packit Service fb6fa5
gtk_recent_manager_error_quark (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  return g_quark_from_static_string ("gtk-recent-manager-error-quark");
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_class_init (GtkRecentManagerClass *klass)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gobject_class->set_property = gtk_recent_manager_set_property;
Packit Service fb6fa5
  gobject_class->get_property = gtk_recent_manager_get_property;
Packit Service fb6fa5
  gobject_class->dispose = gtk_recent_manager_dispose;
Packit Service fb6fa5
  gobject_class->finalize = gtk_recent_manager_finalize;
Packit Service fb6fa5
  
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkRecentManager:filename
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * The full path to the file to be used to store and read the recently
Packit Service fb6fa5
   * used resources list
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * Since: 2.10
Packit Service fb6fa5
   */
Packit Service fb6fa5
  g_object_class_install_property (gobject_class,
Packit Service fb6fa5
		  		   PROP_FILENAME,
Packit Service fb6fa5
				   g_param_spec_string ("filename",
Packit Service fb6fa5
					   		P_("Filename"),
Packit Service fb6fa5
							P_("The full path to the file to be used to store and read the list"),
Packit Service fb6fa5
							NULL,
Packit Service fb6fa5
							(G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)));
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkRecentManager:limit
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * The maximum number of items to be returned by the
Packit Service fb6fa5
   * gtk_recent_manager_get_items() function.
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * Since: 2.10
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * Deprecated: 2.22: Setting this property does not have any effect.
Packit Service fb6fa5
   *   The length of the list should be managed by the view (implementing
Packit Service fb6fa5
   *   #GtkRecentChooser), and not by the model (the #GtkRecentManager).
Packit Service fb6fa5
   *   See #GtkRecentChooser:limit.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  g_object_class_install_property (gobject_class,
Packit Service fb6fa5
  				   PROP_LIMIT,
Packit Service fb6fa5
  				   g_param_spec_int ("limit",
Packit Service fb6fa5
  				   		     P_("Limit"),
Packit Service fb6fa5
  				   		     P_("The maximum number of items to be returned by gtk_recent_manager_get_items()"),
Packit Service fb6fa5
  				   		     -1,
Packit Service fb6fa5
  				   		     G_MAXINT,
Packit Service fb6fa5
  				   		     DEFAULT_LIMIT,
Packit Service fb6fa5
                                                     G_PARAM_READWRITE | G_PARAM_DEPRECATED));
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkRecentManager:size
Packit Service fb6fa5
   * 
Packit Service fb6fa5
   * The size of the recently used resources list.
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * Since: 2.10
Packit Service fb6fa5
   */
Packit Service fb6fa5
  g_object_class_install_property (gobject_class,
Packit Service fb6fa5
		  		   PROP_SIZE,
Packit Service fb6fa5
				   g_param_spec_int ("size",
Packit Service fb6fa5
					   	     P_("Size"),
Packit Service fb6fa5
						     P_("The size of the recently used resources list"),
Packit Service fb6fa5
						     -1,
Packit Service fb6fa5
						     G_MAXINT,
Packit Service fb6fa5
						     0,
Packit Service fb6fa5
						     G_PARAM_READABLE));
Packit Service fb6fa5
  
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkRecentManager::changed
Packit Service fb6fa5
   * @recent_manager: the recent manager
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * Emitted when the current recently used resources manager changes its
Packit Service fb6fa5
   * contents.
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * Since: 2.10
Packit Service fb6fa5
   */
Packit Service fb6fa5
  signal_changed =
Packit Service fb6fa5
    g_signal_new (I_("changed"),
Packit Service fb6fa5
		  G_TYPE_FROM_CLASS (klass),
Packit Service fb6fa5
		  G_SIGNAL_RUN_FIRST,
Packit Service fb6fa5
		  G_STRUCT_OFFSET (GtkRecentManagerClass, changed),
Packit Service fb6fa5
		  NULL, NULL,
Packit Service fb6fa5
		  g_cclosure_marshal_VOID__VOID,
Packit Service fb6fa5
		  G_TYPE_NONE, 0);
Packit Service fb6fa5
  
Packit Service fb6fa5
  klass->changed = gtk_recent_manager_real_changed;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_type_class_add_private (klass, sizeof (GtkRecentManagerPrivate));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_init (GtkRecentManager *manager)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
Packit Service fb6fa5
  manager->priv = priv = GTK_RECENT_MANAGER_GET_PRIVATE (manager);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv->limit = DEFAULT_LIMIT;
Packit Service fb6fa5
  priv->size = 0;
Packit Service fb6fa5
Packit Service fb6fa5
  priv->filename = NULL;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_set_property (GObject               *object,
Packit Service fb6fa5
				 guint                  prop_id,
Packit Service fb6fa5
				 const GValue          *value,
Packit Service fb6fa5
				 GParamSpec            *pspec)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
Packit Service fb6fa5
 
Packit Service fb6fa5
  switch (prop_id)
Packit Service fb6fa5
    {
Packit Service fb6fa5
    case PROP_FILENAME:
Packit Service fb6fa5
      gtk_recent_manager_set_filename (recent_manager, g_value_get_string (value));
Packit Service fb6fa5
      break;      
Packit Service fb6fa5
    case PROP_LIMIT:
Packit Service fb6fa5
      gtk_recent_manager_set_limit (recent_manager, g_value_get_int (value));
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    default:
Packit Service fb6fa5
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_get_property (GObject               *object,
Packit Service fb6fa5
				 guint                  prop_id,
Packit Service fb6fa5
				 GValue                *value,
Packit Service fb6fa5
				 GParamSpec            *pspec)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
Packit Service fb6fa5
  
Packit Service fb6fa5
  switch (prop_id)
Packit Service fb6fa5
    {
Packit Service fb6fa5
    case PROP_FILENAME:
Packit Service fb6fa5
      g_value_set_string (value, recent_manager->priv->filename);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case PROP_LIMIT:
Packit Service fb6fa5
      g_value_set_int (value, recent_manager->priv->limit);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case PROP_SIZE:
Packit Service fb6fa5
      g_value_set_int (value, recent_manager->priv->size);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    default:
Packit Service fb6fa5
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    }
Packit Service fb6fa5
} 
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_finalize (GObject *object)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv = manager->priv;
Packit Service fb6fa5
Packit Service fb6fa5
  g_free (priv->filename);
Packit Service fb6fa5
Packit Service fb6fa5
  if (priv->recent_items != NULL)
Packit Service fb6fa5
    g_bookmark_file_free (priv->recent_items);
Packit Service fb6fa5
Packit Service fb6fa5
  G_OBJECT_CLASS (gtk_recent_manager_parent_class)->finalize (object);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_dispose (GObject *gobject)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManager *manager = GTK_RECENT_MANAGER (gobject);
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv = manager->priv;
Packit Service fb6fa5
Packit Service fb6fa5
  if (priv->monitor != NULL)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_signal_handlers_disconnect_by_func (priv->monitor,
Packit Service fb6fa5
                                            G_CALLBACK (gtk_recent_manager_monitor_changed),
Packit Service fb6fa5
                                            manager);
Packit Service fb6fa5
      g_object_unref (priv->monitor);
Packit Service fb6fa5
      priv->monitor = NULL;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  if (priv->changed_timeout != 0)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_source_remove (priv->changed_timeout);
Packit Service fb6fa5
      priv->changed_timeout = 0;
Packit Service fb6fa5
      priv->changed_age = 0;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  if (priv->is_dirty)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_object_ref (manager);
Packit Service fb6fa5
      g_signal_emit (manager, signal_changed, 0);
Packit Service fb6fa5
      g_object_unref (manager);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  G_OBJECT_CLASS (gtk_recent_manager_parent_class)->dispose (gobject);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_real_changed (GtkRecentManager *manager)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv = manager->priv;
Packit Service fb6fa5
Packit Service fb6fa5
  g_object_freeze_notify (G_OBJECT (manager));
Packit Service fb6fa5
Packit Service fb6fa5
  if (priv->is_dirty)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GError *write_error;
Packit Service fb6fa5
      
Packit Service fb6fa5
      /* we are marked as dirty, so we dump the content of our
Packit Service fb6fa5
       * recently used items list
Packit Service fb6fa5
       */
Packit Service fb6fa5
      g_assert (priv->filename != NULL);
Packit Service fb6fa5
Packit Service fb6fa5
      if (!priv->recent_items)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          /* if no container object has been defined, we create a new
Packit Service fb6fa5
           * empty container, and dump it
Packit Service fb6fa5
           */
Packit Service fb6fa5
          priv->recent_items = g_bookmark_file_new ();
Packit Service fb6fa5
	  priv->size = 0;
Packit Service fb6fa5
	}
Packit Service fb6fa5
      else
Packit Service fb6fa5
        {
Packit Service fb6fa5
          GtkSettings *settings = gtk_settings_get_default ();
Packit Service fb6fa5
          gint age = 30;
Packit Service fb6fa5
          gint max_size = MAX_LIST_SIZE;
Packit Service fb6fa5
Packit Service fb6fa5
          g_object_get (G_OBJECT (settings), "gtk-recent-files-max-age", &age, NULL);
Packit Service fb6fa5
          if (age > 0)
Packit Service fb6fa5
            gtk_recent_manager_clamp_to_age (manager, age);
Packit Service fb6fa5
          else if (age == 0)
Packit Service fb6fa5
            {
Packit Service fb6fa5
              g_bookmark_file_free (priv->recent_items);
Packit Service fb6fa5
              priv->recent_items = g_bookmark_file_new ();
Packit Service fb6fa5
            }
Packit Service fb6fa5
Packit Service fb6fa5
          if (max_size > 0)
Packit Service fb6fa5
            gtk_recent_manager_clamp_to_size (manager, max_size);
Packit Service fb6fa5
        }
Packit Service fb6fa5
Packit Service fb6fa5
      write_error = NULL;
Packit Service fb6fa5
      g_bookmark_file_to_file (priv->recent_items, priv->filename, &write_error);
Packit Service fb6fa5
      if (write_error)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          filename_warning ("Attempting to store changes into `%s', "
Packit Service fb6fa5
			    "but failed: %s",
Packit Service fb6fa5
			    priv->filename,
Packit Service fb6fa5
			    write_error->message);
Packit Service fb6fa5
	  g_error_free (write_error);
Packit Service fb6fa5
	}
Packit Service fb6fa5
Packit Service fb6fa5
      if (g_chmod (priv->filename, 0600) < 0)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          filename_warning ("Attempting to set the permissions of `%s', "
Packit Service fb6fa5
                            "but failed: %s",
Packit Service fb6fa5
                            priv->filename,
Packit Service fb6fa5
                            g_strerror (errno));
Packit Service fb6fa5
        }
Packit Service fb6fa5
Packit Service fb6fa5
      /* mark us as clean */
Packit Service fb6fa5
      priv->is_dirty = FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      /* we are not marked as dirty, so we have been called
Packit Service fb6fa5
       * because the recently used resources file has been
Packit Service fb6fa5
       * changed (and not from us).
Packit Service fb6fa5
       */
Packit Service fb6fa5
      build_recent_items_list (manager);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_object_thaw_notify (G_OBJECT (manager));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_monitor_changed (GFileMonitor      *monitor,
Packit Service fb6fa5
                                    GFile             *file,
Packit Service fb6fa5
                                    GFile             *other_file,
Packit Service fb6fa5
                                    GFileMonitorEvent  event_type,
Packit Service fb6fa5
                                    gpointer           user_data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManager *manager = user_data;
Packit Service fb6fa5
Packit Service fb6fa5
  switch (event_type)
Packit Service fb6fa5
    {
Packit Service fb6fa5
    case G_FILE_MONITOR_EVENT_CHANGED:
Packit Service fb6fa5
    case G_FILE_MONITOR_EVENT_CREATED:
Packit Service fb6fa5
      gdk_threads_enter ();
Packit Service fb6fa5
      gtk_recent_manager_changed (manager);
Packit Service fb6fa5
      gdk_threads_leave ();
Packit Service fb6fa5
      break;
Packit Service fb6fa5
Packit Service fb6fa5
    case G_FILE_MONITOR_EVENT_DELETED:
Packit Service fb6fa5
      break;
Packit Service fb6fa5
Packit Service fb6fa5
    default:
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/*
Packit Service fb6fa5
 * get_default_recent_file:
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Retrieves the default storage file
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * The default file is under XDG_DATA_HOME/recently-used.xbel but we also
Packit Service fb6fa5
 * check if the old $HOME/.recently-used.xbel is still there, and rename it
Packit Service fb6fa5
 * if needed.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: a newly allocated string with the new file
Packit Service fb6fa5
 */
Packit Service fb6fa5
static char *
Packit Service fb6fa5
get_default_recent_file (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  char *old_file = g_build_filename (g_get_home_dir (),
Packit Service fb6fa5
                                     "." GTK_RECENTLY_USED_FILE,
Packit Service fb6fa5
                                     NULL);
Packit Service fb6fa5
  char *new_file = g_build_filename (g_get_user_data_dir (),
Packit Service fb6fa5
                                     GTK_RECENTLY_USED_FILE,
Packit Service fb6fa5
                                     NULL);
Packit Service fb6fa5
  GBookmarkFile *bf_old = NULL, *bf_new = NULL;
Packit Service fb6fa5
  char **uris;
Packit Service fb6fa5
  gsize n_uris, i;
Packit Service fb6fa5
Packit Service fb6fa5
  /* simple case: the old file does not exist, so we just use the new one */
Packit Service fb6fa5
  if (!g_file_test (old_file, G_FILE_TEST_EXISTS))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_free (old_file);
Packit Service fb6fa5
      return new_file;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  /* less simple case: the old file still exists but the new one doesn't,
Packit Service fb6fa5
   * so we rename the old one to the new one
Packit Service fb6fa5
   */
Packit Service fb6fa5
  if (!g_file_test (new_file, G_FILE_TEST_EXISTS))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (g_rename (old_file, new_file) == -1)
Packit Service fb6fa5
        filename_warning ("Unable to rename '%s': %s",
Packit Service fb6fa5
                          old_file,
Packit Service fb6fa5
                          g_strerror (errno));
Packit Service fb6fa5
Packit Service fb6fa5
      g_free (old_file);
Packit Service fb6fa5
      return new_file;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  /* complex case: both the old file and the new file exist, so we do
Packit Service fb6fa5
   * a preliminary parse pass and merge the contents, then remove the
Packit Service fb6fa5
   * old file
Packit Service fb6fa5
   */
Packit Service fb6fa5
  bf_old = g_bookmark_file_new ();
Packit Service fb6fa5
  if (!g_bookmark_file_load_from_file (bf_old, old_file, NULL))
Packit Service fb6fa5
    goto unlink_and_return;
Packit Service fb6fa5
Packit Service fb6fa5
  bf_new = g_bookmark_file_new ();
Packit Service fb6fa5
  if (!g_bookmark_file_load_from_file (bf_new, new_file, NULL))
Packit Service fb6fa5
    goto unlink_and_return;
Packit Service fb6fa5
Packit Service fb6fa5
  uris = g_bookmark_file_get_uris (bf_old, &n_uris);
Packit Service fb6fa5
  for (i = 0; i < n_uris; i++)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      char *mime, *title, *description;
Packit Service fb6fa5
      gboolean is_private;
Packit Service fb6fa5
      char **apps;
Packit Service fb6fa5
      gsize n_apps, j;
Packit Service fb6fa5
Packit Service fb6fa5
      /* the new file always wins */
Packit Service fb6fa5
      if (g_bookmark_file_has_item (bf_new, uris[i]))
Packit Service fb6fa5
        continue;
Packit Service fb6fa5
Packit Service fb6fa5
      mime = g_bookmark_file_get_mime_type (bf_old, uris[i], NULL);
Packit Service fb6fa5
      title = g_bookmark_file_get_title (bf_old, uris[i], NULL);
Packit Service fb6fa5
      description = g_bookmark_file_get_description (bf_old, uris[i], NULL);
Packit Service fb6fa5
      is_private = g_bookmark_file_get_is_private (bf_old, uris[i], NULL);
Packit Service fb6fa5
Packit Service fb6fa5
      g_bookmark_file_set_mime_type (bf_new, uris[i], mime);
Packit Service fb6fa5
Packit Service fb6fa5
      if (title != NULL)
Packit Service fb6fa5
        g_bookmark_file_set_title (bf_new, uris[i], title);
Packit Service fb6fa5
Packit Service fb6fa5
      if (description != NULL)
Packit Service fb6fa5
        g_bookmark_file_set_description (bf_new, uris[i], description);
Packit Service fb6fa5
Packit Service fb6fa5
      g_free (mime);
Packit Service fb6fa5
      g_free (title);
Packit Service fb6fa5
      g_free (description);
Packit Service fb6fa5
Packit Service fb6fa5
      g_bookmark_file_set_is_private (bf_new, uris[i], is_private);
Packit Service fb6fa5
Packit Service fb6fa5
      apps = g_bookmark_file_get_applications (bf_old, uris[i], &n_apps, NULL);
Packit Service fb6fa5
      for (j = 0; j < n_apps; j++)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          char *exec;
Packit Service fb6fa5
          guint count;
Packit Service fb6fa5
          time_t stamp;
Packit Service fb6fa5
Packit Service fb6fa5
          g_bookmark_file_get_app_info (bf_old, uris[i], apps[j],
Packit Service fb6fa5
                                        &exec,
Packit Service fb6fa5
                                        &count,
Packit Service fb6fa5
                                        &stamp,
Packit Service fb6fa5
                                        NULL);
Packit Service fb6fa5
Packit Service fb6fa5
          g_bookmark_file_set_app_info (bf_new, uris[i], apps[j],
Packit Service fb6fa5
                                        exec,
Packit Service fb6fa5
                                        count,
Packit Service fb6fa5
                                        stamp,
Packit Service fb6fa5
                                        NULL);
Packit Service fb6fa5
Packit Service fb6fa5
          g_free (exec);
Packit Service fb6fa5
        }
Packit Service fb6fa5
Packit Service fb6fa5
      g_strfreev (apps);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_strfreev (uris);
Packit Service fb6fa5
Packit Service fb6fa5
  /* we don't particularly care about errors here; if it fails then
Packit Service fb6fa5
   * we start with a blank slate anyhow
Packit Service fb6fa5
   */
Packit Service fb6fa5
  g_bookmark_file_to_file (bf_new, new_file, NULL);
Packit Service fb6fa5
Packit Service fb6fa5
unlink_and_return:
Packit Service fb6fa5
  if (bf_old != NULL)
Packit Service fb6fa5
    g_bookmark_file_free (bf_old);
Packit Service fb6fa5
Packit Service fb6fa5
  if (bf_new != NULL)
Packit Service fb6fa5
    g_bookmark_file_free (bf_new);
Packit Service fb6fa5
Packit Service fb6fa5
  g_unlink (old_file);
Packit Service fb6fa5
  g_free (old_file);
Packit Service fb6fa5
Packit Service fb6fa5
  return new_file;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_set_filename (GtkRecentManager *manager,
Packit Service fb6fa5
				 const gchar      *filename)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
  GFile *file;
Packit Service fb6fa5
  GError *error;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_assert (GTK_IS_RECENT_MANAGER (manager));
Packit Service fb6fa5
Packit Service fb6fa5
  priv = manager->priv;
Packit Service fb6fa5
Packit Service fb6fa5
  /* if a filename is already set and filename is not NULL, then copy
Packit Service fb6fa5
   * it and reset the monitor; otherwise, if it's NULL we're being
Packit Service fb6fa5
   * called from the finalization sequence, so we simply disconnect the
Packit Service fb6fa5
   * monitoring and return.
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * if no filename is set and filename is NULL, use the default.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  if (priv->filename)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_free (priv->filename);
Packit Service fb6fa5
Packit Service fb6fa5
      if (priv->monitor)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          g_signal_handlers_disconnect_by_func (priv->monitor,
Packit Service fb6fa5
                                                G_CALLBACK (gtk_recent_manager_monitor_changed),
Packit Service fb6fa5
                                                manager);
Packit Service fb6fa5
          g_object_unref (priv->monitor);
Packit Service fb6fa5
          priv->monitor = NULL;
Packit Service fb6fa5
        }
Packit Service fb6fa5
Packit Service fb6fa5
      if (!filename || *filename == '\0')
Packit Service fb6fa5
        return;
Packit Service fb6fa5
      else
Packit Service fb6fa5
        priv->filename = g_strdup (filename);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (!filename || *filename == '\0')
Packit Service fb6fa5
        priv->filename = get_default_recent_file ();
Packit Service fb6fa5
      else
Packit Service fb6fa5
        priv->filename = g_strdup (filename);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_assert (priv->filename != NULL);
Packit Service fb6fa5
  file = g_file_new_for_path (priv->filename);
Packit Service fb6fa5
Packit Service fb6fa5
  error = NULL;
Packit Service fb6fa5
  priv->monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
Packit Service fb6fa5
  if (error)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      filename_warning ("Unable to monitor `%s': %s\n"
Packit Service fb6fa5
                        "The GtkRecentManager will not update its contents "
Packit Service fb6fa5
                        "if the file is changed from other instances",
Packit Service fb6fa5
                        priv->filename,
Packit Service fb6fa5
                        error->message);
Packit Service fb6fa5
      g_error_free (error);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    g_signal_connect (priv->monitor, "changed",
Packit Service fb6fa5
                      G_CALLBACK (gtk_recent_manager_monitor_changed),
Packit Service fb6fa5
                      manager);
Packit Service fb6fa5
Packit Service fb6fa5
  g_object_unref (file);
Packit Service fb6fa5
Packit Service fb6fa5
  priv->is_dirty = FALSE;
Packit Service fb6fa5
  build_recent_items_list (manager);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* reads the recently used resources file and builds the items list.
Packit Service fb6fa5
 * we keep the items list inside the parser object, and build the
Packit Service fb6fa5
 * RecentInfo object only on user's demand to avoid useless replication.
Packit Service fb6fa5
 * this function resets the dirty bit of the manager.
Packit Service fb6fa5
 */
Packit Service fb6fa5
static void
Packit Service fb6fa5
build_recent_items_list (GtkRecentManager *manager)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv = manager->priv;
Packit Service fb6fa5
  GError *read_error;
Packit Service fb6fa5
  gint size;
Packit Service fb6fa5
Packit Service fb6fa5
  g_assert (priv->filename != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!priv->recent_items)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      priv->recent_items = g_bookmark_file_new ();
Packit Service fb6fa5
      priv->size = 0;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  /* the file exists, and it's valid (we hope); if not, destroy the container
Packit Service fb6fa5
   * object and hope for a better result when the next "changed" signal is
Packit Service fb6fa5
   * fired. */
Packit Service fb6fa5
  read_error = NULL;
Packit Service fb6fa5
  g_bookmark_file_load_from_file (priv->recent_items, priv->filename, &read_error);
Packit Service fb6fa5
  if (read_error)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      /* if the file does not exist we just wait for the first write
Packit Service fb6fa5
       * operation on this recent manager instance, to avoid creating
Packit Service fb6fa5
       * empty files and leading to spurious file system events (Sabayon
Packit Service fb6fa5
       * will not be happy about those)
Packit Service fb6fa5
       */
Packit Service fb6fa5
      if (read_error->domain == G_FILE_ERROR &&
Packit Service fb6fa5
          read_error->code != G_FILE_ERROR_NOENT)
Packit Service fb6fa5
        filename_warning ("Attempting to read the recently used resources "
Packit Service fb6fa5
                          "file at `%s', but the parser failed: %s.",
Packit Service fb6fa5
                          priv->filename,
Packit Service fb6fa5
                          read_error->message);
Packit Service fb6fa5
Packit Service fb6fa5
      g_bookmark_file_free (priv->recent_items);
Packit Service fb6fa5
      priv->recent_items = NULL;
Packit Service fb6fa5
Packit Service fb6fa5
      g_error_free (read_error);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      size = g_bookmark_file_get_size (priv->recent_items);
Packit Service fb6fa5
      if (priv->size != size)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          priv->size = size;
Packit Service fb6fa5
Packit Service fb6fa5
          g_object_notify (G_OBJECT (manager), "size");
Packit Service fb6fa5
        }
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  priv->is_dirty = FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
/********************
Packit Service fb6fa5
 * GtkRecentManager *
Packit Service fb6fa5
 ********************/
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_new:
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Creates a new recent manager object.  Recent manager objects are used to
Packit Service fb6fa5
 * handle the list of recently used resources.  A #GtkRecentManager object
Packit Service fb6fa5
 * monitors the recently used resources list, and emits the "changed" signal
Packit Service fb6fa5
 * each time something inside the list changes.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * #GtkRecentManager objects are expensive: be sure to create them only when
Packit Service fb6fa5
 * needed. You should use gtk_recent_manager_get_default() instead.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: A newly created #GtkRecentManager object.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
GtkRecentManager *
Packit Service fb6fa5
gtk_recent_manager_new (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_get_default:
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets a unique instance of #GtkRecentManager, that you can share
Packit Service fb6fa5
 * in your application without caring about memory management. The
Packit Service fb6fa5
 * returned instance will be freed when you application terminates.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: (transfer none): A unique #GtkRecentManager. Do not ref or unref it.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
GtkRecentManager *
Packit Service fb6fa5
gtk_recent_manager_get_default (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  if (G_UNLIKELY (!recent_manager_singleton))
Packit Service fb6fa5
    recent_manager_singleton = gtk_recent_manager_new ();
Packit Service fb6fa5
Packit Service fb6fa5
  return recent_manager_singleton;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_get_for_screen:
Packit Service fb6fa5
 * @screen: a #GdkScreen
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the recent manager object associated with @screen; if this
Packit Service fb6fa5
 * function has not previously been called for the given screen,
Packit Service fb6fa5
 * a new recent manager object will be created and associated with
Packit Service fb6fa5
 * the screen. Recent manager objects are fairly expensive to create,
Packit Service fb6fa5
 * so using this function is usually a better choice than calling 
Packit Service fb6fa5
 * gtk_recent_manager_new() and setting the screen yourself; by using
Packit Service fb6fa5
 * this function a single recent manager object will be shared between
Packit Service fb6fa5
 * users.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: A unique #GtkRecentManager associated with the given
Packit Service fb6fa5
 *   screen. This recent manager is associated to the with the screen
Packit Service fb6fa5
 *   and can be used as long as the screen is open. Do not ref or
Packit Service fb6fa5
 *   unref it.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Deprecated: 2.12: This function has been deprecated and should
Packit Service fb6fa5
 *   not be used in newly written code. Calling this function is
Packit Service fb6fa5
 *   equivalent to calling gtk_recent_manager_get_default().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
GtkRecentManager *
Packit Service fb6fa5
gtk_recent_manager_get_for_screen (GdkScreen *screen)
Packit Service fb6fa5
{
Packit Service fb6fa5
  return gtk_recent_manager_get_default ();
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_set_screen:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 * @screen: a #GdkScreen
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the screen for a recent manager; the screen is used to
Packit Service fb6fa5
 * track the user's currently configured recently used documents
Packit Service fb6fa5
 * storage.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Deprecated: 2.12: This function has been deprecated and should
Packit Service fb6fa5
 *   not be used in newly written code. Calling this function has
Packit Service fb6fa5
 *   no effect.
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_recent_manager_set_screen (GtkRecentManager *manager,
Packit Service fb6fa5
			       GdkScreen        *screen)
Packit Service fb6fa5
{
Packit Service fb6fa5
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_set_limit:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 * @limit: the maximum number of items to return, or -1.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the maximum number of item that the gtk_recent_manager_get_items()
Packit Service fb6fa5
 * function should return.  If @limit is set to -1, then return all the
Packit Service fb6fa5
 * items.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Deprecated: 2.22: The length of the list should be managed by the
Packit Service fb6fa5
 *   view (implementing #GtkRecentChooser), and not by the model (the
Packit Service fb6fa5
 *   #GtkRecentManager). See #GtkRecentChooser:limit.
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_recent_manager_set_limit (GtkRecentManager *manager,
Packit Service fb6fa5
			      gint              limit)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_RECENT_MANAGER (manager));
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = manager->priv;
Packit Service fb6fa5
  priv->limit = limit;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_get_limit:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the maximum number of items that the gtk_recent_manager_get_items()
Packit Service fb6fa5
 * function should return.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the number of items to return, or -1 for every item.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Deprecated: 2.22: The length of the list should be managed by the
Packit Service fb6fa5
 *   view (implementing #GtkRecentChooser), and not by the model (the
Packit Service fb6fa5
 *   #GtkRecentManager). See #GtkRecentChooser:limit.
Packit Service fb6fa5
 */
Packit Service fb6fa5
gint
Packit Service fb6fa5
gtk_recent_manager_get_limit (GtkRecentManager *manager)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), DEFAULT_LIMIT);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = manager->priv;
Packit Service fb6fa5
  return priv->limit;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_add_item_query_info (GObject      *source_object,
Packit Service fb6fa5
                                        GAsyncResult *res,
Packit Service fb6fa5
                                        gpointer      user_data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GFile *file = G_FILE (source_object);
Packit Service fb6fa5
  GtkRecentManager *manager = user_data;
Packit Service fb6fa5
  GtkRecentData recent_data;
Packit Service fb6fa5
  GFileInfo *file_info;
Packit Service fb6fa5
  gchar *uri;
Packit Service fb6fa5
Packit Service fb6fa5
  uri = g_file_get_uri (file);
Packit Service fb6fa5
Packit Service fb6fa5
  file_info = g_file_query_info_finish (file, res, NULL); /* NULL-GError */
Packit Service fb6fa5
Packit Service fb6fa5
  recent_data.display_name = NULL;
Packit Service fb6fa5
  recent_data.description = NULL;
Packit Service fb6fa5
Packit Service fb6fa5
  if (file_info)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *content_type;
Packit Service fb6fa5
Packit Service fb6fa5
      content_type = g_file_info_get_attribute_as_string (file_info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
Packit Service fb6fa5
Packit Service fb6fa5
      if (G_LIKELY (content_type))
Packit Service fb6fa5
        recent_data.mime_type = g_content_type_get_mime_type (content_type);
Packit Service fb6fa5
      else
Packit Service fb6fa5
        recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
Packit Service fb6fa5
Packit Service fb6fa5
      g_free (content_type);
Packit Service fb6fa5
      g_object_unref (file_info);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME); /* FIXME: maybe we should make up the MIME type from the filename's extension */
Packit Service fb6fa5
Packit Service fb6fa5
  recent_data.app_name = g_strdup (g_get_application_name ());
Packit Service fb6fa5
  recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
Packit Service fb6fa5
  recent_data.groups = NULL;
Packit Service fb6fa5
  recent_data.is_private = FALSE;
Packit Service fb6fa5
Packit Service fb6fa5
  gdk_threads_enter ();
Packit Service fb6fa5
Packit Service fb6fa5
  /* Ignore return value, this can't fail anyway since all required
Packit Service fb6fa5
   * fields are set */
Packit Service fb6fa5
  gtk_recent_manager_add_full (manager, uri, &recent_data);
Packit Service fb6fa5
Packit Service fb6fa5
  manager->priv->is_dirty = TRUE;
Packit Service fb6fa5
  gtk_recent_manager_changed (manager);
Packit Service fb6fa5
Packit Service fb6fa5
  gdk_threads_leave ();
Packit Service fb6fa5
Packit Service fb6fa5
  g_free (recent_data.mime_type);
Packit Service fb6fa5
  g_free (recent_data.app_name);
Packit Service fb6fa5
  g_free (recent_data.app_exec);
Packit Service fb6fa5
Packit Service fb6fa5
  g_object_unref (manager);
Packit Service fb6fa5
  g_free (uri);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_add_item:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 * @uri: a valid URI
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Adds a new resource, pointed by @uri, into the recently used
Packit Service fb6fa5
 * resources list.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This function automatically retrieves some of the needed
Packit Service fb6fa5
 * metadata and setting other metadata to common default values; it
Packit Service fb6fa5
 * then feeds the data to gtk_recent_manager_add_full().
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * See gtk_recent_manager_add_full() if you want to explicitly
Packit Service fb6fa5
 * define the metadata for the resource pointed by @uri.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if the new item was successfully added
Packit Service fb6fa5
 *   to the recently used resources list
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_manager_add_item (GtkRecentManager  *manager,
Packit Service fb6fa5
			     const gchar       *uri)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GFile* file;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (uri != NULL, FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  file = g_file_new_for_uri (uri);
Packit Service fb6fa5
Packit Service fb6fa5
  g_file_query_info_async (file,
Packit Service fb6fa5
                           G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
Packit Service fb6fa5
                           G_PRIORITY_DEFAULT,
Packit Service fb6fa5
                           G_FILE_QUERY_INFO_NONE,
Packit Service fb6fa5
                           NULL,
Packit Service fb6fa5
                           gtk_recent_manager_add_item_query_info,
Packit Service fb6fa5
                           g_object_ref (manager));
Packit Service fb6fa5
Packit Service fb6fa5
  g_object_unref (file);
Packit Service fb6fa5
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_add_full:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 * @uri: a valid URI
Packit Service fb6fa5
 * @recent_data: metadata of the resource
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Adds a new resource, pointed by @uri, into the recently used
Packit Service fb6fa5
 * resources list, using the metadata specified inside the #GtkRecentData
Packit Service fb6fa5
 * structure passed in @recent_data.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * The passed URI will be used to identify this resource inside the
Packit Service fb6fa5
 * list.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * In order to register the new recently used resource, metadata about
Packit Service fb6fa5
 * the resource must be passed as well as the URI; the metadata is
Packit Service fb6fa5
 * stored in a #GtkRecentData structure, which must contain the MIME
Packit Service fb6fa5
 * type of the resource pointed by the URI; the name of the application
Packit Service fb6fa5
 * that is registering the item, and a command line to be used when
Packit Service fb6fa5
 * launching the item.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Optionally, a #GtkRecentData structure might contain a UTF-8 string
Packit Service fb6fa5
 * to be used when viewing the item instead of the last component of the
Packit Service fb6fa5
 * URI; a short description of the item; whether the item should be
Packit Service fb6fa5
 * considered private - that is, should be displayed only by the
Packit Service fb6fa5
 * applications that have registered it.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if the new item was successfully added to the
Packit Service fb6fa5
 * recently used resources list, %FALSE otherwise.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_manager_add_full (GtkRecentManager     *manager,
Packit Service fb6fa5
			     const gchar          *uri,
Packit Service fb6fa5
			     const GtkRecentData  *data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (uri != NULL, FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (data != NULL, FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  /* sanity checks */
Packit Service fb6fa5
  if ((data->display_name) &&
Packit Service fb6fa5
      (!g_utf8_validate (data->display_name, -1, NULL)))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_warning ("Attempting to add `%s' to the list of recently used "
Packit Service fb6fa5
		 "resources, but the display name is not a valid UTF-8 "
Packit Service fb6fa5
          	 "encoded string",
Packit Service fb6fa5
		 uri);
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  if ((data->description) &&
Packit Service fb6fa5
      (!g_utf8_validate (data->description, -1, NULL)))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_warning ("Attempting to add `%s' to the list of recently used "
Packit Service fb6fa5
		 "resources, but the description is not a valid UTF-8 "
Packit Service fb6fa5
          	 "encoded string",
Packit Service fb6fa5
		 uri);
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
 
Packit Service fb6fa5
  if (!data->mime_type)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_warning ("Attempting to add `%s' to the list of recently used "
Packit Service fb6fa5
		 "resources, but not MIME type was defined",
Packit Service fb6fa5
		 uri);
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!data->app_name)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_warning ("Attempting to add `%s' to the list of recently used "
Packit Service fb6fa5
		 "resources, but no name of the application that is "
Packit Service fb6fa5
		 "registering it was defined",
Packit Service fb6fa5
      		 uri);
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!data->app_exec)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_warning ("Attempting to add `%s' to the list of recently used "
Packit Service fb6fa5
		 "resources, but no command line for the application "
Packit Service fb6fa5
		 "that is registering it was defined",
Packit Service fb6fa5
		 uri);
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = manager->priv;
Packit Service fb6fa5
Packit Service fb6fa5
  if (!priv->recent_items)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      priv->recent_items = g_bookmark_file_new ();
Packit Service fb6fa5
      priv->size = 0;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  if (data->display_name)  
Packit Service fb6fa5
    g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (data->description)
Packit Service fb6fa5
    g_bookmark_file_set_description (priv->recent_items, uri, data->description);
Packit Service fb6fa5
Packit Service fb6fa5
  g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (data->groups && data->groups[0] != '\0')
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gint j;
Packit Service fb6fa5
      
Packit Service fb6fa5
      for (j = 0; (data->groups)[j] != NULL; j++)
Packit Service fb6fa5
        g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* register the application; this will take care of updating the
Packit Service fb6fa5
   * registration count and time in case the application has
Packit Service fb6fa5
   * already registered the same document inside the list
Packit Service fb6fa5
   */
Packit Service fb6fa5
  g_bookmark_file_add_application (priv->recent_items, uri,
Packit Service fb6fa5
		  		   data->app_name,
Packit Service fb6fa5
				   data->app_exec);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_bookmark_file_set_is_private (priv->recent_items, uri,
Packit Service fb6fa5
		  		  data->is_private);
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* mark us as dirty, so that when emitting the "changed" signal we
Packit Service fb6fa5
   * will dump our changes
Packit Service fb6fa5
   */
Packit Service fb6fa5
  priv->is_dirty = TRUE;
Packit Service fb6fa5
  gtk_recent_manager_changed (manager);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_remove_item:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 * @uri: the URI of the item you wish to remove
Packit Service fb6fa5
 * @error: (allow-none): return location for a #GError, or %NULL
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Removes a resource pointed by @uri from the recently used resources
Packit Service fb6fa5
 * list handled by a recent manager.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if the item pointed by @uri has been successfully
Packit Service fb6fa5
 *   removed by the recently used resources list, and %FALSE otherwise.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_manager_remove_item (GtkRecentManager  *manager,
Packit Service fb6fa5
				const gchar       *uri,
Packit Service fb6fa5
				GError           **error)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
  GError *remove_error = NULL;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (uri != NULL, FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = manager->priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!priv->recent_items)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      priv->recent_items = g_bookmark_file_new ();
Packit Service fb6fa5
      priv->size = 0;
Packit Service fb6fa5
Packit Service fb6fa5
      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
Packit Service fb6fa5
		   GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
Packit Service fb6fa5
		   _("Unable to find an item with URI '%s'"),
Packit Service fb6fa5
		   uri);
Packit Service fb6fa5
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
Packit Service fb6fa5
  if (remove_error)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_error_free (remove_error);
Packit Service fb6fa5
Packit Service fb6fa5
      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
Packit Service fb6fa5
		   GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
Packit Service fb6fa5
		   _("Unable to find an item with URI '%s'"),
Packit Service fb6fa5
		   uri);
Packit Service fb6fa5
      
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  priv->is_dirty = TRUE;
Packit Service fb6fa5
  gtk_recent_manager_changed (manager);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_has_item:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 * @uri: a URI
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Checks whether there is a recently used resource registered
Packit Service fb6fa5
 * with @uri inside the recent manager.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if the resource was found, %FALSE otherwise.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_manager_has_item (GtkRecentManager *manager,
Packit Service fb6fa5
			     const gchar      *uri)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (uri != NULL, FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  priv = manager->priv;
Packit Service fb6fa5
  g_return_val_if_fail (priv->recent_items != NULL, FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  return g_bookmark_file_has_item (priv->recent_items, uri);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
build_recent_info (GBookmarkFile  *bookmarks,
Packit Service fb6fa5
		   GtkRecentInfo  *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar **apps, **groups;
Packit Service fb6fa5
  gsize apps_len, groups_len, i;
Packit Service fb6fa5
Packit Service fb6fa5
  g_assert (bookmarks != NULL);
Packit Service fb6fa5
  g_assert (info != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
Packit Service fb6fa5
  info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
Packit Service fb6fa5
  info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
Packit Service fb6fa5
    
Packit Service fb6fa5
  info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
Packit Service fb6fa5
  info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
Packit Service fb6fa5
  info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
Packit Service fb6fa5
  for (i = 0; i < groups_len; i++)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *group_name = g_strdup (groups[i]);
Packit Service fb6fa5
      
Packit Service fb6fa5
      info->groups = g_slist_append (info->groups, group_name);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_strfreev (groups);
Packit Service fb6fa5
  
Packit Service fb6fa5
  apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
Packit Service fb6fa5
  for (i = 0; i < apps_len; i++)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *app_name, *app_exec;
Packit Service fb6fa5
      guint count;
Packit Service fb6fa5
      time_t stamp;
Packit Service fb6fa5
      RecentAppInfo *app_info;
Packit Service fb6fa5
      gboolean res;
Packit Service fb6fa5
      
Packit Service fb6fa5
      app_name = apps[i];
Packit Service fb6fa5
      
Packit Service fb6fa5
      res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
Packit Service fb6fa5
      					  &app_exec,
Packit Service fb6fa5
      					  &count,
Packit Service fb6fa5
      					  &stamp,
Packit Service fb6fa5
      					  NULL);
Packit Service fb6fa5
      if (!res)
Packit Service fb6fa5
        continue;
Packit Service fb6fa5
      
Packit Service fb6fa5
      app_info = recent_app_info_new (app_name);
Packit Service fb6fa5
      app_info->exec = app_exec;
Packit Service fb6fa5
      app_info->count = count;
Packit Service fb6fa5
      app_info->stamp = stamp;
Packit Service fb6fa5
      
Packit Service fb6fa5
      info->applications = g_slist_prepend (info->applications, app_info);
Packit Service fb6fa5
      g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_strfreev (apps);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_lookup_item:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 * @uri: a URI
Packit Service fb6fa5
 * @error: (allow-none): a return location for a #GError, or %NULL
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Searches for a URI inside the recently used resources list, and
Packit Service fb6fa5
 * returns a structure containing informations about the resource
Packit Service fb6fa5
 * like its MIME type, or its display name.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: a #GtkRecentInfo structure containing information
Packit Service fb6fa5
 *   about the resource pointed by @uri, or %NULL if the URI was
Packit Service fb6fa5
 *   not registered in the recently used resources list.  Free with
Packit Service fb6fa5
 *   gtk_recent_info_unref().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
GtkRecentInfo *
Packit Service fb6fa5
gtk_recent_manager_lookup_item (GtkRecentManager  *manager,
Packit Service fb6fa5
				const gchar       *uri,
Packit Service fb6fa5
				GError           **error)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
  GtkRecentInfo *info = NULL;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
Packit Service fb6fa5
  g_return_val_if_fail (uri != NULL, NULL);
Packit Service fb6fa5
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = manager->priv;
Packit Service fb6fa5
  if (!priv->recent_items)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      priv->recent_items = g_bookmark_file_new ();
Packit Service fb6fa5
      priv->size = 0;
Packit Service fb6fa5
Packit Service fb6fa5
      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
Packit Service fb6fa5
		   GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
Packit Service fb6fa5
		   _("Unable to find an item with URI '%s'"),
Packit Service fb6fa5
		   uri);
Packit Service fb6fa5
Packit Service fb6fa5
      return NULL;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!g_bookmark_file_has_item (priv->recent_items, uri))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
Packit Service fb6fa5
      		   GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
Packit Service fb6fa5
      		   _("Unable to find an item with URI '%s'"),
Packit Service fb6fa5
      		   uri);
Packit Service fb6fa5
      return NULL;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  info = gtk_recent_info_new (uri);
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* fill the RecentInfo structure with the data retrieved by our
Packit Service fb6fa5
   * parser object from the storage file 
Packit Service fb6fa5
   */
Packit Service fb6fa5
  build_recent_info (priv->recent_items, info);
Packit Service fb6fa5
Packit Service fb6fa5
  return info;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_move_item:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 * @uri: the URI of a recently used resource
Packit Service fb6fa5
 * @new_uri: (allow-none): the new URI of the recently used resource, or %NULL to
Packit Service fb6fa5
 *    remove the item pointed by @uri in the list
Packit Service fb6fa5
 * @error: (allow-none): a return location for a #GError, or %NULL
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Changes the location of a recently used resource from @uri to @new_uri.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Please note that this function will not affect the resource pointed
Packit Service fb6fa5
 * by the URIs, but only the URI used in the recently used resources list.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE on success.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */ 
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_manager_move_item (GtkRecentManager  *recent_manager,
Packit Service fb6fa5
			      const gchar       *uri,
Packit Service fb6fa5
			      const gchar       *new_uri,
Packit Service fb6fa5
			      GError           **error)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
  GError *move_error;
Packit Service fb6fa5
  gboolean res;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (uri != NULL, FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = recent_manager->priv;
Packit Service fb6fa5
Packit Service fb6fa5
  if (!priv->recent_items)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
Packit Service fb6fa5
      		   GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
Packit Service fb6fa5
      		   _("Unable to find an item with URI '%s'"),
Packit Service fb6fa5
      		   uri);
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  if (!g_bookmark_file_has_item (priv->recent_items, uri))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
Packit Service fb6fa5
      		   GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
Packit Service fb6fa5
      		   _("Unable to find an item with URI '%s'"),
Packit Service fb6fa5
      		   uri);
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  move_error = NULL;
Packit Service fb6fa5
  res = g_bookmark_file_move_item (priv->recent_items,
Packit Service fb6fa5
                                   uri, new_uri,
Packit Service fb6fa5
                                   &move_error);
Packit Service fb6fa5
  if (move_error)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_error_free (move_error);
Packit Service fb6fa5
Packit Service fb6fa5
      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
Packit Service fb6fa5
      		   GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
Packit Service fb6fa5
      		   _("Unable to find an item with URI '%s'"),
Packit Service fb6fa5
      		   uri);
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv->is_dirty = TRUE;
Packit Service fb6fa5
  gtk_recent_manager_changed (recent_manager);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_get_items:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the list of recently used resources.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value:  (element-type GtkRecentInfo) (transfer full): a list of
Packit Service fb6fa5
 *   newly allocated #GtkRecentInfo objects. Use
Packit Service fb6fa5
 *   gtk_recent_info_unref() on each item inside the list, and then
Packit Service fb6fa5
 *   free the list itself using g_list_free().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
GList *
Packit Service fb6fa5
gtk_recent_manager_get_items (GtkRecentManager *manager)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
  GList *retval = NULL;
Packit Service fb6fa5
  gchar **uris;
Packit Service fb6fa5
  gsize uris_len, i;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = manager->priv;
Packit Service fb6fa5
  if (!priv->recent_items)
Packit Service fb6fa5
    return NULL;
Packit Service fb6fa5
Packit Service fb6fa5
  uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
Packit Service fb6fa5
  for (i = 0; i < uris_len; i++)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GtkRecentInfo *info;
Packit Service fb6fa5
      
Packit Service fb6fa5
      info = gtk_recent_info_new (uris[i]);
Packit Service fb6fa5
      build_recent_info (priv->recent_items, info);
Packit Service fb6fa5
      
Packit Service fb6fa5
      retval = g_list_prepend (retval, info);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_strfreev (uris);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return retval;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
purge_recent_items_list (GtkRecentManager  *manager,
Packit Service fb6fa5
			 GError           **error)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv = manager->priv;
Packit Service fb6fa5
Packit Service fb6fa5
  if (priv->recent_items == NULL)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
Packit Service fb6fa5
  g_bookmark_file_free (priv->recent_items);
Packit Service fb6fa5
  priv->recent_items = g_bookmark_file_new ();
Packit Service fb6fa5
  priv->size = 0;
Packit Service fb6fa5
Packit Service fb6fa5
  /* emit the changed signal, to ensure that the purge is written */
Packit Service fb6fa5
  priv->is_dirty = TRUE;
Packit Service fb6fa5
  gtk_recent_manager_changed (manager);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_manager_purge_items:
Packit Service fb6fa5
 * @manager: a #GtkRecentManager
Packit Service fb6fa5
 * @error: (allow-none): a return location for a #GError, or %NULL
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Purges every item from the recently used resources list.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the number of items that have been removed from the
Packit Service fb6fa5
 *   recently used resources list.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gint
Packit Service fb6fa5
gtk_recent_manager_purge_items (GtkRecentManager  *manager,
Packit Service fb6fa5
				GError           **error)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv;
Packit Service fb6fa5
  gint count, purged;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
Packit Service fb6fa5
Packit Service fb6fa5
  priv = manager->priv;
Packit Service fb6fa5
  if (!priv->recent_items)
Packit Service fb6fa5
    return 0;
Packit Service fb6fa5
  
Packit Service fb6fa5
  count = g_bookmark_file_get_size (priv->recent_items);
Packit Service fb6fa5
  if (!count)
Packit Service fb6fa5
    return 0;
Packit Service fb6fa5
  
Packit Service fb6fa5
  purge_recent_items_list (manager, error);
Packit Service fb6fa5
  
Packit Service fb6fa5
  purged = count - g_bookmark_file_get_size (priv->recent_items);
Packit Service fb6fa5
Packit Service fb6fa5
  return purged;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
emit_manager_changed (gpointer data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManager *manager = data;
Packit Service fb6fa5
Packit Service fb6fa5
  manager->priv->changed_age = 0;
Packit Service fb6fa5
  manager->priv->changed_timeout = 0;
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_emit (manager, signal_changed, 0);
Packit Service fb6fa5
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_changed (GtkRecentManager *manager)
Packit Service fb6fa5
{
Packit Service fb6fa5
  /* coalesce consecutive changes
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * we schedule a write in 250 msecs immediately; if we get more than one
Packit Service fb6fa5
   * request per millisecond before the timeout has a chance to run, we
Packit Service fb6fa5
   * schedule an emission immediately.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  if (manager->priv->changed_timeout == 0)
Packit Service fb6fa5
    manager->priv->changed_timeout = gdk_threads_add_timeout (250, emit_manager_changed, manager);
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      manager->priv->changed_age += 1;
Packit Service fb6fa5
Packit Service fb6fa5
      if (manager->priv->changed_age > 250)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          g_source_remove (manager->priv->changed_timeout);
Packit Service fb6fa5
          g_signal_emit (manager, signal_changed, 0);
Packit Service fb6fa5
Packit Service fb6fa5
          manager->priv->changed_age = 0;
Packit Service fb6fa5
          manager->priv->changed_timeout = 0;
Packit Service fb6fa5
        }
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
Packit Service fb6fa5
                                 gint              age)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv = manager->priv;
Packit Service fb6fa5
  gchar **uris;
Packit Service fb6fa5
  gsize n_uris, i;
Packit Service fb6fa5
  time_t now;
Packit Service fb6fa5
Packit Service fb6fa5
  if (G_UNLIKELY (!priv->recent_items))
Packit Service fb6fa5
    return;
Packit Service fb6fa5
Packit Service fb6fa5
  now = time (NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
Packit Service fb6fa5
Packit Service fb6fa5
  for (i = 0; i < n_uris; i++)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      const gchar *uri = uris[i];
Packit Service fb6fa5
      time_t modified;
Packit Service fb6fa5
      gint item_age;
Packit Service fb6fa5
Packit Service fb6fa5
      modified = g_bookmark_file_get_modified (priv->recent_items, uri, NULL);
Packit Service fb6fa5
      item_age = (gint) ((now - modified) / (60 * 60 * 24));
Packit Service fb6fa5
      if (item_age > age)
Packit Service fb6fa5
        g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_strfreev (uris);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_manager_clamp_to_size (GtkRecentManager *manager,
Packit Service fb6fa5
                                  const gint        size)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentManagerPrivate *priv = manager->priv;
Packit Service fb6fa5
  gchar **uris;
Packit Service fb6fa5
  gsize n_uris, i;
Packit Service fb6fa5
Packit Service fb6fa5
  if (G_UNLIKELY (!priv->recent_items) || G_UNLIKELY (size < 0))
Packit Service fb6fa5
    return;
Packit Service fb6fa5
Packit Service fb6fa5
  uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
Packit Service fb6fa5
Packit Service fb6fa5
  if (n_uris < size)
Packit Service fb6fa5
  {
Packit Service fb6fa5
    g_strfreev (uris);
Packit Service fb6fa5
    return;
Packit Service fb6fa5
  }
Packit Service fb6fa5
Packit Service fb6fa5
  for (i = 0; i < n_uris - size; i++)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      const gchar *uri = uris[i];
Packit Service fb6fa5
      g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_strfreev (uris);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/*****************
Packit Service fb6fa5
 * GtkRecentInfo *
Packit Service fb6fa5
 *****************/
Packit Service fb6fa5
 
Packit Service fb6fa5
GType
Packit Service fb6fa5
gtk_recent_info_get_type (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  static GType info_type = 0;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!info_type)
Packit Service fb6fa5
    info_type = g_boxed_type_register_static (I_("GtkRecentInfo"),
Packit Service fb6fa5
    					      (GBoxedCopyFunc) gtk_recent_info_ref,
Packit Service fb6fa5
    					      (GBoxedFreeFunc) gtk_recent_info_unref);
Packit Service fb6fa5
  return info_type;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static GtkRecentInfo *
Packit Service fb6fa5
gtk_recent_info_new (const gchar *uri)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkRecentInfo *info;
Packit Service fb6fa5
Packit Service fb6fa5
  g_assert (uri != NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  info = g_new0 (GtkRecentInfo, 1);
Packit Service fb6fa5
  info->uri = g_strdup (uri);
Packit Service fb6fa5
  
Packit Service fb6fa5
  info->applications = NULL;
Packit Service fb6fa5
  info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
Packit Service fb6fa5
  
Packit Service fb6fa5
  info->groups = NULL;
Packit Service fb6fa5
  
Packit Service fb6fa5
  info->ref_count = 1;
Packit Service fb6fa5
Packit Service fb6fa5
  return info;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_recent_info_free (GtkRecentInfo *recent_info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  if (!recent_info)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
Packit Service fb6fa5
  g_free (recent_info->uri);
Packit Service fb6fa5
  g_free (recent_info->display_name);
Packit Service fb6fa5
  g_free (recent_info->description);
Packit Service fb6fa5
  g_free (recent_info->mime_type);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (recent_info->applications)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_slist_foreach (recent_info->applications,
Packit Service fb6fa5
      		       (GFunc) recent_app_info_free,
Packit Service fb6fa5
      		       NULL);
Packit Service fb6fa5
      g_slist_free (recent_info->applications);
Packit Service fb6fa5
      
Packit Service fb6fa5
      recent_info->applications = NULL;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (recent_info->apps_lookup)
Packit Service fb6fa5
    g_hash_table_destroy (recent_info->apps_lookup);
Packit Service fb6fa5
Packit Service fb6fa5
  if (recent_info->groups)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_slist_foreach (recent_info->groups,
Packit Service fb6fa5
		       (GFunc) g_free,
Packit Service fb6fa5
		       NULL);
Packit Service fb6fa5
      g_slist_free (recent_info->groups);
Packit Service fb6fa5
Packit Service fb6fa5
      recent_info->groups = NULL;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (recent_info->icon)
Packit Service fb6fa5
    g_object_unref (recent_info->icon);
Packit Service fb6fa5
Packit Service fb6fa5
  g_free (recent_info);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_ref:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Increases the reference count of @recent_info by one.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the recent info object with its reference count increased
Packit Service fb6fa5
 *   by one.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
GtkRecentInfo *
Packit Service fb6fa5
gtk_recent_info_ref (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  g_return_val_if_fail (info->ref_count > 0, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  info->ref_count += 1;
Packit Service fb6fa5
    
Packit Service fb6fa5
  return info;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_unref:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Decreases the reference count of @info by one.  If the reference
Packit Service fb6fa5
 * count reaches zero, @info is deallocated, and the memory freed.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_recent_info_unref (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_if_fail (info != NULL);
Packit Service fb6fa5
  g_return_if_fail (info->ref_count > 0);
Packit Service fb6fa5
Packit Service fb6fa5
  info->ref_count -= 1;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (info->ref_count == 0)
Packit Service fb6fa5
    gtk_recent_info_free (info);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_uri:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the URI of the resource.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the URI of the resource.  The returned string is
Packit Service fb6fa5
 *   owned by the recent manager, and should not be freed.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
const gchar *
Packit Service fb6fa5
gtk_recent_info_get_uri (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return info->uri;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_display_name:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the name of the resource.  If none has been defined, the basename
Packit Service fb6fa5
 * of the resource is obtained.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the display name of the resource.  The returned string
Packit Service fb6fa5
 *   is owned by the recent manager, and should not be freed.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
const gchar *
Packit Service fb6fa5
gtk_recent_info_get_display_name (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!info->display_name)
Packit Service fb6fa5
    info->display_name = gtk_recent_info_get_short_name (info);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return info->display_name;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_description:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the (short) description of the resource.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the description of the resource.  The returned string
Packit Service fb6fa5
 *   is owned by the recent manager, and should not be freed.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 **/
Packit Service fb6fa5
const gchar *
Packit Service fb6fa5
gtk_recent_info_get_description (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return info->description;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_mime_type:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the MIME type of the resource.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the MIME type of the resource.  The returned string
Packit Service fb6fa5
 *   is owned by the recent manager, and should not be freed.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
const gchar *
Packit Service fb6fa5
gtk_recent_info_get_mime_type (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!info->mime_type)
Packit Service fb6fa5
    info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return info->mime_type;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_added:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the timestamp (seconds from system's Epoch) when the resource
Packit Service fb6fa5
 * was added to the recently used resources list.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the number of seconds elapsed from system's Epoch when
Packit Service fb6fa5
 *   the resource was added to the list, or -1 on failure.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
time_t
Packit Service fb6fa5
gtk_recent_info_get_added (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, (time_t) -1);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return info->added;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_modified:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the timestamp (seconds from system's Epoch) when the resource
Packit Service fb6fa5
 * was last modified.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the number of seconds elapsed from system's Epoch when
Packit Service fb6fa5
 *   the resource was last modified, or -1 on failure.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
time_t
Packit Service fb6fa5
gtk_recent_info_get_modified (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, (time_t) -1);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return info->modified;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_visited:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the timestamp (seconds from system's Epoch) when the resource
Packit Service fb6fa5
 * was last visited.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the number of seconds elapsed from system's Epoch when
Packit Service fb6fa5
 *   the resource was last visited, or -1 on failure.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
time_t
Packit Service fb6fa5
gtk_recent_info_get_visited (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, (time_t) -1);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return info->visited;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_private_hint:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the value of the "private" flag.  Resources in the recently used
Packit Service fb6fa5
 * list that have this flag set to %TRUE should only be displayed by the
Packit Service fb6fa5
 * applications that have registered them.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if the private flag was found, %FALSE otherwise.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_info_get_private_hint (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return info->is_private;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
static RecentAppInfo *
Packit Service fb6fa5
recent_app_info_new (const gchar *app_name)
Packit Service fb6fa5
{
Packit Service fb6fa5
  RecentAppInfo *app_info;
Packit Service fb6fa5
Packit Service fb6fa5
  g_assert (app_name != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  app_info = g_slice_new0 (RecentAppInfo);
Packit Service fb6fa5
  app_info->name = g_strdup (app_name);
Packit Service fb6fa5
  app_info->exec = NULL;
Packit Service fb6fa5
  app_info->count = 1;
Packit Service fb6fa5
  app_info->stamp = 0; 
Packit Service fb6fa5
  
Packit Service fb6fa5
  return app_info;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
recent_app_info_free (RecentAppInfo *app_info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  if (!app_info)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_free (app_info->name);
Packit Service fb6fa5
  g_free (app_info->exec);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_slice_free (RecentAppInfo, app_info);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_application_info:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 * @app_name: the name of the application that has registered this item
Packit Service fb6fa5
 * @app_exec: (transfer none) (out): return location for the string containing the command line
Packit Service fb6fa5
 * @count: (out): return location for the number of times this item was registered
Packit Service fb6fa5
 * @time_: (out): return location for the timestamp this item was last registered
Packit Service fb6fa5
 *    for this application
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the data regarding the application that has registered the resource
Packit Service fb6fa5
 * pointed by @info.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * If the command line contains any escape characters defined inside the
Packit Service fb6fa5
 * storage specification, they will be expanded.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if an application with @app_name has registered this
Packit Service fb6fa5
 *   resource inside the recently used list, or %FALSE otherwise. The
Packit Service fb6fa5
 *   @app_exec string is owned by the #GtkRecentInfo and should not be
Packit Service fb6fa5
 *   modified or freed
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_info_get_application_info (GtkRecentInfo  *info,
Packit Service fb6fa5
				      const gchar    *app_name,
Packit Service fb6fa5
				      const gchar   **app_exec,
Packit Service fb6fa5
				      guint          *count,
Packit Service fb6fa5
				      time_t         *time_)
Packit Service fb6fa5
{
Packit Service fb6fa5
  RecentAppInfo *ai;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (app_name != NULL, FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
Packit Service fb6fa5
  					      app_name);
Packit Service fb6fa5
  if (!ai)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_warning ("No registered application with name '%s' "
Packit Service fb6fa5
                 "for item with URI '%s' found",
Packit Service fb6fa5
                 app_name,
Packit Service fb6fa5
                 info->uri);
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (app_exec)
Packit Service fb6fa5
    *app_exec = ai->exec;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (count)
Packit Service fb6fa5
    *count = ai->count;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (time_)
Packit Service fb6fa5
    *time_ = ai->stamp;
Packit Service fb6fa5
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_applications:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 * @length: (out) (allow-none): return location for the length of the returned list
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Retrieves the list of applications that have registered this resource.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: (array length=length zero-terminated=1) (transfer full):
Packit Service fb6fa5
 *     a newly allocated %NULL-terminated array of strings.
Packit Service fb6fa5
 *     Use g_strfreev() to free it.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gchar **
Packit Service fb6fa5
gtk_recent_info_get_applications (GtkRecentInfo *info,
Packit Service fb6fa5
				  gsize         *length)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GSList *l;
Packit Service fb6fa5
  gchar **retval;
Packit Service fb6fa5
  gsize n_apps, i;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!info->applications)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (length)
Packit Service fb6fa5
        *length = 0;
Packit Service fb6fa5
      
Packit Service fb6fa5
      return NULL;    
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  n_apps = g_slist_length (info->applications);
Packit Service fb6fa5
  
Packit Service fb6fa5
  retval = g_new0 (gchar *, n_apps + 1);
Packit Service fb6fa5
  
Packit Service fb6fa5
  for (l = info->applications, i = 0;
Packit Service fb6fa5
       l != NULL;
Packit Service fb6fa5
       l = l->next)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      RecentAppInfo *ai = (RecentAppInfo *) l->data;
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_assert (ai != NULL);
Packit Service fb6fa5
      
Packit Service fb6fa5
      retval[i++] = g_strdup (ai->name);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  retval[i] = NULL;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (length)
Packit Service fb6fa5
    *length = i;
Packit Service fb6fa5
  
Packit Service fb6fa5
  return retval;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_has_application:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 * @app_name: a string containing an application name
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Checks whether an application registered this resource using @app_name.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if an application with name @app_name was found,
Packit Service fb6fa5
 *   %FALSE otherwise.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_info_has_application (GtkRecentInfo *info,
Packit Service fb6fa5
				 const gchar   *app_name)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (app_name != NULL, FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_last_application:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the name of the last application that have registered the
Packit Service fb6fa5
 * recently used resource represented by @info.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: an application name.  Use g_free() to free it.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gchar *
Packit Service fb6fa5
gtk_recent_info_last_application (GtkRecentInfo  *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GSList *l;
Packit Service fb6fa5
  time_t last_stamp = (time_t) -1;
Packit Service fb6fa5
  gchar *name = NULL;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  for (l = info->applications; l != NULL; l = l->next)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      RecentAppInfo *ai = (RecentAppInfo *) l->data;
Packit Service fb6fa5
      
Packit Service fb6fa5
      if (ai->stamp > last_stamp)
Packit Service fb6fa5
        {
Packit Service fb6fa5
	  name = ai->name;
Packit Service fb6fa5
	  last_stamp = ai->stamp;
Packit Service fb6fa5
	}
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  return g_strdup (name);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static GdkPixbuf *
Packit Service fb6fa5
get_icon_for_mime_type (const char *mime_type,
Packit Service fb6fa5
			gint        pixel_size)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIconTheme *icon_theme;
Packit Service fb6fa5
  char *content_type;
Packit Service fb6fa5
  GIcon *icon;
Packit Service fb6fa5
  GtkIconInfo *info;
Packit Service fb6fa5
  GdkPixbuf *pixbuf;
Packit Service fb6fa5
Packit Service fb6fa5
  icon_theme = gtk_icon_theme_get_default ();
Packit Service fb6fa5
Packit Service fb6fa5
  content_type = g_content_type_from_mime_type (mime_type);
Packit Service fb6fa5
Packit Service fb6fa5
  if (!content_type)
Packit Service fb6fa5
    return NULL;
Packit Service fb6fa5
Packit Service fb6fa5
  icon = g_content_type_get_icon (content_type);
Packit Service fb6fa5
  info = gtk_icon_theme_lookup_by_gicon (icon_theme, 
Packit Service fb6fa5
                                         icon, 
Packit Service fb6fa5
                                         pixel_size, 
Packit Service fb6fa5
                                         GTK_ICON_LOOKUP_USE_BUILTIN);
Packit Service fb6fa5
  g_free (content_type);
Packit Service fb6fa5
  g_object_unref (icon);
Packit Service fb6fa5
Packit Service fb6fa5
  if (!info)
Packit Service fb6fa5
    return NULL;
Packit Service fb6fa5
Packit Service fb6fa5
  pixbuf = gtk_icon_info_load_icon (info, NULL);
Packit Service fb6fa5
  gtk_icon_info_free (info);
Packit Service fb6fa5
Packit Service fb6fa5
  return pixbuf;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static GdkPixbuf *
Packit Service fb6fa5
get_icon_fallback (const gchar *icon_name,
Packit Service fb6fa5
		   gint         size)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIconTheme *icon_theme;
Packit Service fb6fa5
  GdkPixbuf *retval;
Packit Service fb6fa5
Packit Service fb6fa5
  icon_theme = gtk_icon_theme_get_default ();
Packit Service fb6fa5
  
Packit Service fb6fa5
  retval = gtk_icon_theme_load_icon (icon_theme, icon_name,
Packit Service fb6fa5
  				     size,
Packit Service fb6fa5
  				     GTK_ICON_LOOKUP_USE_BUILTIN,
Packit Service fb6fa5
  				     NULL);
Packit Service fb6fa5
  g_assert (retval != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return retval; 
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_icon:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 * @size: the size of the icon in pixels
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Retrieves the icon of size @size associated to the resource MIME type.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: (transfer full): a #GdkPixbuf containing the icon,
Packit Service fb6fa5
 *     or %NULL. Use g_object_unref() when finished using the icon.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
GdkPixbuf *
Packit Service fb6fa5
gtk_recent_info_get_icon (GtkRecentInfo *info,
Packit Service fb6fa5
			  gint           size)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GdkPixbuf *retval = NULL;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (info->mime_type)
Packit Service fb6fa5
    retval = get_icon_for_mime_type (info->mime_type, size);
Packit Service fb6fa5
Packit Service fb6fa5
  /* this function should never fail */  
Packit Service fb6fa5
  if (!retval)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (info->mime_type &&
Packit Service fb6fa5
          strcmp (info->mime_type, "x-directory/normal") == 0)
Packit Service fb6fa5
        retval = get_icon_fallback ("folder", size);
Packit Service fb6fa5
      else
Packit Service fb6fa5
        retval = get_icon_fallback ("text-x-generic", size);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  return retval;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_is_local:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Checks whether the resource is local or not by looking at the
Packit Service fb6fa5
 * scheme of its URI.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if the resource is local.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_info_is_local (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return has_case_prefix (info->uri, "file:/");
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_exists:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Checks whether the resource pointed by @info still exists.  At
Packit Service fb6fa5
 * the moment this check is done only on resources pointing to local files.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if the resource exists
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_info_exists (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *filename;
Packit Service fb6fa5
  struct stat stat_buf;
Packit Service fb6fa5
  gboolean retval = FALSE;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* we guarantee only local resources */
Packit Service fb6fa5
  if (!gtk_recent_info_is_local (info))
Packit Service fb6fa5
    return FALSE;
Packit Service fb6fa5
  
Packit Service fb6fa5
  filename = g_filename_from_uri (info->uri, NULL, NULL);
Packit Service fb6fa5
  if (filename)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (stat (filename, &stat_buf) == 0)
Packit Service fb6fa5
        retval = TRUE;
Packit Service fb6fa5
     
Packit Service fb6fa5
      g_free (filename);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  return retval;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_match:
Packit Service fb6fa5
 * @info_a: a #GtkRecentInfo
Packit Service fb6fa5
 * @info_b: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Checks whether two #GtkRecentInfo structures point to the same
Packit Service fb6fa5
 * resource.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if both #GtkRecentInfo structures point to se same
Packit Service fb6fa5
 *   resource, %FALSE otherwise.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_info_match (GtkRecentInfo *info_a,
Packit Service fb6fa5
		       GtkRecentInfo *info_b)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (info_a != NULL, FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (info_b != NULL, FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return (0 == strcmp (info_a->uri, info_b->uri));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* taken from gnome-vfs-uri.c */
Packit Service fb6fa5
static const gchar *
Packit Service fb6fa5
get_method_string (const gchar  *substring, 
Packit Service fb6fa5
		   gchar       **method_string)
Packit Service fb6fa5
{
Packit Service fb6fa5
  const gchar *p;
Packit Service fb6fa5
  char *method;
Packit Service fb6fa5
	
Packit Service fb6fa5
  for (p = substring;
Packit Service fb6fa5
       g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
Packit Service fb6fa5
       p++)
Packit Service fb6fa5
    ;
Packit Service fb6fa5
Packit Service fb6fa5
  if (*p == ':'
Packit Service fb6fa5
#ifdef G_OS_WIN32
Packit Service fb6fa5
                &&
Packit Service fb6fa5
      !(p == substring + 1 && g_ascii_isalpha (*substring))
Packit Service fb6fa5
#endif
Packit Service fb6fa5
							   )
Packit Service fb6fa5
    {
Packit Service fb6fa5
      /* Found toplevel method specification.  */
Packit Service fb6fa5
      method = g_strndup (substring, p - substring);
Packit Service fb6fa5
      *method_string = g_ascii_strdown (method, -1);
Packit Service fb6fa5
      g_free (method);
Packit Service fb6fa5
      p++;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      *method_string = g_strdup ("file");
Packit Service fb6fa5
      p = substring;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  return p;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* Stolen from gnome_vfs_make_valid_utf8() */
Packit Service fb6fa5
static char *
Packit Service fb6fa5
make_valid_utf8 (const char *name)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GString *string;
Packit Service fb6fa5
  const char *remainder, *invalid;
Packit Service fb6fa5
  int remaining_bytes, valid_bytes;
Packit Service fb6fa5
Packit Service fb6fa5
  string = NULL;
Packit Service fb6fa5
  remainder = name;
Packit Service fb6fa5
  remaining_bytes = name ? strlen (name) : 0;
Packit Service fb6fa5
Packit Service fb6fa5
  while (remaining_bytes != 0)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (g_utf8_validate (remainder, remaining_bytes, &invalid))
Packit Service fb6fa5
        break;
Packit Service fb6fa5
      
Packit Service fb6fa5
      valid_bytes = invalid - remainder;
Packit Service fb6fa5
      
Packit Service fb6fa5
      if (string == NULL)
Packit Service fb6fa5
        string = g_string_sized_new (remaining_bytes);
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_string_append_len (string, remainder, valid_bytes);
Packit Service fb6fa5
      g_string_append_c (string, '?');
Packit Service fb6fa5
      
Packit Service fb6fa5
      remaining_bytes -= valid_bytes + 1;
Packit Service fb6fa5
      remainder = invalid + 1;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (string == NULL)
Packit Service fb6fa5
    return g_strdup (name);
Packit Service fb6fa5
Packit Service fb6fa5
  g_string_append (string, remainder);
Packit Service fb6fa5
  g_assert (g_utf8_validate (string->str, -1, NULL));
Packit Service fb6fa5
Packit Service fb6fa5
  return g_string_free (string, FALSE);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gchar *
Packit Service fb6fa5
get_uri_shortname_for_display (const gchar *uri)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *name = NULL;
Packit Service fb6fa5
  gboolean validated = FALSE;
Packit Service fb6fa5
Packit Service fb6fa5
  if (has_case_prefix (uri, "file:/"))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *local_file;
Packit Service fb6fa5
      
Packit Service fb6fa5
      local_file = g_filename_from_uri (uri, NULL, NULL);
Packit Service fb6fa5
      
Packit Service fb6fa5
      if (local_file)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          name = g_filename_display_basename (local_file);
Packit Service fb6fa5
          validated = TRUE;
Packit Service fb6fa5
        }
Packit Service fb6fa5
		
Packit Service fb6fa5
      g_free (local_file);
Packit Service fb6fa5
    } 
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!name)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *method;
Packit Service fb6fa5
      gchar *local_file;
Packit Service fb6fa5
      const gchar *rest;
Packit Service fb6fa5
      
Packit Service fb6fa5
      rest = get_method_string (uri, &method);
Packit Service fb6fa5
      local_file = g_filename_display_basename (rest);
Packit Service fb6fa5
      
Packit Service fb6fa5
      name = g_strconcat (method, ": ", local_file, NULL);
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_free (local_file);
Packit Service fb6fa5
      g_free (method);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_assert (name != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!validated && !g_utf8_validate (name, -1, NULL))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *utf8_name;
Packit Service fb6fa5
      
Packit Service fb6fa5
      utf8_name = make_valid_utf8 (name);
Packit Service fb6fa5
      g_free (name);
Packit Service fb6fa5
      
Packit Service fb6fa5
      name = utf8_name;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return name;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_short_name:
Packit Service fb6fa5
 * @info: an #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Computes a valid UTF-8 string that can be used as the name of the item in a
Packit Service fb6fa5
 * menu or list.  For example, calling this function on an item that refers to
Packit Service fb6fa5
 * "file:///foo/bar.txt" will yield "bar.txt".
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: A newly-allocated string in UTF-8 encoding; free it with
Packit Service fb6fa5
 *   g_free().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gchar *
Packit Service fb6fa5
gtk_recent_info_get_short_name (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *short_name;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  if (info->uri == NULL)
Packit Service fb6fa5
    return NULL;
Packit Service fb6fa5
Packit Service fb6fa5
  short_name = get_uri_shortname_for_display (info->uri);
Packit Service fb6fa5
Packit Service fb6fa5
  return short_name;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_uri_display:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets a displayable version of the resource's URI.  If the resource
Packit Service fb6fa5
 * is local, it returns a local path; if the resource is not local,
Packit Service fb6fa5
 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: a newly allocated UTF-8 string containing the
Packit Service fb6fa5
 *   resource's URI or %NULL. Use g_free() when done using it.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gchar *
Packit Service fb6fa5
gtk_recent_info_get_uri_display (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *retval;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  retval = NULL;
Packit Service fb6fa5
  if (gtk_recent_info_is_local (info))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *filename;
Packit Service fb6fa5
Packit Service fb6fa5
      filename = g_filename_from_uri (info->uri, NULL, NULL);
Packit Service fb6fa5
      if (!filename)
Packit Service fb6fa5
        return NULL;
Packit Service fb6fa5
      
Packit Service fb6fa5
      retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
Packit Service fb6fa5
      g_free (filename);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      retval = make_valid_utf8 (info->uri);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return retval;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_age:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the number of days elapsed since the last update of the resource
Packit Service fb6fa5
 * pointed by @info.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: a positive integer containing the number of days elapsed
Packit Service fb6fa5
 *   since the time this resource was last modified.  
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gint
Packit Service fb6fa5
gtk_recent_info_get_age (GtkRecentInfo *info)
Packit Service fb6fa5
{
Packit Service fb6fa5
  time_t now, delta;
Packit Service fb6fa5
  gint retval;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, -1);
Packit Service fb6fa5
Packit Service fb6fa5
  now = time (NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  delta = now - info->modified;
Packit Service fb6fa5
  
Packit Service fb6fa5
  retval = (gint) (delta / (60 * 60 * 24));
Packit Service fb6fa5
  
Packit Service fb6fa5
  return retval;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_get_groups:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 * @length: (out) (allow-none): return location for the number of groups returned
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Returns all groups registered for the recently used item @info.  The
Packit Service fb6fa5
 * array of returned group names will be %NULL terminated, so length might
Packit Service fb6fa5
 * optionally be %NULL.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value:  (array length=length zero-terminated=1) (transfer full):
Packit Service fb6fa5
 *     a newly allocated %NULL terminated array of strings.
Packit Service fb6fa5
 *     Use g_strfreev() to free it.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gchar **
Packit Service fb6fa5
gtk_recent_info_get_groups (GtkRecentInfo *info,
Packit Service fb6fa5
			    gsize         *length)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GSList *l;
Packit Service fb6fa5
  gchar **retval;
Packit Service fb6fa5
  gsize n_groups, i;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!info->groups)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (length)
Packit Service fb6fa5
        *length = 0;
Packit Service fb6fa5
      
Packit Service fb6fa5
      return NULL;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  n_groups = g_slist_length (info->groups);
Packit Service fb6fa5
  
Packit Service fb6fa5
  retval = g_new0 (gchar *, n_groups + 1);
Packit Service fb6fa5
  
Packit Service fb6fa5
  for (l = info->groups, i = 0;
Packit Service fb6fa5
       l != NULL;
Packit Service fb6fa5
       l = l->next)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *group_name = (gchar *) l->data;
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_assert (group_name != NULL);
Packit Service fb6fa5
      
Packit Service fb6fa5
      retval[i++] = g_strdup (group_name);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  retval[i] = NULL;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (length)
Packit Service fb6fa5
    *length = i;
Packit Service fb6fa5
  
Packit Service fb6fa5
  return retval;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_recent_info_has_group:
Packit Service fb6fa5
 * @info: a #GtkRecentInfo
Packit Service fb6fa5
 * @group_name: name of a group
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Checks whether @group_name appears inside the groups registered for the
Packit Service fb6fa5
 * recently used item @info.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if the group was found.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.10
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_recent_info_has_group (GtkRecentInfo *info,
Packit Service fb6fa5
			   const gchar   *group_name)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GSList *l;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (info != NULL, FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (group_name != NULL, FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  if (!info->groups)
Packit Service fb6fa5
    return FALSE;
Packit Service fb6fa5
Packit Service fb6fa5
  for (l = info->groups; l != NULL; l = l->next)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *g = (gchar *) l->data;
Packit Service fb6fa5
Packit Service fb6fa5
      if (strcmp (g, group_name) == 0)
Packit Service fb6fa5
        return TRUE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/*
Packit Service fb6fa5
 * _gtk_recent_manager_sync:
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Private function for synchronising the recent manager singleton.
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
_gtk_recent_manager_sync (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  if (recent_manager_singleton)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      /* force a dump of the contents of the recent manager singleton */
Packit Service fb6fa5
      recent_manager_singleton->priv->is_dirty = TRUE;
Packit Service fb6fa5
      gtk_recent_manager_real_changed (recent_manager_singleton);
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
#define __GTK_RECENT_MANAGER_C__
Packit Service fb6fa5
#include "gtkaliasdef.c"