2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* gtkrecentmanager.c: a manager for the recently used resources
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006 Emmanuele Bassi
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2010-07-15 08:10:55 +00:00
|
|
|
|
/**
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* GtkRecentManager:
|
|
|
|
|
*
|
|
|
|
|
* `GtkRecentManager` manages and looks up recently used files.
|
|
|
|
|
*
|
|
|
|
|
* Each recently used file is identified by its URI, and has meta-data
|
|
|
|
|
* associated to it, like the names and command lines of the applications
|
|
|
|
|
* that have registered it, the number of time each application has
|
|
|
|
|
* registered the same file, the mime type of the file and whether
|
|
|
|
|
* the file should be displayed only by the applications that have
|
2010-07-15 08:10:55 +00:00
|
|
|
|
* registered it.
|
|
|
|
|
*
|
2014-02-02 06:22:14 +00:00
|
|
|
|
* The recently used files list is per user.
|
2010-07-15 08:10:55 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* `GtkRecentManager` acts like a database of all the recently
|
|
|
|
|
* used files. You can create new `GtkRecentManager` objects, but
|
|
|
|
|
* it is more efficient to use the default manager created by GTK.
|
2010-07-15 08:10:55 +00:00
|
|
|
|
*
|
|
|
|
|
* Adding a new recently used file is as simple as:
|
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* ```c
|
2010-07-15 08:10:55 +00:00
|
|
|
|
* GtkRecentManager *manager;
|
|
|
|
|
*
|
|
|
|
|
* manager = gtk_recent_manager_get_default ();
|
|
|
|
|
* gtk_recent_manager_add_item (manager, file_uri);
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* ```
|
2010-07-15 08:10:55 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* The `GtkRecentManager` will try to gather all the needed information
|
2010-07-15 08:10:55 +00:00
|
|
|
|
* from the file itself through GIO.
|
|
|
|
|
*
|
|
|
|
|
* Looking up the meta-data associated with a recently used file
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* given its URI requires calling [method@Gtk.RecentManager.lookup_item]:
|
2010-07-15 08:10:55 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* ```c
|
2010-07-15 08:10:55 +00:00
|
|
|
|
* GtkRecentManager *manager;
|
|
|
|
|
* GtkRecentInfo *info;
|
|
|
|
|
* GError *error = NULL;
|
|
|
|
|
*
|
|
|
|
|
* manager = gtk_recent_manager_get_default ();
|
2014-01-27 20:42:15 +00:00
|
|
|
|
* info = gtk_recent_manager_lookup_item (manager, file_uri, &error);
|
2010-07-15 08:10:55 +00:00
|
|
|
|
* if (error)
|
|
|
|
|
* {
|
2014-01-27 20:42:15 +00:00
|
|
|
|
* g_warning ("Could not find the file: %s", error->message);
|
2010-07-15 08:10:55 +00:00
|
|
|
|
* g_error_free (error);
|
|
|
|
|
* }
|
|
|
|
|
* else
|
|
|
|
|
* {
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Use the info object
|
2010-07-15 08:10:55 +00:00
|
|
|
|
* gtk_recent_info_unref (info);
|
|
|
|
|
* }
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* ```
|
2010-07-15 08:10:55 +00:00
|
|
|
|
*
|
|
|
|
|
* In order to retrieve the list of recently used files, you can use
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* [method@Gtk.RecentManager.get_items], which returns a list of
|
|
|
|
|
* [struct@Gtk.RecentInfo].
|
2010-07-15 08:10:55 +00:00
|
|
|
|
*
|
2014-02-02 06:22:14 +00:00
|
|
|
|
* Note that the maximum age of the recently used files list is
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* controllable through the [property@Gtk.Settings:gtk-recent-files-max-age]
|
2014-02-02 06:22:14 +00:00
|
|
|
|
* property.
|
2010-07-15 08:10:55 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <glib/gstdio.h>
|
2008-04-15 22:00:17 +00:00
|
|
|
|
#include <gio/gio.h>
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
#include "gtkrecentmanager.h"
|
|
|
|
|
#include "gtkintl.h"
|
2010-10-19 17:14:46 +00:00
|
|
|
|
#include "gtksettings.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
|
|
|
|
|
|
/* the file where we store the recently used items */
|
2014-12-22 22:16:30 +00:00
|
|
|
|
#define GTK_RECENTLY_USED_FILE "recently-used.xbel"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
/* return all items by default */
|
2014-12-22 22:16:30 +00:00
|
|
|
|
#define DEFAULT_LIMIT -1
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2016-10-27 13:51:29 +00:00
|
|
|
|
/* limit the size of the list */
|
|
|
|
|
#define MAX_LIST_SIZE 1000
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* keep in sync with xdgmime */
|
2014-12-22 22:16:30 +00:00
|
|
|
|
#define GTK_RECENT_DEFAULT_MIME "application/octet-stream"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *name;
|
|
|
|
|
char *exec;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
guint count;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *stamp;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
} RecentAppInfo;
|
|
|
|
|
|
2010-07-15 08:10:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkRecentInfo:
|
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* `GtkRecentInfo` contains the metadata associated with an item in the
|
|
|
|
|
* recently used files list.
|
2010-07-15 08:10:55 +00:00
|
|
|
|
*/
|
2006-03-29 20:16:44 +00:00
|
|
|
|
struct _GtkRecentInfo
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *uri;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *display_name;
|
|
|
|
|
char *description;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *added;
|
|
|
|
|
GDateTime *modified;
|
|
|
|
|
GDateTime *visited;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *mime_type;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
RecentAppInfo *applications;
|
|
|
|
|
int n_applications;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GHashTable *apps_lookup;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
char **groups;
|
|
|
|
|
int n_groups;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gboolean is_private;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int ref_count;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _GtkRecentManagerPrivate
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *filename;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
guint is_dirty : 1;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int size;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
GBookmarkFile *recent_items;
|
2008-04-15 22:22:44 +00:00
|
|
|
|
|
|
|
|
|
GFileMonitor *monitor;
|
2010-10-22 15:12:16 +00:00
|
|
|
|
|
|
|
|
|
guint changed_timeout;
|
|
|
|
|
guint changed_age;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
|
2014-12-22 22:16:30 +00:00
|
|
|
|
PROP_FILENAME,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
PROP_LIMIT,
|
|
|
|
|
PROP_SIZE
|
|
|
|
|
};
|
|
|
|
|
|
2008-04-15 22:31:01 +00:00
|
|
|
|
static void gtk_recent_manager_dispose (GObject *object);
|
|
|
|
|
static void gtk_recent_manager_finalize (GObject *object);
|
|
|
|
|
static void gtk_recent_manager_set_property (GObject *object,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2008-04-15 22:31:01 +00:00
|
|
|
|
static void gtk_recent_manager_get_property (GObject *object,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2008-04-15 22:31:01 +00:00
|
|
|
|
static void gtk_recent_manager_add_item_query_info (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GFile *other_file,
|
|
|
|
|
GFileMonitorEvent event_type,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void gtk_recent_manager_changed (GtkRecentManager *manager);
|
|
|
|
|
static void gtk_recent_manager_real_changed (GtkRecentManager *manager);
|
|
|
|
|
static void gtk_recent_manager_set_filename (GtkRecentManager *manager,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *filename);
|
2008-04-15 22:37:32 +00:00
|
|
|
|
static void gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int age);
|
2016-10-27 13:51:29 +00:00
|
|
|
|
static void gtk_recent_manager_clamp_to_size (GtkRecentManager *manager,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
const int size);
|
2016-10-27 13:51:29 +00:00
|
|
|
|
|
2013-02-13 16:05:47 +00:00
|
|
|
|
static void gtk_recent_manager_enabled_changed (GtkRecentManager *manager);
|
2008-04-15 22:37:32 +00:00
|
|
|
|
|
2008-04-15 22:22:44 +00:00
|
|
|
|
|
2014-12-22 22:16:30 +00:00
|
|
|
|
static void build_recent_items_list (GtkRecentManager *manager);
|
|
|
|
|
static void purge_recent_items_list (GtkRecentManager *manager,
|
|
|
|
|
GError **error);
|
2008-04-15 22:22:44 +00:00
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static GtkRecentInfo *gtk_recent_info_new (const char *uri);
|
2008-04-15 22:22:44 +00:00
|
|
|
|
static void gtk_recent_info_free (GtkRecentInfo *recent_info);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
static guint signal_changed = 0;
|
|
|
|
|
|
2007-06-19 10:29:55 +00:00
|
|
|
|
static GtkRecentManager *recent_manager_singleton = NULL;
|
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-04-16 03:55:07 +00:00
|
|
|
|
/* Test of haystack has the needle prefix, comparing case
|
|
|
|
|
* insensitive. haystack may be UTF-8, but needle must
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* contain only lowercase ascii.
|
|
|
|
|
*/
|
2006-04-16 03:55:07 +00:00
|
|
|
|
static gboolean
|
2020-07-24 18:40:36 +00:00
|
|
|
|
has_case_prefix (const char *haystack,
|
|
|
|
|
const char *needle)
|
2006-04-16 03:55:07 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *h, *n;
|
2006-04-16 03:55:07 +00:00
|
|
|
|
|
|
|
|
|
/* Eat one character at a time. */
|
|
|
|
|
h = haystack;
|
|
|
|
|
n = needle;
|
|
|
|
|
|
|
|
|
|
while (*n && *h && *n == g_ascii_tolower (*h))
|
|
|
|
|
{
|
|
|
|
|
n++;
|
|
|
|
|
h++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return *n == '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GQuark
|
|
|
|
|
gtk_recent_manager_error_quark (void)
|
|
|
|
|
{
|
2006-04-04 03:25:16 +00:00
|
|
|
|
return g_quark_from_static_string ("gtk-recent-manager-error-quark");
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_manager_class_init (GtkRecentManagerClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gobject_class->set_property = gtk_recent_manager_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_recent_manager_get_property;
|
2007-07-20 10:39:03 +00:00
|
|
|
|
gobject_class->dispose = gtk_recent_manager_dispose;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gobject_class->finalize = gtk_recent_manager_finalize;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/**
|
2012-04-13 00:07:28 +00:00
|
|
|
|
* GtkRecentManager:filename:
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* The full path to the file to be used to store and read the
|
|
|
|
|
* recently used resources list
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
PROP_FILENAME,
|
|
|
|
|
g_param_spec_string ("filename",
|
|
|
|
|
P_("Filename"),
|
|
|
|
|
P_("The full path to the file to be used to store and read the list"),
|
|
|
|
|
NULL,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
(G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE)));
|
2010-07-15 01:04:50 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/**
|
2012-04-13 00:07:28 +00:00
|
|
|
|
* GtkRecentManager:size:
|
2014-12-22 22:16:30 +00:00
|
|
|
|
*
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* The size of the recently used resources list.
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
PROP_SIZE,
|
|
|
|
|
g_param_spec_int ("size",
|
|
|
|
|
P_("Size"),
|
|
|
|
|
P_("The size of the recently used resources list"),
|
2017-11-18 13:18:11 +00:00
|
|
|
|
-1, G_MAXINT, 0,
|
|
|
|
|
GTK_PARAM_READABLE));
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/**
|
2012-04-13 00:07:28 +00:00
|
|
|
|
* GtkRecentManager::changed:
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @recent_manager: the recent manager
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Emitted when the current recently used resources manager changes
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* its contents.
|
|
|
|
|
*
|
|
|
|
|
* This can happen either by calling [method@Gtk.RecentManager.add_item]
|
|
|
|
|
* or by another application.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
signal_changed =
|
|
|
|
|
g_signal_new (I_("changed"),
|
2014-12-22 22:16:30 +00:00
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkRecentManagerClass, changed),
|
|
|
|
|
NULL, NULL,
|
2019-05-29 20:05:19 +00:00
|
|
|
|
NULL,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
klass->changed = gtk_recent_manager_real_changed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_manager_init (GtkRecentManager *manager)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv;
|
2013-02-13 16:05:47 +00:00
|
|
|
|
GtkSettings *settings;
|
2008-04-15 22:22:44 +00:00
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
|
manager->priv = gtk_recent_manager_get_instance_private (manager);
|
2010-07-08 00:05:32 +00:00
|
|
|
|
priv = manager->priv;
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
priv->size = 0;
|
2008-04-15 22:37:32 +00:00
|
|
|
|
priv->filename = NULL;
|
2013-02-13 16:05:47 +00:00
|
|
|
|
|
|
|
|
|
settings = gtk_settings_get_default ();
|
2014-12-22 04:14:02 +00:00
|
|
|
|
if (settings)
|
|
|
|
|
g_signal_connect_swapped (settings, "notify::gtk-recent-files-enabled",
|
|
|
|
|
G_CALLBACK (gtk_recent_manager_enabled_changed), manager);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-12-22 22:16:30 +00:00
|
|
|
|
gtk_recent_manager_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_FILENAME:
|
|
|
|
|
gtk_recent_manager_set_filename (recent_manager, g_value_get_string (value));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-12-22 22:16:30 +00:00
|
|
|
|
gtk_recent_manager_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_FILENAME:
|
|
|
|
|
g_value_set_string (value, recent_manager->priv->filename);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SIZE:
|
|
|
|
|
g_value_set_int (value, recent_manager->priv->size);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2010-10-22 15:12:16 +00:00
|
|
|
|
gtk_recent_manager_finalize (GObject *object)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
|
|
|
|
|
GtkRecentManagerPrivate *priv = manager->priv;
|
|
|
|
|
|
2010-10-22 15:12:16 +00:00
|
|
|
|
g_free (priv->filename);
|
|
|
|
|
|
|
|
|
|
if (priv->recent_items != NULL)
|
|
|
|
|
g_bookmark_file_free (priv->recent_items);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_recent_manager_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_manager_dispose (GObject *gobject)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentManager *manager = GTK_RECENT_MANAGER (gobject);
|
|
|
|
|
GtkRecentManagerPrivate *priv = manager->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->monitor != NULL)
|
2007-07-20 10:39:03 +00:00
|
|
|
|
{
|
2008-04-15 22:22:44 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->monitor,
|
|
|
|
|
G_CALLBACK (gtk_recent_manager_monitor_changed),
|
|
|
|
|
manager);
|
|
|
|
|
g_object_unref (priv->monitor);
|
|
|
|
|
priv->monitor = NULL;
|
2007-07-20 10:39:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-22 15:12:16 +00:00
|
|
|
|
if (priv->changed_timeout != 0)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (priv->changed_timeout);
|
|
|
|
|
priv->changed_timeout = 0;
|
|
|
|
|
priv->changed_age = 0;
|
|
|
|
|
}
|
2007-07-20 10:39:03 +00:00
|
|
|
|
|
2010-10-22 15:12:16 +00:00
|
|
|
|
if (priv->is_dirty)
|
|
|
|
|
{
|
|
|
|
|
g_object_ref (manager);
|
|
|
|
|
g_signal_emit (manager, signal_changed, 0);
|
|
|
|
|
g_object_unref (manager);
|
|
|
|
|
}
|
2007-06-19 10:29:55 +00:00
|
|
|
|
|
2010-10-22 15:12:16 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_recent_manager_parent_class)->dispose (gobject);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 16:05:47 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_manager_enabled_changed (GtkRecentManager *manager)
|
|
|
|
|
{
|
|
|
|
|
manager->priv->is_dirty = TRUE;
|
|
|
|
|
gtk_recent_manager_changed (manager);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_manager_real_changed (GtkRecentManager *manager)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv = manager->priv;
|
|
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (manager));
|
|
|
|
|
|
|
|
|
|
if (priv->is_dirty)
|
|
|
|
|
{
|
|
|
|
|
GError *write_error;
|
2014-12-22 13:21:50 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* we are marked as dirty, so we dump the content of our
|
|
|
|
|
* recently used items list
|
|
|
|
|
*/
|
|
|
|
|
if (!priv->recent_items)
|
|
|
|
|
{
|
2008-04-15 22:37:32 +00:00
|
|
|
|
/* if no container object has been defined, we create a new
|
|
|
|
|
* empty container, and dump it
|
|
|
|
|
*/
|
2006-03-29 20:16:44 +00:00
|
|
|
|
priv->recent_items = g_bookmark_file_new ();
|
2014-12-22 22:16:30 +00:00
|
|
|
|
priv->size = 0;
|
|
|
|
|
}
|
2008-04-15 22:37:32 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2014-12-22 04:14:02 +00:00
|
|
|
|
GtkSettings *settings;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int age;
|
|
|
|
|
int max_size = MAX_LIST_SIZE;
|
2013-02-13 16:05:47 +00:00
|
|
|
|
gboolean enabled;
|
2008-04-15 22:37:32 +00:00
|
|
|
|
|
2014-12-22 04:14:02 +00:00
|
|
|
|
settings = gtk_settings_get_default ();
|
|
|
|
|
if (settings)
|
|
|
|
|
g_object_get (G_OBJECT (settings),
|
|
|
|
|
"gtk-recent-files-max-age", &age,
|
|
|
|
|
"gtk-recent-files-enabled", &enabled,
|
|
|
|
|
NULL);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
age = 30;
|
|
|
|
|
enabled = TRUE;
|
|
|
|
|
}
|
2013-02-13 16:05:47 +00:00
|
|
|
|
|
2016-10-27 13:51:29 +00:00
|
|
|
|
if (age == 0 || max_size == 0 || !enabled)
|
2008-04-15 22:46:15 +00:00
|
|
|
|
{
|
|
|
|
|
g_bookmark_file_free (priv->recent_items);
|
|
|
|
|
priv->recent_items = g_bookmark_file_new ();
|
2016-04-10 17:41:23 +00:00
|
|
|
|
priv->size = 0;
|
2008-04-15 22:46:15 +00:00
|
|
|
|
}
|
2016-10-27 13:51:29 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (age > 0)
|
|
|
|
|
gtk_recent_manager_clamp_to_age (manager, age);
|
|
|
|
|
if (max_size > 0)
|
|
|
|
|
gtk_recent_manager_clamp_to_size (manager, max_size);
|
|
|
|
|
}
|
2008-04-15 22:37:32 +00:00
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2014-12-22 13:21:50 +00:00
|
|
|
|
if (priv->filename != NULL)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2014-12-22 13:21:50 +00:00
|
|
|
|
write_error = NULL;
|
|
|
|
|
g_bookmark_file_to_file (priv->recent_items, priv->filename, &write_error);
|
|
|
|
|
if (write_error)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *utf8 = g_filename_to_utf8 (priv->filename, -1, NULL, NULL, NULL);
|
2016-04-04 13:03:12 +00:00
|
|
|
|
g_warning ("Attempting to store changes into '%s', but failed: %s",
|
|
|
|
|
utf8 ? utf8 : "(invalid filename)",
|
|
|
|
|
write_error->message);
|
|
|
|
|
g_free (utf8);
|
2014-12-22 13:21:50 +00:00
|
|
|
|
g_error_free (write_error);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2014-12-22 13:21:50 +00:00
|
|
|
|
if (g_chmod (priv->filename, 0600) < 0)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *utf8 = g_filename_to_utf8 (priv->filename, -1, NULL, NULL, NULL);
|
2016-04-04 13:03:12 +00:00
|
|
|
|
g_warning ("Attempting to set the permissions of '%s', but failed: %s",
|
|
|
|
|
utf8 ? utf8 : "(invalid filename)",
|
|
|
|
|
g_strerror (errno));
|
|
|
|
|
g_free (utf8);
|
2014-12-22 13:21:50 +00:00
|
|
|
|
}
|
2008-08-07 00:54:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* mark us as clean */
|
|
|
|
|
priv->is_dirty = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* we are not marked as dirty, so we have been called
|
|
|
|
|
* because the recently used resources file has been
|
|
|
|
|
* changed (and not from us).
|
|
|
|
|
*/
|
|
|
|
|
build_recent_items_list (manager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (manager));
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-15 22:22:44 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GFile *other_file,
|
|
|
|
|
GFileMonitorEvent event_type,
|
|
|
|
|
gpointer user_data)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2008-04-15 22:22:44 +00:00
|
|
|
|
GtkRecentManager *manager = user_data;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2008-04-15 22:22:44 +00:00
|
|
|
|
switch (event_type)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2008-04-15 22:22:44 +00:00
|
|
|
|
case G_FILE_MONITOR_EVENT_CHANGED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_CREATED:
|
2016-04-10 17:28:01 +00:00
|
|
|
|
case G_FILE_MONITOR_EVENT_DELETED:
|
2008-04-15 22:22:44 +00:00
|
|
|
|
gtk_recent_manager_changed (manager);
|
|
|
|
|
break;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2017-10-06 19:19:42 +00:00
|
|
|
|
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_UNMOUNTED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_MOVED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_RENAMED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_MOVED_IN:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_MOVED_OUT:
|
|
|
|
|
|
2008-04-15 22:22:44 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static char *
|
2010-10-21 13:06:29 +00:00
|
|
|
|
get_default_filename (void)
|
|
|
|
|
{
|
2012-07-04 10:41:50 +00:00
|
|
|
|
if (g_mkdir_with_parents (g_get_user_data_dir (), 0755) == -1)
|
|
|
|
|
{
|
|
|
|
|
int saved_errno = errno;
|
|
|
|
|
|
|
|
|
|
g_critical ("Unable to create user data directory '%s' for storing "
|
|
|
|
|
"the recently used files list: %s",
|
|
|
|
|
g_get_user_data_dir (),
|
|
|
|
|
g_strerror (saved_errno));
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-21 13:06:29 +00:00
|
|
|
|
return g_build_filename (g_get_user_data_dir (),
|
|
|
|
|
GTK_RECENTLY_USED_FILE,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_manager_set_filename (GtkRecentManager *manager,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *filename)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv;
|
2008-04-15 22:22:44 +00:00
|
|
|
|
GFile *file;
|
|
|
|
|
GError *error;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_assert (GTK_IS_RECENT_MANAGER (manager));
|
2008-04-15 22:22:44 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
priv = manager->priv;
|
2008-04-15 22:22:44 +00:00
|
|
|
|
|
2008-04-15 22:37:32 +00:00
|
|
|
|
/* if a filename is already set and filename is not NULL, then copy
|
|
|
|
|
* it and reset the monitor; otherwise, if it's NULL we're being
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* called from the finalization sequence, so we simply disconnect
|
|
|
|
|
* the monitoring and return.
|
2008-04-15 22:37:32 +00:00
|
|
|
|
*
|
|
|
|
|
* if no filename is set and filename is NULL, use the default.
|
|
|
|
|
*/
|
|
|
|
|
if (priv->filename)
|
2008-04-15 22:22:44 +00:00
|
|
|
|
{
|
2008-04-15 22:37:32 +00:00
|
|
|
|
g_free (priv->filename);
|
|
|
|
|
|
|
|
|
|
if (priv->monitor)
|
|
|
|
|
{
|
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->monitor,
|
|
|
|
|
G_CALLBACK (gtk_recent_manager_monitor_changed),
|
|
|
|
|
manager);
|
|
|
|
|
g_object_unref (priv->monitor);
|
|
|
|
|
priv->monitor = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!filename || *filename == '\0')
|
|
|
|
|
return;
|
|
|
|
|
else
|
|
|
|
|
priv->filename = g_strdup (filename);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!filename || *filename == '\0')
|
2010-10-21 13:06:29 +00:00
|
|
|
|
priv->filename = get_default_filename ();
|
2008-04-15 22:37:32 +00:00
|
|
|
|
else
|
|
|
|
|
priv->filename = g_strdup (filename);
|
2008-04-15 22:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 13:21:50 +00:00
|
|
|
|
if (priv->filename != NULL)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2014-12-22 13:21:50 +00:00
|
|
|
|
file = g_file_new_for_path (priv->filename);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2014-12-22 13:21:50 +00:00
|
|
|
|
error = NULL;
|
|
|
|
|
priv->monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
|
|
|
|
|
if (error)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *utf8 = g_filename_to_utf8 (priv->filename, -1, NULL, NULL, NULL);
|
2016-04-04 13:03:12 +00:00
|
|
|
|
g_warning ("Unable to monitor '%s': %s\n"
|
|
|
|
|
"The GtkRecentManager will not update its contents "
|
|
|
|
|
"if the file is changed from other instances",
|
|
|
|
|
utf8 ? utf8 : "(invalid filename)",
|
|
|
|
|
error->message);
|
|
|
|
|
g_free (utf8);
|
2014-12-22 13:21:50 +00:00
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_signal_connect (priv->monitor, "changed",
|
|
|
|
|
G_CALLBACK (gtk_recent_manager_monitor_changed),
|
|
|
|
|
manager);
|
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
2007-06-19 10:59:37 +00:00
|
|
|
|
|
2006-04-11 21:04:15 +00:00
|
|
|
|
build_recent_items_list (manager);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* reads the recently used resources file and builds the items list.
|
|
|
|
|
* we keep the items list inside the parser object, and build the
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* RecentInfo object only on user’s demand to avoid useless replication.
|
2006-04-11 21:04:15 +00:00
|
|
|
|
* this function resets the dirty bit of the manager.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
build_recent_items_list (GtkRecentManager *manager)
|
|
|
|
|
{
|
2008-04-15 22:22:44 +00:00
|
|
|
|
GtkRecentManagerPrivate *priv = manager->priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GError *read_error;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int size;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (!priv->recent_items)
|
|
|
|
|
{
|
|
|
|
|
priv->recent_items = g_bookmark_file_new ();
|
|
|
|
|
priv->size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 13:21:50 +00:00
|
|
|
|
if (priv->filename != NULL)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2014-12-22 13:21:50 +00:00
|
|
|
|
/* the file exists, and it's valid (we hope); if not, destroy the container
|
|
|
|
|
* object and hope for a better result when the next "changed" signal is
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* fired.
|
|
|
|
|
*/
|
2014-12-22 13:21:50 +00:00
|
|
|
|
read_error = NULL;
|
|
|
|
|
g_bookmark_file_load_from_file (priv->recent_items, priv->filename, &read_error);
|
|
|
|
|
if (read_error)
|
|
|
|
|
{
|
|
|
|
|
/* if the file does not exist we just wait for the first write
|
|
|
|
|
* operation on this recent manager instance, to avoid creating
|
|
|
|
|
* empty files and leading to spurious file system events (Sabayon
|
|
|
|
|
* will not be happy about those)
|
|
|
|
|
*/
|
|
|
|
|
if (read_error->domain == G_FILE_ERROR &&
|
2019-08-30 04:45:44 +00:00
|
|
|
|
read_error->code != G_FILE_ERROR_NOENT)
|
2016-04-04 13:03:12 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *utf8 = g_filename_to_utf8 (priv->filename, -1, NULL, NULL, NULL);
|
2016-04-04 13:03:12 +00:00
|
|
|
|
g_warning ("Attempting to read the recently used resources "
|
|
|
|
|
"file at '%s', but the parser failed: %s.",
|
|
|
|
|
utf8 ? utf8 : "(invalid filename)",
|
|
|
|
|
read_error->message);
|
|
|
|
|
g_free (utf8);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2014-12-22 13:21:50 +00:00
|
|
|
|
g_bookmark_file_free (priv->recent_items);
|
|
|
|
|
priv->recent_items = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2014-12-22 13:21:50 +00:00
|
|
|
|
g_error_free (read_error);
|
|
|
|
|
}
|
|
|
|
|
else
|
2008-04-15 22:22:44 +00:00
|
|
|
|
{
|
2014-12-22 13:21:50 +00:00
|
|
|
|
size = g_bookmark_file_get_size (priv->recent_items);
|
|
|
|
|
if (priv->size != size)
|
|
|
|
|
{
|
|
|
|
|
priv->size = size;
|
2008-04-15 22:22:44 +00:00
|
|
|
|
|
2014-12-22 13:21:50 +00:00
|
|
|
|
g_object_notify (G_OBJECT (manager), "size");
|
|
|
|
|
}
|
2008-04-15 22:22:44 +00:00
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-11 21:04:15 +00:00
|
|
|
|
priv->is_dirty = FALSE;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************
|
|
|
|
|
* GtkRecentManager *
|
|
|
|
|
********************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_new:
|
2014-12-22 13:21:50 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Creates a new recent manager object.
|
|
|
|
|
*
|
|
|
|
|
* Recent manager objects are used to handle the list of recently used
|
|
|
|
|
* resources. A `GtkRecentManager` object monitors the recently used
|
|
|
|
|
* resources list, and emits the [signal@Gtk.RecentManager::changed]
|
|
|
|
|
* signal each time something inside the list changes.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* `GtkRecentManager` objects are expensive: be sure to create them
|
|
|
|
|
* only when needed. You should use [type_func@Gtk.RecentManager.get_default]
|
|
|
|
|
* instead.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Returns: A newly created `GtkRecentManager` object
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkRecentManager *
|
|
|
|
|
gtk_recent_manager_new (void)
|
|
|
|
|
{
|
2006-04-11 21:04:15 +00:00
|
|
|
|
return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_get_default:
|
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Gets a unique instance of `GtkRecentManager` that you can share
|
2010-10-22 10:51:03 +00:00
|
|
|
|
* in your application without caring about memory management.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Returns: (transfer none): A unique `GtkRecentManager`. Do not ref or
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* unref it.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkRecentManager *
|
|
|
|
|
gtk_recent_manager_get_default (void)
|
|
|
|
|
{
|
2007-06-19 10:29:55 +00:00
|
|
|
|
if (G_UNLIKELY (!recent_manager_singleton))
|
|
|
|
|
recent_manager_singleton = gtk_recent_manager_new ();
|
|
|
|
|
|
|
|
|
|
return recent_manager_singleton;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-04-15 22:00:17 +00:00
|
|
|
|
static void
|
2008-04-15 22:31:01 +00:00
|
|
|
|
gtk_recent_manager_add_item_query_info (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
2008-04-15 22:00:17 +00:00
|
|
|
|
{
|
|
|
|
|
GFile *file = G_FILE (source_object);
|
|
|
|
|
GtkRecentManager *manager = user_data;
|
|
|
|
|
GtkRecentData recent_data;
|
|
|
|
|
GFileInfo *file_info;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *uri, *basename, *content_type;
|
2008-04-15 22:00:17 +00:00
|
|
|
|
|
|
|
|
|
uri = g_file_get_uri (file);
|
|
|
|
|
|
2011-11-23 15:44:26 +00:00
|
|
|
|
file_info = g_file_query_info_finish (file, res, NULL); /* NULL-GError */
|
2008-04-15 22:00:17 +00:00
|
|
|
|
|
|
|
|
|
recent_data.display_name = NULL;
|
|
|
|
|
recent_data.description = NULL;
|
|
|
|
|
|
|
|
|
|
if (file_info)
|
|
|
|
|
{
|
2008-05-31 18:52:50 +00:00
|
|
|
|
content_type = g_file_info_get_attribute_as_string (file_info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
|
|
|
|
|
|
|
|
|
|
if (G_LIKELY (content_type))
|
|
|
|
|
recent_data.mime_type = g_content_type_get_mime_type (content_type);
|
|
|
|
|
else
|
|
|
|
|
recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
|
|
|
|
|
|
|
|
|
|
g_free (content_type);
|
2008-04-15 22:00:17 +00:00
|
|
|
|
g_object_unref (file_info);
|
|
|
|
|
}
|
|
|
|
|
else
|
2012-01-24 18:22:54 +00:00
|
|
|
|
{
|
|
|
|
|
basename = g_file_get_basename (file);
|
2017-03-09 03:52:58 +00:00
|
|
|
|
content_type = g_content_type_guess (basename, NULL, 0, NULL);
|
|
|
|
|
recent_data.mime_type = g_content_type_get_mime_type (content_type);
|
2012-01-24 18:22:54 +00:00
|
|
|
|
g_free (basename);
|
2017-03-09 03:52:58 +00:00
|
|
|
|
g_free (content_type);
|
2012-01-24 18:22:54 +00:00
|
|
|
|
}
|
2008-04-15 22:00:17 +00:00
|
|
|
|
|
|
|
|
|
recent_data.app_name = g_strdup (g_get_application_name ());
|
|
|
|
|
recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
|
|
|
|
|
recent_data.groups = NULL;
|
|
|
|
|
recent_data.is_private = FALSE;
|
|
|
|
|
|
|
|
|
|
/* Ignore return value, this can't fail anyway since all required
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* fields are set
|
|
|
|
|
*/
|
2008-04-15 22:00:17 +00:00
|
|
|
|
gtk_recent_manager_add_full (manager, uri, &recent_data);
|
|
|
|
|
|
2008-04-15 22:31:01 +00:00
|
|
|
|
manager->priv->is_dirty = TRUE;
|
|
|
|
|
gtk_recent_manager_changed (manager);
|
|
|
|
|
|
2008-04-15 22:00:17 +00:00
|
|
|
|
g_free (recent_data.mime_type);
|
|
|
|
|
g_free (recent_data.app_name);
|
|
|
|
|
g_free (recent_data.app_exec);
|
|
|
|
|
|
|
|
|
|
g_object_unref (manager);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_add_item:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @manager: a `GtkRecentManager`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @uri: a valid URI
|
|
|
|
|
*
|
|
|
|
|
* Adds a new resource, pointed by @uri, into the recently used
|
|
|
|
|
* resources list.
|
|
|
|
|
*
|
2007-07-20 10:39:03 +00:00
|
|
|
|
* This function automatically retrieves some of the needed
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* metadata and setting other metadata to common default values;
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* it then feeds the data to [method@Gtk.RecentManager.add_full].
|
2014-12-22 13:21:50 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* See [method@Gtk.RecentManager.add_full] if you want to explicitly
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* define the metadata for the resource pointed by @uri.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the new item was successfully added
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* to the recently used resources list
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2014-12-22 22:16:30 +00:00
|
|
|
|
gtk_recent_manager_add_item (GtkRecentManager *manager,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *uri)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2008-04-15 22:00:17 +00:00
|
|
|
|
GFile* file;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
|
|
|
|
|
2008-04-15 22:00:17 +00:00
|
|
|
|
file = g_file_new_for_uri (uri);
|
2007-03-15 19:58:00 +00:00
|
|
|
|
|
2008-04-15 22:00:17 +00:00
|
|
|
|
g_file_query_info_async (file,
|
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
NULL,
|
2008-04-15 22:31:01 +00:00
|
|
|
|
gtk_recent_manager_add_item_query_info,
|
2008-04-15 22:00:17 +00:00
|
|
|
|
g_object_ref (manager));
|
2007-03-15 19:58:00 +00:00
|
|
|
|
|
2008-04-15 22:00:17 +00:00
|
|
|
|
g_object_unref (file);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2008-04-15 22:00:17 +00:00
|
|
|
|
return TRUE;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_add_full:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @manager: a `GtkRecentManager`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @uri: a valid URI
|
|
|
|
|
* @recent_data: metadata of the resource
|
|
|
|
|
*
|
|
|
|
|
* Adds a new resource, pointed by @uri, into the recently used
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* resources list, using the metadata specified inside the
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* `GtkRecentData` passed in @recent_data.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* The passed URI will be used to identify this resource inside the
|
|
|
|
|
* list.
|
|
|
|
|
*
|
|
|
|
|
* In order to register the new recently used resource, metadata about
|
|
|
|
|
* the resource must be passed as well as the URI; the metadata is
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* stored in a `GtkRecentData`, which must contain the MIME
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* type of the resource pointed by the URI; the name of the application
|
|
|
|
|
* that is registering the item, and a command line to be used when
|
|
|
|
|
* launching the item.
|
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Optionally, a `GtkRecentData` might contain a UTF-8 string
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* to be used when viewing the item instead of the last component of
|
|
|
|
|
* the URI; a short description of the item; whether the item should
|
|
|
|
|
* be considered private - that is, should be displayed only by the
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* applications that have registered it.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the new item was successfully added to the
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* recently used resources list, %FALSE otherwise
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2014-12-22 22:16:30 +00:00
|
|
|
|
gtk_recent_manager_add_full (GtkRecentManager *manager,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *uri,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
const GtkRecentData *data)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv;
|
2013-02-13 16:05:47 +00:00
|
|
|
|
GtkSettings *settings;
|
|
|
|
|
gboolean enabled;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (data != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
|
if ((data->display_name) &&
|
|
|
|
|
(!g_utf8_validate (data->display_name, -1, NULL)))
|
|
|
|
|
{
|
2015-09-20 06:32:48 +00:00
|
|
|
|
g_warning ("Attempting to add '%s' to the list of recently used "
|
2014-12-22 22:16:30 +00:00
|
|
|
|
"resources, but the display name is not a valid UTF-8 "
|
|
|
|
|
"encoded string",
|
|
|
|
|
uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if ((data->description) &&
|
|
|
|
|
(!g_utf8_validate (data->description, -1, NULL)))
|
|
|
|
|
{
|
2015-09-20 06:32:48 +00:00
|
|
|
|
g_warning ("Attempting to add '%s' to the list of recently used "
|
2014-12-22 22:16:30 +00:00
|
|
|
|
"resources, but the description is not a valid UTF-8 "
|
|
|
|
|
"encoded string",
|
|
|
|
|
uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!data->mime_type)
|
|
|
|
|
{
|
2015-09-20 06:32:48 +00:00
|
|
|
|
g_warning ("Attempting to add '%s' to the list of recently used "
|
2014-12-22 22:16:30 +00:00
|
|
|
|
"resources, but no MIME type was defined",
|
|
|
|
|
uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!data->app_name)
|
|
|
|
|
{
|
2015-09-20 06:32:48 +00:00
|
|
|
|
g_warning ("Attempting to add '%s' to the list of recently used "
|
2014-12-22 22:16:30 +00:00
|
|
|
|
"resources, but no name of the application that is "
|
|
|
|
|
"registering it was defined",
|
|
|
|
|
uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!data->app_exec)
|
|
|
|
|
{
|
2015-09-20 06:32:48 +00:00
|
|
|
|
g_warning ("Attempting to add '%s' to the list of recently used "
|
2014-12-22 22:16:30 +00:00
|
|
|
|
"resources, but no command line for the application "
|
|
|
|
|
"that is registering it was defined",
|
|
|
|
|
uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2013-02-13 16:05:47 +00:00
|
|
|
|
|
|
|
|
|
settings = gtk_settings_get_default ();
|
|
|
|
|
g_object_get (G_OBJECT (settings), "gtk-recent-files-enabled", &enabled, NULL);
|
|
|
|
|
if (!enabled)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
priv = manager->priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (!priv->recent_items)
|
|
|
|
|
{
|
|
|
|
|
priv->recent_items = g_bookmark_file_new ();
|
|
|
|
|
priv->size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 22:16:30 +00:00
|
|
|
|
if (data->display_name)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (data->description)
|
|
|
|
|
g_bookmark_file_set_description (priv->recent_items, uri, data->description);
|
|
|
|
|
|
|
|
|
|
g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2017-03-23 16:15:26 +00:00
|
|
|
|
if (data->groups && ((char*)data->groups)[0] != '\0')
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int j;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
for (j = 0; (data->groups)[j] != NULL; j++)
|
|
|
|
|
g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* register the application; this will take care of updating the
|
|
|
|
|
* registration count and time in case the application has
|
|
|
|
|
* already registered the same document inside the list
|
|
|
|
|
*/
|
|
|
|
|
g_bookmark_file_add_application (priv->recent_items, uri,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
data->app_name,
|
|
|
|
|
data->app_exec);
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_bookmark_file_set_is_private (priv->recent_items, uri,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
data->is_private);
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* mark us as dirty, so that when emitting the "changed" signal we
|
|
|
|
|
* will dump our changes
|
|
|
|
|
*/
|
|
|
|
|
priv->is_dirty = TRUE;
|
2006-03-30 21:30:37 +00:00
|
|
|
|
gtk_recent_manager_changed (manager);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_remove_item:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @manager: a `GtkRecentManager`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @uri: the URI of the item you wish to remove
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @error: (allow-none): return location for a #GError, or %NULL
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Removes a resource pointed by @uri from the recently used resources
|
|
|
|
|
* list handled by a recent manager.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the item pointed by @uri has been successfully
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* removed by the recently used resources list, and %FALSE otherwise
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2006-03-30 21:30:37 +00:00
|
|
|
|
gtk_recent_manager_remove_item (GtkRecentManager *manager,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *uri,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
GError **error)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv;
|
|
|
|
|
GError *remove_error = NULL;
|
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
priv = manager->priv;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!priv->recent_items)
|
|
|
|
|
{
|
|
|
|
|
priv->recent_items = g_bookmark_file_new ();
|
|
|
|
|
priv->size = 0;
|
|
|
|
|
|
2008-06-17 13:42:53 +00:00
|
|
|
|
g_set_error (error, GTK_RECENT_MANAGER_ERROR,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("Unable to find an item with URI “%s”"),
|
2014-12-22 22:16:30 +00:00
|
|
|
|
uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
|
|
|
|
|
if (remove_error)
|
|
|
|
|
{
|
2008-06-17 13:46:48 +00:00
|
|
|
|
g_error_free (remove_error);
|
2008-06-17 13:42:53 +00:00
|
|
|
|
|
|
|
|
|
g_set_error (error, GTK_RECENT_MANAGER_ERROR,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("Unable to find an item with URI “%s”"),
|
2014-12-22 22:16:30 +00:00
|
|
|
|
uri);
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
priv->is_dirty = TRUE;
|
2006-03-30 21:30:37 +00:00
|
|
|
|
gtk_recent_manager_changed (manager);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_has_item:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @manager: a `GtkRecentManager`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @uri: a URI
|
|
|
|
|
*
|
|
|
|
|
* Checks whether there is a recently used resource registered
|
|
|
|
|
* with @uri inside the recent manager.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: %TRUE if the resource was found, %FALSE otherwise
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2006-03-30 21:30:37 +00:00
|
|
|
|
gtk_recent_manager_has_item (GtkRecentManager *manager,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *uri)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv;
|
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
priv = manager->priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (priv->recent_items != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
return g_bookmark_file_has_item (priv->recent_items, uri);
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-25 16:15:21 +00:00
|
|
|
|
static void
|
2014-12-22 22:16:30 +00:00
|
|
|
|
build_recent_info (GBookmarkFile *bookmarks,
|
|
|
|
|
GtkRecentInfo *info)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char **apps, **groups;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gsize apps_len, groups_len, i;
|
2019-08-30 06:26:25 +00:00
|
|
|
|
int app_index;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
g_assert (bookmarks != NULL);
|
|
|
|
|
g_assert (info != NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
|
|
|
|
|
info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
|
|
|
|
|
info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
info->added = g_bookmark_file_get_added_date_time (bookmarks, info->uri, NULL);
|
|
|
|
|
info->modified = g_bookmark_file_get_modified_date_time (bookmarks, info->uri, NULL);
|
|
|
|
|
info->visited = g_bookmark_file_get_visited_date_time (bookmarks, info->uri, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
|
2019-08-30 06:26:25 +00:00
|
|
|
|
info->groups = g_malloc (sizeof (char *) * groups_len);
|
|
|
|
|
info->n_groups = groups_len;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
for (i = 0; i < groups_len; i++)
|
2019-08-30 06:26:25 +00:00
|
|
|
|
info->groups[i] = g_strdup (groups[i]);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
g_strfreev (groups);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
app_index = 0;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
|
2019-08-30 06:26:25 +00:00
|
|
|
|
info->applications = g_malloc (sizeof (RecentAppInfo ) * apps_len);
|
|
|
|
|
info->n_applications = 0;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
for (i = 0; i < apps_len; i++)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *app_name, *app_exec;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
guint count;
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *stamp;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
RecentAppInfo *app_info;
|
|
|
|
|
gboolean res;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
app_name = apps[i];
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
res = g_bookmark_file_get_application_info (bookmarks, info->uri, app_name,
|
|
|
|
|
&app_exec,
|
|
|
|
|
&count,
|
|
|
|
|
&stamp,
|
|
|
|
|
NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!res)
|
|
|
|
|
continue;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
app_info = &info->applications[app_index];
|
|
|
|
|
app_info->name= g_strdup (app_name);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
app_info->exec = app_exec;
|
|
|
|
|
app_info->count = count;
|
2020-07-31 16:08:41 +00:00
|
|
|
|
app_info->stamp = g_date_time_ref (stamp);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
|
2019-08-30 06:26:25 +00:00
|
|
|
|
|
|
|
|
|
app_index ++;
|
|
|
|
|
info->n_applications ++;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_strfreev (apps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_lookup_item:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @manager: a `GtkRecentManager`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @uri: a URI
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @error: (allow-none): a return location for a #GError, or %NULL
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Searches for a URI inside the recently used resources list, and
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* returns a `GtkRecentInfo` containing information about the resource
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* like its MIME type, or its display name.
|
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Returns: (nullable): a `GtkRecentInfo` containing information
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* about the resource pointed by @uri, or %NULL if the URI was
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* not registered in the recently used resources list. Free with
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* [method@Gtk.RecentInfo.unref].
|
2006-08-16 03:42:23 +00:00
|
|
|
|
*/
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GtkRecentInfo *
|
2006-03-30 21:30:37 +00:00
|
|
|
|
gtk_recent_manager_lookup_item (GtkRecentManager *manager,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *uri,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
GError **error)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv;
|
|
|
|
|
GtkRecentInfo *info = NULL;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (uri != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
priv = manager->priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!priv->recent_items)
|
|
|
|
|
{
|
|
|
|
|
priv->recent_items = g_bookmark_file_new ();
|
|
|
|
|
priv->size = 0;
|
|
|
|
|
|
|
|
|
|
g_set_error (error, GTK_RECENT_MANAGER_ERROR,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("Unable to find an item with URI “%s”"),
|
2014-12-22 22:16:30 +00:00
|
|
|
|
uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!g_bookmark_file_has_item (priv->recent_items, uri))
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error, GTK_RECENT_MANAGER_ERROR,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("Unable to find an item with URI “%s”"),
|
2014-12-22 22:16:30 +00:00
|
|
|
|
uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
info = gtk_recent_info_new (uri);
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* fill the RecentInfo structure with the data retrieved by our
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* parser object from the storage file
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2007-06-25 16:15:21 +00:00
|
|
|
|
build_recent_info (priv->recent_items, info);
|
|
|
|
|
|
2007-04-18 14:37:49 +00:00
|
|
|
|
return info;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_move_item:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @manager: a `GtkRecentManager`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @uri: the URI of a recently used resource
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* @new_uri: (allow-none): the new URI of the recently used resource, or
|
|
|
|
|
* %NULL to remove the item pointed by @uri in the list
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @error: (allow-none): a return location for a #GError, or %NULL
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Changes the location of a recently used resource from @uri to @new_uri.
|
2014-12-22 22:16:30 +00:00
|
|
|
|
*
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* Please note that this function will not affect the resource pointed
|
|
|
|
|
* by the URIs, but only the URI used in the recently used resources list.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: %TRUE on success
|
2011-01-24 02:50:39 +00:00
|
|
|
|
*/
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_recent_manager_move_item (GtkRecentManager *recent_manager,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *uri,
|
|
|
|
|
const char *new_uri,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
GError **error)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv;
|
|
|
|
|
GError *move_error;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
|
|
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
priv = recent_manager->priv;
|
|
|
|
|
|
2008-06-17 13:42:53 +00:00
|
|
|
|
if (!priv->recent_items)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error, GTK_RECENT_MANAGER_ERROR,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("Unable to find an item with URI “%s”"),
|
2011-01-24 02:50:39 +00:00
|
|
|
|
uri);
|
2008-06-17 13:42:53 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!g_bookmark_file_has_item (priv->recent_items, uri))
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error, GTK_RECENT_MANAGER_ERROR,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("Unable to find an item with URI “%s”"),
|
2011-01-24 02:50:39 +00:00
|
|
|
|
uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
move_error = NULL;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
if (!g_bookmark_file_move_item (priv->recent_items,
|
|
|
|
|
uri,
|
|
|
|
|
new_uri,
|
|
|
|
|
&move_error))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2008-06-17 13:42:53 +00:00
|
|
|
|
g_error_free (move_error);
|
|
|
|
|
|
|
|
|
|
g_set_error (error, GTK_RECENT_MANAGER_ERROR,
|
2016-04-10 17:39:33 +00:00
|
|
|
|
GTK_RECENT_MANAGER_ERROR_UNKNOWN,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("Unable to move the item with URI “%s” to “%s”"),
|
2016-04-10 17:39:33 +00:00
|
|
|
|
uri, new_uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
priv->is_dirty = TRUE;
|
|
|
|
|
gtk_recent_manager_changed (recent_manager);
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_get_items:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @manager: a `GtkRecentManager`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the list of recently used resources.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: (element-type GtkRecentInfo) (transfer full): a list of
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* newly allocated `GtkRecentInfo objects`. Use
|
|
|
|
|
* [method@Gtk.RecentInfo.unref] on each item inside the list, and then
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* free the list itself using g_list_free().
|
|
|
|
|
*/
|
|
|
|
|
GList *
|
2006-03-30 21:30:37 +00:00
|
|
|
|
gtk_recent_manager_get_items (GtkRecentManager *manager)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv;
|
|
|
|
|
GList *retval = NULL;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char **uris;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gsize uris_len, i;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
priv = manager->priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!priv->recent_items)
|
|
|
|
|
return NULL;
|
2006-11-16 09:57:45 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
|
|
|
|
|
for (i = 0; i < uris_len; i++)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
info = gtk_recent_info_new (uris[i]);
|
2007-06-25 16:15:21 +00:00
|
|
|
|
build_recent_info (priv->recent_items, info);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
retval = g_list_prepend (retval, info);
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_strfreev (uris);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
purge_recent_items_list (GtkRecentManager *manager,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
GError **error)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv = manager->priv;
|
|
|
|
|
|
2010-10-22 15:12:16 +00:00
|
|
|
|
if (priv->recent_items == NULL)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return;
|
2010-10-22 15:12:16 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_bookmark_file_free (priv->recent_items);
|
|
|
|
|
priv->recent_items = g_bookmark_file_new ();
|
|
|
|
|
priv->size = 0;
|
2010-10-22 15:12:16 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* emit the changed signal, to ensure that the purge is written */
|
2010-10-22 15:12:16 +00:00
|
|
|
|
priv->is_dirty = TRUE;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_manager_changed (manager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_manager_purge_items:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @manager: a `GtkRecentManager`
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @error: (allow-none): a return location for a #GError, or %NULL
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Purges every item from the recently used resources list.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the number of items that have been removed from the
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* recently used resources list
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int
|
2006-03-30 21:30:37 +00:00
|
|
|
|
gtk_recent_manager_purge_items (GtkRecentManager *manager,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
GError **error)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int count, purged;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
priv = manager->priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!priv->recent_items)
|
|
|
|
|
return 0;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
count = g_bookmark_file_get_size (priv->recent_items);
|
|
|
|
|
if (!count)
|
|
|
|
|
return 0;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
purge_recent_items_list (manager, error);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
purged = count - g_bookmark_file_get_size (priv->recent_items);
|
|
|
|
|
|
|
|
|
|
return purged;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-22 15:12:16 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
emit_manager_changed (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentManager *manager = data;
|
|
|
|
|
|
|
|
|
|
manager->priv->changed_age = 0;
|
|
|
|
|
manager->priv->changed_timeout = 0;
|
|
|
|
|
|
|
|
|
|
g_signal_emit (manager, signal_changed, 0);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
static void
|
2010-10-22 15:12:16 +00:00
|
|
|
|
gtk_recent_manager_changed (GtkRecentManager *manager)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2010-10-22 15:12:16 +00:00
|
|
|
|
/* coalesce consecutive changes
|
|
|
|
|
*
|
|
|
|
|
* we schedule a write in 250 msecs immediately; if we get more than one
|
|
|
|
|
* request per millisecond before the timeout has a chance to run, we
|
|
|
|
|
* schedule an emission immediately.
|
|
|
|
|
*/
|
|
|
|
|
if (manager->priv->changed_timeout == 0)
|
2013-10-22 13:43:43 +00:00
|
|
|
|
{
|
2018-02-02 14:51:47 +00:00
|
|
|
|
manager->priv->changed_timeout = g_timeout_add (250, emit_manager_changed, manager);
|
2019-02-05 10:26:20 +00:00
|
|
|
|
g_source_set_name_by_id (manager->priv->changed_timeout, "[gtk] emit_manager_changed");
|
2013-10-22 13:43:43 +00:00
|
|
|
|
}
|
2010-10-22 15:12:16 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
manager->priv->changed_age += 1;
|
|
|
|
|
|
|
|
|
|
if (manager->priv->changed_age > 250)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (manager->priv->changed_timeout);
|
|
|
|
|
g_signal_emit (manager, signal_changed, 0);
|
|
|
|
|
|
|
|
|
|
manager->priv->changed_age = 0;
|
|
|
|
|
manager->priv->changed_timeout = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-04-15 22:37:32 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int age)
|
2008-04-15 22:37:32 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv = manager->priv;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char **uris;
|
2008-04-15 22:37:32 +00:00
|
|
|
|
gsize n_uris, i;
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *now;
|
2008-04-15 22:37:32 +00:00
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!priv->recent_items))
|
|
|
|
|
return;
|
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
now = g_date_time_new_now_utc ();
|
2008-04-15 22:37:32 +00:00
|
|
|
|
|
|
|
|
|
uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
|
2008-04-18 13:05:56 +00:00
|
|
|
|
|
2008-04-15 22:37:32 +00:00
|
|
|
|
for (i = 0; i < n_uris; i++)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *uri = uris[i];
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *modified;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int item_age;
|
2008-04-15 22:37:32 +00:00
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
modified = g_bookmark_file_get_modified_date_time (priv->recent_items, uri, NULL);
|
|
|
|
|
|
|
|
|
|
item_age = (int) (g_date_time_difference (now, modified) / (double)G_TIME_SPAN_DAY);
|
2008-04-15 22:37:32 +00:00
|
|
|
|
if (item_age > age)
|
|
|
|
|
g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
|
|
|
|
|
}
|
2008-04-18 13:05:56 +00:00
|
|
|
|
|
|
|
|
|
g_strfreev (uris);
|
2008-04-15 22:37:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 13:51:29 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_manager_clamp_to_size (GtkRecentManager *manager,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
const int size)
|
2016-10-27 13:51:29 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManagerPrivate *priv = manager->priv;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char **uris;
|
2016-10-27 13:51:29 +00:00
|
|
|
|
gsize n_uris, i;
|
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!priv->recent_items) || G_UNLIKELY (size < 0))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
|
|
|
|
|
|
|
|
|
|
if (n_uris < size)
|
2016-11-11 09:36:20 +00:00
|
|
|
|
{
|
|
|
|
|
g_strfreev (uris);
|
2016-10-27 13:51:29 +00:00
|
|
|
|
return;
|
2016-11-11 09:36:20 +00:00
|
|
|
|
}
|
2016-10-27 13:51:29 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_uris - size; i++)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *uri = uris[i];
|
2016-10-27 13:51:29 +00:00
|
|
|
|
g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_strfreev (uris);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/*****************
|
|
|
|
|
* GtkRecentInfo *
|
|
|
|
|
*****************/
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2010-04-27 11:31:23 +00:00
|
|
|
|
G_DEFINE_BOXED_TYPE (GtkRecentInfo, gtk_recent_info,
|
|
|
|
|
gtk_recent_info_ref,
|
|
|
|
|
gtk_recent_info_unref)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
static GtkRecentInfo *
|
2020-07-24 18:40:36 +00:00
|
|
|
|
gtk_recent_info_new (const char *uri)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info;
|
|
|
|
|
|
|
|
|
|
g_assert (uri != NULL);
|
|
|
|
|
|
|
|
|
|
info = g_new0 (GtkRecentInfo, 1);
|
|
|
|
|
info->uri = g_strdup (uri);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
info->applications = NULL;
|
|
|
|
|
info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
info->groups = NULL;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
info->ref_count = 1;
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_info_free (GtkRecentInfo *recent_info)
|
|
|
|
|
{
|
2019-08-30 06:26:25 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!recent_info)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_free (recent_info->uri);
|
|
|
|
|
g_free (recent_info->display_name);
|
|
|
|
|
g_free (recent_info->description);
|
|
|
|
|
g_free (recent_info->mime_type);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
for (i = 0; i < recent_info->n_applications; i ++)
|
|
|
|
|
{
|
|
|
|
|
const RecentAppInfo *app_info = &recent_info->applications[i];
|
|
|
|
|
|
|
|
|
|
g_free (app_info->name);
|
|
|
|
|
g_free (app_info->exec);
|
2020-07-31 16:08:41 +00:00
|
|
|
|
g_date_time_unref (app_info->stamp);
|
2019-08-30 06:26:25 +00:00
|
|
|
|
}
|
|
|
|
|
g_free (recent_info->applications);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (recent_info->apps_lookup)
|
|
|
|
|
g_hash_table_destroy (recent_info->apps_lookup);
|
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
for (i = 0; i < recent_info->n_groups; i ++)
|
|
|
|
|
g_free (recent_info->groups[i]);
|
|
|
|
|
|
|
|
|
|
g_free (recent_info->groups);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_free (recent_info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_ref:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Increases the reference count of @recent_info by one.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: the recent info object with its reference count
|
|
|
|
|
* increased by one
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkRecentInfo *
|
|
|
|
|
gtk_recent_info_ref (GtkRecentInfo *info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (info->ref_count > 0, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
info->ref_count += 1;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_unref:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Decreases the reference count of @info by one.
|
|
|
|
|
*
|
|
|
|
|
* If the reference count reaches zero, @info is
|
|
|
|
|
* deallocated, and the memory freed.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_recent_info_unref (GtkRecentInfo *info)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
g_return_if_fail (info->ref_count > 0);
|
|
|
|
|
|
|
|
|
|
info->ref_count -= 1;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (info->ref_count == 0)
|
|
|
|
|
gtk_recent_info_free (info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_uri:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `tkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the URI of the resource.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: the URI of the resource. The returned string is
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* owned by the recent manager, and should not be freed.
|
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_uri (GtkRecentInfo *info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return info->uri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_display_name:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
|
|
|
|
*
|
|
|
|
|
* Gets the name of the resource.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* If none has been defined, the basename
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* of the resource is obtained.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: the display name of the resource. The returned string
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* is owned by the recent manager, and should not be freed.
|
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_display_name (GtkRecentInfo *info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!info->display_name)
|
|
|
|
|
info->display_name = gtk_recent_info_get_short_name (info);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return info->display_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_description:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the (short) description of the resource.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: the description of the resource. The returned string
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* is owned by the recent manager, and should not be freed.
|
|
|
|
|
**/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_description (GtkRecentInfo *info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return info->description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_mime_type:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the MIME type of the resource.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: the MIME type of the resource. The returned string
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* is owned by the recent manager, and should not be freed.
|
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_mime_type (GtkRecentInfo *info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!info->mime_type)
|
|
|
|
|
info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return info->mime_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_added:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2020-07-31 16:08:41 +00:00
|
|
|
|
* Gets the the time when the resource
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* was added to the recently used resources list.
|
|
|
|
|
*
|
2020-07-31 16:08:41 +00:00
|
|
|
|
* Returns: (transfer none): a #GDateTime for the time
|
|
|
|
|
* when the resource was added
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_added (GtkRecentInfo *info)
|
|
|
|
|
{
|
2020-07-31 16:08:41 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return info->added;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_modified:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2020-07-31 16:08:41 +00:00
|
|
|
|
* Gets the time when the meta-data
|
2013-07-08 21:41:27 +00:00
|
|
|
|
* for the resource was last modified.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2020-07-31 16:08:41 +00:00
|
|
|
|
* Returns: (transfer none): a #GDateTime for the time
|
|
|
|
|
* when the resource was last modified
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_modified (GtkRecentInfo *info)
|
|
|
|
|
{
|
2020-07-31 16:08:41 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return info->modified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_visited:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2020-07-31 16:08:41 +00:00
|
|
|
|
* Gets the time when the meta-data
|
2013-07-08 21:41:27 +00:00
|
|
|
|
* for the resource was last visited.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2020-07-31 16:08:41 +00:00
|
|
|
|
* Returns: (transfer none): a #GDateTime for the time
|
|
|
|
|
* when the resource was last visited
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_visited (GtkRecentInfo *info)
|
|
|
|
|
{
|
2020-07-31 16:08:41 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return info->visited;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_private_hint:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
|
|
|
|
*
|
|
|
|
|
* Gets the value of the “private” flag.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Resources in the recently used list that have this flag
|
|
|
|
|
* set to %TRUE should only be displayed by the applications
|
|
|
|
|
* that have registered them.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: %TRUE if the private flag was found, %FALSE otherwise
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_recent_info_get_private_hint (GtkRecentInfo *info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return info->is_private;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_application_info:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @app_name: the name of the application that has registered this item
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* @app_exec: (transfer none) (out): return location for the string containing
|
|
|
|
|
* the command line
|
2009-12-10 10:23:40 +00:00
|
|
|
|
* @count: (out): return location for the number of times this item was registered
|
2020-07-31 16:08:41 +00:00
|
|
|
|
* @stamp: (out) (transfer none): return location for the time this item was last
|
|
|
|
|
* registered for this application
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the data regarding the application that has registered the resource
|
|
|
|
|
* pointed by @info.
|
|
|
|
|
*
|
|
|
|
|
* If the command line contains any escape characters defined inside the
|
|
|
|
|
* storage specification, they will be expanded.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if an application with @app_name has registered this
|
2009-06-15 21:22:58 +00:00
|
|
|
|
* resource inside the recently used list, or %FALSE otherwise. The
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @app_exec string is owned by the `GtkRecentInfo` and should not be
|
2009-06-15 21:22:58 +00:00
|
|
|
|
* modified or freed
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_recent_info_get_application_info (GtkRecentInfo *info,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *app_name,
|
|
|
|
|
const char **app_exec,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
guint *count,
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime **stamp)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
RecentAppInfo *ai;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (app_name != NULL, FALSE);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
app_name);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!ai)
|
|
|
|
|
{
|
|
|
|
|
g_warning ("No registered application with name '%s' "
|
|
|
|
|
"for item with URI '%s' found",
|
|
|
|
|
app_name,
|
|
|
|
|
info->uri);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (app_exec)
|
|
|
|
|
*app_exec = ai->exec;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (count)
|
|
|
|
|
*count = ai->count;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
if (stamp)
|
|
|
|
|
*stamp = ai->stamp;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_applications:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2009-12-10 10:23:40 +00:00
|
|
|
|
* @length: (out) (allow-none): return location for the length of the returned list
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Retrieves the list of applications that have registered this resource.
|
|
|
|
|
*
|
2021-02-14 17:59:05 +00:00
|
|
|
|
* Returns: (array length=length zero-terminated=1) (transfer full): a newly
|
|
|
|
|
* allocated %NULL-terminated array of strings. Use g_strfreev() to free it.
|
2009-12-10 10:23:40 +00:00
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char **
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_applications (GtkRecentInfo *info,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
gsize *length)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char **retval;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gsize n_apps, i;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!info->applications)
|
|
|
|
|
{
|
|
|
|
|
if (length)
|
|
|
|
|
*length = 0;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
|
|
|
|
return NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
n_apps = info->n_applications;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
retval = g_new0 (char *, n_apps + 1);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
for (i = 0; i < info->n_applications; i ++)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2019-08-30 06:26:25 +00:00
|
|
|
|
const RecentAppInfo *ai = &info->applications[i];
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
retval[i] = g_strdup (ai->name);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
retval[i] = NULL;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (length)
|
2019-08-30 06:26:25 +00:00
|
|
|
|
*length = info->n_applications;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_has_application:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @app_name: a string containing an application name
|
|
|
|
|
*
|
|
|
|
|
* Checks whether an application registered this resource using @app_name.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if an application with name @app_name was found,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* %FALSE otherwise
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_recent_info_has_application (GtkRecentInfo *info,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *app_name)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (app_name != NULL, FALSE);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_last_application:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the name of the last application that have registered the
|
|
|
|
|
* recently used resource represented by @info.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: an application name. Use g_free() to free it.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *
|
2014-12-22 22:16:30 +00:00
|
|
|
|
gtk_recent_info_last_application (GtkRecentInfo *info)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2019-08-30 06:26:25 +00:00
|
|
|
|
int i;
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *last_stamp = NULL;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *name = NULL;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
for (i = 0; i < info->n_applications; i ++)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2019-08-30 06:26:25 +00:00
|
|
|
|
const RecentAppInfo *ai = &info->applications[i];
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
if (last_stamp == NULL ||
|
|
|
|
|
g_date_time_compare (ai->stamp, last_stamp) > 0)
|
2006-04-01 00:44:55 +00:00
|
|
|
|
{
|
2014-12-22 22:16:30 +00:00
|
|
|
|
name = ai->name;
|
|
|
|
|
last_stamp = ai->stamp;
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return g_strdup (name);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-29 13:21:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_gicon:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2010-04-29 13:21:23 +00:00
|
|
|
|
*
|
|
|
|
|
* Retrieves the icon associated to the resource MIME type.
|
|
|
|
|
*
|
2016-09-22 11:56:47 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): a #GIcon containing the icon, or %NULL.
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Use g_object_unref() when finished using the icon
|
2010-04-29 13:21:23 +00:00
|
|
|
|
*/
|
|
|
|
|
GIcon *
|
2014-12-22 22:16:30 +00:00
|
|
|
|
gtk_recent_info_get_gicon (GtkRecentInfo *info)
|
2010-04-29 13:21:23 +00:00
|
|
|
|
{
|
|
|
|
|
GIcon *icon = NULL;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *content_type;
|
2010-04-29 13:21:23 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (info->mime_type != NULL &&
|
|
|
|
|
(content_type = g_content_type_from_mime_type (info->mime_type)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
icon = g_content_type_get_icon (content_type);
|
|
|
|
|
g_free (content_type);
|
|
|
|
|
}
|
2017-10-22 20:20:12 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (info->mime_type &&
|
|
|
|
|
strcmp (info->mime_type, "x-directory/normal") == 0)
|
|
|
|
|
icon = g_themed_icon_new ("folder");
|
|
|
|
|
else
|
|
|
|
|
icon = g_themed_icon_new ("text-x-generic");
|
|
|
|
|
}
|
2010-04-29 13:21:23 +00:00
|
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_is_local:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Checks whether the resource is local or not by looking at the
|
|
|
|
|
* scheme of its URI.
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: %TRUE if the resource is local
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_recent_info_is_local (GtkRecentInfo *info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-04-16 03:55:07 +00:00
|
|
|
|
return has_case_prefix (info->uri, "file:/");
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_exists:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Checks whether the resource pointed by @info still exists.
|
|
|
|
|
* At the moment this check is done only on resources pointing
|
|
|
|
|
* to local files.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the resource exists
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_recent_info_exists (GtkRecentInfo *info)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *filename;
|
2011-10-03 15:25:33 +00:00
|
|
|
|
GStatBuf stat_buf;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gboolean retval = FALSE;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* we guarantee only local resources */
|
|
|
|
|
if (!gtk_recent_info_is_local (info))
|
|
|
|
|
return FALSE;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
filename = g_filename_from_uri (info->uri, NULL, NULL);
|
|
|
|
|
if (filename)
|
|
|
|
|
{
|
2011-10-03 15:25:33 +00:00
|
|
|
|
if (g_stat (filename, &stat_buf) == 0)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
retval = TRUE;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_free (filename);
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_match:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info_a: a `GtkRecentInfo`
|
|
|
|
|
* @info_b: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Checks whether two `GtkRecentInfo` point to the same resource.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Returns: %TRUE if both `GtkRecentInfo` point to the same
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* resource, %FALSE otherwise
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2006-03-30 21:30:37 +00:00
|
|
|
|
gtk_recent_info_match (GtkRecentInfo *info_a,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
GtkRecentInfo *info_b)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2006-03-30 21:30:37 +00:00
|
|
|
|
g_return_val_if_fail (info_a != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (info_b != NULL, FALSE);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-30 21:30:37 +00:00
|
|
|
|
return (0 == strcmp (info_a->uri, info_b->uri));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* taken from gnome-vfs-uri.c */
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static const char *
|
|
|
|
|
get_method_string (const char *substring,
|
|
|
|
|
char **method_string)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *p;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
char *method;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
for (p = substring;
|
|
|
|
|
g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
|
|
|
|
|
p++)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
if (*p == ':'
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
&&
|
|
|
|
|
!(p == substring + 1 && g_ascii_isalpha (*substring))
|
|
|
|
|
#endif
|
2014-12-22 22:16:30 +00:00
|
|
|
|
)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
/* Found toplevel method specification. */
|
|
|
|
|
method = g_strndup (substring, p - substring);
|
|
|
|
|
*method_string = g_ascii_strdown (method, -1);
|
|
|
|
|
g_free (method);
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*method_string = g_strdup ("file");
|
|
|
|
|
p = substring;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Stolen from gnome_vfs_make_valid_utf8() */
|
|
|
|
|
static char *
|
|
|
|
|
make_valid_utf8 (const char *name)
|
|
|
|
|
{
|
|
|
|
|
GString *string;
|
|
|
|
|
const char *remainder, *invalid;
|
|
|
|
|
int remaining_bytes, valid_bytes;
|
|
|
|
|
|
|
|
|
|
string = NULL;
|
|
|
|
|
remainder = name;
|
|
|
|
|
remaining_bytes = name ? strlen (name) : 0;
|
|
|
|
|
|
|
|
|
|
while (remaining_bytes != 0)
|
|
|
|
|
{
|
|
|
|
|
if (g_utf8_validate (remainder, remaining_bytes, &invalid))
|
|
|
|
|
break;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
valid_bytes = invalid - remainder;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (string == NULL)
|
|
|
|
|
string = g_string_sized_new (remaining_bytes);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_string_append_len (string, remainder, valid_bytes);
|
|
|
|
|
g_string_append_c (string, '?');
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
remaining_bytes -= valid_bytes + 1;
|
|
|
|
|
remainder = invalid + 1;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (string == NULL)
|
|
|
|
|
return g_strdup (name);
|
|
|
|
|
|
|
|
|
|
g_string_append (string, remainder);
|
|
|
|
|
g_assert (g_utf8_validate (string->str, -1, NULL));
|
|
|
|
|
|
|
|
|
|
return g_string_free (string, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static char *
|
|
|
|
|
get_uri_shortname_for_display (const char *uri)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *name = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gboolean validated = FALSE;
|
|
|
|
|
|
2006-04-16 03:55:07 +00:00
|
|
|
|
if (has_case_prefix (uri, "file:/"))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *local_file;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
local_file = g_filename_from_uri (uri, NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-11-22 09:12:49 +00:00
|
|
|
|
if (local_file)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
name = g_filename_display_basename (local_file);
|
|
|
|
|
validated = TRUE;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_free (local_file);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-22 09:12:49 +00:00
|
|
|
|
if (!name)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *method;
|
|
|
|
|
char *local_file;
|
|
|
|
|
const char *rest;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
rest = get_method_string (uri, &method);
|
|
|
|
|
local_file = g_filename_display_basename (rest);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2007-07-13 16:34:05 +00:00
|
|
|
|
name = g_strconcat (method, ": ", local_file, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_free (local_file);
|
|
|
|
|
g_free (method);
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_assert (name != NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (!validated && !g_utf8_validate (name, -1, NULL))
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *utf8_name;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
utf8_name = make_valid_utf8 (name);
|
|
|
|
|
g_free (name);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
name = utf8_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_short_name:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: an `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Computes a valid UTF-8 string that can be used as the
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* name of the item in a menu or list.
|
|
|
|
|
*
|
|
|
|
|
* For example, calling this function on an item that refers
|
|
|
|
|
* to “file:///foo/bar.txt” will yield “bar.txt”.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: A newly-allocated string in UTF-8 encoding
|
|
|
|
|
* free it with g_free()
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_short_name (GtkRecentInfo *info)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *short_name;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (info->uri == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
short_name = get_uri_shortname_for_display (info->uri);
|
|
|
|
|
|
|
|
|
|
return short_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_uri_display:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
|
|
|
|
*
|
|
|
|
|
* Gets a displayable version of the resource’s URI.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* If the resource is local, it returns a local path; if the
|
|
|
|
|
* resource is not local, it returns the UTF-8 encoded content
|
|
|
|
|
* of [method@Gtk.RecentInfo.get_uri].
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2016-09-22 11:56:47 +00:00
|
|
|
|
* Returns: (nullable): a newly allocated UTF-8 string containing the
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* resource’s URI or %NULL. Use g_free() when done using it.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_uri_display (GtkRecentInfo *info)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *retval;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2006-11-16 11:12:12 +00:00
|
|
|
|
|
|
|
|
|
retval = NULL;
|
|
|
|
|
if (gtk_recent_info_is_local (info))
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *filename;
|
2006-11-16 11:12:12 +00:00
|
|
|
|
|
|
|
|
|
filename = g_filename_from_uri (info->uri, NULL, NULL);
|
|
|
|
|
if (!filename)
|
|
|
|
|
return NULL;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-11-16 11:12:12 +00:00
|
|
|
|
retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
|
|
|
|
g_free (filename);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
retval = make_valid_utf8 (info->uri);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-11-16 11:12:12 +00:00
|
|
|
|
return retval;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_age:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Gets the number of days elapsed since the last update
|
|
|
|
|
* of the resource pointed by @info.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: a positive integer containing the number of days
|
|
|
|
|
* elapsed since the time this resource was last modified
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_age (GtkRecentInfo *info)
|
|
|
|
|
{
|
2020-07-31 16:08:41 +00:00
|
|
|
|
GDateTime *now;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, -1);
|
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
now = g_date_time_new_now_utc ();
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-31 16:08:41 +00:00
|
|
|
|
return (int) (g_date_time_difference (now, info->modified) / (double)G_TIME_SPAN_DAY);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_get_groups:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2009-12-10 10:23:40 +00:00
|
|
|
|
* @length: (out) (allow-none): return location for the number of groups returned
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns all groups registered for the recently used item @info.
|
2021-03-02 03:52:30 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* The array of returned group names will be %NULL terminated, so
|
|
|
|
|
* length might optionally be %NULL.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: (array length=length zero-terminated=1) (transfer full):
|
|
|
|
|
* a newly allocated %NULL terminated array of strings.
|
|
|
|
|
* Use g_strfreev() to free it.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char **
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_recent_info_get_groups (GtkRecentInfo *info,
|
2014-12-22 22:16:30 +00:00
|
|
|
|
gsize *length)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char **retval;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gsize n_groups, i;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
if (!info->groups || info->n_groups == 0)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (length)
|
|
|
|
|
*length = 0;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
n_groups = info->n_groups;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
retval = g_new0 (char *, n_groups + 1);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
for (i = 0; i < info->n_groups; i ++)
|
|
|
|
|
retval[i] = g_strdup (info->groups[i]);
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
retval[i] = NULL;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (length)
|
2019-08-30 06:26:25 +00:00
|
|
|
|
*length = info->n_groups;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_has_group:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* @group_name: name of a group
|
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Checks whether @group_name appears inside the groups
|
|
|
|
|
* registered for the recently used item @info.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
2014-12-22 22:16:30 +00:00
|
|
|
|
* Returns: %TRUE if the group was found
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_recent_info_has_group (GtkRecentInfo *info,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *group_name)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2019-08-30 06:26:25 +00:00
|
|
|
|
int i;
|
2014-12-22 22:16:30 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (group_name != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
if (!info->groups)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2019-08-30 06:26:25 +00:00
|
|
|
|
for (i = 0; i < info->n_groups; i ++)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2019-08-30 06:26:25 +00:00
|
|
|
|
const char *g = info->groups[i];
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (strcmp (g, group_name) == 0)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-22 10:42:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_info_create_app_info:
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* @info: a `GtkRecentInfo`
|
2010-10-22 10:42:39 +00:00
|
|
|
|
* @app_name: (allow-none): the name of the application that should
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* be mapped to a `GAppInfo`; if %NULL is used then the default
|
2010-10-22 10:42:39 +00:00
|
|
|
|
* application for the MIME type is used
|
|
|
|
|
* @error: (allow-none): return location for a #GError, or %NULL
|
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Creates a `GAppInfo` for the specified `GtkRecentInfo`
|
2010-10-22 10:42:39 +00:00
|
|
|
|
*
|
2021-03-02 03:52:30 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): the newly created `GAppInfo`,
|
|
|
|
|
* or %NULL. In case of error, @error will be set either with a
|
2010-10-22 10:42:39 +00:00
|
|
|
|
* %GTK_RECENT_MANAGER_ERROR or a %G_IO_ERROR
|
|
|
|
|
*/
|
|
|
|
|
GAppInfo *
|
|
|
|
|
gtk_recent_info_create_app_info (GtkRecentInfo *info,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *app_name,
|
2010-10-22 10:42:39 +00:00
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
RecentAppInfo *ai;
|
|
|
|
|
GAppInfo *app_info;
|
|
|
|
|
GError *internal_error = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (app_name == NULL || *app_name == '\0')
|
|
|
|
|
{
|
|
|
|
|
char *content_type;
|
|
|
|
|
|
|
|
|
|
if (info->mime_type == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
content_type = g_content_type_from_mime_type (info->mime_type);
|
|
|
|
|
if (content_type == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
app_info = g_app_info_get_default_for_type (content_type, TRUE);
|
|
|
|
|
g_free (content_type);
|
|
|
|
|
|
|
|
|
|
return app_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ai = g_hash_table_lookup (info->apps_lookup, app_name);
|
|
|
|
|
if (ai == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error, GTK_RECENT_MANAGER_ERROR,
|
|
|
|
|
GTK_RECENT_MANAGER_ERROR_NOT_REGISTERED,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("No registered application with name “%s” for item with URI “%s” found"),
|
2010-10-22 10:42:39 +00:00
|
|
|
|
app_name,
|
|
|
|
|
info->uri);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal_error = NULL;
|
|
|
|
|
app_info = g_app_info_create_from_commandline (ai->exec, ai->name,
|
|
|
|
|
G_APP_INFO_CREATE_NONE,
|
|
|
|
|
&internal_error);
|
|
|
|
|
if (internal_error != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_propagate_error (error, internal_error);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return app_info;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-19 10:29:55 +00:00
|
|
|
|
/*
|
|
|
|
|
* _gtk_recent_manager_sync:
|
2014-12-22 22:16:30 +00:00
|
|
|
|
*
|
2007-06-19 10:29:55 +00:00
|
|
|
|
* Private function for synchronising the recent manager singleton.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
_gtk_recent_manager_sync (void)
|
|
|
|
|
{
|
|
|
|
|
if (recent_manager_singleton)
|
|
|
|
|
{
|
|
|
|
|
/* force a dump of the contents of the recent manager singleton */
|
|
|
|
|
recent_manager_singleton->priv->is_dirty = TRUE;
|
|
|
|
|
gtk_recent_manager_real_changed (recent_manager_singleton);
|
|
|
|
|
}
|
|
|
|
|
}
|