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 "snprintf.h"
58
59#include <ctime>
60#include <cstdlib>
61#include <iostream>
62
65
66class TViewUpdateTimer : public TTimer {
67
68private:
70
71public:
73 Bool_t Notify() override;
74};
75
76
77
78class TGFileIcon : public TGIcon {
79
80protected:
81 const TGPicture *fLpic; // icon picture
82
83 void DoRedraw() override;
84
85public:
86 TGFileIcon(const TGWindow *p, const TGPicture *pic, const TGPicture *lpic,
87 UInt_t options = kChildFrame, Pixel_t back = GetWhitePixel()) :
88 TGIcon(p, pic, 0, 0, options, back) { fLpic = lpic; }
89};
90
91
92
93////////////////////////////////////////////////////////////////////////////////
94
96public:
97 TGFileContainer *fContainer; // file container
98
99 Bool_t IsSortable() const override { return kTRUE; }
100 Int_t Compare(const TObject *obj) const override;
101};
102
103////////////////////////////////////////////////////////////////////////////////
104/// Sort frame elements in file selection list view container.
105
107{
108 Int_t type1, type2;
109
111 TGFileItem *f2 = (TGFileItem *) ((TGFrameElement *) obj)->fFrame;
112
113 switch (fContainer->fSortType) {
114 default:
115 case kSortByName:
116 //--- this is not exactly what I want...
117 type1 = f1->GetType();
118 type2 = f2->GetType();
119
120 //--- use posix macros
121 if (R_ISDIR(type1)) type1 = 1;
122 else type1 = 6;
123
124 if (R_ISDIR(type2)) type2 = 1;
125 else type2 = 6;
126
127 if (type1 < type2) return -1;
128 if (type1 > type2) return 1;
129 return strcmp(f1->GetItemName()->GetString(),
130 f2->GetItemName()->GetString());
131
132 case kSortByOwner:
133 if (f1->GetUid() != f2->GetUid()) {
134 if (f1->GetUid() < f2->GetUid())
135 return -1;
136 else
137 return +1;
138 }
139
140 // else sort by name
141 type1 = f1->GetType();
142 type2 = f2->GetType();
143
144 //--- use posix macros
145 if (R_ISDIR(type1)) type1 = 1;
146 else type1 = 6;
147
148 if (R_ISDIR(type2)) type2 = 1;
149 else type2 = 6;
150
151 if (type1 < type2) return -1;
152 if (type1 > type2) return 1;
153 return strcmp(f1->GetItemName()->GetString(),
154 f2->GetItemName()->GetString());
155
156 case kSortByGroup:
157 if (f1->GetGid() != f2->GetGid()) {
158 if (f1->GetGid() < f2->GetGid())
159 return -1;
160 else
161 return +1;
162 }
163
164 // else sort by name
165 type1 = f1->GetType();
166 type2 = f2->GetType();
167
168 //--- use posix macros
169 if (R_ISDIR(type1)) type1 = 1;
170 else type1 = 6;
171
172 if (R_ISDIR(type2)) type2 = 1;
173 else type2 = 6;
174
175 if (type1 < type2) return -1;
176 if (type1 > type2) return 1;
177 return strcmp(f1->GetItemName()->GetString(),
178 f2->GetItemName()->GetString());
179
180 case kSortByType:
181 //--- this is not exactly what I want...
182
183 type1 = f1->GetType();
184 type2 = f2->GetType();
185
186 //--- use posix macros
187
188 if (R_ISDIR(type1)) type1 = 1;
189 else if (R_ISLNK(type1)) type1 = 2;
190 else if (R_ISSOCK(type1)) type1 = 3;
191 else if (R_ISFIFO(type1)) type1 = 4;
192 else if (R_ISREG(type1) && (type1 & kS_IXUSR)) type1 = 5;
193 else type1 = 6;
194
195 if (R_ISDIR(type2)) type2 = 1;
196 else if (R_ISLNK(type2)) type2 = 2;
197 else if (R_ISSOCK(type2)) type2 = 3;
198 else if (R_ISFIFO(type2)) type2 = 4;
199 else if (R_ISREG(type2) && (type2 & kS_IXUSR)) type2 = 5;
200 else type2 = 6;
201
202 if (type1 < type2) return -1;
203 if (type1 > type2) return 1;
204 return strcmp(f1->GetItemName()->GetString(),
205 f2->GetItemName()->GetString());
206
207 case kSortBySize:
208 if (f1->GetSize() < f2->GetSize()) return -1;
209 if (f1->GetSize() > f2->GetSize()) return 1;
210 return strcmp(f1->GetItemName()->GetString(),
211 f2->GetItemName()->GetString());
212
213 case kSortByDate:
214 time_t loctimeF1 = (time_t) f1->GetModTime();
215 // coverity[returned_null]
216 struct tm tmF1 = *localtime(&loctimeF1);
217
218 time_t loctimeF2 = (time_t) f2->GetModTime();
219 // coverity[returned_null]
220 struct tm tmF2 = *localtime(&loctimeF2);
221
222 if ( tmF1.tm_year != tmF2.tm_year )
223 return (tmF1.tm_year < tmF2.tm_year) ? +1 : -1;
224 else if ( tmF1.tm_mon != tmF2.tm_mon )
225 return (tmF1.tm_mon < tmF2.tm_mon) ? +1 : -1;
226 else if ( tmF1.tm_mday != tmF2.tm_mday )
227 return (tmF1.tm_mday < tmF2.tm_mday) ? +1 : -1;
228 else if ( tmF1.tm_hour != tmF2.tm_hour )
229 return (tmF1.tm_hour < tmF2.tm_hour) ? +1 : -1;
230 else if ( tmF1.tm_min != tmF2.tm_min )
231 return (tmF1.tm_min < tmF2.tm_min) ? +1 : -1;
232 else if ( tmF1.tm_sec != tmF2.tm_sec )
233 return (tmF1.tm_sec < tmF2.tm_sec) ? +1 : -1;
234 else
235 return 0;
236 }
237}
238
239
240////////////////////////////////////////////////////////////////////////////////
241/// Reset the timer.
242
244{
246 Reset();
247 return kFALSE;
248}
249
250
251////////////////////////////////////////////////////////////////////////////////
252/// Draw icon.
253
255{
257 if (fLpic) fLpic->Draw(fId, GetBckgndGC()(), 0, 0);
258}
259
260
261////////////////////////////////////////////////////////////////////////////////
262/// Create a list view item.
263
265 const TGPicture *bpic, const TGPicture *blpic,
266 const TGPicture *spic, const TGPicture *slpic,
268 Int_t gid, Long_t modtime, EListViewMode viewMode,
269 UInt_t options, Pixel_t back) :
270 TGLVEntry(p, bpic, spic, name, 0, viewMode, options, back)
271{
272 FileStat_t buf;
273
274 buf.fMode = type;
275 buf.fSize = size;
276 buf.fUid = uid;
277 buf.fGid = gid;
278 buf.fMtime = modtime;
279 buf.fIsLink = (blpic != 0); // FIXME: hack...
280
281 Init(blpic, slpic, buf, viewMode);
282}
283
284////////////////////////////////////////////////////////////////////////////////
285/// Create a list view item.
286
288 const TGPicture *bpic, const TGPicture *blpic,
289 const TGPicture *spic, const TGPicture *slpic,
290 TGString *name, FileStat_t &stat, EListViewMode viewMode,
291 UInt_t options, Pixel_t back) :
292 TGLVEntry(p, bpic, spic, name, 0, viewMode, options, back)
293{
294 Init(blpic, slpic, stat, viewMode);
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Common initializer for file list view item.
299
300void TGFileItem::Init(const TGPicture *blpic, const TGPicture *slpic,
301 FileStat_t &stat, EListViewMode viewMode)
302{
303 char tmp[256];
304 Long64_t fsize, bsize;
305
306 fBuf = 0;
307 fDNDData.fData = 0;
310 fLcurrent =
311 fBlpic = blpic;
312 fSlpic = slpic;
313
315 SetViewMode(viewMode);
316
317 fType = stat.fMode;
318 fSize = stat.fSize;
319 fUid = stat.fUid;
320 fGid = stat.fGid;
321 fModTime = stat.fMtime;
322 fIsLink = stat.fIsLink;
323
324 fSubnames = new TGString* [6];
325
326 // file type
327 snprintf(tmp, sizeof(tmp), "%c%c%c%c%c%c%c%c%c%c",
328 (fIsLink ?
329 'l' :
330 R_ISREG(fType) ?
331 '-' :
332 (R_ISDIR(fType) ?
333 'd' :
334 (R_ISCHR(fType) ?
335 'c' :
336 (R_ISBLK(fType) ?
337 'b' :
338 (R_ISFIFO(fType) ?
339 'p' :
340 (R_ISSOCK(fType) ?
341 's' : '?' )))))),
342 ((fType & kS_IRUSR) ? 'r' : '-'),
343 ((fType & kS_IWUSR) ? 'w' : '-'),
344 ((fType & kS_ISUID) ? 's' : ((fType & kS_IXUSR) ? 'x' : '-')),
345 ((fType & kS_IRGRP) ? 'r' : '-'),
346 ((fType & kS_IWGRP) ? 'w' : '-'),
347 ((fType & kS_ISGID) ? 's' : ((fType & kS_IXGRP) ? 'x' : '-')),
348 ((fType & kS_IROTH) ? 'r' : '-'),
349 ((fType & kS_IWOTH) ? 'w' : '-'),
350 ((fType & kS_ISVTX) ? 't' : ((fType & kS_IXOTH) ? 'x' : '-')));
351 fSubnames[0] = new TGString(tmp);
352
353 // file size
354 fsize = bsize = fSize;
355 if (fsize > 1024) {
356 fsize /= 1024;
357 if (fsize > 1024) {
358 // 3.7MB is more informative than just 3MB
359 snprintf(tmp, sizeof(tmp), "%lld.%lldM", fsize/1024, (fsize%1024)/103);
360 } else {
361 snprintf(tmp, sizeof(tmp), "%lld.%lldK", bsize/1024, (bsize%1024)/103);
362 }
363 } else {
364 snprintf(tmp, sizeof(tmp), "%lld", bsize);
365 }
366 fSubnames[1] = new TGString(tmp);
367
368 {
369 struct UserGroup_t *user_group;
370
371 user_group = gSystem->GetUserInfo(fUid);
372 if (user_group) {
373 fSubnames[2] = new TGString(user_group->fUser);
374 fSubnames[3] = new TGString(user_group->fGroup);
375 delete user_group;
376 } else {
377 fSubnames[2] = new TGString(TString::Format("%d", fUid));
378 fSubnames[3] = new TGString(TString::Format("%d", fGid));
379 }
380 }
381
382 struct tm *newtime;
383 time_t loctime = (time_t) fModTime;
384 newtime = localtime(&loctime);
385 if (newtime) {
386 snprintf(tmp, sizeof(tmp), "%d-%02d-%02d %02d:%02d", newtime->tm_year + 1900,
387 newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour,
388 newtime->tm_min);
389 fSubnames[4] = new TGString(tmp);
390 }
391 else
392 fSubnames[4] = new TGString("1901-01-01 00:00");
393
394 fSubnames[5] = 0;
395
396 int i;
397 for (i = 0; fSubnames[i] != 0; ++i)
398 ;
399 fCtw = new int[i+1];
400 fCtw[i] = 0;
401 for (i = 0; fSubnames[i] != 0; ++i)
402 fCtw[i] = gVirtualX->TextWidth(fFontStruct, fSubnames[i]->GetString(),
403 fSubnames[i]->GetLength());
404
406}
407
408////////////////////////////////////////////////////////////////////////////////
409/// Destructor.
410
412{
413 delete fBuf;
414}
415
416////////////////////////////////////////////////////////////////////////////////
417/// Set container item view mode.
418
420{
421 TGLVEntry::SetViewMode(viewMode);
422
423 if (viewMode == kLVLargeIcons)
425 else
427
428 if (fClient) fClient->NeedRedraw(this);
429}
430
431////////////////////////////////////////////////////////////////////////////////
432/// Draw list view container item.
433
435{
436 int ix, iy;
437
439 if (!fLcurrent) return;
440
441 if (fViewMode == kLVLargeIcons) {
442 ix = (fWidth - fLcurrent->GetWidth()) >> 1;
443 iy = 0;
444 } else {
445 ix = 0;
446 iy = (fHeight - fLcurrent->GetHeight()) >> 1;
447 }
448
449 fLcurrent->Draw(fId, fNormGC, ix, iy);
450}
451
452////////////////////////////////////////////////////////////////////////////////
453/// Handle drag and drop enter
454
456{
457 if (!IsDNDTarget()) return kNone;
458 return gVirtualX->InternAtom("application/root", kFALSE);
459}
460
461////////////////////////////////////////////////////////////////////////////////
462/// Set drag and drop data
463
465{
466 if (fDNDData.fDataLength > 0)
468 fDNDData.fData = calloc(sizeof(unsigned char), data->fDataLength);
469 if (fDNDData.fData)
470 memcpy(fDNDData.fData, data->fData, data->fDataLength);
471 fDNDData.fDataLength = data->fDataLength;
472 fDNDData.fDataType = data->fDataType;
473}
474
475////////////////////////////////////////////////////////////////////////////////
476/// Set drag and drop object
477
479{
482 fBuf->WriteObject(obj);
485 fDNDData.fDataType = gVirtualX->InternAtom("application/root", kFALSE);
486}
487
488
489
490////////////////////////////////////////////////////////////////////////////////
491/// Create a list view container which will hold the contents of
492/// the current directory.
493
495 UInt_t options, Pixel_t back) :
496 TGLVContainer(p, w, h, options, back)
497{
499 fFilter = 0;
500 fMtime = 0;
502 fRefresh = new TViewUpdateTimer(this, 1000);
506 fCleanups = new TList;
507
508 fFolder_s = fClient->GetPicture("folder_s.xpm");
509 fFolder_t = fClient->GetPicture("folder_t.xpm");
510 fApp_s = fClient->GetPicture("app_s.xpm");
511 fApp_t = fClient->GetPicture("app_t.xpm");
512 fDoc_s = fClient->GetPicture("doc_s.xpm");
513 fDoc_t = fClient->GetPicture("doc_t.xpm");
514 fSlink_s = fClient->GetPicture("slink_s.xpm");
515 fSlink_t = fClient->GetPicture("slink_t.xpm");
516
517 if (!fFolder_s || !fFolder_t ||
518 !fApp_s || !fApp_t ||
519 !fDoc_s || !fDoc_t ||
520 !fSlink_s || !fSlink_t)
521 Error("TGFileContainer", "required pixmap(s) missing\n");
522
524}
525
526////////////////////////////////////////////////////////////////////////////////
527/// Create a list view container which will hold the contents of
528/// the current directory.
529
531 TGLVContainer(p,options, back)
532{
534 fFilter = 0;
535 fMtime = 0;
537 fRefresh = new TViewUpdateTimer(this, 1000);
541 fCleanups = new TList;
542
543 fFolder_s = fClient->GetPicture("folder_s.xpm");
544 fFolder_t = fClient->GetPicture("folder_t.xpm");
545 fApp_s = fClient->GetPicture("app_s.xpm");
546 fApp_t = fClient->GetPicture("app_t.xpm");
547 fDoc_s = fClient->GetPicture("doc_s.xpm");
548 fDoc_t = fClient->GetPicture("doc_t.xpm");
549 fSlink_s = fClient->GetPicture("slink_s.xpm");
550 fSlink_t = fClient->GetPicture("slink_t.xpm");
551
552 if (!fFolder_s || !fFolder_t ||
553 !fApp_s || !fApp_t ||
554 !fDoc_s || !fDoc_t ||
555 !fSlink_s || !fSlink_t)
556 Error("TGFileContainer", "required pixmap(s) missing\n");
557
559}
560
561////////////////////////////////////////////////////////////////////////////////
562/// Delete list view file container.
563
565{
566 if (fRefresh) delete fRefresh;
567 if (fFilter) delete fFilter;
576 if (fCleanups) {
577 TGPicture *pic;
578 TIter nextp(fCleanups);
579 while ((pic = (TGPicture *)nextp())) {
581 }
582 fCleanups->Clear();
583 delete fCleanups;
584 }
585}
586
587////////////////////////////////////////////////////////////////////////////////
588/// Add frame to the composite frame.
589
591{
593
594 nw = new TGFSFrameElement;
595 nw->fFrame = f;
596 nw->fLayout = l ? l : fgDefaultHints;
597 nw->fState = 1;
598 nw->fContainer = this;
599 fList->Add(nw);
600}
601
602////////////////////////////////////////////////////////////////////////////////
603/// Refresh container contents. Check every 5 seconds to see if the
604/// directory modification date has changed.
605
607{
608 FileStat_t sbuf;
609
610 if (gSystem->GetPathInfo(fDirectory, sbuf) == 0)
611 if (fMtime != (ULong_t)sbuf.fMtime) DisplayDirectory();
612
613 return kTRUE;
614}
615
616////////////////////////////////////////////////////////////////////////////////
617/// Set file selection filter.
618
619void TGFileContainer::SetFilter(const char *filter)
620{
621 if (fFilter) delete fFilter;
622 fFilter = new TRegexp(filter, kTRUE);
623}
624
625////////////////////////////////////////////////////////////////////////////////
626/// Sort file system list view container according to sortType.
627
629{
630 fSortType = sortType;
631
632 fList->Sort();
633
634 TGCanvas *canvas = (TGCanvas *) this->GetParent()->GetParent();
635 canvas->Layout();
636}
637
638////////////////////////////////////////////////////////////////////////////////
639/// Determine the file picture for the given file type.
640
642 const TGPicture **lpic, Int_t file_type, Bool_t is_link,
643 const char *name, Bool_t /*small*/)
644{
645 static TString cached_ext;
646 static const TGPicture *cached_spic = 0;
647 static const TGPicture *cached_lpic = 0;
648 const char *ext = name ? strrchr(name, '.') : 0;
649 *pic = 0;
650 *lpic = 0;
651
652 if (fCachePictures && ext && cached_spic && cached_lpic && (cached_ext == ext)) {
653 *pic = cached_spic;
654 *lpic = cached_lpic;
655 if (!is_link) return;
656 }
657
658 if (R_ISREG(file_type)) {
659 TString fname(name);
660 if (is_link && fname.EndsWith(".lnk")) {
661 fname.Remove(fname.Length()-4);
662 }
663 *pic = fClient->GetMimeTypeList()->GetIcon(fname.Data(), kTRUE);
664 *lpic = fClient->GetMimeTypeList()->GetIcon(fname.Data(), kFALSE);
665
666 if (*pic) {
667 if (!*lpic) *lpic = *pic;
668 if (ext) {
669 cached_ext = ext;
670 cached_spic = *pic;
671 cached_lpic = *lpic;
672 if (!is_link) return;
673 }
674 }
675 } else {
676 *pic = 0;
677 }
678
679 if (*pic == 0) {
680 *pic = fDoc_t;
681 *lpic = fDoc_s;
682
683 if (R_ISREG(file_type) && (file_type) & kS_IXUSR) {
684 *pic = fApp_t;
685 *lpic = fApp_s;
686 }
687 if (R_ISDIR(file_type)) {
688 *pic = fFolder_t;
689 *lpic = fFolder_s;
690 }
691 }
692 if (is_link) {
693 TImage *img1, *img2;
694 if (*pic && *lpic) {
695 TString lnk_name;
696 img1 = TImage::Create();
697 if (img1) {
698 img1->SetImage(((const TGPicture *)*pic)->GetPicture(),
699 ((const TGPicture *)*pic)->GetMask());
700 img2 = TImage::Open("slink_t.xpm");
701 if (img2) img1->Merge(img2);
702 lnk_name = ((const TGPicture *)*pic)->GetName();
703 lnk_name.Prepend("lnk_");
704 *pic = fClient->GetPicturePool()->GetPicture(lnk_name.Data(),
705 img1->GetPixmap(), img1->GetMask());
706 fCleanups->Add(((TObject *)*pic));
707 if (img2) delete img2;
708 delete img1;
709 }
710 img1 = TImage::Create();
711 if (img1) {
712 img1->SetImage(((const TGPicture *)*lpic)->GetPicture(),
713 ((const TGPicture *)*lpic)->GetMask());
714 img2 = TImage::Open("slink_s.xpm");
715 if (img2) img1->Merge(img2);
716 lnk_name = ((const TGPicture *)*lpic)->GetName();
717 lnk_name.Prepend("lnk_");
718 *lpic = fClient->GetPicturePool()->GetPicture(lnk_name.Data(),
719 img1->GetPixmap(), img1->GetMask());
720 fCleanups->Add(((TObject *)*lpic));
721 if (img2) delete img2;
722 delete img1;
723 }
724 }
725 else {
726 *pic = fSlink_t;
727 *lpic = fSlink_s;
728 }
729 }
730
731 cached_lpic = 0;
732 cached_spic = 0;
733 cached_ext = "";
734}
735
736////////////////////////////////////////////////////////////////////////////////
737/// Change current directory.
738
740{
741 TString savdir = gSystem->WorkingDirectory();
742 gSystem->ChangeDirectory(fDirectory.Data()); // so path of ".." will work
743 char *exppath = gSystem->ExpandPathName(path);
744 if (gSystem->ChangeDirectory(exppath)) {
746 gSystem->ChangeDirectory(savdir.Data());
748 }
749 delete[] exppath;
750}
751
752////////////////////////////////////////////////////////////////////////////////
753/// Display the contents of the current directory in the container.
754/// This can be used to refresh the contents of the window.
755
757{
758 RemoveAll();
760
761 // This automatically calls layout
763
764 // Make TGExplorerMainFrame display total objects in status bar
767
769}
770
771////////////////////////////////////////////////////////////////////////////////
772/// This function creates the file list from current dir.
773
775{
776 TString savdir = gSystem->WorkingDirectory();
777 if (!gSystem->ChangeDirectory(fDirectory.Data())) return;
778
779 FileStat_t sbuf;
780 if (gSystem->GetPathInfo(".", sbuf) == 0)
781 fMtime = sbuf.fMtime;
782
783 void *dirp;
784 if ((dirp = gSystem->OpenDirectory(".")) == 0) {
785 gSystem->ChangeDirectory(savdir.Data());
786 return;
787 }
788
789 const char *name;
790 while ((name = gSystem->GetDirEntry(dirp)) != 0 && fDisplayStat) {
791 if (strcmp(name, ".") && strcmp(name, ".."))
792 AddFile(name);
794 }
795 gSystem->FreeDirectory(dirp);
796
797 gSystem->ChangeDirectory(savdir.Data());
798}
799
800////////////////////////////////////////////////////////////////////////////////
801/// Add file in container.
802
804 const TGPicture *ilpic)
805{
807 TGFileItem *item = 0;
808 const TGPicture *spic, *slpic;
809 TGPicture *pic, *lpic;
810
811 FileStat_t sbuf;
812
813 if (gSystem->GetPathInfo(name, sbuf)) {
814 if (sbuf.fIsLink) {
815 Info("AddFile", "Broken symlink of %s.", name);
816 } else {
817 TString msg;
818 msg.Form("Can't read file attributes of \"%s\": %s.",
819 name, gSystem->GetError());
821 "Error", msg.Data(), kMBIconStop, kMBOk);
822 }
823 return item;
824 }
825
826 filename = name;
827 if (R_ISDIR(sbuf.fMode) || fFilter == 0 ||
828 (fFilter && filename.Index(*fFilter) != kNPOS)) {
829
830 if (ipic && ilpic) { // dynamic icons
831 spic = ipic;
832 slpic = ilpic;
833 } else {
834 GetFilePictures(&spic, &slpic, sbuf.fMode, sbuf.fIsLink, name, kTRUE);
835 }
836
837 pic = (TGPicture*)spic; pic->AddReference();
838 lpic = (TGPicture*)slpic; lpic->AddReference();
839
840 item = new TGFileItem(this, lpic, slpic, spic, pic,
842 sbuf, fViewMode);
843 AddItem(item);
844 }
845
846 return item;
847}
848
849////////////////////////////////////////////////////////////////////////////////
850/// Add remote file in container.
851
853 const TGPicture *ilpic)
854{
856 TGFileItem *item = 0;
857 const TGPicture *spic, *slpic;
858 TGPicture *pic, *lpic;
859
860 FileStat_t sbuf;
861
862 TRemoteObject *robj = (TRemoteObject *)obj;
863
864 robj->GetFileStat(&sbuf);
865 filename = robj->GetName();
866
867 if (R_ISDIR(sbuf.fMode) || fFilter == 0 ||
868 (fFilter && filename.Index(*fFilter) != kNPOS)) {
869
870 if (ipic && ilpic) { // dynamic icons
871 spic = ipic;
872 slpic = ilpic;
873 } else {
874 GetFilePictures(&spic, &slpic, sbuf.fMode, sbuf.fIsLink, filename, kTRUE);
875 }
876
877 pic = (TGPicture*)spic; pic->AddReference();
878 lpic = (TGPicture*)slpic; lpic->AddReference();
879
880 item = new TGFileItem(this, lpic, slpic, spic, pic, new TGString(filename),
881 sbuf, fViewMode);
882 AddItem(item);
883 }
884 return item;
885}
886
887////////////////////////////////////////////////////////////////////////////////
888/// stop refresh timer
889
891{
892 if (fRefresh) delete fRefresh;
893 fRefresh = 0;
894}
895
896////////////////////////////////////////////////////////////////////////////////
897/// start refreshing
898
900{
901 fRefresh = new TViewUpdateTimer(this, msec);
903}
904
905////////////////////////////////////////////////////////////////////////////////
906/// Save a file container widget as a C++ statement(s) on output stream out.
907
908void TGFileContainer::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
909{
911
912 char quote = '"';
913 out << std::endl << " // container frame" << std::endl;
914 out << " TGFileContainer *";
915
916 if ((fParent->GetParent())->InheritsFrom(TGCanvas::Class())) {
917 out << GetName() << " = new TGFileContainer(" << GetCanvas()->GetName();
918 } else {
919 out << GetName() << " = new TGFileContainer(" << fParent->GetName();
920 out << "," << GetWidth() << "," << GetHeight();
921 }
922
924 if (GetOptions() == kSunkenFrame) {
925 out <<");" << std::endl;
926 } else {
927 out << "," << GetOptionString() <<");" << std::endl;
928 }
929 } else {
930 out << "," << GetOptionString() << ",ucolor);" << std::endl;
931 }
932 if (option && strstr(option, "keep_names"))
933 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
934 out << " " << GetCanvas()->GetName() << "->SetContainer("
935 << GetName() << ");" << std::endl;
936 out << " " << GetName() << "->DisplayDirectory();" << std::endl;
937 out << " " << GetName() << "->AddFile("<< quote << ".." << quote << ");" << std::endl;
938 out << " " << GetName() << "->StopRefreshTimer();" << std::endl;
939}
Handle_t Atom_t
WM token.
Definition GuiTypes.h:37
@ kChildFrame
Definition GuiTypes.h:379
@ kSunkenFrame
Definition GuiTypes.h:383
const Handle_t kNone
Definition GuiTypes.h:88
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#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
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:124
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
unsigned long ULong_t
Definition RtypesCore.h:55
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:230
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:197
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:110
Bool_t R_ISFIFO(Int_t mode)
Definition TSystem.h:120
Bool_t R_ISSOCK(Int_t mode)
Definition TSystem.h:121
Bool_t R_ISBLK(Int_t mode)
Definition TSystem.h:117
Bool_t R_ISREG(Int_t mode)
Definition TSystem.h:118
Bool_t R_ISLNK(Int_t mode)
Definition TSystem.h:119
Bool_t R_ISDIR(Int_t mode)
Definition TSystem.h:115
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
Bool_t R_ISCHR(Int_t mode)
Definition TSystem.h:116
@ kS_IRGRP
Definition TSystem.h:106
@ kS_IWUSR
Definition TSystem.h:103
@ kS_ISUID
Definition TSystem.h:98
@ kS_IRUSR
Definition TSystem.h:102
@ kS_IXOTH
Definition TSystem.h:112
@ kS_ISGID
Definition TSystem.h:99
@ kS_IROTH
Definition TSystem.h:110
@ kS_IWGRP
Definition TSystem.h:107
@ kS_IXUSR
Definition TSystem.h:104
@ kS_ISVTX
Definition TSystem.h:100
@ kS_IWOTH
Definition TSystem.h:111
@ kS_IXGRP
Definition TSystem.h:108
#define gVirtualX
Definition TVirtualX.h:338
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kCT_SELCHANGED
@ kC_CONTAINER
#define free
Definition civetweb.c:1539
#define calloc
Definition civetweb.c:1537
#define snprintf
Definition civetweb.c:1540
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:146
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:372
TGPicturePool * GetPicturePool() const
Definition TGClient.h:126
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:308
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
TList * fList
container of frame elements
Definition TGFrame.h:292
static TGLayoutHints * fgDefaultHints
Definition TGFrame.h:297
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:641
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
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 ~TGFileContainer()
Delete list view file container.
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.
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
virtual ~TGFileItem()
Destructor.
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:709
UInt_t fHeight
frame height
Definition TGFrame.h:88
Bool_t IsDNDTarget() const
Definition TGFrame.h:273
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:683
virtual UInt_t GetOptions() const
Definition TGFrame.h:197
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2506
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:645
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:225
UInt_t GetWidth() const
Definition TGFrame.h:224
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2479
Pixel_t fBackground
frame background color
Definition TGFrame.h:95
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:775
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:82
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:152
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:129
const TGWindow * GetParent() const
Definition TGWindow.h:83
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
An abstract interface to image processing library.
Definition TImage.h:29
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:118
static TImage * Create()
Create an image.
Definition TImage.cxx:35
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition TImage.h:172
virtual Pixmap_t GetPixmap()
Definition TImage.h:235
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=nullptr)
Definition TImage.h:116
virtual Pixmap_t GetMask()
Definition TImage.h:236
A doubly linked list.
Definition TList.h:38
void Clear(Option_t *option="") override
Remove all objects from the list.
Definition TList.cxx:402
void Add(TObject *obj) override
Definition TList.h:81
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition TList.cxx:937
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
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:139
Ssiz_t Length() const
Definition TString.h:421
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2222
const char * Data() const
Definition TString.h:380
TString & Prepend(const char *cs)
Definition TString.h:673
TString & Remove(Ssiz_t pos)
Definition TString.h:685
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:2356
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2334
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1277
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:848
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition TSystem.cxx:839
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:1401
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition TSystem.cxx:856
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition TSystem.cxx:865
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:937
virtual const char * WorkingDirectory()
Return working directory.
Definition TSystem.cxx:874
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:253
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition TSystem.cxx:1602
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:159
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:127
Long64_t fSize
Definition TSystem.h:130
Int_t fGid
Definition TSystem.h:129
Long_t fMtime
Definition TSystem.h:131
Bool_t fIsLink
Definition TSystem.h:132
Int_t fUid
Definition TSystem.h:128
TString fUser
Definition TSystem.h:141
TString fGroup
Definition TSystem.h:142
TLine l
Definition textangle.C:4