Commit 902f90e5 authored by Robert Ancell's avatar Robert Ancell Committed by Robert Ancell

printers: Add methods for getting printer name and location

Remove the GObject properties that aren't type safe.
parent 598505e7
Pipeline #225598 passed with stages
in 5 minutes and 6 seconds
......@@ -253,9 +253,7 @@ printer_removed_cb (GObject *source_object,
{
PpPrinter *printer = PP_PRINTER (source_object);
g_autoptr(GError) error = NULL;
g_autofree gchar *printer_name = NULL;
g_object_get (printer, "printer-name", &printer_name, NULL);
pp_printer_delete_finish (printer, result, &error);
if (user_data != NULL)
......@@ -269,7 +267,7 @@ printer_removed_cb (GObject *source_object,
for (iter = self->deleted_printers; iter != NULL; iter = iter->next)
{
if (g_strcmp0 (iter->data, printer_name) == 0)
if (g_strcmp0 (iter->data, pp_printer_get_name (printer)) == 0)
{
g_free (iter->data);
self->deleted_printers = g_list_delete_link (self->deleted_printers, iter);
......@@ -678,23 +676,18 @@ on_printer_deleted (CcPrintersPanel *self,
{
GtkLabel *label;
g_autofree gchar *notification_message = NULL;
g_autofree gchar *printer_name = NULL;
GtkWidget *widget;
on_notification_dismissed (self);
g_object_get (printer_entry,
"printer-name", &printer_name,
NULL);
/* Translators: %s is the printer name */
notification_message = g_strdup_printf (_("Printer “%s” has been deleted"),
printer_name);
pp_printer_entry_get_name (printer_entry));
label = (GtkLabel*)
gtk_builder_get_object (self->builder, "notification-label");
gtk_label_set_label (label, notification_message);
self->deleted_printer_name = g_strdup (printer_name);
self->deleted_printer_name = g_strdup (pp_printer_entry_get_name (printer_entry));
widget = (GtkWidget*) gtk_builder_get_object (self->builder, "content");
gtk_list_box_invalidate_filter (GTK_LIST_BOX (widget));
......@@ -709,10 +702,7 @@ on_printer_renamed (CcPrintersPanel *self,
gchar *new_name,
PpPrinterEntry *printer_entry)
{
g_object_get (printer_entry,
"printer-name",
&self->old_printer_name,
NULL);
self->old_printer_name = g_strdup (pp_printer_entry_get_name (printer_entry));
self->renamed_printer_name = g_strdup (new_name);
}
......@@ -786,15 +776,12 @@ destroy_nonexisting_entries (PpPrinterEntry *entry,
gpointer user_data)
{
CcPrintersPanel *self = (CcPrintersPanel *) user_data;
g_autofree gchar *printer_name = NULL;
gboolean exists = FALSE;
gint i;
g_object_get (G_OBJECT (entry), "printer-name", &printer_name, NULL);
for (i = 0; i < self->num_dests; i++)
{
if (g_strcmp0 (self->dests[i].name, printer_name) == 0)
if (g_strcmp0 (self->dests[i].name, pp_printer_entry_get_name (entry)) == 0)
{
exists = TRUE;
break;
......@@ -803,8 +790,8 @@ destroy_nonexisting_entries (PpPrinterEntry *entry,
if (!exists)
{
g_hash_table_remove (self->printer_entries, pp_printer_entry_get_name (entry));
gtk_widget_destroy (GTK_WIDGET (entry));
g_hash_table_remove (self->printer_entries, printer_name);
}
}
......@@ -1120,20 +1107,14 @@ filter_function (GtkListBoxRow *row,
gpointer user_data)
{
CcPrintersPanel *self = (CcPrintersPanel*) user_data;
PpPrinterEntry *entry = PP_PRINTER_ENTRY (row);
GtkWidget *search_entry;
gboolean retval;
g_autofree gchar *search = NULL;
g_autofree gchar *name = NULL;
g_autofree gchar *location = NULL;
g_autofree gchar *printer_name = NULL;
g_autofree gchar *printer_location = NULL;
GList *iter;
g_object_get (G_OBJECT (row),
"printer-name", &printer_name,
"printer-location", &printer_location,
NULL);
search_entry = (GtkWidget*)
gtk_builder_get_object (self->builder, "search-entry");
......@@ -1143,8 +1124,8 @@ filter_function (GtkListBoxRow *row,
}
else
{
name = cc_util_normalize_casefold_and_unaccent (printer_name);
location = cc_util_normalize_casefold_and_unaccent (printer_location);
name = cc_util_normalize_casefold_and_unaccent (pp_printer_entry_get_name (entry));
location = cc_util_normalize_casefold_and_unaccent (pp_printer_entry_get_location (entry));
search = cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (search_entry)));
......@@ -1154,7 +1135,7 @@ filter_function (GtkListBoxRow *row,
}
if (self->deleted_printer_name != NULL &&
g_strcmp0 (self->deleted_printer_name, printer_name) == 0)
g_strcmp0 (self->deleted_printer_name, pp_printer_entry_get_name (entry)) == 0)
{
retval = FALSE;
}
......@@ -1163,7 +1144,7 @@ filter_function (GtkListBoxRow *row,
{
for (iter = self->deleted_printers; iter != NULL; iter = iter->next)
{
if (g_strcmp0 (iter->data, printer_name) == 0)
if (g_strcmp0 (iter->data, pp_printer_entry_get_name (entry)) == 0)
{
retval = FALSE;
break;
......@@ -1179,27 +1160,19 @@ sort_function (GtkListBoxRow *row1,
GtkListBoxRow *row2,
gpointer user_data)
{
g_autofree gchar *printer_name1 = NULL;
g_autofree gchar *printer_name2 = NULL;
g_object_get (G_OBJECT (row1),
"printer-name", &printer_name1,
NULL);
g_object_get (G_OBJECT (row2),
"printer-name", &printer_name2,
NULL);
PpPrinterEntry *entry1 = PP_PRINTER_ENTRY (row1);
PpPrinterEntry *entry2 = PP_PRINTER_ENTRY (row2);
if (printer_name1 != NULL)
if (pp_printer_entry_get_name (entry1) != NULL)
{
if (printer_name2 != NULL)
return g_ascii_strcasecmp (printer_name1, printer_name2);
if (pp_printer_entry_get_name (entry2) != NULL)
return g_ascii_strcasecmp (pp_printer_entry_get_name (entry1), pp_printer_entry_get_name (entry2));
else
return 1;
}
else
{
if (printer_name2 != NULL)
if (pp_printer_entry_get_name (entry2) != NULL)
return -1;
else
return 0;
......
......@@ -93,12 +93,6 @@ struct _PpPrinterEntryClass
G_DEFINE_TYPE (PpPrinterEntry, pp_printer_entry, GTK_TYPE_LIST_BOX_ROW)
enum {
PROP_0,
PROP_PRINTER_NAME,
PROP_PRINTER_LOCATION,
};
enum {
IS_DEFAULT_PRINTER,
PRINTER_DELETE,
......@@ -124,49 +118,6 @@ ink_level_data_free (InkLevelData *data)
g_slice_free (InkLevelData, data);
}
static void
pp_printer_entry_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PpPrinterEntry *self = PP_PRINTER_ENTRY (object);
switch (prop_id)
{
case PROP_PRINTER_NAME:
g_value_set_string (value, self->printer_name);
break;
case PROP_PRINTER_LOCATION:
g_value_set_string (value, self->printer_location);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
pp_printer_entry_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PpPrinterEntry *self = PP_PRINTER_ENTRY (object);
switch (prop_id)
{
case PROP_PRINTER_NAME:
self->printer_name = g_value_dup_string (value);
break;
case PROP_PRINTER_LOCATION:
self->printer_location = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
pp_printer_entry_init (PpPrinterEntry *self)
{
......@@ -403,16 +354,11 @@ on_printer_rename_cb (GObject *source_object,
gpointer user_data)
{
PpPrinterEntry *self = user_data;
g_autofree gchar *printer_name = NULL;
if (!pp_printer_rename_finish (PP_PRINTER (source_object), result, NULL))
return;
g_object_get (PP_PRINTER (source_object),
"printer-name", &printer_name,
NULL);
g_signal_emit_by_name (self, "printer-renamed", printer_name);
g_signal_emit_by_name (self, "printer-renamed", pp_printer_get_name (PP_PRINTER (source_object)));
}
static void
......@@ -691,7 +637,9 @@ pp_printer_entry_new (cups_dest_t printer,
{
PpPrinterEntry *self;
self = g_object_new (PP_PRINTER_ENTRY_TYPE, "printer-name", printer.name, NULL);
self = g_object_new (PP_PRINTER_ENTRY_TYPE, NULL);
self->printer_name = g_strdup (printer.name);
self->clean_command = pp_maintenance_command_new (self->printer_name,
"Clean",
......@@ -707,6 +655,20 @@ pp_printer_entry_new (cups_dest_t printer,
return self;
}
const gchar *
pp_printer_entry_get_name (PpPrinterEntry *self)
{
g_return_val_if_fail (PP_IS_PRINTER_ENTRY (self), NULL);
return self->printer_name;
}
const gchar *
pp_printer_entry_get_location (PpPrinterEntry *self)
{
g_return_val_if_fail (PP_IS_PRINTER_ENTRY (self), NULL);
return self->printer_location;
}
void
pp_printer_entry_update (PpPrinterEntry *self,
cups_dest_t printer,
......@@ -924,7 +886,8 @@ pp_printer_entry_update (PpPrinterEntry *self,
else
printer_icon_name = g_strdup ("printer-network");
g_object_set (self, "printer-location", location, NULL);
g_free (self->printer_location);
self->printer_location = g_strdup (location);
self->is_accepting_jobs = is_accepting_jobs;
self->is_authorized = is_authorized;
......@@ -1024,26 +987,8 @@ pp_printer_entry_class_init (PpPrinterEntryClass *klass)
gtk_widget_class_bind_template_callback (widget_class, show_jobs_dialog);
gtk_widget_class_bind_template_callback (widget_class, restart_printer);
object_class->get_property = pp_printer_entry_get_property;
object_class->set_property = pp_printer_entry_set_property;
object_class->dispose = pp_printer_entry_dispose;
g_object_class_install_property (object_class,
PROP_PRINTER_NAME,
g_param_spec_string ("printer-name",
"Printer Name",
"The Printer unique name",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_PRINTER_LOCATION,
g_param_spec_string ("printer-location",
"Printer Location",
"Printer location string",
NULL,
G_PARAM_READWRITE));
signals[IS_DEFAULT_PRINTER] =
g_signal_new ("printer-changed",
G_TYPE_FROM_CLASS (klass),
......
......@@ -28,6 +28,10 @@ G_DECLARE_FINAL_TYPE (PpPrinterEntry, pp_printer_entry, PP, PRINTER_ENTRY, GtkLi
PpPrinterEntry *pp_printer_entry_new (cups_dest_t printer,
gboolean is_authorized);
const gchar *pp_printer_entry_get_name (PpPrinterEntry *self);
const gchar *pp_printer_entry_get_location (PpPrinterEntry *self);
void pp_printer_entry_update_jobs_count (PpPrinterEntry *self);
GSList *pp_printer_entry_get_size_group_widgets (PpPrinterEntry *self);
......
......@@ -34,12 +34,6 @@ struct _PpPrinter
G_DEFINE_TYPE (PpPrinter, pp_printer, G_TYPE_OBJECT)
enum
{
PROP_0 = 0,
PROP_NAME
};
static void
pp_printer_dispose (GObject *object)
{
......@@ -50,61 +44,12 @@ pp_printer_dispose (GObject *object)
G_OBJECT_CLASS (pp_printer_parent_class)->dispose (object);
}
static void
pp_printer_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PpPrinter *self = PP_PRINTER (object);
switch (property_id)
{
case PROP_NAME:
g_value_set_string (value, self->printer_name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
pp_printer_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PpPrinter *self = PP_PRINTER (object);
switch (property_id)
{
case PROP_NAME:
g_free (self->printer_name);
self->printer_name = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
pp_printer_class_init (PpPrinterClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = pp_printer_set_property;
gobject_class->get_property = pp_printer_get_property;
gobject_class->dispose = pp_printer_dispose;
g_object_class_install_property (gobject_class, PROP_NAME,
g_param_spec_string ("printer-name",
"Printer name",
"Name of this printer",
NULL,
G_PARAM_READWRITE));
}
static void
......@@ -115,11 +60,20 @@ pp_printer_init (PpPrinter *self)
PpPrinter *
pp_printer_new (const gchar *name)
{
PpPrinter *self = g_object_new (PP_TYPE_PRINTER, "printer-name", name, NULL);
PpPrinter *self = g_object_new (PP_TYPE_PRINTER, NULL);
self->printer_name = g_strdup (name);
return self;
}
const gchar *
pp_printer_get_name (PpPrinter *self)
{
g_return_val_if_fail (PP_IS_PRINTER (self), NULL);
return self->printer_name;
}
static void
printer_rename_thread (GTask *task,
gpointer source_object,
......@@ -128,16 +82,14 @@ printer_rename_thread (GTask *task,
{
PpPrinter *self = PP_PRINTER (source_object);
gboolean result;
gchar *new_printer_name = task_data;
g_autofree gchar *old_printer_name = NULL;
const gchar *new_printer_name = task_data;
g_object_get (self, "printer-name", &old_printer_name, NULL);
result = printer_rename (old_printer_name, new_printer_name);
result = printer_rename (self->printer_name, new_printer_name);
if (result)
{
g_object_set (self, "printer-name", new_printer_name, NULL);
g_free (self->printer_name);
self->printer_name = g_strdup (new_printer_name);
}
g_task_return_boolean (task, result);
......@@ -160,21 +112,20 @@ printer_rename_dbus_cb (GObject *source_object,
if (output != NULL)
{
g_autofree gchar *old_printer_name = NULL;
const gchar *ret_error;
self = g_task_get_source_object (task);
g_object_get (self, "printer-name", &old_printer_name, NULL);
g_variant_get (output, "(&s)", &ret_error);
if (ret_error[0] != '\0')
{
g_warning ("cups-pk-helper: renaming of printer %s failed: %s", old_printer_name, ret_error);
g_warning ("cups-pk-helper: renaming of printer %s failed: %s", self->printer_name, ret_error);
}
else
{
result = TRUE;
g_object_set (self, "printer-name", g_task_get_task_data (task), NULL);
g_free (self->printer_name);
self->printer_name = g_strdup (g_task_get_task_data (task));
}
g_task_return_boolean (task, result);
......@@ -201,6 +152,7 @@ get_bus_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
PpPrinter *self;
GDBusConnection *bus;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = user_data;
......@@ -208,18 +160,14 @@ get_bus_cb (GObject *source_object,
bus = g_bus_get_finish (res, &error);
if (bus != NULL)
{
g_autofree gchar *printer_name = NULL;
g_object_get (g_task_get_source_object (task),
"printer-name", &printer_name,
NULL);
self = g_task_get_source_object (task);
g_dbus_connection_call (bus,
MECHANISM_BUS,
"/",
MECHANISM_BUS,
"PrinterRename",
g_variant_new ("(ss)",
printer_name,
self->printer_name,
g_task_get_task_data (task)),
G_VARIANT_TYPE ("(s)"),
G_DBUS_CALL_FLAGS_NONE,
......@@ -295,10 +243,8 @@ get_jobs_thread (GTask *task,
gint num_jobs;
gint i, j;
g_object_get (self, "printer-name", &printer_name, NULL);
num_jobs = cupsGetJobs (&jobs,
printer_name,
self->printer_name,
get_jobs_data->myjobs ? 1 : 0,
get_jobs_data->which_jobs);
......@@ -328,7 +274,7 @@ get_jobs_thread (GTask *task,
if (auth_info_required == NULL)
{
g_autofree gchar *printer_uri = g_strdup_printf ("ipp://localhost/printers/%s", printer_name);
g_autofree gchar *printer_uri = g_strdup_printf ("ipp://localhost/printers/%s", self->printer_name);
printer_request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
ippAddString (printer_request, IPP_TAG_OPERATION, IPP_TAG_URI,
......@@ -408,6 +354,7 @@ pp_printer_delete_dbus_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
PpPrinter *self;
g_autoptr(GVariant) output = NULL;
gboolean result = FALSE;
g_autoptr(GError) error = NULL;
......@@ -419,14 +366,13 @@ pp_printer_delete_dbus_cb (GObject *source_object,
if (output != NULL)
{
g_autofree gchar *printer_name = NULL;
const gchar *ret_error;
g_object_get (g_task_get_source_object (task), "printer-name", &printer_name, NULL);
self = g_task_get_source_object (task);
g_variant_get (output, "(&s)", &ret_error);
if (ret_error[0] != '\0')
g_warning ("cups-pk-helper: removing of printer %s failed: %s", printer_name, ret_error);
g_warning ("cups-pk-helper: removing of printer %s failed: %s", self->printer_name, ret_error);
else
result = TRUE;
......@@ -445,6 +391,7 @@ pp_printer_delete_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
PpPrinter *self;
GDBusConnection *bus;
g_autoptr(GError) error = NULL;
GTask *task = user_data;
......@@ -452,18 +399,14 @@ pp_printer_delete_cb (GObject *source_object,
bus = g_bus_get_finish (res, &error);
if (bus != NULL)
{
g_autofree gchar *printer_name = NULL;
g_object_get (g_task_get_source_object (task),
"printer-name", &printer_name,
NULL);
self = g_task_get_source_object (task);
g_dbus_connection_call (bus,
MECHANISM_BUS,
"/",
MECHANISM_BUS,
"PrinterDelete",
g_variant_new ("(s)", printer_name),
g_variant_new ("(s)", self->printer_name),
G_VARIANT_TYPE ("(s)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
......@@ -531,14 +474,12 @@ print_file_thread (GTask *task,
cups_dest_t *dest = NULL;
const gchar *printer_type = NULL;
gboolean ret = FALSE;
g_autofree gchar *printer_name = NULL;
g_autofree gchar *printer_uri = NULL;
g_autofree gchar *resource = NULL;
ipp_t *response = NULL;
ipp_t *request;
g_object_get (self, "printer-name", &printer_name, NULL);
dest = cupsGetNamedDest (CUPS_HTTP_DEFAULT, printer_name, NULL);
dest = cupsGetNamedDest (CUPS_HTTP_DEFAULT, self->printer_name, NULL);
if (dest != NULL)
{
printer_type = cupsGetOption ("printer-type",
......@@ -552,13 +493,13 @@ print_file_thread (GTask *task,
if (type & CUPS_PRINTER_CLASS)
{
printer_uri = g_strdup_printf ("ipp://localhost/classes/%s", printer_name);
resource = g_strdup_printf ("/classes/%s", printer_name);
printer_uri = g_strdup_printf ("ipp://localhost/classes/%s", self->printer_name);
resource = g_strdup_printf ("/classes/%s", self->printer_name);
}
else
{
printer_uri = g_strdup_printf ("ipp://localhost/printers/%s", printer_name);
resource = g_strdup_printf ("/printers/%s", printer_name);
printer_uri = g_strdup_printf ("ipp://localhost/printers/%s", self->printer_name);
resource = g_strdup_printf ("/printers/%s", self->printer_name);
}
print_file_data = g_task_get_task_data (task);
......
......@@ -34,6 +34,8 @@ GType pp_printer_get_type (void) G_GNUC_CONST;
PpPrinter *pp_printer_new (const gchar *name);
const gchar *pp_printer_get_name (PpPrinter *printer);
void pp_printer_rename_async (PpPrinter *printer,
const gchar *new_printer_name,
GCancellable *cancellable,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment