| 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
| 2 |
* |
| 3 |
* Copyright (C) 2010-2012 Richard Hughes <[email protected]> |
| 4 |
* |
| 5 |
* Licensed under the GNU Lesser General Public License Version 2.1 |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
|
| 24 |
#include <colord.h> |
| 25 |
#include <glib.h> |
| 26 |
#include <glib-object.h> |
| 27 |
#include <gtk/gtk.h> |
| 28 |
|
| 29 |
#include "cd-sample-window.h" |
| 30 |
#include "cd-window.h" |
| 31 |
|
| 32 |
static void |
| 33 |
cd_window_get_profile_cb (GObject *source, |
| 34 |
GAsyncResult *res, |
| 35 |
gpointer user_data) |
| 36 |
{ |
| 37 |
CdWindow *window = CD_WINDOW (source); |
| 38 |
GtkWidget *widget = GTK_WIDGET (user_data); |
| 39 |
GError *error = NULL; |
| 40 |
CdProfile *profile; |
| 41 |
|
| 42 |
profile = cd_window_get_profile_finish (window, |
| 43 |
res, |
| 44 |
&error); |
| 45 |
g_assert_no_error (error); |
| 46 |
g_assert (profile != NULL); |
| 47 |
g_debug ("profile was %s", cd_profile_get_filename (profile)); |
| 48 |
g_object_unref (profile); |
| 49 |
|
| 50 |
/* kill the dialog */ |
| 51 |
gtk_widget_destroy (widget); |
| 52 |
} |
| 53 |
|
| 54 |
static void |
| 55 |
map_cb (GtkWidget *this_widget, gpointer user_data) |
| 56 |
{ |
| 57 |
CdWindow *window = CD_WINDOW (user_data); |
| 58 |
|
| 59 |
/* get the profile for this widget */ |
| 60 |
cd_window_get_profile (window, |
| 61 |
this_widget, |
| 62 |
NULL, |
| 63 |
cd_window_get_profile_cb, |
| 64 |
this_widget); |
| 65 |
} |
| 66 |
|
| 67 |
static void |
| 68 |
colord_window_func (void) |
| 69 |
{ |
| 70 |
CdWindow *window; |
| 71 |
GtkWidget *dialog; |
| 72 |
|
| 73 |
window = cd_window_new (); |
| 74 |
dialog = gtk_message_dialog_new (NULL, |
| 75 |
GTK_DIALOG_MODAL, |
| 76 |
GTK_MESSAGE_INFO, |
| 77 |
GTK_BUTTONS_OK, |
| 78 |
"%s", "Hello world"); |
| 79 |
g_signal_connect (dialog, "map", |
| 80 |
G_CALLBACK (map_cb), |
| 81 |
window); |
| 82 |
gtk_dialog_run (GTK_DIALOG (dialog)); |
| 83 |
g_object_unref (window); |
| 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_widget_destroy (GTK_WIDGET (window)); |
| 117 |
} |
| 118 |
|
| 119 |
int |
| 120 |
main (int argc, char **argv) |
| 121 |
{ |
| 122 |
g_type_init (); |
| 123 |
g_test_init (&argc, &argv, NULL); |
| 124 |
gtk_init (&argc, &argv); |
| 125 |
|
| 126 |
/* only critical and error are fatal */ |
| 127 |
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL); |
| 128 |
|
| 129 |
/* tests go here */ |
| 130 |
g_test_add_func ("/colord/window", colord_window_func); |
| 131 |
g_test_add_func ("/colors/sample-window", colord_sample_window_func); |
| 132 |
return g_test_run (); |
| 133 |
} |
| 134 |
|