web: add optional project-specific pref for preferring non-graphical apps

Also: show beta-test preference if project has beta app versions
This commit is contained in:
David Anderson 2014-08-07 15:43:41 -07:00
parent 82da9693a3
commit b1fabcfedd
3 changed files with 45 additions and 16 deletions

View File

@ -115,7 +115,7 @@ if ($app_types->intel_gpu) {
);
}
if (isset($project_has_beta) && $project_has_beta) {
if (project_has_beta()) {
$project_pref_descs[] = new PREF_BOOL(
tra("Run test applications?")
."<br><span class=note>"

View File

@ -472,4 +472,14 @@ function row_links($subset, $prefs) {
echo "<td><br></td></tr>\n";
}
// see if we have any beta apps or app versions
//
function project_has_beta() {
$apps = BoincApp::enum("deprecated=0 and beta>0");
if (count($apps)) return true;
$avs = BoincAppVersion::enum("deprecated=0 and beta>0");
if (count($avs)) return true;
return false;
}
?>

View File

@ -12,10 +12,16 @@
// Select standard prefs here:
define ('COLOR_PREFS', false);
define ('GFX_CPU_PREFS', true);
define ('APP_SELECT_PREFS', true);
$project_has_beta = false;
define('COLOR_PREFS', false);
// user can select screensaver color scheme
define('GFX_CPU_PREFS', false);
// user can limit % CPU used by screensaver
// (lower frame rate if exceeded)
// This is probably irrelevant if your screensaver uses OpenGL
define('APP_SELECT_PREFS', true);
// user can choose which apps to run
define('NON_GRAPHICAL_PREF', false);
// user can choose to run faster non-graphical app versions if available
// Project-specific prefs are represented in three ways:
// - as an XML document (stored in the DB in this form)
@ -23,7 +29,7 @@ $project_has_beta = false;
// - as a set of HTTP GET form variables
// This file exports the following functions
// (called from html/inc/prefs.inc):
// (called from html/inc/prefs_project.inc):
//
// project_specific_prefs_default()
// Returns XML for default preferences
@ -48,6 +54,7 @@ define('COLOR_DESC', tra('Color scheme for graphics'));
define("MAX_GFX_CPU_PCT_DESC", tra("Maximum CPU % for graphics%10 ... 100%2", "<br><span class=note>", "</span>"));
define('APP_SELECT_DESC', tra('Run only the selected applications'));
define('ACCEPT_ANY_DESC', tra('If no work for selected applications is available, accept work from other applications?'));
define('NON_GRAPHICAL_DESC', tra("Use faster non-graphical applications if available?"));
// stuff related to app filtering.
// Note: in this implementation, if a user selects all apps,
@ -64,16 +71,6 @@ if (APP_SELECT_PREFS) {
$app_array = null;
}
// see if we have any beta apps
//
$apps = BoincApp::enum("deprecated=0");
foreach($apps as $app) {
if ($app->beta) {
$project_has_beta = true;
break;
}
}
function selected_app_text($prefs) {
global $app_array;
if (isset($prefs->app_ids)) {
@ -137,6 +134,13 @@ function project_specific_prefs_edit($prefs, $error=false) {
$checked = $prefs->allow_non_preferred_apps?"checked":"";
row2(ACCEPT_ANY_DESC, "<input type=checkbox name=allow_non_preferred_apps $checked>");
}
if (NON_GRAPHICAL_PREF) {
$checked = $prefs->non_graphical?"checked":"";
row2(
NON_GRAPHICAL_DESC,
"<input type=checkbox name=non_graphical $checked>"
);
}
}
function project_specific_prefs_parse_form(&$error) {
@ -174,6 +178,12 @@ function project_specific_prefs_parse_form(&$error) {
}
}
if (NON_GRAPHICAL_PREF) {
if (isset($_GET["non_graphical"])) {
$x .= "<non_graphical>1</non_graphical>\n";
}
}
return $x;
}
@ -194,6 +204,9 @@ function project_specific_prefs_show($prefs, $columns=false) {
row_defs(APP_SELECT_DESC, "app_id_text", "", "", $prefs);
row_defs(ACCEPT_ANY_DESC, "allow_non_preferred_apps_text", "", "", $prefs);
}
if (NON_GRAPHICAL_PREF) {
row_defs(NON_GRAPHICAL_DESC, "non_graphical", "", "yesno", $prefs);
}
} else {
if (COLOR_PREFS) {
row2(COLOR_DESC, $prefs->color_scheme);
@ -205,6 +218,9 @@ function project_specific_prefs_show($prefs, $columns=false) {
row2(APP_SELECT_DESC, selected_app_text($prefs));
row2(ACCEPT_ANY_DESC, $prefs->allow_non_preferred_apps_text);
}
if (NON_GRAPHICAL_PREF) {
row2(NON_GRAPHICAL_DESC, $prefs->non_graphical?tra("yes"):tra("no"));
}
}
}
@ -227,6 +243,9 @@ function project_specific_prefs_parse($prefs_xml) {
$prefs->allow_non_preferred_apps = parse_element($prefs_xml, "<allow_non_preferred_apps>");
$prefs->allow_non_preferred_apps_text = $prefs->allow_non_preferred_apps?"yes":"no";
}
if (NON_GRAPHICAL_PREF) {
$prefs->non_graphical = parse_bool($prefs_xml, "non_graphical");
}
return $prefs;
}