Debian Codegraph @

src/dialogs/config/configcomponent.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2021 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/configcomponent.h>
14
15 #include <config.h>
16
17 using namespace BoCA;
18 using namespace BoCA::AS;
19
20 freac::ConfigComponentDialog::ConfigComponentDialog(Component *component)
21 {
22 BoCA::Config *config = BoCA::Config::Get();
23 BoCA::I18n *i18n = BoCA::I18n::Get();
24
25 i18n->SetContext("Configuration");
26
27 componentID = component->GetID();
28 layer = component->GetConfigurationLayer();
29
30 if (layer != NIL)
31 {
32 mainWnd = new Window(component->GetName(), Point(config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosXID, Config::SettingsWindowPosXDefault), config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosYID, Config::SettingsWindowPosYDefault)) + Point(60, 60), layer->GetSize() + Size(8, 73));
33 mainWnd->SetRightToLeft(i18n->IsActiveLanguageRightToLeft());
34
35 mainWnd_titlebar = new Titlebar(TB_CLOSEBUTTON);
36 divbar = new Divider(39, OR_HORZ | OR_BOTTOM);
37
38 btn_cancel = new Button(i18n->TranslateString("Cancel"), Point(175, 29), Size());
39 btn_cancel->onAction.Connect(&ConfigComponentDialog::Cancel, this);
40 btn_cancel->SetOrientation(OR_LOWERRIGHT);
41
42 btn_ok = new Button(i18n->TranslateString("OK"), btn_cancel->GetPosition() - Point(88, 0), Size());
43 btn_ok->onAction.Connect(&ConfigComponentDialog::OK, this);
44 btn_ok->SetOrientation(OR_LOWERRIGHT);
45
46 Add(mainWnd);
47
48 mainWnd->Add(mainWnd_titlebar);
49 mainWnd->Add(divbar);
50 mainWnd->Add(btn_ok);
51 mainWnd->Add(btn_cancel);
52
53 mainWnd->GetMainLayer()->Add(layer);
54
55 mainWnd->SetFlags(mainWnd->GetFlags() | WF_NOTASKBUTTON | WF_MODAL);
56 mainWnd->SetIcon(ImageLoader::Load(String(Config::Get()->resourcesPath).Append("icons/freac.png")));
57 }
58 else
59 {
60 mainWnd = NIL;
61 mainWnd_titlebar = NIL;
62
63 btn_cancel = NIL;
64 btn_ok = NIL;
65
66 divbar = NIL;
67 }
68 }
69
70 freac::ConfigComponentDialog::~ConfigComponentDialog()
71 {
72 if (layer == NIL) return;
73
74 DeleteObject(mainWnd_titlebar);
75 DeleteObject(mainWnd);
76 DeleteObject(btn_ok);
77 DeleteObject(btn_cancel);
78 DeleteObject(divbar);
79 }
80
81 const Error &freac::ConfigComponentDialog::ShowDialog()
82 {
83 if (layer != NIL) mainWnd->WaitUntilClosed();
84 else error = Error();
85
86 return error;
87 }
88
89 Void freac::ConfigComponentDialog::OK()
90 {
91 if (layer->SaveSettings() == Error()) return;
92
93 mainWnd->Close();
94
95 Settings::onChangeComponentSettings.Emit(componentID);
96 }
97
98 Void freac::ConfigComponentDialog::Cancel()
99 {
100 mainWnd->Close();
101 }