home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / plugins / nullplugin / nullplugin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.7 KB  |  194 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.  * nullplugin.c
  20.  *
  21.  * Implementation of the null plugins for Unix.
  22.  *
  23.  * dp <dp@netscape.com>
  24.  *
  25.  */
  26.  
  27. #include <stdio.h>
  28. #include <Xm/Xm.h>
  29. #include <Xm/MessageB.h>
  30. #include "npapi.h"
  31. #include "nullplugin.h"
  32.  
  33. /* Global data */
  34. MimeTypeElement *head = NULL;
  35.  
  36. static void
  37. UnmanageChild_safe (Widget w)
  38. {
  39.   if (w) XtUnmanageChild (w);
  40. }
  41.  
  42. static void
  43. nullPlugin_cb(Widget widget, XtPointer closure, XtPointer call_data)
  44. {
  45.     XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data;
  46.     PluginInstance* This = (PluginInstance*) closure;
  47.     char *url;
  48.  
  49.     switch (cb->reason) {
  50.         case XmCR_OK:
  51.         XtUnmanageChild(This->dialog);
  52.  
  53.         if (This->pluginsFileUrl != NULL)
  54.         {
  55.             /* Get the JavaScript command string */
  56.             char* buf = "javascript:netscape.softupdate.Trigger.StartSoftwareUpdate(\"%s\")";
  57.             url = NPN_MemAlloc(strlen(This->pluginsFileUrl) + 1 + strlen(buf) + 1);
  58.             if (url != NULL)
  59.             {
  60.             /* Insert the file URL into the JavaScript command */
  61.             sprintf(url, buf, This->pluginsFileUrl);
  62.             NPN_GetURL(This->instance, url, "_current");
  63.             NPN_MemFree(url);
  64.             }
  65.         }
  66.         else
  67.         {
  68.             /* If necessary, get the default plug-ins page resource */
  69.             char* address = This->pluginsPageUrl;
  70.             if (address == NULL)
  71.                 address = PLUGINSPAGE_URL;
  72.             
  73.             url = NPN_MemAlloc(strlen(address) + 1 + strlen(This->type) + 1);
  74.             if (url != NULL)
  75.             {
  76.             /* Append the MIME type to the URL */
  77.             sprintf(url, "%s?%s", address, This->type);
  78.             NPN_GetURL(This->instance, url, "PluginRegistry");
  79.             NPN_MemFree(url);
  80.             }
  81.         }
  82.  
  83.         
  84.  
  85.             break;
  86.  
  87.         case XmCR_CANCEL:
  88.             XtUnmanageChild(This->dialog);
  89.             break;
  90.     }
  91. }
  92.  
  93.  
  94. void
  95. showPluginDialog(Widget widget, XtPointer closure, XtPointer call_data)
  96. {
  97.     PluginInstance* This = (PluginInstance*) closure;
  98.     Widget dialog;
  99.     Arg av[20];
  100.     int ac;
  101.     XmString xmstr;
  102.     char message[1024];
  103.  
  104.     if (!This) return;
  105.  
  106.     dialog = This->dialog;
  107.  
  108.     if (dialog) {
  109.         /* The dialog is already available */
  110.         XtManageChild(dialog);
  111.         XMapRaised(XtDisplay(dialog), XtWindow(dialog));
  112.         return;
  113.     }
  114.  
  115.     /* Create the dialog */
  116.  
  117.     sprintf(message, MESSAGE, This->type);
  118.  
  119.     xmstr = XmStringCreateLtoR(message, XmSTRING_DEFAULT_CHARSET);
  120.  
  121.     ac = 0;
  122.     XtSetArg (av[ac], XmNvisual, This->visual); ac++;
  123.     XtSetArg (av[ac], XmNdepth, This->depth); ac++;
  124.     XtSetArg (av[ac], XmNcolormap, This->colormap); ac++;
  125.     XtSetArg (av[ac], XmNallowShellResize, TRUE); ac++;
  126.     XtSetArg (av[ac], XmNdialogStyle, XmDIALOG_MODELESS); ac++;
  127.     XtSetArg (av[ac], XmNdialogType, XmDIALOG_QUESTION); ac++;
  128.     XtSetArg (av[ac], XmNdeleteResponse, XmUNMAP); ac++;
  129.     XtSetArg (av[ac], XmNautoUnmanage, False); ac++;
  130.     XtSetArg (av[ac], XmNmessageString, xmstr); ac++;
  131.     dialog = XmCreateMessageDialog(This->button, "nullpluginDialog",
  132.                     av, ac);
  133.  
  134.     UnmanageChild_safe (XmMessageBoxGetChild (dialog,
  135.                         XmDIALOG_HELP_BUTTON));
  136.  
  137.     XtAddCallback(dialog, XmNokCallback, nullPlugin_cb, This);
  138.     XtAddCallback(dialog, XmNcancelCallback, nullPlugin_cb, This);
  139.  
  140.     XmStringFree(xmstr);
  141.  
  142.     This->dialog = dialog;
  143.     XtManageChild(dialog);
  144. }
  145.  
  146. /* MIMETypeList maintenance routines */
  147.  
  148. static Boolean
  149. isEqual(NPMIMEType t1, NPMIMEType t2)
  150. {
  151.     return(strcmp(t1, t2) == 0);
  152. }
  153.  
  154. static Boolean
  155. isExist(MimeTypeElement **typelist, NPMIMEType type)
  156. {
  157.     MimeTypeElement *ele;
  158.  
  159.     if (typelist == NULL) return False;
  160.  
  161.     ele = *typelist;
  162.     while (ele != NULL) {
  163.         if (isEqual(ele->value, type))
  164.             return True;
  165.         ele = ele->next;
  166.     }
  167.     return False;
  168. }
  169.  
  170. NPMIMEType
  171. dupMimeType(NPMIMEType type)
  172. {
  173.     NPMIMEType mimetype = NPN_MemAlloc(strlen(type)+1);
  174.     if (mimetype)
  175.         strcpy(mimetype, type);
  176.     return(mimetype);
  177. }
  178.  
  179. int
  180. addToList(MimeTypeElement **typelist, NPMIMEType type)
  181. {
  182.     MimeTypeElement *ele;
  183.  
  184.     if (!typelist) return(0);
  185.  
  186.     if (isExist(typelist, type)) return(0);
  187.  
  188.     ele = (MimeTypeElement *) NPN_MemAlloc(sizeof(MimeTypeElement));
  189.     ele->value = dupMimeType(type);
  190.     ele->next = *typelist;
  191.     *typelist = ele;
  192.     return(1);
  193. }
  194.