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.
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.
See signal(7) for details about signals.
.TP
.TP
.B \-\-print-xid=\fI[FILENAME]\fP
Output X Window ID of a yad's window to the specified file or stderr.
.TP
......@@ -234,6 +234,17 @@ Enable spell checking in textview widgets
.TP
.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.
.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
.TP
......
......@@ -83,7 +83,7 @@ expand_action (gchar * cmd)
break;
}
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;
case YAD_FIELD_COMBO:
case YAD_FIELD_COMBO_ENTRY:
......@@ -1217,11 +1217,11 @@ form_print_field (guint fn)
}
case YAD_FIELD_CHECK:
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" :
"FALSE", options.common_data.separator);
g_printf ("'%s'%s", print_bool_val (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, fn)))),
options.common_data.separator);
else
g_printf ("%s%s", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, fn))) ? "TRUE" :
"FALSE", options.common_data.separator);
g_printf ("%s%s", print_bool_val (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, fn)))),
options.common_data.separator);
break;
case YAD_FIELD_COMBO:
case YAD_FIELD_COMBO_ENTRY:
......
......@@ -449,7 +449,7 @@ cell_get_data (GtkTreeIter *it, guint num)
{
gboolean bval;
gtk_tree_model_get (model, it, num, &bval, -1);
data = g_strdup (bval ? "TRUE" : "FALSE");
data = g_strdup (print_bool_val (bval));
break;
}
case YAD_COLUMN_NUM:
......@@ -1120,9 +1120,9 @@ print_col (GtkTreeModel * model, GtkTreeIter * iter, gint num)
gboolean bval;
gtk_tree_model_get (model, iter, num, &bval, -1);
if (options.common_data.quoted_output)
g_printf ("'%s'", bval ? "TRUE" : "FALSE");
g_printf ("'%s'", print_bool_val (bval));
else
g_printf ("%s", bval ? "TRUE" : "FALSE");
g_printf ("%s", print_bool_val (bval));
break;
}
case YAD_COLUMN_NUM:
......
......@@ -51,6 +51,7 @@ static gboolean parse_signal (const gchar *, const gchar *, gpointer, GError **)
#endif
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_bool_fmt_type (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 **);
#if GLIB_CHECK_VERSION(2,30,0)
......@@ -213,6 +214,8 @@ static GOptionEntry common_options[] = {
N_("Identifier of embedded dialogs"), N_("KEY") },
{ "complete", 0, 0, G_OPTION_ARG_CALLBACK, set_complete_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)
{ "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 },
......@@ -1166,6 +1169,39 @@ set_complete_type (const gchar * option_name, const gchar * value, gpointer data
}
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)
{
if (strncasecmp (value, "hor", 3) == 0)
......@@ -1463,6 +1499,7 @@ yad_options_init (void)
options.common_data.num_output = FALSE;
options.common_data.filters = NULL;
options.common_data.key = -1;
options.common_data.bool_fmt = YAD_BOOL_FMT_UT;
options.common_data.complete = YAD_COMPLETE_SIMPLE;
#if GLIB_CHECK_VERSION(2,30,0)
options.common_data.size_fmt = G_FORMAT_SIZE_DEFAULT;
......
......@@ -674,7 +674,34 @@ get_bool_val (gchar *str)
gchar *
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
......
......@@ -167,6 +167,16 @@ typedef enum {
YAD_COMPLETE_REGEX
} 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 {
gchar *name;
gchar *cmd;
......@@ -458,6 +468,7 @@ typedef struct {
#if GLIB_CHECK_VERSION(2,30,0)
GFormatSizeFlags size_fmt;
#endif
YadBoolFormat bool_fmt;
YadCompletionType complete;
GList *filters;
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