talkatu/talkatu

Parents 14150e2ef19b
Children 1736f120213a
Replace the insert-image action with attach-file, add it to html and markdown buffer, and display dialogs up to the point where we can right now.
--- a/talkatu/data/toolbar.ui Thu May 07 21:27:14 2020 -0500
+++ b/talkatu/data/toolbar.ui Thu May 07 21:32:25 2020 -0500
@@ -127,20 +127,6 @@
</packing>
</child>
<child>
- <object class="GtkToolButton" id="insert_image">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="action_name">talkatu.insert-image</property>
- <property name="label" translatable="yes">Insert Image</property>
- <property name="use_underline">True</property>
- <property name="icon_name">insert-image</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="homogeneous">True</property>
- </packing>
- </child>
- <child>
<object class="GtkToggleToolButton" id="insert_link">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -158,8 +144,8 @@
<object class="GtkToolButton" id="insert_file">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="action_name">talkatu.insert-file</property>
- <property name="label" translatable="yes">Insert File</property>
+ <property name="action_name">talkatu.attach-file</property>
+ <property name="label" translatable="yes">Attach File</property>
<property name="icon_name">insert-object</property>
</object>
<packing>
--- a/talkatu/talkatuactiongroup.c Thu May 07 21:27:14 2020 -0500
+++ b/talkatu/talkatuactiongroup.c Thu May 07 21:32:25 2020 -0500
@@ -18,6 +18,8 @@
#include <glib/gi18n-lib.h>
#include "talkatu/talkatuactiongroup.h"
+#include "talkatu/talkatuattachment.h"
+#include "talkatu/talkatuattachmentdialog.h"
#include "talkatu/talkatubuffer.h"
#include "talkatu/talkatulinkdialog.h"
#include "talkatu/talkatutag.h"
@@ -96,6 +98,12 @@
*/
/**
+ * TALKATU_ACTION_ATTACH_FILE:
+ *
+ * A constant that represents the attach file action.
+ */
+
+/**
* TALKATU_ACTION_INSERT_LINK:
*
* A constant that presents the action to activate when the user wants to
@@ -345,6 +353,73 @@
}
static void
+talkatu_action_attach_file_attach_response_cb(GtkDialog *dialog, gint response,
+ gpointer data)
+{
+ if(response == GTK_RESPONSE_CANCEL) {
+ /* we call this separately for GTK_RESPONSE_CANCEL becase
+ * GTK_RESPONSE_DELETE_EVENT already destroys the dialog.
+ */
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+ } else if(response == GTK_RESPONSE_ACCEPT) {
+ /* implement me */
+
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+ }
+}
+
+static void
+talkatu_action_attach_file_response_cb(GtkDialog *dialog, gint response,
+ gpointer data)
+{
+ if(response == GTK_RESPONSE_CANCEL) {
+ /* we call this separately for GTK_RESPONSE_CANCEL becase
+ * GTK_RESPONSE_DELETE_EVENT already destroys the dialog.
+ */
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+ } else if(response == GTK_RESPONSE_ACCEPT) {
+ TalkatuAttachment *attachment = NULL;
+ GtkWidget *attach_dialog = NULL;
+ gchar *filename = NULL, *content_type = NULL;
+
+ filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ content_type = g_content_type_guess(filename, NULL, 0, NULL);
+
+ attachment = talkatu_attachment_new(G_GUINT64_CONSTANT(0), content_type);
+ g_free(content_type);
+
+ talkatu_attachment_set_local_uri(attachment, filename);
+ g_free(filename);
+
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+
+ attach_dialog = talkatu_attachment_dialog_new(attachment, "");
+ g_signal_connect(G_OBJECT(attach_dialog), "response",
+ G_CALLBACK(talkatu_action_attach_file_attach_response_cb),
+ data);
+ gtk_widget_show_all(attach_dialog);
+ }
+}
+
+static void
+talkatu_action_attach_file(GSimpleAction *action, GVariant *parameter,
+ gpointer data)
+{
+ GtkWidget *dialog = NULL;
+
+ dialog = gtk_file_chooser_dialog_new(_("Attach file..."),
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ _("Cancel"), GTK_RESPONSE_CANCEL,
+ _("Open"), GTK_RESPONSE_ACCEPT,
+ NULL);
+ g_signal_connect(G_OBJECT(dialog), "response",
+ G_CALLBACK(talkatu_action_attach_file_response_cb),
+ data);
+ gtk_widget_show_all(dialog);
+}
+
+static void
talkatu_action_insert_link(GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
@@ -486,6 +561,9 @@
.name = TALKATU_ACTION_FORMAT_RESET,
.activate = talkatu_action_reset_activate,
}, {
+ .name = TALKATU_ACTION_ATTACH_FILE,
+ .activate = talkatu_action_attach_file,
+ }, {
.name = TALKATU_ACTION_INSERT_LINK,
.activate = talkatu_action_insert_link,
.state = "false",
--- a/talkatu/talkatuactiongroup.h Thu May 07 21:27:14 2020 -0500
+++ b/talkatu/talkatuactiongroup.h Thu May 07 21:32:25 2020 -0500
@@ -34,6 +34,8 @@
#define TALKATU_ACTION_FORMAT_SHRINK ("format-shrink")
#define TALKATU_ACTION_FORMAT_RESET ("format-reset")
+#define TALKATU_ACTION_ATTACH_FILE ("attach-file")
+
#define TALKATU_ACTION_INSERT_LINK ("insert-link")
G_BEGIN_DECLS
--- a/talkatu/talkatuhtmlbuffer.c Thu May 07 21:27:14 2020 -0500
+++ b/talkatu/talkatuhtmlbuffer.c Thu May 07 21:32:25 2020 -0500
@@ -69,6 +69,7 @@
talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_FORMAT_SHRINK);
talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_FORMAT_GROW);
talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_FORMAT_RESET);
+ talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_ATTACH_FILE);
talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_INSERT_LINK);
return ag;
--- a/talkatu/talkatumarkdownbuffer.c Thu May 07 21:27:14 2020 -0500
+++ b/talkatu/talkatumarkdownbuffer.c Thu May 07 21:32:25 2020 -0500
@@ -274,6 +274,7 @@
talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_FORMAT_UNDERLINE);
talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_FORMAT_STRIKETHROUGH);
talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_FORMAT_RESET);
+ talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_ATTACH_FILE);
talkatu_action_group_enable_action(TALKATU_ACTION_GROUP(ag), TALKATU_ACTION_INSERT_LINK);
return ag;