]>
Commit | Line | Data |
---|---|---|
1a7cb232 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | ||
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 | //----------------------------------------------------------------- | |
23 | ||
24 | ||
25 | //ROOT | |
26 | #include "TApplication.h" | |
27 | #include "TSystem.h" | |
28 | #include "TObjString.h" | |
29 | ||
30 | class TGMenu; | |
31 | class TGToolBar; | |
32 | class TG3DLine; | |
33 | class TGStatusBar; | |
34 | class TGFileDialog; | |
35 | class TGButton; | |
36 | class TGIcon; | |
37 | class TGDockableFrame; | |
38 | class TGTab; | |
39 | class TGListTree; | |
40 | ||
41 | #include "TGFrame.h" | |
42 | #include "TGListTree.h" | |
43 | ||
44 | #include "TGrid.h" | |
45 | #include "TGridResult.h" | |
46 | #include "TSystemDirectory.h" | |
47 | #include "TSystemFile.h" | |
48 | ||
49 | #include "AliAlienBrowser.h" | |
50 | ||
51 | ClassImp(AliAlienBrowser) | |
52 | ||
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) { | |
55 | // Constructor. | |
56 | ||
57 | fListTree = new TGListTree(this, kHorizontalFrame); | |
58 | // fListTree->Associate(this); | |
59 | fListTree->Connect("DoubleClicked(TGListTreeItem*,Int_t)", classToConnect,frame, "OnDoubleClick(TGListTreeItem*,Int_t)"); | |
60 | ||
61 | MapSubwindows(); | |
62 | Resize(); | |
63 | MapWindow(); | |
64 | } | |
65 | ||
66 | //___________________________________________________________________________ | |
67 | AliAlienBrowser::~AliAlienBrowser() { | |
68 | // Dtcor. | |
69 | ||
70 | DeleteWindow(); | |
71 | SetCleanup(kDeepCleanup); | |
72 | } | |
73 | ||
74 | //___________________________________________________________________________ | |
75 | void AliAlienBrowser::OnDoubleClick(TGListTreeItem* item, Int_t btn) { | |
76 | // OnDoubleClick at the ListTree, depending on Local or Grid Browsing | |
77 | ||
78 | if(fBrowseType == kLocalBrowse) | |
79 | OnDoubleClickLocal(item,btn); | |
80 | else if(fBrowseType == kGridBrowse) | |
81 | OnDoubleClickGrid(item,btn); | |
82 | } | |
83 | ||
84 | //___________________________________________________________________________ | |
85 | void AliAlienBrowser::OnDoubleClickGrid(TGListTreeItem* item, Int_t btn) { | |
86 | // OnDoubleClick at the ListTree | |
87 | ||
88 | if(!gGrid) | |
89 | return; | |
90 | ||
91 | if ((btn!=kButton1) || !item) | |
92 | return; | |
93 | ||
94 | if((Bool_t)item->GetUserData()) | |
95 | return; | |
96 | ||
97 | // use UserData to indicate that item was already browsed | |
98 | item->SetUserData((void*)1); | |
99 | ||
100 | TString filename; | |
101 | ||
102 | TGridResult * result = gGrid->Ls(GetPath(item), "-F"); | |
103 | ||
104 | int i = 0; | |
105 | while(result->GetFileName(i)){ | |
106 | filename = result->GetFileName(i++); | |
107 | ||
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)); | |
112 | } | |
113 | } | |
114 | } | |
115 | ||
116 | Refresh(); | |
117 | } | |
118 | ||
119 | //___________________________________________________________________________ | |
120 | void AliAlienBrowser::OnDoubleClickLocal(TGListTreeItem* item, Int_t btn) { | |
121 | // Show contents of directory. | |
122 | ||
123 | if ((btn!=kButton1) || !item || (Bool_t)item->GetUserData()) return; | |
124 | ||
125 | // use UserData to indicate that item was already browsed | |
126 | item->SetUserData((void*)1); | |
127 | ||
128 | TSystemDirectory dir(item->GetText(),DirName(item)); | |
129 | ||
130 | TList *files = dir.GetListOfFiles(); | |
131 | ||
132 | if (files) { | |
133 | TIter next(files); | |
134 | TSystemFile *file; | |
135 | TString fname; | |
136 | ||
137 | while ((file=(TSystemFile*)next())) { | |
138 | fname = file->GetName(); | |
139 | if (file->IsDirectory()) { | |
140 | if ((fname!="..") && (fname!=".")) { // skip it | |
141 | fListTree->AddItem(item,fname); | |
142 | } | |
143 | } | |
144 | } | |
145 | fListTree->SortChildren(item); | |
146 | delete files; | |
147 | } | |
148 | Refresh(); | |
149 | } | |
150 | ||
151 | //___________________________________________________________________________ | |
152 | void AliAlienBrowser::GotoDir(const char* dirToGo) { | |
153 | // Goto the given destination dir | |
154 | ||
155 | fListTree->ClearHighlighted(); | |
156 | ||
157 | TString destDir(dirToGo); | |
158 | ||
159 | TObjArray * destDirSplit = destDir.Tokenize("/"); | |
160 | TString dir; | |
161 | TGListTreeItem * item = fListTree->GetFirstItem(); | |
162 | ||
163 | if(strcmp(item->GetText(), "/") == 0){ | |
164 | OnDoubleClick(item, kButton1); | |
165 | fListTree->OpenItem(item); | |
166 | item = item->GetFirstChild(); | |
167 | } | |
168 | Bool_t found = false; | |
169 | ||
170 | for(Int_t i=0;i != destDirSplit->GetEntries();i++){ | |
171 | found = false; | |
172 | dir = ((TObjString*)destDirSplit->At(i))->GetString(); | |
173 | ||
174 | do { | |
175 | found = dir.CompareTo(item->GetText()) == 0 ? true : false; | |
176 | ||
177 | if(found){ | |
178 | ||
179 | OnDoubleClick(item, kButton1); // add subdirectories | |
180 | ||
181 | fListTree->SetSelected(item); | |
182 | fListTree->OpenItem(item); | |
183 | fListTree->AdjustPosition(item); | |
184 | Refresh(); | |
185 | ||
186 | }else{ | |
187 | item = item->GetNextSibling(); | |
188 | } | |
189 | }while(!found); | |
190 | ||
191 | item = item->GetFirstChild(); | |
192 | } | |
193 | ||
194 | // SetHsbPosition(50); | |
195 | ||
196 | Refresh(); | |
197 | ||
198 | delete destDirSplit; | |
199 | } | |
200 | ||
201 | //___________________________________________________________________________ | |
202 | TString AliAlienBrowser::DirName(TGListTreeItem* item) const { | |
203 | // Returns an absolute path. | |
204 | ||
205 | TGListTreeItem* parent; | |
206 | TString dirname = item->GetText(); | |
207 | ||
208 | while ((parent=item->GetParent())) { | |
209 | dirname = gSystem->ConcatFileName(parent->GetText(),dirname); | |
210 | item = parent; | |
211 | } | |
212 | ||
213 | return dirname; | |
214 | } | |
215 | ||
216 | //___________________________________________________________________________ | |
217 | void AliAlienBrowser::AddItem(TGListTreeItem* parent, const char* txt) { | |
218 | // Add item | |
219 | fListTree->AddItem(parent, txt); | |
220 | fListTree->SetSelected(fListTree->GetFirstItem()); | |
221 | Refresh(); | |
222 | } | |
223 | ||
224 | //___________________________________________________________________________ | |
225 | void AliAlienBrowser::Refresh() const { | |
226 | // Refresh the windows | |
227 | ||
228 | gClient->NeedRedraw(fListTree); | |
229 | } | |
230 | ||
231 | //___________________________________________________________________________ | |
232 | const char* AliAlienBrowser::GetPath(TGListTreeItem *item) const { | |
233 | // Get the selected item's path. | |
234 | ||
235 | // TGListTreeItem *item = fListTree->GetSelected(); | |
236 | TString dirName = DirName(item); | |
237 | TSystemDirectory dir(item->GetText(),dirName); | |
238 | ||
239 | return dirName.Data(); | |
240 | } | |
241 | ||
242 | //___________________________________________________________________________ | |
243 | const char* AliAlienBrowser::GetPath() { | |
244 | // Get the selected item's path. | |
245 | ||
246 | return GetPath(fListTree->GetSelected()); | |
247 | } |