示例#1
0
  @Override
  protected void socketClosed() {
    // Try to close both, even if one fails.
    StreamUtils.close(out);
    StreamUtils.close(in);
    out = null;
    in = null;

    for (DCCTransferHandler handler : handlers.get(DCCTransferHandler.class)) {
      handler.socketClosed(this);
    }
    // Try to delete empty files.
    if (transferType == TransferType.RECEIVE
        && transferFile != null
        && transferFile.length() == 0) {
      transferFile.delete();
    }
    synchronized (TRANSFERS) {
      TRANSFERS.remove(this);
    }
    active = false;
  }
示例#2
0
  /**
   * Used to show a notification using this plugin.
   *
   * @param title Title of dialog if applicable
   * @param message Message to show
   * @return True if the notification was shown.
   */
  public boolean showNotification(final String title, final String message) {
    if (filesHelper.getFilesDir() == null) {
      return false;
    }

    final String[] args = {
      "/usr/bin/env",
      "python",
      filesHelper.getFilesDirString() + "notify.py",
      "-a",
      "DMDirc",
      "-i",
      icon,
      "-t",
      Integer.toString(timeout * 1000),
      "-s",
      Strings.isNullOrEmpty(title) ? "Notification from DMDirc" : prepareString(title),
      prepareString(message)
    };

    try {
      final Process myProcess = Runtime.getRuntime().exec(args);
      StreamUtils.readStream(myProcess.getErrorStream());
      StreamUtils.readStream(myProcess.getInputStream());
      try {
        myProcess.waitFor();
      } catch (InterruptedException e) {
        // Not a problem, carry on
      }
      return true;
    } catch (SecurityException | IOException e) {
      LOG.info(USER_ERROR, "Unable to show notification", e);
    }

    return false;
  }