1/* Part of ClioPatria SeRQL and SPARQL server 2 3 Author: Jan Wielemaker 4 E-mail: J.Wielemaker@cs.vu.nl 5 WWW: http://www.swi-prolog.org 6 Copyright (C): 2010, University of Amsterdam, 7 VU University Amsterdam 8 9 This program is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 2 12 of the License, or (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public 20 License along with this library; if not, write to the Free Software 21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 23 As a special exception, if you link this library with other files, 24 compiled with a Free Software compiler, to produce an executable, this 25 library does not by itself cause the resulting executable to be covered 26 by the GNU General Public License. This exception does not however 27 invalidate any other reasons why the executable file might be covered by 28 the GNU General Public License. 29*/ 30 31:- module(user_preferences, 32 [ user_preference/2 % ?Preference, ?Value 33 ]). 34:- use_module(library(semweb/rdf_db)). 35:- use_module(cliopatria(hooks)). 36 37:- rdf_register_ns(user, 'http://www.swi-prolog.org/cliopatria/user/'). 38 39/** <module> User preference handling 40 41This module defines _access_ to user-preferences. The API for the 42preference system is based on RDF. This allows for using the RDF-store 43for storing preferences, typically using the OpenID URI as subject. The 44actual storage infrastructure must be implemented using hooks in the 45=cliopatria= module: cliopatria:user_preference_db/2 and 46cliopatria:user_preference_default/2. 47 48Preferences are defines in the RDF namespace with prefix =user=, which 49expands to: 50 51 == 52 http://www.swi-prolog.org/cliopatria/user/ 53 == 54*/ 55 56:- rdf_meta 57 user_preference(r,o), 58 builtin_default(r,o). 59 60%% user_preference(?Preference:resource, ?Value:object) is nondet. 61% 62% True if Preference has Value. Preference and Value use the RDF 63% data-representation. E.g., 64% 65% == 66% ?- user_preference(user:lang, literal(Lang)) 67% 68% Lang = en 69% == 70% 71% @see cliopatria:user_preference_db/2 provides the storage hook 72% @see cliopatria:user_preference_default/2 provides a hook for 73% defaults 74% @see builtin_default/2 provides built-in defaults 75 76user_preference(Pref, Value) :- 77 nonvar(Pref), !, 78 ( cliopatria:user_preference_db(Pref, Value) 79 *-> true 80 ; cliopatria:user_preference_default(Pref, Value) 81 *-> true 82 ; builtin_default(Pref, Value) 83 ). 84user_preference(Pref, Value) :- 85 current_preference(Pref), 86 user_preference(Pref, Value). 87 88current_preference(Pref) :- 89 setof(P, current_pref(P), Prefs), 90 member(Pref, Prefs). 91 92current_pref(P) :- cliopatria:user_preference_db(P, _). 93current_pref(P) :- cliopatria:user_preference_default(P, _). 94current_pref(P) :- builtin_default(P, _). 95 96%% builtin_default(?Preference, ?Value) is nondet. 97% 98% Provide defaults for commonly used preferences. 99 100builtin_default(user:lang, literal(en)).