X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Flauncher%2FMain.java;h=29cf8a699bcfde3c62d768a85a8e520077af3992;hp=b57a0f758711af87176d90d560f78d13b7fb0eac;hb=30a4aa17f2141ad80a23447ee2e6303f6c9ef995;hpb=f29274a79cd091262b65411ce81127b9de47f9b6 diff --git a/src/be/nikiroo/jvcard/launcher/Main.java b/src/be/nikiroo/jvcard/launcher/Main.java index b57a0f7..29cf8a6 100644 --- a/src/be/nikiroo/jvcard/launcher/Main.java +++ b/src/be/nikiroo/jvcard/launcher/Main.java @@ -7,6 +7,8 @@ import java.net.Socket; import java.nio.charset.Charset; import java.util.LinkedList; import java.util.List; +import java.util.MissingResourceException; +import java.util.ResourceBundle; import javax.imageio.ImageIO; @@ -40,6 +42,9 @@ public class Main { static private final int ERR_INTERNAL = 3; static private Trans transService; + static private String defaultFn; + static private boolean forceComputedFn; + enum Mode { CONTACT_MANAGER, I18N, SERVER, LOAD_PHOTO, SAVE_PHOTO, ONLY_PHOTO, } @@ -262,6 +267,9 @@ public class Main { utf8(); } + // N/FN fix information: + readNFN(); + // Error management: if (mode == Mode.SERVER && files.size() > 0) { System.err @@ -400,7 +408,11 @@ public class Main { /** * Return the {@link Card} corresponding to the given resource name -- a - * file or a remote jvcard URL + * file or a remote jvcard URL. + * + *

+ * Will also fix the FN if required (see display.properties). + *

* * @param input * a filename or a remote jvcard url with named resource (e.g.: @@ -446,6 +458,22 @@ public class Main { 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; } @@ -536,4 +564,29 @@ public class Main { } 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() { + ResourceBundle map = Bundles.getBundle("display"); + try { + defaultFn = map.getString("CONTACT_DETAILS_DEFAULT_FN"); + if (defaultFn.trim().length() == 0) + defaultFn = null; + } catch (MissingResourceException e) { + e.printStackTrace(); + } + + try { + String forceComputedFnStr = map + .getString("CONTACT_DETAILS_SHOW_COMPUTED_FN"); + if (forceComputedFnStr.length() > 0 + && forceComputedFnStr.equalsIgnoreCase("true")) + forceComputedFn = true; + } catch (MissingResourceException e) { + e.printStackTrace(); + } + } }