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