import be.nikiroo.jvcard.remote.SimpleSocket;
import be.nikiroo.jvcard.resources.Bundles;
import be.nikiroo.jvcard.resources.StringUtils;
-import be.nikiroo.jvcard.resources.Trans;
-import be.nikiroo.jvcard.resources.Trans.StringId;
+import be.nikiroo.jvcard.resources.bundles.ColorBundle;
+import be.nikiroo.jvcard.resources.bundles.DisplayBundle;
+import be.nikiroo.jvcard.resources.bundles.RemoteBundle;
+import be.nikiroo.jvcard.resources.bundles.TransBundle;
+import be.nikiroo.jvcard.resources.enums.DisplayOption;
+import be.nikiroo.jvcard.resources.enums.StringId;
/**
* This class contains the runnable Main method. It will parse the user supplied
static private final int ERR_NO_FILE = 1;
static private final int ERR_SYNTAX = 2;
static private final int ERR_INTERNAL = 3;
- static private Trans transService;
+ static private TransBundle transService;
+
+ static private String defaultFn;
+ static private boolean forceComputedFn;
enum Mode {
- CONTACT_MANAGER, I18N, SERVER, LOAD_PHOTO, SAVE_PHOTO, ONLY_PHOTO,
+ CONTACT_MANAGER, I18N, SERVER, LOAD_PHOTO, SAVE_PHOTO, ONLY_PHOTO, SAVE_CONFIG
}
/**
*
* @return the translated text with the given value where required
*/
- static public String trans(StringId id, String... values) {
- return transService.trans(id, (String[]) values);
+ static public String trans(StringId id, Object... values) {
+ return transService.getString(id, (Object[]) values);
}
/**
// get the "system default" language to help translate the --help
// message if needed
String language = null;
- transService = new Trans(language);
+ transService = new TransBundle(language);
boolean unicode = transService.isUnicode();
String dir = null;
+ "\t--tui: force pure text mode even if swing treminal is available\n"
+ "\t--gui: force swing terminal mode\n"
+ "\t--noutf: force non-utf8 mode if you need it\n"
- + "\t--config DIRECTORY: force the given directory as a CONFIG_DIR\n"
+ + "\t--config DIRECTORY: use the given directory as a CONFIG_DIR\n"
+ + "\t--save-config DIRECTORY: save the current config to DIRECTORY (lang: only current)\n"
+ "\t--server PORT: start a remoting server instead of a client\n"
+ "\t--i18n DIR: generate the translation file for the given language (can be \"\") to/from the .properties given dir\n"
+ "\t--save-photo DIR FORMAT: save the contacts' photos to DIR, named after FORMAT\n"
}
language = args[index];
- transService = new Trans(language);
+ transService = new TransBundle(language);
transService.setUnicode(unicode);
} else if (!noMoreParams && arg.equals("--config")) {
index++;
}
Bundles.setDirectory(args[index]);
- transService = new Trans(language);
+ transService = new TransBundle(language);
transService.setUnicode(unicode);
+ } else if (!noMoreParams && arg.equals("--save-config")) {
+ index++;
+ if (index >= args.length) {
+ System.err
+ .println("Syntax error: no config directory given");
+ System.exit(ERR_SYNTAX);
+ return;
+ }
+ dir = args[index];
+
+ if (mode != Mode.CONTACT_MANAGER) {
+ System.err
+ .println("Syntax error: you can only use one of: \n"
+ + "--server\n"
+ + "--save-config\n"
+ + "--i18n\n"
+ + "--load-photo\n"
+ + "--save-photo\n" + "--only-photo\n");
+ System.exit(ERR_SYNTAX);
+ return;
+ }
+ mode = Mode.SAVE_CONFIG;
} else if (!noMoreParams && arg.equals("--server")) {
if (mode != Mode.CONTACT_MANAGER) {
System.err
.println("Syntax error: you can only use one of: \n"
+ "--server\n"
+ + "--save-config\n"
+ "--i18n\n"
+ "--load-photo\n"
- + "--save-photo\n"
- + "--only-photo\n");
+ + "--save-photo\n" + "--only-photo\n");
System.exit(ERR_SYNTAX);
return;
}
System.err
.println("Syntax error: you can only use one of: \n"
+ "--server\n"
+ + "--save-config\n"
+ "--i18n\n"
+ "--load-photo\n"
- + "--save-photo\n"
- + "--only-photo\n");
+ + "--save-photo\n" + "--only-photo\n");
System.exit(ERR_SYNTAX);
return;
}
System.err
.println("Syntax error: you can only use one of: \n"
+ "--server\n"
+ + "--save-config\n"
+ "--i18n\n"
+ "--load-photo\n"
- + "--save-photo\n"
- + "--only-photo\n");
+ + "--save-photo\n" + "--only-photo\n");
System.exit(ERR_SYNTAX);
return;
}
utf8();
}
+ // N/FN fix information:
+ readNFN();
+
// Error management:
if (mode == Mode.SERVER && files.size() > 0) {
System.err
//
switch (mode) {
+ case SAVE_CONFIG: {
+ try {
+ if (!new File(dir).isDirectory()) {
+ if (!new File(dir).mkdir()) {
+ System.err
+ .println("Cannot create configuration directory: "
+ + dir);
+ }
+ }
+
+ transService.updateFile(dir); // current lang TransBundle
+ new TransBundle().updateFile(dir);
+ new ColorBundle().updateFile(dir);
+ new DisplayBundle().updateFile(dir);
+ new RemoteBundle().updateFile(dir);
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.exit(ERR_INTERNAL);
+ }
+ break;
+ }
case SERVER: {
try {
Optional.runServer(port);
}
case I18N: {
try {
- Trans.generateTranslationFile(dir, language);
+ transService.updateFile(dir);
} catch (IOException e) {
System.err
.println("I/O Exception: Cannot create/update a language in directory: "
+ dir);
+ e.printStackTrace();
}
break;
}
/**
* Return the {@link Card} corresponding to the given resource name -- a
- * file or a remote jvcard URL
+ * file or a remote jvcard URL.
+ *
+ * <p>
+ * Will also fix the FN if required (see display.properties).
+ * </p>
*
* @param input
* a filename or a remote jvcard url with named resource (e.g.:
throw new IOException("Remoting support not available", e);
}
+ // Fix the FN value
+ if (defaultFn != null) {
+ try {
+ for (Contact contact : card.getCard()) {
+ Data name = contact.getPreferredData("FN");
+ if (name == null || name.getValue().length() == 0
+ || forceComputedFn) {
+ name.setValue(contact.toString(defaultFn, ""));
+ }
+ }
+ } catch (Exception e) {
+ // sync failed -> getCard() throws.
+ // do not update.
+ }
+ }
+
return card;
}
} catch (IllegalAccessException e) {
}
}
+
+ /**
+ * Read display.properties to know if we should fix the FN field when empty,
+ * or always, or never.
+ */
+ static private void readNFN() {
+ DisplayBundle map = new DisplayBundle();
+
+ defaultFn = map.getString(DisplayOption.CONTACT_DETAILS_DEFAULT_FN);
+
+ forceComputedFn = map.getBoolean(
+ DisplayOption.CONTACT_DETAILS_SHOW_COMPUTED_FN, false);
+ }
}