Search in sources :

Example 41 with Message

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

the class OutlookContactProxy method findContacts.

public synchronized ICallerList findContacts(String searchTerm, String f) throws OutlookContactProxyException {
    if (searchTerm == null || searchTerm.trim().length() == 0)
        return this.getContacts(f);
    ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
    Dispatch mapiNS = null;
    Dispatch contactsFolder = null;
    Dispatch contactsSubFolder = null;
    Dispatch items = null;
    try {
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("created Outlook.Application dispatch");
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Microsoft Outlook version: " + Dispatch.get(outlook.getObject(), "Version"));
        mapiNS = outlook.getProperty("Session").toDispatch();
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Microsoft Outlook namespace: " + mapiNS);
        Variant contactsVariant = new Variant(10);
        contactsFolder = Dispatch.call(mapiNS, "GetDefaultFolder", contactsVariant).toDispatch();
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Microsoft Outlook folder: " + contactsFolder);
        contactsVariant.safeRelease();
        // getting configured subfolders
        List subfolders = new ArrayList();
        if (f != null) {
            subfolders.add(f);
        } else {
            subfolders.add("");
            subfolders.addAll(getAllContactFolders());
        }
        String folder = null;
        for (int i = 0, j = subfolders.size(); i < j; i++) {
            folder = (String) subfolders.get(i);
            items = Dispatch.get(contactsFolder, "items").toDispatch();
            if (items == null)
                continue;
            String[] filters = { OutlookContactConst.LastName, OutlookContactConst.FirstName, OutlookContactConst.BusinessAddressCity, OutlookContactConst.BusinessAddressStreet, OutlookContactConst.BusinessAddressPostalCode, OutlookContactConst.BusinessAddressCountry, OutlookContactConst.BusinessTelephoneNumber, OutlookContactConst.Business2TelephoneNumber, OutlookContactConst.BusinessFaxNumber, OutlookContactConst.Home2TelephoneNumber, OutlookContactConst.HomeAddressCity, OutlookContactConst.HomeAddressCountry, OutlookContactConst.HomeAddressPostalCode, OutlookContactConst.HomeAddressStreet, OutlookContactConst.HomeFaxNumber, OutlookContactConst.HomeTelephoneNumber, OutlookContactConst.MobileTelephoneNumber };
            for (int z = 0; z < filters.length; z++) {
                String filter = String.format("[" + filters[z] + "] = '%s'", searchTerm);
                Variant item = Dispatch.call(items, "find", filter);
                ICallerList cl = null;
                while ((item != null) && (!item.isNull())) {
                    try {
                        Dispatch contact = item.toDispatch();
                        // check UUID in User1 attribute
                        this.checkContactUUID(contact);
                        cl = getCallerListFromSingleContact(contact);
                        if (cl.size() > 0) {
                            if (folder.trim().length() > 0) {
                                IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, folder);
                                for (int l = 0, m = cl.size(); l < m; l++) {
                                    cl.get(l).setAttribute(category);
                                }
                            }
                            for (int k = 0; k < cl.size(); k++) {
                                if (!callers.contains(cl.get(k)))
                                    callers.add(cl.get(k));
                            }
                        }
                        if (contact != null)
                            contact.safeRelease();
                    } catch (ComFailException ex) {
                        this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
                        if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
                            this.m_logger.log(Level.SEVERE, ex.toString(), ex);
                            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
                        } else
                            this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
                    }
                    if (item != null)
                        item.safeRelease();
                    item = Dispatch.call(items, "findNext");
                }
            }
        }
    } catch (ComFailException ex) {
        this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
        if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
            this.m_logger.log(Level.SEVERE, ex.toString(), ex);
            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
        } else
            this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
    } catch (Exception ex) {
        throw new OutlookContactProxyException("Error in Application Outlook.", ex);
    } finally {
        // added 2006/02/05: clean outlook references
        if (items != null)
            items.safeRelease();
        if (contactsFolder != null)
            contactsFolder.safeRelease();
        if (contactsSubFolder != null)
            contactsSubFolder.safeRelease();
        if (mapiNS != null)
            mapiNS.safeRelease();
        if (outlook != null)
            outlook.safeRelease();
    }
    return callers;
}
Also used : Message(de.janrufmonitor.exception.Message) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException) Variant(com.jacob.com.Variant) ICallerList(de.janrufmonitor.framework.ICallerList) ActiveXComponent(com.jacob.activeX.ActiveXComponent) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException)

Example 42 with Message

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

the class OutlookContactProxy method getContacts.

public synchronized ICallerList getContacts(String f) throws OutlookContactProxyException {
    ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    long outlookItemsCount = 0;
    this.m_current = 0;
    this.m_total = (f == null ? this.countAllContact() : this.countContacts(f));
    ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
    Dispatch mapiNS = null;
    Dispatch contactsFolder = null;
    Dispatch contactsSubFolder = null;
    Dispatch items = null;
    try {
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("created Outlook.Application dispatch");
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Microsoft Outlook version: " + Dispatch.get(outlook.getObject(), "Version"));
        mapiNS = outlook.getProperty("Session").toDispatch();
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Microsoft Outlook namespace: " + mapiNS);
        Variant contactsVariant = new Variant(10);
        contactsFolder = Dispatch.call(mapiNS, "GetDefaultFolder", contactsVariant).toDispatch();
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Microsoft Outlook folder: " + contactsFolder);
        contactsVariant.safeRelease();
        // getting configured subfolders
        List subfolders = new ArrayList();
        if (f != null) {
            subfolders.add(f);
        } else {
            subfolders.add("");
            subfolders.addAll(getAllContactFolders());
        }
        String folder = null;
        for (int i = 0, j = subfolders.size(); i < j; i++) {
            folder = (String) subfolders.get(i);
            items = this.getItemsOfFolder(contactsFolder, folder, false);
            if (items == null)
                continue;
            Variant item = Dispatch.call(items, "GetFirst");
            ICallerList cl = null;
            while ((item != null) && (!item.isNull())) {
                try {
                    outlookItemsCount++;
                    this.m_current++;
                    Dispatch contact = item.toDispatch();
                    // check UUID in User1 attribute
                    this.checkContactUUID(contact);
                    cl = getCallerListFromSingleContact(contact);
                    if (cl.size() > 0) {
                        if (folder.trim().length() > 0) {
                            IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, folder);
                            for (int l = 0, m = cl.size(); l < m; l++) {
                                cl.get(l).setAttribute(category);
                            }
                        }
                        callers.add(cl);
                    }
                    if (contact != null)
                        contact.safeRelease();
                } catch (ComFailException ex) {
                    this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
                    if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
                        this.m_logger.log(Level.SEVERE, ex.toString(), ex);
                        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
                    } else
                        this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
                }
                if (item != null)
                    item.safeRelease();
                item = Dispatch.call(items, "GetNext");
            }
        }
    } catch (ComFailException ex) {
        this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
        if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
            this.m_logger.log(Level.SEVERE, ex.toString(), ex);
            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
        } else
            this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
    } catch (Exception ex) {
        throw new OutlookContactProxyException("Error in Application Outlook.", ex);
    } finally {
        // added 2006/02/05: clean outlook references
        if (items != null)
            items.safeRelease();
        if (contactsFolder != null)
            contactsFolder.safeRelease();
        if (contactsSubFolder != null)
            contactsSubFolder.safeRelease();
        if (mapiNS != null)
            mapiNS.safeRelease();
        if (outlook != null)
            outlook.safeRelease();
    }
    this.m_logger.info(outlookItemsCount + " Outlook contacts found and " + callers.size() + " numbers available.");
    return callers;
}
Also used : Message(de.janrufmonitor.exception.Message) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException) Variant(com.jacob.com.Variant) ICallerList(de.janrufmonitor.framework.ICallerList) ActiveXComponent(com.jacob.activeX.ActiveXComponent) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException)

Example 43 with Message

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

the class AbstractBaseApplication method checkAmountOfEntries.

protected void checkAmountOfEntries(long time1, long time2) {
    long delta = time2 - time1;
    long entries = this.m_controller.countElements();
    boolean doNotShowmessage = this.getConfiguration().getProperty(CFG_SHOW_ENTRY_WARNING, "false").equalsIgnoreCase("true");
    if (!doNotShowmessage && delta > 2000 && entries > 100) {
        long right_entry = Math.round((entries / (delta / 1000)) * 0.9);
        String message = this.getI18nManager().getString(this.getNamespace(), "timemessage", "description", this.getLanguage());
        message = StringUtils.replaceString(message, "{%1}", Long.toString(entries));
        message = StringUtils.replaceString(message, "{%2}", Long.toString(right_entry));
        PropagationFactory.getInstance().fire(new Message(Message.WARNING, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(message)), "Tray");
        MessageDialogWithToggle d = MessageDialogWithToggle.openWarning(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "timemessage", "label", this.getLanguage()), message, this.getI18nManager().getString(this.getNamespace(), "confirmtimemessage", "label", this.getLanguage()), false, null, null);
        this.getConfiguration().setProperty(CFG_SHOW_ENTRY_WARNING, (d.getToggleState() ? "true" : "false"));
        this.storeConfiguration();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Message(de.janrufmonitor.exception.Message) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle)

Example 44 with Message

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

the class Activator method setParameters.

public void setParameters(Map m) {
    if (m != null) {
        String status = (String) m.get("status");
        if (status != null && status.length() > 0) {
            IMonitorListener ml = PIMRuntime.getInstance().getMonitorListener();
            if (status.equalsIgnoreCase("invert")) {
                ml.stop();
            }
            if (status.equalsIgnoreCase("revert")) {
                ml.start();
            }
            if (status.equalsIgnoreCase("delay")) {
            // do nothing so far
            }
            IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
            if (tray != null && tray instanceof TrayIcon) {
                ((TrayIcon) tray).setIconStateMonitorListener();
            }
            if (!status.equalsIgnoreCase("delay"))
                PropagationFactory.getInstance().fire(new Message((ml.isRunning() ? Message.INFO : Message.WARNING), getRuntime().getI18nManagerFactory().getI18nManager().getString("monitor.MonitorListener", "title", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE)), new Exception((ml.isRunning() ? getRuntime().getI18nManagerFactory().getI18nManager().getString("monitor.MonitorListener", "on", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE)) : getRuntime().getI18nManagerFactory().getI18nManager().getString("monitor.MonitorListener", "off", "label", getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE))))), "Tray");
        }
    }
}
Also used : IMonitorListener(de.janrufmonitor.framework.monitor.IMonitorListener) Message(de.janrufmonitor.exception.Message) IService(de.janrufmonitor.service.IService)

Example 45 with Message

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

the class IdentifyAction method run.

public synchronized void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            if (selection.getFirstElement() instanceof ICaller) {
                ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                try {
                    IRunnableWithProgress r = new IRunnableWithProgress() {

                        public void run(IProgressMonitor progressMonitor) {
                            progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "identifyprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                            progressMonitor.worked(1);
                            final ICaller caller = (ICaller) selection.getFirstElement();
                            List phones = new ArrayList();
                            if (caller instanceof IMultiPhoneCaller) {
                                phones.addAll(((IMultiPhoneCaller) caller).getPhonenumbers());
                            } else {
                                phones.add(caller.getPhoneNumber());
                            }
                            String ignoreCM = "";
                            IAttribute att = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
                            if (att != null) {
                                ignoreCM = att.getValue();
                            }
                            List activeCMs = getAllActiveCallerManagers(getRuntime(), ignoreCM);
                            ICaller identifiedCaller = null;
                            // identification only makes sence if there are active CMs or if there are numbers
                            if (activeCMs.size() > 0 && phones.size() > 0) {
                                IPhonenumber pn = null;
                                for (int i = 0; i < phones.size(); i++) {
                                    pn = (IPhonenumber) phones.get(i);
                                    identifiedCaller = Identifier.identify(getRuntime(), pn, activeCMs);
                                    if (identifiedCaller != null)
                                        break;
                                }
                            }
                            progressMonitor.done();
                            if (identifiedCaller == null) {
                                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "failedidentify", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                                PropagationFactory.getInstance().fire(new Message(Message.INFO, getNamespace(), "failedidentify", new Exception("Caller with number " + caller.getPhoneNumber() + " not identified...")));
                                return;
                            }
                            // remove repository flag and set all numbers
                            if (!(identifiedCaller instanceof IMultiPhoneCaller)) {
                                identifiedCaller = getRuntime().getCallerFactory().toMultiPhoneCaller(identifiedCaller);
                            }
                            ((IMultiPhoneCaller) identifiedCaller).setPhonenumbers(phones);
                            ((IMultiPhoneCaller) identifiedCaller).setPhoneNumber((IPhonenumber) phones.get(0));
                            IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
                            m.addAll(caller.getAttributes());
                            m.addAll(identifiedCaller.getAttributes());
                            m.remove(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
                            identifiedCaller.setAttributes(m);
                            final ICaller theIdentifiedCaller = identifiedCaller;
                            new SWTExecuter() {

                                protected void execute() {
                                    if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "identify", "label", getLanguage()), getI18nManager().getString(getNamespace(), "identify", "description", getLanguage()))) {
                                        ICaller newCaller = openCallerWizard(theIdentifiedCaller);
                                        if (newCaller != null) {
                                            ICallerList list = getRuntime().getCallerFactory().createCallerList(1);
                                            list.add(caller);
                                            m_app.getController().deleteElements(list);
                                            list.clear();
                                            list.add(newCaller);
                                            m_app.getController().addElements(list);
                                            m_app.updateViews(true);
                                        }
                                    }
                                }
                            }.start();
                        }
                    };
                    pmd.setBlockOnOpen(false);
                    pmd.run(true, false, r);
                // 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);
                }
            }
        }
    }
}
Also used : Message(de.janrufmonitor.exception.Message) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) ICallerList(de.janrufmonitor.framework.ICallerList) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

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