DisplayOptionsPanel.c 3.93 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
2
3
4
5
6
/*
htop - DisplayOptionsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
Hisham Muhammad's avatar
Hisham Muhammad committed
7

8
#include "DisplayOptionsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
9
10

#include "CheckItem.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
11

Hisham Muhammad's avatar
Hisham Muhammad committed
12
#include <assert.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
13
14
#include <stdlib.h>
#include <string.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
15
16

/*{
Hisham Muhammad's avatar
Hisham Muhammad committed
17
18
19
#include "Panel.h"
#include "Settings.h"
#include "ScreenManager.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
20

21
22
typedef struct DisplayOptionsPanel_ {
   Panel super;
Hisham Muhammad's avatar
Hisham Muhammad committed
23
24
25

   Settings* settings;
   ScreenManager* scr;
26
} DisplayOptionsPanel;
Hisham Muhammad's avatar
Hisham Muhammad committed
27
28
29

}*/

30
31
static const char* DisplayOptionsFunctions[] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  ", NULL};

32
static void DisplayOptionsPanel_delete(Object* object) {
33
34
35
   Panel* super = (Panel*) object;
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
36
37
38
   free(this);
}

39
static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
40
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
41
42
   
   HandlerResult result = IGNORED;
43
   CheckItem* selected = (CheckItem*) Panel_getSelected(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
44
45
46
47
48

   switch(ch) {
   case 0x0a:
   case 0x0d:
   case KEY_ENTER:
49
   case KEY_MOUSE:
Hisham Muhammad's avatar
Hisham Muhammad committed
50
   case ' ':
51
      CheckItem_set(selected, ! (CheckItem_get(selected)) );
Hisham Muhammad's avatar
Hisham Muhammad committed
52
53
54
55
56
      result = HANDLED;
   }

   if (result == HANDLED) {
      this->settings->changed = true;
Hisham Muhammad's avatar
Hisham Muhammad committed
57
58
59
      const Header* header = this->scr->header;
      Header_calculateHeight((Header*) header);
      Header_reinit((Header*) header);
Hisham Muhammad's avatar
Hisham Muhammad committed
60
61
62
63
64
65
      Header_draw(header);
      ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
   }
   return result;
}

66
67
68
69
70
71
72
73
PanelClass DisplayOptionsPanel_class = {
   .super = {
      .extends = Class(Panel),
      .delete = DisplayOptionsPanel_delete
   },
   .eventHandler = DisplayOptionsPanel_eventHandler
};

74
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
75
   DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
76
   Panel* super = (Panel*) this;
77
78
   FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
   Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
79
80
81
82
83

   this->settings = settings;
   this->scr = scr;

   Panel_setHeader(super, "Display options");
Hisham Muhammad's avatar
Hisham Muhammad committed
84
85
86
87
88
89
   Panel_add(super, (Object*) CheckItem_new(strdup("Tree view"), &(settings->treeView), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Shadow other users' processes"), &(settings->shadowOtherUsers), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Hide kernel threads"), &(settings->hideKernelThreads), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Hide userland threads"), &(settings->hideUserlandThreads), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Display threads in a different color"), &(settings->highlightThreads), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Show custom thread names"), &(settings->showThreadNames), false));
90
   Panel_add(super, (Object*) CheckItem_new(strdup("Show program path"), &(settings->showProgramPath), true));
Hisham Muhammad's avatar
Hisham Muhammad committed
91
92
93
94
95
96
97
   Panel_add(super, (Object*) CheckItem_new(strdup("Highlight program \"basename\""), &(settings->highlightBaseName), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Leave a margin around header"), &(settings->headerMargin), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Update process names on every refresh"), &(settings->updateProcessNames), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter), false));
98
99
   return this;
}