home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Program / parentmulti.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  7KB  |  267 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopus.h"
  32.  
  33. enum {
  34.     PM_CANCEL,
  35.     PM_OKAY
  36. };
  37.  
  38. struct RequesterBase pm_req={
  39.     50,12,32,19,
  40.     8,6,
  41.     0,0,0,0,NULL,NULL,NULL,NULL,
  42.     NULL,NULL,NULL,
  43.     0,0,NULL,0,NULL};
  44.  
  45. struct TagItem
  46.     pm_lister[]={
  47.         {RO_Type,OBJECT_LISTVIEW},
  48.         {RO_ListViewID,0},
  49.         {RO_Top,1},
  50.         {RO_Width,50},
  51.         {RO_Height,10},
  52.         {RO_HighRecess,TRUE},
  53.         {TAG_END,0}},
  54.  
  55.     pm_okay_gadget[]={
  56.         {RO_Type,OBJECT_GADGET},
  57.         {RO_GadgetType,GADGET_BOOLEAN},
  58.         {RO_GadgetID,PM_OKAY},
  59.         {RO_Top,11},
  60.         {RO_TopFine,5},
  61.         {RO_Left,4},
  62.         {RO_LeftFine,-2},
  63.         {RO_Width,12},
  64.         {RO_Height,1},
  65.         {RO_HeightFine,4},
  66.         {RO_TextNum,STR_OKAY},
  67.         {RO_TextPos,TEXTPOS_CENTER},
  68.         {RO_HighRecess,TRUE},
  69.         {TAG_END,0}},
  70.  
  71.     pm_cancel_gadget[]={
  72.         {RO_Type,OBJECT_GADGET},
  73.         {RO_GadgetType,GADGET_BOOLEAN},
  74.         {RO_GadgetID,PM_CANCEL},
  75.         {RO_Top,11},
  76.         {RO_TopFine,5},
  77.         {RO_Width,12},
  78.         {RO_Height,1},
  79.         {RO_HeightFine,4},
  80.         {RO_Left,34},
  81.         {RO_LeftFine,18},
  82.         {RO_TextNum,STR_CANCEL},
  83.         {RO_TextPos,TEXTPOS_CENTER},
  84.         {RO_HighRecess,TRUE},
  85.         {TAG_END,0}},
  86.  
  87.     *pm_gadgets[]={
  88.         pm_okay_gadget,
  89.         pm_cancel_gadget,
  90.         NULL};
  91.  
  92. do_parent_multi(path)
  93. char *path;
  94. {
  95.     ULONG class;
  96.     USHORT gadgetid;
  97.     struct Window *rwindow;
  98.     struct Gadget *gadlist;
  99.     struct DOpusListView *listview,*view;
  100.     BPTR lock,parentlock,temp;
  101.     char buf[256],**table;
  102.     int a,count,lastsel=-1;
  103.     ULONG lastseconds=0,lastmicros=0,seconds,micros;
  104.  
  105.     if (!(lock=Lock(path,ACCESS_READ))) return(0);
  106.  
  107.     fix_requester(&pm_req,globstring[STR_SELECT_A_DIRECTORY]);
  108.  
  109.     if (!(rwindow=OpenRequester(&pm_req)) ||
  110.         !(gadlist=addreqgadgets(&pm_req,pm_gadgets,0,NULL)) ||
  111.         !(listview=(struct DOpusListView *)
  112.             AddRequesterObject(&pm_req,pm_lister))) {
  113.         CloseRequester(&pm_req);
  114.         UnLock(lock);
  115.         return(0);
  116.     }
  117.  
  118.     listview->window=rwindow;
  119.     listview->flags|=DLVF_LEAVE|DLVF_SLOW|DLVF_TTOP;
  120.     listview->sliderwidth=8;
  121.     listview->slidercol=pm_req.rb_fg;
  122.     listview->sliderbgcol=pm_req.rb_bg;
  123.     listview->textcol=pm_req.rb_fg;
  124.     listview->boxhi=pm_req.rb_shine;
  125.     listview->boxlo=pm_req.rb_shadow;
  126.     listview->arrowfg=pm_req.rb_fg;
  127.     listview->arrowbg=pm_req.rb_bg;
  128.     listview->itemfg=pm_req.rb_fg;
  129.     listview->itembg=pm_req.rb_bg;
  130.     listview->title=globstring[STR_PARENT_MULTI];
  131.  
  132.     SetBusyPointer(rwindow);
  133.  
  134.     parentlock=DupLock(lock);
  135.     count=0;
  136.     while (parentlock) {
  137.         ++count;
  138.         count+=get_multi_volume(parentlock,NULL,NULL);
  139.         temp=parentlock;
  140.         parentlock=ParentDir(parentlock);        
  141.         UnLock(temp);
  142.     }
  143.  
  144.     if (!(table=LAllocRemember(&pm_req.rb_memory,(count+1)*sizeof(char *),MEMF_CLEAR))) {
  145.         CloseRequester(&pm_req);
  146.         return(0);
  147.     }
  148.  
  149.     parentlock=DupLock(lock);
  150.     count=0;
  151.     while (parentlock) {
  152.         PathName(parentlock,buf,256);
  153.         if (table[count]=LAllocRemember(&pm_req.rb_memory,(a=(strlen(buf)+3)),0)) {
  154.             strcpy(table[count],buf);
  155.             TackOn(table[count],NULL,a-1);
  156.             ++count;
  157.         }
  158.         count+=get_multi_volume(parentlock,&table[count],&pm_req.rb_memory);
  159.         temp=parentlock;
  160.         parentlock=ParentDir(parentlock);        
  161.         UnLock(temp);
  162.     }
  163.  
  164.     UnLock(lock);
  165.  
  166.     listview->items=table;
  167.  
  168.     if (!(AddListView(listview,1))) {
  169.         CloseRequester(&pm_req);
  170.         return(0);
  171.     }
  172.  
  173.     RefreshRequesterObject(&pm_req,NULL);
  174.  
  175.     ClearPointer(rwindow);
  176.  
  177.     if (table[0]) strcpy(buf,table[0]);
  178.  
  179.     FOREVER {
  180.         while (IMsg=(struct IntuiMessage *)GetMsg(rwindow->UserPort)) {
  181.             seconds=IMsg->Seconds;
  182.             micros=IMsg->Micros;
  183.             if ((view=(struct DOpusListView *)ListViewIDCMP(listview,IMsg))==
  184.                 (struct DOpusListView *)-1) {
  185.                 if ((class=IMsg->Class)==IDCMP_VANILLAKEY && IMsg->Code==0x1b) {
  186.                     class=IDCMP_GADGETUP;
  187.                     gadgetid=PM_CANCEL;
  188.                 }
  189.                 else if (class==IDCMP_GADGETUP)
  190.                     gadgetid=((struct Gadget *) IMsg->IAddress)->GadgetID;
  191.                 ReplyMsg((struct Message *) IMsg);
  192.  
  193.                 switch (class) {
  194.                     case IDCMP_GADGETUP:
  195.                         RemoveListView(listview,1);    
  196.                         CloseRequester(&pm_req);
  197.                         if (gadgetid==PM_OKAY) strcpy(path,buf);
  198.                         return((int)gadgetid);
  199.                 }
  200.             }
  201.             else if (view) {
  202.                 if (table[view->itemselected]) {
  203.                     if (LStrnCmp(table[view->itemselected],"  + ",4)==0)
  204.                         strcpy(buf,&table[view->itemselected][4]);
  205.                     else strcpy(buf,table[view->itemselected]);
  206.                     if (view->itemselected==lastsel &&
  207.                         (DoubleClick(lastseconds,lastmicros,seconds,micros))) {
  208.                         RemoveListView(listview,1);    
  209.                         CloseRequester(&pm_req);
  210.                         strcpy(path,buf);
  211.                         return(PM_OKAY);
  212.                     }
  213.                     lastseconds=seconds;
  214.                     lastmicros=micros;
  215.                     lastsel=view->itemselected;
  216.                 }
  217.             }
  218.         }
  219.         Wait(1<<rwindow->UserPort->mp_SigBit);
  220.     }
  221. }
  222.  
  223. get_multi_volume(lock,table,key)
  224. BPTR lock;
  225. char **table;
  226. struct DOpusRemember **key;
  227. {
  228.     struct DosList *doslist;
  229.     struct RootNode *rootnode;
  230.     struct DosInfo *dosinfo;
  231.     struct AssignList *list;
  232.     char buf[256];
  233.     int count=0,tabcount=0,a;
  234.  
  235.     if (!system_version2) return(0);
  236.  
  237.     Forbid();
  238.  
  239.     rootnode=(struct RootNode *)DOSBase->dl_Root;
  240.     dosinfo=(struct DosInfo *)BADDR(rootnode->rn_Info);
  241.     doslist=(struct DosList *)BADDR(dosinfo->di_DevInfo);
  242.  
  243.     while (doslist) {
  244.         if (doslist->dol_Type==DLT_DIRECTORY &&
  245.             (SameLock(lock,doslist->dol_Lock)==LOCK_SAME)) {
  246.             list=doslist->dol_misc.dol_assign.dol_List;
  247.             while (list) {
  248.                 if (table) {
  249.                     PathName(list->al_Lock,buf,256);
  250.                     if (table[tabcount]=LAllocRemember(key,(a=(strlen(buf)+7)),0)) {
  251.                         StrCombine(table[tabcount],"  + ",buf,a-1);
  252.                         TackOn(table[tabcount],NULL,a-1);
  253.                         ++tabcount;
  254.                     }
  255.                 }
  256.                 ++count;
  257.                 list=list->al_Next;
  258.             }
  259.         }
  260.         doslist=(struct DosList *)BADDR(doslist->dol_Next);
  261.     }
  262.  
  263.     Permit();
  264.     if (table) return(tabcount);
  265.     else return(count);
  266. }
  267.