printers: Don't request port during creation of PpHost
This allows us to distinguish between situations when the port was specified and when it was not. https://bugzilla.gnome.org/show_bug.cgi?id=695564
This commit is contained in:
parent
8331c88bcd
commit
a15c2f831a
3 changed files with 29 additions and 19 deletions
|
@ -119,7 +119,7 @@ pp_host_class_init (PpHostClass *klass)
|
|||
g_param_spec_int ("port",
|
||||
"Port",
|
||||
"The port",
|
||||
0, G_MAXINT32, 631,
|
||||
-1, G_MAXINT32, PP_HOST_UNSET_PORT,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
|
@ -129,15 +129,14 @@ pp_host_init (PpHost *host)
|
|||
host->priv = G_TYPE_INSTANCE_GET_PRIVATE (host,
|
||||
PP_TYPE_HOST,
|
||||
PpHostPrivate);
|
||||
host->priv->port = PP_HOST_UNSET_PORT;
|
||||
}
|
||||
|
||||
PpHost *
|
||||
pp_host_new (const gchar *hostname,
|
||||
gint port)
|
||||
pp_host_new (const gchar *hostname)
|
||||
{
|
||||
return g_object_new (PP_TYPE_HOST,
|
||||
"hostname", hostname,
|
||||
"port", port,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
@ -380,14 +379,20 @@ _pp_host_get_remote_cups_devices_thread (GSimpleAsyncResult *res,
|
|||
PpPrintDevice *device;
|
||||
http_t *http;
|
||||
gint num_of_devices = 0;
|
||||
gint port;
|
||||
gint i;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (res);
|
||||
data->devices = g_new0 (PpDevicesList, 1);
|
||||
data->devices->devices = NULL;
|
||||
|
||||
if (priv->port == PP_HOST_UNSET_PORT)
|
||||
port = PP_HOST_DEFAULT_IPP_PORT;
|
||||
else
|
||||
port = priv->port;
|
||||
|
||||
/* Connect to remote CUPS server and get its devices */
|
||||
http = httpConnect (priv->hostname, priv->port);
|
||||
http = httpConnect (priv->hostname, port);
|
||||
if (http)
|
||||
{
|
||||
num_of_devices = cupsGetDests2 (http, &dests);
|
||||
|
@ -399,14 +404,14 @@ _pp_host_get_remote_cups_devices_thread (GSimpleAsyncResult *res,
|
|||
device->device_class = g_strdup ("network");
|
||||
device->device_uri = g_strdup_printf ("ipp://%s:%d/printers/%s",
|
||||
priv->hostname,
|
||||
priv->port,
|
||||
port,
|
||||
dests[i].name);
|
||||
device->device_name = g_strdup (dests[i].name);
|
||||
device->device_location = g_strdup (cupsGetOption ("printer-location",
|
||||
dests[i].num_options,
|
||||
dests[i].options));
|
||||
device->host_name = g_strdup (priv->hostname);
|
||||
device->host_port = priv->port;
|
||||
device->host_port = port;
|
||||
device->acquisition_method = ACQUISITION_METHOD_REMOTE_CUPS_SERVER;
|
||||
data->devices->devices = g_list_append (data->devices->devices, device);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ G_BEGIN_DECLS
|
|||
#define PP_IS_HOST_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PP_TYPE_HOST))
|
||||
#define PP_HOST_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PP_TYPE_HOST, PpHostClass))
|
||||
|
||||
#define PP_HOST_UNSET_PORT -1
|
||||
#define PP_HOST_DEFAULT_IPP_PORT 631
|
||||
|
||||
typedef struct _PpHost PpHost;
|
||||
typedef struct _PpHostClass PpHostClass;
|
||||
typedef struct _PpHostPrivate PpHostPrivate;
|
||||
|
@ -51,8 +54,7 @@ struct _PpHostClass
|
|||
|
||||
GType pp_host_get_type (void) G_GNUC_CONST;
|
||||
|
||||
PpHost *pp_host_new (const gchar *hostname,
|
||||
gint port);
|
||||
PpHost *pp_host_new (const gchar *hostname);
|
||||
|
||||
void pp_host_get_snmp_devices_async (PpHost *host,
|
||||
GCancellable *cancellable,
|
||||
|
|
|
@ -1263,9 +1263,9 @@ parse_uri (const gchar *uri,
|
|||
{
|
||||
const gchar *tmp = NULL;
|
||||
gchar *resulting_host = NULL;
|
||||
gchar *port_string = NULL;
|
||||
gchar *position;
|
||||
int resulting_port = 631;
|
||||
|
||||
*port = PP_HOST_UNSET_PORT;
|
||||
|
||||
if (g_strrstr (uri, "://"))
|
||||
tmp = g_strrstr (uri, "://") + 3;
|
||||
|
@ -1287,14 +1287,10 @@ parse_uri (const gchar *uri,
|
|||
if ((position = g_strrstr (resulting_host, ":")))
|
||||
{
|
||||
*position = '\0';
|
||||
port_string = position + 1;
|
||||
*port = atoi (position + 1);
|
||||
}
|
||||
|
||||
if (port_string)
|
||||
resulting_port = atoi (port_string);
|
||||
|
||||
*host = resulting_host;
|
||||
*port = resulting_port;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1326,8 +1322,15 @@ search_for_remote_printers (THostSearchData *data)
|
|||
|
||||
priv->remote_host_cancellable = g_cancellable_new ();
|
||||
|
||||
priv->remote_cups_host = pp_host_new (data->host_name, data->host_port);
|
||||
priv->snmp_host = pp_host_new (data->host_name, data->host_port);
|
||||
priv->remote_cups_host = pp_host_new (data->host_name);
|
||||
priv->snmp_host = pp_host_new (data->host_name);
|
||||
|
||||
if (data->host_port != PP_HOST_UNSET_PORT)
|
||||
{
|
||||
g_object_set (priv->remote_cups_host, "port", data->host_port, NULL);
|
||||
g_object_set (priv->snmp_host, "port", data->host_port, NULL);
|
||||
}
|
||||
|
||||
priv->samba_host = pp_samba_new (GTK_WINDOW (priv->dialog),
|
||||
data->host_name);
|
||||
|
||||
|
@ -1456,7 +1459,7 @@ search_address (const gchar *text,
|
|||
if (text && text[0] != '\0')
|
||||
{
|
||||
gchar *host = NULL;
|
||||
gint port = 631;
|
||||
gint port;
|
||||
|
||||
parse_uri (text, &host, &port);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue