summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/text.c75
1 files changed, 75 insertions, 0 deletions
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