Debian Codegraph @

src/dialogs/config/config_tagformats.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2022 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_tagformats.h>
14
15 #include <config.h>
16
17 using namespace BoCA::AS;
18
19 freac::ConfigureTagFormats::ConfigureTagFormats()
20 {
21 BoCA::Config *config = BoCA::Config::Get();
22 BoCA::I18n *i18n = BoCA::I18n::Get();
23
24 i18n->SetContext("Configuration::Tags");
25
26 /* Get configuration.
27 */
28 prependZero = False;
29
30 /* Create widgets.
31 */
32 group_tags = new GroupBox(i18n->TranslateString("Tag formats"), Point(7, 11), Size(552, 117));
33
34 list_tag_formats = new ListBox(Point(10, 13), Size(250, 94));
35 list_tag_formats->SetFlags(LF_MULTICHECKBOX);
36
37 Registry &boca = Registry::Get();
38
39 for (Int i = 0; i < boca.GetNumberOfComponents(); i++)
40 {
41 if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_TAGGER) continue;
42
43 const Array<TagSpec *> &specs = boca.GetComponentTagSpecs(i);
44
45 foreach (TagSpec *spec, specs)
46 {
47 list_tag_formats->AddEntry(spec->GetName(), config->GetIntValue(Config::CategoryTagsID, String("Enable").Append(spec->GetName().Replace(" ", NIL)), spec->IsDefault()));
48
49 selected_encodings.Add(config->GetStringValue(Config::CategoryTagsID, spec->GetName().Replace(" ", NIL).Append("Encoding"), spec->GetDefaultEncoding()));
50 tags_prependzero.Add(config->GetIntValue(Config::CategoryTagsID, String("TrackPrependZero").Append(spec->GetName().Replace(" ", NIL)), spec->IsPrependZeroDefault()));
51 }
52 }
53
54 list_tag_formats->onSelectEntry.Connect(&ConfigureTagFormats::ToggleTags, this);
55 list_tag_formats->onMarkEntry.Connect(&ConfigureTagFormats::ToggleTags, this);
56
57 text_encoding = new Text(i18n->AddColon(i18n->TranslateString("Encoding")), Point(268, 16));
58
59 list_encodings = new List();
60
61 edit_encoding = new EditBox(Point(text_encoding->GetUnscaledTextWidth() + 275, 13), Size(249 - text_encoding->GetUnscaledTextWidth(), 0));
62 edit_encoding->onInput.Connect(&ConfigureTagFormats::OnEditEncoding, this);
63
64 combo_encoding = new ComboBox(Point(text_encoding->GetUnscaledTextWidth() + 275, 13), Size(249 - text_encoding->GetUnscaledTextWidth(), 0));
65 combo_encoding->onSelectEntry.Connect(&ConfigureTagFormats::OnEditEncoding, this);
66 combo_encoding->Hide();
67
68 check_prependzero = new CheckBox(i18n->TranslateString("Prepend zero to track numbers below 10"), Point(268, edit_encoding->GetY() + 28), Size(256, 0), &prependZero);
69 check_prependzero->SetWidth(Math::Max(271, check_prependzero->GetUnscaledTextWidth() + 21));
70 check_prependzero->onAction.Connect(&ConfigureTagFormats::TogglePrependZero, this);
71
72 group_tags->SetWidth(281 + check_prependzero->GetWidth());
73
74 group_tags->Add(list_tag_formats);
75 group_tags->Add(text_encoding);
76 group_tags->Add(edit_encoding);
77 group_tags->Add(combo_encoding);
78 group_tags->Add(check_prependzero);
79
80 Add(group_tags);
81
82 /* Adjust element widths.
83 */
84 edit_encoding->SetWidth(group_tags->GetWidth() - edit_encoding->GetX() - 10);
85 combo_encoding->SetWidth(group_tags->GetWidth() - combo_encoding->GetX() - 10);
86 check_prependzero->SetWidth(group_tags->GetWidth() - check_prependzero->GetX() - 10);
87
88 /* Finish initialization.
89 */
90 ToggleTags();
91
92 SetSize(group_tags->GetSize() + Size(14, 18));
93 }
94
95 freac::ConfigureTagFormats::~ConfigureTagFormats()
96 {
97 DeleteObject(group_tags);
98 DeleteObject(list_tag_formats);
99 DeleteObject(text_encoding);
100 DeleteObject(edit_encoding);
101 DeleteObject(combo_encoding);
102 DeleteObject(list_encodings);
103 DeleteObject(check_prependzero);
104 }
105
106 Void freac::ConfigureTagFormats::OnEditEncoding()
107 {
108 if (edit_encoding->IsVisible()) selected_encodings.SetNth(list_tag_formats->GetSelectedEntryNumber(), edit_encoding->GetText());
109 else selected_encodings.SetNth(list_tag_formats->GetSelectedEntryNumber(), combo_encoding->GetSelectedEntry()->GetText());
110 }
111
112 Void freac::ConfigureTagFormats::ToggleTags()
113 {
114 ListEntry *entry = list_tag_formats->GetSelectedEntry();
115
116 if (entry == NIL)
117 {
118 edit_encoding->SetText(NIL);
119
120 text_encoding->Deactivate();
121 edit_encoding->Deactivate();
122
123 check_prependzero->Deactivate();
124
125 return;
126 }
127
128 /* Hide all controls first.
129 */
130 edit_encoding->Hide();
131 combo_encoding->Hide();
132
133 list_encodings->RemoveAllEntries();
134 combo_encoding->RemoveAllEntries();
135
136 /* Configure and show controls according to format capabilities.
137 */
138 Registry &boca = Registry::Get();
139 Int n = 0;
140
141 for (Int i = 0; i < boca.GetNumberOfComponents(); i++)
142 {
143 if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_TAGGER) continue;
144
145 const Array<TagSpec *> &specs = boca.GetComponentTagSpecs(i);
146
147 foreach (TagSpec *spec, specs)
148 {
149 if (n++ != list_tag_formats->GetSelectedEntryNumber()) continue;
150
151 const Array<String> &encodings = spec->GetEncodings();
152
153 foreach (const String &encoding, encodings)
154 {
155 list_encodings->AddEntry(encoding);
156 combo_encoding->AddEntry(encoding);
157 }
158
159 if (spec->IsFreeEncodingSupported())
160 {
161 edit_encoding->SetText(selected_encodings.GetNth(n - 1));
162 edit_encoding->Show();
163 }
164 else
165 {
166 combo_encoding->SelectEntry(selected_encodings.GetNth(n - 1));
167 combo_encoding->Show();
168 }
169
170 check_prependzero->SetChecked(tags_prependzero.GetNth(n - 1));
171
172 if (spec->IsPrependZeroAllowed()) check_prependzero->Activate();
173 else check_prependzero->Deactivate();
174
175 break;
176 }
177
178 if (n > list_tag_formats->GetSelectedEntryNumber()) break;
179 }
180
181 edit_encoding->SetDropDownList(list_encodings);
182
183 /* Activate encoding controls if more than one encoding is available.
184 */
185 if (list_encodings->Length() > 1)
186 {
187 text_encoding->Activate();
188 edit_encoding->Activate();
189 combo_encoding->Activate();
190 }
191 else
192 {
193 text_encoding->Deactivate();
194 edit_encoding->Deactivate();
195 combo_encoding->Deactivate();
196 }
197 }
198
199 Void freac::ConfigureTagFormats::TogglePrependZero()
200 {
201 tags_prependzero.SetNth(list_tag_formats->GetSelectedEntryNumber(), prependZero);
202 }
203
204 Int freac::ConfigureTagFormats::SaveSettings()
205 {
206 BoCA::Config *config = BoCA::Config::Get();
207 Registry &boca = Registry::Get();
208
209 for (Int i = 0; i < boca.GetNumberOfComponents(); i++)
210 {
211 if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_TAGGER) continue;
212
213 const Array<TagSpec *> &specs = boca.GetComponentTagSpecs(i);
214
215 foreach (TagSpec *spec, specs)
216 {
217 config->SetIntValue(Config::CategoryTagsID, String("Enable").Append(spec->GetName().Replace(" ", NIL)), list_tag_formats->GetEntry(spec->GetName())->IsMarked());
218 config->SetStringValue(Config::CategoryTagsID, spec->GetName().Replace(" ", NIL).Append("Encoding"), selected_encodings.GetNth(list_tag_formats->GetEntryNumber(spec->GetName())));
219
220 if (spec->IsPrependZeroAllowed()) config->SetIntValue(Config::CategoryTagsID, String("TrackPrependZero").Append(spec->GetName().Replace(" ", NIL)), tags_prependzero.GetNth(list_tag_formats->GetEntryNumber(spec->GetName())));
221 }
222 }
223
224 return Success();
225 }