Search in sources :

Example 1 with DLNAMediaDatabase

use of net.pms.dlna.DLNAMediaDatabase in project UniversalMediaServer by UniversalMediaServer.

the class HTMLConsole method servePage.

public static String servePage(String resource) {
    StringBuilder sb = new StringBuilder();
    sb.append("<html><head><title>").append(PropertiesUtil.getProjectProperties().get("project.name")).append(" HTML Console</title></head><body>");
    DLNAMediaDatabase database = PMS.get().getDatabase();
    PmsConfiguration configuration = PMS.getConfiguration();
    if (resource.equals("scan") && configuration.getUseCache()) {
        if (!database.isScanLibraryRunning()) {
            database.scanLibrary();
        }
        if (database.isScanLibraryRunning()) {
            sb.append("<p align=center><b>Scan in progress! you can also <a href=\"stop\">stop it</a></b></p><br>");
        }
    }
    if (resource.equals("stop") && configuration.getUseCache() && database.isScanLibraryRunning()) {
        database.stopScanLibrary();
        sb.append("<p align=center><b>Scan stopped!</b></p><br>");
    }
    sb.append("<p align=center><img src='/images/logo.png'><br>").append(PropertiesUtil.getProjectProperties().get("project.name")).append(" HTML console<br><br>Menu:<br>");
    sb.append("<a href=\"home\">Home</a><br>");
    sb.append("<a href=\"scan\">Scan folders</a><br>");
    sb.append("</p></body></html>");
    return sb.toString();
}
Also used : PmsConfiguration(net.pms.configuration.PmsConfiguration) DLNAMediaDatabase(net.pms.dlna.DLNAMediaDatabase)

Example 2 with DLNAMediaDatabase

use of net.pms.dlna.DLNAMediaDatabase in project UniversalMediaServer by UniversalMediaServer.

the class NavigationShareTab method initSharedFoldersGuiComponents.

private PanelBuilder initSharedFoldersGuiComponents(CellConstraints cc) {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec(SHARED_FOLDER_COL_SPEC, orientation);
    FormLayout layoutFolders = new FormLayout(colSpec, SHARED_FOLDER_ROW_SPEC);
    PanelBuilder builderFolder = new PanelBuilder(layoutFolders);
    builderFolder.opaque(true);
    JComponent cmp = builderFolder.addSeparator(Messages.getString("FoldTab.7"), FormLayoutUtil.flip(cc.xyw(1, 1, 7), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
    folderTableModel = new SharedFoldersTableModel();
    FList = new JTable(folderTableModel);
    TableColumn column = FList.getColumnModel().getColumn(0);
    column.setMinWidth(650);
    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItemMarkPlayed = new JMenuItem(Messages.getString("FoldTab.75"));
    JMenuItem menuItemMarkUnplayed = new JMenuItem(Messages.getString("FoldTab.76"));
    menuItemMarkPlayed.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) FList.getValueAt(FList.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, true);
        }
    });
    menuItemMarkUnplayed.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) FList.getValueAt(FList.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, false);
        }
    });
    popupMenu.add(menuItemMarkPlayed);
    popupMenu.add(menuItemMarkUnplayed);
    FList.setComponentPopupMenu(popupMenu);
    FList.addMouseListener(new TableMouseListener(FList));
    /* 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) FList.getCellRenderer(0, 0);
    FontMetrics metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
    FList.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
    FList.setIntercellSpacing(new Dimension(8, 2));
    CustomJButton but = new CustomJButton(LooksFrame.readImageIcon("button-adddirectory.png"));
    but.setToolTipText(Messages.getString("FoldTab.9"));
    but.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showOpenDialog((Component) e.getSource());
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                ((SharedFoldersTableModel) FList.getModel()).addRow(new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
                if (FList.getModel().getValueAt(0, 0).equals(ALL_DRIVES)) {
                    ((SharedFoldersTableModel) FList.getModel()).removeRow(0);
                }
                updateModel();
            }
        }
    });
    builderFolder.add(but, FormLayoutUtil.flip(cc.xy(1, 3), colSpec, orientation));
    CustomJButton but2 = new CustomJButton(LooksFrame.readImageIcon("button-remove.png"));
    but2.setToolTipText(Messages.getString("FoldTab.36"));
    but2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (FList.getSelectedRow() > -1) {
                if (FList.getModel().getRowCount() == 0) {
                    folderTableModel.addRow(new Object[] { ALL_DRIVES, false });
                } else {
                    PMS.get().getDatabase().removeMediaEntriesInFolder((String) FList.getValueAt(FList.getSelectedRow(), 0));
                }
                ((SharedFoldersTableModel) FList.getModel()).removeRow(FList.getSelectedRow());
                updateModel();
            }
        }
    });
    builderFolder.add(but2, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));
    CustomJButton but3 = new CustomJButton(LooksFrame.readImageIcon("button-arrow-down.png"));
    but3.setToolTipText(Messages.getString("FoldTab.12"));
    but3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < FList.getRowCount() - 1; i++) {
                if (FList.isRowSelected(i)) {
                    Object value1 = FList.getValueAt(i, 0);
                    boolean value2 = (boolean) FList.getValueAt(i, 1);
                    FList.setValueAt(FList.getValueAt(i + 1, 0), i, 0);
                    FList.setValueAt(value1, i + 1, 0);
                    FList.setValueAt(FList.getValueAt(i + 1, 1), i, 1);
                    FList.setValueAt(value2, i + 1, 1);
                    FList.changeSelection(i + 1, 1, false, false);
                    break;
                }
            }
        }
    });
    builderFolder.add(but3, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation));
    CustomJButton but4 = new CustomJButton(LooksFrame.readImageIcon("button-arrow-up.png"));
    but4.setToolTipText(Messages.getString("FoldTab.12"));
    but4.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 1; i < FList.getRowCount(); i++) {
                if (FList.isRowSelected(i)) {
                    Object value1 = FList.getValueAt(i, 0);
                    boolean value2 = (boolean) FList.getValueAt(i, 1);
                    FList.setValueAt(FList.getValueAt(i - 1, 0), i, 0);
                    FList.setValueAt(value1, i - 1, 0);
                    FList.setValueAt(FList.getValueAt(i - 1, 1), i, 1);
                    FList.setValueAt(value2, i - 1, 1);
                    FList.changeSelection(i - 1, 1, false, false);
                    break;
                }
            }
        }
    });
    builderFolder.add(but4, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation));
    but5 = new CustomJButton(LooksFrame.readImageIcon("button-scan.png"));
    but5.setToolTipText(Messages.getString("FoldTab.2"));
    but5.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (configuration.getUseCache()) {
                DLNAMediaDatabase database = PMS.get().getDatabase();
                if (database != null) {
                    if (database.isScanLibraryRunning()) {
                        int option = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("FoldTab.10"), Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
                        if (option == JOptionPane.YES_OPTION) {
                            database.stopScanLibrary();
                            looksFrame.setStatusLine(Messages.getString("FoldTab.41"));
                            setScanLibraryEnabled(false);
                            but5.setToolTipText(Messages.getString("FoldTab.41"));
                        }
                    } else {
                        database.scanLibrary();
                        but5.setIcon(LooksFrame.readImageIcon("button-scan-busy.gif"));
                        but5.setRolloverIcon(LooksFrame.readImageIcon("button-scan-cancel.png"));
                        but5.setToolTipText(Messages.getString("FoldTab.40"));
                    }
                }
            }
        }
    });
    /**
     * Hide the scan button in basic mode since we do it automatically now.
     */
    if (!configuration.isHideAdvancedOptions()) {
        builderFolder.add(but5, FormLayoutUtil.flip(cc.xy(5, 3), colSpec, orientation));
    }
    but5.setEnabled(configuration.getUseCache());
    isScanSharedFoldersOnStartup = new JCheckBox(Messages.getString("NetworkTab.StartupScan"), configuration.isScanSharedFoldersOnStartup());
    isScanSharedFoldersOnStartup.setToolTipText(Messages.getString("NetworkTab.StartupScanTooltip"));
    isScanSharedFoldersOnStartup.setContentAreaFilled(false);
    isScanSharedFoldersOnStartup.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setScanSharedFoldersOnStartup((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builderFolder.add(isScanSharedFoldersOnStartup, FormLayoutUtil.flip(cc.xy(7, 3), colSpec, orientation));
    File[] folders = PMS.get().getSharedFoldersArray(false);
    if (folders != null && folders.length > 0) {
        File[] foldersMonitored = PMS.get().getSharedFoldersArray(true);
        for (File folder : folders) {
            boolean isMonitored = false;
            if (foldersMonitored != null && foldersMonitored.length > 0) {
                for (File folderMonitored : foldersMonitored) {
                    if (folderMonitored.getAbsolutePath().equals(folder.getAbsolutePath())) {
                        isMonitored = true;
                    }
                }
            }
            folderTableModel.addRow(new Object[] { folder.getAbsolutePath(), isMonitored });
        }
    } else {
        folderTableModel.addRow(new Object[] { ALL_DRIVES, false });
    }
    JScrollPane pane = new JScrollPane(FList);
    Dimension d = FList.getPreferredSize();
    pane.setPreferredSize(new Dimension(d.width, FList.getRowHeight() * 2));
    builderFolder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 5, 7), colSpec, orientation));
    return builderFolder;
}
Also used : DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) FontMetrics(java.awt.FontMetrics) Component(java.awt.Component) FormLayout(com.jgoodies.forms.layout.FormLayout) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) ComponentOrientation(java.awt.ComponentOrientation) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) CustomJButton(net.pms.newgui.components.CustomJButton) DLNAMediaDatabase(net.pms.dlna.DLNAMediaDatabase) File(java.io.File)

Aggregations

DLNAMediaDatabase (net.pms.dlna.DLNAMediaDatabase)2 PanelBuilder (com.jgoodies.forms.builder.PanelBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 Component (java.awt.Component)1 ComponentOrientation (java.awt.ComponentOrientation)1 Dimension (java.awt.Dimension)1 FontMetrics (java.awt.FontMetrics)1 File (java.io.File)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1 TableColumn (javax.swing.table.TableColumn)1 PmsConfiguration (net.pms.configuration.PmsConfiguration)1 CustomJButton (net.pms.newgui.components.CustomJButton)1