use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.
the class TamMessagePlay method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
Object o = selection.getFirstElement();
if (o instanceof ICall) {
if (((ICall) o).getAttributes().contains("fritzbox.tamurl")) {
File message_file = null;
String url = ((ICall) o).getAttributes().get("fritzbox.tamurl").getValue();
File tamMessageDir = new File(PathResolver.getInstance(PIMRuntime.getInstance()).getDataDirectory() + File.separator + "fritzbox-messages");
tamMessageDir.mkdirs();
if (tamMessageDir.exists() && tamMessageDir.isDirectory()) {
message_file = new File(tamMessageDir, ((ICall) o).getUUID() + ".wav");
if (!message_file.exists()) {
FirmwareManager fwm = FirmwareManager.getInstance();
try {
if (!fwm.isLoggedIn())
fwm.login();
String data = fwm.getTamMessage(url);
if (data == null)
return;
ByteArrayInputStream bin = new ByteArrayInputStream(data.getBytes());
Base64Decoder b64 = new Base64Decoder(bin);
FileOutputStream fos = new FileOutputStream(message_file);
Stream.copy(b64, fos);
fos.flush();
fos.close();
} catch (IOException e) {
this.m_logger.warning(e.toString());
} catch (FritzBoxLoginException e) {
this.m_logger.warning(e.toString());
}
}
}
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(message_file);
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
clip.start();
} catch (IOException e) {
this.m_logger.severe(e.getMessage());
} catch (LineUnavailableException e) {
this.m_logger.severe(e.getMessage());
} catch (UnsupportedAudioFileException e) {
this.m_logger.severe(e.getMessage());
}
} else {
new SWTExecuter() {
protected void execute() {
int style = SWT.APPLICATION_MODAL | SWT.OK;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
messageBox.setMessage(getI18nManager().getString(getNamespace(), "notam", "label", getLanguage()));
messageBox.open();
}
}.start();
return;
}
}
}
}
}
use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.
the class FritzBoxPhonebookManager method createFieldEditors.
protected void createFieldEditors() {
FirmwareManager fwm = FirmwareManager.getInstance();
String label = this.m_i18n.getString(this.getNamespace(), "enabled", "label", this.m_language);
if (label.length() < 150)
for (int i = 150; i > label.length(); i--) {
label += " ";
}
BooleanFieldEditor bfe = new BooleanFieldEditor(this.getConfigNamespace() + SEPARATOR + "enabled", label, this.getFieldEditorParent());
bfe.setEnabled((fwm.isInstance(UnitymediaFirmware.class) || fwm.isInstance(SessionIDFritzBoxFirmware.class) || fwm.isInstance(FritzOSFirmware.class) || fwm.isInstance(FritzOS559Firmware.class) || fwm.isInstance(TR064FritzBoxFirmware.class)), this.getFieldEditorParent());
addField(bfe);
if (fwm.isInstance(FritzOSFirmware.class) || fwm.isInstance(FritzOS559Firmware.class) || fwm.isInstance(TR064FritzBoxFirmware.class)) {
try {
if (!fwm.isLoggedIn())
fwm.login();
Map adb = fwm.getAddressbooks();
String[][] list = new String[adb.size()][2];
Iterator i = adb.keySet().iterator();
int c = 0;
while (i.hasNext()) {
list[c][1] = ((Integer) i.next()).toString();
list[c][0] = (String) adb.get(Integer.parseInt(list[c][1]));
c++;
}
ComboFieldEditor cfe = new ComboFieldEditor(getConfigNamespace() + SEPARATOR + "ab", this.m_i18n.getString(this.getNamespace(), "ab", "label", this.m_language), list, this.getFieldEditorParent());
addField(cfe);
} catch (GetAddressbooksException e) {
this.m_logger.severe(e.getMessage());
} catch (IOException e) {
this.m_logger.severe(e.getMessage());
} catch (FritzBoxLoginException e) {
this.m_logger.severe(e.getMessage());
}
}
}
use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.
the class FritzBoxPhonebookManager method createCallerListFromFritzBoxPhonebook.
private void createCallerListFromFritzBoxPhonebook() {
Thread t = new Thread(new Runnable() {
Logger m_logger;
public void run() {
isSyncing = true;
this.m_logger = LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER);
if (this.m_logger.isLoggable(Level.FINE))
this.m_logger.fine("Starting JAM-FritzBoxPhonebookSync-Thread");
File mso_cache = new File(FBP_CACHE_PATH);
if (!mso_cache.exists())
mso_cache.mkdirs();
ICallerList cl = getRuntime().getCallerFactory().createCallerList();
FirmwareManager fwm = FirmwareManager.getInstance();
fwm.startup();
try {
if (!fwm.isLoggedIn())
fwm.login();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("FritzBox Firmware created.");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Login to FritzBox successfull.");
// check if phonebook is configured
String abId = getConfiguration().getProperty(CFG_ADDRESSBOOK, "0");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook ID: #" + abId);
int id = Integer.parseInt(abId);
String name = null;
try {
Map abs = fwm.getAddressbooks();
if (abs.containsKey(Integer.parseInt(abId))) {
name = (String) abs.get(Integer.parseInt(abId));
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook name: " + name);
}
} catch (GetAddressbooksException e) {
this.m_logger.log(Level.WARNING, e.getMessage(), e);
}
List callers = null;
if (name != null) {
callers = fwm.getCallerList(id, name);
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook callers: " + callers.size());
} else {
callers = fwm.getCallerList();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox default phonebook callers: " + callers.size());
}
if (callers.size() == 0) {
try {
getDatabaseHandler().deleteCallerList(getRuntime().getCallerFactory().createCallerList());
getDatabaseHandler().commit();
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
try {
getDatabaseHandler().rollback();
} catch (SQLException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
isSyncing = false;
return;
}
cl.add(FritzBoxMappingManager.getInstance().toCallerList(callers));
} catch (FritzBoxLoginException e2) {
this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
} catch (GetCallerListException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (Throwable e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
try {
getDatabaseHandler().deleteCallerList(getRuntime().getCallerFactory().createCallerList());
getDatabaseHandler().insertOrUpdateCallerList(cl);
getDatabaseHandler().commit();
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
try {
getDatabaseHandler().rollback();
} catch (SQLException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
isSyncing = false;
if (this.m_logger.isLoggable(Level.FINE))
this.m_logger.fine("Stopping JAM-FritzBoxPhonebookSync-Thread");
}
});
t.setName("JAM-FritzBoxPhonebookSync-Thread-(non-deamon)");
t.start();
}
use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.
the class FritzBoxPhonebookManager method removeCaller.
public void removeCaller(ICaller caller) {
FirmwareManager fwm = FirmwareManager.getInstance();
fwm.startup();
try {
if (!fwm.isLoggedIn())
fwm.login();
// check if phonebook is configured
String abId = getConfiguration().getProperty(CFG_ADDRESSBOOK, "0");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook ID: #" + abId);
int id = Integer.parseInt(abId);
IPhonebookEntry pe = FritzBoxMappingManager.getInstance().mapJamCallerToFritzBox(caller);
fwm.deleteCaller(id, pe);
ICallerList cl = getRuntime().getCallerFactory().createCallerList(1);
cl.add(caller);
try {
getDatabaseHandler().deleteCallerList(cl);
getDatabaseHandler().commit();
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
try {
getDatabaseHandler().rollback();
} catch (SQLException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
} catch (FritzBoxLoginException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (DeleteCallerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
if (!this.isSyncing)
this.createCallerListFromFritzBoxPhonebook();
}
use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.
the class FritzBoxPhonebookManager method setCaller.
public void setCaller(ICaller caller) {
FirmwareManager fwm = FirmwareManager.getInstance();
fwm.startup();
try {
if (!fwm.isLoggedIn())
fwm.login();
// check if phonebook is configured
String abId = getConfiguration().getProperty(CFG_ADDRESSBOOK, "0");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook ID: #" + abId);
int id = Integer.parseInt(abId);
IPhonebookEntry pe = FritzBoxMappingManager.getInstance().mapJamCallerToFritzBox(caller);
fwm.setCaller(id, pe);
ICallerList cl = getRuntime().getCallerFactory().createCallerList(1);
cl.add(caller);
try {
getDatabaseHandler().insertOrUpdateCallerList(cl);
getDatabaseHandler().commit();
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
try {
getDatabaseHandler().rollback();
} catch (SQLException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
} catch (FritzBoxLoginException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (SetCallerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
if (!this.isSyncing)
this.createCallerListFromFritzBoxPhonebook();
}
Aggregations