ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TGFSContainer.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 19/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 /**************************************************************************
12 
13  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // TGFileIcon, TGFileEntry, TGFSContainer //
26 // //
27 // Utility classes used by the file selection dialog (TGFSDialog). //
28 // //
29 //////////////////////////////////////////////////////////////////////////
30 
31 #include "TGFSContainer.h"
32 #include "TGIcon.h"
33 #include "TGMsgBox.h"
34 #include "TGMimeTypes.h"
35 #include "TRegexp.h"
36 #include "TList.h"
37 #include "TSystem.h"
38 #include "TGDNDManager.h"
39 #include "TBufferFile.h"
40 #include "Riostream.h"
41 #include "TRemoteObject.h"
42 #include "TImage.h"
43 #include <time.h>
44 
47 
48 class TViewUpdateTimer : public TTimer {
49 
50 private:
51  TGFileContainer *fContainer;
52 
53 public:
54  TViewUpdateTimer(TGFileContainer *t, Long_t ms) : TTimer(ms, kTRUE) { fContainer = t; }
55  Bool_t Notify();
56 };
57 
58 
59 
60 class TGFileIcon : public TGIcon {
61 
62 protected:
63  const TGPicture *fLpic; // icon picture
64 
65  virtual void DoRedraw();
66 
67 public:
68  TGFileIcon(const TGWindow *p, const TGPicture *pic, const TGPicture *lpic,
69  UInt_t options = kChildFrame, Pixel_t back = GetWhitePixel()) :
70  TGIcon(p, pic, 0, 0, options, back) { fLpic = lpic; }
71 };
72 
73 
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 
77 class TGFSFrameElement : public TGFrameElement {
78 public:
79  TGFileContainer *fContainer; // file container
80 
81  Bool_t IsSortable() const { return kTRUE; }
82  Int_t Compare(const TObject *obj) const;
83 };
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Sort frame elements in file selection list view container.
87 
88 Int_t TGFSFrameElement::Compare(const TObject *obj) const
89 {
90  Int_t type1, type2;
91 
92  TGFileItem *f1 = (TGFileItem *) fFrame;
93  TGFileItem *f2 = (TGFileItem *) ((TGFrameElement *) obj)->fFrame;
94 
95  switch (fContainer->fSortType) {
96  default:
97  case kSortByName:
98  //--- this is not exactly what I want...
99  type1 = f1->GetType();
100  type2 = f2->GetType();
101 
102  //--- use posix macros
103  if (R_ISDIR(type1)) type1 = 1;
104  else type1 = 6;
105 
106  if (R_ISDIR(type2)) type2 = 1;
107  else type2 = 6;
108 
109  if (type1 < type2) return -1;
110  if (type1 > type2) return 1;
111  return strcmp(f1->GetItemName()->GetString(),
112  f2->GetItemName()->GetString());
113 
114  case kSortByOwner:
115  if (f1->GetUid() != f2->GetUid()) {
116  if (f1->GetUid() < f2->GetUid())
117  return -1;
118  else
119  return +1;
120  }
121 
122  // else sort by name
123  type1 = f1->GetType();
124  type2 = f2->GetType();
125 
126  //--- use posix macros
127  if (R_ISDIR(type1)) type1 = 1;
128  else type1 = 6;
129 
130  if (R_ISDIR(type2)) type2 = 1;
131  else type2 = 6;
132 
133  if (type1 < type2) return -1;
134  if (type1 > type2) return 1;
135  return strcmp(f1->GetItemName()->GetString(),
136  f2->GetItemName()->GetString());
137 
138  case kSortByGroup:
139  if (f1->GetGid() != f2->GetGid()) {
140  if (f1->GetGid() < f2->GetGid())
141  return -1;
142  else
143  return +1;
144  }
145 
146  // else sort by name
147  type1 = f1->GetType();
148  type2 = f2->GetType();
149 
150  //--- use posix macros
151  if (R_ISDIR(type1)) type1 = 1;
152  else type1 = 6;
153 
154  if (R_ISDIR(type2)) type2 = 1;
155  else type2 = 6;
156 
157  if (type1 < type2) return -1;
158  if (type1 > type2) return 1;
159  return strcmp(f1->GetItemName()->GetString(),
160  f2->GetItemName()->GetString());
161 
162  case kSortByType:
163  //--- this is not exactly what I want...
164 
165  type1 = f1->GetType();
166  type2 = f2->GetType();
167 
168  //--- use posix macros
169 
170  if (R_ISDIR(type1)) type1 = 1;
171  else if (R_ISLNK(type1)) type1 = 2;
172  else if (R_ISSOCK(type1)) type1 = 3;
173  else if (R_ISFIFO(type1)) type1 = 4;
174  else if (R_ISREG(type1) && (type1 & kS_IXUSR)) type1 = 5;
175  else type1 = 6;
176 
177  if (R_ISDIR(type2)) type2 = 1;
178  else if (R_ISLNK(type2)) type2 = 2;
179  else if (R_ISSOCK(type2)) type2 = 3;
180  else if (R_ISFIFO(type2)) type2 = 4;
181  else if (R_ISREG(type2) && (type2 & kS_IXUSR)) type2 = 5;
182  else type2 = 6;
183 
184  if (type1 < type2) return -1;
185  if (type1 > type2) return 1;
186  return strcmp(f1->GetItemName()->GetString(),
187  f2->GetItemName()->GetString());
188 
189  case kSortBySize:
190  if (f1->GetSize() < f2->GetSize()) return -1;
191  if (f1->GetSize() > f2->GetSize()) return 1;
192  return strcmp(f1->GetItemName()->GetString(),
193  f2->GetItemName()->GetString());
194 
195  case kSortByDate:
196  time_t loctimeF1 = (time_t) f1->GetModTime();
197  // coverity[returned_null]
198  struct tm tmF1 = *localtime(&loctimeF1);
199 
200  time_t loctimeF2 = (time_t) f2->GetModTime();
201  // coverity[returned_null]
202  struct tm tmF2 = *localtime(&loctimeF2);
203 
204  if ( tmF1.tm_year != tmF2.tm_year )
205  return (tmF1.tm_year < tmF2.tm_year) ? +1 : -1;
206  else if ( tmF1.tm_mon != tmF2.tm_mon )
207  return (tmF1.tm_mon < tmF2.tm_mon) ? +1 : -1;
208  else if ( tmF1.tm_mday != tmF2.tm_mday )
209  return (tmF1.tm_mday < tmF2.tm_mday) ? +1 : -1;
210  else if ( tmF1.tm_hour != tmF2.tm_hour )
211  return (tmF1.tm_hour < tmF2.tm_hour) ? +1 : -1;
212  else if ( tmF1.tm_min != tmF2.tm_min )
213  return (tmF1.tm_min < tmF2.tm_min) ? +1 : -1;
214  else if ( tmF1.tm_sec != tmF2.tm_sec )
215  return (tmF1.tm_sec < tmF2.tm_sec) ? +1 : -1;
216  else
217  return 0;
218  }
219 }
220 
221 
222 ////////////////////////////////////////////////////////////////////////////////
223 /// Reset the timer.
224 
226 {
227  fContainer->HandleTimer(0);
228  Reset();
229  return kFALSE;
230 }
231 
232 
233 ////////////////////////////////////////////////////////////////////////////////
234 /// Draw icon.
235 
236 void TGFileIcon::DoRedraw()
237 {
239  if (fLpic) fLpic->Draw(fId, GetBckgndGC()(), 0, 0);
240 }
241 
242 
243 ////////////////////////////////////////////////////////////////////////////////
244 /// Create a list view item.
245 
247  const TGPicture *bpic, const TGPicture *blpic,
248  const TGPicture *spic, const TGPicture *slpic,
249  TGString *name, Int_t type, Long64_t size, Int_t uid,
250  Int_t gid, Long_t modtime, EListViewMode viewMode,
251  UInt_t options, ULong_t back) :
252  TGLVEntry(p, bpic, spic, name, 0, viewMode, options, back)
253 {
254  FileStat_t buf;
255 
256  buf.fMode = type;
257  buf.fSize = size;
258  buf.fUid = uid;
259  buf.fGid = gid;
260  buf.fMtime = modtime;
261  buf.fIsLink = (blpic != 0); // FIXME: hack...
262 
263  Init(blpic, slpic, buf, viewMode);
264 }
265 
266 ////////////////////////////////////////////////////////////////////////////////
267 /// Create a list view item.
268 
270  const TGPicture *bpic, const TGPicture *blpic,
271  const TGPicture *spic, const TGPicture *slpic,
272  TGString *name, FileStat_t &stat, EListViewMode viewMode,
273  UInt_t options, ULong_t back) :
274  TGLVEntry(p, bpic, spic, name, 0, viewMode, options, back)
275 {
276  Init(blpic, slpic, stat, viewMode);
277 }
278 
279 ////////////////////////////////////////////////////////////////////////////////
280 /// Common initializer for file list view item.
281 
282 void TGFileItem::Init(const TGPicture *blpic, const TGPicture *slpic,
283  FileStat_t &stat, EListViewMode viewMode)
284 {
285  char tmp[256];
286  Long64_t fsize, bsize;
287 
288  fBuf = 0;
289  fDNDData.fData = 0;
290  fDNDData.fDataLength = 0;
291  fDNDData.fDataType = 0;
292  fLcurrent =
293  fBlpic = blpic;
294  fSlpic = slpic;
295 
296  fViewMode = (EListViewMode) -1;
297  SetViewMode(viewMode);
298 
299  fType = stat.fMode;
300  fSize = stat.fSize;
301  fUid = stat.fUid;
302  fGid = stat.fGid;
303  fModTime = stat.fMtime;
304  fIsLink = stat.fIsLink;
305 
306  fSubnames = new TGString* [6];
307 
308  // file type
309  snprintf(tmp, sizeof(tmp), "%c%c%c%c%c%c%c%c%c%c",
310  (fIsLink ?
311  'l' :
312  R_ISREG(fType) ?
313  '-' :
314  (R_ISDIR(fType) ?
315  'd' :
316  (R_ISCHR(fType) ?
317  'c' :
318  (R_ISBLK(fType) ?
319  'b' :
320  (R_ISFIFO(fType) ?
321  'p' :
322  (R_ISSOCK(fType) ?
323  's' : '?' )))))),
324  ((fType & kS_IRUSR) ? 'r' : '-'),
325  ((fType & kS_IWUSR) ? 'w' : '-'),
326  ((fType & kS_ISUID) ? 's' : ((fType & kS_IXUSR) ? 'x' : '-')),
327  ((fType & kS_IRGRP) ? 'r' : '-'),
328  ((fType & kS_IWGRP) ? 'w' : '-'),
329  ((fType & kS_ISGID) ? 's' : ((fType & kS_IXGRP) ? 'x' : '-')),
330  ((fType & kS_IROTH) ? 'r' : '-'),
331  ((fType & kS_IWOTH) ? 'w' : '-'),
332  ((fType & kS_ISVTX) ? 't' : ((fType & kS_IXOTH) ? 'x' : '-')));
333  fSubnames[0] = new TGString(tmp);
334 
335  // file size
336  fsize = bsize = fSize;
337  if (fsize > 1024) {
338  fsize /= 1024;
339  if (fsize > 1024) {
340  // 3.7MB is more informative than just 3MB
341  snprintf(tmp, sizeof(tmp), "%lld.%lldM", fsize/1024, (fsize%1024)/103);
342  } else {
343  snprintf(tmp, sizeof(tmp), "%lld.%lldK", bsize/1024, (bsize%1024)/103);
344  }
345  } else {
346  snprintf(tmp, sizeof(tmp), "%lld", bsize);
347  }
348  fSubnames[1] = new TGString(tmp);
349 
350  {
351  struct UserGroup_t *user_group;
352 
353  user_group = gSystem->GetUserInfo(fUid);
354  if (user_group) {
355  fSubnames[2] = new TGString(user_group->fUser);
356  fSubnames[3] = new TGString(user_group->fGroup);
357  delete user_group;
358  } else {
359  fSubnames[2] = new TGString(TString::Format("%d", fUid));
360  fSubnames[3] = new TGString(TString::Format("%d", fGid));
361  }
362  }
363 
364  struct tm *newtime;
365  time_t loctime = (time_t) fModTime;
366  newtime = localtime(&loctime);
367  if (newtime) {
368  snprintf(tmp, sizeof(tmp), "%d-%02d-%02d %02d:%02d", newtime->tm_year + 1900,
369  newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour,
370  newtime->tm_min);
371  fSubnames[4] = new TGString(tmp);
372  }
373  else
374  fSubnames[4] = new TGString("1901-01-01 00:00");
375 
376  fSubnames[5] = 0;
377 
378  int i;
379  for (i = 0; fSubnames[i] != 0; ++i)
380  ;
381  fCtw = new int[i+1];
382  fCtw[i] = 0;
383  for (i = 0; fSubnames[i] != 0; ++i)
384  fCtw[i] = gVirtualX->TextWidth(fFontStruct, fSubnames[i]->GetString(),
385  fSubnames[i]->GetLength());
386 
387  SetWindowName();
388 }
389 
390 ////////////////////////////////////////////////////////////////////////////////
391 /// Destructor.
392 
394 {
395  delete fBuf;
396 }
397 
398 ////////////////////////////////////////////////////////////////////////////////
399 /// Set container item view mode.
400 
402 {
403  TGLVEntry::SetViewMode(viewMode);
404 
405  if (viewMode == kLVLargeIcons)
406  fLcurrent = fBlpic;
407  else
408  fLcurrent = fSlpic;
409 
410  if (fClient) fClient->NeedRedraw(this);
411 }
412 
413 ////////////////////////////////////////////////////////////////////////////////
414 /// Draw list view container item.
415 
417 {
418  int ix, iy;
419 
421  if (!fLcurrent) return;
422 
423  if (fViewMode == kLVLargeIcons) {
424  ix = (fWidth - fLcurrent->GetWidth()) >> 1;
425  iy = 0;
426  } else {
427  ix = 0;
428  iy = (fHeight - fLcurrent->GetHeight()) >> 1;
429  }
430 
431  fLcurrent->Draw(fId, fNormGC, ix, iy);
432 }
433 
434 
435 ////////////////////////////////////////////////////////////////////////////////
436 /// Create a list view container which will hold the contents of
437 /// the current directory.
438 
440  UInt_t options, ULong_t back) :
441  TGLVContainer(p, w, h, options, back)
442 {
444  fFilter = 0;
445  fMtime = 0;
447  fRefresh = new TViewUpdateTimer(this, 1000);
451  fCleanups = new TList;
452 
453  fFolder_s = fClient->GetPicture("folder_s.xpm");
454  fFolder_t = fClient->GetPicture("folder_t.xpm");
455  fApp_s = fClient->GetPicture("app_s.xpm");
456  fApp_t = fClient->GetPicture("app_t.xpm");
457  fDoc_s = fClient->GetPicture("doc_s.xpm");
458  fDoc_t = fClient->GetPicture("doc_t.xpm");
459  fSlink_s = fClient->GetPicture("slink_s.xpm");
460  fSlink_t = fClient->GetPicture("slink_t.xpm");
461 
462  if (!fFolder_s || !fFolder_t ||
463  !fApp_s || !fApp_t ||
464  !fDoc_s || !fDoc_t ||
465  !fSlink_s || !fSlink_t)
466  Error("TGFileContainer", "required pixmap(s) missing\n");
467 
468  SetWindowName();
469 }
470 
471 ////////////////////////////////////////////////////////////////////////////////
472 /// Create a list view container which will hold the contents of
473 /// the current directory.
474 
476  TGLVContainer(p,options, back)
477 {
479  fFilter = 0;
480  fMtime = 0;
482  fRefresh = new TViewUpdateTimer(this, 1000);
486  fCleanups = new TList;
487 
488  fFolder_s = fClient->GetPicture("folder_s.xpm");
489  fFolder_t = fClient->GetPicture("folder_t.xpm");
490  fApp_s = fClient->GetPicture("app_s.xpm");
491  fApp_t = fClient->GetPicture("app_t.xpm");
492  fDoc_s = fClient->GetPicture("doc_s.xpm");
493  fDoc_t = fClient->GetPicture("doc_t.xpm");
494  fSlink_s = fClient->GetPicture("slink_s.xpm");
495  fSlink_t = fClient->GetPicture("slink_t.xpm");
496 
497  if (!fFolder_s || !fFolder_t ||
498  !fApp_s || !fApp_t ||
499  !fDoc_s || !fDoc_t ||
500  !fSlink_s || !fSlink_t)
501  Error("TGFileContainer", "required pixmap(s) missing\n");
502 
503  SetWindowName();
504 }
505 
506 ////////////////////////////////////////////////////////////////////////////////
507 /// Delete list view file container.
508 
510 {
511  if (fRefresh) delete fRefresh;
512  if (fFilter) delete fFilter;
521  if (fCleanups) {
522  TGPicture *pic;
523  TIter nextp(fCleanups);
524  while ((pic = (TGPicture *)nextp())) {
526  }
527  fCleanups->Clear();
528  delete fCleanups;
529  }
530 }
531 
532 ////////////////////////////////////////////////////////////////////////////////
533 /// Add frame to the composite frame.
534 
536 {
537  TGFSFrameElement *nw;
538 
539  nw = new TGFSFrameElement;
540  nw->fFrame = f;
541  nw->fLayout = l ? l : fgDefaultHints;
542  nw->fState = 1;
543  nw->fContainer = this;
544  fList->Add(nw);
545 }
546 
547 ////////////////////////////////////////////////////////////////////////////////
548 /// Refresh container contents. Check every 5 seconds to see if the
549 /// directory modification date has changed.
550 
552 {
553  FileStat_t sbuf;
554 
555  if (gSystem->GetPathInfo(fDirectory, sbuf) == 0)
556  if (fMtime != (ULong_t)sbuf.fMtime) DisplayDirectory();
557 
558  return kTRUE;
559 }
560 
561 ////////////////////////////////////////////////////////////////////////////////
562 /// Set file selection filter.
563 
564 void TGFileContainer::SetFilter(const char *filter)
565 {
566  if (fFilter) delete fFilter;
567  fFilter = new TRegexp(filter, kTRUE);
568 }
569 
570 ////////////////////////////////////////////////////////////////////////////////
571 /// Sort file system list view container according to sortType.
572 
574 {
575  fSortType = sortType;
576 
577  fList->Sort();
578 
579  TGCanvas *canvas = (TGCanvas *) this->GetParent()->GetParent();
580  canvas->Layout();
581 }
582 
583 ////////////////////////////////////////////////////////////////////////////////
584 /// Determine the file picture for the given file type.
585 
587  const TGPicture **lpic, Int_t file_type, Bool_t is_link,
588  const char *name, Bool_t /*small*/)
589 {
590  static TString cached_ext;
591  static const TGPicture *cached_spic = 0;
592  static const TGPicture *cached_lpic = 0;
593  const char *ext = name ? strrchr(name, '.') : 0;
594  *pic = 0;
595  *lpic = 0;
596 
597  if (fCachePictures && ext && cached_spic && cached_lpic && (cached_ext == ext)) {
598  *pic = cached_spic;
599  *lpic = cached_lpic;
600  if (!is_link) return;
601  }
602 
603  if (R_ISREG(file_type)) {
604  TString fname(name);
605  if (is_link && fname.EndsWith(".lnk")) {
606  fname.Remove(fname.Length()-4);
607  }
608  *pic = fClient->GetMimeTypeList()->GetIcon(fname.Data(), kTRUE);
609  *lpic = fClient->GetMimeTypeList()->GetIcon(fname.Data(), kFALSE);
610 
611  if (*pic) {
612  if (!*lpic) *lpic = *pic;
613  if (ext) {
614  cached_ext = ext;
615  cached_spic = *pic;
616  cached_lpic = *lpic;
617  if (!is_link) return;
618  }
619  }
620  } else {
621  *pic = 0;
622  }
623 
624  if (*pic == 0) {
625  *pic = fDoc_t;
626  *lpic = fDoc_s;
627 
628  if (R_ISREG(file_type) && (file_type) & kS_IXUSR) {
629  *pic = fApp_t;
630  *lpic = fApp_s;
631  }
632  if (R_ISDIR(file_type)) {
633  *pic = fFolder_t;
634  *lpic = fFolder_s;
635  }
636  }
637  if (is_link) {
638  TImage *img1, *img2;
639  if (*pic && *lpic) {
640  TString lnk_name;
641  img1 = TImage::Create();
642  if (img1) {
643  img1->SetImage(((const TGPicture *)*pic)->GetPicture(),
644  ((const TGPicture *)*pic)->GetMask());
645  img2 = TImage::Open("slink_t.xpm");
646  if (img2) img1->Merge(img2);
647  lnk_name = ((const TGPicture *)*pic)->GetName();
648  lnk_name.Prepend("lnk_");
649  *pic = fClient->GetPicturePool()->GetPicture(lnk_name.Data(),
650  img1->GetPixmap(), img1->GetMask());
651  fCleanups->Add(((TObject *)*pic));
652  if (img2) delete img2; delete img1;
653  }
654  img1 = TImage::Create();
655  if (img1) {
656  img1->SetImage(((const TGPicture *)*lpic)->GetPicture(),
657  ((const TGPicture *)*lpic)->GetMask());
658  img2 = TImage::Open("slink_s.xpm");
659  if (img2) img1->Merge(img2);
660  lnk_name = ((const TGPicture *)*lpic)->GetName();
661  lnk_name.Prepend("lnk_");
662  *lpic = fClient->GetPicturePool()->GetPicture(lnk_name.Data(),
663  img1->GetPixmap(), img1->GetMask());
664  fCleanups->Add(((TObject *)*lpic));
665  if (img2) delete img2; delete img1;
666  }
667  }
668  else {
669  *pic = fSlink_t;
670  *lpic = fSlink_s;
671  }
672  }
673 
674  cached_lpic = 0;
675  cached_spic = 0;
676  cached_ext = "";
677 }
678 
679 ////////////////////////////////////////////////////////////////////////////////
680 /// Change current directory.
681 
682 void TGFileContainer::ChangeDirectory(const char *path)
683 {
684  TString savdir = gSystem->WorkingDirectory();
685  gSystem->ChangeDirectory(fDirectory.Data()); // so path of ".." will work
688  gSystem->ChangeDirectory(savdir.Data());
690  }
691 }
692 
693 ////////////////////////////////////////////////////////////////////////////////
694 /// Display the contents of the current directory in the container.
695 /// This can be used to refresh the contents of the window.
696 
698 {
699  RemoveAll();
700  CreateFileList();
701 
702  // This automatically calls layout
703  Sort(fSortType);
704 
705  // Make TGExplorerMainFrame display total objects in status bar
707  fTotal, fSelected);
708 
709  MapSubwindows();
710 }
711 
712 ////////////////////////////////////////////////////////////////////////////////
713 /// This function creates the file list from current dir.
714 
716 {
717  TString savdir = gSystem->WorkingDirectory();
718  if (!gSystem->ChangeDirectory(fDirectory.Data())) return;
719 
720  FileStat_t sbuf;
721  if (gSystem->GetPathInfo(".", sbuf) == 0)
722  fMtime = sbuf.fMtime;
723 
724  void *dirp;
725  if ((dirp = gSystem->OpenDirectory(".")) == 0) {
726  gSystem->ChangeDirectory(savdir.Data());
727  return;
728  }
729 
730  const char *name;
731  while ((name = gSystem->GetDirEntry(dirp)) != 0 && fDisplayStat) {
732  if (strcmp(name, ".") && strcmp(name, ".."))
733  AddFile(name);
735  }
736  gSystem->FreeDirectory(dirp);
737 
738  gSystem->ChangeDirectory(savdir.Data());
739 }
740 
741 ////////////////////////////////////////////////////////////////////////////////
742 /// Add file in container.
743 
745  const TGPicture *ilpic)
746 {
748  TGFileItem *item = 0;
749  const TGPicture *spic, *slpic;
750  TGPicture *pic, *lpic;
751 
752  FileStat_t sbuf;
753 
754  if (gSystem->GetPathInfo(name, sbuf)) {
755  if (sbuf.fIsLink) {
756  Info("AddFile", "Broken symlink of %s.", name);
757  } else {
758  TString msg;
759  msg.Form("Can't read file attributes of \"%s\": %s.",
760  name, gSystem->GetError());
762  "Error", msg.Data(), kMBIconStop, kMBOk);
763  }
764  return item;
765  }
766 
767  filename = name;
768  if (R_ISDIR(sbuf.fMode) || fFilter == 0 ||
769  (fFilter && filename.Index(*fFilter) != kNPOS)) {
770 
771  if (ipic && ilpic) { // dynamic icons
772  spic = ipic;
773  slpic = ilpic;
774  } else {
775  GetFilePictures(&spic, &slpic, sbuf.fMode, sbuf.fIsLink, name, kTRUE);
776  }
777 
778  pic = (TGPicture*)spic; pic->AddReference();
779  lpic = (TGPicture*)slpic; lpic->AddReference();
780 
781  item = new TGFileItem(this, lpic, slpic, spic, pic,
782  new TGString(gSystem->BaseName(name)),
783  sbuf, fViewMode);
784  AddItem(item);
785  }
786 
787  return item;
788 }
789 
790 ////////////////////////////////////////////////////////////////////////////////
791 /// Add remote file in container.
792 
794  const TGPicture *ilpic)
795 {
797  TGFileItem *item = 0;
798  const TGPicture *spic, *slpic;
799  TGPicture *pic, *lpic;
800 
801  FileStat_t sbuf;
802 
803  TRemoteObject *robj = (TRemoteObject *)obj;
804 
805  robj->GetFileStat(&sbuf);
806  filename = robj->GetName();
807 
808  if (R_ISDIR(sbuf.fMode) || fFilter == 0 ||
809  (fFilter && filename.Index(*fFilter) != kNPOS)) {
810 
811  if (ipic && ilpic) { // dynamic icons
812  spic = ipic;
813  slpic = ilpic;
814  } else {
815  GetFilePictures(&spic, &slpic, sbuf.fMode, sbuf.fIsLink, filename, kTRUE);
816  }
817 
818  pic = (TGPicture*)spic; pic->AddReference();
819  lpic = (TGPicture*)slpic; lpic->AddReference();
820 
821  item = new TGFileItem(this, lpic, slpic, spic, pic, new TGString(filename),
822  sbuf, fViewMode);
823  AddItem(item);
824  }
825  return item;
826 }
827 
828 ////////////////////////////////////////////////////////////////////////////////
829 /// stop refresh timer
830 
832 {
833  if (fRefresh) delete fRefresh;
834  fRefresh = 0;
835 }
836 
837 ////////////////////////////////////////////////////////////////////////////////
838 /// start refreshing
839 
841 {
842  fRefresh = new TViewUpdateTimer(this, msec);
844 }
845 
846 ////////////////////////////////////////////////////////////////////////////////
847 /// Save a file container widget as a C++ statement(s) on output stream out.
848 
849 void TGFileContainer::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
850 {
851  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
852 
853  char quote = '"';
854  out << std::endl << " // container frame" << std::endl;
855  out << " TGFileContainer *";
856 
858  out << GetName() << " = new TGFileContainer(" << GetCanvas()->GetName();
859  } else {
860  out << GetName() << " = new TGFileContainer(" << fParent->GetName();
861  out << "," << GetWidth() << "," << GetHeight();
862  }
863 
865  if (GetOptions() == kSunkenFrame) {
866  out <<");" << std::endl;
867  } else {
868  out << "," << GetOptionString() <<");" << std::endl;
869  }
870  } else {
871  out << "," << GetOptionString() << ",ucolor);" << std::endl;
872  }
873  if (option && strstr(option, "keep_names"))
874  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
875  out << " " << GetCanvas()->GetName() << "->SetContainer("
876  << GetName() << ");" << std::endl;
877  out << " " << GetName() << "->DisplayDirectory();" << std::endl;
878  out << " " << GetName() << "->AddFile("<< quote << ".." << quote << ");" << std::endl;
879  out << " " << GetName() << "->StopRefreshTimer();" << std::endl;
880 }
TGString ** fSubnames
Definition: TGListView.h:68
Bool_t R_ISSOCK(Int_t mode)
Definition: TSystem.h:132
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:912
const TGWindow * fParent
Definition: TGWindow.h:43
void Init(const TGPicture *blpic, const TGPicture *slpic, FileStat_t &stat, EListViewMode viewMode)
Common initializer for file list view item.
Bool_t R_ISCHR(Int_t mode)
Definition: TSystem.h:127
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:420
Int_t fDataLength
Definition: TGDNDManager.h:80
Bool_t R_ISLNK(Int_t mode)
Definition: TSystem.h:130
TDNDData fDNDData
Definition: TGFSContainer.h:69
TGPicturePool * GetPicturePool() const
Definition: TGClient.h:143
Int_t fSelected
Definition: TGCanvas.h:61
long long Long64_t
Definition: RtypesCore.h:69
virtual void RemoveAll()
Remove all items from the container.
Definition: TGCanvas.cxx:638
const TGPicture * fFolder_s
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
const TGPicture * fLcurrent
Definition: TGFSContainer.h:62
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
void StopRefreshTimer()
stop refresh timer
const TGWindow * GetParent() const
Definition: TGWindow.h:87
const TGPicture * fDoc_t
Ssiz_t Length() const
Definition: TString.h:390
const char Option_t
Definition: RtypesCore.h:62
const TGPicture * GetIcon(const char *filename, Bool_t small_icon)
Return icon belonging to mime type of filename.
Int_t fUid
Definition: TSystem.h:139
void StartRefreshTimer(ULong_t msec=1000)
start refreshing
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1311
TH1 * h
Definition: legend2.C:5
Long_t GetModTime() const
Definition: TGFSContainer.h:99
FontStruct_t fFontStruct
Definition: TGListView.h:83
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:691
UInt_t GetWidth() const
Definition: TGFrame.h:287
TString fGroup
Definition: TSystem.h:153
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
const TGPicture * fSlpic
Definition: TGFSContainer.h:61
Regular expression class.
Definition: TRegexp.h:35
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:856
EListViewMode
Definition: TGListView.h:45
static const char * filename()
const TGPicture * fBlpic
Definition: TGFSContainer.h:60
Basic string class.
Definition: TString.h:137
Pixel_t fBackground
Definition: TGFrame.h:158
int Int_t
Definition: RtypesCore.h:41
Int_t GetGid() const
bool Bool_t
Definition: RtypesCore.h:59
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual TGFileItem * AddRemoteFile(TObject *obj, const TGPicture *ipic=0, const TGPicture *ilpic=0)
Add remote file in container.
Long_t fMtime
Definition: TSystem.h:142
An abstract interface to image processing library.
Definition: TImage.h:45
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:188
TString & Prepend(const char *cs)
Definition: TString.h:604
UInt_t GetHeight() const
Definition: TGFrame.h:288
const TGWindow * fMsgWindow
Definition: TGCanvas.h:54
virtual void SetViewMode(EListViewMode viewMode)
Set container item view mode.
Long64_t fSize
Definition: TSystem.h:141
Long64_t GetSize() const
Definition: TGFSContainer.h:98
EFSSortMode fSortType
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:132
TGString * GetItemName() const
Definition: TGListView.h:112
TFile * f
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:129
virtual Pixmap_t GetPixmap()
Definition: TImage.h:251
TRegexp * fFilter
Int_t fMode
Definition: TSystem.h:138
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:771
void Draw(Option_t *="")
Default Draw method for all objects.
Definition: TGPicture.h:67
friend class TGFSFrameElement
const char * Data() const
Definition: TString.h:349
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:847
const TGPicture * fFolder_t
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session...
Definition: TRemoteObject.h:42
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2321
ULong_t Pixel_t
Definition: GuiTypes.h:41
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:665
virtual void ChangeDirectory(const char *path)
Change current directory.
Int_t bsize[]
Definition: SparseFit4.cxx:31
virtual UInt_t GetOptions() const
Definition: TGFrame.h:260
void CreateFileList()
This function creates the file list from current dir.
void Class()
Definition: Class.C:29
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:306
UInt_t GetWidth() const
Definition: TGPicture.h:73
Definition: TGIcon.h:34
if(pyself &&pyself!=Py_None)
void * fData
Definition: TGDNDManager.h:79
Int_t GetUid() const
void FreePicture(const TGPicture *pic)
Remove picture from cache if nobody is using it anymore.
Definition: TGPicture.cxx:276
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:627
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition: TSystem.cxx:1511
virtual void Sort(EFSSortMode sortType)
Sort file system list view container according to sortType.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual Bool_t HandleTimer(TTimer *t)
Refresh container contents.
Int_t fGid
Definition: TSystem.h:140
char * out
Definition: TBase64.cxx:29
virtual Bool_t IsSortable() const
Definition: TObject.h:139
A doubly linked list.
Definition: TList.h:47
TGFileContainer(const TGWindow *p=0, UInt_t w=1, UInt_t h=1, UInt_t options=kSunkenFrame, Pixel_t back=GetDefaultFrameBackground())
Create a list view container which will hold the contents of the current directory.
const TGPicture * fApp_t
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame.
TThread * t[5]
Definition: threadsh1.C:13
TString fUser
Definition: TSystem.h:152
TList * fList
Definition: TGFrame.h:367
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2207
Bool_t fIsLink
Definition: TSystem.h:143
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
Long_t fModTime
Definition: TGFSContainer.h:66
UInt_t GetHeight() const
Definition: TGPicture.h:74
static TGLayoutHints * fgDefaultHints
Definition: TGFrame.h:372
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2308
TViewUpdateTimer * fRefresh
TGCanvas * GetCanvas() const
Definition: TGCanvas.h:111
virtual TGFileItem * AddFile(const char *name, const TGPicture *pic=0, const TGPicture *lpic=0)
Add file in container.
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t GetType() const
Definition: TGFSContainer.h:97
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:79
EFSSortMode
Definition: TGFSContainer.h:36
tuple w
Definition: qtexample.py:51
TLine * l
Definition: textangle.C:4
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual void AddItem(TGLVEntry *item)
Definition: TGListView.h:231
void Reset(Detail::TBranchProxy *x)
Atom_t fDataType
Definition: TGDNDManager.h:77
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:839
#define gVirtualX
Definition: TVirtualX.h:362
const TGPicture * fSlink_s
static TImage * Create()
UInt_t fWidth
Definition: TGFrame.h:150
TGMimeTypes * GetMimeTypeList() const
Definition: TGClient.h:163
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:133
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a file container widget as a C++ statement(s) on output stream out.
Bool_t Notify()
Definition: TTimer.cxx:65
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
long Long_t
Definition: RtypesCore.h:50
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:232
TBufferFile * fBuf
Definition: TGFSContainer.h:68
#define ClassImp(name)
Definition: Rtypes.h:279
TViewUpdateTimer(TGFileContainer *t, Long_t ms)
EListViewMode fViewMode
Definition: TGListView.h:76
virtual Pixmap_t GetMask()
Definition: TImage.h:252
Int_t GetLength() const
Definition: TGString.h:43
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:287
int type
Definition: TGX11.cxx:120
const TGPicture * fSlink_t
unsigned long ULong_t
Definition: RtypesCore.h:51
UInt_t fHeight
Definition: TGFrame.h:151
Int_t * fCtw
Definition: TGListView.h:71
virtual void SetViewMode(EListViewMode viewMode)
Set the view mode for this list item.
Definition: TGListView.cxx:271
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:349
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
Bool_t fIsLink
Definition: TGFSContainer.h:65
Handle_t fId
Definition: TGObject.h:40
virtual void DoRedraw()
Redraw picture.
Definition: TGIcon.cxx:127
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void Layout()
Create layout for canvas.
Definition: TGCanvas.cxx:2226
Bool_t R_ISDIR(Int_t mode)
Definition: TSystem.h:126
virtual void SetFilter(const char *filter)
Set file selection filter.
virtual ~TGFileItem()
Destructor.
virtual void Add(TObject *obj)
Definition: TList.h:81
const Ssiz_t kNPOS
Definition: Rtypes.h:115
GContext_t fNormGC
Definition: TGListView.h:82
void AddReference()
Definition: TRefCnt.h:42
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:475
TGClient * fClient
Definition: TGObject.h:41
Int_t Compare(const void *item1, const void *item2)
Long64_t fSize
Definition: TGFSContainer.h:67
virtual void DoRedraw()
Draw list view container item.
EListViewMode fViewMode
Definition: TGListView.h:210
virtual void GetFilePictures(const TGPicture **pic, const TGPicture **lpic, Int_t file_type, Bool_t is_link, const char *ext, Bool_t small)
Determine the file picture for the given file type.
Int_t fTotal
Definition: TGCanvas.h:60
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
virtual void DisplayDirectory()
Display the contents of the current directory in the container.
virtual Int_t Compare(const TObject *obj) const
Compare abstract method.
Definition: TObject.cxx:218
Bool_t R_ISBLK(Int_t mode)
Definition: TSystem.h:128
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:830
virtual void DoRedraw()
Redraw list view item.
Definition: TGListView.cxx:314
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition: TGFrame.cxx:2433
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:110
const char * GetString() const
Definition: TGString.h:44
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1191
Bool_t GetFileStat(FileStat_t *sbuf)
Get remote file status.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
virtual ~TGFileContainer()
Delete list view file container.
const Bool_t kTRUE
Definition: Rtypes.h:91
Bool_t R_ISFIFO(Int_t mode)
Definition: TSystem.h:131
TObject * obj
const TGPicture * fDoc_s
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2460
const TGPicture * fApp_s
virtual const char * GetError()
Return system error string.
Definition: TSystem.cxx:254
TGFileItem(const TGWindow *p=0, const TGPicture *bpic=0, const TGPicture *blpic=0, const TGPicture *spic=0, const TGPicture *slpic=0, TGString *name=0, Int_t type=0, Long64_t size=1, Int_t uid=0, Int_t gid=0, Long_t modtime=0, EListViewMode viewMode=kLVList, UInt_t options=kVerticalFrame, Pixel_t back=GetWhitePixel())
Create a list view item.
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:118
Definition: TGMsgBox.h:52