Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/** \class TGFileIcon
25 \ingroup guiwidgets
26
27Utility class used by the file selection dialog (TGFSDialog).
28
29*/
30
31/** \class TGFileEntry
32 \ingroup guiwidgets
33
34Utility class used by the file selection dialog (TGFSDialog).
35
36*/
37
38/** \class TGFSContainer
39 \ingroup guiwidgets
40
41Utility class used by the file selection dialog (TGFSDialog).
42
43*/
44
45#include "TGFSContainer.h"
46#include "TGIcon.h"
47#include "TGMsgBox.h"
48#include "TGMimeTypes.h"
49#include "TRegexp.h"
50#include "TList.h"
51#include "TSystem.h"
52#include "TVirtualX.h"
53#include "TGDNDManager.h"
54#include "TRemoteObject.h"
55#include "TBufferFile.h"
56#include "TImage.h"
57#include "TASUtils.h"
58
59#include <cstdio>
60#include <ctime>
61#include <cstdlib>
62#include <iostream>
63
64
65class TViewUpdateTimer : public TTimer {
66
67private:
69
70public:
72 Bool_t Notify() override;
73};
74
75
76
77class TGFileIcon : public TGIcon {
78
79protected:
80 const TGPicture *fLpic; // icon picture
81
82 void DoRedraw() override;
83
84public:
85 TGFileIcon(const TGWindow *p, const TGPicture *pic, const TGPicture *lpic,
86 UInt_t options = kChildFrame, Pixel_t back = GetWhitePixel()) :
87 TGIcon(p, pic, 0, 0, options, back) { fLpic = lpic; }
88};
89
90
91
92////////////////////////////////////////////////////////////////////////////////
93
95public:
96 TGFileContainer *fContainer; // file container
97
98 Bool_t IsSortable() const override { return kTRUE; }
99 Int_t Compare(const TObject *obj) const override;
100};
101
102////////////////////////////////////////////////////////////////////////////////
103/// Sort frame elements in file selection list view container.
104
106{
107 Int_t type1, type2;
108
110 TGFileItem *f2 = (TGFileItem *) ((TGFrameElement *) obj)->fFrame;
111
112 switch (fContainer->fSortType) {
113 default:
114 case kSortByName:
115 //--- this is not exactly what I want...
116 type1 = f1->GetType();
117 type2 = f2->GetType();
118
119 //--- use posix macros
120 if (R_ISDIR(type1)) type1 = 1;
121 else type1 = 6;
122
123 if (R_ISDIR(type2)) type2 = 1;
124 else type2 = 6;
125
126 if (type1 < type2) return -1;
127 if (type1 > type2) return 1;
128 return strcmp(f1->GetItemName()->GetString(),
129 f2->GetItemName()->GetString());
130
131 case kSortByOwner:
132 if (f1->GetUid() != f2->GetUid()) {
133 if (f1->GetUid() < f2->GetUid())
134 return -1;
135 else
136 return +1;
137 }
138
139 // else sort by name
140 type1 = f1->GetType();
141 type2 = f2->GetType();
142
143 //--- use posix macros
144 if (R_ISDIR(type1)) type1 = 1;
145 else type1 = 6;
146
147 if (R_ISDIR(type2)) type2 = 1;
148 else type2 = 6;
149
150 if (type1 < type2) return -1;
151 if (type1 > type2) return 1;
152 return strcmp(f1->GetItemName()->GetString(),
153 f2->GetItemName()->GetString());
154
155 case kSortByGroup:
156 if (f1->GetGid() != f2->GetGid()) {
157 if (f1->GetGid() < f2->GetGid())
158 return -1;
159 else
160 return +1;
161 }
162
163 // else sort by name
164 type1 = f1->GetType();
165 type2 = f2->GetType();
166
167 //--- use posix macros
168 if (R_ISDIR(type1)) type1 = 1;
169 else type1 = 6;
170
171 if (R_ISDIR(type2)) type2 = 1;
172 else type2 = 6;
173
174 if (type1 < type2) return -1;
175 if (type1 > type2) return 1;
176 return strcmp(f1->GetItemName()->GetString(),
177 f2->GetItemName()->GetString());
178
179 case kSortByType:
180 //--- this is not exactly what I want...
181
182 type1 = f1->GetType();
183 type2 = f2->GetType();
184
185 //--- use posix macros
186
187 if (R_ISDIR(type1)) type1 = 1;
188 else if (R_ISLNK(type1)) type1 = 2;
189 else if (R_ISSOCK(type1)) type1 = 3;
190 else if (R_ISFIFO(type1)) type1 = 4;
191 else if (R_ISREG(type1) && (type1 & kS_IXUSR)) type1 = 5;
192 else type1 = 6;
193
194 if (R_ISDIR(type2)) type2 = 1;
195 else if (R_ISLNK(type2)) type2 = 2;
196 else if (R_ISSOCK(type2)) type2 = 3;
197 else if (R_ISFIFO(type2)) type2 = 4;
198 else if (R_ISREG(type2) && (type2 & kS_IXUSR)) type2 = 5;
199 else type2 = 6;
200
201 if (type1 < type2) return -1;
202 if (type1 > type2) return 1;
203 return strcmp(f1->GetItemName()->GetString(),
204 f2->GetItemName()->GetString());
205
206 case kSortBySize:
207 if (f1->GetSize() < f2->GetSize()) return -1;
208 if (f1->GetSize() > f2->GetSize()) return 1;
209 return strcmp(f1->GetItemName()->GetString(),
210 f2->GetItemName()->GetString());
211
212 case kSortByDate:
213 time_t loctimeF1 = (time_t) f1->GetModTime();
214 // coverity[returned_null]
215 struct tm tmF1 = *localtime(&loctimeF1);
216
217 time_t loctimeF2 = (time_t) f2->GetModTime();
218 // coverity[returned_null]
219 struct tm tmF2 = *localtime(&loctimeF2);
220
221 if ( tmF1.tm_year != tmF2.tm_year )
222 return (tmF1.tm_year < tmF2.tm_year) ? +1 : -1;
223 else if ( tmF1.tm_mon != tmF2.tm_mon )
224 return (tmF1.tm_mon < tmF2.tm_mon) ? +1 : -1;
225 else if ( tmF1.tm_mday != tmF2.tm_mday )
226 return (tmF1.tm_mday < tmF2.tm_mday) ? +1 : -1;
227 else if ( tmF1.tm_hour != tmF2.tm_hour )
228 return (tmF1.tm_hour < tmF2.tm_hour) ? +1 : -1;
229 else if ( tmF1.tm_min != tmF2.tm_min )
230 return (tmF1.tm_min < tmF2.tm_min) ? +1 : -1;
231 else if ( tmF1.tm_sec != tmF2.tm_sec )
232 return (tmF1.tm_sec < tmF2.tm_sec) ? +1 : -1;
233 else
234 return 0;
235 }
236}
237
238
239////////////////////////////////////////////////////////////////////////////////
240/// Reset the timer.
241
243{
245 Reset();
246 return kFALSE;
247}
248
249
250////////////////////////////////////////////////////////////////////////////////
251/// Draw icon.
252
254{
256 if (fLpic) fLpic->Draw(fId, GetBckgndGC()(), 0, 0);
257}
258
259
260////////////////////////////////////////////////////////////////////////////////
261/// Create a list view item.
262
264 const TGPicture *bpic, const TGPicture *blpic,
265 const TGPicture *spic, const TGPicture *slpic,
267 Int_t gid, Long_t modtime, EListViewMode viewMode,
268 UInt_t options, Pixel_t back) :
269 TGLVEntry(p, bpic, spic, name, 0, viewMode, options, back)
270{
271 FileStat_t buf;
272
273 buf.fMode = type;
274 buf.fSize = size;
275 buf.fUid = uid;
276 buf.fGid = gid;
277 buf.fMtime = modtime;
278 buf.fIsLink = (blpic != 0); // FIXME: hack...
279
280 Init(blpic, slpic, buf, viewMode);
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Create a list view item.
285
287 const TGPicture *bpic, const TGPicture *blpic,
288 const TGPicture *spic, const TGPicture *slpic,
289 TGString *name, FileStat_t &stat, EListViewMode viewMode,
290 UInt_t options, Pixel_t back) :
291 TGLVEntry(p, bpic, spic, name, 0, viewMode, options, back)
292{
293 Init(blpic, slpic, stat, viewMode);
294}
295
296////////////////////////////////////////////////////////////////////////////////
297/// Common initializer for file list view item.
298
299void TGFileItem::Init(const TGPicture *blpic, const TGPicture *slpic,
300 FileStat_t &stat, EListViewMode viewMode)
301{
302 char tmp[256];
303 Long64_t fsize, bsize;
304
305 fBuf = 0;
306 fDNDData.fData = 0;
309 fLcurrent =
310 fBlpic = blpic;
311 fSlpic = slpic;
312
314 SetViewMode(viewMode);
315
316 fType = stat.fMode;
317 fSize = stat.fSize;
318 fUid = stat.fUid;
319 fGid = stat.fGid;
320 fModTime = stat.fMtime;
321 fIsLink = stat.fIsLink;
322
323 fSubnames = new TGString* [6];
324
325 // file type
326 snprintf(tmp, sizeof(tmp), "%c%c%c%c%c%c%c%c%c%c",
327 (fIsLink ?
328 'l' :
329 R_ISREG(fType) ?
330 '-' :
331 (R_ISDIR(fType) ?
332 'd' :
333 (R_ISCHR(fType) ?
334 'c' :
335 (R_ISBLK(fType) ?
336 'b' :
337 (R_ISFIFO(fType) ?
338 'p' :
339 (R_ISSOCK(fType) ?
340 's' : '?' )))))),
341 ((fType & kS_IRUSR) ? 'r' : '-'),
342 ((fType & kS_IWUSR) ? 'w' : '-'),
343 ((fType & kS_ISUID) ? 's' : ((fType & kS_IXUSR) ? 'x' : '-')),
344 ((fType & kS_IRGRP) ? 'r' : '-'),
345 ((fType & kS_IWGRP) ? 'w' : '-'),
346 ((fType & kS_ISGID) ? 's' : ((fType & kS_IXGRP) ? 'x' : '-')),
347 ((fType & kS_IROTH) ? 'r' : '-'),
348 ((fType & kS_IWOTH) ? 'w' : '-'),
349 ((fType & kS_ISVTX) ? 't' : ((fType & kS_IXOTH) ? 'x' : '-')));
350 fSubnames[0] = new TGString(tmp);
351
352 // file size
353 fsize = bsize = fSize;
354 if (fsize > 1024) {
355 fsize /= 1024;
356 if (fsize > 1024) {
357 // 3.7MB is more informative than just 3MB
358 snprintf(tmp, sizeof(tmp), "%lld.%lldM", fsize/1024, (fsize%1024)/103);
359 } else {
360 snprintf(tmp, sizeof(tmp), "%lld.%lldK", bsize/1024, (bsize%1024)/103);
361 }
362 } else {
363 snprintf(tmp, sizeof(tmp), "%lld", bsize);
364 }
365 fSubnames[1] = new TGString(tmp);
366
367 {
368 struct UserGroup_t *user_group;
369
370 user_group = gSystem->GetUserInfo(fUid);
371 if (user_group) {
372 fSubnames[2] = new TGString(user_group->fUser);
373 fSubnames[3] = new TGString(user_group->fGroup);
374 delete user_group;
375 } else {
376 fSubnames[2] = new TGString(TString::Format("%d", fUid));
377 fSubnames[3] = new TGString(TString::Format("%d", fGid));
378 }
379 }
380
381 struct tm *newtime;
382 time_t loctime = (time_t) fModTime;
383 newtime = localtime(&loctime);
384 if (newtime) {
385 snprintf(tmp, sizeof(tmp), "%d-%02d-%02d %02d:%02d", newtime->tm_year + 1900,
386 newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour,
387 newtime->tm_min);
388 fSubnames[4] = new TGString(tmp);
389 }
390 else
391 fSubnames[4] = new TGString("1901-01-01 00:00");
392
393 fSubnames[5] = 0;
394
395 int i;
396 for (i = 0; fSubnames[i] != 0; ++i)
397 ;
398 fCtw = new int[i+1];
399 fCtw[i] = 0;
400 for (i = 0; fSubnames[i] != 0; ++i)
401 fCtw[i] = gVirtualX->TextWidth(fFontStruct, fSubnames[i]->GetString(),
402 fSubnames[i]->GetLength());
403
405}
406
407////////////////////////////////////////////////////////////////////////////////
408/// Destructor.
409
411{
412 delete fBuf;
413}
414
415////////////////////////////////////////////////////////////////////////////////
416/// Set container item view mode.
417
419{
420 TGLVEntry::SetViewMode(viewMode);
421
422 if (viewMode == kLVLargeIcons)
424 else
426
427 if (fClient) fClient->NeedRedraw(this);
428}
429
430////////////////////////////////////////////////////////////////////////////////
431/// Draw list view container item.
432
434{
435 int ix, iy;
436
438 if (!fLcurrent) return;
439
440 if (fViewMode == kLVLargeIcons) {
441 ix = (fWidth - fLcurrent->GetWidth()) >> 1;
442 iy = 0;
443 } else {
444 ix = 0;
445 iy = (fHeight - fLcurrent->GetHeight()) >> 1;
446 }
447
448 fLcurrent->Draw(fId, fNormGC, ix, iy);
449}
450
451////////////////////////////////////////////////////////////////////////////////
452/// Handle drag and drop enter
453
455{
456 if (!IsDNDTarget()) return kNone;
457 return gVirtualX->InternAtom("application/root", kFALSE);
458}
459
460////////////////////////////////////////////////////////////////////////////////
461/// Set drag and drop data
462
464{
465 if (fDNDData.fDataLength > 0)
467 fDNDData.fData = calloc(data->fDataLength, sizeof(unsigned char));
468 if (fDNDData.fData)
469 memcpy(fDNDData.fData, data->fData, data->fDataLength);
470 fDNDData.fDataLength = data->fDataLength;
471 fDNDData.fDataType = data->fDataType;
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// Set drag and drop object
476
478{
481 fBuf->WriteObject(obj);
484 fDNDData.fDataType = gVirtualX->InternAtom("application/root", kFALSE);
485}
486
487
488
489////////////////////////////////////////////////////////////////////////////////
490/// Create a list view container which will hold the contents of
491/// the current directory.
492
494 UInt_t options, Pixel_t back) :
495 TGLVContainer(p, w, h, options, back)
496{
498 fFilter = 0;
499 fMtime = 0;
501 fRefresh = new TViewUpdateTimer(this, 1000);
505 fCleanups = new TList;
506
507 fFolder_s = fClient->GetPicture("folder_s.xpm");
508 fFolder_t = fClient->GetPicture("folder_t.xpm");
509 fApp_s = fClient->GetPicture("app_s.xpm");
510 fApp_t = fClient->GetPicture("app_t.xpm");
511 fDoc_s = fClient->GetPicture("doc_s.xpm");
512 fDoc_t = fClient->GetPicture("doc_t.xpm");
513 fSlink_s = fClient->GetPicture("slink_s.xpm");
514 fSlink_t = fClient->GetPicture("slink_t.xpm");
515
516 if (!fFolder_s || !fFolder_t ||
517 !fApp_s || !fApp_t ||
518 !fDoc_s || !fDoc_t ||
519 !fSlink_s || !fSlink_t)
520 Error("TGFileContainer", "required pixmap(s) missing\n");
521
523}
524
525////////////////////////////////////////////////////////////////////////////////
526/// Create a list view container which will hold the contents of
527/// the current directory.
528
530 TGLVContainer(p,options, back)
531{
533 fFilter = 0;
534 fMtime = 0;
536 fRefresh = new TViewUpdateTimer(this, 1000);
540 fCleanups = new TList;
541
542 fFolder_s = fClient->GetPicture("folder_s.xpm");
543 fFolder_t = fClient->GetPicture("folder_t.xpm");
544 fApp_s = fClient->GetPicture("app_s.xpm");
545 fApp_t = fClient->GetPicture("app_t.xpm");
546 fDoc_s = fClient->GetPicture("doc_s.xpm");
547 fDoc_t = fClient->GetPicture("doc_t.xpm");
548 fSlink_s = fClient->GetPicture("slink_s.xpm");
549 fSlink_t = fClient->GetPicture("slink_t.xpm");
550
551 if (!fFolder_s || !fFolder_t ||
552 !fApp_s || !fApp_t ||
553 !fDoc_s || !fDoc_t ||
554 !fSlink_s || !fSlink_t)
555 Error("TGFileContainer", "required pixmap(s) missing\n");
556
558}
559
560////////////////////////////////////////////////////////////////////////////////
561/// Delete list view file container.
562
564{
565 if (fRefresh) delete fRefresh;
566 if (fFilter) delete fFilter;
575 if (fCleanups) {
576 TGPicture *pic;
577 TIter nextp(fCleanups);
578 while ((pic = (TGPicture *)nextp())) {
580 }
581 fCleanups->Clear();
582 delete fCleanups;
583 }
584}
585
586////////////////////////////////////////////////////////////////////////////////
587/// Add frame to the composite frame.
588
590{
592
593 nw = new TGFSFrameElement;
594 nw->fFrame = f;
595 nw->fLayout = l ? l : fgDefaultHints;
596 nw->fState = 1;
597 nw->fContainer = this;
598 fList->Add(nw);
599}
600
601////////////////////////////////////////////////////////////////////////////////
602/// Refresh container contents. Check every 5 seconds to see if the
603/// directory modification date has changed.
604
606{
607 FileStat_t sbuf;
608
609 if (gSystem->GetPathInfo(fDirectory, sbuf) == 0)
610 if (fMtime != (ULong_t)sbuf.fMtime) DisplayDirectory();
611
612 return kTRUE;
613}
614
615////////////////////////////////////////////////////////////////////////////////
616/// Set file selection filter.
617
618void TGFileContainer::SetFilter(const char *filter)
619{
620 if (fFilter) delete fFilter;
621 fFilter = new TRegexp(filter, kTRUE);
622}
623
624////////////////////////////////////////////////////////////////////////////////
625/// Sort file system list view container according to sortType.
626
628{
629 fSortType = sortType;
630
631 fList->Sort();
632
633 const TGWindow *parent = this->GetParent();
634 if (parent) {
635 TGCanvas *canvas = (TGCanvas *)parent->GetParent();
636 if (canvas)
637 canvas->Layout();
638 }
639}
640
641////////////////////////////////////////////////////////////////////////////////
642/// Determine the file picture for the given file type.
643
645 const TGPicture **lpic, Int_t file_type, Bool_t is_link,
646 const char *name, Bool_t /*small*/)
647{
648 static TString cached_ext;
649 static const TGPicture *cached_spic = 0;
650 static const TGPicture *cached_lpic = 0;
651 const char *ext = name ? strrchr(name, '.') : 0;
652 *pic = 0;
653 *lpic = 0;
654
655 if (fCachePictures && ext && cached_spic && cached_lpic && (cached_ext == ext)) {
656 *pic = cached_spic;
657 *lpic = cached_lpic;
658 if (!is_link) return;
659 }
660
661 if (R_ISREG(file_type)) {
662 TString fname(name);
663 if (is_link && fname.EndsWith(".lnk")) {
664 fname.Remove(fname.Length()-4);
665 }
666 *pic = fClient->GetMimeTypeList()->GetIcon(fname.Data(), kTRUE);
667 *lpic = fClient->GetMimeTypeList()->GetIcon(fname.Data(), kFALSE);
668
669 if (*pic) {
670 if (!*lpic) *lpic = *pic;
671 if (ext) {
672 cached_ext = ext;
673 cached_spic = *pic;
674 cached_lpic = *lpic;
675 if (!is_link) return;
676 }
677 }
678 } else {
679 *pic = 0;
680 }
681
682 if (*pic == 0) {
683 *pic = fDoc_t;
684 *lpic = fDoc_s;
685
686 if (R_ISREG(file_type) && (file_type) & kS_IXUSR) {
687 *pic = fApp_t;
688 *lpic = fApp_s;
689 }
690 if (R_ISDIR(file_type)) {
691 *pic = fFolder_t;
692 *lpic = fFolder_s;
693 }
694 }
695 if (is_link) {
696 if (*pic && *lpic) {
697 auto img1 = TASUtils::FromPixmap((*pic)->GetPicture(), (*pic)->GetMask());
698 if (img1) {
699 std::unique_ptr<TImage> img2(TImage::Open("slink_t.xpm"));
700 if (img2)
701 img1->Merge(img2.get());
702 TString lnk_name = (*pic)->GetName();
703 lnk_name.Prepend("lnk_");
704 *pic = fClient->GetPicturePool()->GetPicture(lnk_name.Data(),
705 TASUtils::GetPixmap(img1.get()), TASUtils::GetMask(img1.get()));
706 fCleanups->Add(((TObject *)*pic));
707 }
708 img1 = TASUtils::FromPixmap((*lpic)->GetPicture(), (*lpic)->GetMask());
709 if (img1) {
710 std::unique_ptr<TImage> img2(TImage::Open("slink_s.xpm"));
711 if (img2)
712 img1->Merge(img2.get());
713 TString lnk_name = (*lpic)->GetName();
714 lnk_name.Prepend("lnk_");
715 *lpic = fClient->GetPicturePool()->GetPicture(lnk_name.Data(),
716 TASUtils::GetPixmap(img1.get()), TASUtils::GetMask(img1.get()));
717 fCleanups->Add(((TObject *)*lpic));
718 }
719 }
720 else {
721 *pic = fSlink_t;
722 *lpic = fSlink_s;
723 }
724 }
725
726 cached_lpic = 0;
727 cached_spic = 0;
728 cached_ext = "";
729}
730
731////////////////////////////////////////////////////////////////////////////////
732/// Change current directory.
733
735{
736 TString savdir = gSystem->WorkingDirectory();
737 gSystem->ChangeDirectory(fDirectory.Data()); // so path of ".." will work
738 char *exppath = gSystem->ExpandPathName(path);
739 if (gSystem->ChangeDirectory(exppath)) {
741 gSystem->ChangeDirectory(savdir.Data());
743 }
744 delete[] exppath;
745}
746
747////////////////////////////////////////////////////////////////////////////////
748/// Display the contents of the current directory in the container.
749/// This can be used to refresh the contents of the window.
750
752{
753 RemoveAll();
755
756 // This automatically calls layout
758
759 // Make TGExplorerMainFrame display total objects in status bar
762
764}
765
766////////////////////////////////////////////////////////////////////////////////
767/// This function creates the file list from current dir.
768
770{
771 TString savdir = gSystem->WorkingDirectory();
772 if (!gSystem->ChangeDirectory(fDirectory.Data())) return;
773
774 FileStat_t sbuf;
775 if (gSystem->GetPathInfo(".", sbuf) == 0)
776 fMtime = sbuf.fMtime;
777
778 void *dirp;
779 if ((dirp = gSystem->OpenDirectory(".")) == 0) {
780 gSystem->ChangeDirectory(savdir.Data());
781 return;
782 }
783
784 const char *name;
785 while ((name = gSystem->GetDirEntry(dirp)) != 0 && fDisplayStat) {
786 if (strcmp(name, ".") && strcmp(name, ".."))
787 AddFile(name);
789 }
790 gSystem->FreeDirectory(dirp);
791
792 gSystem->ChangeDirectory(savdir.Data());
793}
794
795////////////////////////////////////////////////////////////////////////////////
796/// Add file in container.
797
799 const TGPicture *ilpic)
800{
802 TGFileItem *item = 0;
803 const TGPicture *spic, *slpic;
804 TGPicture *pic, *lpic;
805
806 FileStat_t sbuf;
807
808 if (gSystem->GetPathInfo(name, sbuf)) {
809 if (sbuf.fIsLink) {
810 Info("AddFile", "Broken symlink of %s.", name);
811 } else if (errno != ENOENT) {
812 TString msg;
813 msg.Form("Can't read file attributes of \"%s\": %s.",
814 name, gSystem->GetError());
816 "Error", msg.Data(), kMBIconStop, kMBOk);
817 }
818 return item;
819 }
820
821 filename = name;
822 if (R_ISDIR(sbuf.fMode) || fFilter == 0 ||
823 (fFilter && filename.Index(*fFilter) != kNPOS)) {
824
825 if (ipic && ilpic) { // dynamic icons
826 spic = ipic;
827 slpic = ilpic;
828 } else {
829 GetFilePictures(&spic, &slpic, sbuf.fMode, sbuf.fIsLink, name, kTRUE);
830 }
831
832 pic = (TGPicture*)spic; pic->AddReference();
833 lpic = (TGPicture*)slpic; lpic->AddReference();
834
835 item = new TGFileItem(this, lpic, slpic, spic, pic,
837 sbuf, fViewMode);
838 AddItem(item);
839 }
840
841 return item;
842}
843
844////////////////////////////////////////////////////////////////////////////////
845/// Add remote file in container.
846
848 const TGPicture *ilpic)
849{
851 TGFileItem *item = 0;
852 const TGPicture *spic, *slpic;
853 TGPicture *pic, *lpic;
854
855 FileStat_t sbuf;
856
857 TRemoteObject *robj = (TRemoteObject *)obj;
858
859 robj->GetFileStat(&sbuf);
860 filename = robj->GetName();
861
862 if (R_ISDIR(sbuf.fMode) || fFilter == 0 ||
863 (fFilter && filename.Index(*fFilter) != kNPOS)) {
864
865 if (ipic && ilpic) { // dynamic icons
866 spic = ipic;
867 slpic = ilpic;
868 } else {
869 GetFilePictures(&spic, &slpic, sbuf.fMode, sbuf.fIsLink, filename, kTRUE);
870 }
871
872 pic = (TGPicture*)spic; pic->AddReference();
873 lpic = (TGPicture*)slpic; lpic->AddReference();
874
875 item = new TGFileItem(this, lpic, slpic, spic, pic, new TGString(filename),
876 sbuf, fViewMode);
877 AddItem(item);
878 }
879 return item;
880}
881
882////////////////////////////////////////////////////////////////////////////////
883/// stop refresh timer
884
886{
887 if (fRefresh) delete fRefresh;
888 fRefresh = 0;
889}
890
891////////////////////////////////////////////////////////////////////////////////
892/// start refreshing
893
899
900////////////////////////////////////////////////////////////////////////////////
901/// Save a file container widget as a C++ statement(s) on output stream out.
902
903void TGFileContainer::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
904{
905 // save options and color if necessary
906 auto extra_args = SaveCtorArgs(out, kSunkenFrame);
907
908 out << "\n // container frame\n";
909 out << " TGFileContainer *" << GetName() << " = new TGFileContainer(";
910
911 if ((fParent->GetParent())->InheritsFrom(TGCanvas::Class()))
912 out << GetCanvas()->GetName();
913 else
914 out << fParent->GetName() << "," << GetWidth() << "," << GetHeight();
915
916 out << extra_args << ");\n";
917
918 if (option && strstr(option, "keep_names"))
919 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
920 out << " " << GetCanvas()->GetName() << "->SetContainer(" << GetName() << ");\n";
921 out << " " << GetName() << "->DisplayDirectory();\n";
922 out << " " << GetName() << "->AddFile(\"..\");\n";
923 out << " " << GetName() << "->StopRefreshTimer();\n";
924}
free(fBuffer)
Handle_t Atom_t
WM token.
Definition GuiTypes.h:38
@ kChildFrame
Definition GuiTypes.h:380
@ kSunkenFrame
Definition GuiTypes.h:384
const Handle_t kNone
Definition GuiTypes.h:89
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:70
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:132
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:84
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:241
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
EFSSortMode
@ kSortByDate
@ kSortByOwner
@ kSortByName
@ kSortByGroup
@ kSortByType
@ kSortBySize
EListViewMode
Definition TGListView.h:21
@ kLVLargeIcons
Definition TGListView.h:22
@ kMBOk
Definition TGMsgBox.h:33
@ kMBIconStop
Definition TGMsgBox.h:22
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
Bool_t R_ISFIFO(Int_t mode)
Definition TSystem.h:128
Bool_t R_ISSOCK(Int_t mode)
Definition TSystem.h:129
Bool_t R_ISBLK(Int_t mode)
Definition TSystem.h:125
Bool_t R_ISREG(Int_t mode)
Definition TSystem.h:126
Bool_t R_ISLNK(Int_t mode)
Definition TSystem.h:127
Bool_t R_ISDIR(Int_t mode)
Definition TSystem.h:123
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
Bool_t R_ISCHR(Int_t mode)
Definition TSystem.h:124
@ kS_IRGRP
Definition TSystem.h:114
@ kS_IWUSR
Definition TSystem.h:111
@ kS_ISUID
Definition TSystem.h:106
@ kS_IRUSR
Definition TSystem.h:110
@ kS_IXOTH
Definition TSystem.h:120
@ kS_ISGID
Definition TSystem.h:107
@ kS_IROTH
Definition TSystem.h:118
@ kS_IWGRP
Definition TSystem.h:115
@ kS_IXUSR
Definition TSystem.h:112
@ kS_ISVTX
Definition TSystem.h:108
@ kS_IWOTH
Definition TSystem.h:119
@ kS_IXGRP
Definition TSystem.h:116
#define gVirtualX
Definition TVirtualX.h:379
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kCT_SELCHANGED
@ kC_CONTAINER
static Pixmap_t GetPixmap(TImage *timg)
Returns image pixmap.
Definition TASUtils.cxx:132
static Pixmap_t GetMask(TImage *timg)
Returns image mask pixmap (alpha channel).
Definition TASUtils.cxx:178
static std::unique_ptr< TImage > FromPixmap(Pixmap_t pxm, Pixmap_t mask)
Create image from pixmap.
Definition TASUtils.cxx:268
void WriteObject(const TObject *obj, Bool_t cacheReuse=kTRUE) override
Write object to I/O buffer.
Int_t Length() const
Definition TBuffer.h:100
char * Buffer() const
Definition TBuffer.h:96
Drag and drop data container.
Atom_t fDataType
Data type description.
Int_t fDataLength
Length of data.
void * fData
Actual data.
A frame containing two scrollbars (a horizontal and a vertical) and a viewport.
Definition TGCanvas.h:192
void Layout() override
Create layout for canvas.
static TClass * Class()
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:234
TGMimeTypes * GetMimeTypeList() const
Definition TGClient.h:147
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition TGClient.cxx:289
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:381
TGPicturePool * GetPicturePool() const
Definition TGClient.h:126
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:317
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1158
TList * fList
container of frame elements
Definition TGFrame.h:294
static TGLayoutHints * fgDefaultHints
Definition TGFrame.h:299
const TGWindow * fMsgWindow
window handling container messages
Definition TGCanvas.h:42
TGCanvas * GetCanvas() const
Definition TGCanvas.h:99
Int_t fSelected
number of selected items
Definition TGCanvas.h:49
Int_t fTotal
total items
Definition TGCanvas.h:48
void RemoveAll() override
Remove all items from the container.
Definition TGCanvas.cxx:638
Int_t Compare(const TObject *obj) const override
Sort frame elements in file selection list view container.
TGFileContainer * fContainer
Bool_t IsSortable() const override
const TGPicture * fSlink_s
big symbolic link icon
void CreateFileList()
This function creates the file list from current dir.
const TGPicture * fFolder_s
big folder icon
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a file container widget as a C++ statement(s) on output stream out.
Bool_t HandleTimer(TTimer *t) override
Refresh container contents.
TList * fCleanups
list of pictures to cleanup
TString fDirectory
current directory
TViewUpdateTimer * fRefresh
refresh timer
void StopRefreshTimer()
stop refresh timer
const TGPicture * fDoc_t
small document icon
const TGPicture * fApp_t
small application icon
const TGPicture * fApp_s
big application icon
void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr) override
Add frame to the composite frame.
virtual void Sort(EFSSortMode sortType)
Sort file system list view container according to sortType.
const TGPicture * fDoc_s
big document icon
~TGFileContainer() override
Delete list view file container.
Bool_t fCachePictures
kTRUE use caching
virtual void ChangeDirectory(const char *path)
Change current directory.
const TGPicture * fSlink_t
small symbolic link icon
virtual void DisplayDirectory()
Display the contents of the current directory in the container.
ULong_t fMtime
directory modification time
virtual TGFileItem * AddFile(const char *name, const TGPicture *pic=nullptr, const TGPicture *lpic=nullptr)
Add file in container.
virtual TGFileItem * AddRemoteFile(TObject *obj, const TGPicture *ipic=nullptr, const TGPicture *ilpic=nullptr)
Add remote file in container.
void StartRefreshTimer(ULong_t msec=1000)
start refreshing
const TGPicture * fFolder_t
small folder icon
TRegexp * fFilter
file filter
friend class TGFSFrameElement
Bool_t fDisplayStat
kFALSE to interrupt display directory contents in case of many files inside
virtual void SetFilter(const char *filter)
Set file selection filter.
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.
TGFileContainer(const TGWindow *p=nullptr, 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.
EFSSortMode fSortType
sorting mode of contents
Utility class used by the file selection dialog (TGFSDialog).
TGFileIcon(const TGWindow *p, const TGPicture *pic, const TGPicture *lpic, UInt_t options=kChildFrame, Pixel_t back=GetWhitePixel())
void DoRedraw() override
Draw icon.
const TGPicture * fLpic
Int_t fGid
file uid and gid
void DoRedraw() override
Draw list view container item.
Int_t GetUid() const
Long64_t fSize
file size
const TGPicture * fLcurrent
current icon
void SetViewMode(EListViewMode viewMode) override
Set container item view mode.
Int_t GetGid() const
TBufferFile * fBuf
buffer used for Drag and Drop
const TGPicture * fBlpic
big icon
Atom_t HandleDNDEnter(Atom_t *) override
Handle drag and drop enter.
void Init(const TGPicture *blpic, const TGPicture *slpic, FileStat_t &stat, EListViewMode viewMode)
Common initializer for file list view item.
~TGFileItem() override
Destructor.
Long_t fModTime
modification time
const TGPicture * fSlpic
small icon
Long64_t GetSize() const
void SetDNDObject(TObject *obj)
Set drag and drop object.
TDNDData fDNDData
Drag and Drop data.
Long_t GetModTime() const
Int_t fType
file type
Int_t GetType() const
void SetDNDData(TDNDData *data)
Set drag and drop data.
TGFileItem(const TGWindow *p=nullptr, const TGPicture *bpic=nullptr, const TGPicture *blpic=nullptr, const TGPicture *spic=nullptr, const TGPicture *slpic=nullptr, TGString *name=nullptr, 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.
Bool_t fIsLink
true if symbolic link
TGLayoutHints * fLayout
Definition TGLayout.h:114
TGFrame * fFrame
Definition TGLayout.h:112
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:703
UInt_t fHeight
frame height
Definition TGFrame.h:88
Bool_t IsDNDTarget() const
Definition TGFrame.h:275
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:639
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
TString SaveCtorArgs(std::ostream &out, UInt_t dflt_options=kChildFrame, Bool_t check_white_pixel=kFALSE)
Return options and custom color as constructor args Used in the SavePrimitive methods,...
Definition TGFrame.cxx:2494
UInt_t GetWidth() const
Definition TGFrame.h:226
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:769
This class handles GUI icons.
Definition TGIcon.h:22
void DoRedraw() override
Redraw picture.
Definition TGIcon.cxx:126
virtual void AddItem(TGLVEntry *item)
Definition TGListView.h:207
EListViewMode fViewMode
list view viewing mode
Definition TGListView.h:186
TGString ** fSubnames
sub names of item (details)
Definition TGListView.h:44
void DoRedraw() override
Redraw list view item.
FontStruct_t fFontStruct
text font
Definition TGListView.h:59
EListViewMode fViewMode
list view viewing mode
Definition TGListView.h:52
GContext_t fNormGC
drawing graphics context
Definition TGListView.h:58
virtual void SetViewMode(EListViewMode viewMode)
Set the view mode for this list item.
TGString * GetItemName() const
Definition TGListView.h:88
Int_t * fCtw
width of sub names
Definition TGListView.h:47
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
const TGPicture * GetIcon(const char *filename, Bool_t small_icon)
Return icon belonging to mime type of filename.
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
void FreePicture(const TGPicture *pic)
Remove picture from cache if nobody is using it anymore.
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition TGPicture.cxx:81
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
void Draw(Option_t *="") override
Default Draw method for all objects.
Definition TGPicture.h:46
UInt_t GetHeight() const
Definition TGPicture.h:53
UInt_t GetWidth() const
Definition TGPicture.h:52
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition TGString.h:20
Int_t GetLength() const
Definition TGString.h:29
const char * GetString() const
Definition TGString.h:30
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition TGWindow.cxx:153
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:130
const TGWindow * GetParent() const
Definition TGWindow.h:83
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:337
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:123
A doubly linked list.
Definition TList.h:38
void Clear(Option_t *option="") override
Remove all objects from the list.
Definition TList.cxx:532
void Add(TObject *obj) override
Definition TList.h:81
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition TList.cxx:1067
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Mother of all ROOT objects.
Definition TObject.h:42
void AddReference()
Definition TRefCnt.h:40
Regular expression class.
Definition TRegexp.h:31
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session.
Bool_t GetFileStat(FileStat_t *sbuf)
Get remote file status.
Basic string class.
Definition TString.h:137
Ssiz_t Length() const
Definition TString.h:426
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2325
const char * Data() const
Definition TString.h:385
TString & Prepend(const char *cs)
Definition TString.h:683
TString & Remove(Ssiz_t pos)
Definition TString.h:695
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:2460
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2438
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1296
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:860
virtual void * OpenDirectory(const char *name)
Open a directory.
Definition TSystem.cxx:851
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:1420
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition TSystem.cxx:868
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition TSystem.cxx:877
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:474
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:949
virtual const char * WorkingDirectory()
Return working directory.
Definition TSystem.cxx:886
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:419
virtual const char * GetError()
Return system error string.
Definition TSystem.cxx:254
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition TSystem.cxx:1623
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:162
TViewUpdateTimer(TGFileContainer *t, Long_t ms)
Bool_t Notify() override
Reset the timer.
TGFileContainer * fContainer
TF1 * f1
Definition legend1.C:11
Int_t fMode
Definition TSystem.h:135
Long64_t fSize
Definition TSystem.h:138
Int_t fGid
Definition TSystem.h:137
Long_t fMtime
Definition TSystem.h:139
Bool_t fIsLink
Definition TSystem.h:140
Int_t fUid
Definition TSystem.h:136
TString fUser
Definition TSystem.h:149
TString fGroup
Definition TSystem.h:150
TLine l
Definition textangle.C:4