Index: mail/ChangeLog
===================================================================
--- mail/ChangeLog	(revision 33610)
+++ mail/ChangeLog	(working copy)
@@ -1,3 +1,16 @@
+2007-05-31  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #352346
+
+	* mail-config.glade: Applying partial
+	of Matthew Barnes' patch from bug #383842. (component width)
+	Added two radiobuttons to choose if select file or directory.
+
+	* em-account-editor.c: (emae_service_provider_changed),
+	(emae_setup_service): Added support for new radiobuttons and
+	response function (emae_path_select_file_toggled) when toggled.
+	All to properly use flag CAMEL_URL_ALLOW_PATH_FILE.
+
 2007-05-31  Daniel Nylander <po@danielnylander.se>
 
 	*default/sv : Added Swedish Welcome mail. 
Index: mail/mail-config.glade
===================================================================
--- mail/mail-config.glade	(revision 33610)
+++ mail/mail-config.glade	(working copy)
@@ -1312,6 +1312,49 @@
 			      </child>
 
 			      <child>
+				<widget class="GtkRadioButton" id="source_select_file">
+				  <property name="visible">True</property>
+				  <property name="can_focus">True</property>
+				  <property name="label" translatable="yes">Select f_ile</property>
+				  <property name="use_underline">True</property>
+				  <property name="relief">GTK_RELIEF_NORMAL</property>
+				  <property name="focus_on_click">True</property>
+				  <property name="active">False</property>
+				  <property name="inconsistent">False</property>
+				  <property name="draw_indicator">True</property>
+				</widget>
+				<packing>
+				  <property name="left_attach">1</property>
+				  <property name="right_attach">2</property>
+				  <property name="top_attach">0</property>
+				  <property name="bottom_attach">1</property>
+				  <property name="y_options"></property>
+				</packing>
+			      </child>
+
+			      <child>
+				<widget class="GtkRadioButton" id="source_select_directory">
+				  <property name="visible">True</property>
+				  <property name="can_focus">True</property>
+				  <property name="label" translatable="yes">Select _directory</property>
+				  <property name="use_underline">True</property>
+				  <property name="relief">GTK_RELIEF_NORMAL</property>
+				  <property name="focus_on_click">True</property>
+				  <property name="active">False</property>
+				  <property name="inconsistent">False</property>
+				  <property name="draw_indicator">True</property>
+				  <property name="group">source_select_file</property>
+				</widget>
+				<packing>
+				  <property name="left_attach">1</property>
+				  <property name="right_attach">2</property>
+				  <property name="top_attach">1</property>
+				  <property name="bottom_attach">2</property>
+				  <property name="y_options"></property>
+				</packing>
+			      </child>
+
+			      <child>
 				<widget class="GtkLabel" id="source_path_label">
 				  <property name="visible">True</property>
 				  <property name="label" translatable="yes">_Path:</property>
@@ -1354,7 +1397,6 @@
 				  <property name="right_attach">2</property>
 				  <property name="top_attach">2</property>
 				  <property name="bottom_attach">3</property>
-				  <property name="x_options">fill</property>
 				  <property name="y_options"></property>
 				</packing>
 			      </child>
Index: mail/em-account-editor.c
===================================================================
--- mail/em-account-editor.c	(revision 33610)
+++ mail/em-account-editor.c	(working copy)
@@ -117,6 +117,8 @@
 	struct _GtkLabel *userlabel;
 	struct _GtkEntry *username;
 	struct _GtkEntry *path;
+	struct _GtkWidget *pathselectfile;
+	struct _GtkWidget *pathselectdirectory;
 	struct _GtkLabel *pathlabel;
 	struct _GtkWidget *pathentry;
 
@@ -1077,6 +1079,8 @@
 	char *username;
 	char *userlabel;
 	char *path;
+	char *pathselectfile;
+	char *pathselectdirectory;
 	char *pathlabel;
 	char *pathentry;
 
@@ -1097,7 +1101,8 @@
 } emae_service_info[CAMEL_NUM_PROVIDER_TYPES] = {
 	{ E_ACCOUNT_SOURCE_URL, E_ACCOUNT_SOURCE_SAVE_PASSWD,
 	  "source_frame", "source_type_dropdown",
-	  "source_vbox", "source_description", "source_host", "source_host_label", "source_user", "source_user_label", "source_path", "source_path_label", "source_path_entry",
+	  "source_vbox", "source_description", "source_host", "source_host_label", "source_user", "source_user_label",
+	  "source_path", "source_select_file", "source_select_directory", "source_path_label", "source_path_entry",
 	  "source_security_frame", "source_ssl_hbox", "source_use_ssl", "source_ssl_disabled",
 	  NULL, "source_auth_frame",
 	  "source_auth_dropdown", "source_check_supported",
@@ -1106,7 +1111,8 @@
 	},
 	{ E_ACCOUNT_TRANSPORT_URL, E_ACCOUNT_TRANSPORT_SAVE_PASSWD,
 	  "transport_frame", "transport_type_dropdown",
-	  "transport_vbox", "transport_description", "transport_host", "transport_host_label", "transport_user", "transport_user_label", NULL, NULL, NULL,
+	  "transport_vbox", "transport_description", "transport_host", "transport_host_label", "transport_user", "transport_user_label",
+	  NULL, NULL, NULL, NULL, NULL,
 	  "transport_security_frame", "transport_ssl_hbox", "transport_use_ssl", "transport_ssl_disabled",
 	  "transport_needs_auth", "transport_auth_frame",
 	  "transport_auth_dropdown", "transport_check_supported",
@@ -1217,6 +1223,23 @@
 	emae_service_url_path_changed(service, camel_url_set_path, widget);
 }
 
+static void
+emae_path_select_file_toggled(GtkToggleButton *togglebutton, EMAccountEditorService *service)
+{
+	if (togglebutton && GTK_WIDGET_VISIBLE (togglebutton) && service && service->pathentry) {
+		GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
+
+		if (gtk_toggle_button_get_active (togglebutton))
+			action = GTK_FILE_CHOOSER_ACTION_OPEN;
+
+		if (action != gtk_file_chooser_get_action (GTK_FILE_CHOOSER (service->pathentry))) {
+			gtk_file_chooser_set_action (GTK_FILE_CHOOSER (service->pathentry), action);
+		}
+
+		emae_path_changed (service->pathentry, service);
+	}
+}
+
 static int
 emae_ssl_update(EMAccountEditorService *service, CamelURL *url)
 {
@@ -1343,12 +1366,19 @@
 		gtk_widget_show(service->no_ssl);
 		camel_url_set_param(url, "use_ssl", NULL);
 #endif
+		if (service->pathselectfile)
+			emae_path_select_file_toggled (GTK_TOGGLE_BUTTON (service->pathselectfile), service );
 	} else {
 		camel_url_set_protocol(url, NULL);
 		gtk_label_set_text(service->description, "");
 		gtk_widget_hide(service->frame);
 		gtk_widget_hide(service->auth_frame);
 		gtk_widget_hide(service->ssl_frame);
+
+		if (service->pathentry) {
+			gtk_widget_hide (service->pathselectfile);
+			gtk_widget_hide (service->pathselectdirectory);
+		}
 	}
 
 	/* FIXME: linked services? */
@@ -1643,6 +1673,8 @@
 	service->username = GTK_ENTRY (glade_xml_get_widget (xml, info->username));
 	service->userlabel = (GtkLabel *)glade_xml_get_widget (xml, info->userlabel);
 	if (info->pathentry) {
+		service->pathselectfile = glade_xml_get_widget(xml, info->pathselectfile);
+		service->pathselectdirectory = glade_xml_get_widget(xml, info->pathselectdirectory);
 		service->pathlabel = (GtkLabel *)glade_xml_get_widget(xml, info->pathlabel);
 		service->pathentry = glade_xml_get_widget(xml, info->pathentry);
 	}
@@ -1665,9 +1697,38 @@
 	}
 	if (url->user)
 		gtk_entry_set_text(service->username, url->user);
-	if (service->pathentry && url->path)
-		gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (service->pathentry), url->path);
 
+	if (service->pathentry) {
+		GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
+		struct stat st;
+
+		if (service->provider && (service->provider->url_flags & CAMEL_URL_ALLOW_PATH_FILE) != 0) {
+			action = GTK_FILE_CHOOSER_ACTION_OPEN;
+			gtk_widget_show (service->pathselectfile);
+			gtk_widget_show (service->pathselectdirectory);
+		} else {
+			gtk_widget_hide (service->pathselectfile);
+			gtk_widget_hide (service->pathselectdirectory);
+		}
+
+		if (action != gtk_file_chooser_get_action (GTK_FILE_CHOOSER (service->pathentry)))
+			gtk_file_chooser_set_action (GTK_FILE_CHOOSER (service->pathentry), action);
+
+		if (url->path && url->path[0]=='/' && stat(url->path, &st) != -1 && S_ISREG(st.st_mode))
+			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (service->pathselectfile), TRUE);
+		else
+			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (service->pathselectdirectory), TRUE);
+
+		if (url->path)
+			gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (service->pathentry), url->path);
+	} else {
+		if (service->pathselectfile)
+			gtk_widget_hide (service->pathselectfile);
+
+		if (service->pathselectdirectory)
+			gtk_widget_hide (service->pathselectdirectory);
+	}
+
 	tmp = camel_url_get_param(url, "use_ssl");
 	if (tmp == NULL)
 		tmp = "never";
@@ -1681,8 +1742,10 @@
 
 	g_signal_connect (service->hostname, "changed", G_CALLBACK (emae_hostname_changed), service);
 	g_signal_connect (service->username, "changed", G_CALLBACK (emae_username_changed), service);
-	if (service->pathentry)
+	if (service->pathentry) {
+		g_signal_connect (service->pathselectfile, "toggled", G_CALLBACK (emae_path_select_file_toggled), service);
 		g_signal_connect (GTK_FILE_CHOOSER (service->pathentry), "selection-changed", G_CALLBACK (emae_path_changed), service);
+	}
 
 	g_signal_connect(service->use_ssl, "changed", G_CALLBACK(emae_ssl_changed), service);
 
