[gnome-control-center/wip/feborges/new-printers-panel: 4/5] printers: introduce PpPrinterEntry widget
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/feborges/new-printers-panel: 4/5] printers: introduce PpPrinterEntry widget
- Date: Mon, 13 Jun 2016 09:58:15 +0000 (UTC)
commit c0f2073774c15bf45f6d1f8ad4bc54283293c87f
Author: Felipe Borges <felipeborges gnome org>
Date: Sat Jun 11 14:34:41 2016 +0200
printers: introduce PpPrinterEntry widget
This commit introduces the following regressions:
- no possibility of renaming properties such as printer names,
location, or changing model/driver. This issue is going to be
solved nextly by the introduction of the PpDetailsDialog.
- impossibility of changing default printer
https://bugzilla.gnome.org/show_bug.cgi?id=767600
panels/printers/Makefile.am | 2 +
panels/printers/cc-printers-panel.c | 1896 ++------------------------------
panels/printers/pp-printer-entry.c | 517 +++++++++
panels/printers/pp-printer-entry.h | 44 +
panels/printers/printer-entry.ui | 250 +++++
panels/printers/printers.gresource.xml | 1 +
panels/printers/printers.ui | 456 +--------
7 files changed, 879 insertions(+), 2287 deletions(-)
---
diff --git a/panels/printers/Makefile.am b/panels/printers/Makefile.am
index 938e3b0..6163d4b 100644
--- a/panels/printers/Makefile.am
+++ b/panels/printers/Makefile.am
@@ -50,6 +50,8 @@ libprinters_la_SOURCES = \
pp-samba.h \
pp-print-device.c \
pp-print-device.h \
+ pp-printer-entry.c \
+ pp-printer-entry.h \
cc-printers-panel.c \
cc-printers-panel.h
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index 2ec88b8..342d7bd 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -31,25 +31,19 @@
#include <math.h>
-#include "cc-editable-entry.h"
#include "pp-new-printer-dialog.h"
#include "pp-ppd-selection-dialog.h"
-#include "pp-options-dialog.h"
-#include "pp-jobs-dialog.h"
#include "pp-utils.h"
#include "pp-maintenance-command.h"
#include "pp-cups.h"
#include "pp-job.h"
+#include "pp-printer-entry.h"
CC_PANEL_REGISTER (CcPrintersPanel, cc_printers_panel)
#define PRINTERS_PANEL_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_PRINTERS_PANEL, CcPrintersPanelPrivate))
-#define SUPPLY_BAR_HEIGHT 20
-
-#define EMPTY_TEXT "\xe2\x80\x94"
-
#define RENEW_INTERVAL 500
#define SUBSCRIPTION_DURATION 600
@@ -87,8 +81,6 @@ struct _CcPrintersPanelPrivate
PpNewPrinterDialog *pp_new_printer_dialog;
PpPPDSelectionDialog *pp_ppd_selection_dialog;
- PpOptionsDialog *pp_options_dialog;
- PpJobsDialog *pp_jobs_dialog;
GDBusProxy *cups_proxy;
GDBusConnection *cups_bus_connection;
@@ -121,10 +113,8 @@ typedef struct
GCancellable *cancellable;
} SetPPDItem;
-static void update_jobs_count (CcPrintersPanel *self);
static void actualize_printers_list (CcPrintersPanel *self);
static void update_sensitivity (gpointer user_data);
-static void printer_disable_cb (GObject *gobject, GParamSpec *pspec, gpointer user_data);
static void printer_set_default_cb (GtkToggleButton *button, gpointer user_data);
static void detach_from_cups_notifier (gpointer data);
static void free_dests (CcPrintersPanel *self);
@@ -276,56 +266,6 @@ cc_printers_panel_class_init (CcPrintersPanelClass *klass)
}
static void
-on_get_job_attributes_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- CcPrintersPanelPrivate *priv;
- const gchar *job_originating_user_name;
- const gchar *job_printer_uri;
- GVariant *attributes;
- GVariant *username;
- GVariant *printer_uri;
- GError *error = NULL;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- attributes = pp_job_get_attributes_finish (PP_JOB (source_object), res, &error);
- g_object_unref (source_object);
-
- if (attributes != NULL)
- {
- if ((username = g_variant_lookup_value (attributes, "job-originating-user-name", G_VARIANT_TYPE
("as"))) != NULL)
- {
- if ((printer_uri = g_variant_lookup_value (attributes, "job-printer-uri", G_VARIANT_TYPE ("as")))
!= NULL)
- {
- job_originating_user_name = g_variant_get_string (g_variant_get_child_value (username, 0),
NULL);
- job_printer_uri = g_variant_get_string (g_variant_get_child_value (printer_uri, 0), NULL);
-
- if (job_originating_user_name != NULL && job_printer_uri != NULL &&
- g_strcmp0 (job_originating_user_name, cupsUser ()) == 0 &&
- g_strrstr (job_printer_uri, "/") != 0 &&
- priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL &&
- g_strcmp0 (g_strrstr (job_printer_uri, "/") + 1,
- priv->dests[priv->current_dest].name) == 0)
- {
- update_jobs_count (self);
- }
-
- g_variant_unref (printer_uri);
- }
-
- g_variant_unref (username);
- }
-
- g_variant_unref (attributes);
- }
-}
-
-static void
on_cups_notification (GDBusConnection *connection,
const char *sender_name,
const char *object_path,
@@ -335,22 +275,7 @@ on_cups_notification (GDBusConnection *connection,
gpointer user_data)
{
CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- gboolean printer_is_accepting_jobs;
- gchar *printer_name = NULL;
gchar *text = NULL;
- gchar *printer_uri = NULL;
- gchar *printer_state_reasons = NULL;
- PpJob *job;
- gchar *job_state_reasons = NULL;
- gchar *job_name = NULL;
- guint job_id;
- gint printer_state;
- gint job_state;
- gint job_impressions_completed;
- static gchar *requested_attrs[] = {
- "job-printer-uri",
- "job-originating-user-name",
- NULL };
if (g_strcmp0 (signal_name, "PrinterAdded") != 0 &&
g_strcmp0 (signal_name, "PrinterDeleted") != 0 &&
@@ -362,47 +287,11 @@ on_cups_notification (GDBusConnection *connection,
if (g_variant_n_children (parameters) == 1)
g_variant_get (parameters, "(&s)", &text);
- else if (g_variant_n_children (parameters) == 6)
- {
- g_variant_get (parameters, "(&s&s&su&sb)",
- &text,
- &printer_uri,
- &printer_name,
- &printer_state,
- &printer_state_reasons,
- &printer_is_accepting_jobs);
- }
- else if (g_variant_n_children (parameters) == 11)
- {
- g_variant_get (parameters, "(&s&s&su&sbuu&s&su)",
- &text,
- &printer_uri,
- &printer_name,
- &printer_state,
- &printer_state_reasons,
- &printer_is_accepting_jobs,
- &job_id,
- &job_state,
- &job_state_reasons,
- &job_name,
- &job_impressions_completed);
- }
-
- if (g_strcmp0 (signal_name, "PrinterAdded") == 0 ||
- g_strcmp0 (signal_name, "PrinterDeleted") == 0 ||
- g_strcmp0 (signal_name, "PrinterStateChanged") == 0 ||
- g_strcmp0 (signal_name, "PrinterStopped") == 0)
+ else if (g_strcmp0 (signal_name, "PrinterAdded") == 0 ||
+ g_strcmp0 (signal_name, "PrinterDeleted") == 0 ||
+ g_strcmp0 (signal_name, "PrinterStateChanged") == 0 ||
+ g_strcmp0 (signal_name, "PrinterStopped") == 0)
actualize_printers_list (self);
- else if (g_strcmp0 (signal_name, "JobCreated") == 0 ||
- g_strcmp0 (signal_name, "JobCompleted") == 0)
- {
- job = g_object_new (PP_TYPE_JOB, "id", job_id, NULL);
- pp_job_get_attributes_async (job,
- requested_attrs,
- NULL,
- on_get_job_attributes_cb,
- self);
- }
}
static gchar *subscription_events[] = {
@@ -606,14 +495,6 @@ free_dests (CcPrintersPanel *self)
enum
{
- NOTEBOOK_INFO_PAGE = 0,
- NOTEBOOK_NO_PRINTERS_PAGE,
- NOTEBOOK_NO_CUPS_PAGE,
- NOTEBOOK_N_PAGES
-};
-
-enum
-{
PRINTER_ID_COLUMN,
PRINTER_NAME_COLUMN,
PRINTER_PAUSED_COLUMN,
@@ -623,92 +504,61 @@ enum
};
static void
+add_printer_entry (CcPrintersPanel *self,
+ cups_dest_t printer)
+{
+ CcPrintersPanelPrivate *priv;
+ PpPrinterEntry *printer_entry;
+ GtkWidget *content;
+
+ priv = PRINTERS_PANEL_PRIVATE (self);
+
+ content = (GtkWidget*) gtk_builder_get_object (priv->builder, "content");
+
+ printer_entry = pp_printer_entry_new (printer);
+
+ gtk_box_pack_start (GTK_BOX (content), GTK_WIDGET (printer_entry), TRUE, TRUE, 5);
+ gtk_widget_show_all (content);
+}
+
+static void
+clear_all_printer_entries (GtkWidget *widget,
+ GtkWidget *container)
+{
+ gtk_container_remove (GTK_CONTAINER (container), widget);
+}
+
+static void
+set_current_page (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GtkWidget *widget = GTK_WIDGET (user_data);
+ PpCups *cups = PP_CUPS (source_object);
+ gboolean success;
+
+ success = pp_cups_connection_test_finish (cups, result);
+ g_object_unref (source_object);
+
+ if (success)
+ gtk_stack_set_visible_child_name (GTK_STACK (widget), "empty-state");
+ else
+ gtk_stack_set_visible_child_name (GTK_STACK (widget), "no-cups-page");
+}
+
+static void
printer_selection_changed_cb (GtkTreeSelection *selection,
gpointer user_data)
{
CcPrintersPanelPrivate *priv;
CcPrintersPanel *self = (CcPrintersPanel*) user_data;
GtkTreeModel *model;
- cups_ptype_t type = 0;
GtkTreeIter iter;
GtkWidget *widget;
- GtkWidget *model_button_label;
- GtkWidget *model_label;
- gboolean is_accepting_jobs = TRUE;
- GValue value = G_VALUE_INIT;
- gchar *printer_make_and_model = NULL;
- gchar *printer_model = NULL;
- gchar *reason = NULL;
- gchar **printer_reasons = NULL;
- gchar *marker_types = NULL;
+ PpCups *cups;
gchar *printer_name = NULL;
gchar *printer_icon = NULL;
- gchar *printer_type = NULL;
- gchar *supply_type = NULL;
- gchar *printer_uri = NULL;
- gchar *location = NULL;
- gchar *status = NULL;
- gchar *device_uri = NULL;
- gchar *printer_hostname = NULL;
- int printer_state = 3;
int id = -1;
- int i, j;
- static const char * const reasons[] =
- {
- "toner-low",
- "toner-empty",
- "developer-low",
- "developer-empty",
- "marker-supply-low",
- "marker-supply-empty",
- "cover-open",
- "door-open",
- "media-low",
- "media-empty",
- "offline",
- "paused",
- "marker-waste-almost-full",
- "marker-waste-full",
- "opc-near-eol",
- "opc-life-over"
- };
- static const char * statuses[] =
- {
- /* Translators: The printer is low on toner */
- N_("Low on toner"),
- /* Translators: The printer has no toner left */
- N_("Out of toner"),
- /* Translators: "Developer" is a chemical for photo development,
- * http://en.wikipedia.org/wiki/Photographic_developer */
- N_("Low on developer"),
- /* Translators: "Developer" is a chemical for photo development,
- * http://en.wikipedia.org/wiki/Photographic_developer */
- N_("Out of developer"),
- /* Translators: "marker" is one color bin of the printer */
- N_("Low on a marker supply"),
- /* Translators: "marker" is one color bin of the printer */
- N_("Out of a marker supply"),
- /* Translators: One or more covers on the printer are open */
- N_("Open cover"),
- /* Translators: One or more doors on the printer are open */
- N_("Open door"),
- /* Translators: At least one input tray is low on media */
- N_("Low on paper"),
- /* Translators: At least one input tray is empty */
- N_("Out of paper"),
- /* Translators: The printer is offline */
- NC_("printer state", "Offline"),
- /* Translators: Someone has stopped the Printer */
- NC_("printer state", "Stopped"),
- /* Translators: The printer marker supply waste receptacle is almost full */
- N_("Waste receptacle almost full"),
- /* Translators: The printer marker supply waste receptacle is full */
- N_("Waste receptacle full"),
- /* Translators: Optical photo conductors are used in laser printers */
- N_("The optical photo conductor is near end of life"),
- /* Translators: Optical photo conductors are used in laser printers */
- N_("The optical photo conductor is no longer functioning")
- };
priv = PRINTERS_PANEL_PRIVATE (self);
@@ -724,425 +574,19 @@ printer_selection_changed_cb (GtkTreeSelection *selection,
id = -1;
priv->current_dest = id;
+ cups = pp_cups_new ();
- update_jobs_count (self);
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- {
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "main-vbox");
- gtk_stack_set_visible_child_name (GTK_STACK (widget), "printers-list");
-
- for (i = 0; i < priv->dests[id].num_options; i++)
- {
- if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "printer-location") == 0)
- location = g_strdup (priv->dests[priv->current_dest].options[i].value);
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "printer-state") == 0)
- printer_state = atoi (priv->dests[priv->current_dest].options[i].value);
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "printer-state-reasons") == 0)
- reason = priv->dests[priv->current_dest].options[i].value;
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "marker-types") == 0)
- marker_types = priv->dests[priv->current_dest].options[i].value;
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "printer-make-and-model") ==
0)
- printer_make_and_model = priv->dests[priv->current_dest].options[i].value;
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "printer-uri-supported") == 0)
- printer_uri = priv->dests[priv->current_dest].options[i].value;
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "printer-type") == 0)
- printer_type = priv->dests[priv->current_dest].options[i].value;
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "device-uri") == 0)
- device_uri = priv->dests[priv->current_dest].options[i].value;
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "printer-is-accepting-jobs")
== 0)
- {
- if (g_strcmp0 (priv->dests[priv->current_dest].options[i].value, "true") == 0)
- is_accepting_jobs = TRUE;
- else
- is_accepting_jobs = FALSE;
- }
- }
-
- if (priv->ppd_file_names[priv->current_dest] == NULL)
- priv->ppd_file_names[priv->current_dest] =
- g_strdup (cupsGetPPD (priv->dests[priv->current_dest].name));
-
- if (priv->dest_model_names[priv->current_dest] == NULL)
- priv->dest_model_names[priv->current_dest] =
- get_ppd_attribute (priv->ppd_file_names[priv->current_dest],
- "ModelName");
-
- printer_model = g_strdup (priv->dest_model_names[priv->current_dest]);
-
- if (printer_model == NULL && printer_make_and_model)
- {
- gchar *breakpoint = NULL, *tmp = NULL, *tmp2 = NULL;
- gchar backup;
- size_t length = 0;
- gchar *forbiden[] = {
- "foomatic",
- ",",
- "hpijs",
- "hpcups",
- "(recommended)",
- "postscript (recommended)",
- NULL };
-
- tmp = g_ascii_strdown (printer_make_and_model, -1);
-
- for (i = 0; i < g_strv_length (forbiden); i++)
- {
- tmp2 = g_strrstr (tmp, forbiden[i]);
- if (breakpoint == NULL ||
- (tmp2 != NULL && tmp2 < breakpoint))
- breakpoint = tmp2;
- }
-
- if (breakpoint)
- {
- backup = *breakpoint;
- *breakpoint = '\0';
- length = strlen (tmp);
- *breakpoint = backup;
- g_free (tmp);
-
- if (length > 0)
- printer_model = g_strndup (printer_make_and_model, length);
- }
- else
- printer_model = g_strdup (printer_make_and_model);
- }
-
- if (priv->new_printer_name &&
- g_strcmp0 (priv->new_printer_name, printer_name) == 0)
- {
- /* Translators: Printer's state (printer is being configured right now) */
- status = g_strdup ( C_("printer state", "Configuring"));
- }
-
- /* Find the first of the most severe reasons
- * and show it in the status field
- */
- if (!status &&
- reason &&
- !g_str_equal (reason, "none"))
- {
- int errors = 0, warnings = 0, reports = 0;
- int error_index = -1, warning_index = -1, report_index = -1;
-
- printer_reasons = g_strsplit (reason, ",", -1);
- for (i = 0; i < g_strv_length (printer_reasons); i++)
- {
- for (j = 0; j < G_N_ELEMENTS (reasons); j++)
- if (strncmp (printer_reasons[i],
- reasons[j],
- strlen (reasons[j])) == 0)
- {
- if (g_str_has_suffix (printer_reasons[i], "-report"))
- {
- if (reports == 0)
- report_index = j;
- reports++;
- }
- else if (g_str_has_suffix (printer_reasons[i], "-warning"))
- {
- if (warnings == 0)
- warning_index = j;
- warnings++;
- }
- else
- {
- if (errors == 0)
- error_index = j;
- errors++;
- }
- }
- }
- g_strfreev (printer_reasons);
-
- if (error_index >= 0)
- status = g_strdup (_(statuses[error_index]));
- else if (warning_index >= 0)
- status = g_strdup (_(statuses[warning_index]));
- else if (report_index >= 0)
- status = g_strdup (_(statuses[report_index]));
- }
-
- if (status == NULL)
- {
- switch (printer_state)
- {
- case 3:
- if (is_accepting_jobs)
- {
- /* Translators: Printer's state (can start new job without waiting) */
- status = g_strdup ( C_("printer state", "Ready"));
- }
- else
- {
- /* Translators: Printer's state (printer is ready but doesn't accept new jobs) */
- status = g_strdup ( C_("printer state", "Does not accept jobs"));
- }
- break;
- case 4:
- /* Translators: Printer's state (jobs are processing) */
- status = g_strdup ( C_("printer state", "Processing"));
- break;
- case 5:
- /* Translators: Printer's state (no jobs can be processed) */
- status = g_strdup ( C_("printer state", "Stopped"));
- break;
- }
- }
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-icon");
- g_value_init (&value, G_TYPE_INT);
- g_object_get_property ((GObject *) widget, "icon-size", &value);
-
- if (printer_icon)
- {
- gtk_image_set_from_icon_name ((GtkImage *) widget, printer_icon, g_value_get_int (&value));
- g_free (printer_icon);
- }
- else
- gtk_image_set_from_icon_name ((GtkImage *) widget, "printer", g_value_get_int (&value));
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-name-label");
-
- if (printer_name)
- {
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), printer_name);
- g_free (printer_name);
- }
- else
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
-
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-status-label");
-
- if (status)
- {
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), status);
- g_free (status);
- }
- else
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
-
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-location-label");
-
- if (location)
- {
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), location);
- g_free (location);
- }
- else
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
-
-
- model_button_label = GTK_WIDGET (gtk_builder_get_object (priv->builder, "printer-model-button-label"));
-
- model_label = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-model-label");
-
- if (printer_model)
- {
- gtk_label_set_text (GTK_LABEL (model_button_label), printer_model);
- gtk_label_set_text (GTK_LABEL (model_label), printer_model);
- g_free (printer_model);
- }
- else
- {
- gtk_label_set_text (GTK_LABEL (model_button_label), EMPTY_TEXT);
- gtk_label_set_text (GTK_LABEL (model_label), EMPTY_TEXT);
- }
-
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-ip-address-label");
-
- if (printer_type)
- type = atoi (printer_type);
-
- printer_hostname = printer_get_hostname (type, device_uri, printer_uri);
-
- if (printer_hostname)
- {
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), printer_hostname);
- g_free (printer_hostname);
- }
- else
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
-
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-disable-switch");
-
- g_signal_handlers_block_by_func (G_OBJECT (widget), printer_disable_cb, self);
- gtk_switch_set_active (GTK_SWITCH (widget), printer_state != 5 && is_accepting_jobs);
- g_signal_handlers_unblock_by_func (G_OBJECT (widget), printer_disable_cb, self);
-
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-default-check-button");
-
- g_signal_handlers_block_by_func (G_OBJECT (widget), printer_set_default_cb, self);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), priv->dests[id].is_default);
- g_signal_handlers_unblock_by_func (G_OBJECT (widget), printer_set_default_cb, self);
-
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "supply-drawing-area");
- gtk_widget_set_size_request (widget, -1, SUPPLY_BAR_HEIGHT);
- gtk_widget_queue_draw (widget);
-
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "supply-label");
-
- if (marker_types && g_strrstr (marker_types, "toner") != NULL)
- /* Translators: Toner supply */
- supply_type = g_strdup ( _("Toner Level"));
- else if (marker_types && g_strrstr (marker_types, "ink") != NULL)
- /* Translators: Ink supply */
- supply_type = g_strdup ( _("Ink Level"));
- else
- /* Translators: By supply we mean ink, toner, staples, water, ... */
- supply_type = g_strdup ( _("Supply Level"));
-
- if (supply_type)
- {
- gtk_label_set_text (GTK_LABEL (widget), supply_type);
- g_free (supply_type);
- }
- else
- gtk_label_set_text (GTK_LABEL (widget), EMPTY_TEXT);
- }
+ widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "main-vbox");
+ if (priv->num_dests == 0 && !priv->new_printer_name)
+ pp_cups_connection_test_async (g_object_ref (cups), set_current_page, widget);
else
- {
- if (id == -1)
- {
- if (priv->new_printer_name &&
- g_strcmp0 (priv->new_printer_name, printer_name) == 0)
- {
- /* Translators: Printer's state (printer is being installed right now) */
- status = g_strdup ( C_("printer state", "Installing"));
- location = g_strdup (priv->new_printer_location);
- printer_model = g_strdup (priv->new_printer_make_and_model);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "main-vbox");
- gtk_stack_set_visible_child_name (GTK_STACK (widget), "printers-list");
- }
- }
+ gtk_stack_set_visible_child_name (GTK_STACK (widget), "printers-list");
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-icon");
- g_value_init (&value, G_TYPE_INT);
- g_object_get_property ((GObject *) widget, "icon-size", &value);
+ widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "content");
- if (printer_icon)
- {
- gtk_image_set_from_icon_name ((GtkImage *) widget, printer_icon, g_value_get_int (&value));
- g_free (printer_icon);
- }
- else
- gtk_image_set_from_icon_name ((GtkImage *) widget, "printer", g_value_get_int (&value));
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-name-label");
- if (printer_name)
- {
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), printer_name);
- g_free (printer_name);
- }
- else
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
+ gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback)clear_all_printer_entries, widget);
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-status-label");
- if (status)
- {
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), status);
- g_free (status);
- }
- else
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-location-label");
-
- if (location)
- {
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), location);
- g_free (location);
- }
- else
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
-
-
- model_button_label = GTK_WIDGET (gtk_builder_get_object (priv->builder, "printer-model-button-label"));
-
- model_label = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-model-label");
-
- if (printer_model)
- {
- gtk_label_set_text (GTK_LABEL (model_button_label), printer_model);
- gtk_label_set_text (GTK_LABEL (model_label), printer_model);
- g_free (printer_model);
- }
- else
- {
- gtk_label_set_text (GTK_LABEL (model_button_label), EMPTY_TEXT);
- gtk_label_set_text (GTK_LABEL (model_label), EMPTY_TEXT);
- }
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-ip-address-label");
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-jobs-label");
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-disable-switch");
-
- g_signal_handlers_block_by_func (G_OBJECT (widget), printer_disable_cb, self);
- gtk_switch_set_active (GTK_SWITCH (widget), FALSE);
- g_signal_handlers_unblock_by_func (G_OBJECT (widget), printer_disable_cb, self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-default-check-button");
-
- g_signal_handlers_block_by_func (G_OBJECT (widget), printer_set_default_cb, self);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
- g_signal_handlers_unblock_by_func (G_OBJECT (widget), printer_set_default_cb, self);
- }
-
- update_sensitivity (self);
-}
-
-static void
-set_current_page (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- GtkWidget *widget = GTK_WIDGET (user_data);
- PpCups *cups = PP_CUPS (source_object);
- gboolean success;
-
- success = pp_cups_connection_test_finish (cups, result);
- g_object_unref (source_object);
-
- if (success)
- gtk_stack_set_visible_child_name (GTK_STACK (widget), "empty-state");
- else
- gtk_stack_set_visible_child_name (GTK_STACK (widget), "no-cups-page");
+ add_printer_entry (self, priv->dests[priv->current_dest]);
}
static void
@@ -1504,305 +948,6 @@ populate_printers_list (CcPrintersPanel *self)
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
}
-enum
-{
- JOB_ID_COLUMN,
- JOB_TITLE_COLUMN,
- JOB_STATE_COLUMN,
- JOB_CREATION_TIME_COLUMN,
- JOB_N_COLUMNS
-};
-
-static void
-update_jobs_count (CcPrintersPanel *self)
-{
- CcPrintersPanelPrivate *priv;
- cups_job_t *jobs;
- GtkWidget *widget;
- gchar *active_jobs = NULL;
- gint num_jobs;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- priv->num_jobs = -1;
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- {
- priv->num_jobs = cupsGetJobs (&jobs, priv->dests[priv->current_dest].name, 1, CUPS_WHICHJOBS_ACTIVE);
- if (priv->num_jobs > 0)
- cupsFreeJobs (priv->num_jobs, jobs);
-
- num_jobs = priv->num_jobs < 0 ? 0 : (guint) priv->num_jobs;
- /* Translators: there is n active print jobs on this printer */
- active_jobs = g_strdup_printf (ngettext ("%u active", "%u active", num_jobs), num_jobs);
- }
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-jobs-label");
-
- if (active_jobs)
- {
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), active_jobs);
- g_free (active_jobs);
- }
- else
- cc_editable_entry_set_text (CC_EDITABLE_ENTRY (widget), EMPTY_TEXT);
-
- if (priv->pp_jobs_dialog)
- {
- pp_jobs_dialog_update (priv->pp_jobs_dialog);
- }
-}
-
-static void
-printer_disable_cb (GObject *gobject,
- GParamSpec *pspec,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- gboolean paused = FALSE;
- gboolean is_accepting_jobs = TRUE;
- char *name = NULL;
- int i;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- {
- name = priv->dests[priv->current_dest].name;
-
- for (i = 0; i < priv->dests[priv->current_dest].num_options; i++)
- {
- if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "printer-state") == 0)
- paused = (g_strcmp0 (priv->dests[priv->current_dest].options[i].value, "5") == 0);
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "printer-is-accepting-jobs")
== 0)
- {
- if (g_strcmp0 (priv->dests[priv->current_dest].options[i].value, "true") == 0)
- is_accepting_jobs = TRUE;
- else
- is_accepting_jobs = FALSE;
- }
- }
- }
-
- if (name)
- {
- if (!paused && is_accepting_jobs)
- {
- printer_set_enabled (name, FALSE);
- printer_set_accepting_jobs (name, FALSE, NULL);
- }
- else
- {
- if (paused)
- printer_set_enabled (name, TRUE);
-
- if (!is_accepting_jobs)
- printer_set_accepting_jobs (name, TRUE, NULL);
- }
-
- actualize_printers_list (self);
- }
-}
-
-typedef struct {
- gchar *color;
- gchar *type;
- gchar *name;
- gint level;
-} MarkerItem;
-
-static gint
-markers_cmp (gconstpointer a,
- gconstpointer b)
-{
- MarkerItem *x = (MarkerItem*) a;
- MarkerItem *y = (MarkerItem*) b;
-
- if (x->level < y->level)
- return 1;
- else if (x->level == y->level)
- return 0;
- else
- return -1;
-}
-
-static void
-rounded_rectangle (cairo_t *cr, double x, double y, double w, double h, double r)
-{
- cairo_new_sub_path (cr);
- cairo_arc (cr, x + r, y + r, r, M_PI, 3 * M_PI / 2);
- cairo_arc (cr, x + w - r, y + r, r, 3 *M_PI / 2, 2 * M_PI);
- cairo_arc (cr, x + w - r, y + h - r, r, 0, M_PI / 2);
- cairo_arc (cr, x + r, y + h - r, r, M_PI / 2, M_PI);
- cairo_close_path (cr);
-}
-
-static gboolean
-supply_levels_draw_cb (GtkWidget *widget,
- cairo_t *cr,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- GtkStyleContext *context;
- gchar *marker_levels = NULL;
- gchar *marker_colors = NULL;
- gchar *marker_names = NULL;
- gchar *marker_types = NULL;
- gchar *tooltip_text = NULL;
- gint width;
- gint height;
- int i;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- context = gtk_widget_get_style_context (widget);
-
- width = gtk_widget_get_allocated_width (widget);
- height = gtk_widget_get_allocated_height (widget);
-
- gtk_render_background (context, cr, 0, 0, width, height);
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- {
- for (i = 0; i < priv->dests[priv->current_dest].num_options; i++)
- {
- if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "marker-names") == 0)
- marker_names = g_strcompress (priv->dests[priv->current_dest].options[i].value);
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "marker-levels") == 0)
- marker_levels = priv->dests[priv->current_dest].options[i].value;
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "marker-colors") == 0)
- marker_colors = priv->dests[priv->current_dest].options[i].value;
- else if (g_strcmp0 (priv->dests[priv->current_dest].options[i].name, "marker-types") == 0)
- marker_types = priv->dests[priv->current_dest].options[i].value;
- }
-
- if (marker_levels && marker_colors && marker_names && marker_types)
- {
- GSList *markers = NULL;
- GSList *tmp_list = NULL;
- GValue int_val = G_VALUE_INIT;
- gchar **marker_levelsv = NULL;
- gchar **marker_colorsv = NULL;
- gchar **marker_namesv = NULL;
- gchar **marker_typesv = NULL;
- gchar *tmp = NULL;
- gint border_radius = 0;
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
-
- gtk_style_context_get_property (
- context, GTK_STYLE_PROPERTY_BORDER_RADIUS, 0, &int_val);
- if (G_VALUE_HOLDS_INT (&int_val))
- border_radius = g_value_get_int (&int_val);
-
- marker_levelsv = g_strsplit (marker_levels, ",", -1);
- marker_colorsv = g_strsplit (marker_colors, ",", -1);
- marker_namesv = g_strsplit (marker_names, ",", -1);
- marker_typesv = g_strsplit (marker_types, ",", -1);
-
- if (g_strv_length (marker_levelsv) == g_strv_length (marker_colorsv) &&
- g_strv_length (marker_colorsv) == g_strv_length (marker_namesv) &&
- g_strv_length (marker_namesv) == g_strv_length (marker_typesv))
- {
- for (i = 0; i < g_strv_length (marker_levelsv); i++)
- {
- MarkerItem *marker;
-
- if (g_strcmp0 (marker_typesv[i], "ink") == 0 ||
- g_strcmp0 (marker_typesv[i], "toner") == 0 ||
- g_strcmp0 (marker_typesv[i], "inkCartridge") == 0 ||
- g_strcmp0 (marker_typesv[i], "tonerCartridge") == 0)
- {
- marker = g_new0 (MarkerItem, 1);
- marker->type = g_strdup (marker_typesv[i]);
- marker->name = g_strdup (marker_namesv[i]);
- marker->color = g_strdup (marker_colorsv[i]);
- marker->level = atoi (marker_levelsv[i]);
-
- markers = g_slist_prepend (markers, marker);
- }
- }
-
- markers = g_slist_sort (markers, markers_cmp);
-
- for (tmp_list = markers; tmp_list; tmp_list = tmp_list->next)
- {
- GdkRGBA color = {0.0, 0.0, 0.0, 1.0};
- double display_value;
- int value;
-
- value = ((MarkerItem*) tmp_list->data)->level;
-
- gdk_rgba_parse (&color, ((MarkerItem*) tmp_list->data)->color);
-
- if (value > 0)
- {
- display_value = value / 100.0 * (width - 3.0);
- gdk_cairo_set_source_rgba (cr, &color);
- rounded_rectangle (cr, 1.5, 1.5, display_value, SUPPLY_BAR_HEIGHT - 3.0,
border_radius);
- cairo_fill (cr);
- }
-
- if (tooltip_text)
- {
- tmp = g_strdup_printf ("%s\n%s",
- tooltip_text,
- ((MarkerItem*) tmp_list->data)->name);
- g_free (tooltip_text);
- tooltip_text = tmp;
- tmp = NULL;
- }
- else
- tooltip_text = g_strdup_printf ("%s",
- ((MarkerItem*) tmp_list->data)->name);
- }
-
- gtk_render_frame (context, cr, 1, 1, width - 2, SUPPLY_BAR_HEIGHT - 2);
-
- for (tmp_list = markers; tmp_list; tmp_list = tmp_list->next)
- {
- g_free (((MarkerItem*) tmp_list->data)->name);
- g_free (((MarkerItem*) tmp_list->data)->type);
- g_free (((MarkerItem*) tmp_list->data)->color);
- }
- g_slist_free_full (markers, g_free);
- }
-
- gtk_style_context_restore (context);
-
- g_strfreev (marker_levelsv);
- g_strfreev (marker_colorsv);
- g_strfreev (marker_namesv);
- g_strfreev (marker_typesv);
- }
-
- g_free (marker_names);
-
- if (tooltip_text)
- {
- gtk_widget_set_tooltip_text (widget, tooltip_text);
- g_free (tooltip_text);
- }
- else
- {
- gtk_widget_set_tooltip_text (widget, NULL);
- gtk_widget_set_has_tooltip (widget, FALSE);
- }
- }
-
- return TRUE;
-}
-
static void
printer_set_default_cb (GtkToggleButton *button,
gpointer user_data)
@@ -1934,711 +1079,6 @@ printer_remove_cb (GtkToolButton *toolbutton,
}
static void
-printer_name_edit_cb (GtkWidget *entry,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- const gchar *new_name;
- gchar *old_name = NULL;
- gint i;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- new_name = cc_editable_entry_get_text (CC_EDITABLE_ENTRY (entry));
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- old_name = priv->dests[priv->current_dest].name;
-
- if (printer_rename (old_name, new_name))
- {
- free_dests (self);
- priv->num_dests = cupsGetDests (&priv->dests);
- priv->dest_model_names = g_new0 (gchar *, priv->num_dests);
- priv->ppd_file_names = g_new0 (gchar *, priv->num_dests);
-
- for (i = 0; i < priv->num_dests; i++)
- if (g_strcmp0 (priv->dests[i].name, new_name) == 0)
- {
- priv->current_dest = i;
- break;
- }
- }
-
- actualize_printers_list (self);
-}
-
-static void
-printer_location_edit_cb (GtkWidget *entry,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- const gchar *location;
- gchar *printer_name = NULL;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- location = cc_editable_entry_get_text (CC_EDITABLE_ENTRY (entry));
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- printer_name = priv->dests[priv->current_dest].name;
-
- if (printer_name && location &&
- printer_set_location (printer_name, location))
- actualize_printers_list (self);
-}
-
-static void
-set_ppd_cb (gchar *printer_name,
- gboolean success,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- GList *iter;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- for (iter = priv->driver_change_list; iter; iter = iter->next)
- {
- SetPPDItem *item = (SetPPDItem *) iter->data;
-
- if (g_strcmp0 (item->printer_name, printer_name) == 0)
- {
- priv->driver_change_list = g_list_remove_link (priv->driver_change_list, iter);
-
- g_object_unref (item->cancellable);
- g_free (item->printer_name);
- g_free (item);
- g_list_free (iter);
- break;
- }
- }
-
- update_sensitivity (self);
-
- if (success)
- {
- actualize_printers_list (self);
- }
-
- g_free (printer_name);
-}
-
-static void
-select_ppd_manually (GtkMenuItem *menuitem,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- GtkFileFilter *filter;
- GtkWidget *dialog;
- gchar *printer_name = NULL;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- gtk_menu_shell_cancel (GTK_MENU_SHELL (priv->popup_menu));
-
- dialog = gtk_file_chooser_dialog_new (_("Select PPD File"),
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("_Open"), GTK_RESPONSE_ACCEPT,
- NULL);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter,
- _("PostScript Printer Description files (*.ppd, *.PPD, *.ppd.gz, *.PPD.gz, *.PPD.GZ)"));
- gtk_file_filter_add_pattern (filter, "*.ppd");
- gtk_file_filter_add_pattern (filter, "*.PPD");
- gtk_file_filter_add_pattern (filter, "*.ppd.gz");
- gtk_file_filter_add_pattern (filter, "*.PPD.gz");
- gtk_file_filter_add_pattern (filter, "*.PPD.GZ");
-
- gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
- {
- gchar *ppd_filename;
-
- ppd_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- printer_name = priv->dests[priv->current_dest].name;
-
- if (printer_name && ppd_filename)
- {
- SetPPDItem *item;
-
- item = g_new0 (SetPPDItem, 1);
- item->printer_name = g_strdup (printer_name);
- item->cancellable = g_cancellable_new ();
-
- priv->driver_change_list =
- g_list_prepend (priv->driver_change_list, item);
- update_sensitivity (self);
- printer_set_ppd_file_async (printer_name,
- ppd_filename,
- item->cancellable,
- set_ppd_cb,
- user_data);
- }
-
- g_free (ppd_filename);
- }
-
- gtk_widget_destroy (dialog);
-}
-
-static void
-ppd_selection_dialog_response_cb (GtkDialog *dialog,
- gint response_id,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- gchar *printer_name = NULL;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- if (response_id == GTK_RESPONSE_OK)
- {
- gchar *ppd_name;
-
- ppd_name = pp_ppd_selection_dialog_get_ppd_name (priv->pp_ppd_selection_dialog);
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- printer_name = priv->dests[priv->current_dest].name;
-
- if (printer_name && ppd_name)
- {
- SetPPDItem *item;
-
- item = g_new0 (SetPPDItem, 1);
- item->printer_name = g_strdup (printer_name);
- item->cancellable = g_cancellable_new ();
-
- priv->driver_change_list = g_list_prepend (priv->driver_change_list,
- item);
- update_sensitivity (self);
- printer_set_ppd_async (printer_name,
- ppd_name,
- item->cancellable,
- set_ppd_cb,
- user_data);
- }
-
- g_free (ppd_name);
- }
-
- pp_ppd_selection_dialog_free (priv->pp_ppd_selection_dialog);
- priv->pp_ppd_selection_dialog = NULL;
-}
-
-static void
-select_ppd_in_dialog (GtkMenuItem *menuitem,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- GtkWidget *widget;
- gchar *device_id = NULL;
- gchar *manufacturer = NULL;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "main-vbox");
-
- if (!priv->pp_ppd_selection_dialog)
- {
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests)
- {
- device_id =
- get_ppd_attribute (priv->ppd_file_names[priv->current_dest],
- "1284DeviceID");
-
- if (device_id)
- {
- manufacturer = get_tag_value (device_id, "mfg");
- if (!manufacturer)
- manufacturer = get_tag_value (device_id, "manufacturer");
- }
-
- if (manufacturer == NULL)
- {
- manufacturer =
- get_ppd_attribute (priv->ppd_file_names[priv->current_dest],
- "Manufacturer");
- }
-
- if (manufacturer == NULL)
- {
- manufacturer = g_strdup ("Raw");
- }
- }
-
- priv->pp_ppd_selection_dialog = pp_ppd_selection_dialog_new (
- GTK_WINDOW (gtk_widget_get_toplevel (widget)),
- priv->all_ppds_list,
- manufacturer,
- ppd_selection_dialog_response_cb,
- self);
-
- g_free (manufacturer);
- g_free (device_id);
- }
-}
-
-static void
-set_ppd_from_list (GtkMenuItem *menuitem,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- gchar *printer_name = NULL;
- gchar *ppd_name;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- ppd_name = (gchar *) g_object_get_data (G_OBJECT (menuitem), "ppd-name");
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- printer_name = priv->dests[priv->current_dest].name;
-
- if (printer_name && ppd_name)
- {
- SetPPDItem *item;
-
- item = g_new0 (SetPPDItem, 1);
- item->printer_name = g_strdup (printer_name);
- item->cancellable = g_cancellable_new ();
-
- priv->driver_change_list = g_list_prepend (priv->driver_change_list,
- item);
- update_sensitivity (self);
- printer_set_ppd_async (printer_name,
- ppd_name,
- item->cancellable,
- set_ppd_cb,
- user_data);
- }
-}
-
-static void
-ppd_names_free (gpointer user_data)
-{
- PPDName **names = (PPDName **) user_data;
- gint i;
-
- if (names)
- {
- for (i = 0; names[i]; i++)
- {
- g_free (names[i]->ppd_name);
- g_free (names[i]->ppd_display_name);
- g_free (names[i]);
- }
-
- g_free (names);
- }
-}
-
-static void
-get_ppd_names_cb (PPDName **names,
- const gchar *printer_name,
- gboolean cancelled,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- GtkWidget *informal = NULL;
- GtkWidget *placeholders[3];
- GtkWidget *spinner;
- gpointer value = NULL;
- gboolean found = FALSE;
- PPDName **hash_names = NULL;
- GList *children, *iter;
- gint i;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- priv->getting_ppd_names = FALSE;
-
- for (i = 0; i < 3; i++)
- placeholders[i] = NULL;
-
- children = gtk_container_get_children (GTK_CONTAINER (priv->popup_menu));
- if (children)
- {
- for (iter = children; iter; iter = iter->next)
- {
- if (g_strcmp0 ((gchar *) g_object_get_data (G_OBJECT (iter->data), "purpose"),
- "informal") == 0)
- informal = GTK_WIDGET (iter->data);
- else if (g_strcmp0 ((gchar *) g_object_get_data (G_OBJECT (iter->data), "purpose"),
- "placeholder1") == 0)
- placeholders[0] = GTK_WIDGET (iter->data);
- else if (g_strcmp0 ((gchar *) g_object_get_data (G_OBJECT (iter->data), "purpose"),
- "placeholder2") == 0)
- placeholders[1] = GTK_WIDGET (iter->data);
- else if (g_strcmp0 ((gchar *) g_object_get_data (G_OBJECT (iter->data), "purpose"),
- "placeholder3") == 0)
- placeholders[2] = GTK_WIDGET (iter->data);
- }
-
- g_list_free (children);
- }
-
- if (!priv->preferred_drivers)
- {
- priv->preferred_drivers = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, ppd_names_free);
- }
-
- if (!cancelled &&
- !g_hash_table_lookup_extended (priv->preferred_drivers,
- printer_name, NULL, NULL))
- g_hash_table_insert (priv->preferred_drivers, g_strdup (printer_name), names);
-
- if (priv->preferred_drivers &&
- g_hash_table_lookup_extended (priv->preferred_drivers,
- printer_name, NULL, &value))
- {
- hash_names = (PPDName **) value;
- if (hash_names)
- {
- for (i = 0; hash_names[i]; i++)
- {
- if (placeholders[i])
- {
- gtk_menu_item_set_label (GTK_MENU_ITEM (placeholders[i]),
- hash_names[i]->ppd_display_name);
- g_object_set_data_full (G_OBJECT (placeholders[i]),
- "ppd-name",
- g_strdup (hash_names[i]->ppd_name),
- g_free);
- g_signal_connect (placeholders[i],
- "activate",
- G_CALLBACK (set_ppd_from_list),
- self);
- gtk_widget_set_sensitive (GTK_WIDGET (placeholders[i]), TRUE);
- gtk_widget_show (placeholders[i]);
- }
- }
-
- found = TRUE;
- }
- else
- {
- found = FALSE;
- }
- }
-
- if (informal)
- {
- spinner = g_object_get_data (G_OBJECT (informal), "spinner");
- if (spinner)
- {
- gtk_widget_hide (spinner);
- gtk_spinner_stop (GTK_SPINNER (spinner));
- }
-
- if (found)
- gtk_widget_hide (informal);
- else
- gtk_label_set_text (GTK_LABEL (g_object_get_data (G_OBJECT (informal), "label")),
- _("No suitable driver found"));
- }
-
- gtk_widget_show_all (priv->popup_menu);
-
- update_sensitivity (self);
-}
-
-static void
-popup_menu_done (GtkMenuShell *menushell,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- if (priv->get_ppd_name_cancellable)
- {
- g_cancellable_cancel (priv->get_ppd_name_cancellable);
- g_object_unref (priv->get_ppd_name_cancellable);
- priv->get_ppd_name_cancellable = NULL;
- }
-}
-
-static void
-popup_model_menu_cb (GtkButton *button,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- GtkWidget *spinner;
- GtkWidget *item;
- GtkWidget *label;
- GtkWidget *box;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- priv->popup_menu = gtk_menu_new ();
- g_signal_connect (priv->popup_menu,
- "selection-done",
- G_CALLBACK (popup_menu_done),
- user_data);
-
- /*
- * These placeholders are a workaround for a situation
- * when we want to actually append new menu item in a callback.
- * But unfortunately it is not possible to connect to "activate"
- * signal of such menu item (appended after gtk_menu_popup()).
- */
- item = gtk_menu_item_new_with_label ("");
- g_object_set_data_full (G_OBJECT (item), "purpose",
- g_strdup ("placeholder1"), g_free);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
- gtk_widget_set_no_show_all (item, TRUE);
- gtk_widget_hide (item);
-
- item = gtk_menu_item_new_with_label ("");
- g_object_set_data_full (G_OBJECT (item), "purpose",
- g_strdup ("placeholder2"), g_free);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
- gtk_widget_set_no_show_all (item, TRUE);
- gtk_widget_hide (item);
-
- item = gtk_menu_item_new_with_label ("");
- g_object_set_data_full (G_OBJECT (item), "purpose",
- g_strdup ("placeholder3"), g_free);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
- gtk_widget_set_no_show_all (item, TRUE);
- gtk_widget_hide (item);
-
- label = gtk_label_new (_("Searching for preferred drivers…"));
- spinner = gtk_spinner_new ();
- gtk_spinner_start (GTK_SPINNER (spinner));
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_container_add (GTK_CONTAINER (box), spinner);
- gtk_container_add (GTK_CONTAINER (box), label);
- item = gtk_menu_item_new ();
- gtk_container_add (GTK_CONTAINER (item), box);
- gtk_widget_show_all (item);
- g_object_set_data_full (G_OBJECT (item), "purpose",
- g_strdup ("informal"), g_free);
- g_object_set_data (G_OBJECT (item), "spinner", spinner);
- g_object_set_data (G_OBJECT (item), "label", label);
- gtk_widget_set_sensitive (item, FALSE);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
- gtk_widget_set_no_show_all (item, TRUE);
- gtk_widget_show (item);
-
- item = gtk_separator_menu_item_new ();
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
-
- item = gtk_menu_item_new_with_label (_("Select from database…"));
- g_object_set_data_full (G_OBJECT (item), "purpose",
- g_strdup ("ppd-select"), g_free);
- g_signal_connect (item, "activate", G_CALLBACK (select_ppd_in_dialog), self);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
-
- item = gtk_separator_menu_item_new ();
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
-
- item = gtk_menu_item_new_with_label (_("Provide PPD File…"));
- g_object_set_data_full (G_OBJECT (item), "purpose",
- g_strdup ("ppdfile-select"), g_free);
- g_signal_connect (item, "activate", G_CALLBACK (select_ppd_manually), self);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
-
- gtk_widget_show_all (priv->popup_menu);
-
- gtk_menu_popup (GTK_MENU (priv->popup_menu),
- NULL, NULL, NULL, NULL, 0,
- gtk_get_current_event_time());
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- {
- if (priv->preferred_drivers &&
- g_hash_table_lookup_extended (priv->preferred_drivers,
- priv->dests[priv->current_dest].name,
- NULL, NULL))
- {
- get_ppd_names_cb (NULL,
- priv->dests[priv->current_dest].name,
- FALSE,
- user_data);
- }
- else
- {
- priv->get_ppd_name_cancellable = g_cancellable_new ();
- priv->getting_ppd_names = TRUE;
- get_ppd_names_async (priv->dests[priv->current_dest].name,
- 3,
- priv->get_ppd_name_cancellable,
- get_ppd_names_cb,
- user_data);
-
- update_sensitivity (self);
- }
- }
-}
-
-static void
-pp_maintenance_command_execute_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- PpMaintenanceCommand *command = (PpMaintenanceCommand *) source_object;
- GError *error = NULL;
-
- pp_maintenance_command_execute_finish (command, res, &error);
-
- 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
-test_page_cb (GtkButton *button,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- cups_ptype_t type = 0;
- const gchar *printer_type = NULL;
- gchar *printer_name = NULL;
- gint i;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- {
- printer_name = priv->dests[priv->current_dest].name;
- printer_type = cupsGetOption ("printer-type",
- priv->dests[priv->current_dest].num_options,
- priv->dests[priv->current_dest].options);
- if (printer_type)
- type = atoi (printer_type);
- }
-
- if (printer_name)
- {
- const gchar *const dirs[] = { "/usr/share/cups",
- "/usr/local/share/cups",
- NULL };
- const gchar *datadir = NULL;
- http_t *http = NULL;
- gchar *printer_uri = NULL;
- gchar *filename = NULL;
- gchar *resource = NULL;
- ipp_t *response = NULL;
- ipp_t *request;
-
- 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)
- {
- if (type & CUPS_PRINTER_CLASS)
- {
- printer_uri = g_strdup_printf ("ipp://localhost/classes/%s", printer_name);
- resource = g_strdup_printf ("/classes/%s", printer_name);
- }
- else
- {
- printer_uri = g_strdup_printf ("ipp://localhost/printers/%s", printer_name);
- resource = g_strdup_printf ("/printers/%s", printer_name);
- }
-
- http = httpConnectEncrypt (cupsServer (), ippPort (), cupsEncryption ());
- if (http)
- {
- request = ippNewRequest (IPP_PRINT_JOB);
- ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, printer_uri);
- ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME,
- "requesting-user-name", NULL, cupsUser ());
- ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME,
- /* Translators: Name of job which makes printer to print test page */
- "job-name", NULL, _("Test page"));
- response = cupsDoFileRequest (http, request, resource, filename);
- httpClose (http);
- }
-
- if (response)
- {
- if (ippGetState (response) == IPP_ERROR)
- g_warning ("An error has occured during printing of test page.");
- ippDelete (response);
- }
-
- g_free (filename);
- g_free (printer_uri);
- g_free (resource);
- }
- else
- {
- PpMaintenanceCommand *command;
-
- command = pp_maintenance_command_new (printer_name,
- "PrintSelfTestPage",
- /* 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, self);
- }
- }
-}
-
-static void
update_sensitivity (gpointer user_data)
{
CcPrintersPanelPrivate *priv;
@@ -2730,8 +1170,8 @@ update_sensitivity (gpointer user_data)
cups_server[0] != '/')
local_server = FALSE;
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "notebook");
- if (gtk_notebook_get_current_page (GTK_NOTEBOOK (widget)) == NOTEBOOK_NO_CUPS_PAGE)
+ widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "main-vbox");
+ if (g_strcmp0 (gtk_stack_get_visible_child_name (GTK_STACK (widget)), "no-cups-page") == 0)
no_cups = TRUE;
already_present_local = local_server && !is_discovered && is_authorized && !is_new;
@@ -2745,42 +1185,17 @@ update_sensitivity (gpointer user_data)
widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-remove-button");
gtk_widget_set_sensitive (widget, already_present_local && printer_selected && !no_cups);
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-disable-switch");
- gtk_widget_set_sensitive (widget, already_present_local);
-
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-default-check-button");
- gtk_widget_set_sensitive (widget, is_authorized && !is_new);
-
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "print-test-page-button");
- gtk_widget_set_sensitive (widget, printer_selected && !is_new);
-
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-options-button");
- gtk_widget_set_sensitive (widget, printer_selected && local_server && !is_discovered &&
- !priv->pp_options_dialog && !is_new);
-
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-jobs-button");
- gtk_widget_set_sensitive (widget, printer_selected && !is_new);
-
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-icon");
- gtk_widget_set_sensitive (widget, printer_selected);
-
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-name-label");
- cc_editable_entry_set_editable (CC_EDITABLE_ENTRY (widget), already_present_local);
-
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-location-label");
- cc_editable_entry_set_editable (CC_EDITABLE_ENTRY (widget), already_present_local);
-
- widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-model-notebook");
+ widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "main-vbox");
if (is_changing_driver)
{
- gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 2);
+ gtk_stack_set_visible_child_name (GTK_STACK (widget), "loading-page");
}
else
{
if (already_present_local && !is_class && !priv->getting_ppd_names)
- gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 0);
+ gtk_stack_set_visible_child_name (GTK_STACK (widget), "empty-state");
else
- gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 1);
+ gtk_stack_set_visible_child_name (GTK_STACK (widget), "printers-list");
}
}
@@ -2815,58 +1230,6 @@ on_lockdown_settings_changed (GSettings *settings,
}
static void
-printer_options_response_cb (GtkDialog *dialog,
- gint response_id,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- pp_options_dialog_free (priv->pp_options_dialog);
- priv->pp_options_dialog = NULL;
- update_sensitivity (self);
-
- if (response_id == GTK_RESPONSE_OK)
- actualize_printers_list (self);
-}
-
-static void
-printer_options_cb (GtkToolButton *toolbutton,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- GtkWidget *widget;
- gboolean is_authorized;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "main-vbox");
-
- is_authorized =
- priv->permission &&
- g_permission_get_allowed (G_PERMISSION (priv->permission)) &&
- priv->lockdown_settings &&
- !g_settings_get_boolean (priv->lockdown_settings, "disable-print-setup");
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- {
- priv->pp_options_dialog = pp_options_dialog_new (
- GTK_WINDOW (gtk_widget_get_toplevel (widget)),
- printer_options_response_cb,
- self,
- priv->dests[priv->current_dest].name,
- is_authorized);
- update_sensitivity (self);
- }
-}
-
-static void
cups_status_check_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
@@ -2952,81 +1315,6 @@ get_all_ppds_async_cb (PPDList *ppds,
}
static void
-update_label_padding (GtkWidget *widget,
- GtkAllocation *allocation,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- GtkAllocation allocation1, allocation2;
- GtkWidget *label;
- GtkWidget *sublabel;
- gint offset;
- gint margin;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- sublabel = gtk_bin_get_child (GTK_BIN (widget));
- if (sublabel)
- {
- gtk_widget_get_allocation (widget, &allocation1);
- gtk_widget_get_allocation (sublabel, &allocation2);
-
- offset = allocation2.x - allocation1.x;
-
- label = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-model-label");
-
- margin = gtk_widget_get_margin_start (label);
- if (offset != margin)
- gtk_widget_set_margin_start (label, offset);
-
- label = GTK_WIDGET (gtk_builder_get_object (priv->builder, "printer-model-setting"));
-
- margin = gtk_widget_get_margin_start (label);
- if (offset != margin)
- gtk_widget_set_margin_start (label, offset);
- }
-}
-
-static void
-jobs_dialog_response_cb (GtkDialog *dialog,
- gint response_id,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- pp_jobs_dialog_free (priv->pp_jobs_dialog);
- priv->pp_jobs_dialog = NULL;
-}
-
-static void
-printer_jobs_cb (GtkToolButton *toolbutton,
- gpointer user_data)
-{
- CcPrintersPanelPrivate *priv;
- CcPrintersPanel *self = (CcPrintersPanel*) user_data;
- GtkWidget *widget;
-
- priv = PRINTERS_PANEL_PRIVATE (self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "main-vbox");
-
- if (priv->current_dest >= 0 &&
- priv->current_dest < priv->num_dests &&
- priv->dests != NULL)
- priv->pp_jobs_dialog = pp_jobs_dialog_new (
- GTK_WINDOW (gtk_widget_get_toplevel (widget)),
- jobs_dialog_response_cb,
- self,
- priv->dests[priv->current_dest].name);
-}
-
-static void
cc_printers_panel_init (CcPrintersPanel *self)
{
CcPrintersPanelPrivate *priv;
@@ -3035,7 +1323,6 @@ cc_printers_panel_init (CcPrintersPanel *self)
PpCups *cups;
GError *error = NULL;
gchar *objects[] = { "main-vbox", NULL };
- GtkStyleContext *context;
guint builder_result;
priv = self->priv = PRINTERS_PANEL_PRIVATE (self);
@@ -3052,7 +1339,6 @@ cc_printers_panel_init (CcPrintersPanel *self)
priv->num_jobs = 0;
priv->pp_new_printer_dialog = NULL;
- priv->pp_options_dialog = NULL;
priv->subscription_id = 0;
priv->cups_status_check_id = 0;
@@ -3106,38 +1392,6 @@ cc_printers_panel_init (CcPrintersPanel *self)
gtk_builder_get_object (priv->builder, "printer-remove-button");
g_signal_connect (widget, "clicked", G_CALLBACK (printer_remove_cb), self);
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-disable-switch");
- g_signal_connect (widget, "notify::active", G_CALLBACK (printer_disable_cb), self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "supply-drawing-area");
- g_signal_connect (widget, "draw", G_CALLBACK (supply_levels_draw_cb), self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-default-check-button");
- g_signal_connect (widget, "toggled", G_CALLBACK (printer_set_default_cb), self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "print-test-page-button");
- g_signal_connect (widget, "clicked", G_CALLBACK (test_page_cb), self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-jobs-button");
- g_signal_connect (widget, "clicked", G_CALLBACK (printer_jobs_cb), self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-options-button");
- g_signal_connect (widget, "clicked", G_CALLBACK (printer_options_cb), self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-name-label");
- g_signal_connect (widget, "editing-done", G_CALLBACK (printer_name_edit_cb), self);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-location-label");
- g_signal_connect (widget, "editing-done", G_CALLBACK (printer_location_edit_cb), self);
-
priv->lockdown_settings = g_settings_new ("org.gnome.desktop.lockdown");
if (priv->lockdown_settings)
g_signal_connect_object (priv->lockdown_settings,
@@ -3146,30 +1400,6 @@ cc_printers_panel_init (CcPrintersPanel *self)
self,
G_CONNECT_AFTER);
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-model-button");
- g_signal_connect (widget, "clicked", G_CALLBACK (popup_model_menu_cb), self);
- g_signal_connect (widget, "size-allocate", G_CALLBACK (update_label_padding), self);
-
-
- /* Set junctions */
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printers-scrolledwindow");
- context = gtk_widget_get_style_context (widget);
- gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printers-toolbar");
- context = gtk_widget_get_style_context (widget);
- gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
-
-
- /* Make model label and ip-address label selectable */
- widget = (GtkWidget*)
- gtk_builder_get_object (priv->builder, "printer-ip-address-label");
- cc_editable_entry_set_selectable (CC_EDITABLE_ENTRY (widget), TRUE);
-
-
/* Add unlock button */
priv->permission = (GPermission *)polkit_permission_new_sync (
"org.opensuse.cupspkhelper.mechanism.all-edit", NULL, NULL, NULL);
diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
new file mode 100644
index 0000000..be8c403
--- /dev/null
+++ b/panels/printers/pp-printer-entry.c
@@ -0,0 +1,517 @@
+/*
+ * Copyright 2016 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (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
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Felipe Borges <feborges redhat com>
+ */
+
+#include <config.h>
+
+#include "pp-printer-entry.h"
+#include <gtk/gtk.h>
+#include <glib/gi18n-lib.h>
+#include <glib/gstdio.h>
+
+#include "pp-options-dialog.h"
+#include "pp-jobs-dialog.h"
+#include "pp-utils.h"
+
+#define SUPPLY_BAR_HEIGHT 12
+
+struct _PpPrinterEntry
+{
+ GtkBox parent;
+
+ gchar *printer_uri;
+ gchar *printer_name;
+ gchar *ppd_file_name;
+ int num_jobs;
+ gboolean is_accepting_jobs;
+ gchar *printer_make_and_model;
+ gchar *printer_location;
+ gchar *printer_hostname;
+
+ /* Widgets */
+ GtkImage *printer_icon;
+ GtkLabel *printer_status;
+ GtkLabel *printer_name_label;
+ GtkLabel *printer_model_label;
+ GtkLabel *printer_model;
+ GtkLabel *printer_location_label;
+ GtkLabel *printer_location_address_label;
+ GtkDrawingArea *supply_drawing_area;
+ GtkWidget *show_jobs_dialog_button;
+ GtkCheckButton *printer_default_checkbutton;
+
+ /* Dialogs */
+ PpOptionsDialog *pp_options_dialog;
+ PpJobsDialog *pp_jobs_dialog;
+};
+
+struct _PpPrinterEntryClass
+{
+ GtkBoxClass parent_class;
+};
+
+G_DEFINE_TYPE (PpPrinterEntry, pp_printer_entry, GTK_TYPE_BOX)
+
+static void
+pp_printer_entry_init (PpPrinterEntry *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+typedef struct {
+ gchar *color;
+ gchar *type;
+ gchar *name;
+ gint level;
+} MarkerItem;
+
+static gint
+markers_cmp (gconstpointer a,
+ gconstpointer b)
+{
+ MarkerItem *x = (MarkerItem*) a;
+ MarkerItem *y = (MarkerItem*) b;
+
+ if (x->level < y->level)
+ return 1;
+ else if (x->level == y->level)
+ return 0;
+ else
+ return -1;
+}
+
+static gchar *
+sanitize_printer_model (gchar *printer_make_and_model)
+{
+ gchar *breakpoint = NULL, *tmp = NULL, *tmp2 = NULL;
+ gchar *printer_model = NULL;
+ gchar backup;
+ size_t length = 0;
+ gchar *forbiden[] = {
+ "foomatic",
+ ",",
+ "hpijs",
+ "hpcups",
+ "(recommended)",
+ "postscript (recommended)",
+ NULL };
+ int i;
+
+ tmp = g_ascii_strdown (printer_make_and_model, -1);
+
+ for (i = 0; i < g_strv_length (forbiden); i++)
+ {
+ tmp2 = g_strrstr (tmp, forbiden[i]);
+ if (breakpoint == NULL ||
+ (tmp2 != NULL && tmp2 < breakpoint))
+ breakpoint = tmp2;
+ }
+
+ if (breakpoint)
+ {
+ backup = *breakpoint;
+ *breakpoint = '\0';
+ length = strlen (tmp);
+ *breakpoint = backup;
+ g_free (tmp);
+
+ if (length > 0)
+ printer_model = g_strndup (printer_make_and_model, length);
+ }
+ else
+ printer_model = g_strdup (printer_make_and_model);
+
+ return printer_model;
+}
+
+static gboolean
+supply_levels_draw_cb (GtkWidget *widget,
+ cairo_t *cr,
+ InkLevelData *inklevel)
+{
+ GtkStyleContext *context;
+ gchar *tooltip_text = NULL;
+ gint width;
+ gint height;
+ int i;
+
+ context = gtk_widget_get_style_context (widget);
+
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
+
+ gtk_render_background (context, cr, 0, 0, width, height);
+
+ if (inklevel->marker_levels && inklevel->marker_colors && inklevel->marker_names && inklevel->marker_types)
+ {
+ GSList *markers = NULL;
+ GSList *tmp_list = NULL;
+ gchar **marker_levelsv = NULL;
+ gchar **marker_colorsv = NULL;
+ gchar **marker_namesv = NULL;
+ gchar **marker_typesv = NULL;
+ gchar *tmp = NULL;
+
+ gtk_style_context_save (context);
+
+ marker_levelsv = g_strsplit (inklevel->marker_levels, ",", -1);
+ marker_colorsv = g_strsplit (inklevel->marker_colors, ",", -1);
+ marker_namesv = g_strsplit (inklevel->marker_names, ",", -1);
+ marker_typesv = g_strsplit (inklevel->marker_types, ",", -1);
+
+ if (g_strv_length (marker_levelsv) == g_strv_length (marker_colorsv) &&
+ g_strv_length (marker_colorsv) == g_strv_length (marker_namesv) &&
+ g_strv_length (marker_namesv) == g_strv_length (marker_typesv))
+ {
+ for (i = 0; i < g_strv_length (marker_levelsv); i++)
+ {
+ MarkerItem *marker;
+
+ if (g_strcmp0 (marker_typesv[i], "ink") == 0 ||
+ g_strcmp0 (marker_typesv[i], "toner") == 0 ||
+ g_strcmp0 (marker_typesv[i], "inkCartridge") == 0 ||
+ g_strcmp0 (marker_typesv[i], "tonerCartridge") == 0)
+ {
+ marker = g_new0 (MarkerItem, 1);
+ marker->type = g_strdup (marker_typesv[i]);
+ marker->name = g_strdup (marker_namesv[i]);
+ marker->color = g_strdup (marker_colorsv[i]);
+ marker->level = atoi (marker_levelsv[i]);
+
+ markers = g_slist_prepend (markers, marker);
+ }
+ }
+
+ markers = g_slist_sort (markers, markers_cmp);
+
+ for (tmp_list = markers; tmp_list; tmp_list = tmp_list->next)
+ {
+ GdkRGBA color = {0.0, 0.0, 0.0, 1.0};
+ double display_value;
+ int value;
+
+ value = ((MarkerItem*) tmp_list->data)->level;
+
+ gdk_rgba_parse (&color, ((MarkerItem*) tmp_list->data)->color);
+
+ if (value > 0)
+ {
+ display_value = value / 100.0 * (width - 3.0);
+ gdk_cairo_set_source_rgba (cr, &color);
+ cairo_rectangle (cr, 3.5, 3.5, display_value, SUPPLY_BAR_HEIGHT - 3.0);
+ cairo_fill (cr);
+ }
+
+ if (tooltip_text)
+ {
+ tmp = g_strdup_printf ("%s\n%s",
+ tooltip_text,
+ ((MarkerItem*) tmp_list->data)->name);
+ g_free (tooltip_text);
+ tooltip_text = tmp;
+ tmp = NULL;
+ }
+ else
+ tooltip_text = g_strdup_printf ("%s",
+ ((MarkerItem*) tmp_list->data)->name);
+ }
+
+ gtk_render_frame (context, cr, 1, 1, width - 1, SUPPLY_BAR_HEIGHT + 3);
+
+ for (tmp_list = markers; tmp_list; tmp_list = tmp_list->next)
+ {
+ g_free (((MarkerItem*) tmp_list->data)->name);
+ g_free (((MarkerItem*) tmp_list->data)->type);
+ g_free (((MarkerItem*) tmp_list->data)->color);
+ }
+ g_slist_free_full (markers, g_free);
+ }
+
+ gtk_style_context_restore (context);
+
+ // free inkLevelData
+
+ if (tooltip_text)
+ {
+ gtk_widget_set_tooltip_text (widget, tooltip_text);
+ g_free (tooltip_text);
+ }
+ else
+ {
+ gtk_widget_set_tooltip_text (widget, NULL);
+ gtk_widget_set_has_tooltip (widget, FALSE);
+ }
+ }
+
+ return TRUE;
+}
+
+static void
+printer_options_dialog_cb (GtkDialog *dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ PpPrinterEntry *self = PP_PRINTER_ENTRY (user_data);
+
+ pp_options_dialog_free (self->pp_options_dialog);
+ self->pp_options_dialog = NULL;
+}
+
+static void
+on_show_printer_options_dialog (GtkButton *button,
+ PpPrinterEntry *self)
+{
+ gboolean is_authorized = TRUE; // FIXME
+
+ self->pp_options_dialog = pp_options_dialog_new (
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))),
+ printer_options_dialog_cb,
+ self,
+ self->printer_name,
+ is_authorized);
+}
+
+static void
+set_as_default_printer (GtkToggleButton *button,
+ PpPrinterEntry *self)
+{
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->printer_default_checkbutton), TRUE);
+ printer_set_default (self->printer_name);
+
+ // update printers list here
+}
+
+static void
+remove_printer (GtkButton *button,
+ PpPrinterEntry *self)
+{
+ printer_delete (self->printer_name);
+}
+
+static void
+update_jobs_count (PpPrinterEntry *self)
+{
+ cups_job_t *jobs;
+ gchar *button_label;
+ gint *num_paused_jobs = 0;
+ gint num_jobs;
+ int i;
+
+ // FIXME do this async
+ self->num_jobs = cupsGetJobs (&jobs, self->printer_name, 1, CUPS_WHICHJOBS_ACTIVE);
+ if (self->num_jobs > 0)
+ cupsFreeJobs (self->num_jobs, jobs);
+
+ num_jobs = self->num_jobs < 0 ? 0 : (guint) self->num_jobs;
+
+ for (i = 0; i < num_jobs; i++)
+ if (jobs[i].state == IPP_JOB_HELD)
+ num_paused_jobs++;
+
+ if (self->num_jobs <= 0)
+ button_label = g_strdup ("No Active Jobs");
+ else
+ if (num_paused_jobs > 0)
+ button_label = g_strdup_printf ("%u Paused Jobs", num_jobs);
+ else
+ button_label = g_strdup_printf ("%u Jobs", num_jobs);
+
+ gtk_button_set_label (GTK_BUTTON (self->show_jobs_dialog_button), button_label);
+ gtk_widget_set_sensitive (self->show_jobs_dialog_button, self->is_accepting_jobs);
+
+ g_free (button_label);
+}
+
+static void
+jobs_dialog_response_cb (GtkDialog *dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ PpPrinterEntry *self = PP_PRINTER_ENTRY (user_data);
+
+ pp_jobs_dialog_free (self->pp_jobs_dialog);
+ self->pp_jobs_dialog = NULL;
+}
+
+static void
+show_jobs_dialog (GtkButton *button,
+ PpPrinterEntry *self)
+{
+ self->pp_jobs_dialog = pp_jobs_dialog_new (
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))),
+ jobs_dialog_response_cb,
+ self,
+ self->printer_name);
+}
+
+PpPrinterEntry *
+pp_printer_entry_new (cups_dest_t printer)
+{
+ PpPrinterEntry *self;
+ InkLevelData *inklevel;
+ cups_ptype_t printer_type = 0;
+ gboolean is_accepting_jobs;
+ gchar *instance;
+ gchar *printer_uri = NULL;
+ gchar *location = NULL;
+ gchar *printer_icon_name = NULL;
+ gchar *default_icon_name = NULL;
+ gchar *printer_make_and_model = NULL;
+ gchar *printer_status = NULL;
+ int printer_state = 3;
+ int i;
+
+ self = g_object_new (PP_PRINTER_ENTRY_TYPE, NULL);
+
+ inklevel = g_slice_new0 (InkLevelData);
+
+ if (printer.instance)
+ {
+ instance = g_strdup_printf ("%s / %s", printer.name, printer.instance);
+ }
+ else
+ {
+ instance = g_strdup (printer.name);
+ }
+
+ for (i = 0; i < printer.num_options; i++)
+ {
+ if (g_strcmp0 (printer.options[i].name, "device-uri") == 0)
+ self->printer_uri = printer.options[i].value;
+ else if (g_strcmp0 (printer.options[i].name, "printer-uri-supported") == 0)
+ printer_uri = printer.options[i].value;
+ else if (g_strcmp0 (printer.options[i].name, "printer-type") == 0)
+ printer_type = atoi (printer.options[i].value);
+ else if (g_strcmp0 (printer.options[i].name, "printer-location") == 0)
+ location = printer.options[i].value;
+ else if (g_strcmp0 (printer.options[i].name, "marker-names") == 0)
+ inklevel->marker_names = g_strcompress (printer.options[i].value);
+ else if (g_strcmp0 (printer.options[i].name, "marker-levels") == 0)
+ inklevel->marker_levels = printer.options[i].value;
+ else if (g_strcmp0 (printer.options[i].name, "marker-colors") == 0)
+ inklevel->marker_colors = printer.options[i].value;
+ else if (g_strcmp0 (printer.options[i].name, "marker-types") == 0)
+ inklevel->marker_types = printer.options[i].value;
+ else if (g_strcmp0 (printer.options[i].name, "printer-make-and-model") == 0)
+ printer_make_and_model = printer.options[i].value;
+ else if (g_strcmp0 (printer.options[i].name, "printer-state") == 0)
+ printer_state = atoi (printer.options[i].value);
+ else if (g_strcmp0 (printer.options[i].name, "printer-is-accepting-jobs") == 0)
+ {
+ if (g_strcmp0 (printer.options[i].value, "true") == 0)
+ is_accepting_jobs = TRUE;
+ else
+ is_accepting_jobs = FALSE;
+ }
+ }
+
+ switch (printer_state)
+ {
+ case 3:
+ if (is_accepting_jobs)
+ {
+ /* Translators: Printer's state (can start new job without waiting) */
+ printer_status = g_strdup ( C_("printer state", "Ready"));
+ }
+ else
+ {
+ /* Translators: Printer's state (printer is ready but doesn't accept new jobs) */
+ printer_status = g_strdup ( C_("printer state", "Does not accept jobs"));
+ }
+ break;
+ case 4:
+ /* Translators: Printer's state (jobs are processing) */
+ printer_status = g_strdup ( C_("printer state", "Processing"));
+ break;
+ case 5:
+ /* Translators: Printer's state (no jobs can be processed) */
+ printer_status = g_strdup ( C_("printer state", "Stopped"));
+ break;
+ }
+
+ if (printer_is_local (printer_type, self->printer_uri))
+ printer_icon_name = g_strdup ("printer");
+ else
+ printer_icon_name = g_strdup ("printer-network");
+
+ self->printer_name = printer.name;
+ self->is_accepting_jobs = is_accepting_jobs;
+ self->printer_make_and_model = printer_make_and_model;
+ self->printer_location = location;
+
+ self->printer_hostname = printer_get_hostname (printer_type, self->printer_uri, printer_uri);
+
+ gtk_image_set_from_icon_name (self->printer_icon, printer_icon_name, GTK_ICON_SIZE_DIALOG);
+ gtk_label_set_text (self->printer_status, printer_status);
+ gtk_label_set_text (self->printer_name_label, instance);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->printer_default_checkbutton), printer.is_default);
+
+ self->printer_make_and_model = sanitize_printer_model (printer_make_and_model);
+
+ if (self->printer_make_and_model == NULL)
+ {
+ gtk_widget_hide (GTK_WIDGET (self->printer_model_label));
+ gtk_widget_hide (GTK_WIDGET (self->printer_model));
+ }
+
+ gtk_label_set_text (self->printer_model, self->printer_make_and_model);
+
+ if (location[0] == '\0')
+ {
+ gtk_widget_hide (GTK_WIDGET (self->printer_location_label));
+ gtk_widget_hide (GTK_WIDGET (self->printer_location_address_label));
+ }
+
+ gtk_label_set_text (self->printer_location_address_label, location);
+
+ g_signal_connect (self->supply_drawing_area, "draw", G_CALLBACK (supply_levels_draw_cb), inklevel);
+
+ update_jobs_count (self);
+
+ self->pp_options_dialog = NULL;
+ self->pp_jobs_dialog = NULL;
+
+ g_free (printer_icon_name);
+ g_free (default_icon_name);
+
+ return self;
+}
+
+static void
+pp_printer_entry_class_init (PpPrinterEntryClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/printers/printer-entry.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_icon);
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_name_label);
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_status);
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_model_label);
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_model);
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_location_label);
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_location_address_label);
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, supply_drawing_area);
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_default_checkbutton);
+ gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, show_jobs_dialog_button);
+
+ gtk_widget_class_bind_template_callback (widget_class, on_show_printer_options_dialog);
+ gtk_widget_class_bind_template_callback (widget_class, set_as_default_printer);
+ gtk_widget_class_bind_template_callback (widget_class, remove_printer);
+ gtk_widget_class_bind_template_callback (widget_class, show_jobs_dialog);
+}
diff --git a/panels/printers/pp-printer-entry.h b/panels/printers/pp-printer-entry.h
new file mode 100644
index 0000000..fce1e2c
--- /dev/null
+++ b/panels/printers/pp-printer-entry.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2016 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (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
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Felipe Borges <feborges redhat com>
+ */
+
+#ifndef PP_PRINTER_ENTRY_H
+#define PP_PRINTER_ENTRY_H
+
+#include <gtk/gtk.h>
+#include <cups/cups.h>
+
+#define PP_PRINTER_ENTRY_TYPE (pp_printer_entry_get_type ())
+#define PP_PRINTER_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PP_PRINTER_ENTRY_TYPE, PpPrinterEntry))
+
+typedef struct _PpPrinterEntry PpPrinterEntry;
+typedef struct _PpPrinterEntryClass PpPrinterEntryClass;
+
+typedef struct
+{
+ gchar *marker_names;
+ gchar *marker_levels;
+ gchar *marker_colors;
+ gchar *marker_types;
+} InkLevelData;
+
+GType pp_printer_entry_get_type (void);
+
+PpPrinterEntry *pp_printer_entry_new (cups_dest_t printer);
+
+#endif /* PP_PRINTER_ENTRY_H */
diff --git a/panels/printers/printer-entry.ui b/panels/printers/printer-entry.ui
new file mode 100644
index 0000000..4ac3b35
--- /dev/null
+++ b/panels/printers/printer-entry.ui
@@ -0,0 +1,250 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <object class="GtkPopover" id="printer-menu">
+ <child>
+ <object class="GtkGrid">
+ <property name="visible">True</property>
+ <property name="margin">10</property>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="text" translatable="yes">Printing Options</property>
+ <signal name="clicked" handler="on_show_printer_options_dialog"/>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="printer_default_checkbutton">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <signal name="toggled" handler="set_as_default_printer"/>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="text" translatable="yes">Use Printer by Default</property>
+ <signal name="clicked" handler="set_as_default_printer"/>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkModelButton" id="remove_printer_menuitem">
+ <property name="visible">True</property>
+ <property name="text" translatable="yes">Remove Printer</property>
+ <signal name="clicked" handler="remove_printer"/>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">3</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+
+ <template class="PpPrinterEntry" parent="GtkBox">
+ <property name="valign">center</property>
+ <child>
+ <object class="GtkFrame" id="content_area">
+ <property name="visible">True</property>
+ <property name="valign">start</property>
+ <style>
+ <class name="view"/>
+ </style>
+ <child>
+ <object class="GtkGrid">
+ <property name="visible">True</property>
+ <property name="row-spacing">10</property>
+ <property name="column-spacing">15</property>
+ <property name="margin_start">20</property>
+ <property name="margin_end">20</property>
+ <property name="margin_top">5</property>
+ <property name="margin_bottom">20</property>
+ <property name="no-show-all">True</property>
+ <child>
+ <object class="GtkImage" id="printer_icon">
+ <property name="visible">True</property>
+ <property name="pixel-size">64</property>
+ <property name="icon_name">printer</property>
+ <property name="halign">end</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="printer_name_grid">
+ <property name="visible">True</property>
+ <property name="margin">10</property>
+ <property name="margin_start">0</property>
+ <property name="halign">start</property>
+ <child>
+ <object class="GtkLabel" id="printer_name_label">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
+ <property name="max-width-chars">30</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ <attribute name="scale" value="1.5"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="printer_status">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="spacing">5</property>
+ <property name="orientation">horizontal</property>
+ <child>
+ <object class="GtkButton" id="show_jobs_dialog_button">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <property name="can_focus">True</property>
+ <signal name="clicked" handler="show_jobs_dialog"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuButton">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <property name="popover">printer-menu</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon_name">emblem-system-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left-attach">2</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="printer_model_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Model</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
+ <property name="max-width-chars">30</property>
+ <property name="halign">end</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="printer_model">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="printer_location_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Location</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
+ <property name="max-width-chars">30</property>
+ <property name="halign">end</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="printer_location_address_label">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="printer_inklevel_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Ink Level</property>
+ <property name="halign">end</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFrame" id="supply_frame">
+ <property name="visible">True</property>
+ <property name="width_request">300</property>
+ <property name="halign">start</property>
+ <property name="shadow_type">in</property>
+ <property name="halign">start</property>
+ <property name="margin_top">1</property>
+ <child>
+ <object class="GtkDrawingArea" id="supply_drawing_area">
+ <property name="visible">True</property>
+ <property name="margin_top">1</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">3</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+
+</interface>
diff --git a/panels/printers/printers.gresource.xml b/panels/printers/printers.gresource.xml
index 607055e..68d9a29 100644
--- a/panels/printers/printers.gresource.xml
+++ b/panels/printers/printers.gresource.xml
@@ -6,6 +6,7 @@
<file preprocess="xml-stripblanks">new-printer-dialog.ui</file>
<file preprocess="xml-stripblanks">options-dialog.ui</file>
<file preprocess="xml-stripblanks">ppd-selection-dialog.ui</file>
+ <file preprocess="xml-stripblanks">printer-entry.ui</file>
<file preprocess="xml-stripblanks">printers.ui</file>
</gresource>
</gresources>
diff --git a/panels/printers/printers.ui b/panels/printers/printers.ui
index 95ab120..c334a11 100644
--- a/panels/printers/printers.ui
+++ b/panels/printers/printers.ui
@@ -99,462 +99,10 @@
</packing>
</child>
<child>
- <object class="GtkNotebook" id="notebook">
+ <object class="GtkBox" id="content">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="show_tabs">False</property>
- <property name="show_border">False</property>
- <child>
- <object class="GtkBox" id="vbox1">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">10</property>
- <child>
- <object class="GtkTable" id="table1">
- <property name="visible">True</property>
- <property name="n_rows">8</property>
- <property name="n_columns">3</property>
- <property name="column_spacing">6</property>
- <property name="row_spacing">6</property>
- <child>
- <object class="GtkLabel" id="supply-label">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes" comments="Translators: By supply we mean
ink, toner, staples, water, ...">Supply</property>
- <style>
- <class name="dim-label"/>
- </style>
- </object>
- <packing>
- <property name="top_attach">5</property>
- <property name="bottom_attach">6</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label10">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes" comments="Translators: Location of the
printer (e.g. Lab, 1st floor,...).">Location</property>
- <style>
- <class name="dim-label"/>
- </style>
- </object>
- <packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkDrawingArea" id="supply-drawing-area">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">3</property>
- <property name="top_attach">5</property>
- <property name="bottom_attach">6</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="CcEditableEntry" id="printer-location-label">
- <property name="visible">True</property>
- <property name="halign">fill</property>
- <property name="text">---</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
- <accessibility>
- <relation type="labelled-by" target="label10"/>
- </accessibility>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">3</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="CcEditableEntry" id="printer-status-label">
- <property name="visible">True</property>
- <property name="text">Printing…</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="printer-default-check-button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
- <child>
- <object class="GtkLabel" id="label8">
- <property name="visible">True</property>
- <property name="label" translatable="yes" comments="Translators: This checkbox
is checked when the default printer is selected.">_Default printer</property>
- <property name="use_underline">True</property>
- <attributes>
- <attribute name="style" value="normal"/>
- </attributes>
- </object>
- </child>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">7</property>
- <property name="bottom_attach">8</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label12">
- <property name="visible">True</property>
- <property name="label" translatable="yes"></property>
- </object>
- <packing>
- <property name="top_attach">7</property>
- <property name="bottom_attach">8</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label3">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Jobs</property>
- <style>
- <class name="dim-label"/>
- </style>
- </object>
- <packing>
- <property name="top_attach">6</property>
- <property name="bottom_attach">7</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <object class="CcEditableEntry" id="printer-jobs-label">
- <property name="visible">True</property>
- <property name="text" translatable="no">0 active</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">6</property>
- <property name="bottom_attach">7</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="printer-jobs-button">
- <property name="label" translatable="yes" comments="Translators: Opens a dialog
containing printer's jobs">Show _Jobs</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_underline">True</property>
- <property name="halign">GTK_ALIGN_END</property>
- <property name="valign">GTK_ALIGN_CENTER</property>
- <accessibility>
- <relation type="labelled-by" target="label3"/>
- <relation type="labelled-by" target="printer-jobs-label"/>
- </accessibility>
- </object>
- <packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">6</property>
- <property name="bottom_attach">7</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="CcEditableEntry" id="printer-name-label">
- <property name="visible">True</property>
- <property name="halign">fill</property>
- <property name="valign">end</property>
- <property name="text">Printer</property>
- <property name="weight">700</property>
- <property name="scale">1.2</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkImage" id="printer-icon">
- <property name="visible">True</property>
- <property name="halign">end</property>
- <property name="pixel_size">64</property>
- <property name="icon_name">printer</property>
- </object>
- <packing>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label14">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Model</property>
- <style>
- <class name="dim-label"/>
- </style>
- </object>
- <packing>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label15">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">IP Address</property>
- <style>
- <class name="dim-label"/>
- </style>
- </object>
- <packing>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkNotebook" id="printer-model-notebook">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="show_tabs">False</property>
- <property name="show_border">False</property>
- <child>
- <object class="GtkButton" id="printer-model-button">
- <property name="use_action_appearance">False</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_action_appearance">False</property>
- <property name="relief">none</property>
- <property name="halign">fill</property>
- <child>
- <object class="GtkLabel" id="printer-model-button-label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="margin-start">8</property>
- <property name="label" translatable="no">label</property>
- </object>
- </child>
- <accessibility>
- <relation type="labelled-by" target="label14"/>
- </accessibility>
- </object>
- </child>
- <child type="tab">
- <object class="GtkLabel" id="label7">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">page 1</property>
- </object>
- <packing>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="printer-model-label">
- <property name="visible">True</property>
- <property name="selectable">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">label</property>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child type="tab">
- <object class="GtkLabel" id="label13">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">page 2</property>
- </object>
- <packing>
- <property name="position">1</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="printer-model-setting">
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Setting new driver…</property>
- </object>
- <packing>
- <property name="position">2</property>
- </packing>
- </child>
- <child type="tab">
- <object class="GtkLabel" id="label16">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">page 3</property>
- </object>
- <packing>
- <property name="position">2</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">3</property>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
- </packing>
- </child>
- <child>
- <object class="CcEditableEntry" id="printer-ip-address-label">
- <property name="visible">True</property>
- <property name="text">---</property>
- <accessibility>
- <relation type="labelled-by" target="label15"/>
- </accessibility>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkSwitch" id="printer-disable-switch">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="halign">GTK_ALIGN_END</property>
- <property name="valign">GTK_ALIGN_CENTER</property>
- </object>
- <packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label18">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
- <property name="x_options">0</property>
- <property name="y_options">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label20">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">7</property>
- <property name="bottom_attach">8</property>
- <property name="x_options">0</property>
- <property name="y_options">0</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButtonBox" id="hbuttonbox1">
- <property name="visible">True</property>
- <property name="spacing">5</property>
- <property name="homogeneous">True</property>
- <child>
- <object class="GtkButton" id="print-test-page-button">
- <property name="label" translatable="yes" comments="Translators: This button
executes command which prints test page.">Print _Test Page</property>
- <property name="use_underline">True</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="printer-options-button">
- <property name="label" translatable="yes" comments="Translators: This button opens
printer's options tab">_Options</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">end</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="tab_expand">True</property>
- </packing>
- </child>
- <child type="tab">
- <object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- <property name="label">Info</property>
- </object>
- <packing>
- <property name="tab_fill">False</property>
- </packing>
- </child>
+ <property name="can_focus">False</property>
</object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
</child>
</object>
<packing>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]