[Ultrapossum-cvs 491] projects/yubin/gui 1.1,1.2,yubin.rb

Back to archive index

Masato Taruishi taru****@users*****
2004年 9月 21日 (火) 15:07:02 JST


===================================================================
RCS file: projects/yubin/gui/yubin.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- projects/yubin/gui/yubin.rb	2004/09/21 05:08:01	1.1
+++ projects/yubin/gui/yubin.rb	2004/09/21 06:07:02	1.2
@@ -1,6 +1,7 @@
 #!/usr/bin/ruby
 
 require 'libglade2'
+require 'base64'
 
 class PostalFactory
 
@@ -10,8 +11,24 @@
   end
 
   def create( filter )
-   puts "ldapsearch -LLL -x -h #{@host} -b #{@base} #{filter}"
-   system("ldapsearch -LLL -x -h #{@host} -b #{@base} #{filter}")
+   puts "ldapsearch -LLL -x -h #{@host} -b #{@base} #{filter}" if $DEBUG
+   open("|ldapsearch -LLL -x -h #{@host} -b #{@base} #{filter}") { |io|
+     postalCode = nil
+     postalAddress = nil
+     io.each_line do |line|
+       puts line if $DEBUG
+       case line
+       when /o:: (.*)/
+         postalAddress = Base64::decode64($1)
+       when /postalCode: (.*)/
+         postalCode = $1
+       when /^$/
+         yield( postalCode, postalAddress )
+	 postalCode = postalAddress = nil
+       end
+     end
+     yield( postalCode, postalAddress ) if ! postalCode.nil?
+   }
   end
 
 end
@@ -25,6 +42,8 @@
     @widgets = widgets
     @postalfactory = postalfactory
     @list = Gtk::ListStore.new( String, String )
+    @row = {}
+    @visible = {}
     @columns = []
     Column.size.times do |i|
       @columns << Gtk::TreeViewColumn.new(Column[i], Gtk::CellRendererText.new, { :markup => i })
@@ -38,11 +57,31 @@
   def on_filterentry_changed
     key = @widgets["filterentry"].text
     if key != ""
+      visible = {}
       filter = "postalCode=#{key}*"
-      @postalfactory.create(filter)
+      @postalfactory.create(filter) do |code, addr|
+        puts "#{code}: #{addr}" if $DEBUG
+        if @row[addr].nil?
+	  @row[addr] = [ @list.append, code ]
+	end
+        visible[addr] = true
+      end
+      @row.each_key do |addr|
+        if visible[addr].nil?
+	  @list.remove( @row[addr][0] )
+          @row.delete( addr )
+	end
+      end
+      update
     end
   end
 
+  def update
+    @row.each_key do |addr|
+        @list.set_value(@row[addr][0], 0, @row[addr][1])
+        @list.set_value(@row[addr][0], 1, addr)
+    end
+  end
 
 end
 



Ultrapossum-cvs メーリングリストの案内
Back to archive index