1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

Cfg: Add dynamic default text feature

This commit is contained in:
gnosygnu 2016-12-23 10:18:01 -05:00
parent d380278390
commit 3177979558
4 changed files with 27 additions and 31 deletions

View File

@ -16,15 +16,12 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.apps.cfgs.mgrs.dflts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
public interface Xocfg_dflt_itm {
String Get_str(String key);
}
class Xocfg_dflt_itm__static implements Xocfg_dflt_itm {
class Xocfg_dflt_itm__static implements Gfo_invk {
private final String val;
public Xocfg_dflt_itm__static(String val) {
this.val = val;
}
public String Get_str(String key) {
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return val;
}
}

View File

@ -28,14 +28,16 @@ public class Xocfg_dflt_mgr {
loader.Load_by_file(this, app.Fsys_mgr().Bin_plat_dir().GenSubFil_nest("xowa", "cfg", "xo.cfg.dflt.json"));
}
public String Get_or(String key, String or) {
Xocfg_dflt_itm itm = (Xocfg_dflt_itm)hash.Get_by(key);
return (itm == null) ? or : itm.Get_str(key);
Gfo_invk itm = (Gfo_invk)hash.Get_by(key);
return (itm == null) ? or : (String)Gfo_invk_.Invk_by_key(itm, key);
}
public void Add(String key, String val) {
cache_mgr.Dflt(key, val);
hash.Add(key, new Xocfg_dflt_itm__static(val));
}
public void Add(String key, Xocfg_dflt_itm itm) {
hash.Add(key, itm);
public void Add(Gfo_invk invk, String... keys) {
for (String key : keys) {
hash.Add(key, invk);
}
}
}

View File

@ -28,7 +28,6 @@ public class Xoi_firefox_installer implements Gfo_invk {
trg_xpi_package = trg_xpi.OwnerDir().GenSubDir("package");
Xoa_fsys_eval cmd_eval = app.Url_cmd_eval();
Process_adp.ini_(this, app.Usr_dlg(), program, cmd_eval, Process_adp.Run_mode_async, 0, "firefox", "\"~{url}\"", "url");
app.Cfg().Bind_many_app(this, Cfg__firefox_cmd);
}
public void Install_via_process() {
Generate();
@ -59,10 +58,7 @@ public class Xoi_firefox_installer implements Gfo_invk {
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_install)) Install_via_process();
else if (ctx.Match(k, Cfg__firefox_cmd)) gplx.xowa.apps.progs.Xoa_prog_mgr.Init_cmd(m.ReadStr("v"), program);
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_install = "install";
private static final String Cfg__firefox_cmd = "xowa.addon.xowa_viewer.firefox";
}

View File

@ -35,6 +35,7 @@ public class Xou_cache_mgr implements Gfo_invk {
public void Init_by_app(Xoa_app app) {
app.Cfg().Bind_many_app(this, Cfg__fsys_size_min, Cfg__fsys_size_max);
app.Cfg().Sub_many_app(this, Run__fsys_reduce_to_min, Run__fsys_clear);
app.Cfg().Dflt_mgr().Add(this, Val__fsys_info);
}
public Xou_cache_itm Get_or_null(Xof_fsdb_itm fsdb) {return Get_or_null(fsdb.Lnki_wiki_abrv(), fsdb.Lnki_ttl(), fsdb.Lnki_type(), fsdb.Lnki_upright(), fsdb.Lnki_w(), fsdb.Lnki_h(), fsdb.Lnki_time(), fsdb.Lnki_page(), fsdb.User_thumb_w());}
public Xou_cache_itm Get_or_null(byte[] wiki, byte[] ttl, int type, double upright, int w, int h, double time, int page, int user_thumb_w) {
@ -166,20 +167,32 @@ public class Xou_cache_mgr implements Gfo_invk {
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Cfg__fsys_size_min)) this.fsys_size_min = m.ReadLong("v") * Io_mgr.Len_mb;
else if (ctx.Match(k, Cfg__fsys_size_max)) this.fsys_size_max = m.ReadLong("v") * Io_mgr.Len_mb;
else if (ctx.Match(k, Val__fsys_info)) return this.Info_str();
else if (ctx.Match(k, Run__fsys_reduce_to_min)) {this.Reduce(fsys_size_min);}
else if (ctx.Match(k, Run__fsys_clear)) {this.Reduce(0);}
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Cfg__fsys_size_min = "xowa.wiki.files.cache.fsys_size_min"
, Cfg__fsys_size_max = "xowa.wiki.files.cache.fsys_size_max"
, Run__fsys_reduce_to_min = "xowa.wiki.files.cache.reduce_to_min"
, Run__fsys_clear = "xowa.wiki.files.cache.clear"
Cfg__fsys_size_min = "xowa.wiki.files.cache.fsys_size_min"
, Cfg__fsys_size_max = "xowa.wiki.files.cache.fsys_size_max"
, Val__fsys_info = "xowa.wiki.files.cache.info"
, Run__fsys_reduce_to_min = "xowa.wiki.files.cache.reduce_to_min"
, Run__fsys_clear = "xowa.wiki.files.cache.clear"
;
public void Fsys_size_(long min, long max) {fsys_size_min = min; fsys_size_max = max;} // TEST:
/*
private Keyval[] Info() {
private String Info_str() {
this.Page_bgn();
Bry_bfr bfr = Bry_bfr_.New_w_size(255);
Keyval[] ary = this.Info_kvs();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Keyval kv = ary[i];
bfr.Add_str_a7(kv.Key()).Add_str_a7(": ").Add_str_u8(kv.Val_to_str_or_empty()).Add_byte_nl();
}
return bfr.To_str_and_clear();
}
private Keyval[] Info_kvs() {
long view_date = Long_.Max_value;
long fsys_size = 0;
int len = hash.Count();
@ -195,18 +208,6 @@ public class Xou_cache_mgr implements Gfo_invk {
, Keyval_.new_("oldest file", view_date == Long_.Max_value ? "" : DateAdp_.unixtime_utc_seconds_(view_date).XtoStr_fmt_iso_8561())
);
}
private String Info() {
cache_mgr.Page_bgn();
Bry_bfr bfr = Bry_bfr_.New_w_size(255);
Keyval[] ary = cache_mgr.Info();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Keyval kv = ary[i];
bfr.Add_str_a7(kv.Key()).Add_str_a7(": ").Add_str_u8(kv.Val_to_str_or_empty()).Add_byte_nl();
}
return bfr.To_str_and_clear();
}
*/
}
class Xou_cache_grp {
private final List_adp list = List_adp_.New();