From 48c1564ac5ef431e9111606e40488d04a96f3059 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Fri, 3 Jan 2003 13:26:04 +0000 Subject: Initial revision --- src/Makefile.am | 28 ++ src/calendar.c | 90 +++++ src/entry.c | 94 +++++ src/fileselection.c | 80 +++++ src/main.c | 834 +++++++++++++++++++++++++++++++++++++++++++ src/msg.c | 117 ++++++ src/progress.c | 139 ++++++++ src/text.c | 83 +++++ src/tree.c | 208 +++++++++++ src/util.c | 158 +++++++++ src/util.h | 26 ++ src/zenity.glade | 999 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/zenity.h | 95 +++++ 13 files changed, 2951 insertions(+) create mode 100644 src/Makefile.am create mode 100644 src/calendar.c create mode 100644 src/entry.c create mode 100644 src/fileselection.c create mode 100644 src/main.c create mode 100644 src/msg.c create mode 100644 src/progress.c create mode 100644 src/text.c create mode 100644 src/tree.c create mode 100644 src/util.c create mode 100644 src/util.h create mode 100644 src/zenity.glade create mode 100644 src/zenity.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 00000000..11e0816c --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,28 @@ +bin_PROGRAMS = zenity + +zenity_SOURCES = \ + main.c \ + zenity.h \ + calendar.c \ + msg.c \ + fileselection.c \ + entry.c \ + text.c \ + progress.c \ + tree.c \ + util.h \ + util.c + +INCLUDES = \ + $(ZENITY_CFLAGS) \ + -I$(includedir) \ + -DGNOMELOCALEDIR=\""$(zenitylocaledir)"\" \ + -DZENITY_DATADIR=\""$(datadir)/zenity"\" + +zenity_LDADD = \ + $(ZENITY_LIBS) + +gladedir = $(datadir)/zenity + +glade_DATA = \ + zenity.glade diff --git a/src/calendar.c b/src/calendar.c new file mode 100644 index 00000000..4cdf4811 --- /dev/null +++ b/src/calendar.c @@ -0,0 +1,90 @@ +/* + * calendar.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + */ + +#include +#include "zenity.h" +#include "util.h" + +void zenity_calendar_dialog_response (GtkWindow *window, int button, gpointer data); + +int zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data) +{ + GladeXML *glade_dialog = NULL; + GtkWidget *dialog; + GtkWidget *calendar; + GtkWidget *text; + + glade_dialog = zenity_util_load_glade_file ("zenity_calendar_dialog"); + + if (glade_dialog == NULL) + return FALSE; + + glade_xml_signal_autoconnect (glade_dialog); + + dialog = glade_xml_get_widget (glade_dialog, "zenity_calendar_dialog"); + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else + zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-calendar.png")); + + text = glade_xml_get_widget (glade_dialog, "zenity_calendar_text"); + gtk_label_set_text (GTK_LABEL (text), cal_data->dialog_text); + + calendar = glade_xml_get_widget (glade_dialog, "zenity_calendar"); + + if (cal_data->month != 0 && cal_data->year !=0) + gtk_calendar_select_month (GTK_CALENDAR (calendar), cal_data->month, cal_data->year); + if (cal_data->day) + gtk_calendar_select_day (GTK_CALENDAR (calendar), cal_data->day); + + gtk_label_set_mnemonic_widget (GTK_LABEL (text), calendar); + gtk_widget_show (dialog); + gtk_main (); + + if (glade_dialog) + g_object_unref (glade_dialog); + + return TRUE; +} + +void +zenity_calendar_dialog_response (GtkWindow *window, int button, gpointer data) +{ + GError *error = NULL; + + switch (button) { + case GTK_RESPONSE_OK: + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + gtk_main_quit (); + break; + + default: + break; + } +} diff --git a/src/entry.c b/src/entry.c new file mode 100644 index 00000000..3816a502 --- /dev/null +++ b/src/entry.c @@ -0,0 +1,94 @@ +/* + * entry.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + */ + +#include +#include "zenity.h" +#include "util.h" + +void zenity_entry_dialog_response (GtkWindow *window, int button, gpointer data); + +int zenity_entry (ZenityData *data, ZenityEntryData *entry_data) +{ + GladeXML *glade_dialog = NULL; + GtkWidget *dialog; + GtkWidget *text; + GtkWidget *entry; + + glade_dialog = zenity_util_load_glade_file ("zenity_entry_dialog"); + + if (glade_dialog == NULL) + return FALSE; + + glade_xml_signal_autoconnect (glade_dialog); + + dialog = glade_xml_get_widget (glade_dialog, "zenity_entry_dialog"); + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else + /* FIXME: Come up with a nice default window icon */; + + text = glade_xml_get_widget (glade_dialog, "zenity_entry_text"); + + if (entry_data->dialog_text) + gtk_label_set_text_with_mnemonic (GTK_LABEL (text), entry_data->dialog_text); + + entry = glade_xml_get_widget (glade_dialog, "zenity_entry_input"); + + if (entry_data->entry_text) + gtk_entry_set_text (GTK_ENTRY (entry), entry_data->entry_text); + + if (entry_data->visible == FALSE) + g_object_set (G_OBJECT (entry), "visibility", entry_data->visible, NULL); + + gtk_label_set_mnemonic_widget (GTK_LABEL (text), entry); + + gtk_widget_show (dialog); + gtk_main (); + + if (glade_dialog) + g_object_unref (glade_dialog); + + return TRUE; +} + +void +zenity_entry_dialog_response (GtkWindow *window, int button, gpointer data) +{ + GError *error = NULL; + + switch (button) { + case GTK_RESPONSE_OK: + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + gtk_main_quit (); + break; + + default: + break; + } +} diff --git a/src/fileselection.c b/src/fileselection.c new file mode 100644 index 00000000..52c0021a --- /dev/null +++ b/src/fileselection.c @@ -0,0 +1,80 @@ +/* + * fileselection.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + */ + +#include +#include "zenity.h" +#include "util.h" + +void zenity_fileselection_dialog_response (GtkWindow *window, int button, gpointer data); + +int zenity_fileselection (ZenityData *data, ZenityFileData *file_data) +{ + GladeXML *glade_dialog; + GtkWidget *dialog; + + glade_dialog = zenity_util_load_glade_file ("zenity_fileselection_dialog"); + + if (glade_dialog == NULL) + return FALSE; + + glade_xml_signal_autoconnect (glade_dialog); + + dialog = glade_xml_get_widget (glade_dialog, "zenity_fileselection_dialog"); + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else + zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-file.png")); + + if (file_data->uri) + gtk_file_selection_set_filename (GTK_FILE_SELECTION (dialog), file_data->uri); + + gtk_widget_show (dialog); + gtk_main (); + + if (glade_dialog) + g_object_unref (glade_dialog); + + return TRUE; +} + +void +zenity_fileselection_dialog_response (GtkWindow *window, int button, gpointer data) +{ + GError *error = NULL; + + switch (button) { + case GTK_RESPONSE_OK: + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + gtk_main_quit (); + break; + + default: + break; + } +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 00000000..cf17d7dd --- /dev/null +++ b/src/main.c @@ -0,0 +1,834 @@ +/* + * main.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + */ + +#include "config.h" +#include "zenity.h" +#include + +typedef enum { + MODE_CALENDAR, + MODE_ENTRY, + MODE_ERROR, + MODE_FILE, + MODE_LIST, + MODE_PROGRESS, + MODE_QUESTION, + MODE_TEXTINFO, + MODE_WARNING, + MODE_LAST +} ZenityDialogMode; + +typedef struct { + ZenityDialogMode mode; + ZenityData *data; + + ZenityCalendarData *calendar_data; + ZenityMsgData *msg_data; + ZenityFileData *file_data; + ZenityEntryData *entry_data; + ZenityProgressData *progress_data; + ZenityTextData *text_data; + ZenityTreeData *tree_data; +} ZenityParsingOptions; + +enum { + OPTION_CALENDAR = 1, + OPTION_ENTRY, + OPTION_ERROR, + OPTION_FILE, + OPTION_LIST, + OPTION_PROGRESS, + OPTION_QUESTION, + OPTION_TEXTINFO, + OPTION_WARNING, + OPTION_TITLE, + OPTION_ICON, + OPTION_CALENDARTEXT, + OPTION_DAY, + OPTION_MONTH, + OPTION_YEAR, + OPTION_ENTRYTEXT, + OPTION_INPUTTEXT, + OPTION_HIDETEXT, + OPTION_ERRORTEXT, + OPTION_FILENAME, + OPTION_COLUMN, + OPTION_CHECKLIST, + OPTION_RADIOLIST, + OPTION_PROGRESSTEXT, + OPTION_PERCENTAGE, + OPTION_QUESTIONTEXT, + OPTION_TEXTFILE, + OPTION_WARNINGTEXT, + OPTION_ABOUT, + OPTION_VERSION, + OPTION_LAST, +}; + +static void zenity_parse_options_callback (poptContext ctx, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, + void *data); + +struct poptOption options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "calendar", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_CALENDAR, + N_("Display calendar dialog"), + NULL + }, + { + "entry", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_ENTRY, + N_("Display text entry dialog"), + NULL + }, + { + "error", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_ERROR, + N_("Display error dialog"), + NULL + }, + { + "file-selection", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_FILE, + N_("Display file selection dialog"), + NULL + }, + { + "list", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_LIST, + N_("Display list dialog"), + NULL + }, + { + "progress", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_PROGRESS, + N_("Display progress indication dialog"), + NULL + }, + { + "question", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_QUESTION, + N_("Display question dialog"), + NULL + }, + { + "text-info", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_TEXTINFO, + N_("Display text information dialog"), + NULL + }, + { + "warning", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_WARNING, + N_("Display warning dialog"), + NULL + }, + POPT_TABLEEND +}; + +struct poptOption general_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "title", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_TITLE, + N_("Set the dialog title"), + N_("TITLE") + }, + { + "window-icon", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_ICON, + N_("Set the window icon"), + N_("ICONPATH") + }, + POPT_TABLEEND +}; + +struct poptOption calendar_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "text", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_CALENDARTEXT, + N_("Set the dialog text"), + NULL + }, + { + "day", + '\0', + POPT_ARG_INT, + NULL, + OPTION_DAY, + N_("Set the calendar day"), + NULL + }, + { + "month", + '\0', + POPT_ARG_INT, + NULL, + OPTION_MONTH, + N_("Set the calendar month"), + NULL + }, + { + "year", + '\0', + POPT_ARG_INT, + NULL, + OPTION_YEAR, + N_("Set the calendar year"), + NULL + }, + POPT_TABLEEND +}; + +struct poptOption entry_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "text", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_ENTRYTEXT, + N_("Set the dialog text"), + NULL + }, + { + "entry-text", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_INPUTTEXT, + N_("Set the entry text"), + NULL + }, + { + "hide-text", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_HIDETEXT, + N_("Hide the entry text"), + NULL + }, + POPT_TABLEEND +}; + +struct poptOption error_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "text", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_ERRORTEXT, + N_("Set the dialog text"), + NULL + }, + POPT_TABLEEND +}; + +struct poptOption file_selection_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "filename", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_FILENAME, + N_("Set the filename"), + N_("FILENAME") + }, + POPT_TABLEEND +}; + +struct poptOption list_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "column", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_COLUMN, + N_("Set the column header"), + NULL + }, + { + "checklist", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_CHECKLIST, + N_("Use check boxes for first column"), + NULL + }, + { + "radiolist", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_RADIOLIST, + N_("Use radio buttons for first column"), + NULL + }, + POPT_TABLEEND +}; + +struct poptOption progress_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "text", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_PROGRESSTEXT, + N_("Set the dialog text"), + NULL + }, + { + "percentage", + '\0', + POPT_ARG_INT, + NULL, + OPTION_PERCENTAGE, + N_("Set initial percentage"), + NULL + }, + POPT_TABLEEND +}; + +struct poptOption question_options[] = { + { + "text", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_QUESTIONTEXT, + N_("Set the dialog text"), + NULL + }, + POPT_TABLEEND +}; + +struct poptOption text_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "filename", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_TEXTFILE, + N_("Open file"), + N_("FILENAME") + }, + POPT_TABLEEND +}; + +struct poptOption warning_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "text", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_WARNINGTEXT, + N_("Set the dialog text"), + NULL + }, + POPT_TABLEEND +}; + +struct poptOption miscellaneous_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK | POPT_CBFLAG_POST, + zenity_parse_options_callback, + 0, + NULL, + NULL + }, + { + "about", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_ABOUT, + N_("About zenity"), + NULL + }, + { + "version", + '\0', + POPT_ARG_NONE, + NULL, + OPTION_VERSION, + N_("Print version"), + NULL + }, + POPT_TABLEEND +}; + +struct poptOption application_options[] = { + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + options, + 0, + N_("Dialog options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + general_options, + 0, + N_("General options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + calendar_options, + 0, + N_("Calendar options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + entry_options, + 0, + N_("Text entry options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + error_options, + 0, + N_("Error options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + file_selection_options, + 0, + N_("File selection options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + list_options, + 0, + N_("List options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + progress_options, + 0, + N_("Progress options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + question_options, + 0, + N_("Question options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + text_options, + 0, + N_("Text options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + warning_options, + 0, + N_("Warning options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + miscellaneous_options, + 0, + N_("Miscellaneous options"), + NULL + }, + { + NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + poptHelpOptions, + 0, + N_("Help options"), + NULL + }, + POPT_TABLEEND +}; + +ZenityParsingOptions *results; + +gint +main (gint argc, gchar **argv) { + poptContext ctx; + int nextopt; + ZenityData *general; + ZenityCalendarData *cal_data; + + bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + + results = g_new0 (ZenityParsingOptions, 1); + results->data = g_new0 (ZenityData, 1); + results->calendar_data = g_new0 (ZenityCalendarData, 1); + results->msg_data = g_new0 (ZenityMsgData, 1); + results->file_data = g_new0 (ZenityFileData, 1); + results->entry_data = g_new0 (ZenityEntryData, 1); + results->entry_data->visible = TRUE; + results->progress_data = g_new0 (ZenityProgressData, 1); + results->text_data = g_new0 (ZenityTextData, 1); + results->tree_data = g_new0 (ZenityTreeData, 1); + results->tree_data->checkbox = FALSE; + results->tree_data->radiobox = FALSE; + + /* FIXME: popt doesn't like passing stuff through data + * but it doesn't seem to cope with the data that I try + * to pass in, not quite sure why though. If someone knows + * what I'm doing wrong, we could probably put this back: + * options[0].descrip = (void*) results; + */ + + ctx = poptGetContext ("zenity", argc, (const char **)argv, application_options, 0); + poptSetOtherOptionHelp(ctx, "[OPTIONS] ..."); + poptReadDefaultConfig(ctx, TRUE); + while((nextopt = poptGetNextOpt(ctx)) > 0) + /*nothing*/; + + gtk_init (&argc, &argv); + + if (argc < 2) + exit (1); + + switch (results->mode) { + case MODE_CALENDAR: + zenity_calendar (results->data, results->calendar_data); + break; + case MODE_ENTRY: + zenity_entry (results->data, results->entry_data); + break; + case MODE_ERROR: + case MODE_QUESTION: + case MODE_WARNING: + zenity_msg (results->data, results->msg_data); + break; + case MODE_FILE: + zenity_fileselection (results->data, results->file_data); + break; + case MODE_LIST: + zenity_tree (results->data, results->tree_data); + break; + case MODE_PROGRESS: + zenity_progress (results->data, results->progress_data); + break; + case MODE_TEXTINFO: + zenity_text (results->data, results->text_data); + break; + default: + break; + } + + poptFreeContext(ctx); + exit (0); +} + +static +void zenity_parse_options_callback (poptContext ctx, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, + void *data) +{ + gint i = 0; + if (reason == POPT_CALLBACK_REASON_POST) { + return; + } + else if (reason != POPT_CALLBACK_REASON_OPTION) + return; + + switch (opt->val & POPT_ARG_MASK) { + + case OPTION_CALENDAR: + results->mode = MODE_CALENDAR; + break; + case OPTION_ENTRY: + results->mode = MODE_ENTRY; + break; + case OPTION_ERROR: + results->mode = MODE_ERROR; + results->msg_data->mode = ZENITY_MSG_ERROR; + break; + case OPTION_FILE: + results->mode = MODE_FILE; + break; + case OPTION_LIST: + results->mode = MODE_LIST; + break; + case OPTION_PROGRESS: + results->mode = MODE_PROGRESS; + break; + case OPTION_QUESTION: + results->mode = MODE_QUESTION; + results->msg_data->mode = ZENITY_MSG_QUESTION; + break; + case OPTION_TEXTINFO: + results->mode = MODE_TEXTINFO; + break; + case OPTION_WARNING: + results->mode = MODE_WARNING; + results->msg_data->mode = ZENITY_MSG_WARNING; + break; + case OPTION_TITLE: + results->data->dialog_title = g_strdup (arg); + break; + case OPTION_ICON: + results->data->window_icon = g_strdup (arg); + break; + case OPTION_CALENDARTEXT: + case OPTION_ENTRYTEXT: + case OPTION_ERRORTEXT: + case OPTION_QUESTIONTEXT: + case OPTION_PROGRESSTEXT: + case OPTION_WARNINGTEXT: + switch (results->mode) { + case MODE_CALENDAR: + results->calendar_data->dialog_text = g_strdup (arg); + break; + case MODE_ENTRY: + results->entry_data->dialog_text = g_strdup (arg); + break; + case MODE_ERROR: + case MODE_QUESTION: + case MODE_WARNING: + results->msg_data->dialog_text = g_strdup (arg); + break; + case MODE_PROGRESS: + results->progress_data->dialog_text = g_strdup (arg); + break; + default: + break; + } + break; + case OPTION_DAY: + results->calendar_data->day = atoi (arg); + break; + case OPTION_MONTH: + results->calendar_data->month = atoi (arg); + break; + case OPTION_YEAR: + results->calendar_data->year = atoi (arg); + break; + case OPTION_INPUTTEXT: + results->entry_data->entry_text = g_strdup (arg); + break; + case OPTION_HIDETEXT: + results->entry_data->visible = FALSE; + break; + case OPTION_FILENAME: + case OPTION_TEXTFILE: + switch (results->mode) { + case MODE_FILE: + results->file_data->uri = g_strdup (arg); + break; + case MODE_TEXTINFO: + results->text_data->uri = g_strdup (arg); + break; + default: + break; + } + break; + case OPTION_COLUMN: + break; + case OPTION_CHECKLIST: + results->tree_data->checkbox = TRUE; + break; + case OPTION_RADIOLIST: + results->tree_data->radiobox = TRUE; + break; + case OPTION_PERCENTAGE: + results->progress_data->percentage = atoi (arg); + break; + case OPTION_ABOUT: + results->mode = MODE_LAST; + break; + case OPTION_VERSION: + results->mode = MODE_LAST; + g_print ("%s\n", VERSION); + break; + default: + break; + } +} diff --git a/src/msg.c b/src/msg.c new file mode 100644 index 00000000..a8e5c2de --- /dev/null +++ b/src/msg.c @@ -0,0 +1,117 @@ +/* + * msg.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + */ + +#include +#include "zenity.h" +#include "util.h" + +void zenity_msg_dialog_response (GtkWindow *window, int button, gpointer data); + +int zenity_msg (ZenityData *data, ZenityMsgData *msg_data) +{ + GladeXML *glade_dialog; + GtkWidget *dialog; + GtkWidget *text; + + switch (msg_data->mode) { + + case ZENITY_MSG_WARNING: + glade_dialog = zenity_util_load_glade_file ("zenity_warning_dialog"); + dialog = glade_xml_get_widget (glade_dialog, "zenity_warning_dialog"); + text = glade_xml_get_widget (glade_dialog, "zenity_warning_text"); + break; + + case ZENITY_MSG_QUESTION: + glade_dialog = zenity_util_load_glade_file ("zenity_question_dialog"); + dialog = glade_xml_get_widget (glade_dialog, "zenity_question_dialog"); + text = glade_xml_get_widget (glade_dialog, "zenity_question_text"); + break; + + case ZENITY_MSG_ERROR: + glade_dialog = zenity_util_load_glade_file ("zenity_error_dialog"); + dialog = glade_xml_get_widget (glade_dialog, "zenity_error_dialog"); + text = glade_xml_get_widget (glade_dialog, "zenity_error_text"); + break; + + default: + g_assert_not_reached (); + break; + } + + if (glade_dialog == NULL) + return FALSE; + + glade_xml_signal_autoconnect (glade_dialog); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else { + GdkPixbuf *pixbuf = NULL; + switch (msg_data->mode) { + + case ZENITY_MSG_WARNING: + zenity_util_set_window_icon_from_stock (dialog, GTK_STOCK_DIALOG_WARNING); + break; + case ZENITY_MSG_QUESTION: + zenity_util_set_window_icon_from_stock (dialog, GTK_STOCK_DIALOG_QUESTION); + break; + case ZENITY_MSG_ERROR: + zenity_util_set_window_icon_from_stock (dialog, GTK_STOCK_DIALOG_ERROR); + break; + default: + break; + } + } + + gtk_label_set_text (GTK_LABEL (text), msg_data->dialog_text); + + gtk_widget_show (dialog); + gtk_main (); + + if (glade_dialog) + g_object_unref (glade_dialog); + + return TRUE; +} + +void +zenity_msg_dialog_response (GtkWindow *window, int button, gpointer data) +{ + GError *error = NULL; + + switch (button) { + case GTK_RESPONSE_OK: + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + gtk_main_quit (); + break; + + default: + break; + } +} diff --git a/src/progress.c b/src/progress.c new file mode 100644 index 00000000..21305917 --- /dev/null +++ b/src/progress.c @@ -0,0 +1,139 @@ +/* + * progress.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + */ + +#include +#include +#include "zenity.h" +#include "util.h" + +static guint timer; +static GladeXML *glade_dialog; + +static gboolean zenity_progress_pulsate_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data); +static gboolean zenity_progress_increment_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data); + +void zenity_progress_dialog_response (GtkWindow *window, int button, gpointer data); + +gint +zenity_progress_timeout (gpointer data) +{ + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (data)); + return TRUE; +} + +int zenity_progress (ZenityData *data, ZenityProgressData *progress_data) +{ + GtkWidget *dialog; + GtkWidget *text; + GtkWidget *progress_bar; + GIOChannel *giochannel; + guint input; + + glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog"); + + if (glade_dialog == NULL) + return FALSE; + + glade_xml_signal_autoconnect (glade_dialog); + + dialog = glade_xml_get_widget (glade_dialog, "zenity_progress_dialog"); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else { + zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-progress.png")); + } + + text = glade_xml_get_widget (glade_dialog, "zenity_progress_text"); + gtk_label_set_text (GTK_LABEL (text), progress_data->dialog_text); + + progress_bar = glade_xml_get_widget (glade_dialog, "zenity_progress_bar"); + + giochannel = g_io_channel_unix_new (0); + + if (progress_data->pulsate != TRUE) { + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), progress_data->percentage/100.0); + } + else { + input = g_io_add_watch (giochannel, G_IO_IN | G_IO_HUP, zenity_progress_pulsate_bar, NULL); + timer = gtk_timeout_add (100, zenity_progress_timeout, progress_bar); + } + + g_io_channel_unref (giochannel); + gtk_widget_show (dialog); + gtk_main (); + + if (glade_dialog) + g_object_unref (glade_dialog); + + return TRUE; +} + +static gboolean +zenity_progress_pulsate_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data) +{ + gchar buf[1024]; + + if (!feof (stdin)) { + GtkWidget *button; + gtk_timeout_remove (timer); + g_io_channel_shutdown (giochannel, 0, NULL); + button = glade_xml_get_widget (glade_dialog, "zenity_progress_ok_button"); + gtk_widget_set_sensitive (button, TRUE); + gtk_widget_grab_focus (button); + button = glade_xml_get_widget (glade_dialog, "zenity_progress_cancel_button"); + gtk_widget_set_sensitive (button, FALSE); + return FALSE; + } + + fgets (buf, sizeof (buf)-1, stdin); + return TRUE; +} + +static gboolean +zenity_progress_increment_bar (GIOChannel *giochannel, GIOCondition condition, gpointer data) +{ + /* FIXME: Do nothing at the moment */ +} + +void +zenity_progress_dialog_response (GtkWindow *window, int button, gpointer data) +{ + GError *error = NULL; + + switch (button) { + case GTK_RESPONSE_OK: + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + gtk_main_quit (); + break; + + default: + break; + } +} diff --git a/src/text.c b/src/text.c new file mode 100644 index 00000000..0d2dbe11 --- /dev/null +++ b/src/text.c @@ -0,0 +1,83 @@ +/* + * text.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + */ + +#include +#include "zenity.h" +#include "util.h" + +void zenity_text_dialog_response (GtkWindow *window, int button, gpointer data); + +int zenity_text (ZenityData *data, ZenityTextData *text_data) +{ + GladeXML *glade_dialog = NULL; + GtkWidget *dialog; + GtkWidget *text_view; + GtkTextBuffer *text_buffer; + + glade_dialog = zenity_util_load_glade_file ("zenity_text_dialog"); + + if (glade_dialog == NULL) + return FALSE; + + glade_xml_signal_autoconnect (glade_dialog); + + dialog = glade_xml_get_widget (glade_dialog, "zenity_text_dialog"); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else + ; + + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); + + text_buffer = gtk_text_buffer_new (NULL); + text_view = glade_xml_get_widget (glade_dialog, "zenity_text_view"); + if (zenity_util_fill_file_buffer (text_buffer, text_data->uri)) + gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), text_buffer); + + gtk_widget_show (dialog); + gtk_main (); + + if (glade_dialog) + g_object_unref (glade_dialog); + + return TRUE; +} + +void +zenity_text_dialog_response (GtkWindow *window, int button, gpointer data) +{ + GError *error = NULL; + + switch (button) { + case GTK_RESPONSE_CLOSE: + gtk_main_quit (); + break; + + default: + break; + } +} diff --git a/src/tree.c b/src/tree.c new file mode 100644 index 00000000..c5eef5a4 --- /dev/null +++ b/src/tree.c @@ -0,0 +1,208 @@ +/* + * tree.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + * Jonathan Blanford + * Kristian Rietveld + */ + +#include +#include "zenity.h" +#include "util.h" + +#define MAX_ELEMENTS_BEFORE_SCROLLING 8 + +static GladeXML *glade_dialog; + +enum +{ + NAME_COLUMN, + DESCRIPTION_COLUMN, + N_COLUMNS +}; + +void zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data); + +static void +zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, gpointer data) +{ + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *path; + gboolean value; + + model = GTK_TREE_MODEL (data); + path = gtk_tree_path_new_from_string (path_string); + + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, NAME_COLUMN, &value, -1); + + value = !value; + gtk_list_store_set (GTK_LIST_STORE (model), &iter, NAME_COLUMN, value, -1); + + gtk_tree_path_free (path); +} + +static gboolean +count_rows_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +{ + gint *rows = data; + + (*rows)++; + return FALSE; +} + +static void +zenity_tree_fill_entries (GtkTreeView *tree_view, const **argv) +{ + GtkTreeModel *model; + GtkTreeIter iter; + gint i = 0; + + model = gtk_tree_view_get_model (tree_view); + gtk_tree_model_foreach (model, count_rows_foreach, &i); + + while (i<10) { + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + NAME_COLUMN, "TRUE", + DESCRIPTION_COLUMN, "This is the bar above foobar", + -1); + + if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { + GtkWidget *scrolled_window; + GtkRequisition rectangle; + + gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); + scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); + gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + } + i++; + } +} + +int +zenity_tree (ZenityData *data, ZenityTreeData *tree_data) +{ + GtkWidget *dialog; + GtkWidget *tree_view; + GtkTreeViewColumn *column; + GtkListStore *model; + + glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); + + if (glade_dialog == NULL) + return FALSE; + + glade_xml_signal_autoconnect (glade_dialog); + + dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else + zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); + + tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); + + if (tree_data->checkbox || tree_data->radiobox) + model = gtk_list_store_new (N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING); + else + model = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); + + gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); + + if (tree_data->checkbox) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_toggle_new (); + g_signal_connect (cell_renderer, "toggled", + G_CALLBACK (zenity_tree_toggled_callback), model); + + column = gtk_tree_view_column_new_with_attributes (NULL, + cell_renderer, + "active", NAME_COLUMN, NULL); + } + else if (tree_data->radiobox) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_toggle_new (); + g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); + g_signal_connect (cell_renderer, "toggled", + G_CALLBACK (zenity_tree_toggled_callback), model); + + column = gtk_tree_view_column_new_with_attributes (NULL, + cell_renderer, + "active", NAME_COLUMN, NULL); + + } + else { + column = gtk_tree_view_column_new_with_attributes (tree_data->column_one_header, + gtk_cell_renderer_text_new (), + "text", NAME_COLUMN, NULL); + gtk_tree_view_column_set_sort_column_id (column, NAME_COLUMN); + } + + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + + column = gtk_tree_view_column_new_with_attributes (tree_data->column_two_header, + gtk_cell_renderer_text_new (), + "text", DESCRIPTION_COLUMN, NULL); + gtk_tree_view_column_set_sort_column_id (column, DESCRIPTION_COLUMN); + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); + + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), NULL); + + gtk_widget_show (dialog); + gtk_main (); + + if (glade_dialog) + g_object_unref (glade_dialog); + + return TRUE; +} + +void +zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data) +{ + GError *error = NULL; + + switch (button) { + case GTK_RESPONSE_OK: + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + gtk_main_quit (); + break; + + default: + break; + } +} diff --git a/src/util.c b/src/util.c new file mode 100644 index 00000000..b9116acb --- /dev/null +++ b/src/util.c @@ -0,0 +1,158 @@ +/* + * util.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + * Havoc Pennington + */ + +#include +#include +#include "config.h" +#include "util.h" + +GladeXML* +zenity_util_load_glade_file (const gchar *widget_root) +{ + GladeXML *xml = NULL; + + if (g_file_test (ZENITY_GLADE_FILE_RELATIVEPATH, + G_FILE_TEST_EXISTS)) { + /* Try current dir, for debugging */ + xml = glade_xml_new (ZENITY_GLADE_FILE_RELATIVEPATH, widget_root, GETTEXT_PACKAGE); + } + + if (xml == NULL) + xml = glade_xml_new (ZENITY_GLADE_FILE_FULLPATH, widget_root, GETTEXT_PACKAGE); + + if (xml == NULL) { + g_warning ("Could not load glade file : %s", ZENITY_GLADE_FILE_FULLPATH); + return NULL; + } + + return xml; +} + +gboolean +zenity_util_fill_file_buffer (GtkTextBuffer *buffer, const gchar *filename) +{ + GtkTextIter iter, end; + FILE* f; + gchar buf[2048]; + gint remaining = 0; + + if (filename == NULL) + return FALSE; + + f = fopen (filename, "r"); + + if (f == NULL) { + g_warning ("Cannot open file '%s': %s", filename, g_strerror (errno)); + return FALSE; + } + + gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0); + + while (!feof (f)) { + gint count; + const char *leftover; + int to_read = 2047 - remaining; + + count = fread (buf + remaining, 1, to_read, f); + buf[count + remaining] = '\0'; + + g_utf8_validate (buf, count + remaining, &leftover); + + g_assert (g_utf8_validate (buf, leftover - buf, NULL)); + gtk_text_buffer_insert (buffer, &iter, buf, leftover - buf); + + remaining = (buf + remaining + count) - leftover; + g_memmove (buf, leftover, remaining); + + if (remaining > 6 || count < to_read) + break; + } + + if (remaining) { + g_warning ("Invalid UTF-8 data encountered reading file '%s'", filename); + return FALSE; + } + + /* We had a newline in the buffer to begin with. (The buffer always contains + * a newline, so we delete to the end of the buffer to clean up. + */ + gtk_text_buffer_get_end_iter (buffer, &end); + gtk_text_buffer_delete (buffer, &iter, &end); + + gtk_text_buffer_set_modified (buffer, FALSE); + + return TRUE; +} + +static GList * +zenity_util_list_from_char_array (const char **s) +{ + GList *list = NULL; + gint i; + + for (i = 0; s[i]; i++) { + GdkPixbuf *pixbuf; + + pixbuf = gdk_pixbuf_new_from_file (s[i], NULL); + if (pixbuf) + list = g_list_prepend (list, pixbuf); + } + + return list; +} + +static void +zenity_util_free_list (GList *list) +{ + g_list_foreach (list, (GFunc) g_object_unref, NULL); + g_list_free (list); +} + +void +zenity_util_set_window_icon (GtkWidget *widget, const gchar *filename) +{ + const gchar *filenames[2] = { NULL}; + GList *list; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_WINDOW (widget)); + + if (filename == NULL) + return; + + filenames[0] = filename; + list = zenity_util_list_from_char_array (filenames); + gtk_window_set_icon_list (GTK_WINDOW (widget), list); + zenity_util_free_list (list); +} + +void +zenity_util_set_window_icon_from_stock (GtkWidget *widget, const gchar *stock_id) +{ + GdkPixbuf *pixbuf; + + pixbuf = gtk_widget_render_icon (widget, stock_id, (GtkIconSize) -1, NULL); + gtk_window_set_icon (GTK_WINDOW (widget), pixbuf); + g_object_unref (pixbuf); +} diff --git a/src/util.h b/src/util.h new file mode 100644 index 00000000..3f9d8e1d --- /dev/null +++ b/src/util.h @@ -0,0 +1,26 @@ +#ifndef UTIL_H +#define UTIL_H + +#include +#include + +G_BEGIN_DECLS + +#define ZENITY_GLADE_FILE_FULLPATH ZENITY_DATADIR "/zenity.glade" +#define ZENITY_GLADE_FILE_RELATIVEPATH "./zenity.glade" +#define ZENITY_IMAGE_FULLPATH(filename) (g_strconcat (ZENITY_DATADIR, "/", filename, NULL)) + +GladeXML* zenity_util_load_glade_file (const gchar *widget_root); + +gboolean zenity_util_fill_file_buffer (GtkTextBuffer *buffer, + const gchar *filename); + +void zenity_util_set_window_icon (GtkWidget *widget, + const gchar *filename); + +void zenity_util_set_window_icon_from_stock (GtkWidget *widget, + const gchar *stock_id); + +G_END_DECLS + +#endif /* UTIL_H */ diff --git a/src/zenity.glade b/src/zenity.glade new file mode 100644 index 00000000..27b3cf1b --- /dev/null +++ b/src/zenity.glade @@ -0,0 +1,999 @@ + + + + + + + True + zenity_calendar_dialog_title + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + False + False + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + -6 + + + + + + True + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 6 + True + False + 0 + + + + True + False + 4 + + + + True + zenity_calendar_text + False + True + GTK_JUSTIFY_LEFT + True + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + 12 + True + True + + + + + + True + C_alendar: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + + + + 0 + False + False + + + + + + True + True + GTK_CALENDAR_SHOW_HEADING|GTK_CALENDAR_SHOW_DAY_NAMES + + + 0 + False + False + + + + + 0 + True + True + + + + + + + + True + zenity_warning_dialog_title + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + False + False + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + -6 + + + + + + True + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 13 + True + False + 0 + + + + True + gtk-dialog-warning + 6 + 0 + 0.5 + 0 + 0 + + + 0 + False + True + + + + + + True + zenity_warning_text + False + True + GTK_JUSTIFY_LEFT + True + False + 0.5 + 0.5 + 7 + 0 + + + 0 + False + False + + + + + 0 + True + True + + + + + + + + 10 + True + zenity_fileselection_dialog_text + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + False + False + True + + + + + + True + True + True + True + GTK_RELIEF_NORMAL + + + + + + True + True + True + GTK_RELIEF_NORMAL + + + + + + True + zenity_question_dialog_text + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + False + False + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + -6 + + + + + + True + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 13 + True + False + 0 + + + + True + gtk-dialog-question + 6 + 0 + 0.5 + 0 + 0 + + + 0 + False + True + + + + + + True + zenity_question_text + False + True + GTK_JUSTIFY_LEFT + True + False + 0.5 + 0.5 + 7 + 0 + + + 0 + False + False + + + + + 0 + True + True + + + + + + + + True + zenity_entry_dialog_text + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + False + False + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 6 + True + False + 0 + + + + True + False + 0 + + + + True + zenity_entry_text: + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + + + + 0 + False + False + + + + + + True + True + True + True + 0 + zenity_entry_input + True + * + False + + + 0 + False + False + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + + True + zenity_text_dialog + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + 300 + 200 + True + False + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-close + True + GTK_RELIEF_NORMAL + -7 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 7 + True + False + 0 + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_ETCHED_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + GTK_JUSTIFY_LEFT + GTK_WRAP_WORD + True + 2 + 2 + 0 + 2 + 2 + 0 + zenity_text_view + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + + True + zenity_progress_dialog + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + False + False + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + -6 + + + + + + True + False + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 6 + True + False + 0 + + + + True + False + 5 + + + + True + zenity_progress text + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + GTK_PROGRESS_LEFT_TO_RIGHT + 0 + 0.1 + + + + 0 + False + False + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + + True + zenity_error_dialog + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + False + False + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 6 + True + False + 0 + + + + True + False + 0 + + + + True + gtk-dialog-error + 6 + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + True + zenity_error_text + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + + True + dialog1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + 300 + 200 + True + False + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + -6 + + + + + + True + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 6 + True + False + 0 + + + + True + False + 6 + + + + True + zenity_tree_text + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + diff --git a/src/zenity.h b/src/zenity.h new file mode 100644 index 00000000..1543436b --- /dev/null +++ b/src/zenity.h @@ -0,0 +1,95 @@ +#ifndef ZENITY_H +#define ZENITY_H + +#include + +G_BEGIN_DECLS + +#ifdef ENABLE_NLS +#include +#define _(String) dgettext(GETTEXT_PACKAGE,String) +#ifdef gettext_noop +#define N_(String) gettext_noop(String) +#else +#define N_(String) (String) +#endif +#else /* NLS is disabled */ +#define _(String) (String) +#define N_(String) (String) +#define textdomain(String) (String) +#define gettext(String) (String) +#define dgettext(Domain,String) (String) +#define dcgettext(Domain,String,Type) (String) +#define bindtextdomain(Domain,Directory) (Domain) +#endif + +typedef struct { + gchar *dialog_title; + gchar *window_icon; +} ZenityData; + +typedef struct { + gchar *dialog_text; + gint day; + gint month; + gint year; +} ZenityCalendarData; + +typedef enum { + ZENITY_MSG_WARNING, + ZENITY_MSG_QUESTION, + ZENITY_MSG_ERROR +} MsgMode; + +typedef struct { + gchar *dialog_text; + MsgMode mode; +} ZenityMsgData; + +typedef struct { + gchar *uri; +} ZenityFileData; + +typedef struct { + gchar *dialog_text; + gchar *entry_text; + gboolean visible; +} ZenityEntryData; + +typedef struct { + gchar *dialog_text; + gchar *entry_text; + gboolean pulsate; + gdouble percentage; +} ZenityProgressData; + +typedef struct { + gchar *uri; +} ZenityTextData; + +typedef struct { + gchar *dialog_text; + gchar *column_one_header; + gchar *column_two_header; + gboolean checkbox; + gboolean radiobox; +} ZenityTreeData; + +int zenity_calendar (ZenityData *data, + ZenityCalendarData *calendar_data); +int zenity_msg (ZenityData *data, + ZenityMsgData *msg_data); +int zenity_fileselection (ZenityData *data, + ZenityFileData *file_data); +int zenity_entry (ZenityData *data, + ZenityEntryData *entry_data); +int zenity_progress (ZenityData *data, + ZenityProgressData *progress_data); +int zenity_text (ZenityData *data, + ZenityTextData *text_data); +int zenity_tree (ZenityData *data, + ZenityTreeData *tree_data); + +G_END_DECLS + +#endif /* ZENITY_H */ -- cgit