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 +21 -1
- data/VERSION +1 -1
- data/bin/okayu +1 -0
- data/lib/app.rb +1 -1
- data/lib/app_dir.rb +3 -0
- data/lib/client.rb +4 -5
- data/lib/controllers.rb +0 -2
- data/lib/controllers/live_controller.rb +22 -14
- data/lib/cookie_thief.rb +26 -5
- data/lib/db/migrate/{000_create_lives.rb → 000_create_programs.rb} +3 -3
- data/lib/db/migrate/001_create_comments.rb +1 -2
- data/lib/db/migrate/005_create_listeners_programs.rb +12 -0
- data/lib/db/migrate/006_create_programs_visitors.rb +13 -0
- data/lib/models.rb +1 -1
- data/lib/models/comment.rb +1 -16
- data/lib/models/community.rb +1 -1
- data/lib/models/listener.rb +1 -2
- data/lib/models/{live.rb → program.rb} +1 -1
- data/lib/models/visitor.rb +1 -1
- data/lib/user_info.rb +0 -1
- data/lib/views/app_frame.rb +6 -0
- data/lib/views/live_panel.rb +213 -48
- data/lib/views/main_panel.rb +1 -1
- data/okayu.gemspec +8 -12
- data/{logged_in_page → test/logged_in_page} +0 -0
- data/{login_error_page → test/login_error_page} +0 -0
- metadata +8 -12
- data/lib/controllers/listeners_controller.rb +0 -18
- data/lib/controllers/visitors_controller.rb +0 -19
- data/lib/db/migrate/005_create_listeners_lives.rb +0 -12
- data/lib/db/migrate/006_create_lives_visitors.rb +0 -13
- data/lib/factory.rb +0 -16
- data/tcp_log +0 -0
data/README.rdoc
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
= okayu
|
2
2
|
|
3
|
-
|
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
|
+
0.0.2
|
data/bin/okayu
CHANGED
data/lib/app.rb
CHANGED
data/lib/app_dir.rb
CHANGED
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
@@ -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 @
|
8
|
-
@community = @
|
7
|
+
if @program = Program.find(:first, :conditions => {:live_id => @live_id})
|
8
|
+
@community = @program.community
|
9
9
|
else
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
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
|
-
@
|
19
|
-
@
|
18
|
+
@program.community = @community
|
19
|
+
@program.save
|
20
20
|
end
|
21
21
|
else
|
22
22
|
@live_now = false
|
23
|
-
if @
|
24
|
-
@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
|
-
!!@
|
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
|
-
@
|
41
|
+
@program.base_time
|
42
42
|
end
|
43
43
|
|
44
44
|
def comments
|
45
|
-
@
|
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 => {:
|
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.
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
1
|
+
class CreatePrograms < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
create_table :
|
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 :
|
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 :
|
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
data/lib/models/comment.rb
CHANGED
@@ -1,22 +1,7 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
|
3
1
|
class Comment < ActiveRecord::Base
|
4
2
|
belongs_to :community
|
5
|
-
belongs_to :
|
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
|
data/lib/models/community.rb
CHANGED
data/lib/models/listener.rb
CHANGED
data/lib/models/visitor.rb
CHANGED
data/lib/user_info.rb
CHANGED
data/lib/views/app_frame.rb
CHANGED
@@ -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
|
data/lib/views/live_panel.rb
CHANGED
@@ -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
|
-
|
3
|
-
NAME
|
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(
|
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
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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(
|
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
|
-
|
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
|
-
|
147
|
-
|
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
|
-
|
160
|
-
if is_colored?(
|
161
|
-
on_color_unset
|
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
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
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
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
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
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
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?
|
data/lib/views/main_panel.rb
CHANGED
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.
|
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-
|
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/
|
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/
|
43
|
-
"lib/db/migrate/
|
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/
|
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.
|
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-
|
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/
|
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/
|
126
|
-
- lib/db/migrate/
|
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/
|
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
data/tcp_log
DELETED
Binary file
|