| 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_albumart.h> |
| 14 | |
| 15 | #include <config.h> |
| 16 | |
| 17 | using namespace BoCA::AS; |
| 18 | |
| 19 | freac::ConfigureAlbumArt::ConfigureAlbumArt() |
| 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 | enableAlbumArtReadFromTags = config->GetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtReadFromTagsID, Config::TagsAlbumArtReadFromTagsDefault); |
| 29 | enableAlbumArtWriteToTags = config->GetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtWriteToTagsID, Config::TagsAlbumArtWriteToTagsDefault); |
| 30 | |
| 31 | enableAlbumArtReadFromFiles = config->GetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtReadFromFilesID, Config::TagsAlbumArtReadFromFilesDefault); |
| 32 | enableAlbumArtWriteToFiles = config->GetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtWriteToFilesID, Config::TagsAlbumArtWriteToFilesDefault); |
| 33 | |
| 34 | albumArtUsePatterns = config->GetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtUsePatternsID, Config::TagsAlbumArtUsePatternsDefault); |
| 35 | |
| 36 | albumArtMaxFileSize = config->GetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtMaxFileSizeID, Config::TagsAlbumArtMaxFileSizeDefault); |
| 37 | |
| 38 | albumArtWriteRef = config->GetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtWriteToFilesWithReferenceID, Config::TagsAlbumArtWriteToFilesWithReferenceDefault); |
| 39 | |
| 40 | /* Create widgets. |
| 41 | */ |
| 42 | group_albumart_tags = new GroupBox(i18n->TranslateString("Album art tags"), Point(7, 11), Size(552, 120)); |
| 43 | |
| 44 | check_albumart_read_tags = new CheckBox(i18n->TranslateString("Read album art from tags"), Point(10, 14), Size(262, 0), &enableAlbumArtReadFromTags); |
| 45 | |
| 46 | check_albumart_write_tags = new CheckBox(i18n->TranslateString("Write album art to tags"), Point(280, 14), Size(262, 0), &enableAlbumArtWriteToTags); |
| 47 | check_albumart_write_tags->onAction.Connect(&ConfigureAlbumArt::ToggleWriteAlbumArt, this); |
| 48 | |
| 49 | list_albumart_write_tags_format = new ListBox(Point(297, 39), Size(236, 71)); |
| 50 | list_albumart_write_tags_format->SetFlags(LF_MULTICHECKBOX); |
| 51 | |
| 52 | Registry &boca = Registry::Get(); |
| 53 | |
| 54 | for (Int i = 0; i < boca.GetNumberOfComponents(); i++) |
| 55 | { |
| 56 | if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_TAGGER) continue; |
| 57 | |
| 58 | const Array<TagSpec *> &specs = boca.GetComponentTagSpecs(i); |
| 59 | |
| 60 | foreach (TagSpec *spec, specs) |
| 61 | { |
| 62 | if (spec->IsCoverArtSupported()) list_albumart_write_tags_format->AddEntry(spec->GetName(), config->GetIntValue(Config::CategoryTagsID, String("CoverArtWriteTo").Append(spec->GetName().Replace(" ", NIL)), spec->IsCoverArtDefault())); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | group_albumart_tags->Add(check_albumart_read_tags); |
| 67 | group_albumart_tags->Add(check_albumart_write_tags); |
| 68 | group_albumart_tags->Add(list_albumart_write_tags_format); |
| 69 | |
| 70 | group_albumart_files = new GroupBox(i18n->TranslateString("Album art files"), Point(7, 143), Size(552, 116)); |
| 71 | |
| 72 | check_albumart_read_files = new CheckBox(i18n->TranslateString("Read album art from files"), Point(10, 14), Size(262, 0), &enableAlbumArtReadFromFiles); |
| 73 | check_albumart_read_files->onAction.Connect(&ConfigureAlbumArt::ToggleReadAlbumArt, this); |
| 74 | |
| 75 | check_albumart_read_patterns = new CheckBox(i18n->TranslateString("Restrict file names"), Point(27, 37), Size(245, 0), &albumArtUsePatterns); |
| 76 | check_albumart_read_patterns->onAction.Connect(&ConfigureAlbumArt::ToggleUsePatterns, this); |
| 77 | |
| 78 | edit_albumart_read_patterns = new EditBox(config->GetStringValue(Config::CategoryTagsID, Config::TagsAlbumArtPatternsID, Config::TagsAlbumArtPatternsDefault), Point(44, 62), Size(228, 0), 0); |
| 79 | |
| 80 | list_albumart_read_patterns = new List(); |
| 81 | list_albumart_read_patterns->AddEntry(Config::TagsAlbumArtPatternsDefault); |
| 82 | |
| 83 | edit_albumart_read_patterns->SetDropDownList(list_albumart_read_patterns); |
| 84 | |
| 85 | Int maxTextSize = Math::Max(Font().GetUnscaledTextSizeX(i18n->TranslateString("%1 kB", "Technical").Replace("%1", "250")), Font().GetUnscaledTextSizeX(i18n->TranslateString("unlimited"))); |
| 86 | |
| 87 | text_albumart_read_max = new Text(i18n->AddColon(i18n->TranslateString("File size limit")), Point(27, 91)); |
| 88 | text_albumart_read_max_value = new Text(NIL, Point(272 - maxTextSize, 91)); |
| 89 | |
| 90 | slider_albumart_read_max = new Slider(Point(34 + text_albumart_read_max->GetUnscaledTextWidth(), 89), Size(230 - text_albumart_read_max->GetUnscaledTextWidth() - maxTextSize, 0), OR_HORZ, NIL, 1, 21); |
| 91 | slider_albumart_read_max->SetValue(albumArtMaxFileSize == 0 ? 9999 : albumArtMaxFileSize / 25); |
| 92 | slider_albumart_read_max->onValueChange.Connect(&ConfigureAlbumArt::ChangeMaxAlbumArtSize, this); |
| 93 | |
| 94 | check_albumart_write_files = new CheckBox(i18n->TranslateString("Write album art to files"), Point(280, 14), Size(262, 0), &enableAlbumArtWriteToFiles); |
| 95 | check_albumart_write_files->onAction.Connect(&ConfigureAlbumArt::ToggleWriteAlbumArt, this); |
| 96 | |
| 97 | text_albumart_write_files_name = new Text(i18n->AddColon(i18n->TranslateString("Filename pattern")), Point(297, 39)); |
| 98 | edit_albumart_write_files_name = new EditBox(config->GetStringValue(Config::CategoryTagsID, Config::TagsAlbumArtFilenamePatternID, Config::TagsAlbumArtFilenamePatternDefault), Point(297, 62), Size(236, 0), 0); |
| 99 | |
| 100 | check_albumart_write_files_ref = new CheckBox(i18n->TranslateString("Add reference to audio file tag"), Point(297, 89), Size(236, 0), &albumArtWriteRef); |
| 101 | check_albumart_write_files_ref->SetWidth(Math::Max(245, check_albumart_write_files_ref->GetUnscaledTextWidth() + 21)); |
| 102 | |
| 103 | group_albumart_files->SetWidth(307 + check_albumart_write_files_ref->GetWidth()); |
| 104 | |
| 105 | group_albumart_files->Add(check_albumart_read_files); |
| 106 | group_albumart_files->Add(check_albumart_read_patterns); |
| 107 | group_albumart_files->Add(edit_albumart_read_patterns); |
| 108 | group_albumart_files->Add(text_albumart_read_max); |
| 109 | group_albumart_files->Add(slider_albumart_read_max); |
| 110 | group_albumart_files->Add(text_albumart_read_max_value); |
| 111 | group_albumart_files->Add(check_albumart_write_files); |
| 112 | group_albumart_files->Add(text_albumart_write_files_name); |
| 113 | group_albumart_files->Add(edit_albumart_write_files_name); |
| 114 | group_albumart_files->Add(check_albumart_write_files_ref); |
| 115 | |
| 116 | Add(group_albumart_tags); |
| 117 | Add(group_albumart_files); |
| 118 | |
| 119 | /* Adjust element widths. |
| 120 | */ |
| 121 | group_albumart_tags->SetWidth(group_albumart_files->GetWidth()); |
| 122 | |
| 123 | check_albumart_write_tags->SetWidth(group_albumart_tags->GetWidth() - check_albumart_write_tags->GetX() - 10); |
| 124 | list_albumart_write_tags_format->SetWidth(check_albumart_write_tags->GetWidth() - 17); |
| 125 | |
| 126 | check_albumart_write_files->SetWidth(group_albumart_files->GetWidth() - check_albumart_write_files->GetX() - 10); |
| 127 | edit_albumart_write_files_name->SetWidth(group_albumart_files->GetWidth() - edit_albumart_write_files_name->GetX() - 10); |
| 128 | check_albumart_write_files_ref->SetWidth(group_albumart_files->GetWidth() - check_albumart_write_files_ref->GetX() - 10); |
| 129 | |
| 130 | /* Finish initialization. |
| 131 | */ |
| 132 | ToggleReadAlbumArt(); |
| 133 | ToggleWriteAlbumArt(); |
| 134 | |
| 135 | ChangeMaxAlbumArtSize(slider_albumart_read_max->GetValue()); |
| 136 | |
| 137 | SetSize(group_albumart_tags->GetSize() + Size(14, group_albumart_files->GetHeight() + 30)); |
| 138 | } |
| 139 | |
| 140 | freac::ConfigureAlbumArt::~ConfigureAlbumArt() |
| 141 | { |
| 142 | DeleteObject(group_albumart_tags); |
| 143 | DeleteObject(check_albumart_read_tags); |
| 144 | DeleteObject(check_albumart_write_tags); |
| 145 | DeleteObject(list_albumart_write_tags_format); |
| 146 | |
| 147 | DeleteObject(group_albumart_files); |
| 148 | DeleteObject(check_albumart_read_files); |
| 149 | DeleteObject(check_albumart_read_patterns); |
| 150 | DeleteObject(edit_albumart_read_patterns); |
| 151 | DeleteObject(text_albumart_read_max); |
| 152 | DeleteObject(slider_albumart_read_max); |
| 153 | DeleteObject(text_albumart_read_max_value); |
| 154 | DeleteObject(check_albumart_write_files); |
| 155 | DeleteObject(text_albumart_write_files_name); |
| 156 | DeleteObject(edit_albumart_write_files_name); |
| 157 | DeleteObject(check_albumart_write_files_ref); |
| 158 | } |
| 159 | |
| 160 | Void freac::ConfigureAlbumArt::ToggleWriteAlbumArt() |
| 161 | { |
| 162 | if (enableAlbumArtWriteToTags) list_albumart_write_tags_format->Activate(); |
| 163 | else list_albumart_write_tags_format->Deactivate(); |
| 164 | |
| 165 | if (enableAlbumArtWriteToFiles) |
| 166 | { |
| 167 | text_albumart_write_files_name->Activate(); |
| 168 | edit_albumart_write_files_name->Activate(); |
| 169 | check_albumart_write_files_ref->Activate(); |
| 170 | } |
| 171 | else |
| 172 | { |
| 173 | text_albumart_write_files_name->Deactivate(); |
| 174 | edit_albumart_write_files_name->Deactivate(); |
| 175 | check_albumart_write_files_ref->Deactivate(); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | Void freac::ConfigureAlbumArt::ToggleReadAlbumArt() |
| 180 | { |
| 181 | if (enableAlbumArtReadFromFiles) |
| 182 | { |
| 183 | check_albumart_read_patterns->Activate(); |
| 184 | |
| 185 | text_albumart_read_max->Activate(); |
| 186 | slider_albumart_read_max->Activate(); |
| 187 | text_albumart_read_max_value->Activate(); |
| 188 | |
| 189 | ToggleUsePatterns(); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | check_albumart_read_patterns->Deactivate(); |
| 194 | edit_albumart_read_patterns->Deactivate(); |
| 195 | |
| 196 | text_albumart_read_max->Deactivate(); |
| 197 | slider_albumart_read_max->Deactivate(); |
| 198 | text_albumart_read_max_value->Deactivate(); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | Void freac::ConfigureAlbumArt::ToggleUsePatterns() |
| 203 | { |
| 204 | if (albumArtUsePatterns) edit_albumart_read_patterns->Activate(); |
| 205 | else edit_albumart_read_patterns->Deactivate(); |
| 206 | } |
| 207 | |
| 208 | Void freac::ConfigureAlbumArt::ChangeMaxAlbumArtSize(Int value) |
| 209 | { |
| 210 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 211 | |
| 212 | i18n->SetContext("Configuration::Tags"); |
| 213 | |
| 214 | if (value <= 20) text_albumart_read_max_value->SetText(i18n->TranslateString("%1 kB", "Technical").Replace("%1", String::FromInt(value * 25))); |
| 215 | else text_albumart_read_max_value->SetText(i18n->TranslateString("unlimited")); |
| 216 | } |
| 217 | |
| 218 | Int freac::ConfigureAlbumArt::SaveSettings() |
| 219 | { |
| 220 | BoCA::Config *config = BoCA::Config::Get(); |
| 221 | Registry &boca = Registry::Get(); |
| 222 | |
| 223 | for (Int i = 0; i < boca.GetNumberOfComponents(); i++) |
| 224 | { |
| 225 | if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_TAGGER) continue; |
| 226 | |
| 227 | const Array<TagSpec *> &specs = boca.GetComponentTagSpecs(i); |
| 228 | |
| 229 | foreach (TagSpec *spec, specs) |
| 230 | { |
| 231 | if (spec->IsCoverArtSupported()) config->SetIntValue(Config::CategoryTagsID, String("CoverArtWriteTo").Append(spec->GetName().Replace(" ", NIL)), list_albumart_write_tags_format->GetEntry(spec->GetName())->IsMarked()); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | config->SetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtReadFromTagsID, enableAlbumArtReadFromTags); |
| 236 | config->SetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtWriteToTagsID, enableAlbumArtWriteToTags); |
| 237 | |
| 238 | config->SetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtReadFromFilesID, enableAlbumArtReadFromFiles); |
| 239 | config->SetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtWriteToFilesID, enableAlbumArtWriteToFiles); |
| 240 | |
| 241 | config->SetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtUsePatternsID, albumArtUsePatterns); |
| 242 | config->SetStringValue(Config::CategoryTagsID, Config::TagsAlbumArtPatternsID, edit_albumart_read_patterns->GetText()); |
| 243 | |
| 244 | config->SetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtMaxFileSizeID, slider_albumart_read_max->GetValue() % 21 * 25); |
| 245 | |
| 246 | config->SetStringValue(Config::CategoryTagsID, Config::TagsAlbumArtFilenamePatternID, edit_albumart_write_files_name->GetText()); |
| 247 | config->SetIntValue(Config::CategoryTagsID, Config::TagsAlbumArtWriteToFilesWithReferenceID, albumArtWriteRef); |
| 248 | |
| 249 | return Success(); |
| 250 | } |