From b9cf243537bd25750abfdb9977b5eccd7ecc3613 Mon Sep 17 00:00:00 2001 From: moguno Date: Sat, 1 Nov 2014 21:37:02 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E7=94=BB=E9=9D=A2=E3=81=AB?= =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=81=99=E3=82=8B=E6=A7=98=E3=81=AB=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/plugin/skin/skin.rb | 77 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/core/plugin/skin/skin.rb b/core/plugin/skin/skin.rb index f771bb8..fddcb3d 100644 --- a/core/plugin/skin/skin.rb +++ b/core/plugin/skin/skin.rb @@ -1,19 +1,78 @@ # -*- 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 -- 2.1.2