| 1 | class KeywordListWindow < Ruwin::Window
|
|---|
| 2 | caption "Keywords List"
|
|---|
| 3 |
|
|---|
| 4 | exstyle exstyle | WS_EX_TOOLWINDOW
|
|---|
| 5 |
|
|---|
| 6 | left 50
|
|---|
| 7 | top 400
|
|---|
| 8 | width 200
|
|---|
| 9 | height 200
|
|---|
| 10 |
|
|---|
| 11 | add_control ListBox::Dropdown, "type" do
|
|---|
| 12 | left 0
|
|---|
| 13 | right 0
|
|---|
| 14 | top 0
|
|---|
| 15 | bottom 0
|
|---|
| 16 |
|
|---|
| 17 | font Font.new "MS Gothic", 11
|
|---|
| 18 | end
|
|---|
| 19 |
|
|---|
| 20 | add_control EditField::Rich, "word" do
|
|---|
| 21 | left 0
|
|---|
| 22 | right 0
|
|---|
| 23 | top 18
|
|---|
| 24 | height 14
|
|---|
| 25 |
|
|---|
| 26 | font Font.new "MS Gothic", 11
|
|---|
| 27 | end
|
|---|
| 28 |
|
|---|
| 29 | ListBox "list" do
|
|---|
| 30 | left 0
|
|---|
| 31 | right 0
|
|---|
| 32 | top 32
|
|---|
| 33 | bottom 8
|
|---|
| 34 |
|
|---|
| 35 | style style | Const::ListBox::LBS_NOINTEGRALHEIGHT
|
|---|
| 36 |
|
|---|
| 37 | font Font.new "MS Gothic", 11
|
|---|
| 38 | end
|
|---|
| 39 |
|
|---|
| 40 | add_control ProgressBar, "progress" do
|
|---|
| 41 | left 0
|
|---|
| 42 | right 0
|
|---|
| 43 | height 8
|
|---|
| 44 | bottom 0
|
|---|
| 45 | end
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | def created
|
|---|
| 49 | type.push "Keywords"
|
|---|
| 50 | type.push "Hot Keywords"
|
|---|
| 51 | type.push "Following Keywords"
|
|---|
| 52 | type.push "Favorite Keywords"
|
|---|
| 53 | word.enabled = false
|
|---|
| 54 | end
|
|---|
| 55 |
|
|---|
| 56 | def type_changed
|
|---|
| 57 | if type.position == 0
|
|---|
| 58 | word.enabled = true
|
|---|
| 59 | list.clear
|
|---|
| 60 | else
|
|---|
| 61 | word.enabled = false
|
|---|
| 62 | word.clear
|
|---|
| 63 | reload
|
|---|
| 64 | end
|
|---|
| 65 | end
|
|---|
| 66 |
|
|---|
| 67 | def word_keydown key
|
|---|
| 68 | return unless key == 13
|
|---|
| 69 | reload
|
|---|
| 70 | end
|
|---|
| 71 |
|
|---|
| 72 | def list_double_click
|
|---|
| 73 | return if @loadging
|
|---|
| 74 | open_chat :keyword => NKF.nkf("-Sw", list[list.position])
|
|---|
| 75 | end
|
|---|
| 76 |
|
|---|
| 77 | def reload
|
|---|
| 78 | @loadging = true
|
|---|
| 79 | type.enabled = false
|
|---|
| 80 |
|
|---|
| 81 | list.clear
|
|---|
| 82 | list.push "Now Loading..."
|
|---|
| 83 |
|
|---|
| 84 | progress.pos = 0
|
|---|
| 85 |
|
|---|
| 86 | Thread.new do
|
|---|
| 87 | begin
|
|---|
| 88 | if type.position == 3
|
|---|
| 89 | keywords = File.readlines("favorites.txt").map{|v| {"title" => v.strip} }
|
|---|
| 90 | else
|
|---|
| 91 | path = %W{keywords/list.json?word=#{URI.encode word.string} keywords/hot.json statuses/keywords/#{$CONF["user"]["id"]}.json}[type.position]
|
|---|
| 92 | uri = URI("http://h.hatena.ne.jp/api/#{path}")
|
|---|
| 93 |
|
|---|
| 94 | data = uri.read(:content_length_proc => proc{|v| progress.max = v/1024 }, :progress_proc => proc{|v| progress.pos = v/1024 })
|
|---|
| 95 |
|
|---|
| 96 | keywords = YAML.load(data)
|
|---|
| 97 | end
|
|---|
| 98 |
|
|---|
| 99 | list.clear
|
|---|
| 100 | @loadging = false
|
|---|
| 101 |
|
|---|
| 102 | keywords.each do |keyword|
|
|---|
| 103 | list.push NKF.nkf("-Ws", keyword["title"])
|
|---|
| 104 | end
|
|---|
| 105 | rescue => e
|
|---|
| 106 | SWin::Application.messageBox e, "Keyword load Error"
|
|---|
| 107 | ensure
|
|---|
| 108 | progress.pos = 0
|
|---|
| 109 | type.enabled = true
|
|---|
| 110 | @loadging = false
|
|---|
| 111 | end
|
|---|
| 112 | end
|
|---|
| 113 | end
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | @singleton = nil
|
|---|
| 117 | def self.show
|
|---|
| 118 | @singleton = self.new unless @singleton && @singleton.alive?
|
|---|
| 119 | @singleton.top
|
|---|
| 120 | end
|
|---|
| 121 | end
|
|---|