1 /*
2 * Part of WCM Commander
3 * https://github.com/corporateshark/WCMCommander
4 * wcm@linderdaum.com
5 */
6
7 #include "dlg-ctrl-l.h"
8 #include "ltext.h"
9 #include "string-util.h"
10
11 class DirCtrlL: public NCDialog
12 {
13 Layout lo;
14 ccollect< clPtr<Win> > list;
15 int row;
16 void PutLabel( const char* s );
17 void PutValue( const char* name, const char* value );
18 void PutValue( const char* name, const unicode_t* value );
19 void PutSpace( int height );
20 public:
DirCtrlL(NCDialogParent * parent,FSStatVfs & statVfs)21 DirCtrlL( NCDialogParent* parent, FSStatVfs& statVfs )
22 : NCDialog( ::createDialogAsChild, 0, parent, utf8_to_unicode( _LT( "Information" ) ).data(), bListOk ),
23 lo( 50, 5 ),
24 row( 0 )
25 {
26 //PutLabel( _LT("Information") );
27
28 char hostName[0x100] = "";
29 gethostname( hostName, sizeof( hostName ) );
30 PutValue( _LT( "Computer name" ), hostName );
31
32 #ifdef _WIN32
33 #define BUFLEN (0x100)
34 wchar_t buf[BUFLEN];
35 DWORD l = BUFLEN - 1;
36
37 if ( !GetUserNameW( buf, &l ) ) { buf[0] = 0; }
38
39 unicode_t u[BUFLEN];
40 int i;
41
42 for ( i = 0; i < BUFLEN - 1 && buf[i]; i++ )
43 {
44 u[i] = buf[i];
45 }
46
47 u[i] = 0;
48 #undef BUFLEN
49 PutValue( _LT( "User name" ), u );
50 #else
51 {
52 const char* user = getenv( "USER" );
53
54 if ( user )
55 {
56 PutValue( _LT( "User name" ), user );
57 }
58
59 }
60 #endif
61 PutSpace( 10 );
62 PutLabel( _LT( "Disk" ) );
63 PutValue( _LT( "Total bytes" ), ToStringGrouped( statVfs.size ).c_str() );
64 PutValue( _LT( "Free bytes" ), ToStringGrouped(statVfs.avail ).c_str() );
65 PutSpace( 10 );
66
67 #ifdef _WIN32
68 SYSTEM_INFO si;
69 GetNativeSystemInfo( &si );
70 PutLabel( _LT( "System info" ) );
71 {
72 const char* pt = "";
73
74 switch ( si.wProcessorArchitecture )
75 {
76 case 0:
77 pt = "x86";
78 break;
79
80 case 6:
81 pt = "IA64";
82 break;
83
84 case 9:
85 pt = "x64";
86 break;
87 }
88
89 char buf[0x100];
90 Lsnprintf( buf, sizeof( buf ), "%s (%i)", pt, int( si.dwNumberOfProcessors ) );
91 PutValue( _LT( "Processor" ), buf );
92 }
93
94 MEMORYSTATUSEX ms;
95 ms.dwLength = sizeof( ms );
96
97 if ( GlobalMemoryStatusEx( &ms ) )
98 {
99 PutSpace( 5 );
100 PutValue( _LT( "Total physical memory" ), ToStringGrouped( ms.ullTotalPhys ).c_str() );
101 PutValue( _LT( "Free physical memory" ), ToStringGrouped( ms.ullAvailPhys ).c_str() );
102 PutSpace( 5 );
103 PutValue( _LT( "Total paging file" ), ToStringGrouped( ms.ullTotalPageFile ).c_str() );
104 PutValue( _LT( "Free paging file" ), ToStringGrouped( ms.ullAvailPageFile ).c_str() );
105 }
106
107 #else
108 #endif
109
110 lo.ColSet( 0, 20 );
111 lo.ColSet( 2, 10 );
112 lo.ColSet( 4, 20 );
113 lo.SetColGrowth( 4 );
114 lo.SetColGrowth( 0 );
115
116 this->AddLayout( &lo );
117 this->SetEnterCmd( CMD_OK );
118 SetPosition();
119 }
120
121 bool Key( cevent_key* pEvent );
122 virtual bool EventKey( cevent_key* pEvent );
123 virtual bool EventChildKey( Win* child, cevent_key* pEvent );
124 virtual ~DirCtrlL();
125 };
126
PutLabel(const char * s)127 void DirCtrlL::PutLabel( const char* s )
128 {
129 int n = row;
130 clPtr<Win> win = new StaticLine( 0, this, utf8_to_unicode( s ).data() );
131 lo.AddWin( win.ptr(), n, 0, n, 4, Layout::CENTER );
132 win->Show();
133 win->Enable();
134 list.append( win );
135 row++;
136 }
137
PutValue(const char * name,const char * value)138 void DirCtrlL::PutValue( const char* name, const char* value )
139 {
140 int n = row;
141 clPtr<Win> win = new StaticLine( uiVariable, this, utf8_to_unicode( name ).data() );
142 lo.AddWin( win.ptr(), n, 1 );
143 win->Show();
144 win->Enable();
145 list.append( win );
146
147 win = new StaticLine( uiValue, this, utf8_to_unicode( value ).data() );
148 lo.AddWin( win.ptr(), n, 3, n, 3, Layout::RIGHT );
149 win->Show();
150 win->Enable();
151 list.append( win );
152 row++;
153 }
154
PutValue(const char * name,const unicode_t * value)155 void DirCtrlL::PutValue( const char* name, const unicode_t* value )
156 {
157 int n = row;
158 clPtr<Win> win = new StaticLine( uiVariable, this, utf8_to_unicode( name ).data() );
159 lo.AddWin( win.ptr(), n, 1 );
160 win->Show();
161 win->Enable();
162 list.append( win );
163
164 win = new StaticLine( uiValue, this, value );
165 lo.AddWin( win.ptr(), n, 3, n, 3, Layout::RIGHT );
166 win->Show();
167 win->Enable();
168 list.append( win );
169 row++;
170 }
171
PutSpace(int height)172 void DirCtrlL::PutSpace( int height )
173 {
174 lo.LineSet( row, height );
175 row++;
176 }
177
Key(cevent_key * pEvent)178 bool DirCtrlL::Key( cevent_key* pEvent )
179 {
180 if ( pEvent->Type() == EV_KEYDOWN )
181 {
182 if ( pEvent->Key() == VK_L && pEvent->Mod() == KM_CTRL )
183 {
184 EndModal( CMD_OK );
185 return true;
186 }
187 }
188
189 return false;
190 }
191
192
EventKey(cevent_key * pEvent)193 bool DirCtrlL::EventKey( cevent_key* pEvent )
194 {
195 if ( Key( pEvent ) ) { return true; }
196
197 return NCDialog::EventKey( pEvent );
198 }
199
EventChildKey(Win * child,cevent_key * pEvent)200 bool DirCtrlL::EventChildKey( Win* child, cevent_key* pEvent )
201 {
202 if ( Key( pEvent ) ) { return true; }
203
204 return NCDialog::EventChildKey( child, pEvent );
205 }
206
~DirCtrlL()207 DirCtrlL::~DirCtrlL()
208 {
209 }
210
DoCtrlLDialog(NCDialogParent * parent,FSStatVfs statVfs)211 void DoCtrlLDialog( NCDialogParent* parent, FSStatVfs statVfs )
212 {
213 DirCtrlL dlg( parent, statVfs );
214 dlg.Enable();
215 dlg.Show();
216 ( void )dlg.DoModal();
217 }
218