2006-04-21 15:09:32 +00:00
|
|
|
/* GtkPrinterOptionWidget
|
|
|
|
* Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2006-07-18 18:26:51 +00:00
|
|
|
#include <ctype.h>
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkalignment.h"
|
|
|
|
#include "gtkcheckbutton.h"
|
|
|
|
#include "gtkcelllayout.h"
|
|
|
|
#include "gtkcellrenderertext.h"
|
|
|
|
#include "gtkcombobox.h"
|
|
|
|
#include "gtkfilechooserbutton.h"
|
|
|
|
#include "gtkimage.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkliststore.h"
|
2006-06-17 04:53:22 +00:00
|
|
|
#include "gtkradiobutton.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
#include "gtkstock.h"
|
|
|
|
#include "gtktable.h"
|
|
|
|
#include "gtktogglebutton.h"
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
|
|
|
#include "gtkprinteroptionwidget.h"
|
|
|
|
|
|
|
|
#define GTK_PRINTER_OPTION_WIDGET_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PRINTER_OPTION_WIDGET, GtkPrinterOptionWidgetPrivate))
|
|
|
|
|
|
|
|
static void gtk_printer_option_widget_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void deconstruct_widgets (GtkPrinterOptionWidget *widget);
|
|
|
|
static void construct_widgets (GtkPrinterOptionWidget *widget);
|
|
|
|
static void update_widgets (GtkPrinterOptionWidget *widget);
|
|
|
|
|
|
|
|
struct GtkPrinterOptionWidgetPrivate
|
|
|
|
{
|
|
|
|
GtkPrinterOption *source;
|
|
|
|
gulong source_changed_handler;
|
|
|
|
|
|
|
|
GtkWidget *check;
|
|
|
|
GtkWidget *combo;
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *filechooser;
|
2006-06-17 04:53:22 +00:00
|
|
|
GtkWidget *box;
|
2006-04-21 15:09:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2007-09-09 20:08:31 +00:00
|
|
|
PROP_SOURCE
|
2006-04-21 15:09:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2006-05-14 04:25:34 +00:00
|
|
|
G_DEFINE_TYPE (GtkPrinterOptionWidget, gtk_printer_option_widget, GTK_TYPE_HBOX)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
static void gtk_printer_option_widget_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_printer_option_widget_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2006-04-30 05:31:14 +00:00
|
|
|
static gboolean gtk_printer_option_widget_mnemonic_activate (GtkWidget *widget,
|
2006-08-23 19:31:56 +00:00
|
|
|
gboolean group_cycling);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_printer_option_widget_class_init (GtkPrinterOptionWidgetClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
|
|
|
|
object_class = (GObjectClass *) class;
|
|
|
|
widget_class = (GtkWidgetClass *) class;
|
|
|
|
|
|
|
|
object_class->finalize = gtk_printer_option_widget_finalize;
|
|
|
|
object_class->set_property = gtk_printer_option_widget_set_property;
|
|
|
|
object_class->get_property = gtk_printer_option_widget_get_property;
|
|
|
|
|
2006-04-30 05:31:14 +00:00
|
|
|
widget_class->mnemonic_activate = gtk_printer_option_widget_mnemonic_activate;
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
g_type_class_add_private (class, sizeof (GtkPrinterOptionWidgetPrivate));
|
|
|
|
|
|
|
|
signals[CHANGED] =
|
|
|
|
g_signal_new ("changed",
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkPrinterOptionWidgetClass, changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_SOURCE,
|
|
|
|
g_param_spec_object ("source",
|
|
|
|
P_("Source option"),
|
|
|
|
P_("The PrinterOption backing this widget"),
|
|
|
|
GTK_TYPE_PRINTER_OPTION,
|
|
|
|
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_printer_option_widget_init (GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
|
|
|
widget->priv = GTK_PRINTER_OPTION_WIDGET_GET_PRIVATE (widget);
|
2006-04-30 05:31:14 +00:00
|
|
|
|
|
|
|
gtk_box_set_spacing (GTK_BOX (widget), 12);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_printer_option_widget_finalize (GObject *object)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidget *widget = GTK_PRINTER_OPTION_WIDGET (object);
|
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
if (priv->source)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
g_object_unref (priv->source);
|
|
|
|
priv->source = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
G_OBJECT_CLASS (gtk_printer_option_widget_parent_class)->finalize (object);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_printer_option_widget_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkPrinterOptionWidget *widget;
|
|
|
|
|
|
|
|
widget = GTK_PRINTER_OPTION_WIDGET (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SOURCE:
|
|
|
|
gtk_printer_option_widget_set_source (widget, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_printer_option_widget_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidget *widget = GTK_PRINTER_OPTION_WIDGET (object);
|
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SOURCE:
|
2006-05-02 12:48:52 +00:00
|
|
|
g_value_set_object (value, priv->source);
|
2006-04-21 15:09:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-30 05:31:14 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_printer_option_widget_mnemonic_activate (GtkWidget *widget,
|
|
|
|
gboolean group_cycling)
|
|
|
|
{
|
|
|
|
GtkPrinterOptionWidget *powidget = GTK_PRINTER_OPTION_WIDGET (widget);
|
|
|
|
GtkPrinterOptionWidgetPrivate *priv = powidget->priv;
|
|
|
|
|
|
|
|
if (priv->check)
|
|
|
|
return gtk_widget_mnemonic_activate (priv->check, group_cycling);
|
|
|
|
if (priv->combo)
|
|
|
|
return gtk_widget_mnemonic_activate (priv->combo, group_cycling);
|
|
|
|
if (priv->entry)
|
|
|
|
return gtk_widget_mnemonic_activate (priv->entry, group_cycling);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
static void
|
|
|
|
emit_changed (GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
|
|
|
g_signal_emit (widget, signals[CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_printer_option_widget_new (GtkPrinterOption *source)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_PRINTER_OPTION_WIDGET, "source", source, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
source_changed_cb (GtkPrinterOption *source,
|
|
|
|
GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
|
|
|
update_widgets (widget);
|
|
|
|
emit_changed (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-08-23 19:31:56 +00:00
|
|
|
gtk_printer_option_widget_set_source (GtkPrinterOptionWidget *widget,
|
|
|
|
GtkPrinterOption *source)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
if (source)
|
|
|
|
g_object_ref (source);
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
if (priv->source)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
g_signal_handler_disconnect (priv->source,
|
|
|
|
priv->source_changed_handler);
|
|
|
|
g_object_unref (priv->source);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->source = source;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
if (source)
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->source_changed_handler =
|
2006-04-21 15:09:32 +00:00
|
|
|
g_signal_connect (source, "changed", G_CALLBACK (source_changed_cb), widget);
|
|
|
|
|
|
|
|
construct_widgets (widget);
|
|
|
|
update_widgets (widget);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (widget), "source");
|
|
|
|
}
|
|
|
|
|
2006-08-23 19:31:56 +00:00
|
|
|
enum {
|
|
|
|
NAME_COLUMN,
|
|
|
|
VALUE_COLUMN,
|
|
|
|
N_COLUMNS
|
|
|
|
};
|
|
|
|
|
2006-07-18 18:26:51 +00:00
|
|
|
static void
|
|
|
|
combo_box_set_model (GtkWidget *combo_box)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
|
2006-08-23 19:31:56 +00:00
|
|
|
store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
|
2006-07-18 18:26:51 +00:00
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
|
2006-04-21 15:09:32 +00:00
|
|
|
g_object_unref (store);
|
2006-07-18 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
combo_box_set_view (GtkWidget *combo_box)
|
|
|
|
{
|
|
|
|
GtkCellRenderer *cell;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
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,
|
2006-08-23 19:31:56 +00:00
|
|
|
"text", NAME_COLUMN,
|
2006-07-18 18:26:51 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
combo_box_entry_new (void)
|
|
|
|
{
|
|
|
|
GtkWidget *combo_box;
|
2010-10-14 01:52:27 +00:00
|
|
|
combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, NULL);
|
2006-07-18 18:26:51 +00:00
|
|
|
|
|
|
|
combo_box_set_model (combo_box);
|
|
|
|
|
2010-10-14 01:52:27 +00:00
|
|
|
gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (combo_box), NAME_COLUMN);
|
2006-07-18 18:26:51 +00:00
|
|
|
|
|
|
|
return combo_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
combo_box_new (void)
|
|
|
|
{
|
|
|
|
GtkWidget *combo_box;
|
|
|
|
combo_box = gtk_combo_box_new ();
|
|
|
|
|
|
|
|
combo_box_set_model (combo_box);
|
|
|
|
combo_box_set_view (combo_box);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
return combo_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-08-23 19:31:56 +00:00
|
|
|
combo_box_append (GtkWidget *combo,
|
|
|
|
const gchar *display_text,
|
|
|
|
const gchar *value)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
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,
|
2006-08-23 19:31:56 +00:00
|
|
|
NAME_COLUMN, display_text,
|
|
|
|
VALUE_COLUMN, value,
|
2006-04-21 15:09:32 +00:00
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ComboSet {
|
|
|
|
GtkComboBox *combo;
|
2006-08-23 19:31:56 +00:00
|
|
|
const gchar *value;
|
2006-04-21 15:09:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
2006-08-23 19:31:56 +00:00
|
|
|
set_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
struct ComboSet *set_data = data;
|
|
|
|
gboolean found;
|
|
|
|
char *value;
|
|
|
|
|
2006-08-23 19:31:56 +00:00
|
|
|
gtk_tree_model_get (model, iter, VALUE_COLUMN, &value, -1);
|
2006-04-21 15:09:32 +00:00
|
|
|
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
|
2006-08-23 19:31:56 +00:00
|
|
|
combo_box_set (GtkWidget *combo,
|
|
|
|
const gchar *value)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
struct ComboSet set_data;
|
|
|
|
|
|
|
|
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;
|
2006-08-23 19:31:56 +00:00
|
|
|
gchar *value;
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2010-10-18 17:01:55 +00:00
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
|
2006-07-18 18:26:51 +00:00
|
|
|
|
2010-10-18 17:01:55 +00:00
|
|
|
value = NULL;
|
|
|
|
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
|
|
|
|
gtk_tree_model_get (model, &iter, VALUE_COLUMN, &value, -1);
|
2006-08-23 19:31:56 +00:00
|
|
|
|
|
|
|
return value;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
deconstruct_widgets (GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
|
|
|
|
|
|
|
if (priv->check)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_destroy (priv->check);
|
|
|
|
priv->check = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
if (priv->combo)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_destroy (priv->combo);
|
|
|
|
priv->combo = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
if (priv->entry)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_destroy (priv->entry);
|
|
|
|
priv->entry = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure entry and combo are destroyed first */
|
|
|
|
/* as we use the two of them to create the filechooser */
|
2006-05-02 12:48:52 +00:00
|
|
|
if (priv->filechooser)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_destroy (priv->filechooser);
|
|
|
|
priv->filechooser = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
if (priv->image)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_destroy (priv->image);
|
|
|
|
priv->image = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
if (priv->label)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_destroy (priv->label);
|
|
|
|
priv->label = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-08-23 19:31:56 +00:00
|
|
|
check_toggled_cb (GtkToggleButton *toggle_button,
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
|
|
|
|
|
|
|
g_signal_handler_block (priv->source, priv->source_changed_handler);
|
|
|
|
gtk_printer_option_set_boolean (priv->source,
|
2006-04-21 15:09:32 +00:00
|
|
|
gtk_toggle_button_get_active (toggle_button));
|
2006-05-02 12:48:52 +00:00
|
|
|
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
|
2006-04-21 15:09:32 +00:00
|
|
|
emit_changed (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-08-23 19:31:56 +00:00
|
|
|
filesave_changed_cb (GtkWidget *button,
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
2007-01-03 21:23:42 +00:00
|
|
|
gchar *uri, *file;
|
2008-09-30 08:45:01 +00:00
|
|
|
gchar *directory;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-06-20 17:36:55 +00:00
|
|
|
file = g_filename_from_utf8 (gtk_entry_get_text (GTK_ENTRY (priv->entry)),
|
|
|
|
-1, NULL, NULL, NULL);
|
|
|
|
if (file == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* combine the value of the chooser with the value of the entry */
|
|
|
|
g_signal_handler_block (priv->source, priv->source_changed_handler);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2008-09-30 08:45:01 +00:00
|
|
|
directory = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (priv->combo));
|
|
|
|
|
|
|
|
if ((g_uri_parse_scheme (file) == NULL) && (directory != NULL))
|
2006-06-20 17:36:55 +00:00
|
|
|
{
|
2008-09-30 08:45:01 +00:00
|
|
|
if (g_path_is_absolute (file))
|
|
|
|
uri = g_filename_to_uri (file, NULL, NULL);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *path;
|
2007-01-03 21:23:42 +00:00
|
|
|
|
2006-05-23 08:20:30 +00:00
|
|
|
#ifdef G_OS_UNIX
|
2008-09-30 08:45:01 +00:00
|
|
|
if (file[0] == '~' && file[1] == '/')
|
|
|
|
{
|
|
|
|
path = g_build_filename (g_get_home_dir (), file + 2, NULL);
|
|
|
|
}
|
|
|
|
else
|
2006-05-23 08:20:30 +00:00
|
|
|
#endif
|
2008-09-30 08:45:01 +00:00
|
|
|
{
|
|
|
|
path = g_build_filename (directory, file, NULL);
|
|
|
|
}
|
2007-01-03 21:23:42 +00:00
|
|
|
|
2008-09-30 08:45:01 +00:00
|
|
|
uri = g_filename_to_uri (path, NULL, NULL);
|
2007-01-03 21:23:42 +00:00
|
|
|
|
2008-09-30 08:45:01 +00:00
|
|
|
g_free (path);
|
2007-01-03 21:23:42 +00:00
|
|
|
}
|
2008-09-30 08:45:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (g_uri_parse_scheme (file) != NULL)
|
|
|
|
uri = g_strdup (file);
|
|
|
|
else
|
|
|
|
uri = g_build_path ("/", gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (priv->combo)), file, NULL);
|
2006-06-20 17:36:55 +00:00
|
|
|
}
|
2007-02-26 14:56:11 +00:00
|
|
|
|
2006-06-20 17:36:55 +00:00
|
|
|
if (uri)
|
|
|
|
gtk_printer_option_set (priv->source, uri);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-06-20 17:36:55 +00:00
|
|
|
g_free (uri);
|
2007-01-03 21:23:42 +00:00
|
|
|
g_free (file);
|
2008-09-30 08:45:01 +00:00
|
|
|
g_free (directory);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
|
2006-04-21 15:09:32 +00:00
|
|
|
emit_changed (widget);
|
|
|
|
}
|
|
|
|
|
2006-08-23 19:31:56 +00:00
|
|
|
static gchar *
|
|
|
|
filter_numeric (const gchar *val,
|
|
|
|
gboolean allow_neg,
|
|
|
|
gboolean allow_dec,
|
|
|
|
gboolean *changed_out)
|
2006-07-18 18:26:51 +00:00
|
|
|
{
|
|
|
|
gchar *filtered_val;
|
|
|
|
int i, j;
|
|
|
|
int len = strlen (val);
|
|
|
|
gboolean dec_set = FALSE;
|
|
|
|
|
|
|
|
filtered_val = g_malloc (len + 1);
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < len; i++)
|
|
|
|
{
|
2007-01-03 21:23:42 +00:00
|
|
|
if (isdigit (val[i]))
|
2006-07-18 18:26:51 +00:00
|
|
|
{
|
|
|
|
filtered_val[j] = val[i];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
else if (allow_dec && !dec_set &&
|
|
|
|
(val[i] == '.' || val[i] == ','))
|
|
|
|
{
|
|
|
|
/* allow one period or comma
|
|
|
|
* we should be checking locals
|
|
|
|
* but this is good enough for now
|
|
|
|
*/
|
|
|
|
filtered_val[j] = val[i];
|
|
|
|
dec_set = TRUE;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
else if (allow_neg && i == 0 && val[0] == '-')
|
|
|
|
{
|
|
|
|
filtered_val[0] = val[0];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filtered_val[j] = '\0';
|
|
|
|
*changed_out = !(i == j);
|
|
|
|
|
|
|
|
return filtered_val;
|
|
|
|
}
|
2006-08-23 19:31:56 +00:00
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
static void
|
2006-08-23 19:31:56 +00:00
|
|
|
combo_changed_cb (GtkWidget *combo,
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
2006-07-18 18:26:51 +00:00
|
|
|
gchar *value;
|
|
|
|
gchar *filtered_val = NULL;
|
|
|
|
gboolean changed;
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
g_signal_handler_block (priv->source, priv->source_changed_handler);
|
2006-07-18 18:26:51 +00:00
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
value = combo_box_get (combo);
|
2006-07-18 18:26:51 +00:00
|
|
|
|
|
|
|
/* handle some constraints */
|
|
|
|
switch (priv->source->type)
|
|
|
|
{
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
|
|
|
|
filtered_val = filter_numeric (value, FALSE, FALSE, &changed);
|
|
|
|
break;
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_INT:
|
|
|
|
filtered_val = filter_numeric (value, TRUE, FALSE, &changed);
|
|
|
|
break;
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_REAL:
|
|
|
|
filtered_val = filter_numeric (value, TRUE, TRUE, &changed);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filtered_val)
|
|
|
|
{
|
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
GtkEntry *entry;
|
|
|
|
|
|
|
|
entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo)));
|
|
|
|
|
|
|
|
gtk_entry_set_text (entry, filtered_val);
|
|
|
|
}
|
|
|
|
value = filtered_val;
|
|
|
|
}
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
if (value)
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_printer_option_set (priv->source, value);
|
2006-04-21 15:09:32 +00:00
|
|
|
g_free (value);
|
2006-05-02 12:48:52 +00:00
|
|
|
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
|
2006-04-21 15:09:32 +00:00
|
|
|
emit_changed (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-08-23 19:31:56 +00:00
|
|
|
entry_changed_cb (GtkWidget *entry,
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
2006-08-23 19:31:56 +00:00
|
|
|
const gchar *value;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
g_signal_handler_block (priv->source, priv->source_changed_handler);
|
2006-04-21 15:09:32 +00:00
|
|
|
value = gtk_entry_get_text (GTK_ENTRY (entry));
|
|
|
|
if (value)
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_printer_option_set (priv->source, value);
|
|
|
|
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
|
2006-04-21 15:09:32 +00:00
|
|
|
emit_changed (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-17 04:53:22 +00:00
|
|
|
static void
|
|
|
|
radio_changed_cb (GtkWidget *button,
|
|
|
|
GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
2006-08-23 19:31:56 +00:00
|
|
|
gchar *value;
|
2006-06-17 04:53:22 +00:00
|
|
|
|
|
|
|
g_signal_handler_block (priv->source, priv->source_changed_handler);
|
|
|
|
value = g_object_get_data (G_OBJECT (button), "value");
|
|
|
|
if (value)
|
|
|
|
gtk_printer_option_set (priv->source, value);
|
|
|
|
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
|
|
|
|
emit_changed (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-17 05:15:49 +00:00
|
|
|
select_maybe (GtkWidget *widget,
|
|
|
|
const gchar *value)
|
2006-06-17 04:53:22 +00:00
|
|
|
{
|
2006-08-23 19:31:56 +00:00
|
|
|
gchar *v = g_object_get_data (G_OBJECT (widget), "value");
|
2006-06-17 04:53:22 +00:00
|
|
|
|
2006-06-17 05:15:49 +00:00
|
|
|
if (strcmp (value, v) == 0)
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
|
|
|
|
}
|
2006-06-17 04:53:22 +00:00
|
|
|
|
2006-06-17 05:15:49 +00:00
|
|
|
static void
|
|
|
|
alternative_set (GtkWidget *box,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
gtk_container_foreach (GTK_CONTAINER (box),
|
|
|
|
(GtkCallback) select_maybe,
|
2006-06-20 17:36:55 +00:00
|
|
|
(gpointer) value);
|
2006-06-17 04:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2006-08-23 19:31:56 +00:00
|
|
|
alternative_append (GtkWidget *box,
|
|
|
|
const gchar *label,
|
|
|
|
const gchar *value,
|
2006-06-17 04:53:22 +00:00
|
|
|
GtkPrinterOptionWidget *widget,
|
2006-08-23 19:31:56 +00:00
|
|
|
GSList *group)
|
2006-06-17 04:53:22 +00:00
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
button = gtk_radio_button_new_with_label (group, label);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (button), "value", (gpointer)value);
|
|
|
|
g_signal_connect (button, "toggled",
|
|
|
|
G_CALLBACK (radio_changed_cb), widget);
|
|
|
|
|
|
|
|
return gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
|
|
|
|
}
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
static void
|
|
|
|
construct_widgets (GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPrinterOption *source;
|
|
|
|
char *text;
|
|
|
|
int i;
|
2006-06-17 04:53:22 +00:00
|
|
|
GSList *group;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
source = priv->source;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
deconstruct_widgets (widget);
|
|
|
|
|
2010-01-04 06:30:57 +00:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (widget), TRUE);
|
2009-12-20 23:32:58 +00:00
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
if (source == NULL)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->combo = combo_box_new ();
|
|
|
|
combo_box_append (priv->combo,_("Not available"), "None");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo), 0);
|
2010-01-04 06:30:57 +00:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (widget), FALSE);
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_show (priv->combo);
|
|
|
|
gtk_box_pack_start (GTK_BOX (widget), priv->combo, TRUE, TRUE, 0);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
else switch (source->type)
|
|
|
|
{
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_BOOLEAN:
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->check = gtk_check_button_new_with_mnemonic (source->display_text);
|
|
|
|
g_signal_connect (priv->check, "toggled", G_CALLBACK (check_toggled_cb), widget);
|
|
|
|
gtk_widget_show (priv->check);
|
|
|
|
gtk_box_pack_start (GTK_BOX (widget), priv->check, TRUE, TRUE, 0);
|
2006-04-21 15:09:32 +00:00
|
|
|
break;
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE:
|
2006-07-18 18:26:51 +00:00
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSWORD:
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_REAL:
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_INT:
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_STRING:
|
|
|
|
if (source->type == GTK_PRINTER_OPTION_TYPE_PICKONE)
|
|
|
|
{
|
|
|
|
priv->combo = combo_box_new ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->combo = combo_box_entry_new ();
|
|
|
|
|
|
|
|
if (source->type == GTK_PRINTER_OPTION_TYPE_PICKONE_PASSWORD ||
|
|
|
|
source->type == GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE)
|
|
|
|
{
|
|
|
|
GtkEntry *entry;
|
|
|
|
|
|
|
|
entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->combo)));
|
|
|
|
|
|
|
|
gtk_entry_set_visibility (entry, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
for (i = 0; i < source->num_choices; i++)
|
2006-05-02 12:48:52 +00:00
|
|
|
combo_box_append (priv->combo,
|
2006-04-21 15:09:32 +00:00
|
|
|
source->choices_display[i],
|
|
|
|
source->choices[i]);
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_show (priv->combo);
|
|
|
|
gtk_box_pack_start (GTK_BOX (widget), priv->combo, TRUE, TRUE, 0);
|
|
|
|
g_signal_connect (priv->combo, "changed", G_CALLBACK (combo_changed_cb), widget);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-04-30 05:31:14 +00:00
|
|
|
text = g_strdup_printf ("%s:", source->display_text);
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->label = gtk_label_new_with_mnemonic (text);
|
2006-04-21 15:09:32 +00:00
|
|
|
g_free (text);
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_show (priv->label);
|
2006-04-21 15:09:32 +00:00
|
|
|
break;
|
2006-06-17 04:53:22 +00:00
|
|
|
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_ALTERNATIVE:
|
|
|
|
group = NULL;
|
|
|
|
priv->box = gtk_hbox_new (FALSE, 12);
|
|
|
|
gtk_widget_show (priv->box);
|
|
|
|
gtk_box_pack_start (GTK_BOX (widget), priv->box, TRUE, TRUE, 0);
|
|
|
|
for (i = 0; i < source->num_choices; i++)
|
|
|
|
group = alternative_append (priv->box,
|
|
|
|
source->choices_display[i],
|
|
|
|
source->choices[i],
|
|
|
|
widget,
|
|
|
|
group);
|
|
|
|
|
|
|
|
if (source->display_text)
|
|
|
|
{
|
|
|
|
text = g_strdup_printf ("%s:", source->display_text);
|
|
|
|
priv->label = gtk_label_new_with_mnemonic (text);
|
|
|
|
g_free (text);
|
|
|
|
gtk_widget_show (priv->label);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
case GTK_PRINTER_OPTION_TYPE_STRING:
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->entry = gtk_entry_new ();
|
2009-08-11 07:24:18 +00:00
|
|
|
gtk_entry_set_activates_default (GTK_ENTRY (priv->entry),
|
|
|
|
gtk_printer_option_get_activates_default (source));
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_show (priv->entry);
|
|
|
|
gtk_box_pack_start (GTK_BOX (widget), priv->entry, TRUE, TRUE, 0);
|
|
|
|
g_signal_connect (priv->entry, "changed", G_CALLBACK (entry_changed_cb), widget);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-04-30 05:31:14 +00:00
|
|
|
text = g_strdup_printf ("%s:", source->display_text);
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->label = gtk_label_new_with_mnemonic (text);
|
2006-04-21 15:09:32 +00:00
|
|
|
g_free (text);
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_show (priv->label);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_FILESAVE:
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->filechooser = gtk_table_new (2, 2, FALSE);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (priv->filechooser), 6);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (priv->filechooser), 12);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
/* TODO: make this a gtkfilechooserentry once we move to GTK */
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->entry = gtk_entry_new ();
|
2010-04-29 21:14:14 +00:00
|
|
|
priv->combo = gtk_file_chooser_button_new (_("Select a folder"),
|
2006-06-20 17:36:55 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2008-09-30 08:45:01 +00:00
|
|
|
g_object_set (priv->combo, "local-only", FALSE, NULL);
|
2009-08-11 07:24:18 +00:00
|
|
|
gtk_entry_set_activates_default (GTK_ENTRY (priv->entry),
|
|
|
|
gtk_printer_option_get_activates_default (source));
|
2008-09-30 08:45:01 +00:00
|
|
|
|
2006-04-30 05:31:14 +00:00
|
|
|
label = gtk_label_new_with_mnemonic (_("_Name:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->entry);
|
2006-04-30 05:31:14 +00:00
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_table_attach (GTK_TABLE (priv->filechooser), label,
|
2006-04-21 15:09:32 +00:00
|
|
|
0, 1, 0, 1, GTK_FILL, 0,
|
|
|
|
0, 0);
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_table_attach (GTK_TABLE (priv->filechooser), priv->entry,
|
2006-04-21 15:09:32 +00:00
|
|
|
1, 2, 0, 1, GTK_FILL, 0,
|
|
|
|
0, 0);
|
|
|
|
|
2006-04-30 05:31:14 +00:00
|
|
|
label = gtk_label_new_with_mnemonic (_("_Save in folder:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->combo);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_table_attach (GTK_TABLE (priv->filechooser), label,
|
2006-04-21 15:09:32 +00:00
|
|
|
0, 1, 1, 2, GTK_FILL, 0,
|
|
|
|
0, 0);
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_table_attach (GTK_TABLE (priv->filechooser), priv->combo,
|
2006-04-21 15:09:32 +00:00
|
|
|
1, 2, 1, 2, GTK_FILL, 0,
|
|
|
|
0, 0);
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_show_all (priv->filechooser);
|
|
|
|
gtk_box_pack_start (GTK_BOX (widget), priv->filechooser, TRUE, TRUE, 0);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
g_signal_connect (priv->entry, "changed", G_CALLBACK (filesave_changed_cb), widget);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2007-02-26 14:56:11 +00:00
|
|
|
g_signal_connect (priv->combo, "selection-changed", G_CALLBACK (filesave_changed_cb), widget);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
|
|
|
|
gtk_box_pack_start (GTK_BOX (widget), priv->image, FALSE, FALSE, 0);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_widgets (GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPrinterOption *source;
|
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
source = priv->source;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
if (source == NULL)
|
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_hide (priv->image);
|
2006-04-21 15:09:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (source->type)
|
|
|
|
{
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_BOOLEAN:
|
2009-09-09 15:52:07 +00:00
|
|
|
if (g_ascii_strcasecmp (source->value, "True") == 0)
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->check), TRUE);
|
2006-04-21 15:09:32 +00:00
|
|
|
else
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->check), FALSE);
|
2006-04-21 15:09:32 +00:00
|
|
|
break;
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_PICKONE:
|
2006-05-02 12:48:52 +00:00
|
|
|
combo_box_set (priv->combo, source->value);
|
2006-04-21 15:09:32 +00:00
|
|
|
break;
|
2006-06-17 04:53:22 +00:00
|
|
|
case GTK_PRINTER_OPTION_TYPE_ALTERNATIVE:
|
|
|
|
alternative_set (priv->box, source->value);
|
|
|
|
break;
|
2006-04-21 15:09:32 +00:00
|
|
|
case GTK_PRINTER_OPTION_TYPE_STRING:
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->entry), source->value);
|
2006-04-21 15:09:32 +00:00
|
|
|
break;
|
|
|
|
case GTK_PRINTER_OPTION_TYPE_FILESAVE:
|
|
|
|
{
|
2006-08-18 01:30:24 +00:00
|
|
|
gchar *filename = g_filename_from_uri (source->value, NULL, NULL);
|
|
|
|
if (filename != NULL)
|
|
|
|
{
|
|
|
|
gchar *basename, *dirname, *text;
|
|
|
|
|
|
|
|
basename = g_path_get_basename (filename);
|
|
|
|
dirname = g_path_get_dirname (filename);
|
|
|
|
text = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (text != NULL)
|
2007-10-16 17:25:55 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
|
2006-08-18 01:30:24 +00:00
|
|
|
if (g_path_is_absolute (dirname))
|
|
|
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->combo),
|
|
|
|
dirname);
|
|
|
|
g_free (text);
|
|
|
|
g_free (basename);
|
|
|
|
g_free (dirname);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->entry), source->value);
|
2006-04-21 15:09:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source->has_conflict)
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_show (priv->image);
|
2006-04-21 15:09:32 +00:00
|
|
|
else
|
2006-05-02 12:48:52 +00:00
|
|
|
gtk_widget_hide (priv->image);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2006-08-23 19:31:56 +00:00
|
|
|
gtk_printer_option_widget_has_external_label (GtkPrinterOptionWidget *widget)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
return widget->priv->label != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_printer_option_widget_get_external_label (GtkPrinterOptionWidget *widget)
|
|
|
|
{
|
|
|
|
return widget->priv->label;
|
|
|
|
}
|
|
|
|
|
2006-08-23 19:31:56 +00:00
|
|
|
const gchar *
|
|
|
|
gtk_printer_option_widget_get_value (GtkPrinterOptionWidget *widget)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
|
|
|
|
|
|
|
if (priv->source)
|
|
|
|
return priv->source->value;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|