talkatu/talkatu

f3a71aa833cd
Parents 753aa6a080dd
Children f2ee37b685d6
Handle the TalkatuAttachmentDialog reponse
--- a/talkatu/talkatuview.c Sat Jan 25 15:33:51 2020 -0600
+++ b/talkatu/talkatuview.c Sat Jan 25 15:35:26 2020 -0600
@@ -278,6 +278,44 @@
}
static void
+talkaktu_view_attachment_response_cb(GtkDialog *dialog, gint response,
+ gpointer data)
+{
+ /* If the user hit's escape response is GTK_RESPONSE_DELETE_EVENT and
+ * Gtk cleans up the dialog for us automatically.
+ */
+
+ if(response == GTK_RESPONSE_CANCEL) {
+ /* we call this separately for GTK_RESPONSE_CANCEL be
+ * GTK_RESPONSE_DELETE_EVENT already destroys the dialog.
+ */
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+ } else if(response == GTK_RESPONSE_ACCEPT) {
+ GtkTextBuffer *buffer = NULL;
+ TalkatuAttachment *attachment = NULL;
+ TalkatuAttachmentDialog *adialog = TALKATU_ATTACHMENT_DIALOG(dialog);
+ TalkatuView *view = TALKATU_VIEW(data);
+ const gchar *comment = NULL;
+
+ comment = talkatu_attachment_dialog_get_comment(adialog);
+
+ /* it's a pretty safe assumption that our buffer is a talkatu buffer */
+ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
+ talkatu_markup_set_html(TALKATU_BUFFER(buffer), comment, -1);
+
+ /* now send the attachment */
+ attachment = talkatu_attachment_dialog_get_attachment(adialog);
+ g_object_unref(G_OBJECT(attachment));
+
+ /* send the message */
+ talkatu_view_send_message(view);
+
+ /* kill the dialog */
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+ }
+}
+
+static void
talkatu_view_image_received_cb(GtkClipboard *clipboard, GdkPixbuf *pixbuf,
gpointer data)
{
@@ -293,6 +331,8 @@
attachment = talkatu_attachment_new_from_pixbuf("unknown.png", pixbuf);
dialog = talkatu_attachment_dialog_new(attachment, comment);
+ g_signal_connect(G_OBJECT(dialog), "response",
+ G_CALLBACK(talkaktu_view_attachment_response_cb), view);
gtk_widget_show_all(dialog);
g_free(comment);
@@ -641,7 +681,7 @@
/**
* TalkatuView::send-message:
- * @talkatutextview: The #TalkatuView instance.
+ * @talkatuview: The #TalkatuView instance.
* @user_data: User supplied data.
*
* Emitted when a message should be sent.