New cloudprint GTK+ print module for Google Cloud Print.
This is a web service provided by Google that allows people to share their printers (https://www.google.com/cloudprint/learn/). In addition to being able to print to printers shared on Google Cloud Print, there is an equivalent of "Print to file" in the form of "Save to Google Drive". The cloudprint module uses gnome-online-accounts to obtain the OAuth 2.0 access token for the Google account. Currently it can discover available printers, get simple details about them such as display name and status, and submit jobs without any special options. https://bugzilla.gnome.org/show_bug.cgi?id=723368
This commit is contained in:
32
configure.ac
32
configure.ac
@ -1520,6 +1520,37 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# Checks to see if we should compile with cloudprint backend for GTK+
|
||||
#
|
||||
|
||||
AC_ARG_ENABLE(cloudprint,
|
||||
[AS_HELP_STRING([--disable-cloudprint],
|
||||
[disable cloudprint print backend])],,
|
||||
[enable_cloudprint=auto])
|
||||
|
||||
if test "x$enable_cloudprint" = "xno"; then
|
||||
AM_CONDITIONAL(HAVE_CLOUDPRINT, false)
|
||||
else
|
||||
PKG_CHECK_MODULES(REST, [rest-0.7], have_rest=yes, have_rest=no)
|
||||
PKG_CHECK_MODULES(JSON_GLIB, [json-glib-1.0], have_json_glib=yes, have_json_glib=no)
|
||||
if test "x$have_rest" = "xyes" -a "x$have_json_glib" = "xyes"; then
|
||||
PRINT_BACKENDS="$PRINT_BACKENDS cloudprint"
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_CLOUDPRINT, test "x$have_rest" = "xyes" -a "x$have_json_glib" = "xyes")
|
||||
fi
|
||||
|
||||
if test "x$enable_cloudprint" = "xyes" -a "x$have_rest" = "xno"; then
|
||||
AC_MSG_ERROR([
|
||||
*** rest not found.
|
||||
])
|
||||
fi
|
||||
|
||||
if test "x$enable_cloudprint" = "xyes" -a "x$have_json_glib" = "xno"; then
|
||||
AC_MSG_ERROR([
|
||||
*** json-glib not found.
|
||||
])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(HAVE_PAPI_CUPS, test "x$have_papi" = "xyes" -a "x$CUPS_CONFIG" != "xno")
|
||||
|
||||
gtk_save_cppflags="$CPPFLAGS"
|
||||
@ -1859,6 +1890,7 @@ modules/engines/pixbuf/Makefile
|
||||
modules/input/Makefile
|
||||
modules/printbackends/Makefile
|
||||
modules/printbackends/cups/Makefile
|
||||
modules/printbackends/cloudprint/Makefile
|
||||
modules/printbackends/lpr/Makefile
|
||||
modules/printbackends/file/Makefile
|
||||
modules/printbackends/papi/Makefile
|
||||
|
@ -18,6 +18,21 @@ endif
|
||||
|
||||
SUBDIRS = a11y native .
|
||||
|
||||
if HAVE_CLOUDPRINT
|
||||
if HAVE_PAPI_CUPS
|
||||
GTK_PRINT_BACKENDS=file,papi,cups,cloudprint
|
||||
else
|
||||
if HAVE_CUPS
|
||||
GTK_PRINT_BACKENDS=file,cups,cloudprint
|
||||
else
|
||||
if HAVE_PAPI
|
||||
GTK_PRINT_BACKENDS=file,papi,cloudprint
|
||||
else
|
||||
GTK_PRINT_BACKENDS=file,lpr,cloudprint
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if HAVE_PAPI_CUPS
|
||||
GTK_PRINT_BACKENDS=file,papi,cups
|
||||
else
|
||||
@ -31,6 +46,7 @@ GTK_PRINT_BACKENDS=file,lpr
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-DG_LOG_DOMAIN=\"Gtk\" \
|
||||
|
@ -2,6 +2,10 @@ include $(top_srcdir)/Makefile.decl
|
||||
|
||||
SUBDIRS = file lpr
|
||||
|
||||
if HAVE_CLOUDPRINT
|
||||
SUBDIRS += cloudprint
|
||||
endif
|
||||
|
||||
if HAVE_CUPS
|
||||
SUBDIRS += cups
|
||||
endif
|
||||
|
44
modules/printbackends/cloudprint/Makefile.am
Normal file
44
modules/printbackends/cloudprint/Makefile.am
Normal file
@ -0,0 +1,44 @@
|
||||
include $(top_srcdir)/Makefile.decl
|
||||
|
||||
if PLATFORM_WIN32
|
||||
no_undefined = -no-undefined
|
||||
endif
|
||||
|
||||
backenddir = $(libdir)/gtk-3.0/$(GTK_BINARY_VERSION)/printbackends
|
||||
|
||||
backend_LTLIBRARIES = libprintbackend-cloudprint.la
|
||||
|
||||
libprintbackend_cloudprint_la_SOURCES = \
|
||||
gtkprintbackendcloudprint.h \
|
||||
gtkprintbackendcloudprint.c \
|
||||
gtkprintercloudprint.h \
|
||||
gtkprintercloudprint.c \
|
||||
gtkcloudprintaccount.h \
|
||||
gtkcloudprintaccount.c
|
||||
|
||||
libprintbackend_cloudprint_la_CPPFLAGS = \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_srcdir)/gtk \
|
||||
-I$(top_builddir)/gtk \
|
||||
-I$(top_srcdir)/gdk \
|
||||
-I$(top_builddir)/gdk \
|
||||
-DGTK_PRINT_BACKEND_ENABLE_UNSUPPORTED \
|
||||
$(AM_CPPFLAGS)
|
||||
|
||||
libprintbackend_cloudprint_la_CFLAGS = \
|
||||
$(GTK_DEP_CFLAGS) \
|
||||
$(GTK_DEBUG_FLAGS) \
|
||||
$(REST_CFLAGS) \
|
||||
$(JSON_GLIB_CFLAGS) \
|
||||
$(AM_CFLAGS)
|
||||
|
||||
libprintbackend_cloudprint_la_LDFLAGS = \
|
||||
-avoid-version -module $(no_undefined)
|
||||
|
||||
libprintbackend_cloudprint_la_LIBADD = \
|
||||
$(top_builddir)/gtk/libgtk-3.la \
|
||||
$(REST_LIBS) \
|
||||
$(JSON_GLIB_LIBS) \
|
||||
$(GTK_DEP_LIBS)
|
||||
|
||||
-include $(top_srcdir)/git.mk
|
664
modules/printbackends/cloudprint/gtkcloudprintaccount.c
Normal file
664
modules/printbackends/cloudprint/gtkcloudprintaccount.c
Normal file
@ -0,0 +1,664 @@
|
||||
/* gtkcloudprintaccount.c: Google Cloud Print account class
|
||||
* Copyright (C) 2014, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <rest/oauth2-proxy.h>
|
||||
#include <rest/rest-proxy.h>
|
||||
#include <rest/rest-proxy-call.h>
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#include <gtk/gtkunixprint.h>
|
||||
#include "gtkcloudprintaccount.h"
|
||||
#include "gtkprintercloudprint.h"
|
||||
|
||||
#define CLOUDPRINT_PROXY "GTK+"
|
||||
|
||||
#define ACCOUNT_IFACE "org.gnome.OnlineAccounts.Account"
|
||||
#define O_AUTH2_BASED_IFACE "org.gnome.OnlineAccounts.OAuth2Based"
|
||||
|
||||
#define GTK_CLOUDPRINT_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CLOUDPRINT_ACCOUNT, GtkCloudprintAccountClass))
|
||||
#define GTK_IS_CLOUDPRINT_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CLOUDPRINT_ACCOUNT))
|
||||
#define GTK_CLOUDPRINT_ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CLOUDPRINT_ACCOUNT, GtkCloudprintAccountClass))
|
||||
|
||||
static GObjectClass *gtk_cloudprint_account_parent_class;
|
||||
static GType gtk_cloudprint_account_type = 0;
|
||||
|
||||
typedef struct _GtkCloudprintAccountClass GtkCloudprintAccountClass;
|
||||
|
||||
struct _GtkCloudprintAccountClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
struct _GtkCloudprintAccount
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
gchar *printer_id;
|
||||
gchar *goa_path;
|
||||
gchar *presentation_identity;
|
||||
RestProxy *rest_proxy;
|
||||
gchar *oauth2_access_token;
|
||||
};
|
||||
|
||||
static void gtk_cloudprint_account_class_init (GtkCloudprintAccountClass *class);
|
||||
static void gtk_cloudprint_account_init (GtkCloudprintAccount *impl);
|
||||
static void gtk_cloudprint_account_finalize (GObject *object);
|
||||
|
||||
void
|
||||
gtk_cloudprint_account_register_type (GTypeModule *module)
|
||||
{
|
||||
const GTypeInfo cloudprint_account_info =
|
||||
{
|
||||
sizeof (GtkCloudprintAccountClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) gtk_cloudprint_account_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (GtkCloudprintAccount),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) gtk_cloudprint_account_init,
|
||||
};
|
||||
|
||||
gtk_cloudprint_account_type = g_type_module_register_type (module,
|
||||
G_TYPE_OBJECT,
|
||||
"GtkCloudprintAccount",
|
||||
&cloudprint_account_info, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* GtkCloudprintAccount
|
||||
*/
|
||||
GType
|
||||
gtk_cloudprint_account_get_type (void)
|
||||
{
|
||||
return gtk_cloudprint_account_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_cloudprint_account_new:
|
||||
*
|
||||
* Creates a new #GtkCloudprintAccount object, representing a Google
|
||||
* Cloud Print account and its state data.
|
||||
*
|
||||
* Return value: the new #GtkCloudprintAccount object
|
||||
**/
|
||||
GtkCloudprintAccount *
|
||||
gtk_cloudprint_account_new (const gchar *id,
|
||||
const gchar *path,
|
||||
const gchar *presentation_identity)
|
||||
{
|
||||
GtkCloudprintAccount *account = g_object_new (GTK_TYPE_CLOUDPRINT_ACCOUNT,
|
||||
NULL);
|
||||
account->printer_id = g_strdup (id);
|
||||
account->goa_path = g_strdup (path);
|
||||
account->presentation_identity = g_strdup (presentation_identity);
|
||||
return account;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cloudprint_account_class_init (GtkCloudprintAccountClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
gtk_cloudprint_account_parent_class = g_type_class_peek_parent (klass);
|
||||
gobject_class->finalize = gtk_cloudprint_account_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cloudprint_account_init (GtkCloudprintAccount *account)
|
||||
{
|
||||
account->printer_id = NULL;
|
||||
account->goa_path = NULL;
|
||||
account->presentation_identity = NULL;
|
||||
account->rest_proxy = NULL;
|
||||
account->oauth2_access_token = NULL;
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: +GtkCloudprintAccount(%p)\n",
|
||||
account));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cloudprint_account_finalize (GObject *object)
|
||||
{
|
||||
GtkCloudprintAccount *account;
|
||||
|
||||
account = GTK_CLOUDPRINT_ACCOUNT (object);
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: -GtkCloudprintAccount(%p)\n",
|
||||
account));
|
||||
|
||||
g_clear_object (&(account->rest_proxy));
|
||||
g_clear_pointer (&(account->printer_id), g_free);
|
||||
g_clear_pointer (&(account->goa_path), g_free);
|
||||
g_clear_pointer (&(account->presentation_identity), g_free);
|
||||
g_clear_pointer (&(account->oauth2_access_token), g_free);
|
||||
|
||||
G_OBJECT_CLASS (gtk_cloudprint_account_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static JsonParser *
|
||||
cloudprint_json_parse (RestProxyCall *call, JsonObject **result, GError **error)
|
||||
{
|
||||
JsonParser *json_parser = json_parser_new ();
|
||||
JsonNode *root;
|
||||
JsonObject *json_object;
|
||||
gboolean success = FALSE;
|
||||
|
||||
if (!json_parser_load_from_data (json_parser,
|
||||
rest_proxy_call_get_payload (call),
|
||||
rest_proxy_call_get_payload_length (call),
|
||||
error))
|
||||
{
|
||||
g_object_unref (json_parser);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
root = json_parser_get_root (json_parser);
|
||||
if (JSON_NODE_TYPE (root) != JSON_NODE_OBJECT)
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = g_error_new_literal (gtk_print_error_quark (),
|
||||
GTK_PRINT_ERROR_INTERNAL_ERROR,
|
||||
"Bad reply");
|
||||
|
||||
g_object_unref (json_parser);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
json_object = json_node_get_object (root);
|
||||
if (json_object_has_member (json_object, "success"))
|
||||
success = json_object_get_boolean_member (json_object, "success");
|
||||
|
||||
if (!success)
|
||||
{
|
||||
const gchar *message = "(no message)";
|
||||
|
||||
if (json_object_has_member (json_object, "message"))
|
||||
message = json_object_get_string_member (json_object, "message");
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: unsuccessful submit: %s\n",
|
||||
message));
|
||||
|
||||
if (error != NULL)
|
||||
*error = g_error_new_literal (gtk_print_error_quark (),
|
||||
GTK_PRINT_ERROR_INTERNAL_ERROR,
|
||||
message);
|
||||
|
||||
g_object_unref (json_parser);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (result != NULL)
|
||||
*result = json_node_dup_object (root);
|
||||
|
||||
return json_parser;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cloudprint_account_search_rest_call_cb (RestProxyCall *call,
|
||||
const GError *cb_error,
|
||||
GObject *weak_object,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
GtkCloudprintAccount *account = g_task_get_task_data (task);
|
||||
JsonParser *json_parser = NULL;
|
||||
JsonObject *result;
|
||||
JsonNode *printers = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: (%p) 'search' REST call "
|
||||
"returned\n", account));
|
||||
|
||||
if (cb_error != NULL)
|
||||
{
|
||||
error = g_error_copy (cb_error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_task_return_error_if_cancelled (task))
|
||||
{
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((json_parser = cloudprint_json_parse (call, &result, &error)) == NULL)
|
||||
{
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
g_object_unref (json_parser);
|
||||
|
||||
if (json_object_has_member (result, "printers"))
|
||||
printers = json_object_dup_member (result, "printers");
|
||||
|
||||
json_object_unref (result);
|
||||
if (printers == NULL)
|
||||
{
|
||||
g_task_return_new_error (task,
|
||||
gtk_print_error_quark (),
|
||||
GTK_PRINT_ERROR_INTERNAL_ERROR,
|
||||
"Bad reply to 'search' request");
|
||||
return;
|
||||
}
|
||||
|
||||
g_task_return_pointer (task,
|
||||
printers,
|
||||
(GDestroyNotify) json_node_free);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cloudprint_account_got_oauth2_access_token_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
GtkCloudprintAccount *account = g_task_get_task_data (task);
|
||||
RestProxyCall *call;
|
||||
RestProxy *rest;
|
||||
GVariant *output;
|
||||
gint expires_in = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
|
||||
result,
|
||||
&error);
|
||||
g_object_unref (source);
|
||||
|
||||
if (output == NULL)
|
||||
{
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
g_variant_get (output, "(si)",
|
||||
&account->oauth2_access_token,
|
||||
&expires_in);
|
||||
g_variant_unref (output);
|
||||
|
||||
rest = oauth2_proxy_new_with_token (account->printer_id,
|
||||
account->oauth2_access_token,
|
||||
"https://accounts.google.com/o/oauth2/token",
|
||||
"https://www.google.com/cloudprint/",
|
||||
FALSE);
|
||||
|
||||
if (rest == NULL)
|
||||
{
|
||||
g_task_return_new_error (task,
|
||||
gtk_print_error_quark (),
|
||||
GTK_PRINT_ERROR_INTERNAL_ERROR,
|
||||
"REST proxy creation failed");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: (%p) 'search' REST call\n",
|
||||
account));
|
||||
|
||||
account->rest_proxy = g_object_ref (rest);
|
||||
|
||||
call = rest_proxy_new_call (REST_PROXY (rest));
|
||||
g_object_unref (rest);
|
||||
rest_proxy_call_set_function (call, "search");
|
||||
rest_proxy_call_add_header (call, "X-CloudPrint-Proxy", CLOUDPRINT_PROXY);
|
||||
rest_proxy_call_add_param (call, "connection_status", "ALL");
|
||||
if (!rest_proxy_call_async (call,
|
||||
gtk_cloudprint_account_search_rest_call_cb,
|
||||
NULL,
|
||||
task,
|
||||
&error))
|
||||
{
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
g_object_unref (call);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cloudprint_account_ensure_credentials_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
GtkCloudprintAccount *account = g_task_get_task_data (task);
|
||||
GVariant *output;
|
||||
gint expires_in = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
|
||||
result,
|
||||
&error);
|
||||
|
||||
if (output == NULL)
|
||||
{
|
||||
g_object_unref (source);
|
||||
if (error->domain != G_DBUS_ERROR ||
|
||||
(error->code != G_DBUS_ERROR_SERVICE_UNKNOWN &&
|
||||
error->code != G_DBUS_ERROR_UNKNOWN_METHOD))
|
||||
g_task_return_error (task, error);
|
||||
else
|
||||
/* Return an empty list. */
|
||||
g_task_return_pointer (task,
|
||||
json_node_new (JSON_NODE_ARRAY),
|
||||
(GDestroyNotify) json_node_free);
|
||||
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
g_variant_get (output, "(i)",
|
||||
&expires_in);
|
||||
g_variant_unref (output);
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: (%p) getting access token\n",
|
||||
account));
|
||||
|
||||
g_dbus_connection_call (G_DBUS_CONNECTION (source),
|
||||
ONLINE_ACCOUNTS_BUS,
|
||||
account->goa_path,
|
||||
O_AUTH2_BASED_IFACE,
|
||||
"GetAccessToken",
|
||||
NULL,
|
||||
G_VARIANT_TYPE ("(si)"),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
g_task_get_cancellable (task),
|
||||
gtk_cloudprint_account_got_oauth2_access_token_cb,
|
||||
task);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_cloudprint_account_search (GtkCloudprintAccount *account,
|
||||
GDBusConnection *dbus_connection,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = g_task_new (G_OBJECT (account),
|
||||
cancellable,
|
||||
callback,
|
||||
user_data);
|
||||
g_task_set_task_data (task,
|
||||
g_object_ref (account),
|
||||
(GDestroyNotify) g_object_unref);
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: (%p) ensuring credentials\n",
|
||||
account));
|
||||
|
||||
g_dbus_connection_call (g_object_ref (dbus_connection),
|
||||
ONLINE_ACCOUNTS_BUS,
|
||||
account->goa_path,
|
||||
ACCOUNT_IFACE,
|
||||
"EnsureCredentials",
|
||||
NULL,
|
||||
G_VARIANT_TYPE ("(i)"),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
cancellable,
|
||||
gtk_cloudprint_account_ensure_credentials_cb,
|
||||
task);
|
||||
}
|
||||
|
||||
JsonNode *
|
||||
gtk_cloudprint_account_search_finish (GtkCloudprintAccount *account,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, account), NULL);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cloudprint_account_printer_rest_call_cb (RestProxyCall *call,
|
||||
const GError *cb_error,
|
||||
GObject *weak_object,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
GtkCloudprintAccount *account = g_task_get_task_data (task);
|
||||
JsonParser *json_parser = NULL;
|
||||
JsonObject *result;
|
||||
GError *error = NULL;
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: (%p) 'printer' REST call "
|
||||
"returned\n", account));
|
||||
|
||||
if (cb_error != NULL)
|
||||
{
|
||||
error = g_error_copy (cb_error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_task_return_error_if_cancelled (task))
|
||||
{
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((json_parser = cloudprint_json_parse (call, &result, &error)) == NULL)
|
||||
{
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
g_object_unref (json_parser);
|
||||
g_task_return_pointer (task,
|
||||
result,
|
||||
(GDestroyNotify) json_object_unref);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_cloudprint_account_printer (GtkCloudprintAccount *account,
|
||||
const gchar *printerid,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
RestProxyCall *call;
|
||||
GError *error = NULL;
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: (%p) 'printer' REST call for "
|
||||
"printer id %s", account, printerid));
|
||||
|
||||
GTask *task = g_task_new (G_OBJECT (account),
|
||||
cancellable,
|
||||
callback,
|
||||
user_data);
|
||||
|
||||
g_task_set_task_data (task,
|
||||
g_object_ref (account),
|
||||
(GDestroyNotify) g_object_unref);
|
||||
|
||||
call = rest_proxy_new_call (REST_PROXY (account->rest_proxy));
|
||||
rest_proxy_call_set_function (call, "printer");
|
||||
rest_proxy_call_add_header (call, "X-CloudPrint-Proxy", CLOUDPRINT_PROXY);
|
||||
rest_proxy_call_add_param (call, "printerid", printerid);
|
||||
if (!rest_proxy_call_async (call,
|
||||
gtk_cloudprint_account_printer_rest_call_cb,
|
||||
NULL,
|
||||
task,
|
||||
&error))
|
||||
{
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
g_object_unref (call);
|
||||
}
|
||||
|
||||
JsonObject *
|
||||
gtk_cloudprint_account_printer_finish (GtkCloudprintAccount *account,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, account), NULL);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cloudprint_account_submit_rest_call_cb (RestProxyCall *call,
|
||||
const GError *cb_error,
|
||||
GObject *weak_object,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
GtkCloudprintAccount *account = g_task_get_task_data (task);
|
||||
JsonParser *json_parser = NULL;
|
||||
JsonObject *result;
|
||||
GError *error = NULL;
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: (%p) 'submit' REST call "
|
||||
"returned\n", account));
|
||||
|
||||
if (cb_error != NULL)
|
||||
{
|
||||
error = g_error_copy (cb_error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_task_return_error_if_cancelled (task))
|
||||
{
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((json_parser = cloudprint_json_parse (call, &result, &error)) == NULL)
|
||||
{
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
g_object_unref (json_parser);
|
||||
g_task_return_pointer (task,
|
||||
result,
|
||||
(GDestroyNotify) json_object_unref);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_cloudprint_account_submit (GtkCloudprintAccount *account,
|
||||
GtkPrinterCloudprint *printer,
|
||||
GMappedFile *file,
|
||||
const gchar *title,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task;
|
||||
RestProxyCall *call;
|
||||
gchar *printerid = NULL;
|
||||
RestParam *param;
|
||||
GError *error = NULL;
|
||||
gchar *auth;
|
||||
|
||||
g_object_get (printer,
|
||||
"printer-id", &printerid,
|
||||
NULL);
|
||||
|
||||
g_warn_if_fail (printerid != NULL);
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: (%p) 'submit' REST call for "
|
||||
"printer id %s\n", account, printerid));
|
||||
|
||||
task = g_task_new (G_OBJECT (account),
|
||||
cancellable,
|
||||
callback,
|
||||
user_data);
|
||||
|
||||
g_task_set_task_data (task,
|
||||
g_object_ref (account),
|
||||
(GDestroyNotify) g_object_unref);
|
||||
|
||||
call = rest_proxy_new_call (REST_PROXY (account->rest_proxy));
|
||||
rest_proxy_call_set_method (call, "POST");
|
||||
rest_proxy_call_set_function (call, "submit");
|
||||
|
||||
auth = g_strdup_printf ("Bearer %s", account->oauth2_access_token);
|
||||
rest_proxy_call_add_header (call, "Authorization", auth);
|
||||
g_free (auth);
|
||||
rest_proxy_call_add_header (call, "X-CloudPrint-Proxy", CLOUDPRINT_PROXY);
|
||||
|
||||
rest_proxy_call_add_param (call, "printerid", printerid);
|
||||
g_free (printerid);
|
||||
|
||||
rest_proxy_call_add_param (call, "contentType", "dataUrl");
|
||||
rest_proxy_call_add_param (call, "title", title);
|
||||
param = rest_param_new_with_owner ("content",
|
||||
g_mapped_file_get_contents (file),
|
||||
g_mapped_file_get_length (file),
|
||||
"dataUrl",
|
||||
NULL,
|
||||
file,
|
||||
(GDestroyNotify) g_mapped_file_unref);
|
||||
rest_proxy_call_add_param_full (call, param);
|
||||
|
||||
if (!rest_proxy_call_async (call,
|
||||
gtk_cloudprint_account_submit_rest_call_cb,
|
||||
NULL,
|
||||
task,
|
||||
&error))
|
||||
{
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (call);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
g_object_unref (call);
|
||||
}
|
||||
|
||||
JsonObject *
|
||||
gtk_cloudprint_account_submit_finish (GtkCloudprintAccount *account,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, account), NULL);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gtk_cloudprint_account_get_presentation_identity (GtkCloudprintAccount *account)
|
||||
{
|
||||
return account->presentation_identity;
|
||||
}
|
74
modules/printbackends/cloudprint/gtkcloudprintaccount.h
Normal file
74
modules/printbackends/cloudprint/gtkcloudprintaccount.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* gtkcloudprintaccount.h: Google Cloud Print account class
|
||||
* Copyright (C) 2014, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_CLOUDPRINT_ACCOUNT_H__
|
||||
#define __GTK_CLOUDPRINT_ACCOUNT_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#include "gtkprintbackendcloudprint.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_CLOUDPRINT_ACCOUNT (gtk_cloudprint_account_get_type ())
|
||||
#define GTK_CLOUDPRINT_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CLOUDPRINT_ACCOUNT, GtkCloudprintAccount))
|
||||
#define GTK_IS_CLOUDPRINT_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CLOUDPRINT_ACCOUNT))
|
||||
|
||||
typedef struct _GtkPrinterCloudprint GtkPrinterCloudprint;
|
||||
typedef struct _GtkCloudprintAccount GtkCloudprintAccount;
|
||||
|
||||
void gtk_cloudprint_account_register_type (GTypeModule *module);
|
||||
GtkCloudprintAccount *gtk_cloudprint_account_new (const gchar *id,
|
||||
const gchar *path,
|
||||
const gchar *presentation_identity);
|
||||
GType gtk_cloudprint_account_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void gtk_cloudprint_account_search (GtkCloudprintAccount *account,
|
||||
GDBusConnection *connection,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
JsonNode *gtk_cloudprint_account_search_finish (GtkCloudprintAccount *account,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
|
||||
void gtk_cloudprint_account_printer (GtkCloudprintAccount *account,
|
||||
const gchar *printerid,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
JsonObject *gtk_cloudprint_account_printer_finish (GtkCloudprintAccount *account,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
|
||||
void gtk_cloudprint_account_submit (GtkCloudprintAccount *account,
|
||||
GtkPrinterCloudprint *printer,
|
||||
GMappedFile *file,
|
||||
const gchar *title,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
JsonObject *gtk_cloudprint_account_submit_finish (GtkCloudprintAccount *account,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
|
||||
const gchar *gtk_cloudprint_account_get_presentation_identity (GtkCloudprintAccount *account);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_CLOUDPRINT_ACCOUNT_H__ */
|
1053
modules/printbackends/cloudprint/gtkprintbackendcloudprint.c
Normal file
1053
modules/printbackends/cloudprint/gtkprintbackendcloudprint.c
Normal file
File diff suppressed because it is too large
Load Diff
40
modules/printbackends/cloudprint/gtkprintbackendcloudprint.h
Normal file
40
modules/printbackends/cloudprint/gtkprintbackendcloudprint.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* gtkprintbackendcloudprint.h: Google Cloud Print implementation of
|
||||
* GtkPrintBackend
|
||||
* Copyright (C) 2014, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_PRINT_BACKEND_CLOUDPRINT_H__
|
||||
#define __GTK_PRINT_BACKEND_CLOUDPRINT_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "gtkprintbackend.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_PRINT_BACKEND_CLOUDPRINT (gtk_print_backend_cloudprint_get_type ())
|
||||
#define GTK_PRINT_BACKEND_CLOUDPRINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PRINT_BACKEND_CLOUDPRINT, GtkPrintBackendCloudprint))
|
||||
#define GTK_IS_PRINT_BACKEND_CLOUDPRINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PRINT_BACKEND_CLOUDPRINT))
|
||||
|
||||
#define ONLINE_ACCOUNTS_BUS "org.gnome.OnlineAccounts"
|
||||
|
||||
typedef struct _GtkPrintBackendCloudprint GtkPrintBackendCloudprint;
|
||||
|
||||
GtkPrintBackend *gtk_print_backend_cloudprint_new (void);
|
||||
GType gtk_print_backend_cloudprint_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_PRINT_BACKEND_CLOUDPRINT_H__ */
|
231
modules/printbackends/cloudprint/gtkprintercloudprint.c
Normal file
231
modules/printbackends/cloudprint/gtkprintercloudprint.c
Normal file
@ -0,0 +1,231 @@
|
||||
/* gtkprintercloudprint.c: Google Cloud Print -specific Printer class,
|
||||
* GtkPrinterCloudprint
|
||||
* Copyright (C) 2014, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <gtk/gtkintl.h>
|
||||
|
||||
#include "gtkprintercloudprint.h"
|
||||
#include "gtkcloudprintaccount.h"
|
||||
|
||||
typedef struct _GtkPrinterCloudprintClass GtkPrinterCloudprintClass;
|
||||
|
||||
#define GTK_PRINTER_CLOUDPRINT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PRINTER_CLOUDPRINT, GtkPrinterCloudprintClass))
|
||||
#define GTK_IS_PRINTER_CLOUDPRINT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PRINTER_CLOUDPRINT))
|
||||
#define GTK_PRINTER_CLOUDPRINT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PRINTER_CLOUDPRINT, GtkPrinterCloudprintClass))
|
||||
|
||||
static GtkPrinterClass *gtk_printer_cloudprint_parent_class;
|
||||
static GType printer_cloudprint_type = 0;
|
||||
|
||||
struct _GtkPrinterCloudprintClass
|
||||
{
|
||||
GtkPrinterClass parent_class;
|
||||
};
|
||||
|
||||
struct _GtkPrinterCloudprint
|
||||
{
|
||||
GtkPrinter parent_instance;
|
||||
|
||||
GtkCloudprintAccount *account;
|
||||
gchar *id;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CLOUDPRINT_ACCOUNT,
|
||||
PROP_PRINTER_ID
|
||||
};
|
||||
|
||||
static void gtk_printer_cloudprint_class_init (GtkPrinterCloudprintClass *class);
|
||||
static void gtk_printer_cloudprint_init (GtkPrinterCloudprint *impl);
|
||||
static void gtk_printer_cloudprint_finalize (GObject *object);
|
||||
static void gtk_printer_cloudprint_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gtk_printer_cloudprint_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
void
|
||||
gtk_printer_cloudprint_register_type (GTypeModule *module)
|
||||
{
|
||||
const GTypeInfo printer_cloudprint_info =
|
||||
{
|
||||
sizeof (GtkPrinterCloudprintClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) gtk_printer_cloudprint_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (GtkPrinterCloudprint),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) gtk_printer_cloudprint_init,
|
||||
};
|
||||
|
||||
printer_cloudprint_type = g_type_module_register_type (module,
|
||||
GTK_TYPE_PRINTER,
|
||||
"GtkPrinterCloudprint",
|
||||
&printer_cloudprint_info, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* GtkPrinterCloudprint
|
||||
*/
|
||||
GType
|
||||
gtk_printer_cloudprint_get_type (void)
|
||||
{
|
||||
return printer_cloudprint_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_printer_cloudprint_new:
|
||||
*
|
||||
* Creates a new #GtkPrinterCloudprint object. #GtkPrinterCloudprint
|
||||
* implements the #GtkPrinter interface and stores a reference to the
|
||||
* #GtkCloudprintAccount object and the printer-id to use
|
||||
*
|
||||
* Return value: the new #GtkPrinterCloudprint object
|
||||
**/
|
||||
GtkPrinterCloudprint *
|
||||
gtk_printer_cloudprint_new (const char *name,
|
||||
gboolean is_virtual,
|
||||
GtkPrintBackend *backend,
|
||||
GtkCloudprintAccount *account,
|
||||
const gchar *id)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_PRINTER_CLOUDPRINT,
|
||||
"name", name,
|
||||
"backend", backend,
|
||||
"is-virtual", is_virtual,
|
||||
"accepts-pdf", TRUE,
|
||||
"cloudprint-account", account,
|
||||
"printer-id", id,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_printer_cloudprint_class_init (GtkPrinterCloudprintClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
gtk_printer_cloudprint_parent_class = g_type_class_peek_parent (klass);
|
||||
gobject_class->finalize = gtk_printer_cloudprint_finalize;
|
||||
gobject_class->set_property = gtk_printer_cloudprint_set_property;
|
||||
gobject_class->get_property = gtk_printer_cloudprint_get_property;
|
||||
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass),
|
||||
PROP_CLOUDPRINT_ACCOUNT,
|
||||
g_param_spec_object ("cloudprint-account",
|
||||
P_("Cloud Print account"),
|
||||
P_("GtkCloudprintAccount instance"),
|
||||
GTK_TYPE_CLOUDPRINT_ACCOUNT,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass),
|
||||
PROP_PRINTER_ID,
|
||||
g_param_spec_string ("printer-id",
|
||||
P_("Printer ID"),
|
||||
P_("Cloud Print printer ID"),
|
||||
"",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_printer_cloudprint_init (GtkPrinterCloudprint *printer)
|
||||
{
|
||||
printer->account = NULL;
|
||||
printer->id = NULL;
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: +GtkPrinterCloudprint(%p)\n",
|
||||
printer));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_printer_cloudprint_finalize (GObject *object)
|
||||
{
|
||||
GtkPrinterCloudprint *printer;
|
||||
|
||||
printer = GTK_PRINTER_CLOUDPRINT (object);
|
||||
|
||||
GTK_NOTE (PRINTING,
|
||||
g_print ("Cloud Print Backend: -GtkPrinterCloudprint(%p)\n",
|
||||
printer));
|
||||
|
||||
if (printer->account != NULL)
|
||||
g_object_unref (printer->account);
|
||||
|
||||
g_free (printer->id);
|
||||
|
||||
G_OBJECT_CLASS (gtk_printer_cloudprint_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_printer_cloudprint_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkPrinterCloudprint *printer = GTK_PRINTER_CLOUDPRINT (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CLOUDPRINT_ACCOUNT:
|
||||
printer->account = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_PRINTER_ID:
|
||||
printer->id = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_printer_cloudprint_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkPrinterCloudprint *printer = GTK_PRINTER_CLOUDPRINT (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CLOUDPRINT_ACCOUNT:
|
||||
g_value_set_object (value, printer->account);
|
||||
break;
|
||||
|
||||
case PROP_PRINTER_ID:
|
||||
g_value_set_string (value, printer->id);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
45
modules/printbackends/cloudprint/gtkprintercloudprint.h
Normal file
45
modules/printbackends/cloudprint/gtkprintercloudprint.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* gtkprintercloudprint.h: Google Cloud Print -specific Printer class
|
||||
* GtkPrinterCloudprint
|
||||
* Copyright (C) 2014, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_PRINTER_CLOUDPRINT_H__
|
||||
#define __GTK_PRINTER_CLOUDPRINT_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gtk/gtkprinter-private.h>
|
||||
|
||||
#include "gtkcloudprintaccount.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_PRINTER_CLOUDPRINT (gtk_printer_cloudprint_get_type ())
|
||||
#define GTK_PRINTER_CLOUDPRINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PRINTER_CLOUDPRINT, GtkPrinterCloudprint))
|
||||
#define GTK_IS_PRINTER_CLOUDPRINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PRINTER_CLOUDPRINT))
|
||||
|
||||
typedef struct _GtkPrinterCloudprint GtkPrinterCloudprint;
|
||||
|
||||
void gtk_printer_cloudprint_register_type (GTypeModule *module);
|
||||
GtkPrinterCloudprint *gtk_printer_cloudprint_new (const char *name,
|
||||
gboolean is_virtual,
|
||||
GtkPrintBackend *backend,
|
||||
GtkCloudprintAccount *account,
|
||||
const gchar *id);
|
||||
GType gtk_printer_cloudprint_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_PRINTER_CLOUDPRINT_H__ */
|
Reference in New Issue
Block a user