* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkrecentchooser.h"
#include "gtkrecentchooserprivate.h"
#include "gtkrecentmanager.h"
+#include "gtkrecentaction.h"
+#include "gtkactivatable.h"
#include "gtkintl.h"
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
#include "gtkmarshalers.h"
-#include "gtkalias.h"
+
+/**
+ * SECTION:gtkrecentchooser
+ * @Short_description: Interface implemented by widgets displaying recently
+ * used files
+ * @Title: GtkRecentChooser
+ * @See_also: #GtkRecentManager, #GtkRecentChooserDialog,
+ * #GtkRecentChooserWidget, #GtkRecentChooserMenu
+ *
+ * #GtkRecentChooser is an interface that can be implemented by widgets
+ * displaying the list of recently used files. In GTK+, the main objects
+ * that implement this interface are #GtkRecentChooserWidget,
+ * #GtkRecentChooserDialog and #GtkRecentChooserMenu.
+ *
+ * Recently used files are supported since GTK+ 2.10.
+ */
enum
LAST_SIGNAL
};
-static void gtk_recent_chooser_class_init (gpointer g_iface);
+static gboolean recent_chooser_has_show_numbers (GtkRecentChooser *chooser);
+
+static GQuark quark_gtk_related_action = 0;
+static GQuark quark_gtk_use_action_appearance = 0;
+static const gchar gtk_related_action_key[] = "gtk-related-action";
+static const gchar gtk_use_action_appearance_key[] = "gtk-use-action-appearance";
+
static guint chooser_signals[LAST_SIGNAL] = { 0, };
-GType
-gtk_recent_chooser_get_type (void)
-{
- static GType chooser_type = 0;
-
- if (!chooser_type)
- {
- static const GTypeInfo chooser_info =
- {
- sizeof (GtkRecentChooserIface),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_recent_chooser_class_init,
- };
-
- chooser_type = g_type_register_static (G_TYPE_INTERFACE,
- I_("GtkRecentChooser"),
- &chooser_info, 0);
-
- g_type_interface_add_prerequisite (chooser_type, GTK_TYPE_OBJECT);
- }
-
- return chooser_type;
-}
+
+typedef GtkRecentChooserIface GtkRecentChooserInterface;
+G_DEFINE_INTERFACE (GtkRecentChooser, gtk_recent_chooser, G_TYPE_OBJECT);
+
static void
-gtk_recent_chooser_class_init (gpointer g_iface)
+gtk_recent_chooser_default_init (GtkRecentChooserInterface *iface)
{
- GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
+ GType iface_type = G_TYPE_FROM_INTERFACE (iface);
+
+ quark_gtk_related_action = g_quark_from_static_string (gtk_related_action_key);
+ quark_gtk_use_action_appearance = g_quark_from_static_string (gtk_use_action_appearance_key);
/**
- * GtkRecentChooser::selection-changed
+ * GtkRecentChooser::selection-changed:
* @chooser: the object which received the signal
*
* This signal is emitted when there is a change in the set of
G_TYPE_NONE, 0);
/**
- * GtkRecentChooser::item-activated
+ * GtkRecentChooser::item-activated:
* @chooser: the object which received the signal
*
* This signal is emitted when the user "activates" a recent item
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
-
- g_object_interface_install_property (g_iface,
+
+ /**
+ * GtkRecentChooser:recent-manager:
+ *
+ * The #GtkRecentManager instance used by the #GtkRecentChooser to
+ * display the list of recently used resources.
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_object ("recent-manager",
P_("Recent Manager"),
P_("The RecentManager object to use"),
GTK_TYPE_RECENT_MANAGER,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
- g_object_interface_install_property (g_iface,
+ GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+ /**
+ * GtkRecentManager:show-private:
+ *
+ * Whether this #GtkRecentChooser should display recently used resources
+ * marked with the "private" flag. Such resources should be considered
+ * private to the applications and groups that have added them.
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_boolean ("show-private",
P_("Show Private"),
P_("Whether the private items should be displayed"),
FALSE,
- G_PARAM_READWRITE));
- g_object_interface_install_property (g_iface,
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkRecentChooser:show-tips:
+ *
+ * Whether this #GtkRecentChooser should display a tooltip containing the
+ * full path of the recently used resources.
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_boolean ("show-tips",
P_("Show Tooltips"),
P_("Whether there should be a tooltip on the item"),
FALSE,
- G_PARAM_READWRITE));
- g_object_interface_install_property (g_iface,
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkRecentChooser:show-icons:
+ *
+ * Whether this #GtkRecentChooser should display an icon near the item.
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_boolean ("show-icons",
P_("Show Icons"),
P_("Whether there should be an icon near the item"),
TRUE,
- G_PARAM_READWRITE));
- g_object_interface_install_property (g_iface,
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkRecentChooser:show-not-found:
+ *
+ * Whether this #GtkRecentChooser should display the recently used resources
+ * even if not present anymore. Setting this to %FALSE will perform a
+ * potentially expensive check on every local resource (every remote
+ * resource will always be displayed).
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_boolean ("show-not-found",
P_("Show Not Found"),
P_("Whether the items pointing to unavailable resources should be displayed"),
- FALSE,
- G_PARAM_READWRITE));
- g_object_interface_install_property (g_iface,
+ TRUE,
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkRecentChooser:select-multiple:
+ *
+ * Allow the user to select multiple resources.
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_boolean ("select-multiple",
P_("Select Multiple"),
P_("Whether to allow multiple items to be selected"),
FALSE,
- G_PARAM_READWRITE));
- g_object_interface_install_property (g_iface,
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkRecentChooser:local-only:
+ *
+ * Whether this #GtkRecentChooser should display only local (file:)
+ * resources.
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_boolean ("local-only",
P_("Local only"),
P_("Whether the selected resource(s) should be limited to local file: URIs"),
TRUE,
- G_PARAM_READWRITE));
- g_object_interface_install_property (g_iface,
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkRecentChooser:limit:
+ *
+ * The maximum number of recently used resources to be displayed,
+ * or -1 to display all items. By default, the
+ * GtkSetting:gtk-recent-files-limit setting is respected: you can
+ * override that limit on a particular instance of #GtkRecentChooser
+ * by setting this property.
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_int ("limit",
P_("Limit"),
P_("The maximum number of items to be displayed"),
-1,
G_MAXINT,
-1,
- G_PARAM_READWRITE));
- g_object_interface_install_property (g_iface,
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkRecentChooser:sort-type:
+ *
+ * Sorting order to be used when displaying the recently used resources.
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_enum ("sort-type",
P_("Sort Type"),
P_("The sorting order of the items displayed"),
GTK_TYPE_RECENT_SORT_TYPE,
GTK_RECENT_SORT_NONE,
- G_PARAM_READWRITE));
- g_object_interface_install_property (g_iface,
+ GTK_PARAM_READWRITE));
+ /**
+ * GtkRecentChooser:filter:
+ *
+ * The #GtkRecentFilter object to be used when displaying
+ * the recently used resources.
+ *
+ * Since: 2.10
+ */
+ g_object_interface_install_property (iface,
g_param_spec_object ("filter",
P_("Filter"),
P_("The current filter for selecting which resources are displayed"),
GTK_TYPE_RECENT_FILTER,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
}
GQuark
gtk_recent_chooser_error_quark (void)
{
- static GQuark error_quark = 0;
- if (!error_quark)
- error_quark = g_quark_from_static_string ("gtk-recent-chooser-error-quark");
- return error_quark;
+ return g_quark_from_static_string ("gtk-recent-chooser-error-quark");
}
/**
* @chooser: a #GtkRecentChooser
* @show_tips: %TRUE if tooltips should be shown
*
- * Sets whether to show a tooltips on the widget.
+ * Sets whether to show a tooltips containing the full path of each
+ * recently used resource in a #GtkRecentChooser widget.
*
* Since: 2.10
*/
* gtk_recent_chooser_get_show_tips:
* @chooser: a #GtkRecentChooser
*
- * Gets whether @chooser should display tooltips.
+ * Gets whether @chooser should display tooltips containing the full path
+ * of a recently user resource.
*
* Return value: %TRUE if the recent chooser should show tooltips,
* %FALSE otherwise.
return show_tips;
}
-/**
- * gtk_recent_chooser_set_show_numbers:
- * @chooser: a #GtkRecentChooser
- * @show_private: %TRUE to show numbers, %FALSE otherwise
- *
- * Whether to show recently used resources prepended by a unique number.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_show_numbers (GtkRecentChooser *chooser,
- gboolean show_numbers)
+static gboolean
+recent_chooser_has_show_numbers (GtkRecentChooser *chooser)
{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
+ GParamSpec *pspec;
- g_object_set (chooser, "show-numbers", show_numbers, NULL);
-}
+ /* This is the result of a minor screw up: the "show-numbers" property
+ * was removed from the GtkRecentChooser interface, but the accessors
+ * remained in the interface API; now we need to check whether the
+ * implementation of the RecentChooser interface has a "show-numbers"
+ * boolean property installed before accessing it, and avoid an
+ * assertion failure using a more graceful warning. This should really
+ * go away as soon as we can break API and remove these accessors.
+ */
+ pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (chooser),
+ "show-numbers");
-/**
- * gtk_recent_chooser_get_show_numbers:
- * @chooser: a #GtkRecentChooser
- *
- * Returns whether @chooser should display recently used resources
- * prepended by a unique number.
- *
- * Return value: %TRUE if the recent chooser should show display numbers,
- * %FALSE otherwise.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_get_show_numbers (GtkRecentChooser *chooser)
-{
- gboolean show_numbers;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
-
- g_object_get (chooser, "show-numbers", &show_numbers, NULL);
-
- return show_numbers;
+ return (pspec && pspec->value_type == G_TYPE_BOOLEAN);
}
-
/**
* gtk_recent_chooser_set_sort_type:
* @chooser: a #GtkRecentChooser
* gtk_recent_chooser_set_sort_func:
* @chooser: a #GtkRecentChooser
* @sort_func: the comparison function
- * @sort_data: user data to pass to @sort_func, or %NULL
- * @destroy_data: destroy notifier for @sort_data, or %NULL
+ * @sort_data: (allow-none): user data to pass to @sort_func, or %NULL
+ * @data_destroy: (allow-none): destroy notifier for @sort_data, or %NULL
*
* Sets the comparison function used when sorting to be @sort_func. If
* the @chooser has the sort type set to #GTK_RECENT_SORT_CUSTOM then
* gtk_recent_chooser_set_current_uri:
* @chooser: a #GtkRecentChooser
* @uri: a URI
- * @error: return location for a #GError, or %NULL
+ * @error: (allow-none): return location for a #GError, or %NULL
*
* Sets @uri as the current URI for @chooser.
*
* gtk_recent_chooser_select_uri:
* @chooser: a #GtkRecentChooser
* @uri: a URI
- * @error: return location for a #GError, or %NULL
+ * @error: (allow-none): return location for a #GError, or %NULL
*
* Selects @uri inside @chooser.
*
* The return value of this function is affected by the "sort-type" and
* "limit" properties of @chooser.
*
- * Return value: A newly allocated list of #GtkRecentInfo objects. You should
+ * Return value: (element-type GtkRecentInfo) (transfer full): A newly allocated
+ * list of #GtkRecentInfo objects. You should
* use gtk_recent_info_unref() on every item of the list, and then free
* the list itself using g_list_free().
*
/**
* gtk_recent_chooser_get_uris:
* @chooser: a #GtkRecentChooser
- * @length: return location for a the length of the URI list, or %NULL
+ * @length: (allow-none): return location for a the length of the URI list, or %NULL
*
* Gets the URI of the recently used resources.
*
*
* Since the returned array is %NULL terminated, @length may be %NULL.
*
- * Return value: A newly allocated, %NULL terminated array of strings. Use
- * g_strfreev() to free it.
+ * Return value: (array length=length zero-terminated=1) (transfer full):
+ * A newly allocated, %NULL-terminated array of strings. Use
+ * g_strfreev() to free it.
*
* Since: 2.10
*/
gsize n_items, i;
items = gtk_recent_chooser_get_items (chooser);
- if (!items)
- return NULL;
n_items = g_list_length (items);
retval = g_new0 (gchar *, n_items + 1);
if (length)
*length = i;
- g_list_foreach (items,
- (GFunc) gtk_recent_info_unref,
- NULL);
- g_list_free (items);
+ g_list_free_full (items, (GDestroyNotify) gtk_recent_info_unref);
return retval;
}
GtkRecentFilter *filter)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
+ g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
GTK_RECENT_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
}
GtkRecentFilter *filter)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
+ g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
GTK_RECENT_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
}
*
* Gets the #GtkRecentFilter objects held by @chooser.
*
- * Return value: A singly linked list of #GtkRecentFilter objects. You
+ * Return value: (element-type GtkRecentFilter) (transfer container): A singly linked list
+ * of #GtkRecentFilter objects. You
* should just free the returned list using g_slist_free().
*
* Since: 2.10
GtkRecentFilter *filter)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
+ g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
g_object_set (G_OBJECT (chooser), "filter", filter, NULL);
}
* Gets the #GtkRecentFilter object currently used by @chooser to affect
* the display of the recently used resources.
*
- * Return value: a #GtkRecentFilter object.
+ * Return value: (transfer none): a #GtkRecentFilter object.
*
* Since: 2.10
*/
g_signal_emit (chooser, chooser_signals[SELECTION_CHANGED], 0);
}
-#define __GTK_RECENT_CHOOSER_H__
-#include "gtkaliasdef.c"
+void
+_gtk_recent_chooser_update (GtkActivatable *activatable,
+ GtkAction *action,
+ const gchar *property_name)
+{
+ GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
+ GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
+ GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
+
+ if (strcmp (property_name, "show-numbers") == 0 && recent_chooser_has_show_numbers (recent_chooser))
+ g_object_set (recent_chooser, "show-numbers",
+ gtk_recent_action_get_show_numbers (recent_action), NULL);
+ else if (strcmp (property_name, "show-private") == 0)
+ gtk_recent_chooser_set_show_private (recent_chooser, gtk_recent_chooser_get_show_private (action_chooser));
+ else if (strcmp (property_name, "show-not-found") == 0)
+ gtk_recent_chooser_set_show_not_found (recent_chooser, gtk_recent_chooser_get_show_not_found (action_chooser));
+ else if (strcmp (property_name, "show-tips") == 0)
+ gtk_recent_chooser_set_show_tips (recent_chooser, gtk_recent_chooser_get_show_tips (action_chooser));
+ else if (strcmp (property_name, "show-icons") == 0)
+ gtk_recent_chooser_set_show_icons (recent_chooser, gtk_recent_chooser_get_show_icons (action_chooser));
+ else if (strcmp (property_name, "limit") == 0)
+ gtk_recent_chooser_set_limit (recent_chooser, gtk_recent_chooser_get_limit (action_chooser));
+ else if (strcmp (property_name, "local-only") == 0)
+ gtk_recent_chooser_set_local_only (recent_chooser, gtk_recent_chooser_get_local_only (action_chooser));
+ else if (strcmp (property_name, "sort-type") == 0)
+ gtk_recent_chooser_set_sort_type (recent_chooser, gtk_recent_chooser_get_sort_type (action_chooser));
+ else if (strcmp (property_name, "filter") == 0)
+ gtk_recent_chooser_set_filter (recent_chooser, gtk_recent_chooser_get_filter (action_chooser));
+}
+
+void
+_gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
+ GtkAction *action)
+{
+ GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
+ GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
+
+ if (!action)
+ return;
+
+ if (recent_chooser_has_show_numbers (recent_chooser))
+ g_object_set (recent_chooser, "show-numbers",
+ gtk_recent_action_get_show_numbers (GTK_RECENT_ACTION (action)),
+ NULL);
+ gtk_recent_chooser_set_show_private (recent_chooser, gtk_recent_chooser_get_show_private (action_chooser));
+ gtk_recent_chooser_set_show_not_found (recent_chooser, gtk_recent_chooser_get_show_not_found (action_chooser));
+ gtk_recent_chooser_set_show_tips (recent_chooser, gtk_recent_chooser_get_show_tips (action_chooser));
+ gtk_recent_chooser_set_show_icons (recent_chooser, gtk_recent_chooser_get_show_icons (action_chooser));
+ gtk_recent_chooser_set_limit (recent_chooser, gtk_recent_chooser_get_limit (action_chooser));
+ gtk_recent_chooser_set_local_only (recent_chooser, gtk_recent_chooser_get_local_only (action_chooser));
+ gtk_recent_chooser_set_sort_type (recent_chooser, gtk_recent_chooser_get_sort_type (action_chooser));
+ gtk_recent_chooser_set_filter (recent_chooser, gtk_recent_chooser_get_filter (action_chooser));
+}
+
+void
+_gtk_recent_chooser_set_related_action (GtkRecentChooser *recent_chooser,
+ GtkAction *action)
+{
+ GtkAction *prev_action;
+
+ prev_action = g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
+
+ if (prev_action == action)
+ return;
+
+ gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (recent_chooser), action);
+ g_object_set_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action, action);
+}
+
+GtkAction *
+_gtk_recent_chooser_get_related_action (GtkRecentChooser *recent_chooser)
+{
+ return g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
+}
+
+/* The default for use-action-appearance is TRUE, so we try to set the
+ * qdata backwards for this case.
+ */
+void
+_gtk_recent_chooser_set_use_action_appearance (GtkRecentChooser *recent_chooser,
+ gboolean use_appearance)
+{
+ GtkAction *action;
+ gboolean use_action_appearance;
+
+ action = g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
+ use_action_appearance = !GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance));
+
+ if (use_action_appearance != use_appearance)
+ {
+
+ g_object_set_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance, GINT_TO_POINTER (!use_appearance));
+
+ gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (recent_chooser), action);
+ }
+}
+
+gboolean
+_gtk_recent_chooser_get_use_action_appearance (GtkRecentChooser *recent_chooser)
+{
+ return !GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance));
+}