talkatu/talkatu

Fix warnings with GTK 4.10

11 months ago, Elliott Sales de Andrade
f1e368a967e6
Parents 42c7cfb1acd1
Children 7f0fbe7e68d6
Fix warnings with GTK 4.10

Testing Done:
Compiled and saw no warnings.
Opened the insert dialogs and selected/cancelled.

Reviewed at https://reviews.imfreedom.org/r/2455/
--- a/demo/talkatudemo.c Thu Mar 23 22:52:19 2023 -0500
+++ b/demo/talkatudemo.c Sat Jun 03 01:15:00 2023 -0500
@@ -72,7 +72,7 @@
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
--- a/demo/talkatudemowindow.c Thu Mar 23 22:52:19 2023 -0500
+++ b/demo/talkatudemowindow.c Sat Jun 03 01:15:00 2023 -0500
@@ -47,6 +47,44 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
--- a/talkatu/talkatuactiongroup.c Thu Mar 23 22:52:19 2023 -0500
+++ b/talkatu/talkatuactiongroup.c Sat Jun 03 01:15:00 2023 -0500
@@ -394,6 +394,53 @@
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 @@
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 @@
{
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 @@
G_CALLBACK(talkatu_action_attach_file_response_cb),
ag);
gtk_native_dialog_show(GTK_NATIVE_DIALOG(dialog));
+#endif
}
static void
@@ -526,7 +586,7 @@
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));
}
/******************************************************************************
--- a/talkatu/talkatuhistoryrow.c Thu Mar 23 22:52:19 2023 -0500
+++ b/talkatu/talkatuhistoryrow.c Sat Jun 03 01:15:00 2023 -0500
@@ -97,11 +97,7 @@
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);