Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
da23c8c5
Commit
da23c8c5
authored
Mar 09, 2008
by
Hisham Muhammad
Browse files
Clean up headers by using 'static' whenever possible.
Reduces resulting code size.
parent
12f4f09e
Changes
64
Hide whitespace changes
Inline
Side-by-side
AffinityPanel.c
View file @
da23c8c5
...
...
@@ -7,6 +7,23 @@
#include "debug.h"
#include <assert.h>
static
HandlerResult
AffinityPanel_eventHandler
(
Panel
*
this
,
int
ch
)
{
HandlerResult
result
=
IGNORED
;
CheckItem
*
selected
=
(
CheckItem
*
)
Panel_getSelected
(
this
);
switch
(
ch
)
{
case
' '
:
CheckItem_set
(
selected
,
!
(
CheckItem_get
(
selected
))
);
result
=
HANDLED
;
break
;
case
0x0a
:
case
0x0d
:
case
KEY_ENTER
:
result
=
BREAK_LOOP
;
break
;
}
return
result
;
}
Panel
*
AffinityPanel_new
(
int
processorCount
,
unsigned
long
mask
)
{
Panel
*
this
=
Panel_new
(
1
,
1
,
1
,
1
,
CHECKITEM_CLASS
,
true
,
ListItem_compare
);
this
->
eventHandler
=
AffinityPanel_eventHandler
;
...
...
@@ -29,20 +46,3 @@ unsigned long AffinityPanel_getAffinity(Panel* this) {
}
return
mask
;
}
HandlerResult
AffinityPanel_eventHandler
(
Panel
*
this
,
int
ch
)
{
HandlerResult
result
=
IGNORED
;
CheckItem
*
selected
=
(
CheckItem
*
)
Panel_getSelected
(
this
);
switch
(
ch
)
{
case
' '
:
CheckItem_set
(
selected
,
!
(
CheckItem_get
(
selected
))
);
result
=
HANDLED
;
break
;
case
0x0a
:
case
0x0d
:
case
KEY_ENTER
:
result
=
BREAK_LOOP
;
break
;
}
return
result
;
}
AffinityPanel.h
View file @
da23c8c5
...
...
@@ -14,6 +14,4 @@ Panel* AffinityPanel_new(int processorCount, unsigned long mask);
unsigned
long
AffinityPanel_getAffinity
(
Panel
*
this
);
HandlerResult
AffinityPanel_eventHandler
(
Panel
*
this
,
int
ch
);
#endif
AvailableColumnsPanel.c
View file @
da23c8c5
...
...
@@ -22,34 +22,14 @@ typedef struct AvailableColumnsPanel_ {
}*/
AvailableColumnsPanel
*
AvailableColumnsPanel_new
(
Settings
*
settings
,
Panel
*
columns
,
ScreenManager
*
scr
)
{
AvailableColumnsPanel
*
this
=
(
AvailableColumnsPanel
*
)
malloc
(
sizeof
(
AvailableColumnsPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
AvailableColumnsPanel_delete
;
this
->
settings
=
settings
;
this
->
scr
=
scr
;
super
->
eventHandler
=
AvailableColumnsPanel_eventHandler
;
Panel_setHeader
(
super
,
"Available Columns"
);
for
(
int
i
=
1
;
i
<
LAST_PROCESSFIELD
;
i
++
)
{
if
(
i
!=
COMM
)
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
Process_fieldNames
[
i
],
0
));
}
this
->
columns
=
columns
;
return
this
;
}
void
AvailableColumnsPanel_delete
(
Object
*
object
)
{
static
void
AvailableColumnsPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
AvailableColumnsPanel
*
this
=
(
AvailableColumnsPanel
*
)
object
;
Panel_done
(
super
);
free
(
this
);
}
HandlerResult
AvailableColumnsPanel_eventHandler
(
Panel
*
super
,
int
ch
)
{
static
HandlerResult
AvailableColumnsPanel_eventHandler
(
Panel
*
super
,
int
ch
)
{
AvailableColumnsPanel
*
this
=
(
AvailableColumnsPanel
*
)
super
;
char
*
text
=
((
ListItem
*
)
Panel_getSelected
(
super
))
->
value
;
HandlerResult
result
=
IGNORED
;
...
...
@@ -69,3 +49,23 @@ HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
}
return
result
;
}
AvailableColumnsPanel
*
AvailableColumnsPanel_new
(
Settings
*
settings
,
Panel
*
columns
,
ScreenManager
*
scr
)
{
AvailableColumnsPanel
*
this
=
(
AvailableColumnsPanel
*
)
malloc
(
sizeof
(
AvailableColumnsPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
AvailableColumnsPanel_delete
;
this
->
settings
=
settings
;
this
->
scr
=
scr
;
super
->
eventHandler
=
AvailableColumnsPanel_eventHandler
;
Panel_setHeader
(
super
,
"Available Columns"
);
for
(
int
i
=
1
;
i
<
LAST_PROCESSFIELD
;
i
++
)
{
if
(
i
!=
COMM
)
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
Process_fieldNames
[
i
],
0
));
}
this
->
columns
=
columns
;
return
this
;
}
AvailableColumnsPanel.h
View file @
da23c8c5
...
...
@@ -25,8 +25,4 @@ typedef struct AvailableColumnsPanel_ {
AvailableColumnsPanel
*
AvailableColumnsPanel_new
(
Settings
*
settings
,
Panel
*
columns
,
ScreenManager
*
scr
);
void
AvailableColumnsPanel_delete
(
Object
*
object
);
HandlerResult
AvailableColumnsPanel_eventHandler
(
Panel
*
super
,
int
ch
);
#endif
AvailableMetersPanel.c
View file @
da23c8c5
...
...
@@ -23,41 +23,7 @@ typedef struct AvailableMetersPanel_ {
}*/
AvailableMetersPanel
*
AvailableMetersPanel_new
(
Settings
*
settings
,
Panel
*
leftMeters
,
Panel
*
rightMeters
,
ScreenManager
*
scr
)
{
AvailableMetersPanel
*
this
=
(
AvailableMetersPanel
*
)
malloc
(
sizeof
(
AvailableMetersPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
AvailableMetersPanel_delete
;
this
->
settings
=
settings
;
this
->
leftPanel
=
leftMeters
;
this
->
rightPanel
=
rightMeters
;
this
->
scr
=
scr
;
super
->
eventHandler
=
AvailableMetersPanel_EventHandler
;
Panel_setHeader
(
super
,
"Available meters"
);
for
(
int
i
=
1
;
Meter_types
[
i
];
i
++
)
{
MeterType
*
type
=
Meter_types
[
i
];
if
(
type
!=
&
CPUMeter
)
{
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
type
->
uiName
,
i
<<
16
));
}
}
MeterType
*
type
=
&
CPUMeter
;
int
processors
=
settings
->
pl
->
processorCount
;
if
(
processors
>
1
)
{
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"CPU average"
,
0
));
for
(
int
i
=
1
;
i
<=
processors
;
i
++
)
{
char
buffer
[
50
];
sprintf
(
buffer
,
"%s %d"
,
type
->
uiName
,
i
);
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
buffer
,
i
));
}
}
else
{
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"CPU"
,
1
));
}
return
this
;
}
void
AvailableMetersPanel_delete
(
Object
*
object
)
{
static
void
AvailableMetersPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
AvailableMetersPanel
*
this
=
(
AvailableMetersPanel
*
)
object
;
Panel_done
(
super
);
...
...
@@ -69,7 +35,7 @@ static inline void AvailableMetersPanel_addHeader(Header* header, Panel* panel,
Panel_add
(
panel
,
(
Object
*
)
Meter_toListItem
(
meter
));
}
HandlerResult
AvailableMetersPanel_
E
ventHandler
(
Panel
*
super
,
int
ch
)
{
static
HandlerResult
AvailableMetersPanel_
e
ventHandler
(
Panel
*
super
,
int
ch
)
{
AvailableMetersPanel
*
this
=
(
AvailableMetersPanel
*
)
super
;
Header
*
header
=
this
->
settings
->
header
;
...
...
@@ -104,3 +70,37 @@ HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch) {
}
return
result
;
}
AvailableMetersPanel
*
AvailableMetersPanel_new
(
Settings
*
settings
,
Panel
*
leftMeters
,
Panel
*
rightMeters
,
ScreenManager
*
scr
)
{
AvailableMetersPanel
*
this
=
(
AvailableMetersPanel
*
)
malloc
(
sizeof
(
AvailableMetersPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
AvailableMetersPanel_delete
;
this
->
settings
=
settings
;
this
->
leftPanel
=
leftMeters
;
this
->
rightPanel
=
rightMeters
;
this
->
scr
=
scr
;
super
->
eventHandler
=
AvailableMetersPanel_eventHandler
;
Panel_setHeader
(
super
,
"Available meters"
);
for
(
int
i
=
1
;
Meter_types
[
i
];
i
++
)
{
MeterType
*
type
=
Meter_types
[
i
];
if
(
type
!=
&
CPUMeter
)
{
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
type
->
uiName
,
i
<<
16
));
}
}
MeterType
*
type
=
&
CPUMeter
;
int
processors
=
settings
->
pl
->
processorCount
;
if
(
processors
>
1
)
{
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"CPU average"
,
0
));
for
(
int
i
=
1
;
i
<=
processors
;
i
++
)
{
char
buffer
[
50
];
sprintf
(
buffer
,
"%s %d"
,
type
->
uiName
,
i
);
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
buffer
,
i
));
}
}
else
{
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"CPU"
,
1
));
}
return
this
;
}
AvailableMetersPanel.h
View file @
da23c8c5
...
...
@@ -26,8 +26,4 @@ typedef struct AvailableMetersPanel_ {
AvailableMetersPanel
*
AvailableMetersPanel_new
(
Settings
*
settings
,
Panel
*
leftMeters
,
Panel
*
rightMeters
,
ScreenManager
*
scr
);
void
AvailableMetersPanel_delete
(
Object
*
object
);
HandlerResult
AvailableMetersPanel_EventHandler
(
Panel
*
super
,
int
ch
);
#endif
CPUMeter.c
View file @
da23c8c5
...
...
@@ -22,33 +22,6 @@ int CPUMeter_attributes[] = {
CPU_NICE
,
CPU_NORMAL
,
CPU_KERNEL
,
CPU_IRQ
,
CPU_SOFTIRQ
,
CPU_IOWAIT
};
MeterType
CPUMeter
=
{
.
setValues
=
CPUMeter_setValues
,
.
display
=
CPUMeter_display
,
.
mode
=
BAR_METERMODE
,
.
items
=
6
,
.
total
=
100
.
0
,
.
attributes
=
CPUMeter_attributes
,
.
name
=
"CPU"
,
.
uiName
=
"CPU"
,
.
caption
=
"CPU"
,
.
init
=
CPUMeter_init
};
MeterType
AllCPUsMeter
=
{
.
mode
=
0
,
.
items
=
1
,
.
total
=
100
.
0
,
.
attributes
=
CPUMeter_attributes
,
.
name
=
"AllCPUs"
,
.
uiName
=
"All CPUs"
,
.
caption
=
"CPU"
,
.
draw
=
AllCPUsMeter_draw
,
.
init
=
AllCPUsMeter_init
,
.
setMode
=
AllCPUsMeter_setMode
,
.
done
=
AllCPUsMeter_done
};
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
...
...
@@ -56,7 +29,7 @@ MeterType AllCPUsMeter = {
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
void
CPUMeter_init
(
Meter
*
this
)
{
static
void
CPUMeter_init
(
Meter
*
this
)
{
int
processor
=
this
->
param
;
if
(
this
->
pl
->
processorCount
>
1
)
{
char
caption
[
10
];
...
...
@@ -67,7 +40,7 @@ void CPUMeter_init(Meter* this) {
Meter_setCaption
(
this
,
"Avg"
);
}
void
CPUMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
)
{
static
void
CPUMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
)
{
ProcessList
*
pl
=
this
->
pl
;
int
processor
=
this
->
param
;
double
total
=
(
double
)
pl
->
totalPeriod
[
processor
];
...
...
@@ -90,7 +63,7 @@ void CPUMeter_setValues(Meter* this, char* buffer, int size) {
snprintf
(
buffer
,
size
,
"%5.1f%%"
,
cpu
);
}
void
CPUMeter_display
(
Object
*
cast
,
RichString
*
out
)
{
static
void
CPUMeter_display
(
Object
*
cast
,
RichString
*
out
)
{
char
buffer
[
50
];
Meter
*
this
=
(
Meter
*
)
cast
;
RichString_init
(
out
);
...
...
@@ -123,7 +96,7 @@ void CPUMeter_display(Object* cast, RichString* out) {
}
}
void
AllCPUsMeter_init
(
Meter
*
this
)
{
static
void
AllCPUsMeter_init
(
Meter
*
this
)
{
int
processors
=
this
->
pl
->
processorCount
;
this
->
drawBuffer
=
malloc
(
sizeof
(
Meter
*
)
*
processors
);
Meter
**
meters
=
(
Meter
**
)
this
->
drawBuffer
;
...
...
@@ -133,21 +106,21 @@ void AllCPUsMeter_init(Meter* this) {
this
->
mode
=
BAR_METERMODE
;
}
void
AllCPUsMeter_done
(
Meter
*
this
)
{
static
void
AllCPUsMeter_done
(
Meter
*
this
)
{
int
processors
=
this
->
pl
->
processorCount
;
Meter
**
meters
=
(
Meter
**
)
this
->
drawBuffer
;
for
(
int
i
=
0
;
i
<
processors
;
i
++
)
Meter_delete
((
Object
*
)
meters
[
i
]);
}
void
AllCPUsMeter_setMode
(
Meter
*
this
,
int
mode
)
{
static
void
AllCPUsMeter_setMode
(
Meter
*
this
,
int
mode
)
{
this
->
mode
=
mode
;
int
processors
=
this
->
pl
->
processorCount
;
int
h
=
Meter_modes
[
this
->
mode
]
->
h
;
this
->
h
=
h
*
processors
;
}
void
AllCPUsMeter_draw
(
Meter
*
this
,
int
x
,
int
y
,
int
w
)
{
static
void
AllCPUsMeter_draw
(
Meter
*
this
,
int
x
,
int
y
,
int
w
)
{
int
processors
=
this
->
pl
->
processorCount
;
Meter
**
meters
=
(
Meter
**
)
this
->
drawBuffer
;
for
(
int
i
=
0
;
i
<
processors
;
i
++
)
{
...
...
@@ -156,3 +129,30 @@ void AllCPUsMeter_draw(Meter* this, int x, int y, int w) {
y
+=
meters
[
i
]
->
h
;
}
}
MeterType
CPUMeter
=
{
.
setValues
=
CPUMeter_setValues
,
.
display
=
CPUMeter_display
,
.
mode
=
BAR_METERMODE
,
.
items
=
6
,
.
total
=
100
.
0
,
.
attributes
=
CPUMeter_attributes
,
.
name
=
"CPU"
,
.
uiName
=
"CPU"
,
.
caption
=
"CPU"
,
.
init
=
CPUMeter_init
};
MeterType
AllCPUsMeter
=
{
.
mode
=
0
,
.
items
=
1
,
.
total
=
100
.
0
,
.
attributes
=
CPUMeter_attributes
,
.
name
=
"AllCPUs"
,
.
uiName
=
"All CPUs"
,
.
caption
=
"CPU"
,
.
draw
=
AllCPUsMeter_draw
,
.
init
=
AllCPUsMeter_init
,
.
setMode
=
AllCPUsMeter_setMode
,
.
done
=
AllCPUsMeter_done
};
CPUMeter.h
View file @
da23c8c5
...
...
@@ -23,10 +23,6 @@ in the source distribution for its full text.
extern
int
CPUMeter_attributes
[];
extern
MeterType
CPUMeter
;
extern
MeterType
AllCPUsMeter
;
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
...
...
@@ -34,18 +30,8 @@ extern MeterType AllCPUsMeter;
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
void
CPUMeter_init
(
Meter
*
this
);
void
CPUMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
);
void
CPUMeter_display
(
Object
*
cast
,
RichString
*
out
);
void
AllCPUsMeter_init
(
Meter
*
this
);
void
AllCPUsMeter_done
(
Meter
*
this
);
void
AllCPUsMeter_setMode
(
Meter
*
this
,
int
mode
);
extern
MeterType
CPUMeter
;
void
AllCPUsMeter_draw
(
Meter
*
this
,
int
x
,
int
y
,
int
w
)
;
extern
MeterType
AllCPUsMeter
;
#endif
CRT.c
View file @
da23c8c5
...
...
@@ -114,6 +114,17 @@ int CRT_colors[LAST_COLORELEMENT] = { 0 };
char
*
CRT_termType
;
static
void
CRT_handleSIGSEGV
(
int
signal
)
{
CRT_done
();
fprintf
(
stderr
,
"htop "
VERSION
" aborted. Please report bug at http://htop.sf.net
\n
"
);
exit
(
1
);
}
static
void
CRT_handleSIGTERM
(
int
signal
)
{
CRT_done
();
exit
(
0
);
}
// TODO: pass an instance of Settings instead.
void
CRT_init
(
int
delay
,
int
colorScheme
)
{
...
...
@@ -182,17 +193,6 @@ void CRT_enableDelay() {
halfdelay
(
CRT_delay
);
}
void
CRT_handleSIGSEGV
(
int
signal
)
{
CRT_done
();
fprintf
(
stderr
,
"htop "
VERSION
" aborted. Please report bug at http://htop.sf.net
\n
"
);
exit
(
1
);
}
void
CRT_handleSIGTERM
(
int
signal
)
{
CRT_done
();
exit
(
0
);
}
void
CRT_setColors
(
int
colorScheme
)
{
CRT_colorScheme
=
colorScheme
;
if
(
colorScheme
==
COLORSCHEME_BLACKNIGHT
)
{
...
...
CRT.h
View file @
da23c8c5
...
...
@@ -127,10 +127,6 @@ void CRT_disableDelay();
void
CRT_enableDelay
();
void
CRT_handleSIGSEGV
(
int
signal
);
void
CRT_handleSIGTERM
(
int
signal
);
void
CRT_setColors
(
int
colorScheme
);
#endif
CategoriesPanel.c
View file @
da23c8c5
...
...
@@ -35,31 +35,40 @@ static char* ColorsFunctions[10] = {" ", " ", " ", " ", "
static
char
*
AvailableColumnsFunctions
[
10
]
=
{
" "
,
" "
,
" "
,
" "
,
"Add "
,
" "
,
" "
,
" "
,
" "
,
"Done "
};
CategoriesPanel
*
CategoriesPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
)
{
CategoriesPanel
*
this
=
(
CategoriesPanel
*
)
malloc
(
sizeof
(
CategoriesPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
CategoriesPanel_delete
;
this
->
settings
=
settings
;
this
->
scr
=
scr
;
super
->
eventHandler
=
CategoriesPanel_eventHandler
;
Panel_setHeader
(
super
,
"Setup"
);
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"Meters"
,
0
));
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"Display options"
,
0
));
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"Colors"
,
0
));
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"Columns"
,
0
));
return
this
;
}
void
CategoriesPanel_delete
(
Object
*
object
)
{
static
void
CategoriesPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
CategoriesPanel
*
this
=
(
CategoriesPanel
*
)
object
;
Panel_done
(
super
);
free
(
this
);
}
HandlerResult
CategoriesPanel_eventHandler
(
Panel
*
super
,
int
ch
)
{
void
CategoriesPanel_makeMetersPage
(
CategoriesPanel
*
this
)
{
Panel
*
leftMeters
=
(
Panel
*
)
MetersPanel_new
(
this
->
settings
,
"Left column"
,
this
->
settings
->
header
->
leftMeters
,
this
->
scr
);
Panel
*
rightMeters
=
(
Panel
*
)
MetersPanel_new
(
this
->
settings
,
"Right column"
,
this
->
settings
->
header
->
rightMeters
,
this
->
scr
);
Panel
*
availableMeters
=
(
Panel
*
)
AvailableMetersPanel_new
(
this
->
settings
,
leftMeters
,
rightMeters
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
leftMeters
,
FunctionBar_new
(
10
,
MetersFunctions
,
NULL
,
NULL
),
20
);
ScreenManager_add
(
this
->
scr
,
rightMeters
,
FunctionBar_new
(
10
,
MetersFunctions
,
NULL
,
NULL
),
20
);
ScreenManager_add
(
this
->
scr
,
availableMeters
,
FunctionBar_new
(
10
,
AvailableMetersFunctions
,
NULL
,
NULL
),
-
1
);
}
static
void
CategoriesPanel_makeDisplayOptionsPage
(
CategoriesPanel
*
this
)
{
Panel
*
displayOptions
=
(
Panel
*
)
DisplayOptionsPanel_new
(
this
->
settings
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
displayOptions
,
FunctionBar_new
(
10
,
DisplayOptionsFunctions
,
NULL
,
NULL
),
-
1
);
}
static
void
CategoriesPanel_makeColorsPage
(
CategoriesPanel
*
this
)
{
Panel
*
colors
=
(
Panel
*
)
ColorsPanel_new
(
this
->
settings
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
colors
,
FunctionBar_new
(
10
,
ColorsFunctions
,
NULL
,
NULL
),
-
1
);
}
static
void
CategoriesPanel_makeColumnsPage
(
CategoriesPanel
*
this
)
{
Panel
*
columns
=
(
Panel
*
)
ColumnsPanel_new
(
this
->
settings
,
this
->
scr
);
Panel
*
availableColumns
=
(
Panel
*
)
AvailableColumnsPanel_new
(
this
->
settings
,
columns
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
columns
,
FunctionBar_new
(
10
,
ColumnsFunctions
,
NULL
,
NULL
),
20
);
ScreenManager_add
(
this
->
scr
,
availableColumns
,
FunctionBar_new
(
10
,
AvailableColumnsFunctions
,
NULL
,
NULL
),
-
1
);
}
static
HandlerResult
CategoriesPanel_eventHandler
(
Panel
*
super
,
int
ch
)
{
CategoriesPanel
*
this
=
(
CategoriesPanel
*
)
super
;
HandlerResult
result
=
IGNORED
;
...
...
@@ -107,28 +116,19 @@ HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
return
result
;
}
void
CategoriesPanel_makeMetersPage
(
CategoriesPanel
*
this
)
{
Panel
*
leftMeters
=
(
Panel
*
)
MetersPanel_new
(
this
->
settings
,
"Left column"
,
this
->
settings
->
header
->
leftMeters
,
this
->
scr
);
Panel
*
rightMeters
=
(
Panel
*
)
MetersPanel_new
(
this
->
settings
,
"Right column"
,
this
->
settings
->
header
->
rightMeters
,
this
->
scr
);
Panel
*
availableMeters
=
(
Panel
*
)
AvailableMetersPanel_new
(
this
->
settings
,
leftMeters
,
rightMeters
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
leftMeters
,
FunctionBar_new
(
10
,
MetersFunctions
,
NULL
,
NULL
),
20
);
ScreenManager_add
(
this
->
scr
,
rightMeters
,
FunctionBar_new
(
10
,
MetersFunctions
,
NULL
,
NULL
),
20
);
ScreenManager_add
(
this
->
scr
,
availableMeters
,
FunctionBar_new
(
10
,
AvailableMetersFunctions
,
NULL
,
NULL
),
-
1
);
}
void
CategoriesPanel_makeDisplayOptionsPage
(
CategoriesPanel
*
this
)
{
Panel
*
displayOptions
=
(
Panel
*
)
DisplayOptionsPanel_new
(
this
->
settings
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
displayOptions
,
FunctionBar_new
(
10
,
DisplayOptionsFunctions
,
NULL
,
NULL
),
-
1
);
}
void
CategoriesPanel_makeColorsPage
(
CategoriesPanel
*
this
)
{
Panel
*
colors
=
(
Panel
*
)
ColorsPanel_new
(
this
->
settings
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
colors
,
FunctionBar_new
(
10
,
ColorsFunctions
,
NULL
,
NULL
),
-
1
);
}
CategoriesPanel
*
CategoriesPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
)
{
CategoriesPanel
*
this
=
(
CategoriesPanel
*
)
malloc
(
sizeof
(
CategoriesPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
CategoriesPanel_delete
;
void
CategoriesPanel_makeColumnsPage
(
CategoriesPanel
*
this
)
{
Panel
*
columns
=
(
Panel
*
)
ColumnsPanel_new
(
this
->
settings
,
this
->
scr
);
Panel
*
availableColumns
=
(
Panel
*
)
AvailableColumnsPanel_new
(
this
->
settings
,
columns
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
columns
,
FunctionBar_new
(
10
,
ColumnsFunctions
,
NULL
,
NULL
),
20
);
ScreenManager_add
(
this
->
scr
,
availableColumns
,
FunctionBar_new
(
10
,
AvailableColumnsFunctions
,
NULL
,
NULL
),
-
1
);
this
->
settings
=
settings
;
this
->
scr
=
scr
;
super
->
eventHandler
=
CategoriesPanel_eventHandler
;
Panel_setHeader
(
super
,
"Setup"
);
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"Meters"
,
0
));
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"Display options"
,
0
));
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"Colors"
,
0
));
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
"Columns"
,
0
));
return
this
;
}
CategoriesPanel.h
View file @
da23c8c5
...
...
@@ -24,18 +24,8 @@ typedef struct CategoriesPanel_ {
}
CategoriesPanel
;
CategoriesPanel
*
CategoriesPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
);
void
CategoriesPanel_delete
(
Object
*
object
);
HandlerResult
CategoriesPanel_eventHandler
(
Panel
*
super
,
int
ch
);
void
CategoriesPanel_makeMetersPage
(
CategoriesPanel
*
this
);
void
CategoriesPanel_makeDisplayOptionsPage
(
CategoriesPanel
*
this
);
void
CategoriesPanel_makeColorsPage
(
CategoriesPanel
*
this
);
void
CategoriesPanel_makeColumnsPage
(
CategoriesPanel
*
this
);
CategoriesPanel
*
CategoriesPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
);
#endif
CheckItem.c
View file @
da23c8c5
...
...
@@ -28,6 +28,26 @@ char* CHECKITEM_CLASS = "CheckItem";
#define CHECKITEM_CLASS NULL
#endif
static
void
CheckItem_delete
(
Object
*
cast
)
{
CheckItem
*
this
=
(
CheckItem
*
)
cast
;
assert
(
this
!=
NULL
);
free
(
this
->
text
);
free
(
this
);
}
static
void
CheckItem_display
(
Object
*
cast
,
RichString
*
out
)
{
CheckItem
*
this
=
(
CheckItem
*
)
cast
;
assert
(
this
!=
NULL
);
RichString_write
(
out
,
CRT_colors
[
CHECK_BOX
],
"["
);
if
(
CheckItem_get
(
this
))
RichString_append
(
out
,
CRT_colors
[
CHECK_MARK
],
"x"
);
else
RichString_append
(
out
,
CRT_colors
[
CHECK_MARK
],
" "
);
RichString_append
(
out
,
CRT_colors
[
CHECK_BOX
],
"] "
);
RichString_append
(
out
,
CRT_colors
[
CHECK_TEXT
],
this
->
text
);
}
CheckItem
*
CheckItem_new
(
char
*
text
,
bool
*
ref
,
bool
value
)
{
CheckItem
*
this
=
malloc
(
sizeof
(
CheckItem
));
Object_setClass
(
this
,
CHECKITEM_CLASS
);
...
...
@@ -39,14 +59,6 @@ CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
return
this
;
}
void
CheckItem_delete
(
Object
*
cast
)
{
CheckItem
*
this
=
(
CheckItem
*
)
cast
;
assert
(
this
!=
NULL
);
free
(
this
->
text
);
free
(
this
);
}
void
CheckItem_set
(
CheckItem
*
this
,
bool
value
)
{
if
(
this
->
ref
)
*
(
this
->
ref
)
=
value
;
...
...
@@ -60,15 +72,3 @@ bool CheckItem_get(CheckItem* this) {
else
return
this
->
value
;
}
void
CheckItem_display
(
Object
*
cast
,
RichString
*
out
)
{
CheckItem
*
this
=
(
CheckItem
*
)
cast
;
assert
(
this
!=
NULL
);
RichString_write
(
out
,
CRT_colors
[
CHECK_BOX
],
"["
);
if
(
CheckItem_get
(
this
))
RichString_append
(
out
,
CRT_colors
[
CHECK_MARK
],
"x"
);
else
RichString_append
(
out
,
CRT_colors
[
CHECK_MARK
],
" "
);
RichString_append
(
out
,
CRT_colors
[
CHECK_BOX
],
"] "
);
RichString_append
(
out
,
CRT_colors
[
CHECK_TEXT
],
this
->
text
);
}
CheckItem.h
View file @
da23c8c5
...
...
@@ -31,12 +31,8 @@ extern char* CHECKITEM_CLASS;
CheckItem
*
CheckItem_new
(
char
*
text
,
bool
*
ref
,
bool
value
);
void
CheckItem_delete
(
Object
*
cast
);
void
CheckItem_set
(
CheckItem
*
this
,
bool
value
);
bool
CheckItem_get
(
CheckItem
*
this
);
void
CheckItem_display
(
Object
*
cast
,
RichString
*
out
);
#endif
ClockMeter.c
View file @
da23c8c5
...
...
@@ -16,6 +16,13 @@ int ClockMeter_attributes[] = {
CLOCK
};
static
void
ClockMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
)
{
time_t
t
=
time
(
NULL
);
struct
tm
*
lt
=
localtime
(
&
t
);
this
->
values
[
0
]
=
lt
->
tm_hour
*
60
+
lt
->
tm_min
;
strftime
(
buffer
,
size
,
"%H:%M:%S"
,
lt
);
}
MeterType
ClockMeter
=
{
.
setValues
=
ClockMeter_setValues
,
.
display
=
NULL
,
...
...
@@ -27,10 +34,3 @@ MeterType ClockMeter = {
.
uiName
=
"Clock"
,
.
caption
=
"Time: "
,
};
void
ClockMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
)
{
time_t
t
=
time
(
NULL
);
struct
tm
*
lt
=
localtime
(
&
t
);
this
->
values
[
0
]
=
lt
->
tm_hour
*
60
+
lt
->
tm_min
;
strftime
(
buffer
,
size
,
"%H:%M:%S"
,
lt
);
}
ClockMeter.h
View file @
da23c8c5
...
...
@@ -19,6 +19,4 @@ extern int ClockMeter_attributes[];
extern
MeterType
ClockMeter
;
void
ClockMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
);
#endif
ColorsPanel.c
View file @
da23c8c5
...
...
@@ -37,32 +37,14 @@ static char* ColorSchemes[] = {
NULL
};
ColorsPanel
*
ColorsPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
)
{
ColorsPanel
*
this
=
(
ColorsPanel
*
)
malloc
(
sizeof
(
ColorsPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
CHECKITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
ColorsPanel_delete
;
this
->
settings
=
settings
;
this
->
scr
=
scr
;
super
->
eventHandler
=
ColorsPanel_EventHandler
;
Panel_setHeader
(
super
,
"Colors"
);
for
(
int
i
=
0
;
ColorSchemes
[
i
]
!=
NULL
;
i
++
)
{
Panel_add
(
super
,
(
Object
*
)
CheckItem_new
(
String_copy
(
ColorSchemes
[
i
]),
NULL
,
false
));
}
CheckItem_set
((
CheckItem
*
)
Panel_get
(
super
,
settings
->
colorScheme
),
true
);
return
this
;
}
void
ColorsPanel_delete
(
Object
*
object
)
{
static
void
ColorsPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
ColorsPanel
*
this
=
(
ColorsPanel
*
)
object
;
Panel_done
(
super
);
free
(
this
);
}
HandlerResult
ColorsPanel_EventHandler
(
Panel
*
super
,
int
ch
)
{
static
HandlerResult
ColorsPanel_EventHandler
(
Panel
*
super
,
int
ch
)
{
ColorsPanel
*
this
=
(
ColorsPanel
*
)
super
;
HandlerResult
result
=
IGNORED
;
...
...
@@ -93,3 +75,20 @@ HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
return
result
;
}
ColorsPanel
*
ColorsPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
)
{
ColorsPanel
*
this
=
(
ColorsPanel
*
)
malloc
(
sizeof
(
ColorsPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
CHECKITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
ColorsPanel_delete
;
this
->
settings
=
settings
;
this
->
scr
=
scr
;
super
->
eventHandler
=
ColorsPanel_EventHandler
;
Panel_setHeader
(
super
,
"Colors"
);
for
(
int
i
=
0
;
ColorSchemes
[
i
]
!=
NULL
;
i
++
)
{
Panel_add
(
super
,
(
Object
*
)
CheckItem_new
(
String_copy
(
ColorSchemes
[
i
]),
NULL
,
false
));
}
CheckItem_set
((
CheckItem
*
)
Panel_get
(
super
,
settings
->
colorScheme
),
true
);
return
this
;
}
ColorsPanel.h
View file @
da23c8c5
...
...
@@ -30,9 +30,4 @@ typedef struct ColorsPanel_ {
ColorsPanel
*
ColorsPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
);
void
ColorsPanel_delete
(
Object
*
object
);
HandlerResult
ColorsPanel_EventHandler
(
Panel
*
super
,
int
ch
);
#endif
ColumnsPanel.c
View file @
da23c8c5
...
...
@@ -19,57 +19,14 @@ typedef struct ColumnsPanel_ {
}*/
ColumnsPanel
*
ColumnsPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
)
{
ColumnsPanel
*
this
=
(
ColumnsPanel
*
)
malloc
(
sizeof
(
ColumnsPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
ColumnsPanel_delete
;
this
->
settings
=
settings
;
this
->
scr
=
scr
;
super
->
eventHandler
=
ColumnsPanel_eventHandler
;
Panel_setHeader
(
super
,
"Active Columns"
);
ProcessField
*
fields
=
this
->
settings
->
pl
->
fields
;
for
(;
*
fields
;
fields
++
)
{
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
Process_fieldNames
[
*
fields
],
0
));
}
return
this
;
}
void
ColumnsPanel_delete
(
Object
*
object
)
{
static
void
ColumnsPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
ColumnsPanel
*
this
=
(
ColumnsPanel
*
)
object
;
Panel_done
(
super
);
free
(
this
);
}
int
ColumnsPanel_fieldNameToIndex
(
const
char
*
name
)
{
for
(
int
j
=
1
;
j
<=
LAST_PROCESSFIELD
;
j
++
)
{
if
(
String_eq
(
name
,
Process_fieldNames
[
j
]))
{
return
j
;
}
}
return
0
;
}
void
ColumnsPanel_update
(
Panel
*
super
)
{
ColumnsPanel
*
this
=
(
ColumnsPanel
*
)
super
;
int
size
=
Panel_getSize
(
super
);
this
->
settings
->
changed
=
true
;
// FIXME: this is crappily inefficient
free
(
this
->
settings
->
pl
->
fields
);
this
->
settings
->
pl
->
fields
=
(
ProcessField
*
)
malloc
(
sizeof
(
ProcessField
)
*
(
size
+
1
));
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
char
*
text
=
((
ListItem
*
)
Panel_get
(
super
,
i
))
->
value
;
int
j
=
ColumnsPanel_fieldNameToIndex
(
text
);
if
(
j
>
0
)
this
->
settings
->
pl
->
fields
[
i
]
=
j
;
}
this
->
settings
->
pl
->
fields
[
size
]
=
0
;
}
HandlerResult
ColumnsPanel_eventHandler
(
Panel
*
super
,
int
ch
)
{
static
HandlerResult
ColumnsPanel_eventHandler
(
Panel
*
super
,
int
ch
)
{
int
selected
=
Panel_getSelectedIndex
(
super
);
HandlerResult
result
=
IGNORED
;
...
...
@@ -108,3 +65,47 @@ HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
ColumnsPanel_update
(
super
);
return
result
;
}
ColumnsPanel
*
ColumnsPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
)
{
ColumnsPanel
*
this
=
(
ColumnsPanel
*
)
malloc
(
sizeof
(
ColumnsPanel
));
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
LISTITEM_CLASS
,
true
);
((
Object
*
)
this
)
->
delete
=
ColumnsPanel_delete
;
this
->
settings
=
settings
;
this
->
scr
=
scr
;
super
->
eventHandler
=
ColumnsPanel_eventHandler
;
Panel_setHeader
(
super
,
"Active Columns"
);
ProcessField
*
fields
=
this
->
settings
->
pl
->
fields
;
for
(;
*
fields
;
fields
++
)
{
Panel_add
(
super
,
(
Object
*
)
ListItem_new
(
Process_fieldNames
[
*
fields
],
0
));
}
return
this
;
}
int
ColumnsPanel_fieldNameToIndex
(
const
char
*
name
)
{
for
(
int
j
=
1
;
j
<=
LAST_PROCESSFIELD
;
j
++
)
{
if
(
String_eq
(
name
,
Process_fieldNames
[
j
]))
{
return
j
;
}
}
return
0
;
}
void
ColumnsPanel_update
(
Panel
*
super
)
{
ColumnsPanel
*
this
=
(
ColumnsPanel
*
)
super
;
int
size
=
Panel_getSize
(
super
);
this
->
settings
->
changed
=
true
;
// FIXME: this is crappily inefficient
free
(
this
->
settings
->
pl
->
fields
);
this
->
settings
->
pl
->
fields
=
(
ProcessField
*
)
malloc
(
sizeof
(
ProcessField
)
*
(
size
+
1
));
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
char
*
text
=
((
ListItem
*
)
Panel_get
(
super
,
i
))
->
value
;
int
j
=
ColumnsPanel_fieldNameToIndex
(
text
);
if
(
j
>
0
)
this
->
settings
->
pl
->
fields
[
i
]
=
j
;
}
this
->
settings
->
pl
->
fields
[
size
]
=
0
;
}
ColumnsPanel.h
View file @
da23c8c5
...
...
@@ -22,12 +22,9 @@ typedef struct ColumnsPanel_ {
ColumnsPanel
*
ColumnsPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
);
void
ColumnsPanel_delete
(
Object
*
object
);
int
ColumnsPanel_fieldNameToIndex
(
const
char
*
name
);
void
ColumnsPanel_update
(
Panel
*
super
);
HandlerResult
ColumnsPanel_eventHandler
(
Panel
*
super
,
int
ch
);
#endif
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment