static gboolean handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data) { if ((condition & G_IO_IN) != 0) { GString *string; GError *err = NULL; string = g_string_new (NULL); while (channel->is_readable == FALSE); do { gint status; gchar *command = NULL, *value = NULL, **args; do { status = g_io_channel_read_line_string (channel, string, NULL, &err); while (gdk_events_pending ()) gtk_main_iteration (); } while (status == G_IO_STATUS_AGAIN); if (status != G_IO_STATUS_NORMAL) { if (err) { g_printerr ("yad_notification_handle_stdin(): %s\n", err->message); g_error_free (err); err = NULL; } /* stop handling but not exit */ g_io_channel_shutdown (channel, TRUE, NULL); return FALSE; } strip_new_line (string->str); if (!string->str[0]) continue; args = g_strsplit (string->str, ":", 2); command = g_strdup (args[0]); if (args[1]) value = g_strdup (args[1]); g_strfreev (args); if (value) g_strstrip (value); if (!g_ascii_strcasecmp (command, "icon") && value) { g_free (icon); icon = g_strdup (value); if (gtk_status_icon_get_visible (status_icon) && gtk_status_icon_is_embedded (status_icon)) set_icon (); } else if (!g_ascii_strcasecmp (command, "tooltip")) { if (g_utf8_validate (value, -1, NULL)) { gchar *message = g_strcompress (value); if (!options.data.no_markup) gtk_status_icon_set_tooltip_markup (status_icon, message); else gtk_status_icon_set_tooltip_text (status_icon, message); g_free (message); } else g_printerr (_("Invalid UTF-8 in tooltip!\n")); } else if (!g_ascii_strcasecmp (command, "visible")) { #if !GTK_CHECK_VERSION(2,22,0) if (!g_ascii_strcasecmp (value, "blink")) { gboolean state = gtk_status_icon_get_blinking (status_icon); gtk_status_icon_set_blinking (status_icon, !state); } else #endif if (!g_ascii_strcasecmp (value, "false")) { gtk_status_icon_set_visible (status_icon, FALSE); #if !GTK_CHECK_VERSION(2,22,0) gtk_status_icon_set_blinking (status_icon, FALSE); #endif } else { gtk_status_icon_set_visible (status_icon, TRUE); #if !GTK_CHECK_VERSION(2,22,0) gtk_status_icon_set_blinking (status_icon, FALSE); #endif } } else if (!g_ascii_strcasecmp (command, "action")) { g_free (action); if (value) action = g_strdup (value); } else if (!g_ascii_strcasecmp (command, "quit")) { exit_code = YAD_RESPONSE_OK; gtk_main_quit (); } else if (!g_ascii_strcasecmp (command, "menu")) { if (value) parse_menu_str (value); } else g_printerr (_("Unknown command '%s'\n"), command); g_free (command); g_free (value); } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); g_string_free (string, TRUE); } if ((condition & G_IO_HUP) != 0) { g_io_channel_shutdown (channel, TRUE, NULL); gtk_main_quit (); return FALSE; } return TRUE; }
static gboolean handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data) { static GtkTreeIter iter; static gint column_count = 0; static gint row_count = 0; gint n_columns = GPOINTER_TO_INT (data); GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (list_view)); if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP)) { GError *err = NULL; GString *string = g_string_new (NULL); while (channel->is_readable != TRUE); do { YadColumn *col; GdkPixbuf *pb; gint status; do { status = g_io_channel_read_line_string (channel, string, NULL, &err); while (gtk_events_pending ()) gtk_main_iteration (); } while (status == G_IO_STATUS_AGAIN); if (status != G_IO_STATUS_NORMAL) { if (err) { g_printerr ("yad_list_handle_stdin(): %s\n", err->message); g_error_free (err); err = NULL; } /* stop handling */ g_io_channel_shutdown (channel, TRUE, NULL); return FALSE; } strip_new_line (string->str); if (string->str[0] == '\014') { /* clear list if ^L received */ gtk_list_store_clear (GTK_LIST_STORE (model)); row_count = column_count = 0; continue; } if (row_count == 0 && column_count == 0) gtk_list_store_append (GTK_LIST_STORE (model), &iter); else if (column_count == n_columns) { /* We're starting a new row */ column_count = 0; row_count++; if (options.list_data.limit && row_count >= options.list_data.limit) { gtk_tree_model_get_iter_first (model, &iter); gtk_list_store_remove (GTK_LIST_STORE (model), &iter); } gtk_list_store_append (GTK_LIST_STORE (model), &iter); } col = (YadColumn *) g_slist_nth_data (options.list_data.columns, column_count); switch (col->type) { case YAD_COLUMN_CHECK: case YAD_COLUMN_RADIO: if (strcasecmp (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); break; case YAD_COLUMN_NUM: gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, g_ascii_strtoll (string->str, NULL, 10), -1); break; case YAD_COLUMN_FLOAT: gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, g_ascii_strtod (string->str, NULL), -1); break; case YAD_COLUMN_IMAGE: pb = get_pixbuf (string->str, YAD_SMALL_ICON); if (pb) { gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, pb, -1); g_object_unref (pb); } break; default: gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, string->str, -1); break; } column_count++; } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); g_string_free (string, TRUE); } if ((condition != G_IO_IN) && (condition != G_IO_IN + G_IO_HUP)) { g_io_channel_shutdown (channel, TRUE, NULL); return FALSE; } return TRUE; }