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 <TGListTree.h>
30 #include <TGridResult.h>
31 #include <TObjArray.h>
32 #include <TObjString.h>
34 #include <TSystemDirectory.h>
35 #include <TSystemFile.h>
38 class TGDockableFrame;
47 #include "AliAlienBrowser.h"
49 ClassImp(AliAlienBrowser)
51 //___________________________________________________________________________
52 AliAlienBrowser::AliAlienBrowser(const TGWindow* p, UInt_t w, UInt_t h, TGFrame* frame, const char* classToConnect, EBrowseType type) : TGCanvas(p, w, h), fFrame(frame), fListTree(new TGListTree(this, kHorizontalFrame)), fBrowseType(type) {
56 // fListTree->Associate(this);
57 fListTree->Connect("DoubleClicked(TGListTreeItem*,Int_t)", classToConnect,frame, "OnDoubleClick(TGListTreeItem*,Int_t)");
64 //___________________________________________________________________________
65 AliAlienBrowser::~AliAlienBrowser() {
69 SetCleanup(kDeepCleanup);
72 //___________________________________________________________________________
73 void AliAlienBrowser::OnDoubleClick(TGListTreeItem* item, Int_t btn) {
74 // OnDoubleClick at the ListTree, depending on Local or Grid Browsing
76 if(fBrowseType == kLocalBrowse)
77 OnDoubleClickLocal(item,btn);
78 else if(fBrowseType == kGridBrowse)
79 OnDoubleClickGrid(item,btn);
82 //___________________________________________________________________________
83 void AliAlienBrowser::OnDoubleClickGrid(TGListTreeItem* item, Int_t btn) {
84 // OnDoubleClick at the ListTree
89 if ((btn!=kButton1) || !item)
92 if((Bool_t)item->GetUserData())
95 // use UserData to indicate that item was already browsed
96 item->SetUserData((void*)1);
100 TGridResult * result = gGrid->Ls(GetPath(item), "-F");
103 while(result->GetFileName(i)){
104 filename = result->GetFileName(i++);
106 // if the file is a directory
107 if(filename.EndsWith("/")){
108 if(filename.CompareTo("..") != 0 && filename.CompareTo(".") != 0){
109 fListTree->AddItem(item, filename.Remove(filename.Length()-1));
117 //___________________________________________________________________________
118 void AliAlienBrowser::OnDoubleClickLocal(TGListTreeItem* item, Int_t btn) {
119 // Show contents of directory.
121 if ((btn!=kButton1) || !item || (Bool_t)item->GetUserData()) return;
123 // use UserData to indicate that item was already browsed
124 item->SetUserData((void*)1);
126 TSystemDirectory dir(item->GetText(),DirName(item));
128 TList *files = dir.GetListOfFiles();
135 while ((file=(TSystemFile*)next())) {
136 fname = file->GetName();
137 if (file->IsDirectory()) {
138 if ((fname!="..") && (fname!=".")) { // skip it
139 fListTree->AddItem(item,fname);
143 fListTree->SortChildren(item);
149 //___________________________________________________________________________
150 void AliAlienBrowser::GotoDir(const char* dirToGo) {
151 // Goto the given destination dir
153 fListTree->ClearHighlighted();
155 TString destDir(dirToGo);
157 TObjArray * destDirSplit = destDir.Tokenize("/");
159 TGListTreeItem * item = fListTree->GetFirstItem();
161 if(strcmp(item->GetText(), "/") == 0){
162 OnDoubleClick(item, kButton1);
163 fListTree->OpenItem(item);
164 item = item->GetFirstChild();
166 Bool_t found = false;
168 for(Int_t i=0;i != destDirSplit->GetEntries();i++){
170 dir = ((TObjString*)destDirSplit->At(i))->GetString();
173 found = dir.CompareTo(item->GetText()) == 0 ? true : false;
177 OnDoubleClick(item, kButton1); // add subdirectories
179 fListTree->SetSelected(item);
180 fListTree->OpenItem(item);
181 fListTree->AdjustPosition(item);
185 item = item->GetNextSibling();
189 item = item->GetFirstChild();
192 // SetHsbPosition(50);
199 //___________________________________________________________________________
200 TString AliAlienBrowser::DirName(TGListTreeItem* item) const {
201 // Returns an absolute path.
203 TGListTreeItem* parent;
204 TString dirname = item->GetText();
206 while ((parent=item->GetParent())) {
207 dirname = gSystem->ConcatFileName(parent->GetText(),dirname);
214 //___________________________________________________________________________
215 void AliAlienBrowser::AddItem(TGListTreeItem* parent, const char* txt) {
217 fListTree->AddItem(parent, txt);
218 fListTree->SetSelected(fListTree->GetFirstItem());
222 //___________________________________________________________________________
223 void AliAlienBrowser::Refresh() const {
224 // Refresh the windows
226 gClient->NeedRedraw(fListTree);
229 //___________________________________________________________________________
230 const char* AliAlienBrowser::GetPath(TGListTreeItem *item) const {
231 // Get the selected item's path.
233 // TGListTreeItem *item = fListTree->GetSelected();
234 TString dirName = DirName(item);
235 TSystemDirectory dir(item->GetText(),dirName);
237 return dirName.Data();
240 //___________________________________________________________________________
241 const char* AliAlienBrowser::GetPath() {
242 // Get the selected item's path.
244 return GetPath(fListTree->GetSelected());