fantasdic r340 - in trunk: . lib/fantasdic lib/fantasdic/sources lib/fantasdic/ui



Author: mblondel
Date: Mon Aug 25 16:06:25 2008
New Revision: 340
URL: http://svn.gnome.org/viewvc/fantasdic?rev=340&view=rev

Log:
    * lib/fantasdic/file_source.rb: Renamed @hash to @config.
    * lib/fantasdic/sources/virtual_dictionary.rb: Likewise.
    * lib/fantasdic/sources/dictd_file.rb: Likewise.
    * lib/fantasdic/sources/edict_file.rb: Likewise.
    * lib/fantasdic/sources/dict_server.rb: Likewise.
    * lib/fantasdic/source_base.rb: Likewise.
    * lib/fantasdic/ui/add_dictionary_dialog.rb: Likewise.


Modified:
   trunk/ChangeLog
   trunk/lib/fantasdic/file_source.rb
   trunk/lib/fantasdic/source_base.rb
   trunk/lib/fantasdic/sources/dict_server.rb
   trunk/lib/fantasdic/sources/dictd_file.rb
   trunk/lib/fantasdic/sources/edict_file.rb
   trunk/lib/fantasdic/ui/add_dictionary_dialog.rb

Modified: trunk/lib/fantasdic/file_source.rb
==============================================================================
--- trunk/lib/fantasdic/file_source.rb	(original)
+++ trunk/lib/fantasdic/file_source.rb	Mon Aug 25 16:06:25 2008
@@ -98,14 +98,14 @@
         end
 
         def initialize_data
-            if @hash
-                if @hash[:filename]
-                    @file_chooser_button.filename = @hash[:filename]
+            if @config
+                if @config[:filename]
+                    @file_chooser_button.filename = @config[:filename]
                 end
 
                 if @encodings.length > 0
-                    if @hash[:encoding]
-                        case @hash[:encoding]
+                    if @config[:encoding]
+                        case @config[:encoding]
                             when "UTF-8"
                                 @encoding_combobox.active = 0
                             when "EUC-JP"
@@ -115,7 +115,7 @@
                 end
             end
 
-            if @encodings.length > 0 and (! hash or ! hash[:encoding])
+            if @encodings.length > 0 and (! config or ! config[:encoding])
                 @encoding_combobox.active = 0
             end
         end

Modified: trunk/lib/fantasdic/source_base.rb
==============================================================================
--- trunk/lib/fantasdic/source_base.rb	(original)
+++ trunk/lib/fantasdic/source_base.rb	Mon Aug 25 16:06:25 2008
@@ -90,9 +90,9 @@
             def_field :disable_search_all_databases, :no_databases
         end
 
-        def initialize(hash={})
-            @hash = hash
-            @max_cache = hash[:max_cache] ? hash[:max_cache] : MAX_CACHE
+        def initialize(config={})
+            @config = config
+            @max_cache = config[:max_cache] ? config[:max_cache] : MAX_CACHE
         end
 
         # Methods which should be implemented by children classes
@@ -157,10 +157,10 @@
             include GetText
             GetText.bindtextdomain(Fantasdic::TEXTDOMAIN, nil, nil, "UTF-8")
 
-            def initialize(parent_dialog, hash, on_databases_changed_block)
+            def initialize(parent_dialog, config, on_databases_changed_block)
                 super()
                 @parent_dialog
-                @hash = hash
+                @config = config
                 @on_databases_changed_block = on_databases_changed_block
                 self.spacing = 15
             end
@@ -206,7 +206,7 @@
 
         def cached_multiple_define(dbs, word)
             cache = Cache.new
-            cache.key = [ hash object_id, dbs, word]
+            cache.key = [ config object_id, dbs, word]
 
             i = self.class.cache_queue.index(cache)
             if i.nil?
@@ -221,7 +221,7 @@
 
         def cached_multiple_match(dbs, strategy, word)
             cache = Cache.new
-            cache.key = [ hash object_id, dbs, strategy, word]
+            cache.key = [ config object_id, dbs, strategy, word]
 
             i = self.class.cache_queue.index(cache)
             if i.nil?

Modified: trunk/lib/fantasdic/sources/dict_server.rb
==============================================================================
--- trunk/lib/fantasdic/sources/dict_server.rb	(original)
+++ trunk/lib/fantasdic/sources/dict_server.rb	Mon Aug 25 16:06:25 2008
@@ -223,13 +223,14 @@
             end
 
             def initialize_data
-                if @hash and @hash[:server] and @hash[:port]
-                    @server_entry.text = @hash[:server] 
-                    @port_entry.text = @hash[:port]
-                    @serv_auth_checkbutton.active = @hash[:auth]
-                    @auth_table.sensitive = @hash[:auth]
-                    @login_entry.text = @hash[:login] if @hash[:login]
-                    @password_entry.text = @hash[:password] if @hash[:password]
+                if @config and @config[:server] and @config[:port]
+                    @server_entry.text = @config[:server]
+                    @port_entry.text = @config[:port]
+                    @serv_auth_checkbutton.active = @config[:auth]
+                    @auth_table.sensitive = @config[:auth]
+                    @login_entry.text = @config[:login] if @config[:login]
+                    @password_entry.text = @config[:password] \
+                        if @config[:password]
                 else
                     @auth_table.sensitive = false
                     @server_entry.text = "dict.org"
@@ -249,21 +250,21 @@
             DICTClient.close_long_connections
             
             begin
-                if @hash[:auth]
+                if @config[:auth]
                     @dict = DICTClient.get_connection(Fantasdic::TITLE,
-                                                      @hash[:server],
-                                                      @hash[:port],
-                                                      @hash[:login],
-                                                      @hash[:password])
+                                                      @config[:server],
+                                                      @config[:port],
+                                                      @config[:login],
+                                                      @config[:password])
                 else 
                     @dict = DICTClient.get_connection(Fantasdic::TITLE,
-                                                      @hash[:server],
-                                                      @hash[:port])
+                                                      @config[:server],
+                                                      @config[:port])
                 end
             rescue DICTClient::ConnectionError, Errno::ECONNRESET => e
                 DICTClient.close_all_connections                
                 raise Source::SourceError,
-                      _("Could not connect to %s") % @hash[:server]
+                      _("Could not connect to %s") % @config[:server]
             end
         end
 
@@ -273,7 +274,7 @@
             rescue DICTClient::ConnectionLost, Errno::EPIPE
                 DICTClient.close_active_connection
                 raise Source::SourceError,
-                      _("Could not connect to %s") % @hash[:server]
+                      _("Could not connect to %s") % @config[:server]
             end
         end
 
@@ -288,7 +289,7 @@
             rescue DICTClient::ConnectionLost, Errno::EPIPE
                 DICTClient.close_active_connection
                 raise Source::SourceError,
-                      _("Could not connect to %s") % @hash[:server]
+                      _("Could not connect to %s") % @config[:server]
             end
         end
 
@@ -299,7 +300,7 @@
             rescue DICTClient::ConnectionLost, Errno::EPIPE
                 DICTClient.close_active_connection
                 raise Source::SourceError,
-                      _("Could not connect to %s") % @hash[:server]
+                      _("Could not connect to %s") % @config[:server]
             end
         end
 
@@ -322,11 +323,11 @@
         end
 
         def connecting_to_source_str
-            _("Waiting for %s...") % @hash[:server]
+            _("Waiting for %s...") % @config[:server]
         end
 
         def transferring_data_str
-            _("Transferring data from %s...") % @hash[:server]
+            _("Transferring data from %s...") % @config[:server]
         end
 
     end

Modified: trunk/lib/fantasdic/sources/dictd_file.rb
==============================================================================
--- trunk/lib/fantasdic/sources/dictd_file.rb	(original)
+++ trunk/lib/fantasdic/sources/dictd_file.rb	Mon Aug 25 16:06:25 2008
@@ -214,7 +214,7 @@
     end
 
     def define(db, word)        
-        db = File.basename(@hash[:filename]).slice(0...-6)
+        db = File.basename(@config[:filename]).slice(0...-6)
         db_capitalize = db.capitalize
 
         dictd_file_open do |index_file, dict_file|
@@ -244,7 +244,7 @@
         end
 
         hsh = {}
-        db = File.basename(@hash[:filename])
+        db = File.basename(@config[:filename])
         hsh[db] = matches unless matches.empty?
         hsh
     end
@@ -257,12 +257,12 @@
     end
 
     def dictd_file_open
-        if !File.readable? @hash[:filename]
+        if !File.readable? @config[:filename]
             raise Source::SourceError,
-                    _("Cannot open file %s.") % @hash[:filename]
+                    _("Cannot open file %s.") % @config[:filename]
         end
 
-        dict_file = @hash[:filename].gsub(/.index$/, ".dict")
+        dict_file = @config[:filename].gsub(/.index$/, ".dict")
         dict_gz_file = dict_file + ".dz"
 
         if !File.readable? dict_file and !File.readable? dict_gz_file
@@ -275,7 +275,7 @@
             "dict.dz file not implemented yet"
         end
 
-        index_file = DictdIndex.new(@hash[:filename])
+        index_file = DictdIndex.new(@config[:filename])
 
         if block_given?
             ret = yield(index_file, dict_file) 
@@ -285,7 +285,7 @@
 
             ret
         else
-            [ hash[:filename], dict_file]
+            [ config[:filename], dict_file]
         end
     end
 

Modified: trunk/lib/fantasdic/sources/edict_file.rb
==============================================================================
--- trunk/lib/fantasdic/sources/edict_file.rb	(original)
+++ trunk/lib/fantasdic/sources/edict_file.rb	Mon Aug 25 16:06:25 2008
@@ -65,8 +65,8 @@
         begin
             edict_file_open do |file|
                 file.each_line do |line|
-                    if @hash[:encoding] and @hash[:encoding] != "UTF-8"
-                        line = convert_to_utf8(@hash[:encoding], line)
+                    if @config[:encoding] and @config[:encoding] != "UTF-8"
+                        line = convert_to_utf8(@config[:encoding], line)
                     end
                     n_errors += 1 if REGEXP.match(line).nil?
                     n_lines += 1
@@ -101,7 +101,7 @@
             regexp = "^#{wesc}|\\[#{wesc}\\]|/#{wesc}/"
         end
         
-        db = File.basename(@hash[:filename])
+        db = File.basename(@config[:filename])
         db_capitalize = db.capitalize
 
         match_with_regexp(regexp).map do |line|
@@ -132,7 +132,7 @@
         end
 
         hsh = {}
-        db = File.basename(@hash[:filename])
+        db = File.basename(@config[:filename])
         hsh[db] = arr unless arr.empty?
         hsh
     end
@@ -191,19 +191,19 @@
     end
 
     def edict_file_open
-        if !File.readable? @hash[:filename]
+        if !File.readable? @config[:filename]
             raise Source::SourceError,
-                    _("Cannot open file %s.") % @hash[:filename]
+                    _("Cannot open file %s.") % @config[:filename]
         end
-        if @hash[:filename] =~ /.gz$/
+        if @config[:filename] =~ /.gz$/
             begin
-                file = Zlib::GzipReader.new(File.new(@hash[:filename]))
+                file = Zlib::GzipReader.new(File.new(@config[:filename]))
             rescue Zlib::GzipFile::Error => e
                 raise Source::SourceError,
                     _("This file is not a valid EDICT file!")
             end
         else
-            file = File.new(@hash[:filename])
+            file = File.new(@config[:filename])
         end
 
         if block_given?
@@ -250,14 +250,14 @@
     def get_command(regexp)
         cmd = []
 
-        cmd << "cat #{ hash[:filename]}"
+        cmd << "cat #{ config[:filename]}"
 
-        if @hash[:filename] =~ /.gz$/
+        if @config[:filename] =~ /.gz$/
             cmd << "gunzip -c"
         end
 
-        if @hash[:encoding] and @hash[:encoding] != "UTF-8"
-            cmd << "iconv -f #{ hash[:encoding]} -t UTF-8"
+        if @config[:encoding] and @config[:encoding] != "UTF-8"
+            cmd << "iconv -f #{ config[:encoding]} -t UTF-8"
         end
 
         cmd << "egrep \"#{regexp}\""
@@ -271,7 +271,7 @@
 class EdictFileRuby < EdictFileBase
     def initialize(*args)
         super(*args)
-        if @hash and @hash[:encoding] != "UTF-8"
+        if @config and @config[:encoding] != "UTF-8"
             # FIXME: Find a way to look up words in EUC-JP with reasonable
             # performance...
             raise Source::SourceError,

Modified: trunk/lib/fantasdic/ui/add_dictionary_dialog.rb
==============================================================================
--- trunk/lib/fantasdic/ui/add_dictionary_dialog.rb	(original)
+++ trunk/lib/fantasdic/ui/add_dictionary_dialog.rb	Mon Aug 25 16:06:25 2008
@@ -65,7 +65,7 @@
             @dialog.type_hint = Gdk::Window::TypeHint::DIALOG
             @prefs = Preferences.instance
             @dicname = dicname
-            @hash = hash
+            @config = hash
             @callback_proc = callback_proc
             initialize_ui
             initialize_signals
@@ -109,25 +109,25 @@
             # Main fields
             @name_entry.text = @dicname if @dicname
 
-            if @hash
+            if @config
                 # Font buttons
                 if HAVE_PRINT
-                    if @hash[:print_font_name]
-                        @print_fontbutton.font_name = @hash[:print_font_name]
+                    if @config[:print_font_name]
+                        @print_fontbutton.font_name = @config[:print_font_name]
                     else
                         @print_fontbutton.font_name = Print::DEFAULT_FONT.to_s
                     end
                 end
 
-                if @hash[:results_font_name]                
-                    @results_fontbutton.font_name = @hash[:results_font_name]
+                if @config[:results_font_name]
+                    @results_fontbutton.font_name = @config[:results_font_name]
                 else
                     @results_fontbutton.font_name = \
                         LinkBuffer::DEFAULT_FONT.to_s
                 end
 
                 # Selected dbs
-                if ! hash[:all_dbs]
+                if ! config[:all_dbs]
                     @sel_db_radiobutton.active = true
                 end
             end
@@ -336,10 +336,10 @@
 
             # it means we are updating an existing dictionary
             # as opposed to adding a new one
-            @update_dialog = true if @hash
+            @update_dialog = true if @config
 
-            if @hash and @hash[:source]
-                self.selected_source = @hash[:source]
+            if @config and @config[:source]
+                self.selected_source = @config[:source]
             elsif 
                 self.selected_source = Source::Base::DEFAULT_SOURCE
             end
@@ -396,15 +396,15 @@
                         row[NAME] = name
                         row[DESC] = dbs[name]
 
-                        if ! hash nil? and ! hash[:sel_dbs].nil? and \
-                            @hash[:sel_dbs].include? name
+                        if ! config nil? and ! config[:sel_dbs].nil? and \
+                            @config[:sel_dbs].include? name
                             sel_db_desc[name] = row[DESC]
                         end
                     end
 
                     # Add selected databases
-                    if ! hash nil? and ! hash[:sel_dbs].nil?
-                        @hash[:sel_dbs].each do |name|
+                    if ! config nil? and ! config[:sel_dbs].nil?
+                        @config[:sel_dbs].each do |name|
                             unless sel_db_desc[name].nil?
                                 row = @sel_db_treeview.model.append
             
@@ -412,7 +412,7 @@
                                 row[DESC] = sel_db_desc[name]
                             end
                         end
-                        unless @hash[:sel_dbs].empty? or @hash[:all_dbs]
+                        unless @config[:sel_dbs].empty? or @config[:all_dbs]
                             @sel_db_radiobutton.activate
                         end
                     else
@@ -461,7 +461,7 @@
             unless @config_widgets[src_str]
                 @config_widgets[src_str] = \
                     @src_class::ConfigWidget.new(@dialog,
-                                                 @hash,
+                                                 @config,
                                                  on_db_chgd_blk)
             end
             @last_config_widget = @config_widgets[src_str]



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