Debian Codegraph @

src/dialogs/config/config.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2023 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.h>
14 #include <dialogs/config/config_albumart.h>
15 #include <dialogs/config/config_cddb.h>
16 #include <dialogs/config/config_cuesheets.h>
17 #include <dialogs/config/config_dsp.h>
18 #include <dialogs/config/config_encoders.h>
19 #include <dialogs/config/config_files.h>
20 #include <dialogs/config/config_interface.h>
21 #include <dialogs/config/config_language.h>
22 #include <dialogs/config/config_playlists.h>
23 #include <dialogs/config/config_resources.h>
24 #include <dialogs/config/config_tagfields.h>
25 #include <dialogs/config/config_tagformats.h>
26 #include <dialogs/config/config_verification.h>
27
28 #include <freac.h>
29 #include <config.h>
30
31 using namespace BoCA;
32 using namespace BoCA::AS;
33
34 freac::ConfigurePage freac::ConfigDialog::previousPage = ConfigurePageDefault;
35
36 freac::ConfigDialog::ConfigDialog()
37 {
38 BoCA::Config *config = BoCA::Config::Get();
39 BoCA::I18n *i18n = BoCA::I18n::Get();
40
41 i18n->SetContext("Configuration");
42
43 initialConfig = config->GetConfigurationName();
44 initialPage = ConfigurePagePrevious;
45
46 mainWnd = new Window(i18n->TranslateString("General settings setup"), Point(config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosXID, Config::SettingsWindowPosXDefault), config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosYID, Config::SettingsWindowPosYDefault)) + Point(30, 30), Size(600, 512));
47 mainWnd->SetRightToLeft(i18n->IsActiveLanguageRightToLeft());
48 mainWnd->GetMainLayer()->onChangeSize.Connect(&ConfigDialog::OnChangeSize, this);
49
50 mainWnd_titlebar = new Titlebar(TB_CLOSEBUTTON);
51 divbar = new Divider(39, OR_HORZ | OR_BOTTOM);
52
53 btn_cancel = new Button(i18n->TranslateString("Cancel"), Point(175, 29), Size());
54 btn_cancel->onAction.Connect(&ConfigDialog::Cancel, this);
55 btn_cancel->SetOrientation(OR_LOWERRIGHT);
56
57 btn_ok = new Button(i18n->TranslateString("OK"), btn_cancel->GetPosition() - Point(88, 0), Size());
58 btn_ok->onAction.Connect(&ConfigDialog::OK, this);
59 btn_ok->SetOrientation(OR_LOWERRIGHT);
60
61 text_config = new Text(i18n->AddColon(i18n->TranslateString("Active configuration")), Point(7, 11));
62
63 combo_config = new ComboBox(Point(text_config->GetUnscaledTextWidth() + 15, 8), Size());
64
65 for (Int i = 0; i < config->GetNOfConfigurations(); i++)
66 {
67 if (i == 0) combo_config->AddEntry(i18n->TranslateString("Default configuration"));
68 else combo_config->AddEntry(config->GetNthConfigurationName(i));
69 }
70
71 if (config->GetConfigurationName() == "default") combo_config->SelectNthEntry(0);
72 else combo_config->SelectEntry(config->GetConfigurationName());
73
74 combo_config->onSelectEntry.Connect(&ConfigDialog::OnSelectConfiguration, this);
75
76 edit_config = new EditBox(Point(text_config->GetUnscaledTextWidth() + 15, 8), Size(), 0);
77 edit_config->SetDropDownList(combo_config);
78 edit_config->onSelectEntry.Connect(&ConfigDialog::OnSelectConfigurationByName, this);
79 edit_config->onInput.Connect(&ConfigDialog::OnEditConfigurationName, this);
80
81 button_config_new = new Button(i18n->TranslateString("New"), Point(175, 7), Size());
82 button_config_new->SetOrientation(OR_UPPERRIGHT);
83 button_config_new->onAction.Connect(&ConfigDialog::OnCreateConfig, this);
84
85 button_config_delete = new Button(i18n->TranslateString("Delete"), Point(87, 7), Size());
86 button_config_delete->SetOrientation(OR_UPPERRIGHT);
87 button_config_delete->onAction.Connect(&ConfigDialog::OnDeleteConfig, this);
88
89 divider_top = new Divider(37, OR_HORZ | OR_TOP);
90
91 mainWnd->Add(text_config);
92 mainWnd->Add(combo_config);
93 mainWnd->Add(edit_config);
94 mainWnd->Add(button_config_new);
95 mainWnd->Add(button_config_delete);
96 mainWnd->Add(divider_top);
97
98 list_layers = new ListBox(Point(7, 47), Size(210, 244));
99
100 selectedLayer = NIL;
101
102 tree_freac = new Tree(freac::appName);
103
104 tree_interface = new Tree(i18n->TranslateString("Interface"));
105 tree_ripper = new Tree(i18n->TranslateString("Ripper"));
106 tree_metadata = new Tree(i18n->TranslateString("Metadata"));
107
108 tree_components = new Tree(i18n->TranslateString("Components"));
109
110 tree_extension = new Tree(i18n->TranslateString("Extensions"));
111 tree_encoders = new Tree(i18n->TranslateString("Encoders"));
112 tree_decoders = new Tree(i18n->TranslateString("Decoders"));
113 tree_verifiers = new Tree(i18n->TranslateString("Verifiers"));
114 tree_taggers = new Tree(i18n->TranslateString("Taggers"));
115 tree_playlists = new Tree(i18n->TranslateString("Playlists"));
116 tree_dsp = new Tree(i18n->TranslateString("DSP"));
117 tree_output = new Tree(i18n->TranslateString("Output"));
118 tree_other = new Tree(i18n->TranslateString("Other"));
119
120 /* Connect to BoCA's onChangeComponentSettings signal to be
121 * notified when settings for a specific component are changed.
122 */
123 BoCA::Settings::onChangeComponentSettings.Connect(&ConfigDialog::OnChangeComponentSettings, this);
124
125 OnSelectConfiguration();
126
127 if (tree_encoders->Length() > 0) tree_components->Add(tree_encoders);
128 if (tree_decoders->Length() > 0) tree_components->Add(tree_decoders);
129 if (tree_verifiers->Length() > 0) tree_components->Add(tree_verifiers);
130 if (tree_taggers->Length() > 0) tree_components->Add(tree_taggers);
131 if (tree_playlists->Length() > 0) tree_components->Add(tree_playlists);
132 if (tree_dsp->Length() > 0) tree_components->Add(tree_dsp);
133 if (tree_output->Length() > 0) tree_components->Add(tree_output);
134 if (tree_other->Length() > 0) tree_components->Add(tree_other);
135
136 tree_freac->Open();
137
138 tree_interface->Open();
139 tree_ripper->Open();
140 tree_metadata->Open();
141
142 tree_extension->Open();
143 tree_components->Open();
144
145 list_layers->Add(tree_freac);
146
147 if (tree_extension->Length() > 0) list_layers->Add(tree_extension);
148
149 list_layers->Add(tree_components);
150
151 Add(mainWnd);
152
153 mainWnd->Add(mainWnd_titlebar);
154 mainWnd->Add(divbar);
155 mainWnd->Add(btn_ok);
156 mainWnd->Add(btn_cancel);
157 mainWnd->Add(list_layers);
158
159 #ifdef __WIN32__
160 Int frameWidth = mainWnd->GetFrameWidth();
161 #else
162 Int frameWidth = 4;
163 #endif
164
165 Layer *firstLayer = layers.GetFirst();
166
167 mainWnd->SetSize(Size(Math::Max(600, firstLayer->GetWidth() + 218 + 2 * frameWidth), Math::Max(512, firstLayer->GetHeight() + 105 + 2 * frameWidth)));
168
169 mainWnd->SetFlags(WF_MODAL);
170 mainWnd->SetIcon(ImageLoader::Load(String(Config::Get()->resourcesPath).Append("icons/freac.png")));
171 }
172
173 freac::ConfigDialog::~ConfigDialog()
174 {
175 /* Disconnect from BoCA's onChangeComponentSettings signal.
176 */
177 BoCA::Settings::onChangeComponentSettings.Disconnect(&ConfigDialog::OnChangeComponentSettings, this);
178
179 DeleteLayers();
180
181 DeleteObject(mainWnd_titlebar);
182 DeleteObject(mainWnd);
183 DeleteObject(btn_ok);
184 DeleteObject(btn_cancel);
185 DeleteObject(divbar);
186
187 DeleteObject(text_config);
188 DeleteObject(combo_config);
189 DeleteObject(edit_config);
190 DeleteObject(button_config_new);
191 DeleteObject(button_config_delete);
192 DeleteObject(divider_top);
193
194 DeleteObject(list_layers);
195
196 DeleteObject(tree_freac);
197
198 DeleteObject(tree_interface);
199 DeleteObject(tree_ripper);
200 DeleteObject(tree_metadata);
201
202 DeleteObject(tree_components);
203
204 DeleteObject(tree_extension);
205 DeleteObject(tree_encoders);
206 DeleteObject(tree_decoders);
207 DeleteObject(tree_verifiers);
208 DeleteObject(tree_taggers);
209 DeleteObject(tree_playlists);
210 DeleteObject(tree_dsp);
211 DeleteObject(tree_output);
212 DeleteObject(tree_other);
213 }
214
215 Void freac::ConfigDialog::AddLayers()
216 {
217 BoCA::I18n *i18n = BoCA::I18n::Get();
218
219 i18n->SetContext("Configuration");
220
221 Registry &boca = Registry::Get();
222
223 /* Add encoder configuration layer.
224 */
225 layers.Add(new ConfigureEncoders());
226 createdLayers.Add(layers.GetLast());
227 entries.Add(new ConfigEntry(i18n->TranslateString("Encoders"), layers.GetLast()));
228 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
229 tree_freac->Add(entries.GetLast());
230
231 /* Add output files configuration layer.
232 */
233 layers.Add(new ConfigureFiles());
234 createdLayers.Add(layers.GetLast());
235 entries.Add(new ConfigEntry(i18n->TranslateString("Output files"), layers.GetLast()));
236 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
237 tree_freac->Add(entries.GetLast());
238
239 /* Add DSP configuration layer.
240 */
241 layers.Add(new ConfigureDSP());
242 createdLayers.Add(layers.GetLast());
243 entries.Add(new ConfigEntry(i18n->TranslateString("Processing"), layers.GetLast()));
244 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
245 tree_freac->Add(entries.GetLast());
246
247 /* Add verification configuration layer.
248 */
249 layers.Add(new ConfigureVerification());
250 createdLayers.Add(layers.GetLast());
251 entries.Add(new ConfigEntry(i18n->TranslateString("Verification"), layers.GetLast()));
252 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
253 tree_freac->Add(entries.GetLast());
254
255 /* Add resources configuration layer.
256 */
257 #ifndef __WIN32__
258 if (CPU().GetNumLogicalCPUs() > 1)
259 {
260 #endif
261 layers.Add(new ConfigureResources());
262 createdLayers.Add(layers.GetLast());
263 entries.Add(new ConfigEntry(i18n->TranslateString("Resources"), layers.GetLast()));
264 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
265 tree_freac->Add(entries.GetLast());
266 #ifndef __WIN32__
267 }
268 #endif
269
270 /* Add interface configuration layers.
271 */
272 if (i18n->GetNOfLanguages() > 1)
273 {
274 layers.Add(new ConfigureLanguage());
275 createdLayers.Add(layers.GetLast());
276 entries.Add(new ConfigEntry(i18n->TranslateString("Language"), layers.GetLast()));
277 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
278 tree_interface->Add(entries.GetLast());
279 }
280
281 layers.Add(new ConfigureInterface());
282 createdLayers.Add(layers.GetLast());
283 entries.Add(new ConfigEntry(i18n->TranslateString("Joblist"), layers.GetLast()));
284 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
285 tree_interface->Add(entries.GetLast());
286
287 tree_freac->Add(tree_interface);
288
289 /* Add ripper and CDDB configuration layers.
290 */
291 Component *component = NIL;
292
293 if (component == NIL) component = boca.CreateComponentByID("cdio-dec");
294 if (component == NIL) component = boca.CreateComponentByID("cdparanoia-dec");
295 if (component == NIL) component = boca.CreateComponentByID("cdrip-dec");
296 if (component == NIL) component = boca.CreateComponentByID("akrip-dec");
297
298 if (component != NIL)
299 {
300 if (component->GetConfigurationLayer() != NIL)
301 {
302 components.Add(component);
303 layers.Add(component->GetConfigurationLayer());
304
305 i18n->SetContext("Configuration");
306
307 entries.Add(new ConfigEntry(i18n->TranslateString("Settings"), layers.GetLast()));
308 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
309
310 tree_ripper->Add(entries.GetLast());
311 }
312 else
313 {
314 boca.DeleteComponent(component);
315 }
316 }
317
318 layers.Add(new ConfigureCDDB());
319 createdLayers.Add(layers.GetLast());
320 entries.Add(new ConfigEntry(i18n->TranslateString("CDDB"), layers.GetLast()));
321 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
322 tree_ripper->Add(entries.GetLast());
323
324 tree_freac->Add(tree_ripper);
325
326 /* Add metadata configuration layers.
327 */
328 layers.Add(new ConfigureTagFormats());
329 createdLayers.Add(layers.GetLast());
330 entries.Add(new ConfigEntry(i18n->TranslateString("Tag formats"), layers.GetLast()));
331 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
332 tree_metadata->Add(entries.GetLast());
333
334 layers.Add(new ConfigureTagFields());
335 createdLayers.Add(layers.GetLast());
336 entries.Add(new ConfigEntry(i18n->TranslateString("Tag fields"), layers.GetLast()));
337 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
338 tree_metadata->Add(entries.GetLast());
339
340 layers.Add(new ConfigureAlbumArt());
341 createdLayers.Add(layers.GetLast());
342 entries.Add(new ConfigEntry(i18n->TranslateString("Album art"), layers.GetLast()));
343 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
344 tree_metadata->Add(entries.GetLast());
345
346 if (boca.GetNumberOfComponentsOfType(COMPONENT_TYPE_PLAYLIST) > 0)
347 {
348 layers.Add(new ConfigurePlaylists());
349 createdLayers.Add(layers.GetLast());
350 entries.Add(new ConfigEntry(i18n->TranslateString("Playlists"), layers.GetLast()));
351 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
352 tree_metadata->Add(entries.GetLast());
353 }
354
355 layers.Add(new ConfigureCueSheets());
356 createdLayers.Add(layers.GetLast());
357 entries.Add(new ConfigEntry(i18n->TranslateString("Cue sheets"), layers.GetLast()));
358 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
359 tree_metadata->Add(entries.GetLast());
360
361 tree_freac->Add(tree_metadata);
362
363 /* Add component configuration layers.
364 */
365 i18n->SetContext("Configuration");
366
367 for (Int i = 0; i < boca.GetNumberOfComponents(); i++)
368 {
369 if (boca.GetComponentID(i) == "cdio-dec") continue;
370 if (boca.GetComponentID(i) == "cdparanoia-dec") continue;
371 if (boca.GetComponentID(i) == "cdrip-dec") continue;
372 if (boca.GetComponentID(i) == "akrip-dec") continue;
373
374 Component *component = boca.CreateComponentByID(boca.GetComponentID(i));
375
376 if (component == NIL) continue;
377
378 if (component->GetConfigurationLayer() != NIL)
379 {
380 components.Add(component);
381 layers.Add(component->GetConfigurationLayer());
382 entries.Add(new ConfigEntry(component->GetName(), layers.GetLast()));
383 entries.GetLast()->onChangeLayer.Connect(&ConfigDialog::OnSelectEntry, this);
384
385 Tree *tree = NIL;
386
387 switch (component->GetType())
388 {
389 case BoCA::COMPONENT_TYPE_EXTENSION: tree = tree_extension; break;
390 case BoCA::COMPONENT_TYPE_DECODER: tree = tree_decoders; break;
391 case BoCA::COMPONENT_TYPE_ENCODER: tree = tree_encoders; break;
392 case BoCA::COMPONENT_TYPE_VERIFIER: tree = tree_verifiers; break;
393 case BoCA::COMPONENT_TYPE_TAGGER: tree = tree_taggers; break;
394 case BoCA::COMPONENT_TYPE_PLAYLIST: tree = tree_playlists; break;
395 case BoCA::COMPONENT_TYPE_DSP: tree = tree_dsp; break;
396 case BoCA::COMPONENT_TYPE_OUTPUT: tree = tree_output; break;
397 default:
398 case BoCA::COMPONENT_TYPE_UNKNOWN: tree = tree_other; break;
399 }
400
401 tree->Add(entries.GetLast());
402 }
403 else
404 {
405 boca.DeleteComponent(component);
406 }
407 }
408 }
409
410 Void freac::ConfigDialog::DeleteLayers()
411 {
412 if (layers.Length() == 0) return;
413
414 for (Int i = 0; i < createdLayers.Length(); i++) DeleteObject(createdLayers.GetNth(i));
415
416 createdLayers.RemoveAll();
417
418 for (Int i = 0; i < entries.Length(); i++) DeleteObject(entries.GetNth(i));
419
420 layers.RemoveAll();
421 entries.RemoveAll();
422
423 tree_freac->Remove(tree_interface);
424 tree_freac->Remove(tree_ripper);
425 tree_freac->Remove(tree_metadata);
426
427 Registry &boca = Registry::Get();
428
429 for (Int i = 0; i < components.Length(); i++)
430 {
431 Component *component = components.GetNth(i);
432
433 boca.DeleteComponent(component);
434 }
435
436 components.RemoveAll();
437
438 selectedLayer = NIL;
439 }
440
441 const Error &freac::ConfigDialog::ShowDialog()
442 {
443 /* Select initial page.
444 */
445 if (initialPage == ConfigurePagePrevious) initialPage = previousPage;
446
447 ConfigEntry *initialEntry = entries.GetNth(initialPage);
448 Tree *initialTree = (Tree *) initialEntry->GetContainer()->GetContainer();
449
450 initialTree->Open();
451 initialTree->SelectEntry(initialEntry);
452
453 /* Show dialog.
454 */
455 mainWnd->WaitUntilClosed();
456
457 /* Save selected page.
458 */
459 foreach (ConfigEntry *entry, entries)
460 {
461 if (entry->GetLayer() != selectedLayer) continue;
462
463 previousPage = ConfigurePage(foreachindex);
464
465 break;
466 }
467
468 return error;
469 }
470
471 const Error &freac::ConfigDialog::ShowDialog(ConfigurePage page)
472 {
473 initialPage = page;
474
475 return ShowDialog();
476 }
477
478 Void freac::ConfigDialog::OK()
479 {
480 for (Int i = 0; i < layers.Length(); i++)
481 {
482 if (layers.GetNth(i)->SaveSettings() == Error()) return;
483 }
484
485 mainWnd->Close();
486 }
487
488 Void freac::ConfigDialog::Cancel()
489 {
490 BoCA::Config *config = BoCA::Config::Get();
491
492 config->SetActiveConfiguration(initialConfig);
493
494 mainWnd->Close();
495 }
496
497 Void freac::ConfigDialog::OnChangeSize(const Size &nSize)
498 {
499 Rect clientRect = Rect(mainWnd->GetMainLayer()->GetPosition(), mainWnd->GetMainLayer()->GetSize());
500 Size clientSize = Size(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
501
502 combo_config->SetWidth(clientSize.cx - text_config->GetUnscaledTextWidth() - 198);
503 edit_config->SetWidth(clientSize.cx - text_config->GetUnscaledTextWidth() - 198);
504
505 list_layers->SetSize(Size(210, clientSize.cy - 94));
506 }
507
508 Void freac::ConfigDialog::OnSelectConfiguration()
509 {
510 BoCA::Config *config = BoCA::Config::Get();
511 BoCA::I18n *i18n = BoCA::I18n::Get();
512
513 i18n->SetContext("Configuration");
514
515 Surface *surface = mainWnd->GetDrawSurface();
516
517 if (combo_config->GetSelectedEntryNumber() == 0)
518 {
519 button_config_delete->Deactivate();
520
521 surface->StartPaint(Rect(combo_config->GetRealPosition(), combo_config->GetRealSize()));
522
523 edit_config->Hide();
524 combo_config->Show();
525
526 surface->EndPaint();
527 }
528 else
529 {
530 button_config_delete->Activate();
531
532 surface->StartPaint(Rect(combo_config->GetRealPosition(), combo_config->GetRealSize()));
533
534 combo_config->Hide();
535 edit_config->Show();
536 edit_config->SetDropDownList(combo_config);
537 edit_config->SetText(combo_config->GetSelectedEntry()->GetText());
538
539 surface->EndPaint();
540 }
541
542 surface->PaintRect(mainWnd->GetClientRect());
543
544 if (selectedLayer != NIL) for (Int i = 0; i < layers.Length(); i++) layers.GetNth(i)->SaveSettings();
545
546 if (combo_config->GetSelectedEntryNumber() == 0) config->SetActiveConfiguration("default");
547 else config->SetActiveConfiguration(combo_config->GetSelectedEntry()->GetText());
548
549 surface->StartPaint(mainWnd->GetVisibleArea());
550
551 DeleteLayers();
552 AddLayers();
553
554 tree_freac->SelectNthEntry(0);
555
556 list_layers->Paint(SP_PAINT);
557
558 surface->EndPaint();
559 }
560
561 Void freac::ConfigDialog::OnSelectConfigurationByName()
562 {
563 combo_config->SelectEntry(edit_config->GetText());
564 }
565
566 Void freac::ConfigDialog::OnEditConfigurationName(const String &name)
567 {
568 if (combo_config->GetSelectedEntryNumber() == 0) return;
569
570 BoCA::Config *config = BoCA::Config::Get();
571 ListEntry *entry = combo_config->GetSelectedEntry();
572
573 String newName = name;
574
575 for (Int i = 1, n = 0; i < combo_config->Length(); i++)
576 {
577 ListEntry *nth = combo_config->GetNthEntry(i);
578
579 if (entry == nth) continue;
580
581 if (nth->GetText() == newName)
582 {
583 newName = String(name).Append(" (").Append(String::FromInt(++n)).Append(")");
584
585 i = 0;
586 }
587 }
588
589 entry->SetText(newName);
590
591 edit_config->SetDropDownList(combo_config);
592
593 config->SetConfigurationName(newName);
594 }
595
596 Void freac::ConfigDialog::OnCreateConfig()
597 {
598 BoCA::I18n *i18n = BoCA::I18n::Get();
599
600 i18n->SetContext("Configuration");
601
602 BoCA::Config *config = BoCA::Config::Get();
603 ListEntry *entry = combo_config->AddEntry(i18n->TranslateString("New configuration"));
604
605 /* Find a name for the new configuration.
606 */
607 Int n = 0;
608
609 while (config->AddConfiguration(entry->GetText()) != Success())
610 {
611 entry->SetText(i18n->TranslateString("New configuration").Append(" (").Append(String::FromInt(++n)).Append(")"));
612 }
613
614 /* Save configuration.
615 */
616 for (Int i = 0; i < layers.Length(); i++) layers.GetNth(i)->SaveSettings();
617
618 /* Activate the new configuration.
619 */
620 config->SetActiveConfiguration(entry->GetText());
621
622 combo_config->SelectEntry(entry);
623 edit_config->MarkAll();
624 }
625
626 Void freac::ConfigDialog::OnDeleteConfig()
627 {
628 BoCA::Config *config = BoCA::Config::Get();
629 ListEntry *entry = combo_config->GetSelectedEntry();
630 String name = entry->GetText();
631
632 selectedLayer = NIL;
633
634 combo_config->SelectNthEntry(0);
635 combo_config->Remove(entry);
636
637 config->RemoveConfiguration(name);
638 }
639
640 Void freac::ConfigDialog::OnSelectEntry(ConfigLayer *newLayer)
641 {
642 if (newLayer != NIL)
643 {
644 #ifdef __WIN32__
645 Int frameWidth = mainWnd->GetFrameWidth();
646 #else
647 Int frameWidth = 4;
648 #endif
649 newLayer->SetPosition(Point(218, 40));
650
651 mainWnd->SetMinimumSize(Size(Math::Max(232, newLayer->GetWidth() + 218 + 2 * frameWidth), Math::Max(342, newLayer->GetHeight() + 105 + 2 * frameWidth)));
652
653 /* Wrap layer drawing in a paint operation.
654 */
655 Surface *surface = mainWnd->GetDrawSurface();
656 Layer *mainLayer = mainWnd->GetMainLayer();
657
658 surface->StartPaint(Rect(mainLayer->GetRealPosition() + Point(218, 40) * surface->GetSurfaceDPI() / 96.0, mainLayer->GetRealSize() - Size(218, 40) * surface->GetSurfaceDPI() / 96.0));
659
660 if (selectedLayer != NIL) mainLayer->Remove(selectedLayer);
661
662 mainLayer->Add(newLayer);
663
664 surface->EndPaint();
665
666 selectedLayer = newLayer;
667 }
668 else
669 {
670 mainWnd->SetMinimumSize(Size(232, 342));
671
672 Layer *mainLayer = mainWnd->GetMainLayer();
673
674 if (selectedLayer != NIL) mainLayer->Remove(selectedLayer);
675
676 selectedLayer = NIL;
677 }
678 }
679
680 Void freac::ConfigDialog::OnChangeComponentSettings(const String &componentID)
681 {
682 /* One of the component configurations has changed
683 * so find the affected component here.
684 */
685 Component *component = NIL;
686 Int componentIndex = -1;
687
688 for (Int i = 0; i < components.Length(); i++)
689 {
690 component = components.GetNth(i);
691 componentIndex = i;
692
693 if (component->GetID() == componentID) break;
694 }
695
696 if (component == NIL) return;
697
698 /* Replace the affected component.
699 */
700 Registry &boca = Registry::Get();
701
702 for (Int i = 0; i < layers.Length(); i++)
703 {
704 if (layers.GetNth(i) != component->GetConfigurationLayer()) continue;
705
706 Component *replacement = boca.CreateComponentByID(componentID);
707
708 if (replacement != NIL)
709 {
710 boca.DeleteComponent(component);
711
712 components.SetNth(componentIndex, replacement);
713
714 layers.SetNth(i, replacement->GetConfigurationLayer());
715 ((ConfigEntry *) entries.GetNth(i))->SetLayer(layers.GetNth(i));
716 }
717
718 break;
719 }
720 }