-
-
Save toshia/950314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 | |
miquire :addon, 'addon' | |
miquire :core, 'environment' | |
miquire :addon, 'settings' | |
require 'net/http' | |
module Net | |
class <<HTTP | |
alias new_org new | |
def new(host, port=80, proxy_addr=nil, proxy_port=nil, proxy_user=nil, proxy_pass=nil) | |
case UserConfig[:proxy_enabled] | |
when :specify | |
pu, pp = nil, nil | |
pu, pp = UserConfig[:proxy_user], UserConfig[:proxy_password] if UserConfig[:proxy_cert] | |
new_org(host, port, UserConfig[:proxy_server], UserConfig[:proxy_port].to_i, pu, pp) | |
when :disable | |
new_org(host, port) | |
else | |
new_org(host, port, *get_env_proxy_settings)end | |
end | |
def get_env_proxy_settings | |
env_proxy_settings = (ENV["HTTP_PROXY"] || '').sub(/http:\/\//, '').split(/[@:]/) | |
case(env_proxy_settings.size) | |
when 2 | |
[env_proxy_settings[0], env_proxy_settings[1].to_i] | |
when 4 | |
[env_proxy_settings[2], env_proxy_settings[3].to_i, env_proxy_settings[0], env_proxy_settings[1]] | |
else | |
[] end end | |
memoize :_env_proxy_settings | |
end | |
end | |
Module.new do | |
def self.boot | |
plugin = Plugin::create(:proxy) | |
plugin.add_event(:boot) { |service| | |
Plugin.call(:setting_tab_regist, settings, "プロキシ") | |
} | |
UserConfig.connect(:proxy_enabled) { |key, new_val, before_val, id| | |
#UserStreamを使っているなら繋ぎなおさせる | |
if UserConfig[:realtime_rewind] | |
Thread.new { | |
UserConfig[:realtime_rewind] = false | |
sleep(3) | |
UserConfig[:realtime_rewind] = true | |
} | |
end | |
} | |
end | |
def self.settings | |
box = Gtk::VBox.new(false, 8) | |
radio_tag = radio_specify = Gtk::RadioButton.new('自分で設定する') | |
radio_envval = Gtk::RadioButton.new(radio_tag, '環境変数の設定を使う') | |
radio_disable = Gtk::RadioButton.new(radio_tag, 'プロキシを使わない') | |
case UserConfig[:proxy_enabled] | |
when :specify | |
radio_specify.active = true | |
when :disable | |
radio_disable.active = true | |
else | |
radio_envval.active = true end | |
box. | |
closeup(gen_group(:specify, radio_specify)). | |
closeup(gen_group(:envval, radio_envval)). | |
closeup(gen_record(:disable, radio_disable)) | |
end | |
def self.gen_record(name, radio) | |
radio.signal_connect('toggled'){ |widget| | |
UserConfig[:proxy_enabled] = name } | |
radio | |
end | |
def self.gen_group(name, radio) | |
eventbox = __send__("gen_#{name}_ev") | |
radio.signal_connect('toggled'){ |widget| | |
UserConfig[:proxy_enabled] = name | |
eventbox.sensitive = widget.active? } | |
eventbox.sensitive = UserConfig[:proxy_enabled] == name | |
Mtk::group(radio, eventbox) | |
end | |
def self.gen_specify_ev | |
sv = Mtk.input(:proxy_server, "サーバ") | |
pt = Mtk.input(:proxy_port, "ポート") | |
us = Mtk.input(:proxy_user, "ユーザ") | |
pw = Mtk.input(:proxy_password, "パスワード") | |
ct = Mtk.boolean(:proxy_cert, "ユーザ認証が必要") | |
auth_group = Mtk::group(ct, us, pw) | |
UserConfig.connect(:proxy_cert){ |key, new_val, before_val, id| | |
us.sensitive = pw.sensitive = new_val } | |
Gtk::EventBox.new.add(Gtk::VBox.new(false, 8).closeup(sv).closeup(pt).closeup(auth_group)) | |
end | |
def self.gen_envval_ev | |
c = lambda{ |index| | |
lambda{|x| Net::HTTP.get_env_proxy_settings[index].to_s } } | |
sv = Mtk.input(c[0], "サーバ"){|c,i|i.sensitive = false} | |
pt = Mtk.input(c[1], "ポート"){|c,i|i.sensitive = false} | |
us = Mtk.input(c[2], "ユーザ"){|c,i|i.sensitive = false} | |
pw = Mtk.input(c[3], "パスワード"){|c,i|i.sensitive = false} | |
Gtk::EventBox.new.add(Gtk::VBox.new(false, 8).closeup(sv).closeup(pt).closeup(us).closeup(pw)) | |
end | |
boot | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment