1 //------------------------------------------------------------------------------
2 // emDirStatPanel.cpp
3 //
4 // Copyright (C) 2007-2008,2010,2016,2020 Oliver Hamann.
5 //
6 // Homepage: http://eaglemode.sourceforge.net/
7 //
8 // This program is free software: you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License version 3 as published by the
10 // Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License version 3
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //------------------------------------------------------------------------------
20
21 #include <emFileMan/emDirStatPanel.h>
22
23
emDirStatPanel(ParentArg parent,const emString & name,emDirModel * fileModel,bool updateFileModel)24 emDirStatPanel::emDirStatPanel(
25 ParentArg parent, const emString & name, emDirModel * fileModel,
26 bool updateFileModel
27 )
28 : emFilePanel(parent,name)
29 {
30 AddWakeUpSignal(GetVirFileStateSignal());
31 SetFileModel(fileModel,updateFileModel);
32 Config=emFileManViewConfig::Acquire(GetView());
33 TotalCount=-1;
34 FileCount=-1;
35 SubDirCount=-1;
36 OtherTypeCount=-1;
37 HiddenCount=-1;
38
39 AddWakeUpSignal(Config->GetChangeSignal());
40 }
41
42
SetFileModel(emFileModel * fileModel,bool updateFileModel)43 void emDirStatPanel::SetFileModel(emFileModel * fileModel, bool updateFileModel)
44 {
45 if (fileModel && (dynamic_cast<emDirModel*>(fileModel))==NULL) {
46 fileModel=NULL;
47 }
48 emFilePanel::SetFileModel(fileModel,updateFileModel);
49 }
50
51
Cycle()52 bool emDirStatPanel::Cycle()
53 {
54 bool busy;
55
56 busy=emFilePanel::Cycle();
57 if (IsSignaled(GetVirFileStateSignal())) {
58 UpdateStatistics();
59 InvalidatePainting();
60 }
61 if (IsSignaled(Config->GetChangeSignal())) {
62 InvalidatePainting();
63 }
64 return busy;
65 }
66
67
IsOpaque() const68 bool emDirStatPanel::IsOpaque() const
69 {
70 if (GetVirFileState()!=VFS_LOADED) return emFilePanel::IsOpaque();
71 return Config->GetTheme().BackgroundColor.Get().IsOpaque();
72 }
73
74
Paint(const emPainter & painter,emColor canvasColor) const75 void emDirStatPanel::Paint(const emPainter & painter, emColor canvasColor) const
76 {
77 char tmp[1024];
78
79 if (GetVirFileState()!=VFS_LOADED) {
80 emFilePanel::Paint(painter,canvasColor);
81 return;
82 }
83
84 painter.Clear(Config->GetTheme().BackgroundColor.Get());
85
86 sprintf(tmp,
87 "Directory Statistics\n"
88 "~~~~~~~~~~~~~~~~~~~~\n"
89 "\n"
90 "Total Entries : %5d\n"
91 "\n"
92 "Hidden Entries: %5d\n"
93 "\n"
94 "Regular Files : %5d\n"
95 "Subdirectories: %5d\n"
96 "Other Types : %5d",
97 TotalCount,
98 HiddenCount,
99 FileCount,
100 SubDirCount,
101 OtherTypeCount
102 );
103 painter.PaintTextBoxed(
104 0.02, 0.02,
105 1.0-0.04, GetHeight()-0.04,
106 tmp,
107 GetHeight(),
108 Config->GetTheme().DirNameColor,
109 canvasColor
110 );
111 }
112
113
UpdateStatistics()114 void emDirStatPanel::UpdateStatistics()
115 {
116 const emDirEntry * de;
117 const emDirModel * dm;
118 int i;
119
120 if (GetVirFileState()==VFS_LOADED) {
121 dm=(const emDirModel*)GetFileModel();
122 TotalCount=dm->GetEntryCount();
123 FileCount=0;
124 SubDirCount=0;
125 OtherTypeCount=0;
126 HiddenCount=0;
127 for (i=0; i<TotalCount; i++) {
128 de=&dm->GetEntry(i);
129 if (de->IsRegularFile()) FileCount++;
130 else if (de->IsDirectory()) SubDirCount++;
131 else OtherTypeCount++;
132 if (de->IsHidden()) HiddenCount++;
133 }
134 }
135 else {
136 TotalCount=-1;
137 FileCount=-1;
138 SubDirCount=-1;
139 OtherTypeCount=-1;
140 HiddenCount=-1;
141 }
142 }
143