2012-08-07 14:09:33 +02:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
|
|
|
*
|
|
|
|
* Copyright 2012 Red Hat, Inc,
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2012-09-06 14:06:01 +02:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2012-08-07 14:09:33 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 12:57:27 +01:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-08-07 14:09:33 +02:00
|
|
|
*
|
|
|
|
* Author: Marek Kasik <mkasik@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdesktop-enums.h>
|
|
|
|
|
|
|
|
#include <cups/cups.h>
|
|
|
|
|
|
|
|
#include "pp-jobs-dialog.h"
|
|
|
|
#include "pp-utils.h"
|
2015-09-08 16:55:38 +02:00
|
|
|
#include "pp-job.h"
|
2020-10-29 14:20:05 +13:00
|
|
|
#include "pp-job-row.h"
|
2015-09-08 16:55:38 +02:00
|
|
|
#include "pp-cups.h"
|
2017-02-28 16:18:39 +01:00
|
|
|
#include "pp-printer.h"
|
2012-08-07 14:09:33 +02:00
|
|
|
|
|
|
|
#define EMPTY_TEXT "\xe2\x80\x94"
|
|
|
|
|
|
|
|
#define CLOCK_SCHEMA "org.gnome.desktop.interface"
|
|
|
|
#define CLOCK_FORMAT_KEY "clock-format"
|
|
|
|
|
|
|
|
struct _PpJobsDialog {
|
2018-07-04 15:34:05 +12:00
|
|
|
GtkDialog parent_instance;
|
|
|
|
|
|
|
|
GtkButton *authenticate_button;
|
|
|
|
GtkMenuButton *authenticate_jobs_button;
|
|
|
|
GtkLabel *authenticate_jobs_label;
|
|
|
|
GtkInfoBar *authentication_infobar;
|
|
|
|
GtkLabel *authentication_label;
|
|
|
|
GtkEntry *domain_entry;
|
|
|
|
GtkLabel *domain_label;
|
|
|
|
GtkButton *jobs_clear_all_button;
|
|
|
|
GtkListBox *jobs_listbox;
|
|
|
|
GtkScrolledWindow *list_jobs_page;
|
|
|
|
GtkBox *no_jobs_page;
|
|
|
|
GtkEntry *password_entry;
|
|
|
|
GtkLabel *password_label;
|
|
|
|
GtkStack *stack;
|
|
|
|
GListStore *store;
|
|
|
|
GtkEntry *username_entry;
|
|
|
|
GtkLabel *username_label;
|
2012-08-07 14:09:33 +02:00
|
|
|
|
|
|
|
gchar *printer_name;
|
|
|
|
|
2018-02-19 01:02:32 +01:00
|
|
|
gchar **actual_auth_info_required;
|
2018-02-16 17:02:19 +01:00
|
|
|
gboolean jobs_filled;
|
|
|
|
gboolean pop_up_authentication_popup;
|
2020-12-24 13:20:24 +08:00
|
|
|
gint max_priority;
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2017-02-28 16:18:39 +01:00
|
|
|
GCancellable *get_jobs_cancellable;
|
2012-08-07 14:09:33 +02:00
|
|
|
};
|
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
G_DEFINE_TYPE (PpJobsDialog, pp_jobs_dialog, GTK_TYPE_DIALOG)
|
|
|
|
|
2018-02-19 01:02:32 +01:00
|
|
|
static gboolean
|
2018-12-04 10:46:35 +13:00
|
|
|
is_info_required (PpJobsDialog *self,
|
2018-02-19 01:02:32 +01:00
|
|
|
const gchar *info)
|
|
|
|
{
|
2019-09-10 14:00:16 +12:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (self->actual_auth_info_required == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; self->actual_auth_info_required[i] != NULL; i++)
|
|
|
|
if (g_strcmp0 (self->actual_auth_info_required[i], info) == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-12-04 10:46:35 +13:00
|
|
|
is_domain_required (PpJobsDialog *self)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
return is_info_required (self, "domain");
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-12-04 10:46:35 +13:00
|
|
|
is_username_required (PpJobsDialog *self)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
return is_info_required (self, "username");
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-12-04 10:46:35 +13:00
|
|
|
is_password_required (PpJobsDialog *self)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
return is_info_required (self, "password");
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-12-04 10:46:35 +13:00
|
|
|
auth_popup_filled (PpJobsDialog *self)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
|
|
|
gboolean domain_required;
|
|
|
|
gboolean username_required;
|
|
|
|
gboolean password_required;
|
|
|
|
guint16 domain_length;
|
|
|
|
guint16 username_length;
|
|
|
|
guint16 password_length;
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
domain_required = is_domain_required (self);
|
|
|
|
username_required = is_username_required (self);
|
|
|
|
password_required = is_password_required (self);
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
domain_length = gtk_entry_get_text_length (self->domain_entry);
|
|
|
|
username_length = gtk_entry_get_text_length (self->username_entry);
|
|
|
|
password_length = gtk_entry_get_text_length (self->password_entry);
|
2018-02-19 01:02:32 +01:00
|
|
|
|
|
|
|
return (!domain_required || domain_length > 0) &&
|
|
|
|
(!username_required || username_length > 0) &&
|
|
|
|
(!password_required || password_length > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-07-04 15:34:05 +12:00
|
|
|
auth_entries_changed (PpJobsDialog *self)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->authenticate_button), auth_popup_filled (self));
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-07-04 15:34:05 +12:00
|
|
|
auth_entries_activated (PpJobsDialog *self)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
if (auth_popup_filled (self))
|
2021-10-29 17:16:45 -03:00
|
|
|
g_signal_emit_by_name (self->authenticate_button, "activate");
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-04 10:46:35 +13:00
|
|
|
authenticate_popover_update (PpJobsDialog *self)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
|
|
|
gboolean domain_required;
|
|
|
|
gboolean username_required;
|
|
|
|
gboolean password_required;
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
domain_required = is_domain_required (self);
|
|
|
|
username_required = is_username_required (self);
|
|
|
|
password_required = is_password_required (self);
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->domain_label), domain_required);
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->domain_entry), domain_required);
|
2018-02-19 01:02:32 +01:00
|
|
|
if (domain_required)
|
2021-10-29 17:16:45 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (self->domain_entry), "");
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->username_label), username_required);
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->username_entry), username_required);
|
2018-02-19 01:02:32 +01:00
|
|
|
if (username_required)
|
2021-10-29 17:16:45 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (self->username_entry), cupsUser ());
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->password_label), password_required);
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->password_entry), password_required);
|
2018-02-19 01:02:32 +01:00
|
|
|
if (password_required)
|
2021-10-29 17:16:45 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (self->password_entry), "");
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->authenticate_button), FALSE);
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
|
2020-12-24 13:20:24 +08:00
|
|
|
static void
|
|
|
|
pp_job_update_cb (GObject *source_object,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
PpJobsDialog *self = user_data;
|
|
|
|
gboolean result;
|
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
PpJob *job = PP_JOB (source_object);
|
|
|
|
|
|
|
|
result = pp_job_set_priority_finish (job, res, &error);
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
pp_jobs_dialog_update (self);
|
|
|
|
}
|
|
|
|
else if (error != NULL)
|
|
|
|
{
|
|
|
|
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
{
|
|
|
|
g_warning ("Could not set job priority: %s", error->message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_priority_changed (PpJobRow *job_row,
|
|
|
|
PpJobsDialog *self)
|
|
|
|
{
|
|
|
|
PpJob *job;
|
|
|
|
|
|
|
|
job = pp_job_row_get_job (job_row);
|
|
|
|
pp_job_set_priority_async (job, ++self->max_priority, NULL, pp_job_update_cb, self);
|
|
|
|
}
|
|
|
|
|
2015-09-08 16:55:38 +02:00
|
|
|
static GtkWidget *
|
|
|
|
create_listbox_row (gpointer item,
|
|
|
|
gpointer user_data)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2020-12-24 13:20:24 +08:00
|
|
|
PpJobRow *job_row;
|
|
|
|
|
|
|
|
job_row = pp_job_row_new (PP_JOB (item));
|
|
|
|
|
|
|
|
g_signal_connect (job_row,
|
|
|
|
"priority-changed",
|
|
|
|
G_CALLBACK (on_priority_changed),
|
|
|
|
user_data);
|
|
|
|
|
|
|
|
return GTK_WIDGET (job_row);
|
2012-08-07 14:09:33 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 17:02:19 +01:00
|
|
|
static void
|
2018-12-04 10:46:35 +13:00
|
|
|
pop_up_authentication_popup (PpJobsDialog *self)
|
2018-02-16 17:02:19 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->actual_auth_info_required != NULL)
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->authenticate_jobs_button), TRUE);
|
2018-02-16 17:02:19 +01:00
|
|
|
}
|
|
|
|
|
2012-08-07 14:09:33 +02:00
|
|
|
static void
|
2017-02-28 16:18:39 +01:00
|
|
|
update_jobs_list_cb (GObject *source_object,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2019-12-17 15:32:57 +13:00
|
|
|
PpJobsDialog *self = user_data;
|
|
|
|
PpPrinter *printer = PP_PRINTER (source_object);
|
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
g_autoptr(GPtrArray) jobs;
|
|
|
|
PpJob *job;
|
|
|
|
gint num_of_auth_jobs = 0;
|
2020-12-24 13:20:24 +08:00
|
|
|
gint job_priority;
|
|
|
|
guint state;
|
2019-12-17 15:32:57 +13:00
|
|
|
guint i;
|
2020-12-24 13:20:24 +08:00
|
|
|
gint current_max_value = 1;
|
|
|
|
gint first_unprocessed_job = -1;
|
2015-09-08 16:55:38 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
g_list_store_remove_all (self->store);
|
2015-09-08 16:55:38 +02:00
|
|
|
|
2017-02-28 16:18:39 +01:00
|
|
|
jobs = pp_printer_get_jobs_finish (printer, result, &error);
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
{
|
|
|
|
g_warning ("Could not get jobs: %s", error->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-17 15:32:57 +13:00
|
|
|
if (jobs->len > 0)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->jobs_clear_all_button), TRUE);
|
|
|
|
gtk_stack_set_visible_child (self->stack, GTK_WIDGET (self->list_jobs_page));
|
2012-08-07 14:09:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->jobs_clear_all_button), FALSE);
|
|
|
|
gtk_stack_set_visible_child (self->stack, GTK_WIDGET (self->no_jobs_page));
|
2012-08-07 14:09:33 +02:00
|
|
|
}
|
|
|
|
|
2020-12-24 13:20:24 +08:00
|
|
|
for (i = 0; i < jobs->len; i++)
|
|
|
|
{
|
|
|
|
job = PP_JOB (g_ptr_array_index (jobs, i));
|
|
|
|
state = pp_job_get_state (job);
|
|
|
|
|
|
|
|
if (state == IPP_JOB_PENDING || state == IPP_JOB_HELD)
|
|
|
|
{
|
|
|
|
if (first_unprocessed_job == -1)
|
|
|
|
{
|
|
|
|
first_unprocessed_job = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 15:32:57 +13:00
|
|
|
for (i = 0; i < jobs->len; i++)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2019-12-17 15:32:57 +13:00
|
|
|
job = PP_JOB (g_ptr_array_index (jobs, i));
|
2020-12-24 13:20:24 +08:00
|
|
|
job_priority = pp_job_get_priority (job);
|
|
|
|
pp_job_priority_set_sensitive (job, (pp_job_get_state (job) == IPP_JOB_PENDING ||
|
|
|
|
pp_job_get_state (job) == IPP_JOB_HELD) &&
|
|
|
|
i > first_unprocessed_job);
|
|
|
|
|
|
|
|
if (job_priority >= current_max_value && job_priority != 100)
|
|
|
|
current_max_value = job_priority;
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2019-12-17 15:32:57 +13:00
|
|
|
g_list_store_append (self->store, g_object_ref (job));
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2020-10-15 09:18:34 +13:00
|
|
|
if (pp_job_get_auth_info_required (job) != NULL)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
|
|
|
num_of_auth_jobs++;
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->actual_auth_info_required == NULL)
|
2020-10-15 09:18:34 +13:00
|
|
|
self->actual_auth_info_required = g_strdupv (pp_job_get_auth_info_required (job));
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-24 13:20:24 +08:00
|
|
|
self->max_priority = current_max_value;
|
2018-02-19 01:02:32 +01:00
|
|
|
if (num_of_auth_jobs > 0)
|
|
|
|
{
|
2018-06-26 11:52:41 +12:00
|
|
|
g_autofree gchar *text = NULL;
|
|
|
|
|
2018-02-19 01:02:32 +01:00
|
|
|
/* Translators: This label shows how many jobs of this printer needs to be authenticated to be printed. */
|
|
|
|
text = g_strdup_printf (ngettext ("%u Job Requires Authentication", "%u Jobs Require Authentication", num_of_auth_jobs), num_of_auth_jobs);
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_label_set_text (self->authenticate_jobs_label, text);
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_widget_show (GTK_WIDGET (self->authentication_infobar));
|
2012-08-07 14:09:33 +02:00
|
|
|
}
|
2018-02-19 01:02:32 +01:00
|
|
|
else
|
|
|
|
{
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_widget_hide (GTK_WIDGET (self->authentication_infobar));
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
authenticate_popover_update (self);
|
2012-08-07 14:09:33 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
g_clear_object (&self->get_jobs_cancellable);
|
2018-02-16 17:02:19 +01:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (!self->jobs_filled)
|
2018-02-16 17:02:19 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->pop_up_authentication_popup)
|
2018-02-16 17:02:19 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
pop_up_authentication_popup (self);
|
|
|
|
self->pop_up_authentication_popup = FALSE;
|
2018-02-16 17:02:19 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->jobs_filled = TRUE;
|
2018-02-16 17:02:19 +01:00
|
|
|
}
|
2012-08-07 14:09:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-04 10:46:35 +13:00
|
|
|
update_jobs_list (PpJobsDialog *self)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2020-06-26 16:51:06 +12:00
|
|
|
g_autoptr(PpPrinter) printer = NULL;
|
2017-02-28 16:18:39 +01:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
if (self->printer_name != NULL)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
g_cancellable_cancel (self->get_jobs_cancellable);
|
|
|
|
g_clear_object (&self->get_jobs_cancellable);
|
2017-02-28 16:18:39 +01:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->get_jobs_cancellable = g_cancellable_new ();
|
2017-02-28 16:18:39 +01:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
printer = pp_printer_new (self->printer_name);
|
2017-02-28 16:18:39 +01:00
|
|
|
pp_printer_get_jobs_async (printer,
|
|
|
|
TRUE,
|
|
|
|
CUPS_WHICHJOBS_ACTIVE,
|
2018-12-04 10:46:35 +13:00
|
|
|
self->get_jobs_cancellable,
|
2017-02-28 16:18:39 +01:00
|
|
|
update_jobs_list_cb,
|
2018-12-04 10:46:35 +13:00
|
|
|
self);
|
2015-09-08 16:55:38 +02:00
|
|
|
}
|
2012-08-07 14:09:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-07-04 15:34:05 +12:00
|
|
|
on_clear_all_button_clicked (PpJobsDialog *self)
|
2015-09-08 16:55:38 +02:00
|
|
|
{
|
|
|
|
guint num_items;
|
|
|
|
guint i;
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
num_items = g_list_model_get_n_items (G_LIST_MODEL (self->store));
|
2015-09-08 16:55:38 +02:00
|
|
|
|
|
|
|
for (i = 0; i < num_items; i++)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpJob *job = PP_JOB (g_list_model_get_item (G_LIST_MODEL (self->store), i));
|
2015-09-08 16:55:38 +02:00
|
|
|
|
|
|
|
pp_job_cancel_purge_async (job, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 01:02:32 +01:00
|
|
|
static void
|
|
|
|
pp_job_authenticate_cb (GObject *source_object,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
PpJobsDialog *self = user_data;
|
2018-06-26 10:40:43 +12:00
|
|
|
gboolean result;
|
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
PpJob *job = PP_JOB (source_object);
|
2018-02-19 01:02:32 +01:00
|
|
|
|
|
|
|
result = pp_job_authenticate_finish (job, res, &error);
|
|
|
|
if (result)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
pp_jobs_dialog_update (self);
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
else if (error != NULL)
|
|
|
|
{
|
|
|
|
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
{
|
|
|
|
g_warning ("Could not authenticate job: %s", error->message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-07-04 15:34:05 +12:00
|
|
|
authenticate_button_clicked (PpJobsDialog *self)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
|
|
|
PpJob *job;
|
|
|
|
gchar **auth_info;
|
|
|
|
guint num_items;
|
|
|
|
gint i;
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
auth_info = g_new0 (gchar *, g_strv_length (self->actual_auth_info_required) + 1);
|
|
|
|
for (i = 0; self->actual_auth_info_required[i] != NULL; i++)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
if (g_strcmp0 (self->actual_auth_info_required[i], "domain") == 0)
|
2021-10-29 17:16:45 -03:00
|
|
|
auth_info[i] = g_strdup (gtk_editable_get_text (GTK_EDITABLE (self->domain_entry)));
|
2018-12-04 10:46:35 +13:00
|
|
|
else if (g_strcmp0 (self->actual_auth_info_required[i], "username") == 0)
|
2021-10-29 17:16:45 -03:00
|
|
|
auth_info[i] = g_strdup (gtk_editable_get_text (GTK_EDITABLE (self->username_entry)));
|
2018-12-04 10:46:35 +13:00
|
|
|
else if (g_strcmp0 (self->actual_auth_info_required[i], "password") == 0)
|
2021-10-29 17:16:45 -03:00
|
|
|
auth_info[i] = g_strdup (gtk_editable_get_text (GTK_EDITABLE (self->password_entry)));
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
num_items = g_list_model_get_n_items (G_LIST_MODEL (self->store));
|
2018-02-19 01:02:32 +01:00
|
|
|
for (i = 0; i < num_items; i++)
|
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
job = PP_JOB (g_list_model_get_item (G_LIST_MODEL (self->store), i));
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2020-10-15 09:18:34 +13:00
|
|
|
if (pp_job_get_auth_info_required (job) != NULL)
|
2018-02-19 01:02:32 +01:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
pp_job_authenticate_async (job, auth_info, NULL, pp_job_authenticate_cb, self);
|
2018-02-19 01:02:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (auth_info);
|
|
|
|
}
|
|
|
|
|
2012-08-07 14:09:33 +02:00
|
|
|
PpJobsDialog *
|
2018-07-04 15:34:05 +12:00
|
|
|
pp_jobs_dialog_new (const gchar *printer_name)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2018-07-04 15:34:05 +12:00
|
|
|
PpJobsDialog *self;
|
2018-06-26 11:52:41 +12:00
|
|
|
g_autofree gchar *text = NULL;
|
|
|
|
g_autofree gchar *title = NULL;
|
2012-08-07 14:09:33 +02:00
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
self = g_object_new (PP_TYPE_JOBS_DIALOG,
|
|
|
|
"use-header-bar", 1,
|
|
|
|
NULL);
|
2012-08-07 14:09:33 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->printer_name = g_strdup (printer_name);
|
|
|
|
self->actual_auth_info_required = NULL;
|
|
|
|
self->jobs_filled = FALSE;
|
|
|
|
self->pop_up_authentication_popup = FALSE;
|
2012-08-07 14:09:33 +02:00
|
|
|
|
2015-09-08 16:55:38 +02:00
|
|
|
/* Translators: This is the printer name for which we are showing the active jobs */
|
2016-10-03 14:43:32 +02:00
|
|
|
title = g_strdup_printf (C_("Printer jobs dialog title", "%s — Active Jobs"), printer_name);
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_window_set_title (GTK_WINDOW (self), title);
|
2012-08-07 14:09:33 +02:00
|
|
|
|
2018-02-19 01:02:32 +01:00
|
|
|
/* Translators: The printer needs authentication info to print. */
|
|
|
|
text = g_strdup_printf (_("Enter credentials to print from %s."), printer_name);
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_label_set_text (self->authentication_label, text);
|
2018-02-19 01:02:32 +01:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
self->store = g_list_store_new (pp_job_get_type ());
|
2018-07-04 15:34:05 +12:00
|
|
|
gtk_list_box_bind_model (self->jobs_listbox, G_LIST_MODEL (self->store),
|
2020-12-24 13:20:24 +08:00
|
|
|
create_listbox_row, self, NULL);
|
2015-09-08 16:55:38 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
update_jobs_list (self);
|
2012-08-07 14:09:33 +02:00
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
return self;
|
2012-08-07 14:09:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-12-04 10:46:35 +13:00
|
|
|
pp_jobs_dialog_update (PpJobsDialog *self)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2018-12-04 10:46:35 +13:00
|
|
|
update_jobs_list (self);
|
2012-08-07 14:09:33 +02:00
|
|
|
}
|
|
|
|
|
2017-03-13 09:16:29 +01:00
|
|
|
void
|
2018-07-04 15:34:05 +12:00
|
|
|
pp_jobs_dialog_authenticate_jobs (PpJobsDialog *self)
|
2017-03-13 09:16:29 +01:00
|
|
|
{
|
2018-07-04 15:34:05 +12:00
|
|
|
if (self->jobs_filled)
|
|
|
|
pop_up_authentication_popup (self);
|
|
|
|
else
|
|
|
|
self->pop_up_authentication_popup = TRUE;
|
|
|
|
}
|
2018-12-04 10:46:35 +13:00
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
static void
|
|
|
|
pp_jobs_dialog_init (PpJobsDialog *dialog)
|
|
|
|
{
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (dialog));
|
2017-03-13 09:16:29 +01:00
|
|
|
}
|
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
static void
|
|
|
|
pp_jobs_dialog_dispose (GObject *object)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2018-07-04 15:34:05 +12:00
|
|
|
PpJobsDialog *self = PP_JOBS_DIALOG (object);
|
|
|
|
|
2018-12-04 10:46:35 +13:00
|
|
|
g_cancellable_cancel (self->get_jobs_cancellable);
|
|
|
|
g_clear_object (&self->get_jobs_cancellable);
|
2018-07-04 15:34:05 +12:00
|
|
|
g_clear_pointer (&self->actual_auth_info_required, g_strfreev);
|
|
|
|
g_clear_pointer (&self->printer_name, g_free);
|
2017-02-28 16:18:39 +01:00
|
|
|
|
2018-07-04 15:34:05 +12:00
|
|
|
G_OBJECT_CLASS (pp_jobs_dialog_parent_class)->dispose (object);
|
2012-08-07 14:09:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-07-04 15:34:05 +12:00
|
|
|
pp_jobs_dialog_class_init (PpJobsDialogClass *klass)
|
2012-08-07 14:09:33 +02:00
|
|
|
{
|
2018-07-04 15:34:05 +12:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/printers/pp-jobs-dialog.ui");
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authenticate_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authenticate_jobs_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authenticate_jobs_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authentication_infobar);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authentication_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, domain_entry);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, domain_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, jobs_clear_all_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, jobs_listbox);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, list_jobs_page);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, no_jobs_page);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, password_entry);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, password_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, stack);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, username_entry);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, username_label);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, authenticate_button_clicked);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_clear_all_button_clicked);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, auth_entries_activated);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, auth_entries_changed);
|
|
|
|
|
|
|
|
object_class->dispose = pp_jobs_dialog_dispose;
|
2021-10-29 17:16:45 -03:00
|
|
|
|
|
|
|
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL);
|
2018-02-16 17:02:19 +01:00
|
|
|
}
|