| 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
| 2 |
* |
| 3 |
* Copyright (C) 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 |
/** |
| 23 |
* SECTION:cd-window-sync |
| 24 |
* @short_description: Sync helpers for #CdWindow |
| 25 |
* |
| 26 |
* These helper functions provide a simple way to use the async functions |
| 27 |
* in command line tools. |
| 28 |
* |
| 29 |
* See also: #CdWindow |
| 30 |
*/ |
| 31 |
|
| 32 |
#include "config.h" |
| 33 |
|
| 34 |
#include <glib.h> |
| 35 |
#include <gio/gio.h> |
| 36 |
|
| 37 |
#include <colord.h> |
| 38 |
|
| 39 |
#include "cd-window.h" |
| 40 |
#include "cd-window-sync.h" |
| 41 |
|
| 42 |
/* tiny helper to help us do the async operation */ |
| 43 |
typedef struct { |
| 44 |
GError **error; |
| 45 |
GMainLoop *loop; |
| 46 |
CdProfile *profile; |
| 47 |
CdWindow *window; |
| 48 |
} CdWindowHelper; |
| 49 |
|
| 50 |
/**********************************************************************/ |
| 51 |
|
| 52 |
static void |
| 53 |
cd_window_get_profile_finish_sync (CdWindow *window, |
| 54 |
GAsyncResult *res, |
| 55 |
CdWindowHelper *helper) |
| 56 |
{ |
| 57 |
helper->profile = cd_window_get_profile_finish (window, |
| 58 |
res, |
| 59 |
helper->error); |
| 60 |
g_main_loop_quit (helper->loop); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* cd_window_get_profile_sync: |
| 65 |
* @window: a #CdWindow instance. |
| 66 |
* @widget: a #GtkWidget |
| 67 |
* @cancellable: a #GCancellable or %NULL |
| 68 |
* @error: a #GError, or %NULL. |
| 69 |
* |
| 70 |
* Gets the screen profile that should be used for the widget, |
| 71 |
* which corresponds to the screen output the widget most covers. |
| 72 |
* |
| 73 |
* WARNING: This function is synchronous, and may block. |
| 74 |
* Do not use it in GUI applications. |
| 75 |
* |
| 76 |
* Return value: (transfer full): a #CdProfile or %NULL |
| 77 |
* |
| 78 |
* Since: 0.1.20 |
| 79 |
**/ |
| 80 |
CdProfile * |
| 81 |
cd_window_get_profile_sync (CdWindow *window, |
| 82 |
GtkWidget *widget, |
| 83 |
GCancellable *cancellable, |
| 84 |
GError **error) |
| 85 |
{ |
| 86 |
CdWindowHelper helper; |
| 87 |
|
| 88 |
/* create temp object */ |
| 89 |
helper.loop = g_main_loop_new (NULL, FALSE); |
| 90 |
helper.error = error; |
| 91 |
|
| 92 |
/* run async method */ |
| 93 |
cd_window_get_profile (window, widget, cancellable, |
| 94 |
(GAsyncReadyCallback) cd_window_get_profile_finish_sync, |
| 95 |
&helper); |
| 96 |
g_main_loop_run (helper.loop); |
| 97 |
|
| 98 |
/* free temp object */ |
| 99 |
g_main_loop_unref (helper.loop); |
| 100 |
|
| 101 |
return helper.profile; |
| 102 |
} |