file-roller r2240 - in trunk: . src



Author: paobac
Date: Sun Apr 13 18:25:41 2008
New Revision: 2240
URL: http://svn.gnome.org/viewvc/file-roller?rev=2240&view=rev

Log:
2008-04-13  Paolo Bacchilega  <paobac svn gnome org>

	* src/typedefs.h: 
	* src/main.c: 
	* src/fr-archive.c: 
	* src/actions.c: 

	Disable the password entry in the save as dialog if the archive type
	doesn't support encryption.


Modified:
   trunk/ChangeLog
   trunk/src/actions.c
   trunk/src/fr-archive.c
   trunk/src/main.c
   trunk/src/typedefs.h

Modified: trunk/src/actions.c
==============================================================================
--- trunk/src/actions.c	(original)
+++ trunk/src/actions.c	Sun Apr 13 18:25:41 2008
@@ -33,13 +33,14 @@
 #include "dlg-open-with.h"
 #include "dlg-password.h"
 #include "dlg-prop.h"
-#include "main.h"
 #include "gtk-utils.h"
 #include "fr-window.h"
 #include "file-utils.h"
 #include "fr-process.h"
 #include "gconf-utils.h"
 #include "glib-utils.h"
+#include "main.h"
+#include "typedefs.h"
 
 
 typedef struct {
@@ -48,6 +49,7 @@
 	GtkWidget *file_sel;
 	GtkWidget *combo_box;
 	GtkWidget *password;
+	GtkWidget *password_label;
 } SaveAsData;
 
 
@@ -290,6 +292,31 @@
 
 
 static void
+update_password_availability_for_ext (SaveAsData *data,
+				      const char *ext)
+{
+	int i;
+	
+	if (data->password == NULL) 
+		return;
+		
+	if (ext == NULL) {
+		gtk_widget_set_sensitive (data->password, FALSE);
+		gtk_widget_set_sensitive (data->password_label, FALSE);
+		return;
+	}
+				
+	for (i = 0; file_type_desc[i].id != FR_FILE_TYPE_NULL; i++) {
+		if (strcmp (file_type_desc[i].ext, ext) == 0) {
+			gtk_widget_set_sensitive (data->password, file_type_desc[i].supports_password);
+			gtk_widget_set_sensitive (data->password_label, file_type_desc[i].supports_password);
+			break;
+		}
+	}
+}
+
+
+static void
 filetype_combobox_changed_cb (GtkComboBox *combo_box,
 			      SaveAsData  *data)
 {
@@ -300,17 +327,22 @@
 	char       *new_basename;
 	char       *new_basename_uft8;
 	
-	idx = gtk_combo_box_get_active (GTK_COMBO_BOX (data->combo_box)) - 1;
-	if (idx < 0)
-		return;
-
 	uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (data->file_sel));
 	if (uri == NULL)
 		return;
-
+	
 	ext = fr_archive_utils__get_file_name_ext (uri);
 	if (ext == NULL)
 		ext = "";
+	
+	idx = gtk_combo_box_get_active (GTK_COMBO_BOX (data->combo_box)) - 1;
+	if (idx < 0) {
+		if (data->password != NULL) {
+			gtk_widget_set_sensitive (data->password, TRUE);
+			gtk_widget_set_sensitive (data->password_label, TRUE);
+		} 
+		return;
+	}
 
 	basename = file_name_from_path (uri);
 	basename_noext = g_strndup (basename, strlen (basename) - strlen (ext));
@@ -319,7 +351,8 @@
 	new_basename = g_strconcat (basename_noext, new_ext, NULL);
 	new_basename_uft8 = g_uri_unescape_string (new_basename, NULL);
 	gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (data->file_sel), new_basename_uft8);
-
+	update_password_availability_for_ext (data, new_ext);
+	
 	g_free (new_basename_uft8);
 	g_free (new_basename);
 	g_free (basename_noext);
@@ -586,9 +619,9 @@
 
 	if (fr_window_get_archive_uri (window)) {
 		const char *uri;
-		GFile     *file;
-		GFileInfo *info;
-		GError    *err = NULL;
+		GFile      *file;
+		GFileInfo  *info;
+		GError     *err = NULL;
 
 		uri = fr_window_get_archive_uri (window);
 		file = g_file_new_for_uri (uri);
@@ -652,7 +685,7 @@
 
 	hbox = gtk_hbox_new (FALSE, 0);
 
-	label = gtk_label_new_with_mnemonic (_("_Encrypt with password:"));
+	data->password_label = label = gtk_label_new_with_mnemonic (_("_Encrypt with password:"));
 	gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
 	
 	gtk_box_pack_start (GTK_BOX (hbox), data->password, FALSE, TRUE, 0);

Modified: trunk/src/fr-archive.c
==============================================================================
--- trunk/src/fr-archive.c	(original)
+++ trunk/src/fr-archive.c	Sun Apr 13 18:25:41 2008
@@ -3254,6 +3254,9 @@
 	int n = sizeof (ext) / sizeof (char*);
 	int i;
 
+	if (filename == NULL)
+		return NULL;
+
 	for (i = n - 1; i >= 0; i--)
 		if (file_extension_is (filename, ext[i]))
 			return ext[i];

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Sun Apr 13 18:25:41 2008
@@ -62,36 +62,37 @@
 static gchar *default_url = NULL;
 
 FRFileTypeDescription file_type_desc[] = {
-	{ FR_FILE_TYPE_ACE,          ".ace",     "application/x-ace", N_("Ace (.ace)") },
-	{ FR_FILE_TYPE_AR,           ".ar",      "application/x-ar", N_("Ar (.ar)") },
-	{ FR_FILE_TYPE_ARJ,          ".arj",     "application/x-arj", N_("Arj (.arj)") },
-	{ FR_FILE_TYPE_BZIP,         ".bz",      "application/x-bzip", NULL },
-	{ FR_FILE_TYPE_BZIP2,        ".bz2",     "application/x-bzip", NULL },
-	{ FR_FILE_TYPE_COMPRESS,     ".Z",       "application/x-compress", NULL },
-	{ FR_FILE_TYPE_CPIO,         ".cpio",    "application/x-cpio", NULL },
-	{ FR_FILE_TYPE_DEB,          ".deb",     "application/x-deb", NULL },
-	{ FR_FILE_TYPE_ISO,          ".iso",     "application/x-cd-image", NULL },
-	{ FR_FILE_TYPE_EAR,          ".ear",     "application/x-ear", N_("Ear (.ear)") },
-	{ FR_FILE_TYPE_EXE,          ".exe",     "application/x-ms-dos-executable", N_("Self-extracting zip (.exe)") },
-	{ FR_FILE_TYPE_GZIP,         ".gz",      "application/x-gzip", NULL},
-	{ FR_FILE_TYPE_JAR,          ".jar",     "application/x-jar", N_("Jar (.jar)")},
-	{ FR_FILE_TYPE_LHA,          ".lzh",     "application/x-lha", N_("Lha (.lzh)") },
-	{ FR_FILE_TYPE_LZMA,         ".lzma",    "application/x-lzma", NULL },
-	{ FR_FILE_TYPE_LZOP,         ".lzo",     "application/x-lzop", NULL },
-	{ FR_FILE_TYPE_RAR,          ".rar",     "application/x-rar", N_("Rar (.rar)") },
-	{ FR_FILE_TYPE_RPM,          ".rpm",     "application/x-rpm", NULL },
-	{ FR_FILE_TYPE_TAR,          ".tar",     "application/x-tar", N_("Tar uncompressed (.tar)") },
-	{ FR_FILE_TYPE_TAR_BZ,       ".tar.bz",  "application/x-bzip-compressed-tar", N_("Tar compressed with bzip (.tar.bz)") },
-	{ FR_FILE_TYPE_TAR_BZ2,      ".tar.bz2", "application/x-bzip-compressed-tar", N_("Tar compressed with bzip2 (.tar.bz2)") },
-	{ FR_FILE_TYPE_TAR_GZ,       ".tar.gz",  "application/x-compressed-tar", N_("Tar compressed with gzip (.tar.gz)") },
-	{ FR_FILE_TYPE_TAR_LZMA,     ".tar.lzma","application/x-lzma-compressed-tar", N_("Tar compressed with lzma (.tar.lzma)") },
-	{ FR_FILE_TYPE_TAR_LZOP,     ".tar.lzo", "application/x-lzop-compressed-tar", N_("Tar compressed with lzop (.tar.lzo)") },
-	{ FR_FILE_TYPE_TAR_COMPRESS, ".tar.Z",   "application/x-compressed-tar", N_("Tar compressed with compress (.tar.Z)") },
-	{ FR_FILE_TYPE_STUFFIT,      ".sit",     "application/x-stuffit", NULL },
-	{ FR_FILE_TYPE_WAR,          ".war",     "application/zip", N_("War (.war)") },
-	{ FR_FILE_TYPE_ZIP,          ".zip",     "application/zip", N_("Zip (.zip)") },
-	{ FR_FILE_TYPE_ZOO,          ".zoo",     "application/x-zoo", N_("Zoo (.zoo)") },
-	{ FR_FILE_TYPE_7ZIP,         ".7z",      "application/x-7z-compressed", N_("7-Zip (.7z)") }
+	{ FR_FILE_TYPE_ACE,          ".ace",     "application/x-ace", N_("Ace (.ace)"), FALSE },
+	{ FR_FILE_TYPE_AR,           ".ar",      "application/x-ar", N_("Ar (.ar)"), FALSE },
+	{ FR_FILE_TYPE_ARJ,          ".arj",     "application/x-arj", N_("Arj (.arj)"), TRUE },
+	{ FR_FILE_TYPE_BZIP,         ".bz",      "application/x-bzip", NULL, FALSE },
+	{ FR_FILE_TYPE_BZIP2,        ".bz2",     "application/x-bzip", NULL, FALSE },
+	{ FR_FILE_TYPE_COMPRESS,     ".Z",       "application/x-compress", NULL, FALSE },
+	{ FR_FILE_TYPE_CPIO,         ".cpio",    "application/x-cpio", NULL, FALSE },
+	{ FR_FILE_TYPE_DEB,          ".deb",     "application/x-deb", NULL, FALSE },
+	{ FR_FILE_TYPE_ISO,          ".iso",     "application/x-cd-image", NULL, FALSE },
+	{ FR_FILE_TYPE_EAR,          ".ear",     "application/x-ear", N_("Ear (.ear)"), TRUE },
+	{ FR_FILE_TYPE_EXE,          ".exe",     "application/x-ms-dos-executable", N_("Self-extracting zip (.exe)"), FALSE },
+	{ FR_FILE_TYPE_GZIP,         ".gz",      "application/x-gzip", NULL, FALSE },
+	{ FR_FILE_TYPE_JAR,          ".jar",     "application/x-jar", N_("Jar (.jar)"), TRUE },
+	{ FR_FILE_TYPE_LHA,          ".lzh",     "application/x-lha", N_("Lha (.lzh)"), FALSE },
+	{ FR_FILE_TYPE_LZMA,         ".lzma",    "application/x-lzma", NULL, FALSE },
+	{ FR_FILE_TYPE_LZOP,         ".lzo",     "application/x-lzop", NULL, FALSE },
+	{ FR_FILE_TYPE_RAR,          ".rar",     "application/x-rar", N_("Rar (.rar)"), TRUE },
+	{ FR_FILE_TYPE_RPM,          ".rpm",     "application/x-rpm", NULL, FALSE },
+	{ FR_FILE_TYPE_TAR,          ".tar",     "application/x-tar", N_("Tar uncompressed (.tar)"), FALSE },
+	{ FR_FILE_TYPE_TAR_BZ,       ".tar.bz",  "application/x-bzip-compressed-tar", N_("Tar compressed with bzip (.tar.bz)"), FALSE },
+	{ FR_FILE_TYPE_TAR_BZ2,      ".tar.bz2", "application/x-bzip-compressed-tar", N_("Tar compressed with bzip2 (.tar.bz2)"), FALSE },
+	{ FR_FILE_TYPE_TAR_GZ,       ".tar.gz",  "application/x-compressed-tar", N_("Tar compressed with gzip (.tar.gz)"), FALSE },
+	{ FR_FILE_TYPE_TAR_LZMA,     ".tar.lzma","application/x-lzma-compressed-tar", N_("Tar compressed with lzma (.tar.lzma)"), FALSE },
+	{ FR_FILE_TYPE_TAR_LZOP,     ".tar.lzo", "application/x-lzop-compressed-tar", N_("Tar compressed with lzop (.tar.lzo)"), FALSE },
+	{ FR_FILE_TYPE_TAR_COMPRESS, ".tar.Z",   "application/x-compressed-tar", N_("Tar compressed with compress (.tar.Z)"), FALSE },
+	{ FR_FILE_TYPE_STUFFIT,      ".sit",     "application/x-stuffit", NULL, FALSE },
+	{ FR_FILE_TYPE_WAR,          ".war",     "application/zip", N_("War (.war)"), TRUE },
+	{ FR_FILE_TYPE_ZIP,          ".zip",     "application/zip", N_("Zip (.zip)"), TRUE },
+	{ FR_FILE_TYPE_ZOO,          ".zoo",     "application/x-zoo", N_("Zoo (.zoo)"), FALSE },
+	{ FR_FILE_TYPE_7ZIP,         ".7z",      "application/x-7z-compressed", N_("7-Zip (.7z)"), TRUE },
+	{ FR_FILE_TYPE_NULL, NULL, NULL, NULL, FALSE }
 };
 
 

Modified: trunk/src/typedefs.h
==============================================================================
--- trunk/src/typedefs.h	(original)
+++ trunk/src/typedefs.h	Sun Apr 13 18:25:41 2008
@@ -118,6 +118,7 @@
 	char       *ext;
 	char       *mime_type;
 	char       *name;
+	gboolean    supports_password;
 } FRFileTypeDescription;
 
 typedef struct {



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