From 3e4dfc47e7803d16d14ffe655f9568871c4f2339 Mon Sep 17 00:00:00 2001 From: Steve Zesch Date: Sat, 24 Nov 2012 20:47:50 -0500 Subject: GTK2 support. Menu fix. Code cleanups. --- src/mate-calc.c | 258 +++++++------------------------------------------------- 1 file changed, 30 insertions(+), 228 deletions(-) (limited to 'src/mate-calc.c') diff --git a/src/mate-calc.c b/src/mate-calc.c index 15efc97..f23ff38 100644 --- a/src/mate-calc.c +++ b/src/mate-calc.c @@ -23,7 +23,6 @@ static GSettings *settings = NULL; static MathWindow *window; -static MathPreferencesDialog *preferences_dialog; static void version(const gchar *progname) @@ -249,12 +248,9 @@ programming_base_cb(MathButtons *buttons, GParamSpec *spec) } -static void -mode_cb(MathButtons *buttons, GParamSpec *spec, GApplication *app) +/*static void +mode_cb(MathButtons *buttons, GParamSpec *spec) { - const char *state; - GAction *action; - g_settings_set_enum(settings, "button-mode", math_buttons_get_mode(buttons)); switch(math_buttons_get_mode(buttons)) @@ -277,162 +273,17 @@ mode_cb(MathButtons *buttons, GParamSpec *spec, GApplication *app) state = "programming"; break; } - - action = g_action_map_lookup_action(G_ACTION_MAP(app), "mode"); - g_simple_action_set_state(G_SIMPLE_ACTION(action), - g_variant_new_string(state)); -} - - -static void -copy_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) -{ - math_equation_copy(math_window_get_equation(window)); -} +}*/ static void -paste_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) +quit_cb(MathWindow *window) { - math_equation_paste(math_window_get_equation(window)); + gtk_main_quit(); } -static void -undo_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) -{ - math_equation_undo(math_window_get_equation(window)); -} - - -static void -redo_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) -{ - math_equation_redo(math_window_get_equation(window)); -} - - -static void -mode_changed_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) -{ - const char *mode_str; - int mode = BASIC; - - mode_str = g_variant_get_string(parameter, NULL); - if (strcmp(mode_str, "basic") == 0) - mode = BASIC; - else if (strcmp(mode_str, "advanced") == 0) - mode = ADVANCED; - else if (strcmp(mode_str, "financial") == 0) - mode = FINANCIAL; - else if (strcmp(mode_str, "programming") == 0) - mode = PROGRAMMING; - math_buttons_set_mode(math_window_get_buttons(window), mode); -} - - -static void -show_preferences_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) -{ - if (!preferences_dialog) { - preferences_dialog = math_preferences_dialog_new(math_window_get_equation(window)); - gtk_window_set_transient_for(GTK_WINDOW(preferences_dialog), GTK_WINDOW(window)); - } - gtk_window_present(GTK_WINDOW(preferences_dialog)); -} - - -static void -help_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) -{ - GdkScreen *screen; - GError *error = NULL; - - screen = gtk_widget_get_screen(GTK_WIDGET(window)); - gtk_show_uri(screen, "help:mate-calc", gtk_get_current_event_time(), &error); - - if (error != NULL) - { - GtkWidget *d; - /* Translators: Error message displayed when unable to launch help browser */ - const char *message = _("Unable to open help file"); - - d = gtk_message_dialog_new(GTK_WINDOW (window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s", message); - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG (d), - "%s", error->message); - g_signal_connect(d, "response", G_CALLBACK(gtk_widget_destroy), NULL); - gtk_window_present(GTK_WINDOW(d)); - - g_error_free(error); - } -} - - -static void -about_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) -{ - const gchar *authors[] = { - "Rich Burridge ", - "Robert Ancell ", - "Klaus Niederkrüger ", - "Robin Sonefors ", - NULL - }; - const gchar *documenters[] = { - "Sun Microsystems", - NULL - }; - - /* The translator credits. Please translate this with your name(s). */ - const gchar *translator_credits = _("translator-credits"); - - /* The license this software is under (GPL2+) */ - char *license = _("mate-calc is free software; you can redistribute it and/or modify\n" - "it under the terms of the GNU General Public License as published by\n" - "the Free Software Foundation; either version 2 of the License, or\n" - "(at your option) any later version.\n" - "\n" - "mate-calc is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - "GNU General Public License for more details.\n" - "\n" - "You should have received a copy of the GNU General Public License\n" - "along with mate-calc; if not, write to the Free Software Foundation, Inc.,\n" - "151 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA"); - - gtk_show_about_dialog(GTK_WINDOW(window), - "name", - /* Program name in the about dialog */ - _("mate-calc"), - "version", VERSION, - "copyright", - /* Copyright notice in the about dialog */ - _("\xc2\xa9 1986–2010 The gcalctool authors\n 2011-2012 mate-calc authors"), - "license", license, - "comments", - /* Short description in the about dialog */ - _("Calculator with financial and scientific modes."), - "authors", authors, - "documenters", documenters, - "translator_credits", translator_credits, - "logo-icon-name", "accessories-calculator", - "website", "http://mate-desktop.org", - NULL); -} - - -static void -quit_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) -{ - gtk_widget_destroy(GTK_WIDGET(window)); -} - - -static GActionEntry app_entries[] = { +/*static GActionEntry app_entries[] = { { "copy", copy_cb, NULL, NULL, NULL }, { "paste", paste_cb, NULL, NULL, NULL }, { "undo", undo_cb, NULL, NULL, NULL }, @@ -442,11 +293,10 @@ static GActionEntry app_entries[] = { { "help", help_cb, NULL, NULL, NULL }, { "about", about_cb, NULL, NULL, NULL }, { "quit", quit_cb, NULL, NULL, NULL }, -}; +};*/ -static void -startup_cb(GApplication *application) +int main(int argc, char **argv) { MathEquation *equation; MathButtons *buttons; @@ -457,7 +307,16 @@ startup_cb(GApplication *application) ButtonMode button_mode; gchar *source_currency, *target_currency; gchar *source_units, *target_units; - GMenu *menu, *section; + + 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)); settings = g_settings_new ("org.mate.calc"); accuracy = g_settings_get_int(settings, "accuracy"); @@ -500,80 +359,23 @@ startup_cb(GApplication *application) 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); - g_action_map_add_action_entries(G_ACTION_MAP(application), app_entries, G_N_ELEMENTS(app_entries), NULL); - - window = math_window_new(GTK_APPLICATION(application), equation); - buttons = math_window_get_buttons(window); - 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), application); - mode_cb (buttons, NULL, application); - - menu = g_menu_new(); - - section = g_menu_new(); - g_menu_append(section, _("Basic"), "app.mode::basic"); - g_menu_append(section, _("Advanced"), "app.mode::advanced"); - g_menu_append(section, _("Financial"), "app.mode::financial"); - g_menu_append(section, _("Programming"), "app.mode::programming"); - g_menu_append_section(menu, _("Mode"), G_MENU_MODEL(section)); - - section = g_menu_new(); - g_menu_append(section, _("Preferences"), "app.preferences"); - g_menu_append_section(menu, NULL, G_MENU_MODEL(section)); - - section = g_menu_new(); - g_menu_append(section, _("About Calculator"), "app.about"); - g_menu_append(section, _("Help"), "app.help"); - g_menu_append(section, _("Quit"), "app.quit"); - g_menu_append_section(menu, NULL, G_MENU_MODEL(section)); - - gtk_application_set_app_menu(GTK_APPLICATION(application), G_MENU_MODEL(menu)); - - gtk_application_add_accelerator(GTK_APPLICATION(application), "Q", "app.quit", NULL); - gtk_application_add_accelerator(GTK_APPLICATION(application), "F1", "app.help", NULL); - gtk_application_add_accelerator(GTK_APPLICATION(application), "C", "app.copy", NULL); - gtk_application_add_accelerator(GTK_APPLICATION(application), "V", "app.paste", NULL); - gtk_application_add_accelerator(GTK_APPLICATION(application), "Z", "app.undo", NULL); - gtk_application_add_accelerator(GTK_APPLICATION(application), "Z", "app.redo", NULL); -} - - -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); - gtk_window_set_default_icon_name("accessories-calculator"); + //gtk_window_set_default_icon_name("accessories-calculator"); - app = gtk_application_new(NULL, G_APPLICATION_NON_UNIQUE); - g_signal_connect(app, "startup", G_CALLBACK(startup_cb), NULL); - g_signal_connect(app, "activate", G_CALLBACK(activate_cb), NULL); + window = math_window_new(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); + //mode_cb (buttons, NULL); - status = g_application_run(G_APPLICATION(app), argc, argv); + gtk_widget_show(GTK_WIDGET(window)); + gtk_main(); - return status; + return 0; } -- cgit v1.2.1