+ public void setSourceCover(final String source, final String luid) {
+ setCover(source, luid, "SOURCE");
+ }
+
+ @Override
+ public void setAuthorCover(final String author, final String luid) {
+ setCover(author, luid, "AUTHOR");
+ }
+
+ // type = "SOURCE" | "AUTHOR"
+ private void setCover(final String value, final String luid,
+ final String type) {
+ try {
+ new ConnectActionClientObject(host, port, false) {
+ @Override
+ public void action(Version serverVersion) throws Exception {
+ sendCmd(this,
+ new Object[] { "SET_COVER", type, value, luid });
+ }
+
+ @Override
+ protected void onError(Exception e) {
+ Instance.getTraceHandler().error(e);
+ }
+ }.connect();
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ }
+ }
+
+ @Override
+ // Could work (more slowly) without it
+ public Story imprt(final URL url, Progress pg) throws IOException {
+ // Import the file locally if it is actually a file
+ if (url == null || url.getProtocol().equalsIgnoreCase("file")) {
+ return super.imprt(url, pg);
+ }
+
+ // Import it remotely if it is an URL
+
+ 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, false) {
+ @Override
+ public void action(Version serverVersion) throws Exception {
+ Progress pg = pgF;
+
+ Object rep = sendCmd(this,
+ new Object[] { "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
+ protected synchronized void changeSTA(final String luid,
+ final String newSource, final String newTitle,
+ final String newAuthor, Progress pg) throws IOException {
+ final Progress pgF = pg == null ? new Progress() : pg;
+
+ try {
+ new ConnectActionClientObject(host, port, false) {
+ @Override
+ public void action(Version serverVersion) throws Exception {
+ Progress pg = pgF;
+
+ Object rep = sendCmd(this, new Object[] { "CHANGE_STA",
+ luid, newSource, newTitle, newAuthor });
+ 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);
+ }