+ int dives_per_page = 1;
+ if (print_options.type == PRETTY) {
+ if (print_options.print_profiles){
+ dives_per_page = 6;
+ } else {
+ dives_per_page = 15;
+ }
+ } else {
+ dives_per_page = 25;
+ }
+ int pages;
+ pages = (dive_table.nr + dives_per_page - 1) / dives_per_page;
+ gtk_print_operation_set_n_pages(operation, pages);
+}
+
+static void update_print_window(GtkWidget *w) {
+ if (print_options.type == TABLE) {
+ // type == table - disable the profile option
+ gtk_widget_set_sensitive(w, FALSE);
+ } else {
+ // type == pretty - enable the profile option
+ gtk_widget_set_sensitive(w, TRUE);
+ }
+}
+
+#define OPTIONCALLBACK(name, type, value) \
+static void name(GtkWidget *w, gpointer data) \
+{\
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) \
+ print_options.type = value; \
+ update_print_window(data); \
+}
+
+OPTIONCALLBACK(set_pretty, type, PRETTY)
+OPTIONCALLBACK(set_table, type, TABLE)
+
+static GtkWidget *print_dialog(GtkPrintOperation *operation, gpointer user_data)
+{
+ GtkWidget *vbox, *button, *radio1, *radio2, *frame, *box;
+ gtk_print_operation_set_custom_tab_label(operation, "Dive details");
+
+ vbox = gtk_vbox_new(TRUE, 5);
+
+ frame = gtk_frame_new("Print type");
+ gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 1);
+
+ box = gtk_hbox_new(FALSE, 2);
+ gtk_container_add(GTK_CONTAINER(frame), box);
+
+ radio1 = gtk_radio_button_new_with_label (NULL, "Pretty print");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio1),
+ print_options.type == PRETTY);
+ radio2 = gtk_radio_button_new_with_label_from_widget (
+ GTK_RADIO_BUTTON (radio1), "Table print");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio2),
+ print_options.type == TABLE);
+ gtk_box_pack_start (GTK_BOX (box), radio1, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), radio2, TRUE, TRUE, 0);
+
+
+ frame = gtk_frame_new("Print options");
+ gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 1);
+
+ box = gtk_hbox_new(FALSE, 3);
+ gtk_container_add(GTK_CONTAINER(frame), box);
+
+ button = gtk_check_button_new_with_label("Show profiles");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), print_options.print_profiles);
+ gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 2);
+ g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(print_profiles_toggle), NULL);
+
+ g_signal_connect(radio1, "toggled", G_CALLBACK(set_pretty), button);
+ g_signal_connect(radio2, "toggled", G_CALLBACK(set_table), button);
+
+ gtk_widget_show_all(vbox);
+ return vbox;
+}
+
+static void print_dialog_apply(GtkPrintOperation *operation, GtkWidget *widget, gpointer user_data)
+{
+ if (print_options.type == PRETTY) {
+ if (print_options.print_profiles){
+ g_signal_connect(operation, "draw_page",
+ G_CALLBACK(draw_page), NULL);
+ } else {
+ g_signal_connect(operation, "draw_page",
+ G_CALLBACK(draw_pretty_table), NULL);
+ }
+ } else {
+ g_signal_connect(operation, "draw_page",
+ G_CALLBACK(draw_table), NULL);
+ }