1
|
# -*- coding: utf-8 -*-
|
2
|
miquire :addon, 'addon'
|
3
|
miquire :core, 'environment'
|
4
|
miquire :addon, 'settings'
|
5
|
|
6
|
#require 'gst'
|
7
|
require_if_exist 'rubygems'
|
8
|
require_if_exist 'win32/sound'
|
9
|
require_if_exist 'ruby-growl'
|
10
|
require_if_exist 'sdl'
|
11
|
|
12
|
Module.new do
|
13
|
|
14
|
DEFAULT_SOUND_DIRECTORY = 'skin/data/sounds'
|
15
|
GROWL = Growl.new '127.0.0.1', 'ruby-growl', ['ruby-growl Notification'] if defined? Growl
|
16
|
if defined? SDL
|
17
|
SDL.init(SDL::INIT_AUDIO)
|
18
|
SDL::Mixer.open
|
19
|
end
|
20
|
def self.boot
|
21
|
plugin = Plugin::create(:notify)
|
22
|
|
23
|
plugin.add_event(:boot){ |service|
|
24
|
Plugin.call(:setting_tab_regist, main, '通知') }
|
25
|
plugin.add_event(:update, &method(:onupdate))
|
26
|
plugin.add_event(:mention, &method(:onmention))
|
27
|
plugin.add_event(:mention, &method(:onretweeted))
|
28
|
plugin.add_event(:followers_created, &method(:onfollowed))
|
29
|
plugin.add_event(:followers_destroy, &method(:onremoved))
|
30
|
plugin.add_event(:favorite, &method(:onfavorited))
|
31
|
plugin.add_event(:after_event){ first?(:after_event) }
|
32
|
end
|
33
|
|
34
|
def self.main
|
35
|
box = Gtk::VBox.new(false, 8)
|
36
|
ft = Mtk.group('フレンドタイムライン',
|
37
|
Mtk.boolean(:notify_friend_timeline, 'ポップアップ'),
|
38
|
Mtk.fileselect(:notify_sound_friend_timeline, 'サウンド', DEFAULT_SOUND_DIRECTORY))
|
39
|
me = Mtk.group('リプライ',
|
40
|
Mtk.boolean(:notify_mention, 'ポップアップ'),
|
41
|
Mtk.fileselect(:notify_sound_mention, 'サウンド', DEFAULT_SOUND_DIRECTORY))
|
42
|
fd = Mtk.group('フォローされたとき',
|
43
|
Mtk.boolean(:notify_followed, 'ポップアップ'),
|
44
|
Mtk.fileselect(:notify_sound_followed, 'サウンド', DEFAULT_SOUND_DIRECTORY))
|
45
|
rd = Mtk.group('フォロー解除されたとき',
|
46
|
Mtk.boolean(:notify_removed, 'ポップアップ'),
|
47
|
Mtk.fileselect(:notify_sound_removed, 'サウンド', DEFAULT_SOUND_DIRECTORY))
|
48
|
rt = Mtk.group('リツイートされたとき',
|
49
|
Mtk.boolean(:notify_retweeted, 'ポップアップ'),
|
50
|
Mtk.fileselect(:notify_sound_retweeted, 'サウンド', DEFAULT_SOUND_DIRECTORY))
|
51
|
fv = Mtk.group('ふぁぼられたとき',
|
52
|
Mtk.boolean(:notify_favorited, 'ポップアップ'),
|
53
|
Mtk.fileselect(:notify_sound_favorited, 'サウンド', DEFAULT_SOUND_DIRECTORY))
|
54
|
box.closeup(ft).closeup(me).closeup(fd).closeup(rd).closeup(rt).closeup(fv)
|
55
|
box.pack_start(Mtk.adjustment('通知を表示し続ける秒数', :notify_expire_time, 1, 60), false)
|
56
|
end
|
57
|
|
58
|
def self.onupdate(post, raw_messages)
|
59
|
messages = Plugin.filtering(:show_filter, raw_messages.select{ |m| not(m.from_me? or m.to_me?) }).first
|
60
|
if not(first?(:update) or messages.empty?)
|
61
|
if(UserConfig[:notify_friend_timeline])
|
62
|
messages.each{ |message|
|
63
|
self.notify(message[:user], message) if not message.from_me? } end
|
64
|
if(UserConfig[:notify_sound_friend_timeline])
|
65
|
self.notify_sound(UserConfig[:notify_sound_friend_timeline]) end end end
|
66
|
|
67
|
def self.onmention(post, raw_messages)
|
68
|
messages = Plugin.filtering(:show_filter, raw_messages.select{ |m| not m.from_me? and not m[:retweet] }).first
|
69
|
if not(first?(:mention) or messages.empty?)
|
70
|
if(not(UserConfig[:notify_friend_timeline]) and UserConfig[:notify_mention])
|
71
|
messages.each{ |message|
|
72
|
self.notify(message[:user], message) } end
|
73
|
if(UserConfig[:notify_sound_mention])
|
74
|
self.notify_sound(UserConfig[:notify_sound_mention]) end end end
|
75
|
|
76
|
def self.onfollowed(post, users)
|
77
|
if not(users.empty?)
|
78
|
if(UserConfig[:notify_followed])
|
79
|
users.each{ |user|
|
80
|
self.notify(users.first, users.map{|u| "@#{u[:idname]}" }.join(' ')+' にフォローされました。') } end
|
81
|
if(UserConfig[:notify_sound_followed])
|
82
|
self.notify_sound(UserConfig[:notify_sound_followed]) end end end
|
83
|
|
84
|
def self.onremoved(post, users)
|
85
|
if not(users.empty?)
|
86
|
if(UserConfig[:notify_removed])
|
87
|
self.notify(users.first, users.map{|u| "@#{u[:idname]}" }.join(' ')+' にリムーブされました。') end
|
88
|
if(UserConfig[:notify_sound_removed])
|
89
|
self.notify_sound(UserConfig[:notify_sound_removed]) end end end
|
90
|
|
91
|
def self.onfavorited(service, by, to)
|
92
|
if to.from_me?
|
93
|
if(UserConfig[:notify_favorited])
|
94
|
self.notify(by, "fav by #{by[:idname]} \"#{to.to_s}\"") end
|
95
|
if(UserConfig[:notify_sound_favorited])
|
96
|
self.notify_sound(UserConfig[:notify_sound_favorited]) end end end
|
97
|
|
98
|
def self.onretweeted(post, raw_messages)
|
99
|
messages = Plugin.filtering(:show_filter, raw_messages.select{ |m| m[:retweet] and not m.from_me? }).first
|
100
|
if not(messages.empty?)
|
101
|
if(UserConfig[:notify_retweeted])
|
102
|
messages.each{ |message|
|
103
|
self.notify(message[:user], 'ReTweet: ' + message.to_s) } end
|
104
|
if(UserConfig[:notify_sound_retweeted])
|
105
|
self.notify_sound(UserConfig[:notify_sound_retweeted]) end end end
|
106
|
|
107
|
def self.first?(func)
|
108
|
@called = [] if not defined? @called
|
109
|
if @called.include?(func.to_sym) and @called.include?(:after_event)
|
110
|
false
|
111
|
else
|
112
|
@called << func.to_sym
|
113
|
true end end
|
114
|
|
115
|
def self.notify(user, text)
|
116
|
if defined? Growl
|
117
|
text = text.to_show if text.is_a? Message
|
118
|
u = "mikumiku"
|
119
|
u = "@#{user[:idname]} (#{user[:name]})" if user
|
120
|
GROWL.notify "ruby-growl Notification", u, text
|
121
|
else
|
122
|
Thread.new(user, text){ |user, text|
|
123
|
command = ["notify-send"]
|
124
|
if(text.is_a? Message)
|
125
|
command << '--category=system'
|
126
|
text = text.to_s
|
127
|
end
|
128
|
command << '-t' << UserConfig[:notify_expire_time].to_s + '000'
|
129
|
if user
|
130
|
command << "-i" << Gtk::WebIcon.local_path(user[:profile_image_url])
|
131
|
command << "@#{user[:idname]} (#{user[:name]})" end
|
132
|
command << text
|
133
|
bg_system(*command) } end end
|
134
|
|
135
|
def self.notify_sound(sndfile)
|
136
|
if sndfile.respond_to?(:to_s) and FileTest.exist?(sndfile.to_s)
|
137
|
if defined?(Win32::Sound)
|
138
|
Win32::Sound.play(sndfile, Win32::Sound::ASYNC)
|
139
|
elsif defined?(SDL::Mixer)
|
140
|
SDL::Mixer.play_music( SDL::Mixer::Music.load(sndfile), 1 )
|
141
|
else
|
142
|
bg_system("aplay","-q", sndfile) end end end
|
143
|
|
144
|
boot
|
145
|
end
|