Changeset 6530 for trunk/gli


Ignore:
Timestamp:
2004-01-16T15:48:42+13:00 (20 years ago)
Author:
jmt12
Message:

Extended configuration to store details about the current previewing software, and streamlined determining the language

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/Configuration.java

    r6389 r6530  
    9898    /** The username for the proxy server indicated above. */
    9999    public String proxy_user = null;
    100     /** The language selected for the interface. Currently hard-wired. */
    101     public String interface_language = "en";
    102100    /** The screen size of the desktop the Gatherer will be displayed on. */
    103101    public Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
     
    177175    }
    178176
    179     // Try to reload the configuration.
    180     File config_xml = new File(CONFIG_XML);
    181     if(config_xml.exists()) {
    182         general_config = Utility.parse(CONFIG_XML, false);
    183     }
    184     // If that fails retrieve the default configuration file from our xml library, which I'll personally guarantee to work.
     177    // Try to reload the configuration. The first place we look is the user specific location
     178    File user_config_xml = null;
     179    // Windows. What to do, what to do?
     180    if(Utility.isWindows()) {
     181       
     182    }
     183    // Unix based systems. This one I know. Look for .gli/config.xml in the users home folder
     184    else {
     185        user_config_xml = new File(System.getProperty("user.home") + File.separator + ".gli" + File.separator + CONFIG_XML);       
     186    }
     187    if(user_config_xml != null && user_config_xml.exists()) {
     188        general_config = Utility.parse(user_config_xml.getAbsolutePath(), false);
     189    }
     190
     191    // We then try within the gli directory itself
     192    if(general_config == null) {
     193        File config_xml = new File(CONFIG_XML);
     194        if(config_xml.exists()) {
     195        general_config = Utility.parse(CONFIG_XML, false);
     196        }
     197    }
     198
     199    // And if that fails retrieve the default configuration file from our xml library, which I'll personally guarantee to work.
    185200    if(general_config == null) {
    186201        general_config = Utility.parse(TEMPLATE_CONFIG_XML, true);
     
    437452    }
    438453    return result;
     454    }
     455
     456    /** Retrieves the current interface language two letter code. */
     457    public String getLanguage() {
     458    Locale locale = getLocale("general.locale", GENERAL_SETTING);
     459    String code = "en"; // Default
     460    if(locale != null) {
     461        code = locale.getLanguage();
     462    }
     463    return code;
    439464    }
    440465
     
    489514    }
    490515
     516    public String getPreviewCommand() {
     517    return getString("general.preview_program", GENERAL_SETTING);
     518    }
     519
    491520    /** Retrieve the value of the named property, and noting whether we consult the general or collection specific configuration. */
    492521    public String getString(String property, boolean general) {
     
    576605    public void save() {
    577606    ///ystem.err.println("Hits " + cache_hit + " vs Misses " + cache_miss);
    578     Utility.export(general_config, Utility.BASE_DIR + CONFIG_XML);
     607    // We first try exporting to a user specific place
     608    File user_config_xml = null;
     609    try {
     610        if(Utility.isWindows()) {
     611       
     612        }
     613        // Unix systems save user preferences in . folders in the home directory.
     614        else {
     615        user_config_xml = new File(System.getProperty("user.home") + File.separator + ".gli" + File.separator + CONFIG_XML);
     616        ///ystem.err.println("Trying to save to: " + user_config_xml.getAbsolutePath());
     617        ///ystem.err.println("Writing.");
     618        user_config_xml.getParentFile().mkdirs();
     619        Utility.export(general_config, user_config_xml.getAbsolutePath());
     620        }
     621    }
     622    catch(Exception exception) {
     623        user_config_xml = null;
     624    }
     625    // Always do this if the above fails.
     626    if(user_config_xml == null || !user_config_xml.exists()) {
     627        // But failing that we produce a general copy
     628        Utility.export(general_config, Utility.BASE_DIR + CONFIG_XML);
     629    }
    579630    }
    580631
     
    711762    public void setMode(int value) {
    712763    setInt("general.mode", GENERAL_SETTING, value);
     764    }
     765
     766    public void setPreviewCommand(String value) {
     767    setString("general.preview_program", GENERAL_SETTING, value);
    713768    }
    714769
Note: See TracChangeset for help on using the changeset viewer.