示例#1
0
  /**
   * this action allows you to give the path of a track on disk, and it will be resolved to the
   * tracks internal ID. this can then be used normally for playing music. the path coming in is
   * assumed to have forward slashes to delimit path components, but this needs to be converted to
   * whatever the actual path separator is for the current system BEFORE we try and query the
   * database, otherwise, well, it just won't work.
   *
   * <p>NB! ATM, this feature is only here for the the folder browsing stuff, so if that's not
   * turned on this this won't work.
   */
  protected void resolvePath() throws BadRequestException, SQLException, IOException {

    // check folder browsing is enabled
    Utils.checkFeatureEnabled(getProperties(), "browse.folders.enabled");

    ResultSet rs = null;
    PreparedStatement st = null;

    try {

      final Database db = getDatabase();
      final Locale locale = getLocale();
      final Request req = getRequest();
      final String path = convertPath(req.getArgument("path"));
      final String sql = Track.getSelectFromSql() + " where t.path = ? ";

      st = db.prepare(sql);
      st.setString(1, path);
      rs = st.executeQuery();

      if (!rs.next())
        throw new BadRequestException(locale.getString("www.error.trackNotFound"), 404);

      final Track track = Track.createFromResultSet(rs);
      final TResolvePath tpl = new TResolvePath();

      tpl.setTrack(track);
      getResponse().showJson(tpl.makeRenderer());

    } finally {
      Utils.close(rs);
      Utils.close(st);
    }
  }
示例#2
0
  /**
   * saves a playlist to the database for the current user. outputs a single integer which is the
   * playlist ID if all goes well, otherwise you'll get a description of the problem.
   *
   * @throws IOException
   */
  protected void savePlaylist() throws IOException, SQLException, BadRequestException {

    final Request req = getRequest();
    final User user = getUser();
    final Locale locale = getLocale();
    final String name = req.getUrlParam(2).trim();
    final String[] args = req.getPlayParams(2);

    String result = locale.getString("www.json.error.unknown");

    // make sure data is ok first
    if (name.equals("")) result = locale.getString("www.json.error.noName");
    else if (args.length == 0) result = locale.getString("www.json.error.noArguments");
    else if (user == null) result = locale.getString("www.json.error.notLoggedIn");
    else {

      final Database db = getDatabase();
      final List<Track> vTracks = Track.getTracksFromPlayArgs(db, args);
      final Track[] tracks = new Track[vTracks.size()];

      for (int i = 0; i < vTracks.size(); i++) tracks[i] = vTracks.get(i);

      result = Integer.toString(cm.savePlaylist(name, tracks, user));
    }

    final TString tpl = new TString();
    tpl.setResult(result);
    getResponse().showJson(tpl.makeRenderer());
  }
示例#3
0
  /** the panel across the bottom of the window */
  private JPanel getBottomPane() {

    final JButton exit =
        new JButton(
            locale.getString("gui.label.exit"), new ImageIcon(r.getImage("icons/22x22/exit.png")));
    exit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            AppFrame.this.exit();
          }
        });

    final JButton hide =
        new JButton(
            locale.getString("gui.label.hide"), new ImageIcon(r.getImage("icons/22x22/hide.png")));
    hide.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            AppFrame.this.setVisible(false);
          }
        });

    final JButton console =
        new JButton(
            locale.getString("gui.label.showConsoleWindow"),
            new ImageIcon(r.getImage("icons/22x22/console.png")));
    console.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            if (consoleFrame == null) {
              consoleFrame = injector.getInstance(ConsoleFrame.class);
              consoleFrame.setBounds(100, 100, 600, 500);
            }
            consoleFrame.setVisible(true);
          }
        });

    // in admin mode we won't have a server
    if (sv != null) {
      urlLabel.setText(locale.getString("gui.label.gettingIPAddress"));
      urlLabel.addMouseListener(injector.getInstance(UrlLabelMouseAdapter.class));
      urlLabel.setToolTipText("Click to open Sockso in your browser.");
      updateUrlLabel();
    }

    final JPanel buttons = new JPanel();
    buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
    buttons.add(console);
    buttons.add(exit);
    if (tray.isActive()) buttons.add(hide);

    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(buttons, BorderLayout.EAST);
    panel.add(urlLabel, BorderLayout.WEST);

    return panel;
  }
示例#4
0
  /**
   * handles the CMD_PROPSET command to set a particular application property
   *
   * @param args command arguments
   */
  public String execute(final String[] args) {

    final String name = args[1];
    final String value = Utils.joinArray(args, " ", 2, args.length - 1);

    p.set(name, value);
    p.save();

    return locale.getString("con.msg.propertySaved");
  }
示例#5
0
  /**
   * this method extracts the full path in the request where the relative path after the json action
   * name is prefixed by the collection path specified in the query string.
   *
   * <p>e.g. /json/action/File/System/Path?collectionId=2
   *
   * <p>Will return /home/rod/File/System/Path because the collection with id = 2 is rooted at
   * /home/rod
   *
   * @return String
   */
  private String getPathFromRequest() throws SQLException, BadRequestException {

    final Request req = getRequest();
    final Locale locale = getLocale();
    final int collectionId = Integer.parseInt(req.getArgument("collectionId"));

    String path = "";
    ResultSet rs = null;
    PreparedStatement st = null;

    for (int i = 2; i < req.getParamCount(); i++) {
      final String pathElement = req.getUrlParam(i);
      // don't allow going up directories
      if (!pathElement.equals("..")) path += "/" + req.getUrlParam(i);
    }

    try {

      final Database db = getDatabase();
      final String sql = " select c.path " + " from collection c " + " where c.id = ? ";
      st = db.prepare(sql);
      st.setInt(1, collectionId);
      rs = st.executeQuery();

      // check the collection exists and we got it's root path
      if (rs.next()) {
        // we need to trim the trailing slash off the collection path
        final String collPath = rs.getString("path");
        path = collPath.substring(0, collPath.length() - 1) + path;
      } else throw new BadRequestException(locale.getString("www.error.invalidCollectionId"), 404);

      path = path.replaceAll("\\/\\/", "\\/");

    } finally {
      Utils.close(rs);
      Utils.close(st);
    }

    log.debug("pathFromRequest: " + path);

    return path;
  }
示例#6
0
  /** the main tab control */
  private JTabbedPane getMainPane() {

    final JTabbedPane pane = new JTabbedPane();

    final MusicPanel musicPanel = injector.getInstance(MusicPanel.class);
    musicPanel.init();

    final UsersPanel usersPanel = injector.getInstance(UsersPanel.class);
    usersPanel.init();

    pane.addTab(
        locale.getString("gui.label.music"),
        new ImageIcon(r.getImage("icons/22x22/music.png")),
        musicPanel,
        locale.getString("gui.tooltip.music"));

    pane.addTab(
        locale.getString("gui.label.collection"),
        new ImageIcon(r.getImage("icons/22x22/collection.png")),
        injector.getInstance(CollectionPanel.class),
        locale.getString("gui.tooltip.collection"));

    pane.addTab(
        locale.getString("gui.label.users"),
        new ImageIcon(r.getImage("icons/22x22/users.png")),
        usersPanel,
        locale.getString("gui.tooltip.users"));

    pane.addTab(
        locale.getString("gui.label.general"),
        new ImageIcon(r.getImage("icons/22x22/general.png")),
        injector.getInstance(GeneralPanel.class),
        locale.getString("gui.tooltip.general"));

    pane.addTab(
        locale.getString("gui.label.encoders"),
        new ImageIcon(r.getImage("icons/22x22/encoders.png")),
        injector.getInstance(EncodersPanel.class),
        locale.getString("gui.tooltip.encoders"));

    return pane;
  }
示例#7
0
  /**
   * creates and returns a popup menu for this component
   *
   * @return a popup menu
   */
  private JPopupMenu createPopupMenu() {

    final JPopupMenu popup = new JPopupMenu();

    final JMenuItem inet = new JMenuItem(locale.getString("gui.label.internetAddress"));
    inet.setFont(inet.getFont().deriveFont(Font.BOLD));
    inet.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            openUrl(sv.getProtocol() + "://" + sv.getHost());
          }
        });

    final JMenuItem local = new JMenuItem(locale.getString("gui.label.myComputer"));
    local.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            openUrl(sv.getProtocol() + "://127.0.0.1:" + sv.getPort());
          }
        });

    final JMenuItem refresh =
        new JMenuItem(
            locale.getString("gui.label.refresh"),
            new ImageIcon(r.getImage("icons/16x16/refresh.png")));
    refresh.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            ipFinder.refresh();
            JOptionPane.showMessageDialog(parent, "IP Updated!");
          }
        });

    popup.add(inet);
    popup.add(local);
    popup.addSeparator();
    popup.add(refresh);

    return popup;
  }
示例#8
0
  /**
   * tries to delete a users playlist. needs to check things like did they create it, etc... if all
   * goes ok then sends back the ID so that the javascript handler can do whatever...
   *
   * @throws BadRequestException
   * @throws SQLException
   * @throws IOException
   */
  protected void deletePlaylist() throws BadRequestException, SQLException, IOException {

    final Request req = getRequest();
    final User user = getUser();
    final Locale locale = getLocale();

    if (user == null)
      throw new BadRequestException(locale.getString("www.json.error.notLoggedIn"), 403);

    final Database db = getDatabase();
    final int id = Integer.parseInt(req.getUrlParam(2));
    final String sql =
        " select 1 " + " from playlists p " + " where p.id = ? " + " and p.user_id = ? ";

    ResultSet rs = null;
    PreparedStatement st = null;

    try {

      // check user owns playlist before deleting it
      st = db.prepare(sql);
      st.setInt(1, id);
      st.setInt(2, user.getId());
      rs = st.executeQuery();
      if (!rs.next()) throw new BadRequestException("You don't own that playlist", 403);

      cm.removePlaylist(id);

      // done, send success response
      final TString tpl = new TString();
      tpl.setResult(Integer.toString(id));
      getResponse().showJson(tpl.makeRenderer());

    } finally {
      Utils.close(rs);
      Utils.close(st);
    }
  }
示例#9
0
  /** checks for a newer version */
  public void latestVersionReceived(final LatestVersionEvent evt) {

    final String latestVersion = evt.getVersion();

    if (latestVersion != null && !latestVersion.equals(Sockso.VERSION)) {

      Splash.closeNow();

      final String message =
          locale.getString("misc.msg.updateAvailable", new String[] {latestVersion});

      JOptionPane.showMessageDialog(this, message, "Sockso", JOptionPane.INFORMATION_MESSAGE);
    }
  }
示例#10
0
  /** updates the URL label to our current address */
  protected void updateUrlLabel() {

    final String myurl = sv.getProtocol() + "://" + sv.getHost();

    urlLabel.setText(
        "<html><head><title></title></head><body>"
            + "&nbsp; "
            + locale.getString("gui.label.yourAddress")
            + ": <a href='"
            + myurl
            + "'>"
            + myurl
            + "</a>"
            + "</body></html>");
  }
示例#11
0
  /** Creates a new instance of AppFrame */
  @Inject
  public AppFrame(
      final Injector injector,
      final Properties p,
      final Server sv,
      final Resources r,
      final Locale locale) {

    super(locale == null ? "" : locale.getString("gui.window.main") + " (" + Sockso.VERSION + ")");

    this.injector = injector;
    this.p = p;
    this.sv = sv;
    this.r = r;
    this.locale = locale;

    urlLabel = new JLabel();
    tray = new TrayIcon(this, r);
  }