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 <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
|
|
|
#include "pp-ppd-option-widget.h"
|
|
|
|
#include "pp-utils.h"
|
|
|
|
|
|
|
|
static void pp_ppd_option_widget_finalize (GObject *object);
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
static gboolean construct_widget (PpPPDOptionWidget *self);
|
|
|
|
static void update_widget (PpPPDOptionWidget *self);
|
|
|
|
static void update_widget_real (PpPPDOptionWidget *self);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-06-15 14:13:15 +12:00
|
|
|
struct _PpPPDOptionWidget
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-06-15 14:13:15 +12:00
|
|
|
GtkBox parent_instance;
|
|
|
|
|
2012-07-16 15:25:10 +02:00
|
|
|
GtkWidget *switch_button;
|
|
|
|
GtkWidget *combo;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *box;
|
|
|
|
|
|
|
|
ppd_option_t *option;
|
|
|
|
|
|
|
|
gchar *printer_name;
|
|
|
|
gchar *option_name;
|
|
|
|
|
|
|
|
cups_dest_t *destination;
|
|
|
|
gboolean destination_set;
|
|
|
|
|
|
|
|
gchar *ppd_filename;
|
|
|
|
gboolean ppd_filename_set;
|
2013-02-28 16:19:21 +01:00
|
|
|
|
|
|
|
GCancellable *cancellable;
|
2012-07-16 15:25:10 +02:00
|
|
|
};
|
|
|
|
|
2014-11-29 18:13:58 +01:00
|
|
|
G_DEFINE_TYPE (PpPPDOptionWidget, pp_ppd_option_widget, GTK_TYPE_BOX)
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
/* This list comes from Gtk+ */
|
|
|
|
static const struct {
|
|
|
|
const char *keyword;
|
|
|
|
const char *choice;
|
|
|
|
const char *translation;
|
|
|
|
} ppd_choice_translations[] = {
|
|
|
|
{ "Duplex", "None", N_("One Sided") },
|
|
|
|
/* Translators: this is an option of "Two Sided" */
|
|
|
|
{ "Duplex", "DuplexNoTumble", N_("Long Edge (Standard)") },
|
|
|
|
/* Translators: this is an option of "Two Sided" */
|
|
|
|
{ "Duplex", "DuplexTumble", N_("Short Edge (Flip)") },
|
|
|
|
/* Translators: this is an option of "Paper Source" */
|
|
|
|
{ "InputSlot", "Auto", N_("Auto Select") },
|
|
|
|
/* Translators: this is an option of "Paper Source" */
|
|
|
|
{ "InputSlot", "AutoSelect", N_("Auto Select") },
|
|
|
|
/* Translators: this is an option of "Paper Source" */
|
|
|
|
{ "InputSlot", "Default", N_("Printer Default") },
|
|
|
|
/* Translators: this is an option of "Paper Source" */
|
|
|
|
{ "InputSlot", "None", N_("Printer Default") },
|
|
|
|
/* Translators: this is an option of "Paper Source" */
|
|
|
|
{ "InputSlot", "PrinterDefault", N_("Printer Default") },
|
|
|
|
/* Translators: this is an option of "Paper Source" */
|
|
|
|
{ "InputSlot", "Unspecified", N_("Auto Select") },
|
|
|
|
/* Translators: this is an option of "Resolution" */
|
|
|
|
{ "Resolution", "default", N_("Printer Default") },
|
|
|
|
/* Translators: this is an option of "GhostScript" */
|
|
|
|
{ "PreFilter", "EmbedFonts", N_("Embed GhostScript fonts only") },
|
|
|
|
/* Translators: this is an option of "GhostScript" */
|
|
|
|
{ "PreFilter", "Level1", N_("Convert to PS level 1") },
|
|
|
|
/* Translators: this is an option of "GhostScript" */
|
|
|
|
{ "PreFilter", "Level2", N_("Convert to PS level 2") },
|
|
|
|
/* Translators: this is an option of "GhostScript" */
|
|
|
|
{ "PreFilter", "No", N_("No pre-filtering") },
|
|
|
|
};
|
|
|
|
|
|
|
|
static ppd_option_t *
|
|
|
|
cups_option_copy (ppd_option_t *option)
|
|
|
|
{
|
|
|
|
ppd_option_t *result;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
result = g_new0 (ppd_option_t, 1);
|
|
|
|
|
|
|
|
*result = *option;
|
|
|
|
|
|
|
|
result->choices = g_new (ppd_choice_t, result->num_choices);
|
|
|
|
for (i = 0; i < result->num_choices; i++)
|
|
|
|
{
|
|
|
|
result->choices[i] = option->choices[i];
|
|
|
|
result->choices[i].code = g_strdup (option->choices[i].code);
|
|
|
|
result->choices[i].option = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cups_option_free (ppd_option_t *option)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (option)
|
|
|
|
{
|
|
|
|
for (i = 0; i < option->num_choices; i++)
|
|
|
|
g_free (option->choices[i].code);
|
|
|
|
|
|
|
|
g_free (option->choices);
|
|
|
|
g_free (option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pp_ppd_option_widget_class_init (PpPPDOptionWidgetClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
object_class->finalize = pp_ppd_option_widget_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-04 10:46:35 +13:00
|
|
|
pp_ppd_option_widget_init (PpPPDOptionWidget *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
|
2014-11-29 18:13:58 +01:00
|
|
|
GTK_ORIENTATION_HORIZONTAL);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->switch_button = NULL;
|
|
|
|
self->combo = NULL;
|
|
|
|
self->image = NULL;
|
|
|
|
self->box = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->printer_name = NULL;
|
|
|
|
self->option_name = NULL;
|
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->ppd_filename = NULL;
|
|
|
|
self->ppd_filename_set = FALSE;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pp_ppd_option_widget_finalize (GObject *object)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpPPDOptionWidget *self = PP_PPD_OPTION_WIDGET (object);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
g_cancellable_cancel (self->cancellable);
|
|
|
|
if (self->ppd_filename)
|
|
|
|
g_unlink (self->ppd_filename);
|
2018-12-06 09:28:35 +13:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
g_clear_pointer (&self->option, cups_option_free);
|
|
|
|
g_clear_pointer (&self->printer_name, g_free);
|
|
|
|
g_clear_pointer (&self->option_name, g_free);
|
|
|
|
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
|
|
|
g_clear_pointer (&self->ppd_filename, g_free);
|
|
|
|
g_clear_object (&self->cancellable);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (pp_ppd_option_widget_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
ppd_choice_translate (ppd_choice_t *choice)
|
|
|
|
{
|
|
|
|
const gchar *keyword = choice->option->keyword;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (ppd_choice_translations); i++)
|
|
|
|
{
|
|
|
|
if (g_strcmp0 (ppd_choice_translations[i].keyword, keyword) == 0 &&
|
|
|
|
g_strcmp0 (ppd_choice_translations[i].choice, choice->choice) == 0)
|
|
|
|
return _(ppd_choice_translations[i].translation);
|
|
|
|
}
|
|
|
|
|
|
|
|
return choice->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
pp_ppd_option_widget_new (ppd_option_t *option,
|
|
|
|
const gchar *printer_name)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpPPDOptionWidget *self = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
if (option && printer_name)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
self = g_object_new (PP_TYPE_PPD_OPTION_WIDGET, NULL);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->printer_name = g_strdup (printer_name);
|
|
|
|
self->option = cups_option_copy (option);
|
|
|
|
self->option_name = g_strdup (option->keyword);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (construct_widget (self))
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
update_widget_real (self);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
g_object_ref_sink (self);
|
|
|
|
g_object_unref (self);
|
|
|
|
self = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
return (GtkWidget *) self;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
NAME_COLUMN,
|
|
|
|
VALUE_COLUMN,
|
|
|
|
N_COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
combo_box_new (void)
|
|
|
|
{
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkWidget *combo_box;
|
|
|
|
|
|
|
|
combo_box = gtk_combo_box_new ();
|
|
|
|
|
|
|
|
store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
|
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
|
|
|
|
g_object_unref (store);
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
|
|
|
|
"text", NAME_COLUMN,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return combo_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
combo_box_append (GtkWidget *combo,
|
|
|
|
const gchar *display_text,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
|
|
|
|
store = GTK_LIST_STORE (model);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
NAME_COLUMN, display_text,
|
|
|
|
VALUE_COLUMN, value,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ComboSet {
|
|
|
|
GtkComboBox *combo;
|
|
|
|
const gchar *value;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
set_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
struct ComboSet *set_data = data;
|
|
|
|
gboolean found;
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, VALUE_COLUMN, &value, -1);
|
|
|
|
found = (strcmp (value, set_data->value) == 0);
|
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
gtk_combo_box_set_active_iter (set_data->combo, iter);
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
combo_box_set (GtkWidget *combo,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
struct ComboSet set_data;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
|
|
|
|
|
|
|
|
set_data.combo = GTK_COMBO_BOX (combo);
|
|
|
|
set_data.value = value;
|
|
|
|
gtk_tree_model_foreach (model, set_cb, &set_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
combo_box_get (GtkWidget *combo)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar *value = NULL;
|
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
|
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
|
|
|
|
gtk_tree_model_get (model, &iter, VALUE_COLUMN, &value, -1);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printer_add_option_async_cb (gboolean success,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpPPDOptionWidget *self = user_data;
|
2013-02-28 16:19:21 +01:00
|
|
|
|
2012-07-16 15:25:10 +02:00
|
|
|
update_widget (user_data);
|
2018-12-04 10:46:35 +13:00
|
|
|
g_clear_object (&self->cancellable);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
switch_changed_cb (GtkWidget *switch_button,
|
|
|
|
GParamSpec *pspec,
|
2018-12-04 10:46:35 +13:00
|
|
|
PpPPDOptionWidget *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
|
|
|
gchar **values;
|
|
|
|
|
|
|
|
values = g_new0 (gchar *, 2);
|
|
|
|
|
|
|
|
if (gtk_switch_get_active (GTK_SWITCH (switch_button)))
|
|
|
|
values[0] = g_strdup ("True");
|
|
|
|
else
|
|
|
|
values[0] = g_strdup ("False");
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->cancellable)
|
2013-02-28 16:19:21 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
g_cancellable_cancel (self->cancellable);
|
|
|
|
g_object_unref (self->cancellable);
|
2013-02-28 16:19:21 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->cancellable = g_cancellable_new ();
|
|
|
|
printer_add_option_async (self->printer_name,
|
|
|
|
self->option_name,
|
2012-07-16 15:25:10 +02:00
|
|
|
values,
|
|
|
|
FALSE,
|
2018-12-04 10:46:35 +13:00
|
|
|
self->cancellable,
|
2012-07-16 15:25:10 +02:00
|
|
|
printer_add_option_async_cb,
|
2018-12-04 10:46:35 +13:00
|
|
|
self);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
g_strfreev (values);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
combo_changed_cb (GtkWidget *combo,
|
2018-12-04 10:46:35 +13:00
|
|
|
PpPPDOptionWidget *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
|
|
|
gchar **values;
|
|
|
|
|
|
|
|
values = g_new0 (gchar *, 2);
|
|
|
|
values[0] = combo_box_get (combo);
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->cancellable)
|
2013-02-28 16:19:21 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
g_cancellable_cancel (self->cancellable);
|
|
|
|
g_object_unref (self->cancellable);
|
2013-02-28 16:19:21 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->cancellable = g_cancellable_new ();
|
|
|
|
printer_add_option_async (self->printer_name,
|
|
|
|
self->option_name,
|
2012-07-16 15:25:10 +02:00
|
|
|
values,
|
|
|
|
FALSE,
|
2018-12-04 10:46:35 +13:00
|
|
|
self->cancellable,
|
2012-07-16 15:25:10 +02:00
|
|
|
printer_add_option_async_cb,
|
2018-12-04 10:46:35 +13:00
|
|
|
self);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
g_strfreev (values);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-12-04 10:46:35 +13:00
|
|
|
construct_widget (PpPPDOptionWidget *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
/* Don't show options which has only one choice */
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->option && self->option->num_choices > 1)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
switch (self->option->ui)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
|
|
|
case PPD_UI_BOOLEAN:
|
2018-12-04 10:46:35 +13:00
|
|
|
self->switch_button = gtk_switch_new ();
|
|
|
|
g_signal_connect (self->switch_button, "notify::active", G_CALLBACK (switch_changed_cb), self);
|
|
|
|
gtk_box_pack_start (GTK_BOX (self), self->switch_button, FALSE, FALSE, 0);
|
2012-07-16 15:25:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPD_UI_PICKONE:
|
2018-12-04 10:46:35 +13:00
|
|
|
self->combo = combo_box_new ();
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
for (i = 0; i < self->option->num_choices; i++)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
combo_box_append (self->combo,
|
|
|
|
ppd_choice_translate (&self->option->choices[i]),
|
|
|
|
self->option->choices[i].choice);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_box_pack_start (GTK_BOX (self), self->combo, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect (self->combo, "changed", G_CALLBACK (combo_changed_cb), self);
|
2012-07-16 15:25:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPD_UI_PICKMANY:
|
2018-12-04 10:46:35 +13:00
|
|
|
self->combo = combo_box_new ();
|
2012-07-16 15:25:10 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
for (i = 0; i < self->option->num_choices; i++)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
combo_box_append (self->combo,
|
|
|
|
ppd_choice_translate (&self->option->choices[i]),
|
|
|
|
self->option->choices[i].choice);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_box_pack_start (GTK_BOX (self), self->combo, TRUE, TRUE, 0);
|
|
|
|
g_signal_connect (self->combo, "changed", G_CALLBACK (combo_changed_cb), self);
|
2012-07-16 15:25:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->image = gtk_image_new_from_icon_name ("dialog-warning-symbolic", GTK_ICON_SIZE_MENU);
|
|
|
|
if (!self->image)
|
|
|
|
self->image = gtk_image_new_from_icon_name ("dialog-warning", GTK_ICON_SIZE_MENU);
|
|
|
|
gtk_box_pack_start (GTK_BOX (self), self->image, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_set_no_show_all (GTK_WIDGET (self->image), TRUE);
|
2012-07-16 15:25:10 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-04 10:46:35 +13:00
|
|
|
update_widget_real (PpPPDOptionWidget *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
|
|
|
ppd_option_t *option = NULL, *iter;
|
|
|
|
ppd_file_t *ppd_file;
|
|
|
|
gchar *value = NULL;
|
|
|
|
gint i;
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->option)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
option = cups_option_copy (self->option);
|
|
|
|
cups_option_free (self->option);
|
|
|
|
self->option = NULL;
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
2018-12-04 10:46:35 +13:00
|
|
|
else if (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);
|
|
|
|
|
|
|
|
for (iter = ppdFirstOption(ppd_file); iter; iter = ppdNextOption(ppd_file))
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
if (g_str_equal (iter->keyword, self->option_name))
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
|
|
|
option = cups_option_copy (iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ppdClose (ppd_file);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (option)
|
|
|
|
{
|
|
|
|
for (i = 0; i < option->num_choices; i++)
|
|
|
|
if (option->choices[i].marked)
|
|
|
|
value = g_strdup (option->choices[i].choice);
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
value = g_strdup (option->defchoice);
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
switch (option->ui)
|
|
|
|
{
|
|
|
|
case PPD_UI_BOOLEAN:
|
2018-12-04 10:46:35 +13:00
|
|
|
g_signal_handlers_block_by_func (self->switch_button, switch_changed_cb, self);
|
2012-07-16 15:25:10 +02:00
|
|
|
if (g_ascii_strcasecmp (value, "True") == 0)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_switch_set_active (GTK_SWITCH (self->switch_button), TRUE);
|
2012-07-16 15:25:10 +02:00
|
|
|
else
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_switch_set_active (GTK_SWITCH (self->switch_button), FALSE);
|
|
|
|
g_signal_handlers_unblock_by_func (self->switch_button, switch_changed_cb, self);
|
2012-07-16 15:25:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPD_UI_PICKONE:
|
2018-12-04 10:46:35 +13:00
|
|
|
g_signal_handlers_block_by_func (self->combo, combo_changed_cb, self);
|
|
|
|
combo_box_set (self->combo, value);
|
|
|
|
g_signal_handlers_unblock_by_func (self->combo, combo_changed_cb, self);
|
2012-07-16 15:25:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPD_UI_PICKMANY:
|
2018-12-04 10:46:35 +13:00
|
|
|
g_signal_handlers_block_by_func (self->combo, combo_changed_cb, self);
|
|
|
|
combo_box_set (self->combo, value);
|
|
|
|
g_signal_handlers_unblock_by_func (self->combo, combo_changed_cb, self);
|
2012-07-16 15:25:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option->conflicted)
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_widget_show (self->image);
|
2012-07-16 15:25:10 +02:00
|
|
|
else
|
2018-12-04 10:46:35 +13:00
|
|
|
gtk_widget_hide (self->image);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cups_option_free (option);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_named_dest_cb (cups_dest_t *dest,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpPPDOptionWidget *self = 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)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
update_widget_real (self);
|
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
|
|
|
PpPPDOptionWidget *self = 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)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
update_widget_real (self);
|
2012-07-16 15:25:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-04 10:46:35 +13:00
|
|
|
update_widget (PpPPDOptionWidget *self)
|
2012-07-16 15:25:10 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
self->ppd_filename_set = FALSE;
|
|
|
|
self->destination_set = FALSE;
|
2015-04-16 15:08:51 +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
|
|
|
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
|
|
|
}
|