Debian Codegraph @

src/dialogs/config/config_resources.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2019 Robert Kausch <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
10 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
12
13 #include <dialogs/config/config_resources.h>
14 #include <dialogs/config/configcomponent.h>
15
16 #include <freac.h>
17 #include <config.h>
18 #include <utilities.h>
19
20 using namespace BoCA::AS;
21
22 using namespace smooth::GUI::Dialogs;
23
24 freac::ConfigureResources::ConfigureResources()
25 {
26 BoCA::Config *config = BoCA::Config::Get();
27 BoCA::I18n *i18n = BoCA::I18n::Get();
28
29 i18n->SetContext("Configuration::Resources");
30
31 enableParallel = config->GetIntValue(Config::CategoryResourcesID, Config::ResourcesEnableParallelConversionsID, Config::ResourcesEnableParallelConversionsDefault);
32 enableSuperFast = config->GetIntValue(Config::CategoryResourcesID, Config::ResourcesEnableSuperFastModeID, Config::ResourcesEnableSuperFastModeDefault);
33
34 group_cpu = new GroupBox(i18n->TranslateString("Parallel processing"), Point(7, 11), Size(350, 89));
35
36 check_enable_parallel = new CheckBox(i18n->TranslateString("Enable parallel processing"), Point(10, 14), Size(group_cpu->GetWidth() - 20, 0), &enableParallel);
37 check_enable_parallel->onAction.Connect(&ConfigureResources::ToggleParallel, this);
38
39 check_enable_superfast = new CheckBox(i18n->TranslateString("Enable SuperFast mode"), Point(27, 37), Size(group_cpu->GetWidth() - 37, 0), &enableSuperFast);
40
41 text_threads = new Text(i18n->AddColon(i18n->TranslateString("Number of conversion threads")), Point(10, 64));
42 text_threads_value = new Text(i18n->TranslateString("auto"), Point(350, 64));
43 text_threads_value->SetX(group_cpu->GetWidth() - text_threads_value->GetUnscaledTextWidth() - 10);
44
45 slider_threads = new Slider(Point(17 + text_threads->GetUnscaledTextWidth(), 62), Size(group_cpu->GetWidth() - 35 - text_threads->GetUnscaledTextWidth() - text_threads_value->GetUnscaledTextWidth(), 0), OR_HORZ, NIL, 1, CPU().GetNumLogicalCPUs());
46 slider_threads->SetValue(config->GetIntValue(Config::CategoryResourcesID, Config::ResourcesNumberOfConversionThreadsID, Config::ResourcesNumberOfConversionThreadsDefault));
47 slider_threads->onAction.Connect(&ConfigureResources::ChangeConversionThreads, this);
48
49 group_cpu->Add(check_enable_parallel);
50 group_cpu->Add(check_enable_superfast);
51 group_cpu->Add(text_threads);
52 group_cpu->Add(text_threads_value);
53 group_cpu->Add(slider_threads);
54
55 if (CPU().GetNumLogicalCPUs() <= 1) group_cpu->Deactivate();
56
57 ToggleParallel();
58 ChangeConversionThreads();
59
60 group_priority = new GroupBox(i18n->TranslateString("Process priority"), Point(7, 111), Size(350, 40));
61
62 text_priority = new Text(i18n->AddColon(i18n->TranslateString("Process priority")), Point(10, 15));
63 text_priority_value = new Text(NIL, Point(350, 15));
64
65 Font font = text_priority_value->GetFont();
66 Int maxTextSize = Math::Max(Math::Max(font.GetUnscaledTextSizeX(i18n->TranslateString("lowest")), font.GetUnscaledTextSizeX(i18n->TranslateString("lower"))), Math::Max(font.GetUnscaledTextSizeX(i18n->TranslateString("normal")), Math::Max(font.GetUnscaledTextSizeX(i18n->TranslateString("higher")), font.GetUnscaledTextSizeX(i18n->TranslateString("highest")))));
67
68 text_priority_value->SetX(group_priority->GetWidth() - maxTextSize - 10);
69
70 slider_priority = new Slider(Point(17 + text_priority->GetUnscaledTextWidth(), 13), Size(group_priority->GetWidth() - 35 - text_priority->GetUnscaledTextWidth() - maxTextSize, 0), OR_HORZ, NIL, -2, 2);
71 slider_priority->SetValue(config->GetIntValue(Config::CategoryResourcesID, Config::ResourcesPriorityID, Config::ResourcesPriorityDefault));
72 slider_priority->onAction.Connect(&ConfigureResources::ChangePriority, this);
73
74 group_priority->Add(text_priority);
75 group_priority->Add(text_priority_value);
76 group_priority->Add(slider_priority);
77
78 ChangePriority();
79
80 Add(group_cpu);
81
82 #ifdef __WIN32__
83 Add(group_priority);
84
85 SetSize(Size(364, 157));
86 #else
87 SetSize(Size(364, 106));
88 #endif
89 }
90
91 freac::ConfigureResources::~ConfigureResources()
92 {
93 DeleteObject(group_cpu);
94 DeleteObject(check_enable_parallel);
95 DeleteObject(check_enable_superfast);
96 DeleteObject(text_threads);
97 DeleteObject(text_threads_value);
98 DeleteObject(slider_threads);
99
100 DeleteObject(group_priority);
101 DeleteObject(text_priority);
102 DeleteObject(text_priority_value);
103 DeleteObject(slider_priority);
104 }
105
106 Void freac::ConfigureResources::ToggleParallel()
107 {
108 if (enableParallel)
109 {
110 check_enable_superfast->Activate();
111 text_threads->Activate();
112 text_threads_value->Activate();
113 slider_threads->Activate();
114 }
115 else
116 {
117 check_enable_superfast->Deactivate();
118 text_threads->Deactivate();
119 text_threads_value->Deactivate();
120 slider_threads->Deactivate();
121 }
122 }
123
124 Void freac::ConfigureResources::ChangeConversionThreads()
125 {
126 BoCA::I18n *i18n = BoCA::I18n::Get();
127
128 i18n->SetContext("Configuration::Resources");
129
130 if (slider_threads->GetValue() == 1) text_threads_value->SetText(i18n->TranslateString("auto"));
131 else text_threads_value->SetText(String::FromInt(slider_threads->GetValue()));
132 }
133
134 Void freac::ConfigureResources::ChangePriority()
135 {
136 BoCA::I18n *i18n = BoCA::I18n::Get();
137
138 i18n->SetContext("Configuration::Resources");
139
140 switch (slider_priority->GetValue())
141 {
142 case -2: text_priority_value->SetText(i18n->TranslateString("lowest")); break;
143 case -1: text_priority_value->SetText(i18n->TranslateString("lower")); break;
144 case 0: text_priority_value->SetText(i18n->TranslateString("normal")); break;
145 case 1: text_priority_value->SetText(i18n->TranslateString("higher")); break;
146 case 2: text_priority_value->SetText(i18n->TranslateString("highest")); break;
147 }
148 }
149
150 Int freac::ConfigureResources::SaveSettings()
151 {
152 BoCA::Config *config = BoCA::Config::Get();
153
154 config->SetIntValue(Config::CategoryResourcesID, Config::ResourcesEnableParallelConversionsID, enableParallel);
155 config->SetIntValue(Config::CategoryResourcesID, Config::ResourcesEnableSuperFastModeID, enableSuperFast);
156
157 config->SetIntValue(Config::CategoryResourcesID, Config::ResourcesNumberOfConversionThreadsID, slider_threads->GetValue());
158
159 config->SetIntValue(Config::CategoryResourcesID, Config::ResourcesPriorityID, slider_priority->GetValue());
160
161 Utilities::SetProcessPriority();
162
163 return Success();
164 }