Merge pull request #479 from geopjr-forks/fix/adw-1-6-deprecations

clapper-app: Fix libadwaita 1.6 deprecations
This commit is contained in:
Rafał Dzięgiel
2025-02-16 13:22:54 +01:00
committed by GitHub
6 changed files with 54 additions and 55 deletions

View File

@@ -22,29 +22,24 @@
#include <clapper/clapper.h>
#include <adwaita.h>
#include "clapper-app-about-window.h"
#include "clapper-app-about-dialog.h"
GtkWidget *
clapper_app_about_window_new (GtkApplication *gtk_app)
clapper_app_about_dialog_new (void)
{
AdwAboutWindow *about;
GtkWindow *window;
AdwAboutDialog *about;
GString *string;
gchar *gst_ver, *debug_info;
about = ADW_ABOUT_WINDOW (adw_about_window_new_from_appdata (
about = ADW_ABOUT_DIALOG (adw_about_dialog_new_from_appdata (
CLAPPER_APP_RESOURCE_PREFIX "/data/metainfo/" CLAPPER_APP_ID ".metainfo.xml",
NULL));
window = gtk_application_get_active_window (gtk_app);
gtk_window_set_modal (GTK_WINDOW (about), TRUE);
gtk_window_set_transient_for (GTK_WINDOW (about), window);
/* Also show development versions */
adw_about_window_set_version (about, CLAPPER_VERSION_S);
adw_about_dialog_set_version (about, CLAPPER_VERSION_S);
/* TRANSLATORS: Put your name(s) here for credits or leave untranslated */
adw_about_window_set_translator_credits (about, _("translator-credits"));
adw_about_dialog_set_translator_credits (about, _("translator-credits"));
string = g_string_new (NULL);
@@ -66,7 +61,7 @@ clapper_app_about_window_new (GtkApplication *gtk_app)
g_free (gst_ver);
debug_info = g_string_free_and_steal (string);
adw_about_window_set_debug_info (about, debug_info);
adw_about_dialog_set_debug_info (about, debug_info);
g_free (debug_info);
return GTK_WIDGET (about);

View File

@@ -24,6 +24,6 @@
G_BEGIN_DECLS
G_GNUC_INTERNAL
GtkWidget * clapper_app_about_window_new (GtkApplication *gtk_app);
GtkWidget * clapper_app_about_dialog_new (void);
G_END_DECLS

View File

@@ -28,7 +28,7 @@
#include "clapper-app-uri-dialog.h"
#include "clapper-app-info-window.h"
#include "clapper-app-preferences-window.h"
#include "clapper-app-about-window.h"
#include "clapper-app-about-dialog.h"
#include "clapper-app-utils.h"
#define PERCENTAGE_ROUND(a) (round ((gdouble) a / 0.01) * 0.01)
@@ -399,10 +399,12 @@ static void
show_about (GSimpleAction *action, GVariant *param, gpointer user_data)
{
GtkApplication *gtk_app = GTK_APPLICATION (user_data);
GtkWidget *about_window;
GtkWindow *window;
GtkWidget *about_dialog;
about_window = clapper_app_about_window_new (gtk_app);
gtk_window_present (GTK_WINDOW (about_window));
window = gtk_application_get_active_window (gtk_app);
about_dialog = clapper_app_about_dialog_new ();
adw_dialog_present (ADW_DIALOG (about_dialog), GTK_WIDGET (window));
}
GApplication *

View File

@@ -25,30 +25,28 @@
#include "clapper-app-utils.h"
static void
_entry_text_changed_cb (GtkEntry *entry,
GParamSpec *pspec G_GNUC_UNUSED, AdwMessageDialog *dialog)
_entry_text_changed_cb (AdwEntryRow *entry,
GParamSpec *pspec G_GNUC_UNUSED, AdwAlertDialog *dialog)
{
GtkEntryBuffer *buffer = gtk_entry_get_buffer (entry);
guint text_length = gtk_entry_buffer_get_length (buffer);
const gchar *text = gtk_editable_get_text (GTK_EDITABLE (entry));
gboolean enabled = FALSE;
if (text_length > 0) {
const gchar *text = gtk_entry_buffer_get_text (buffer);
enabled = (text && gst_uri_is_valid (text));
if (text && *text != '\0') {
enabled = gst_uri_is_valid (text);
}
adw_message_dialog_set_response_enabled (dialog, "add", enabled);
adw_alert_dialog_set_response_enabled (dialog, "add", enabled);
}
static void
_open_uri_cb (AdwMessageDialog *dialog, GAsyncResult *result, GtkApplication *gtk_app)
_open_uri_cb (AdwAlertDialog *dialog, GAsyncResult *result, GtkApplication *gtk_app)
{
const gchar *response = adw_message_dialog_choose_finish (dialog, result);
const gchar *response = adw_alert_dialog_choose_finish (dialog, result);
if (strcmp (response, "add") == 0) {
GtkWidget *extra_child = adw_message_dialog_get_extra_child (dialog);
GtkEntryBuffer *buffer = gtk_entry_get_buffer (GTK_ENTRY (extra_child));
const gchar *text = gtk_entry_buffer_get_text (buffer);
GtkWidget *extra_child = adw_alert_dialog_get_extra_child (dialog);
AdwEntryRow *entry_row = ADW_ENTRY_ROW (gtk_list_box_get_row_at_index (GTK_LIST_BOX (extra_child), 0));
const gchar *text = gtk_editable_get_text (GTK_EDITABLE (entry_row));
GFile **files = NULL;
gint n_files = 0;
@@ -60,16 +58,15 @@ _open_uri_cb (AdwMessageDialog *dialog, GAsyncResult *result, GtkApplication *gt
}
static void
_read_text_cb (GdkClipboard *clipboard, GAsyncResult *result, GtkWidget *extra_child)
_read_text_cb (GdkClipboard *clipboard, GAsyncResult *result, GtkWidget *entry_row)
{
GtkEntry *entry = GTK_ENTRY (extra_child);
GError *error = NULL;
gchar *text = gdk_clipboard_read_text_finish (clipboard, result, &error);
if (G_LIKELY (error == NULL)) {
if (gst_uri_is_valid (text)) {
gtk_editable_set_text (GTK_EDITABLE (entry), text);
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
gtk_editable_set_text (GTK_EDITABLE (entry_row), text);
gtk_editable_select_region (GTK_EDITABLE (entry_row), 0, -1);
}
} else {
/* Common error when clipboard is empty or has unsupported content.
@@ -89,30 +86,28 @@ clapper_app_uri_dialog_open_uri (GtkApplication *gtk_app)
{
GtkWindow *window = gtk_application_get_active_window (gtk_app);
GtkBuilder *builder;
AdwMessageDialog *dialog;
GtkWidget *extra_child;
AdwAlertDialog *dialog;
GtkWidget *entry_row;
GdkDisplay *display;
builder = gtk_builder_new_from_resource (
CLAPPER_APP_RESOURCE_PREFIX "/ui/clapper-app-uri-dialog.ui");
dialog = ADW_MESSAGE_DIALOG (gtk_builder_get_object (builder, "dialog"));
gtk_window_set_transient_for (GTK_WINDOW (dialog), window);
dialog = ADW_ALERT_DIALOG (gtk_builder_get_object (builder, "dialog"));
entry_row = GTK_WIDGET (gtk_builder_get_object (builder, "entry_row"));
extra_child = adw_message_dialog_get_extra_child (dialog);
g_signal_connect (GTK_ENTRY (extra_child), "notify::text",
g_signal_connect (GTK_EDITABLE (entry_row), "notify::text",
G_CALLBACK (_entry_text_changed_cb), dialog);
if ((display = gdk_display_get_default ())) {
GdkClipboard *clipboard = gdk_display_get_clipboard (display);
gdk_clipboard_read_text_async (clipboard, NULL,
(GAsyncReadyCallback) _read_text_cb, extra_child);
(GAsyncReadyCallback) _read_text_cb, entry_row);
}
/* NOTE: Dialog will automatically unref itself after response */
adw_message_dialog_choose (dialog, NULL,
adw_alert_dialog_choose (dialog, GTK_WIDGET (window), NULL,
(GAsyncReadyCallback) _open_uri_cb,
gtk_app);

View File

@@ -67,7 +67,7 @@ configure_file(
)
clapperapp_sources = [
'clapper-app-about-window.c',
'clapper-app-about-dialog.c',
'clapper-app-application.c',
'clapper-app-file-dialog.c',
'clapper-app-headerbar.c',

View File

@@ -1,21 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="clapper-app">
<object class="AdwMessageDialog" id="dialog">
<property name="modal">true</property>
<property name="width-request">420</property>
<object class="AdwAlertDialog" id="dialog">
<property name="heading" translatable="yes">Add URI</property>
<property name="body" translatable="yes">Insert an URI to be added to playback queue</property>
<property name="close-response">cancel</property>
<property name="default-response">add</property>
<property name="follows-content-size">false</property>
<property name="content-width">420</property>
<property name="extra-child">
<object class="GtkEntry">
<property name="halign">fill</property>
<property name="valign">center</property>
<property name="hexpand">true</property>
<property name="activates-default">true</property>
<property name="truncate-multiline">true</property>
<property name="input-purpose">url</property>
<property name="placeholder-text" translatable="yes">Enter or drop URI here</property>
<object class="GtkListBox">
<property name="selection-mode">none</property>
<style>
<class name="boxed-list"/>
</style>
<child>
<object class="AdwEntryRow" id="entry_row">
<property name="halign">fill</property>
<property name="valign">center</property>
<property name="hexpand">true</property>
<property name="activates-default">true</property>
<property name="input-purpose">url</property>
<property name="title" translatable="yes">Enter or drop URI here</property>
</object>
</child>
</object>
</property>
<responses>