Search in sources :

Example 16 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.

the class FritzBoxMonitor method release.

public void release() {
    if (this.cmn != null) {
        this.cmn.disconnect();
        // added: 2007/05/30: set cmn to null
        this.cmn = null;
    }
    int count = 0;
    while (this.cmnThread != null && this.cmnThread.isAlive() && count < 5) {
        this.cmnThread.interrupt();
        this.m_logger.info("Try to release FritzBoxMonitor. Attempt #" + (count + 1));
        count++;
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    if (this.cmnThread != null && this.cmnThread.isAlive()) {
        this.cmnThread.interrupt();
        if (this.cmnThread != null && this.cmnThread.isAlive())
            this.m_logger.warning("Could not release FritzBoxMonitor after " + count + " attempts.");
    }
    this.cmnThread = null;
    FirmwareManager fwm = FirmwareManager.getInstance();
    fwm.shutdown();
    this.m_logger.info("FritzBoxMonitor released FritzBox.");
}
Also used : FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager)

Example 17 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.

the class QuickDialer method dial.

public static void dial(IPhonenumber n, String msn) throws Exception {
    if (n.isClired())
        throw new Exception("no number provided");
    String dial = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toCallable(n.getTelephoneNumber());
    // added 2010/03/06: check for dial prefix for outgoing calls
    if (PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_DIAL_PREFIX).length() > 0) {
        dial = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_DIAL_PREFIX).trim() + dial;
    }
    Properties config = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperties(FritzBoxMonitor.NAMESPACE);
    // FritzBox m_fb = new FritzBox(config.getProperty(CFG_IP, "fritz.box"), config.getProperty(CFG_PASSWORD, ""), config.getProperty(CFG_PORT, "80"));
    FirmwareManager fwm = FirmwareManager.getInstance();
    try {
        if (!fwm.isLoggedIn())
            fwm.login();
        fwm.doCall(dial + "#", config.getProperty(CFG_CLICKDIAL, "50"));
    } catch (IOException e) {
        throw new Exception(e.getMessage());
    }
}
Also used : FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) IOException(java.io.IOException) Properties(java.util.Properties) IOException(java.io.IOException)

Example 18 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.

the class ConsoleDial method execute.

public void execute() {
    this.isExecuting = true;
    if (this.getExecuteParams().length != 2) {
        System.out.println("ERROR: Parameters are invalid. Please specify a valid number e.g. +4930123456 or 030123456 and a fritzbox extension");
        System.out.println();
        System.out.println("Valid extensions:");
        System.out.println("-----------------");
        System.out.println("1 for Fon1, 2 for Fon2, 3 for Fon3");
        System.out.println("51 for ISDN1 ... 59 for ISDN 6, 50 for all ISDN devices");
        this.isExecuting = false;
        return;
    }
    String dial = this.getExecuteParams()[0];
    if (dial.length() < 5) {
        System.out.println("ERROR: Invalid number length. Number must contain at least be 5 digits and start with 0.");
        this.isExecuting = false;
        return;
    }
    if (!dial.startsWith("0"))
        dial = "0" + dial;
    String ext = this.getExecuteParams()[1];
    int i = Integer.parseInt(ext);
    if ((i >= 0 && i <= 9) || (i >= 50 && i <= 59)) {
        FirmwareManager fwm = FirmwareManager.getInstance();
        try {
            fwm.login();
            fwm.doCall(dial + "#", ext);
        } catch (Exception e) {
            System.out.println("ERROR: Dialing fritzbox failed: " + e.getMessage());
        }
    } else {
        System.out.println("ERROR: Invalid fritzbox extension: " + i + "; allowed values 1 for Fon1, 2 for Fon2, 3 for Fon3, 51 for ISDN1 ... 59 for ISDN 6, 50 for all ISDN devices.");
    }
    this.isExecuting = false;
}
Also used : FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager)

Example 19 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.

the class Delete method run.

public void run() {
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
    try {
        if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "delete", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "delete", "description", this.getLanguage()))) {
            IRunnableWithProgress r = new IRunnableWithProgress() {

                public void run(IProgressMonitor progressMonitor) {
                    progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "deleteprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                    progressMonitor.worked(1);
                    progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "loginprogress", "label", getLanguage()));
                    FirmwareManager fwm = FirmwareManager.getInstance();
                    try {
                        if (!fwm.isLoggedIn())
                            fwm.login();
                        progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "deleteprogress", "label", getLanguage()));
                        fwm.deleteCallList();
                        progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "finished", "label", getLanguage()));
                    } catch (IOException e) {
                        m_logger.warning(e.toString());
                        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "faileddelete", e));
                    } catch (FritzBoxLoginException e) {
                        m_logger.warning(e.toString());
                    } catch (DeleteCallListException e) {
                        m_logger.warning(e.toString());
                        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "faileddelete", e));
                    }
                    progressMonitor.done();
                }
            };
            pmd.setBlockOnOpen(false);
            pmd.run(true, false, r);
            m_app.updateViews(true);
        }
    // ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) Message(de.janrufmonitor.exception.Message) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) DeleteCallListException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)

Aggregations

FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)19 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)14 IOException (java.io.IOException)14 Message (de.janrufmonitor.exception.Message)6 Properties (java.util.Properties)5 Shell (org.eclipse.swt.widgets.Shell)5 ICall (de.janrufmonitor.framework.ICall)4 ICallerList (de.janrufmonitor.framework.ICallerList)3 DoCallException (de.janrufmonitor.fritzbox.firmware.exception.DoCallException)3 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)3 File (java.io.File)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 SQLException (java.sql.SQLException)3 Map (java.util.Map)3 ICaller (de.janrufmonitor.framework.ICaller)2 IMonitor (de.janrufmonitor.framework.monitor.IMonitor)2 IPhonebookEntry (de.janrufmonitor.fritzbox.IPhonebookEntry)2 DeleteCallListException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)2 GetAddressbooksException (de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException)2 HashMap (java.util.HashMap)2