home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / libpref / public / prefapi.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  14.0 KB  |  382 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20. // <pre>
  21. */
  22. #ifndef PREFAPI_H
  23. #define PREFAPI_H
  24.  
  25. #include "prtypes.h"
  26. #if defined(XP_UNIX) || defined(XP_MAC) || defined(XP_OS2)
  27. #include "xp_core.h"
  28. #endif     
  29. #include "jscompat.h"
  30. #include "jspubtd.h"
  31.  
  32. #ifdef XP_WIN
  33. #ifndef NSPR20
  34. #include "prhash.h"
  35. #else
  36. #include "plhash.h"
  37. #endif
  38. #endif
  39.  
  40. NSPR_BEGIN_EXTERN_C
  41.  
  42. #if defined(XP_WIN) || defined(XP_OS2)
  43. // horrible pre-declaration...so kill me.
  44. int pref_InitInitialObjects(JSContext *js_context,JSObject *js_object);
  45. PR_EXTERN(int) pref_savePref(PRHashEntry *he, int i, void *arg);
  46. #endif
  47.  
  48. /*
  49. // <font color=blue>
  50. // The Init function sets up of the JavaScript preference context and creates
  51. // the basic preference and pref_array objects:
  52.  
  53. // It also takes the filename of the preference file to use.  This allows the
  54. // module to create its own pref file if that is so desired.  If a filename isn't
  55. // passed, the pref module will either use the current name and file (if known) or
  56. // will call (FE_GetPrefFileName() ?) to have a module prompt the user to determine
  57. // which user it is (on a mulit-user system).  In general, the FE should pass the
  58. // filename and the sub-modules should pass NULL
  59. //
  60. // At the moment, the Init function is defining 3 JavaScript functions that can be
  61. // called in arbitrary JavaScript (like that passed to the EvaluateJS function below).  
  62. // This may increase in the future...
  63. // 
  64. // pref(pref_name,default_value)      : Setup the initial preference storage and default
  65. // user_pref(pref_name, user_value)   : Set a user preference
  66. // lock_pref(pref_name)                  : Lock a preference (prevent it from being modifyed by user)
  67. // </font>
  68. */
  69.  
  70. PR_EXTERN(int)
  71. PREF_ReadUserJSFile(char *filename);
  72.  
  73. /* LI_STUFF read in an li prefs file and give it a name- preobably temporary */
  74. PR_EXTERN(int)
  75. PREF_ReadLIJSFile(char *filename);
  76.  
  77. PR_EXTERN(int) 
  78. PREF_Init(char *filename);
  79.  
  80. PR_EXTERN(int)
  81. PREF_GetConfigContext(JSContext **js_context);
  82.  
  83. PR_EXTERN(int)
  84. PREF_GetGlobalConfigObject(JSObject **js_object);
  85.  
  86. PR_EXTERN(int)
  87. PREF_GetPrefConfigObject(JSObject **js_object);
  88.  
  89. /*
  90. // Cleanup should be called at program exit to free the 
  91. // list of registered callbacks.
  92. */
  93. PR_EXTERN(void)
  94. PREF_Cleanup();
  95.  
  96. /*
  97. // <font color=blue>
  98. // Given a path to a local Lock file, unobscures the file (not implemented yet)
  99. // and verifies the MD5 hash.  Returns PREF_BAD_LOCKFILE if hash failed;
  100. // otherwise, evaluates the contents of the file as a JS buffer.
  101. // </font>
  102. */
  103. PR_EXTERN(int)
  104. PREF_ReadLockFile(const char *filename);
  105.  
  106. /*
  107. // <font color=blue>
  108. // Pass an arbitrary JS buffer to be evaluated in the Preference context.
  109. // On startup modules will want to setup their preferences with reasonable
  110. // defaults.  For example netlib might call with a buffer of:
  111. //
  112. // pref("network.tcpbufsize",4096);
  113. // pref("network.max_connections", 4);
  114. // pref("network.proxy.http_host", "");
  115. // pref("network.proxy.http_port". 0);
  116. // ...etc...
  117. //
  118. // This routine generates callbacks to functions registered with 
  119. // PREF_RegisterCallback() for any user values that have changed.
  120. // </font>
  121. */
  122. PR_EXTERN(int)
  123. PREF_EvaluateJSBuffer(const char * js_buffer, size_t length);
  124.  
  125. /*
  126. // Like the above but does not generate callbacks.
  127. */
  128. PR_EXTERN(int)
  129. PREF_QuietEvaluateJSBuffer(const char * js_buffer, size_t length);
  130.  
  131. /*
  132. // Like the above but does not generate callbacks and executes in scope of global config object
  133. */
  134. PR_EXTERN(int)
  135. PREF_QuietEvaluateJSBufferWithGlobalScope(const char * js_buffer, size_t length);
  136.  
  137. /*
  138. // This routine is newer than the above which are not being called externally,
  139. // as far as I know.  The following is used from mkautocf to evaluate a 
  140. // config URL file with callbacks.
  141. */
  142. PR_EXTERN(JSBool)
  143. PREF_EvaluateConfigScript(const char * js_buffer, size_t length,
  144.     const char* filename, XP_Bool bGlobalContext, XP_Bool bCallbacks);
  145.  
  146.  
  147. /*
  148. // <font color=blue>
  149. // Error codes
  150. // </font>
  151. */
  152. enum {
  153.     PREF_OUT_OF_MEMORY        = -5,
  154.     PREF_TYPE_CHANGE_ERR    = -4,
  155.     PREF_NOT_INITIALIZED    = -3,
  156.     PREF_BAD_LOCKFILE        = -2,
  157.     PREF_ERROR                = -1,
  158.     PREF_NOERROR            = 0,
  159.     PREF_OK                    = 0,    /* same as PREF_NOERROR */
  160.     PREF_VALUECHANGED        = 1
  161. };
  162.  
  163. /*
  164. // <font color=blue>
  165. // Set the various types of preferences.  These functions take a dotted
  166. // notation of the preference name (e.g. "browser.startup.homepage").  
  167. // Note that this will cause the preference to be saved to the file if
  168. // it is different from the default.  In other words, these are used
  169. // to set the _user_ preferences.
  170. // Each set returns PREF_VALUECHANGED if the user value changed
  171. // (triggering a callback), or PREF_NOERROR if the value was unchanged.
  172. // </font>
  173. */
  174. PR_EXTERN(int) PREF_SetCharPref(const char *pref,const char* value);
  175. PR_EXTERN(int) PREF_SetIntPref(const char *pref,int32 value);
  176. PR_EXTERN(int) PREF_SetBoolPref(const char *pref,XP_Bool value);
  177. PR_EXTERN(int) PREF_SetBinaryPref(const char *pref,void * value, long size);
  178. PR_EXTERN(int) PREF_SetColorPref(const char *pref_name, uint8 red, uint8 green, uint8 blue);
  179. PR_EXTERN(int) PREF_SetColorPrefDWord(const char *pref_name, uint32 colorref);
  180. PR_EXTERN(int) PREF_SetRectPref(const char *pref_name, int16 left, int16 top, int16 right, int16 bottom);
  181.  
  182. /*
  183. // <font color=blue>
  184. // Set the default for various types of preferences.  These functions take a dotted
  185. // notation of the preference name (e.g. "browser.startup.homepage")
  186. // This will only affect the program behavior if the user does not have a value
  187. // saved over it for the particular preference.  In addition, these will never
  188. // be saved out to disk.
  189. // </font>
  190. */
  191. PR_EXTERN(int) PREF_SetDefaultCharPref(const char *pref,const char* value);
  192. PR_EXTERN(int) PREF_SetDefaultIntPref(const char *pref,int32 value);
  193. PR_EXTERN(int) PREF_SetDefaultBoolPref(const char *pref,XP_Bool value);
  194. PR_EXTERN(int) PREF_SetDefaultBinaryPref(const char *pref,void * value, long size);
  195. PR_EXTERN(int) PREF_SetDefaultColorPref(const char *pref_name, uint8 red, uint8 green, uint8 blue);
  196. PR_EXTERN(int) PREF_SetDefaultRectPref(const char *pref_name, int16 left, int16 top, int16 right, int16 bottom);
  197.  
  198. /*
  199. // <font color=blue>
  200. // Get the various types of preferences.  These functions take a dotted
  201. // notation of the preference name (e.g. "browser.startup.homepage")
  202. //
  203. // They also take a pointer to fill in with the return value and return an
  204. // error value.  At the moment, this is simply an int but it may
  205. // be converted to an enum once the global error strategy is worked out.
  206. // In addition, the GetChar and GetBinary versions take an (int *) which
  207. // should contain the length of the buffer which is passed to be filled
  208. // in.  If the length passed in is 0, the function will not copy the
  209. // preference but will instead return the length necessary for the buffer,
  210. // including null terminator.
  211. //
  212. // They will perform conversion if the type doesn't match what was requested.
  213. // (if it is reasonably possible)
  214. // </font>
  215. */
  216. PR_EXTERN(int) PREF_GetCharPref(const char *pref, char * return_buf, int * buf_length);
  217. PR_EXTERN(int) PREF_GetIntPref(const char *pref, int32 * return_int);    
  218. PR_EXTERN(int) PREF_GetBoolPref(const char *pref, XP_Bool * return_val);    
  219. PR_EXTERN(int) PREF_GetBinaryPref(const char *pref, void * return_val, int * buf_length);    
  220. PR_EXTERN(int) PREF_GetColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue);
  221. PR_EXTERN(int) PREF_GetColorPrefDWord(const char *pref_name, uint32 *colorref);
  222. PR_EXTERN(int) PREF_GetRectPref(const char *pref_name, int16 *left, int16 *top, int16 *right, int16 *bottom);
  223.  
  224. /*
  225. // <font color=blue>
  226. // These functions are similar to the above "Get" version with the significant
  227. // difference that the preference module will alloc the memory (e.g. XP_STRDUP) and
  228. // the caller will need to be responsible for freeing it...
  229. // </font>
  230. */
  231. PR_EXTERN(int) PREF_CopyCharPref(const char *pref, char ** return_buf);
  232. PR_EXTERN(int) PREF_CopyBinaryPref(const char *pref_name, void ** return_value, int *size);
  233.  
  234. PR_EXTERN(int) PREF_CopyDefaultCharPref( const char *pref_name,  char ** return_buffer );
  235. PR_EXTERN(int) PREF_CopyDefaultBinaryPref(const char *pref, void ** return_val, int * size);    
  236.  
  237. /*
  238. // <font color=blue>
  239. // Get and set encoded full file/directory pathname strings
  240. // (i.e. file URLs without the file:// part).
  241. // On Windows and Unix, these are just stored as string preferences.
  242. // On Mac, paths should be stored as aliases.  These calls convert
  243. // between paths and aliases flattened into binary strings.
  244. // </font>
  245. */
  246. PR_EXTERN(int) PREF_CopyPathPref(const char *pref, char ** return_buf);
  247. PR_EXTERN(int) PREF_SetPathPref(const char *pref_name, const char *path, XP_Bool set_default);
  248.  
  249. /*
  250. // <font color=blue>
  251. // Same as the previous "Get" functions but will always return the
  252. // default value regardless of what the user has set.  These are designed
  253. // to be used by functions which "reset" the preferences
  254. //
  255. // </font>
  256. */
  257. PR_EXTERN(int) PREF_GetDefaultCharPref(const char *pref, char * return_buf, int * buf_length);
  258. PR_EXTERN(int) PREF_GetDefaultIntPref(const char *pref, int32 * return_int);    
  259. PR_EXTERN(int) PREF_GetDefaultBoolPref(const char *pref, XP_Bool * return_val);    
  260. PR_EXTERN(int) PREF_GetDefaultBinaryPref(const char *pref, void * return_val, int * buf_length);    
  261. PR_EXTERN(int) PREF_GetDefaultColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue);
  262. PR_EXTERN(int) PREF_GetDefaultColorPrefDWord(const char *pref_name, uint32 *colorref);
  263. PR_EXTERN(int) PREF_GetDefaultRectPref(const char *pref_name, int16 *left, int16 *top, int16 *right, int16 *bottom);
  264.  
  265. /*
  266. // <font color=blue>
  267. // Administration Kit support
  268. //
  269. // These fetch a given configuration parameter.
  270. // If the parameter is not defined, an error code will be returned;
  271. // a JavaScript error will not be generated (unlike the above Get routines).
  272. //
  273. // IndexConfig fetches an indexed button or menu string, e.g.
  274. //        PREF_CopyIndexConfigString( "menu.help.item", 3, "label", &buf );
  275. // to fetch the label of Help menu item 3.
  276. // The caller is responsible for freeing the returned string.
  277. // </font>
  278. */
  279. PR_EXTERN(int) PREF_CopyConfigString(const char *obj_name, char **return_buffer);
  280. PR_EXTERN(int) PREF_CopyIndexConfigString(const char *obj_name, int index,
  281.     const char *field, char **return_buffer);
  282. PR_EXTERN(int) PREF_GetConfigInt(const char *obj_name, int32 *return_int);
  283. PR_EXTERN(int) PREF_GetConfigBool(const char *obj_name, XP_Bool *return_bool);
  284.  
  285. /* OLD:: */PR_EXTERN(int) PREF_GetConfigString(const char *obj_name, char * return_buffer, int size,
  286.     int index, const char *field);
  287.  
  288. /*
  289. // <font color=blue>
  290. // XP_Bool funtion that returns whether or not the preference is locked and therefore
  291. // cannot be changed.
  292. // </font>
  293. */
  294. PR_EXTERN(XP_Bool) PREF_PrefIsLocked(const char *pref_name);
  295.  
  296. PR_EXTERN(int) PREF_GetPrefType(const char *pref_name);
  297.  
  298. /*
  299. // <font color=blue>
  300. // Cause the preference file to be written to disk
  301. // </font>
  302. */
  303. PR_EXTERN(int) PREF_SavePrefFile(void);
  304. PR_EXTERN(int) PREF_SavePrefFileAs(const char *filename);
  305.  
  306. /* LI_STUFF */
  307. PR_EXTERN(int) PREF_SaveLIPrefFile(const char *filename);
  308.  
  309.  
  310. /*
  311.  * Called to handle the "about:config" command.
  312.  * Currently dumps out some debugging information.
  313.  */
  314. PR_EXTERN(char *) PREF_AboutConfig();
  315.  
  316. /*
  317.  * Delete a branch of the tree
  318.  */
  319. PR_EXTERN(int) PREF_DeleteBranch(const char *branch_name);
  320.  
  321. /*
  322.  * Clears the given pref (reverts it to its default value)
  323.  */
  324. PR_EXTERN(int) PREF_ClearUserPref(const char *pref_name);
  325.  
  326. /*
  327.  * Creates an iterator over the children of a node.  Sample code:
  328.      char* children;
  329.     if ( PREF_CreateChildList("mime", &children) == 0 )
  330.     {    
  331.         int index = 0;
  332.         while (char* child = PREF_NextChild(children, &index)) {
  333.             ...
  334.         }
  335.         XP_FREE(children);
  336.     }
  337.  *    e.g. subsequent calls to Next() return
  338.  *     "mime.image_gif", then
  339.  *     "mime.image_jpeg", etc.
  340.  */
  341. PR_EXTERN(int) PREF_CreateChildList(const char* parent_node, char **child_list);
  342. PR_EXTERN(char*) PREF_NextChild(char *child_list, int *index);
  343.  
  344. /*
  345. // <font color=blue>
  346. // The callback function will get passed the pref_node which triggered the call
  347. // and the void * instance_data which was passed to the register callback function.
  348. // Return a non-zero result to pass an error up to the caller.
  349. // </font>
  350. */
  351. typedef int (*PrefChangedFunc) (const char *, void *); 
  352.  
  353. /*
  354. // <font color=blue>
  355. // Register a callback.  This takes a node in the preference tree and will
  356. // call the callback function if anything below that node is modified.
  357. // Unregister returns PREF_NOERROR if a callback was found that
  358. // matched all the parameters; otherwise it returns PREF_ERROR.
  359. // </font>
  360. */
  361. PR_EXTERN(void) PREF_RegisterCallback( const char* domain,
  362.                                 PrefChangedFunc callback, void* instance_data );
  363. PR_EXTERN(int) PREF_UnregisterCallback( const char* domain,
  364.                                 PrefChangedFunc callback, void* instance_data );
  365.  
  366. /*
  367. // Front ends implement to determine whether AutoAdmin library is installed.
  368. */
  369. PR_EXTERN(XP_Bool) PREF_IsAutoAdminEnabled();
  370.  
  371. #ifdef XP_UNIX
  372. struct fe_icon_data;
  373. typedef void* XmStringPtr;
  374. typedef void* KeySymPtr;
  375. PR_EXTERN(void) PREF_AlterSplashIcon(struct fe_icon_data*);
  376. PR_EXTERN(XP_Bool) PREF_GetLabelAndMnemonic(char*, char**, XmStringPtr xmstring, KeySymPtr keysym);
  377. PR_EXTERN(XP_Bool) PREF_GetUrl(char*, char**);
  378. #endif
  379.  
  380. NSPR_END_EXTERN_C
  381. #endif
  382.