/** * 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); } } }
/** * g_paste_clipboard_set_text: * @self: a GPasteClipboard instance * * Put the text from the intern GtkClipboard in the GPasteClipboard * * Returns: The new text if it was modified, or NULL */ G_PASTE_VISIBLE const gchar * g_paste_clipboard_set_text (GPasteClipboard *self) { g_return_val_if_fail (G_PASTE_IS_CLIPBOARD (self), NULL); GPasteClipboardPrivate *priv = self->priv; gchar *text = gtk_clipboard_wait_for_text (priv->real); if (!text) return NULL; GPasteSettings *settings = priv->settings; gchar *stripped = g_strstrip (g_strdup (text)); gboolean trim_items = g_paste_settings_get_trim_items (settings); const gchar *to_add = trim_items ? stripped : text; const gchar *ret = NULL; guint length = strlen (to_add); if (length < g_paste_settings_get_min_text_item_size (settings) || length > g_paste_settings_get_max_text_item_size (settings) || strlen (stripped) == 0 || (priv->text && g_strcmp0 (priv->text, to_add) == 0)) goto ignore; if (trim_items && priv->target == GDK_SELECTION_CLIPBOARD && g_strcmp0 (text, stripped) != 0) g_paste_clipboard_select_text (self, stripped); else _g_paste_clipboard_set_text (self, to_add); ret = priv->text; ignore: g_free (stripped); g_free (text); return ret; }