root/BF_Node.cpp

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. AllocLIcon
  2. AllocSIcon
  3. FreeSIcon
  4. Name
  5. Type
  6. Set
  7. Set
  8. CopySIconFrom
  9. PermsTo
  10. ConvertNameByMaskExt
  11. ConvertNameByMask
  12. CompareCreateTime
  13. SetSelect
  14. CheckByMask
  15. Load
  16. LoadInfo
  17. PathWFS
  18. String
  19. SetTo
  20. InFolder
  21. GetVolume
  22. IsStorageKit
  23. LastDir
  24. LastDir
  25. IsVirtualRoot
  26. GetPathForCurrentApp
  27. GoParent
  28. GoLocalDir
  29. Compare
  30. IsEmpty
  31. IsExisting
  32. Create
  33. IsVolumeReadOnly
  34. GoLocalDir
  35. GoParent
  36. LoadSIcon
  37. SetTo
  38. Compare
  39. SetTo
  40. NodeRef
  41. CheckNodeRef
  42. MakePath
  43. SetSelfPath
  44. CopyTo
  45. NodeByName
  46. IndexByName
  47. NodeByRef
  48. NodeAt
  49. SetSelectAll
  50. GetSelecting
  51. CountRealNodes
  52. SizeAll
  53. CountAll
  54. SelectedInfo
  55. CountSelected
  56. LoadChilds
  57. MakeSelfNodes
  58. BF_NodeCollection_Sort_Type
  59. BF_NodeCollection_Sort_Size
  60. BF_NodeCollection_Sort_Name
  61. BF_NodeCollection_Sort_Date
  62. Sort

   1 #include "BF_Node.h"
   2 #include "BF_Roster.h"
   3 #include "stdio.h"
   4 
   5 #include <Application.h>
   6 #include <Path.h>
   7 #include <Volume.h>
   8 
   9 BF_Node::BF_Node(const char *pc_Name)
  10 {
  11         if(pc_Name)     sName << pc_Name;
  12         iSize = 0;
  13         iType = BF_NODE_TYPE_UNKNOWN;
  14         bSelect = false;
  15         bLink = false;
  16         poSIcon = NULL;
  17         poLIcon = NULL; 
  18         ploChild = NULL;
  19         iStyles = BF_NODE_STYLE_DEFAULT;        
  20 }
  21 
  22 BF_Node::BF_Node(BF_Node *po_FromNode,bool b_SetIcon)
  23 {
  24         ASSERT(po_FromNode);
  25         bSelect = false;        
  26         poSIcon = NULL;         
  27         poLIcon = NULL;
  28         ploChild = NULL;
  29         Set(po_FromNode,b_SetIcon);
  30         
  31 }
  32 
  33 
  34 BF_Node::BF_Node(const BF_Node &o_FromNode,bool b_SetIcon)
  35 {
  36         bSelect = false;        
  37         poSIcon = NULL;         
  38         poLIcon = NULL;
  39         ploChild = NULL;
  40         Set(o_FromNode,b_SetIcon);
  41         
  42 }
  43 
  44 void
  45 BF_Node::AllocLIcon()    /* [previous][next][first][last][top][bottom][index][help] */
  46 {
  47         if(!poLIcon) poLIcon = new BBitmap(BRect(0,0,31,31),B_CMAP8);
  48 }
  49 
  50 void
  51 BF_Node::AllocSIcon()    /* [previous][next][first][last][top][bottom][index][help] */
  52 {
  53         if(!poSIcon) poSIcon = new BBitmap(BRect(0,0,15,15),B_CMAP8);
  54 }
  55 
  56 void
  57 BF_Node::FreeSIcon()    /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59         if(!poSIcon) return;
  60         DELETE(poSIcon);
  61 }
  62 
  63 const char*
  64 BF_Node::Name() const     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66         return sName.String();
  67 }
  68 
  69 int
  70 BF_Node::Type() const     /* [previous][next][first][last][top][bottom][index][help] */
  71 { return iType; }
  72 
  73 void                            
  74 BF_Node::Set( BF_Node *po_FromNode,bool b_SetIcon)    /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76         ASSERT(po_FromNode && po_FromNode!=this);
  77         Set(*po_FromNode,b_SetIcon);
  78 }
  79 
  80 void                            
  81 BF_Node::Set(const BF_Node &o_FromNode,bool b_SetIcon)    /* [previous][next][first][last][top][bottom][index][help] */
  82 {
  83         sName = o_FromNode.sName;
  84         sType = o_FromNode.sType;
  85         iSize = o_FromNode.iSize;       
  86         uCreateTime = o_FromNode.uCreateTime;           
  87         iType = o_FromNode.iType;                       
  88         bLink = o_FromNode.bLink;                       
  89         uNodeRef = o_FromNode.uNodeRef;         
  90         iStyles = o_FromNode.iStyles;
  91         /* copy icon */
  92         if(b_SetIcon && o_FromNode.poSIcon) CopySIconFrom(o_FromNode.poSIcon);
  93         //uEntryRef = po_FromNode->uEntryRef;                                   
  94 }
  95 
  96 void                            
  97 BF_Node::CopySIconFrom(BBitmap *po_SIcon)    /* [previous][next][first][last][top][bottom][index][help] */
  98 {
  99         ASSERT(po_SIcon);
 100         if(poSIcon) DELETE(poSIcon);
 101         poSIcon = new BBitmap(po_SIcon);
 102 }
 103 
 104 BF_Node::~BF_Node()
 105 {
 106         if(poSIcon) DELETE(poSIcon);
 107         if(poLIcon) DELETE(poLIcon);    
 108         if(ploChild) DELETE(ploChild);
 109 }
 110 
 111 void
 112 BF_Node::PermsTo(BL_String & s_Res) const    /* [previous][next][first][last][top][bottom][index][help] */
 113 {
 114         //read/write/execute * owner/group/others 
 115         s_Res = "";
 116         s_Res<<((uPerms & S_IRUSR)?"r":"-");            
 117         s_Res<<((uPerms & S_IWUSR)?"w":"-");            
 118         s_Res<<((uPerms & S_IXUSR)?"x":"-");            
 119         s_Res<<" ";
 120         s_Res<<((uPerms & S_IRGRP)?"r":"-");            
 121         s_Res<<((uPerms & S_IWGRP)?"w":"-");            
 122         s_Res<<((uPerms & S_IXGRP)?"x":"-");            
 123         s_Res<<" ";
 124         s_Res<<((uPerms & S_IROTH)?"r":"-");            
 125         s_Res<<((uPerms & S_IWOTH)?"w":"-");            
 126         s_Res<<((uPerms & S_IXOTH)?"x":"-");    
 127 }
 128 
 129 const BString*                  
 130 BF_Node::ConvertNameByMaskExt(const BString & s_Mask,BString & s_NewName) const    /* [previous][next][first][last][top][bottom][index][help] */
 131 {
 132         if(!ConvertNameByMask(s_Mask,s_NewName)) return &sName;else return &s_NewName;
 133 }
 134 
 135 bool
 136 BF_Node::ConvertNameByMask(const BString & s_Mask,BString & s_NewName) const    /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138         if(s_Mask=="") return false;
 139         /* check for mask */
 140         if(s_Mask.FindFirst("*")<0){
 141                 s_NewName = s_Mask;
 142                 return true;
 143         }else   
 144         if(s_Mask.FindFirst(".*")>0){
 145                 s_NewName = "";         
 146                 
 147                 int iMaskPos = s_Mask.FindFirst(".*");
 148                 s_NewName.Append(s_Mask,iMaskPos);              
 149 
 150                 int iDotPos = sName.FindFirst(".");
 151                 if(iDotPos<0) return false;
 152                 BL_String s;
 153                 sName.CopyInto(s,iDotPos,sName.Length()-iDotPos);
 154                 s_NewName << s;                         
 155                 
 156                 return true;    
 157         }else           
 158         if(s_Mask.FindFirst("*.")==0){
 159                 s_NewName = "";         
 160                 
 161                 int iDotPos = sName.FindFirst(".");
 162                 if(iDotPos<0) return false;
 163                 sName.CopyInto(s_NewName,0,iDotPos+1);
 164                 
 165                 BL_String s;
 166                 s_Mask.CopyInto(s,2,s_Mask.Length()-2);
 167                 s_NewName<<s;                           
 168                 
 169                 return true;                    
 170         }else
 171         {
 172                 int i=s_Mask.FindFirst("*");
 173                 s_NewName="";
 174                 if(i>0) s_NewName.Append(s_Mask,i);
 175                 i++;
 176                 s_NewName.Append(sName);
 177                 const char *pc = s_Mask.String()+i;
 178                 s_NewName.Append(pc,strlen(pc));
 179                         
 180                 return true;
 181         }
 182 }
 183 
 184 
 185 int8                            
 186 BF_Node::CompareCreateTime(const BF_Node &o_CompNode) const    /* [previous][next][first][last][top][bottom][index][help] */
 187 {
 188         if(o_CompNode.uCreateTime > uCreateTime) return 1;
 189         if(o_CompNode.uCreateTime < uCreateTime) return -1;     
 190         return 0;
 191 }
 192 
 193 void                            
 194 BF_Node::SetSelect(uint i_SelectAction)    /* [previous][next][first][last][top][bottom][index][help] */
 195 {
 196         if(BF_NODE_TYPE_PARENTDIR==iType) return;
 197         switch(i_SelectAction){
 198         case BF_NODE_SELECT_INVERT:
 199                 bSelect = !bSelect;break;
 200         default:
 201                 bSelect = i_SelectAction;               
 202         }
 203 }
 204 
 205 bool 
 206 BF_Node::CheckByMask(const char *pc_MaskLine) const    /* [previous][next][first][last][top][bottom][index][help] */
 207 {
 208         ASSERT(pc_MaskLine);
 209         if(BF_NODE_TYPE_PARENTDIR==iType) return false;
 210         if(strlen(pc_MaskLine)==0) return false;
 211                 
 212 
 213 /*      
 214         BL_String sMask(pc_MaskLine);
 215         // check *.lala 
 216         if(sMask.FindFirst("*")==0 && sMask.FindFirst("*",1)<0){
 217                 BL_String       s;      
 218                 int32           iOffset;
 219                 sMask.CopyInto(s,1,sMask.Length()-2);
 220                 if(sName.FindFirst(s.String())>0) return true;
 221         }else
 222         // check *.*
 223         if(sMask=="*.*" || sMask=="*"){
 224                 return true;
 225         }else
 226         // check *.lala 
 227         if(sMask.FindFirst("*")==(sMask.Length()-1)){
 228                 BL_String s;    
 229                 sMask.CopyInto(s,1,sMask.Length()-2);
 230                 if(sName.FindFirst(s.String())>0) return true;
 231         }else           
 232         {}
 233         
 234         return false;
 235 
 236 */                              
 237         char pcSelf[sName.Length()+1];  
 238         strcpy(pcSelf,sName.String());
 239         //
 240         char *pc,*pc1 = pcSelf,c1,*pc3;
 241         char  pcMask[strlen(pc_MaskLine)+1];
 242         char *pc2 = pcMask;
 243         strcpy(pcMask,pc_MaskLine);
 244         //
 245         while('\0'!=pc2[0] || '\0'!=pc1[0]){
 246                 // if current char '*'   
 247                 if('*'==pc2[0]){
 248                         pc2++;
 249                         if('\0'==pc2[0]) return true;
 250                 }else
 251                 // if current char '?'   
 252                 if('?'==pc2[0]){                        
 253                         pc2++;pc1++;
 254                 }else{
 255                         // any other char 
 256                         pc = pc2;
 257                         while(pc[0]!='\0' && pc[0]!='*' && pc[0]!='?') pc++;
 258                         c1 = pc[0];
 259                         pc[0]='\0';
 260                         //printf("pc1<%s> pc2<%s>\n",pc1,pc2);
 261                         pc3 = strstr(pc1,pc2);
 262                         if(!pc3){
 263                                 pc[0] = c1;
 264                                 if(strcmp(pc2,".*")==0) return true; 
 265                                 return false;                   
 266                         }
 267                         pc1=pc3+strlen(pc2);
 268                         pc[0] = c1;
 269                         if('\0'==pc[0]) return '\0' == pc1[0];
 270                         pc2 = pc;
 271                 }               
 272         }       
 273         return '\0'==pc1[0] && '\0'==pc2[0];
 274 }
 275 
 276 /*=====================================================*/
 277 BF_Volume::BF_Volume():BF_Node((const char*)NULL)
 278 {
 279         bBootVolume = false;
 280         bReadOnly = false;
 281         bRemovable = false;
 282         bPersistent = false;
 283         bShared = false;
 284         bKnowsQuery = false;
 285         
 286         iCapacity = 0;
 287         iFree = 0;
 288         
 289         bLoadedOk = false;
 290 }
 291 
 292 bool
 293 BF_Volume::Load(const char *pc_Name,int i_NodeLoadStyles)    /* [previous][next][first][last][top][bottom][index][help] */
 294 {
 295         bLoadedOk = false;
 296         if(pc_Name) sName = pc_Name;
 297         if(!BF_Roster_ReloadNode(NULL,this,i_NodeLoadStyles)) return false;
 298         
 299         LoadInfo();
 300                  
 301         return true;
 302 }
 303 
 304 void                            
 305 BF_Volume::LoadInfo()    /* [previous][next][first][last][top][bottom][index][help] */
 306 {       
 307         bLoadedOk = false; 
 308         
 309         BVolume oVol(uNodeRef.device);  
 310         bLoadedOk = B_OK==oVol.InitCheck();
 311         if(!bLoadedOk) return;
 312         
 313         iCapacity = oVol.Capacity();
 314         iFree =         oVol.FreeBytes();
 315         bReadOnly = oVol.IsReadOnly();
 316         bRemovable = oVol.IsRemovable();
 317         bPersistent = oVol.IsPersistent();
 318         bShared  = oVol.IsShared();
 319         bKnowsQuery = oVol.KnowsQuery();
 320 }
 321 /*=====================================================*/
 322 BF_Path::BF_Path(const char *pc_Value)
 323 {
 324         SetTo(pc_Value?pc_Value:"");
 325 }
 326 
 327 BF_Path::~BF_Path()
 328 {
 329 }
 330 
 331 const BL_String     
 332 BF_Path::PathWFS() const    /* [previous][next][first][last][top][bottom][index][help] */
 333 {
 334         BL_String s;
 335         sValue.CopyInto(s,1,sValue.Length()-1);
 336         return s;
 337 }
 338 
 339 const BL_String         
 340 BF_Path::String() const    /* [previous][next][first][last][top][bottom][index][help] */
 341 {
 342         return BL_String(Path());
 343 }
 344 
 345 const char*                             
 346 BF_Path::Path() const
 347 {
 348         return sValue.String();
 349 }
 350 
 351 void                            
 352 BF_Path::operator = (const BL_String & s_From)
 353 {
 354         SetTo(s_From.String());
 355 }
 356 
 357 void                            
 358 BF_Path::SetTo(const char *pc_Path)    /* [previous][next][first][last][top][bottom][index][help] */
 359 {
 360         sValue = pc_Path;
 361 }
 362 
 363 bool
 364 BF_Path::operator       == (const char *pc_ComparePath) const
 365 {
 366         return sValue==pc_ComparePath;
 367 }
 368 
 369 bool                            
 370 BF_Path::InFolder(const char *pc_ParentPath) const    /* [previous][next][first][last][top][bottom][index][help] */
 371 {
 372         return sValue.FindFirst(pc_ParentPath)==0;
 373 }
 374 
 375 // sValue="/boot/home/test",s_Result = b_CleanVolume?"boot":"/boot"
 376 
 377 const BString           
 378 BF_Path::GetVolume(bool b_CleanVolume) const    /* [previous][next][first][last][top][bottom][index][help] */
 379 {
 380         BString s;
 381         
 382         if(sValue.FindFirst('/')<0 || sValue.Length()==1) return s;
 383 
 384         int i2=sValue.FindFirst('/',1);
 385         if(i2<=0) i2 = sValue.Length();
 386         //
 387         sValue.CopyInto(s,(b_CleanVolume?1:0),i2-(b_CleanVolume?1:0));
 388         //      
 389         return s;
 390 }
 391 
 392 bool                            
 393 BF_Path::IsStorageKit() const    /* [previous][next][first][last][top][bottom][index][help] */
 394 {
 395         return sValue.FindFirst("//")<0 &&  sValue.FindFirst("/")==0;
 396 }
 397 
 398 bool                            
 399 BF_Path::LastDir(BString & s) const    /* [previous][next][first][last][top][bottom][index][help] */
 400 {       
 401         int i=sValue.FindLast('/');
 402         if(i<0) return false;
 403         sValue.CopyInto(s,i+1,sValue.Length()-1-i);
 404         printf("LastDir %s\n",s.String());
 405         return true;
 406 }
 407 
 408 const BL_String         
 409 BF_Path::LastDir() const    /* [previous][next][first][last][top][bottom][index][help] */
 410 {
 411         BL_String s;
 412         LastDir(s);
 413         return s;
 414 }
 415 
 416 bool
 417 BF_Path::IsVirtualRoot() const    /* [previous][next][first][last][top][bottom][index][help] */
 418 {
 419         return sValue=="/";     
 420 }
 421 
 422 #include <Roster.h>
 423 
 424 bool
 425 BF_Path::GetPathForCurrentApp(BL_String & s_Path)    /* [previous][next][first][last][top][bottom][index][help] */
 426 {
 427         app_info uAppInfo;
 428         be_app->GetAppInfo(&uAppInfo);
 429         BEntry  oEntry(&uAppInfo.ref);
 430         oEntry.GetParent(&oEntry);
 431         BPath   oPath;
 432         oEntry.GetPath(&oPath);
 433 
 434         s_Path  = oPath.Path();
 435         return true;
 436 }
 437 
 438 bool                            
 439 BF_Path::GoParent()    /* [previous][next][first][last][top][bottom][index][help] */
 440 {
 441         BPath oPath(Path());
 442         if(B_OK!=oPath.GetParent(&oPath)) return false;
 443         
 444         sValue = oPath.Path();  
 445         
 446         return(true);
 447 }
 448 
 449 bool                            
 450 BF_Path::GoLocalDir(const BString & s_LocalDir)    /* [previous][next][first][last][top][bottom][index][help] */
 451 {       
 452         if(sValue!="/") sValue<<"/";
 453         sValue<<s_LocalDir;             
 454         
 455         return(true);
 456 }
 457 
 458 bool                            
 459 BF_Path::Compare(const char *pc_Path)    /* [previous][next][first][last][top][bottom][index][help] */
 460 {
 461         ASSERT(pc_Path);
 462         return sValue==pc_Path;
 463 }
 464 
 465 
 466 
 467 
 468 bool
 469 BF_Path::IsEmpty() const    /* [previous][next][first][last][top][bottom][index][help] */
 470 {
 471         return sValue=="";
 472 }
 473 
 474 /*=====================================================*/
 475 
 476 BF_FilesPath::BF_FilesPath(const char *pc_Value)
 477 :BF_Path(pc_Value)
 478 {                       
 479         SetTo(pc_Value,NULL);
 480 }
 481 
 482 BF_FilesPath::BF_FilesPath(const BF_Path & o_SrcPath)
 483 {       
 484         SetTo(o_SrcPath);
 485 }
 486 
 487 
 488 BF_FilesPath::BF_FilesPath(const BF_FilesPath & o_SrcPath)
 489 {       
 490         SetTo(o_SrcPath);
 491 }
 492 
 493 bool                            
 494 BF_FilesPath::IsExisting() const    /* [previous][next][first][last][top][bottom][index][help] */
 495 {
 496         return BF_Roster_NodeExists(Path());
 497 }
 498 
 499 status_t                        
 500 BF_FilesPath::Create()    /* [previous][next][first][last][top][bottom][index][help] */
 501 {
 502         return BF_Roster_MakeDir(Path());
 503 }
 504 
 505 bool
 506 BF_FilesPath::IsVolumeReadOnly() const    /* [previous][next][first][last][top][bottom][index][help] */
 507 {
 508         // check drive for read_only //
 509         BF_Volume       oVol;
 510         BL_String       s(GetVolume(true));
 511         oVol.Load(s.String(),BF_ROSTER_LOAD_NORMAL);
 512         return oVol.bReadOnly;
 513 }
 514 
 515 
 516 
 517 bool                            
 518 BF_FilesPath::GoLocalDir(const BString & s_LocalDir)    /* [previous][next][first][last][top][bottom][index][help] */
 519 {
 520         if(!BF_Path::GoLocalDir(s_LocalDir)) return false;
 521         
 522         BF_Roster_LoadNodeRef(sValue.String(),uNodeRef);
 523         
 524         return true;
 525 }
 526 
 527 bool                            
 528 BF_FilesPath::GoParent()    /* [previous][next][first][last][top][bottom][index][help] */
 529 {
 530         if(!BF_Path::GoParent()) return true;
 531         
 532         BF_Roster_LoadNodeRef(sValue.String(),uNodeRef);
 533         return true;
 534 }
 535 
 536 BBitmap*                
 537 BF_FilesPath::LoadSIcon()    /* [previous][next][first][last][top][bottom][index][help] */
 538 {       
 539         BBitmap* poSIcon;
 540         
 541         BF_Node *poNode = BF_Roster_LoadNode("",Path(),BF_ROSTER_LOAD_SICON);
 542         if(!poNode) return NULL;
 543         poSIcon = poNode->poSIcon;
 544         poNode->poSIcon = NULL;
 545         DELETE(poNode);
 546                         
 547         return poSIcon;
 548 }
 549 
 550 void                            
 551 BF_FilesPath::operator = (const BF_FilesPath &o_Path)
 552 {
 553         BF_FilesPath::SetTo(o_Path);
 554 }
 555 
 556 void                            
 557 BF_FilesPath::operator = (const BF_Path &o_Path)
 558 {
 559         BF_FilesPath::SetTo(o_Path.sValue.String(),NULL);
 560 }
 561 
 562 void                            
 563 BF_FilesPath::SetTo(const BF_FilesPath &o_Path)    /* [previous][next][first][last][top][bottom][index][help] */
 564 {
 565         BF_FilesPath::SetTo(o_Path.sValue.String(),&o_Path.uNodeRef);
 566 }
 567 
 568 bool                            
 569 BF_FilesPath::Compare(const BF_FilesPath &o_SomePath)    /* [previous][next][first][last][top][bottom][index][help] */
 570 {
 571         return uNodeRef==o_SomePath.uNodeRef;
 572 }
 573 
 574 void                            
 575 BF_FilesPath::SetTo(const char *pc_Path,const node_ref *pu_NodeRef)    /* [previous][next][first][last][top][bottom][index][help] */
 576 {
 577         BF_Path::SetTo(pc_Path); 
 578         /* set node_ref for this path */
 579         if(pu_NodeRef) 
 580                 uNodeRef = *pu_NodeRef;
 581         else{
 582                 BF_Roster_LoadNodeRef(pc_Path,uNodeRef); 
 583         }
 584 }
 585 
 586 node_ref&                       
 587 BF_FilesPath::NodeRef() const    /* [previous][next][first][last][top][bottom][index][help] */
 588 {
 589         node_ref *puResultRef = new node_ref(uNodeRef);
 590         return *puResultRef;
 591 }
 592 
 593 bool                            
 594 BF_FilesPath::CheckNodeRef(const node_ref & u_NodeRef) const    /* [previous][next][first][last][top][bottom][index][help] */
 595 {
 596         return uNodeRef==u_NodeRef;
 597 }
 598 
 599 
 600 /*=====================================================*/
 601 BF_NodeCollection::BF_NodeCollection(bool b_DeleteItems)
 602 :BL_Collection(b_DeleteItems)
 603 {
 604         poPath = NULL;
 605         bSelfPath = FALSE;
 606 }
 607 
 608 BF_NodeCollection::~BF_NodeCollection()
 609 {
 610 }
 611 
 612 void                            
 613 BF_NodeCollection::MakePath(const char *pc_Path)    /* [previous][next][first][last][top][bottom][index][help] */
 614 {
 615         if(poPath && !bSelfPath) poPath = NULL;
 616         bSelfPath = true;
 617         if(!poPath) poPath = new BF_Path();
 618         poPath->SetTo(pc_Path);
 619 }
 620 
 621 void                            
 622 BF_NodeCollection::SetSelfPath(BF_Path* po_NewPath)    /* [previous][next][first][last][top][bottom][index][help] */
 623 {
 624         ASSERT(po_NewPath);
 625         if(poPath && bSelfPath) DELETE(poPath);
 626         bSelfPath = true;
 627         poPath = po_NewPath;    
 628 }
 629 
 630 void                            
 631 BF_NodeCollection::CopyTo(BF_NodeCollection & lo_Dest,bool b_CopyIcons) const    /* [previous][next][first][last][top][bottom][index][help] */
 632 {
 633         BF_Node *poNodeSrc,*poNodeDest;
 634         for(int i=0;i<CountItems();i++){
 635                 poNodeSrc = NodeAt(i);
 636                 poNodeDest = new BF_Node(*poNodeSrc,b_CopyIcons);
 637                 lo_Dest.AddItem(poNodeDest);
 638         }
 639 }
 640 
 641 
 642 BF_Node*
 643 BF_NodeCollection::NodeByName(const char *pc_Name) const    /* [previous][next][first][last][top][bottom][index][help] */
 644 {
 645         ASSERT(pc_Name);
 646         BF_Node *poNode;
 647         for(int i=0;i<CountItems();i++){
 648                 poNode =(BF_Node*)ItemAt(i);
 649                 if(poNode->sName==pc_Name){                     
 650                         return poNode;
 651                 }
 652         }
 653         return NULL;
 654 }
 655 
 656 int32
 657 BF_NodeCollection::IndexByName(const char *pc_Name) const    /* [previous][next][first][last][top][bottom][index][help] */
 658 {
 659         ASSERT(pc_Name);
 660         BF_Node *poNode;
 661         for(int i=0;i<CountItems();i++){
 662                 poNode =(BF_Node*)ItemAt(i);
 663                 if(poNode->sName==pc_Name)      return i;
 664         }
 665         return 0;
 666 }
 667  
 668 
 669 
 670 BF_Node*                        
 671 BF_NodeCollection::NodeByRef(node_ref & u_NodeRef) const    /* [previous][next][first][last][top][bottom][index][help] */
 672 {
 673         BF_Node *poNode;
 674         for(int i=0;i<CountItems();i++){
 675                 poNode =(BF_Node*)ItemAt(i);
 676                 if(BF_NODE_TYPE_PARENTDIR == poNode->iType) continue;
 677                 /*printf("checking node name=%s device=%i node=%i\n",
 678                         poNode->sName.String(), poNode->uRef.device,poNode->uRef.node);*/
 679                 if(poNode->uNodeRef==u_NodeRef) return poNode;
 680         }       
 681         return NULL;
 682 }
 683 
 684 BF_Node*                        
 685 BF_NodeCollection::NodeAt(int32 i_Index) const    /* [previous][next][first][last][top][bottom][index][help] */
 686 {
 687         return( (BF_Node*)ItemAt(i_Index) );
 688 }
 689 
 690 void                            
 691 BF_NodeCollection::SetSelectAll(uint i_SelectAction,const char *pc_Mask,int i_What)    /* [previous][next][first][last][top][bottom][index][help] */
 692 {
 693         if(pc_Mask && strlen(pc_Mask)==0) return;
 694         BF_Node *poNode;        
 695         for(int i=0;i<CountItems();i++){
 696                 poNode = (BF_Node*)ItemAt(i);
 697                 if(pc_Mask && !poNode->CheckByMask(pc_Mask)) continue;
 698                 if(poNode->iType==BF_NODE_TYPE_DIR && !(i_What & BF_NODELIST_NODETYPE_DIRS)) continue;
 699                 if(poNode->iType==BF_NODE_TYPE_FILE && !(i_What & BF_NODELIST_NODETYPE_FILES)) continue;                
 700                 if(poNode->iType==BF_NODE_TYPE_LINK && !(i_What & BF_NODELIST_NODETYPE_LINKS)) continue;                
 701                 poNode->SetSelect(i_SelectAction);
 702         }
 703 }
 704 uint64                          
 705 BF_NodeCollection::GetSelecting(BF_NodeCollection & lo_Result) const    /* [previous][next][first][last][top][bottom][index][help] */
 706 {
 707         BF_Node *poNode;        
 708         lo_Result.MakeEmpty();
 709         for(int i=0;i<CountItems();i++){
 710                 poNode = (BF_Node*)ItemAt(i);
 711                 if(poNode->bSelect) lo_Result.AddItem(poNode);
 712         }
 713         lo_Result.poPath = poPath;
 714         return lo_Result.CountItems();
 715 }
 716 
 717 uint64                          
 718 BF_NodeCollection::CountRealNodes() const    /* [previous][next][first][last][top][bottom][index][help] */
 719 {
 720         uint64 iCount = CountItems();
 721         BF_Node *poNode = NodeAt(0);
 722         if(poNode && BF_NODE_TYPE_PARENTDIR==poNode->iType) iCount--;
 723         return iCount;
 724 }
 725 
 726 uint64                          
 727 BF_NodeCollection::SizeAll(bool b_WithChilds) const    /* [previous][next][first][last][top][bottom][index][help] */
 728 {       
 729         uint64 iSize = 0;
 730         BF_Node *poNode;
 731         for(int i=0;i<CountItems();i++){
 732                 poNode = NodeAt(i);                             
 733                 
 734                 if( poNode->bLink ) continue;
 735                 if( BF_NODE_TYPE_FILE==poNode->iType ) iSize+=poNode->iSize;
 736                 if( BF_NODE_TYPE_DIR!=poNode->iType ) continue;
 737                 
 738                 if(!b_WithChilds && !poNode->ploChild) continue;
 739                 /* size of childs this node */
 740                 iSize+=poNode->ploChild->SizeAll(true);
 741         }
 742         return iSize;
 743 }
 744 
 745 uint64                          
 746 BF_NodeCollection::CountAll(bool b_WithChilds) const    /* [previous][next][first][last][top][bottom][index][help] */
 747 {
 748         uint64 iCount = CountItems();
 749         /* count of all childs */
 750         if(b_WithChilds){
 751                 BF_Node *poNode;
 752                 for(int i=0;i<CountItems();i++){
 753                         poNode  = NodeAt(i);                    
 754                         if(poNode->bLink || BF_NODE_TYPE_DIR!=poNode->iType) continue;
 755                         if(!poNode->ploChild) continue;
 756                         iCount+=poNode->ploChild->CountAll(true);
 757                 }
 758         }
 759         return iCount;
 760 }
 761 
 762 void                            
 763 BF_NodeCollection::SelectedInfo(uint64 & i_Bytes,uint64 & i_Count) const    /* [previous][next][first][last][top][bottom][index][help] */
 764 {
 765         i_Bytes = 0;
 766         i_Count = 0;
 767         BF_Node *poNode;        
 768         for(int i=0;i<CountItems();i++){
 769                 poNode = (BF_Node*)ItemAt(i);
 770                 if(BF_NODE_TYPE_PARENTDIR==poNode->iType) continue;
 771                 if(!poNode->bSelect) continue;
 772                 i_Bytes+=poNode->iSize;
 773                 i_Count++;
 774         }       
 775 }
 776 
 777 uint64                          
 778 BF_NodeCollection::CountSelected() const    /* [previous][next][first][last][top][bottom][index][help] */
 779 {
 780         uint64  iCount = 0;
 781         BF_Node *poNode=NULL;
 782         for(int i=0;i<CountItems();i++){
 783                 poNode = (BF_Node*)ItemAt(i);
 784                 if(BF_NODE_TYPE_PARENTDIR==poNode->iType) continue;
 785                 if(poNode->bSelect) iCount++;
 786         }
 787         return iCount;
 788 }
 789 
 790 void                            
 791 BF_NodeCollection::LoadChilds(int i_WhatRosterLoad)    /* [previous][next][first][last][top][bottom][index][help] */
 792 {
 793         BF_Node *poNode;
 794         BString s;
 795         for(int i=0;i<CountItems();i++){
 796                 poNode = NodeAt(i);
 797                 if(poNode->ploChild) poNode->ploChild->DeleteItems();
 798                 if(poNode->bLink || poNode->iType!=BF_NODE_TYPE_DIR) continue;
 799                 /* load childs */
 800                 if(!poNode->ploChild) poNode->ploChild = new  BF_NodeList();            
 801                 //
 802                 ASSERT(poPath);
 803                 /* make path for childs */
 804                 s=poPath->Path();
 805                 s<<"/";
 806                 s<<poNode->sName;
 807                 poNode->ploChild->MakePath(s.String());         
 808                 /* load path */
 809                 BF_Roster_LoadNodeList(*poNode->ploChild->poPath
 810                         ,*poNode->ploChild,i_WhatRosterLoad);
 811                 //µprintf(">>>>>to_deep{%s},childs_count{%i}\n",s.String(),poNode->ploChild->CountItems());            
 812                 //
 813                 poNode->ploChild->LoadChilds(i_WhatRosterLoad);         
 814         }       
 815         
 816 }
 817 
 818 void                            
 819 BF_NodeCollection::MakeSelfNodes()    /* [previous][next][first][last][top][bottom][index][help] */
 820 {       
 821         BF_Node *poNode;
 822         for(int i=0;i<CountItems();i++){
 823                 poNode = NodeAt(i);
 824                 RemoveItem(i);
 825                 AddItem( new BF_Node(*poNode),i);
 826         }
 827         bDeleteItems = true;
 828 }
 829 
 830 uint32  BF_NodeCollection::iSortStyle=BF_SORT_STYLE_DIRFIRST;
 831 
 832 
 833 #define PREPARE_SORT() BF_Node  *po1 = *((BF_Node**)p_1),*po2 = *((BF_Node**)p_2); \
 834         ASSERT(po1  && po2); \
 835         if(po1->iType==BF_NODE_TYPE_PARENTDIR)  return(-1); \
 836         if(po2->iType==BF_NODE_TYPE_PARENTDIR)  return(+1);     \
 837         if((BF_NodeList::iSortStyle & BF_SORT_STYLE_DIRFIRST) &&  po2->iType==BF_NODE_TYPE_DIR && po1->iType!=BF_NODE_TYPE_DIR) \
 838         return(1)
 839 
 840 int
 841 BF_NodeCollection_Sort_Ext(const void * p_1, const void *p_2)
 842 {
 843         PREPARE_SORT();         
 844                 
 845         if(po2->iType!=BF_NODE_TYPE_DIR && po1->iType!=BF_NODE_TYPE_DIR){
 846                 int i1,i2;
 847                 i1 = po1->sName.FindLast('.');
 848                 i2 = po2->sName.FindLast('.');
 849                 if(!i1 && i2) return(-1);
 850                 if(i1 && !i2) return(1);
 851                 if(!i1 && !i2) return(0);                                               
 852                 int iResult=po1->sName.ComparePos(po2->sName,i1+1,i2+1);
 853                 if(iResult!=0) return iResult;
 854                 //printf("{%s},{%s}\n",po1->sName.String(),po2->sName.String());
 855                 return po1->sName.Compare(po2->sName);
 856         }
 857         return 0;       
 858 }
 859 
 860 int
 861 BF_NodeCollection_Sort_Type(const void * p_1, const void *p_2)    /* [previous][next][first][last][top][bottom][index][help] */
 862 {
 863         PREPARE_SORT();         
 864 
 865         if((BF_NodeList::iSortStyle & BF_SORT_STYLE_DIRFIRST) &&
 866                 po2->iType==BF_NODE_TYPE_DIR && po1->iType!=BF_NODE_TYPE_DIR)
 867         {
 868                 return(1);
 869         }
 870         if(po2->iType!=BF_NODE_TYPE_DIR && po1->iType!=BF_NODE_TYPE_DIR){
 871                 return(po1->sType.Compare(po2->sType));
 872         }                       
 873         return 0;
 874 }
 875 
 876 int
 877 BF_NodeCollection_Sort_Size(const void * p_1, const void *p_2)    /* [previous][next][first][last][top][bottom][index][help] */
 878 {
 879         PREPARE_SORT();         
 880         
 881         if((BF_NodeList::iSortStyle & BF_SORT_STYLE_DIRFIRST) &&
 882                 po2->iType==BF_NODE_TYPE_DIR && po1->iType!=BF_NODE_TYPE_DIR)
 883         {
 884                 return(1);
 885         }
 886         if(po2->iType!=BF_NODE_TYPE_DIR && po1->iType!=BF_NODE_TYPE_DIR){
 887                 return(po1->iSize>po2->iSize);
 888         }
 889         return 0;
 890 }
 891 
 892 int
 893 BF_NodeCollection_Sort_Name(const void * p_1, const void *p_2)    /* [previous][next][first][last][top][bottom][index][help] */
 894 {
 895         PREPARE_SORT();         
 896         if((BF_NodeList::iSortStyle & BF_SORT_STYLE_DIRFIRST) &&
 897                 po2->iType==BF_NODE_TYPE_DIR && po1->iType!=BF_NODE_TYPE_DIR)
 898         {
 899                 return(1);
 900         }
 901         if(po2->iType!=BF_NODE_TYPE_DIR && po1->iType!=BF_NODE_TYPE_DIR){
 902                 return(po1->sName.ICompare(po2->sName));
 903         }
 904         if(po2->iType==BF_NODE_TYPE_DIR && po1->iType==BF_NODE_TYPE_DIR){
 905                 return(po1->sName.ICompare(po2->sName));
 906         }                       
 907         return 0;
 908 }
 909 
 910 int
 911 BF_NodeCollection_Sort_Date(const void * p_1, const void *p_2)    /* [previous][next][first][last][top][bottom][index][help] */
 912 {
 913         PREPARE_SORT();         
 914         
 915         if((BF_NodeList::iSortStyle & BF_SORT_STYLE_DIRFIRST) &&
 916                 po2->iType==BF_NODE_TYPE_DIR && po1->iType!=BF_NODE_TYPE_DIR)
 917         {
 918                 return(1);
 919         }
 920         if(po2->iType==po1->iType){
 921                 return(po1->uCreateTime>po2->uCreateTime);
 922         }                       
 923         return 0;
 924 }
 925 
 926 void                            
 927 BF_NodeCollection::Sort(BF_NodeList_SortType i_SortType)    /* [previous][next][first][last][top][bottom][index][help] */
 928 {
 929         switch(i_SortType){
 930         case BF_NODELIST_SORT_EXT:{
 931                 SortItems(BF_NodeCollection_Sort_Ext);
 932                 break;}
 933         case BF_NODELIST_SORT_TYPE:
 934                 SortItems(BF_NodeCollection_Sort_Type);
 935                 break;
 936         case BF_NODELIST_SORT_SIZE:
 937                 SortItems(BF_NodeCollection_Sort_Size);
 938                 break;
 939         case BF_NODELIST_SORT_NAME:
 940                 SortItems(BF_NodeCollection_Sort_Name);
 941                 break;
 942         case BF_NODELIST_SORT_DATE:
 943                 SortItems(BF_NodeCollection_Sort_Date);
 944                 break;
 945         default:
 946                 break;
 947         }
 948 }
 949 
 950 /*=====================================================*/       
 951 BF_NodeList::BF_NodeList(bool b_DeleteItems)
 952 :BF_NodeCollection(b_DeleteItems)
 953 {
 954         
 955 }
 956 
 957 /*=====================================================*/
 958 
 959 
 960 
 961 
 962 
 963 
 964 
 965 
 966 
 967 
 968 
 969 
 970 
 971 
 972 
 973 
 974 
 975 
 976 
 977 

/* [previous][next][first][last][top][bottom][index][help] */