commit 48c1564ac5ef431e9111606e40488d04a96f3059 Author: Glynn Foster Date: Fri Jan 3 13:26:04 2003 +0000 Initial revision diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..30e758d --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Glynn Foster diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..ac8def7 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,4 @@ +2002-12-15 Glynn Foster + + * zenity/*: Initial import into cvs.gnome.org. Don't + expect things to work very well. diff --git a/HACKING b/HACKING new file mode 100644 index 0000000..75114f4 --- /dev/null +++ b/HACKING @@ -0,0 +1,2 @@ +Please send patches to any of the people listed in the MAINTAINERS file +for the moment. diff --git a/MAINTAINERS b/MAINTAINERS new file mode 100644 index 0000000..30e758d --- /dev/null +++ b/MAINTAINERS @@ -0,0 +1 @@ +Glynn Foster diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..b1aa066 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = \ + src \ + data diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..0bac543 --- /dev/null +++ b/README @@ -0,0 +1,3 @@ +This is very beta, unfinished and mostly useless right now. +It's very non-compatible with gdialog. It's also apparently +very Zen. Obviously. diff --git a/TODO b/TODO new file mode 100644 index 0000000..0a59325 --- /dev/null +++ b/TODO @@ -0,0 +1,9 @@ +* Finish off commandline support for list dialog +* Finish off support for progress dialog +* Implement error/return values for all dialogs +* Initialize the ZenityParsingOptions struct properly [nicer way of doing this?] +* Add some accessibility I guess +* Find some nice default window icons +* Implement about box +* Remove extraneous cruft from configure.in +* Start writing help documentation diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..8cc18b2 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +PKG_NAME="zenity" + +(test -f $srcdir/configure.in \ + && test -f $srcdir/ChangeLog \ + && test -d $srcdir/src) || { + echo -n "**Error**: Directory "\`$srcdir\'" does not look like the" + echo " top-level zenity directory" + exit 1 +} + + +which gnome-autogen.sh || { + echo "You need to install gnome-common from the GNOME CVS" + exit 1 +} +USE_GNOME2_MACROS=1 . gnome-autogen.sh diff --git a/configure.in b/configure.in new file mode 100644 index 0000000..e2f23c1 --- /dev/null +++ b/configure.in @@ -0,0 +1,71 @@ +AC_INIT(src) +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE(zenity, 0.1) + +AM_MAINTAINER_MODE + +AC_PROG_INTLTOOL([0.21]) + +dnl ******************************** +dnl I bet I don't need half of these +dnl ******************************** + +AC_ISC_POSIX +AC_PROG_CXX +AC_PROG_CC +AC_PROG_CPP +AC_STDC_HEADERS +AC_PROG_YACC +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +AC_PATH_XTRA + +GNOME_COMPILE_WARNINGS + +PKG_CHECK_MODULES(ZENITY, gtk+-2.0 libglade-2.0) +AC_SUBST(ZENITY_CFLAGS) +AC_SUBST(ZENITY_LIBS) + +AC_CHECK_LIB(popt, poptHelpOptions,, AC_MSG_ERROR([popt is required to build script.])) + +dnl *********************************************** +dnl scrollkeeper checks - don't use these currently +dnl *********************************************** +dnl +dnl AC_PATH_PROG(SCROLLKEEPER_CONFIG, scrollkeeper-config,no) +dnl if test x$SCROLLKEEPER_CONFIG = xno; then +dnl AC_MSG_ERROR(Couldn't find scrollkeeper-config. Please install the scrollkeeper package) +dnl fi + +dnl ******************************* +dnl Internationalization +dnl ******************************* + +ALL_LINGUAS="" +GETTEXT_PACKAGE=zenity-0.1 +AC_SUBST(GETTEXT_PACKAGE) +AM_GLIB_GNU_GETTEXT + +dnl ************************************************************** +dnl AM_GLIB_GNU_GETTEXT above substs $DATADIRNAME +dnl this is the directory where the *.{mo,gmo} files are installed +dnl ************************************************************** + +zenitylocaledir='${prefix}/${DATADIRNAME}/locale' +AC_SUBST(zenitylocaledir) + +AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Finding gettext package]) + +AC_DEFINE_UNQUOTED(GNOME_ICONDIR, "${prefix}/share/pixmaps", [Determining icon location]) + +AC_SUBST(CFLAGS) +AC_SUBST(CPPFLAGS) +AC_SUBST(LDFLAGS) + +AC_OUTPUT([ +Makefile +po/Makefile.in +src/Makefile +data/Makefile +]) diff --git a/data/Makefile.am b/data/Makefile.am new file mode 100644 index 0000000..ef1a1cd --- /dev/null +++ b/data/Makefile.am @@ -0,0 +1,8 @@ +imagesdir = $(datadir)/zenity/ +images_DATA = \ + zenity-calendar.png \ + zenity-list.png \ + zenity-file.png \ + zenity-progress.png + +EXTRA_DIST = $(images_DATA) diff --git a/data/zenity-calendar.png b/data/zenity-calendar.png new file mode 100644 index 0000000..889f329 Binary files /dev/null and b/data/zenity-calendar.png differ diff --git a/data/zenity-file.png b/data/zenity-file.png new file mode 100644 index 0000000..bac6392 Binary files /dev/null and b/data/zenity-file.png differ diff --git a/data/zenity-list.png b/data/zenity-list.png new file mode 100644 index 0000000..5a593b7 Binary files /dev/null and b/data/zenity-list.png differ diff --git a/data/zenity-progress.png b/data/zenity-progress.png new file mode 100644 index 0000000..505c805 Binary files /dev/null and b/data/zenity-progress.png differ diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..e723152 --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1 @@ +src/main.c diff --git a/po/POTFILES.skip b/po/POTFILES.skip new file mode 100644 index 0000000..7d1afb6 --- /dev/null +++ b/po/POTFILES.skip @@ -0,0 +1,11 @@ +src/gscript.h +src/calendar.c +src/entry.c +src/fileselection.c +src/gscript.glade +src/msg.c +src/progress.c +src/text.c +src/tree.c +src/util.c +src/util.h diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..11e0816 --- /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 0000000..4cdf481 --- /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 0000000..3816a50 --- /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 0000000..52c0021 --- /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 0000000..cf17d7d --- /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 0000000..a8e5c2d --- /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 0000000..2130591 --- /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 0000000..0d2dbe1 --- /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 0000000..c5eef5a --- /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 0000000..b9116ac --- /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 0000000..3f9d8e1 --- /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 0000000..27b3cf1 --- /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 0000000..1543436 --- /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 */