* 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 *hostname;
- char *username;
- char *password;
+ char **auth_info_required;
+ char **auth_info;
};
enum {
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))
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,
- const gchar *hostname,
- const gchar *username,
+ gpointer auth_info_required,
+ gpointer auth_info_default,
+ gpointer auth_info_display,
+ gpointer auth_info_visible,
const gchar *prompt);
static void
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintBackendClass, request_password),
NULL, NULL,
- _gtk_marshal_VOID__STRING_STRING_STRING,
- G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+ _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->hostname = NULL;
- priv->username = NULL;
- priv->password = NULL;
+ 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)
{
}
void
-gtk_print_backend_set_password (GtkPrintBackend *backend,
- const gchar *hostname,
- const gchar *username,
- const gchar *password)
+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, hostname, username, password);
+ GTK_PRINT_BACKEND_GET_CLASS (backend)->set_password (backend, auth_info_required, auth_info);
}
static void
-store_password (GtkEntry *entry,
- GtkPrintBackend *backend)
+store_entry (GtkEntry *entry,
+ gpointer user_data)
{
- GtkPrintBackendPrivate *priv = backend->priv;
+ gchar **data = (gchar **) user_data;
- if (priv->password != NULL)
+ if (*data != NULL)
{
- memset (priv->password, 0, strlen (priv->password));
- g_free (priv->password);
+ memset (*data, 0, strlen (*data));
+ g_free (*data);
}
- priv->password = g_strdup (gtk_entry_get_text (entry));
-}
-
-static void
-store_username (GtkEntry *entry,
- GtkPrintBackend *backend)
-{
- GtkPrintBackendPrivate *priv = backend->priv;
-
- g_free (priv->username);
- priv->username = g_strdup (gtk_entry_get_text (entry));
+ *data = g_strdup (gtk_entry_get_text (entry));
}
static void
GtkPrintBackend *backend)
{
GtkPrintBackendPrivate *priv = backend->priv;
+ gint i;
if (response_id == GTK_RESPONSE_OK)
- gtk_print_backend_set_password (backend, priv->hostname, priv->username, priv->password);
+ gtk_print_backend_set_password (backend, priv->auth_info_required, priv->auth_info);
else
- gtk_print_backend_set_password (backend, priv->hostname, priv->username, NULL);
+ gtk_print_backend_set_password (backend, priv->auth_info_required, NULL);
- if (priv->password != NULL)
- {
- memset (priv->password, 0, strlen (priv->password));
- g_free (priv->password);
- priv->password = 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_free (priv->username);
- priv->username = NULL;
+ g_strfreev (priv->auth_info_required);
gtk_widget_destroy (dialog);
}
static void
-request_password (GtkPrintBackend *backend,
- const gchar *hostname,
- const gchar *username,
- const gchar *prompt)
+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, *username_box, *password_box, *main_box, *label, *icon, *vbox,
- *password_prompt, *username_prompt,
- *password_entry, *username_entry;
+ 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,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
- gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
- main_box = gtk_hbox_new (FALSE, 0);
+ 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_misc_set_alignment (GTK_MISC (icon), 0.5, 0.0);
- gtk_misc_set_padding (GTK_MISC (icon), 6, 6);
-
+ 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_vbox_new (FALSE, 0);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_size_request (GTK_WIDGET (vbox), 320, -1);
/* Right - 1. */
g_free (markup);
- /* Right - 2. */
- username_box = gtk_hbox_new (TRUE, 0);
-
- username_prompt = gtk_label_new (_("Username:"));
- gtk_misc_set_alignment (GTK_MISC (username_prompt), 0.0, 0.5);
-
- username_entry = gtk_entry_new ();
- gtk_entry_set_text (GTK_ENTRY (username_entry), username);
-
-
- /* Right - 3. */
- password_box = gtk_hbox_new (TRUE, 0);
-
- password_prompt = gtk_label_new (_("Password:"));
- gtk_misc_set_alignment (GTK_MISC (password_prompt), 0.0, 0.5);
-
- password_entry = gtk_entry_new ();
- gtk_entry_set_visibility (GTK_ENTRY (password_entry), FALSE);
- gtk_entry_set_activates_default (GTK_ENTRY (password_entry), TRUE);
-
-
/* Packing */
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_box, TRUE, FALSE, 0);
+ 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);
- gtk_box_pack_start (GTK_BOX (vbox), username_box, FALSE, TRUE, 6);
- gtk_box_pack_start (GTK_BOX (vbox), password_box, 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);
- gtk_box_pack_start (GTK_BOX (username_box), username_prompt, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (username_box), username_entry, TRUE, TRUE, 0);
+ label = gtk_label_new (ai_display[i]);
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_box_pack_start (GTK_BOX (password_box), password_prompt, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (password_box), password_entry, TRUE, TRUE, 0);
+ entry = gtk_entry_new ();
+ focus = entry;
+ if (ai_default[i] != NULL)
+ gtk_entry_set_text (GTK_ENTRY (entry), ai_default[i]);
- gtk_widget_grab_focus (password_entry);
+ gtk_entry_set_visibility (GTK_ENTRY (entry), ai_visible[i]);
+ gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
- priv->hostname = g_strdup (hostname);
- priv->username = g_strdup (username);
+ gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 6);
- g_signal_connect (password_entry, "changed",
- G_CALLBACK (store_password), backend);
+ 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 (username_entry, "changed",
- G_CALLBACK (store_username), backend);
+ 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_object_run_dispose (G_OBJECT (print_backend));
}
-
-
-#define __GTK_PRINT_BACKEND_C__
-#include "gtkaliasdef.c"