Skip to content

Commit

Permalink
Fix some problems in importing Girr files with embedded IRP protocol.
Browse files Browse the repository at this point in the history
Resolves #542.
  • Loading branch information
bengtmartensson committed Nov 12, 2024
1 parent 643e461 commit 9691652
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/harctoolbox/irscrutinizer/AboutPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import java.net.URI;
import java.net.URISyntaxException;
import org.harctoolbox.guicomponents.GuiUtils;
import org.harctoolbox.ircore.ThisCannotHappenException;

/**
* The mandatory about popup ;-).
*
*/
@SuppressWarnings("serial")
public final class AboutPopup extends javax.swing.JDialog {

private GuiUtils guiUtils;
Expand All @@ -39,15 +41,21 @@ public final class AboutPopup extends javax.swing.JDialog {
public AboutPopup(java.awt.Frame parent, boolean modal) {
super(parent, modal);
if (!(parent instanceof GuiMain))
throw new RuntimeException("Programming error");
throw new ThisCannotHappenException("Programming error");

GuiMain guiMain = (GuiMain) parent;
guiUtils = guiMain.getGuiUtils();
irpTransmogrifierVersion = "IrpTransmogrifier version " + org.harctoolbox.irp.Version.version
+ "; Database version " + guiMain.getIrpDatabase().getVersion();
+ "; Database version ?";
initComponents();
}

public void setVersion(String irpDatabaseVersion) {
irpTransmogrifierVersion = "IrpTransmogrifier version " + org.harctoolbox.irp.Version.version
+ "; Database version " + irpDatabaseVersion;
versionLabel2.setText(irpTransmogrifierVersion);
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
Expand Down
47 changes: 31 additions & 16 deletions src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import org.harctoolbox.remotelocator.NotFoundException;
import org.xml.sax.SAXException;

@SuppressWarnings("serial")
public final class GuiMain extends javax.swing.JFrame {

private final static String ISSUES_URL = "https://github.com/bengtmartensson/IrScrutinizer/issues";
Expand Down Expand Up @@ -225,14 +226,12 @@ public GuiMain(String applicationHome, String propsfilename, boolean verbose, Li
loadLibraries();
setupGuiUtils();
setupTables();
setupIrpDatabase(); // must come before initComponents
setupIrpDatabaseAndDecoder(); // must come before initComponents
setupImporters();
setupDecoder();
loadExportFormats(); // must come before initComponents
initComponents();
if (!LircHardware.isLibraryLoaded())
sendingHardwareTabbedPane.remove(devLircPanel);
girrImporter.setIrpRendererBean(irpMasterBean);
tweakTables();
tweakFrame();
setupRepeatFinder();
Expand All @@ -253,7 +252,7 @@ public GuiMain(String applicationHome, String propsfilename, boolean verbose, Li
* @throws IOException
* @throws ParserConfigurationException
* @throws SAXException
* @throws IrpParseException
* @throws IrpParseException
*/
GuiMain() throws IOException, ParserConfigurationException, SAXException, IrpParseException {
this(System.getProperty("user.dir") + "/target");
Expand Down Expand Up @@ -339,18 +338,24 @@ private void setupTables() {
tableUtils = new TableUtils(guiUtils);
}

private void setupIrpDatabase() throws IOException, IrpParseException, SAXException {
private void setupIrpDatabaseAndDecoder() throws IOException, IrpParseException, SAXException {
List<File> configFiles = new ArrayList<>(4);
configFiles.add(new File(properties.mkPathAbsolute(properties.getIrpProtocolsPath())));
String secondary = properties.getSecondaryIrpProtocolsPath();
if (!secondary.isEmpty())
configFiles.add(new File(secondary));

irpDatabase = new IrpDatabase(configFiles);
Command.setIrpDatabase(irpDatabase);
IrpDatabase newIrpDatabase = new IrpDatabase(configFiles);
properties.addSecondaryIrpProtocolsPathChangeListener((String name1, Object oldValue, Object newValue) -> {
secondaryRemoveMenuItem.setEnabled(!((String) newValue).isEmpty());
});
setupIrpDatabaseAndDecoder(newIrpDatabase);
}

private void setupIrpDatabaseAndDecoder(IrpDatabase newIrpDatabase) throws IrpParseException {
irpDatabase = newIrpDatabase;
setupDecoder();
Command.setIrpDatabase(irpDatabase);
}

private void setupImporters() throws MalformedURLException, IrpParseException {
Expand Down Expand Up @@ -473,7 +478,7 @@ private void setupIctImporter() {

private void setupGirrImporter() throws MalformedURLException {
Command.setAcceptEmptyCommands(properties.getAllowEmptyGirrCommands());
girrImporter = new GirrImporter(properties.getGirrValidate(), new URL(properties.getGirrSchemaLocation()), irpDatabase);
girrImporter = new GirrImporter(properties.getGirrValidate(), new URL(properties.getGirrSchemaLocation()), this);
properties.addGirrSchemaLocationChangeListener((String name1, Object oldValue, Object newValue) -> {
try {
girrImporter.setUrl(new URL((String)newValue));
Expand Down Expand Up @@ -1452,7 +1457,7 @@ private void scrutinizeSignal() {
guiUtils.error("Unspecified error: \"" + ex.getMessage() + "\", please report.");
}
}

/**
* Invoke the decoding on the string given as argument.
* Meant for testing only-
Expand Down Expand Up @@ -1485,10 +1490,6 @@ GuiUtils getGuiUtils() {
return guiUtils;
}

IrpDatabase getIrpDatabase() {
return this.irpDatabase;
}

private void updateOutputFormat(OutputTextFormat format) {
updateOutputFormat(format.ordinal());
}
Expand Down Expand Up @@ -2148,6 +2149,19 @@ private void transformNameActionPerformed(javax.swing.JTable table, NamedIrSigna
model.namesTransform(transformation, rows);
}

public void patchProtocols(IrpDatabase newProtocols) {
if (newProtocols.isEmpty())
return;
irpDatabase.patch(newProtocols);
irpMasterBean.updateProtocols();
try {
setupDecoder();
Command.setIrpDatabase(irpDatabase);
} catch (IrpParseException ex) {
guiUtils.error(ex);
}
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
Expand Down Expand Up @@ -7045,6 +7059,7 @@ private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN
aboutBox = new AboutPopup(this, false);
aboutBox.setLocationRelativeTo(this);
}
aboutBox.setVersion(irpDatabase.getVersion());
aboutBox.setVisible(true);
}//GEN-LAST:event_aboutMenuItemActionPerformed

Expand Down Expand Up @@ -8104,7 +8119,7 @@ private void irpProtocolsSelectMenuItemActionPerformed(java.awt.event.ActionEven

properties.setIrpProtocolsPath(f.getAbsolutePath());
try {
setupIrpDatabase();
setupIrpDatabaseAndDecoder();
} catch (IOException | IrpParseException | SAXException ex) {
guiUtils.error(ex);
}
Expand Down Expand Up @@ -9183,7 +9198,7 @@ private void secondaryIrpProtocolsSelectMenuItemActionPerformed(java.awt.event.A
guiUtils.message("Secondary IrpProtocol file set to " + f.getAbsolutePath() + ".");
}
try {
setupIrpDatabase();
setupIrpDatabaseAndDecoder();
} catch (IOException | IrpParseException | SAXException ex) {
guiUtils.error(ex);
}
Expand All @@ -9205,7 +9220,7 @@ private void secondaryIrpProtocolsEditMenuItemActionPerformed(java.awt.event.Act

private void irpProtocolsReloadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_irpProtocolsReloadMenuItemActionPerformed
try {
setupIrpDatabase();
setupIrpDatabaseAndDecoder();
} catch (IOException | IrpParseException | SAXException ex) {
guiUtils.error(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.harctoolbox.irscrutinizer.importer;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
Expand All @@ -35,10 +34,10 @@
import org.harctoolbox.girr.Remote;
import org.harctoolbox.girr.RemoteSet;
import org.harctoolbox.girr.XmlStatic;
import org.harctoolbox.guicomponents.IrpRenderBean;
import org.harctoolbox.ircore.InvalidArgumentException;
import org.harctoolbox.ircore.IrCoreUtils;
import org.harctoolbox.irp.IrpDatabase;
import org.harctoolbox.irscrutinizer.GuiMain;
import org.harctoolbox.xml.XmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand All @@ -51,22 +50,19 @@
*/
public class GirrImporter extends RemoteSetImporter implements IReaderImporter {
public static final String homeUrl = "http://www.harctoolbox.org/girr";

private static final Logger logger = Logger.getLogger(GirrImporter.class.getName());

private transient Schema schema;
private URL url;
private boolean validate;
private final IrpDatabase irpDatabase;
//private final Set<String>accumulatedProtocols = new HashSet<>(4);
private IrpRenderBean irpMasterBean;
private final GuiMain guiMain;

public GirrImporter(boolean validate, URL url, IrpDatabase irpDatabase) {
public GirrImporter(boolean validate, URL url, GuiMain guiMain) {
super();
schema = null;
this.url = url;
this.validate = validate;
this.irpDatabase = irpDatabase;
this.guiMain = guiMain;
}

/**
Expand Down Expand Up @@ -231,32 +227,13 @@ public String getFormatName() {
return "Girr";
}

public RemoteSet getRemoteSet(File file) throws IOException, FileNotFoundException, ParseException, InvalidArgumentException {
public RemoteSet getRemoteSet(File file) throws IOException, ParseException, InvalidArgumentException {
possiblyZipLoad(file, IrCoreUtils.UTF8_NAME);
return remoteSet;
}

private void accumulateProtocols(String origin) {
IrpDatabase newProtocols = remoteSet.getIrpDatabase();
// This for branch IrpTransmogrifier/setProtocolDocumentation, i.e. IrpTransmogrifier 1.3.*
// for (NamedProtocol p : newProtocols) {
// DocumentFragment doc = p.getDocumentation();
// if (doc == null) {
// try {
// newProtocols.setDocumentation(p.getName(), "Protocol imported from " + origin);
// } catch (UnknownProtocolException ex) {
// throw new ThisCannotHappenException(ex);
// }
// }
// }
if (!newProtocols.isEmpty()) {
// accumulatedProtocols.addAll(newProtocols.getKeys());
irpDatabase.patch(newProtocols);
irpMasterBean.updateProtocols();
}
}

public void setIrpRendererBean(IrpRenderBean irpMasterBean) {
this.irpMasterBean = irpMasterBean;
guiMain.patchProtocols(newProtocols);
}
}

0 comments on commit 9691652

Please sign in to comment.