Initial revision

This commit is contained in:
Glynn Foster 2003-01-03 13:26:04 +00:00
commit 48c1564ac5
30 changed files with 3087 additions and 0 deletions

1
AUTHORS Normal file
View File

@ -0,0 +1 @@
Glynn Foster <glynn.foster@sun.com>

4
ChangeLog Normal file
View File

@ -0,0 +1,4 @@
2002-12-15 Glynn Foster <glynn.foster@sun.com>
* zenity/*: Initial import into cvs.gnome.org. Don't
expect things to work very well.

2
HACKING Normal file
View File

@ -0,0 +1,2 @@
Please send patches to any of the people listed in the MAINTAINERS file
for the moment.

1
MAINTAINERS Normal file
View File

@ -0,0 +1 @@
Glynn Foster <glynn.foster@sun.com>

3
Makefile.am Normal file
View File

@ -0,0 +1,3 @@
SUBDIRS = \
src \
data

0
NEWS Normal file
View File

3
README Normal file
View File

@ -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.

9
TODO Normal file
View File

@ -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

22
autogen.sh Executable file
View File

@ -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

71
configure.in Normal file
View File

@ -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
])

8
data/Makefile.am Normal file
View File

@ -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)

BIN
data/zenity-calendar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
data/zenity-file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
data/zenity-list.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

BIN
data/zenity-progress.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

1
po/POTFILES.in Normal file
View File

@ -0,0 +1 @@
src/main.c

11
po/POTFILES.skip Normal file
View File

@ -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

28
src/Makefile.am Normal file
View File

@ -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

90
src/calendar.c Normal file
View File

@ -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 <glynn.foster@sun.com>
*/
#include <glade/glade.h>
#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;
}
}

94
src/entry.c Normal file
View File

@ -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 <glynn.foster@sun.com>
*/
#include <glade/glade.h>
#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;
}
}

80
src/fileselection.c Normal file
View File

@ -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 <glynn.foster@sun.com>
*/
#include <glade/glade.h>
#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;
}
}

834
src/main.c Normal file
View File

@ -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 <glynn.foster@sun.com>
*/
#include "config.h"
#include "zenity.h"
#include <popt.h>
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;
}
}

117
src/msg.c Normal file
View File

@ -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 <glynn.foster@sun.com>
*/
#include <glade/glade.h>
#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;
}
}

139
src/progress.c Normal file
View File

@ -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 <glynn.foster@sun.com>
*/
#include <stdio.h>
#include <glade/glade.h>
#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];