1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# -*- coding: utf-8 -*-
miquire :mui, 'skin'
miquire :addon, 'addon'
miquire :addon, 'settings'
require 'enumerator'
class Addon::Profile < Addon::Addon
Tab = Class.new(Addon::Addon.gen_tabclass('のプロフィール', nil)){
def initialize(name, service, options = {})
@page = 1
options[:header] = Gtk::VBox.new(false, 0)
super(name, service, options) end
def user
@options[:user] end
def next_page
Delayer.new{ timeline.add(@posts.pop) } if @posts end
def on_create
Thread.new{
tl = @service.scan(:user_timeline, :user_id => user[:id],
:no_auto_since_id => true,
:count => 20)
if tl
@posts = tl.enum_slice(20).to_a
next_page end }
header.closeup(profile).show_all
super
focus end
private
def background_color
style = Gtk::Style.new()
style.set_bg(Gtk::STATE_NORMAL, 0xFF ** 2, 0xFF ** 2, 0xFF ** 2)
style end
def profile
eventbox = Gtk::EventBox.new
eventbox.signal_connect('visibility-notify-event'){
eventbox.style = background_color
false }
eventbox.add(Gtk::VBox.new(false, 0).
closeup(toolbar).
add(Gtk::HBox.new(false, 16).
closeup(Gtk::WebIcon.new(user[:profile_image_url]).top).
add(Gtk::VBox.new(false, 0).add(main(eventbox))))) end
def toolbar
container = Gtk::HBox.new(false, 0)
close = Gtk::Button.new('×')
close.signal_connect('clicked'){ self.remove }
# nextpage = Gtk::Button.new('+')
# nextpage.signal_connect('clicked'){ self.next_page }
container.closeup(close) # .closeup(nextpage)
end
def main(window_parent)
ago = (Time.now - (user[:created] or 1)).to_i / (60 * 60 * 24)
tags = []
text = "#{user[:idname]} #{user[:name]}\n"
append = lambda{ |title, value|
tags << ['_caption_style', text.strsize, title.strsize]
text << "#{title} #{value}" }
append.call "location", "#{user[:location]}\n" if user[:location]
append.call "web", "#{user[:url]}\n" if user[:url]
append.call "bio", "#{user[:detail]}\n\n" if user[:detail]
append.call "フォロー", "#{user[:friends_count]} / "
append.call "フォロワー", "#{user[:followers_count]} / #{user[:statuses_count]}Tweets " +
"(#{(user[:statuses_count].to_f / ago).round_at(2) }/day)\n"
append.call "since", "#{user[:created].strftime('%Y/%m/%d %H:%M:%S')}" if user[:created]
body = Gtk::IntelligentTextview.new(text)
body.buffer.create_tag('_caption_style',
'foreground_gdk' => Gdk::Color.new(0, 0x33 ** 2, 0x66 ** 2),
'weight' => Pango::FontDescription::WEIGHT_BOLD)
tags << [tag_user_id_link(body), 0, user[:idname].size]
tags.each{ |token|
body.buffer.apply_tag(token[0], *body.buffer.get_range(*token[1..2])) }
body.get_background = lambda{ background_color }
body end
private
def tag_user_id_link(body)
tag = body.buffer.create_tag('_user_id_link',
'foreground' => 'blue',
"underline" => Pango::UNDERLINE_SINGLE)
tag.signal_connect('event'){ |this, textview, event, iter|
result = false
if(event.is_a?(Gdk::EventButton)) and
(event.event_type == Gdk::Event::BUTTON_RELEASE) and
not(textview.buffer.selection_bounds[2])
if (event.button == 1)
Gtk::IntelligentTextview.openurl('http://twitter.com/'+user[:idname]) end
elsif(event.is_a?(Gdk::EventMotion))
body.set_cursor(textview, Gdk::Cursor::HAND2) end
result }
tag end }
include Addon::SettingUtils
def onboot(service)
@service = service
Gtk::Mumble.contextmenu.registmenu(lambda{ |m, w|
"#{m.message.user[:idname]}(#{m.message.user[:name]})について".gsub(/_/, '__') },
lambda{ |m, w| m.message.repliable? }){ |m, w|
makescreen(m.message.user) }
Gtk::TimeLine.addlinkrule(/@[a-zA-Z0-9_]+/){ |match, *trash|
user = User.findByIdname(match[1, match.length])
if user
makescreen(user)
else
Thread.new{
user = @service.scan(:user_show,
:no_auto_since_id => false,
:screen_name => match[1, match.length])
Delayer.new{ makescreen(user.first) } if user } end } end
private
def makescreen(user)
if user[:exact]
Tab.new("#{user[:idname]}(#{user[:name]})", @service,
:user => user,
:icon => user[:profile_image_url])
else
Thread.new{
retr = @service.scan(:user_show, :screen_name => user[:idname],
:no_auto_since_id => true)
Delayer.new{ makescreen(retr.first) } if retr }
end end end
Plugin::Ring.push Addon::Profile.new,[:boot]
|