diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2015-08-12 17:29:32 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-08-12 17:29:32 -0300 |
commit | 0ebe688d2462fe99faf3ec9ef4d36e33017a636c (patch) | |
tree | dbd58491ea4825bf624ef7c75ba1e475a6a46770 | |
parent | e1e3ffad19e3d1d14ba8f1e8e4628a7cd01c7af6 (diff) |
Avoid future confusions with how default values are set.
-rw-r--r-- | AffinityPanel.c | 2 | ||||
-rw-r--r-- | CheckItem.c | 12 | ||||
-rw-r--r-- | CheckItem.h | 4 | ||||
-rw-r--r-- | ColorsPanel.c | 2 | ||||
-rw-r--r-- | DisplayOptionsPanel.c | 28 |
5 files changed, 29 insertions, 19 deletions
diff --git a/AffinityPanel.c b/AffinityPanel.c index 8612855c..b400cadb 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -58,7 +58,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) { } else { mode = false; } - Panel_add(this, (Object*) CheckItem_new(strdup(number), NULL, mode)); + Panel_add(this, (Object*) CheckItem_newByVal(strdup(number), mode)); } return this; } diff --git a/CheckItem.c b/CheckItem.c index ea83e6f3..b7ba6fec 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -49,14 +49,22 @@ ObjectClass CheckItem_class = { .delete = CheckItem_delete }; -CheckItem* CheckItem_new(char* text, bool* ref, bool value) { +CheckItem* CheckItem_newByRef(char* text, bool* ref) { CheckItem* this = AllocThis(CheckItem); this->text = text; - this->value = value; + this->value = false; this->ref = ref; return this; } +CheckItem* CheckItem_newByVal(char* text, bool value) { + CheckItem* this = AllocThis(CheckItem); + this->text = text; + this->value = value; + this->ref = NULL; + return this; +} + void CheckItem_set(CheckItem* this, bool value) { if (this->ref) *(this->ref) = value; diff --git a/CheckItem.h b/CheckItem.h index 86d4aa5b..5847d4b2 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -21,7 +21,9 @@ typedef struct CheckItem_ { extern ObjectClass CheckItem_class; -CheckItem* CheckItem_new(char* text, bool* ref, bool value); +CheckItem* CheckItem_newByRef(char* text, bool* ref); + +CheckItem* CheckItem_newByVal(char* text, bool value); void CheckItem_set(CheckItem* this, bool value); diff --git a/ColorsPanel.c b/ColorsPanel.c index 40aa837a..3c40a477 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -105,7 +105,7 @@ ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) { Panel_setHeader(super, "Colors"); for (int i = 0; ColorSchemeNames[i] != NULL; i++) { - Panel_add(super, (Object*) CheckItem_new(strdup(ColorSchemeNames[i]), NULL, false)); + Panel_add(super, (Object*) CheckItem_newByVal(strdup(ColorSchemeNames[i]), false)); } CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true); return this; diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index c544162f..ac0bbfe9 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -81,19 +81,19 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* this->scr = scr; Panel_setHeader(super, "Display options"); - 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)); - Panel_add(super, (Object*) CheckItem_new(strdup("Show program path"), &(settings->showProgramPath), true)); - 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)); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Tree view"), &(settings->treeView))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Shadow other users' processes"), &(settings->shadowOtherUsers))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Hide kernel threads"), &(settings->hideKernelThreads))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Hide userland threads"), &(settings->hideUserlandThreads))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Display threads in a different color"), &(settings->highlightThreads))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Show custom thread names"), &(settings->showThreadNames))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Show program path"), &(settings->showProgramPath))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Highlight program \"basename\""), &(settings->highlightBaseName))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Leave a margin around header"), &(settings->headerMargin))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Update process names on every refresh"), &(settings->updateProcessNames))); + Panel_add(super, (Object*) CheckItem_newByRef(strdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter))); return this; } |