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