diff app/models/setting.rb @ 514:7eba09d624db live

Merge
author Chris Cannam
date Thu, 14 Jul 2011 10:50:53 +0100
parents cbce1fd3b1b7
children cbb26bc654de
line wrap: on
line diff
--- a/app/models/setting.rb	Thu Jul 14 10:46:20 2011 +0100
+++ b/app/models/setting.rb	Thu Jul 14 10:50:53 2011 +0100
@@ -1,16 +1,16 @@
-# redMine - project management software
-# Copyright (C) 2006-2007  Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 # as published by the Free Software Foundation; either version 2
 # of the License, or (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
@@ -28,12 +28,12 @@
 	'%b %d, %Y',
 	'%B %d, %Y'
     ]
-    
+
   TIME_FORMATS = [
     '%H:%M',
     '%I:%M %p'
     ]
-    
+
   ENCODINGS = %w(US-ASCII
                   windows-1250
                   windows-1251
@@ -65,6 +65,7 @@
                   UTF-16LE
                   EUC-JP
                   Shift_JIS
+                  CP932
                   GB18030
                   GBK
                   ISCII91
@@ -72,22 +73,22 @@
                   Big5
                   Big5-HKSCS
                   TIS-620)
-  
+
   cattr_accessor :available_settings
   @@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
   Redmine::Plugin.all.each do |plugin|
     next unless plugin.settings
-    @@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}    
+    @@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
   end
-  
+
   validates_uniqueness_of :name
   validates_inclusion_of :name, :in => @@available_settings.keys
-  validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }  
+  validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }
 
   # Hash used to cache setting values
   @cached_settings = {}
   @cached_cleared_on = Time.now
-  
+
   def value
     v = read_attribute(:value)
     # Unserialize serialized settings
@@ -95,18 +96,18 @@
     v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank?
     v
   end
-  
+
   def value=(v)
     v = v.to_yaml if v && @@available_settings[name] && @@available_settings[name]['serialized']
     write_attribute(:value, v.to_s)
   end
-  
+
   # Returns the value of the setting named name
   def self.[](name)
     v = @cached_settings[name]
     v ? v : (@cached_settings[name] = find_or_default(name).value)
   end
-  
+
   def self.[]=(name, v)
     setting = find_or_default(name)
     setting.value = (v ? v : "")
@@ -114,7 +115,7 @@
     setting.save
     setting.value
   end
-  
+
   # Defines getter and setter for each setting
   # Then setting values can be read using: Setting.some_setting_name
   # or set using Setting.some_setting_name = "some value"
@@ -134,16 +135,16 @@
     END_SRC
     class_eval src, __FILE__, __LINE__
   end
-  
+
   # Helper that returns an array based on per_page_options setting
   def self.per_page_options_array
     per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
   end
-  
+
   def self.openid?
     Object.const_defined?(:OpenID) && self[:openid].to_i > 0
   end
-  
+
   # Checks if settings have changed since the values were read
   # and clears the cache hash if it's the case
   # Called once per request
@@ -155,13 +156,13 @@
       logger.info "Settings cache cleared." if logger
     end
   end
-  
+
 private
   # Returns the Setting instance for the setting named name
   # (record found in database or new record with default value)
   def self.find_or_default(name)
     name = name.to_s
-    raise "There's no setting named #{name}" unless @@available_settings.has_key?(name)    
+    raise "There's no setting named #{name}" unless @@available_settings.has_key?(name)
     setting = find_by_name(name)
     setting ||= new(:name => name, :value => @@available_settings[name]['default']) if @@available_settings.has_key? name
   end