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