[seahorse] Fix filter on file for importer



commit 6984d33cffd20793eb7253829e9844d966441c14
Author: Stef Walter <stefw collabora co uk>
Date:   Tue Dec 13 15:19:30 2011 +0100

    Fix filter on file for importer
    
     * And remove some unused code, clean up

 libseahorse/seahorse-util.c |  218 -------------------------------------------
 libseahorse/seahorse-util.h |   20 ----
 pgp/seahorse-gpgme-photos.c |  106 +++++++++++----------
 src/seahorse-key-manager.c  |   65 ++++++++++++--
 4 files changed, 113 insertions(+), 296 deletions(-)
---
diff --git a/libseahorse/seahorse-util.c b/libseahorse/seahorse-util.c
index 88d2af1..f55e7dc 100644
--- a/libseahorse/seahorse-util.c
+++ b/libseahorse/seahorse-util.c
@@ -365,34 +365,6 @@ seahorse_util_printf_fd (int fd, const char* fmt, ...)
     return ret;
 }
 
-/** 
- * seahorse_util_uri_get_last:
- * @uri: The uri to parse
- *
- * Finds the last portion of @uri. Note that this does
- * not modify @uri. If the uri is invalid or has no 
- * directories then the entire thing is returned.
- *
- * Returns: Last portion of @uri
- **/
-const gchar* 
-seahorse_util_uri_get_last (const gchar* uri)
-{
-    const gchar* t;
-    
-    g_return_val_if_fail (uri, NULL);
-    
-    t = uri + strlen (uri);
-    
-    if (*(t - 1) == '/' && t != uri)
-        t--;
-    
-    while (*(t - 1) != '/' && t != uri)
-        t--;
-    
-    return t;
-}    
-
 GFile *
 seahorse_util_file_increment_unique (GFile *file,
                                      guint *state)
@@ -438,95 +410,6 @@ seahorse_util_file_increment_unique (GFile *file,
 }
 
 /**
- * seahorse_util_detect_mime_type:
- * @mime: The mime string
- *
- * Return the mime type depending on the mime string
- *
- * Returns: SEAHORSE_PGP, SEAHORSE_SSH or 0
- */
-GQuark
-seahorse_util_detect_mime_type (const gchar *mime)
-{
-	if (!mime || g_ascii_strcasecmp (mime, "application/octet-stream") == 0) {
-		g_warning ("couldn't get mime type for data");
-		return 0;
-	}
-
-#ifdef WITH_PGP
-	if (g_ascii_strcasecmp (mime, "application/pgp-encrypted") == 0 ||
-	    g_ascii_strcasecmp (mime, "application/pgp-keys") == 0)
-		return SEAHORSE_PGP;
-#endif
-
-#ifdef WITH_SSH 
-	/* TODO: For now all PEM keys are treated as SSH keys */
-	else if (g_ascii_strcasecmp (mime, "application/x-ssh-key") == 0 ||
-	         g_ascii_strcasecmp (mime, "application/x-pem-key") == 0)
-		return SEAHORSE_SSH;
-#endif 
-
-	g_message ("unsupported type of key data: %s", mime);
-	return 0;
-}
-
-/**
- * seahorse_util_detect_data_type:
- * @data: The buffer to test for content type
- * @length: The length of this buffer
- *
- * Returns: SEAHORSE_PGP, SEAHORSE_SSH or 0
- */
-GQuark
-seahorse_util_detect_data_type (const gchar *data, guint length)
-{
-	gboolean uncertain;
-	gchar *mime;
-	GQuark type;
-	
-	mime = g_content_type_guess (NULL, (const guchar*)data, length, &uncertain);
-	g_return_val_if_fail (mime, 0);
-	
-	type = seahorse_util_detect_mime_type (mime);
-	g_free (mime);
-	
-	return type;
-}
-
-/**
- * seahorse_util_detect_file_type:
- * @uri: The file uri to test for content type
- *
- * Returns: SEAHORSE_PGP, SEAHORSE_SSH or 0
- */
-GQuark
-seahorse_util_detect_file_type (const gchar *uri)
-{
-	const gchar *mime = NULL;
-	GQuark type;
-	GFile *file;
-	GFileInfo *info;
-
-	file = g_file_new_for_uri (uri);
-	info = g_file_query_info (file,
-                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
-                0,
-                NULL,
-                NULL);
-
-	g_return_val_if_fail (info, 0);
-
-	mime = g_file_info_get_content_type (info);
-	
-	g_return_val_if_fail (mime, 0);
-	
-	type = seahorse_util_detect_mime_type (mime);
-	g_object_unref (info);
-	
-	return type;
-}
-
-/**
  * seahorse_util_write_file_private:
  * @filename: file to write to
  * @contents: nul-terminated string to write to the file
@@ -544,107 +427,6 @@ seahorse_util_write_file_private (const gchar* filename, const gchar* contents,
 }
 
 /**
- * seahorse_util_chooser_save_new:
- * @title: The title of the dialog
- * @parent: The parent of the dialog
- *
- * Creates a file chooser dialog to save files.
- *
- * Returns: The new save dialog
- */
-GtkDialog*
-seahorse_util_chooser_save_new (const gchar *title, GtkWindow *parent)
-{
-    GtkDialog *dialog;
-    
-    dialog = GTK_DIALOG (gtk_file_chooser_dialog_new (title, 
-                parent, GTK_FILE_CHOOSER_ACTION_SAVE, 
-                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
-                NULL));
-
-    gtk_dialog_set_default_response (dialog, GTK_RESPONSE_ACCEPT);
-    gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
-    return dialog;
-}
-
-/**
- * seahorse_util_chooser_open_new:
- * @title: The title of the dialog
- * @parent: The parent of the dialog
- *
- * Creates a file chooser dialog to open files.
- *
- * Returns: The new open dialog
- */
-GtkDialog*
-seahorse_util_chooser_open_new (const gchar *title, GtkWindow *parent)
-{
-    GtkDialog *dialog;
-    
-    dialog = GTK_DIALOG (gtk_file_chooser_dialog_new (title, 
-                parent, GTK_FILE_CHOOSER_ACTION_OPEN, 
-                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
-                NULL));
-
-    gtk_dialog_set_default_response (dialog, GTK_RESPONSE_ACCEPT);
-    gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
-    return dialog;
-}
-
-/**
- * seahorse_util_chooser_show_key_files:
- * @dialog: the dialog to add the filter for
- *
- * Adds a key file filter and a "All files" filter. The key filter
- * is used.
- *
- */
-void
-seahorse_util_chooser_show_key_files (GtkDialog *dialog)
-{
-    GtkFileFilter* filter = gtk_file_filter_new ();
-    
-    /* Filter for PGP keys. We also include *.asc, as in many 
-       cases that extension is associated with text/plain */
-    gtk_file_filter_set_name (filter, _("All key files"));
-    gtk_file_filter_add_mime_type (filter, "application/pgp-keys");
-#ifdef WITH_SSH 
-    gtk_file_filter_add_mime_type (filter, "application/x-ssh-key");
-    gtk_file_filter_add_mime_type (filter, "application/x-pem-key");
-#endif
-    gtk_file_filter_add_pattern (filter, "*.asc");
-    gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);    
-    gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
-
-    filter = gtk_file_filter_new ();
-    gtk_file_filter_set_name (filter, _("All files"));
-    gtk_file_filter_add_pattern (filter, "*");    
-    gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);       
-}
-
-/**
- * seahorse_util_chooser_open_prompt:
- * @dialog: open dialog to display
- *
- * Display an open dialog
- *
- * Returns: The uri of the file to open or NULL
- */
-gchar*      
-seahorse_util_chooser_open_prompt (GtkDialog *dialog)
-{
-    gchar *uri = NULL;
-    
-    if(gtk_dialog_run (dialog) == GTK_RESPONSE_ACCEPT)
-        uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-
-    gtk_widget_destroy (GTK_WIDGET (dialog));
-    return uri;
-}
-
-/**
  * sort_objects_by_source:
  * @k1: the first seahorse object
  * @k2: The second seahorse object
diff --git a/libseahorse/seahorse-util.h b/libseahorse/seahorse-util.h
index 9310c8d..b6f1f3d 100644
--- a/libseahorse/seahorse-util.h
+++ b/libseahorse/seahorse-util.h
@@ -69,30 +69,10 @@ gboolean    seahorse_util_printf_fd         (int fd,
 GFile *     seahorse_util_file_increment_unique     (GFile *file,
                                                      guint *state);
 
-const gchar* seahorse_util_uri_get_last     (const gchar* uri);
-
-GQuark      seahorse_util_detect_mime_type   (const gchar *mime);
-
-GQuark      seahorse_util_detect_data_type   (const gchar *data,
-                                              guint length);
-
-GQuark      seahorse_util_detect_file_type   (const gchar *uri);
-
 gboolean    seahorse_util_write_file_private            (const gchar* filename,
                                                          const gchar* contents,
                                                          GError **err);
 
-GtkDialog*  seahorse_util_chooser_open_new              (const gchar *title,
-                                                         GtkWindow *parent);
-
-GtkDialog*  seahorse_util_chooser_save_new              (const gchar *title,
-                                                         GtkWindow *parent);
-
-void        seahorse_util_chooser_show_key_files        (GtkDialog *dialog);
-
-
-gchar*      seahorse_util_chooser_open_prompt           (GtkDialog *dialog);
-
 GList *     seahorse_util_objects_sort_by_place         (GList *objects);
 
 GList *     seahorse_util_objects_splice_by_place       (GList *objects);
diff --git a/pgp/seahorse-gpgme-photos.c b/pgp/seahorse-gpgme-photos.c
index aa665ec..c6215f2 100644
--- a/pgp/seahorse-gpgme-photos.c
+++ b/pgp/seahorse-gpgme-photos.c
@@ -246,62 +246,66 @@ add_image_files (GtkWidget *dialog)
 
 
 gboolean
-seahorse_gpgme_photo_add (SeahorseGpgmeKey *pkey, GtkWindow *parent, const gchar *path)
+seahorse_gpgme_photo_add (SeahorseGpgmeKey *pkey,
+                          GtkWindow *parent,
+                          const gchar *path)
 {
-    gchar *filename = NULL;
-    gchar *tempfile = NULL;
-    GError *error = NULL;
-    gpgme_error_t gerr;
-    GtkDialog *chooser;
-    gboolean res = TRUE;
-    
-    g_return_val_if_fail (SEAHORSE_IS_GPGME_KEY (pkey), FALSE);
+	gchar *filename = NULL;
+	gchar *tempfile = NULL;
+	GError *error = NULL;
+	gpgme_error_t gerr;
+	GtkWidget *chooser;
+	gboolean res = TRUE;
 
-    if (NULL == path) {
-        chooser = seahorse_util_chooser_open_new (_("Choose Photo to Add to Key"), parent);
-        gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), TRUE);
-        add_image_files (GTK_WIDGET (chooser));
+	g_return_val_if_fail (SEAHORSE_IS_GPGME_KEY (pkey), FALSE);
 
-        if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
-            filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
-	
-        gtk_widget_destroy (GTK_WIDGET (chooser));
+	if (NULL == path) {
+		chooser = gtk_file_chooser_dialog_new (_("Choose Photo to Add to Key"), parent,
+		                                      GTK_FILE_CHOOSER_ACTION_OPEN,
+		                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+		                                      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+		                                      NULL);
 
-        if (!filename)
-            return FALSE;
-    } else {
-	filename = g_strdup (path);
-    }
-    
-    if (!prepare_photo_id (parent, filename, &tempfile, &error)) {
-        if (error)
-            seahorse_util_handle_error (&error, NULL, _("Couldn't prepare photo"));
-        return FALSE;
-    }
-    
-    gerr = seahorse_gpgme_key_op_photo_add (pkey, tempfile ? tempfile : filename);
-    if (!GPG_IS_OK (gerr)) {
-        
-        /* A special error value set by seahorse_key_op_photoid_add to 
-           denote an invalid format file */
-        if (gerr == GPG_E (GPG_ERR_USER_1)) 
-            seahorse_util_show_error (NULL, _("Couldn't add photo"), 
-                                      _("The file could not be loaded. It may be in an invalid format"));
-        
-        else
-            seahorse_gpgme_handle_error (gerr, _("Couldn't add photo"));
+		gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT);
+		gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), TRUE);
+		add_image_files (chooser);
 
-        res = FALSE;
-    }
-    
-    g_free (filename);
-    
-    if (tempfile) {
-        unlink (tempfile);
-        g_free (tempfile);
-    }
-    
-    return res;
+		if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
+			filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
+
+		gtk_widget_destroy (chooser);
+
+		if (!filename)
+			return FALSE;
+	} else {
+		filename = g_strdup (path);
+	}
+
+	if (!prepare_photo_id (parent, filename, &tempfile, &error)) {
+		seahorse_util_handle_error (&error, NULL, _("Couldn't prepare photo"));
+		return FALSE;
+	}
+
+	gerr = seahorse_gpgme_key_op_photo_add (pkey, tempfile ? tempfile : filename);
+	if (!GPG_IS_OK (gerr)) {
+
+		/* A special error value set by seahorse_key_op_photoid_add to
+		   denote an invalid format file */
+		if (gerr == GPG_E (GPG_ERR_USER_1))
+			seahorse_util_show_error (NULL, _("Couldn't add photo"),
+			                          _("The file could not be loaded. It may be in an invalid format"));
+		else
+			seahorse_gpgme_handle_error (gerr, _("Couldn't add photo"));
+		res = FALSE;
+	}
+
+	g_free (filename);
+	if (tempfile) {
+		unlink (tempfile);
+		g_free (tempfile);
+	}
+
+	return res;
 }
 
 gboolean
diff --git a/src/seahorse-key-manager.c b/src/seahorse-key-manager.c
index b666e0a..fd8f938 100644
--- a/src/seahorse-key-manager.c
+++ b/src/seahorse-key-manager.c
@@ -227,17 +227,68 @@ import_files (SeahorseKeyManager* self,
 static void 
 import_prompt (SeahorseKeyManager* self) 
 {
-	GtkDialog* dialog;
+	GtkFileFilter *filter;
+	GtkWidget *dialog;
 	gchar *uris[2];
-	gchar* uri;
+	gchar *uri = NULL;
 
 	g_return_if_fail (SEAHORSE_IS_KEY_MANAGER (self));
 
-	dialog = seahorse_util_chooser_open_new (_("Import Key"), 
-	                                         seahorse_catalog_get_window (SEAHORSE_CATALOG (self)));
-	seahorse_util_chooser_show_key_files (dialog);
-	
-	uri = seahorse_util_chooser_open_prompt (dialog);
+	dialog = gtk_file_chooser_dialog_new (_("Import Key"),
+	                                      seahorse_catalog_get_window (SEAHORSE_CATALOG (self)),
+	                                      GTK_FILE_CHOOSER_ACTION_OPEN,
+	                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+	                                      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+	                                      NULL);
+
+	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
+	gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
+
+	/* TODO: This should come from libgcr somehow */
+	filter = gtk_file_filter_new ();
+	gtk_file_filter_set_name (filter, _("All key files"));
+	gtk_file_filter_add_mime_type (filter, "application/pgp-keys");
+	gtk_file_filter_add_mime_type (filter, "application/x-ssh-key");
+	gtk_file_filter_add_mime_type (filter, "application/pkcs12");
+	gtk_file_filter_add_mime_type (filter, "application/pkcs12+pem");
+	gtk_file_filter_add_mime_type (filter, "application/pkcs7-mime");
+	gtk_file_filter_add_mime_type (filter, "application/pkcs7-mime+pem");
+	gtk_file_filter_add_mime_type (filter, "application/pkcs8");
+	gtk_file_filter_add_mime_type (filter, "application/pkcs8+pem");
+	gtk_file_filter_add_mime_type (filter, "application/pkix-cert");
+	gtk_file_filter_add_mime_type (filter, "application/pkix-cert+pem");
+	gtk_file_filter_add_mime_type (filter, "application/pkix-crl");
+	gtk_file_filter_add_mime_type (filter, "application/pkix-crl+pem");
+	gtk_file_filter_add_mime_type (filter, "application/x-pem-file");
+	gtk_file_filter_add_mime_type (filter, "application/x-pem-key");
+	gtk_file_filter_add_mime_type (filter, "application/x-pkcs12");
+	gtk_file_filter_add_mime_type (filter, "application/x-pkcs7-certificates");
+	gtk_file_filter_add_mime_type (filter, "application/x-x509-ca-cert");
+	gtk_file_filter_add_mime_type (filter, "application/x-x509-user-cert");
+	gtk_file_filter_add_mime_type (filter, "application/pkcs10");
+	gtk_file_filter_add_mime_type (filter, "application/pkcs10+pem");
+	gtk_file_filter_add_mime_type (filter, "application/x-spkac");
+	gtk_file_filter_add_mime_type (filter, "application/x-spkac+base64");
+	gtk_file_filter_add_pattern (filter, "*.asc");
+	gtk_file_filter_add_pattern (filter, "*.gpg");
+	gtk_file_filter_add_pattern (filter, "*.pub");
+	gtk_file_filter_add_pattern (filter, "*.pfx");
+	gtk_file_filter_add_pattern (filter, "*.cer");
+	gtk_file_filter_add_pattern (filter, "*.crt");
+	gtk_file_filter_add_pattern (filter, "*.pem");
+	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+	gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+	filter = gtk_file_filter_new ();
+	gtk_file_filter_set_name (filter, _("All files"));
+	gtk_file_filter_add_pattern (filter, "*");
+	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+		uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+
+	gtk_widget_destroy (dialog);
+
 	if (uri != NULL) {
 		uris[0] = uri;
 		uris[1] = NULL;



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