gnome-keyring r1062 - in trunk: . pk pkix



Author: nnielsen
Date: Thu Feb 14 23:37:00 2008
New Revision: 1062
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1062&view=rev

Log:
	* pk/gkr-pk-object-storage.c:
	* pkix/gkr-pkix-parser.c:
	* pkix/gkr-pkix-parser.h:
	* pkix/gkr-pkix-types.h: Make strings more easily translateble. Fixes bug #515119

Modified:
   trunk/ChangeLog
   trunk/pk/gkr-pk-object-storage.c
   trunk/pkix/gkr-pkix-parser.c
   trunk/pkix/gkr-pkix-parser.h
   trunk/pkix/gkr-pkix-types.h

Modified: trunk/pk/gkr-pk-object-storage.c
==============================================================================
--- trunk/pk/gkr-pk-object-storage.c	(original)
+++ trunk/pk/gkr-pk-object-storage.c	Thu Feb 14 23:37:00 2008
@@ -88,6 +88,91 @@
 	object_storage_singleton = NULL;
 }
 
+static const gchar*
+prepare_ask_title (GQuark type)
+{
+	/*
+	 * Yes this is unmaintainable and stupid, but is required 
+	 * for translations to work properly.
+	 */
+	if (type == GKR_PKIX_PRIVATE_KEY)
+		return _("Unlock private key");
+	else if (type == GKR_PKIX_CERTIFICATE)
+		return _("Unlock certificate");
+	else if (type == GKR_PKIX_PUBLIC_KEY)
+		return _("Unlock public key");
+	else 
+		return _("Unlock");
+}
+
+static const gchar*
+prepare_ask_primary (GQuark type)
+{
+	/*
+	 * Yes this is unmaintainable and stupid, but is required 
+	 * for translations to work properly.
+	 */
+	if (type == GKR_PKIX_PRIVATE_KEY)
+		return _("Enter password to unlock the private key");
+	else if (type == GKR_PKIX_CERTIFICATE)
+		return _("Enter password to unlock the certificate");
+	else if (type == GKR_PKIX_PUBLIC_KEY)
+		return _("Enter password to unlock the public key");
+	else 
+		return _("Enter password to unlock");
+}
+
+static const gchar*
+prepare_ask_check (GQuark type)
+{
+	/*
+	 * Yes this is unmaintainable and stupid, but is required 
+	 * for translations to work properly.
+	 */
+	if (type == GKR_PKIX_PRIVATE_KEY)
+		return _("Automatically unlock this private key when I log in.");
+	else if (type == GKR_PKIX_CERTIFICATE)
+		return _("Automatically unlock this certificate when I log in.");
+	else if (type == GKR_PKIX_PUBLIC_KEY)
+		return _("Automatically unlock this public key when I log in.");
+	else 
+		return _("Automatically unlock this when I log in");
+}
+
+static gchar*
+prepare_ask_secondary (GQuark type, gboolean indexed, const gchar *label)
+{
+	/*
+	 * Yes this is unmaintainable and stupid, but is required 
+	 * for translations to work properly.
+	 */
+
+	/* When we've already indexed this data */
+	if (indexed) {
+
+		if (type == GKR_PKIX_PRIVATE_KEY)
+			return g_strdup_printf (_("An application wants access to the private key '%s', but it is locked"), label);
+		else if (type == GKR_PKIX_CERTIFICATE)
+			return g_strdup_printf (_("An application wants access to the certificate '%s', but it is locked"), label);
+		else if (type == GKR_PKIX_PUBLIC_KEY)
+			return g_strdup_printf (_("An application wants access to the public key '%s', but it is locked"), label);
+		else 
+			return g_strdup_printf (_("An application wants access to '%s', but it is locked"), label);
+	
+	/* Never before seen this data */ 
+	} else {
+
+		if (type == GKR_PKIX_PRIVATE_KEY)
+			return g_strdup_printf (_("The system wants to import the private key '%s', but it is locked"), label);
+		else if (type == GKR_PKIX_CERTIFICATE)
+			return g_strdup_printf (_("The system wants to import the certificate '%s', but it is locked"), label);
+		else if (type == GKR_PKIX_PUBLIC_KEY)
+			return g_strdup_printf (_("The system wants to import the public key '%s', but it is locked"), label);
+		else 
+			return g_strdup_printf (_("The system wants to import '%s', but it is locked"), label);
+	}
+}
+
 static gchar* 
 parser_ask_password (GkrPkixParser *parser, GQuark loc, gkrid unique, 
                      GQuark type, const gchar *label, guint failures,
@@ -95,10 +180,8 @@
 {
  	GkrPkObjectStoragePrivate *pv = GKR_PK_OBJECT_STORAGE_GET_PRIVATE (ctx->storage);
 	GkrAskRequest *ask;
-	gchar *title, *primary, *secondary, *check;
-	gchar *custom_label, *ret, *display_name, *stype;
+	gchar *custom_label, *ret, *display_name, *stype, *secondary;
 	const gchar *password;
-	const gchar *display_type;
 	gboolean have_indexed = FALSE;
 	
 	g_return_val_if_fail (loc == ctx->location, NULL);
@@ -147,103 +230,32 @@
 	/* TODO: Load a better label if we have one */
 	custom_label = NULL;
 	
-	/* We have no idea what kind of data it is, poor user */
-	if (!type) {
-		display_type = NULL;
-		title = g_strdup (_("Unlock"));
-		primary = g_strdup (_("Enter password to unlock"));
-		
-	/* We know the type so add that to the strings */
-	} else {
-		/* 
-		 * TRANSLATORS: 
-	 	 *  display_type will be the type of the object like 'certificate' or 'key'
-	 	 */
-		display_type = gkr_pkix_parsed_type_to_display (type);
-
-		/* 
-		 * TRANSLATORS: 
-	 	 *  display_type will be the type of the object like 'certificate' or 'key'
-	 	 */
-		title = g_strdup_printf (_("Unlock %s"), display_type);
-
-		/* 
-		 * TRANSLATORS: 
-	 	 *  display_type will be the type of the object like 'certificate' or 'key'
-	 	 */
-		primary = g_strdup_printf (_("Enter password for the %s to unlock"), display_type);
-	}
-	
 	if (custom_label != NULL)
 		label = custom_label;
 	
-	/* When we've already indexed this data */
-	if (have_indexed) {
-		if (display_type) {
-			/* 
-			 * TRANSLATORS: 
-	 		 *  display_type will be the type of the object like 'certificate' or 'key'
-		 	 *  label is replaced with the name of the locked object.
-		 	 */
-			secondary = g_strdup_printf (_("An application wants access to the %s '%s', but it is locked"), 
-			                             display_type, label);
-		} else {
-			/* 
-			 * TRANSLATORS: 
-	 		 *  label is replaced with the name of the locked object.
-		 	 */
-			secondary = g_strdup_printf (_("An application wants access to '%s', but it is locked"), label);
-		}
-			
-	/* Never before seen this data */ 
-	} else {
-		if (display_type) {
-			/* 
-			 * TRANSLATORS: 
-	 		 *  display_type will be the type of the object like 'certificate' or 'key'
-		 	 *  label is replaced with the name of the locked object.
-		 	 */
-			secondary = g_strdup_printf(_("The system wants to import the %s '%s', but it is locked."),
-			                            display_type, label);
-		} else {
-			/* 
-			 * TRANSLATORS: 
-	 		 *  label is replaced with the name of the locked object.
-		 	 */			
-			secondary = g_strdup_printf(_("The system wants to import '%s', but it is locked."), label);
-		}
-	}
-	
-	ask = gkr_ask_request_new (title, primary, GKR_ASK_REQUEST_PROMPT_PASSWORD);
-	gkr_ask_request_set_secondary (ask, secondary);
-	gkr_ask_request_set_location (ask, loc);
+	ask = gkr_ask_request_new (prepare_ask_title (type), prepare_ask_primary (type), 
+			                   GKR_ASK_REQUEST_PROMPT_PASSWORD);
 
-	g_free (title);
-	g_free (primary);
+	secondary = prepare_ask_secondary (type, have_indexed, label); 
+	gkr_ask_request_set_secondary (ask, secondary);
 	g_free (secondary);
+
+	gkr_ask_request_set_location (ask, loc);
 		
-	if (gkr_keyring_login_is_usable ()) {
-		/* 
-		 * TRANSLATORS: 
- 		 *  display_type will be the type of the object like 'certificate' or 'key'
-		 */
-		check = g_strdup_printf (_("Automatically unlock this %s when I log in."), display_type);
-		gkr_ask_request_set_check_option (ask, check);
-		g_free (check);
-	}
+	if (gkr_keyring_login_is_usable ())
+		gkr_ask_request_set_check_option (ask, prepare_ask_check (type));
 	
 	gkr_ask_daemon_process (ask);
 	
+	/* User denied or cancelled */
 	if (ask->response < GKR_ASK_RESPONSE_ALLOW) {
 		ret = NULL;
+		
+	/* Successful response */
 	} else {
 		ret = gkr_secure_strdup (ask->typed_password);
 		if (ask->checked) {
-			/* 
-			 * TRANSLATORS: 
-		 	 *  label is the name of the object to unlock.
-		 	 */
-			display_name =  g_strdup_printf (_("Unlock password for %s"), label);
+			display_name =  g_strdup_printf (_("Unlock password for '%s'"), label);
 			gkr_keyring_login_attach_secret (GNOME_KEYRING_ITEM_ENCRYPTION_KEY_PASSWORD,
 			                                 display_name, ret,
 			                                 "pk-object", gkr_location_to_string (loc), NULL);

Modified: trunk/pkix/gkr-pkix-parser.c
==============================================================================
--- trunk/pkix/gkr-pkix-parser.c	(original)
+++ trunk/pkix/gkr-pkix-parser.c	Thu Feb 14 23:37:00 2008
@@ -478,19 +478,6 @@
 	return ret;
 }
 
-const gchar*
-gkr_pkix_parsed_type_to_display (GQuark type)
-{
-	if (type == GKR_PKIX_PRIVATE_KEY)
-		return _("private key");
-	else if (type == GKR_PKIX_CERTIFICATE)
-		return _("certificate");
-	else if (type == GKR_PKIX_PUBLIC_KEY)
-		return _("public key");
-	else
-		g_return_val_if_reached ("");
-}
-
 gboolean
 gkr_pkix_parser_parse_location (GkrPkixParser *parser, GQuark loc, GError **err)
 {

Modified: trunk/pkix/gkr-pkix-parser.h
==============================================================================
--- trunk/pkix/gkr-pkix-parser.h	(original)
+++ trunk/pkix/gkr-pkix-parser.h	Thu Feb 14 23:37:00 2008
@@ -81,8 +81,6 @@
 
 GkrPkixParser*      gkr_pkix_parser_new                     (void);
 
-const gchar*        gkr_pkix_parsed_type_to_display         (GQuark type);
-
 gboolean            gkr_pkix_parser_parse                   (GkrPkixParser *parser, GQuark loc,
                                                              const guchar *data, gsize n_data, 
                                                              GError **err);

Modified: trunk/pkix/gkr-pkix-types.h
==============================================================================
--- trunk/pkix/gkr-pkix-types.h	(original)
+++ trunk/pkix/gkr-pkix-types.h	Thu Feb 14 23:37:00 2008
@@ -7,6 +7,11 @@
 	GKR_PKIX_SUCCESS = 1
 } GkrPkixResult;
 
+/* 
+ * There are switch statements that use these in various 
+ * places in the code. When adding a type, make sure
+ * to search them out and add cases for the new type.
+ */
 #define  GKR_PKIX_CERTIFICATE      (g_quark_from_static_string ("certificate"))
 #define  GKR_PKIX_PUBLIC_KEY       (g_quark_from_static_string ("public-key"))
 #define  GKR_PKIX_PRIVATE_KEY      (g_quark_from_static_string ("private-key"))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]