[gnome-color-manager] Port to the new GtkApplication API
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Port to the new GtkApplication API
- Date: Tue, 26 Oct 2010 15:42:35 +0000 (UTC)
commit dfbbad6b80eccb7eb9882b55d468f13407750f88
Author: Richard Hughes <richard hughsie com>
Date: Tue Oct 26 17:38:53 2010 +0100
Port to the new GtkApplication API
data/gcm-viewer.ui | 2 +-
src/gcm-picker.c | 120 +++++++++++++++++++++++++++++++--------------------
src/gcm-viewer.c | 107 +++++++++++++++++++++++++++++-----------------
3 files changed, 141 insertions(+), 88 deletions(-)
---
diff --git a/data/gcm-viewer.ui b/data/gcm-viewer.ui
index 6519b1b..2f58ef7 100644
--- a/data/gcm-viewer.ui
+++ b/data/gcm-viewer.ui
@@ -31,7 +31,7 @@
<object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
+ <property name="hscrollbar_policy">never</property>
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">in</property>
<child>
diff --git a/src/gcm-picker.c b/src/gcm-picker.c
index f31568e..931e503 100644
--- a/src/gcm-picker.c
+++ b/src/gcm-picker.c
@@ -47,6 +47,8 @@ static gboolean done_measure = FALSE;
static GcmSensor *sensor = NULL;
static GcmColorXYZ last_sample;
static gdouble last_ambient = -1.0f;
+static guint xid = 0;
+static GcmSensorClient *sensor_client = NULL;
enum {
GCM_PREFS_COMBO_COLUMN_TEXT,
@@ -284,7 +286,7 @@ static void
gcm_picker_close_cb (GtkWidget *widget, gpointer data)
{
GtkApplication *application = (GtkApplication *) data;
- gtk_application_quit (application);
+ g_application_release (G_APPLICATION (application));
}
/**
@@ -310,7 +312,7 @@ gcm_picker_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
* gcm_picker_sensor_client_setup_ui:
**/
static void
-gcm_picker_sensor_client_setup_ui (GcmSensorClient *sensor_client)
+gcm_picker_sensor_client_setup_ui (GcmSensorClient *_sensor_client)
{
gboolean ret = FALSE;
GtkWidget *widget;
@@ -355,7 +357,7 @@ out:
* gcm_picker_sensor_client_changed_cb:
**/
static void
-gcm_picker_sensor_client_changed_cb (GcmSensorClient *sensor_client, gpointer user_data)
+gcm_picker_sensor_client_changed_cb (GcmSensorClient *_sensor_client, gpointer user_data)
{
gcm_picker_sensor_client_setup_ui (sensor_client);
}
@@ -364,14 +366,14 @@ gcm_picker_sensor_client_changed_cb (GcmSensorClient *sensor_client, gpointer us
* gcm_window_set_parent_xid:
**/
static void
-gcm_window_set_parent_xid (GtkWindow *window, guint32 xid)
+gcm_window_set_parent_xid (GtkWindow *window, guint32 _xid)
{
GdkDisplay *display;
GdkWindow *parent_window;
GdkWindow *our_window;
display = gdk_display_get_default ();
- parent_window = gdk_window_foreign_new_for_display (display, xid);
+ parent_window = gdk_window_foreign_new_for_display (display, _xid);
our_window = gtk_widget_get_window (GTK_WIDGET (window));
/* set this above our parent */
@@ -529,50 +531,26 @@ gcm_prefs_setup_space_combobox (GtkWidget *widget)
}
/**
- * main:
+ * gcm_picker_activate_cb:
**/
-int
-main (int argc, char *argv[])
+static void
+gcm_picker_activate_cb (GApplication *application, gpointer user_data)
+{
+ GtkWindow *window;
+ window = GTK_WINDOW (gtk_builder_get_object (builder, "dialog_picker"));
+ gtk_window_present (window);
+}
+
+/**
+ * gcm_picker_startup_cb:
+ **/
+static void
+gcm_picker_startup_cb (GApplication *application, gpointer user_data)
{
- GOptionContext *context;
guint retval = 0;
GError *error = NULL;
- GtkApplication *application;
GtkWidget *main_window;
GtkWidget *widget;
- guint xid = 0;
- GcmSensorClient *sensor_client = NULL;
-
- const GOptionEntry options[] = {
- { "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
- /* TRANSLATORS: we can make this modal (stay on top of) another window */
- _("Set the parent window to make this modal"), NULL },
- { NULL}
- };
-
- /* setup translations */
- setlocale (LC_ALL, "");
- bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
-
- /* setup type system */
- g_type_init ();
-
- /* setup LCMS */
- cmsSetLogErrorHandler (gcm_picker_error_cb);
-
- context = g_option_context_new (NULL);
- /* TRANSLATORS: tool that is used to pick colors */
- g_option_context_set_summary (context, _("GNOME Color Manager Color Picker"));
- g_option_context_add_group (context, gcm_debug_get_option_group ());
- g_option_context_add_group (context, gtk_get_option_group (TRUE));
- g_option_context_add_main_entries (context, options, NULL);
- g_option_context_parse (context, &argc, &argv, NULL);
- g_option_context_free (context);
-
- /* ensure single instance */
- application = gtk_application_new ("org.gnome.ColorManager.Picker", &argc, &argv);
/* get UI */
builder = gtk_builder_new ();
@@ -584,7 +562,7 @@ main (int argc, char *argv[])
}
main_window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_picker"));
- gtk_application_add_window (application, GTK_WINDOW (main_window));
+ gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (main_window));
gtk_window_set_icon_name (GTK_WINDOW (main_window), GCM_STOCK_ICON);
g_signal_connect (main_window, "delete_event",
G_CALLBACK (gcm_picker_delete_event_cb), application);
@@ -664,9 +642,57 @@ main (int argc, char *argv[])
/* wait */
gtk_widget_show (main_window);
- gtk_application_run (application);
-
out:
+ return;
+}
+
+/**
+ * main:
+ **/
+int
+main (int argc, char *argv[])
+{
+ GOptionContext *context;
+ GtkApplication *application;
+ int status = 0;
+
+ const GOptionEntry options[] = {
+ { "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
+ /* TRANSLATORS: we can make this modal (stay on top of) another window */
+ _("Set the parent window to make this modal"), NULL },
+ { NULL}
+ };
+
+ /* setup translations */
+ setlocale (LC_ALL, "");
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ /* setup type system */
+ g_type_init ();
+
+ /* setup LCMS */
+ cmsSetLogErrorHandler (gcm_picker_error_cb);
+
+ context = g_option_context_new (NULL);
+ /* TRANSLATORS: tool that is used to pick colors */
+ g_option_context_set_summary (context, _("GNOME Color Manager Color Picker"));
+ g_option_context_add_group (context, gcm_debug_get_option_group ());
+ g_option_context_add_group (context, gtk_get_option_group (TRUE));
+ g_option_context_add_main_entries (context, options, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+ g_option_context_free (context);
+
+ /* ensure single instance */
+ application = gtk_application_new ("org.gnome.ColorManager.Picker", 0);
+ g_signal_connect (application, "startup",
+ G_CALLBACK (gcm_picker_startup_cb), NULL);
+ g_signal_connect (application, "activate",
+ G_CALLBACK (gcm_picker_activate_cb), NULL);
+
+ status = g_application_run (G_APPLICATION (application), argc, argv);
+
g_object_unref (application);
if (profile_store != NULL)
g_object_unref (profile_store);
@@ -676,6 +702,6 @@ out:
g_object_unref (calibrate);
if (builder != NULL)
g_object_unref (builder);
- return retval;
+ return status;
}
diff --git a/src/gcm-viewer.c b/src/gcm-viewer.c
index a941ba6..6c6a2f9 100644
--- a/src/gcm-viewer.c
+++ b/src/gcm-viewer.c
@@ -38,6 +38,8 @@
#include "gcm-color.h"
#include "gcm-debug.h"
+static guint xid = 0;
+
typedef struct {
GtkBuilder *builder;
GtkApplication *application;
@@ -103,7 +105,7 @@ gcm_viewer_error_dialog (GcmViewerPrivate *viewer, const gchar *title, const gch
static void
gcm_viewer_close_cb (GtkWidget *widget, GcmViewerPrivate *viewer)
{
- gtk_application_quit (viewer->application);
+ g_application_release (G_APPLICATION (viewer->application));
}
/**
@@ -479,14 +481,14 @@ out:
* gcm_window_set_parent_xid:
**/
static void
-gcm_window_set_parent_xid (GtkWindow *window, guint32 xid)
+gcm_window_set_parent_xid (GtkWindow *window, guint32 _xid)
{
GdkDisplay *display;
GdkWindow *parent_window;
GdkWindow *our_window;
display = gdk_display_get_default ();
- parent_window = gdk_window_foreign_new_for_display (display, xid);
+ parent_window = gdk_window_foreign_new_for_display (display, _xid);
if (parent_window == NULL) {
g_warning ("failed to get parent window");
return;
@@ -1020,47 +1022,28 @@ gcm_viewer_setup_graph_combobox (GcmViewerPrivate *viewer, GtkWidget *widget)
}
/**
- * main:
+ * gcm_viewer_activate_cb:
**/
-int
-main (int argc, char **argv)
+static void
+gcm_viewer_activate_cb (GApplication *application, GcmViewerPrivate *viewer)
+{
+ GtkWindow *window;
+ window = GTK_WINDOW (gtk_builder_get_object (viewer->builder, "dialog_viewer"));
+ gtk_window_present (window);
+}
+
+/**
+ * gcm_viewer_startup_cb:
+ **/
+static void
+gcm_viewer_startup_cb (GApplication *application, GcmViewerPrivate *viewer)
{
- guint retval = 0;
- GOptionContext *context;
GtkWidget *main_window;
GtkWidget *widget;
- guint xid = 0;
GError *error = NULL;
GtkTreeSelection *selection;
GdkScreen *screen;
- GcmViewerPrivate *viewer;
-
- const GOptionEntry options[] = {
- { "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
- /* TRANSLATORS: we can make this modal (stay on top of) another window */
- _("Set the parent window to make this modal"), NULL },
- { NULL}
- };
-
- setlocale (LC_ALL, "");
-
- bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
-
- gtk_init (&argc, &argv);
-
- context = g_option_context_new ("gnome-color-manager prefs program");
- g_option_context_add_main_entries (context, options, NULL);
- g_option_context_add_group (context, gcm_debug_get_option_group ());
- g_option_context_add_group (context, gtk_get_option_group (TRUE));
- g_option_context_parse (context, &argc, &argv, NULL);
- g_option_context_free (context);
-
- viewer = g_new0 (GcmViewerPrivate, 1);
-
- /* ensure single instance */
- viewer->application = gtk_application_new ("org.gnome.ColorManager.Profile", &argc, &argv);
+ gint retval;
/* setup defaults */
viewer->settings = g_settings_new (GCM_SETTINGS_SCHEMA);
@@ -1215,10 +1198,54 @@ main (int argc, char **argv)
/* do all this after the window has been set up */
g_idle_add ((GSourceFunc) gcm_viewer_startup_phase1_idle_cb, viewer);
+out:
+ return;
+}
+
+/**
+ * main:
+ **/
+int
+main (int argc, char **argv)
+{
+ GOptionContext *context;
+ GcmViewerPrivate *viewer;
+ int status = 0;
+
+ const GOptionEntry options[] = {
+ { "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
+ /* TRANSLATORS: we can make this modal (stay on top of) another window */
+ _("Set the parent window to make this modal"), NULL },
+ { NULL}
+ };
+
+ setlocale (LC_ALL, "");
+
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ gtk_init (&argc, &argv);
+
+ context = g_option_context_new ("gnome-color-manager prefs program");
+ g_option_context_add_main_entries (context, options, NULL);
+ g_option_context_add_group (context, gcm_debug_get_option_group ());
+ g_option_context_add_group (context, gtk_get_option_group (TRUE));
+ g_option_context_parse (context, &argc, &argv, NULL);
+ g_option_context_free (context);
+
+ viewer = g_new0 (GcmViewerPrivate, 1);
+
+ /* ensure single instance */
+ viewer->application = gtk_application_new ("org.gnome.ColorManager.Profile", 0);
+ g_signal_connect (viewer->application, "startup",
+ G_CALLBACK (gcm_viewer_startup_cb), viewer);
+ g_signal_connect (viewer->application, "activate",
+ G_CALLBACK (gcm_viewer_activate_cb), viewer);
/* wait */
- gtk_application_run (viewer->application);
-out:
+ status = g_application_run (G_APPLICATION (viewer->application), argc, argv);
+
g_object_unref (viewer->application);
if (viewer->settings != NULL)
g_object_unref (viewer->settings);
@@ -1227,5 +1254,5 @@ out:
if (viewer->profile_store != NULL)
g_object_unref (viewer->profile_store);
g_free (viewer);
- return retval;
+ return status;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]