use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class FritzBoxCallCsv method toCall.
public ICall toCall() {
Logger logger = Logger.getLogger(IJAMConst.DEFAULT_LOGGER);
if (this.m_line == null || this.m_line.trim().length() == 0) {
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("No call data found in CSV line: " + this.m_line);
return null;
}
/**
* Added 2011/01/05: added do to NumberFormatException in log, remove the header
*
* Format: Typ;Datum;Name;Rufnummer;Nebenstelle;Eigene Rufnummer;Dauer
*/
if (this.m_line.trim().toLowerCase().startsWith("typ;")) {
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Ignore CSV header line: " + this.m_line);
return null;
}
if (this.m_call == null) {
try {
IRuntime r = PIMRuntime.getInstance();
String[] call = this.m_line.split(";");
if (call.length >= 7) {
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Tokens in CSV line: " + call.length);
// create msn
IMsn msn = r.getCallFactory().createMsn(getMsn(call[5]), "");
msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("MSN set to: " + msn.toString());
// create caller data
int state = Integer.parseInt(call[0]);
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("State set to: " + state);
// added 2016/01/26: ignore incoming active (5) and outgoung active calls (6)
if (state == 5 || state == 6) {
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Ignoring call state: " + state);
return null;
}
String callByCall = null;
ICaller caller = null;
IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[3].trim());
// if no CLIR call, check internal
if (pn == null && state != this.getOutgoingState())
pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[3].trim(), msn.getMSN());
// if no internal call, check regular
if (pn == null && state != this.getOutgoingState()) {
// if incoming call does not start with 0, the Provider number seems to have the wrong format
// assume it is an international format 4971657110
boolean onlyNumbers = call[3].matches("[+-]?[0-9]+");
if (!call[3].startsWith("0") && onlyNumbers) {
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Assuming international call: " + call[3]);
call[3] = "00" + call[3];
}
pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[3].trim(), msn.getMSN());
}
if (pn == null && state == this.getOutgoingState()) {
// added 2006/08/10: trim call-by-call information
// only can occure on state 3/4 (out-going calls)
callByCall = getCallByCall(call[3]);
if (callByCall != null) {
call[3] = call[3].substring(callByCall.length());
}
pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[3].trim(), msn.getMSN());
if (pn == null) {
// requires addition of areacode
if (!call[3].startsWith("0")) {
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Assuming number " + call[3] + " has missing areacode.");
call[3] = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).getAreaCode() + call[3];
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Added areacode to number " + call[3]);
}
pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[3].trim(), msn.getMSN());
}
}
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Phonenumber set to: " + pn);
caller = Identifier.identify(r, pn);
if (caller == null) {
caller = r.getCallerFactory().createCaller(r.getCallerFactory().createName("", call[2]), pn);
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Setting CSV name field as caller name: " + call[2]);
}
// added 2016/01/19: FB Name data if jAnrufmonitor did not find any in his callermanagers
if (caller.getName().getLastname().length() == 0 && caller.getName().getFirstname().length() == 0 && call[2].trim().length() > 0) {
caller.getAttributes().add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, call[2]));
caller.getAttributes().add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, FritzBoxPhonebookManager.ID));
caller.getAttributes().remove(IJAMConst.ATTRIBUTE_NAME_CITY);
}
// create call data
SimpleDateFormat sdf = new SimpleDateFormat(this.m_config.getProperty(CFG_DATEFORMAT, "dd.MM.yy HH:mm"));
Date date = new Date(0);
try {
date = sdf.parse(call[1]);
} catch (ParseException e) {
if (logger != null && logger.isLoggable(Level.SEVERE))
logger.severe("Wrong date format detected: " + e.getMessage());
}
ICip cip = r.getCallFactory().createCip(getCip(call[4]), "");
cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Set CIP to: " + cip);
// create attributes
IAttributeMap am = r.getCallFactory().createAttributeMap();
if (state == 1) {
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_ACCEPTED));
} else if (state == this.getOutgoingState()) {
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
} else if (this.hasRejectedState() && state == this.getRejectedState()) {
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_REJECTED));
} else {
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
}
am.add(r.getCallFactory().createAttribute("fritzbox.line", call[4]));
am.add(r.getCallFactory().createAttribute("fritzbox.duration", Integer.toString(getTime(call[6]))));
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALL_DURATION, Integer.toString(getTime(call[6]))));
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALL_ACTIVE_INDICATOR, IJAMConst.ATTRIBUTE_VALUE_NO));
if (callByCall != null)
am.add(r.getCallFactory().createAttribute("fritzbox.callbycall", callByCall));
if (isSpoofingnumber(call[2])) {
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Spoofing number detected: " + call[2]);
String sn = getSpoofingnumber(call[2]);
IPhonenumber pnx = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(sn.trim());
ICaller cx = Identifier.identify(r, pnx);
if (cx != null) {
am.add(r.getCallFactory().createAttribute("fritzbox.spoofing", cx.getPhoneNumber().getIntAreaCode() + ";" + cx.getPhoneNumber().getAreaCode() + ";" + cx.getPhoneNumber().getCallNumber()));
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_SPOOFED, "true"));
}
}
if (logger != null && logger.isLoggable(Level.INFO))
logger.info("Set attributes to: " + am);
// // create UUID
// StringBuffer uuid = new StringBuffer();
// uuid.append(date.getTime());
// uuid.append("-");
// uuid.append(pn.getTelephoneNumber());
// uuid.append("-");
// uuid.append(msn.getMSN());
//
// if (logger!=null && logger.isLoggable(Level.INFO))
// logger.info("Set UUID to: "+uuid);
//
// // limit uuid to 32 chars
// if (uuid.length()>31) {
// // reduce byte length to append -1 for redundant calls max -1-1 --> 3 calls
// uuid = new StringBuffer(uuid.substring(0,31));
// if (logger!=null && logger.isLoggable(Level.INFO))
// logger.info("Reduce UUID to: "+uuid);
// }
this.m_call = r.getCallFactory().createCall(FritzBoxUUIDManager.getInstance().getUUID(date, pn, msn), caller, msn, cip, date);
this.m_call.setAttributes(am);
}
} catch (NumberFormatException ex) {
if (logger != null && logger.isLoggable(Level.SEVERE))
logger.log(Level.SEVERE, ex.toString(), ex);
} catch (Exception ex) {
if (logger != null && logger.isLoggable(Level.WARNING))
logger.log(Level.WARNING, ex.toString() + ":" + ex.getMessage() + " : problem with line parsing : " + this.m_line, ex);
if (ex instanceof NullPointerException)
if (logger != null && logger.isLoggable(Level.SEVERE))
logger.log(Level.SEVERE, ex.toString(), ex);
return null;
}
}
return this.m_call;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class FritzBoxCallRaw method toCall.
public ICall toCall() {
if (this.m_line == null || this.m_line.length() == 0)
return null;
if (this.m_call == null) {
IRuntime r = PIMRuntime.getInstance();
String[] call = this.m_line.split(";");
if (call.length >= 4 && call[1].equalsIgnoreCase("RING")) {
// create MSN
IMsn msn = r.getCallFactory().createMsn(getMsn(call[4]), "");
msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[3].trim());
// if no CLIR call, check internal
if (pn == null)
pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[3].trim(), msn.getMSN());
// if no internal call, check regular
if (pn == null) {
// if incoming call does not start with 0, the Provider number seems to have the wrong format
// assume it is an international format 4971657110
boolean onlyNumbers = call[3].matches("[+-]?[0-9]+");
if (!call[3].startsWith("0") && onlyNumbers) {
call[3] = "00" + call[3];
}
pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[3].trim(), msn.getMSN());
}
ICaller caller = r.getCallerFactory().createCaller(pn);
// create call data
// added 2009/05/01
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
Date date = new Date(0);
try {
date = sdf.parse(call[0]);
date = this.toFritzboxDate(date);
} catch (ParseException e) {
Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong standard date format detected.");
sdf = new SimpleDateFormat(this.m_config.getProperty(CFG_DATEFORMAT, "dd.MM.yy HH:mm"));
try {
date = sdf.parse(call[0]);
date = this.toFritzboxDate(date);
} catch (ParseException ex) {
Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong custom date format detected.");
}
}
ICip cip = r.getCallFactory().createCip(getCip(call[5]), "");
cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
// create attributes
IAttributeMap am = r.getCallFactory().createAttributeMap();
am.add(r.getCallFactory().createAttribute("fritzbox.key", call[2]));
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
this.m_call = r.getCallFactory().createCall(FritzBoxUUIDManager.getInstance().calculateUUID(FritzBoxUUIDManager.getInstance().getUUID(date, pn, msn)), caller, msn, cip, date);
this.m_call.setAttributes(am);
}
if (call.length >= 4 && call[1].equalsIgnoreCase("CALL")) {
// create msn
String s_msn = null;
if (call.length >= 7) {
s_msn = getMsn(call[6]);
if (s_msn == null || call[6].equalsIgnoreCase(s_msn))
s_msn = getMsn(call[4]);
} else {
s_msn = getMsn(call[4]);
}
IMsn msn = r.getCallFactory().createMsn((s_msn == null ? "" : s_msn), "");
msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
// create caller data
String callByCall = null;
IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[5].trim());
// if no CLIR call, check internal
if (pn == null)
pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[5].trim(), msn.getMSN());
// if no internal call, check regular
if (pn == null) {
// added 2006/08/10: trim call-by-call information
// only can occure on state CALL (out-going calls)
callByCall = getCallByCall(call[5]);
if (callByCall != null) {
call[5] = call[5].substring(callByCall.length());
}
// requires addition of areacode
if (!call[5].startsWith("0")) {
Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Assuming number " + call[5] + " has missing areacode.");
call[5] = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).getAreaCode() + call[5];
Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Added areacode to number " + call[5]);
}
pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[5].trim(), msn.getMSN());
}
ICaller caller = r.getCallerFactory().createCaller(pn);
// create call data
// added 2009/05/27
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
Date date = new Date(0);
try {
date = sdf.parse(call[0]);
date = this.toFritzboxDate(date);
} catch (ParseException e) {
Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong standard date format detected.");
sdf = new SimpleDateFormat(this.m_config.getProperty(CFG_DATEFORMAT, "dd.MM.yy HH:mm"));
try {
date = sdf.parse(call[0]);
date = this.toFritzboxDate(date);
} catch (ParseException ex) {
Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong custom date format detected.");
}
}
ICip cip = r.getCallFactory().createCip(getCip(call[6]), "");
cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
// create attributes
IAttributeMap am = r.getCallFactory().createAttributeMap();
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
am.add(r.getCallFactory().createAttribute("fritzbox.key", call[2]));
if (callByCall != null)
am.add(r.getCallFactory().createAttribute("fritzbox.callbycall", callByCall));
this.m_call = r.getCallFactory().createCall(FritzBoxUUIDManager.getInstance().calculateUUID(FritzBoxUUIDManager.getInstance().getUUID(date, pn, msn)), caller, msn, cip, date);
this.m_call.setAttributes(am);
}
}
return this.m_call;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class OldImportAction method doImport.
private synchronized void doImport(List fileList) {
this.m_logger.info("Starting import of " + fileList.size() + " comments.");
for (int i = 0; i < fileList.size(); i++) {
File f = (File) fileList.get(i);
String number = f.getName().substring(1, f.getName().indexOf("."));
IPhonenumber pn = this.getRuntime().getCallerFactory().createPhonenumber(number);
try {
ICaller c = Identifier.identifyDefault(PIMRuntime.getInstance(), pn);
ICommentCaller cc = null;
if (this.getHandler().hasCommentCaller(c)) {
cc = this.getHandler().getCommentCaller(c);
} else {
cc = this.getHandler().createCommentCaller(c);
}
IComment comment = this.getHandler().createComment();
String content = this.getCommentContent(new FileInputStream(f));
comment.setText(content);
comment.setDate(new Date(f.lastModified()));
cc.addComment(comment);
this.getHandler().setCommentCaller(cc);
} catch (FileNotFoundException e) {
this.m_logger.severe(e.toString() + ": " + e.getMessage());
} catch (IOException e) {
this.m_logger.severe(e.toString() + ": " + e.getMessage());
}
}
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class MultiPhoneCallerPage method createControl.
public void createControl(Composite parent) {
Composite c = new Composite(parent, SWT.NONE);
c.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300 + ("true".equalsIgnoreCase(System.getProperty(IJAMConst.SYSTEM_UI_4K, "false")) ? 40 : 0);
gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
c.setLayoutData(gd);
// CALLER DATA
Group callerGroup = new Group(c, SWT.SHADOW_ETCHED_IN);
callerGroup.setText(this.m_i18n.getString(getNamespace(), "callergroup", "label", this.m_language));
callerGroup.setLayout(new GridLayout(2, false));
callerGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
this.renderAsText(callerGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME), 210, 0, this.m_callerReadonly);
this.renderAsText(callerGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME), 210, 0, this.m_callerReadonly);
this.renderAsText(callerGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL), 0, 2, this.m_callerReadonly);
this.renderAsText(callerGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL), 0, 2, this.m_callerReadonly);
// ADDRESS AREA
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 2;
Group addressGroup = new Group(callerGroup, SWT.SHADOW_ETCHED_IN);
addressGroup.setText(this.m_i18n.getString(getNamespace(), "addressgroup", "label", this.m_language));
addressGroup.setLayout(new GridLayout(3, false));
addressGroup.setLayoutData(gd);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET), 370, 2, this.m_callerReadonly);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO), 0, 0, this.m_callerReadonly);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE), 75, 0, this.m_callerReadonly);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY), 345, 2, this.m_callerReadonly);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY), 0, 3, this.m_callerReadonly);
Composite t = new Composite(c, SWT.NONE);
t.setLayout(new GridLayout(2, false));
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.verticalSpan = 2;
gd.verticalIndent = 10;
gd.verticalAlignment = GridData.VERTICAL_ALIGN_END;
t.setLayoutData(gd);
// IMAGE
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
if (OSUtils.isMacOSX()) {
gd.heightHint = 110;
final Label image = new Label(t, SWT.NONE);
image.setLayoutData(gd);
image.setImage(this.getCallerImage());
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
} else {
image.setToolTipText(m_i18n.getString(getNamespace(), "pixel", "label", m_language));
}
new Label(t, SWT.NONE);
image.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent arg0) {
if (!m_callerReadonly) {
FileDialog fde = new FileDialog(getShell(), SWT.OPEN);
fde.setFilterExtensions(new String[] { "*.jpg", "*.jpeg", "*.gif", "*.png" });
fde.setText(m_i18n.getString(getNamespace(), "select", "label", m_language));
fde.setFilterPath(PathResolver.getInstance(getRuntime()).resolve(getAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)));
String imagePath = fde.open();
if (imagePath != null) {
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance(getRuntime()).encode(imagePath));
image.setImage(getNewImage(imagePath));
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
}
setPageComplete(isComplete());
}
}
}
public void mouseDown(MouseEvent arg0) {
}
public void mouseUp(MouseEvent arg0) {
}
});
Menu m = new Menu(image);
MenuItem mi = new MenuItem(m, SWT.PUSH);
mi.setText(m_i18n.getString(getNamespace(), "remove", "label", m_language));
mi.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, "");
image.setImage(getNewImage(""));
image.setToolTipText(m_i18n.getString(getNamespace(), "pixel", "label", m_language));
// check if number image exist
if (m_caller != null && m_caller.getPhoneNumber().getTelephoneNumber().length() > 0) {
File photo = new File(PathResolver.getInstance().getPhotoDirectory(), m_caller.getPhoneNumber().getTelephoneNumber() + ".jpg");
if (photo.exists()) {
photo.delete();
}
photo = new File(PathResolver.getInstance().getPhotoDirectory(), m_caller.getPhoneNumber().getTelephoneNumber() + ".png");
if (photo.exists()) {
photo.delete();
}
}
setPageComplete(isComplete());
}
});
image.setMenu(m);
final Button gravatar = new Button(t, SWT.CHECK);
gravatar.setText(this.m_i18n.getString(this.getNamespace(), "gravatar", "label", this.m_language));
gravatar.setSelection(this.m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GRAVATAR));
this.m_useGRAVATAR = this.m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GRAVATAR);
gravatar.setEnabled(!m_callerReadonly);
gravatar.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
m_useGRAVATAR = gravatar.getSelection();
if (m_useGRAVATAR && m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
String email = m_caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue();
if (email != null && email.length() > 0) {
File dir = new File(PathResolver.getInstance().getPhotoDirectory());
if (!dir.exists())
dir.mkdirs();
File img = new File(dir, m_caller.getPhoneNumber().getTelephoneNumber() + ".jpg");
try {
email = StringUtils.toMD5Hex(email);
String gravatar = "http://www.gravatar.com/avatar/" + email + ".jpg?d=404&s=120";
URL url = new URL(gravatar);
URLConnection c = url.openConnection();
StringBuffer agent = new StringBuffer();
agent.append("jAnrufmonitor Update Manager ");
agent.append(IJAMConst.VERSION_DISPLAY);
c.setDoInput(true);
c.setRequestProperty("User-Agent", agent.toString());
c.connect();
Object o = url.openStream();
if (o instanceof InputStream) {
BufferedInputStream bin = new BufferedInputStream((InputStream) o);
FileOutputStream fos = new FileOutputStream(img);
Stream.copy(bin, fos, true);
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, img.getAbsolutePath());
image.setImage(getNewImage(img.getAbsolutePath()));
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
}
}
} catch (FileNotFoundException ex) {
m_logger.info("No GRAVATAR found: " + ex.getMessage());
} catch (IOException ex) {
m_logger.info("IOException: " + ex.getMessage());
}
}
}
setPageComplete(isComplete());
}
});
} else {
final Button image = new Button(t, SWT.PUSH);
image.setLayoutData(gd);
image.setImage(this.getCallerImage());
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
} else {
image.setToolTipText(m_i18n.getString(getNamespace(), "pixel", "label", m_language));
}
new Label(t, SWT.NONE);
image.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (!m_callerReadonly) {
FileDialog fde = new FileDialog(getShell(), SWT.OPEN);
fde.setFilterExtensions(new String[] { "*.jpg", "*.jpeg", "*.gif", "*.png" });
fde.setText(m_i18n.getString(getNamespace(), "select", "label", m_language));
fde.setFilterPath(PathResolver.getInstance(getRuntime()).resolve(getAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)));
String imagePath = fde.open();
if (imagePath != null) {
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance(getRuntime()).encode(imagePath));
image.setImage(getNewImage(imagePath));
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
}
setPageComplete(isComplete());
}
}
}
});
Menu m = new Menu(image);
MenuItem mi = new MenuItem(m, SWT.PUSH);
mi.setText(m_i18n.getString(getNamespace(), "remove", "label", m_language));
mi.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, "");
image.setImage(getNewImage(""));
image.setToolTipText(m_i18n.getString(getNamespace(), "pixel", "label", m_language));
// check if number image exist
if (m_caller != null && m_caller.getPhoneNumber().getTelephoneNumber().length() > 0) {
File photo = new File(PathResolver.getInstance().getPhotoDirectory(), m_caller.getPhoneNumber().getTelephoneNumber() + ".jpg");
if (photo.exists()) {
photo.delete();
}
photo = new File(PathResolver.getInstance().getPhotoDirectory(), m_caller.getPhoneNumber().getTelephoneNumber() + ".png");
if (photo.exists()) {
photo.delete();
}
}
setPageComplete(isComplete());
}
});
image.setMenu(m);
final Button gravatar = new Button(t, SWT.CHECK);
gravatar.setText(this.m_i18n.getString(this.getNamespace(), "gravatar", "label", this.m_language));
gravatar.setSelection(this.m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GRAVATAR));
this.m_useGRAVATAR = this.m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GRAVATAR);
gravatar.setEnabled(!m_callerReadonly);
gravatar.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
m_useGRAVATAR = gravatar.getSelection();
// }
if (m_useGRAVATAR && m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
String email = m_caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue();
if (email != null && email.length() > 0) {
File dir = new File(PathResolver.getInstance().getPhotoDirectory());
if (!dir.exists())
dir.mkdirs();
File img = new File(dir, m_caller.getPhoneNumber().getTelephoneNumber() + ".jpg");
try {
email = StringUtils.toMD5Hex(email);
String gravatar = "http://www.gravatar.com/avatar/" + email + ".jpg?d=404&s=120";
URL url = new URL(gravatar);
URLConnection c = url.openConnection();
StringBuffer agent = new StringBuffer();
agent.append("jAnrufmonitor Update Manager ");
agent.append(IJAMConst.VERSION_DISPLAY);
c.setDoInput(true);
c.setRequestProperty("User-Agent", agent.toString());
c.connect();
Object o = url.openStream();
if (o instanceof InputStream) {
BufferedInputStream bin = new BufferedInputStream((InputStream) o);
FileOutputStream fos = new FileOutputStream(img);
Stream.copy(bin, fos, true);
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, img.getAbsolutePath());
image.setImage(getNewImage(img.getAbsolutePath()));
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
}
}
} catch (FileNotFoundException ex) {
m_logger.info("No GRAVATAR found: " + ex.getMessage());
} catch (IOException ex) {
m_logger.info("IOException: " + ex.getMessage());
}
}
}
setPageComplete(isComplete());
}
});
}
// NUMBER DATA
Composite c1 = new Composite(c, SWT.NONE);
c1.setLayout(new GridLayout(1, false));
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300 + ("true".equalsIgnoreCase(System.getProperty(IJAMConst.SYSTEM_UI_4K, "false")) ? 40 : 0);
gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
c1.setLayoutData(gd);
tabFolder = new TabFolder(c1, SWT.BORDER);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300 + ("true".equalsIgnoreCase(System.getProperty(IJAMConst.SYSTEM_UI_4K, "false")) ? 40 : 0);
gd.heightHint = 65 + ("true".equalsIgnoreCase(System.getProperty(IJAMConst.SYSTEM_UI_4K, "false")) ? 20 : 0);
// gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
tabFolder.setLayoutData(gd);
tabFolder.setFocus();
List phones = m_caller.getPhonenumbers();
for (int i = 0, j = phones.size(); i < j; i++) {
new NumberView((IPhonenumber) phones.get(i), this.m_caller.getAttributes(), tabFolder, m_i18n.getString(getNamespace(), "std_phone", "label", m_language)).render();
}
tabFolder.pack();
if (!this.m_callerReadonly && !m_caller.getPhoneNumber().isClired()) {
// selectButton
gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
Composite bc = new Composite(c1, SWT.NONE);
bc.setLayout(new GridLayout(2, false));
final Button addPhone = new Button(bc, SWT.PUSH);
addPhone.setLayoutData(gd);
addPhone.setText(m_i18n.getString(getNamespace(), "add_phone", "label", m_language));
addPhone.setVisible(!m_numberReadonly);
final Button removePhone = new Button(bc, SWT.PUSH);
removePhone.setLayoutData(gd);
removePhone.setText(m_i18n.getString(getNamespace(), "remove_phone", "label", m_language));
removePhone.setEnabled(false);
removePhone.setVisible(!m_numberReadonly);
addPhone.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (tabFolder.getItemCount() < 6) {
new NumberView(getRuntime().getCallerFactory().createPhonenumber(true), m_caller.getAttributes(), tabFolder, m_i18n.getString(getNamespace(), "std_phone", "label", m_language)).render();
tabFolder.setSelection(tabFolder.getItemCount() - 1);
} else
addPhone.setEnabled(false);
removePhone.setEnabled(true);
setPageComplete(isComplete());
}
});
removePhone.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TabItem[] items = tabFolder.getSelection();
if (items.length == 1 && tabFolder.getItemCount() > 1)
items[0].dispose();
addPhone.setEnabled(true);
removePhone.setEnabled(tabFolder.getItemCount() > 1);
setPageComplete(isComplete());
}
});
if (tabFolder.getItemCount() > 1)
removePhone.setEnabled(true);
// new Label(c, SWT.NONE);
// CATEGORIES
Group categoryGroup = new Group(c, SWT.SHADOW_ETCHED_IN);
categoryGroup.setText(this.m_i18n.getString(getNamespace(), "categorygroup", "label", this.m_language));
categoryGroup.setLayout(new GridLayout(2, true));
categoryGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
categoryGroup.setToolTipText(m_i18n.getString(getNamespace(), "tooltipprefix", "label", m_language) + IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_PREFIX + IJAMConst.ATTRIBUTE_NAME_CATEGORY + IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_POSTFIX);
IAttribute category = this.m_caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
final Combo categoryCombo = new Combo(categoryGroup, SWT.READ_ONLY);
String categories = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(Editor.NAMESPACE, "categories");
String[] tmp = categories.split(",");
String[] categoryList = new String[tmp.length + 1];
categoryList[0] = "";
for (int i = tmp.length - 1, k = 1; i >= 0; i--, k++) {
categoryList[k] = tmp[i];
}
int select = 0;
for (int i = 0; i < categoryList.length; i++) {
categoryCombo.setData(categoryList[i], categoryList[i]);
if (category != null && categoryList[i].equalsIgnoreCase(category.getValue())) {
select = i;
}
}
categoryCombo.setItems(categoryList);
categoryCombo.select(select);
// Add the handler to update the name based on input
categoryCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String scat = categoryCombo.getItem(categoryCombo.getSelectionIndex());
m_caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, scat));
if (scat == null || scat.trim().length() == 0) {
m_caller.getAttributes().remove(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
}
setPageComplete(isComplete());
}
});
}
c.pack();
setPageComplete(isComplete());
setControl(c);
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class AbstractCallDatabaseHandler method updateCallList.
/**
* Updates all calls in the submitted list. The select criterion of teh call is its UUID.
* @param cl
* @throws SQLException
*/
public void updateCallList(ICallList cl) throws SQLException {
if (!isConnected())
try {
this.connect();
} catch (ClassNotFoundException e) {
throw new SQLException(e.getMessage());
}
if (this.containsListAll(cl.size())) {
this.createTables();
this.setCallList(cl);
return;
}
PreparedStatement ps = this.getStatement("UPDATE_CALL");
PreparedStatement psa = this.getStatement("UPDATE_ATTRIBUTE");
ps.clearBatch();
psa.clearBatch();
ICall c = null;
IPhonenumber pn = null;
for (int i = 0, j = cl.size(); i < j; i++) {
c = cl.get(i);
pn = c.getCaller().getPhoneNumber();
try {
this.updateCall(ps, c.getUUID(), c.getCaller().getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), c.getMSN().getMSN(), c.getCIP().getCIP(), c.getDate().getTime(), Serializer.toByteArray(c));
this.updateAttributes(psa, c.getUUID(), c.getAttributes());
this.updateAttributes(psa, c.getCaller().getUUID(), c.getCaller().getAttributes());
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
if (i % this.commit_count == 0) {
ps.executeBatch();
ps.clearBatch();
this.m_logger.info("Executed prepared statement: " + ps.toString());
psa.executeBatch();
psa.clearBatch();
this.m_logger.info("Executed prepared statement: " + psa.toString());
}
}
// execute the rest batch content
ps.executeBatch();
psa.executeBatch();
}
Aggregations