Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port dialogs/popups to AdwDialog counterparts #628

Merged
merged 6 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-aux/flatpak/ca.andyholmes.Valent.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app-id" : "ca.andyholmes.Valent",
"runtime" : "org.gnome.Platform",
"runtime-version" : "45",
"runtime-version" : "46",
"sdk" : "org.gnome.Sdk",
"command" : "valent",
"finish-args" : [
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ json_glib_version = '>= 1.6.0'
libpeas_version = '>= 2.0.0'
eds_version = '>= 3.34'
sqlite_version = '>= 3.24.0'
libadwaita_version = '>= 1.4'
libadwaita_version = '>= 1.5'
libportal_version = ['>= 0.6', '<= 0.7.1']

libm_dep = cc.find_library('m', required: true)
Expand Down
4 changes: 2 additions & 2 deletions src/libvalent/ui/libvalent-ui.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
<gresource prefix="/ca/andyholmes/Valent/ui">
<file>style.css</file>
<file preprocess="xml-stripblanks">valent-device-page.ui</file>
<file preprocess="xml-stripblanks">valent-device-preferences-window.ui</file>
<file preprocess="xml-stripblanks">valent-device-preferences-dialog.ui</file>
<file preprocess="xml-stripblanks">valent-input-remote.ui</file>
<file preprocess="xml-stripblanks">valent-media-remote.ui</file>
<file preprocess="xml-stripblanks">valent-plugin-row.ui</file>
<file preprocess="xml-stripblanks">valent-preferences-window.ui</file>
<file preprocess="xml-stripblanks">valent-preferences-dialog.ui</file>
<file preprocess="xml-stripblanks">valent-window.ui</file>
</gresource>
</gresources>
Expand Down
8 changes: 4 additions & 4 deletions src/libvalent/ui/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ libvalent_ui_public_headers = [
libvalent_ui_private_headers = [
'valent-application-credits.h',
'valent-device-page.h',
'valent-device-preferences-window.h',
'valent-device-preferences-dialog.h',
'valent-input-remote.h',
'valent-media-remote.h',
'valent-menu-list.h',
'valent-menu-stack.h',
'valent-plugin-row.h',
'valent-preferences-window.h',
'valent-preferences-dialog.h',
'valent-ui-manager.h',
'valent-ui-utils-private.h',
'valent-window.h',
Expand All @@ -41,14 +41,14 @@ libvalent_ui_public_sources = [
'valent-device-gadget.c',
'valent-device-page.c',
'valent-device-preferences-group.c',
'valent-device-preferences-window.c',
'valent-device-preferences-dialog.c',
'valent-input-remote.c',
'valent-media-remote.c',
'valent-menu-list.c',
'valent-menu-stack.c',
'valent-plugin-row.c',
'valent-preferences-page.c',
'valent-preferences-window.c',
'valent-preferences-dialog.c',
'valent-time-helpers.c',
'valent-ui-main.c',
'valent-ui-manager.c',
Expand Down
19 changes: 6 additions & 13 deletions src/libvalent/ui/valent-device-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "valent-device-gadget.h"
#include "valent-device-page.h"
#include "valent-device-preferences-window.h"
#include "valent-device-preferences-dialog.h"
#include "valent-menu-list.h"
#include "valent-menu-stack.h"

Expand All @@ -23,7 +23,7 @@ struct _ValentDevicePage

ValentDevice *device;
GHashTable *plugins;
GtkWindow *preferences;
AdwDialog *preferences;

/* template */
GtkStack *stack;
Expand Down Expand Up @@ -193,28 +193,21 @@ page_preferences_action (GtkWidget *widget,
GVariant *parameter)
{
ValentDevicePage *self = VALENT_DEVICE_PAGE (widget);
GtkRoot *window = gtk_widget_get_root (widget);

if (self->preferences == NULL)
{
GtkAllocation allocation;
GtkRoot *window;

gtk_widget_get_allocation (widget, &allocation);
window = gtk_widget_get_root (widget);

self->preferences = g_object_new (VALENT_TYPE_DEVICE_PREFERENCES_WINDOW,
"default-width", allocation.width,
"default-height", allocation.height,
self->preferences = g_object_new (VALENT_TYPE_DEVICE_PREFERENCES_DIALOG,
"device", self->device,
"modal", FALSE,
"transient-for", window,
NULL);

g_object_add_weak_pointer (G_OBJECT (self->preferences),
(gpointer)&self->preferences);
}

gtk_window_present (self->preferences);
adw_dialog_present (ADW_DIALOG (self->preferences), GTK_WIDGET (window));
}

static void
Expand Down Expand Up @@ -289,7 +282,7 @@ valent_device_page_dispose (GObject *object)

g_clear_object (&self->device);
g_clear_pointer (&self->plugins, g_hash_table_unref);
g_clear_pointer (&self->preferences, gtk_window_destroy);
g_clear_pointer (&self->preferences, adw_dialog_force_close);

gtk_widget_dispose_template (GTK_WIDGET (object), VALENT_TYPE_DEVICE_PAGE);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>

#define G_LOG_DOMAIN "valent-device-preferences-window"
#define G_LOG_DOMAIN "valent-device-preferences-dialog"

#include "config.h"

Expand All @@ -12,13 +12,13 @@
#include <libvalent-device.h>

#include "valent-device-preferences-group.h"
#include "valent-device-preferences-window.h"
#include "valent-device-preferences-dialog.h"
#include "valent-plugin-row.h"


struct _ValentDevicePreferencesWindow
struct _ValentDevicePreferencesDialog
{
AdwPreferencesWindow parent_instance;
AdwPreferencesDialog parent_instance;

ValentDevice *device;
GHashTable *plugins;
Expand All @@ -32,7 +32,7 @@ struct _ValentDevicePreferencesWindow
GtkListBox *plugin_list;
};

G_DEFINE_FINAL_TYPE (ValentDevicePreferencesWindow, valent_device_preferences_window, ADW_TYPE_PREFERENCES_WINDOW)
G_DEFINE_FINAL_TYPE (ValentDevicePreferencesDialog, valent_device_preferences_dialog, ADW_TYPE_PREFERENCES_DIALOG)

enum {
PROP_0,
Expand Down Expand Up @@ -61,7 +61,7 @@ plugin_list_sort (GtkListBoxRow *row1,
*/
typedef struct
{
AdwPreferencesWindow *window;
AdwPreferencesDialog *window;
AdwPreferencesPage *page;
AdwPreferencesGroup *group;
GtkWidget *row;
Expand All @@ -71,9 +71,9 @@ static void
plugin_data_free (gpointer data)
{
PluginData *plugin = (PluginData *)data;
ValentDevicePreferencesWindow *self = VALENT_DEVICE_PREFERENCES_WINDOW (plugin->window);
ValentDevicePreferencesDialog *self = VALENT_DEVICE_PREFERENCES_DIALOG (plugin->window);

g_assert (VALENT_IS_DEVICE_PREFERENCES_WINDOW (self));
g_assert (VALENT_IS_DEVICE_PREFERENCES_DIALOG (self));

if (plugin->page != NULL && plugin->group != NULL)
adw_preferences_page_remove (plugin->page, plugin->group);
Expand All @@ -85,7 +85,7 @@ plugin_data_free (gpointer data)
}

static void
valent_device_preferences_window_add_plugin (ValentDevicePreferencesWindow *self,
valent_device_preferences_dialog_add_plugin (ValentDevicePreferencesDialog *self,
const char *module)
{
ValentContext *context = NULL;
Expand All @@ -96,13 +96,13 @@ valent_device_preferences_window_add_plugin (ValentDevicePreferencesWindow *self
const char *title;
const char *subtitle;

g_assert (VALENT_IS_DEVICE_PREFERENCES_WINDOW (self));
g_assert (VALENT_IS_DEVICE_PREFERENCES_DIALOG (self));
g_assert (module != NULL && *module != '\0');

engine = valent_get_plugin_engine ();
info = peas_engine_get_plugin_info (engine, module);
plugin = g_new0 (PluginData, 1);
plugin->window = ADW_PREFERENCES_WINDOW (self);
plugin->window = ADW_PREFERENCES_DIALOG (self);

title = peas_plugin_info_get_name (info);
subtitle = peas_plugin_info_get_description (info);
Expand Down Expand Up @@ -171,7 +171,7 @@ plugin_sort (gconstpointer a,
static void
on_plugins_changed (ValentDevice *device,
GParamSpec *pspec,
ValentDevicePreferencesWindow *self)
ValentDevicePreferencesDialog *self)
{
g_auto (GStrv) plugins = NULL;
GHashTableIter iter;
Expand All @@ -192,17 +192,17 @@ on_plugins_changed (ValentDevice *device,
for (unsigned int i = 0; plugins[i] != NULL; i++)
{
if (!g_hash_table_contains (self->plugins, plugins[i]))
valent_device_preferences_window_add_plugin (self, plugins[i]);
valent_device_preferences_dialog_add_plugin (self, plugins[i]);
}
}

/*
* GObject
*/
static void
valent_device_preferences_window_constructed (GObject *object)
valent_device_preferences_dialog_constructed (GObject *object)
{
ValentDevicePreferencesWindow *self = VALENT_DEVICE_PREFERENCES_WINDOW (object);
ValentDevicePreferencesDialog *self = VALENT_DEVICE_PREFERENCES_DIALOG (object);

/* Device */
g_object_bind_property (self->device, "name",
Expand All @@ -220,30 +220,30 @@ valent_device_preferences_window_constructed (GObject *object)
self, 0);
on_plugins_changed (self->device, NULL, self);

G_OBJECT_CLASS (valent_device_preferences_window_parent_class)->constructed (object);
G_OBJECT_CLASS (valent_device_preferences_dialog_parent_class)->constructed (object);
}

static void
valent_device_preferences_window_dispose (GObject *object)
valent_device_preferences_dialog_dispose (GObject *object)
{
ValentDevicePreferencesWindow *self = VALENT_DEVICE_PREFERENCES_WINDOW (object);
ValentDevicePreferencesDialog *self = VALENT_DEVICE_PREFERENCES_DIALOG (object);

g_clear_object (&self->device);
g_clear_pointer (&self->plugins, g_hash_table_unref);

gtk_widget_dispose_template (GTK_WIDGET (object),
VALENT_TYPE_DEVICE_PREFERENCES_WINDOW);
VALENT_TYPE_DEVICE_PREFERENCES_DIALOG);

G_OBJECT_CLASS (valent_device_preferences_window_parent_class)->dispose (object);
G_OBJECT_CLASS (valent_device_preferences_dialog_parent_class)->dispose (object);
}

static void
valent_device_preferences_window_get_property (GObject *object,
valent_device_preferences_dialog_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ValentDevicePreferencesWindow *self = VALENT_DEVICE_PREFERENCES_WINDOW (object);
ValentDevicePreferencesDialog *self = VALENT_DEVICE_PREFERENCES_DIALOG (object);

switch (prop_id)
{
Expand All @@ -257,12 +257,12 @@ valent_device_preferences_window_get_property (GObject *object,
}

static void
valent_device_preferences_window_set_property (GObject *object,
valent_device_preferences_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ValentDevicePreferencesWindow *self = VALENT_DEVICE_PREFERENCES_WINDOW (object);
ValentDevicePreferencesDialog *self = VALENT_DEVICE_PREFERENCES_DIALOG (object);

switch (prop_id)
{
Expand All @@ -276,26 +276,26 @@ valent_device_preferences_window_set_property (GObject *object,
}

static void
valent_device_preferences_window_class_init (ValentDevicePreferencesWindowClass *klass)
valent_device_preferences_dialog_class_init (ValentDevicePreferencesDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

object_class->constructed = valent_device_preferences_window_constructed;
object_class->dispose = valent_device_preferences_window_dispose;
object_class->get_property = valent_device_preferences_window_get_property;
object_class->set_property = valent_device_preferences_window_set_property;
object_class->constructed = valent_device_preferences_dialog_constructed;
object_class->dispose = valent_device_preferences_dialog_dispose;
object_class->get_property = valent_device_preferences_dialog_get_property;
object_class->set_property = valent_device_preferences_dialog_set_property;

gtk_widget_class_set_template_from_resource (widget_class, "/ca/andyholmes/Valent/ui/valent-device-preferences-window.ui");
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesWindow, status_page);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesWindow, sync_page);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesWindow, other_page);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesWindow, plugin_page);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesWindow, plugin_group);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesWindow, plugin_list);
gtk_widget_class_set_template_from_resource (widget_class, "/ca/andyholmes/Valent/ui/valent-device-preferences-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesDialog, status_page);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesDialog, sync_page);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesDialog, other_page);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesDialog, plugin_page);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesDialog, plugin_group);
gtk_widget_class_bind_template_child (widget_class, ValentDevicePreferencesDialog, plugin_list);

/**
* ValentDevicePreferencesWindow:device:
* ValentDevicePreferencesDialog:device:
*
* The device this panel controls and represents.
*/
Expand All @@ -311,7 +311,7 @@ valent_device_preferences_window_class_init (ValentDevicePreferencesWindowClass
}

static void
valent_device_preferences_window_init (ValentDevicePreferencesWindow *self)
valent_device_preferences_dialog_init (ValentDevicePreferencesDialog *self)
{
gtk_widget_init_template (GTK_WIDGET (self));

Expand Down
16 changes: 16 additions & 0 deletions src/libvalent/ui/valent-device-preferences-dialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>

#pragma once

#include <adwaita.h>

#include "../core/valent-object.h"

G_BEGIN_DECLS

#define VALENT_TYPE_DEVICE_PREFERENCES_DIALOG (valent_device_preferences_dialog_get_type())

G_DECLARE_FINAL_TYPE (ValentDevicePreferencesDialog, valent_device_preferences_dialog, VALENT, DEVICE_PREFERENCES_DIALOG, AdwPreferencesDialog)

G_END_DECLS
Loading
Loading