Search in sources :

Example 1 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class FritzBoxVoip method createFieldEditors.

protected void createFieldEditors() {
    StringFieldEditor sfe = null;
    BooleanFieldEditor bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "activemonitor", this.m_i18n.getString(this.getNamespace(), "activemonitor", "label", this.m_language), this.getFieldEditorParent());
    addField(bfe);
    if (isExpertMode()) {
        bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "outgoing", this.m_i18n.getString(this.getNamespace(), "outgoing", "label", this.m_language), this.getFieldEditorParent());
        addField(bfe);
        sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxip", this.m_i18n.getString(this.getNamespace(), "boxip", "label", this.m_language), this.getFieldEditorParent());
        sfe.setEmptyStringAllowed(false);
        addField(sfe);
    }
    mode = new ComboFieldEditor(getConfigNamespace() + SEPARATOR + "boxloginmode", this.m_i18n.getString(this.getNamespace(), "boxloginmode", "label", this.m_language), new String[][] { { this.m_i18n.getString(this.getNamespace(), "userpassword", "label", this.m_language), "0" }, { this.m_i18n.getString(this.getNamespace(), "password_only", "label", this.m_language), "1" } }, this.getFieldEditorParent());
    addField(mode);
    this.user = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxuser", this.m_i18n.getString(this.getNamespace(), "boxuser", "label", this.m_language), this.getFieldEditorParent());
    addField(this.user);
    String state = this.getPreferenceStore().getString(getConfigNamespace() + SEPARATOR + "boxloginmode");
    if (state.equalsIgnoreCase("1")) {
        this.user.setEnabled(false, this.getFieldEditorParent());
        this.user.getTextControl(getFieldEditorParent()).setBackground(new Color(DisplayManager.getDefaultDisplay(), 190, 190, 190));
        this.user.setStringValue("");
    }
    sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxpassword", this.m_i18n.getString(this.getNamespace(), "boxpassword", "label", this.m_language), this.getFieldEditorParent());
    sfe.getTextControl(this.getFieldEditorParent()).setEchoChar('*');
    addField(sfe);
    if (isExpertMode()) {
        IntegerFieldEditor ife = new IntegerFieldEditor(getConfigNamespace() + SEPARATOR + "retrymax", this.m_i18n.getString(this.getNamespace(), "retrymax", "label", this.m_language), this.getFieldEditorParent());
        ife.setTextLimit(3);
        addField(ife);
        ife = new IntegerFieldEditor(getConfigNamespace() + SEPARATOR + "retrytimeouts", this.m_i18n.getString(this.getNamespace(), "retrytimeouts", "label", this.m_language), this.getFieldEditorParent());
        ife.setTextLimit(3);
        addField(ife);
        bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "tr064off", this.m_i18n.getString(this.getNamespace(), "tr064off", "label", this.m_language), this.getFieldEditorParent());
        addField(bfe);
        new Label(this.getFieldEditorParent(), SWT.NULL);
        new Label(this.getFieldEditorParent(), SWT.NULL);
        ComboFieldEditor cfe = new ComboFieldEditor(getConfigNamespace() + SEPARATOR + "boxclickdial", this.m_i18n.getString(this.getNamespace(), "boxclickdial", "label", this.m_language), new String[][] { { this.m_i18n.getString(this.getNamespace(), "manual", "label", this.m_language), "0" }, { this.m_i18n.getString(this.getNamespace(), "all_analog", "label", this.m_language), "9" }, { this.m_i18n.getString(this.getNamespace(), "all_isdn", "label", this.m_language), "50" }, { "FON 1", "1" }, { "FON 2", "2" }, { "FON 3", "3" }, { "ISDN 1", "51" }, { "ISDN 2", "52" }, { "ISDN 3", "53" }, { "ISDN 4", "54" }, { "ISDN 5", "55" }, { "ISDN 6", "56" }, { "ISDN 7", "57" }, { "ISDN 8", "58" }, { "ISDN 9", "59" }, { "DECT 610", "60" }, { "DECT 611", "61" }, { "DECT 612", "62" }, { "DECT 613", "63" }, { "DECT 614", "64" }, { "DECT 615", "65" } }, this.getFieldEditorParent());
        addField(cfe);
        sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "dialprefixes", this.m_i18n.getString(this.getNamespace(), "dialprefixes", "label", this.m_language), this.getFieldEditorParent());
        sfe.setEmptyStringAllowed(true);
        addField(sfe);
        new Label(this.getFieldEditorParent(), SWT.NULL);
        new Label(this.getFieldEditorParent(), SWT.NULL);
    }
    IMonitor fbMonitor = this.getRuntime().getMonitorListener().getMonitor("FritzBoxMonitor");
    if (fbMonitor != null) {
        String[] fbInfos = fbMonitor.getDescription();
        Label capi_label = new Label(this.getFieldEditorParent(), 0);
        capi_label.setText(this.m_i18n.getString(this.getNamespace(), "fbinfo", "label", this.m_language));
        for (int i = 0; i < fbInfos.length; i++) {
            if (fbInfos[i].trim().length() > 0) {
                Label capi = new Label(this.getFieldEditorParent(), SWT.NULL);
                capi.setText(fbInfos[i]);
                new Label(this.getFieldEditorParent(), SWT.NULL);
            }
        }
    }
    new Label(this.getFieldEditorParent(), SWT.NULL);
    Label statusl = new Label(this.getFieldEditorParent(), 0);
    statusl.setText(this.m_i18n.getString(this.getNamespace(), "status", "label", this.m_language));
    Label status_observer = new Label(this.getFieldEditorParent(), SWT.NULL);
    status_observer.setText(this.m_i18n.getString(this.getNamespace(), "statuso", "label", this.m_language) + ((fbMonitor != null && fbMonitor.isStarted()) ? "OK" : "---"));
    new Label(this.getFieldEditorParent(), SWT.NULL);
    FirmwareManager fwm = FirmwareManager.getInstance();
    fwm.startup();
    if (fwm.isLoggedIn() && !fwm.isInstance(TR064FritzBoxFirmware.class)) {
        Label status_sync = new Label(this.getFieldEditorParent(), SWT.NULL);
        status_sync.setText(this.m_i18n.getString(this.getNamespace(), "statuss", "label", this.m_language) + (fwm.isLoggedIn() ? "OK" : "---"));
        new Label(this.getFieldEditorParent(), SWT.NULL);
        if (fbMonitor != null && fbMonitor.isStarted() && fwm.isLoggedIn()) {
            // set icon to colored
            IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
            try {
                Method m = tray.getClass().getMethod("setIconStateActive", new Class[] {});
                if (m != null) {
                    m.invoke(tray, new Object[] {});
                }
            } catch (Exception ex) {
            }
        }
        if ((fbMonitor == null || !fbMonitor.isStarted()) && !fwm.isLoggedIn()) {
            // set icon to colored
            IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
            try {
                Method m = tray.getClass().getMethod("setIconStateInactive", new Class[] {});
                if (m != null) {
                    m.invoke(tray, new Object[] {});
                }
            } catch (Exception ex) {
            }
        }
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.swt.widgets.Label) BooleanFieldEditor(de.janrufmonitor.ui.jface.configuration.controls.BooleanFieldEditor) Method(java.lang.reflect.Method) ComboFieldEditor(org.eclipse.jface.preference.ComboFieldEditor) IMonitor(de.janrufmonitor.framework.monitor.IMonitor) StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) IntegerFieldEditor(org.eclipse.jface.preference.IntegerFieldEditor) IService(de.janrufmonitor.service.IService)

Example 2 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class BalloonDialog method createDialog.

public void createDialog() {
    final Color color = new Color(getShell().getDisplay(), 255, 255, 225);
    boolean hasCallerImage = this.hasCallerImage();
    Composite c = this.getContents();
    c.setLayout(new GridLayout((hasCallerImage ? 2 : 1), false));
    if (hasCallerImage) {
        Label image = new Label(c, SWT.BORDER | SWT.RIGHT);
        GridData gd = new GridData();
        gd.verticalSpan = 5;
        image.setVisible(false);
        gd.widthHint = 92;
        gd.heightHint = 110;
        gd.horizontalIndent = 10;
        image.setVisible(true);
        image.setImage(this.getCallerImage());
        image.setLayoutData(gd);
    }
    // date
    Label l = new Label(c, SWT.NONE);
    l.setText(this.getI18nManager().getString(this.getNamespace(), "date_label", "label", this.getLanguage()) + this.getParsedDate());
    Font initialFont = l.getFont();
    FontData[] fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
    }
    Font newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    l.setFont(newFont);
    l.setBackground(color);
    // MSN
    l = new Label(c, SWT.NONE);
    l.setText(this.getI18nManager().getString(this.getNamespace(), "msn_label", "label", this.getLanguage()) + this.getParsedMsn());
    initialFont = l.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
        fontData[i].setStyle(SWT.BOLD);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    l.setFont(newFont);
    l.setBackground(color);
    // caller name +  additional
    l = new Label(c, SWT.LEFT);
    l.setText(this.getParsedCaller());
    l.setBackground(color);
    l.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
    initialFont = l.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize());
        fontData[i].setStyle(SWT.BOLD);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    l.setFont(newFont);
    l.pack();
    this.checkCallerLength(l);
    l.pack();
    // number
    // added 2008/04/08: add provider image if present
    Composite numberbar = new Composite(c, SWT.NONE);
    numberbar.setBackground(color);
    ITableCellRenderer tr = RendererRegistry.getInstance().getRenderer("ProviderLogo".toLowerCase());
    Image img = null;
    if (tr != null && this.m_call != null && !isCliredCaller()) {
        tr.updateData(this.m_call);
        img = tr.renderAsImage();
    }
    numberbar.setLayout(new GridLayout((img != null ? 2 : 1), false));
    if (img != null) {
        l = new Label(numberbar, SWT.LEFT);
        l.setBackground(color);
        l.setImage(new Image(DisplayManager.getDefaultDisplay(), img.getImageData().scaledTo(32, 32)));
    }
    l = new Label(numberbar, SWT.LEFT);
    l.setText(this.getParsedNumber());
    l.setBackground(color);
    l.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
    initialFont = l.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    l.setFont(newFont);
    l.pack();
    // CIP
    l = new Label(c, SWT.LEFT);
    l.setText(this.getParsedCip());
    l.setBackground(color);
    l.pack();
    // Buttons
    Composite buttonBar = new Composite(c, SWT.NONE);
    GridData gd = new GridData();
    gd.horizontalSpan = 2;
    // check for plugins
    List plugins = this.getPlugins(this.getConfiguration().getProperty("pluginlist", ""));
    GridLayout gl = new GridLayout(Math.max(5, (plugins.size() + 2)), false);
    gl.marginRight = 20;
    buttonBar.setLayout(gl);
    buttonBar.setLayoutData(gd);
    buttonBar.setBackground(color);
    // Label la = new Label(buttonBar, SWT.LEFT);
    // la.setText("       ");
    // la.setBackground(color);
    // check for active reject service
    IService rejectService = this.getRuntime().getServiceFactory().getService("Reject");
    if (rejectService != null && rejectService.isEnabled()) {
        final HyperLink reject = new HyperLink(buttonBar, SWT.LEFT);
        reject.setBackground(color);
        reject.setText(this.getI18nManager().getString(this.getNamespace(), "reject", "label", this.getLanguage()));
        reject.pack();
        reject.addMouseListener(new MouseAdapter() {

            public void mouseDown(MouseEvent e) {
                if (e.button == 1) {
                    reject.setEnabled(false);
                    reject.setText(getI18nManager().getString(getNamespace(), "rejected", "label", getLanguage()));
                    reject.setUnderline(color);
                    reject.setActiveUnderline(color);
                    reject.setHoverUnderline(color);
                    reject.pack(true);
                    IEventBroker eventBroker = getRuntime().getEventBroker();
                    if (m_call != null)
                        m_call.setAttribute(getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_REJECTED));
                    eventBroker.send(BalloonDialog.this, eventBroker.createEvent(IEventConst.EVENT_TYPE_CALLREJECTED, m_call));
                }
            }
        });
    }
    if (this.isAssignement() && !this.isCliredCaller()) {
        final IDialogPlugin assignPlugin = new AssignPlugin();
        assignPlugin.setDialog(this);
        HyperLink hl = new HyperLink(buttonBar, SWT.LEFT);
        hl.setText(assignPlugin.getLabel());
        hl.setBackground(color);
        hl.pack();
        hl.addMouseListener(new MouseAdapter() {

            public void mouseDown(MouseEvent e) {
                if (e.button == 1) {
                    assignPlugin.run();
                }
            }
        });
    }
    // add plugins
    String classString = null;
    for (int i = 0, j = plugins.size(); i < j; i++) {
        classString = this.getConfiguration().getProperty((String) plugins.get(i));
        if (classString != null && classString.trim().length() > 0) {
            try {
                Class classObject = Thread.currentThread().getContextClassLoader().loadClass(classString);
                final IDialogPlugin plugin = (IDialogPlugin) classObject.newInstance();
                plugin.setDialog(this);
                plugin.setID((String) plugins.get(i));
                if (plugin.isEnabled()) {
                    HyperLink hl = new HyperLink(buttonBar, SWT.LEFT);
                    hl.setText(plugin.getLabel());
                    hl.setBackground(color);
                    hl.pack();
                    hl.addMouseListener(new MouseAdapter() {

                        public void mouseDown(MouseEvent e) {
                            if (e.button == 1) {
                                plugin.run();
                            }
                        }
                    });
                }
            } catch (ClassNotFoundException e) {
                this.m_logger.warning("Class not found: " + classString);
            } catch (InstantiationException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            } catch (IllegalAccessException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    color.dispose();
    c.pack();
}
Also used : HyperLink(de.janrufmonitor.ui.jface.application.controls.HyperLink) GridLayout(org.eclipse.swt.layout.GridLayout) List(java.util.List) IService(de.janrufmonitor.service.IService) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) GridData(org.eclipse.swt.layout.GridData)

Example 3 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class TrayIconPropagator method propagate.

public void propagate(Message m) {
    String message = null;
    String title = null;
    if (m.getNamespace().equalsIgnoreCase(Message.DEFAULT_NAMESPACE) && !m.getMessage().equalsIgnoreCase("unknown") && (m.getVariables() == null || m.getVariables().length == 0)) {
        message = m.getThrowable().getMessage();
        title = m.getMessage();
    } else {
        try {
            message = this.m_i18n.getString(m.getNamespace(), m.getMessage(), "label", this.m_language);
        } catch (NullPointerException ex) {
            message = m.getMessage();
        }
        if (message.equalsIgnoreCase(m.getMessage())) {
            message = this.m_i18n.getString(Message.DEFAULT_NAMESPACE, "unknown", "label", this.m_language);
        } else {
            if (m.getVariables() != null) {
                for (int i = 0; i < m.getVariables().length; i++) {
                    message = StringUtils.replaceString(message, "{%" + (i + 1) + "}", m.getVariables()[i]);
                }
            }
        }
        title = this.m_i18n.getString(m.getNamespace(), "title", "label", this.m_language);
    }
    IService trayicon = PIMRuntime.getInstance().getServiceFactory().getService("TrayIcon");
    if (trayicon != null && trayicon.isRunning()) {
        int status = SWT.ICON_INFORMATION;
        if (m.getLevel().equalsIgnoreCase(Message.WARNING))
            status = SWT.ICON_WARNING;
        if (m.getLevel().equalsIgnoreCase(Message.ERROR))
            status = SWT.ICON_ERROR;
        ((TrayIcon) trayicon).setToolTip(message, title, status);
    }
}
Also used : IService(de.janrufmonitor.service.IService)

Example 4 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class ConsoleServerStatus method execute.

public void execute() {
    System.out.println("Server Status:");
    System.out.println("--------------");
    System.out.println();
    IService server = getRuntime().getServiceFactory().getService("Server");
    if (server != null && server.isRunning()) {
        System.out.println("Server started on Port " + getRuntime().getConfigManagerFactory().getConfigManager().getProperty("service.Server", "port"));
        System.out.println();
    }
    ClientRegistry cr = ClientRegistry.getInstance();
    System.out.println("Connected clients: " + cr.getClientCount());
    System.out.println();
    if (cr.getClientCount() > 0) {
        System.out.println("Client details:");
        System.out.println("---------------");
        System.out.println();
        List clients = cr.getAllClients();
        Client c = null;
        for (int i = 0; i < clients.size(); i++) {
            c = (Client) clients.get(i);
            System.out.println("Client: " + c.getClientName() + " (" + c.getClientIP() + ")");
            System.out.println("Port: " + c.getClientPort());
            System.out.println("Send [bytes]: " + c.getByteSend());
            System.out.println("Received [bytes]: " + c.getByteReceived());
            System.out.println("---");
        }
    }
}
Also used : ClientRegistry(de.janrufmonitor.service.server.ClientRegistry) List(java.util.List) Client(de.janrufmonitor.service.server.Client) IService(de.janrufmonitor.service.IService)

Example 5 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class CommentCommand method execute.

public void execute() throws Exception {
    this.isExecuting = true;
    IService s = this.getRuntime().getServiceFactory().getService("CommentService");
    if (s != null && s instanceof CommentService) {
        CommentService cs = (CommentService) s;
        if (!cs.isEnabled()) {
            new SWTExecuter(true, this.getID()) {

                protected void execute() {
                    MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), m_i18n.getString(getNamespace(), "servicedisabled", "label", m_language), m_i18n.getString(getNamespace(), "servicedisabled", "description", m_language));
                }
            }.start();
            this.isExecuting = false;
            return;
        }
        final ICaller c = cs.getLastCaller();
        if (c == null) {
            new SWTExecuter(true, this.getID()) {

                protected void execute() {
                    MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), m_i18n.getString(getNamespace(), "nocaller", "label", m_language), m_i18n.getString(getNamespace(), "nocaller", "description", m_language));
                }
            }.start();
            this.isExecuting = false;
            return;
        }
        if (c.getPhoneNumber().isClired()) {
            new SWTExecuter(true, this.getID()) {

                protected void execute() {
                    MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), m_i18n.getString(getNamespace(), "clircaller", "label", m_language), m_i18n.getString(getNamespace(), "clircaller", "description", m_language));
                }
            }.start();
        } else {
            new SWTExecuter(true, this.getID()) {

                protected void execute() {
                    new Comment(c).open();
                }
            }.start();
        }
    } else {
        this.m_logger.warning("Service CommentService not available.");
    }
    this.isExecuting = false;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) CommentService(de.janrufmonitor.service.comment.CommentService) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) IService(de.janrufmonitor.service.IService)

Aggregations

IService (de.janrufmonitor.service.IService)18 List (java.util.List)6 ICaller (de.janrufmonitor.framework.ICaller)5 CommentService (de.janrufmonitor.service.comment.CommentService)5 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 ICall (de.janrufmonitor.framework.ICall)3 CommentCallerHandler (de.janrufmonitor.service.comment.CommentCallerHandler)3 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)3 Color (org.eclipse.swt.graphics.Color)3 Shell (org.eclipse.swt.widgets.Shell)3 Message (de.janrufmonitor.exception.Message)2 IMonitorListener (de.janrufmonitor.framework.monitor.IMonitorListener)2 Comment (de.janrufmonitor.ui.jface.application.comment.Comment)2 HyperLink (de.janrufmonitor.ui.jface.application.controls.HyperLink)2 ITableCellRenderer (de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2