2 * this file is part of evince, a gnome document viewer
4 * Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
6 * Evince is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Evince is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <glib/gi18n.h>
25 #include "ev-keyring.h"
28 #include <gnome-keyring.h>
30 static const GnomeKeyringPasswordSchema doc_password_schema = {
31 GNOME_KEYRING_ITEM_GENERIC_SECRET,
33 { "type", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
34 { "uri", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
38 const GnomeKeyringPasswordSchema *EV_DOCUMENT_PASSWORD_SCHEMA = &doc_password_schema;
39 #endif /* WITH_KEYRING */
42 ev_keyring_is_available (void)
45 return gnome_keyring_is_available ();
52 ev_keyring_lookup_password (const gchar *uri)
56 GnomeKeyringResult result;
57 gchar *password = NULL;
59 g_return_val_if_fail (uri != NULL, NULL);
61 if (!gnome_keyring_is_available ())
64 result = gnome_keyring_find_password_sync (EV_DOCUMENT_PASSWORD_SCHEMA,
66 "type", "document_password",
69 if (result != GNOME_KEYRING_RESULT_OK || !password) {
71 gnome_keyring_free_password (password);
75 retval = g_strdup (password);
76 gnome_keyring_free_password (password);
77 #endif /* WITH_KEYRING */
82 ev_keyring_save_password (const gchar *uri,
83 const gchar *password,
87 GnomeKeyringResult result;
92 g_return_val_if_fail (uri != NULL, FALSE);
94 if (!gnome_keyring_is_available ())
97 if (flags == G_PASSWORD_SAVE_NEVER)
100 keyring = (flags == G_PASSWORD_SAVE_FOR_SESSION) ? "session" : NULL;
101 unescaped_uri = g_uri_unescape_string (uri, NULL);
102 name = g_strdup_printf (_("Password for document %s"), unescaped_uri);
103 g_free (unescaped_uri);
105 result = gnome_keyring_store_password_sync (EV_DOCUMENT_PASSWORD_SCHEMA,
106 keyring, name, password,
107 "type", "document_password",
112 return (result == GNOME_KEYRING_RESULT_OK);
115 #endif /* WITH_KEYRING */