Search in sources :

Example 1 with DialerDialog

use of de.janrufmonitor.ui.jface.application.dialer.DialerDialog 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)

Aggregations

Message (de.janrufmonitor.exception.Message)1 ICall (de.janrufmonitor.framework.ICall)1 ICaller (de.janrufmonitor.framework.ICaller)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)1 DoCallException (de.janrufmonitor.fritzbox.firmware.exception.DoCallException)1 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)1 ITreeItemCallerData (de.janrufmonitor.ui.jface.application.ITreeItemCallerData)1 DialerDialog (de.janrufmonitor.ui.jface.application.dialer.DialerDialog)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Properties (java.util.Properties)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Viewer (org.eclipse.jface.viewers.Viewer)1 Shell (org.eclipse.swt.widgets.Shell)1