@Override
    public void actionPerformed(ActionEvent arg0) {
      File selectedFile = DATA_MODEL.getFile(TABLE.getSelectedRow());

      // can't create torrents out of empty folders.
      if (selectedFile.isDirectory() && selectedFile.listFiles().length == 0) {
        JOptionPane.showMessageDialog(
            null,
            I18n.tr("The folder you selected is empty."),
            I18n.tr("Invalid Folder"),
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      // can't create torrents if the folder/file can't be read
      if (!selectedFile.canRead()) {
        JOptionPane.showMessageDialog(
            null,
            I18n.tr("Error: You can't read on that file/folder."),
            I18n.tr("Error"),
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      CreateTorrentDialog dlg = new CreateTorrentDialog(GUIMediator.getAppFrame());
      dlg.setChosenContent(
          selectedFile,
          selectedFile.isFile() ? JFileChooser.FILES_ONLY : JFileChooser.DIRECTORIES_ONLY);
      dlg.setVisible(true);
    }
 public LaunchOSAction() {
   String os = "OS";
   if (OSUtils.isWindows()) {
     os = "Windows";
   } else if (OSUtils.isMacOSX()) {
     os = "Mac";
   } else if (OSUtils.isLinux()) {
     os = "Linux";
   }
   putValue(Action.NAME, I18n.tr("Launch in") + " " + os);
   putValue(Action.SHORT_DESCRIPTION, I18n.tr("Launch Selected Files in") + " " + os);
   putValue(LimeAction.ICON_NAME, "LIBRARY_LAUNCH");
 }
    @Override
    public void actionPerformed(ActionEvent e) {
      final short videoCount = (short) TABLE.getSelectedRows().length;

      // can't happen, but just in case.
      if (videoCount < 1) {
        return;
      }

      // get selected files before we switch to audio and loose the selection
      final List<File> selectedFiles = getSelectedFiles();

      selectAudio();

      String status = I18n.tr("Extracting audio from " + videoCount + " selected videos...");
      if (videoCount == 1) {
        status = I18n.tr("Extracting audio from selected video...");
      }
      LibraryMediator.instance().getLibrarySearch().pushStatus(status);

      SwingWorker<Void, Void> demuxWorker =
          new SwingWorker<Void, Void>() {

            @Override
            protected Void doInBackground() throws Exception {
              isDemuxing = true;
              demuxFiles(selectedFiles);
              isDemuxing = false;
              return null;
            }

            @Override
            protected void done() {
              int failed = videoCount - demuxedFiles.size();
              String failedStr = (failed > 0) ? " (" + failed + " " + I18n.tr("failed") + ")" : "";
              LibraryMediator.instance()
                  .getLibrarySearch()
                  .pushStatus(I18n.tr("Done extracting audio.") + failedStr);
            }
          };
      demuxWorker.execute();
    }
  private JMenu createSearchSubMenu(LibraryFilesTableDataLine dl) {
    SkinMenu menu = new SkinMenu(I18n.tr("Search"));

    if (dl != null) {
      File f = dl.getInitializeObject();
      String keywords = QueryUtils.createQueryString(f.getName());
      if (keywords.length() > 0) menu.add(new SkinMenuItem(new SearchAction(keywords)));
    }

    if (menu.getItemCount() == 0) menu.setEnabled(false);

    return menu;
  }
 /**
  * Returns the options offered to the user when removing files.
  *
  * <p>Depending on the platform these can be a subset of MOVE_TO_TRASH, DELETE, CANCEL.
  */
 private static Object[] createRemoveOptions() {
   if (OSUtils.supportsTrash()) {
     String trashLabel =
         OSUtils.isWindows() ? I18n.tr("Move to Recycle Bin") : I18n.tr("Move to Trash");
     return new Object[] {trashLabel, I18n.tr("Delete"), I18n.tr("Cancel")};
   } else {
     return new Object[] {I18n.tr("Delete"), I18n.tr("Cancel")};
   }
 }
 public DemuxMP4AudioAction() {
   putValue(Action.NAME, I18n.tr("Extract Audio"));
   putValue(Action.SHORT_DESCRIPTION, I18n.tr("Extract .m4a Audio from this .mp4 video"));
   demuxedFiles = new ArrayList<File>();
 }
 public SendAudioFilesToiTunes() {
   if (!OSUtils.isLinux()) {
     putValue(Action.NAME, I18n.tr("Send to iTunes"));
     putValue(Action.SHORT_DESCRIPTION, I18n.tr("Send audio files to iTunes"));
   }
 }
 public RemoveAction() {
   putValue(Action.NAME, I18n.tr("Delete"));
   putValue(Action.SHORT_DESCRIPTION, I18n.tr("Delete Selected Files"));
   putValue(LimeAction.ICON_NAME, "LIBRARY_DELETE");
 }
 public CreateTorrentAction() {
   super(I18n.tr("Create New Torrent"));
   putValue(Action.LONG_DESCRIPTION, I18n.tr("Create a new .torrent file"));
 }
 public OpenInFolderAction() {
   putValue(Action.NAME, I18n.tr("Explore"));
   putValue(LimeAction.SHORT_NAME, I18n.tr("Explore"));
   putValue(Action.SHORT_DESCRIPTION, I18n.tr("Open Folder Containing the File"));
   putValue(LimeAction.ICON_NAME, "LIBRARY_EXPLORE");
 }
 public LaunchAction() {
   putValue(Action.NAME, I18n.tr("Launch"));
   putValue(Action.SHORT_DESCRIPTION, I18n.tr("Launch Selected Files"));
   putValue(LimeAction.ICON_NAME, "LIBRARY_LAUNCH");
 }
  /**
   * Override the default removal so we can actually stop sharing and delete the file. Deletes the
   * selected rows in the table. CAUTION: THIS WILL DELETE THE FILE FROM THE DISK.
   */
  public void removeSelection() {
    int[] rows = TABLE.getSelectedRows();
    if (rows.length == 0) return;

    if (TABLE.isEditing()) {
      TableCellEditor editor = TABLE.getCellEditor();
      editor.cancelCellEditing();
    }

    List<File> files = new ArrayList<File>(rows.length);

    // sort row indices and go backwards so list indices don't change when
    // removing the files from the model list
    Arrays.sort(rows);
    for (int i = rows.length - 1; i >= 0; i--) {
      File file = DATA_MODEL.getFile(rows[i]);
      files.add(file);
    }

    CheckBoxListPanel<File> listPanel =
        new CheckBoxListPanel<File>(files, new FileTextProvider(), true);
    listPanel.getList().setVisibleRowCount(4);

    // display list of files that should be deleted
    Object[] message =
        new Object[] {
          new MultiLineLabel(
              I18n.tr(
                  "Are you sure you want to delete the selected file(s), thus removing it from your computer?"),
              400),
          Box.createVerticalStrut(ButtonRow.BUTTON_SEP),
          listPanel,
          Box.createVerticalStrut(ButtonRow.BUTTON_SEP)
        };

    // get platform dependent options which are displayed as buttons in the dialog
    Object[] removeOptions = createRemoveOptions();

    int option =
        JOptionPane.showOptionDialog(
            MessageService.getParentComponent(),
            message,
            I18n.tr("Message"),
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            removeOptions,
            removeOptions[0] /* default option */);

    if (option == removeOptions.length - 1 /* "cancel" option index */
        || option == JOptionPane.CLOSED_OPTION) {
      return;
    }

    // remove still selected files
    List<File> selected = listPanel.getSelectedElements();
    List<String> undeletedFileNames = new ArrayList<String>();

    boolean somethingWasRemoved = false;

    for (File file : selected) {
      // stop seeding if seeding
      BittorrentDownload dm = null;
      if ((dm = TorrentUtil.getDownloadManager(file)) != null) {
        dm.setDeleteDataWhenRemove(false);
        dm.setDeleteTorrentWhenRemove(false);
        BTDownloadMediator.instance().remove(dm);
      }

      // close media player if still playing
      if (MediaPlayer.instance().isThisBeingPlayed(file)) {
        MediaPlayer.instance().stop();
        MPlayerMediator.instance().showPlayerWindow(false);
      }

      // removeOptions > 2 => OS offers trash options
      boolean removed =
          FileUtils.delete(
              file, removeOptions.length > 2 && option == 0 /* "move to trash" option index */);
      if (removed) {
        somethingWasRemoved = true;
        DATA_MODEL.remove(DATA_MODEL.getRow(file));
      } else {
        undeletedFileNames.add(getCompleteFileName(file));
      }
    }

    clearSelection();

    if (somethingWasRemoved) {
      LibraryMediator.instance().getLibraryExplorer().refreshSelection(true);
    }

    if (undeletedFileNames.isEmpty()) {
      return;
    }

    // display list of files that could not be deleted
    message =
        new Object[] {
          new MultiLineLabel(
              I18n.tr(
                  "The following files could not be deleted. They may be in use by another application or are currently being downloaded to."),
              400),
          Box.createVerticalStrut(ButtonRow.BUTTON_SEP),
          new JScrollPane(createFileList(undeletedFileNames))
        };

    JOptionPane.showMessageDialog(
        MessageService.getParentComponent(), message, I18n.tr("Error"), JOptionPane.ERROR_MESSAGE);

    super.removeSelection();
  }