Search in sources :

Example 11 with FirmwareManager

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

the class SynchronizerService method receivedOtherEventCall.

public void receivedOtherEventCall(IEvent event) {
    ICall aCall = (ICall) event.getData();
    if (aCall != null) {
        if (getRuntime().getRuleEngine().validate(this.getID(), aCall.getMSN(), aCall.getCIP(), aCall.getCaller().getPhoneNumber())) {
            this.receivedValidRule(aCall);
        } else {
            this.m_logger.info("No rule assigned to execute this service for call: " + aCall);
        }
    }
    if (event.getType() == IEventConst.EVENT_TYPE_RETURNED_HIBERNATE) {
        this.cancelingTimebasedSyncing();
        FirmwareManager fwm = FirmwareManager.getInstance();
        fwm.shutdown();
        int counter = 0;
        do {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            fwm.startup();
            if (!fwm.isLoggedIn())
                try {
                    fwm.login();
                } catch (FritzBoxLoginException e) {
                    this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            counter++;
        } while (!fwm.isLoggedIn() && counter < getRetryMaxValue());
        if (counter == getRetryMaxValue()) {
            this.m_logger.severe("FritzBox Syncronizer stopped. Could not get a connection after " + counter + " re-connects try outs to FritzBox.");
            return;
        }
        new SWTExecuter() {

            protected void execute() {
                synchronize(false);
            }
        }.start();
        timebasedSyncing();
    }
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) ICall(de.janrufmonitor.framework.ICall) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 12 with FirmwareManager

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

the class SynchronizerService method synchronize.

public void synchronize(IProgressMonitor progressMonitor) {
    if (m_activeSync)
        return;
    this.m_activeSync = true;
    long start = System.currentTimeMillis();
    if (m_logger.isLoggable(Level.INFO))
        m_logger.info("--> Start Synchronizing (" + (progressMonitor == null ? "w/o progress monitor" : "with progress monitor") + ")");
    if (this.m_tamMap == null)
        this.m_tamMap = new HashMap();
    this.m_tamMap.clear();
    if (progressMonitor != null) {
        progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "refreshprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
        progressMonitor.worked(1);
        progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "loginprogress", "label", getLanguage()));
    }
    try {
        Thread.sleep((progressMonitor != null ? 500 : 100));
    } catch (InterruptedException e1) {
        m_logger.log(Level.SEVERE, e1.getMessage(), e1);
    }
    FirmwareManager fwm = FirmwareManager.getInstance();
    // fwm.startup();
    try {
        if (!fwm.isLoggedIn())
            fwm.login();
        if (progressMonitor != null)
            progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "getprogress", "label", getLanguage()));
        try {
            Thread.sleep((progressMonitor != null ? 1500 : 100));
        } catch (InterruptedException e1) {
            m_logger.log(Level.SEVERE, e1.getMessage(), e1);
        }
        long synctime = Long.parseLong(SynchronizerService.this.m_configuration.getProperty(CFG_SYNCTIME, "-1"));
        long oldestCallTime = -1;
        // added: 2013/02/04: check sync all
        boolean syncall = SynchronizerService.this.m_configuration.getProperty(CFG_SYNCALL, "false").equalsIgnoreCase("true");
        if (syncall) {
            synctime = -1;
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("Sync all option enabled.");
        }
        // sub getSynctimeOffset from time
        if (synctime > 0) {
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("Sync timestamp before decrementing offset: " + synctime);
            synctime -= this.getSyncTimeOffset();
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("Sync timestamp after decrementing offset: " + synctime);
        }
        if (m_logger.isLoggable(Level.INFO))
            m_logger.info("Syncing call list from FRITZ!Box with timestamp: " + synctime);
        List result = fwm.getCallList(synctime);
        if (m_logger.isLoggable(Level.INFO))
            m_logger.info("Call list size from FRITZ!Box: " + result.size());
        if (result.size() > 0) {
            ICallList m_callList = PIMRuntime.getInstance().getCallFactory().createCallList(result.size());
            List m_prefilteredList = new ArrayList(result.size());
            FritzBoxCallCsv call = null;
            Properties conf = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperties(FritzBoxMonitor.NAMESPACE);
            ICall c = null;
            FritzBoxUUIDManager.getInstance().init();
            boolean skipOutgoing = !Boolean.parseBoolean(conf.getProperty(CFG_OUTGOING, "false"));
            for (int i = 0, j = result.size(); i < j; i++) {
                call = new FritzBoxCallCsv((String) result.get(i), conf);
                // added 2016/01/11: check if outgoing call applicable
                if (call != null) {
                    if (call.isOutgoingCall() && skipOutgoing) {
                        if (m_logger.isLoggable(Level.INFO))
                            m_logger.info("Call import skipped by call state (outgoing) from FRITZ!Box.");
                        continue;
                    }
                    Date calltime = call.getPrecalculatedDate();
                    if (calltime != null && calltime.getTime() < synctime && synctime > 0) {
                        if (m_logger.isLoggable(Level.INFO))
                            m_logger.info("Call import skipped by timestamp (last sync time: " + new Date(synctime).toString() + ", call time: " + calltime.toString() + ") from FRITZ!Box.");
                        continue;
                    }
                    if (calltime != null && synctime < 0) {
                        if (oldestCallTime == -1)
                            oldestCallTime = calltime.getTime();
                        if (oldestCallTime > calltime.getTime())
                            oldestCallTime = calltime.getTime();
                        if (m_logger.isLoggable(Level.INFO))
                            m_logger.info("Set oldest call time to: " + new Date(oldestCallTime).toString());
                    }
                    m_prefilteredList.add(call);
                }
            }
            if (m_prefilteredList.size() > 0) {
                if (progressMonitor != null)
                    progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "identifyprogress", "label", getLanguage()));
                try {
                    Thread.sleep((progressMonitor != null ? 1000 : 100));
                } catch (InterruptedException e1) {
                    m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                }
                for (int i = 0, j = m_prefilteredList.size(); i < j; i++) {
                    c = ((FritzBoxCallCsv) m_prefilteredList.get(i)).toCall();
                    if (c != null) {
                        if (getRuntime().getMsnManager().isMsnMonitored(c.getMSN())) {
                            if (progressMonitor != null) {
                                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "processing", "label", getLanguage()) + Formatter.getInstance(this.getRuntime()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, c));
                                try {
                                    Thread.sleep(75);
                                } catch (InterruptedException e1) {
                                    m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                                }
                            }
                            if (!m_callList.contains(c)) {
                                if (m_logger.isLoggable(Level.INFO))
                                    m_logger.info("Adding call imported from FRITZ!Box: " + c.toString());
                                m_callList.add(c);
                            } else {
                                if (m_logger.isLoggable(Level.WARNING))
                                    m_logger.warning("Adding duplicated call imported from FRITZ!Box: " + c.toString());
                                c.setUUID(c.getUUID() + "-1");
                                ICip cip = c.getCIP();
                                // just a dirty hack
                                cip.setCIP("4");
                                c.setCIP(cip);
                                if (!m_callList.contains(c))
                                    m_callList.add(c);
                                else {
                                    c.setUUID(c.getUUID() + "-1");
                                    if (!m_callList.contains(c))
                                        m_callList.add(c);
                                }
                            }
                        }
                    }
                }
            }
            if (m_callList != null && m_callList.size() > 0) {
                if (progressMonitor != null)
                    progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "geocodeprogress", "label", getLanguage()));
                try {
                    Thread.sleep((progressMonitor != null ? 1000 : 100));
                } catch (InterruptedException e1) {
                    m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                }
                boolean synctam = SynchronizerService.this.m_configuration.getProperty(CFG_SYNCTAM, "false").equalsIgnoreCase("true");
                if (synctam) {
                    if (m_logger.isLoggable(Level.INFO))
                        m_logger.info("Sync TAM recordings: " + Boolean.toString(synctam));
                    if (progressMonitor != null)
                        progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "tamprogress", "label", getLanguage()));
                    this.m_tamMap.putAll(fwm.getTamMessages(synctime));
                    try {
                        Thread.sleep((progressMonitor != null ? 1000 : 100));
                    } catch (InterruptedException e1) {
                        m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                    }
                }
                if (m_logger.isLoggable(Level.INFO))
                    m_logger.info("Processing modifier services on call list: " + getRuntime().getServiceFactory().getModifierServices());
                processModifierServices(m_callList, progressMonitor);
                if (progressMonitor != null)
                    progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "synchprogress", "label", getLanguage()));
                try {
                    Thread.sleep((progressMonitor != null ? 1000 : 100));
                } catch (InterruptedException e1) {
                    m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                }
                String repository = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(Journal.NAMESPACE, "repository");
                ICallManager cm = getRuntime().getCallManagerFactory().getCallManager(repository);
                if (cm != null && cm.isActive() && cm.isSupported(IWriteCallRepository.class)) {
                    ICall ca = null;
                    boolean syncclean = SynchronizerService.this.m_configuration.getProperty(CFG_SYNCCLEAN, "false").equalsIgnoreCase("true");
                    if (synctime < 0) {
                        if (m_logger.isLoggable(Level.INFO))
                            m_logger.info("Set syntime to oldest call time to eliminate duplicates.");
                        synctime = oldestCallTime;
                    }
                    if (syncclean && synctime > 0 && cm.isSupported(IReadCallRepository.class) && cm.isSupported(IWriteCallRepository.class)) {
                        if (m_logger.isLoggable(Level.INFO))
                            m_logger.info("Remove duplicated entries (sync clean) option enabled.");
                        if (progressMonitor != null)
                            progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "syncclean", "label", getLanguage()));
                        try {
                            Thread.sleep((progressMonitor != null ? 500 : 100));
                        } catch (InterruptedException e1) {
                            m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                        }
                        IFilter syncFilter = new DateFilter(new Date(System.currentTimeMillis()), new Date(synctime));
                        ICallList cl = ((IReadCallRepository) cm).getCalls(syncFilter);
                        if (cl.size() > 0) {
                            // 2009/03/18: added backup of cleaned calls
                            IImExporter exp = ImExportFactory.getInstance().getExporter("DatFileCallExporter");
                            if (exp != null & exp instanceof ICallExporter) {
                                if (m_logger.isLoggable(Level.INFO))
                                    m_logger.info("Creating backup of cleaned call list...");
                                File backupdir = new File(PathResolver.getInstance(getRuntime()).getDataDirectory(), "fritzbox-sync-clean-backup");
                                if (!backupdir.exists()) {
                                    backupdir.mkdirs();
                                }
                                File backupfile = new File(backupdir, Long.toString(synctime) + ".dat");
                                ((ICallExporter) exp).setFilename(backupfile.getAbsolutePath());
                                ((ICallExporter) exp).setCallList(cl);
                                if (((ICallExporter) exp).doExport()) {
                                    if (m_logger.isLoggable(Level.INFO))
                                        m_logger.info("Backup of cleaned call list successfully finished: " + backupfile.getAbsolutePath());
                                } else {
                                    if (m_logger.isLoggable(Level.WARNING))
                                        m_logger.warning("Backup of cleaned call list failed: " + backupdir.getAbsolutePath());
                                }
                            }
                            ((IWriteCallRepository) cm).removeCalls(createRedundancyList(m_callList, synctime));
                            try {
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                    for (int i = 0, j = m_callList.size(); i < j; i++) {
                        ca = m_callList.get(i);
                        try {
                            ((IWriteCallRepository) cm).setCall(ca);
                            if (progressMonitor != null) {
                                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "processing2", "label", getLanguage()) + Formatter.getInstance(this.getRuntime()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNAME, ca));
                                try {
                                    Thread.sleep(50);
                                } catch (InterruptedException e1) {
                                    m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                                }
                            }
                            if (m_logger.isLoggable(Level.INFO))
                                m_logger.info("Call imported to repository: " + ca.toString());
                        } catch (Exception e) {
                            if (m_logger.isLoggable(Level.WARNING))
                                m_logger.warning("Call already in repository (skipped): " + ca.toString());
                        }
                    }
                    // added 2009/01/08: force refresh of journal, if opened
                    IEventBroker evtBroker = getRuntime().getEventBroker();
                    evtBroker.register(this);
                    evtBroker.send(this, evtBroker.createEvent(IEventConst.EVENT_TYPE_CALL_MANAGER_UPDATED));
                    evtBroker.unregister(this);
                    if (m_logger.isLoggable(Level.INFO))
                        m_logger.info("EventBroker notification sent: EVENT_TYPE_CALL_MANAGER_UPDATED");
                }
                boolean syncDelete = (m_configuration.getProperty(FritzBoxConst.CFG_SYNCDELETE, "false").equalsIgnoreCase("true") ? true : false);
                if (syncDelete) {
                    if (m_logger.isLoggable(Level.INFO))
                        m_logger.info("Delete after sync (sync delete) option enabled.");
                    if (progressMonitor != null)
                        progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "deleteprogress", "label", getLanguage()));
                    fwm.deleteCallList();
                }
                // added 2009/01/07: send mail notification after sync with fritzbox
                boolean syncNotify = (SynchronizerService.this.m_configuration.getProperty(FritzBoxConst.CFG_SYNC_NOTIFICATION, "false").equalsIgnoreCase("true") ? true : false);
                if (syncNotify) {
                    if (m_logger.isLoggable(Level.INFO))
                        m_logger.info("Send notification after sync (sync notification) option enabled.");
                    ICall ca = null;
                    if (progressMonitor != null)
                        progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "sendnotificationprogress", "label", getLanguage()));
                    for (int i = 0, j = m_callList.size(); i < j; i++) {
                        ca = m_callList.get(i);
                        sendMailNotification(ca);
                    }
                }
            }
            String text = getI18nManager().getString(getNamespace(), "finished", "label", getLanguage());
            if (m_callList.size() == 0)
                text = getI18nManager().getString(getNamespace(), "finished0", "label", getLanguage());
            if (m_callList.size() == 1)
                text = getI18nManager().getString(getNamespace(), "finished1", "label", getLanguage());
            if (progressMonitor != null)
                progressMonitor.setTaskName(StringUtils.replaceString(text, "{%1}", Integer.toString(m_callList.size())));
            if (m_callList.size() > 0)
                PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString("monitor.FritzBoxMonitor", "title", "label", getLanguage()), new Exception(StringUtils.replaceString(text, "{%1}", Integer.toString(m_callList.size())))), "Tray");
            SynchronizerService.this.m_configuration.setProperty(CFG_SYNCTIME, Long.toString(System.currentTimeMillis()));
            getRuntime().getConfigManagerFactory().getConfigManager().setProperties(NAMESPACE, SynchronizerService.this.m_configuration);
            getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
            if (progressMonitor != null)
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                    m_logger.log(Level.SEVERE, e1.getMessage(), e1);
                }
        } else {
            // no results from FB list
            if (progressMonitor != null)
                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "noresults", "label", getLanguage()));
            try {
                Thread.sleep((progressMonitor != null ? 1500 : 100));
            } catch (InterruptedException e1) {
                m_logger.log(Level.SEVERE, e1.getMessage(), e1);
            }
        }
    } catch (IOException e) {
        m_logger.warning(e.toString());
        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failedrefresh", e));
    } catch (FritzBoxLoginException e) {
        m_logger.warning(e.toString());
    } catch (GetCallListException e) {
        m_logger.warning(e.toString());
        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failedrefresh", e));
    } catch (DeleteCallListException e) {
        m_logger.warning(e.toString());
        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failedrefresh", e));
    } catch (CloneNotSupportedException e) {
        m_logger.warning(e.toString());
    } finally {
        if (progressMonitor != null)
            progressMonitor.done();
        this.m_activeSync = false;
    }
    if (m_logger.isLoggable(Level.INFO))
        m_logger.info("--> Finished Synchronizing (" + (progressMonitor == null ? "w/o progress monitor" : "with progress monitor") + ") in " + ((System.currentTimeMillis() - start) / 1000) + " sec.");
}
Also used : Message(de.janrufmonitor.exception.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ICallManager(de.janrufmonitor.repository.ICallManager) ICallList(de.janrufmonitor.framework.ICallList) IImExporter(de.janrufmonitor.repository.imexport.IImExporter) ICallList(de.janrufmonitor.framework.ICallList) List(java.util.List) ArrayList(java.util.ArrayList) DateFilter(de.janrufmonitor.repository.filter.DateFilter) IEventBroker(de.janrufmonitor.framework.event.IEventBroker) IReadCallRepository(de.janrufmonitor.repository.types.IReadCallRepository) ICallExporter(de.janrufmonitor.repository.imexport.ICallExporter) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) ICall(de.janrufmonitor.framework.ICall) ICip(de.janrufmonitor.framework.ICip) GetCallListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallListException) IOException(java.io.IOException) Date(java.util.Date) IWriteCallRepository(de.janrufmonitor.repository.types.IWriteCallRepository) InvocationTargetException(java.lang.reflect.InvocationTargetException) DeleteCallListException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException) GetCallListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallListException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) IOException(java.io.IOException) FritzBoxCallCsv(de.janrufmonitor.fritzbox.FritzBoxCallCsv) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) IFilter(de.janrufmonitor.repository.filter.IFilter) File(java.io.File) DeleteCallListException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)

Example 13 with FirmwareManager

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

the class DialerDialog method okPressed.

protected void okPressed() {
    if (dialBox != null) {
        String dial = PhonenumberAnalyzer.getInstance(getRuntime()).toCallable(dialBox.getText());
        if (dials != null) {
            int maxnums = Integer.parseInt(this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(FritzBoxMonitor.NAMESPACE, FritzBoxConst.CFG_LAST_DIALED_NUMBERS));
            if (dials.size() >= maxnums) {
                dials = dials.subList(0, maxnums - 1);
            }
            dials.add(0, dial);
            this.setLast10DialedNumbers(dials);
        }
        // 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;
        }
        if (dial.trim().length() > 0) {
            if (dialPrefix != null) {
                if (dialPrefix.getText().trim().length() > 0) {
                    dial = dialPrefix.getText().trim() + dial;
                }
            }
            Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(FritzBoxMonitor.NAMESPACE);
            String clickdial = config.getProperty(CFG_CLICKDIAL, "50");
            if (clickDial != null) {
                if (clickDial.getText().trim().length() > 0) {
                    if (clickDial.getText().equalsIgnoreCase("FON 1"))
                        clickdial = "1";
                    if (clickDial.getText().equalsIgnoreCase("FON 2"))
                        clickdial = "2";
                    if (clickDial.getText().equalsIgnoreCase("FON 3"))
                        clickdial = "3";
                    if (clickDial.getText().equalsIgnoreCase("Alle ISDN Ger\u00E4te"))
                        clickdial = "50";
                    if (clickDial.getText().equalsIgnoreCase("ISDN 1"))
                        clickdial = "51";
                    if (clickDial.getText().equalsIgnoreCase("ISDN 2"))
                        clickdial = "52";
                    if (clickDial.getText().equalsIgnoreCase("ISDN 3"))
                        clickdial = "53";
                    if (clickDial.getText().equalsIgnoreCase("ISDN 4"))
                        clickdial = "54";
                    if (clickDial.getText().equalsIgnoreCase("ISDN 5"))
                        clickdial = "55";
                    if (clickDial.getText().equalsIgnoreCase("ISDN 6"))
                        clickdial = "56";
                    if (clickDial.getText().equalsIgnoreCase("ISDN 7"))
                        clickdial = "57";
                    if (clickDial.getText().equalsIgnoreCase("ISDN 8"))
                        clickdial = "58";
                    if (clickDial.getText().equalsIgnoreCase("ISDN 9"))
                        clickdial = "59";
                    if (clickDial.getText().equalsIgnoreCase("DECT 610"))
                        clickdial = "60";
                    if (clickDial.getText().equalsIgnoreCase("DECT 611"))
                        clickdial = "61";
                    if (clickDial.getText().equalsIgnoreCase("DECT 612"))
                        clickdial = "62";
                    if (clickDial.getText().equalsIgnoreCase("DECT 613"))
                        clickdial = "63";
                    if (clickDial.getText().equalsIgnoreCase("DECT 614"))
                        clickdial = "64";
                    if (clickDial.getText().equalsIgnoreCase("DECT 615"))
                        clickdial = "65";
                    this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(FritzBoxMonitor.NAMESPACE, "lastext", clickDial.getText());
                }
            }
            String text = getI18nManager().getString("ui.jface.application.fritzbox.action.ClickDialAction", "dial", "description", getLanguage());
            text = StringUtils.replaceString(text, "{%1}", dial);
            FirmwareManager fwm = FirmwareManager.getInstance();
            try {
                if (!fwm.isLoggedIn())
                    fwm.login();
                fwm.doCall(dial + "#", clickdial);
                text = getI18nManager().getString("ui.jface.application.fritzbox.action.ClickDialAction", "success", "description", getLanguage());
                PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString("monitor.FritzBoxMonitor", "title", "label", getLanguage()), new Exception(StringUtils.replaceString(text, "{%1}", dial))), "Tray");
            } catch (IOException e) {
                this.m_logger.warning(e.toString());
                PropagationFactory.getInstance().fire(new Message(Message.ERROR, "ui.jface.application.fritzbox.action.ClickDialAction", "faileddial", e));
            } catch (FritzBoxLoginException e) {
                this.m_logger.warning(e.toString());
                PropagationFactory.getInstance().fire(new Message(Message.ERROR, "ui.jface.application.fritzbox.action.ClickDialAction", "faileddial", e));
            } catch (DoCallException e) {
                this.m_logger.warning(e.toString());
                PropagationFactory.getInstance().fire(new Message(Message.ERROR, "ui.jface.application.fritzbox.action.ClickDialAction", "faileddial", e));
            }
        }
    }
    super.okPressed();
}
Also used : DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) Message(de.janrufmonitor.exception.Message) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) IOException(java.io.IOException) Properties(java.util.Properties) DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) IOException(java.io.IOException)

Example 14 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager 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 15 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager 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

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