root/BF_Roster.cpp

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

DEFINITIONS

This source file includes following definitions.
  1. BF_Roster_RemoveNode
  2. BF_Roster_RunEntry
  3. BF_Roster_RunCommand
  4. BF_Roster_RunFile
  5. BF_Roster_TraverseLink
  6. BF_Roster_LoadNodeList_Entry
  7. BF_Roster_ReloadNode
  8. BF_Roster_GetNodeInfoByRef
  9. BF_Roster_LoadNodeRef
  10. BF_Roster_LoadEntryRef
  11. BF_Roster_LoadNode
  12. BF_Roster_LoadNodeList
  13. BF_Roster_LoadNodeList_Ext
  14. BF_Roster_VolumeList_AddSpec
  15. BF_Roster_VolumeList
  16. BF_Roster_MakeDir
  17. BF_Roster_MakeDirNode
  18. BF_Roster_RemoveNode
  19. BF_Roster_RemoveNode
  20. BF_Roster_RemoveNode
  21. BF_Roster_RenameNode
  22. BF_Roster_NodeExists
  23. BF_Roster_MoveNode
  24. BF_Roster_MakeLink
  25. BF_Roster_StartMonitor_Node
  26. BF_Roster_StartMonitor_Nodes
  27. BF_Roster_StopMonitor_Node
  28. BF_Roster_StopMonitor_Nodes
  29. BF_Roster_StopAllMonitors
  30. BF_Roster_StartMonitor_Dir
  31. BF_Roster_MIME_by_Name

   1 #include <StorageKit.h>
   2 #include <sys/stat.h>
   3 #include <stdio.h>
   4 #include <Roster.h>
   5 #include <Messenger.h>
   6 #include "BF_Roster.h"
   7 
   8 #include <stdlib.h>
   9 
  10 #define BF_ROSTER_MIMETYPE_SYMLINK "application/x-vnd.Be-symlink"
  11 #define BF_ROSTER_MIMETYPE_DIRECTORY "application/x-vnd.Be-directory"
  12 
  13 
  14 bool 
  15 BF_Roster_RemoveNode(BF_Path & o_Path,BF_Node & o_Node)    /* [previous][next][first][last][top][bottom][index][help] */
  16 {
  17         BString s;
  18         s=o_Path.Path();
  19         s<<"/";
  20         s<<o_Node.sName;
  21         //      
  22         BEntry  oEntry(s.String(),true);
  23         if(B_OK==oEntry.InitCheck()){
  24                 oEntry.Remove();
  25                 return true;
  26         }       
  27         return false;
  28 }
  29 
  30 status_t
  31 BF_Roster_RunEntry(const BEntry & o_Entry,const char *pc_Args)    /* [previous][next][first][last][top][bottom][index][help] */
  32 {
  33         BRoster         oRoster;
  34         entry_ref       oRef;
  35         team_id         uTeam=0;
  36         status_t        uRes;
  37         
  38         // prepare args //
  39         BL_List         lsArg;                  
  40         if(pc_Args){
  41                 BL_String s(pc_Args),*ps;
  42                 int     i=0,i1;
  43                 
  44                 while(i<s.Length()){
  45                         i1 = s.FindFirst(' ',i);
  46                         if(i1<0){
  47                                 i1 = s.Length();
  48                                 if(i1<=1) break;
  49                         }
  50                         ps = new BL_String();
  51                         lsArg.AddItem(ps);
  52                         s.CopyInto(*ps,i,i1-i);
  53                         i = i1+1;
  54                 }               
  55         }       
  56         char            *pc1[lsArg.CountItems()>0?lsArg.CountItems():1];
  57         for(int i=0;i<lsArg.CountItems();i++){
  58                 BL_String *ps = (BL_String*)lsArg.ItemAt(i);
  59                 pc1[i] = (char*)ps->String();
  60         }
  61                         
  62         // launch entry //
  63         
  64         uRes = o_Entry.InitCheck();
  65         if(B_OK!=uRes) return uRes;
  66         uRes = o_Entry.GetRef(&oRef);
  67         if(B_OK!=uRes) return uRes;
  68         uRes = oRoster.Launch(&oRef,lsArg.CountItems(),lsArg.CountItems()>0?(&pc1[0]):NULL,&uTeam);
  69         if(uTeam>0) uRes = B_OK;
  70         return uRes;
  71 }
  72 
  73 int
  74 BF_Roster_RunCommand(const BL_String s_Command)    /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76         int iResult = system(s_Command.String());
  77         return iResult;
  78 }
  79 
  80 int 
  81 BF_Roster_RunFile(const char *pc_Path,const char *pc_File,const char *pc_Args)    /* [previous][next][first][last][top][bottom][index][help] */
  82 {       
  83         BL_String s;
  84         if(pc_Path || strlen(pc_Path)>0){
  85                 s<<pc_Path;
  86                 s<<"/";
  87         }
  88         if(pc_File){
  89                 s<<pc_File;
  90         }
  91         if(pc_Args){
  92                 s<<" ";
  93                 s<<pc_Args;
  94         }
  95         
  96         return BF_Roster_RunCommand(s);
  97         
  98 }
  99 
 100 status_t
 101 BF_Roster_TraverseLink(const char *pc_Path,BL_String & s_Name)    /* [previous][next][first][last][top][bottom][index][help] */
 102 {
 103         BEntry          oEntry(pc_Path,true);
 104 //      char            pcName[B_FILE_NAME_LENGTH];
 105         BPath           oPath;
 106         status_t        uRes;
 107                 
 108         uRes = oEntry.InitCheck();
 109         if(B_OK!=uRes) return uRes;
 110         /*uRes = oEntry.GetName(pcName);
 111         if(B_OK!=uRes) return uRes;*/
 112         uRes = oEntry.GetPath(&oPath);
 113         if(B_OK!=uRes) return uRes;
 114         s_Name = oPath.Path();
 115         /*s_Name<<pcName;*/
 116         
 117         return B_OK;    
 118 }
 119 
 120 BF_Node*
 121 BF_Roster_LoadNodeList_Entry(    /* [previous][next][first][last][top][bottom][index][help] */
 122         BEntry &oEntry,
 123         BFile &oFile,
 124         char *pc, 
 125         struct stat *st,
 126         int i_Style , 
 127         BNodeInfo       &oInfo,
 128         BF_Node* po_ToBFNode=NULL
 129         )
 130 {
 131         oEntry.GetName(pc);
 132         BF_Node* poBFNode = po_ToBFNode?po_ToBFNode:new BF_Node(pc);    
 133         /**/
 134         oEntry.GetStat(st);
 135         poBFNode->uCreateTime = st->st_ctime;
 136         poBFNode->uAccessTime = st->st_atime;   
 137         poBFNode->uModifyTime = st->st_mtime;           
 138         if(i_Style & BF_ROSTER_LOAD_PERMS){
 139                 oEntry.GetPermissions(&poBFNode->uPerms);
 140         }
 141         if(S_ISLNK(st->st_mode)) poBFNode->bLink = true;
 142         /* try to open file */
 143         status_t uRes = oFile.SetTo(&oEntry,B_READ_ONLY);       
 144         if(B_OK==uRes){
 145                 /* get mime type */
 146                 if(i_Style & BF_ROSTER_LOAD_TYPE){
 147                         oInfo.SetTo(&oFile);
 148                         oInfo.GetType(pc);
 149                         poBFNode->sType = pc;
 150                 }
 151                 /* get small icon */
 152                 if(i_Style & BF_ROSTER_LOAD_SICON){
 153                         BNodeInfo oNodeInfo(&oFile);
 154                         poBFNode->AllocSIcon();
 155                         if(B_OK!=oNodeInfo.GetIcon(poBFNode->poSIcon,B_MINI_ICON)){
 156                                 if(B_OK!=oNodeInfo.GetTrackerIcon(poBFNode->poSIcon,B_MINI_ICON)){
 157                                         DELETE(poBFNode->poSIcon);
 158                                 }               
 159                         }
 160                 }
 161                 /* get large icon */
 162                 if(i_Style & BF_ROSTER_LOAD_LICON){
 163                         BNodeInfo oNodeInfo(&oFile);
 164                         poBFNode->AllocLIcon();         
 165                         if(B_OK!=oNodeInfo.GetTrackerIcon(poBFNode->poLIcon,B_LARGE_ICON)){
 166                                 if(B_OK!=oNodeInfo.GetIcon(poBFNode->poLIcon,B_LARGE_ICON)){
 167                                         DELETE(poBFNode->poLIcon);
 168                                 }               
 169                         }
 170                 }               
 171                 /* get node_Ref */
 172                 oEntry.GetNodeRef(&poBFNode->uNodeRef);
 173                 /* get size */
 174                 oFile.GetSize(&poBFNode->iSize);
 175                 /* set type */
 176                 if(oFile.IsSymLink()) poBFNode->iType = BF_NODE_TYPE_LINK;else  
 177                 if(oFile.IsFile()) poBFNode->iType = BF_NODE_TYPE_FILE;else
 178                 if(oFile.IsDirectory()) poBFNode->iType = BF_NODE_TYPE_DIR;else                 
 179                 {};
 180         }else{  
 181                 /* try to open Dir */
 182                 BDirectory oDir(&oEntry);
 183                 uRes = oDir.InitCheck();
 184                 if(B_OK==uRes){
 185                         poBFNode->iType = BF_NODE_TYPE_DIR;                     
 186                         oEntry.GetNodeRef(&poBFNode->uNodeRef);
 187                         /* get mime type */
 188                         if(i_Style & BF_ROSTER_LOAD_TYPE){
 189                                 oInfo.SetTo(&oFile);
 190                                 oInfo.GetType(pc);
 191                                 poBFNode->sType = pc;
 192                         }
 193                         /* get small icon */
 194                         if(i_Style & BF_ROSTER_LOAD_SICON){
 195                                 BNodeInfo oNodeInfo(&oFile);
 196                                 if(!poBFNode->poSIcon) poBFNode->poSIcon = new BBitmap(BRect(0,0,15,15),B_CMAP8);
 197                                 if(B_OK!=oNodeInfo.GetTrackerIcon(poBFNode->poSIcon,B_MINI_ICON)){
 198                                         if(B_OK!=oNodeInfo.GetIcon(poBFNode->poSIcon,B_MINI_ICON)){
 199                                                 /* try to get  mime_icon */
 200                                                 BMimeType oType(BF_ROSTER_MIMETYPE_DIRECTORY);
 201                                                 uRes = oType.InitCheck();
 202                                                 if(B_OK==uRes) uRes = oType.GetIcon(poBFNode->poSIcon,B_MINI_ICON);
 203                                                 if(B_OK!=uRes)
 204                                                 {                                               
 205                                                         DELETE(poBFNode->poSIcon);                                                                              
 206                                                 }
 207                                         }               
 208                                 }
 209                         }
 210                 }else{  
 211                         /* print ERROR */
 212                         BL_String s;
 213                         BL_System_TranslError(uRes,s);
 214                         printf("GENERAL ERROR : ");
 215                         s+="\n";
 216                         printf(s.String());
 217                         /* try to init BSymLink */
 218                         BSymLink oLink(&oEntry);
 219                         if(oLink.InitCheck()==B_OK){
 220                                 BNodeInfo oNodeInfo(&oFile);
 221                                 if(!poBFNode->poSIcon) poBFNode->poSIcon = new BBitmap(BRect(0,0,15,15),B_CMAP8);
 222                                 /* attempt to get icon from Link */
 223                                 if(B_OK!=oNodeInfo.GetTrackerIcon(poBFNode->poSIcon,B_MINI_ICON)){
 224                                     /* error.....ok..attempt to get icon from Link.MimeType */
 225                                         oInfo.SetTo(&oLink);
 226                                         oInfo.GetType(pc);
 227                                         BMimeType oType(pc);
 228                                         if(B_OK!=oType.GetIcon(poBFNode->poSIcon,B_MINI_ICON)){
 229                                             /* error.....ok..attempt to get icon from Sys::MimeType */
 230                                                 if(B_OK!=oType.SetTo(BF_ROSTER_MIMETYPE_SYMLINK)) ASSERT(false);
 231                                                 if(B_OK!=oType.GetIcon(poBFNode->poSIcon,B_MINI_ICON)){
 232                                                         poBFNode->FreeSIcon();                                                  
 233                                                 }
 234                                         }
 235                                 }else{                          
 236                                 }       
 237                         }else{
 238                                 /* ups...can`t init link*/
 239                                 return NULL;
 240                         }               
 241                 }
 242         }
 243         return poBFNode;        
 244 }
 245 
 246 bool
 247 BF_Roster_ReloadNode(const char *pc_PathToNode,BF_Node*po_Node,int i_Style,bool b_PathIncludeName)    /* [previous][next][first][last][top][bottom][index][help] */
 248 {       
 249         ASSERT(po_Node);        
 250         
 251         char            pc[500];
 252         BString         s(pc_PathToNode?pc_PathToNode:"");
 253                 
 254         if(!b_PathIncludeName){         
 255                 if(pc_PathToNode && s.FindLast("/")!=s.Length()-1) s<<"/";
 256                 s<<po_Node->sName;
 257         }
 258         
 259         BEntry          oEntry(s.String());     
 260         BFile           oFile;
 261         BNodeInfo       oInfo;
 262         struct stat st;
 263         
 264         return BF_Roster_LoadNodeList_Entry(oEntry,oFile,pc,&st,i_Style,oInfo,po_Node)!=NULL;
 265 }
 266 
 267 status_t
 268 BF_Roster_GetNodeInfoByRef(BF_Node*po_Node,int i_Style)    /* [previous][next][first][last][top][bottom][index][help] */
 269 {
 270         ASSERT(po_Node);
 271 //      status_t uResult;
 272         /*
 273         BEntry oEntry(&po_Node->uEntryRef);
 274         uResult = oEntry.InitCheck();
 275         if(B_OK!=uResult) return uResult;
 276         
 277         if(i_Style & BF_NODEINFO_NAME){
 278                 char            pc[500];
 279                 oEntry.GetName(pc);
 280                 po_Node->sName = pc;
 281         }*/
 282         
 283         return B_OK;
 284 }
 285 
 286 status_t
 287 BF_Roster_LoadNodeRef(const char *pc_NodeFullPath,node_ref & u_Ref)    /* [previous][next][first][last][top][bottom][index][help] */
 288 {
 289         status_t uRes;
 290         BEntry  oEntry(pc_NodeFullPath);        
 291         uRes = oEntry.InitCheck();
 292         if(B_OK!=uRes) return uRes;
 293         return oEntry.GetNodeRef(&u_Ref);
 294 }
 295 
 296 status_t
 297 BF_Roster_LoadEntryRef(const char *pc_NodeFullPath,entry_ref & u_Ref)    /* [previous][next][first][last][top][bottom][index][help] */
 298 {
 299         status_t uRes;
 300         BEntry  oEntry(pc_NodeFullPath);        
 301         uRes = oEntry.InitCheck();
 302         if(B_OK!=uRes) return uRes;
 303         return oEntry.GetRef(&u_Ref);
 304 }
 305 
 306 
 307 BF_Node*
 308 BF_Roster_LoadNode(const char *pc_Path,const char *pc_NodeName,int i_Style)    /* [previous][next][first][last][top][bottom][index][help] */
 309 {
 310         char            pc[500];
 311         BString         s;
 312         
 313         s<<pc_Path;
 314         s<<"/";
 315         s<<pc_NodeName;
 316         
 317         BEntry          oEntry(s.String());     
 318         BFile           oFile;
 319         BNodeInfo       oInfo;
 320         struct stat st;
 321         
 322         BF_Node *poNode = BF_Roster_LoadNodeList_Entry(oEntry,oFile,pc,&st,i_Style,oInfo);      
 323         if(poNode) poNode->sName=pc_NodeName;
 324         return poNode;
 325 }
 326 
 327 bool BF_Roster_LoadNodeList(BF_Path &o_Path,BF_NodeList & lo_Node,int i_Style)    /* [previous][next][first][last][top][bottom][index][help] */
 328 {
 329         lo_Node.DeleteItems();  
 330         lo_Node.poPath = &o_Path;
 331         /**/
 332         BDirectory  oDir(o_Path.Path());
 333         /**/
 334         BEntry          oEntry;
 335         char            pc[500];
 336         BF_Node         *poBFNode;
 337         BFile           oFile;
 338         BNodeInfo       oInfo;
 339         struct stat st;
 340         /**/
 341         BL_String s;
 342         s= o_Path.Path();
 343         if((BF_ROSTER_LOAD_NODE_PARENTDIR & i_Style) && s.CountChars()>1){
 344                 poBFNode = new BF_Node("..");
 345                 poBFNode->iType = BF_NODE_TYPE_PARENTDIR;
 346                 lo_Node.AddItem(poBFNode);
 347         }
 348         /**/
 349         if(B_OK!=oDir.Rewind()) return(false);  
 350         while(B_OK==oDir.GetNextEntry(&oEntry)){
 351                 poBFNode = BF_Roster_LoadNodeList_Entry(oEntry,oFile,pc,&st,i_Style,oInfo);
 352                 if(poBFNode) lo_Node.AddItem(poBFNode);
 353                 /**/            
 354         }
 355         return(true);
 356 }
 357 
 358 bool 
 359 BF_Roster_LoadNodeList_Ext(BF_Path &o_Path,int i_Style, BView *po_View,int i_MessageIter,int i_MessageFinal)    /* [previous][next][first][last][top][bottom][index][help] */
 360 {       
 361         printf("BF_Roster_LoadNodeList_Ext started \n");
 362         ASSERT(po_View);
 363         status_t        uRes;
 364         
 365         /////// preparea message and messenger ////
 366         BMessage oMessage(i_MessageIter);
 367         BMessenger oMessenger((const BHandler*)po_View,(const BLooper*)NULL,&uRes);
 368         if(B_OK!=uRes){
 369                 BL_String s;
 370                 BL_System_TranslError(uRes,s);
 371                 s<<"\n";
 372                 printf(s.String());
 373         }                       
 374         //////////
 375         BDirectory  oDir(o_Path.Path());
 376         int iCount = oDir.CountEntries(),iIndex=0;
 377         //////////
 378         BF_NodeList *ploNode = new BF_NodeList();       
 379         //////////
 380         BEntry          oEntry;
 381         char            pc[500];
 382         BF_Node         *poBFNode;
 383         BFile           oFile;
 384         BNodeInfo       oInfo;
 385         struct stat st; 
 386         /**/
 387         BL_String s;
 388         s= o_Path.Path();
 389         if((BF_ROSTER_LOAD_NODE_PARENTDIR & i_Style) && s.CountChars()>1){
 390                 poBFNode = new BF_Node("..");
 391                 poBFNode->iType = BF_NODE_TYPE_PARENTDIR;
 392                 ploNode->AddItem(poBFNode);
 393                 oMessage.AddInt32("bf_Count",iCount);
 394                 oMessage.AddInt32("bf_Index",iIndex++);         
 395                 printf("BF_Roster_LoadNodeList_Ext: send message \n");
 396                 //oMessenger.SendMessage(&oMessage);    
 397         }
 398         ////
 399         if(B_OK==oDir.Rewind()){
 400                 while(B_OK==oDir.GetNextEntry(&oEntry)){
 401                         //
 402                         poBFNode = BF_Roster_LoadNodeList_Entry(oEntry,oFile,pc,&st,i_Style,oInfo);
 403                         if(!poBFNode) continue;
 404                         ploNode->AddItem(poBFNode);
 405                         iIndex++;
 406                         //
 407                 
 408                         printf("%i %i \n",iIndex,(int(iIndex/10))*10);
 409                         if( (int(iIndex/10))*10==iIndex){
 410                                 oMessage.MakeEmpty();
 411                                 oMessage.AddInt32("bf_Count",iCount);
 412                                 oMessage.AddInt32("bf_Index",iIndex);           
 413                                 printf("BF_Roster_LoadNodeList_Ext: send message ,%i %i \n",iIndex,(int(iIndex/10))*10);
 414                                 oMessenger.SendMessage(&oMessage);                      
 415                         }
 416                         /**/            
 417                 }
 418         }
 419         ////
 420         oMessage.MakeEmpty();
 421         oMessage.what = i_MessageFinal;
 422         oMessage.AddPointer("bf_Nodes",ploNode);
 423         oMessenger.SendMessage(&oMessage);
 424         ////
 425         return(true);
 426 }
 427 
 428 void BF_Roster_VolumeList_AddSpec(BF_NodeCollection &lo_NodeResult,int i_Styles)    /* [previous][next][first][last][top][bottom][index][help] */
 429 {       
 430         /**/
 431         int iNodeStyles = ( (i_Styles & BF_ROSTER_LOADVOLS_SICON)?BF_ROSTER_LOAD_SICON:0 )
 432                                 |       ( (i_Styles & BF_ROSTER_LOADVOLS_LICON)?BF_ROSTER_LOAD_LICON:0 );
 433                                 
 434         lo_NodeResult.AddItem( BF_Roster_LoadNode("","boot",iNodeStyles));
 435         lo_NodeResult.AddItem( BF_Roster_LoadNode("","boot/home",iNodeStyles));
 436         lo_NodeResult.AddItem( BF_Roster_LoadNode("","boot/home/Desktop",iNodeStyles));
 437 }
 438 
 439 void BF_Roster_VolumeList(BF_NodeList &lo_NodeResult,int i_Styles)    /* [previous][next][first][last][top][bottom][index][help] */
 440 {       
 441         //
 442         lo_NodeResult.DeleteItems();
 443         //      
 444         if(i_Styles & BF_ROSTER_LOADVOLS_SPEC){
 445                 BF_Roster_VolumeList_AddSpec(lo_NodeResult,i_Styles);
 446                 lo_NodeResult.AddItem(new BF_Node());
 447         }               
 448         //
 449         {
 450                 BVolumeRoster oRoster;
 451                 BVolume         oVol;
 452                 char            pc[400];
 453                 BF_Volume       *poVol;
 454                 //
 455                 char            pcBoot[400]="";
 456                 if(B_OK==oRoster.GetBootVolume(&oVol)) oVol.GetName(pcBoot);
 457                 //
 458                 oRoster.Rewind();
 459                 while(oRoster.GetNextVolume(&oVol)==B_OK){                              
 460                         //if(oVol.Capacity()==0) continue;
 461                         oVol.GetName(pc);
 462                         if(!pc || strlen(pc)==0) continue;
 463                 
 464                         // init new node 
 465                         poVol = new BF_Volume;  
 466                         poVol->sName = pc;
 467                         poVol->iType = BF_NODE_TYPE_DIR;
 468                         
 469                         // set icons 
 470                         if(i_Styles & BF_ROSTER_LOADVOLS_SICON){
 471                                 poVol->AllocSIcon();
 472                                 oVol.GetIcon(poVol->poSIcon,B_MINI_ICON);
 473                         }
 474                         if(i_Styles & BF_ROSTER_LOADVOLS_LICON){
 475                                 poVol->AllocLIcon();
 476                                 oVol.GetIcon(poVol->poSIcon,B_LARGE_ICON);
 477                         }
 478                         // check for boot_volume //
 479                         poVol->bBootVolume = poVol->sName==pcBoot;                      
 480                         lo_NodeResult.AddItem(poVol);
 481                 }
 482         }       
 483         /*
 484         if(!b_SpecVolumsFirst){
 485                 ls_Result.AddItem(new BL_String(""));
 486                 BF_Roster_VolumeList_AddSpec(ls_Result);
 487         }
 488         */
 489 }
 490 
 491 
 492 status_t
 493 BF_Roster_MakeDir(const char *pc_Name)    /* [previous][next][first][last][top][bottom][index][help] */
 494 {
 495         ASSERT(pc_Name);
 496         return create_directory(pc_Name,777);
 497 }
 498 
 499 BF_Node* 
 500 BF_Roster_MakeDirNode(BF_Path &o_Path,const char *pc_Name,int i_Style)    /* [previous][next][first][last][top][bottom][index][help] */
 501 {       
 502         BString s(o_Path.Path());
 503         if(pc_Name){
 504                 s<<"/";
 505                 s<<pc_Name;
 506         }
 507         if(B_OK==BF_Roster_MakeDir(s.String())){
 508                 if(pc_Name){
 509                         BF_Node *poNode = BF_Roster_LoadNode(o_Path.Path(),pc_Name,i_Style);
 510                         return(poNode);
 511                 }               
 512         }
 513         return(NULL);
 514 }
 515 
 516 bool
 517 BF_Roster_RemoveNode(const char *pc_Path)     /* [previous][next][first][last][top][bottom][index][help] */
 518 {
 519         ASSERT(pc_Path);
 520         
 521         BEntry oEntry;
 522         if(B_OK!=oEntry.SetTo(pc_Path) ) return false;
 523         return B_OK==oEntry.Remove();   
 524 }
 525 
 526 bool            
 527 BF_Roster_RemoveNode(BF_Path &o_Path,const char *pc_Node)    /* [previous][next][first][last][top][bottom][index][help] */
 528 {
 529         ASSERT(pc_Node);
 530         BL_String s;
 531         s<<o_Path.Path(); 
 532         s<<"/"; 
 533         s<<pc_Node;
 534         
 535         return BF_Roster_RemoveNode(s.String());
 536 }
 537 
 538 bool
 539 BF_Roster_RemoveNode(BF_Path &o_Path,BF_Node* po_Node)    /* [previous][next][first][last][top][bottom][index][help] */
 540 {
 541         ASSERT(po_Node);
 542         if(BF_NODE_TYPE_PARENTDIR==po_Node->iType) return false;
 543         BString s;
 544         s<<o_Path.Path();
 545         s<<"/";
 546         s<<po_Node->sName;
 547         
 548         return BF_Roster_RemoveNode(s.String());
 549 }
 550 
 551 
 552 status_t
 553 BF_Roster_RenameNode(const BF_Path & o_Path,BF_Node* po_Node,const char *pc_NewName)    /* [previous][next][first][last][top][bottom][index][help] */
 554 {
 555         ASSERT(po_Node && pc_NewName);
 556         if(BF_NODE_TYPE_PARENTDIR==po_Node->iType || po_Node->sName==pc_NewName) return B_OK;   
 557         BString s;
 558         s<<o_Path.Path();
 559         s<<"/";
 560         s<<po_Node->sName;
 561         //
 562         BEntry oEntry;
 563         status_t uRes=B_OK;
 564         uRes = oEntry.SetTo(s.String());
 565         if(B_OK!=uRes) return uRes;     
 566         //
 567         return oEntry.Rename(pc_NewName,false);
 568 }
 569 
 570 bool            
 571 BF_Roster_NodeExists(const char *pc_Name)    /* [previous][next][first][last][top][bottom][index][help] */
 572 {
 573         BNode oNode(pc_Name);
 574         return(oNode.InitCheck()==B_OK);
 575 }
 576 
 577 status_t
 578 BF_Roster_MoveNode(BF_Path &o_Path,BF_Node* po_Node,const char *pc_NewPath,    /* [previous][next][first][last][top][bottom][index][help] */
 579         const char *pc_NewName)
 580 {
 581         ASSERT(po_Node && pc_NewPath);
 582         if(BF_NODE_TYPE_PARENTDIR==po_Node->iType) return B_ERROR;
 583         //
 584         status_t uRes;
 585         BString s;
 586         s<<o_Path.Path();
 587         s<<"/";
 588         s<<po_Node->sName;
 589         //
 590         BEntry oEntry(s.String());
 591         uRes = oEntry.InitCheck();
 592         if(B_OK!=uRes) return uRes;
 593         //
 594         BDirectory oNewDir(pc_NewPath);
 595         uRes = oNewDir.InitCheck();
 596         if(B_OK!=uRes) return uRes;
 597         
 598         
 599         return oEntry.MoveTo(&oNewDir,pc_NewName);
 600 }
 601 
 602 status_t
 603 BF_Roster_MakeLink(const char *pc_SrcFile,const char *pc_DestFile)    /* [previous][next][first][last][top][bottom][index][help] */
 604 {
 605         ASSERT(pc_SrcFile && pc_DestFile);
 606         BDirectory oDir;        
 607         return oDir.CreateSymLink(pc_DestFile,pc_SrcFile,NULL);
 608 }
 609 
 610 
 611 void
 612 BF_Roster_StartMonitor_Node(BF_Node *po_Node,BHandler *po_Handler,int32 i_Flags)    /* [previous][next][first][last][top][bottom][index][help] */
 613 {
 614         ASSERT(po_Node);
 615         if(-1==i_Flags) i_Flags = B_WATCH_STAT | B_WATCH_NAME;
 616         watch_node(&po_Node->uNodeRef,i_Flags,po_Handler);      
 617         
 618         /*printf("Start_Monitor_Node flags=%i\n",i_Flags);*/
 619 }
 620 
 621 void
 622 BF_Roster_StartMonitor_Nodes(BF_NodeCollection &lo_Node,BHandler *po_Handler)    /* [previous][next][first][last][top][bottom][index][help] */
 623 {
 624         BF_Node *poNode;
 625         for(int i=0;i<lo_Node.CountItems();i++){
 626                 poNode = lo_Node.NodeAt(i);
 627                 if(BF_NODE_TYPE_PARENTDIR == poNode->iType) continue;
 628                 BF_Roster_StartMonitor_Node(poNode,po_Handler,B_WATCH_STAT | B_WATCH_NAME);
 629         }
 630 }
 631 
 632 void
 633 BF_Roster_StopMonitor_Node(BF_Node *po_Node,BHandler *po_Handler)    /* [previous][next][first][last][top][bottom][index][help] */
 634 {
 635         ASSERT(po_Node);
 636         if(BF_NODE_TYPE_PARENTDIR == po_Node->iType) return;
 637         BF_Roster_StartMonitor_Node(po_Node,po_Handler,B_STOP_WATCHING);        
 638 }
 639 
 640 void
 641 BF_Roster_StopMonitor_Nodes(BF_NodeCollection &lo_Node,BHandler *po_Handler)    /* [previous][next][first][last][top][bottom][index][help] */
 642 {
 643         BF_Node *poNode;
 644         for(int i=0;i<lo_Node.CountItems();i++){
 645                 poNode = lo_Node.NodeAt(i);
 646                 if(BF_NODE_TYPE_PARENTDIR == poNode->iType) continue;
 647                 BF_Roster_StartMonitor_Node(poNode,po_Handler,B_STOP_WATCHING);
 648         }
 649 }
 650 
 651 void
 652 BF_Roster_StopAllMonitors(BHandler *po_Handler)    /* [previous][next][first][last][top][bottom][index][help] */
 653 {
 654         stop_watching(po_Handler);
 655 }
 656 
 657 bool            
 658 BF_Roster_StartMonitor_Dir(BF_FilesPath &o_Path,BHandler *po_Handler)    /* [previous][next][first][last][top][bottom][index][help] */
 659 {
 660         node_ref uNodeRef(o_Path.NodeRef());
 661         status_t uRes = watch_node(&uNodeRef,
 662                         B_WATCH_DIRECTORY | B_WATCH_NAME,po_Handler);
 663 /*      printf("start dir {%s} monitoring device=%i node=%i result=%i \n",
 664                 o_Path.String(),uNodeRef.device,uNodeRef.node,(int32)uRes);     
 665         printf("start dir %s\n",uRes==B_OK?"OK":"NO");*/
 666         return B_OK==uRes;
 667         
 668 }
 669 
 670 bool
 671 BF_Roster_MIME_by_Name(BString & s_Name,BString & s_MIME)    /* [previous][next][first][last][top][bottom][index][help] */
 672 {
 673 
 674         BMessage oMessage,oMessage1; 
 675         uint32 i=0,i1=0;
 676         char *pc,*pc1;
 677         BMimeType oMime;
 678         BL_String       sExt;
 679         
 680         i = s_Name.FindLast(".");
 681         if(i>0){
 682                 s_Name.CopyInto(sExt,i+1,s_Name.Length()-i-1);
 683                 
 684                 if(B_OK!=BMimeType::GetInstalledTypes(&oMessage)) return false;
 685                 i = 0;  
 686                 
 687                 while(true){
 688                         if(oMessage.FindString("types", i++, (const char**)&pc) != B_OK) break; 
 689                         //printf("type=%s\n",pc);       
 690                 
 691                         if(B_OK!=oMime.SetTo(pc)) continue;
 692                         
 693                         if(oMime.GetFileExtensions(&oMessage1) != B_OK) continue;
 694                         
 695                         i1 = 0;                 
 696                         while(true){
 697                                 if(oMessage1.FindString("extensions", i1++, (const char**)&pc1) != B_OK) break; 
 698                                 //sprintf("> Extension:  %s \n", pc1);
 699                                 if(sExt==pc1){
 700                                         s_MIME = pc;
 701                                         return true;
 702                                 }
 703                         }                               
 704                 }                               
 705         };
 706         return false;
 707 }

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