Search in sources :

Example 1 with IMonitor

use of de.janrufmonitor.framework.monitor.IMonitor in project janrufmonitor by tbrandt77.

the class FritzBoxVoip method createFieldEditors.

protected void createFieldEditors() {
    StringFieldEditor sfe = null;
    BooleanFieldEditor bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "activemonitor", this.m_i18n.getString(this.getNamespace(), "activemonitor", "label", this.m_language), this.getFieldEditorParent());
    addField(bfe);
    if (isExpertMode()) {
        bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "outgoing", this.m_i18n.getString(this.getNamespace(), "outgoing", "label", this.m_language), this.getFieldEditorParent());
        addField(bfe);
        sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxip", this.m_i18n.getString(this.getNamespace(), "boxip", "label", this.m_language), this.getFieldEditorParent());
        sfe.setEmptyStringAllowed(false);
        addField(sfe);
    }
    mode = new ComboFieldEditor(getConfigNamespace() + SEPARATOR + "boxloginmode", this.m_i18n.getString(this.getNamespace(), "boxloginmode", "label", this.m_language), new String[][] { { this.m_i18n.getString(this.getNamespace(), "userpassword", "label", this.m_language), "0" }, { this.m_i18n.getString(this.getNamespace(), "password_only", "label", this.m_language), "1" } }, this.getFieldEditorParent());
    addField(mode);
    this.user = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxuser", this.m_i18n.getString(this.getNamespace(), "boxuser", "label", this.m_language), this.getFieldEditorParent());
    addField(this.user);
    String state = this.getPreferenceStore().getString(getConfigNamespace() + SEPARATOR + "boxloginmode");
    if (state.equalsIgnoreCase("1")) {
        this.user.setEnabled(false, this.getFieldEditorParent());
        this.user.getTextControl(getFieldEditorParent()).setBackground(new Color(DisplayManager.getDefaultDisplay(), 190, 190, 190));
        this.user.setStringValue("");
    }
    sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxpassword", this.m_i18n.getString(this.getNamespace(), "boxpassword", "label", this.m_language), this.getFieldEditorParent());
    sfe.getTextControl(this.getFieldEditorParent()).setEchoChar('*');
    addField(sfe);
    if (isExpertMode()) {
        IntegerFieldEditor ife = new IntegerFieldEditor(getConfigNamespace() + SEPARATOR + "retrymax", this.m_i18n.getString(this.getNamespace(), "retrymax", "label", this.m_language), this.getFieldEditorParent());
        ife.setTextLimit(3);
        addField(ife);
        ife = new IntegerFieldEditor(getConfigNamespace() + SEPARATOR + "retrytimeouts", this.m_i18n.getString(this.getNamespace(), "retrytimeouts", "label", this.m_language), this.getFieldEditorParent());
        ife.setTextLimit(3);
        addField(ife);
        bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "tr064off", this.m_i18n.getString(this.getNamespace(), "tr064off", "label", this.m_language), this.getFieldEditorParent());
        addField(bfe);
        new Label(this.getFieldEditorParent(), SWT.NULL);
        new Label(this.getFieldEditorParent(), SWT.NULL);
        ComboFieldEditor cfe = new ComboFieldEditor(getConfigNamespace() + SEPARATOR + "boxclickdial", this.m_i18n.getString(this.getNamespace(), "boxclickdial", "label", this.m_language), new String[][] { { this.m_i18n.getString(this.getNamespace(), "manual", "label", this.m_language), "0" }, { this.m_i18n.getString(this.getNamespace(), "all_analog", "label", this.m_language), "9" }, { this.m_i18n.getString(this.getNamespace(), "all_isdn", "label", this.m_language), "50" }, { "FON 1", "1" }, { "FON 2", "2" }, { "FON 3", "3" }, { "ISDN 1", "51" }, { "ISDN 2", "52" }, { "ISDN 3", "53" }, { "ISDN 4", "54" }, { "ISDN 5", "55" }, { "ISDN 6", "56" }, { "ISDN 7", "57" }, { "ISDN 8", "58" }, { "ISDN 9", "59" }, { "DECT 610", "60" }, { "DECT 611", "61" }, { "DECT 612", "62" }, { "DECT 613", "63" }, { "DECT 614", "64" }, { "DECT 615", "65" } }, this.getFieldEditorParent());
        addField(cfe);
        sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "dialprefixes", this.m_i18n.getString(this.getNamespace(), "dialprefixes", "label", this.m_language), this.getFieldEditorParent());
        sfe.setEmptyStringAllowed(true);
        addField(sfe);
        new Label(this.getFieldEditorParent(), SWT.NULL);
        new Label(this.getFieldEditorParent(), SWT.NULL);
    }
    IMonitor fbMonitor = this.getRuntime().getMonitorListener().getMonitor("FritzBoxMonitor");
    if (fbMonitor != null) {
        String[] fbInfos = fbMonitor.getDescription();
        Label capi_label = new Label(this.getFieldEditorParent(), 0);
        capi_label.setText(this.m_i18n.getString(this.getNamespace(), "fbinfo", "label", this.m_language));
        for (int i = 0; i < fbInfos.length; i++) {
            if (fbInfos[i].trim().length() > 0) {
                Label capi = new Label(this.getFieldEditorParent(), SWT.NULL);
                capi.setText(fbInfos[i]);
                new Label(this.getFieldEditorParent(), SWT.NULL);
            }
        }
    }
    new Label(this.getFieldEditorParent(), SWT.NULL);
    Label statusl = new Label(this.getFieldEditorParent(), 0);
    statusl.setText(this.m_i18n.getString(this.getNamespace(), "status", "label", this.m_language));
    Label status_observer = new Label(this.getFieldEditorParent(), SWT.NULL);
    status_observer.setText(this.m_i18n.getString(this.getNamespace(), "statuso", "label", this.m_language) + ((fbMonitor != null && fbMonitor.isStarted()) ? "OK" : "---"));
    new Label(this.getFieldEditorParent(), SWT.NULL);
    FirmwareManager fwm = FirmwareManager.getInstance();
    fwm.startup();
    if (fwm.isLoggedIn() && !fwm.isInstance(TR064FritzBoxFirmware.class)) {
        Label status_sync = new Label(this.getFieldEditorParent(), SWT.NULL);
        status_sync.setText(this.m_i18n.getString(this.getNamespace(), "statuss", "label", this.m_language) + (fwm.isLoggedIn() ? "OK" : "---"));
        new Label(this.getFieldEditorParent(), SWT.NULL);
        if (fbMonitor != null && fbMonitor.isStarted() && fwm.isLoggedIn()) {
            // set icon to colored
            IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
            try {
                Method m = tray.getClass().getMethod("setIconStateActive", new Class[] {});
                if (m != null) {
                    m.invoke(tray, new Object[] {});
                }
            } catch (Exception ex) {
            }
        }
        if ((fbMonitor == null || !fbMonitor.isStarted()) && !fwm.isLoggedIn()) {
            // set icon to colored
            IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
            try {
                Method m = tray.getClass().getMethod("setIconStateInactive", new Class[] {});
                if (m != null) {
                    m.invoke(tray, new Object[] {});
                }
            } catch (Exception ex) {
            }
        }
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.swt.widgets.Label) BooleanFieldEditor(de.janrufmonitor.ui.jface.configuration.controls.BooleanFieldEditor) Method(java.lang.reflect.Method) ComboFieldEditor(org.eclipse.jface.preference.ComboFieldEditor) IMonitor(de.janrufmonitor.framework.monitor.IMonitor) StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) IntegerFieldEditor(org.eclipse.jface.preference.IntegerFieldEditor) IService(de.janrufmonitor.service.IService)

Example 2 with IMonitor

use of de.janrufmonitor.framework.monitor.IMonitor in project janrufmonitor by tbrandt77.

the class CapiInfo method createContents.

protected Control createContents(Composite parent) {
    this.setTitle(this.m_i18n.getString(this.getNamespace(), "title", "label", this.m_language));
    this.noDefaultAndApplyButton();
    Composite c = new Composite(parent, SWT.NONE);
    c.setLayout(new GridLayout(2, false));
    IMonitor capiMonitor = this.getRuntime().getMonitorListener().getMonitor("CapiMonitor");
    if (capiMonitor != null) {
        String[] capiInfos = capiMonitor.getDescription();
        Label capi_label = new Label(c, 0);
        capi_label.setText(this.m_i18n.getString(this.getNamespace(), "capiinfo", "label", this.m_language));
        for (int i = capiInfos.length - 1; i >= 0; i--) {
            if (capiInfos[i].trim().length() > 0 && !capiInfos[i].startsWith("PIM") && !capiInfos[i].startsWith("0000")) {
                Label capi = new Label(c, SWT.NULL);
                capi.setText(capiInfos[i]);
                capi = new Label(c, SWT.NULL);
            }
        }
    } else {
        this.m_logger.warning("No CAPI monitor object found.");
    }
    return c;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) IMonitor(de.janrufmonitor.framework.monitor.IMonitor)

Example 3 with IMonitor

use of de.janrufmonitor.framework.monitor.IMonitor in project janrufmonitor by tbrandt77.

the class InitFritzBoxVariantPage method performFinish.

public boolean performFinish() {
    if (m_boxip == null || m_boxip.trim().length() == 0) {
        try {
            Thread.sleep(550);
        } catch (InterruptedException e) {
            m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
        return true;
    }
    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(FritzBoxMonitor.NAMESPACE, "boxip", m_boxip);
    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(FritzBoxMonitor.NAMESPACE, "boxpassword", m_boxpassword);
    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(FritzBoxMonitor.NAMESPACE, "boxuser", m_boxuser);
    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(FritzBoxMonitor.NAMESPACE, "activemonitor", (m_active ? "true" : "false"));
    getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        return false;
    }
    getRuntime().getConfigurableNotifier().notifyByNamespace(FritzBoxMonitor.NAMESPACE);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        return false;
    }
    if (m_active && !getRuntime().getMonitorListener().isRunning()) {
        getRuntime().getMonitorListener().start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            m_logger.log(Level.SEVERE, e.getMessage(), e);
            return false;
        }
        ICommand c = PIMRuntime.getInstance().getCommandFactory().getCommand("Activator");
        if (c != null) {
            try {
                Map m = new HashMap();
                IMonitor mon = getRuntime().getMonitorListener().getDefaultMonitor();
                m.put("status", (mon.isStarted() ? "revert" : "invert"));
                // this method executes the command as well !!
                c.setParameters(m);
            } catch (Exception e) {
                m_logger.log(Level.SEVERE, e.toString(), e);
            }
        }
    }
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        return false;
    }
    // save MSN settings
    if (m_usemsns) {
        FirmwareManager fwm = FirmwareManager.getInstance();
        fwm.startup();
        try {
            if (!fwm.isLoggedIn())
                fwm.login();
            Map msns = fwm.getMSNMap();
            if (msns != null && msns.size() > 0) {
                StringBuffer list = new StringBuffer();
                Iterator i = msns.keySet().iterator();
                String msn = null;
                while (i.hasNext()) {
                    msn = (String) i.next();
                    list.append(msn);
                    list.append(",");
                    getRuntime().getConfigManagerFactory().getConfigManager().setProperty("manager.MsnManager", msn + "_msn", msn);
                    getRuntime().getConfigManagerFactory().getConfigManager().setProperty("manager.MsnManager", msn + "_label", (String) msns.get(msn));
                }
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty("manager.MsnManager", "list", list.toString());
                getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
            }
        } catch (IOException e) {
            m_logger.log(Level.SEVERE, e.toString(), e);
        } catch (FritzBoxLoginException e) {
            m_logger.log(Level.SEVERE, e.toString(), e);
        }
    }
    return true;
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) HashMap(java.util.HashMap) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) ICommand(de.janrufmonitor.framework.command.ICommand) Iterator(java.util.Iterator) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) IMonitor(de.janrufmonitor.framework.monitor.IMonitor) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) IOException(java.io.IOException)

Example 4 with IMonitor

use of de.janrufmonitor.framework.monitor.IMonitor in project janrufmonitor by tbrandt77.

the class HibernateDetector method startup.

public void startup() {
    super.startup();
    if (isEnabled()) {
        this.isHibernateChecking = true;
        Thread t = new Thread(new Runnable() {

            public void run() {
                // check file system
                File trackFolder = new File(PathResolver.getInstance(getRuntime()).getLogDirectory(), "~" + ID.toLowerCase());
                if (!trackFolder.exists())
                    trackFolder.mkdirs();
                m_logger.info("Hibernate tracking directory: " + trackFolder.getAbsolutePath());
                // clear folder if exists
                File[] files = trackFolder.listFiles();
                for (int i = 0; i < files.length; i++) {
                    files[i].delete();
                }
                File pid = null;
                while (isHibernateChecking) {
                    pid = new File(trackFolder, Long.toString(System.currentTimeMillis()));
                    try {
                        pid.createNewFile();
                    } catch (IOException e) {
                        m_logger.log(Level.SEVERE, e.toString(), e);
                    }
                    try {
                        Thread.sleep(getDelayTime());
                    } catch (InterruptedException e) {
                        m_logger.log(Level.SEVERE, e.toString(), e);
                    }
                    // check if time stamps are there
                    files = trackFolder.listFiles();
                    if (files.length == 0) {
                        isHibernateChecking = false;
                        continue;
                    }
                    if (files.length == 1) {
                        try {
                            long l = Long.parseLong(files[0].getName());
                            long result = System.currentTimeMillis() - l;
                            m_logger.info("Delta hibernate detection time (ms): " + result);
                            if (result > (2 * getDelayTime()) && PIMRuntime.getInstance().getMonitorListener().getMonitors().size() > 0) {
                                if (((IMonitor) PIMRuntime.getInstance().getMonitorListener().getMonitors().get(0)).getID().equalsIgnoreCase("FritzBoxMonitor")) {
                                    m_logger.info("Detected FritzBoxMonitor for re-connect...");
                                    reconnectFritzBox();
                                } else {
                                    m_logger.info("Detected CAPI/TAPI for re-connect...");
                                    reconnectCapiTapi();
                                }
                            }
                        } catch (Exception e) {
                            m_logger.log(Level.SEVERE, e.toString(), e);
                        }
                    }
                    for (int i = 0; i < files.length; i++) {
                        files[i].delete();
                    }
                }
            }
        });
        t.setDaemon(true);
        t.setName("JAM-" + ID + "-Thread-(deamon)");
        t.start();
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) IMonitor(de.janrufmonitor.framework.monitor.IMonitor) IOException(java.io.IOException)

Example 5 with IMonitor

use of de.janrufmonitor.framework.monitor.IMonitor in project janrufmonitor by tbrandt77.

the class NcidVoip method createFieldEditors.

protected void createFieldEditors() {
    StringFieldEditor sfe = null;
    BooleanFieldEditor bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "activemonitor", this.m_i18n.getString(this.getNamespace(), "activemonitor", "label", this.m_language), this.getFieldEditorParent());
    addField(bfe);
    if (isExpertMode()) {
        bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "outgoing", this.m_i18n.getString(this.getNamespace(), "outgoing", "label", this.m_language), this.getFieldEditorParent());
        addField(bfe);
    }
    sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxip", this.m_i18n.getString(this.getNamespace(), "boxip", "label", this.m_language), this.getFieldEditorParent());
    sfe.setEmptyStringAllowed(false);
    addField(sfe);
    if (isExpertMode()) {
        sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxmport", this.m_i18n.getString(this.getNamespace(), "boxmport", "label", this.m_language), this.getFieldEditorParent());
        sfe.setEmptyStringAllowed(false);
        addField(sfe);
        sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "festnetzalias", this.m_i18n.getString(this.getNamespace(), "festnetzalias", "label", this.m_language), this.getFieldEditorParent());
        sfe.setEmptyStringAllowed(true);
        addField(sfe);
        IntegerFieldEditor ife = new IntegerFieldEditor(getConfigNamespace() + SEPARATOR + "retrymax", this.m_i18n.getString(this.getNamespace(), "retrymax", "label", this.m_language), this.getFieldEditorParent());
        ife.setTextLimit(2);
        addField(ife);
        bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "sync_cidlog", this.m_i18n.getString(this.getNamespace(), "sync_cidlog", "label", this.m_language), this.getFieldEditorParent());
        addField(bfe);
    }
    IMonitor fbMonitor = this.getRuntime().getMonitorListener().getMonitor("NcidMonitor");
    if (fbMonitor != null) {
        String[] fbInfos = fbMonitor.getDescription();
        Label capi_label = new Label(this.getFieldEditorParent(), 0);
        capi_label.setText(this.m_i18n.getString(this.getNamespace(), "fbinfo", "label", this.m_language));
        for (int i = 0; i < fbInfos.length; i++) {
            if (fbInfos[i].trim().length() > 0) {
                Label capi = new Label(this.getFieldEditorParent(), SWT.NULL);
                capi.setText(fbInfos[i]);
                new Label(this.getFieldEditorParent(), SWT.NULL);
            }
        }
    }
}
Also used : StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) Label(org.eclipse.swt.widgets.Label) IntegerFieldEditor(org.eclipse.jface.preference.IntegerFieldEditor) BooleanFieldEditor(de.janrufmonitor.ui.jface.configuration.controls.BooleanFieldEditor) IMonitor(de.janrufmonitor.framework.monitor.IMonitor)

Aggregations

IMonitor (de.janrufmonitor.framework.monitor.IMonitor)6 Label (org.eclipse.swt.widgets.Label)4 BooleanFieldEditor (de.janrufmonitor.ui.jface.configuration.controls.BooleanFieldEditor)3 StringFieldEditor (org.eclipse.jface.preference.StringFieldEditor)3 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)2 IOException (java.io.IOException)2 IntegerFieldEditor (org.eclipse.jface.preference.IntegerFieldEditor)2 ICommand (de.janrufmonitor.framework.command.ICommand)1 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)1 IService (de.janrufmonitor.service.IService)1 File (java.io.File)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 ComboFieldEditor (org.eclipse.jface.preference.ComboFieldEditor)1 Color (org.eclipse.swt.graphics.Color)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1