+ // Could work (more slowly) without it
+ public Story imprt(final URL url, Progress pg) throws IOException {
+ if (pg == null) {
+ pg = new Progress();
+ }
+
+ pg.setMinMax(0, 2);
+ Progress pgImprt = new Progress();
+ Progress pgGet = new Progress();
+ pg.addProgress(pgImprt, 1);
+ pg.addProgress(pgGet, 1);
+
+ final Progress pgF = pgImprt;
+ final String[] luid = new String[1];
+
+ try {
+ new ConnectActionClientObject(host, port, true) {
+ @Override
+ public void action(Version serverVersion) throws Exception {
+ Progress pg = pgF;
+
+ Object rep = send(new Object[] { md5, "IMPORT",
+ url.toString() });
+
+ while (true) {
+ if (!RemoteLibraryServer.updateProgress(pg, rep)) {
+ break;
+ }
+
+ rep = send(null);
+ }
+
+ pg.done();
+ luid[0] = (String) rep;
+ }
+
+ @Override
+ protected void onError(Exception e) {
+ Instance.getTraceHandler().error(e);
+ }
+ }.connect();
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ }
+
+ if (luid[0] == null) {
+ throw new IOException("Remote failure");
+ }
+
+ Story story = getStory(luid[0], pgGet);
+ pgGet.done();
+
+ pg.done();
+ return story;
+ }
+
+ @Override
+ // Could work (more slowly) without it
+ public synchronized void changeSource(final String luid,
+ final String newSource, Progress pg) throws IOException {
+ final Progress pgF = pg == null ? new Progress() : pg;
+
+ try {
+ new ConnectActionClientObject(host, port, true) {
+ @Override
+ public void action(Version serverVersion) throws Exception {
+ Progress pg = pgF;
+
+ Object rep = send(new Object[] { md5, "CHANGE_SOURCE",
+ luid, newSource });
+ while (true) {
+ if (!RemoteLibraryServer.updateProgress(pg, rep)) {
+ break;
+ }
+
+ rep = send(null);
+ }
+ }
+
+ @Override
+ protected void onError(Exception e) {
+ Instance.getTraceHandler().error(e);
+ }
+ }.connect();
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ }