1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/* this file is part of evince, a gnome document viewer
*
* Copyright (C) 2005 Red Hat, Inc
*
* Evince is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Evince 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ev-password.h"
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#define EV_PASSWORD_DATA "ev-password-data"
static void
ev_password_set_bad_password_label (GtkWidget *password,
gchar *message)
{
GladeXML *xml;
GtkWidget *label;
gchar *markup;
xml = g_object_get_data (G_OBJECT (password), EV_PASSWORD_DATA);
g_assert (xml);
label = glade_xml_get_widget (xml, "bad_password_label");
markup = g_strdup_printf ("<span color=\"red\" size=\"smaller\">%s</span>",
message);
gtk_label_set_markup (GTK_LABEL (label), markup);
g_free (markup);
}
static void
ev_window_password_entry_changed_cb (GtkEditable *editable,
GtkWidget *password)
{
const char *text;
GtkWidget *button;
GladeXML *xml;
xml = g_object_get_data (G_OBJECT (password), EV_PASSWORD_DATA);
g_assert (xml);
text = gtk_entry_get_text (GTK_ENTRY (editable));
button = glade_xml_get_widget (xml, "ok_button");
if (text == NULL || *text == '\0')
gtk_widget_set_sensitive (button, FALSE);
else
gtk_widget_set_sensitive (button, TRUE);
ev_password_set_bad_password_label (password, " ");
}
GtkWidget *
ev_password_dialog_new (GtkWidget *toplevel,
const char *uri)
{
const char *glade_file = DATADIR "/evince-password.glade";
GladeXML *xml;
GtkWidget *dialog, *label;
GtkWidget *entry;
char *format;
char *markup;
xml = glade_xml_new (glade_file, NULL, NULL);
if (xml == NULL) {
dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
_("Unable to find glade file"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("The glade file, %s, cannot be found. Please check that your installation is complete."),
glade_file);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return NULL;
}
dialog = glade_xml_get_widget (xml, "password_dialog");
label = glade_xml_get_widget (xml, "password_label");
entry = glade_xml_get_widget (xml, "password_entry");
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
g_signal_connect (entry, "changed", G_CALLBACK (ev_window_password_entry_changed_cb), dialog);
format = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
_("Password required"),
_("The document <i>%s</i> is locked and requires a password before it can be opened."));
markup = g_markup_printf_escaped (format, uri);
gtk_label_set_markup (GTK_LABEL (label), markup);
g_free (format);
g_free (markup);
g_object_set_data_full (G_OBJECT (dialog), EV_PASSWORD_DATA, xml, g_object_unref);
ev_password_set_bad_password_label (dialog, " ");
return dialog;
}
char *
ev_password_dialog_get_password (GtkWidget *password)
{
GladeXML *xml;
GtkWidget *entry;
xml = g_object_get_data (G_OBJECT (password), EV_PASSWORD_DATA);
g_assert (xml);
entry = glade_xml_get_widget (xml, "password_entry");
return g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
}
void
ev_password_dialog_set_bad_pass (GtkWidget *password)
{
GladeXML *xml;
GtkWidget *entry;
xml = g_object_get_data (G_OBJECT (password), EV_PASSWORD_DATA);
g_assert (xml);
entry = glade_xml_get_widget (xml, "password_entry");
gtk_entry_set_text (GTK_ENTRY (entry), "");
ev_password_set_bad_password_label (password, _("Incorrect password"));
}
|