home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / libpref / src / unix / unixpref.c < prev   
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.5 KB  |  152 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.  unixpref.c
  21.  **********************************************************************/
  22.  
  23. #include "prefapi.h"
  24. #include "prlink.h"
  25. #include "jsapi.h"
  26. #include "jsbuffer.h"
  27. #include "xpassert.h"
  28.  
  29. #include <Xm/Xm.h>
  30.  
  31. extern PRLibrary* pref_LoadAutoAdminLib(void);
  32. extern PRLibrary* m_AutoAdminLib;
  33.  
  34. #include "icondata.h"
  35.  
  36. static struct fe_icon_type* splash_screen = NULL;
  37.  
  38.  
  39. /*
  40.  * pref_InitInitialObjects
  41.  * Needed by PREF_Init.
  42.  * Sets the default preferences.
  43.  */
  44. JSBool
  45. pref_InitInitialObjects(void)
  46. {
  47.     JSBool status;
  48.  
  49.     XP_ASSERT(pref_init_buffer);
  50.  
  51.     status = PREF_EvaluateJSBuffer(pref_init_buffer, strlen(pref_init_buffer));
  52.  
  53. #if defined(__sgi) || (defined(__sun) && defined(__svr4__))
  54.     PREF_SetDefaultCharPref("print.print_command", "lp");
  55. #endif
  56.  
  57.     return status;
  58. }
  59.  
  60.  
  61. /*
  62.  * PREF_AlterSplashIcon
  63.  */
  64. void
  65. PREF_AlterSplashIcon(struct fe_icon_data* icon)
  66. {
  67.     assert(icon);
  68.  
  69.     if ( PREF_IsAutoAdminEnabled() && 
  70.          icon && 
  71.          (splash_screen = (struct fe_icon_type*)
  72. #ifndef NSPR20
  73.           PR_FindSymbol("_POLARIS_SplashPro", m_AutoAdminLib)) != NULL ) {
  74. #else
  75.           PR_FindSymbol(m_AutoAdminLib, "_POLARIS_SplashPro")) != NULL ) {
  76. #endif
  77.  
  78.         memcpy(icon, splash_screen, sizeof(*icon));
  79.     }
  80. }
  81.  
  82.  
  83. /*
  84.  * PREF_GetLabelAndMnemonic
  85.  */
  86. XP_Bool
  87. PREF_GetLabelAndMnemonic(char* name, char** str, void* v_xm_str, void* v_mnemonic)
  88. {
  89.     XmString *xm_str = (XmString*)v_xm_str;
  90.     KeySym *mnemonic = (KeySym*)v_mnemonic;
  91.     char buf[256];
  92.     char* _str;
  93.     char* p1;
  94.     char* p2;
  95.  
  96.     XP_ASSERT(name);
  97.     XP_ASSERT(str);
  98.     XP_ASSERT(xm_str);
  99.  
  100.     if ( name == NULL || str == NULL || xm_str == NULL ) return FALSE;
  101.  
  102.     _str = NULL;
  103.     *str = NULL;
  104.     *xm_str = NULL;
  105.     *mnemonic = '\0';
  106.  
  107.     strncpy(buf, name, 200);
  108.     strcat(buf, ".label");
  109.  
  110.     PREF_CopyConfigString(buf, &_str);
  111.  
  112.     if ( _str == NULL || *_str == '\0' ) return FALSE;
  113.  
  114.     /* Strip out ampersands */
  115.     if ( strchr(_str, '&') != NULL ) {
  116.         for ( p1 = _str, p2 = _str; *p2; p1++, p2++ ) {
  117.             if ( *p1 == '&' && *(++p1) != '&' ) *mnemonic = *p1;
  118.             *p2 = *p1;
  119.         }
  120.     }
  121.  
  122.     *str = _str;
  123.     *xm_str = XmStringCreateLtoR(_str, XmFONTLIST_DEFAULT_TAG);
  124.  
  125.     return ( *xm_str != NULL );
  126. }
  127.  
  128.  
  129. /*
  130.  * PREF_GetUrl
  131.  */
  132. XP_Bool
  133. PREF_GetUrl(char* name, char** url)
  134. {
  135.     char buf[256];
  136.  
  137.     XP_ASSERT(name);
  138.  
  139.     if ( name == NULL || url == NULL ) return FALSE;
  140.  
  141.     strncpy(buf, name, 200);
  142.     strcat(buf, ".url");
  143.  
  144.     *url = NULL;
  145.  
  146.     PREF_CopyConfigString(buf, url);
  147.  
  148.     return ( url != NULL && *url != NULL && **url != '\0' );
  149. }
  150.  
  151.  
  152.