Logo ROOT   6.12/07
Reference Guide
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 
225 Bool_t TViewUpdateTimer::Notify()
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;
653  delete img1;
654  }
655  img1 = TImage::Create();
656  if (img1) {
657  img1->SetImage(((const TGPicture *)*lpic)->GetPicture(),
658  ((const TGPicture *)*lpic)->GetMask());
659  img2 = TImage::Open("slink_s.xpm");
660  if (img2) img1->Merge(img2);
661  lnk_name = ((const TGPicture *)*lpic)->GetName();
662  lnk_name.Prepend("lnk_");
663  *lpic = fClient->GetPicturePool()->GetPicture(lnk_name.Data(),
664  img1->GetPixmap(), img1->GetMask());
665  fCleanups->Add(((TObject *)*lpic));
666  if (img2) delete img2;
667  delete img1;
668  }
669  }
670  else {
671  *pic = fSlink_t;
672  *lpic = fSlink_s;
673  }
674  }
675 
676  cached_lpic = 0;
677  cached_spic = 0;
678  cached_ext = "";
679 }
680 
681 ////////////////////////////////////////////////////////////////////////////////
682 /// Change current directory.
683 
684 void TGFileContainer::ChangeDirectory(const char *path)
685 {
686  TString savdir = gSystem->WorkingDirectory();
687  gSystem->ChangeDirectory(fDirectory.Data()); // so path of ".." will work
688  char *exppath = gSystem->ExpandPathName(path);
689  if (gSystem->ChangeDirectory(exppath)) {
691  gSystem->ChangeDirectory(savdir.Data());
693  }
694  delete[] exppath;
695 }
696 
697 ////////////////////////////////////////////////////////////////////////////////
698 /// Display the contents of the current directory in the container.
699 /// This can be used to refresh the contents of the window.
700 
702 {
703  RemoveAll();
704  CreateFileList();
705 
706  // This automatically calls layout
707  Sort(fSortType);
708 
709  // Make TGExplorerMainFrame display total objects in status bar
711  fTotal, fSelected);
712 
713  MapSubwindows();
714 }
715 
716 ////////////////////////////////////////////////////////////////////////////////
717 /// This function creates the file list from current dir.
718 
720 {
721  TString savdir = gSystem->WorkingDirectory();
722  if (!gSystem->ChangeDirectory(fDirectory.Data())) return;
723 
724  FileStat_t sbuf;
725  if (gSystem->GetPathInfo(".", sbuf) == 0)
726  fMtime = sbuf.fMtime;
727 
728  void *dirp;
729  if ((dirp = gSystem->OpenDirectory(".")) == 0) {
730  gSystem->ChangeDirectory(savdir.Data());
731  return;
732  }
733 
734  const char *name;
735  while ((name = gSystem->GetDirEntry(dirp)) != 0 && fDisplayStat) {
736  if (strcmp(name, ".") && strcmp(name, ".."))
737  AddFile(name);
739  }
740  gSystem->FreeDirectory(dirp);
741 
742  gSystem->ChangeDirectory(savdir.Data());
743 }
744 
745 ////////////////////////////////////////////////////////////////////////////////
746 /// Add file in container.
747 
749  const TGPicture *ilpic)
750 {
751  TString filename;
752  TGFileItem *item = 0;
753  const TGPicture *spic, *slpic;
754  TGPicture *pic, *lpic;
755 
756  FileStat_t sbuf;
757 
758  if (gSystem->GetPathInfo(name, sbuf)) {
759  if (sbuf.fIsLink) {
760  Info("AddFile", "Broken symlink of %s.", name);
761  } else {
762  TString msg;
763  msg.Form("Can't read file attributes of \"%s\": %s.",
764  name, gSystem->GetError());
766  "Error", msg.Data(), kMBIconStop, kMBOk);
767  }
768  return item;
769  }
770 
771  filename = name;
772  if (R_ISDIR(sbuf.fMode) || fFilter == 0 ||
773  (fFilter && filename.Index(*fFilter) != kNPOS)) {
774 
775  if (ipic && ilpic) { // dynamic icons
776  spic = ipic;
777  slpic = ilpic;
778  } else {
779  GetFilePictures(&spic, &slpic, sbuf.fMode, sbuf.fIsLink, name, kTRUE);
780  }
781 
782  pic = (TGPicture*)spic; pic->AddReference();
783  lpic = (TGPicture*)slpic; lpic->AddReference();
784 
785  item = new TGFileItem(this, lpic, slpic, spic, pic,
786  new TGString(gSystem->BaseName(name)),
787  sbuf, fViewMode);
788  AddItem(item);
789  }
790 
791  return item;
792 }
793 
794 ////////////////////////////////////////////////////////////////////////////////
795 /// Add remote file in container.
796 
798  const TGPicture *ilpic)
799 {
800  TString filename;
801  TGFileItem *item = 0;
802  const TGPicture *spic, *slpic;
803  TGPicture *pic, *lpic;
804 
805  FileStat_t sbuf;
806 
807  TRemoteObject *robj = (TRemoteObject *)obj;
808 
809  robj->GetFileStat(&sbuf);
810  filename = robj->GetName();
811 
812  if (R_ISDIR(sbuf.fMode) || fFilter == 0 ||
813  (fFilter && filename.Index(*fFilter) != kNPOS)) {
814 
815  if (ipic && ilpic) { // dynamic icons
816  spic = ipic;
817  slpic = ilpic;
818  } else {
819  GetFilePictures(&spic, &slpic, sbuf.fMode, sbuf.fIsLink, filename, kTRUE);
820  }
821 
822  pic = (TGPicture*)spic; pic->AddReference();
823  lpic = (TGPicture*)slpic; lpic->AddReference();
824 
825  item = new TGFileItem(this, lpic, slpic, spic, pic, new TGString(filename),
826  sbuf, fViewMode);
827  AddItem(item);
828  }
829  return item;
830 }
831 
832 ////////////////////////////////////////////////////////////////////////////////
833 /// stop refresh timer
834 
836 {
837  if (fRefresh) delete fRefresh;
838  fRefresh = 0;
839 }
840 
841 ////////////////////////////////////////////////////////////////////////////////
842 /// start refreshing
843 
845 {
846  fRefresh = new TViewUpdateTimer(this, msec);
848 }
849 
850 ////////////////////////////////////////////////////////////////////////////////
851 /// Save a file container widget as a C++ statement(s) on output stream out.
852 
853 void TGFileContainer::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
854 {
855  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
856 
857  char quote = '"';
858  out << std::endl << " // container frame" << std::endl;
859  out << " TGFileContainer *";
860 
862  out << GetName() << " = new TGFileContainer(" << GetCanvas()->GetName();
863  } else {
864  out << GetName() << " = new TGFileContainer(" << fParent->GetName();
865  out << "," << GetWidth() << "," << GetHeight();
866  }
867 
869  if (GetOptions() == kSunkenFrame) {
870  out <<");" << std::endl;
871  } else {
872  out << "," << GetOptionString() <<");" << std::endl;
873  }
874  } else {
875  out << "," << GetOptionString() << ",ucolor);" << std::endl;
876  }
877  if (option && strstr(option, "keep_names"))
878  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
879  out << " " << GetCanvas()->GetName() << "->SetContainer("
880  << GetName() << ");" << std::endl;
881  out << " " << GetName() << "->DisplayDirectory();" << std::endl;
882  out << " " << GetName() << "->AddFile("<< quote << ".." << quote << ");" << std::endl;
883  out << " " << GetName() << "->StopRefreshTimer();" << std::endl;
884 }
Int_t GetType() const
Definition: TGFSContainer.h:91
TGString ** fSubnames
Definition: TGListView.h:62
Bool_t R_ISSOCK(Int_t mode)
Definition: TSystem.h:122
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:932
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
const TGWindow * fParent
Definition: TGWindow.h:37
Int_t GetGid() const
Definition: TGFSContainer.h:95
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:117
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:424
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
Int_t fDataLength
Definition: TGDNDManager.h:78
Bool_t R_ISLNK(Int_t mode)
Definition: TSystem.h:120
TDNDData fDNDData
Definition: TGFSContainer.h:63
virtual UInt_t GetOptions() const
Definition: TGFrame.h:244
Int_t fSelected
Definition: TGCanvas.h:59
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:869
const TGPicture * fLcurrent
Definition: TGFSContainer.h:56
void StopRefreshTimer()
stop refresh timer
const TGPicture * fDoc_t
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.
const Ssiz_t kNPOS
Definition: RtypesCore.h:111
Int_t fUid
Definition: TSystem.h:129
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:1374
UInt_t GetHeight() const
Definition: TGFrame.h:272
TH1 * h
Definition: legend2.C:5
FontStruct_t fFontStruct
Definition: TGListView.h:77
TString fGroup
Definition: TSystem.h:143
const TGPicture * fSlpic
Definition: TGFSContainer.h:55
Regular expression class.
Definition: TRegexp.h:31
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:860
EListViewMode
Definition: TGListView.h:39
const TGPicture * fBlpic
Definition: TGFSContainer.h:54
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:585
Basic string class.
Definition: TString.h:125
Pixel_t fBackground
Definition: TGFrame.h:142
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
virtual TGFileItem * AddRemoteFile(TObject *obj, const TGPicture *ipic=0, const TGPicture *ilpic=0)
Add remote file in container.
Long_t fMtime
Definition: TSystem.h:132
An abstract interface to image processing library.
Definition: TImage.h:29
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:172
TString & Prepend(const char *cs)
Definition: TString.h:607
UInt_t GetWidth() const
Definition: TGFrame.h:271
const TGWindow * fMsgWindow
Definition: TGCanvas.h:52
virtual void SetViewMode(EListViewMode viewMode)
Set container item view mode.
Long64_t fSize
Definition: TSystem.h:131
UInt_t GetHeight() const
Definition: TGPicture.h:64
EFSSortMode fSortType
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:116
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:119
virtual Pixmap_t GetPixmap()
Definition: TImage.h:235
TRegexp * fFilter
Int_t fMode
Definition: TSystem.h:128
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:933
void Draw(Option_t *="")
Default Draw method for all objects.
Definition: TGPicture.h:57
friend class TGFSFrameElement
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:851
const TGPicture * fFolder_t
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session...
Definition: TRemoteObject.h:36
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:2365
TGPicturePool * GetPicturePool() const
Definition: TGClient.h:135
ULong_t Pixel_t
Definition: GuiTypes.h:39
void Class()
Definition: Class.C:29
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:665
virtual void ChangeDirectory(const char *path)
Change current directory.
void CreateFileList()
This function creates the file list from current dir.
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:306
Definition: TGIcon.h:30
void * fData
Definition: TGDNDManager.h:77
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2231
void FreePicture(const TGPicture *pic)
Remove picture from cache if nobody is using it anymore.
Definition: TGPicture.cxx:277
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:627
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:133
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition: TSystem.cxx:1574
virtual void Sort(EFSSortMode sortType)
Sort file system list view container according to sortType.
virtual Bool_t HandleTimer(TTimer *t)
Refresh container contents.
Int_t fGid
Definition: TSystem.h:130
TGMimeTypes * GetMimeTypeList() const
Definition: TGClient.h:155
virtual Bool_t Notify()
Notify when timer times out.
Definition: TTimer.cxx:143
A doubly linked list.
Definition: TList.h:44
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.
TString fUser
Definition: TSystem.h:142
TList * fList
Definition: TGFrame.h:351
Bool_t fIsLink
Definition: TSystem.h:133
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
Long_t fModTime
Definition: TGFSContainer.h:60
TGCanvas * GetCanvas() const
Definition: TGCanvas.h:109
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
Long_t GetModTime() const
Definition: TGFSContainer.h:93
static TGLayoutHints * fgDefaultHints
Definition: TGFrame.h:356
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2343
TViewUpdateTimer * fRefresh
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
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
Ssiz_t Length() const
Definition: TString.h:386
Int_t GetUid() const
Definition: TGFSContainer.h:94
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
EFSSortMode
Definition: TGFSContainer.h:30
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
virtual void AddItem(TGLVEntry *item)
Definition: TGListView.h:225
void Reset(Detail::TBranchProxy *x)
Atom_t fDataType
Definition: TGDNDManager.h:75
static constexpr double ms
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:843
#define gVirtualX
Definition: TVirtualX.h:350
const TGPicture * fSlink_s
UInt_t fWidth
Definition: TGFrame.h:134
const char * GetString() const
Definition: TGString.h:40
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a file container widget as a C++ statement(s) on output stream out.
TString & Remove(Ssiz_t pos)
Definition: TString.h:619
long Long_t
Definition: RtypesCore.h:50
TBufferFile * fBuf
Definition: TGFSContainer.h:62
#define ClassImp(name)
Definition: Rtypes.h:359
EListViewMode fViewMode
Definition: TGListView.h:70
virtual Pixmap_t GetMask()
Definition: TImage.h:236
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 GetWidth() const
Definition: TGPicture.h:63
UInt_t fHeight
Definition: TGFrame.h:135
Int_t * fCtw
Definition: TGListView.h:65
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:399
const TGWindow * GetParent() const
Definition: TGWindow.h:85
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
Bool_t fIsLink
Definition: TGFSContainer.h:59
Handle_t fId
Definition: TGObject.h:36
virtual void DoRedraw()
Redraw picture.
Definition: TGIcon.cxx:127
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Layout()
Create layout for canvas.
Definition: TGCanvas.cxx:2226
Bool_t R_ISDIR(Int_t mode)
Definition: TSystem.h:116
virtual void SetFilter(const char *filter)
Set file selection filter.
virtual ~TGFileItem()
Destructor.
virtual void Add(TObject *obj)
Definition: TList.h:87
auto * l
Definition: textangle.C:4
GContext_t fNormGC
Definition: TGListView.h:76
void AddReference()
Definition: TRefCnt.h:40
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:479
TGClient * fClient
Definition: TGObject.h:37
Int_t Compare(const void *item1, const void *item2)
Long64_t fSize
Definition: TGFSContainer.h:61
virtual void DoRedraw()
Draw list view container item.
Long64_t GetSize() const
Definition: TGFSContainer.h:92
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:232
TF1 * f1
Definition: legend1.C:11
EListViewMode fViewMode
Definition: TGListView.h:204
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:58
#define snprintf
Definition: civetweb.c:822
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.
Bool_t R_ISBLK(Int_t mode)
Definition: TSystem.h:118
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:834
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
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2460
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:110
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1254
static TImage * Create()
Create an image.
Definition: TImage.cxx:36
TGString * GetItemName() const
Definition: TGListView.h:106
Bool_t GetFileStat(FileStat_t *sbuf)
Get remote file status.
virtual ~TGFileContainer()
Delete list view file container.
Bool_t R_ISFIFO(Int_t mode)
Definition: TSystem.h:121
const Bool_t kTRUE
Definition: RtypesCore.h:87
Int_t GetLength() const
Definition: TGString.h:39
const TGPicture * fDoc_s
const TGPicture * fApp_s
virtual const char * GetError()
Return system error string.
Definition: TSystem.cxx:258
char name[80]
Definition: TGX11.cxx:109
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:44
const char * Data() const
Definition: TString.h:345