X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-password.c;h=a191b9f131c6b91be5362b68d2a3ff80bc4b63d5;hb=5e55b6b5e74175b5638337616b84527fb8286908;hp=4dc312dfb2d3fbcd9f58d101e52fe128988722d4;hpb=e53e8a7ba14b5156d41e84d56cab85cbe195e344;p=evince.git diff --git a/shell/ev-password.c b/shell/ev-password.c index 4dc312df..a191b9f1 100644 --- a/shell/ev-password.c +++ b/shell/ev-password.c @@ -22,10 +22,15 @@ #endif #include +#include #include #include + +#ifdef WITH_KEYRING #include -#include +#else +#define gnome_keyring_is_available() FALSE +#endif #include "ev-password.h" @@ -70,26 +75,26 @@ ev_password_dialog_set_property (GObject *object, char *format; char *markup; char *base_name; - char *file_name; + GFile *file; - switch (prop_id) - { + switch (prop_id) { case PROP_URI: dialog->priv->uri = g_strdup (g_value_get_string (value)); + + file = g_file_new_for_uri (dialog->priv->uri); - file_name = gnome_vfs_format_uri_for_display (dialog->priv->uri); - base_name = g_path_get_basename (file_name); + base_name = g_file_get_basename (file); format = g_strdup_printf ("%s\n\n%s", _("Password required"), - _("The document %s is locked and requires a password before it can be opened.")); + _("The document “%s” is locked and requires a password before it can be opened.")); markup = g_markup_printf_escaped (format, base_name); gtk_label_set_markup (GTK_LABEL (dialog->priv->label), markup); g_free (base_name); - g_free (file_name); g_free (format); g_free (markup); + g_object_unref (file); ev_password_search_in_keyring (dialog, dialog->priv->uri); break; @@ -173,7 +178,7 @@ ev_password_dialog_init (EvPasswordDialog *dialog) g_signal_connect (dialog->priv->entry, "activate", G_CALLBACK (ev_password_dialog_entry_activated_cb), dialog); ev_password_set_bad_password_label (dialog, " "); - + if (!gnome_keyring_is_available ()) { gtk_widget_hide (dialog->priv->check_default); gtk_widget_hide (dialog->priv->check_session); @@ -219,12 +224,23 @@ ev_password_dialog_entry_activated_cb (GtkEntry *entry, gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); } +#ifdef WITH_KEYRING +static void +ev_password_item_created_callback (GnomeKeyringResult result, + guint32 val, + gpointer data) +{ + /* Nothing yet */ + return; +} +#endif + void ev_password_dialog_save_password (EvPasswordDialog *dialog) { +#ifdef WITH_KEYRING GnomeKeyringAttributeList *attributes; GnomeKeyringAttribute attribute; - guint32 item_id; gchar *name; gchar *unescaped_uri; @@ -240,36 +256,38 @@ ev_password_dialog_save_password (EvPasswordDialog *dialog) attribute.value.string = g_strdup (dialog->priv->uri); g_array_append_val (attributes, attribute); - unescaped_uri = gnome_vfs_unescape_string_for_display (dialog->priv->uri); + unescaped_uri = g_uri_unescape_string (dialog->priv->uri, NULL); name = g_strdup_printf (_("Password for document %s"), unescaped_uri); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->check_default))) { - gnome_keyring_item_create_sync (NULL, - GNOME_KEYRING_ITEM_GENERIC_SECRET, - name, - attributes, - ev_password_dialog_get_password (dialog), - TRUE, - &item_id); + gnome_keyring_item_create (NULL, + GNOME_KEYRING_ITEM_GENERIC_SECRET, + name, + attributes, + ev_password_dialog_get_password (dialog), + TRUE, ev_password_item_created_callback, + NULL, NULL); } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->check_session))) { - gnome_keyring_item_create_sync ("session", - GNOME_KEYRING_ITEM_GENERIC_SECRET, - name, - attributes, - ev_password_dialog_get_password (dialog), - TRUE, - &item_id); + gnome_keyring_item_create ("session", + GNOME_KEYRING_ITEM_GENERIC_SECRET, + name, + attributes, + ev_password_dialog_get_password (dialog), + TRUE, ev_password_item_created_callback, + NULL, NULL); } gnome_keyring_attribute_list_free (attributes); g_free (name); g_free (unescaped_uri); - + +#endif /* WITH_KEYRING */ return; } +#ifdef WITH_KEYRING static void ev_password_keyring_found_cb (GnomeKeyringResult result, GList *list, @@ -285,10 +303,12 @@ ev_password_keyring_found_cb (GnomeKeyringResult result, found = list->data; gtk_entry_set_text (GTK_ENTRY (dialog->priv->entry), found->secret); } +#endif /* WITH_KEYRING */ static void ev_password_search_in_keyring (EvPasswordDialog *dialog, const gchar *uri) { +#ifdef WITH_KEYRING GnomeKeyringAttributeList *attributes; GnomeKeyringAttribute attribute; @@ -310,13 +330,14 @@ ev_password_search_in_keyring (EvPasswordDialog *dialog, const gchar *uri) g_object_ref (dialog), g_object_unref); gnome_keyring_attribute_list_free (attributes); +#endif /* WITH_KEYRING */ return; } -char * +const char * ev_password_dialog_get_password (EvPasswordDialog *dialog) { - return g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry))); + return gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry)); } void