Exemplo n.º 1
0
static VALUE
rg_add_custom_tab(VALUE self, VALUE child, VALUE tab_label)
{
    gtk_print_unix_dialog_add_custom_tab(_SELF(self),
                                         RVAL2GTKWIDGET(child),
                                         RVAL2GTKWIDGET(tab_label));
    return self;
}
Exemplo n.º 2
0
/* void showPrintDialog (in nsIDOMWindow parent,
			 in nsIWebBrowserPrint webBrowserPrint,
			 in nsIPrintSettings printSettings); */
NS_IMETHODIMP
GeckoPrintService::ShowPrintDialog (nsIDOMWindow *aParent,
				    nsIWebBrowserPrint *aWebBrowserPrint,
				    nsIPrintSettings *aSettings)
{
  GaleonEmbedShell *shell;

  GeckoPrintSession *session = GeckoPrintSession::FromSettings (aSettings);
  NS_ENSURE_TRUE (session, NS_ERROR_INVALID_POINTER);

  shell = galeon_shell_get_embed_shell (galeon_shell);

  nsresult rv;
  PRBool haveSelection = PR_FALSE;
  rv = aSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &haveSelection);
  NS_ENSURE_SUCCESS (rv, rv);

  PRInt16 frameUI = nsIPrintSettings::kFrameEnableAll;
  rv = aSettings->GetHowToEnableFrameUI (&frameUI);
  NS_ENSURE_SUCCESS (rv, rv);

  GtkWindow *parent = GTK_WINDOW (GaleonUtils::FindGtkParent (aParent));
  NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER);

  GtkWidget *custom_tab              = NULL,
            *frame_box               = NULL,
            *print_frames_normal     = NULL,
            *print_frames_selected   = NULL,
            *print_frames_separately = NULL;
  GError    *gerror                  = NULL;
  guint      builder_ret;
  
  GtkBuilder *builder = gtk_builder_new ();
  builder_ret = gtk_builder_add_from_file (builder, SHARE_DIR "/print-tab.xml", &gerror);
  if (builder_ret) {
    /* Build the custom tab */
    custom_tab = GTK_WIDGET (gtk_builder_get_object (builder, "custom_tab_container"));

    gul_gui_connect_checkbutton_to_gconf (GTK_WIDGET (gtk_builder_get_object (builder, "print_bg_colors_checkbutton")),
                                          CONF_PRINT_BG_COLORS);
    gul_gui_connect_checkbutton_to_gconf (GTK_WIDGET (gtk_builder_get_object (builder, "print_bg_images_checkbutton")),
                                          CONF_PRINT_BG_IMAGES);
    gul_gui_connect_checkbutton_to_gconf (GTK_WIDGET (gtk_builder_get_object (builder, "print_date_checkbutton")),
                                          CONF_PRINT_DATE);
    gul_gui_connect_checkbutton_to_gconf (GTK_WIDGET (gtk_builder_get_object (builder, "print_page_numbers_checkbutton")),
                                          CONF_PRINT_PAGE_NUMBERS);
    gul_gui_connect_checkbutton_to_gconf (GTK_WIDGET (gtk_builder_get_object (builder, "print_page_title_checkbutton")),
                                          CONF_PRINT_PAGE_TITLE);
    gul_gui_connect_checkbutton_to_gconf (GTK_WIDGET (gtk_builder_get_object (builder, "print_page_url_checkbutton")),
                                          CONF_PRINT_PAGE_URL);

    frame_box = GTK_WIDGET (gtk_builder_get_object (builder, "frame_box"));
    print_frames_normal = GTK_WIDGET (gtk_builder_get_object (builder, "print_frames_normal"));
    print_frames_selected = GTK_WIDGET (gtk_builder_get_object (builder, "print_frames_selected"));
    print_frames_separately = GTK_WIDGET (gtk_builder_get_object (builder, "print_frames_separately"));

    /* FIXME: store/load from pref */
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (print_frames_normal), TRUE);

    if (frameUI == nsIPrintSettings::kFrameEnableAll) {
      /* Allow all frame options */
      gtk_widget_set_sensitive (frame_box, TRUE);
    } else if (frameUI == nsIPrintSettings::kFrameEnableAsIsAndEach) {
      /* Allow all except "selected frame" */
      gtk_widget_set_sensitive (frame_box, TRUE);
      gtk_widget_set_sensitive (print_frames_selected, FALSE);
      /* Preselect this one, since the default above only prints _one page_ ! */
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (print_frames_separately), TRUE);
    }
  }

  /* FIXME: this sucks! find some way to do all of this async! */
  GtkWidget *dialog = gtk_print_unix_dialog_new (NULL /* FIXME title */,
                                                 GTK_WINDOW (parent));
  GtkPrintUnixDialog *print_dialog = GTK_PRINT_UNIX_DIALOG (dialog);

  GtkPrintCapabilities capabilities =
	 GtkPrintCapabilities (GTK_PRINT_CAPABILITY_PAGE_SET |
			       GTK_PRINT_CAPABILITY_COPIES   |
			       GTK_PRINT_CAPABILITY_COLLATE  |
			       GTK_PRINT_CAPABILITY_REVERSE  |
			       GTK_PRINT_CAPABILITY_SCALE |
			       GTK_PRINT_CAPABILITY_GENERATE_PS);
#ifdef HAVE_GECKO_1_9
  capabilities = GtkPrintCapabilities (capabilities | GTK_PRINT_CAPABILITY_GENERATE_PDF);
#endif
  gtk_print_unix_dialog_set_manual_capabilities	(print_dialog, capabilities);

  gtk_print_unix_dialog_set_page_setup (print_dialog,
					galeon_embed_shell_get_page_setup (shell));
  gtk_print_unix_dialog_set_settings (print_dialog,
				      galeon_embed_shell_get_print_settings (shell));

  PRInt16 printFrames = nsIPrintSettings::kNoFrames;
  if (builder_ret) {
    g_object_ref_sink (custom_tab);
    gtk_print_unix_dialog_add_custom_tab (print_dialog, custom_tab,
					  gtk_label_new (_("Options"))); /* FIXME better name! */
  
    g_object_unref (custom_tab);
    g_object_unref (builder);

    if (frameUI != nsIPrintSettings::kFrameEnableNone) {
      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (print_frames_normal))) {
        printFrames = nsIPrintSettings::kFramesAsIs;
      } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (print_frames_selected))) {
        printFrames = nsIPrintSettings::kSelectedFrame;
      } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (print_frames_separately))) {
        printFrames = nsIPrintSettings::kEachFrameSep;
      }
    }
  }

  int response = gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_hide (dialog);

  GtkPrinter *printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);

  if (response != GTK_RESPONSE_OK || !printer) {
    gtk_widget_destroy (dialog);

    return NS_ERROR_ABORT;
  }

  GtkPageSetup *pageSetup = gtk_print_unix_dialog_get_page_setup (print_dialog); /* no reference owned */
  galeon_embed_shell_set_page_setup (shell, pageSetup);

  GtkPrintSettings *settings = gtk_print_unix_dialog_get_settings (print_dialog);
  galeon_embed_shell_set_print_settings (shell, settings);

  /* We copy the setup and settings so we can modify them to unset
   * options handled by gecko.
   */
  GtkPageSetup *pageSetupCopy = gtk_page_setup_copy (pageSetup);
  pageSetup = pageSetupCopy;

  GtkPrintSettings *settingsCopy = gtk_print_settings_copy (settings);
  g_object_unref (settings);
  settings = settingsCopy;

  rv = session->SetSettings (aSettings, settings, pageSetup, printer);

  /* Now translate the settings to nsIPrintSettings */
  if (NS_SUCCEEDED (rv)) {
    nsCString sourceFile;
    session->GetSourceFile (sourceFile);
    if (!sourceFile.IsEmpty ()) {
      rv = TranslateSettings (settings, pageSetup, printer, sourceFile, printFrames, PR_TRUE, aSettings);
    } else {
      rv = NS_ERROR_FAILURE;
    }
  }

  gtk_widget_destroy (dialog);

  g_object_unref (settings);
  g_object_unref (pageSetup);

  return rv;
}