Commit a6c1cb12 authored by Victor Ananjevsky's avatar Victor Ananjevsky

add settings for formatting output of boolean values

parent b3a99043
...@@ -108,7 +108,7 @@ See \fIhttp://code.google.com/p/yad/wiki/TimeoutIndicator\fP for details. ...@@ -108,7 +108,7 @@ See \fIhttp://code.google.com/p/yad/wiki/TimeoutIndicator\fP for details.
Send SIGNAL to parent process. Default value of SIGNAL is a SIGTERM. Send SIGNAL to parent process. Default value of SIGNAL is a SIGTERM.
SIGNAL may be specified by it's number or symbolic name with or without SIG prefix. SIGNAL may be specified by it's number or symbolic name with or without SIG prefix.
See signal(7) for details about signals. See signal(7) for details about signals.
.TP .TP
.B \-\-print-xid=\fI[FILENAME]\fP .B \-\-print-xid=\fI[FILENAME]\fP
Output X Window ID of a yad's window to the specified file or stderr. Output X Window ID of a yad's window to the specified file or stderr.
.TP .TP
...@@ -234,6 +234,17 @@ Enable spell checking in textview widgets ...@@ -234,6 +234,17 @@ Enable spell checking in textview widgets
.TP .TP
.B \-\-spell-lang=\fILANGUAGE\fP .B \-\-spell-lang=\fILANGUAGE\fP
Set spell checking language to \fILANGUAGE\fP. By default language guesses from current locale. Use option \fI\-\-show-langs\fP for get list of all possible languages. Set spell checking language to \fILANGUAGE\fP. By default language guesses from current locale. Use option \fI\-\-show-langs\fP for get list of all possible languages.
.TP
.B \-\-boot-fmt=\fITYPE\fP
Set the output type of boolean values to \fITYPE\fP. Possible types are \fIT\fP, \fIt\fP, \fIY\fP, \fIy\fP, \fIO\fP, \fIo\fP and \fI1\fP.
.br
\fIT\fP and \fIt\fP - for \fItrue/false\fP pair in appropriate case.
.br
\fIY\fP and \fIy\fP - for \fIyes/no\fP pair in appropriate case.
.br
\fIO\fP and \fIo\fP - for \fIon/off\fP pair in appropriate case.
.br
\fI1\fP - for \fI1/0\fP pair in appropriate case.
.SS Calendar options .SS Calendar options
.TP .TP
......
...@@ -83,7 +83,7 @@ expand_action (gchar * cmd) ...@@ -83,7 +83,7 @@ expand_action (gchar * cmd)
break; break;
} }
case YAD_FIELD_CHECK: case YAD_FIELD_CHECK:
arg = g_strdup (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, num))) ? "TRUE" : "FALSE"); arg = g_strdup (print_bool_val (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, num)))));
break; break;
case YAD_FIELD_COMBO: case YAD_FIELD_COMBO:
case YAD_FIELD_COMBO_ENTRY: case YAD_FIELD_COMBO_ENTRY:
...@@ -1217,11 +1217,11 @@ form_print_field (guint fn) ...@@ -1217,11 +1217,11 @@ form_print_field (guint fn)
} }
case YAD_FIELD_CHECK: case YAD_FIELD_CHECK:
if (options.common_data.quoted_output) if (options.common_data.quoted_output)
g_printf ("'%s'%s", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, fn))) ? "TRUE" : g_printf ("'%s'%s", print_bool_val (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, fn)))),
"FALSE", options.common_data.separator); options.common_data.separator);
else else
g_printf ("%s%s", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, fn))) ? "TRUE" : g_printf ("%s%s", print_bool_val (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, fn)))),
"FALSE", options.common_data.separator); options.common_data.separator);
break; break;
case YAD_FIELD_COMBO: case YAD_FIELD_COMBO:
case YAD_FIELD_COMBO_ENTRY: case YAD_FIELD_COMBO_ENTRY:
......
...@@ -449,7 +449,7 @@ cell_get_data (GtkTreeIter *it, guint num) ...@@ -449,7 +449,7 @@ cell_get_data (GtkTreeIter *it, guint num)
{ {
gboolean bval; gboolean bval;
gtk_tree_model_get (model, it, num, &bval, -1); gtk_tree_model_get (model, it, num, &bval, -1);
data = g_strdup (bval ? "TRUE" : "FALSE"); data = g_strdup (print_bool_val (bval));
break; break;
} }
case YAD_COLUMN_NUM: case YAD_COLUMN_NUM:
...@@ -1120,9 +1120,9 @@ print_col (GtkTreeModel * model, GtkTreeIter * iter, gint num) ...@@ -1120,9 +1120,9 @@ print_col (GtkTreeModel * model, GtkTreeIter * iter, gint num)
gboolean bval; gboolean bval;
gtk_tree_model_get (model, iter, num, &bval, -1); gtk_tree_model_get (model, iter, num, &bval, -1);
if (options.common_data.quoted_output) if (options.common_data.quoted_output)
g_printf ("'%s'", bval ? "TRUE" : "FALSE"); g_printf ("'%s'", print_bool_val (bval));
else else
g_printf ("%s", bval ? "TRUE" : "FALSE"); g_printf ("%s", print_bool_val (bval));
break; break;
} }
case YAD_COLUMN_NUM: case YAD_COLUMN_NUM:
......
...@@ -51,6 +51,7 @@ static gboolean parse_signal (const gchar *, const gchar *, gpointer, GError **) ...@@ -51,6 +51,7 @@ static gboolean parse_signal (const gchar *, const gchar *, gpointer, GError **)
#endif #endif
static gboolean add_image_path (const gchar *, const gchar *, gpointer, GError **); static gboolean add_image_path (const gchar *, const gchar *, gpointer, GError **);
static gboolean set_complete_type (const gchar *, const gchar *, gpointer, GError **); static gboolean set_complete_type (const gchar *, const gchar *, gpointer, GError **);
static gboolean set_bool_fmt_type (const gchar *, const gchar *, gpointer, GError **);
static gboolean set_grid_lines (const gchar *, const gchar *, gpointer, GError **); static gboolean set_grid_lines (const gchar *, const gchar *, gpointer, GError **);
static gboolean set_scroll_policy (const gchar *, const gchar *, gpointer, GError **); static gboolean set_scroll_policy (const gchar *, const gchar *, gpointer, GError **);
#if GLIB_CHECK_VERSION(2,30,0) #if GLIB_CHECK_VERSION(2,30,0)
...@@ -213,6 +214,8 @@ static GOptionEntry common_options[] = { ...@@ -213,6 +214,8 @@ static GOptionEntry common_options[] = {
N_("Identifier of embedded dialogs"), N_("KEY") }, N_("Identifier of embedded dialogs"), N_("KEY") },
{ "complete", 0, 0, G_OPTION_ARG_CALLBACK, set_complete_type, { "complete", 0, 0, G_OPTION_ARG_CALLBACK, set_complete_type,
N_("Set extended completion for entries (any, all, or regex)"), N_("TYPE") }, N_("Set extended completion for entries (any, all, or regex)"), N_("TYPE") },
{ "bool-fmt", 0, 0, G_OPTION_ARG_CALLBACK, set_bool_fmt_type,
N_("Set type of output for boolean values (T, t, Y, y, O, o, 1)"), N_("TYPE") },
#if GLIB_CHECK_VERSION(2,30,0) #if GLIB_CHECK_VERSION(2,30,0)
{ "iec-format", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, set_size_format, { "iec-format", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, set_size_format,
N_("Use IEC (base 1024) units with for size values"), NULL }, N_("Use IEC (base 1024) units with for size values"), NULL },
...@@ -1166,6 +1169,39 @@ set_complete_type (const gchar * option_name, const gchar * value, gpointer data ...@@ -1166,6 +1169,39 @@ set_complete_type (const gchar * option_name, const gchar * value, gpointer data
} }
static gboolean static gboolean
set_bool_fmt_type (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
{
switch (value[0])
{
case 'T':
options.common_data.bool_fmt = YAD_BOOL_FMT_UT;
break;
case 't':
options.common_data.bool_fmt = YAD_BOOL_FMT_LT;
break;
case 'Y':
options.common_data.bool_fmt = YAD_BOOL_FMT_UY;
break;
case 'y':
options.common_data.bool_fmt = YAD_BOOL_FMT_LY;
break;
case 'O':
options.common_data.bool_fmt = YAD_BOOL_FMT_UO;
break;
case 'o':
options.common_data.bool_fmt = YAD_BOOL_FMT_LO;
break;
case '1':
options.common_data.bool_fmt = YAD_BOOL_FMT_1;
break;
default:
g_printerr (_("Unknown boolean format type: %s\n"), value);
}
return TRUE;
}
static gboolean
set_grid_lines (const gchar * option_name, const gchar * value, gpointer data, GError ** err) set_grid_lines (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
{ {
if (strncasecmp (value, "hor", 3) == 0) if (strncasecmp (value, "hor", 3) == 0)
...@@ -1463,6 +1499,7 @@ yad_options_init (void) ...@@ -1463,6 +1499,7 @@ yad_options_init (void)
options.common_data.num_output = FALSE; options.common_data.num_output = FALSE;
options.common_data.filters = NULL; options.common_data.filters = NULL;
options.common_data.key = -1; options.common_data.key = -1;
options.common_data.bool_fmt = YAD_BOOL_FMT_UT;
options.common_data.complete = YAD_COMPLETE_SIMPLE; options.common_data.complete = YAD_COMPLETE_SIMPLE;
#if GLIB_CHECK_VERSION(2,30,0) #if GLIB_CHECK_VERSION(2,30,0)
options.common_data.size_fmt = G_FORMAT_SIZE_DEFAULT; options.common_data.size_fmt = G_FORMAT_SIZE_DEFAULT;
......
...@@ -674,7 +674,34 @@ get_bool_val (gchar *str) ...@@ -674,7 +674,34 @@ get_bool_val (gchar *str)
gchar * gchar *
print_bool_val (gboolean val) print_bool_val (gboolean val)
{ {
return ""; gchar *ret = "";
switch (options.common_data.bool_fmt)
{
case YAD_BOOL_FMT_UT:
ret = val ? "TRUE" : "FALSE";
break;
case YAD_BOOL_FMT_UY:
ret = val ? "YES" : "NO";
break;
case YAD_BOOL_FMT_UO:
ret = val ? "ON" : "OFF";
break;
case YAD_BOOL_FMT_LT:
ret = val ? "true" : "false";
break;
case YAD_BOOL_FMT_LY:
ret = val ? "yes" : "no";
break;
case YAD_BOOL_FMT_LO:
ret = val ? "on" : "off";
break;
case YAD_BOOL_FMT_1:
ret = val ? "1" : "0";
break;
}
return ret;
} }
#ifdef HAVE_SPELL #ifdef HAVE_SPELL
......
...@@ -167,6 +167,16 @@ typedef enum { ...@@ -167,6 +167,16 @@ typedef enum {
YAD_COMPLETE_REGEX YAD_COMPLETE_REGEX
} YadCompletionType; } YadCompletionType;
typedef enum {
YAD_BOOL_FMT_UT,
YAD_BOOL_FMT_UY,
YAD_BOOL_FMT_UO,
YAD_BOOL_FMT_LT,
YAD_BOOL_FMT_LY,
YAD_BOOL_FMT_LO,
YAD_BOOL_FMT_1
} YadBoolFormat;
typedef struct { typedef struct {
gchar *name; gchar *name;
gchar *cmd; gchar *cmd;
...@@ -458,6 +468,7 @@ typedef struct { ...@@ -458,6 +468,7 @@ typedef struct {
#if GLIB_CHECK_VERSION(2,30,0) #if GLIB_CHECK_VERSION(2,30,0)
GFormatSizeFlags size_fmt; GFormatSizeFlags size_fmt;
#endif #endif
YadBoolFormat bool_fmt;
YadCompletionType complete; YadCompletionType complete;
GList *filters; GList *filters;
key_t key; key_t key;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment