[gnome-control-center] color: Show a summary page when running on a LiveCD
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] color: Show a summary page when running on a LiveCD
- Date: Wed, 23 Jan 2013 20:37:07 +0000 (UTC)
commit 4c9a96260fc969630eebaed5802454ba340278a1
Author: Richard Hughes <richard hughsie com>
Date: Mon Jan 21 15:47:03 2013 +0000
color: Show a summary page when running on a LiveCD
This matches the mockups from jimmac. You need colord (specifially, the D-Bus
activated helper) from git master to make this work.
You can test this on non-live media by setting CC_COLOR_PANEL_IS_LIVECD=1
before running gnome-control-center.
panels/color/cc-color-calibrate.c | 39 ++++++++++--
panels/color/cc-color-calibrate.h | 1 +
panels/color/cc-color-panel.c | 123 ++++++++++++++++++++++++++++++++++++-
panels/color/color.ui | 94 ++++++++++++++++++++++++++++
4 files changed, 249 insertions(+), 8 deletions(-)
---
diff --git a/panels/color/cc-color-calibrate.c b/panels/color/cc-color-calibrate.c
index 2155eb8..5569571 100644
--- a/panels/color/cc-color-calibrate.c
+++ b/panels/color/cc-color-calibrate.c
@@ -42,6 +42,7 @@ struct _CcColorCalibratePrivate
CdDevice *device;
CdSensorCap device_kind;
CdSensor *sensor;
+ CdProfile *profile;
gchar *title;
GDBusProxy *proxy_helper;
GDBusProxy *proxy_inhibit;
@@ -55,6 +56,7 @@ struct _CcColorCalibratePrivate
guint target_whitepoint; /* in Kelvin */
gdouble target_gamma;
gint inhibit_fd;
+ CdSessionError session_error_code;
};
#define CD_SESSION_ERROR cc_color_calibrate_error_quark()
@@ -137,6 +139,12 @@ cc_color_calibrate_set_title (CcColorCalibrate *calibrate,
calibrate->priv->title = g_strdup (title);
}
+CdProfile *
+cc_color_calibrate_get_profile (CcColorCalibrate *calibrate)
+{
+ g_return_val_if_fail (CC_IS_COLOR_CALIB (calibrate), NULL);
+ return calibrate->priv->profile;
+}
static guint
_gnome_rr_output_get_gamma_size (GnomeRROutput *output)
@@ -433,6 +441,9 @@ cc_color_calibrate_finished (CcColorCalibrate *calibrate,
const gchar *tmp;
CcColorCalibratePrivate *priv = calibrate->priv;
+ /* save failure so we can get this after we've quit the loop */
+ calibrate->priv->session_error_code = code;
+
/* show correct buttons */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
"button_cancel"));
@@ -486,21 +497,27 @@ cc_color_calibrate_signal_cb (GDBusProxy *proxy,
CdColorRGB color;
CdColorRGB *color_tmp;
CdSessionInteraction code;
- const gchar *image;
+ const gchar *image = NULL;
const gchar *message;
- const gchar *str;
+ const gchar *profile_path = NULL;
+ const gchar *str = NULL;
gboolean ret;
GError *error = NULL;
GPtrArray *array = NULL;
GtkImage *img;
GtkLabel *label;
GVariantIter *iter;
+ GVariant *dict = NULL;
if (g_strcmp0 (signal_name, "Finished") == 0)
{
- g_variant_get (parameters, "(u&s)",
+ g_variant_get (parameters, "(u a{sv})",
&code,
- &str);
+ &dict);
+ g_variant_lookup (dict, "ErrorDetails", "&s", &str);
+ ret = g_variant_lookup (dict, "ProfilePath", "&s", &profile_path);
+ if (ret)
+ priv->profile = cd_profile_new_with_object_path (profile_path);
cc_color_calibrate_finished (calibrate, code, str);
goto out;
}
@@ -579,7 +596,8 @@ cc_color_calibrate_signal_cb (GDBusProxy *proxy,
}
g_warning ("got unknown signal %s", signal_name);
out:
- return;
+ if (dict != NULL)
+ g_variant_unref (dict);
}
static void
@@ -961,11 +979,20 @@ cc_color_calibrate_start (CcColorCalibrate *calibrate,
cc_color_calibrate_inhibit (calibrate);
g_main_loop_run (priv->loop);
-
gtk_widget_hide (GTK_WIDGET (window));
/* we can go idle now */
cc_color_calibrate_uninhibit (calibrate);
+
+ /* see if we failed */
+ if (calibrate->priv->session_error_code != CD_SESSION_ERROR_NONE)
+ {
+ ret = FALSE;
+ g_set_error_literal (error,
+ CD_SESSION_ERROR,
+ CD_SESSION_ERROR_INTERNAL,
+ "failed to calibrate");
+ }
out:
if (retval != NULL)
g_variant_unref (retval);
diff --git a/panels/color/cc-color-calibrate.h b/panels/color/cc-color-calibrate.h
index 965efe4..d834c79 100644
--- a/panels/color/cc-color-calibrate.h
+++ b/panels/color/cc-color-calibrate.h
@@ -70,6 +70,7 @@ gboolean cc_color_calibrate_start (CcColorCalibrate *calibrate,
GError **error);
gboolean cc_color_calibrate_setup (CcColorCalibrate *calibrate,
GError **error);
+CdProfile *cc_color_calibrate_get_profile (CcColorCalibrate *calibrate);
G_END_DECLS
diff --git a/panels/color/cc-color-panel.c b/panels/color/cc-color-panel.c
index a61f679..beeec12 100644
--- a/panels/color/cc-color-panel.c
+++ b/panels/color/cc-color-panel.c
@@ -57,6 +57,7 @@ struct _CcColorPanelPrivate
gchar *list_box_filter;
guint list_box_selected_id;
GtkSizeGroup *list_box_size;
+ gboolean is_live_cd;
};
enum {
@@ -317,12 +318,17 @@ gcm_prefs_calib_apply_cb (GtkWidget *widget, CcColorPanel *prefs)
if (!ret)
{
g_warning ("failed to start calibrate: %s", error->message);
+ gtk_widget_hide (GTK_WIDGET (window));
g_error_free (error);
goto out;
}
-out:
- if (window != NULL)
+
+ /* if we are a LiveCD then don't close the window as there is another
+ * summary pane with the export button */
+ if (!prefs->priv->is_live_cd)
gtk_widget_hide (GTK_WIDGET (window));
+out:
+ return;
}
static gboolean
@@ -756,6 +762,74 @@ out:
}
static void
+gcm_prefs_calib_export_cb (GtkWidget *widget, CcColorPanel *prefs)
+{
+ CdProfile *profile;
+ gboolean ret;
+ gchar *default_name = NULL;
+ GError *error = NULL;
+ GFile *destination = NULL;
+ GFile *source = NULL;
+ GtkWidget *dialog;
+
+ /* TRANSLATORS: this is the dialog to save the ICC profile */
+ dialog = gtk_file_chooser_dialog_new (_("Save Profile"),
+ GTK_WINDOW (prefs->priv->main_window),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
+
+ profile = cc_color_calibrate_get_profile (prefs->priv->calibrate);
+ ret = cd_profile_connect_sync (profile, NULL, &error);
+ if (!ret)
+ {
+ g_warning ("Failed to get imported profile: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ default_name = g_strdup_printf ("%s.icc", cd_profile_get_title (profile));
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), default_name);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+ source = g_file_new_for_path (cd_profile_get_filename (profile));
+ destination = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+ ret = g_file_copy (source,
+ destination,
+ G_FILE_COPY_OVERWRITE,
+ NULL,
+ NULL,
+ NULL,
+ &error);
+ if (!ret)
+ {
+ g_warning ("Failed to copy profile: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ }
+out:
+ gtk_widget_destroy (dialog);
+ g_free (default_name);
+ if (source != NULL)
+ g_object_unref (source);
+ if (destination != NULL)
+ g_object_unref (destination);
+}
+
+static void
+gcm_prefs_calib_export_link_cb (GtkLabel *widget,
+ const gchar *url,
+ CcColorPanel *prefs)
+{
+ gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (prefs->priv->main_window)),
+ "help:gnome-help/color-howtoimport",
+ GDK_CURRENT_TIME, NULL);
+}
+
+static void
gcm_prefs_profile_add_cb (GtkWidget *widget, CcColorPanel *prefs)
{
GPtrArray *profiles;
@@ -1796,6 +1870,33 @@ gcm_prefs_connect_cb (GObject *object,
prefs);
}
+static gboolean
+gcm_prefs_is_livecd (void)
+{
+ gboolean ret = TRUE;
+ gchar *data = NULL;
+ GError *error = NULL;
+
+ /* allow testing */
+ if (g_getenv ("CC_COLOR_PANEL_IS_LIVECD") != NULL)
+ goto out;
+
+ /* get the kernel commandline */
+ ret = g_file_get_contents ("/proc/cmdline", &data, NULL, &error);
+ if (!ret)
+ {
+ g_warning ("failed to get kernel command line: %s",
+ error->message);
+ g_error_free (error);
+ goto out;
+ }
+ ret = (g_strstr_len (data, -1, "liveimg") != NULL ||
+ g_strstr_len (data, -1, "casper") != NULL);
+out:
+ g_free (data);
+ return ret;
+}
+
static void
gcm_prefs_window_realize_cb (GtkWidget *widget, CcColorPanel *prefs)
{
@@ -2074,6 +2175,9 @@ cc_color_panel_init (CcColorPanel *prefs)
g_signal_connect (widget, "cancel",
G_CALLBACK (gcm_prefs_calib_cancel_cb),
prefs);
+ g_signal_connect (widget, "close",
+ G_CALLBACK (gcm_prefs_calib_cancel_cb),
+ prefs);
g_signal_connect (widget, "prepare",
G_CALLBACK (gcm_prefs_calib_prepare_cb),
prefs);
@@ -2230,6 +2334,21 @@ cc_color_panel_init (CcColorPanel *prefs)
/* set calibrate button sensitivity */
gcm_prefs_set_calibrate_button_sensitivity (prefs);
+ /* show the confirmation export page if we are running from a LiveCD */
+ priv->is_live_cd = gcm_prefs_is_livecd ();
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+ "box_calib_summary"));
+ gtk_widget_set_visible (widget, priv->is_live_cd);
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+ "button_calib_export"));
+ g_signal_connect (widget, "clicked",
+ G_CALLBACK (gcm_prefs_calib_export_cb), prefs);
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+ "label_calib_summary_message"));
+ g_signal_connect (widget, "activate-link",
+ G_CALLBACK (gcm_prefs_calib_export_link_cb), prefs);
+
+
widget = WID (priv->builder, "dialog-vbox1");
gtk_widget_reparent (widget, (GtkWidget *) prefs);
g_signal_connect (widget, "realize",
diff --git a/panels/color/color.ui b/panels/color/color.ui
index 86dad9b..59b2bff 100644
--- a/panels/color/color.ui
+++ b/panels/color/color.ui
@@ -376,6 +376,100 @@
<property name="title" translatable="yes">Profile Name</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox" id="box_calib_summary">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">9</property>
+ <child>
+ <object class="GtkLabel" id="label_calib_summary_title">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="xpad">6</property>
+ <property name="label" translatable="yes">Profile successfully created!</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_calib_export">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="halign">center</property>
+ <child>
+ <object class="GtkBox" id="box3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">24</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">9</property>
+ <child>
+ <object class="GtkImage" id="image2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="pixel_size">48</property>
+ <property name="icon_name">folder-symbolic</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Export</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">24</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_calib_summary_message">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="xpad">6</property>
+ <property name="label" translatable="yes">You may find these instructions on how to use the profile on <a href="linux">GNU/Linux</a>, <a href="osx">Apple OS X</a> and <a href="windows">Microsoft Windows</a> systems useful.</property>
+ <property name="use_markup">True</property>
+ <property name="wrap">True</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="page_type">summary</property>
+ <property name="title" translatable="yes">Summary</property>
+ </packing>
+ </child>
<child internal-child="action_area">
<object class="GtkBox" id="assistant-action_area1">
<property name="can_focus">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]