summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlynn Foster <glynn.foster@sun.com>2004-01-26 03:50:50 +0000
committerGlynn Foster <gman@src.gnome.org>2004-01-26 03:50:50 +0000
commit2a297420c2ebd72089f74a59f3bc93b0313510ec (patch)
tree2978758a2ce20f1d738d792f143238edc4c1b493
parentupdate (diff)
downloadzenity-2a297420c2ebd72089f74a59f3bc93b0313510ec.tar.gz
zenity-2a297420c2ebd72089f74a59f3bc93b0313510ec.tar.bz2
zenity-2a297420c2ebd72089f74a59f3bc93b0313510ec.zip
Handle stdin. Fixes #132517.
2004-01-26 Glynn Foster <glynn.foster@sun.com> * src/text.c: Handle stdin. Fixes #132517.
-rw-r--r--ChangeLog4
-rw-r--r--src/text.c75
2 files changed, 79 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 4712120d..d6a6a606 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2004-01-26 Glynn Foster <glynn.foster@sun.com>
+
+ * src/text.c: Handle stdin. Fixes #132517.
+
2004-01-20 Åsmund Skjæveland <aasmunds@fys.uio.no>
* configure.in: Added 'nn' to ALL_LINGUAS.
diff --git a/src/text.c b/src/text.c
index 0cf992c0..c4a49f8b 100644
--- a/src/text.c
+++ b/src/text.c
@@ -29,6 +29,79 @@ static ZenityTextData *zen_text_data;
static void zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data);
+static gboolean
+zenity_text_handle_stdin (GIOChannel *channel,
+ GIOCondition condition,
+ gpointer data)
+{
+ static GtkTextBuffer *buffer;
+ gchar buf[1024];
+
+ static GtkTextIter iter, end;
+ static gboolean first_time = FALSE;
+ gchar *str;
+ gsize len;
+
+ buffer = GTK_TEXT_BUFFER (data);
+
+ if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP)) {
+ GError *error = NULL;
+
+ while (channel->is_readable != TRUE)
+ ;
+ do {
+ gint status;
+
+ do {
+ status = g_io_channel_read_chars (channel, buf, 1024, &len, &error);
+
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ } while (status == G_IO_STATUS_AGAIN);
+
+ if (status != G_IO_STATUS_NORMAL) {
+ if (error) {
+ g_warning ("zenity_text_handle_stdin () : %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ continue;
+ }
+
+ if (len > 0) {
+ GtkTextIter end;
+ gchar *utftext;
+ gsize localelen;
+ gsize utflen;
+
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ utftext = g_convert_with_fallback (buf, len, "UTF-8", "ISO-8859-1", NULL, &localelen, &utflen, NULL);
+ gtk_text_buffer_insert (buffer, &end, utftext, utflen);
+ g_free (utftext);
+ }
+
+ } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN);
+ }
+
+ if (condition != G_IO_IN) {
+ g_io_channel_shutdown (channel, TRUE, NULL);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void
+zenity_text_fill_entries_from_stdin (GtkTextBuffer *text_buffer)
+{
+ GIOChannel *channel;
+
+ channel = g_io_channel_unix_new (0);
+ g_io_channel_set_encoding (channel, NULL, NULL);
+ g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_text_handle_stdin, text_buffer);
+}
+
void
zenity_text (ZenityData *data, ZenityTextData *text_data)
{
@@ -70,6 +143,8 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
if (text_data->uri)
zenity_util_fill_file_buffer (text_buffer, text_data->uri);
+ else
+ zenity_text_fill_entries_from_stdin (GTK_TEXT_BUFFER (text_buffer));
if (text_data->editable)
zen_text_data->buffer = text_buffer;
bgstack15