1 |
1 |
# -*- coding: utf-8 -*-
|
2 |
2 |
|
3 |
3 |
Plugin.create :skin do
|
4 |
|
# スキンのリストを返す
|
5 |
|
def get_skin_list()
|
6 |
|
dirs = Dir.glob(File.join(Skin::SKIN_ROOT, "**", "*.png")).map { |_| File.dirname(_) }.uniq
|
7 |
|
dirs.map { |_| _.gsub(/^#{Skin::SKIN_ROOT}\//, "") }
|
|
4 |
# プレビューアイコンのリスト
|
|
5 |
def preview_icons(dir)
|
|
6 |
famous_icons = [ "timeline.png", "reply.png", "activity.png", "directmessage.png" ]
|
|
7 |
skin_icons = Dir.glob(File.join(dir, "*.png")).sort.map { |_| File.basename(_) }
|
|
8 |
|
|
9 |
(famous_icons + skin_icons).uniq.select { |_| File.exist?(File.join(dir, _)) }[0, 12]
|
8 |
10 |
end
|
9 |
11 |
|
10 |
|
# 設定
|
11 |
|
settings("スキン") do
|
12 |
|
dirs = get_skin_list.inject({:vanilla => _("(デフォルト)")}) { |hash, _|
|
13 |
|
hash[_] = _
|
|
12 |
# スキンのプレビューを表示するウィジェットを生成する
|
|
13 |
def preview_widget(info)
|
|
14 |
fix = Gtk::Fixed.new
|
|
15 |
frame = Gtk::Frame.new
|
|
16 |
box = Gtk::HBox.new(false)
|
|
17 |
|
|
18 |
preview_icons(info[:dir]).each { |_|
|
|
19 |
pixbuf = Gdk::WebImageLoader.pixbuf(File.join(info[:dir], _), 32, 32)
|
|
20 |
box.pack_start(Gtk::Image.new(pixbuf), false, false)
|
|
21 |
}
|
|
22 |
|
|
23 |
fix.put(frame.add(box, nil), 16, 0)
|
|
24 |
end
|
|
25 |
|
|
26 |
# インストール済みスキンのリスト
|
|
27 |
def skin_list()
|
|
28 |
dirs = Dir.glob(File.join(Skin::SKIN_ROOT, "*")).select { |_|
|
|
29 |
File.directory?(_)
|
|
30 |
}.select { |_|
|
|
31 |
Dir.glob(File.join(_, "*.png")).length != 0
|
|
32 |
}.map { |_|
|
|
33 |
_.gsub(/^#{Skin::SKIN_ROOT}\//, "")
|
|
34 |
}
|
|
35 |
|
|
36 |
dirs
|
|
37 |
end
|
|
38 |
|
|
39 |
# スキンの情報を得る
|
|
40 |
def skin_infos()
|
|
41 |
default_info = { :vanilla => { :face => _("(デフォルト)"), :dir => Skin::default_dir } }
|
|
42 |
|
|
43 |
skin_infos_tmp = skin_list.inject({}) { |hash, _|
|
|
44 |
hash[_] = { :face => _, :dir => File.join(Skin::SKIN_ROOT, _) }
|
14 |
45 |
hash
|
15 |
46 |
}
|
|
47 |
|
|
48 |
default_info.merge(skin_infos_tmp)
|
|
49 |
end
|
|
50 |
|
|
51 |
# 設定
|
|
52 |
settings(_("スキン")) do
|
|
53 |
current_radio = nil
|
16 |
54 |
|
17 |
|
select(_("スキンディレクトリ(再起動後に反映)"), :skin_dir, dirs)
|
|
55 |
skin_infos.each { |slug, info|
|
|
56 |
button = if current_radio
|
|
57 |
Gtk::RadioButton.new(current_radio, info[:face])
|
|
58 |
else
|
|
59 |
Gtk::RadioButton.new(info[:face])
|
|
60 |
end
|
|
61 |
|
|
62 |
if slug == UserConfig[:skin_dir]
|
|
63 |
button.active = true
|
|
64 |
end
|
|
65 |
|
|
66 |
button.ssc(:toggled) {
|
|
67 |
if button.active?
|
|
68 |
UserConfig[:skin_dir] = slug
|
|
69 |
end
|
|
70 |
}
|
|
71 |
|
|
72 |
pack_start(button)
|
|
73 |
pack_start(preview_widget(info))
|
|
74 |
|
|
75 |
current_radio = button
|
|
76 |
}
|
18 |
77 |
end
|
19 |
78 |
end
|