1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.6.3.3'

This commit is contained in:
gnosygnu
2016-06-21 18:32:10 -04:00
parent d43e0d2341
commit 04af0accdb
35 changed files with 395 additions and 119 deletions

View File

@@ -18,4 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.net.emails; import gplx.*; import gplx.core.*; import gplx.core.net.*;
public class Gfo_email_mgr_ {
public static Gfo_email_mgr Instance = new Gfo_email_mgr__noop();
public static Gfo_email_mgr New_jre() {return new Gfo_email_mgr__jre();}
}

View File

@@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.core.net.emails; import gplx.*; import gplx.core.*; import gplx.core.net.*;
import gplx.langs.htmls.encoders.*;
import java.awt.Desktop;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
class Gfo_email_mgr__jre implements Gfo_email_mgr {
public void Send(String to, String subject, String body) {
try {
Gfo_url_encoder url_encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_wnt;
subject = url_encoder.Encode_str(subject);
body = url_encoder.Encode_str(body);
body = String_.Replace(body, "`", "%60");
String url_str = "mailto:gnosygnu+xowa_xolog@gmail.com?subject=" + subject + "&body=" + body;
URI uri = new URI(url_str);
Desktop.getDesktop().mail(uri);
} catch (Exception e) {
Gfo_log_.Instance.Warn("email failed", "subject", subject, "body", body, "err", Err_.Message_gplx_log(e));
}
}
}

View File

@@ -0,0 +1,90 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.core.threads; import gplx.*; import gplx.core.*;
public class Gfo_thread_grp implements Gfo_invk {
private final Object thread_lock = new Object();
private final List_adp list = List_adp_.New();
private int active_cur;
public Gfo_thread_grp(String key) {this.key = key;}
public String Key() {return key;} private final String key;
public boolean Autorun() {return autorun;} public Gfo_thread_grp Autorun_(boolean v) {autorun = v; return this;} private boolean autorun = true;
public int Active_max() {return active_max;} public Gfo_thread_grp Active_max_(int v) {active_max = v; return this;} private int active_max = 1;
public void Add(Gfo_thread_itm... ary) {
synchronized (thread_lock) {
list.Add_many((Object[])ary);
}
if (autorun)
this.Run();
}
public void Run() {
int len = list.Len(); if (len == 0) return; // nothing in list; occurs when last item calls Run
for (int i = 0; i < len; ++i) {
if (active_cur == active_max) break; // already at limit; return
Gfo_thread_itm itm = null;
synchronized (thread_lock) {
itm = (Gfo_thread_itm)List_adp_.Pop_first(list);
++active_cur;
}
Thread_adp_.Start_by_msg(itm.Thread__name(), this, GfoMsg_.new_cast_(Invk_run_wkr).Add("v", itm));
}
}
public void Stop_all() {
synchronized (thread_lock) {
int len = list.Len();
for (int i = 0; i < len; ++i) {
Gfo_thread_itm itm = (Gfo_thread_itm)list.Get_at(i);
itm.Thread__stop();
}
active_cur = 0;
list.Clear();
}
}
public void Del(String key) {
synchronized (thread_lock) {
List_adp deleted = List_adp_.New();
int len = list.Len();
for (int i = 0; i < len; ++i) {
Gfo_thread_itm itm = (Gfo_thread_itm)list.Get_at(i);
if (itm.Thread__can_delete(key))
deleted.Add(itm);
}
len = deleted.Len();
for (int i = 0; i < len; ++i) {
Gfo_thread_itm itm = (Gfo_thread_itm)deleted.Get_at(i);
itm.Thread__stop();
list.Del(itm);
}
}
}
private void Run_wkr(Gfo_thread_itm itm) {
try {itm.Thread__exec();}
catch (Exception e) {Gfo_usr_dlg_.Instance.Warn_many("", "", "uncaught exception while running thread; name=~{0} err=~{1}", itm.Thread__name(), Err_.Message_gplx_log(e));}
finally {
synchronized (thread_lock) {
--active_cur;
}
this.Run();
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run_wkr)) Run_wkr((Gfo_thread_itm)m.ReadObj("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_run_wkr = "run_wkr";
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.core.threads; import gplx.*; import gplx.core.*;
public interface Gfo_thread_itm {
String Thread__name();
void Thread__exec();
void Thread__stop();
boolean Thread__can_delete(String key);
}

View File

@@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.core.threads; import gplx.*; import gplx.core.*;
public class Gfo_thread_mgr {
private final Ordered_hash hash = Ordered_hash_.New();
public Gfo_thread_grp Get_by_or_new(String k) {
Gfo_thread_grp rv = (Gfo_thread_grp)hash.Get_by(k);
if (rv == null) {
rv = new Gfo_thread_grp(k);
hash.Add(k, rv);
}
return rv;
}
public void Stop_all() {
int len = hash.Len();
for (int i = 0; i < len; ++i) {
Gfo_thread_grp grp = (Gfo_thread_grp)hash.Get_at(i);
grp.Stop_all();
}
hash.Clear();
}
}