void pgd_action_view_set_action (GtkWidget *action_view, PopplerAction *action) { GtkWidget *alignment; GtkWidget *table; gint row = 0; alignment = gtk_bin_get_child (GTK_BIN (action_view)); if (alignment) { gtk_container_remove (GTK_CONTAINER (action_view), alignment); } alignment = gtk_alignment_new (0.5, 0.5, 1, 1); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 12, 5); gtk_container_add (GTK_CONTAINER (action_view), alignment); gtk_widget_show (alignment); if (!action) return; table = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (table), 6); gtk_grid_set_row_spacing (GTK_GRID (table), 6); pgd_table_add_property (GTK_GRID (table), "<b>Title:</b>", action->any.title, &row); switch (action->type) { case POPPLER_ACTION_UNKNOWN: pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "Unknown", &row); break; case POPPLER_ACTION_NONE: pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "None", &row); break; case POPPLER_ACTION_GOTO_DEST: pgd_action_view_add_destination (action_view, GTK_GRID (table), action->goto_dest.dest, FALSE, &row); break; case POPPLER_ACTION_GOTO_REMOTE: pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "Remote Destination", &row); pgd_table_add_property (GTK_GRID (table), "<b>Filename:</b>", action->goto_remote.file_name, &row); pgd_action_view_add_destination (action_view, GTK_GRID (table), action->goto_remote.dest, TRUE, &row); break; case POPPLER_ACTION_LAUNCH: pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "Launch", &row); pgd_table_add_property (GTK_GRID (table), "<b>Filename:</b>", action->launch.file_name, &row); pgd_table_add_property (GTK_GRID (table), "<b>Params:</b>", action->launch.params, &row); break; case POPPLER_ACTION_URI: pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "External URI", &row); pgd_table_add_property (GTK_GRID (table), "<b>URI</b>", action->uri.uri, &row); break; case POPPLER_ACTION_NAMED: pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "Named Action", &row); pgd_table_add_property (GTK_GRID (table), "<b>Name:</b>", action->named.named_dest, &row); break; case POPPLER_ACTION_MOVIE: { GtkWidget *movie_view = pgd_movie_view_new (); pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "Movie", &row); pgd_table_add_property (GTK_GRID (table), "<b>Operation:</b>", get_movie_op (action->movie.operation), &row); pgd_movie_view_set_movie (movie_view, action->movie.movie); pgd_table_add_property_with_custom_widget (GTK_GRID (table), "<b>Movie:</b>", movie_view, &row); } break; case POPPLER_ACTION_RENDITION: { gchar *text; pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "Rendition", &row); text = g_strdup_printf ("%d", action->rendition.op); pgd_table_add_property (GTK_GRID (table), "<b>Operation:</b>", text, &row); g_free (text); if (action->rendition.media) { gboolean embedded = poppler_media_is_embedded (action->rendition.media); GtkWidget *button; pgd_table_add_property (GTK_GRID (table), "<b>Embedded:</b>", embedded ? "Yes": "No", &row); if (embedded) { const gchar *mime_type = poppler_media_get_mime_type (action->rendition.media); pgd_table_add_property (GTK_GRID (table), "<b>Mime type:</b>", mime_type ? mime_type : "", &row); } else { pgd_table_add_property (GTK_GRID (table), "<b>Filename:</b>", poppler_media_get_filename (action->rendition.media), &row); } button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY); g_signal_connect (button, "clicked", G_CALLBACK (pgd_action_view_play_rendition), action->rendition.media); pgd_table_add_property_with_custom_widget (GTK_GRID (table), NULL, button, &row); gtk_widget_show (button); } } break; case POPPLER_ACTION_OCG_STATE: { GList *l; GtkWidget *button; pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "OCGState", &row); for (l = action->ocg_state.state_list; l; l = g_list_next (l)) { PopplerActionLayer *action_layer = (PopplerActionLayer *)l->data; gchar *text; gint n_layers = g_list_length (action_layer->layers); switch (action_layer->action) { case POPPLER_ACTION_LAYER_ON: text = g_strdup_printf ("%d layers On", n_layers); break; case POPPLER_ACTION_LAYER_OFF: text = g_strdup_printf ("%d layers Off", n_layers); break; case POPPLER_ACTION_LAYER_TOGGLE: text = g_strdup_printf ("%d layers Toggle", n_layers); break; } pgd_table_add_property (GTK_GRID (table), "<b>Action:</b>", text, &row); g_free (text); } button = gtk_button_new_with_label ("Do action"); g_signal_connect (button, "clicked", G_CALLBACK (pgd_action_view_do_action_layer), action->ocg_state.state_list); pgd_table_add_property_with_custom_widget (GTK_GRID (table), NULL, button, &row); gtk_widget_show (button); } break; case POPPLER_ACTION_JAVASCRIPT: { GtkTextBuffer *buffer; GtkWidget *textview; GtkWidget *swindow; pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "JavaScript", &row); buffer = gtk_text_buffer_new (NULL); if (action->javascript.script) gtk_text_buffer_set_text (buffer, action->javascript.script, -1); textview = gtk_text_view_new_with_buffer (buffer); gtk_text_view_set_editable (GTK_TEXT_VIEW (textview), FALSE); g_object_unref (buffer); swindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (swindow), textview); gtk_widget_show (textview); pgd_table_add_property_with_custom_widget (GTK_GRID (table), NULL, swindow, &row); gtk_widget_show (swindow); } break; default: g_assert_not_reached (); } gtk_container_add (GTK_CONTAINER (alignment), table); gtk_widget_show (table); }
static void pgd_action_view_add_destination (GtkWidget *action_view, GtkGrid *table, PopplerDest *dest, gboolean remote, gint *row) { PopplerDocument *document; GEnumValue *enum_value; gchar *str; pgd_table_add_property (table, "<b>Type:</b>", "Destination", row); enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_DEST_TYPE), dest->type); pgd_table_add_property (table, "<b>Destination Type:</b>", enum_value->value_name, row); document = g_object_get_data (G_OBJECT (action_view), "document"); if (dest->type != POPPLER_DEST_NAMED) { str = NULL; if (document && !remote) { PopplerPage *poppler_page; gchar *page_label; poppler_page = poppler_document_get_page (document, MAX (0, dest->page_num - 1)); g_object_get (G_OBJECT (poppler_page), "label", &page_label, NULL); if (page_label) { str = g_strdup_printf ("%d (%s)", dest->page_num, page_label); g_free (page_label); } } if (!str) str = g_strdup_printf ("%d", dest->page_num); pgd_table_add_property (table, "<b>Page:</b>", str, row); g_free (str); str = g_strdup_printf ("%.2f", dest->left); pgd_table_add_property (table, "<b>Left:</b>", str, row); g_free (str); str = g_strdup_printf ("%.2f", dest->right); pgd_table_add_property (table, "<b>Right:</b>", str, row); g_free (str); str = g_strdup_printf ("%.2f", dest->top); pgd_table_add_property (table, "<b>Top:</b>", str, row); g_free (str); str = g_strdup_printf ("%.2f", dest->bottom); pgd_table_add_property (table, "<b>Bottom:</b>", str, row); g_free (str); str = g_strdup_printf ("%.2f", dest->zoom); pgd_table_add_property (table, "<b>Zoom:</b>", str, row); g_free (str); } else { pgd_table_add_property (table, "<b>Named Dest:</b>", dest->named_dest, row); if (document && !remote) { PopplerDest *new_dest; new_dest = poppler_document_find_dest (document, dest->named_dest); if (new_dest) { GtkWidget *new_table, *alignment; gint new_row = 0; alignment = gtk_alignment_new (0.5, 0.5, 1, 1); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 12, 5); new_table = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (new_table), 6); gtk_grid_set_row_spacing (GTK_GRID (new_table), 6); gtk_grid_attach (GTK_GRID(table), alignment, 0, *row, 1, 1); gtk_widget_show (alignment); pgd_action_view_add_destination (action_view, GTK_GRID (new_table), new_dest, FALSE, &new_row); poppler_dest_free (new_dest); gtk_container_add (GTK_CONTAINER (alignment), new_table); gtk_widget_show (new_table); *row += 1; } } } }
void pgd_action_view_set_action (GtkWidget *action_view, PopplerAction *action) { GtkWidget *alignment; GtkWidget *table; GEnumValue *enum_value; gint row = 0; alignment = gtk_bin_get_child (GTK_BIN (action_view)); if (alignment) { gtk_container_remove (GTK_CONTAINER (action_view), alignment); } alignment = gtk_alignment_new (0.5, 0.5, 1, 1); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 12, 5); gtk_container_add (GTK_CONTAINER (action_view), alignment); gtk_widget_show (alignment); if (!action) return; table = gtk_table_new (10, 2, FALSE); gtk_table_set_col_spacings (GTK_TABLE (table), 6); gtk_table_set_row_spacings (GTK_TABLE (table), 6); pgd_table_add_property (GTK_TABLE (table), "<b>Title:</b>", action->any.title, &row); switch (action->type) { case POPPLER_ACTION_UNKNOWN: pgd_table_add_property (GTK_TABLE (table), "<b>Type:</b>", "Unknown", &row); break; case POPPLER_ACTION_GOTO_DEST: pgd_action_view_add_destination (action_view, GTK_TABLE (table), action->goto_dest.dest, &row); break; case POPPLER_ACTION_GOTO_REMOTE: pgd_table_add_property (GTK_TABLE (table), "<b>Type:</b>", "Remote Destination", &row); pgd_table_add_property (GTK_TABLE (table), "<b>Filename:</b>", action->goto_remote.file_name, &row); pgd_action_view_add_destination (action_view, GTK_TABLE (table), action->goto_remote.dest, &row); break; case POPPLER_ACTION_LAUNCH: pgd_table_add_property (GTK_TABLE (table), "<b>Type:</b>", "Launch", &row); pgd_table_add_property (GTK_TABLE (table), "<b>Filename:</b>", action->launch.file_name, &row); pgd_table_add_property (GTK_TABLE (table), "<b>Params:</b>", action->launch.file_name, &row); break; case POPPLER_ACTION_URI: pgd_table_add_property (GTK_TABLE (table), "<b>Type:</b>", "External URI", &row); pgd_table_add_property (GTK_TABLE (table), "<b>URI</b>", action->uri.uri, &row); break; case POPPLER_ACTION_NAMED: pgd_table_add_property (GTK_TABLE (table), "<b>Type:</b>", "Named Action", &row); pgd_table_add_property (GTK_TABLE (table), "<b>Name:</b>", action->named.named_dest, &row); break; case POPPLER_ACTION_MOVIE: pgd_table_add_property (GTK_TABLE (table), "<b>Type:</b>", "Movie", &row); break; default: g_assert_not_reached (); } gtk_container_add (GTK_CONTAINER (alignment), table); gtk_widget_show (table); }