| 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_playlists.h> |
| 14 | #include <dialogs/config/configcomponent.h> |
| 15 | |
| 16 | #include <config.h> |
| 17 | |
| 18 | using namespace BoCA::AS; |
| 19 | |
| 20 | using namespace smooth::GUI::Dialogs; |
| 21 | |
| 22 | Signal1<Void, Bool> freac::ConfigurePlaylists::onToggleCreateCueSheets; |
| 23 | |
| 24 | freac::ConfigurePlaylists::ConfigurePlaylists() |
| 25 | { |
| 26 | BoCA::Config *config = BoCA::Config::Get(); |
| 27 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 28 | |
| 29 | i18n->SetContext("Configuration::Playlists"); |
| 30 | |
| 31 | String playlistOutputDir = config->GetStringValue(Config::CategoryPlaylistID, Config::PlaylistOutputDirID, config->GetStringValue(Config::CategorySettingsID, Config::SettingsEncoderOutputDirectoryID, Config::SettingsEncoderOutputDirectoryDefault)); |
| 32 | String playlistOutputPattern = config->GetStringValue(Config::CategoryPlaylistID, Config::PlaylistFilenamePatternID, Config::PlaylistFilenamePatternDefault); |
| 33 | |
| 34 | createPlaylists = config->GetIntValue(Config::CategoryPlaylistID, Config::PlaylistCreatePlaylistID, Config::PlaylistCreatePlaylistDefault); |
| 35 | createCueSheets = config->GetIntValue(Config::CategoryPlaylistID, Config::PlaylistCreateCueSheetID, Config::PlaylistCreateCueSheetDefault); |
| 36 | useEncOutdir = config->GetIntValue(Config::CategoryPlaylistID, Config::PlaylistUseEncoderOutputDirID, Config::PlaylistUseEncoderOutputDirDefault); |
| 37 | createSingleFile = config->GetIntValue(Config::CategoryPlaylistID, Config::PlaylistCreateSingleFileID, Config::PlaylistCreateSingleFileDefault); |
| 38 | |
| 39 | group_options = new GroupBox(i18n->TranslateString("Playlists"), Point(7, 11), Size(552, 44)); |
| 40 | |
| 41 | check_createPlaylists = new CheckBox(i18n->TranslateString("Create playlists"), Point(10, 14), Size(157, 0), &createPlaylists); |
| 42 | check_createPlaylists->onAction.Connect(&ConfigurePlaylists::ToggleCreatePlaylists, this); |
| 43 | |
| 44 | Registry &boca = Registry::Get(); |
| 45 | |
| 46 | if (boca.GetNumberOfComponentsOfType(BoCA::COMPONENT_TYPE_PLAYLIST) == 0 || (boca.GetNumberOfComponentsOfType(BoCA::COMPONENT_TYPE_PLAYLIST) == 1 && boca.ComponentExists("cuesheet-playlist"))) |
| 47 | { |
| 48 | createPlaylists = False; |
| 49 | |
| 50 | check_createPlaylists->Deactivate(); |
| 51 | } |
| 52 | |
| 53 | check_createPlaylists->SetWidth(21 + check_createPlaylists->GetUnscaledTextWidth()); |
| 54 | |
| 55 | combo_formats = new ComboBox(Point(39 + check_createPlaylists->GetUnscaledTextWidth(), 13), Size(365 - check_createPlaylists->GetUnscaledTextWidth(), 0)); |
| 56 | |
| 57 | for (Int i = 0; i < boca.GetNumberOfComponents(); i++) |
| 58 | { |
| 59 | if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_PLAYLIST) continue; |
| 60 | |
| 61 | const Array<FileFormat *> &formats = boca.GetComponentFormats(i); |
| 62 | |
| 63 | foreach (FileFormat *format, formats) |
| 64 | { |
| 65 | const Array<String> &formatExtensions = format->GetExtensions(); |
| 66 | |
| 67 | combo_formats->AddEntry(format->GetName()); |
| 68 | |
| 69 | if (config->GetStringValue(Config::CategoryPlaylistID, Config::PlaylistFormatID, Config::PlaylistFormatDefault) == boca.GetComponentID(i).Append("-").Append(formatExtensions.GetNth(0))) combo_formats->SelectNthEntry(combo_formats->Length() - 1); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | combo_formats->onSelectEntry.Connect(&ConfigurePlaylists::SelectFormat, this); |
| 74 | |
| 75 | button_config = new Button(i18n->TranslateString("Configure plugin"), Point(412, 12), Size(130, 0)); |
| 76 | button_config->onAction.Connect(&ConfigurePlaylists::ConfigureFormat, this); |
| 77 | |
| 78 | SelectFormat(); |
| 79 | |
| 80 | group_options->Add(check_createPlaylists); |
| 81 | group_options->Add(combo_formats); |
| 82 | group_options->Add(button_config); |
| 83 | |
| 84 | group_outdir = new GroupBox(i18n->TranslateString("Output folder"), Point(7, 67), Size(552, 70)); |
| 85 | |
| 86 | check_useEncOutdir = new CheckBox(i18n->TranslateString("Use encoder output folder"), Point(10, 14), Size(444, 0), &useEncOutdir); |
| 87 | check_useEncOutdir->onAction.Connect(&ConfigurePlaylists::ToggleUseEncOutdir, this); |
| 88 | |
| 89 | edit_outdir = new EditBox(playlistOutputDir, Point(10, 39), Size(444, 0), 0); |
| 90 | |
| 91 | button_outdir_browse = new Button(i18n->TranslateString("Select"), Point(462, 38), Size(0, 0)); |
| 92 | button_outdir_browse->onAction.Connect(&ConfigurePlaylists::SelectDir, this); |
| 93 | |
| 94 | group_outdir->Add(check_useEncOutdir); |
| 95 | group_outdir->Add(edit_outdir); |
| 96 | group_outdir->Add(button_outdir_browse); |
| 97 | |
| 98 | group_filename = new GroupBox(i18n->TranslateString("Output filenames"), Point(7, 149), Size(552, 66)); |
| 99 | |
| 100 | text_filename = new Text(i18n->AddColon(i18n->TranslateString("Filename pattern")), Point(10, 15)); |
| 101 | edit_filename = new EditBox(playlistOutputPattern, Point(17 + text_filename->GetUnscaledTextWidth(), 12), Size(525 - text_filename->GetUnscaledTextWidth(), 0), 0); |
| 102 | |
| 103 | list_filename = new List(); |
| 104 | list_filename->AddEntry(String("<albumartist> - <album>")); |
| 105 | list_filename->AddEntry(String("<albumartist> - <album>").Append(Directory::GetDirectoryDelimiter()).Append("<albumartist> - <album>")); |
| 106 | |
| 107 | edit_filename->SetDropDownList(list_filename); |
| 108 | |
| 109 | check_singlefile = new CheckBox(i18n->TranslateString("Create only a single playlist and/or cue sheet file per conversion"), Point(10, 39), Size(532, 0), &createSingleFile); |
| 110 | |
| 111 | group_filename->Add(text_filename); |
| 112 | group_filename->Add(edit_filename); |
| 113 | group_filename->Add(check_singlefile); |
| 114 | |
| 115 | ToggleUseEncOutdir(); |
| 116 | ToggleCreatePlaylists(); |
| 117 | |
| 118 | Add(group_outdir); |
| 119 | Add(group_filename); |
| 120 | Add(group_options); |
| 121 | |
| 122 | SetSize(Size(566, 222)); |
| 123 | |
| 124 | onToggleCreateCueSheets.Connect(&ConfigurePlaylists::OnToggleCreateCueSheets, this); |
| 125 | } |
| 126 | |
| 127 | freac::ConfigurePlaylists::~ConfigurePlaylists() |
| 128 | { |
| 129 | |
| 130 | onToggleCreateCueSheets.Disconnect(&ConfigurePlaylists::OnToggleCreateCueSheets, this); |
| 131 | |
| 132 | DeleteObject(group_outdir); |
| 133 | DeleteObject(check_useEncOutdir); |
| 134 | DeleteObject(edit_outdir); |
| 135 | DeleteObject(button_outdir_browse); |
| 136 | |
| 137 | DeleteObject(group_filename); |
| 138 | DeleteObject(text_filename); |
| 139 | DeleteObject(edit_filename); |
| 140 | DeleteObject(list_filename); |
| 141 | DeleteObject(check_singlefile); |
| 142 | |
| 143 | DeleteObject(group_options); |
| 144 | DeleteObject(check_createPlaylists); |
| 145 | DeleteObject(combo_formats); |
| 146 | DeleteObject(button_config); |
| 147 | } |
| 148 | |
| 149 | Void freac::ConfigurePlaylists::SelectDir() |
| 150 | { |
| 151 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 152 | |
| 153 | i18n->SetContext("Configuration::Playlists"); |
| 154 | |
| 155 | DirSelection dialog; |
| 156 | |
| 157 | dialog.SetParentWindow(GetContainerWindow()); |
| 158 | dialog.SetCaption(i18n->AddColon(i18n->TranslateString("Select the folder in which the playlist files will be placed"))); |
| 159 | dialog.SetDirName(BoCA::Utilities::GetAbsolutePathName(edit_outdir->GetText())); |
| 160 | |
| 161 | if (dialog.ShowDialog() == Success()) |
| 162 | { |
| 163 | edit_outdir->SetText(dialog.GetDirName()); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | String freac::ConfigurePlaylists::GetSelectedComponent() const |
| 168 | { |
| 169 | Registry &boca = Registry::Get(); |
| 170 | |
| 171 | Int index = combo_formats->GetSelectedEntryNumber(); |
| 172 | Int count = 0; |
| 173 | |
| 174 | for (Int i = 0; i < boca.GetNumberOfComponents(); i++) |
| 175 | { |
| 176 | if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_PLAYLIST) continue; |
| 177 | |
| 178 | const Array<FileFormat *> &formats = boca.GetComponentFormats(i); |
| 179 | |
| 180 | for (Int j = 0; j < formats.Length(); j++) |
| 181 | { |
| 182 | if (count++ < index) continue; |
| 183 | |
| 184 | return boca.GetComponentID(i); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | return NIL; |
| 189 | } |
| 190 | |
| 191 | Void freac::ConfigurePlaylists::SelectFormat() |
| 192 | { |
| 193 | Registry &boca = Registry::Get(); |
| 194 | Component *component = boca.CreateComponentByID(GetSelectedComponent()); |
| 195 | |
| 196 | if (component != NIL) |
| 197 | { |
| 198 | if (component->GetConfigurationLayer() != NIL) button_config->Activate(); |
| 199 | else button_config->Deactivate(); |
| 200 | |
| 201 | boca.DeleteComponent(component); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | Void freac::ConfigurePlaylists::ConfigureFormat() |
| 206 | { |
| 207 | Registry &boca = Registry::Get(); |
| 208 | Component *component = boca.CreateComponentByID(GetSelectedComponent()); |
| 209 | |
| 210 | if (component != NIL) |
| 211 | { |
| 212 | ConfigComponentDialog(component).ShowDialog(); |
| 213 | |
| 214 | boca.DeleteComponent(component); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | Void freac::ConfigurePlaylists::ToggleCreatePlaylists() |
| 219 | { |
| 220 | if (createPlaylists || createCueSheets) |
| 221 | { |
| 222 | group_outdir->Activate(); |
| 223 | group_filename->Activate(); |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | group_outdir->Deactivate(); |
| 228 | group_filename->Deactivate(); |
| 229 | } |
| 230 | |
| 231 | if (createPlaylists) |
| 232 | { |
| 233 | combo_formats->Activate(); |
| 234 | |
| 235 | SelectFormat(); |
| 236 | } |
| 237 | else |
| 238 | { |
| 239 | combo_formats->Deactivate(); |
| 240 | button_config->Deactivate(); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | Void freac::ConfigurePlaylists::ToggleUseEncOutdir() |
| 245 | { |
| 246 | if (useEncOutdir) |
| 247 | { |
| 248 | edit_outdir->Deactivate(); |
| 249 | button_outdir_browse->Deactivate(); |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | edit_outdir->Activate(); |
| 254 | button_outdir_browse->Activate(); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | Void freac::ConfigurePlaylists::OnToggleCreateCueSheets(Bool createCueSheetsEnabled) |
| 259 | { |
| 260 | createCueSheets = createCueSheetsEnabled; |
| 261 | |
| 262 | ToggleCreatePlaylists(); |
| 263 | } |
| 264 | |
| 265 | Int freac::ConfigurePlaylists::SaveSettings() |
| 266 | { |
| 267 | BoCA::Config *config = BoCA::Config::Get(); |
| 268 | |
| 269 | String playlistOutputDir = edit_outdir->GetText(); |
| 270 | String playlistOutputPattern = edit_filename->GetText(); |
| 271 | |
| 272 | if (!playlistOutputDir.EndsWith(Directory::GetDirectoryDelimiter())) playlistOutputDir.Append(Directory::GetDirectoryDelimiter()); |
| 273 | |
| 274 | config->SetIntValue(Config::CategoryPlaylistID, Config::PlaylistCreatePlaylistID, createPlaylists); |
| 275 | config->SetStringValue(Config::CategoryPlaylistID, Config::PlaylistOutputDirID, playlistOutputDir); |
| 276 | config->SetStringValue(Config::CategoryPlaylistID, Config::PlaylistFilenamePatternID, playlistOutputPattern); |
| 277 | config->SetIntValue(Config::CategoryPlaylistID, Config::PlaylistUseEncoderOutputDirID, useEncOutdir); |
| 278 | config->SetIntValue(Config::CategoryPlaylistID, Config::PlaylistCreateSingleFileID, createSingleFile); |
| 279 | |
| 280 | Registry &boca = Registry::Get(); |
| 281 | Int index = combo_formats->GetSelectedEntryNumber(); |
| 282 | Int count = 0; |
| 283 | |
| 284 | for (Int i = 0; i < boca.GetNumberOfComponents(); i++) |
| 285 | { |
| 286 | if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_PLAYLIST) continue; |
| 287 | |
| 288 | const Array<FileFormat *> &formats = boca.GetComponentFormats(i); |
| 289 | |
| 290 | foreach (FileFormat *format, formats) |
| 291 | { |
| 292 | if (count++ < index) continue; |
| 293 | |
| 294 | const Array<String> &formatExtensions = format->GetExtensions(); |
| 295 | |
| 296 | config->SetStringValue(Config::CategoryPlaylistID, Config::PlaylistFormatID, boca.GetComponentID(i).Append("-").Append(formatExtensions.GetNth(0))); |
| 297 | |
| 298 | break; |
| 299 | } |
| 300 | |
| 301 | if (count > index) break; |
| 302 | } |
| 303 | |
| 304 | return Success(); |
| 305 | } |