OSDN Git Service

cookieはファイルの場合もディレクトリの場合もあるのでchooserでも両方選択可能とする.
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / ConfigDialog.java
index 6acaf89..720a1f9 100644 (file)
@@ -12,9 +12,10 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.File;
 import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import javax.swing.BorderFactory;
+import javax.swing.ButtonGroup;
 import javax.swing.ComboBoxModel;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.GroupLayout;
@@ -28,16 +29,16 @@ import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JPasswordField;
+import javax.swing.JRadioButton;
 import javax.swing.JSpinner;
 import javax.swing.JTabbedPane;
 import javax.swing.JTextField;
 import javax.swing.LayoutStyle.ComponentPlacement;
 import javax.swing.SpinnerNumberModel;
-import javax.swing.UIManager;
-import javax.swing.UnsupportedLookAndFeelException;
 import javax.swing.WindowConstants;
 import org.apache.commons.configuration.ConfigurationException;
 import yukihane.inqubus.config.Config;
+import yukihane.inqubus.config.Config.CookieBrowser;
 
 /**
  *
@@ -45,7 +46,7 @@ import yukihane.inqubus.config.Config;
  */
 public class ConfigDialog extends JDialog {
     private static final long serialVersionUID = 1L;
-    private static final Logger logger = Logger.getLogger(ConfigDialog.class.getName());
+    private static final Logger logger = LoggerFactory.getLogger(ConfigDialog.class);
     private static final String NEED_REBOOT = "設定を有効にするにはいんきゅばすの再起動が必要です";
 
     /** Creates new form Properties */
@@ -59,10 +60,8 @@ public class ConfigDialog extends JDialog {
         final JTabbedPane tabbedPane = new JTabbedPane();
         final JPanel pnlNetwork = new JPanel();
         final JPanel pnlAccount = new JPanel();
-        final JLabel lblMail = new JLabel();
         fldMail = new JTextField();
         fldPassword.setEchoChar('*');
-        final JLabel lblPassword = new JLabel();
         final JPanel pnlProxy = new JPanel();
         cbProxyUse = new JCheckBox();
         final JLabel lblProxyHost = new JLabel();
@@ -94,10 +93,9 @@ public class ConfigDialog extends JDialog {
         fldFontIndex = new JTextField();
         final JPanel pnlFfmpeg = new JPanel();
         final JPanel pnlFfmpegBinPath = new JPanel();
-        final JLabel lblFfmpegPath = new JLabel();
-        final JLabel lblFfmpegDllPath = new JLabel();
-        fldFfmpegPath = new JTextField();
-        fldFfmpegDllPath = new JTextField();
+        final JLabel lblFfmpegPath = new JLabel("ffmpeg");
+        final JLabel lblFfmpegDllPath = new JLabel("拡張ライブラリ");
+        final JLabel lblMediaInfoPath = new JLabel("MediaInfo");
         final JPanel pnlNgSetting = new JPanel();
         final JPanel pnlSearch = new JPanel();
 
@@ -107,29 +105,34 @@ public class ConfigDialog extends JDialog {
 
         pnlAccount.setBorder(BorderFactory.createTitledBorder("アカウント"));
 
-        lblMail.setText("ID(メールアドレス)");
-
-        lblPassword.setText("パスワード");
+        final JLabel lblMail = new JLabel("ID(メールアドレス)");
+        final JLabel lblPassword = new JLabel("パスワード");
 
         GroupLayout gl_pnlAccount = new GroupLayout(pnlAccount);
         pnlAccount.setLayout(gl_pnlAccount);
-        gl_pnlAccount.setHorizontalGroup(
-            gl_pnlAccount.createParallelGroup(GroupLayout.Alignment.LEADING)
+        gl_pnlAccount.setHorizontalGroup(gl_pnlAccount.createParallelGroup(GroupLayout.Alignment.LEADING)
+            .addComponent(btnAccount)
             .addGroup(gl_pnlAccount.createSequentialGroup()
                 .addContainerGap()
+                .addGap(10)
                 .addGroup(gl_pnlAccount.createParallelGroup(GroupLayout.Alignment.LEADING)
                     .addComponent(lblMail)
-                    .addComponent(lblPassword))
+                    .addComponent(lblPassword)
+                )
                 .addPreferredGap(ComponentPlacement.RELATED)
                 .addGroup(gl_pnlAccount.createParallelGroup(GroupLayout.Alignment.LEADING)
                     .addComponent(fldPassword, GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
-                    .addComponent(fldMail, GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE))
-                .addContainerGap())
+                    .addComponent(fldMail, GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
+                )
+                .addContainerGap()
+            )
         );
         gl_pnlAccount.setVerticalGroup(
             gl_pnlAccount.createParallelGroup(GroupLayout.Alignment.LEADING)
             .addGroup(gl_pnlAccount.createSequentialGroup()
                 .addContainerGap()
+                .addComponent(btnAccount)
+                .addPreferredGap(ComponentPlacement.RELATED)
                 .addGroup(gl_pnlAccount.createParallelGroup(GroupLayout.Alignment.BASELINE)
                     .addComponent(lblMail)
                     .addComponent(fldMail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
@@ -140,6 +143,63 @@ public class ConfigDialog extends JDialog {
                 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
         );
 
+
+        final JButton btnCookie = new JButton("...");
+        btnCookie.addActionListener(new FileChooseActionListener(this, JFileChooser.FILES_AND_DIRECTORIES, fldCookie));
+
+        final ButtonGroup grpLoginType = new ButtonGroup();
+        grpLoginType.add(btnAccount);
+        grpLoginType.add(btnLoginCookie);
+
+        final ButtonGroup grpCookie = new ButtonGroup();
+        grpCookie.add(btnCookieIe);
+        grpCookie.add(btnCookieFirefox);
+        grpCookie.add(btnCookieChrome);
+        grpCookie.add(btnCookieChromium);
+        grpCookie.add(btnCookieOpera);
+        grpCookie.add(btnCookieOther);
+
+        final JPanel pnlCookie = new JPanel();
+        pnlCookie.setBorder(BorderFactory.createTitledBorder("cookie"));
+        final GroupLayout glCookie = new GroupLayout(pnlCookie);
+        pnlCookie.setLayout(glCookie);
+        glCookie.setAutoCreateContainerGaps(true);
+        glCookie.setAutoCreateGaps(true);
+
+        glCookie.setHorizontalGroup(glCookie.createParallelGroup()
+            .addComponent(btnLoginCookie)
+            .addGroup(glCookie.createSequentialGroup()
+                .addGap(10)
+                .addGroup(glCookie.createParallelGroup()
+                    .addComponent(btnCookieIe)
+                    .addComponent(btnCookieFirefox)
+                    .addComponent(btnCookieChrome)
+                    .addComponent(btnCookieChromium)
+                    .addComponent(btnCookieOpera)
+                    .addComponent(btnCookieOther)
+                    .addGroup(glCookie.createSequentialGroup()
+                        .addComponent(fldCookie)
+                        .addComponent(btnCookie)
+                    )
+                )
+            )
+        );
+
+        glCookie.setVerticalGroup(glCookie.createSequentialGroup()
+            .addComponent(btnLoginCookie)
+            .addComponent(btnCookieIe)
+            .addComponent(btnCookieFirefox)
+            .addComponent(btnCookieChrome)
+            .addComponent(btnCookieChromium)
+            .addComponent(btnCookieOpera)
+            .addComponent(btnCookieOther)
+            .addGroup(glCookie.createParallelGroup(Alignment.BASELINE)
+                .addComponent(fldCookie)
+                .addComponent(btnCookie)
+            )
+        );
+
+
         pnlProxy.setBorder(BorderFactory.createTitledBorder("プロキシ"));
 
         cbProxyUse.setText("プロキシを使用する");
@@ -179,9 +239,10 @@ public class ConfigDialog extends JDialog {
                 .addGroup(gl_pnlProxy.createParallelGroup(GroupLayout.Alignment.BASELINE)
                     .addComponent(lblProxyPort)
                     .addComponent(fldProxyPort, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
-                .addContainerGap(39, Short.MAX_VALUE))
+                .addContainerGap())
         );
 
+
         GroupLayout gl_pnlNetwork = new GroupLayout(pnlNetwork);
         pnlNetwork.setLayout(gl_pnlNetwork);
         gl_pnlNetwork.setHorizontalGroup(
@@ -189,8 +250,10 @@ public class ConfigDialog extends JDialog {
             .addGroup(GroupLayout.Alignment.TRAILING, gl_pnlNetwork.createSequentialGroup()
                 .addContainerGap()
                 .addGroup(gl_pnlNetwork.createParallelGroup(GroupLayout.Alignment.TRAILING)
+                    .addComponent(pnlAccount, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                    .addComponent(pnlCookie, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .addComponent(pnlProxy, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-                    .addComponent(pnlAccount, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+                )
                 .addContainerGap())
         );
         gl_pnlNetwork.setVerticalGroup(
@@ -199,8 +262,11 @@ public class ConfigDialog extends JDialog {
                 .addContainerGap()
                 .addComponent(pnlAccount, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(ComponentPlacement.RELATED)
+                .addComponent(pnlCookie, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                .addPreferredGap(ComponentPlacement.RELATED)
                 .addComponent(pnlProxy, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
-                .addContainerGap(178, Short.MAX_VALUE))
+                .addContainerGap()
+            )
         );
 
         tabbedPane.addTab("ネットワーク", pnlNetwork);
@@ -480,10 +546,6 @@ public class ConfigDialog extends JDialog {
 
         pnlFfmpegBinPath.setBorder(BorderFactory.createTitledBorder("ファイルパス"));
 
-        lblFfmpegPath.setText("ffmpeg");
-
-        lblFfmpegDllPath.setText("拡張ライブラリ");
-
         final JButton btnFfmpegPath = new JButton("...");
         btnFfmpegPath.addActionListener(
                 new FileChooseActionListener(ConfigDialog.this, JFileChooser.FILES_ONLY, fldFfmpegPath));
@@ -492,6 +554,10 @@ public class ConfigDialog extends JDialog {
         btnFfmpegDllPath.addActionListener(
                 new FileChooseActionListener(ConfigDialog.this, JFileChooser.FILES_ONLY, fldFfmpegDllPath));
 
+        final JButton btnMediaInfoPath = new JButton("...");
+        btnMediaInfoPath.addActionListener(
+                new FileChooseActionListener(ConfigDialog.this, JFileChooser.FILES_ONLY, fldMediaInfoPath));
+
         GroupLayout gl_jPanel10 = new GroupLayout(pnlFfmpegBinPath);
         pnlFfmpegBinPath.setLayout(gl_jPanel10);
         gl_jPanel10.setHorizontalGroup(
@@ -499,16 +565,22 @@ public class ConfigDialog extends JDialog {
             .addGroup(gl_jPanel10.createSequentialGroup()
                 .addContainerGap()
                 .addGroup(gl_jPanel10.createParallelGroup(GroupLayout.Alignment.LEADING)
+                    .addComponent(lblFfmpegPath)
                     .addComponent(lblFfmpegDllPath)
-                    .addComponent(lblFfmpegPath))
+                    .addComponent(lblMediaInfoPath)
+                )
                 .addPreferredGap(ComponentPlacement.RELATED)
                 .addGroup(gl_jPanel10.createParallelGroup(GroupLayout.Alignment.LEADING)
                     .addComponent(fldFfmpegDllPath, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
-                    .addComponent(fldFfmpegPath, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE))
+                    .addComponent(fldFfmpegPath, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
+                    .addComponent(fldMediaInfoPath, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
+                )
                 .addPreferredGap(ComponentPlacement.RELATED)
                 .addGroup(gl_jPanel10.createParallelGroup(GroupLayout.Alignment.LEADING)
                     .addComponent(btnFfmpegPath, GroupLayout.Alignment.TRAILING)
-                    .addComponent(btnFfmpegDllPath, GroupLayout.Alignment.TRAILING))
+                    .addComponent(btnFfmpegDllPath, GroupLayout.Alignment.TRAILING)
+                    .addComponent(btnMediaInfoPath, GroupLayout.Alignment.TRAILING)
+                )
                 .addContainerGap())
         );
         gl_jPanel10.setVerticalGroup(
@@ -518,12 +590,15 @@ public class ConfigDialog extends JDialog {
                     .addComponent(lblFfmpegPath)
                     .addComponent(fldFfmpegPath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                     .addComponent(btnFfmpegPath))
-                .addPreferredGap(ComponentPlacement.RELATED)
                 .addGroup(gl_jPanel10.createParallelGroup(GroupLayout.Alignment.BASELINE)
                     .addComponent(lblFfmpegDllPath)
                     .addComponent(fldFfmpegDllPath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                     .addComponent(btnFfmpegDllPath))
-                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+                .addGroup(gl_jPanel10.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                    .addComponent(lblMediaInfoPath)
+                    .addComponent(fldMediaInfoPath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                    .addComponent(btnMediaInfoPath))
+            )
         );
 
         pnlFfmpegParam.setBorder(BorderFactory.createTitledBorder("ffmpegパラメータ"));
@@ -750,40 +825,20 @@ public class ConfigDialog extends JDialog {
         loadConfig();
     }
 
-    /**
-     * @param args the command line arguments
-     */
-    public static void main(String args[]) {
-        /* Set the Nimbus look and feel */
-        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
-         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
-         */
-        try {
-            for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
-                if ("Nimbus".equals(info.getName())) {
-                    UIManager.setLookAndFeel(info.getClassName());
-                    break;
-                }
-            }
-        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
-            java.util.logging.Logger.getLogger(ConfigDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        }
-
-        /* Create and display the form */
-        java.awt.EventQueue.invokeLater(new Runnable() {
-
-            @Override
-            public void run() {
-                new ConfigDialog().setVisible(true);
-            }
-        });
-    }
-    // Variables declaration - do not modify//GEN-BEGIN:variables
-
     // ネットワーク
     // ネットワーク - アカウント
+    final JRadioButton btnAccount = new JRadioButton("次の情報を使用してログインする");
     private final JTextField fldMail;
     private final JPasswordField fldPassword = new JPasswordField();
+    // ネットワーク - cookie
+    final JRadioButton btnLoginCookie = new JRadioButton("ブラウザのログイン情報を使用してアクセスする");
+    final JRadioButton btnCookieIe = new JRadioButton("IE(7以降) (Windows)");
+    final JRadioButton btnCookieFirefox = new JRadioButton("Firefox(4以降) (Windows)");
+    final JRadioButton btnCookieChrome = new JRadioButton("Google Chrome (Windows)");
+    final JRadioButton btnCookieChromium = new JRadioButton("Chrome派生ブラウザ (Windows)");
+    final JRadioButton btnCookieOpera = new JRadioButton("Opera (Windows)");
+    final JRadioButton btnCookieOther = new JRadioButton("上記以外 - cookie保存ディレクトリを次に入力");
+    final JTextField fldCookie = new JTextField();
     // ネットワーク - プロキシ
     private final JCheckBox cbProxyUse;
     private final JTextField fldProxyHost = new JTextField();
@@ -820,8 +875,9 @@ public class ConfigDialog extends JDialog {
     private final JCheckBox cbCommentOpaque;
     // ffmpeg
     // ffmpeg - ファイルパス
-    private final JTextField fldFfmpegPath;
-    private final JTextField fldFfmpegDllPath;
+    private final JTextField fldFfmpegPath = new JTextField();
+    private final JTextField fldFfmpegDllPath = new JTextField();
+    private final JTextField fldMediaInfoPath = new JTextField();
     // ffmpeg - ffmpegパラメータ
     private final FfmpegParamPanel pnlFfmpegParam = new FfmpegParamPanel();
     // ffmpeg - その他
@@ -852,10 +908,42 @@ public class ConfigDialog extends JDialog {
         /*
          * ネットワーク - アカウント
          */
+        btnAccount.setSelected(p.getNeedsLogin());
         fldMail.setText(p.getId());
         fldPassword.setText(p.getPassword());
 
         /*
+         * ネットワーク - cookie
+         */
+        btnLoginCookie.setSelected(!p.getNeedsLogin());
+        final CookieBrowser cookieBrowser = p.getCookieBrowser();
+        final JRadioButton enabledBrowser;
+        switch(cookieBrowser){
+            case MSIE:
+                enabledBrowser = btnCookieIe;
+                break;
+            case FIREFOX:
+                enabledBrowser = btnCookieFirefox;
+                break;
+            case CHROME:
+                enabledBrowser = btnCookieChrome;
+                break;
+            case CHROMIUM:
+                enabledBrowser = btnCookieChromium;
+                break;
+            case OPERA:
+                enabledBrowser = btnCookieOpera;
+                break;
+            case OTHER:
+                enabledBrowser = btnCookieOther;
+                break;
+            default:
+                throw new UnsupportedOperationException();
+        }
+        enabledBrowser.setSelected(true);
+        fldCookie.setText(p.getCookieDir());
+
+        /*
          * ネットワーク - プロキシ
          */
         cbProxyUse.setSelected(p.getProxyUse());
@@ -916,6 +1004,7 @@ public class ConfigDialog extends JDialog {
          */
         fldFfmpegPath.setText(p.getFfmpegPath());
         fldFfmpegDllPath.setText(p.getFfmpegDllPath());
+        fldMediaInfoPath.setText(p.getMediaInfoPath());
 
         /*
          * ffmpeg - ffmpegパラメータ
@@ -957,11 +1046,33 @@ public class ConfigDialog extends JDialog {
         /*
          * ネットワーク - アカウント
          */
-
+        p.setNeedsLogin(btnAccount.isSelected());
         p.setId(fldMail.getText());
         p.setPassword(String.valueOf(fldPassword.getPassword()));
 
         /*
+         * ネットワーク - cookie
+         */
+        final CookieBrowser cookieBrowser;
+        if(btnCookieIe.isSelected()) {
+            cookieBrowser = CookieBrowser.MSIE;
+        } else if(btnCookieFirefox.isSelected()) {
+            cookieBrowser = CookieBrowser.FIREFOX;
+        } else if (btnCookieChrome.isSelected()) {
+            cookieBrowser = CookieBrowser.CHROME;
+        } else if (btnCookieChromium.isSelected()) {
+            cookieBrowser = CookieBrowser.CHROMIUM;
+        } else if(btnCookieOpera.isSelected()) {
+            cookieBrowser = CookieBrowser.OPERA;
+        } else if(btnCookieOther.isSelected()) {
+            cookieBrowser = CookieBrowser.OTHER;
+        } else {
+            throw new UnsupportedOperationException();
+        }
+        p.setCookieBrowser(cookieBrowser);
+        p.setCookieDir(fldCookie.getText());
+
+        /*
          * ネットワーク - プロキシ
          */
         p.setProxyUse(cbProxyUse.isSelected());
@@ -1022,6 +1133,7 @@ public class ConfigDialog extends JDialog {
          */
         p.setFfmpegPath(fldFfmpegPath.getText());
         p.setFfmpegDllPath(fldFfmpegDllPath.getText());
+        p.setMediaInfoPath(fldMediaInfoPath.getText());
 
         /*
          * ffmpeg - ffmpegパラメータ
@@ -1067,12 +1179,14 @@ public class ConfigDialog extends JDialog {
         try {
             p.save();
         } catch (ConfigurationException ex) {
-            logger.log(Level.SEVERE, "コンフィグファイル保存に失敗", ex);
+            logger.error("コンフィグファイル保存に失敗", ex);
         }
     }
 }
 
 class DownloadLocationPanel extends JPanel {
+
+    private static final long serialVersionUID = 1L;
     final JTextField fldDir = new JTextField();
     final JTextField fldFileNamePattern = new JTextField();
     final JCheckBox cbLocal = new JCheckBox("local");