示例#1
0
void Settings::load_settings (Glib::RefPtr<Gio::File> file)
{
  Glib::KeyFile cfg;

  set_defaults();

  try {
    if (!cfg.load_from_file (file->get_path())) {
      std::cout << "Failed to load settings from file '" << file->get_path() << "\n";
      return;
    }
  } catch (const Glib::KeyFileError &err) {
    std::cout << "Exception " << err.what() << " loading settings from file '" << file->get_path() << "\n";
    return;
  }

  std::cout << "parsing config from '" << file->get_path() << "\n";

  for (uint i = 0; i < G_N_ELEMENTS (settings); i++) {
    Glib::ustring group, key;

    if (!get_group_and_key (i, group, key))
      continue;

    if (!cfg.has_key (group, key))
      continue;

    // group & string ...
    switch (settings[i].type) {
    case T_BOOL:
      *PTR_BOOL(this, i) = cfg.get_boolean (group, key);
      break;
    case T_INT:
      *PTR_INT(this, i) = cfg.get_integer (group, key);
      break;
    case T_FLOAT:
    case T_COLOUR_MEMBER:
      *PTR_FLOAT(this, i) = cfg.get_double (group, key);
      break;
    case T_STRING:
      *PTR_STRING(this, i) = cfg.get_string (group, key);
      break;
    default:
      std::cerr << "corrupt setting type\n";
      break;
    }
  }

  GCode.m_impl->loadSettings (cfg);

  m_signal_visual_settings_changed.emit();
  m_signal_update_settings_gui.emit();
}
示例#2
0
void PlayerConfiguration::readKeyFile(const Glib::KeyFile& key)
  throw(DaoException, Glib::KeyFileError)
{
  string type, algorithm, color;
  type = key.get_string(m_sectionName, "type");
  m_type = stringToPlayerType(type);
  
  color = key.get_string(m_sectionName, "color");
  m_color = stringToPlayerColor(color);

  if (m_type == PLAYER_COMPUTER)
    {
      algorithm = key.get_string(m_sectionName, "algorithm");
      m_algorithm = stringToPlayerAlgorithm(algorithm);
    }

  m_k[0] = key.get_double(m_sectionName, "k1");
  m_k[1] = key.get_double(m_sectionName, "k2");
  m_k[2] = key.get_double(m_sectionName, "k3");
  m_h = key.get_double(m_sectionName, "h");
  m_depth = key.get_integer(m_sectionName, "depth");
}