From 9064f0ea9ec98090c8d571f868c3ac76bc53de4e Mon Sep 17 00:00:00 2001 From: "vit.jonas@gmail.com" Date: Thu, 2 Jun 2011 08:41:23 +0000 Subject: [PATCH] * finished Issue 65: download via Zip with national alphabet in filename git-svn-id: http://redmine-dmsf.googlecode.com/svn/trunk/redmine_dmsf@119 5e329b0b-a2ee-ea63-e329-299493fc886d --- app/controllers/dmsf_controller.rb | 2 +- app/helpers/dmsf_zip.rb | 14 +++++++++++++- app/views/settings/_dmsf_settings.erb | 9 +++++++++ config/locales/cs.yml | 2 ++ config/locales/de.yml | 2 ++ config/locales/en-GB.yml | 2 ++ config/locales/en.yml | 3 +++ config/locales/es.yml | 2 ++ config/locales/fr.yml | 2 ++ config/locales/ja.yml | 2 ++ config/locales/ru.yml | 2 ++ init.rb | 1 + 12 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index a770a125..919e40c2 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -66,7 +66,7 @@ class DmsfController < ApplicationController if selected_folders.nil? && selected_files.nil? flash[:warning] = l(:warning_no_entries_selected) - redirect_to :action => "index", :id => @project, :folder_id => @folder + redirect_to :action => "show", :id => @project, :folder_id => @folder return end diff --git a/app/helpers/dmsf_zip.rb b/app/helpers/dmsf_zip.rb index f238090b..e09e4eda 100644 --- a/app/helpers/dmsf_zip.rb +++ b/app/helpers/dmsf_zip.rb @@ -18,6 +18,7 @@ require 'zip/zip' require 'zip/zipfilesystem' +require 'iconv' class DmsfZip @@ -42,6 +43,11 @@ class DmsfZip def add_file(file) string_path = file.folder.nil? ? "" : file.folder.dmsf_path_str + "/" string_path += file.name + #TODO: somewhat ugly conversion problems handling bellow + begin + string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path) + rescue + end @zip_file.put_next_entry(string_path) File.open(file.last_revision.disk_file, "rb") do |f| buffer = "" @@ -53,7 +59,13 @@ class DmsfZip end def add_folder(folder) - @zip_file.put_next_entry(folder.dmsf_path_str + "/") + string_path = folder.dmsf_path_str + "/" + #TODO: somewhat ugly conversion problems handling bellow + begin + string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path) + rescue + end + @zip_file.put_next_entry(string_path) folder.subfolders.each { |subfolder| self.add_folder(subfolder) } folder.files.each { |file| self.add_file(file) } end diff --git a/app/views/settings/_dmsf_settings.erb b/app/views/settings/_dmsf_settings.erb index e2a4304f..fc112eda 100644 --- a/app/views/settings/_dmsf_settings.erb +++ b/app/views/settings/_dmsf_settings.erb @@ -29,6 +29,15 @@ :selected => @settings["dmsf_default_notifications"])) %>
(<%=l(:label_default)%>: <%=l(:select_option_deactivated)%>)

+ +

+ <%=content_tag(:label, l(:label_zip_names_encoding) + ":") %> + <%=text_field_tag "settings[dmsf_zip_encoding]", @settings["dmsf_zip_encoding"], :size=>50 %>
+ (<%=l(:label_default)%>: utf-8) +
+ <%= l(:note_zip_names_encoding_iconv) %> +

+

<%=content_tag(:label, l(:label_index_database) + ":") %> diff --git a/config/locales/cs.yml b/config/locales/cs.yml index ed039400..bf4c42cd 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -151,4 +151,6 @@ cs: :title_filename_for_download: "Filename used for download or in Zip archive" :label_number_of_folders: "Folders" :label_number_of_documents: "Documents" + :label_zip_names_encoding: "Zip names encoding" + :note_zip_names_encoding_iconv: "Iconv is used for charset conversion from utf-8 to target encoding" \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index ff4589f2..14023a28 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -147,4 +147,6 @@ de: :title_filename_for_download: "Filename used for download or in Zip archive" :label_number_of_folders: "Folders" :label_number_of_documents: "Documents" + :label_zip_names_encoding: "Zip names encoding" + :note_zip_names_encoding_iconv: "Iconv is used for charset conversion from utf-8 to target encoding" \ No newline at end of file diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index 683ad1b4..2c887d31 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -147,4 +147,6 @@ en-GB: :title_filename_for_download: "Filename used for download or in Zip archive" :label_number_of_folders: "Folders" :label_number_of_documents: "Documents" + :label_zip_names_encoding: "Zip names encoding" + :note_zip_names_encoding_iconv: "Iconv is used for charset conversion from utf-8 to target encoding" \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 2cb18243..a81cf429 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -151,4 +151,7 @@ en: :title_filename_for_download: "Filename used for download or in Zip archive" :label_number_of_folders: "Folders" :label_number_of_documents: "Documents" + + :label_zip_names_encoding: "Zip names encoding" + :note_zip_names_encoding_iconv: "Iconv is used for charset conversion from utf-8 to target encoding" \ No newline at end of file diff --git a/config/locales/es.yml b/config/locales/es.yml index b007b511..3e9f6bd9 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -149,4 +149,6 @@ es: :title_filename_for_download: "Filename used for download or in Zip archive" :label_number_of_folders: "Folders" :label_number_of_documents: "Documents" + :label_zip_names_encoding: "Zip names encoding" + :note_zip_names_encoding_iconv: "Iconv is used for charset conversion from utf-8 to target encoding" \ No newline at end of file diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 035ba982..4877cc2f 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -147,4 +147,6 @@ fr: :title_filename_for_download: "Filename used for download or in Zip archive" :label_number_of_folders: "Folders" :label_number_of_documents: "Documents" + :label_zip_names_encoding: "Zip names encoding" + :note_zip_names_encoding_iconv: "Iconv is used for charset conversion from utf-8 to target encoding" \ No newline at end of file diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 2cb18243..30ee464b 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -151,4 +151,6 @@ en: :title_filename_for_download: "Filename used for download or in Zip archive" :label_number_of_folders: "Folders" :label_number_of_documents: "Documents" + :label_zip_names_encoding: "Zip names encoding" + :note_zip_names_encoding_iconv: "Iconv is used for charset conversion from utf-8 to target encoding" \ No newline at end of file diff --git a/config/locales/ru.yml b/config/locales/ru.yml index c3526da6..2ae5ad13 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -147,4 +147,6 @@ ru: :title_filename_for_download: "Filename used for download or in Zip archive" :label_number_of_folders: "Folders" :label_number_of_documents: "Documents" + :label_zip_names_encoding: "Zip names encoding" + :note_zip_names_encoding_iconv: "Iconv is used for charset conversion from utf-8 to target encoding" \ No newline at end of file diff --git a/init.rb b/init.rb index 4ccac156..226214bc 100644 --- a/init.rb +++ b/init.rb @@ -40,6 +40,7 @@ Redmine::Plugin.register :redmine_dmsf do "dmsf_max_file_upload" => "0", "dmsf_max_file_download" => "0", "dmsf_storage_directory" => "#{RAILS_ROOT}/files/dmsf", + "dmsf_zip_encoding" => "utf-8", "dmsf_index_database" => "#{RAILS_ROOT}/files/dmsf_index", "dmsf_stemming_lang" => "english", "dmsf_stemming_strategy" => "STEM_NONE"