summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/zenity.112
-rw-r--r--src/Makefile.am1
-rw-r--r--src/color.c97
-rw-r--r--src/main.c3
-rw-r--r--src/option.c90
-rw-r--r--src/option.h2
-rw-r--r--src/zenity.h7
7 files changed, 212 insertions, 0 deletions
diff --git a/data/zenity.1 b/data/zenity.1
index 91201fb..e7f03be 100644
--- a/data/zenity.1
+++ b/data/zenity.1
@@ -60,6 +60,8 @@ Display warning dialog
.TP
.B \-\-scale
Display scale dialog
+.B \-\-color-selection
+Display color selection dialog
.PP
General options
@@ -267,6 +269,16 @@ Print partial values
Hide value
.PP
+Color selection options
+
+.TP
+.B \-\-color=VALUE
+Set the initial color
+.TP
+.B \-\-show\-palette
+Show the palette
+
+.PP
Miscellaneous options
.TP
diff --git a/src/Makefile.am b/src/Makefile.am
index 30f7ccd..dbd672d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,6 +16,7 @@ zenity_SOURCES = \
scale.c \
text.c \
tree.c \
+ color.c \
util.c \
util.h \
zenity.h
diff --git a/src/color.c b/src/color.c
new file mode 100644
index 0000000..8f31937
--- /dev/null
+++ b/src/color.c
@@ -0,0 +1,97 @@
+/*
+ * color.c
+ *
+ * Copyright (C) 2010 Berislav Kovacki
+ *
+ * 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Authors: Berislav Kovacki <pantokrator@pantokrator.net>
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include "zenity.h"
+#include "util.h"
+
+static ZenityData *zen_data;
+
+static void zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer data);
+
+void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
+{
+ GtkWidget *dialog;
+ GtkWidget *colorsel;
+ GdkColor color;
+
+ zen_data = data;
+
+ dialog = gtk_color_selection_dialog_new (NULL);
+
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (zenity_colorselection_dialog_response),
+ color_data);
+
+ if (data->dialog_title)
+ gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
+
+ colorsel = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (dialog));
+
+ if (color_data->color) {
+ if (gdk_color_parse (color_data->color, &color))
+ gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (colorsel),
+ &color);
+ }
+
+ gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (colorsel),
+ color_data->show_palette);
+
+ zenity_util_show_dialog (dialog);
+
+ if (data->timeout_delay > 0) {
+ g_timeout_add (data->timeout_delay * 1000,
+ (GSourceFunc) zenity_util_timeout_handle,
+ NULL);
+ }
+
+ gtk_main();
+}
+
+static void
+zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer data)
+{
+ GtkWidget *colorsel;
+ GdkColor color;
+
+ switch (response) {
+ case GTK_RESPONSE_OK:
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
+ colorsel = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (widget));
+ gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (colorsel), &color);
+ g_print ("%s\n", gdk_color_to_string (&color));
+ break;
+
+ case GTK_RESPONSE_CANCEL:
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
+ break;
+
+ default:
+ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
+ break;
+ }
+
+ gtk_main_quit ();
+}
diff --git a/src/main.c b/src/main.c
index 4f87e6d..5e07970 100644
--- a/src/main.c
+++ b/src/main.c
@@ -84,6 +84,9 @@ main (gint argc, gchar **argv) {
case MODE_TEXTINFO:
zenity_text (results->data, results->text_data);
break;
+ case MODE_COLOR:
+ zenity_colorselection (results->data, results->color_data);
+ break;
case MODE_ABOUT:
zenity_about (results->data);
break;
diff --git a/src/option.c b/src/option.c
index bc09009..0046745 100644
--- a/src/option.c
+++ b/src/option.c
@@ -108,6 +108,11 @@ static gint zenity_scale_step;
static gboolean zenity_scale_print_partial;
static gboolean zenity_scale_hide_value;
+/* Color Selection Dialog Options */
+static gboolean zenity_colorsel_active;
+static gchar *zenity_colorsel_color;
+static gboolean zenity_colorsel_show_palette;
+
/* Miscelaneus Options */
static gboolean zenity_misc_about;
static gboolean zenity_misc_version;
@@ -818,6 +823,39 @@ static GOptionEntry scale_options[] = {
}
};
+static GOptionEntry color_selection_options[] = {
+ {
+ "color-selection",
+ '\0',
+ G_OPTION_FLAG_IN_MAIN,
+ G_OPTION_ARG_NONE,
+ &zenity_colorsel_active,
+ N_("Display color selection dialog"),
+ NULL
+ },
+ {
+ "color",
+ '\0',
+ 0,
+ G_OPTION_ARG_STRING,
+ &zenity_colorsel_color,
+ N_("Set the color"),
+ N_("VALUE")
+ },
+ {
+ "show-palette",
+ '\0',
+ 0,
+ G_OPTION_ARG_NONE,
+ &zenity_colorsel_show_palette,
+ N_("Show the palette"),
+ NULL
+ },
+ {
+ NULL
+ }
+};
+
static GOptionEntry miscellaneous_options[] = {
{
"about",
@@ -862,6 +900,7 @@ zenity_option_init (void) {
results->text_data = g_new0 (ZenityTextData, 1);
results->tree_data = g_new0 (ZenityTreeData, 1);
results->notification_data = g_new0 (ZenityNotificationData, 1);
+ results->color_data = g_new0 (ZenityColorData, 1);
}
void
@@ -897,6 +936,9 @@ zenity_option_free (void) {
if (zenity_question_cancel_button)
g_free (zenity_question_cancel_button);
+ if (zenity_colorsel_color)
+ g_free (zenity_colorsel_color);
+
g_option_context_free (ctx);
}
@@ -1116,6 +1158,19 @@ zenity_scale_pre_callback (GOptionContext *context,
}
static gboolean
+zenity_color_pre_callback (GOptionContext *context,
+ GOptionGroup *group,
+ gpointer data,
+ GError **error)
+{
+ zenity_colorsel_active = FALSE;
+ zenity_colorsel_color = NULL;
+ zenity_colorsel_show_palette = FALSE;
+
+ return TRUE;
+}
+
+static gboolean
zenity_misc_pre_callback (GOptionContext *context,
GOptionGroup *group,
gpointer data,
@@ -1481,6 +1536,30 @@ zenity_scale_post_callback (GOptionContext *context,
}
static gboolean
+zenity_color_post_callback (GOptionContext *context,
+ GOptionGroup *group,
+ gpointer data,
+ GError **error)
+{
+ zenity_option_set_dialog_mode (zenity_colorsel_active, MODE_COLOR);
+
+ if (results->mode == MODE_COLOR) {
+ results->color_data->color = zenity_colorsel_color;
+ results->color_data->show_palette = zenity_colorsel_show_palette;
+ } else {
+ if (zenity_colorsel_color)
+ zenity_option_error (zenity_option_get_name(color_selection_options, &zenity_colorsel_color),
+ ERROR_SUPPORT);
+
+ if (zenity_colorsel_show_palette)
+ zenity_option_error (zenity_option_get_name(color_selection_options, &zenity_colorsel_show_palette),
+ ERROR_SUPPORT);
+ }
+
+ return TRUE;
+}
+
+static gboolean
zenity_misc_post_callback (GOptionContext *context,
GOptionGroup *group,
gpointer data,
@@ -1643,6 +1722,17 @@ zenity_create_context (void)
g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
g_option_context_add_group(tmp_ctx, a_group);
+ /* Adds color selection option entries */
+ a_group = g_option_group_new("color-selection",
+ N_("Color selection options"),
+ N_("Show color selection options"), NULL, NULL);
+ g_option_group_add_entries(a_group, color_selection_options);
+ g_option_group_set_parse_hooks (a_group,
+ zenity_color_pre_callback, zenity_color_post_callback);
+ g_option_group_set_error_hook (a_group, zenity_option_error_callback);
+ g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
+ g_option_context_add_group(tmp_ctx, a_group);
+
/* Adds misc option entries */
a_group = g_option_group_new("misc",
N_("Miscellaneous options"),
diff --git a/src/option.h b/src/option.h
index 2b7a703..f52c312 100644
--- a/src/option.h
+++ b/src/option.h
@@ -45,6 +45,7 @@ typedef enum {
MODE_SCALE,
MODE_INFO,
MODE_NOTIFICATION,
+ MODE_COLOR,
MODE_ABOUT,
MODE_VERSION,
MODE_LAST
@@ -70,6 +71,7 @@ typedef struct {
ZenityTextData *text_data;
ZenityTreeData *tree_data;
ZenityNotificationData *notification_data;
+ ZenityColorData *color_data;
} ZenityParsingOptions;
void zenity_option_error (gchar *string,
diff --git a/src/zenity.h b/src/zenity.h
index 9d7a153..a4cff2b 100644
--- a/src/zenity.h
+++ b/src/zenity.h
@@ -126,6 +126,11 @@ typedef struct {
gboolean listen;
} ZenityNotificationData;
+typedef struct {
+ gchar *color;
+ gboolean show_palette;
+} ZenityColorData;
+
void zenity_calendar (ZenityData *data,
ZenityCalendarData *calendar_data);
void zenity_msg (ZenityData *data,
@@ -142,6 +147,8 @@ void zenity_tree (ZenityData *data,
ZenityTreeData *tree_data);
void zenity_notification (ZenityData *data,
ZenityNotificationData *notification_data);
+void zenity_colorselection (ZenityData *data,
+ ZenityColorData *notification_data);
void zenity_scale (ZenityData *data,
ZenityScaleData *scale_data);
void zenity_about (ZenityData *data);