home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / addrbk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.3 KB  |  160 lines

  1. /* -*- Mode: C; tab-width: 8; 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.    addrbk.c    - a hack at the new address book STUFF
  21.  
  22.            Created:    Benjie Chen - 6/8/96
  23.            Copied lots of code from hot.c
  24.            Then deleted lots of code from hot.c
  25.            Then deleted lots of code from here
  26.            Then faked bunch of code here
  27.  
  28.            Modified:   Major changes - 7/17
  29.                       - I am separating the addressing window stuff
  30.                  from the address book stuff and putting the
  31.                  addressing window stuff off mailcompose window
  32.                  to allow multiple addressing windows and
  33.                  multiple mailcompose window instances - Benjie
  34. */
  35.  
  36.  
  37.  
  38. #include "mozilla.h"
  39. #include "xfe.h"
  40. #include "menu.h"
  41. #include "outline.h"
  42. #include "felocale.h"
  43. #include "xlate.h"
  44. #include "addrbook.h"
  45. #include "xp_file.h"
  46. #include "intl_csi.h"
  47.  
  48. /* Kludge around conflicts between Motif and xp_core.h... */
  49. #undef Bool
  50. #define Bool char
  51.  
  52. #include <Xfe/Xfe.h>            /* for xfe widgets and utilities */
  53.  
  54.  
  55. /* for XP_GetString() */
  56. #include <xpgetstr.h>
  57. #include "addrbk.h"
  58.  
  59. #ifndef LDAP_PORT
  60. #define LDAP_PORT       389
  61. #endif
  62.  
  63. /* list of DIR_Server 
  64. */
  65. static ABook*       AddrBook = NULL; 
  66. static MWContext*   ABfeContext = NULL;
  67.  
  68. extern ABook*       fe_GetABook(MWContext *); 
  69. extern void         fe_attach_dropfunc(Widget dropw, void* closure, 
  70.                                        fe_dnd_Event type,
  71.                                        fe_dnd_Source* source, 
  72.                                        XEvent* event);
  73.  
  74. #define XFE_CHUNK_SIZE   1024
  75. #define AB_DATA(context) ((context->type == MWContextAddressBook)?CONTEXT_DATA(context)->abdata:CONTEXT_DATA(context)->mailcomposer->abdata) 
  76.  
  77. /*****************************************************
  78.  * Actual code begins here 
  79.  */
  80. extern ABook* fe_GetABook(MWContext *context) 
  81. {
  82.   return AddrBook;
  83. }
  84.  
  85. extern XP_List* FE_GetDirServers()
  86. {
  87.       char tmp[256];
  88.     XP_List* m_directories = XP_ListNew();
  89.  
  90.     /* database file is not html anymore ... 
  91.      */
  92.     PR_snprintf(tmp, sizeof (tmp), "abook.nab"); 
  93.     DIR_GetServerPreferences (&m_directories, tmp);
  94.     return m_directories;
  95. }
  96.  
  97. ABook* FE_GetAddressBook(MSG_Pane *pane)
  98. {
  99.     return AddrBook;
  100. }
  101.  
  102. void FE_InitAddrBook() 
  103. {
  104.  
  105.     static XP_List *directories = NULL;
  106.     char     oldFile[1024];
  107.     XP_File  oldFp = 0;
  108.  
  109.       char     tmp[1024];
  110.       char    *home = getenv("HOME");
  111.       /*DIR_Server *dir;*/
  112.  
  113.       if (!home) home = "";
  114.  
  115.     PR_snprintf(oldFile, sizeof (oldFile), "%.900s/.netscape/addrbook.db", home); 
  116.     oldFp = XP_FileOpen(oldFile, xpAddrBook, "r");
  117.     if (oldFp) {
  118.         char    newFile[256];
  119.         XP_File newFp = 0;
  120.  
  121.         /* extern int XP_FileClose(XP_File file);
  122.          */
  123.         XP_FileClose(oldFp);
  124.  
  125.         PR_snprintf(newFile, sizeof (newFile), "%s", "abook.nab");
  126.         newFp = XP_FileOpen(newFile, xpAddrBookNew, "r");
  127.         if (!newFp) {
  128.             /* Rename file for backward compatibility reason
  129.              *   extern int XP_FileRename(const char * from, XP_FileType fromtype,
  130.              *     const char * to,   XP_FileType totype);
  131.              */
  132.             XP_FileRename(oldFile, xpAddrBook,
  133.                           newFile, xpAddrBookNew);
  134.         }/* !newFp */
  135.         else
  136.             XP_FileClose(newFp);
  137.     
  138.     }/* if */
  139.  
  140.     /* all right, lets do the list of directories and stuff */
  141.     directories = XP_ListNew();
  142.  
  143.     /* first the addressbook stuff */
  144.     /* database file is not html anymore ... */
  145.     PR_snprintf(tmp, sizeof (tmp), "abook.nab"); 
  146.  
  147.     DIR_GetServerPreferences (&directories, tmp);
  148.     PR_snprintf(tmp, sizeof (tmp), 
  149.                 "%.900s/.netscape/address-book.html", home); 
  150.     {
  151.         DIR_Server *pabDir = NULL;
  152.         DIR_GetPersonalAddressBook(directories, &pabDir);
  153.         AB_InitializeAddressBook(pabDir, &AddrBook, tmp);
  154.     }
  155. }
  156.  
  157. void FE_CloseAddrBook() {
  158.   AB_CloseAddressBook(&AddrBook);
  159. }
  160.