372
380
g_variant_unref (devices_variant);
374
g_variant_unref (dg_output);
376
g_object_unref (source_object);
378
if (error || (ret_error && ret_error[0] != '\0'))
383
g_variant_unref (dg_output);
387
g_warning ("%s", error->message);
388
g_error_free (error);
391
g_object_unref (source_object);
393
if (ret_error && ret_error[0] != '\0')
394
g_warning ("%s", ret_error);
405
keys = g_hash_table_get_keys (devices);
406
for (iter = keys; iter; iter = iter->next)
410
cut = g_strrstr ((gchar *)iter->data, ":");
412
index = atoi (cut + 1);
414
if (index > max_index)
420
pp->num_devices = max_index + 1;
421
pp->devices = g_new0 (CupsDevice, pp->num_devices);
423
g_hash_table_foreach (devices, store_device_parameter, pp);
425
/* Assign names to devices */
426
for (i = 0; i < pp->num_devices; i++)
430
if (pp->devices[i].device_id)
432
name = get_tag_value (pp->devices[i].device_id, "mdl");
434
name = get_tag_value (pp->devices[i].device_id, "model");
437
name = g_strcanon (name, ALLOWED_CHARACTERS, '-');
441
pp->devices[i].device_info)
443
name = g_strdup (pp->devices[i].device_info);
445
name = g_strcanon (name, ALLOWED_CHARACTERS, '-');
449
already_present = FALSE;
450
num_dests = cupsGetDests (&dests);
455
new_name = g_strdup_printf ("%s-%d", name, name_index);
459
new_name = g_strdup (name);
461
already_present = FALSE;
462
for (j = 0; j < num_dests; j++)
463
if (g_strcmp0 (dests[j].name, new_name) == 0)
464
already_present = TRUE;
473
} while (already_present);
474
cupsFreeDests (num_dests, dests);
476
pp->devices[i].display_name = name;
480
* Don't show duplicates.
481
* Show devices with device-id.
482
* Other preferences should apply here.
484
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
485
G_DBUS_PROXY_FLAGS_NONE,
495
GVariantBuilder device_list;
496
GVariantBuilder device_hash;
497
GVariant *input = NULL;
498
GVariant *output = NULL;
499
GVariant *array = NULL;
500
GVariant *subarray = NULL;
502
g_variant_builder_init (&device_list, G_VARIANT_TYPE ("a{sv}"));
504
for (i = 0; i < pp->num_devices; i++)
506
if (pp->devices[i].device_uri)
508
g_variant_builder_init (&device_hash, G_VARIANT_TYPE ("a{ss}"));
510
if (pp->devices[i].device_id)
511
g_variant_builder_add (&device_hash,
514
pp->devices[i].device_id);
516
if (pp->devices[i].device_make_and_model)
517
g_variant_builder_add (&device_hash,
519
"device-make-and-model",
520
pp->devices[i].device_make_and_model);
522
if (pp->devices[i].device_class)
523
g_variant_builder_add (&device_hash,
526
pp->devices[i].device_class);
528
g_variant_builder_add (&device_list,
530
pp->devices[i].device_uri,
531
g_variant_builder_end (&device_hash));
535
input = g_variant_new ("(v)", g_variant_builder_end (&device_list));
537
output = g_dbus_proxy_call_sync (proxy,
538
"GroupPhysicalDevices",
540
G_DBUS_CALL_FLAGS_NONE,
545
if (output && g_variant_n_children (output) == 1)
547
array = g_variant_get_child_value (output, 0);
550
for (i = 0; i < g_variant_n_children (array); i++)
552
subarray = g_variant_get_child_value (array, i);
555
device_uri = g_strdup (g_variant_get_string (
556
g_variant_get_child_value (subarray, 0),
559
for (k = 0; k < pp->num_devices; k++)
560
if (g_str_has_prefix (pp->devices[k].device_uri, device_uri))
561
pp->devices[k].show = TRUE;
570
g_variant_unref (output);
571
g_variant_unref (input);
572
g_object_unref (proxy);
381
g_warning ("%s", error->message);
383
if (ret_error && ret_error[0] != '\0')
384
g_warning ("%s", ret_error);
396
keys = g_hash_table_get_keys (devices);
397
for (iter = keys; iter; iter = iter->next)
401
cut = g_strrstr ((gchar *)iter->data, ":");
403
index = atoi (cut + 1);
405
if (index > max_index)
411
pp->num_devices = max_index + 1;
412
pp->devices = g_new0 (CupsDevice, pp->num_devices);
414
g_hash_table_foreach (devices, store_device_parameter, pp);
416
/* Assign names to devices */
417
for (i = 0; i < pp->num_devices; i++)
421
if (pp->devices[i].device_id)
423
name = get_tag_value (pp->devices[i].device_id, "mdl");
425
name = get_tag_value (pp->devices[i].device_id, "model");
428
name = g_strcanon (name, ALLOWED_CHARACTERS, '-');
432
pp->devices[i].device_info)
434
name = g_strdup (pp->devices[i].device_info);
436
name = g_strcanon (name, ALLOWED_CHARACTERS, '-');
440
already_present = FALSE;
441
num_dests = cupsGetDests (&dests);
446
new_name = g_strdup_printf ("%s-%d", name, name_index);
450
new_name = g_strdup (name);
452
already_present = FALSE;
453
for (j = 0; j < num_dests; j++)
454
if (g_strcmp0 (dests[j].name, new_name) == 0)
455
already_present = TRUE;
464
} while (already_present);
465
cupsFreeDests (num_dests, dests);
467
pp->devices[i].display_name = name;
471
* Don't show duplicates.
472
* Show devices with device-id.
473
* Other preferences should apply here.
475
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
476
G_DBUS_PROXY_FLAGS_NONE,
486
GVariantBuilder device_list;
487
GVariantBuilder device_hash;
488
GVariant *input = NULL;
489
GVariant *output = NULL;
490
GVariant *array = NULL;
491
GVariant *subarray = NULL;
493
g_variant_builder_init (&device_list, G_VARIANT_TYPE ("a{sv}"));
495
for (i = 0; i < pp->num_devices; i++)
497
if (pp->devices[i].device_uri)
499
g_variant_builder_init (&device_hash, G_VARIANT_TYPE ("a{ss}"));
501
if (pp->devices[i].device_id)
502
g_variant_builder_add (&device_hash,
505
pp->devices[i].device_id);
507
if (pp->devices[i].device_make_and_model)
508
g_variant_builder_add (&device_hash,
510
"device-make-and-model",
511
pp->devices[i].device_make_and_model);
513
if (pp->devices[i].device_class)
514
g_variant_builder_add (&device_hash,
517
pp->devices[i].device_class);
519
g_variant_builder_add (&device_list,
521
pp->devices[i].device_uri,
522
g_variant_builder_end (&device_hash));
526
input = g_variant_new ("(v)", g_variant_builder_end (&device_list));
528
output = g_dbus_proxy_call_sync (proxy,
529
"GroupPhysicalDevices",
531
G_DBUS_CALL_FLAGS_NONE,
536
if (output && g_variant_n_children (output) == 1)
538
array = g_variant_get_child_value (output, 0);
541
for (i = 0; i < g_variant_n_children (array); i++)
543
subarray = g_variant_get_child_value (array, i);
546
device_uri = g_strdup (g_variant_get_string (
547
g_variant_get_child_value (subarray, 0),
550
for (k = 0; k < pp->num_devices; k++)
551
if (g_str_has_prefix (pp->devices[k].device_uri, device_uri))
552
pp->devices[k].show = TRUE;
561
g_variant_unref (output);
562
g_variant_unref (input);
563
g_object_unref (proxy);
569
(error->domain == G_DBUS_ERROR &&
570
(error->code == G_DBUS_ERROR_SERVICE_UNKNOWN ||
571
error->code == G_DBUS_ERROR_UNKNOWN_METHOD)))
572
g_warning ("Install system-config-printer which provides \
578
(error->domain == G_DBUS_ERROR &&
579
(error->code == G_DBUS_ERROR_SERVICE_UNKNOWN ||
580
error->code == G_DBUS_ERROR_UNKNOWN_METHOD)))
581
g_warning ("Install system-config-printer which provides \
573
582
DBus method \"GroupPhysicalDevices\" to group duplicates in device list.");
575
for (i = 0; i < pp->num_devices; i++)
576
pp->devices[i].show = TRUE;
579
584
for (i = 0; i < pp->num_devices; i++)
580
if (!pp->devices[i].device_id)
581
pp->devices[i].show = FALSE;
585
pp->devices[i].show = TRUE;
584
g_hash_table_destroy (devices);
585
actualize_devices_list (pp);
588
widget = (GtkWidget*)
589
gtk_builder_get_object (pp->builder, "get-devices-status-label");
590
gtk_label_set_text (GTK_LABEL (widget), " ");
592
widget = (GtkWidget*)
593
gtk_builder_get_object (pp->builder, "spinner");
594
gtk_spinner_stop (GTK_SPINNER (widget));
595
gtk_widget_set_sensitive (widget, FALSE);
596
gtk_widget_hide (widget);
598
if (pp->cancellable != NULL)
600
g_object_unref (pp->cancellable);
601
pp->cancellable = NULL;
604
g_clear_error (&error);
588
for (i = 0; i < pp->num_devices; i++)
589
if (!pp->devices[i].device_id)
590
pp->devices[i].show = FALSE;
593
g_hash_table_destroy (devices);
594
actualize_devices_list (pp);
597
widget = (GtkWidget*)
598
gtk_builder_get_object (pp->builder, "get-devices-status-label");
599
gtk_label_set_text (GTK_LABEL (widget), " ");
601
widget = (GtkWidget*)
602
gtk_builder_get_object (pp->builder, "spinner");
603
gtk_spinner_stop (GTK_SPINNER (widget));
604
gtk_widget_set_sensitive (widget, FALSE);
605
gtk_widget_hide (widget);
607
if (pp->cancellable != NULL)
609
g_object_unref (pp->cancellable);
610
pp->cancellable = NULL;
629
if (pp->show_warning)
631
widget = (GtkWidget*)
632
gtk_builder_get_object (pp->builder, "local-devices-notebook");
633
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WARNING_TAB);
635
widget = (GtkWidget*)
636
gtk_builder_get_object (pp->builder, "network-devices-notebook");
637
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WARNING_TAB);
640
in_include = g_variant_builder_new (G_VARIANT_TYPE ("as"));
641
in_exclude = g_variant_builder_new (G_VARIANT_TYPE ("as"));
643
dg_input = g_variant_new ("(iiasas)",
649
widget = (GtkWidget*)
650
gtk_builder_get_object (pp->builder, "get-devices-status-label");
651
gtk_label_set_text (GTK_LABEL (widget), _("Getting devices..."));
653
widget = (GtkWidget*)
654
gtk_builder_get_object (pp->builder, "spinner");
655
gtk_spinner_start (GTK_SPINNER (widget));
656
gtk_widget_set_sensitive (widget, TRUE);
657
gtk_widget_show (widget);
659
pp->cancellable = g_cancellable_new ();
661
g_dbus_proxy_call (proxy,
664
G_DBUS_CALL_FLAGS_NONE,
670
g_variant_builder_unref (in_exclude);
671
g_variant_builder_unref (in_include);
672
g_variant_unref (dg_input);
637
g_warning ("%s", error->message);
638
g_error_free (error);
639
pp->searching = FALSE;
643
if (pp->show_warning)
645
widget = (GtkWidget*)
646
gtk_builder_get_object (pp->builder, "local-devices-notebook");
647
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WARNING_TAB);
649
widget = (GtkWidget*)
650
gtk_builder_get_object (pp->builder, "network-devices-notebook");
651
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WARNING_TAB);
654
in_include = g_variant_builder_new (G_VARIANT_TYPE ("as"));
655
in_exclude = g_variant_builder_new (G_VARIANT_TYPE ("as"));
657
dg_input = g_variant_new ("(iiasas)",
663
widget = (GtkWidget*)
664
gtk_builder_get_object (pp->builder, "get-devices-status-label");
665
gtk_label_set_text (GTK_LABEL (widget), _("Getting devices..."));
667
widget = (GtkWidget*)
668
gtk_builder_get_object (pp->builder, "spinner");
669
gtk_spinner_start (GTK_SPINNER (widget));
670
gtk_widget_set_sensitive (widget, TRUE);
671
gtk_widget_show (widget);
673
pp->cancellable = g_cancellable_new ();
675
g_dbus_proxy_call (proxy,
678
G_DBUS_CALL_FLAGS_NONE,
684
g_variant_builder_unref (in_exclude);
685
g_variant_builder_unref (in_include);
686
g_variant_unref (dg_input);
688
pp->searching = FALSE;
1204
1263
DEVICE_ID_COLUMN, i,
1205
1264
DEVICE_NAME_COLUMN, pp->devices[i].display_name,
1266
no_local_device = FALSE;
1271
if (no_local_device && !pp->searching)
1273
gtk_list_store_append (local_store, &iter);
1274
gtk_list_store_set (local_store, &iter,
1275
DEVICE_ID_COLUMN, 0,
1276
/* Translators: No localy connected printers were found */
1277
DEVICE_NAME_COLUMN, _("No local printers found"),
1279
gtk_widget_set_sensitive (GTK_WIDGET (local_treeview), FALSE);
1282
gtk_widget_set_sensitive (GTK_WIDGET (local_treeview), TRUE);
1284
if (no_network_device && !pp->show_warning && !pp->searching)
1286
gtk_list_store_append (network_store, &iter);
1287
gtk_list_store_set (network_store, &iter,
1288
DEVICE_ID_COLUMN, 0,
1289
/* Translators: No network printers were found */
1290
DEVICE_NAME_COLUMN, _("No network printers found"),
1292
gtk_widget_set_sensitive (GTK_WIDGET (network_treeview), FALSE);
1295
gtk_widget_set_sensitive (GTK_WIDGET (network_treeview), TRUE);
1211
1297
gtk_tree_view_set_model (network_treeview, GTK_TREE_MODEL (network_store));
1212
1298
gtk_tree_view_set_model (local_treeview, GTK_TREE_MODEL (local_store));
1214
if (gtk_tree_model_get_iter_first ((GtkTreeModel *) network_store, &iter))
1300
if (!no_network_device &&
1301
gtk_tree_model_get_iter_first ((GtkTreeModel *) network_store, &iter))
1215
1302
gtk_tree_selection_select_iter (
1216
1303
gtk_tree_view_get_selection (GTK_TREE_VIEW (network_treeview)),
1219
if (gtk_tree_model_get_iter_first ((GtkTreeModel *) local_store, &iter))
1306
if (!no_local_device &&
1307
gtk_tree_model_get_iter_first ((GtkTreeModel *) local_store, &iter))
1220
1308
gtk_tree_selection_select_iter (
1221
1309
gtk_tree_view_get_selection (GTK_TREE_VIEW (local_treeview)),
1510
dbus_g_proxy_call (proxy, "PrinterAddWithPpdFile", &error,
1511
G_TYPE_STRING, pp->devices[device_id].display_name,
1512
G_TYPE_STRING, pp->devices[device_id].device_uri,
1513
G_TYPE_STRING, ppd_file_name,
1514
G_TYPE_STRING, pp->devices[device_id].device_info,
1515
G_TYPE_STRING, pp->devices[device_id].device_location,
1517
G_TYPE_STRING, &ret_error,
1520
if (error || (ret_error && ret_error[0] != '\0'))
1522
dialog_response = GTK_RESPONSE_REJECT;
1525
g_warning ("%s", error->message);
1527
if (ret_error && ret_error[0] != '\0')
1528
g_warning ("%s", ret_error);
1530
g_clear_error (&error);
1591
result = dbus_g_proxy_call (proxy, "PrinterAddWithPpdFile", &error,
1592
G_TYPE_STRING, pp->devices[device_id].display_name,
1593
G_TYPE_STRING, pp->devices[device_id].device_uri,
1594
G_TYPE_STRING, ppd_file_name,
1595
G_TYPE_STRING, pp->devices[device_id].device_info,
1596
G_TYPE_STRING, pp->devices[device_id].device_location,
1598
G_TYPE_STRING, &ret_error,
1603
g_warning ("%s", error->message);
1604
g_error_free (error);
1605
dialog_response = GTK_RESPONSE_REJECT;
1608
if (ret_error && ret_error[0] != '\0')
1610
g_warning ("%s", ret_error);
1611
dialog_response = GTK_RESPONSE_REJECT;
1614
if (result && (!ret_error || ret_error[0] == '\0'))
1533
1615
success = TRUE;
1535
1617
g_object_unref (proxy);
1625
dbus_g_proxy_call (proxy, "PrinterAdd", &error,
1626
G_TYPE_STRING, pp->devices[device_id].display_name,
1627
G_TYPE_STRING, pp->devices[device_id].device_uri,
1628
G_TYPE_STRING, ppd_name->ppd_name,
1629
G_TYPE_STRING, pp->devices[device_id].device_info,
1630
G_TYPE_STRING, pp->devices[device_id].device_location,
1632
G_TYPE_STRING, &ret_error,
1635
if (error || (ret_error && ret_error[0] != '\0'))
1637
dialog_response = GTK_RESPONSE_REJECT;
1640
g_warning ("%s", error->message);
1642
if (ret_error && ret_error[0] != '\0')
1643
g_warning ("%s", ret_error);
1645
g_clear_error (&error);
1710
result = dbus_g_proxy_call (proxy, "PrinterAdd", &error,
1711
G_TYPE_STRING, pp->devices[device_id].display_name,
1712
G_TYPE_STRING, pp->devices[device_id].device_uri,
1713
G_TYPE_STRING, ppd_name->ppd_name,
1714
G_TYPE_STRING, pp->devices[device_id].device_info,
1715
G_TYPE_STRING, pp->devices[device_id].device_location,
1717
G_TYPE_STRING, &ret_error,
1722
g_warning ("%s", error->message);
1723
g_error_free (error);
1724
dialog_response = GTK_RESPONSE_REJECT;
1727
if (ret_error && ret_error[0] != '\0')
1729
g_warning ("%s", ret_error);
1730
dialog_response = GTK_RESPONSE_REJECT;
1648
1733
g_object_unref (proxy);