Ejemplo n.º 1
0
 /**
  * do we have values for user/pass/api and are we a donator?!
  *
  * @return true/false if trakt could be called
  */
 private boolean isEnabled() {
   if (!Globals.isDonator()) {
     LOGGER.warn("Won't spawn TRAKT.TV since you are not a donator!");
     return false;
   }
   if (!TRAKT.isTokenSet()) {
     // if we have no token (because auth does not work, try it again)
     return this.Login();
   }
   return true;
 }
  /** Instantiates a new tv show settings panel. */
  public TvShowSettingsPanel() {
    setLayout(
        new FormLayout(
            new ColumnSpec[] {
              FormFactory.RELATED_GAP_COLSPEC,
              ColumnSpec.decode("default:grow"),
              FormFactory.RELATED_GAP_COLSPEC,
              FormFactory.DEFAULT_COLSPEC,
            },
            new RowSpec[] {
              FormFactory.RELATED_GAP_ROWSPEC,
              FormFactory.DEFAULT_ROWSPEC,
              FormFactory.RELATED_GAP_ROWSPEC,
              RowSpec.decode("default:grow"),
            }));

    {
      JPanel panelTvShowDataSources = new JPanel();

      panelTvShowDataSources.setBorder(
          new TitledBorder(
              null,
              BUNDLE.getString("Settings.tvshowdatasource"),
              TitledBorder.LEADING,
              TitledBorder.TOP,
              null,
              null)); //$NON-NLS-1$
      add(panelTvShowDataSources, "2, 2, fill, top");
      panelTvShowDataSources.setLayout(
          new FormLayout(
              new ColumnSpec[] {
                FormFactory.RELATED_GAP_COLSPEC,
                FormFactory.DEFAULT_COLSPEC,
                FormFactory.RELATED_GAP_COLSPEC,
                ColumnSpec.decode("max(40dlu;default)"),
                FormFactory.RELATED_GAP_COLSPEC,
                ColumnSpec.decode("max(44dlu;default):grow"),
                FormFactory.RELATED_GAP_COLSPEC,
                FormFactory.DEFAULT_COLSPEC,
                FormFactory.RELATED_GAP_COLSPEC,
              },
              new RowSpec[] {
                FormFactory.RELATED_GAP_ROWSPEC,
                RowSpec.decode("160px:grow"),
                FormFactory.RELATED_GAP_ROWSPEC,
                FormFactory.DEFAULT_ROWSPEC,
                FormFactory.RELATED_GAP_ROWSPEC,
                FormFactory.DEFAULT_ROWSPEC,
                FormFactory.RELATED_GAP_ROWSPEC,
              }));

      JScrollPane scrollPane = new JScrollPane();
      panelTvShowDataSources.add(scrollPane, "2, 2, 5, 1, fill, fill");

      tableTvShowSources = new JTable();
      tableTvShowSources.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      scrollPane.setViewportView(tableTvShowSources);

      JPanel panelTvShowSourcesButtons = new JPanel();
      panelTvShowDataSources.add(panelTvShowSourcesButtons, "8, 2, default, top");
      panelTvShowSourcesButtons.setLayout(
          new FormLayout(
              new ColumnSpec[] {
                FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
              },
              new RowSpec[] {
                FormFactory.DEFAULT_ROWSPEC,
                FormFactory.RELATED_GAP_ROWSPEC,
                FormFactory.DEFAULT_ROWSPEC,
              }));

      JButton btnAdd = new JButton(BUNDLE.getString("Button.add")); // $NON-NLS-1$
      btnAdd.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
              File file =
                  TmmUIHelper.selectDirectory(
                      BUNDLE.getString("Settings.tvshowdatasource.folderchooser")); // $NON-NLS-1$
              if (file != null && file.exists() && file.isDirectory()) {
                settings.getTvShowSettings().addTvShowDataSources(file.getAbsolutePath());
              }
            }
          });

      panelTvShowSourcesButtons.add(btnAdd, "2, 1, fill, top");

      JButton btnRemove = new JButton(BUNDLE.getString("Button.remove")); // $NON-NLS-1$
      btnRemove.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
              int row =
                  tableTvShowSources.convertRowIndexToModel(tableTvShowSources.getSelectedRow());
              if (row != -1) { // nothing selected
                String path = Globals.settings.getTvShowSettings().getTvShowDataSource().get(row);
                String[] choices = {
                  BUNDLE.getString("Button.continue"), BUNDLE.getString("Button.abort")
                }; //$NON-NLS-1$
                int decision =
                    JOptionPane.showOptionDialog(
                        null,
                        String.format(
                            BUNDLE.getString("Settings.tvshowdatasource.remove.info"), path),
                        BUNDLE.getString("Settings.datasource.remove"),
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.PLAIN_MESSAGE,
                        null,
                        choices,
                        BUNDLE.getString("Button.abort")); // $NON-NLS-1$
                if (decision == 0) {
                  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                  Globals.settings.getTvShowSettings().removeTvShowDataSources(path);
                  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
              }
            }
          });
      panelTvShowSourcesButtons.add(btnRemove, "2, 3, fill, top");

      JLabel lblDvdOrder = new JLabel(BUNDLE.getString("Settings.dvdorder")); // $NON-NLS-1$
      panelTvShowDataSources.add(lblDvdOrder, "2, 4, right, default");

      cbDvdOrder = new JCheckBox("");
      panelTvShowDataSources.add(cbDvdOrder, "4, 4");

      lblImageCache = new JLabel(BUNDLE.getString("Settings.imagecacheimport")); // $NON-NLS-1$
      panelTvShowDataSources.add(lblImageCache, "2, 6, right, default");

      chckbxImageCache = new JCheckBox("");
      panelTvShowDataSources.add(chckbxImageCache, "4, 6");

      lblImageCacheHint =
          new JLabel(BUNDLE.getString("Settings.imagecacheimporthint")); // $NON-NLS-1$
      TmmFontHelper.changeFont(lblImageCacheHint, 0.833);
      panelTvShowDataSources.add(lblImageCacheHint, "6, 6, 3, 1");
    }

    JPanel panel = new JPanel();
    add(panel, "2, 4, fill, fill");
    panel.setLayout(
        new FormLayout(
            new ColumnSpec[] {
              FormFactory.RELATED_GAP_COLSPEC,
              FormFactory.DEFAULT_COLSPEC,
              FormFactory.RELATED_GAP_COLSPEC,
              FormFactory.DEFAULT_COLSPEC,
              FormFactory.RELATED_GAP_COLSPEC,
              FormFactory.DEFAULT_COLSPEC,
              FormFactory.RELATED_GAP_COLSPEC,
            },
            new RowSpec[] {
              FormFactory.RELATED_GAP_ROWSPEC,
              FormFactory.DEFAULT_ROWSPEC,
              FormFactory.RELATED_GAP_ROWSPEC,
            }));

    JLabel lblTraktTv = new JLabel(BUNDLE.getString("Settings.trakt")); // $NON-NLS-1$
    panel.add(lblTraktTv, "2, 2");

    chckbxTraktTv = new JCheckBox("");
    panel.add(chckbxTraktTv, "4, 2");
    btnClearTraktTvShows =
        new JButton(BUNDLE.getString("Settings.trakt.cleartvshows")); // $NON-NLS-1$
    btnClearTraktTvShows.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            int confirm =
                JOptionPane.showOptionDialog(
                    null,
                    BUNDLE.getString("Settings.trakt.cleartvshows.hint"),
                    BUNDLE.getString("Settings.trakt.cleartvshows"),
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    null,
                    null); //$NON-NLS-1$
            if (confirm == JOptionPane.YES_OPTION) {
              TmmTask task = new ClearTraktTvTask(false, true);
              TmmTaskManager.getInstance().addUnnamedTask(task);
            }
          }
        });
    panel.add(btnClearTraktTvShows, "6, 2");

    initDataBindings();

    // column headings
    tableTvShowSources
        .getColumnModel()
        .getColumn(0)
        .setHeaderValue(BUNDLE.getString("Settings.source")); // $NON-NLS-1$

    if (!Globals.isDonator()) {
      chckbxTraktTv.setSelected(false);
      chckbxTraktTv.setEnabled(false);
      btnClearTraktTvShows.setEnabled(false);
    }
  }