From b65a74287bf28bec6e020af51a34e123c670b531 Mon Sep 17 00:00:00 2001 From: Perberos Date: Tue, 8 Nov 2011 14:30:53 -0300 Subject: renaming from gcalctool to mate-conf --- src/Makefile.am | 32 +++---- src/currency.c | 4 +- src/gcalccmd.c | 98 ------------------- src/gcalctool.c | 260 --------------------------------------------------- src/mate-calc-cmd.c | 98 +++++++++++++++++++ src/mate-conf.c | 260 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/math-variables.c | 14 +-- src/math-window.c | 32 +++---- 8 files changed, 399 insertions(+), 399 deletions(-) delete mode 100644 src/gcalccmd.c delete mode 100644 src/gcalctool.c create mode 100644 src/mate-calc-cmd.c create mode 100644 src/mate-conf.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index ce63954..c01c037 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,17 +1,17 @@ -bin_PROGRAMS = gcalctool gcalccmd +bin_PROGRAMS = mate-calc mate-calc-cmd INCLUDES = \ - -DUI_DIR=\""$(datadir)/gcalctool"\" \ + -DUI_DIR=\""$(datadir)/mate-calc"\" \ -DVERSION=\""$(VERSION)"\" \ -DLOCALE_DIR=\""$(localedir)"\" \ -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \ $(WARN_CFLAGS) \ - $(GCALCTOOL_CFLAGS) + $(MATE_CALC_CFLAGS) -gcalctool_SOURCES = \ +mate_calc_SOURCES = \ currency.c \ currency.h \ - gcalctool.c \ + mate-calc.c \ math-buttons.c \ math-buttons.h \ math-display.c \ @@ -42,11 +42,11 @@ gcalctool_SOURCES = \ unittest.c \ unittest.h -gcalctool_LDADD = \ - $(GCALCTOOL_LIBS) +mate_calc_LDADD = \ + $(MATE_CALC_LIBS) -gcalccmd_SOURCES = \ - gcalccmd.c \ +mate_calc_cmd_SOURCES = \ + mate-calc-cmd.c \ mp.c \ mp-convert.c \ mp-binary.c \ @@ -55,8 +55,8 @@ gcalccmd_SOURCES = \ mp-equation-parser.c \ mp-equation-lexer.c -gcalccmd_LDADD = \ - $(GCALCCMD_LIBS) \ +mate_calc_cmd_LDADD = \ + $(MATE_CALC_CMD_LIBS) \ -lm CLEANFILES = \ @@ -78,12 +78,12 @@ mp-equation-parser.o: mp-equation-lexer.h mp-equation-lexer.o: mp-equation-parser.h mp-equation.c: mp-equation-lexer.h mp-equation-parser.h -# Install a symlink between gcalctool and mate-calculator +# Install a symlink between mate-calc and mate-calculator install-exec-hook: test -e "$(DESTDIR)$(bindir)/mate-calculator" \ - || (cd "$(DESTDIR)$(bindir)" && ln -s gcalctool mate-calculator) + || (cd "$(DESTDIR)$(bindir)" && ln -s mate-calc mate-calculator) -# Remove the symlink between gcalctool and mate-calculator +# Remove the symlink between mate-calc and mate-calculator uninstall-local: test -h "$(DESTDIR)$(bindir)/mate-calculator" \ && rm -f "$(DESTDIR)$(bindir)/mate-calculator" @@ -95,5 +95,5 @@ EXTRA_DIST = \ DISTCLEANFILES = \ Makefile.in -test: gcalctool - ./gcalctool -u +test: mate-calc + ./mate-calc -u diff --git a/src/currency.c b/src/currency.c index 1900a58..4029763 100644 --- a/src/currency.c +++ b/src/currency.c @@ -25,7 +25,7 @@ static char* get_rate_filepath() { return g_build_filename(g_get_user_cache_dir (), - "gcalctool", + "mate-calc", "eurofxref-daily.xml", NULL); } @@ -211,7 +211,7 @@ currency_convert(const MPNumber *from_amount, } if (!loaded_rates) currency_load_rates(); - + from_index = currency_get_index(source_currency); to_index = currency_get_index(target_currency); if (from_index < 0 || to_index < 0) diff --git a/src/gcalccmd.c b/src/gcalccmd.c deleted file mode 100644 index 9af9a58..0000000 --- a/src/gcalccmd.c +++ /dev/null @@ -1,98 +0,0 @@ -/* $Header$ - * - * Copyright (c) 2009 Rich Burridge - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include -#include -#include -#include -#include - -#include "mp-equation.h" - -#define MAXLINE 1024 - -static void -solve(const char *equation) -{ - int ret; - MPEquationOptions options; - MPNumber z; - char result_str[MAXLINE]; - - memset(&options, 0, sizeof(options)); - options.base = 10; - options.wordlen = 32; - options.angle_units = MP_DEGREES; - - ret = mp_equation_parse(equation, &options, &z, NULL); - - if (ret == PARSER_ERR_MP) - fprintf(stderr, "Error %s\n", mp_get_error()); - else if (ret) - fprintf(stderr, "Error %d\n", ret); - else { - mp_cast_to_string(&z, 10, 10, 9, 1, result_str, MAXLINE); - printf("%s\n", result_str); - } -} - - -/* Adjust user input equation string before solving it. */ -static void -str_adjust(char *str) -{ - int i, j = 0; - - str[strlen(str)-1] = '\0'; /* Remove newline at end of string. */ - for (i = 0; str[i] != '\0'; i++) { /* Remove whitespace. */ - if (str[i] != ' ' && str[i] != '\t') - str[j++] = str[i]; - } - str[j] = '\0'; - if (j > 0 && str[j-1] == '=') /* Remove trailing '=' (if present). */ - str[j-1] = '\0'; -} - -int -main(int argc, char **argv) -{ - char *equation, *line; - size_t nbytes = MAXLINE; - - /* Seed random number generator. */ - srand48((long) time((time_t *) 0)); - - equation = (char *) malloc(MAXLINE * sizeof(char)); - while (1) { - printf("> "); - line = fgets(equation, nbytes, stdin); - - if (line != NULL) - str_adjust(equation); - - if (line == NULL || strcmp(equation, "exit") == 0 || strcmp(equation, "quit") == 0 || strlen(equation) == 0) - break; - - solve(equation); - } - free(equation); - - return 0; -} diff --git a/src/gcalctool.c b/src/gcalctool.c deleted file mode 100644 index 4e40f6a..0000000 --- a/src/gcalctool.c +++ /dev/null @@ -1,260 +0,0 @@ -/* Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2008-2009 Robert Ancell - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include -#include -#include - -#include "currency.h" -#include "unittest.h" -#include "math-window.h" -#include "mp-equation.h" - -static GSettings *settings = NULL; - -static MathWindow *window; - -static void -version(const gchar *progname) -{ - /* NOTE: Is not translated so can be easily parsed */ - fprintf(stderr, "%1$s %2$s\n", progname, VERSION); -} - - -static void -solve(const char *equation) -{ - MPEquationOptions options; - MPErrorCode error; - MPNumber result; - char result_str[1024]; - - memset(&options, 0, sizeof(options)); - options.base = 10; - options.wordlen = 32; - options.angle_units = MP_DEGREES; - - error = mp_equation_parse(equation, &options, &result, NULL); - if(error == PARSER_ERR_MP) { - fprintf(stderr, "Error: %s\n", mp_get_error()); - exit(1); - } - else if(error != 0) { - fprintf(stderr, "Error: %s\n", mp_error_code_to_string(error)); - exit(1); - } - else { - mp_cast_to_string(&result, 10, 10, 9, 1, result_str, 1024); - printf("%s\n", result_str); - exit(0); - } -} - - -static void -usage(const gchar *progname, gboolean show_application, gboolean show_gtk) -{ - fprintf(stderr, - /* Description on how to use gcalctool displayed on command-line */ - _("Usage:\n" - " %s — Perform mathematical calculations"), progname); - - fprintf(stderr, - "\n\n"); - - fprintf(stderr, - /* Description on gcalctool command-line help options displayed on command-line */ - _("Help Options:\n" - " -v, --version Show release version\n" - " -h, -?, --help Show help options\n" - " --help-all Show all help options\n" - " --help-gtk Show GTK+ options")); - fprintf(stderr, - "\n\n"); - - if (show_gtk) { - fprintf(stderr, - /* Description on gcalctool command-line GTK+ options displayed on command-line */ - _("GTK+ Options:\n" - " --class=CLASS Program class as used by the window manager\n" - " --name=NAME Program name as used by the window manager\n" - " --screen=SCREEN X screen to use\n" - " --sync Make X calls synchronous\n" - " --gtk-module=MODULES Load additional GTK+ modules\n" - " --g-fatal-warnings Make all warnings fatal")); - fprintf(stderr, - "\n\n"); - } - - if (show_application) { - fprintf(stderr, - /* Description on gcalctool application options displayed on command-line */ - _("Application Options:\n" - " -u, --unittest Perform unit tests\n" - " -s, --solve Solve the given equation")); - fprintf(stderr, - "\n\n"); - } -} - - -static void -get_options(int argc, char *argv[]) -{ - int i; - char *progname, *arg; - - progname = g_path_get_basename(argv[0]); - - for (i = 1; i < argc; i++) { - arg = argv[i]; - - if (strcmp(arg, "-v") == 0 || - strcmp(arg, "--version") == 0) { - version(progname); - exit(0); - } - else if (strcmp(arg, "-h") == 0 || - strcmp(arg, "-?") == 0 || - strcmp(arg, "--help") == 0) { - usage(progname, TRUE, FALSE); - exit(0); - } - else if (strcmp(arg, "--help-all") == 0) { - usage(progname, TRUE, TRUE); - exit(0); - } - else if (strcmp(arg, "--help-gtk") == 0) { - usage(progname, FALSE, TRUE); - exit(0); - } - else if (strcmp(arg, "-s") == 0 || - strcmp(arg, "--solve") == 0) { - i++; - if (i >= argc) { - fprintf(stderr, - /* Error printed to stderr when user uses --solve argument without an equation */ - _("Argument --solve requires an equation to solve")); - fprintf(stderr, "\n"); - exit(1); - } - else - solve(argv[i]); - } - else if (strcmp(arg, "-u") == 0 || - strcmp(arg, "--unittest") == 0) { - unittest(); - } - else { - fprintf(stderr, - /* Error printed to stderr when user provides an unknown command-line argument */ - _("Unknown argument '%s'"), arg); - fprintf(stderr, "\n"); - usage(progname, TRUE, FALSE); - exit(1); - } - } -} - - -static void -quit_cb(MathWindow *window) -{ - MathEquation *equation; - MathButtons *buttons; - - equation = math_window_get_equation(window); - buttons = math_window_get_buttons(window); - - g_settings_set_int(settings, "accuracy", math_equation_get_accuracy(equation)); - g_settings_set_int(settings, "word-size", math_equation_get_word_size(equation)); - g_settings_set_int(settings, "base", math_buttons_get_programming_base(buttons)); - g_settings_set_boolean(settings, "show-thousands", math_equation_get_show_thousands_separators(equation)); - g_settings_set_boolean(settings, "show-zeroes", math_equation_get_show_trailing_zeroes(equation)); - g_settings_set_enum(settings, "number-format", math_equation_get_number_format(equation)); - g_settings_set_enum(settings, "angle-units", math_equation_get_angle_units(equation)); - g_settings_set_enum(settings, "button-mode", math_buttons_get_mode(buttons)); - g_settings_set_string(settings, "source-currency", math_equation_get_source_currency(equation)); - g_settings_set_string(settings, "target-currency", math_equation_get_target_currency(equation)); - g_settings_sync(); - - currency_free_resources(); - gtk_main_quit(); -} - - -int -main(int argc, char **argv) -{ - MathEquation *equation; - int accuracy = 9, word_size = 64, base = 10; - gboolean show_tsep = FALSE, show_zeroes = FALSE; - DisplayFormat number_format; - MPAngleUnit angle_units; - ButtonMode button_mode; - gchar *source_currency, *target_currency; - - g_type_init(); - - 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.mate.gcalctool"); - accuracy = g_settings_get_int(settings, "accuracy"); - word_size = g_settings_get_int(settings, "word-size"); - base = g_settings_get_int(settings, "base"); - show_tsep = g_settings_get_boolean(settings, "show-thousands"); - show_zeroes = g_settings_get_boolean(settings, "show-zeroes"); - number_format = g_settings_get_enum(settings, "number-format"); - angle_units = g_settings_get_enum(settings, "angle-units"); - button_mode = g_settings_get_enum(settings, "button-mode"); - source_currency = g_settings_get_string(settings, "source-currency"); - target_currency = g_settings_get_string(settings, "target-currency"); - - equation = math_equation_new(); - math_equation_set_accuracy(equation, accuracy); - math_equation_set_word_size(equation, word_size); - math_equation_set_show_thousands_separators(equation, show_tsep); - math_equation_set_show_trailing_zeroes(equation, show_zeroes); - math_equation_set_number_format(equation, number_format); - math_equation_set_angle_units(equation, angle_units); - math_equation_set_source_currency(equation, source_currency); - math_equation_set_target_currency(equation, target_currency); - g_free(source_currency); - g_free(target_currency); - - gtk_init(&argc, &argv); - - window = math_window_new(equation); - g_signal_connect(G_OBJECT(window), "quit", G_CALLBACK(quit_cb), NULL); - math_buttons_set_programming_base(math_window_get_buttons(window), base); - math_buttons_set_mode(math_window_get_buttons(window), button_mode); // FIXME: We load the basic buttons even if we immediately switch to the next type - - gtk_widget_show(GTK_WIDGET(window)); - gtk_main(); - - return(0); -} diff --git a/src/mate-calc-cmd.c b/src/mate-calc-cmd.c new file mode 100644 index 0000000..9af9a58 --- /dev/null +++ b/src/mate-calc-cmd.c @@ -0,0 +1,98 @@ +/* $Header$ + * + * Copyright (c) 2009 Rich Burridge + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include +#include +#include +#include +#include + +#include "mp-equation.h" + +#define MAXLINE 1024 + +static void +solve(const char *equation) +{ + int ret; + MPEquationOptions options; + MPNumber z; + char result_str[MAXLINE]; + + memset(&options, 0, sizeof(options)); + options.base = 10; + options.wordlen = 32; + options.angle_units = MP_DEGREES; + + ret = mp_equation_parse(equation, &options, &z, NULL); + + if (ret == PARSER_ERR_MP) + fprintf(stderr, "Error %s\n", mp_get_error()); + else if (ret) + fprintf(stderr, "Error %d\n", ret); + else { + mp_cast_to_string(&z, 10, 10, 9, 1, result_str, MAXLINE); + printf("%s\n", result_str); + } +} + + +/* Adjust user input equation string before solving it. */ +static void +str_adjust(char *str) +{ + int i, j = 0; + + str[strlen(str)-1] = '\0'; /* Remove newline at end of string. */ + for (i = 0; str[i] != '\0'; i++) { /* Remove whitespace. */ + if (str[i] != ' ' && str[i] != '\t') + str[j++] = str[i]; + } + str[j] = '\0'; + if (j > 0 && str[j-1] == '=') /* Remove trailing '=' (if present). */ + str[j-1] = '\0'; +} + +int +main(int argc, char **argv) +{ + char *equation, *line; + size_t nbytes = MAXLINE; + + /* Seed random number generator. */ + srand48((long) time((time_t *) 0)); + + equation = (char *) malloc(MAXLINE * sizeof(char)); + while (1) { + printf("> "); + line = fgets(equation, nbytes, stdin); + + if (line != NULL) + str_adjust(equation); + + if (line == NULL || strcmp(equation, "exit") == 0 || strcmp(equation, "quit") == 0 || strlen(equation) == 0) + break; + + solve(equation); + } + free(equation); + + return 0; +} diff --git a/src/mate-conf.c b/src/mate-conf.c new file mode 100644 index 0000000..ccc74bd --- /dev/null +++ b/src/mate-conf.c @@ -0,0 +1,260 @@ +/* Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2008-2009 Robert Ancell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include +#include +#include + +#include "currency.h" +#include "unittest.h" +#include "math-window.h" +#include "mp-equation.h" + +static GSettings *settings = NULL; + +static MathWindow *window; + +static void +version(const gchar *progname) +{ + /* NOTE: Is not translated so can be easily parsed */ + fprintf(stderr, "%1$s %2$s\n", progname, VERSION); +} + + +static void +solve(const char *equation) +{ + MPEquationOptions options; + MPErrorCode error; + MPNumber result; + char result_str[1024]; + + memset(&options, 0, sizeof(options)); + options.base = 10; + options.wordlen = 32; + options.angle_units = MP_DEGREES; + + error = mp_equation_parse(equation, &options, &result, NULL); + if(error == PARSER_ERR_MP) { + fprintf(stderr, "Error: %s\n", mp_get_error()); + exit(1); + } + else if(error != 0) { + fprintf(stderr, "Error: %s\n", mp_error_code_to_string(error)); + exit(1); + } + else { + mp_cast_to_string(&result, 10, 10, 9, 1, result_str, 1024); + printf("%s\n", result_str); + exit(0); + } +} + + +static void +usage(const gchar *progname, gboolean show_application, gboolean show_gtk) +{ + fprintf(stderr, + /* Description on how to use mate-calc displayed on command-line */ + _("Usage:\n" + " %s — Perform mathematical calculations"), progname); + + fprintf(stderr, + "\n\n"); + + fprintf(stderr, + /* Description on mate-calc command-line help options displayed on command-line */ + _("Help Options:\n" + " -v, --version Show release version\n" + " -h, -?, --help Show help options\n" + " --help-all Show all help options\n" + " --help-gtk Show GTK+ options")); + fprintf(stderr, + "\n\n"); + + if (show_gtk) { + fprintf(stderr, + /* Description on mate-calc command-line GTK+ options displayed on command-line */ + _("GTK+ Options:\n" + " --class=CLASS Program class as used by the window manager\n" + " --name=NAME Program name as used by the window manager\n" + " --screen=SCREEN X screen to use\n" + " --sync Make X calls synchronous\n" + " --gtk-module=MODULES Load additional GTK+ modules\n" + " --g-fatal-warnings Make all warnings fatal")); + fprintf(stderr, + "\n\n"); + } + + if (show_application) { + fprintf(stderr, + /* Description on mate-calc application options displayed on command-line */ + _("Application Options:\n" + " -u, --unittest Perform unit tests\n" + " -s, --solve Solve the given equation")); + fprintf(stderr, + "\n\n"); + } +} + + +static void +get_options(int argc, char *argv[]) +{ + int i; + char *progname, *arg; + + progname = g_path_get_basename(argv[0]); + + for (i = 1; i < argc; i++) { + arg = argv[i]; + + if (strcmp(arg, "-v") == 0 || + strcmp(arg, "--version") == 0) { + version(progname); + exit(0); + } + else if (strcmp(arg, "-h") == 0 || + strcmp(arg, "-?") == 0 || + strcmp(arg, "--help") == 0) { + usage(progname, TRUE, FALSE); + exit(0); + } + else if (strcmp(arg, "--help-all") == 0) { + usage(progname, TRUE, TRUE); + exit(0); + } + else if (strcmp(arg, "--help-gtk") == 0) { + usage(progname, FALSE, TRUE); + exit(0); + } + else if (strcmp(arg, "-s") == 0 || + strcmp(arg, "--solve") == 0) { + i++; + if (i >= argc) { + fprintf(stderr, + /* Error printed to stderr when user uses --solve argument without an equation */ + _("Argument --solve requires an equation to solve")); + fprintf(stderr, "\n"); + exit(1); + } + else + solve(argv[i]); + } + else if (strcmp(arg, "-u") == 0 || + strcmp(arg, "--unittest") == 0) { + unittest(); + } + else { + fprintf(stderr, + /* Error printed to stderr when user provides an unknown command-line argument */ + _("Unknown argument '%s'"), arg); + fprintf(stderr, "\n"); + usage(progname, TRUE, FALSE); + exit(1); + } + } +} + + +static void +quit_cb(MathWindow *window) +{ + MathEquation *equation; + MathButtons *buttons; + + equation = math_window_get_equation(window); + buttons = math_window_get_buttons(window); + + g_settings_set_int(settings, "accuracy", math_equation_get_accuracy(equation)); + g_settings_set_int(settings, "word-size", math_equation_get_word_size(equation)); + g_settings_set_int(settings, "base", math_buttons_get_programming_base(buttons)); + g_settings_set_boolean(settings, "show-thousands", math_equation_get_show_thousands_separators(equation)); + g_settings_set_boolean(settings, "show-zeroes", math_equation_get_show_trailing_zeroes(equation)); + g_settings_set_enum(settings, "number-format", math_equation_get_number_format(equation)); + g_settings_set_enum(settings, "angle-units", math_equation_get_angle_units(equation)); + g_settings_set_enum(settings, "button-mode", math_buttons_get_mode(buttons)); + g_settings_set_string(settings, "source-currency", math_equation_get_source_currency(equation)); + g_settings_set_string(settings, "target-currency", math_equation_get_target_currency(equation)); + g_settings_sync(); + + currency_free_resources(); + gtk_main_quit(); +} + + +int +main(int argc, char **argv) +{ + MathEquation *equation; + int accuracy = 9, word_size = 64, base = 10; + gboolean show_tsep = FALSE, show_zeroes = FALSE; + DisplayFormat number_format; + MPAngleUnit angle_units; + ButtonMode button_mode; + gchar *source_currency, *target_currency; + + g_type_init(); + + 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.mate.mate-calc"); + accuracy = g_settings_get_int(settings, "accuracy"); + word_size = g_settings_get_int(settings, "word-size"); + base = g_settings_get_int(settings, "base"); + show_tsep = g_settings_get_boolean(settings, "show-thousands"); + show_zeroes = g_settings_get_boolean(settings, "show-zeroes"); + number_format = g_settings_get_enum(settings, "number-format"); + angle_units = g_settings_get_enum(settings, "angle-units"); + button_mode = g_settings_get_enum(settings, "button-mode"); + source_currency = g_settings_get_string(settings, "source-currency"); + target_currency = g_settings_get_string(settings, "target-currency"); + + equation = math_equation_new(); + math_equation_set_accuracy(equation, accuracy); + math_equation_set_word_size(equation, word_size); + math_equation_set_show_thousands_separators(equation, show_tsep); + math_equation_set_show_trailing_zeroes(equation, show_zeroes); + math_equation_set_number_format(equation, number_format); + math_equation_set_angle_units(equation, angle_units); + math_equation_set_source_currency(equation, source_currency); + math_equation_set_target_currency(equation, target_currency); + g_free(source_currency); + g_free(target_currency); + + gtk_init(&argc, &argv); + + window = math_window_new(equation); + g_signal_connect(G_OBJECT(window), "quit", G_CALLBACK(quit_cb), NULL); + math_buttons_set_programming_base(math_window_get_buttons(window), base); + math_buttons_set_mode(math_window_get_buttons(window), button_mode); // FIXME: We load the basic buttons even if we immediately switch to the next type + + gtk_widget_show(GTK_WIDGET(window)); + gtk_main(); + + return(0); +} diff --git a/src/math-variables.c b/src/math-variables.c index b4f7720..47a672a 100644 --- a/src/math-variables.c +++ b/src/math-variables.c @@ -43,24 +43,24 @@ registers_load(MathVariables *variables) { FILE *f; char line[1024]; - + f = fopen(variables->priv->file_name, "r"); if (!f) return; - + g_hash_table_remove_all(variables->priv->registers); while (fgets(line, 1024, f) != NULL) { char *name, *value; MPNumber *t; - + value = strchr(line, '='); if (!value) continue; *value = '\0'; value = value + 1; - + name = g_strstrip(line); value = g_strstrip(value); @@ -89,7 +89,7 @@ registers_save(MathVariables *variables) f = fopen(variables->priv->file_name, "w"); if (!f) return; - + g_hash_table_iter_init(&iter, variables->priv->registers); while (g_hash_table_iter_next(&iter, &key, &val)) { @@ -112,7 +112,7 @@ math_variables_get_names(MathVariables *variables) gpointer key; gint i = 0; gchar **names; - + names = g_malloc0(sizeof(gchar *) * (g_hash_table_size(variables->priv->registers) + 1)); g_hash_table_iter_init(&iter, variables->priv->registers); @@ -158,6 +158,6 @@ math_variables_init(MathVariables *variables) { variables->priv = G_TYPE_INSTANCE_GET_PRIVATE (variables, math_variables_get_type(), MathVariablesPrivate); variables->priv->registers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - variables->priv->file_name = g_build_filename(g_get_user_data_dir(), "gcalctool", "registers", NULL); + variables->priv->file_name = g_build_filename(g_get_user_data_dir(), "mate-calc", "registers", NULL); registers_load(variables); } diff --git a/src/math-window.c b/src/math-window.c index 0daf030..2fc010e 100644 --- a/src/math-window.c +++ b/src/math-window.c @@ -105,7 +105,7 @@ math_window_critical_error(MathWindow *window, const gchar *title, const gchar * static void copy_cb(GtkWidget *widget, MathWindow *window) { - math_equation_copy (window->priv->equation); + math_equation_copy (window->priv->equation); } @@ -161,7 +161,7 @@ help_cb(GtkWidget *widget, MathWindow *window) GError *error = NULL; screen = gtk_widget_get_screen (GTK_WIDGET (window)); - gtk_show_uri (screen, "ghelp:gcalctool", gtk_get_current_event_time (), &error); + gtk_show_uri (screen, "ghelp:mate-calc", gtk_get_current_event_time (), &error); if (error != NULL) { @@ -201,28 +201,28 @@ about_cb(GtkWidget *widget, MathWindow *window) const gchar *translator_credits = _("translator-credits"); /* The license this software is under (GPL2+) */ - char *license = _("Gcalctool is free software; you can redistribute it and/or modify\n" + 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" - "Gcalctool is distributed in the hope that it will be useful,\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 Gcalctool; if not, write to the Free Software Foundation, Inc.,\n" + "along with mate-calc; if not, write to the Free Software Foundation, Inc.,\n" "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA"); gtk_show_about_dialog(GTK_WINDOW(window), "name", /* Program name in the about dialog */ - _("Gcalctool"), + _("mate-calc"), "version", VERSION, "copyright", /* Copyright notice in the about dialog */ - _("\xc2\xa9 1986–2010 The Gcalctool authors"), + _("\xc2\xa9 1986–2010 The mate-calc authors"), "license", license, "comments", /* Short description in the about dialog */ @@ -347,21 +347,21 @@ create_menu(MathWindow *window) GtkAccelGroup *accel_group; GtkWidget *menu, *menu_item; GSList *group = NULL; - + accel_group = gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(window), accel_group); - /* Calculator menu */ + /* Calculator menu */ #define CALCULATOR_MENU_LABEL _("_Calculator") /* Mode menu */ #define MODE_MENU_LABEL _("_Mode") /* Help menu label */ #define HELP_MENU_LABEL _("_Help") - /* Basic menu label */ + /* Basic menu label */ #define MODE_BASIC_LABEL _("_Basic") - /* Advanced menu label */ + /* Advanced menu label */ #define MODE_ADVANCED_LABEL _("_Advanced") - /* Financial menu label */ + /* Financial menu label */ #define MODE_FINANCIAL_LABEL _("_Financial") /* Programming menu label */ #define MODE_PROGRAMMING_LABEL _("_Programming") @@ -403,7 +403,7 @@ create_gui(MathWindow *window) { GtkWidget *main_vbox, *vbox; GtkWidget *scrolled_window; - + main_vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(window), main_vbox); gtk_widget_show(main_vbox); @@ -411,12 +411,12 @@ create_gui(MathWindow *window) window->priv->menu_bar = gtk_menu_bar_new(); gtk_box_pack_start(GTK_BOX(main_vbox), window->priv->menu_bar, TRUE, TRUE, 0); gtk_widget_show(window->priv->menu_bar); - + create_menu(window); vbox = gtk_vbox_new(FALSE, 6); gtk_container_set_border_width(GTK_CONTAINER(vbox), 6); - gtk_box_pack_start(GTK_BOX(main_vbox), vbox, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(main_vbox), vbox, TRUE, TRUE, 0); gtk_widget_show(vbox); scrolled_window = gtk_scrolled_window_new(NULL, NULL); @@ -520,7 +520,7 @@ math_window_init(MathWindow *window) /* Title of main window */ _("Calculator")); gtk_window_set_icon_name(GTK_WINDOW(window), "accessories-calculator"); - gtk_window_set_role(GTK_WINDOW(window), "gcalctool"); + gtk_window_set_role(GTK_WINDOW(window), "mate-calc"); 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); -- cgit v1.2.1