Roxen.git / server / etc / modules / Variable.pmod / module.pmod

version» Context lines:

Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1: - // $Id: module.pmod,v 1.93 2006/05/05 11:05:37 wellhard Exp $ + // $Id: module.pmod,v 1.94 2006/12/14 16:50:56 grubba Exp $      #include <module.h>   #include <roxen.h>      // Locale macros   //<locale-token project="roxen_config"> LOCALE </locale-token>      #define LOCALE(X,Y) \    ([string](mixed)Locale.translate("roxen_config",roxenp()->locale->get(),X,Y))   
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1129:    m->selected="selected";    selected = 1;    }    res += " "+Roxen.make_container( "option", m, _title( elem ) )+"\n";    }    if (!selected)    // Make an entry for the current value if it's not in the list,    // so no other value appears to be selected, and to ensure that    // the value doesn't change as a side-effect by another change.    res += " " + Roxen.make_container ( -  "option", (["value":_name(current), "selected": "selected"]), -  sprintf(LOCALE(332,"(keep stale value %s)"),_name(current))); +  "option", (["value":current, "selected": "selected"]), +  sprintf(LOCALE(332,"(keep stale value %s)"),current));    return res + "</select>";    }       static void create( mixed default_value, array|mapping choices,    void|int _flags, void|LocaleString std_name,    void|LocaleString std_doc )    //! Constructor.    //!    //! Choices is the list of possible choices, can be set with    //! set_choice_list at any time.
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1340:       static void create( string default_value, int flags,    string std_name, string std_doc,    Configuration c )    {    config = c;    ::create( default_value, ({}), flags, std_name, std_doc );    }   }    + // FIXME: Consider making a ModuleChoice as well.    -  + //! Select a module that provides the specified interface. + class ProviderChoice + { +  inherit StringChoice; +  constant type = "ProviderChoice"; +  static Configuration conf; +  static string provides; +  static string default_id; +  static string local_id = ""; +  +  int low_set(RoxenModule to) +  { +  local_id = _name(to); +  return ::low_set(to); +  } +  +  RoxenModule query() +  { +  RoxenModule res = ::query(); +  if (!res) { +  if (local_id != "") { +  // The module might have been reloaded. +  // Try locating it again. +  res = transform_from_form(local_id); +  if (res) low_set(res); +  } +  } +  return res; +  } +  +  array get_choice_list() +  { +  return conf->get_providers(provides); +  } +  +  static string _name(RoxenModule val) +  { +  return val?val->module_local_id():""; +  } +  +  static string _title(RoxenModule val) +  { +  return val?val->module_name:""; +  } +  +  RoxenModule transform_from_form(string local_id, mapping|void v) +  { +  return conf->find_module(local_id); +  } +  +  RoxenModule default_value() +  { +  if (default_id) { +  return transform_from_form(default_id); +  } else { +  array(RoxenModule) providers = get_choice_list(); +  if (sizeof(providers)) { +  // FIXME: Add sorting? +  return providers[0]; +  } +  return UNDEFINED; +  } +  } +  +  array(string|mixed) verify_set( mixed new_value ) +  { +  if (!new_value) { +  return ({ "Not configured", 0 }); +  } +  return ({ 0, new_value }); +  } +  +  //! @param default_id +  //! The @[RoxenModule.module_local_id] of the default value. +  //! @param provides +  //! The provider string to match modules against. +  //! @param conf +  //! The current configuration. +  static void create(string default_id, int flags, +  string std_name, string std_doc, +  string provides, Configuration conf) +  { +  this_program::provides = provides; +  this_program::default_id = default_id; +  this_program::conf = conf; +  ::create(0, ({}), flags, std_name, std_doc); +  } + } +    // =====================================================================   // List baseclass   // =====================================================================   class List   //! Many of one type types   {    inherit Variable;    constant type="List";    int width = 40;