Localise output of --calendar dialog by default (using nl_langinfo),
and provide a --date-format option to provide a strftime-style format for the returned date.
This commit is contained in:
parent
69636459e1
commit
9a77e41fec
@ -1,3 +1,10 @@
|
||||
2003-01-13 Mike Newman <mike@gtnorthern.demon.co.uk>
|
||||
|
||||
* src/calendar.c, src/main.c, src/zenity.h: Make the calendar
|
||||
return a localised date, and provide a means to override this with
|
||||
a --date-format option which takes a strftime style string -
|
||||
"%A %d/%m/%Y" for example.
|
||||
|
||||
2003-01-13 Glynn Foster <glynn.foster@sun.com>
|
||||
|
||||
* src/main.c: Improve error handling.
|
||||
|
@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
#include <glade/glade.h>
|
||||
#include <time.h>
|
||||
#include "zenity.h"
|
||||
#include "util.h"
|
||||
|
||||
@ -49,7 +50,7 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
|
||||
dialog = glade_xml_get_widget (glade_dialog, "zenity_calendar_dialog");
|
||||
|
||||
g_signal_connect (G_OBJECT (dialog), "response",
|
||||
G_CALLBACK (zenity_calendar_dialog_response), data);
|
||||
G_CALLBACK (zenity_calendar_dialog_response), cal_data);
|
||||
|
||||
if (data->dialog_title)
|
||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||
@ -80,13 +81,20 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
|
||||
static void
|
||||
zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
|
||||
{
|
||||
ZenityData *zen_data = data;
|
||||
guint day, month, year;
|
||||
|
||||
ZenityCalendarData *cal_data = data;
|
||||
ZenityData *zen_data;
|
||||
gint day, month, year;
|
||||
gchar time_string[128];
|
||||
GDate *date = NULL;
|
||||
|
||||
switch (response) {
|
||||
case GTK_RESPONSE_OK:
|
||||
gtk_calendar_get_date (GTK_CALENDAR (calendar), &day, &month, &year);
|
||||
g_printerr ("%02d/%02d/%02d\n", year, month + 1, day);
|
||||
date = g_date_new_dmy (year, month+1, day);
|
||||
g_date_strftime (time_string, 127,
|
||||
cal_data->date_format, date);
|
||||
g_printerr ("%s\n",time_string);
|
||||
g_date_free ( date );
|
||||
zen_data->exit_code = 0;
|
||||
gtk_main_quit ();
|
||||
break;
|
||||
|
21
src/main.c
21
src/main.c
@ -24,6 +24,7 @@
|
||||
#include "config.h"
|
||||
#include "zenity.h"
|
||||
#include <popt.h>
|
||||
#include <langinfo.h>
|
||||
|
||||
typedef enum {
|
||||
MODE_CALENDAR,
|
||||
@ -54,6 +55,7 @@ typedef struct {
|
||||
|
||||
enum {
|
||||
OPTION_CALENDAR = 1,
|
||||
OPTION_DATEFORMAT,
|
||||
OPTION_ENTRY,
|
||||
OPTION_ERROR,
|
||||
OPTION_INFO,
|
||||
@ -275,6 +277,14 @@ struct poptOption calendar_options[] = {
|
||||
N_("Set the calendar year"),
|
||||
NULL
|
||||
},
|
||||
{ "date-format",
|
||||
'\0',
|
||||
POPT_ARG_STRING,
|
||||
NULL,
|
||||
OPTION_DATEFORMAT,
|
||||
N_("Set the format for the returned date"),
|
||||
NULL
|
||||
},
|
||||
POPT_TABLEEND
|
||||
};
|
||||
|
||||
@ -701,6 +711,7 @@ zenity_init_parsing_options (void) {
|
||||
results->tree_data = g_new0 (ZenityTreeData, 1);
|
||||
|
||||
/* Give some sensible defaults */
|
||||
results->calendar_data->date_format = g_strdup (nl_langinfo (D_FMT));
|
||||
results->calendar_data->day = 0;
|
||||
results->calendar_data->month = 0;
|
||||
results->calendar_data->year = 0;
|
||||
@ -726,6 +737,8 @@ zenity_free_parsing_options (void) {
|
||||
case MODE_CALENDAR:
|
||||
if (results->calendar_data->dialog_text)
|
||||
g_free (results->calendar_data->dialog_text);
|
||||
if (results->calendar_data->date_format)
|
||||
g_free (results->calendar_data->date_format);
|
||||
break;
|
||||
case MODE_ENTRY:
|
||||
if (results->entry_data->dialog_text)
|
||||
@ -1027,6 +1040,14 @@ void zenity_parse_options_callback (poptContext ctx,
|
||||
}
|
||||
results->calendar_data->year = atoi (arg);
|
||||
break;
|
||||
case OPTION_DATEFORMAT:
|
||||
if (results->mode != MODE_CALENDAR) {
|
||||
g_printerr (_("--date-format is not supported for this dialog\n"));
|
||||
zenity_free_parsing_options ();
|
||||
exit (-1);
|
||||
}
|
||||
results->calendar_data->date_format = g_strdup (arg);
|
||||
break;
|
||||
case OPTION_INPUTTEXT:
|
||||
if (results->mode != MODE_ENTRY) {
|
||||
g_printerr (_("--entry-text is not supported for this dialog\n"));
|
||||
|
@ -6,7 +6,7 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
#include<libintl.h>
|
||||
#include <libintl.h>
|
||||
#define _(String) dgettext(GETTEXT_PACKAGE,String)
|
||||
#ifdef gettext_noop
|
||||
#define N_(String) gettext_noop(String)
|
||||
@ -34,6 +34,7 @@ typedef struct {
|
||||
gint day;
|
||||
gint month;
|
||||
gint year;
|
||||
gchar *date_format;
|
||||
} ZenityCalendarData;
|
||||
|
||||
typedef enum {
|
||||
|
Reference in New Issue
Block a user