function settingsStart()
{
  // Find current values
  var coreserver = "";
  try {
    coreserver = getCoreServer();
  } catch (e) {};
  var playerpath = prefService().getCharPref("zeipis.videoplayer.path");
  var playerargs = prefService().getCharPref("zeipis.videoplayer.args");

  // UI
  var menu = new Menu("Settings");
  menu.createMenuItem("Zeipis core server: " + coreserver, coreserver, setCoreServer);
  menu.createMenuItem("Video player, pathname: " + playerpath, playerpath, setPlayerPath);
  menu.createMenuItem("Video player, arguments: " + playerargs, playerargs, setPlayerArgs);
  menu.load();
}

function setCoreServer(oldValue)
{
  coreserver = prompt("Zeipis core server\nFormat: hostname:port or just hostname", oldValue);
  if ( ! coreserver)
    return;

  if (coreserver.indexOf(":") == -1)
    coreserver += ":" + kPortDefault;
  // don't write same value in prefs that is already in dotfiles,
  // to pick up changes in dotfiles
  var coreserverFromDotfiles = null;
  try {
    coreserverFromDotfiles = getCoreServerFromDotfiles();
  } catch (e) {}
  if (coreserverFromDotfiles &&
      coreserver == coreserverFromDotfiles &&
      prefService().prefHasUserValue("zeipis.coreserver"))
    prefService().clearUserPref("zeipis.coreserver");
  else
    prefService().setCharPref("zeipis.coreserver", coreserver);
  
  refresh();
}

function setPlayerPath(oldValue)
{
  playerpath = prompt("Video player, pathname", oldValue);
  if ( ! playerpath)
    return;

  prefService().setCharPref("zeipis.videoplayer.path", playerpath);
  refresh();
}

function setPlayerArgs(oldValue)
{
  playerargs = prompt("Video player, arguments", oldValue);
  if ( ! playerargs)
    return;

  prefService().setCharPref("zeipis.videoplayer.args", playerargs);
  refresh();
}

function refresh()
{
  actionBack();
  settingsStart();
}
