Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
 - Fixed #1739
 - Fixed text when adding web content
 - Formatting and log level
  • Loading branch information
SubJunk committed Jan 3, 2019
1 parent 8d04fcc commit 1b8d9bc
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/pms/PMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ private synchronized static void createInstance() {
}
} catch (Exception e) {
LOGGER.error("A serious error occurred during {} initialization: {}", PMS.NAME, e.getMessage());
LOGGER.trace("", e);
LOGGER.debug("", e);
}
}

Expand Down
19 changes: 4 additions & 15 deletions src/main/java/net/pms/dlna/RootFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,6 @@ public void loadWebConf() {
*/
private void parseWebConf(File webConf) {
try {
// Remove any existing rows from the Web content GUI

if (SharedContentTab.webContentList != null && SharedContentTab.webContentList.getModel() != null) {
((SharedContentTab.WebContentTableModel) SharedContentTab.webContentList.getModel()).setRowCount(0);
}

try (LineNumberReader br = new LineNumberReader(new InputStreamReader(new FileInputStream(webConf), StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
Expand Down Expand Up @@ -574,34 +568,25 @@ private void parseWebConf(File webConf) {
}
}

String readableType = "";
switch (sourceType) {
case "imagefeed":
readableType = "Image feed";
parent.addChild(new ImagesFeed(uri));
break;
case "videofeed":
readableType = "Video feed";
parent.addChild(new VideosFeed(uri));
break;
case "audiofeed":
readableType = "Podcast";
parent.addChild(new AudiosFeed(uri));
break;
case "audiostream":
readableType = "Audio stream";
parent.addChild(new WebAudioStream(uri, values[1], values[2]));
break;
case "videostream":
readableType = "Video stream";
parent.addChild(new WebVideoStream(uri, values[1], values[2]));
break;
default:
break;
}

// Update the GUI on the Shared Content tab
SharedContentTab.webContentTableModel.addRow(new Object[]{readableType, folderName, uri});
}
} catch (ArrayIndexOutOfBoundsException e) {
// catch exception here and go with parsing
Expand All @@ -616,6 +601,10 @@ private void parseWebConf(File webConf) {
} catch (IOException e) {
LOGGER.warn("Unexpected error in WEB.conf: " + e.getMessage());
LOGGER.debug("", e);
} finally {
if (SharedContentTab.webContentList != null) {
SharedContentTab.parseWebConf(webConf);
}
}
}

Expand Down
107 changes: 100 additions & 7 deletions src/main/java/net/pms/newgui/SharedContentTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
import java.awt.FontMetrics;
import java.awt.Point;
import java.awt.event.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -43,16 +50,21 @@
import net.pms.configuration.PmsConfiguration;
import net.pms.database.TableFilesStatus;
import net.pms.dlna.DLNAMediaDatabase;
import static net.pms.dlna.RootFolder.parseFeedKey;
import static net.pms.dlna.RootFolder.parseFeedValue;
import net.pms.newgui.components.AnimatedIcon;
import net.pms.newgui.components.JAnimatedButton;
import net.pms.newgui.components.JImageButton;
import net.pms.util.FormLayoutUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SharedContentTab {
private static final Vector<String> FOLDERS_COLUMN_NAMES = new Vector<>(
Arrays.asList(new String[] {Messages.getString("Generic.Folder"), Messages.getString("FoldTab.65")})
);
public static final String ALL_DRIVES = Messages.getString("FoldTab.0");
private static final Logger LOGGER = LoggerFactory.getLogger(SharedContentTab.class);

private JPanel sharedPanel;
private JPanel sharedFoldersPanel;
Expand Down Expand Up @@ -162,6 +174,13 @@ public JComponent build() {
sharedFoldersPanel = initSharedFoldersGuiComponents(cc).build();
sharedWebContentPanel = initWebContentGuiComponents(cc).build();

// Load WEB.conf after we are sure the GUI has initialized
String webConfPath = configuration.getWebConfPath();
File webConf = new File(webConfPath);
if (webConf.exists() && configuration.getExternalNetwork()) {
parseWebConf(webConf);
}

builder.add(sharedFoldersPanel, FormLayoutUtil.flip(cc.xyw(1, 1, 12), colSpec, orientation));
builder.add(sharedWebContentPanel, FormLayoutUtil.flip(cc.xyw(1, 3, 12), colSpec, orientation));

Expand Down Expand Up @@ -424,10 +443,12 @@ private PanelBuilder initWebContentGuiComponents(CellConstraints cc) {

webContentList.addMouseListener(new TableMouseListener(webContentList));

/* An attempt to set the correct row height adjusted for font scaling.
/*
* An attempt to set the correct row height adjusted for font scaling.
* It sets all rows based on the font size of cell (0, 0). The + 4 is
* to allow 2 pixels above and below the text. */
DefaultTableCellRenderer cellRenderer = (DefaultTableCellRenderer) webContentList.getCellRenderer(0,0);
* to allow 2 pixels above and below the text.
*/
DefaultTableCellRenderer cellRenderer = (DefaultTableCellRenderer) webContentList.getCellRenderer(0, 0);
FontMetrics metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
webContentList.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
webContentList.setIntercellSpacing(new Dimension(8, 2));
Expand Down Expand Up @@ -457,7 +478,7 @@ public void actionPerformed(ActionEvent e) {

GroupLayout layout = new GroupLayout(addNewWebContentPanel);
addNewWebContentPanel.setLayout(layout);

layout.setHorizontalGroup(
layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
Expand All @@ -478,7 +499,7 @@ public void actionPerformed(ActionEvent e) {
.addContainerGap()
)
);

layout.setVerticalGroup(
layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
Expand All @@ -497,8 +518,8 @@ public void actionPerformed(ActionEvent e) {
.addContainerGap()
)
);
int result = JOptionPane.showConfirmDialog(null, addNewWebContentPanel, Messages.getString("SharedContentTab.AddNewWebFeedStream"), JOptionPane.OK_CANCEL_OPTION);

int result = JOptionPane.showConfirmDialog(null, addNewWebContentPanel, Messages.getString("SharedContentTab.AddNewWebContent"), JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
((WebContentTableModel) webContentList.getModel()).addRow(new Object[]{newEntryType.getSelectedItem(), newEntryFolders.getText(), newEntrySource.getText()});
updateWebContentModel();
Expand Down Expand Up @@ -788,4 +809,76 @@ public void mousePressed(MouseEvent event) {
}
}
}

/**
* This parses the web config and populates the web section of this tab.
*
* @param webConf
*/
public static void parseWebConf(File webConf) {
try {
// Remove any existing rows
((WebContentTableModel) webContentList.getModel()).setRowCount(0);

try (LineNumberReader br = new LineNumberReader(new InputStreamReader(new FileInputStream(webConf), StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
line = line.trim();

if (line.length() > 0 && !line.startsWith("#") && line.indexOf('=') > -1) {
String key = line.substring(0, line.indexOf('='));
String value = line.substring(line.indexOf('=') + 1);
String[] keys = parseFeedKey(key);
String sourceType = keys[0];
String folderName = keys[1] == null ? null : keys[1];

try {
if (
sourceType.equals("imagefeed") ||
sourceType.equals("audiofeed") ||
sourceType.equals("videofeed") ||
sourceType.equals("audiostream") ||
sourceType.equals("videostream")
) {
String[] values = parseFeedValue(value);
String uri = values[0];

String readableType = "";
switch (sourceType) {
case "imagefeed":
readableType = "Image feed";
break;
case "videofeed":
readableType = "Video feed";
break;
case "audiofeed":
readableType = "Podcast";
break;
case "audiostream":
readableType = "Audio stream";
break;
case "videostream":
readableType = "Video stream";
break;
default:
break;
}

webContentTableModel.addRow(new Object[]{readableType, folderName, uri});
}
} catch (ArrayIndexOutOfBoundsException e) {
// catch exception here and go with parsing
LOGGER.info("Error at line " + br.getLineNumber() + " of WEB.conf: " + e.getMessage());
LOGGER.debug(null, e);
}
}
}
}
} catch (FileNotFoundException e) {
LOGGER.debug("Can't read web configuration file {}", e.getMessage());
} catch (IOException e) {
LOGGER.warn("Unexpected error in WEB.conf: " + e.getMessage());
LOGGER.debug("", e);
}
}
}

0 comments on commit 1b8d9bc

Please sign in to comment.