Add a new TalkatuAttachmentPreview widget
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/data/attachmentpreview.ui Wed Feb 05 00:24:08 2020 -0600
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> + <requires lib="gtk+" version="3.20"/> + <template class="TalkatuAttachmentPreview" parent="GtkInfoBar"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child internal-child="action_area"> + <object class="GtkButtonBox"> + <property name="can_focus">False</property> + <property name="spacing">6</property> + <property name="layout_style">end</property> + <object class="GtkButton"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="relief">none</property> + <signal name="clicked" handler="talkatu_attachment_preview_download_cb" object="TalkatuAttachmentPreview" swapped="no"/> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="icon_name">document-save-symbolic</property> + <property name="icon_size">5</property> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + <property name="non_homogeneous">True</property> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + <child internal-child="content_area"> + <object class="GtkBox"> + <property name="can_focus">False</property> + <property name="spacing">16</property> + <object class="GtkImage" id="preview"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="icon_name">text-x-generic</property> + <property name="icon_size">6</property> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <object class="GtkLabel" id="filename"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">unknown</property> + <property name="xalign">0</property> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + <object class="GtkLabel" id="filesize"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> --- a/talkatu/data/talkatu.gresource.xml Tue Feb 04 22:32:19 2020 -0600
+++ b/talkatu/data/talkatu.gresource.xml Wed Feb 05 00:24:08 2020 -0600
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresource prefix="/org/bitbucket/pidgin/talkatu/ui">
- <file compressed="true">attachmentdialog.ui</file>
- <file compressed="true">editor.ui</file>
- <file compressed="true">linkdialog.ui</file>
- <file compressed="true">messageactions.ui</file>
+ <file compressed="true">attachmentdialog.ui</file> + <file compressed="true">attachmentpreview.ui</file> + <file compressed="true">editor.ui</file> + <file compressed="true">linkdialog.ui</file> + <file compressed="true">messageactions.ui</file> <file compressed="true">toolbar.ui</file>
--- a/talkatu/meson.build Tue Feb 04 22:32:19 2020 -0600
+++ b/talkatu/meson.build Wed Feb 05 00:24:08 2020 -0600
@@ -7,6 +7,7 @@
'talkatuattachmentdialog.h',
+ 'talkatuattachmentpreview.h', @@ -34,6 +35,7 @@
'talkatuattachmentdialog.c',
+ 'talkatuattachmentpreview.c', --- a/talkatu/reference/talkatu-docs.xml Tue Feb 04 22:32:19 2020 -0600
+++ b/talkatu/reference/talkatu-docs.xml Wed Feb 05 00:24:08 2020 -0600
@@ -54,6 +54,8 @@
<xi:include href="xml/talkatuattachment.xml"/>
<xi:include href="xml/talkatuattachmentdialog.xml"/>
+ <xi:include href="xml/talkatuattachmentpreview.xml"/> <xi:include href="xml/talkatucore.xml"/>
<xi:include href="xml/talkatucodeset.xml"/>
<xi:include href="xml/talkatuversion.xml"/>
--- a/talkatu/talkatu.xml Tue Feb 04 22:32:19 2020 -0600
+++ b/talkatu/talkatu.xml Wed Feb 05 00:24:08 2020 -0600
@@ -10,6 +10,7 @@
<glade-widget-class name="TalkatuAttachmentDialog" generic-name="attachment_dialog" title="Attachment Dialog"/>
+ <glade-widget-class name="TalkatuAttachmentPreview" generic-name="attachment_preview" title="Attachment Preview"/> <glade-widget-class name="TalkatuHistory" generic-name="history" title="History"/>
<glade-widget-class name="TalkatuInput" generic-name="input" title="Input"/>
<glade-widget-class name="TalkatuLinkDialog" generic-name="link_dialog" title="LinkDialog"/>
@@ -52,6 +53,7 @@
<glade-widget-group name="Talkatu" title="Talkatu">
<glade-widget-class-ref name="TalkatuAttachmentDialog"/>
+ <glade-widget-class-ref name="TalkatuAttachmentPreview"/> <glade-widget-class-ref name="TalkatuBuffer"/>
<glade-widget-class-ref name="TalkatuEditor"/>
<glade-widget-class-ref name="TalkatuHistory"/>
--- a/talkatu/talkatuattachment.c Tue Feb 04 22:32:19 2020 -0600
+++ b/talkatu/talkatuattachment.c Wed Feb 05 00:24:08 2020 -0600
@@ -328,7 +328,7 @@
* Returns the content type of the attachment.
- * Returns: (transfer none): The content type of @attachment.
+ * Returns: The content type of @attachment. talkatu_attachment_get_content_type(TalkatuAttachment *attachment) {
@@ -343,7 +343,7 @@
* Returns the filename of the attachment.
- * Returns: (transfer none): The filename of @attachment.
+ * Returns: The filename of @attachment. talkatu_attachment_get_filename(TalkatuAttachment *attachment) {
@@ -353,6 +353,21 @@
+ * talkatu_attachment_get_size: + * @attachment: The #TalkatuAttachment instance. + * Gets the size of @attachment. + * Returns: The size of @attachment. +talkatu_attachment_get_size(TalkatuAttachment *attachment) { + g_return_val_if_fail(TALKATU_IS_ATTACHMENT(attachment), -1); + return g_bytes_get_size(attachment->contents); * talkatu_attachment_get_contents:
* @attachment: The #TalkatuAttachment instance.
--- a/talkatu/talkatuattachment.h Tue Feb 04 22:32:19 2020 -0600
+++ b/talkatu/talkatuattachment.h Wed Feb 05 00:24:08 2020 -0600
@@ -41,6 +41,7 @@
const gchar *talkatu_attachment_get_content_type(TalkatuAttachment *attachment);
const gchar *talkatu_attachment_get_filename(TalkatuAttachment *attachment);
+gsize talkatu_attachment_get_size(TalkatuAttachment *attachment); GBytes *talkatu_attachment_get_contents(TalkatuAttachment *attachment);
GIcon *talkatu_attachment_get_preview(TalkatuAttachment *attachment);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/talkatuattachmentpreview.c Wed Feb 05 00:24:08 2020 -0600
@@ -0,0 +1,215 @@
+ * Copyright (C) 2017-2020 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * 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, see <http://www.gnu.org/licenses/>. +#include "talkatu/talkatuattachmentpreview.h" + * SECTION:talkatuattachmentpreview + * @Title: Attachment Preview + * @Short_description: Previews for TalkatuAttachments. + * A simple widget that displays a preview of a #TalkatuAttachment. + * TALKATU_TYPE_ATTACHMENT_PREVIEW: + * The standard _get_type macro for #TalkatuAttachmentPreview. + * TalkatuAttachmentPreview: + * A #GtkWidget that displays a preview of a #TalkatuAttachment and allows the +struct _TalkatuAttachmentPreview { + TalkatuAttachment *attachment; +static GParamSpec *properties[N_PROPERTIES] = {NULL, }; +/****************************************************************************** + *****************************************************************************/ +talkatu_attachment_preview_download_cb(GtkButton *button, gpointer data) { +/****************************************************************************** + *****************************************************************************/ +talkatu_attachment_preview_set_attachment(TalkatuAttachmentPreview *preview, + TalkatuAttachment *attachment) + if(g_set_object(&preview->attachment, attachment)) { + if(TALKATU_IS_ATTACHMENT(attachment)) { + GIcon *icon = talkatu_attachment_get_preview(attachment); + gchar *filesize = NULL; + gtk_image_set_from_gicon(GTK_IMAGE(preview->preview), icon, + g_object_unref(G_OBJECT(icon)); + gtk_label_set_text(GTK_LABEL(preview->filename), + talkatu_attachment_get_filename(preview->attachment)); + filesize = g_format_size(talkatu_attachment_get_size(preview->attachment)); + gtk_label_set_text(GTK_LABEL(preview->filesize), filesize); + g_object_notify_by_pspec(G_OBJECT(preview), + properties[PROP_ATTACHMENT]); +/****************************************************************************** + * GObject Implementation + *****************************************************************************/ +G_DEFINE_TYPE(TalkatuAttachmentPreview, talkatu_attachment_preview, GTK_TYPE_INFO_BAR) +talkatu_attachment_preview_get_property(GObject *obj, guint prop_id, + GValue *value, GParamSpec *pspec) + TalkatuAttachmentPreview *preview = TALKATU_ATTACHMENT_PREVIEW(obj); + g_value_set_object(value, talkatu_attachment_preview_get_attachment(preview)); + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); +talkatu_attachment_preview_set_property(GObject *obj, guint prop_id, + const GValue *value, GParamSpec *pspec) + TalkatuAttachmentPreview *preview = TALKATU_ATTACHMENT_PREVIEW(obj); + talkatu_attachment_preview_set_attachment(preview, g_value_get_object(value)); + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); +talkatu_attachment_preview_finalize(GObject *obj) { + TalkatuAttachmentPreview *preview = TALKATU_ATTACHMENT_PREVIEW(obj); + g_clear_object(&preview->attachment); + G_OBJECT_CLASS(talkatu_attachment_preview_parent_class)->finalize(obj); +talkatu_attachment_preview_init(TalkatuAttachmentPreview *preview) { + gtk_widget_init_template(GTK_WIDGET(preview)); +talkatu_attachment_preview_class_init(TalkatuAttachmentPreviewClass *klass) { + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + obj_class->get_property = talkatu_attachment_preview_get_property; + obj_class->set_property = talkatu_attachment_preview_set_property; + obj_class->finalize = talkatu_attachment_preview_finalize; + properties[PROP_ATTACHMENT] = g_param_spec_object( + "attachment", "attachment", + "The attachment that this preview is customizing", + TALKATU_TYPE_ATTACHMENT, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties(obj_class, N_PROPERTIES, properties); + gtk_widget_class_set_template_from_resource( + "/org/bitbucket/pidgin/talkatu/ui/attachmentpreview.ui" + gtk_widget_class_bind_template_child(widget_class, TalkatuAttachmentPreview, preview); + gtk_widget_class_bind_template_child(widget_class, TalkatuAttachmentPreview, filename); + gtk_widget_class_bind_template_child(widget_class, TalkatuAttachmentPreview, filesize); + gtk_widget_class_bind_template_callback(widget_class, talkatu_attachment_preview_download_cb); +/****************************************************************************** + *****************************************************************************/ + * talkatu_attachment_preview_new: + * @attachment: The #TalkatuAttachment we're previewing. + * Creates a new #TalkatuAttachmentPreview for the given attachment. + * Returns: (transfer full): The new #TalkatuAttachmentPreview. +talkatu_attachment_preview_new(TalkatuAttachment *attachment) { + g_return_val_if_fail(TALKATU_IS_ATTACHMENT(attachment), NULL); + return GTK_WIDGET(g_object_new( + TALKATU_TYPE_ATTACHMENT_PREVIEW, + "attachment", attachment, + * talkatu_attachment_preview_get_attachment: + * @preview: The #TalkatuAttachmentPreview. + * Gets the #TalkatuAttachment from @preview. + * Returns: (transfer full): The URL that the user entered. +talkatu_attachment_preview_get_attachment(TalkatuAttachmentPreview *preview) { + g_return_val_if_fail(TALKATU_IS_ATTACHMENT_PREVIEW(preview), NULL); + return g_object_ref(preview->attachment); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/talkatu/talkatuattachmentpreview.h Wed Feb 05 00:24:08 2020 -0600
@@ -0,0 +1,44 @@
+ * Copyright (C) 2017-2020 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * 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, see <http://www.gnu.org/licenses/>. +#if !defined(TALKATU_GLOBAL_HEADER_INSIDE) && !defined(TALKATU_COMPILATION) +#error "only <talkatu.h> may be included directly" +#ifndef TALKATU_ATTACHMENT_PREVIEW_H +#define TALKATU_ATTACHMENT_PREVIEW_H +#include <glib-object.h> +#include <talkatu/talkatuattachment.h> +#define TALKATU_TYPE_ATTACHMENT_PREVIEW (talkatu_attachment_preview_get_type()) +G_DECLARE_FINAL_TYPE(TalkatuAttachmentPreview, talkatu_attachment_preview, TALKATU, ATTACHMENT_PREVIEW, GtkInfoBar) +GtkWidget *talkatu_attachment_preview_new(TalkatuAttachment *attachment); +TalkatuAttachment *talkatu_attachment_preview_get_attachment(TalkatuAttachmentPreview *preview); +#endif /* TALKATU_ATTACHMENT_PREVIEW_H */ --- a/talkatu/talkatuhistory.c Tue Feb 04 22:32:19 2020 -0600
+++ b/talkatu/talkatuhistory.c Wed Feb 05 00:24:08 2020 -0600
@@ -18,6 +18,8 @@
#include <talkatu/talkatuhistory.h>
+#include <talkatu/talkatuattachmentpreview.h> #include <talkatu/talkatuhistorybuffer.h>
#include <talkatu/talkatumessage.h>
@@ -113,14 +115,7 @@
attachment = g_object_get_data(G_OBJECT(anchor), "talkatu:attachment");
if(TALKATU_IS_ATTACHMENT(attachment)) {
- GtkWidget *preview = NULL;
- icon = talkatu_attachment_get_preview(attachment);
- preview = gtk_image_new_from_gicon(icon, GTK_ICON_SIZE_DIALOG);
- gtk_image_set_pixel_size(GTK_IMAGE(preview), 128);
+ GtkWidget *preview = talkatu_attachment_preview_new(attachment); gtk_text_view_add_child_at_anchor(view, preview, anchor);
gtk_widget_show(preview);