[gcalctool] Port to GtkApplication
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Port to GtkApplication
- Date: Fri, 27 Apr 2012 03:26:48 +0000 (UTC)
commit 0ff9d46b4004a2d2398a86d84c86c2994356f163
Author: Florian MÃllner <fmuellner gnome org>
Date: Wed Apr 25 20:08:38 2012 +0200
Port to GtkApplication
https://bugzilla.gnome.org/show_bug.cgi?id=674529
src/gcalctool.c | 64 +++++++++++++++++++++++++++++++---------------------
src/math-window.c | 36 +++++------------------------
src/math-window.h | 6 ++--
3 files changed, 48 insertions(+), 58 deletions(-)
---
diff --git a/src/gcalctool.c b/src/gcalctool.c
index c3349b3..14dcb3e 100644
--- a/src/gcalctool.c
+++ b/src/gcalctool.c
@@ -255,14 +255,7 @@ mode_cb(MathButtons *buttons, GParamSpec *spec)
static void
-quit_cb(MathWindow *window)
-{
- gtk_main_quit();
-}
-
-
-int
-main(int argc, char **argv)
+startup_cb(GApplication *application)
{
MathEquation *equation;
MathButtons *buttons;
@@ -274,18 +267,6 @@ main(int argc, char **argv)
gchar *source_currency, *target_currency;
gchar *source_units, *target_units;
- g_type_init();
-
- setlocale(LC_ALL, "");
- bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
- bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
- textdomain(GETTEXT_PACKAGE);
-
- /* Seed random number generator. */
- srand48((long) time((time_t *) 0));
-
- get_options(argc, argv);
-
settings = g_settings_new ("org.gnome.gcalctool");
accuracy = g_settings_get_int(settings, "accuracy");
word_size = g_settings_get_int(settings, "word-size");
@@ -327,18 +308,49 @@ main(int argc, char **argv)
g_signal_connect(equation, "notify::source-units", G_CALLBACK(source_units_cb), NULL);
g_signal_connect(equation, "notify::target-units", G_CALLBACK(target_units_cb), NULL);
- gtk_init(&argc, &argv);
-
- window = math_window_new(equation);
+ window = math_window_new(GTK_APPLICATION(application), equation);
buttons = math_window_get_buttons(window);
- g_signal_connect(G_OBJECT(window), "quit", G_CALLBACK(quit_cb), NULL);
math_buttons_set_programming_base(buttons, base);
math_buttons_set_mode(buttons, button_mode); // FIXME: We load the basic buttons even if we immediately switch to the next type
g_signal_connect(buttons, "notify::programming-base", G_CALLBACK(programming_base_cb), NULL);
g_signal_connect(buttons, "notify::mode", G_CALLBACK(mode_cb), NULL);
gtk_widget_show(GTK_WIDGET(window));
- gtk_main();
+}
+
+
+static void
+activate_cb(GApplication *application)
+{
+ gtk_window_present(GTK_WINDOW(window));
+}
+
+
+int
+main(int argc, char **argv)
+{
+ GtkApplication *app;
+ int status;
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
+ bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+ textdomain(GETTEXT_PACKAGE);
+
+ /* Seed random number generator. */
+ srand48((long) time((time_t *) 0));
+
+ g_type_init();
+
+ get_options(argc, argv);
+
+ gtk_init(&argc, &argv);
+
+ app = gtk_application_new("org.gnome.gcalctool", G_APPLICATION_FLAGS_NONE);
+ g_signal_connect(app, "startup", G_CALLBACK(startup_cb), NULL);
+ g_signal_connect(app, "activate", G_CALLBACK(activate_cb), NULL);
+
+ status = g_application_run(G_APPLICATION(app), argc, argv);
- return(0);
+ return status;
}
diff --git a/src/math-window.c b/src/math-window.c
index 803acd0..7ec4723 100644
--- a/src/math-window.c
+++ b/src/math-window.c
@@ -32,20 +32,15 @@ struct MathWindowPrivate
GtkWidget *mode_basic_menu_item, *mode_advanced_menu_item, *mode_financial_menu_item, *mode_programming_menu_item;
};
-G_DEFINE_TYPE (MathWindow, math_window, GTK_TYPE_WINDOW);
-
-enum
-{
- QUIT,
- LAST_SIGNAL
-};
-static guint signals[LAST_SIGNAL] = { 0, };
+G_DEFINE_TYPE (MathWindow, math_window, GTK_TYPE_APPLICATION_WINDOW);
MathWindow *
-math_window_new(MathEquation *equation)
+math_window_new(GtkApplication *app, MathEquation *equation)
{
- return g_object_new(math_window_get_type(), "equation", equation, NULL);
+ return g_object_new(math_window_get_type(),
+ "application", app,
+ "equation", equation, NULL);
}
@@ -100,7 +95,7 @@ math_window_critical_error(MathWindow *window, const gchar *title, const gchar *
gtk_dialog_run(GTK_DIALOG(dialog));
- g_signal_emit(window, signals[QUIT], 0);
+ gtk_widget_destroy(GTK_WIDGET(window));
}
@@ -241,7 +236,7 @@ about_cb(GtkWidget *widget, MathWindow *window)
static void
quit_cb(GtkWidget *widget, MathWindow *window)
{
- g_signal_emit(window, signals[QUIT], 0);
+ gtk_widget_destroy(GTK_WIDGET(window));
}
@@ -278,13 +273,6 @@ key_press_cb(MathWindow *window, GdkEventKey *event)
static void
-delete_cb(MathWindow *window, GdkEvent *event)
-{
- g_signal_emit(window, signals[QUIT], 0);
-}
-
-
-static void
scroll_changed_cb(GtkAdjustment *adjustment, MathWindow *window)
{
if (window->priv->right_aligned)
@@ -525,15 +513,6 @@ math_window_class_init(MathWindowClass *klass)
"Equation being calculated",
math_equation_get_type(),
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- signals[QUIT] =
- g_signal_new("quit",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (MathWindowClass, quit),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
}
@@ -548,5 +527,4 @@ math_window_init(MathWindow *window)
gtk_window_set_role(GTK_WINDOW(window), "gcalctool");
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
g_signal_connect_after(G_OBJECT(window), "key-press-event", G_CALLBACK(key_press_cb), NULL);
- g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK(delete_cb), NULL);
}
diff --git a/src/math-window.h b/src/math-window.h
index 40caef2..25aa626 100644
--- a/src/math-window.h
+++ b/src/math-window.h
@@ -25,20 +25,20 @@ typedef struct MathWindowPrivate MathWindowPrivate;
typedef struct
{
- GtkWindow parent_instance;
+ GtkApplicationWindow parent_instance;
MathWindowPrivate *priv;
} MathWindow;
typedef struct
{
- GtkWindowClass parent_class;
+ GtkApplicationWindowClass parent_class;
void (*quit)(MathWindow *window);
} MathWindowClass;
GType math_window_get_type(void);
-MathWindow *math_window_new(MathEquation *equation);
+MathWindow *math_window_new(GtkApplication *app, MathEquation *equation);
GtkWidget *math_window_get_menu_bar(MathWindow *window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]