* 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkintl.h"
#include "gtkmodules.h"
+#include "gtkmodulesprivate.h"
+#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkprintbackend.h"
-#include "gtkprinter-private.h"
-#include "gtkalias.h"
-#define GTK_PRINT_BACKEND_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PRINT_BACKEND, GtkPrintBackendPrivate))
static void gtk_print_backend_dispose (GObject *object);
static void gtk_print_backend_set_property (GObject *object,
guint printer_list_requested : 1;
guint printer_list_done : 1;
GtkPrintBackendStatus status;
+ char **auth_info_required;
+ char **auth_info;
};
enum {
PRINTER_ADDED,
PRINTER_REMOVED,
PRINTER_STATUS_CHANGED,
+ REQUEST_PASSWORD,
LAST_SIGNAL
};
GTypeModuleClass parent_class;
};
+GType _gtk_print_backend_module_get_type (void);
+
G_DEFINE_TYPE (GtkPrintBackendModule, _gtk_print_backend_module, G_TYPE_TYPE_MODULE)
#define GTK_TYPE_PRINT_BACKEND_MODULE (_gtk_print_backend_module_get_type ())
#define GTK_PRINT_BACKEND_MODULE(module) (G_TYPE_CHECK_INSTANCE_CAST ((module), GTK_TYPE_PRINT_BACKEND_MODULE, GtkPrintBackendModule))
pb_module->library = g_module_open (pb_module->path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
if (!pb_module->library)
{
- g_warning (g_module_error());
+ g_warning ("%s", g_module_error());
return FALSE;
}
!g_module_symbol (pb_module->library, "pb_module_create",
&createp))
{
- g_warning (g_module_error());
+ g_warning ("%s", g_module_error());
g_module_close (pb_module->library);
return FALSE;
GParamSpec *pspec)
{
GtkPrintBackend *backend = GTK_PRINT_BACKEND (object);
- GtkPrintBackendPrivate *priv;
-
- priv = backend->priv = GTK_PRINT_BACKEND_GET_PRIVATE (backend);
+ GtkPrintBackendPrivate *priv = backend->priv;
switch (prop_id)
{
GParamSpec *pspec)
{
GtkPrintBackend *backend = GTK_PRINT_BACKEND (object);
- GtkPrintBackendPrivate *priv;
-
- priv = backend->priv = GTK_PRINT_BACKEND_GET_PRIVATE (backend);
+ GtkPrintBackendPrivate *priv = backend->priv;
switch (prop_id)
{
return pb;
}
+/**
+ * gtk_print_backend_load_modules:
+ *
+ * Return value: (element-type GtkPrintBackend) (transfer container):
+ */
GList *
gtk_print_backend_load_modules (void)
{
static void fallback_printer_request_details (GtkPrinter *printer);
static gboolean fallback_printer_mark_conflicts (GtkPrinter *printer,
GtkPrinterOptionSet *options);
-static void fallback_printer_get_hard_margins (GtkPrinter *printer,
- gdouble *top,
- gdouble *bottom,
- gdouble *left,
- gdouble *right);
+static gboolean fallback_printer_get_hard_margins (GtkPrinter *printer,
+ gdouble *top,
+ gdouble *bottom,
+ gdouble *left,
+ gdouble *right);
static GList * fallback_printer_list_papers (GtkPrinter *printer);
static GtkPageSetup * fallback_printer_get_default_page_size (GtkPrinter *printer);
static GtkPrintCapabilities fallback_printer_get_capabilities (GtkPrinter *printer);
+static void request_password (GtkPrintBackend *backend,
+ gpointer auth_info_required,
+ gpointer auth_info_default,
+ gpointer auth_info_display,
+ gpointer auth_info_visible,
+ const gchar *prompt);
static void
gtk_print_backend_class_init (GtkPrintBackendClass *class)
class->printer_list_papers = fallback_printer_list_papers;
class->printer_get_default_page_size = fallback_printer_get_default_page_size;
class->printer_get_capabilities = fallback_printer_get_capabilities;
+ class->request_password = request_password;
g_object_class_install_property (object_class,
PROP_STATUS,
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, GTK_TYPE_PRINTER);
+ signals[REQUEST_PASSWORD] =
+ g_signal_new (I_("request-password"),
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkPrintBackendClass, request_password),
+ NULL, NULL,
+ _gtk_marshal_VOID__POINTER_POINTER_POINTER_POINTER_STRING,
+ G_TYPE_NONE, 5, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING);
}
static void
{
GtkPrintBackendPrivate *priv;
- priv = backend->priv = GTK_PRINT_BACKEND_GET_PRIVATE (backend);
+ priv = backend->priv = G_TYPE_INSTANCE_GET_PRIVATE (backend,
+ GTK_TYPE_PRINT_BACKEND,
+ GtkPrintBackendPrivate);
priv->printers = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_object_unref);
+ priv->auth_info_required = NULL;
+ priv->auth_info = NULL;
}
static void
return FALSE;
}
-static void
+static gboolean
fallback_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top,
gdouble *bottom,
gdouble *left,
gdouble *right)
{
- *top = 0;
- *bottom = 0;
- *left = 0;
- *right = 0;
+ return FALSE;
}
static GList *
}
+/**
+ * gtk_print_backend_get_printer_list:
+ *
+ * Returns the current list of printers.
+ *
+ * Return value: (element-type GtkPrinter) (transfer container):
+ * A list of #GtkPrinter objects. The list should be freed
+ * with g_list_free().
+ */
GList *
gtk_print_backend_get_printer_list (GtkPrintBackend *backend)
{
dnotify);
}
+void
+gtk_print_backend_set_password (GtkPrintBackend *backend,
+ gchar **auth_info_required,
+ gchar **auth_info)
+{
+ g_return_if_fail (GTK_IS_PRINT_BACKEND (backend));
+
+ if (GTK_PRINT_BACKEND_GET_CLASS (backend)->set_password)
+ GTK_PRINT_BACKEND_GET_CLASS (backend)->set_password (backend, auth_info_required, auth_info);
+}
+
+static void
+store_entry (GtkEntry *entry,
+ gpointer user_data)
+{
+ gchar **data = (gchar **) user_data;
+
+ if (*data != NULL)
+ {
+ memset (*data, 0, strlen (*data));
+ g_free (*data);
+ }
+
+ *data = g_strdup (gtk_entry_get_text (entry));
+}
+
+static void
+password_dialog_response (GtkWidget *dialog,
+ gint response_id,
+ GtkPrintBackend *backend)
+{
+ GtkPrintBackendPrivate *priv = backend->priv;
+ gint i;
+
+ if (response_id == GTK_RESPONSE_OK)
+ gtk_print_backend_set_password (backend, priv->auth_info_required, priv->auth_info);
+ else
+ gtk_print_backend_set_password (backend, priv->auth_info_required, NULL);
+
+ for (i = 0; i < g_strv_length (priv->auth_info_required); i++)
+ if (priv->auth_info[i] != NULL)
+ {
+ memset (priv->auth_info[i], 0, strlen (priv->auth_info[i]));
+ g_free (priv->auth_info[i]);
+ priv->auth_info[i] = NULL;
+ }
+ g_free (priv->auth_info);
+ priv->auth_info = NULL;
+
+ g_strfreev (priv->auth_info_required);
+
+ gtk_widget_destroy (dialog);
+
+ g_object_unref (backend);
+}
+
+static void
+request_password (GtkPrintBackend *backend,
+ gpointer auth_info_required,
+ gpointer auth_info_default,
+ gpointer auth_info_display,
+ gpointer auth_info_visible,
+ const gchar *prompt)
+{
+ GtkPrintBackendPrivate *priv = backend->priv;
+ GtkWidget *dialog, *box, *main_box, *label, *icon, *vbox, *entry;
+ GtkWidget *focus = NULL;
+ GtkWidget *content_area;
+ gchar *markup;
+ gint length;
+ gint i;
+ gchar **ai_required = (gchar **) auth_info_required;
+ gchar **ai_default = (gchar **) auth_info_default;
+ gchar **ai_display = (gchar **) auth_info_display;
+ gboolean *ai_visible = (gboolean *) auth_info_visible;
+
+ priv->auth_info_required = g_strdupv (ai_required);
+ length = g_strv_length (ai_required);
+ priv->auth_info = g_new0 (gchar *, length);
+
+ dialog = gtk_dialog_new_with_buttons ( _("Authentication"), NULL, GTK_DIALOG_MODAL,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+
+ /* Left */
+ icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG);
+ gtk_widget_set_halign (icon, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (icon, GTK_ALIGN_START);
+ g_object_set (icon, "margin", 6, NULL);
+
+ /* Right */
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_set_size_request (GTK_WIDGET (vbox), 320, -1);
+
+ /* Right - 1. */
+ label = gtk_label_new (NULL);
+ markup = g_markup_printf_escaped ("<span weight=\"bold\" size=\"large\">%s</span>", prompt);
+ gtk_label_set_markup (GTK_LABEL (label), markup);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_widget_set_size_request (GTK_WIDGET (label), 320, -1);
+ g_free (markup);
+
+
+ /* Packing */
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ gtk_box_pack_start (GTK_BOX (content_area), main_box, TRUE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (main_box), icon, FALSE, FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (main_box), vbox, FALSE, FALSE, 6);
+
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 6);
+
+ /* Right - 2. */
+ for (i = 0; i < length; i++)
+ {
+ priv->auth_info[i] = g_strdup (ai_default[i]);
+ if (ai_display[i] != NULL)
+ {
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
+
+ label = gtk_label_new (ai_display[i]);
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+
+ entry = gtk_entry_new ();
+ focus = entry;
+
+ if (ai_default[i] != NULL)
+ gtk_entry_set_text (GTK_ENTRY (entry), ai_default[i]);
+
+ gtk_entry_set_visibility (GTK_ENTRY (entry), ai_visible[i]);
+ gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
+
+ gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 6);
+
+ gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 0);
+
+ g_signal_connect (entry, "changed",
+ G_CALLBACK (store_entry), &(priv->auth_info[i]));
+ }
+ }
+
+ if (focus != NULL)
+ {
+ gtk_widget_grab_focus (focus);
+ focus = NULL;
+ }
+
+ g_object_ref (backend);
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (password_dialog_response), backend);
+
+ gtk_widget_show_all (dialog);
+}
+
void
gtk_print_backend_destroy (GtkPrintBackend *print_backend)
{
*/
g_object_run_dispose (G_OBJECT (print_backend));
}
-
-
-#define __GTK_PRINT_BACKEND_C__
-#include "gtkaliasdef.c"