public void EVENT_openfile(ActionEvent e) {
    int selection[] = table.getSelectedRows();

    if (selection == null || selection.length == 0) {
      return;
    }
    if (selection.length > 1) {
      OptionDialog.showErrorDialog(ui.getMainWindow(), "You can only open one folder or file");
      return;
    }

    Download d = rows.get(selection[0]).download;
    if (d.isComplete() == true) {
      String path =
          ui.getCore().getSettings().getInternal().getDownloadfolder()
              + "\\"
              + d.getAuxInfoFilename();
      try {
        Desktop.getDesktop().open(new File(path));
      } catch (IOException ex) {
        OptionDialog.showErrorDialog(
            ui.getMainWindow(), "This type of file hasn't been associated with any program");
      } catch (IllegalArgumentException ex) {
        OptionDialog.showErrorDialog(
            ui.getMainWindow(), "This type of file hasn't been associated with any program");
      } catch (UnsupportedOperationException ex) {
        OptionDialog.showErrorDialog(
            ui.getMainWindow(), "This operation is not supported on this architecture");
      }
    } else {
      OptionDialog.showErrorDialog(ui.getMainWindow(), "File hasn't been downloaded yet");
    }
  }
  public void EVENT_remove(ActionEvent e) {
    int selection[] = table.getSelectedRows();

    if (selection != null && selection.length > 0) {
      for (int i : selection) {
        Download d = rows.get(i).download;
        if (!d.isComplete()) {
          if (OptionDialog.showQuestionDialog(
              ui.getMainWindow(),
              "Are you sure you want to remove the selected downloads from your harddrive and download queue?")) {
            break;
          } else {
            return;
          }
        }
      }

      final ArrayList<Download> dls = new ArrayList<Download>();
      for (int i : selection) {
        dls.add(rows.get(i).download);
      }
      ui.getCore()
          .invokeLater(
              new Runnable() {

                @Override
                public void run() {
                  for (Download d : dls) {
                    if (d.isComplete()) {
                      ui.getCore().getNetworkManager().getDownloadManager().remove(d);
                    } else {
                      try {
                        ui.getCore().getNetworkManager().getDownloadManager().deleteDownload(d);
                      } catch (IOException e1) {
                        ui.handleErrorInEventLoop(e1);
                      }
                    }
                  }
                  SwingUtilities.invokeLater(
                      new Runnable() {

                        @Override
                        public void run() {
                          update();
                        }
                      });
                }
              });
    }
  }
Esempio n. 3
0
 public static Download createFrom(ObjectInputStream in, DownloadManager m) throws IOException {
   try {
     Hash h = new Hash();
     int r = in.read(h.array());
     String fn = in.readUTF();
     ArrayList<Integer> guids = (ArrayList<Integer>) in.readObject();
     if (T.t) {
       T.ass(r == h.array().length, "Incorrect length when deserializing download");
     }
     BlockStorage bs = BlockStorage.getById(m.getCore(), in.readInt());
     Download d = new Download(m, h, bs, fn, guids);
     d.fd = d.manager.getCore().getFileManager().getFd(h);
     return d;
   } catch (ClassNotFoundException e) {
     throw new IOException("Could not find class while deserializing: " + e);
   }
 }
 public void update() {
   try {
     if (download.getFd() == null) {
       if (download.getNConnections() == 0) {
         name = download.getAuxInfoFilename();
       } else {
         name = download.getAuxInfoFilename() + " - starting...";
       }
       size = "?";
     } else {
       name = download.getFd().getSubpath();
       size = TextUtils.formatByteSize(download.getFd().getSize());
     }
     percentComplete = download.getPercentComplete();
     numberOfConnections = download.getNConnections();
     speed = download.getBandwidth().getCPSHumanReadable();
     complete = download.isComplete();
     state = download.getState();
     if (download.getBandwidth().hasGoodAverage()) {
       eta = formatETA(download.getETAInMinutes());
     } else {
       eta = "?";
     }
   } catch (IOException e) {
     if (T.t) {
       T.error("Exception while updating downloadwrapper: " + e);
     }
   }
 }