Search in sources :

Example 56 with Message

use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.

the class Block method doBlock.

private boolean doBlock(IPhonenumber n) {
    String dial = n.getTelephoneNumber();
    if (!n.getIntAreaCode().equalsIgnoreCase(this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA))) {
        dial = "00" + n.getIntAreaCode() + dial;
    }
    if (!dial.startsWith("0"))
        dial = "0" + dial;
    String text = getI18nManager().getString(getNamespace(), "block", "description", getLanguage());
    text = StringUtils.replaceString(text, "{%1}", dial);
    if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "block", "label", this.getLanguage()), text)) {
        FirmwareManager fwm = FirmwareManager.getInstance();
        try {
            if (!fwm.isLoggedIn())
                fwm.login();
            fwm.doBlock(dial);
            FritzBoxBlockedListManager.invalidate();
        } catch (IOException e) {
            this.m_logger.warning(e.toString());
            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failedblock", e));
        } catch (FritzBoxLoginException e) {
            this.m_logger.warning(e.toString());
        } catch (DoBlockException e) {
            this.m_logger.warning(e.toString());
            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failedblock", e));
        }
        return true;
    }
    return false;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) Message(de.janrufmonitor.exception.Message) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) IOException(java.io.IOException) DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)

Example 57 with Message

use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.

the class ClickDialAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Object o = selection.getFirstElement();
            if (o instanceof ICall) {
                o = ((ICall) o).getCaller();
            }
            if (o instanceof ICaller) {
                o = ((ICaller) o).getPhoneNumber();
            }
            if (o instanceof ITreeItemCallerData) {
                o = ((ITreeItemCallerData) o).getPhone();
            }
            if (o instanceof IPhonenumber) {
                if (((IPhonenumber) o).isClired())
                    return;
                String dial = ((IPhonenumber) o).getTelephoneNumber();
                if (!((IPhonenumber) o).getIntAreaCode().equalsIgnoreCase(this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA))) {
                    dial = "00" + ((IPhonenumber) o).getIntAreaCode() + dial;
                }
                if (!dial.startsWith("0"))
                    dial = "0" + dial;
                Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(FritzBoxMonitor.NAMESPACE);
                String prefixes = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(FritzBoxMonitor.NAMESPACE, "dialprefixes");
                if ((prefixes != null && prefixes.length() > 0) || config.getProperty(CFG_CLICKDIAL, "50").equalsIgnoreCase("0")) {
                    DialerDialog id = new DialerDialog(new Shell(DisplayManager.getDefaultDisplay()), dial);
                    id.open();
                } else {
                    // added 2010/03/06: check for dial prefix for outgoing calls
                    if (this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_DIAL_PREFIX).length() > 0) {
                        if (this.m_logger.isLoggable(Level.INFO))
                            this.m_logger.info("Using dial prefix: " + this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_DIAL_PREFIX));
                        dial = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_DIAL_PREFIX).trim() + dial;
                    }
                    String text = getI18nManager().getString(getNamespace(), "dial", "description", getLanguage());
                    text = StringUtils.replaceString(text, "{%1}", dial);
                    if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "success", "label", this.getLanguage()), text)) {
                        FirmwareManager fwm = FirmwareManager.getInstance();
                        try {
                            if (!fwm.isLoggedIn())
                                fwm.login();
                            fwm.doCall(dial + "#", config.getProperty(CFG_CLICKDIAL, "50"));
                            try {
                                final String n = dial;
                                ModalContext.run(new IRunnableWithProgress() {

                                    public void run(IProgressMonitor progressMonitor) {
                                        progressMonitor.done();
                                        String text = getI18nManager().getString(getNamespace(), "success", "description", getLanguage());
                                        text = StringUtils.replaceString(text, "{%1}", n);
                                        MessageDialog.openInformation(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "success", "label", getLanguage()), text);
                                    }
                                }, false, m_app.getApplication().getStatusLineManager().getProgressMonitor(), m_app.getApplication().getShell().getDisplay());
                            } catch (InterruptedException e) {
                                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                            } catch (InvocationTargetException e) {
                                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                            }
                        } catch (IOException e) {
                            this.m_logger.warning(e.toString());
                            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "faileddial", e));
                        } catch (FritzBoxLoginException e) {
                            this.m_logger.warning(e.toString());
                        } catch (DoCallException e) {
                            this.m_logger.warning(e.toString());
                            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "faileddial", e));
                        }
                        this.m_app.updateViews(false);
                    }
                }
            }
        }
    }
}
Also used : DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) ICall(de.janrufmonitor.framework.ICall) Message(de.janrufmonitor.exception.Message) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) Properties(java.util.Properties) DialerDialog(de.janrufmonitor.ui.jface.application.dialer.DialerDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 58 with Message

use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.

the class FirmwareManager method promptPassword.

private void promptPassword() throws FritzBoxLoginException {
    boolean dnl = false;
    // check for password
    // password is mandatory
    String pw = this.getFritzBoxPassword();
    if (pw.trim().length() == 0) {
        int i = Integer.parseInt(System.getProperty("jam.fritzbox.session.counter", "0"));
        do {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            dnl = Boolean.parseBoolean(System.getProperty("jam.fritzbox.session.donotlogin", "false"));
            boolean isPWDialogRunning = Boolean.parseBoolean(System.getProperty("jam.fritzbox.session.ispwdialogvisible", "false"));
            pw = this.getFritzBoxPassword();
            if (!isPWDialogRunning && pw.trim().length() == 0 && i < 4 && !dnl) {
                final ICommand c = this.getRuntime().getCommandFactory().getCommand("PasswordDialog");
                if (c != null && c.isExecutable() && !c.isExecuting())
                    try {
                        c.execute();
                    } catch (Exception e) {
                        m_logger.log(Level.SEVERE, e.getMessage(), e);
                    }
            }
            i = Integer.parseInt(System.getProperty("jam.fritzbox.session.counter", "0"));
        } while (pw.trim().length() == 0 && i < 4 && !dnl);
        if (i >= 4 || dnl) {
            PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.login", "loginfailed", new Exception("No password set for login."), true));
            this.m_isLoggingIn = false;
            throw new FritzBoxLoginException("No password set for login.");
        }
    }
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) Message(de.janrufmonitor.exception.Message) ICommand(de.janrufmonitor.framework.command.ICommand) DeleteCallListException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException) GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) GetAddressbooksException(de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException) InvalidSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException) FritzBoxInitializationException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException) GetCallListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallListException) GetCallerImageException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerImageException) FritzBoxNotFoundException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException) IOException(java.io.IOException) SetCallerException(de.janrufmonitor.fritzbox.firmware.exception.SetCallerException) DeleteCallerException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)

Example 59 with Message

use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.

the class ExternalApplicationLauncher method receivedValidRule.

public void receivedValidRule(ICall aCall) {
    String msn = aCall.getMSN().getMSN();
    String command = this.m_configuration.getProperty(msn + this.CONFIG_APPLICATION, "");
    if (command.length() == 0) {
        this.m_logger.info("No command configured for MSN " + msn + ". Taking default command.");
        command = this.m_configuration.getProperty("default" + this.CONFIG_APPLICATION, "");
    } else {
        this.m_logger.info("Taking command configured for MSN " + msn + ".");
    }
    if (command.length() > 0) {
        try {
            command = PathResolver.getInstance(this.getRuntime()).resolve(command);
            Formatter f = Formatter.getInstance(this.getRuntime());
            StringTokenizer st = new StringTokenizer(command);
            String[] env = new String[st.countTokens()];
            int i = 0;
            while (st.hasMoreTokens()) {
                env[i] = st.nextToken();
                env[i] = f.parse(env[i], aCall);
                i++;
            }
            command = f.parse(command, aCall);
            // 2009/04/17: added path resolution to command if %imagepath% or else is used
            if (command.indexOf("%") > -1)
                command = PathResolver.getInstance(getRuntime()).resolve(command);
            if (command.toLowerCase().indexOf(".bat") > 0 || command.toLowerCase().indexOf(".cmd") > 0)
                command = "cmd /c start " + command;
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("Launching command: \"" + command + "\" for call " + aCall.toString());
                String text = this.getRuntime().getI18nManagerFactory().getI18nManager().getString(getNamespace(), "executed", "label", this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE));
                PropagationFactory.getInstance().fire(new Message(Message.INFO, this.getRuntime().getI18nManagerFactory().getI18nManager().getString(getNamespace(), "title", "label", this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE)), new Exception(StringUtils.replaceString(text, "{%1}", command))), "Tray");
            }
            Runtime.getRuntime().exec(command);
        } catch (IOException e) {
            this.m_logger.severe(e.getMessage());
        }
    } else {
        this.m_logger.info("No command configured for MSN " + msn + " and no default command available.");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(de.janrufmonitor.exception.Message) Formatter(de.janrufmonitor.util.formatter.Formatter) IOException(java.io.IOException) IOException(java.io.IOException)

Example 60 with Message

use of de.janrufmonitor.exception.Message 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

Message (de.janrufmonitor.exception.Message)64 List (java.util.List)25 ICallerList (de.janrufmonitor.framework.ICallerList)20 ArrayList (java.util.ArrayList)20 IOException (java.io.IOException)19 Shell (org.eclipse.swt.widgets.Shell)19 ComFailException (com.jacob.com.ComFailException)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 Properties (java.util.Properties)15 ZipArchiveException (de.janrufmonitor.repository.zip.ZipArchiveException)14 ActiveXComponent (com.jacob.activeX.ActiveXComponent)13 Dispatch (com.jacob.com.Dispatch)13 Variant (com.jacob.com.Variant)13 SQLException (java.sql.SQLException)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)12 IAttribute (de.janrufmonitor.framework.IAttribute)11 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)11 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)11 ICaller (de.janrufmonitor.framework.ICaller)9