機能 #722 » 0001-.patch
core/plugin/skin/skin.rb | ||
---|---|---|
# -*- coding: utf-8 -*-
|
||
Plugin.create :skin do
|
||
# スキンのリストを返す
|
||
def get_skin_list()
|
||
dirs = Dir.glob(File.join(Skin::SKIN_ROOT, "**", "*.png")).map { |_| File.dirname(_) }.uniq
|
||
dirs.map { |_| _.gsub(/^#{Skin::SKIN_ROOT}\//, "") }
|
||
# プレビューアイコンのリスト
|
||
def preview_icons(dir)
|
||
famous_icons = [ "timeline.png", "reply.png", "activity.png", "directmessage.png" ]
|
||
skin_icons = Dir.glob(File.join(dir, "*.png")).sort.map { |_| File.basename(_) }
|
||
(famous_icons + skin_icons).uniq.select { |_| File.exist?(File.join(dir, _)) }[0, 12]
|
||
end
|
||
# 設定
|
||
settings("スキン") do
|
||
dirs = get_skin_list.inject({:vanilla => _("(デフォルト)")}) { |hash, _|
|
||
hash[_] = _
|
||
# スキンのプレビューを表示するウィジェットを生成する
|
||
def preview_widget(info)
|
||
fix = Gtk::Fixed.new
|
||
frame = Gtk::Frame.new
|
||
box = Gtk::HBox.new(false)
|
||
preview_icons(info[:dir]).each { |_|
|
||
pixbuf = Gdk::WebImageLoader.pixbuf(File.join(info[:dir], _), 32, 32)
|
||
box.pack_start(Gtk::Image.new(pixbuf), false, false)
|
||
}
|
||
fix.put(frame.add(box, nil), 16, 0)
|
||
end
|
||
# インストール済みスキンのリスト
|
||
def skin_list()
|
||
dirs = Dir.glob(File.join(Skin::SKIN_ROOT, "*")).select { |_|
|
||
File.directory?(_)
|
||
}.select { |_|
|
||
Dir.glob(File.join(_, "*.png")).length != 0
|
||
}.map { |_|
|
||
_.gsub(/^#{Skin::SKIN_ROOT}\//, "")
|
||
}
|
||
dirs
|
||
end
|
||
# スキンの情報を得る
|
||
def skin_infos()
|
||
default_info = { :vanilla => { :face => _("(デフォルト)"), :dir => Skin::default_dir } }
|
||
skin_infos_tmp = skin_list.inject({}) { |hash, _|
|
||
hash[_] = { :face => _, :dir => File.join(Skin::SKIN_ROOT, _) }
|
||
hash
|
||
}
|
||
|
||
default_info.merge(skin_infos_tmp)
|
||
end
|
||
# 設定
|
||
settings(_("スキン")) do
|
||
current_radio = nil
|
||
select(_("スキンディレクトリ(再起動後に反映)"), :skin_dir, dirs)
|
||
skin_infos.each { |slug, info|
|
||
button = if current_radio
|
||
Gtk::RadioButton.new(current_radio, info[:face])
|
||
else
|
||
Gtk::RadioButton.new(info[:face])
|
||
end
|
||
if slug == UserConfig[:skin_dir]
|
||
button.active = true
|
||
end
|
||
button.ssc(:toggled) {
|
||
if button.active?
|
||
UserConfig[:skin_dir] = slug
|
||
end
|
||
}
|
||
pack_start(button)
|
||
pack_start(preview_widget(info))
|
||
current_radio = button
|
||
}
|
||
end
|
||
end
|