mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Cfg: Refactor 'Gui - Url bar'; Add better support for buttons
This commit is contained in:
@@ -20,6 +20,9 @@ import gplx.core.primitives.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.users.data.*;
|
||||
public class Xou_cache_mgr implements Gfo_invk {
|
||||
private long fsys_size_cur = 0;
|
||||
private long fsys_size_min = Io_mgr.Len_mb * 75;
|
||||
private long fsys_size_max = Io_mgr.Len_mb * 100;
|
||||
private final Xoa_wiki_mgr wiki_mgr; private final Xou_cache_tbl cache_tbl; private final Db_cfg_tbl cfg_tbl; private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(512);
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry(); private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2(); private final Object thread_lock = new Object();
|
||||
private final Io_url cache_dir; private boolean db_load_needed = true;
|
||||
@@ -29,29 +32,9 @@ public class Xou_cache_mgr implements Gfo_invk {
|
||||
this.cache_tbl = db_file.Tbl__cache();
|
||||
}
|
||||
public boolean Enabled() {return enabled;} private boolean enabled = true; public void Enabled_n_() {enabled = false;}
|
||||
public int Fsys_count_cur() {return hash.Count();}
|
||||
public long Fsys_size_cur() {return fsys_size_cur;} private long fsys_size_cur = 0;
|
||||
public long Fsys_size_min() {return fsys_size_min;} public void Fsys_size_min_(long v) {fsys_size_min = v;} private long fsys_size_min = Io_mgr.Len_mb * 75;
|
||||
public long Fsys_size_max() {return fsys_size_max;} public void Fsys_size_max_(long v) {fsys_size_max = v;} private long fsys_size_max = Io_mgr.Len_mb * 100;
|
||||
public Keyval[] Info() {
|
||||
long view_date = Long_.Max_value;
|
||||
long fsys_size = 0;
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xou_cache_itm itm = (Xou_cache_itm)hash.Get_at(i);
|
||||
fsys_size += itm.File_size();
|
||||
if (itm.View_date() < view_date) view_date = itm.View_date();
|
||||
}
|
||||
return Keyval_.Ary
|
||||
( Keyval_.new_("cache folder", cache_dir.Xto_api())
|
||||
, Keyval_.new_("space used", gplx.core.ios.Io_size_.To_str(fsys_size))
|
||||
, Keyval_.new_("file count", len)
|
||||
, Keyval_.new_("oldest file", view_date == Long_.Max_value ? "" : DateAdp_.unixtime_utc_seconds_(view_date).XtoStr_fmt_iso_8561())
|
||||
);
|
||||
}
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
app.Cfg().Bind_many_app(this, Cfg__fsys_size_min, Cfg__fsys_size_max, Run__fsys_clear);
|
||||
// app.Cfg().Exec_mgr().Add(this, Run__fsys_clear);
|
||||
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);
|
||||
}
|
||||
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) {
|
||||
@@ -183,15 +166,47 @@ 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");
|
||||
else if (ctx.Match(k, Cfg__fsys_size_max)) this.fsys_size_max = m.ReadLong("v");
|
||||
// else if (ctx.Match(k, Run__fsys_clear)) this.Reduce(0);
|
||||
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"
|
||||
;
|
||||
public void Fsys_size_(long min, long max) {fsys_size_min = min; fsys_size_max = max;} // TEST:
|
||||
/*
|
||||
private Keyval[] Info() {
|
||||
long view_date = Long_.Max_value;
|
||||
long fsys_size = 0;
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xou_cache_itm itm = (Xou_cache_itm)hash.Get_at(i);
|
||||
fsys_size += itm.File_size();
|
||||
if (itm.View_date() < view_date) view_date = itm.View_date();
|
||||
}
|
||||
return Keyval_.Ary
|
||||
( Keyval_.new_("cache folder", cache_dir.Xto_api())
|
||||
, Keyval_.new_("space used", gplx.core.ios.Io_size_.To_str(fsys_size))
|
||||
, Keyval_.new_("file count", len)
|
||||
, 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();
|
||||
|
||||
@@ -59,6 +59,7 @@ public class Xou_cache_mgr_tst {
|
||||
}
|
||||
class Xou_cache_mgr_fxt {
|
||||
private Xou_cache_mgr mgr;
|
||||
private long cache_min;
|
||||
public void Clear() {
|
||||
Datetime_now.Manual_(DateAdp_.new_(1970, 1, 1, 0, 0, 0, 0));
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
@@ -70,8 +71,8 @@ class Xou_cache_mgr_fxt {
|
||||
this.mgr = new Xou_cache_mgr(app.Wiki_mgr(), app.Fsys_mgr().File_dir(), app.User().User_db_mgr().Db_file());
|
||||
}
|
||||
public void Init_delete(long min, long max) {
|
||||
mgr.Fsys_size_min_(min);
|
||||
mgr.Fsys_size_max_(max);
|
||||
cache_min = min;
|
||||
mgr.Fsys_size_(min, max);
|
||||
}
|
||||
public Xof_fsdb_itm Make_itm(String wiki, String file, int size) {
|
||||
Xof_fsdb_itm rv = new Xof_fsdb_itm();
|
||||
@@ -91,7 +92,7 @@ class Xou_cache_mgr_fxt {
|
||||
mgr.Clear();
|
||||
}
|
||||
public void Exec_reduce() {
|
||||
mgr.Reduce(mgr.Fsys_size_min());
|
||||
mgr.Reduce(cache_min);
|
||||
}
|
||||
public void Test_get(Xof_fsdb_itm fsdb, int expd_view_count, long expd_view_date) {
|
||||
Xou_cache_itm cache = mgr.Get_or_null(fsdb);
|
||||
|
||||
Reference in New Issue
Block a user