kentaroi-okayu 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,26 @@
1
1
  = okayu
2
2
 
3
- Description goes here.
3
+ okayu = おかゆ は、ニコニコ生放送用のシンプルなコメントビューアです。
4
+
5
+ == Download
6
+ Github: http://github.com/kentaroi/okayu/tree/master
7
+
8
+ == Installing
9
+ Linux:
10
+ # Install packagies for sqlite3
11
+ # if you use Debian:
12
+ sudo aptitude install sqlite3 libsqlite3-dev libsqlite3-ruby1.8
13
+
14
+ # Install the gem
15
+ sudo gem install kentaroi-okayu --source http://gems.github.com
16
+
17
+ Windows:
18
+ http://www.sqlite.org/download.html
19
+ 上記サイトから、SQLiteのDLLをダウンロード
20
+
21
+ # Install the gem
22
+ gem install kentaroi-okayu --source http://gems.github.com
23
+
4
24
 
5
25
  == Note on Patches/Pull Requests
6
26
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/bin/okayu CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
3
4
  require 'okayu.rb'
4
5
 
5
6
  okayu = Okayu::App.new
data/lib/app.rb CHANGED
@@ -18,8 +18,8 @@ module Okayu
18
18
  unless @teardowned
19
19
  UserInfo.save
20
20
  @teardowned = true
21
- puts "teardown!!"
22
21
  end
22
+ super
23
23
  end
24
24
  end
25
25
  end
data/lib/app_dir.rb CHANGED
@@ -2,6 +2,9 @@ require 'rubygems'
2
2
  require 'facter'
3
3
 
4
4
  module Okayu
5
+ # for some windows environment
6
+ ENV['HOME'] = ENV['HOMEPATH'].gsub(/\\/, '/') unless ENV['HOME']
7
+
5
8
  class AppDir
6
9
  if Facter.value(:kernel) == 'Linux'
7
10
  if File.exist?(@@app_dir = ENV['HOME'] + '/.okayu')
data/lib/client.rb CHANGED
@@ -4,7 +4,6 @@ require 'mechanize'
4
4
  require 'thread'
5
5
  require 'player_status.rb'
6
6
  require 'thread_info.rb'
7
- require 'ruby-debug'
8
7
 
9
8
  class WWW::Mechanize::CookieJar
10
9
  def load_cookie cookie
@@ -28,6 +27,7 @@ module Okayu
28
27
  PLAYER_STATUS_URL = 'http://live.nicovideo.jp/api/getplayerstatus?v='
29
28
  @@channels = []
30
29
  @@connected = false
30
+ @@agent = WWW::Mechanize.new
31
31
 
32
32
  class << self
33
33
  def channels
@@ -42,7 +42,6 @@ module Okayu
42
42
  end
43
43
 
44
44
  def connect auth={}
45
- @@agent = WWW::Mechanize.new
46
45
  begin
47
46
  if auth[:mail] && auth[:password]
48
47
  @@login_page = @@agent.post(LOGIN_URL, 'mail' => auth[:mail], 'password' => auth[:password])
@@ -176,15 +175,15 @@ module Okayu
176
175
  hash[:number] = reader.attribute('no')
177
176
  hash[:user_id] = reader.attribute('user_id')
178
177
  case reader.attribute('premium')
179
- when 1
178
+ when '1'
180
179
  hash[:premium] = true
181
180
  hash[:owner] = false
182
181
  hash[:command] = false
183
- when 2
182
+ when '2'
184
183
  hash[:premium] = true
185
184
  hash[:owner] = true
186
185
  hash[:command] = true
187
- when 3
186
+ when '3'
188
187
  hash[:premium] = true
189
188
  hash[:owner] = true
190
189
  hash[:command] = false
data/lib/controllers.rb CHANGED
@@ -1,3 +1 @@
1
1
  require 'controllers/live_controller.rb'
2
- require 'controllers/listeners_controller.rb'
3
- require 'controllers/visitors_controller.rb'
@@ -4,24 +4,24 @@ module Okayu
4
4
  @live_id = live_id
5
5
  if @client = Client.open(live_id)
6
6
  @live_now = true
7
- if @live = Live.find(:first, :conditions => {:live_id => @live_id})
8
- @community = @live.community
7
+ if @program = Program.find(:first, :conditions => {:live_id => @live_id})
8
+ @community = @program.community
9
9
  else
10
- @live = Live.new
11
- @live.live_id = @live_id
12
- @live.base_time = @client.base_time
10
+ @program = Program.new
11
+ @program.live_id = @live_id
12
+ @program.base_time = @client.base_time
13
13
  unless @community = Community.find(:first, :conditions => {:community_id => @client.community})
14
14
  @community = Community.new
15
15
  @community.community_id = @client.community
16
16
  @community.save
17
17
  end
18
- @live.community = @community
19
- @live.save
18
+ @program.community = @community
19
+ @program.save
20
20
  end
21
21
  else
22
22
  @live_now = false
23
- if @live = Live.find(:first, :conditions => {:live_id => @live_id})
24
- @community = @live.community
23
+ if @program = Program.find(:first, :conditions => {:live_id => @live_id})
24
+ @community = @program.community
25
25
  else
26
26
  @community = nil
27
27
  end
@@ -29,7 +29,7 @@ module Okayu
29
29
  end
30
30
 
31
31
  def valid?
32
- !!@live
32
+ !!@program
33
33
  end
34
34
 
35
35
  def live_now?
@@ -38,22 +38,30 @@ module Okayu
38
38
 
39
39
 
40
40
  def base_time
41
- @live.base_time
41
+ @program.base_time
42
42
  end
43
43
 
44
44
  def comments
45
- @live.comments
45
+ @program.comments
46
+ end
47
+
48
+ def reload_comments
49
+ @program.comments.reload
50
+ end
51
+
52
+ def comment number
53
+ @program.comments.reload.find :first, :conditions => {:number => number}
46
54
  end
47
55
 
48
56
  def new_comments
49
57
  if @live_now
50
58
  @client.comments.map{|comment_hash|
51
- if Comment.find :first, :conditions => {:live_id => @live_id, :number => comment_hash[:number]}
59
+ if Comment.find :first, :conditions => {:program_id => @program.id, :number => comment_hash[:number]}
52
60
  nil
53
61
  else
54
62
  comment = Comment.new(comment_hash)
55
63
  comment.community = @community
56
- comment.live = @live
64
+ comment.program = @program
57
65
  if comment_hash[:user_id]
58
66
  if visitor = Visitor.find(:first, :conditions => {:user_id => comment_hash[:user_id]})
59
67
  comment.visitor = visitor
data/lib/cookie_thief.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'fileutils'
1
2
  require 'rubygems'
2
3
  require 'sqlite3'
3
4
 
@@ -9,12 +10,17 @@ module Okayu
9
10
  end
10
11
 
11
12
  def send_query sql
12
- db = SQLite3::Database.new(cookies_filename)
13
- cookie_array = db.execute(sql).first
14
- db.close
13
+ cookie_array = []
14
+
15
+ do_on_tmpfile(cookies_filename) do |tmpfile|
16
+ db = SQLite3::Database.new(tmpfile)
17
+ cookie_array = db.execute(sql).first
18
+ db.close
19
+ end
20
+
15
21
  cookie_array
16
22
  end
17
-
23
+
18
24
  def cookiestxt_from_array cookie_array
19
25
  if cookie_array
20
26
  cookie_array[1] = 'TRUE'
@@ -22,6 +28,13 @@ module Okayu
22
28
  cookie_array.join("\t") + "\n"
23
29
  end
24
30
  end
31
+
32
+ def do_on_tmpfile filename
33
+ tmpfile = "#{AppDir}/tmpfile"
34
+ FileUtils.cp(cookies_filename, tmpfile)
35
+ yield tmpfile
36
+ File.unlink "#{AppDir}/tmpfile"
37
+ end
25
38
  end
26
39
  end
27
40
 
@@ -71,10 +84,18 @@ module Okayu
71
84
  cookie_filename = []
72
85
  case Facter.value(:kernel)
73
86
  when 'windows'
74
- cookie_filenames = Dir.glob("#{ENV['HOME']}/AppData/Roaming/Microsoft/Windows/Cookies/Low/*").select{|path| path =~ /#{host_main_str(host)}/}
87
+ if Facter.value(:operatingsystemrelease).to_i < 6 # before Vista
88
+ unless cookie_filenames = Dir.glob("#{ENV['HOME']}/Application Data/Microsoft/Windows/Cookies/Low/*").select{|path| path =~ /#{host_main_str(host)}/}
89
+ cookie_filenames = Dir.glob("#{ENV['HOME']}/../Administrator/Application Data/Microsoft/Windows/Cookies/Low/*").select{|path| path =~ /#{host_main_str(host)}/}
90
+
91
+ end
92
+ else # from Vista
93
+ cookie_filenames = Dir.glob("#{ENV['HOME']}/AppData/Roaming/Microsoft/Windows/Cookies/Low/*").select{|path| path =~ /#{host_main_str(host)}/}
94
+ end
75
95
  end
76
96
  cookie_filenames
77
97
  end
98
+
78
99
  def host_main_str host
79
100
  host_main_str = host.sub(/^\./, '').sub(/\..*$/, '')
80
101
  end
@@ -1,6 +1,6 @@
1
- class CreateLives < ActiveRecord::Migration
1
+ class CreatePrograms < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :lives do |t|
3
+ create_table :programs do |t|
4
4
  t.string :live_id, :default => '', :null => false
5
5
  t.datetime :base_time, :default => 0, :null => false
6
6
  t.text :title
@@ -9,6 +9,6 @@ class CreateLives < ActiveRecord::Migration
9
9
  end
10
10
 
11
11
  def self.down
12
- drop_table :lives
12
+ drop_table :programs
13
13
  end
14
14
  end
@@ -10,8 +10,7 @@ class CreateComments < ActiveRecord::Migration
10
10
  t.boolean :command, :default => false, :null => false
11
11
  t.boolean :ng, :default => false, :null => false
12
12
  t.string :ngword, :default => nil
13
- t.references :live, :visitor, :default => 0, :null => false
14
- t.references :listener
13
+ t.references :program, :visitor, :default => 0, :null => false
15
14
  end
16
15
  end
17
16
 
@@ -0,0 +1,12 @@
1
+ class CreateListenersPrograms < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :listeners_programs, :id => false do |t|
4
+ t.references :listener, :program, :default => 0, :null => false
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :listeners_programs
10
+ end
11
+ end
12
+
@@ -0,0 +1,13 @@
1
+ class CreateProgramsVisitors < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :programs_visitors, :id => false do |t|
4
+ t.references :program, :visitor, :default => 0, :null => false
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :programs_visitors
10
+ end
11
+ end
12
+
13
+
data/lib/models.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'active_record'
3
3
 
4
4
  require 'models/community.rb'
5
- require 'models/live.rb'
5
+ require 'models/program.rb'
6
6
  require 'models/listener.rb'
7
7
  require 'models/visitor.rb'
8
8
  require 'models/comment.rb'
@@ -1,22 +1,7 @@
1
- require 'nokogiri'
2
-
3
1
  class Comment < ActiveRecord::Base
4
2
  belongs_to :community
5
- belongs_to :live
6
- belongs_to :listener
3
+ belongs_to :program
7
4
  belongs_to :visitor
8
5
 
9
6
  attr_accessor :user_id
10
- def load_from_xml chat_xml
11
- reader = Nokogiri::XML::Reader(chat_xml)
12
- reader.read
13
- if reader.name == 'chat'
14
- self.commented_at = reader.attribute('date').to_i
15
- self.command = reader.attribute('mail') || ''
16
- self.number = reader.attribute('no')
17
- @user_id = reader.attribute('user_id')
18
- reader.read
19
- self.message = reader.value
20
- end
21
- end
22
7
  end
@@ -1,3 +1,3 @@
1
1
  class Community < ActiveRecord::Base
2
- has_many :lives
2
+ has_many :programs
3
3
  end
@@ -1,5 +1,4 @@
1
1
  class Listener < ActiveRecord::Base
2
2
  has_many :visitors
3
- has_and_belongs_to_many :lives
4
- has_many :comments
3
+ has_and_belongs_to_many :programs
5
4
  end
@@ -1,4 +1,4 @@
1
- class Live < ActiveRecord::Base
1
+ class Program < ActiveRecord::Base
2
2
  belongs_to :community
3
3
  has_and_belongs_to_many :listners
4
4
  has_and_belongs_to_many :visitors
@@ -1,5 +1,5 @@
1
1
  class Visitor < ActiveRecord::Base
2
2
  belongs_to :listener
3
- has_and_belongs_to_many :lives
3
+ has_and_belongs_to_many :programs
4
4
  has_many :comments
5
5
  end
data/lib/user_info.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'yaml'
2
2
  require 'rubygems'
3
- require 'ruby-debug'
4
3
 
5
4
 
6
5
  module Okayu
@@ -36,6 +36,9 @@ module Okayu
36
36
 
37
37
  set_menu_bar(menu_bar)
38
38
 
39
+ @status_bar = Wx::StatusBar.new(self, Wx::ID_ANY)
40
+ set_status_bar(@status_bar)
41
+
39
42
  rect = get_client_rect
40
43
  @panel = MainPanel.new(self, rect.x, rect.y, rect.width, rect.height)
41
44
 
@@ -64,6 +67,9 @@ module Okayu
64
67
  def on_connect
65
68
  login_dialog = LoginDialog.new(self)
66
69
  login_dialog.show_modal
70
+ if Client.connected?
71
+ @status_bar.set_status_text '接続してるかも'
72
+ end
67
73
  end
68
74
 
69
75
  def on_move event
@@ -1,6 +1,17 @@
1
+ module Wx
2
+ class ListItem
3
+ def color color_data
4
+ set_background_colour(color_data[:color])
5
+ if color_data[:white_text]
6
+ set_text_colour(Wx::WHITE)
7
+ end
8
+ end
9
+ end
10
+ end
11
+
1
12
  module Okayu
2
- COLORIZE = 300
3
- NAME = 301
13
+ DYE = 300
14
+ NAME = 301
4
15
 
5
16
  class LiveListCtrl < Wx::ListCtrl
6
17
  COLUMNS = { :no => 0,
@@ -29,9 +40,10 @@ module Okayu
29
40
 
30
41
  evt_list_item_right_click(get_id) {|event| on_list_item_right_click(event)}
31
42
  evt_list_item_activated(Wx::ID_ANY) {|event| on_activated(event)}
43
+ evt_list_item_selected(Wx::ID_ANY) {|event| on_selected(event)}
32
44
  evt_key_down(){|event| get_parent.on_key_down(event)}
33
45
 
34
- evt_menu(COLORIZE){show_color_dialog}
46
+ evt_menu(DYE){show_color_dialog}
35
47
  evt_menu(NAME){show_name_dialog}
36
48
  end
37
49
 
@@ -50,12 +62,23 @@ module Okayu
50
62
  def insert_comment comment
51
63
  item = Wx::ListItem.new
52
64
  item.set_data({:id => comment.id,
65
+ :message => comment.message,
53
66
  :visitor_id => comment.visitor_id,
54
- :listener_id => comment.listener_id})
67
+ :listener_id => comment.visitor.listener_id})
55
68
  item.set_id 0
56
69
  item.set_column COLUMNS[:no]
57
70
  item.set_text comment.number.to_s
58
- # item.set_text_colour Wx::GREEN
71
+
72
+ if comment.visitor.listener
73
+ if color_index = comment.visitor.listener.color_index
74
+ item.color COLORS[color_index]
75
+ end
76
+ elsif comment.visitor
77
+ if color_index = comment.visitor.color_index
78
+ item.color COLORS[color_index]
79
+ end
80
+ end
81
+
59
82
  insert_item(item)
60
83
 
61
84
  item.set_column COLUMNS[:message]
@@ -70,9 +93,9 @@ module Okayu
70
93
  item.set_text Time.at(comment.commented_at - @base_time).strftime("%M:%S")
71
94
  set_item(item)
72
95
 
73
- if comment.listener
96
+ if comment.visitor.listener
74
97
  item.set_column COLUMNS[:name]
75
- item.set_text comment.listener.name
98
+ item.set_text comment.visitor.listener.name
76
99
  set_item(item)
77
100
  end
78
101
 
@@ -92,16 +115,50 @@ module Okayu
92
115
  end
93
116
  set_item(item)
94
117
 
95
- if comment.listener
96
- if color_index = comment.listener.color_index
97
- set_color_to_an_item(0, COLORS[color_index])
98
- end
99
- elsif comment.visitor
100
- if color_index = comment.visitor.color_index
101
- set_color_to_an_item(0, COLORS[color_index])
102
- end
118
+ end
119
+
120
+ def rewrite_item item_index
121
+ item = get_item(item_index)
122
+ comment = Comment.find item.get_data[:id]
123
+
124
+ item.set_id 0
125
+ item.set_column COLUMNS[:no]
126
+ item.set_text comment.number.to_s
127
+ set_item(item)
128
+
129
+ item.set_column COLUMNS[:message]
130
+ item.set_text comment.message
131
+ set_item(item)
132
+
133
+ item.set_column COLUMNS[:mail]
134
+ item.set_text comment.mail
135
+ set_item(item)
136
+
137
+ item.set_column COLUMNS[:time]
138
+ item.set_text Time.at(comment.commented_at - @base_time).strftime("%M:%S")
139
+ set_item(item)
140
+
141
+ if comment.visitor.listener
142
+ item.set_column COLUMNS[:name]
143
+ item.set_text comment.visitor.listener.name
144
+ set_item(item)
103
145
  end
104
146
 
147
+ item.set_column COLUMNS[:id]
148
+ item.set_text comment.user_id || comment.visitor.user_id
149
+ set_item(item)
150
+
151
+ item.set_column COLUMNS[:premium]
152
+ if comment.owner
153
+ item.set_text '主'
154
+ elsif comment.premium
155
+ item.set_text 'P'
156
+ elsif comment.command
157
+ item.set_text 'System'
158
+ else
159
+ item.set_text ''
160
+ end
161
+ set_item(item)
105
162
  end
106
163
 
107
164
  def on_column_resized event
@@ -123,8 +180,9 @@ module Okayu
123
180
  end
124
181
 
125
182
  def on_list_item_right_click event
183
+ @selected_item_text = get_item_text(event.get_index) # code for windows
126
184
  menu = Wx::Menu.new
127
- menu.append(COLORIZE, "色をつける(&C)", "")
185
+ menu.append(DYE, "色をつける(&C)", "")
128
186
  menu.append(NAME, "名前をつける(&M)", "")
129
187
  popup_menu(menu, event.get_point)
130
188
  end
@@ -132,22 +190,30 @@ module Okayu
132
190
  def show_color_dialog
133
191
  dialog = ColorDialog.new(self)
134
192
  color_index = dialog.show_modal
135
- item_index = get_selections.first
193
+ item_index = get_selections.first # get_selections won't work in windows
194
+ item_index = find_item(-1, @selected_item_text) unless item_index # code for windows
136
195
  if color_index >= 0 && color_index < COLORS.length
137
196
  on_color_set item_index, color_index
138
197
  end
139
198
  end
140
199
 
141
200
  def show_name_dialog
142
- dialog = Wx::TextEntryDialog.new(self, "名前を入力してください")
201
+ message = get_message(@selected_index)
202
+ message =~ /(@|@)(.*)/
203
+ default_name = $2 || ''
204
+ dialog = Wx::TextEntryDialog.new(self, "名前を入力してください", "名前の設定", default_name)
143
205
  dialog.show_modal
144
- item_index = get_selections.first
206
+ item_index = get_selections.first # get_selections won't work in windows
207
+ item_index = find_item(-1, @selected_item_text) unless item_index # code for windows
208
+ if (name = dialog.get_value) != ''
209
+ on_name_set(item_index, name)
210
+ else
211
+ on_name_unset(item_index, name)
212
+ end
213
+ end
145
214
 
146
- item = get_item(item_index)
147
- item.set_text_colour(COLORS[WHITE][:color])
148
- item.set_column COLUMNS[:name]
149
- item.set_text(dialog.get_value)
150
- set_item(item)
215
+ def get_message index
216
+ get_item_data(index)[:message]
151
217
  end
152
218
 
153
219
  def is_colored? index
@@ -156,30 +222,46 @@ module Okayu
156
222
  end
157
223
 
158
224
  def on_activated event
159
- item_index = event.get_index
160
- if is_colored?(item_index)
161
- on_color_unset item_index
225
+ @selected_index = event.get_index
226
+ if is_colored?(@selected_index)
227
+ on_color_unset @selected_index
162
228
  else
163
- on_color_set item_index
229
+ on_color_set @selected_index
164
230
  end
165
231
  end
166
232
 
233
+ def on_selected event
234
+ @selected_index = event.get_index
235
+ end
236
+
237
+ def same_text_color? a, b
238
+ COLORS[a||WHITE][:white_text] == COLORS[b||WHITE][:white_text]
239
+ end
240
+
167
241
  def on_color_set index, color_index=nil
168
242
  color_index = rand(COLORS.length) unless color_index
169
243
  data = get_item_data(index)
170
244
  return unless data
171
245
 
172
246
  if data[:listener_id]
173
- set_color({:listener_id => data[:listener_id]}, COLORS[color_index])
174
- unless ListenersController.set_color_index :id => data[:listener_id],
175
- :color_index => color_index
176
- Wx::message_box('色設定の保存に失敗しました')
177
- end
247
+ listener = Listener.find(data[:listener_id])
248
+ same_text_color = same_text_color?(listener.color_index, color_index)
249
+ listener.color_index = color_index
250
+ listener.save
251
+ if same_text_color
252
+ set_color({:listener_id => data[:listener_id]}, COLORS[color_index])
253
+ else
254
+ redraw
255
+ end
178
256
  else
179
- set_color({:visitor_id => data[:visitor_id]}, COLORS[color_index])
180
- unless VisitorsController.set_color_index :id => data[:visitor_id],
181
- :color_index => color_index
182
- Wx::message_box('色設定の保存に失敗しました')
257
+ visitor = Visitor.find(data[:visitor_id])
258
+ same_text_color = same_text_color?(visitor.color_index, color_index)
259
+ visitor.color_index = color_index
260
+ visitor.save
261
+ if same_text_color
262
+ set_color({:visitor_id => data[:visitor_id]}, COLORS[color_index])
263
+ else
264
+ redraw
183
265
  end
184
266
  end
185
267
  end
@@ -189,14 +271,24 @@ module Okayu
189
271
  return unless data
190
272
 
191
273
  if data[:listener_id]
192
- set_color({:listener_id => data[:listener_id]}, COLORS[WHITE])
193
- unless ListenersController.unset_color_index :id => data[:listener_id]
194
- Wx::message_box('色設定の消去に失敗しました')
195
- end
274
+ listener = Listener.find(data[:listener_id])
275
+ old_color_index = listener.color_index
276
+ listener.color_index = nil
277
+ listener.save
278
+ if COLORS[old_color_index||WHITE][:white_text]
279
+ redraw
280
+ else
281
+ set_color({:listener_id => data[:listener_id]}, COLORS[WHITE])
282
+ end
196
283
  else
197
- set_color({:visitor_id => data[:visitor_id]}, COLORS[WHITE])
198
- unless VisitorsController.unset_color_index :id => data[:visitor_id]
199
- Wx::message_box('色設定の消去に失敗しました')
284
+ visitor = Visitor.find(data[:visitor_id])
285
+ old_color_index = visitor.color_index
286
+ visitor.color_index = nil
287
+ visitor.save
288
+ if COLORS[old_color_index||WHITE][:white_text]
289
+ redraw
290
+ else
291
+ set_color({:visitor_id => data[:visitor_id]}, COLORS[WHITE])
200
292
  end
201
293
  end
202
294
  end
@@ -217,6 +309,12 @@ module Okayu
217
309
  end
218
310
  end
219
311
 
312
+ def redraw
313
+ get_parent.pause
314
+ get_parent.redraw_list @selected_index
315
+ get_parent.resume
316
+ end
317
+
220
318
  def set_color_to_an_item index, color
221
319
  set_item_background_colour(index, color[:color])
222
320
  if color[:white_text]
@@ -225,13 +323,65 @@ module Okayu
225
323
  end
226
324
 
227
325
  def on_name_set index, name
326
+ data = get_item_data(index)
327
+ return unless data
328
+
329
+ if data[:listener_id]
330
+ listener = Listener.find(data[:listener_id])
331
+ listener.name = name
332
+ listener.save
333
+ set_name_to_listener(data[:listener_id], name)
334
+ else
335
+ visitor = Visitor.find(data[:visitor_id])
336
+ visitor.create_listener(:name => name)
337
+ visitor.save
338
+ set_name_to_visitor(data[:visitor_id], visitor.listener_id, name)
339
+ end
228
340
  end
341
+
229
342
  def on_name_unset index, name
343
+ data = get_item_data(index)
344
+ return unless data
345
+
346
+ visitor = Visitor.find(data[:visitor_id])
347
+ visitor.listener_id = nil
348
+ visitor.save
349
+ if data[:listener_id]
350
+ listener = Listener.find data[:listener_id]
351
+ if listener.visitors.size == 0
352
+ listener.destroy
353
+ end
354
+ end
355
+ set_name_to_visitor data[:visitor_id], nil, ''
230
356
  end
231
- def set_name target, name
357
+
358
+
359
+ def set_name_to_listener listener_id, name
360
+ self.each do |index|
361
+ if get_item_data(index)[:listener_id] == listener_id
362
+ set_name_to_an_item(index, name)
363
+ end
364
+ end
232
365
  end
366
+
367
+ def set_name_to_visitor visitor_id, listener_id, name
368
+ self.each do |index|
369
+ data = get_item_data(index)
370
+ if data[:visitor_id] == visitor_id
371
+ data[:listener_id] = listener_id
372
+ set_item_data(index, data)
373
+ set_name_to_an_item(index, name)
374
+ end
375
+ end
376
+ end
377
+
233
378
  def set_name_to_an_item index, name
379
+ item = get_item(index)
380
+ item.set_column COLUMNS[:name]
381
+ item.set_text(name)
382
+ set_item(item)
234
383
  end
384
+
235
385
  end
236
386
 
237
387
  class LivePanel < Wx::Panel
@@ -254,7 +404,6 @@ module Okayu
254
404
 
255
405
  @live_url.set_focus
256
406
 
257
- #@live_url.evt_key_down(){|event| on_key_down(event)}
258
407
  evt_key_down(){|event| on_key_down(event)}
259
408
 
260
409
 
@@ -284,12 +433,21 @@ module Okayu
284
433
  @live_controller.comments.each do |comment|
285
434
  @list.insert_comment(comment)
286
435
  end
287
-
436
+
437
+ @list.set_focus
288
438
  @ready = true
289
439
  end
290
440
  end
291
441
  end
292
-
442
+
443
+ def redraw_list selected_item_index
444
+ @list.delete_all_items
445
+ @live_controller.reload_comments.each do |comment|
446
+ @list.insert_comment(comment)
447
+ end
448
+ @list.get_item(selected_item_index).set_state(Wx::LIST_STATE_SELECTED)
449
+ end
450
+
293
451
  def live_id_from_url url
294
452
  if /^\d+$/ =~ url
295
453
  "lv#{url}"
@@ -319,6 +477,13 @@ module Okayu
319
477
  end
320
478
  end
321
479
 
480
+ def pause
481
+ @ready = false
482
+ end
483
+
484
+ def resume
485
+ @ready = true
486
+ end
322
487
 
323
488
  def on_update
324
489
  if @ready && @live_controller.live_now?
@@ -12,7 +12,7 @@ module Okayu
12
12
  create_tab
13
13
 
14
14
  @timer = Wx::Timer.new(self, Wx::ID_ANY)
15
- @timer.start
15
+ @timer.start 100
16
16
  evt_timer(@timer.get_id) {|event| on_update}
17
17
 
18
18
  evt_size{|event| on_size(event)}
data/okayu.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{okayu}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kentaro Imai"]
12
- s.date = %q{2009-09-18}
12
+ s.date = %q{2009-09-19}
13
13
  s.default_executable = %q{okayu}
14
14
  s.description = %q{A comment viewer for http://live.nicovideo.jp/}
15
15
  s.email = %q{kentaroi@gmail.com}
@@ -30,23 +30,20 @@ Gem::Specification.new do |s|
30
30
  "lib/app_dir.rb",
31
31
  "lib/client.rb",
32
32
  "lib/controllers.rb",
33
- "lib/controllers/listeners_controller.rb",
34
33
  "lib/controllers/live_controller.rb",
35
- "lib/controllers/visitors_controller.rb",
36
34
  "lib/cookie_thief.rb",
37
- "lib/db/migrate/000_create_lives.rb",
35
+ "lib/db/migrate/000_create_programs.rb",
38
36
  "lib/db/migrate/001_create_comments.rb",
39
37
  "lib/db/migrate/002_create_visitors.rb",
40
38
  "lib/db/migrate/003_create_listeners.rb",
41
39
  "lib/db/migrate/004_create_communities.rb",
42
- "lib/db/migrate/005_create_listeners_lives.rb",
43
- "lib/db/migrate/006_create_lives_visitors.rb",
44
- "lib/factory.rb",
40
+ "lib/db/migrate/005_create_listeners_programs.rb",
41
+ "lib/db/migrate/006_create_programs_visitors.rb",
45
42
  "lib/models.rb",
46
43
  "lib/models/comment.rb",
47
44
  "lib/models/community.rb",
48
45
  "lib/models/listener.rb",
49
- "lib/models/live.rb",
46
+ "lib/models/program.rb",
50
47
  "lib/models/visitor.rb",
51
48
  "lib/okayu.rb",
52
49
  "lib/player_status.rb",
@@ -60,13 +57,12 @@ Gem::Specification.new do |s|
60
57
  "lib/views/live_panel.rb",
61
58
  "lib/views/login_dialog.rb",
62
59
  "lib/views/main_panel.rb",
63
- "logged_in_page",
64
- "login_error_page",
65
60
  "okayu.gemspec",
66
- "tcp_log",
67
61
  "test/client_test.rb",
68
62
  "test/cookie_thief_test.rb",
69
63
  "test/ie_cookie.txt",
64
+ "test/logged_in_page",
65
+ "test/login_error_page",
70
66
  "test/okayu_test.rb",
71
67
  "test/player_status_test.rb",
72
68
  "test/raw_player_status",
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kentaroi-okayu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Imai
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-18 00:00:00 -07:00
12
+ date: 2009-09-19 00:00:00 -07:00
13
13
  default_executable: okayu
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -113,23 +113,20 @@ files:
113
113
  - lib/app_dir.rb
114
114
  - lib/client.rb
115
115
  - lib/controllers.rb
116
- - lib/controllers/listeners_controller.rb
117
116
  - lib/controllers/live_controller.rb
118
- - lib/controllers/visitors_controller.rb
119
117
  - lib/cookie_thief.rb
120
- - lib/db/migrate/000_create_lives.rb
118
+ - lib/db/migrate/000_create_programs.rb
121
119
  - lib/db/migrate/001_create_comments.rb
122
120
  - lib/db/migrate/002_create_visitors.rb
123
121
  - lib/db/migrate/003_create_listeners.rb
124
122
  - lib/db/migrate/004_create_communities.rb
125
- - lib/db/migrate/005_create_listeners_lives.rb
126
- - lib/db/migrate/006_create_lives_visitors.rb
127
- - lib/factory.rb
123
+ - lib/db/migrate/005_create_listeners_programs.rb
124
+ - lib/db/migrate/006_create_programs_visitors.rb
128
125
  - lib/models.rb
129
126
  - lib/models/comment.rb
130
127
  - lib/models/community.rb
131
128
  - lib/models/listener.rb
132
- - lib/models/live.rb
129
+ - lib/models/program.rb
133
130
  - lib/models/visitor.rb
134
131
  - lib/okayu.rb
135
132
  - lib/player_status.rb
@@ -143,13 +140,12 @@ files:
143
140
  - lib/views/live_panel.rb
144
141
  - lib/views/login_dialog.rb
145
142
  - lib/views/main_panel.rb
146
- - logged_in_page
147
- - login_error_page
148
143
  - okayu.gemspec
149
- - tcp_log
150
144
  - test/client_test.rb
151
145
  - test/cookie_thief_test.rb
152
146
  - test/ie_cookie.txt
147
+ - test/logged_in_page
148
+ - test/login_error_page
153
149
  - test/okayu_test.rb
154
150
  - test/player_status_test.rb
155
151
  - test/raw_player_status
@@ -1,18 +0,0 @@
1
- module Okayu
2
- class ListenersController
3
- def self.set_color_index params
4
- begin
5
- listener = Listener.find params[:id]
6
- listener.color_index = params[:color_index]
7
- listener.save!
8
- rescue
9
- return false
10
- end
11
- true
12
- end
13
-
14
- def self.unset_color_index params
15
- self.set_color_index params
16
- end
17
- end
18
- end
@@ -1,19 +0,0 @@
1
- module Okayu
2
- class VisitorsController
3
- def self.set_color_index params
4
- begin
5
- visitor = Visitor.find params[:id]
6
- visitor.color_index = params[:color_index]
7
- visitor.save!
8
- rescue
9
- return false
10
- end
11
- true
12
- end
13
-
14
- def self.unset_color_index params
15
- self.set_color_index params
16
- end
17
- end
18
- end
19
-
@@ -1,12 +0,0 @@
1
- class CreateListenersLives < ActiveRecord::Migration
2
- def self.up
3
- create_table :listeners_lives, :id => false do |t|
4
- t.references :listener, :live, :default => 0, :null => false
5
- end
6
- end
7
-
8
- def self.down
9
- drop_table :listeners_lives
10
- end
11
- end
12
-
@@ -1,13 +0,0 @@
1
- class CreateLivesVisitors < ActiveRecord::Migration
2
- def self.up
3
- create_table :lives_visitors, :id => false do |t|
4
- t.references :live, :visitor, :default => 0, :null => false
5
- end
6
- end
7
-
8
- def self.down
9
- drop_table :lives_visitors
10
- end
11
- end
12
-
13
-
data/lib/factory.rb DELETED
@@ -1,16 +0,0 @@
1
- module Okayu
2
- class Factory
3
- def initialize
4
- UserInfo.load
5
- @client = Client.instance
6
- @app = Okayu::App.new
7
- @app.main_loop
8
- end
9
-
10
- def close
11
- @client.kill_all
12
- UserInfo.save
13
- end
14
- end
15
- end
16
-
data/tcp_log DELETED
Binary file