# HG changeset patch
# Node ID 7364f9642927
# Parent  42c7cfb1acd1
diff --git a/demo/talkatudemo.c b/demo/talkatudemo.c
--- a/demo/talkatudemo.c
+++ b/demo/talkatudemo.c
@@ -72,7 +72,7 @@ talkatu_demo_activate(GApplication *app,
 
 	win = talkatu_demo_window_new();
 	gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW(win));
-	gtk_widget_show(win);
+	gtk_window_present(GTK_WINDOW(win));
 }
 
 gint
diff --git a/demo/talkatudemowindow.c b/demo/talkatudemowindow.c
--- a/demo/talkatudemowindow.c
+++ b/demo/talkatudemowindow.c
@@ -47,6 +47,44 @@ struct _TalkatuDemoWindow {
 
 G_DEFINE_TYPE(TalkatuDemoWindow, talkatu_demo_window, GTK_TYPE_APPLICATION_WINDOW);
 
+#if GTK_CHECK_VERSION(4, 10, 0)
+static void
+talkatu_demo_window_insert_html_response_cb(GObject *obj, GAsyncResult *result,
+                                            gpointer data)
+{
+	TalkatuDemoWindow *window = TALKATU_DEMO_WINDOW(data);
+	GFile *file = NULL;
+	char *contents = NULL;
+	gsize len;
+	GError *error = NULL;
+
+	file = gtk_file_dialog_open_finish(GTK_FILE_DIALOG(obj), result, &error);
+	if(file == NULL) {
+		if(!g_error_matches(error, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_CANCELLED) &&
+		   !g_error_matches(error, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_DISMISSED)) {
+			g_warning("Failed to determine HTML file to insert: %s",
+			          error->message);
+		}
+		g_clear_error(&error);
+		return;
+	}
+
+	if(g_file_load_contents(file, NULL, &contents, &len, NULL, NULL)) {
+		GtkTextMark *mark = NULL;
+		GtkTextIter iter;
+
+		mark = gtk_text_buffer_get_insert(GTK_TEXT_BUFFER(window->buffer_html));
+		gtk_text_buffer_get_iter_at_mark(GTK_TEXT_BUFFER(window->buffer_html),
+		                                 &iter, mark);
+
+		talkatu_markup_insert_html(TALKATU_BUFFER(window->buffer_html),
+		                           &iter, contents, len);
+		g_free(contents);
+	}
+
+	g_object_unref(file);
+}
+#else
 static void
 talkatu_demo_window_insert_html_response_cb(GtkNativeDialog *dialog,
                                             gint response, gpointer data)
@@ -77,13 +115,34 @@ talkatu_demo_window_insert_html_response
 	gtk_native_dialog_destroy(dialog);
 	g_object_unref(dialog);
 }
+#endif
 
 static void
 talkatu_demo_window_insert_html_cb(G_GNUC_UNUSED GtkButton *toggle,
                                    gpointer data) {
 	TalkatuDemoWindow *window = TALKATU_DEMO_WINDOW(data);
+	GtkFileFilter *filter = NULL;
+#if GTK_CHECK_VERSION(4, 10, 0)
+	GtkFileDialog *dialog = NULL;
+	GListStore *store = NULL;
+
+	store = g_list_store_new(GTK_TYPE_FILE_FILTER);
+
+	filter = gtk_file_filter_new();
+	gtk_file_filter_set_name(filter, "HTML files");
+	gtk_file_filter_add_pattern(filter, "*.html");
+	g_list_store_append(store, filter);
+
+	dialog = gtk_file_dialog_new();
+	gtk_file_dialog_set_title(dialog, _("Insert html..."));
+	gtk_file_dialog_set_filters(dialog, G_LIST_MODEL(store));
+
+	gtk_file_dialog_open(dialog, GTK_WINDOW(window), NULL,
+	                     talkatu_demo_window_insert_html_response_cb,
+	                     window);
+
+#else
 	GtkFileChooserNative *dialog = NULL;
-	GtkFileFilter *filter = NULL;
 
 	dialog = gtk_file_chooser_native_new(
 		_("Insert html..."),
@@ -103,8 +162,48 @@ talkatu_demo_window_insert_html_cb(G_GNU
 	                 window);
 	gtk_native_dialog_set_modal(GTK_NATIVE_DIALOG(dialog), TRUE);
 	gtk_native_dialog_show(GTK_NATIVE_DIALOG(dialog));
+#endif
 }
 
+#if GTK_CHECK_VERSION(4, 10, 0)
+static void
+talkatu_demo_window_insert_markdown_response_cb(GObject *obj,
+                                                GAsyncResult *result,
+                                                gpointer data)
+{
+	TalkatuDemoWindow *window = TALKATU_DEMO_WINDOW(data);
+	GFile *file = NULL;
+	char *contents = NULL;
+	gsize len;
+	GError *error = NULL;
+
+	file = gtk_file_dialog_open_finish(GTK_FILE_DIALOG(obj), result, &error);
+	if(file == NULL) {
+		if(!g_error_matches(error, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_CANCELLED) &&
+		   !g_error_matches(error, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_DISMISSED)) {
+			g_warning("Failed to determine markdown file to insert: %s",
+			          error->message);
+		}
+		g_clear_error(&error);
+		return;
+	}
+
+	if(g_file_load_contents(file, NULL, &contents, &len, NULL, NULL)) {
+		GtkTextMark *mark = NULL;
+		GtkTextIter iter;
+
+		mark = gtk_text_buffer_get_insert(GTK_TEXT_BUFFER(window->buffer_markdown));
+		gtk_text_buffer_get_iter_at_mark(GTK_TEXT_BUFFER(window->buffer_markdown),
+		                                 &iter, mark);
+
+		talkatu_markdown_insert(TALKATU_BUFFER(window->buffer_markdown),
+		                        &iter, contents, len);
+		g_free(contents);
+	}
+
+	g_object_unref(file);
+}
+#else
 static void
 talkatu_demo_window_insert_markdown_response_cb(GtkNativeDialog *dialog,
                                                 gint response, gpointer data)
@@ -135,13 +234,33 @@ talkatu_demo_window_insert_markdown_resp
 	gtk_native_dialog_destroy(dialog);
 	g_object_unref(dialog);
 }
+#endif
 
 static void
 talkatu_demo_window_insert_markdown_cb(G_GNUC_UNUSED GtkButton *toggle,
                                        gpointer data) {
 	TalkatuDemoWindow *window = TALKATU_DEMO_WINDOW(data);
+	GtkFileFilter *filter = NULL;
+#if GTK_CHECK_VERSION(4, 10, 0)
+	GtkFileDialog *dialog = NULL;
+	GListStore *store = NULL;
+
+	store = g_list_store_new(GTK_TYPE_FILE_FILTER);
+
+	filter = gtk_file_filter_new();
+	gtk_file_filter_set_name(filter, "Markdown files");
+	gtk_file_filter_add_pattern(filter, "*.md");
+	g_list_store_append(store, filter);
+
+	dialog = gtk_file_dialog_new();
+	gtk_file_dialog_set_title(dialog, _("Insert markdown..."));
+	gtk_file_dialog_set_filters(dialog, G_LIST_MODEL(store));
+
+	gtk_file_dialog_open(dialog, GTK_WINDOW(window), NULL,
+	                     talkatu_demo_window_insert_markdown_response_cb,
+	                     window);
+#else
 	GtkFileChooserNative *dialog = NULL;
-	GtkFileFilter *filter = NULL;
 
 	dialog = gtk_file_chooser_native_new(
 		_("Insert markdown..."),
@@ -161,6 +280,7 @@ talkatu_demo_window_insert_markdown_cb(G
 	                 window);
 	gtk_native_dialog_set_modal(GTK_NATIVE_DIALOG(dialog), TRUE);
 	gtk_native_dialog_show(GTK_NATIVE_DIALOG(dialog));
+#endif
 }
 
 static void
@@ -207,7 +327,15 @@ static void
 talkatu_demo_window_view_open_url_cb(G_GNUC_UNUSED TalkatuView *view,
                                      const gchar *url, gpointer data)
 {
+#if GTK_CHECK_VERSION(4, 10, 0)
+	GtkUriLauncher *launcher = NULL;
+
+	launcher = gtk_uri_launcher_new(url);
+	gtk_uri_launcher_launch(launcher, GTK_WINDOW(data), NULL, NULL, NULL);
+	g_object_unref(launcher);
+#else
 	gtk_show_uri(GTK_WINDOW(data), url, GDK_CURRENT_TIME);
+#endif
 }
 
 static void
diff --git a/talkatu/talkatuactiongroup.c b/talkatu/talkatuactiongroup.c
--- a/talkatu/talkatuactiongroup.c
+++ b/talkatu/talkatuactiongroup.c
@@ -394,6 +394,53 @@ talkatu_action_attach_file_attach_respon
 	g_object_unref(dialog);
 }
 
+#if GTK_CHECK_VERSION(4, 10, 0)
+static void
+talkatu_action_attach_file_response_cb(GObject *obj, GAsyncResult *result,
+                                       gpointer data)
+{
+	TalkatuActionGroup *ag = TALKATU_ACTION_GROUP(data);
+	TalkatuActionGroupPrivate *priv = NULL;
+	TalkatuAttachment *attachment = NULL;
+	GtkWidget *attach_dialog = NULL;
+	char *filename = NULL, *content_type = NULL, *comment = NULL;
+	GFile *file = NULL;
+	GError *error = NULL;
+
+	file = gtk_file_dialog_open_finish(GTK_FILE_DIALOG(obj), result, &error);
+	if(file == NULL) {
+		if(!g_error_matches(error, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_CANCELLED) &&
+		   !g_error_matches(error, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_DISMISSED)) {
+			g_warning("Failed to determine file to attach: %s",
+			          error->message);
+		}
+		g_clear_error(&error);
+		return;
+	}
+
+	priv = talkatu_action_group_get_instance_private(ag);
+
+	filename = g_file_get_path(file);
+	content_type = g_content_type_guess(filename, NULL, 0, NULL);
+
+	attachment = talkatu_simple_attachment_new(G_GUINT64_CONSTANT(0),
+	                                           content_type);
+	g_free(content_type);
+
+	talkatu_attachment_set_local_uri(attachment, filename);
+	g_free(filename);
+	g_object_unref(file);
+
+	comment = talkatu_markup_get_html(priv->buffer, NULL);
+	attach_dialog = talkatu_attachment_dialog_new(attachment, comment);
+	g_free(comment);
+
+	g_signal_connect(G_OBJECT(attach_dialog), "response",
+	                 G_CALLBACK(talkatu_action_attach_file_attach_response_cb),
+	                 data);
+	gtk_window_present(GTK_WINDOW(attach_dialog));
+}
+#else
 static void
 talkatu_action_attach_file_response_cb(GtkDialog *dialog, gint response,
                                        gpointer data)
@@ -433,6 +480,7 @@ talkatu_action_attach_file_response_cb(G
 	gtk_native_dialog_destroy(GTK_NATIVE_DIALOG(dialog));
 	g_object_unref(dialog);
 }
+#endif
 
 static void
 talkatu_action_attach_file(G_GNUC_UNUSED GSimpleAction *action,
@@ -441,11 +489,22 @@ talkatu_action_attach_file(G_GNUC_UNUSED
 {
 	TalkatuActionGroup *ag = TALKATU_ACTION_GROUP(data);
 	TalkatuActionGroupPrivate *priv = NULL;
+#if GTK_CHECK_VERSION(4, 10, 0)
+	GtkFileDialog *dialog = NULL;
+#else
 	GtkFileChooserNative *dialog = NULL;
+#endif
 
 	priv = talkatu_action_group_get_instance_private(ag);
 	g_return_if_fail(TALKATU_IS_INPUT(priv->input));
 
+#if GTK_CHECK_VERSION(4, 10, 0)
+	dialog = gtk_file_dialog_new();
+	gtk_file_dialog_set_title(dialog, _("Attach file..."));
+	gtk_file_dialog_open(dialog, NULL, NULL,
+	                     talkatu_action_attach_file_response_cb,
+	                     ag);
+#else
 	dialog = gtk_file_chooser_native_new(_("Attach file..."),
 	                                     NULL,
 	                                     GTK_FILE_CHOOSER_ACTION_OPEN,
@@ -455,6 +514,7 @@ talkatu_action_attach_file(G_GNUC_UNUSED
 	                 G_CALLBACK(talkatu_action_attach_file_response_cb),
 	                 ag);
 	gtk_native_dialog_show(GTK_NATIVE_DIALOG(dialog));
+#endif
 }
 
 static void
@@ -526,7 +586,7 @@ talkatu_action_insert_link(G_GNUC_UNUSED
 			 G_CALLBACK(talkatu_action_insert_link_response_cb),
 			 data);
 	gtk_window_set_modal(GTK_WINDOW(link_dialog), TRUE);
-	gtk_widget_show(link_dialog);
+	gtk_window_present(GTK_WINDOW(link_dialog));
 }
 
 /******************************************************************************
diff --git a/talkatu/talkatuhistoryrow.c b/talkatu/talkatuhistoryrow.c
--- a/talkatu/talkatuhistoryrow.c
+++ b/talkatu/talkatuhistoryrow.c
@@ -97,11 +97,7 @@ talkatu_history_row_update(TalkatuHistor
 		datetime = g_date_time_format(timestamp, "%I:%M %P");
 		gtk_label_set_text(GTK_LABEL(row->timestamp), datetime);
 
-		if(edited) {
-			gtk_widget_show(row->edited);
-		} else {
-			gtk_widget_hide(row->edited);
-		}
+		gtk_widget_set_visible(row->edited, edited);
 
 		if(content_type == TALKATU_CONTENT_TYPE_PANGO) {
 			gtk_label_set_markup(GTK_LABEL(row->content), contents);
