summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlynn Foster <glynn.foster@sun.com>2003-05-05 17:17:02 +0000
committerGlynn Foster <gman@src.gnome.org>2003-05-05 17:17:02 +0000
commit8ff2b32c9eb4b2eb8970a9fa48c4889847c347b1 (patch)
treece428fee7a962be0ad60705f86eb1b4ad81e39ad
parentUpdate Japanese translation. (diff)
downloadzenity-8ff2b32c9eb4b2eb8970a9fa48c4889847c347b1.tar.gz
zenity-8ff2b32c9eb4b2eb8970a9fa48c4889847c347b1.tar.bz2
zenity-8ff2b32c9eb4b2eb8970a9fa48c4889847c347b1.zip
Make the list dialog handle stdin - a little bit buggy still. Update
2003-05-05 Glynn Foster <glynn.foster@sun.com> * src/tree.c, src/util.c, src/util.h: Make the list dialog handle stdin - a little bit buggy still. * TODO: Update
-rw-r--r--ChangeLog6
-rw-r--r--TODO11
-rw-r--r--src/tree.c133
-rw-r--r--src/util.c19
-rw-r--r--src/util.h1
5 files changed, 163 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 5cc89cf6..696373d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-05-05 Glynn Foster <glynn.foster@sun.com>
+
+ * src/tree.c, src/util.c, src/util.h: Make the list dialog
+ handle stdin - a little bit buggy still.
+ * TODO: Update
+
2003-04-16 Jordi Mallach <jordi@sindominio.net>
* configure.in: Added "ca" (Catalan) to ALL_LINGUAS.
diff --git a/TODO b/TODO
index c8cf0734..71579b3c 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,10 @@
-* List dialog should read data from stdin
+* Fix bugs in the list dialog with stdin
+* Add pixmap support to list dialog ?
+ - Suggested by Dani Brody <brodydani@hotmail.com>
+* Add new format ?
+ --list --column=check,hide --column=pixmap --column=string,editable
+ - Suggested by Dani Brody <brodydani@hotmail.com>
* Fix up progress dialog so that it actually works
-* Add some accessibility I guess
+* Add support for DML (Dialog Meta Language)?
+ - ftp://ftp.pld.org.pl/people/malekith/dml/
+ - Suggested by Michal Moskal <malekith@pld-linux.org>
diff --git a/src/tree.c b/src/tree.c
index 08043787..2481d8b9 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -75,6 +75,119 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g
gtk_tree_path_free (path);
}
+static gboolean
+zenity_tree_handle_stdin (GIOChannel *channel,
+ GIOCondition condition,
+ gpointer data)
+{
+ static GtkTreeView *tree_view;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ static gint column_count = 0;
+ static gint row_count = 0;
+ static gint n_columns;
+ static gboolean editable;
+ static gboolean toggles;
+
+ tree_view = GTK_TREE_VIEW (data);
+ n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
+ editable = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "editable"));
+ toggles = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "toggles"));
+
+ model = gtk_tree_view_get_model (tree_view);
+
+ if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP)) {
+ GString *string;
+ GError *error = NULL;
+
+ string = g_string_new (NULL);
+
+ while (channel->is_readable != TRUE)
+ ;
+ do {
+ gint status;
+
+ do {
+ status = g_io_channel_read_line_string (channel, string, NULL, &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_tree_handle_stdin () : %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ continue;
+ }
+
+ if (column_count == n_columns) {
+ /* We're starting a new row */
+ column_count = 0;
+ row_count++;
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+ }
+
+ if (toggles && column_count == 0) {
+ if (strcmp (string->str, "TRUE") == 0)
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, TRUE, -1);
+ else
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, FALSE, -1);
+ }
+ else {
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, zenity_util_strip_newline (string->str), -1);
+ }
+
+ if (editable) {
+ g_print ("Shouldn't be going here");
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1);
+ }
+
+ if (row_count == MAX_ELEMENTS_BEFORE_SCROLLING) {
+ GtkWidget *scrolled_window;
+ GtkRequisition rectangle;
+
+ gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle);
+ scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window");
+ gtk_widget_set_size_request (scrolled_window, -1, rectangle.height);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ }
+
+ column_count ++;
+
+ } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN);
+ g_string_free (string, TRUE);
+ }
+
+ if (condition != G_IO_IN) {
+ g_io_channel_shutdown (channel, TRUE, NULL);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void
+zenity_tree_fill_entries_from_stdin (GtkTreeView *tree_view,
+ gint n_columns,
+ gboolean toggles,
+ gboolean editable)
+{
+ GIOChannel *channel;
+
+ g_object_set_data (G_OBJECT (tree_view), "n_columns", (gint *) n_columns);
+ g_object_set_data (G_OBJECT (tree_view), "toggles", (gint *) toggles);
+ g_object_set_data (G_OBJECT (tree_view), "editable", (gint *) editable);
+
+ 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_tree_handle_stdin, tree_view);
+}
+
static void
zenity_tree_fill_entries (GtkTreeView *tree_view,
const gchar **args,
@@ -118,8 +231,8 @@ zenity_tree_fill_entries (GtkTreeView *tree_view,
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
}
- i += n_columns;
+ i += n_columns;
}
}
@@ -174,11 +287,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
return;
}
+ /*
if (tree_data->data == NULL) {
g_printerr (_("No contents specified for --list\n"));
data->exit_code = -1;
return;
}
+ */
glade_xml_signal_autoconnect (glade_dialog);
@@ -310,10 +425,18 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
- if (tree_data->radiobox || tree_data->checkbox)
- zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable);
- else
- zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable);
+ if (tree_data->radiobox || tree_data->checkbox) {
+ if (tree_data->data)
+ zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable);
+ else
+ zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, TRUE, tree_data->editable);
+ }
+ else {
+ if (tree_data->data)
+ zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable);
+ else
+ zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, FALSE, tree_data->editable);
+ }
gtk_widget_show (dialog);
gtk_main ();
diff --git a/src/util.c b/src/util.c
index 907b04c5..2b3e8dc1 100644
--- a/src/util.c
+++ b/src/util.c
@@ -59,6 +59,25 @@ zenity_util_load_glade_file (const gchar *widget_root)
return xml;
}
+gchar*
+zenity_util_strip_newline (gchar *string)
+{
+ gsize len;
+
+ g_return_val_if_fail (string != NULL, NULL);
+
+ len = strlen (string);
+ while (len--)
+ {
+ if (string[len] == '\n')
+ string[len] = '\0';
+ else
+ break;
+ }
+
+ return string;
+}
+
gboolean
zenity_util_fill_file_buffer (GtkTextBuffer *buffer, const gchar *filename)
{
diff --git a/src/util.h b/src/util.h
index 7a817abf..abfd2aed 100644
--- a/src/util.h
+++ b/src/util.h
@@ -11,6 +11,7 @@ G_BEGIN_DECLS
#define ZENITY_IMAGE_FULLPATH(filename) (g_strconcat (ZENITY_DATADIR, "/", filename, NULL))
GladeXML* zenity_util_load_glade_file (const gchar *widget_root);
+gchar * zenity_util_strip_newline (gchar *string);
gboolean zenity_util_fill_file_buffer (GtkTextBuffer *buffer,
const gchar *filename);
void zenity_util_set_window_icon (GtkWidget *widget,
bgstack15