/**
 * g_paste_clipboard_select_item:
 * @self: a #GPasteClipboard instance
 * @item: the item to select
 *
 * Put the value of the item into the #GPasteClipbaord and the intern GtkClipboard
 *
 * Returns:
 */
G_PASTE_VISIBLE void
g_paste_clipboard_select_item (GPasteClipboard  *self,
                               const GPasteItem *item)
{
    g_return_if_fail (G_PASTE_IS_CLIPBOARD (self));
    g_return_if_fail (G_PASTE_IS_ITEM (item));

    if (G_PASTE_IS_IMAGE_ITEM (item))
    {
        GPasteImageItem *image_item = G_PASTE_IMAGE_ITEM (item);
        const gchar *checksum = g_paste_image_item_get_checksum (image_item);

        if (g_strcmp0 (checksum, self->priv->image_checksum) != 0)
            _g_paste_clipboard_select_image (self,
                                             g_paste_image_item_get_image (image_item),
                                             checksum);
    }
    else
    {
        const gchar *text = g_paste_item_get_value (item);

        if (g_strcmp0 (text, self->priv->text) != 0)
        {
            if (G_PASTE_IS_URIS_ITEM (item))
                _g_paste_clipboard_select_uris (self, G_PASTE_URIS_ITEM (item));
            else /* if (G_PASTE_IS_TEXT_ITEM (item)) */
                g_paste_clipboard_select_text (self, text);
        }
    }
}
Beispiel #2
0
static void
g_paste_clipboard_clear_clipboard_data (GtkClipboard *clipboard G_GNUC_UNUSED,
                                        gpointer      user_data_or_owner G_GNUC_UNUSED)
{
}

static void
g_paste_clipboard_get_clipboard_data (GtkClipboard     *clipboard G_GNUC_UNUSED,
                                      GtkSelectionData *selection_data,
                                      guint             info G_GNUC_UNUSED,
                                      gpointer          user_data_or_owner)
{
    g_return_if_fail (G_PASTE_IS_URIS_ITEM (user_data_or_owner));

    GPasteUrisItem *item = G_PASTE_URIS_ITEM (user_data_or_owner);

    GdkAtom targets[1] = { gtk_selection_data_get_target (selection_data) };

    /* The content is requested as text */
    if (gtk_targets_include_text (targets, 1))
        gtk_selection_data_set_text (selection_data, g_paste_item_get_value (G_PASTE_ITEM (item)), -1);
    /* The content is requested as uris */
    else if (gtk_targets_include_uri (targets, 1))
        gtk_selection_data_set_uris (selection_data, (gchar **) g_paste_uris_item_get_uris (item));
    /* The content is requested as special gnome-copied-files by nautilus */
    else
    {
        GString *copy_string = g_string_new ("copy");
        const gchar * const *uris = g_paste_uris_item_get_uris (item);
        guint length = g_strv_length ((gchar **) uris);