diff options
author | Bastien Nocera <hadess@hadess.net> | 2021-11-25 11:13:33 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2021-11-30 12:17:35 +0100 |
commit | 7bbf8883db4902792a1622aba92929d69ceba6e2 (patch) | |
tree | cee640131807facc7462f4bee7504c05884c5f77 /lib | |
parent | 5d1dd725d4fb9f77ca5dcaf76430de9fb589b377 (diff) | |
download | gnome-bluetooth-7bbf8883db4902792a1622aba92929d69ceba6e2.tar.gz |
lib: Add UI test for the devices GListStore
Diffstat (limited to 'lib')
-rw-r--r-- | lib/meson.build | 1 | ||||
-rw-r--r-- | lib/test-liststore.c | 67 |
2 files changed, 68 insertions, 0 deletions
diff --git a/lib/meson.build b/lib/meson.build index c50bd7ec..cf0b79e0 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -151,6 +151,7 @@ test_names = [ 'test-agent', 'test-class', 'test-client', + 'test-liststore', 'test-pairing-dialog', 'test-pin', 'test-settings', diff --git a/lib/test-liststore.c b/lib/test-liststore.c new file mode 100644 index 00000000..dfdc89c3 --- /dev/null +++ b/lib/test-liststore.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2021 Bastien Nocera <hadess@hadess.net> + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <gtk/gtk.h> +#include <adwaita.h> + +#include "bluetooth-client.h" +#include "bluetooth-device.h" + +static void +device_notify_cb (BluetoothDevice *device, + GParamSpec *pspec, + gpointer user_data) +{ + GtkWidget *label = user_data; + g_autofree char *label_str = NULL; + + label_str = bluetooth_device_to_string (device); + gtk_label_set_text (GTK_LABEL (label), label_str); +} + +static GtkWidget * +create_device_cb (gpointer item, gpointer user_data) +{ + BluetoothDevice *device = BLUETOOTH_DEVICE (item); + g_autofree char *label_str = NULL; + GtkWidget *row, *label; + + label_str = bluetooth_device_to_string (device); + label = gtk_label_new (label_str); + row = gtk_list_box_row_new (); + gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), label); + g_signal_connect (G_OBJECT (device), "notify", + G_CALLBACK (device_notify_cb), label); + return row; +} + +int main (int argc, char **argv) +{ + GtkWidget *window; + GtkWidget *listbox; + GListStore *model; + g_autoptr(BluetoothClient) client = NULL; + + gtk_init(); + adw_init (); + + window = gtk_window_new(); + gtk_window_set_title(GTK_WINDOW(window), "Test client"); + gtk_window_set_icon_name(GTK_WINDOW(window), "bluetooth"); + gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); + + client = bluetooth_client_new (); + model = bluetooth_client_get_devices (client); + listbox = gtk_list_box_new (); + gtk_list_box_bind_model (GTK_LIST_BOX (listbox), G_LIST_MODEL (model), create_device_cb, NULL, NULL); + gtk_window_set_child (GTK_WINDOW (window), listbox); + gtk_widget_show (window); + + while (g_list_model_get_n_items (gtk_window_get_toplevels()) > 0) + g_main_context_iteration (NULL, TRUE); + + return 0; +} |