Search in sources :

Example 6 with ICommand

use of de.janrufmonitor.framework.command.ICommand in project janrufmonitor by tbrandt77.

the class AutoUpdate method createFieldEditors.

protected void createFieldEditors() {
    this.noDefaultAndApplyButton();
    super.createFieldEditors();
    FieldEditor bfe = new FieldEditor("check-button", "c", this.getFieldEditorParent()) {

        protected void adjustForNumColumns(int arg0) {
        }

        protected void doFillIntoGrid(Composite c, int numCols) {
            GridData gd = new GridData();
            gd.horizontalAlignment = GridData.FILL;
            gd.grabExcessHorizontalSpace = true;
            gd.horizontalSpan = numCols - 1;
            gd.widthHint = 200;
            new Label(c, SWT.NONE);
            II18nManager i18 = PIMRuntime.getInstance().getI18nManagerFactory().getI18nManager();
            String l = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE);
            String text = i18.getString("ui.jface.configuration.pages.AutoUpdate", "execute", "label", l);
            Button up = new Button(c, SWT.PUSH);
            up.setText(text);
            up.pack();
            up.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    ICommand c = getRuntime().getCommandFactory().getCommand("UpdatesCommand");
                    if (c != null && c.isExecutable()) {
                        try {
                            c.execute();
                        } catch (Exception ex) {
                            m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                        }
                    }
                }
            });
        }

        protected void doLoad() {
        }

        protected void doLoadDefault() {
        }

        protected void doStore() {
        }

        public int getNumberOfControls() {
            return 1;
        }
    };
    addField(bfe);
}
Also used : FieldEditor(org.eclipse.jface.preference.FieldEditor) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) ICommand(de.janrufmonitor.framework.command.ICommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) II18nManager(de.janrufmonitor.framework.i18n.II18nManager)

Example 7 with ICommand

use of de.janrufmonitor.framework.command.ICommand 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 8 with ICommand

use of de.janrufmonitor.framework.command.ICommand in project janrufmonitor by tbrandt77.

the class DonationService method startup.

public void startup() {
    super.startup();
    try {
        if (this.hasDonated()) {
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("User has already donated. No popup shown at all.");
            return;
        }
    } catch (NoSuchAlgorithmException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    if (this.isEnabled()) {
        int count = getDonationCount();
        if (m_logger.isLoggable(Level.INFO))
            m_logger.info("Donation service counter is #" + count + ", display dialog = (" + (count % getDonationIntervall() == 0) + ")");
        if (count % getDonationIntervall() == 0) {
            ICommand donationCommand = this.getRuntime().getCommandFactory().getCommand("DonationCommand");
            if (donationCommand != null && donationCommand.isExecutable()) {
                try {
                    this.m_logger.info("Executing DonationCommand...");
                    donationCommand.execute();
                } catch (Exception e) {
                    this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    }
}
Also used : ICommand(de.janrufmonitor.framework.command.ICommand) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 9 with ICommand

use of de.janrufmonitor.framework.command.ICommand in project janrufmonitor by tbrandt77.

the class RunConsole method main.

public static void main(String[] args) {
    LoggingInitializer.run();
    Thread.currentThread().setContextClassLoader(JamCacheMasterClassLoader.getInstance());
    System.setProperty("jam.console", "true");
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Welcome to jAnrufmonitor 5 Console:");
    System.out.println("===================================");
    System.out.println("");
    try {
        start();
        help();
        prompt();
    } catch (NoClassDefFoundError e) {
        System.out.println("Updates have been installed. jAnrufmonitor needs to be restarted.");
        System.out.println("... have a nice day :-)");
        System.exit(0);
    }
    while (true) {
        try {
            String lineToBeSent = input.readLine();
            if (lineToBeSent.equalsIgnoreCase("quit")) {
                PIMRuntime.getInstance().shutdown();
                System.out.println("... have a nice day :-)");
                System.exit(0);
            } else if (lineToBeSent.toLowerCase().startsWith("help")) {
                help();
            } else if (lineToBeSent.toLowerCase().startsWith("restart")) {
                restart();
            } else {
                StringTokenizer st = new StringTokenizer(lineToBeSent, " ");
                if (st.countTokens() > 0) {
                    String command = st.nextToken().toLowerCase();
                    String[] arg = null;
                    if (st.hasMoreTokens()) {
                        int i = 0;
                        arg = new String[st.countTokens()];
                        while (st.hasMoreTokens()) {
                            arg[i] = st.nextToken();
                            i++;
                        }
                    }
                    ICommand cmd = PIMRuntime.getInstance().getCommandFactory().getCommand(command);
                    if (cmd != null && cmd instanceof IConsoleCommand) {
                        ((IConsoleCommand) cmd).setExecuteParams(arg);
                        if (cmd.isExecutable() && !cmd.isExecuting()) {
                            try {
                                cmd.execute();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            System.out.println("WARNING: Command " + lineToBeSent + " already executing. Please be patient.");
                        }
                    } else {
                        System.out.println("ERROR: Command " + lineToBeSent + " not found.");
                    }
                }
            }
            prompt();
        } catch (IOException ex) {
            System.out.println("ERROR: " + ex.getMessage());
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) InputStreamReader(java.io.InputStreamReader) ICommand(de.janrufmonitor.framework.command.ICommand) IConsoleCommand(de.janrufmonitor.framework.command.IConsoleCommand) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException)

Example 10 with ICommand

use of de.janrufmonitor.framework.command.ICommand in project janrufmonitor by tbrandt77.

the class MonitorListener method start.

public void start() {
    this.m_logger.entering(MonitorListener.class.getName(), "start");
    if (!this.running) {
        // check if already initialized
        while (this.m_configuration == null) {
            this.m_logger.warning("MonitorListener not yet initialized. Waiting 250ms...");
            try {
                Thread.sleep(250);
            } catch (InterruptedException e) {
            }
        }
        long delayTime = this.getDelayTime() * 1000;
        if (delayTime > 0) {
            ICommand c = PIMRuntime.getInstance().getCommandFactory().getCommand("Activator");
            if (c != null) {
                try {
                    Map m = new HashMap();
                    m.put("status", "delay");
                    // this method executes the command as well !!
                    c.setParameters(m);
                } catch (Exception e) {
                    m_logger.log(Level.SEVERE, e.toString(), e);
                }
            }
            this.m_logger.info("Delaying startup of monitor for " + delayTime + " ms");
            try {
                Thread.sleep(delayTime);
            } catch (InterruptedException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        List monitors = this.getMonitors();
        IMonitor m = null;
        for (int i = 0, j = monitors.size(); i < j; i++) {
            m = (IMonitor) monitors.get(i);
            if (m.isAvailable()) {
                m.setListener(this);
                m.start();
                this.m_logger.info("Started monitor: " + m.getID());
            } else {
                this.m_logger.info("Monitor is disabled: " + m.getID());
            }
        }
        for (int i = 0, j = monitors.size(); i < j; i++) {
            final IMonitor mon = (IMonitor) monitors.get(i);
            if (mon != null) {
                Thread s_check = new Thread() {

                    public void run() {
                        IMonitor l_mon = mon;
                        try {
                            Thread.sleep(5000);
                        } catch (InterruptedException e) {
                        }
                        if (l_mon != null && l_mon.isStarted()) {
                            String[] desc = l_mon.getDescription();
                            if (desc != null && desc.length > 0) {
                                StringBuffer d = new StringBuffer();
                                d.append(desc[0]);
                                for (int i = 1; i < desc.length; i++) {
                                    if (desc[i] != null && desc[i].length() > 0) {
                                        desc[i] = StringUtils.replaceString(desc[i], ",", " ");
                                        d.append(", ");
                                        d.append(desc[i].trim());
                                    }
                                }
                                getRuntime().getConfigManagerFactory().getConfigManager().setProperty(IJAMConst.GLOBAL_NAMESPACE, "monitorsignature", d.toString());
                                getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
                            }
                        }
                    }
                };
                s_check.setName("JAM-MonitorSignatureCheck-Thread-(non-deamon)");
                s_check.start();
            }
        }
        IEventBroker eventBroker = this.getRuntime().getEventBroker();
        // register as EventSender
        eventBroker.register(this);
        // register as EventReceiver
        eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_CALLREJECTED));
        eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_RETURNED_HIBERNATE));
        this.running = true;
        this.m_logger.info("All monitors started on line.");
        for (int i = 0; i < this.getCapiInformation().length; i++) {
            this.m_logger.info(this.getCapiInformation()[i]);
        }
        if (m_mac != null) {
            m_mac.setFinished(true);
            m_mac = null;
        }
        m_mac = new MonitorActiveCheck(this);
        m_mac.setName("JAM-MonitorActiveCheck-Thread-(non-deamon)");
        m_mac.start();
        // activate icon if it has to
        if (delayTime > 0) {
            ICommand c = PIMRuntime.getInstance().getCommandFactory().getCommand("Activator");
            if (c != null) {
                try {
                    Map mp = new HashMap();
                    mp.put("status", "delay");
                    // this method executes the command as well !!
                    c.setParameters(mp);
                } catch (Exception e) {
                    m_logger.log(Level.SEVERE, e.toString(), e);
                }
            }
        }
    }
    this.m_logger.exiting(MonitorListener.class.getName(), "start");
}
Also used : HashMap(java.util.HashMap) ICommand(de.janrufmonitor.framework.command.ICommand) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ICommand (de.janrufmonitor.framework.command.ICommand)12 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Message (de.janrufmonitor.exception.Message)3 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)3 IConsoleCommand (de.janrufmonitor.framework.command.IConsoleCommand)2 DeleteCallListException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)2 DeleteCallerException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)2 DoBlockException (de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)2 DoCallException (de.janrufmonitor.fritzbox.firmware.exception.DoCallException)2 FritzBoxInitializationException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException)2 FritzBoxNotFoundException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException)2 GetAddressbooksException (de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException)2 GetBlockedListException (de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException)2 GetCallListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallListException)2 GetCallerImageException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerImageException)2 GetCallerListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException)2 InvalidSessionIDException (de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException)2 SetCallerException (de.janrufmonitor.fritzbox.firmware.exception.SetCallerException)2