summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c110
1 files changed, 79 insertions, 31 deletions
diff --git a/src/main.c b/src/main.c
index 7f0c2db..01545be 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,120 +1,168 @@
+/* vim: colorcolumn=80 ts=4 sw=4
+ */
/*
* main.c
*
- * Copyright (C) 2002 Sun Microsystems, Inc.
+ * Copyright © 2002 Sun Microsystems, Inc.
+ * Copyright © 2021 Logan Rathbone
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
- * Authors: Glynn Foster <glynn.foster@sun.com>
+ * Original Author: Glynn Foster <glynn.foster@sun.com>
*/
-#include <config.h>
-
#include "option.h"
#include "zenity.h"
-#include <glib.h>
#include <gtk/gtk.h>
-#include <langinfo.h>
-#include <stdlib.h>
-#ifdef HAVE_LOCALE_H
#include <locale.h>
-#endif
-
-gint
-main (gint argc, gchar **argv) {
- ZenityParsingOptions *results;
- gint retval;
+#include <stdlib.h>
-#ifdef HAVE_LOCALE_H
- setlocale (LC_ALL, "");
-#endif
+#include <config.h>
- bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
+typedef struct {
+ int argc;
+ char **argv;
+} ZenityArgs;
- gtk_init (&argc, &argv);
+static void
+command_line_cb (GtkApplication *app,
+ GApplicationCommandLine *command_line,
+ gpointer user_data)
+{
+ ZenityArgs *args = user_data;
+ ZenityParsingOptions *results;
- results = zenity_option_parse (argc, argv);
+ results = zenity_option_parse (args->argc, args->argv);
- switch (results->mode) {
+ switch (results->mode)
+ {
case MODE_CALENDAR:
zenity_calendar (results->data, results->calendar_data);
break;
+
case MODE_ENTRY:
- results->entry_data->data = (const gchar **) argv + 1;
+ /* allow for a series of tokens (or even a bash array!) to be
+ * passed as arguments so as to auto-populate the entry with
+ * a list of options as a combo-box.
+ */
+ results->entry_data->data = (const char **) args->argv + 1;
zenity_entry (results->data, results->entry_data);
break;
+
case MODE_ERROR:
case MODE_QUESTION:
case MODE_WARNING:
case MODE_INFO:
zenity_msg (results->data, results->msg_data);
break;
+
case MODE_SCALE:
zenity_scale (results->data, results->scale_data);
break;
+
case MODE_FILE:
zenity_fileselection (results->data, results->file_data);
break;
+
case MODE_LIST:
- results->tree_data->data = (const gchar **) argv + 1;
+ results->tree_data->data = (const char **) args->argv + 1;
zenity_tree (results->data, results->tree_data);
break;
+
#ifdef HAVE_LIBNOTIFY
case MODE_NOTIFICATION:
zenity_notification (results->data, results->notification_data);
break;
#endif
+
case MODE_PROGRESS:
zenity_progress (results->data, results->progress_data);
break;
+
case MODE_TEXTINFO:
zenity_text (results->data, results->text_data);
break;
+
case MODE_COLOR:
zenity_colorselection (results->data, results->color_data);
break;
+
case MODE_PASSWORD:
zenity_password_dialog (results->data, results->password_data);
break;
+
case MODE_ABOUT:
zenity_about (results->data);
break;
+
case MODE_FORMS:
zenity_forms_dialog (results->data, results->forms_data);
break;
+
case MODE_VERSION:
g_print ("%s\n", VERSION);
break;
+
case MODE_LAST:
g_printerr (_ ("You must specify a dialog type. See 'zenity "
"--help' for details\n"));
zenity_option_free ();
exit (-1);
+
default:
g_assert_not_reached ();
zenity_option_free ();
exit (-1);
}
- retval = results->data->exit_code;
-
zenity_option_free ();
+ g_free (args);
+
+ g_application_command_line_set_exit_status (command_line,
+ results->data->exit_code);
+}
+
+int
+main (int argc, char *argv[])
+{
+ ZenityArgs *args;
+ GtkApplication *app;
+ int status;
+
+ /* boilerplate i18n stuff */
+ setlocale (LC_ALL, "");
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+ /* </i18n> */
+
+ args = g_new (ZenityArgs, 1);
+ args->argc = argc;
+ args->argv = argv;
+
+ app = gtk_application_new ("org.gnome.Zenity",
+ G_APPLICATION_HANDLES_COMMAND_LINE);
+
+ g_signal_connect (app, "command-line",
+ G_CALLBACK(command_line_cb), args);
+
+ status = g_application_run (G_APPLICATION(app), 0, NULL);
+ g_object_unref (app);
- exit (retval);
+ return status;
}