Exemplo n.º 1
0
int main(int argc, char **argv)
#endif
{
    if (gui_init(argc, argv) != 0) return -1;

    gui_signal_connect("on_menulist_clicked"   , on_menulist_clicked);
    gui_signal_connect("on_setlanguage_clicked", on_setlanguage_clicked);
    gui_signal_connect("on_MainWindow_keypress", on_MainWindow_keypress);

#ifndef WIN32
    if (argc > 1)
        i18n_set_language(argv[1]);
    else
#endif
        i18n_set_language("chinese");
    gui_loop();
    gui_release();

    return 0;
}
Exemplo n.º 2
0
static int on_setlanguage_clicked(GuiWidget *widget, void *userdata)
{
    GuiWidget *item = (GuiWidget *)userdata;
    printf("%s(%s, %s)\n", __FUNCTION__, widget_get_name(widget), widget_get_name(item));
    if (item) {
        const char *name = widget_get_name(item);
        i18n_set_language(name);
        widget_close(NULL);
    }

    return 0;
}
Exemplo n.º 3
0
  std::pair<boost::optional<boost::program_options::variables_map>, bool> main(
    int argc, char** argv,
    const char* const usage,
    const char* const notice,
    boost::program_options::options_description desc_params,
    const boost::program_options::positional_options_description& positional_options,
    const std::function<void(const std::string&, bool)> &print,
    const char *default_log_name,
    bool log_to_console)
  
  {
    namespace bf = boost::filesystem;
    namespace po = boost::program_options;
#ifdef WIN32
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

    const command_line::arg_descriptor<std::string> arg_log_level = {"log-level", "0-4 or categories", ""};
    const command_line::arg_descriptor<std::size_t> arg_max_log_file_size = {"max-log-file-size", "Specify maximum log file size [B]", MAX_LOG_FILE_SIZE};
    const command_line::arg_descriptor<std::size_t> arg_max_log_files = {"max-log-files", "Specify maximum number of rotated log files to be saved (no limit by setting to 0)", MAX_LOG_FILES};
    const command_line::arg_descriptor<uint32_t> arg_max_concurrency = {"max-concurrency", wallet_args::tr("Max number of threads to use for a parallel job"), DEFAULT_MAX_CONCURRENCY};
    const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", wallet_args::tr("Specify log file"), ""};
    const command_line::arg_descriptor<std::string> arg_config_file = {"config-file", wallet_args::tr("Config file"), "", true};


    std::string lang = i18n_get_language();
    tools::on_startup();
    tools::set_strict_default_file_permissions(true);

    epee::string_tools::set_module_name_and_folder(argv[0]);

    po::options_description desc_general(wallet_args::tr("General options"));
    command_line::add_arg(desc_general, command_line::arg_help);
    command_line::add_arg(desc_general, command_line::arg_version);

    command_line::add_arg(desc_params, arg_log_file);
    command_line::add_arg(desc_params, arg_log_level);
    command_line::add_arg(desc_params, arg_max_log_file_size);
    command_line::add_arg(desc_params, arg_max_log_files);
    command_line::add_arg(desc_params, arg_max_concurrency);
    command_line::add_arg(desc_params, arg_config_file);

    i18n_set_language("translations", "monero", lang);

    po::options_description desc_all;
    desc_all.add(desc_general).add(desc_params);
    po::variables_map vm;
    bool should_terminate = false;
    bool r = command_line::handle_error_helper(desc_all, [&]()
    {
      auto parser = po::command_line_parser(argc, argv).options(desc_all).positional(positional_options);
      po::store(parser.run(), vm);

      if (command_line::get_arg(vm, command_line::arg_help))
      {
        Print(print) << "Aeon '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL;
        Print(print) << wallet_args::tr("This is the command line Aeon wallet. It needs to connect to a Aeon\n"
												  "daemon to work correctly.") << ENDL;
        Print(print) << wallet_args::tr("Usage:") << ENDL << "  " << usage;
        Print(print) << desc_all;
        should_terminate = true;
        return true;
      }
      else if (command_line::get_arg(vm, command_line::arg_version))
      {
        Print(print) << "Aeon '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
        should_terminate = true;
        return true;
      }

      if(command_line::has_arg(vm, arg_config_file))
      {
        std::string config = command_line::get_arg(vm, arg_config_file);
        bf::path config_path(config);
        boost::system::error_code ec;
        if (bf::exists(config_path, ec))
        {
          po::store(po::parse_config_file<char>(config_path.string<std::string>().c_str(), desc_params), vm);
        }
        else
        {
          MERROR(wallet_args::tr("Can't find config file ") << config);
          return false;
        }
      }

      po::notify(vm);
      return true;
    });
    if (!r)
      return {boost::none, true};

    if (should_terminate)
      return {std::move(vm), should_terminate};

    std::string log_path;
    if (!command_line::is_arg_defaulted(vm, arg_log_file))
      log_path = command_line::get_arg(vm, arg_log_file);
    else
      log_path = mlog_get_default_log_path(default_log_name);
    mlog_configure(log_path, log_to_console, command_line::get_arg(vm, arg_max_log_file_size), command_line::get_arg(vm, arg_max_log_files));
    if (!command_line::is_arg_defaulted(vm, arg_log_level))
    {
      mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
    }
    else if (!log_to_console)
    {
      mlog_set_categories("");
    }

    if (notice)
      Print(print) << notice << ENDL;

    if (!command_line::is_arg_defaulted(vm, arg_max_concurrency))
      tools::set_max_concurrency(command_line::get_arg(vm, arg_max_concurrency));

    Print(print) << "Aeon '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";

    if (!command_line::is_arg_defaulted(vm, arg_log_level))
      MINFO("Setting log level = " << command_line::get_arg(vm, arg_log_level));
    else
      MINFO("Setting log levels = " << getenv("AEON_LOGS"));
    MINFO(wallet_args::tr("Logging to: ") << log_path);

    Print(print) << boost::format(wallet_args::tr("Logging to %s")) % log_path;

    return {std::move(vm), should_terminate};
  }
Exemplo n.º 4
0
int main(char *argv[],int argc) {
  mc_init();
  el_bool stop = el_false;
  
  hre_t re_load = hre_compile("^load(&play)?\\s+(.*)$","i");
  hre_t re_play = hre_compile("^play$","i");
  hre_t re_pause = hre_compile("^pause$","i");
  hre_t re_next = hre_compile("^next$","i");
  hre_t re_previous = hre_compile("^prev(ious)?$","i");
  hre_t re_track = hre_compile("^track\\s+([0-9]+)$","i");
  hre_t re_quhit = hre_compile("^quit$","i");
  hre_t re_seek = hre_compile("^seek\\s([0-9]+([.][0-9]+)?)$","i");
  hre_t re_quit = hre_compile("^quit$","i");
  hre_t re_repeat = hre_compile("^repeat\\s+(off|list|track)$","i");
  hre_t re_again = hre_compile("^again$","i");
  hre_t re_scan = hre_compile("^scan\\s+(.*)$","i");
  
  file_info_t *history_file = mc_take_over(file_info_new_home(".btb_playlist"));
  printf("history file: %s\n", file_info_absolute_path(history_file));
  printf("history file: %s\n", file_info_path(history_file));
  if (file_info_exists(history_file)) {
    read_history(file_info_absolute_path(history_file));
  }
  
  i18n_set_language("nl");
  printf(_("Starting btb_playlist\n"));

  playlist_player_t *player = playlist_player_new();

  while (!stop) {
    char* line = readln(">", player);
    hre_trim(line);
    if (hre_has_match(re_quit, line)) {
      stop = el_true;
    } else if (hre_has_match(re_load, line)) {
      hre_matches m = hre_match(re_load, line);
      hre_match_t *mplay = hre_matches_get(m, 1);
      hre_match_t *match = hre_matches_get(m, 2);
      char* file = mc_strdup(hre_match_str(match));
      char* play = mc_strdup(hre_match_str(mplay));
      hre_matches_destroy(m);
      printf("loading '%s', '%s'\n", file, play);
      file_info_t *info = file_info_new(file);
      if (file_info_exists(info)) {
        if (file_info_is_file(info)) {
          if (file_info_can_read(info)) {
            const char *mediafile = NULL;
            track_array array;
            if (strcasecmp(file_info_ext(info),"cue") == 0) {
              array = tracks_from_cue(file_info_absolute_path(info));
              track_t* t = track_array_get(array, 0);
            } else {
              array = tracks_from_media(file_info_absolute_path(info));
            }
            playlist_t* pl = playlist_new("playlist");
            int i;
            for(i=0; i < track_array_count(array); ++i) {
              playlist_append(pl, track_array_get(array, i));
            }
            playlist_player_set_playlist(player, pl);
            track_array_destroy(array);
          }
        }
      }
      file_info_destroy(info);      
      if (strcasecmp(play,"&play")==0) { playlist_player_play(player); }
      mc_free(file);
      mc_free(play);
    } else if (hre_has_match(re_play, line)) {
      playlist_player_play(player);
    } else if (hre_has_match(re_pause, line)) {
      playlist_player_pause(player);
    } else if (hre_has_match(re_seek, line)) {
      hre_matches m = hre_match(re_seek, line);
      hre_match_t* match = hre_matches_get(m, 1);
      char* position = mc_strdup(hre_match_str(match));
      hre_matches_destroy(m);
      double s = atof(position);
      int ms = s * 1000;
      mc_free(position);
      playlist_player_seek(player, ms); 
    } else if (hre_has_match(re_next, line)) {
      playlist_player_next(player);
    } else if (hre_has_match(re_previous, line)) {
      playlist_player_previous(player);
    } else if (hre_has_match(re_track, line)) {
      hre_matches m = hre_match(re_track, line);
      hre_match_t* match = hre_matches_get(m, 1);
      char* nr = mc_strdup(hre_match_str(match));
      hre_matches_destroy(m);
      int index = atoi(nr);
      mc_free(nr);
      printf("setting track %d\n",index);
      playlist_player_set_track(player, index);
    } else if (hre_has_match(re_repeat, line)) {
      hre_matches m = hre_match(re_repeat, line);
      hre_match_t* match = hre_matches_get(m, 1);
      if (strcasecmp(hre_match_str(match),"track") == 0) {
        playlist_player_set_repeat(player, PLP_TRACK_REPEAT);
      } else if (strcasecmp(hre_match_str(match),"list") == 0) {
        playlist_player_set_repeat(player, PLP_LIST_REPEAT);
      } else {
        playlist_player_set_repeat(player, PLP_NO_REPEAT);
      }
      hre_matches_destroy(m);
    } else if (hre_has_match(re_again, line)) {
      playlist_player_again(player);
    } else if (hre_has_match(re_scan, line)) {
      hre_matches m = hre_match(re_scan, line);
      hre_match_t* match = hre_matches_get(m, 1);
      printf("scanning %s\n", hre_match_str(match));
      library_t* library = library_new();
      printf("calling scan_library\n");
      //scan_library(library, hre_match_str(match), library_cb);
      printf("\n");
      printf("library: %d tracks\n", library_count(library));
      printf("done scanning, destroying library\n");
      library_destroy(library);
      printf("library destroyed\n");
      hre_matches_destroy(m);
      printf("matches destroyed\n");
    }
    
    mc_free(line);
  }

  playlist_player_destroy(player);
  
  printf("%d\n",write_history(file_info_absolute_path(history_file)));
  
  file_info_destroy(history_file);
  hre_destroy(re_load);
  hre_destroy(re_play);
  hre_destroy(re_pause);
  hre_destroy(re_quit);
  hre_destroy(re_seek);
  hre_destroy(re_track);
  hre_destroy(re_next);
  hre_destroy(re_previous);
  hre_destroy(re_again);
  hre_destroy(re_repeat);
  hre_destroy(re_scan);
  
  return 0;
}