2012-07-16 15:25:10 +02:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
|
|
|
*
|
|
|
|
* Copyright 2012 Red Hat, Inc,
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2012-09-06 14:06:01 +02:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2012-07-16 15:25:10 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 12:57:27 +01:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-07-16 15:25:10 +02:00
|
|
|
*
|
|
|
|
* Author: Marek Kasik <mkasik@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include <cups/cups.h>
|
|
|
|
#include <cups/ppd.h>
|
|
|
|
|
|
|
|
#include "pp-options-dialog.h"
|
2017-03-06 18:05:38 +01:00
|
|
|
#include "pp-maintenance-command.h"
|
2012-07-16 15:25:10 +02:00
|
|
|
#include "pp-ppd-option-widget.h"
|
|
|
|
#include "pp-ipp-option-widget.h"
|
|
|
|
#include "pp-utils.h"
|
2017-03-06 18:05:38 +01:00
|
|
|
#include "pp-printer.h"
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
struct _PpOptionsDialog {
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
UserResponseCallback user_callback;
|
|
|
|
gpointer user_data;
|
|
|
|
|
|
|
|
gchar *printer_name;
|
|
|
|
|
|
|
|
gchar *ppd_filename;
|
|
|
|
gboolean ppd_filename_set;
|
|
|
|
|
|
|
|
cups_dest_t *destination;
|
|
|
|
gboolean destination_set;
|
|
|
|
|
|
|
|
GHashTable *ipp_attributes;
|
|
|
|
gboolean ipp_attributes_set;
|
|
|
|
|
|
|
|
gboolean populating_dialog;
|
|
|
|
|
|
|
|
GtkResponseType response;
|
|
|
|
|
|
|
|
gboolean sensitive;
|
|
|
|
};
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
static void pp_options_dialog_hide (PpOptionsDialog *self);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CATEGORY_IDS_COLUMN = 0,
|
|
|
|
CATEGORY_NAMES_COLUMN
|
|
|
|
};
|
|
|
|
|
|
|
|
/* These lists come from Gtk+ */
|
|
|
|
static const struct {
|
|
|
|
const char *keyword;
|
|
|
|
const char *translation;
|
|
|
|
} ppd_option_translations[] = {
|
|
|
|
{ "Duplex", N_("Two Sided") },
|
|
|
|
{ "MediaType", N_("Paper Type") },
|
|
|
|
{ "InputSlot", N_("Paper Source") },
|
|
|
|
{ "OutputBin", N_("Output Tray") },
|
|
|
|
{ "Resolution", N_("Resolution") },
|
|
|
|
{ "PreFilter", N_("GhostScript pre-filtering") },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *page_setup_option_whitelist[] = {
|
|
|
|
"InputSlot",
|
|
|
|
"MediaType",
|
|
|
|
"OutputBin",
|
|
|
|
"PageSize",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *color_option_whitelist[] = {
|
|
|
|
"BRColorEnhancement",
|
|
|
|
"BRColorMatching",
|
|
|
|
"BRColorMatching",
|
|
|
|
"BRColorMode",
|
|
|
|
"BRGammaValue",
|
|
|
|
"BRImprovedGray",
|
|
|
|
"BlackSubstitution",
|
|
|
|
"ColorModel",
|
|
|
|
"HPCMYKInks",
|
|
|
|
"HPCSGraphics",
|
|
|
|
"HPCSImages",
|
|
|
|
"HPCSText",
|
|
|
|
"HPColorSmart",
|
|
|
|
"RPSBlackMode",
|
|
|
|
"RPSBlackOverPrint",
|
|
|
|
"Rcmyksimulation",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *color_group_whitelist[] = {
|
|
|
|
"Color",
|
|
|
|
"Color1",
|
|
|
|
"Color2",
|
|
|
|
"ColorBalance",
|
|
|
|
"ColorPage",
|
|
|
|
"ColorSettings1",
|
|
|
|
"ColorSettings2",
|
|
|
|
"ColorSettings3",
|
|
|
|
"ColorSettings4",
|
|
|
|
"EPColorSettings",
|
|
|
|
"FPColorWise1",
|
|
|
|
"FPColorWise2",
|
|
|
|
"FPColorWise3",
|
|
|
|
"FPColorWise4",
|
|
|
|
"FPColorWise5",
|
|
|
|
"HPCMYKInksPanel",
|
|
|
|
"HPColorOptions",
|
|
|
|
"HPColorOptionsPanel",
|
|
|
|
"HPColorQualityOptionsPanel",
|
|
|
|
"ManualColor",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *image_quality_option_whitelist[] = {
|
|
|
|
"BRDocument",
|
|
|
|
"BRHalfTonePattern",
|
|
|
|
"BRNormalPrt",
|
|
|
|
"BRPrintQuality",
|
|
|
|
"BitsPerPixel",
|
|
|
|
"Darkness",
|
|
|
|
"Dithering",
|
|
|
|
"EconoMode",
|
|
|
|
"Economode",
|
|
|
|
"HPEconoMode",
|
|
|
|
"HPEdgeControl",
|
|
|
|
"HPGraphicsHalftone",
|
|
|
|
"HPHalftone",
|
|
|
|
"HPImagingOptions",
|
|
|
|
"HPLJDensity",
|
|
|
|
"HPPhotoHalftone",
|
|
|
|
"HPPrintQualityOptions",
|
|
|
|
"HPResolutionOptions",
|
|
|
|
"OutputMode",
|
|
|
|
"REt",
|
|
|
|
"RPSBitsPerPixel",
|
|
|
|
"RPSDitherType",
|
|
|
|
"Resolution",
|
|
|
|
"ScreenLock",
|
|
|
|
"Smoothing",
|
|
|
|
"TonerSaveMode",
|
|
|
|
"UCRGCRForImage",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *image_quality_group_whitelist[] = {
|
|
|
|
"EPQualitySettings",
|
|
|
|
"FPImageQuality1",
|
|
|
|
"FPImageQuality2",
|
|
|
|
"FPImageQuality3",
|
|
|
|
"ImageQualityPage",
|
|
|
|
"Quality",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char * finishing_option_whitelist[] = {
|
|
|
|
"BindColor",
|
|
|
|
"BindEdge",
|
|
|
|
"BindType",
|
|
|
|
"BindWhen",
|
|
|
|
"Booklet",
|
|
|
|
"FoldType",
|
|
|
|
"FoldWhen",
|
|
|
|
"HPStaplerOptions",
|
|
|
|
"Jog",
|
|
|
|
"Slipsheet",
|
|
|
|
"Sorter",
|
|
|
|
"StapleLocation",
|
|
|
|
"StapleOrientation",
|
|
|
|
"StapleWhen",
|
|
|
|
"StapleX",
|
|
|
|
"StapleY",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *job_group_whitelist[] = {
|
|
|
|
"JobHandling",
|
|
|
|
"JobLog",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *finishing_group_whitelist[] = {
|
|
|
|
"Booklet",
|
|
|
|
"BookletCover",
|
|
|
|
"BookletModeOptions",
|
|
|
|
"FPFinishing1",
|
|
|
|
"FPFinishing2",
|
|
|
|
"FPFinishing3",
|
|
|
|
"FPFinishing4",
|
|
|
|
"Finishing",
|
|
|
|
"FinishingOptions",
|
|
|
|
"FinishingPage",
|
|
|
|
"HPBookletPanel",
|
|
|
|
"HPFinishing",
|
|
|
|
"HPFinishingOptions",
|
|
|
|
"HPFinishingPanel",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *installable_options_group_whitelist[] = {
|
|
|
|
"InstallableOptions",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *page_setup_group_whitelist[] = {
|
|
|
|
"HPMarginAndLayout",
|
|
|
|
"OutputControl",
|
|
|
|
"PaperHandling",
|
|
|
|
"Paper",
|
|
|
|
"Source",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* keep sorted when changing */
|
|
|
|
static const char *ppd_option_blacklist[] = {
|
|
|
|
"Collate",
|
|
|
|
"Copies",
|
|
|
|
"Duplex",
|
|
|
|
"HPManualDuplexOrientation",
|
|
|
|
"HPManualDuplexSwitch",
|
|
|
|
"OutputOrder",
|
|
|
|
"PageRegion"
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
strptr_cmp (const void *a,
|
|
|
|
const void *b)
|
|
|
|
{
|
|
|
|
char **aa = (char **)a;
|
|
|
|
char **bb = (char **)b;
|
|
|
|
return strcmp (*aa, *bb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
string_in_table (gchar *str,
|
|
|
|
const gchar *table[],
|
|
|
|
gint table_len)
|
|
|
|
{
|
|
|
|
return bsearch (&str, table, table_len, sizeof (char *), (void *)strptr_cmp) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define STRING_IN_TABLE(_str, _table) (string_in_table (_str, _table, G_N_ELEMENTS (_table)))
|
|
|
|
|
2018-06-15 14:38:03 +12:00
|
|
|
static const gchar *
|
2012-07-16 15:25:10 +02:00
|
|
|
ppd_option_name_translate (ppd_option_t *option)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (ppd_option_translations); i++)
|
|
|
|
{
|
|
|
|
if (g_strcmp0 (ppd_option_translations[i].keyword, option->keyword) == 0)
|
2018-06-15 14:38:03 +12:00
|
|
|
return _(ppd_option_translations[i].translation);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-06-15 14:38:03 +12:00
|
|
|
return option->text;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
grid_get_height (GtkWidget *grid)
|
|
|
|
{
|
|
|
|
GList *children;
|
|
|
|
GList *child;
|
|
|
|
gint height = 0;
|
|
|
|
gint top_attach = 0;
|
|
|
|
gint max = 0;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (grid));
|
|
|
|
for (child = children; child; child = g_list_next (child))
|
|
|
|
{
|
|
|
|
gtk_container_child_get (GTK_CONTAINER (grid), child->data,
|
|
|
|
"top-attach", &top_attach,
|
|
|
|
"height", &height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (height + top_attach > max)
|
|
|
|
max = height + top_attach;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
grid_is_empty (GtkWidget *grid)
|
|
|
|
{
|
|
|
|
GList *children;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (grid));
|
|
|
|
if (children)
|
|
|
|
{
|
|
|
|
g_list_free (children);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
ipp_option_add (IPPAttribute *attr_supported,
|
|
|
|
IPPAttribute *attr_default,
|
|
|
|
const gchar *option_name,
|
|
|
|
const gchar *option_display_name,
|
|
|
|
const gchar *printer_name,
|
|
|
|
GtkWidget *grid,
|
|
|
|
gboolean sensitive)
|
|
|
|
{
|
|
|
|
GtkStyleContext *context;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *label;
|
|
|
|
gint position;
|
|
|
|
|
|
|
|
widget = (GtkWidget *) pp_ipp_option_widget_new (attr_supported,
|
|
|
|
attr_default,
|
|
|
|
option_name,
|
|
|
|
printer_name);
|
|
|
|
if (widget)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (widget, sensitive);
|
|
|
|
position = grid_get_height (grid);
|
|
|
|
|
|
|
|
label = gtk_label_new (option_display_name);
|
2019-01-03 15:58:30 -05:00
|
|
|
gtk_label_set_mnemonic_widget (label, widget);
|
2012-07-16 15:25:10 +02:00
|
|
|
context = gtk_widget_get_style_context (label);
|
|
|
|
gtk_style_context_add_class (context, "dim-label");
|
2014-11-07 14:57:00 +01:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2013-11-19 22:28:28 +02:00
|
|
|
gtk_widget_set_margin_start (label, 10);
|
2012-07-16 15:25:10 +02:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, position, 1, 1);
|
|
|
|
|
2013-11-19 22:28:28 +02:00
|
|
|
gtk_widget_set_margin_start (widget, 20);
|
2012-07-16 15:25:10 +02:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), widget, 1, position, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
ppd_option_add (ppd_option_t option,
|
|
|
|
const gchar *printer_name,
|
|
|
|
GtkWidget *grid,
|
|
|
|
gboolean sensitive)
|
|
|
|
{
|
|
|
|
GtkStyleContext *context;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *label;
|
|
|
|
gint position;
|
|
|
|
|
|
|
|
widget = (GtkWidget *) pp_ppd_option_widget_new (&option, printer_name);
|
|
|
|
if (widget)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (widget, sensitive);
|
|
|
|
position = grid_get_height (grid);
|
|
|
|
|
|
|
|
label = gtk_label_new (ppd_option_name_translate (&option));
|
2019-01-03 15:58:30 -05:00
|
|
|
gtk_label_set_mnemonic_widget (label, widget);
|
2012-07-16 15:25:10 +02:00
|
|
|
context = gtk_widget_get_style_context (label);
|
|
|
|
gtk_style_context_add_class (context, "dim-label");
|
2014-11-07 14:57:00 +01:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2013-11-19 22:28:28 +02:00
|
|
|
gtk_widget_set_margin_start (label, 10);
|
2012-07-16 15:25:10 +02:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, position, 1, 1);
|
|
|
|
|
2013-11-19 22:28:28 +02:00
|
|
|
gtk_widget_set_margin_start (widget, 20);
|
2012-07-16 15:25:10 +02:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), widget, 1, position, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
tab_grid_new ()
|
|
|
|
{
|
|
|
|
GtkWidget *grid;
|
|
|
|
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (grid), 20);
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 15);
|
|
|
|
|
|
|
|
return grid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tab_add (const gchar *tab_name,
|
|
|
|
GtkWidget *options_notebook,
|
|
|
|
GtkTreeView *treeview,
|
|
|
|
GtkWidget *grid)
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
gboolean unref_store = FALSE;
|
|
|
|
gint id;
|
|
|
|
|
|
|
|
if (!grid_is_empty (grid))
|
|
|
|
{
|
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_NEVER,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2013-03-28 12:09:57 +01:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), grid);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
id = gtk_notebook_append_page (GTK_NOTEBOOK (options_notebook),
|
|
|
|
scrolled_window,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (id >= 0)
|
|
|
|
{
|
|
|
|
store = GTK_LIST_STORE (gtk_tree_view_get_model (treeview));
|
|
|
|
if (!store)
|
|
|
|
{
|
|
|
|
store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
|
|
|
|
unref_store = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
CATEGORY_IDS_COLUMN, id,
|
|
|
|
CATEGORY_NAMES_COLUMN, tab_name,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (unref_store)
|
|
|
|
{
|
|
|
|
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (store));
|
|
|
|
g_object_unref (store);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_ref_sink (grid);
|
|
|
|
g_object_unref (grid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
category_selection_changed_cb (GtkTreeSelection *selection,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpOptionsDialog *self = (PpOptionsDialog *) user_data;
|
2012-07-16 15:25:10 +02:00
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkWidget *options_notebook;
|
|
|
|
gint id = -1;
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected (selection, &model, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
CATEGORY_IDS_COLUMN, &id,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id >= 0)
|
|
|
|
{
|
|
|
|
options_notebook = (GtkWidget*)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_builder_get_object (self->builder, "options-notebook");
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
gtk_notebook_set_current_page (GTK_NOTEBOOK (options_notebook), id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-04 10:46:35 +13:00
|
|
|
populate_options_real (PpOptionsDialog *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeView *treeview;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
ppd_file_t *ppd_file;
|
|
|
|
GtkWidget *notebook;
|
|
|
|
GtkWidget *grid;
|
|
|
|
GtkWidget *general_tab_grid = tab_grid_new ();
|
|
|
|
GtkWidget *page_setup_tab_grid = tab_grid_new ();
|
|
|
|
GtkWidget *installable_options_tab_grid = tab_grid_new ();
|
|
|
|
GtkWidget *job_tab_grid = tab_grid_new ();
|
|
|
|
GtkWidget *image_quality_tab_grid = tab_grid_new ();
|
|
|
|
GtkWidget *color_tab_grid = tab_grid_new ();
|
|
|
|
GtkWidget *finishing_tab_grid = tab_grid_new ();
|
|
|
|
GtkWidget *advanced_tab_grid = tab_grid_new ();
|
|
|
|
GtkWidget *widget;
|
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
widget = (GtkWidget*)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_builder_get_object (self->builder, "options-spinner");
|
2012-07-16 15:25:10 +02:00
|
|
|
gtk_spinner_stop (GTK_SPINNER (widget));
|
|
|
|
|
|
|
|
widget = (GtkWidget*)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_builder_get_object (self->builder, "stack");
|
2015-09-27 23:51:40 -05:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (widget), "main-box");
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
treeview = (GtkTreeView *)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_builder_get_object (self->builder, "options-categories-treeview");
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
notebook = (GtkWidget *)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_builder_get_object (self->builder, "options-notebook");
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->ipp_attributes)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
|
|
|
/* Add number-up option to Page Setup tab */
|
2018-12-04 10:46:35 +13:00
|
|
|
ipp_option_add (g_hash_table_lookup (self->ipp_attributes,
|
2012-07-16 15:25:10 +02:00
|
|
|
"number-up-supported"),
|
2018-12-04 10:46:35 +13:00
|
|
|
g_hash_table_lookup (self->ipp_attributes,
|
2012-07-16 15:25:10 +02:00
|
|
|
"number-up-default"),
|
|
|
|
"number-up",
|
|
|
|
/* Translators: This option sets number of pages printed on one sheet */
|
|
|
|
_("Pages per side"),
|
2018-12-04 10:46:35 +13:00
|
|
|
self->printer_name,
|
2012-07-16 15:25:10 +02:00
|
|
|
page_setup_tab_grid,
|
2018-12-04 10:46:35 +13:00
|
|
|
self->sensitive);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
/* Add sides option to Page Setup tab */
|
2018-12-04 10:46:35 +13:00
|
|
|
ipp_option_add (g_hash_table_lookup (self->ipp_attributes,
|
2012-07-16 15:25:10 +02:00
|
|
|
"sides-supported"),
|
2018-12-04 10:46:35 +13:00
|
|
|
g_hash_table_lookup (self->ipp_attributes,
|
2012-07-16 15:25:10 +02:00
|
|
|
"sides-default"),
|
|
|
|
"sides",
|
|
|
|
/* Translators: This option sets whether to print on both sides of paper */
|
|
|
|
_("Two-sided"),
|
2018-12-04 10:46:35 +13:00
|
|
|
self->printer_name,
|
2012-07-16 15:25:10 +02:00
|
|
|
page_setup_tab_grid,
|
2018-12-04 10:46:35 +13:00
|
|
|
self->sensitive);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
/* Add orientation-requested option to Page Setup tab */
|
2018-12-04 10:46:35 +13:00
|
|
|
ipp_option_add (g_hash_table_lookup (self->ipp_attributes,
|
2012-07-16 15:25:10 +02:00
|
|
|
"orientation-requested-supported"),
|
2018-12-04 10:46:35 +13:00
|
|
|
g_hash_table_lookup (self->ipp_attributes,
|
2012-07-16 15:25:10 +02:00
|
|
|
"orientation-requested-default"),
|
|
|
|
"orientation-requested",
|
|
|
|
/* Translators: This option sets orientation of print (portrait, landscape...) */
|
|
|
|
_("Orientation"),
|
2018-12-04 10:46:35 +13:00
|
|
|
self->printer_name,
|
2012-07-16 15:25:10 +02:00
|
|
|
page_setup_tab_grid,
|
2018-12-04 10:46:35 +13:00
|
|
|
self->sensitive);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->destination && self->ppd_filename)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
ppd_file = ppdOpenFile (self->ppd_filename);
|
2012-07-16 15:25:10 +02:00
|
|
|
ppdLocalize (ppd_file);
|
|
|
|
|
|
|
|
if (ppd_file)
|
|
|
|
{
|
|
|
|
ppdMarkDefaults (ppd_file);
|
|
|
|
cupsMarkOptions (ppd_file,
|
2018-12-04 10:46:35 +13:00
|
|
|
self->destination->num_options,
|
|
|
|
self->destination->options);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
for (i = 0; i < ppd_file->num_groups; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < ppd_file->groups[i].num_options; j++)
|
|
|
|
{
|
|
|
|
grid = NULL;
|
|
|
|
|
|
|
|
if (STRING_IN_TABLE (ppd_file->groups[i].name,
|
|
|
|
color_group_whitelist))
|
|
|
|
grid = color_tab_grid;
|
|
|
|
else if (STRING_IN_TABLE (ppd_file->groups[i].name,
|
|
|
|
image_quality_group_whitelist))
|
|
|
|
grid = image_quality_tab_grid;
|
|
|
|
else if (STRING_IN_TABLE (ppd_file->groups[i].name,
|
|
|
|
job_group_whitelist))
|
|
|
|
grid = job_tab_grid;
|
|
|
|
else if (STRING_IN_TABLE (ppd_file->groups[i].name,
|
|
|
|
finishing_group_whitelist))
|
|
|
|
grid = finishing_tab_grid;
|
|
|
|
else if (STRING_IN_TABLE (ppd_file->groups[i].name,
|
|
|
|
installable_options_group_whitelist))
|
|
|
|
grid = installable_options_tab_grid;
|
|
|
|
else if (STRING_IN_TABLE (ppd_file->groups[i].name,
|
|
|
|
page_setup_group_whitelist))
|
|
|
|
grid = page_setup_tab_grid;
|
|
|
|
|
|
|
|
if (!STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword,
|
|
|
|
ppd_option_blacklist))
|
|
|
|
{
|
|
|
|
if (!grid && STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword,
|
|
|
|
color_option_whitelist))
|
|
|
|
grid = color_tab_grid;
|
|
|
|
else if (!grid && STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword,
|
|
|
|
image_quality_option_whitelist))
|
|
|
|
grid = image_quality_tab_grid;
|
|
|
|
else if (!grid && STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword,
|
|
|
|
finishing_option_whitelist))
|
|
|
|
grid = finishing_tab_grid;
|
|
|
|
else if (!grid && STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword,
|
|
|
|
page_setup_option_whitelist))
|
|
|
|
grid = page_setup_tab_grid;
|
|
|
|
|
|
|
|
if (!grid)
|
|
|
|
grid = advanced_tab_grid;
|
|
|
|
|
|
|
|
ppd_option_add (ppd_file->groups[i].options[j],
|
2018-12-04 10:46:35 +13:00
|
|
|
self->printer_name,
|
2012-07-16 15:25:10 +02:00
|
|
|
grid,
|
2018-12-04 10:46:35 +13:00
|
|
|
self->sensitive);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ppdClose (ppd_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->ppd_filename_set = FALSE;
|
|
|
|
if (self->ppd_filename)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
g_unlink (self->ppd_filename);
|
|
|
|
g_free (self->ppd_filename);
|
|
|
|
self->ppd_filename = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->destination_set = FALSE;
|
|
|
|
if (self->destination)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
cupsFreeDests (1, self->destination);
|
|
|
|
self->destination = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->ipp_attributes_set = FALSE;
|
|
|
|
if (self->ipp_attributes)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
g_hash_table_unref (self->ipp_attributes);
|
|
|
|
self->ipp_attributes = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Translators: "General" tab contains general printer options */
|
|
|
|
tab_add (C_("Printer Option Group", "General"), notebook, treeview, general_tab_grid);
|
|
|
|
|
|
|
|
/* Translators: "Page Setup" tab contains settings related to pages (page size, paper source, etc.) */
|
|
|
|
tab_add (C_("Printer Option Group", "Page Setup"), notebook, treeview, page_setup_tab_grid);
|
|
|
|
|
|
|
|
/* Translators: "Installable Options" tab contains settings of presence of installed options (amount of RAM, duplex unit, etc.) */
|
|
|
|
tab_add (C_("Printer Option Group", "Installable Options"), notebook, treeview, installable_options_tab_grid);
|
|
|
|
|
|
|
|
/* Translators: "Job" tab contains settings for jobs */
|
|
|
|
tab_add (C_("Printer Option Group", "Job"), notebook, treeview, job_tab_grid);
|
|
|
|
|
|
|
|
/* Translators: "Image Quality" tab contains settings for quality of output print (e.g. resolution) */
|
|
|
|
tab_add (C_("Printer Option Group", "Image Quality"), notebook, treeview, image_quality_tab_grid);
|
|
|
|
|
|
|
|
/* Translators: "Color" tab contains color settings (e.g. color printing) */
|
|
|
|
tab_add (C_("Printer Option Group", "Color"), notebook, treeview, color_tab_grid);
|
|
|
|
|
|
|
|
/* Translators: "Finishing" tab contains finishing settings (e.g. booklet printing) */
|
|
|
|
tab_add (C_("Printer Option Group", "Finishing"), notebook, treeview, finishing_tab_grid);
|
|
|
|
|
|
|
|
/* Translators: "Advanced" tab contains all others settings */
|
|
|
|
tab_add (C_("Printer Option Group", "Advanced"), notebook, treeview, advanced_tab_grid);
|
|
|
|
|
|
|
|
gtk_widget_show_all (GTK_WIDGET (notebook));
|
|
|
|
|
|
|
|
/* Select the first option group */
|
|
|
|
if ((selection = gtk_tree_view_get_selection (treeview)) != NULL)
|
|
|
|
{
|
|
|
|
g_signal_connect (selection,
|
|
|
|
"changed",
|
2018-12-04 10:46:35 +13:00
|
|
|
G_CALLBACK (category_selection_changed_cb), self);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
if ((model = gtk_tree_view_get_model (treeview)) != NULL &&
|
|
|
|
gtk_tree_model_get_iter_first (model, &iter))
|
|
|
|
gtk_tree_selection_select_iter (selection, &iter);
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->populating_dialog = FALSE;
|
|
|
|
if (self->response != GTK_RESPONSE_NONE)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
self->user_callback (GTK_DIALOG (self->dialog), self->response, self->user_data);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printer_get_ppd_cb (const gchar *ppd_filename,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpOptionsDialog *self = (PpOptionsDialog *) user_data;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->ppd_filename)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
g_unlink (self->ppd_filename);
|
|
|
|
g_free (self->ppd_filename);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->ppd_filename = g_strdup (ppd_filename);
|
|
|
|
self->ppd_filename_set = TRUE;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->destination_set &&
|
|
|
|
self->ipp_attributes_set)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
populate_options_real (self);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_named_dest_cb (cups_dest_t *dest,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpOptionsDialog *self = (PpOptionsDialog *) user_data;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->destination)
|
|
|
|
cupsFreeDests (1, self->destination);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->destination = dest;
|
|
|
|
self->destination_set = TRUE;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->ppd_filename_set &&
|
|
|
|
self->ipp_attributes_set)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
populate_options_real (self);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_ipp_attributes_cb (GHashTable *table,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpOptionsDialog *self = (PpOptionsDialog *) user_data;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->ipp_attributes)
|
|
|
|
g_hash_table_unref (self->ipp_attributes);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->ipp_attributes = table;
|
|
|
|
self->ipp_attributes_set = TRUE;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->ppd_filename_set &&
|
|
|
|
self->destination_set)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
populate_options_real (self);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-04 10:46:35 +13:00
|
|
|
populate_options (PpOptionsDialog *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkTreeView *treeview;
|
|
|
|
GtkWidget *widget;
|
|
|
|
/*
|
|
|
|
* Options which we need to obtain through an IPP request
|
|
|
|
* to be able to fill the options dialog.
|
|
|
|
* *-supported - possible values of the option
|
|
|
|
* *-default - actual value of the option
|
|
|
|
*/
|
|
|
|
const gchar *attributes[] =
|
|
|
|
{ "number-up-supported",
|
|
|
|
"number-up-default",
|
|
|
|
"sides-supported",
|
|
|
|
"sides-default",
|
|
|
|
"orientation-requested-supported",
|
|
|
|
"orientation-requested-default",
|
|
|
|
NULL};
|
|
|
|
|
2015-09-27 23:51:40 -05:00
|
|
|
widget = (GtkWidget*)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_builder_get_object (self->builder, "stack");
|
2015-09-27 23:51:40 -05:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (widget), "progress-box");
|
|
|
|
|
2012-07-16 15:25:10 +02:00
|
|
|
treeview = (GtkTreeView *)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_builder_get_object (self->builder, "options-categories-treeview");
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
|
|
|
|
column = gtk_tree_view_column_new_with_attributes ("Categories", renderer,
|
|
|
|
"text", CATEGORY_NAMES_COLUMN, NULL);
|
|
|
|
gtk_tree_view_column_set_expand (column, TRUE);
|
|
|
|
gtk_tree_view_append_column (treeview, column);
|
|
|
|
|
|
|
|
widget = (GtkWidget*)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_builder_get_object (self->builder, "options-spinner");
|
2012-07-16 15:25:10 +02:00
|
|
|
gtk_spinner_start (GTK_SPINNER (widget));
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
printer_get_ppd_async (self->printer_name,
|
2012-09-03 20:33:21 +02:00
|
|
|
NULL,
|
|
|
|
0,
|
2012-07-16 15:25:10 +02:00
|
|
|
printer_get_ppd_cb,
|
2018-12-04 10:46:35 +13:00
|
|
|
self);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
get_named_dest_async (self->printer_name,
|
2012-07-16 15:25:10 +02:00
|
|
|
get_named_dest_cb,
|
2018-12-04 10:46:35 +13:00
|
|
|
self);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
get_ipp_attributes_async (self->printer_name,
|
2012-07-16 15:25:10 +02:00
|
|
|
(gchar **) attributes,
|
|
|
|
get_ipp_attributes_cb,
|
2018-12-04 10:46:35 +13:00
|
|
|
self);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2017-03-06 18:05:38 +01:00
|
|
|
static void
|
|
|
|
pp_maintenance_command_execute_cb (GObject *source_object,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
PpMaintenanceCommand *command = (PpMaintenanceCommand *) source_object;
|
|
|
|
|
|
|
|
pp_maintenance_command_execute_finish (command, res, NULL);
|
|
|
|
|
|
|
|
g_object_unref (command);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
get_testprint_filename (const gchar *datadir)
|
|
|
|
{
|
|
|
|
const gchar *testprint[] = { "/data/testprint",
|
|
|
|
"/data/testprint.ps",
|
|
|
|
NULL };
|
|
|
|
gchar *filename = NULL;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; testprint[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
filename = g_strconcat (datadir, testprint[i], NULL);
|
|
|
|
if (g_access (filename, R_OK) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
g_clear_pointer (&filename, g_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_test_page_cb (GObject *source_object,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
pp_printer_print_file_finish (PP_PRINTER (source_object),
|
|
|
|
result, NULL);
|
|
|
|
|
|
|
|
g_object_unref (source_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_page_cb (GtkButton *button,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpOptionsDialog *self = (PpOptionsDialog*) user_data;
|
2017-03-06 18:05:38 +01:00
|
|
|
gint i;
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->printer_name)
|
2017-03-06 18:05:38 +01:00
|
|
|
{
|
2018-06-26 11:52:41 +12:00
|
|
|
const gchar *const dirs[] = { "/usr/share/cups",
|
|
|
|
"/usr/local/share/cups",
|
|
|
|
NULL };
|
|
|
|
const gchar *datadir = NULL;
|
|
|
|
g_autofree gchar *filename = NULL;
|
2017-03-06 18:05:38 +01:00
|
|
|
|
|
|
|
datadir = getenv ("CUPS_DATADIR");
|
|
|
|
if (datadir != NULL)
|
|
|
|
{
|
|
|
|
filename = get_testprint_filename (datadir);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; dirs[i] != NULL && filename == NULL; i++)
|
|
|
|
filename = get_testprint_filename (dirs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename != NULL)
|
|
|
|
{
|
|
|
|
PpPrinter *printer;
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
printer = pp_printer_new (self->printer_name);
|
2017-03-06 18:05:38 +01:00
|
|
|
pp_printer_print_file_async (printer,
|
|
|
|
filename,
|
|
|
|
/* Translators: Name of job which makes printer to print test page */
|
|
|
|
_("Test Page"),
|
|
|
|
NULL,
|
|
|
|
print_test_page_cb,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PpMaintenanceCommand *command;
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
command = pp_maintenance_command_new (self->printer_name,
|
2017-03-06 18:05:38 +01:00
|
|
|
"PrintSelfTestPage",
|
|
|
|
NULL,
|
|
|
|
/* Translators: Name of job which makes printer to print test page */
|
|
|
|
_("Test page"));
|
|
|
|
|
|
|
|
pp_maintenance_command_execute_async (command, NULL, pp_maintenance_command_execute_cb, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 15:25:10 +02:00
|
|
|
static void
|
|
|
|
options_dialog_response_cb (GtkDialog *_dialog,
|
|
|
|
gint response_id,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpOptionsDialog *self = (PpOptionsDialog*) user_data;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
pp_options_dialog_hide (self);
|
|
|
|
self->response = response_id;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (!self->populating_dialog)
|
|
|
|
self->user_callback (GTK_DIALOG (self->dialog), response_id, self->user_data);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PpOptionsDialog *
|
|
|
|
pp_options_dialog_new (GtkWindow *parent,
|
|
|
|
UserResponseCallback user_callback,
|
|
|
|
gpointer user_data,
|
|
|
|
gchar *printer_name,
|
|
|
|
gboolean sensitive)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpOptionsDialog *self;
|
2018-06-26 10:40:43 +12:00
|
|
|
GtkWidget *test_page_button;
|
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
gchar *objects[] = { "options-dialog", NULL };
|
|
|
|
guint builder_result;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self = g_new0 (PpOptionsDialog, 1);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->builder = gtk_builder_new ();
|
|
|
|
self->parent = GTK_WIDGET (parent);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
builder_result = gtk_builder_add_objects_from_resource (self->builder,
|
2013-01-04 15:54:43 +01:00
|
|
|
"/org/gnome/control-center/printers/options-dialog.ui",
|
|
|
|
objects, &error);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
if (builder_result == 0)
|
|
|
|
{
|
|
|
|
g_warning ("Could not load ui: %s", error->message);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->dialog = (GtkWidget *) gtk_builder_get_object (self->builder, "options-dialog");
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (self->dialog), GTK_WINDOW (parent));
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->user_callback = user_callback;
|
|
|
|
self->user_data = user_data;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->printer_name = g_strdup (printer_name);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->ppd_filename = NULL;
|
|
|
|
self->ppd_filename_set = FALSE;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->destination = NULL;
|
|
|
|
self->destination_set = FALSE;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->ipp_attributes = NULL;
|
|
|
|
self->ipp_attributes_set = FALSE;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->response = GTK_RESPONSE_NONE;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->sensitive = sensitive;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
/* connect signals */
|
2018-12-04 10:46:35 +13:00
|
|
|
g_signal_connect (self->dialog, "response", G_CALLBACK (options_dialog_response_cb), self);
|
|
|
|
test_page_button = (GtkWidget*) gtk_builder_get_object (self->builder, "print-test-page");
|
|
|
|
g_signal_connect (test_page_button, "clicked", G_CALLBACK (test_page_cb), self);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_window_set_title (GTK_WINDOW (self->dialog), printer_name);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_widget_show_all (GTK_WIDGET (self->dialog));
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->populating_dialog = TRUE;
|
|
|
|
populate_options (self);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
return self;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2017-03-13 09:16:29 +01:00
|
|
|
void
|
2018-12-04 10:46:35 +13:00
|
|
|
pp_options_dialog_set_callback (PpOptionsDialog *self,
|
2017-03-13 09:16:29 +01:00
|
|
|
UserResponseCallback user_callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self != NULL)
|
2017-03-13 09:16:29 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
self->user_callback = user_callback;
|
|
|
|
self->user_data = user_data;
|
2017-03-13 09:16:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 15:25:10 +02:00
|
|
|
void
|
2018-12-04 10:46:35 +13:00
|
|
|
pp_options_dialog_free (PpOptionsDialog *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (self->dialog));
|
|
|
|
self->dialog = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
g_object_unref (self->builder);
|
|
|
|
self->builder = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
g_free (self->printer_name);
|
|
|
|
self->printer_name = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->ppd_filename)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
g_unlink (self->ppd_filename);
|
|
|
|
g_free (self->ppd_filename);
|
|
|
|
self->ppd_filename = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->destination)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
cupsFreeDests (1, self->destination);
|
|
|
|
self->destination = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->ipp_attributes)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
g_hash_table_unref (self->ipp_attributes);
|
|
|
|
self->ipp_attributes = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
g_free (self);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-04 10:46:35 +13:00
|
|
|
pp_options_dialog_hide (PpOptionsDialog *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_widget_hide (GTK_WIDGET (self->dialog));
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|