1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-----------------------------------------------------------------
19 // AliAlienBrowser class
20 // The class that deals with the AliEn browser of the GUI
21 // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
22 //-----------------------------------------------------------------
26 #include "TApplication.h"
28 #include "TObjString.h"
37 class TGDockableFrame;
42 #include "TGListTree.h"
45 #include "TGridResult.h"
46 #include "TSystemDirectory.h"
47 #include "TSystemFile.h"
49 #include "AliAlienBrowser.h"
51 ClassImp(AliAlienBrowser)
53 //___________________________________________________________________________
54 AliAlienBrowser::AliAlienBrowser(const TGWindow* p, UInt_t w, UInt_t h, TGFrame* frame, const char* classToConnect, EBrowseType type) : TGCanvas(p, w, h), fFrame(frame), fBrowseType(type) {
57 fListTree = new TGListTree(this, kHorizontalFrame);
58 // fListTree->Associate(this);
59 fListTree->Connect("DoubleClicked(TGListTreeItem*,Int_t)", classToConnect,frame, "OnDoubleClick(TGListTreeItem*,Int_t)");
66 //___________________________________________________________________________
67 AliAlienBrowser::~AliAlienBrowser() {
71 SetCleanup(kDeepCleanup);
74 //___________________________________________________________________________
75 void AliAlienBrowser::OnDoubleClick(TGListTreeItem* item, Int_t btn) {
76 // OnDoubleClick at the ListTree, depending on Local or Grid Browsing
78 if(fBrowseType == kLocalBrowse)
79 OnDoubleClickLocal(item,btn);
80 else if(fBrowseType == kGridBrowse)
81 OnDoubleClickGrid(item,btn);
84 //___________________________________________________________________________
85 void AliAlienBrowser::OnDoubleClickGrid(TGListTreeItem* item, Int_t btn) {
86 // OnDoubleClick at the ListTree
91 if ((btn!=kButton1) || !item)
94 if((Bool_t)item->GetUserData())
97 // use UserData to indicate that item was already browsed
98 item->SetUserData((void*)1);
102 TGridResult * result = gGrid->Ls(GetPath(item), "-F");
105 while(result->GetFileName(i)){
106 filename = result->GetFileName(i++);
108 // if the file is a directory
109 if(filename.EndsWith("/")){
110 if(filename.CompareTo("..") != 0 && filename.CompareTo(".") != 0){
111 fListTree->AddItem(item, filename.Remove(filename.Length()-1));
119 //___________________________________________________________________________
120 void AliAlienBrowser::OnDoubleClickLocal(TGListTreeItem* item, Int_t btn) {
121 // Show contents of directory.
123 if ((btn!=kButton1) || !item || (Bool_t)item->GetUserData()) return;
125 // use UserData to indicate that item was already browsed
126 item->SetUserData((void*)1);
128 TSystemDirectory dir(item->GetText(),DirName(item));
130 TList *files = dir.GetListOfFiles();
137 while ((file=(TSystemFile*)next())) {
138 fname = file->GetName();
139 if (file->IsDirectory()) {
140 if ((fname!="..") && (fname!=".")) { // skip it
141 fListTree->AddItem(item,fname);
145 fListTree->SortChildren(item);
151 //___________________________________________________________________________
152 void AliAlienBrowser::GotoDir(const char* dirToGo) {
153 // Goto the given destination dir
155 fListTree->ClearHighlighted();
157 TString destDir(dirToGo);
159 TObjArray * destDirSplit = destDir.Tokenize("/");
161 TGListTreeItem * item = fListTree->GetFirstItem();
163 if(strcmp(item->GetText(), "/") == 0){
164 OnDoubleClick(item, kButton1);
165 fListTree->OpenItem(item);
166 item = item->GetFirstChild();
168 Bool_t found = false;
170 for(Int_t i=0;i != destDirSplit->GetEntries();i++){
172 dir = ((TObjString*)destDirSplit->At(i))->GetString();
175 found = dir.CompareTo(item->GetText()) == 0 ? true : false;
179 OnDoubleClick(item, kButton1); // add subdirectories
181 fListTree->SetSelected(item);
182 fListTree->OpenItem(item);
183 fListTree->AdjustPosition(item);
187 item = item->GetNextSibling();
191 item = item->GetFirstChild();
194 // SetHsbPosition(50);
201 //___________________________________________________________________________
202 TString AliAlienBrowser::DirName(TGListTreeItem* item) const {
203 // Returns an absolute path.
205 TGListTreeItem* parent;
206 TString dirname = item->GetText();
208 while ((parent=item->GetParent())) {
209 dirname = gSystem->ConcatFileName(parent->GetText(),dirname);
216 //___________________________________________________________________________
217 void AliAlienBrowser::AddItem(TGListTreeItem* parent, const char* txt) {
219 fListTree->AddItem(parent, txt);
220 fListTree->SetSelected(fListTree->GetFirstItem());
224 //___________________________________________________________________________
225 void AliAlienBrowser::Refresh() const {
226 // Refresh the windows
228 gClient->NeedRedraw(fListTree);
231 //___________________________________________________________________________
232 const char* AliAlienBrowser::GetPath(TGListTreeItem *item) const {
233 // Get the selected item's path.
235 // TGListTreeItem *item = fListTree->GetSelected();
236 TString dirName = DirName(item);
237 TSystemDirectory dir(item->GetText(),dirName);
239 return dirName.Data();
242 //___________________________________________________________________________
243 const char* AliAlienBrowser::GetPath() {
244 // Get the selected item's path.
246 return GetPath(fListTree->GetSelected());