OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
 * 
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
 * language governing permissions and limitations under the License.
 * 
 * When distributing the software, include this License Header Notice in each file.
 */
 
 package org.openconcerto.ui.preferences;

import org.openconcerto.utils.FileUtils;

import java.io.File;
import java.io.IOException;

public class EmailProps extends AbstractProps {
    public static final int DEFAULT = 0;
    public static final int THUNDERBIRD = 1;
    public static final int OUTLOOK = 2;
    protected static EmailProps instance;
    private String propsFileName = null;
    private static String DEFAULT_FILE = "./Configuration/Email.properties";
    private String defaultPropsFileName = DEFAULT_FILE;

    public synchronized static EmailProps getInstance() {
        if (instance == null) {
            instance = new EmailProps();
        }
        return instance;
    }

    @Override
    protected String getPropsFileName() {
        if (this.propsFileName == null) {
            return getDefaultPropsFileName();
        } else {
            return this.propsFileName;
        }
    }

    public void setDefaultPropsFileName(String defaultPropsFileName) {
        this.defaultPropsFileName = defaultPropsFileName;
    }

    protected String getDefaultPropsFileName() {
        if (this.defaultPropsFileName == null) {
            return DEFAULT_FILE;
        } else {
            return defaultPropsFileName;
        }
    }

    public void setPropsFileName(String propsFileName) {
        this.propsFileName = propsFileName;
        final File file = new File(getPropsFileName());
        final File fileDefault = new File(getDefaultPropsFileName());
        if (!file.exists() && fileDefault.exists()) {
            try {
                FileUtils.copyFile(fileDefault, file);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        load();
    }

    public String getThunderbirdPath() {
        final String stringProperty = this.getStringProperty("thunderbird.path");
        if (stringProperty.trim().length() == 0) {
            return "C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe";
        }
        return stringProperty;
    }

    public void setThunderbirdPath(String text) {
        this.setProperty("thunderbird.path", text);
    }

    public int getMode() {
        return this.getIntProperty("mode", DEFAULT);
    }

    public void setMode(int mode) {
        this.setProperty("mode", String.valueOf(mode));
    }

    public void setTitle(String text) {
        this.setProperty("title", String.valueOf(text));
    }

    public String getTitle() {
        return this.getStringProperty("title");
    }

    public void setHeader(String text) {
        this.setProperty("header", String.valueOf(text));
    }

    public String getHeader() {
        return this.getStringProperty("header");
    }

    public void setFooter(String text) {
        this.setProperty("footer", String.valueOf(text));
    }

    public void setEncodingCharsetName(String charset) {
        this.setProperty("encoding", charset);
    }

    public String getFooter() {
        return this.getStringProperty("footer");
    }

    public String getEncodingCharsetName() {
        String charset = "UTF-8";
        String tmp = this.getStringProperty("encoding");
        if (tmp.trim().length() > 0) {
            charset = tmp;
        }
        return charset;
    }
}