home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE2.TAR / actions.c next >
Encoding:
C/C++ Source or Header  |  1991-11-12  |  6.4 KB  |  246 lines

  1. /*
  2.  * actions.c : Widget action procedures
  3.  *
  4.  * This file defines the global actionTable used in XtAppAddActions() and
  5.  * defines the action procedures, except those used on the settingsPanel
  6.  * which are imported. Eventually there may be more actions, and they'll
  7.  * be put here.
  8.  *
  9.  * George Ferguson, ferguson@cs.rochester.edu, 12 Nov 1991.
  10.  *
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <X11/Intrinsic.h>
  15. #include <X11/StringDefs.h>
  16. #include <X11/Xaw/Text.h>
  17. #include <X11/Xaw/Cardinals.h>
  18. #include "procquery.h"
  19. #include "xarchie.h"
  20. #include "types.h"
  21. #include "appres.h"
  22. #include "db.h"
  23. #include "settings.h"        /* for settings actions */
  24. #include "ftp.h"
  25. #include "alert.h"
  26. #include "confirm.h"
  27. #include "dialog.h"
  28. #include "regex.h"
  29. extern char *progname;
  30. extern Database *db;
  31. extern abortDirsend();        /* dirsend.c */
  32.  
  33. /*
  34.  * Functions defined here
  35.  */
  36. static void quitAction(),queryAction(),ftpAction();
  37. static void saveAction(),abortAction();
  38.  
  39. /*
  40.  * Data defined here:
  41.  */
  42. XtActionsRec actionTable[22] = {    /* check size in actions.h! */
  43.     { "quit",            quitAction },
  44.     { "query",            queryAction },
  45.     { "ftp",            ftpAction },
  46.     { "settings",        settingsAction },
  47.     { "apply-settings",        applySettingsAction },
  48.     { "default-settings",    defaultSettingsAction },
  49.     { "done-settings",        doneSettingsAction },
  50.     { "set-search-type",    setSearchTypeAction },
  51.     { "set-search-type-now",    setSearchTypeNowAction },
  52.     { "set-sort-type",        setSortTypeAction },
  53.     { "set-sort-type-now",    setSortTypeNowAction },
  54.     { "set-host",        setHostAction },
  55.     { "set-host-now",        setHostNowAction },
  56.     { "set-nice-level",        setNiceLevelAction },
  57.     { "set-nice-level-now",    setNiceLevelNowAction },
  58.     { "save-to-file",        saveAction },
  59.     { "abort",            abortAction },
  60.     { "alert-ok",        alertOk },
  61.     { "confirm-yes",        confirmYes },
  62.     { "confirm-no",        confirmNo },
  63.     { "dialog-ok",        dialogOk },
  64.     { "dialog-cancel",        dialogCancel },
  65. };
  66. static Boolean doingQuery;
  67.  
  68. /*    -    -    -    -    -    -    -    -    */
  69.  
  70. /*ARGSUSED*/
  71. static void
  72. quitAction(w,event,params,num_params)
  73. Widget w;
  74. XEvent *event;
  75. String *params;
  76. Cardinal *num_params;
  77. {
  78.     if (*num_params > ZERO || appResources.expert ||
  79.                     confirm0("Really quit xarchie?")) {
  80.     XtDestroyApplicationContext(appContext);
  81.     exit(0);
  82.     }
  83. }
  84.  
  85. /*ARGSUSED*/
  86. static void
  87. queryAction(w,event,params,num_params)
  88. Widget w;
  89. XEvent *event;
  90. String *params;
  91. Cardinal *num_params;
  92. {
  93.     Arg args[1];
  94.     char *s;
  95.     int len;
  96.     Boolean gif;
  97.  
  98.     if (doingQuery) {
  99.     /* Don't do anything using popups since we could be in dirsend()
  100.        by now. */
  101.     XBell(display,0);
  102.     return;
  103.     }
  104.     XtSetArg(args[0],XtNstring,&s);
  105.     XtGetValues(searchText,args,ONE);
  106.     if (*s == '\0') {
  107.     alert0("No search term specified.");
  108.     return;
  109.     }
  110. #ifndef DONT_CATCH_GIFS
  111.     len = strlen(s);
  112.     gif = False;
  113.     switch (appResources.searchType) {
  114.     case GfExact:
  115.         gif = ((len > 4 &&
  116.             (!strcmp(s+len-4,".gif") || !strcmp(s+len-4,".GIF"))) ||
  117.            (len > 6 &&
  118.             (!strcmp(s+len-6,".gif.Z") || !strcmp(s+len-6,".GIF.Z"))));
  119.         break;
  120.     case GfSubstr:
  121.     case GfExactSubstr:
  122.     case GfSubcase:
  123.     case GfExactSubcase:
  124.         gif = (sindex(s,"gif") || sindex(s,"GIF"));
  125.         break;
  126.     case GfRegexp:
  127.     case GfExactRegexp:
  128.         gif = (re_comp(s) == NULL &&
  129.            (re_exec("@PrObAbLyNoTaFiLe@.gif") ||
  130.             re_exec("@PrObAbLyNoTaFiLe@.gif.Z")));
  131.         break;
  132.     }
  133.     if (gif) {
  134.     if (!confirm0("Your search term will match GIFs. Do it anyway?"))
  135.         return;
  136.     else if (appResources.niceLevel <= 0 &&
  137.          !confirm0("Really do it without increasing niceness?"))
  138.         return;
  139.     }
  140. #endif /* DONT_CATCH_GIFS */
  141.     doingQuery = True;
  142.     if (queryButton != NULL)
  143.     XtSetSensitive(queryButton,False);
  144.     if (abortButton != NULL)
  145.     XtSetSensitive(abortButton,True);
  146.     if (appResources.sortType == GfInvdate)
  147.     procquery(appResources.archieHost,s,appResources.maxHits,
  148.           appResources.offset,appResources.searchType,True,0);
  149.     else
  150.     procquery(appResources.archieHost,s,appResources.maxHits,
  151.           appResources.offset,appResources.searchType,False,0);
  152.     doingQuery = False;
  153.     if (abortButton != NULL)
  154.     XtSetSensitive(abortButton,False);
  155.     if (queryButton != NULL)
  156.     XtSetSensitive(queryButton,True);
  157. }
  158.  
  159. /*ARGSUSED*/
  160. static void
  161. ftpAction(w,event,params,num_params)
  162. Widget w;
  163. XEvent *event;
  164. String *params;
  165. Cardinal *num_params;
  166. {
  167.     if (selectedHostEntry == HOST_NULL || selectedLocEntry == LOC_NULL ||
  168.     selectedFileEntry == FILE_NULL) {
  169.     alert0("You must specify a host, location and file before invoking ftp()");
  170.     return;
  171.     }
  172.     if (selectedFileEntry->modes[0] == 'd') {
  173.     alert0("Sorry, can't fetch whole directories yet.");
  174.     return;
  175.     }
  176.     ftp(selectedHostEntry->hostname,selectedLocEntry->linkpath,
  177.     selectedFileEntry->name);
  178. }
  179.  
  180. /*ARGSUSED*/
  181. static void
  182. saveAction(w,event,params,num_params)
  183. Widget w;
  184. XEvent *event;
  185. String *params;
  186. Cardinal *num_params;
  187. {
  188.     static char filename[256];
  189.     Arg args[1];
  190.     char *s;
  191.     FILE *fp;
  192.     HostEntry *hostp;
  193.     LocEntry *locp;
  194.     FileEntry *filep;
  195.  
  196.     if (*num_params == ZERO) {
  197.     if ((s=dialog("Filename to save to:",filename)) == NULL || *s == '\0')
  198.         return;
  199.     strncpy(filename,s,255);
  200.     } else if (*num_params == ONE) {
  201.     XtSetArg(args[0],XtNstring,&s);
  202.     XtGetValues(searchText,args,ONE);
  203.      sprintf(filename,*params,s);
  204.     } else {
  205.     fprintf(stderr,"%s: wrong number of args to \"save-to-file()\"",
  206.                                 progname);
  207.     return;
  208.     }
  209.     if ((fp=fopen(filename,"w")) == NULL) {
  210.     alert1("Can't open %s for writing",filename);
  211.     return;
  212.     }
  213.     status1("Writing %s...",filename);
  214.     if (appResources.saveFormatOneLine) {
  215.     for (hostp=db->hostEntries; hostp != NULL; hostp = hostp->next)
  216.         for (locp=hostp->locEntries; locp != NULL; locp = locp->next)
  217.         for (filep=locp->fileEntries; filep != NULL; filep=filep->next)
  218.             fprintf(fp,"%s %10d  %s  %s:%s/%s\n",
  219.                 filep->modes,filep->size,filep->date,
  220.                 hostp->hostname,locp->linkpath,filep->name);
  221.     } else {
  222.     for (hostp=db->hostEntries; hostp != NULL; hostp = hostp->next) {
  223.         fprintf(fp,"%s\n",hostp->hostname);
  224.         for (locp=hostp->locEntries; locp != NULL; locp = locp->next) {
  225.         fprintf(fp,"\t%s\n",locp->linkpath);
  226.         for (filep=locp->fileEntries; filep != NULL; filep=filep->next)
  227.             fprintf(fp,"\t\t%s %10d  %s  %s\n",
  228.                 filep->modes,filep->size,filep->date,filep->name);
  229.         }
  230.     }
  231.     }
  232.     fclose(fp);
  233.     status0("Ready");
  234. }
  235.  
  236. /*ARGSUSED*/
  237. static void
  238. abortAction(w,event,params,num_params)
  239. Widget w;
  240. XEvent *event;
  241. String *params;
  242. Cardinal *num_params;
  243. {
  244.     abortDirsend();
  245. }
  246.