summaryrefslogtreecommitdiff
path: root/panels
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2020-10-29 14:20:05 +1300
committerRobert Ancell <robert.ancell@canonical.com>2020-12-14 09:51:19 +1300
commit6622b3963248a1800739fa785c158a9ad2183c0c (patch)
treebd27f134dda7de438571b27407388ed1965354b1 /panels
parentcd070d2e5a8031f3f1de790a20ce2bf4ca6c1320 (diff)
downloadgnome-control-center-6622b3963248a1800739fa785c158a9ad2183c0c.tar.gz
printers: Make PpJobRow widget
Diffstat (limited to 'panels')
-rw-r--r--panels/printers/meson.build2
-rw-r--r--panels/printers/pp-job-row.c151
-rw-r--r--panels/printers/pp-job-row.h34
-rw-r--r--panels/printers/pp-job-row.ui67
-rw-r--r--panels/printers/pp-jobs-dialog.c100
-rw-r--r--panels/printers/printers.gresource.xml1
6 files changed, 257 insertions, 98 deletions
diff --git a/panels/printers/meson.build b/panels/printers/meson.build
index f887625db..ccce64cb7 100644
--- a/panels/printers/meson.build
+++ b/panels/printers/meson.build
@@ -24,6 +24,7 @@ sources = files(
'pp-host.c',
'pp-ipp-option-widget.c',
'pp-job.c',
+ 'pp-job-row.c',
'pp-jobs-dialog.c',
'pp-maintenance-command.c',
'pp-new-printer-dialog.c',
@@ -43,6 +44,7 @@ resource_data = files(
'new-printer-dialog.ui',
'ppd-selection-dialog.ui',
'pp-details-dialog.ui',
+ 'pp-job-row.ui',
'pp-jobs-dialog.ui',
'pp-options-dialog.ui',
'printer-entry.ui',
diff --git a/panels/printers/pp-job-row.c b/panels/printers/pp-job-row.c
new file mode 100644
index 000000000..7caa8319b
--- /dev/null
+++ b/panels/printers/pp-job-row.c
@@ -0,0 +1,151 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2020 Canonical Ltd.
+ *
+ * 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 3 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <config.h>
+#include <glib/gi18n.h>
+
+#include "pp-job-row.h"
+#include "cc-printers-resources.h"
+
+struct _PpJobRow
+{
+ GtkListBoxRow parent;
+
+ GtkButton *pause_button;
+ GtkImage *pause_image;
+ GtkLabel *state_label;
+ GtkLabel *title_label;
+
+ PpJob *job;
+};
+
+G_DEFINE_TYPE (PpJobRow, pp_job_row, GTK_TYPE_LIST_BOX_ROW)
+
+static void
+pause_cb (PpJobRow *self)
+{
+ pp_job_set_hold_until_async (self->job, pp_job_get_state (self->job) == IPP_JOB_HELD ? "no-hold" : "indefinite");
+ gtk_image_set_from_icon_name (self->pause_image,
+ pp_job_get_state (self->job) == IPP_JOB_HELD ?
+ "media-playback-pause-symbolic" : "media-playback-start-symbolic",
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
+}
+
+static void
+stop_cb (PpJobRow *self)
+{
+ pp_job_cancel_purge_async (self->job, FALSE);
+}
+
+static void
+pp_job_row_dispose (GObject *object)
+{
+ PpJobRow *self = PP_JOB_ROW (object);
+
+ g_clear_object (&self->job);
+
+ G_OBJECT_CLASS (pp_job_row_parent_class)->dispose (object);
+}
+
+static void
+pp_job_row_class_init (PpJobRowClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->dispose = pp_job_row_dispose;
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/printers/pp-job-row.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, PpJobRow, pause_button);
+ gtk_widget_class_bind_template_child (widget_class, PpJobRow, pause_image);
+ gtk_widget_class_bind_template_child (widget_class, PpJobRow, state_label);
+ gtk_widget_class_bind_template_child (widget_class, PpJobRow, title_label);
+
+ gtk_widget_class_bind_template_callback (widget_class, pause_cb);
+ gtk_widget_class_bind_template_callback (widget_class, stop_cb);
+}
+
+static void
+pp_job_row_init (PpJobRow *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+PpJobRow *
+pp_job_row_new (PpJob *job)
+{
+ PpJobRow *self;
+ g_autofree gchar *state_string = NULL;
+
+ self = g_object_new (PP_TYPE_JOB_ROW, NULL);
+
+ self->job = g_object_ref (job);
+
+ switch (pp_job_get_state (job))
+ {
+ case IPP_JOB_PENDING:
+ /* Translators: Job's state (job is waiting to be printed) */
+ state_string = g_strdup (C_("print job", "Pending"));
+ break;
+ case IPP_JOB_HELD:
+ if (pp_job_get_auth_info_required (job) == NULL)
+ {
+ /* Translators: Job's state (job is held for printing) */
+ state_string = g_strdup (C_("print job", "Paused"));
+ }
+ else
+ {
+ /* Translators: Job's state (job needs authentication to proceed further) */
+ state_string = g_strdup_printf ("<span foreground=\"#ff0000\">%s</span>", C_("print job", "Authentication required"));
+ }
+ break;
+ case IPP_JOB_PROCESSING:
+ /* Translators: Job's state (job is currently printing) */
+ state_string = g_strdup (C_("print job", "Processing"));
+ break;
+ case IPP_JOB_STOPPED:
+ /* Translators: Job's state (job has been stopped) */
+ state_string = g_strdup (C_("print job", "Stopped"));
+ break;
+ case IPP_JOB_CANCELED:
+ /* Translators: Job's state (job has been canceled) */
+ state_string = g_strdup (C_("print job", "Canceled"));
+ break;
+ case IPP_JOB_ABORTED:
+ /* Translators: Job's state (job has aborted due to error) */
+ state_string = g_strdup (C_("print job", "Aborted"));
+ break;
+ case IPP_JOB_COMPLETED:
+ /* Translators: Job's state (job has completed successfully) */
+ state_string = g_strdup (C_("print job", "Completed"));
+ break;
+ }
+
+ gtk_label_set_text (self->title_label, pp_job_get_title (job));
+ gtk_label_set_markup (self->state_label, state_string);
+ gtk_widget_set_sensitive (GTK_WIDGET (self->pause_button), pp_job_get_auth_info_required (job) == NULL);
+ gtk_image_set_from_icon_name (self->pause_image,
+ pp_job_get_state (self->job) == IPP_JOB_HELD ?
+ "media-playback-start-symbolic" : "media-playback-pause-symbolic",
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
+
+ return self;
+}
diff --git a/panels/printers/pp-job-row.h b/panels/printers/pp-job-row.h
new file mode 100644
index 000000000..9e8b6df79
--- /dev/null
+++ b/panels/printers/pp-job-row.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2020 Canonical Ltd.
+ *
+ * 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 3 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include "pp-job.h"
+
+G_BEGIN_DECLS
+
+#define PP_TYPE_JOB_ROW (pp_job_row_get_type())
+G_DECLARE_FINAL_TYPE (PpJobRow, pp_job_row, PP, JOB_ROW, GtkListBoxRow)
+
+PpJobRow* pp_job_row_new (PpJob *job);
+
+G_END_DECLS
diff --git a/panels/printers/pp-job-row.ui b/panels/printers/pp-job-row.ui
new file mode 100644
index 000000000..50674871e
--- /dev/null
+++ b/panels/printers/pp-job-row.ui
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="PpJobRow" parent="GtkListBoxRow">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="border-width">2</property>
+ <property name="margin">6</property>
+ <child>
+ <object class="GtkLabel" id="title_label">
+ <property name="visible">True</property>
+ <property name="ellipsize">end</property>
+ <property name="max-width-chars">40</property>
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ <property name="margin-start">10</property>
+ <property name="margin-end">10</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="state_label">
+ <property name="visible">True</property>
+ <property name="halign">end</property>
+ <property name="margin-start">74</property>
+ <property name="margin-end">74</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="pause_button">
+ <property name="visible">True</property>
+ <property name="margin-left">4</property>
+ <property name="margin-right">4</property>
+ <signal name="clicked" handler="pause_cb" object="PpJobRow" swapped="yes" />
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child>
+ <object class="GtkImage" id="pause_image">
+ <property name="visible">True</property>
+ <property name="icon-size">2</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">True</property>
+ <property name="margin-left">4</property>
+ <property name="margin-right">4</property>
+ <signal name="clicked" handler="stop_cb" object="PpJobRow" swapped="yes" />
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon-name">edit-delete-symbolic</property>
+ <property name="icon-size">2</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/panels/printers/pp-jobs-dialog.c b/panels/printers/pp-jobs-dialog.c
index aecb7f272..c47741fd3 100644
--- a/panels/printers/pp-jobs-dialog.c
+++ b/panels/printers/pp-jobs-dialog.c
@@ -35,6 +35,7 @@
#include "pp-jobs-dialog.h"
#include "pp-utils.h"
#include "pp-job.h"
+#include "pp-job-row.h"
#include "pp-cups.h"
#include "pp-printer.h"
@@ -174,108 +175,11 @@ authenticate_popover_update (PpJobsDialog *self)
gtk_widget_set_sensitive (GTK_WIDGET (self->authenticate_button), FALSE);
}
-static void
-job_stop_cb (GtkButton *button,
- PpJob *job)
-{
- pp_job_cancel_purge_async (job, FALSE);
-}
-
-static void
-job_pause_cb (GtkButton *button,
- PpJob *job)
-{
- pp_job_set_hold_until_async (job, pp_job_get_state (job) == IPP_JOB_HELD ? "no-hold" : "indefinite");
-
- gtk_button_set_image (button,
- gtk_image_new_from_icon_name (pp_job_get_state (job) == IPP_JOB_HELD ?
- "media-playback-pause-symbolic" : "media-playback-start-symbolic",
- GTK_ICON_SIZE_SMALL_TOOLBAR));
-}
-
static GtkWidget *
create_listbox_row (gpointer item,
gpointer user_data)
{
- PpJob *job = PP_JOB (item);
- GtkWidget *widget;
- GtkWidget *box;
- g_autofree gchar *state_string = NULL;
-
- switch (pp_job_get_state (job))
- {
- case IPP_JOB_PENDING:
- /* Translators: Job's state (job is waiting to be printed) */
- state_string = g_strdup (C_("print job", "Pending"));
- break;
- case IPP_JOB_HELD:
- if (pp_job_get_auth_info_required (job) == NULL)
- {
- /* Translators: Job's state (job is held for printing) */
- state_string = g_strdup (C_("print job", "Paused"));
- }
- else
- {
- /* Translators: Job's state (job needs authentication to proceed further) */
- state_string = g_strdup_printf ("<span foreground=\"#ff0000\">%s</span>", C_("print job", "Authentication required"));
- }
- break;
- case IPP_JOB_PROCESSING:
- /* Translators: Job's state (job is currently printing) */
- state_string = g_strdup (C_("print job", "Processing"));
- break;
- case IPP_JOB_STOPPED:
- /* Translators: Job's state (job has been stopped) */
- state_string = g_strdup (C_("print job", "Stopped"));
- break;
- case IPP_JOB_CANCELED:
- /* Translators: Job's state (job has been canceled) */
- state_string = g_strdup (C_("print job", "Canceled"));
- break;
- case IPP_JOB_ABORTED:
- /* Translators: Job's state (job has aborted due to error) */
- state_string = g_strdup (C_("print job", "Aborted"));
- break;
- case IPP_JOB_COMPLETED:
- /* Translators: Job's state (job has completed successfully) */
- state_string = g_strdup (C_("print job", "Completed"));
- break;
- }
-
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_widget_show (box);
- g_object_set (box, "margin", 6, NULL);
- gtk_container_set_border_width (GTK_CONTAINER (box), 2);
-
- widget = gtk_label_new (pp_job_get_title (job));
- gtk_widget_show (widget);
- gtk_label_set_max_width_chars (GTK_LABEL (widget), 40);
- gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_END);
- gtk_widget_set_halign (widget, GTK_ALIGN_START);
- gtk_box_pack_start (GTK_BOX (box), widget, TRUE, TRUE, 10);
-
- widget = gtk_label_new (NULL);
- gtk_widget_show (widget);
- gtk_label_set_markup (GTK_LABEL (widget), state_string);
- gtk_widget_set_halign (widget, GTK_ALIGN_END);
- gtk_widget_set_margin_end (widget, 64);
- gtk_widget_set_margin_start (widget, 64);
- gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 10);
-
- widget = gtk_button_new_from_icon_name (pp_job_get_state (job) == IPP_JOB_HELD ? "media-playback-start-symbolic" : "media-playback-pause-symbolic",
- GTK_ICON_SIZE_SMALL_TOOLBAR);
- gtk_widget_show (widget);
- g_signal_connect (widget, "clicked", G_CALLBACK (job_pause_cb), job);
- gtk_widget_set_sensitive (widget, pp_job_get_auth_info_required (job) == NULL);
- gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 4);
-
- widget = gtk_button_new_from_icon_name ("edit-delete-symbolic",
- GTK_ICON_SIZE_SMALL_TOOLBAR);
- gtk_widget_show (widget);
- g_signal_connect (widget, "clicked", G_CALLBACK (job_stop_cb), job);
- gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 4);
-
- return box;
+ return GTK_WIDGET (pp_job_row_new (PP_JOB (item)));
}
static void
diff --git a/panels/printers/printers.gresource.xml b/panels/printers/printers.gresource.xml
index b9a7d4be1..7b216ba7e 100644
--- a/panels/printers/printers.gresource.xml
+++ b/panels/printers/printers.gresource.xml
@@ -6,6 +6,7 @@
<file preprocess="xml-stripblanks">pp-options-dialog.ui</file>
<file preprocess="xml-stripblanks">ppd-selection-dialog.ui</file>
<file preprocess="xml-stripblanks">pp-details-dialog.ui</file>
+ <file preprocess="xml-stripblanks">pp-job-row.ui</file>
<file preprocess="xml-stripblanks">pp-jobs-dialog.ui</file>
<file preprocess="xml-stripblanks">printer-entry.ui</file>
<file preprocess="xml-stripblanks">printers.ui</file>