Debian Codegraph @

libcolord-gtk/cd-self-test-gtk4.c

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2021 Georges Basile Stavracas Neto <[email protected]>
4 * 2010-2012 Richard Hughes <[email protected]>
5 *
6 * Licensed under the GNU Lesser General Public License Version 2.1
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "config.h"
24
25 #include <colord.h>
26 #include <glib.h>
27 #include <glib-object.h>
28 #include <gtk/gtk.h>
29
30 #include "cd-sample-window.h"
31 #include "cd-window.h"
32
33 static void
34 cd_window_get_profile_cb (GObject *source,
35 GAsyncResult *res,
36 gpointer user_data)
37 {
38 CdWindow *window = CD_WINDOW (source);
39 GtkWidget *widget = GTK_WIDGET (user_data);
40 GError *error = NULL;
41 CdProfile *profile;
42
43 profile = cd_window_get_profile_finish (window,
44 res,
45 &error);
46 g_assert_no_error (error);
47 g_assert (profile != NULL);
48 g_debug ("profile was %s", cd_profile_get_filename (profile));
49 g_object_unref (profile);
50
51 /* kill the dialog */
52 gtk_window_destroy (GTK_WINDOW (widget));
53 }
54
55 static void
56 map_cb (GtkWidget *this_widget, gpointer user_data)
57 {
58 CdWindow *window = CD_WINDOW (user_data);
59
60 /* get the profile for this widget */
61 cd_window_get_profile (window,
62 this_widget,
63 NULL,
64 cd_window_get_profile_cb,
65 this_widget);
66 }
67
68 static void
69 colord_window_func (void)
70 {
71 CdWindow *window;
72 GtkWidget *dialog;
73
74 window = cd_window_new ();
75 dialog = gtk_message_dialog_new (NULL,
76 GTK_DIALOG_MODAL,
77 GTK_MESSAGE_INFO,
78 GTK_BUTTONS_OK,
79 "%s", "Hello world");
80 g_signal_connect (dialog, "map",
81 G_CALLBACK (map_cb),
82 window);
83 gtk_window_present (GTK_WINDOW (dialog));
84 }
85
86 static gboolean
87 colord_sample_window_loop_cb (GMainLoop *loop)
88 {
89 g_main_loop_quit (loop);
90 return FALSE;
91 }
92
93 static void
94 colord_sample_window_func (void)
95 {
96 GtkWindow *window;
97 GMainLoop *loop;
98 CdColorRGB source;
99
100 window = cd_sample_window_new ();
101 g_assert (window != NULL);
102 source.R = 1.0f;
103 source.G = 1.0f;
104 source.B = 0.0f;
105 cd_sample_window_set_color (CD_SAMPLE_WINDOW (window), &source);
106 cd_sample_window_set_fraction (CD_SAMPLE_WINDOW (window), -1);
107
108 /* move to the center of device lvds1 */
109 gtk_window_present (window);
110
111 loop = g_main_loop_new (NULL, FALSE);
112 g_timeout_add_seconds (5, (GSourceFunc) colord_sample_window_loop_cb, loop);
113 g_main_loop_run (loop);
114
115 g_main_loop_unref (loop);
116 gtk_window_destroy (GTK_WINDOW (window));
117 }
118
119 int
120 main (int argc, char **argv)
121 {
122 g_test_init (&argc, &argv, NULL);
123 gtk_init ();
124
125 /* only critical and error are fatal */
126 g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
127
128 /* tests go here */
129 g_test_add_func ("/colord/window", colord_window_func);
130 g_test_add_func ("/colors/sample-window", colord_sample_window_func);
131 return g_test_run ();
132 }
133