Debian Codegraph @

src/dialogs/config/config_tagfields.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_tagfields.h>
14
15 #include <config.h>
16
17 using namespace BoCA::AS;
18
19 freac::ConfigureTagFields::ConfigureTagFields()
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 readChapters = config->GetIntValue(Config::CategoryTagsID, Config::TagsReadChaptersID, Config::TagsReadChaptersDefault);
29 writeChapters = config->GetIntValue(Config::CategoryTagsID, Config::TagsWriteChaptersID, Config::TagsWriteChaptersDefault);
30
31 writeMCDI = config->GetIntValue(Config::CategoryTagsID, Config::TagsWriteMCDIID, Config::TagsWriteMCDIDefault);
32 preserveReplayGain = config->GetIntValue(Config::CategoryTagsID, Config::TagsPreserveReplayGainID, Config::TagsPreserveReplayGainDefault);
33
34 useFileNames = config->GetIntValue(Config::CategoryTagsID, Config::TagsExtractFromFileNamesID, Config::TagsExtractFromFileNamesDefault);
35
36 replaceComments = config->GetIntValue(Config::CategoryTagsID, Config::TagsReplaceExistingCommentsID, Config::TagsReplaceExistingCommentsDefault);
37
38 /* Create widgets.
39 */
40 group_chapters = new GroupBox(i18n->TranslateString("Chapters"), Point(7, 11), Size(263, 64));
41
42 check_read_chapters = new CheckBox(i18n->TranslateString("Read chapters from files"), Point(10, 14), Size(243, 0), &readChapters);
43 check_write_chapters = new CheckBox(i18n->TranslateString("Write chapters to files"), check_read_chapters->GetPosition() + Point(0, 23), Size(243, 0), &writeChapters);
44
45 group_chapters->Add(check_read_chapters);
46 group_chapters->Add(check_write_chapters);
47
48 group_special = new GroupBox(i18n->TranslateString("Special fields"), Point(278, 11), Size(263, 64));
49
50 check_mcdi = new CheckBox(i18n->TranslateString("Write CD table of contents"), Point(10, 14), Size(243, 0), &writeMCDI);
51 check_replaygain = new CheckBox(i18n->TranslateString("Preserve Replay Gain information"), check_mcdi->GetPosition() + Point(0, 23), Size(243, 0), &preserveReplayGain);
52
53 group_special->Add(check_mcdi);
54 group_special->Add(check_replaygain);
55
56 Add(group_chapters);
57 Add(group_special);
58
59 group_misc = new GroupBox(i18n->TranslateString("Miscellaneous"), Point(7, 87), Size(552, 41));
60
61 check_filenames = new CheckBox(i18n->TranslateString("Fill missing fields with information obtained from file names"), Point(10, 14), Size(514, 0), &useFileNames);
62
63 group_misc->Add(check_filenames);
64
65 Add(group_misc);
66
67 group_comments = new GroupBox(i18n->TranslateString("Comments"), Point(7, 140), Size(552, 67));
68
69 text_defcomment = new Text(i18n->AddColon(i18n->TranslateString("Default comment string")), Point(10, 15));
70 edit_defcomment = new EditBox(config->GetStringValue(Config::CategoryTagsID, Config::TagsDefaultCommentID, NIL), Point(17 + text_defcomment->GetUnscaledTextWidth(), 12), Size(507 - text_defcomment->GetUnscaledTextWidth(), 0), 0);
71 check_replace = new CheckBox(i18n->TranslateString("Replace existing comments with default comment"), Point(10, edit_defcomment->GetY() + 28), Size(514, 0), &replaceComments);
72
73 group_comments->Add(text_defcomment);
74 group_comments->Add(edit_defcomment);
75 group_comments->Add(check_replace);
76
77 Add(group_comments);
78
79 /* Adjust element widths.
80 */
81 Int maxTextSize = Math::Max(Math::Max(check_read_chapters->GetUnscaledTextWidth(), check_write_chapters->GetUnscaledTextWidth()), Math::Max(check_mcdi->GetUnscaledTextWidth(), check_replaygain->GetUnscaledTextWidth()));
82
83 group_comments->SetWidth(Math::Max(552, (maxTextSize + 21 + 20) * 2 + 8));
84
85 edit_defcomment->SetWidth(group_comments->GetWidth() - edit_defcomment->GetX() - 10);
86 check_replace->SetWidth(group_comments->GetWidth() - 20);
87
88 group_chapters->SetWidth((group_comments->GetWidth() - 8) / 2);
89 group_special->SetX(group_chapters->GetWidth() + 15);
90 group_special->SetWidth(group_chapters->GetWidth() + group_comments->GetWidth() % 2);
91
92 check_read_chapters->SetWidth(group_chapters->GetWidth() - 20);
93 check_write_chapters->SetWidth(group_chapters->GetWidth() - 20);
94
95 check_mcdi->SetWidth(group_special->GetWidth() - 20);
96 check_replaygain->SetWidth(group_special->GetWidth() - 20);
97
98 group_misc->SetWidth(group_comments->GetWidth());
99
100 check_filenames->SetWidth(group_misc->GetWidth() - 20);
101
102 /* Finish initialization.
103 */
104 SetSize(group_comments->GetSize() + Size(14, group_chapters->GetHeight() + group_misc->GetHeight() + 42));
105 }
106
107 freac::ConfigureTagFields::~ConfigureTagFields()
108 {
109 DeleteObject(group_chapters);
110 DeleteObject(check_read_chapters);
111 DeleteObject(check_write_chapters);
112
113 DeleteObject(group_special);
114 DeleteObject(check_mcdi);
115 DeleteObject(check_replaygain);
116
117 DeleteObject(group_misc);
118 DeleteObject(check_filenames);
119
120 DeleteObject(group_comments);
121 DeleteObject(text_defcomment);
122 DeleteObject(edit_defcomment);
123 DeleteObject(check_replace);
124 }
125
126 Int freac::ConfigureTagFields::SaveSettings()
127 {
128 BoCA::Config *config = BoCA::Config::Get();
129
130 config->SetIntValue(Config::CategoryTagsID, Config::TagsReadChaptersID, readChapters);
131 config->SetIntValue(Config::CategoryTagsID, Config::TagsWriteChaptersID, writeChapters);
132
133 config->SetIntValue(Config::CategoryTagsID, Config::TagsWriteMCDIID, writeMCDI);
134 config->SetIntValue(Config::CategoryTagsID, Config::TagsPreserveReplayGainID, preserveReplayGain);
135
136 config->SetIntValue(Config::CategoryTagsID, Config::TagsExtractFromFileNamesID, useFileNames);
137
138 config->SetStringValue(Config::CategoryTagsID, Config::TagsDefaultCommentID, edit_defcomment->GetText());
139 config->SetIntValue(Config::CategoryTagsID, Config::TagsReplaceExistingCommentsID, replaceComments);
140
141 return Success();
142 }