| 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_encoders.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 | freac::ConfigureEncoders::ConfigureEncoders() |
| 23 | { |
| 24 | BoCA::Config *config = BoCA::Config::Get(); |
| 25 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 26 | |
| 27 | i18n->SetContext("Configuration::Encoders"); |
| 28 | |
| 29 | /* Get configuration. |
| 30 | */ |
| 31 | singleFile = config->GetIntValue(Config::CategorySettingsID, Config::SettingsEncodeToSingleFileID, Config::SettingsEncodeToSingleFileDefault); |
| 32 | onTheFly = config->GetIntValue(Config::CategorySettingsID, Config::SettingsEncodeOnTheFlyID, Config::SettingsEncodeOnTheFlyDefault); |
| 33 | keepWaves = config->GetIntValue(Config::CategorySettingsID, Config::SettingsKeepWaveFilesID, Config::SettingsKeepWaveFilesDefault); |
| 34 | removeTracks = config->GetIntValue(Config::CategorySettingsID, Config::SettingsRemoveTracksID, Config::SettingsRemoveTracksDefault); |
| 35 | addEncodedTracks = config->GetIntValue(Config::CategorySettingsID, Config::SettingsAddEncodedTracksID, Config::SettingsAddEncodedTracksDefault); |
| 36 | |
| 37 | /* Encoder group. |
| 38 | */ |
| 39 | group_encoder = new GroupBox(i18n->TranslateString("Encoder"), Point(7, 11), Size(552, 43)); |
| 40 | |
| 41 | combo_encoder = new ComboBox(Point(10, 12), Size(394, 0)); |
| 42 | |
| 43 | Registry &boca = Registry::Get(); |
| 44 | |
| 45 | for (Int i = 0; i < boca.GetNumberOfComponents(); i++) |
| 46 | { |
| 47 | if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_ENCODER) continue; |
| 48 | |
| 49 | combo_encoder->AddEntry(boca.GetComponentName(i)); |
| 50 | |
| 51 | if (config->GetStringValue(Config::CategorySettingsID, Config::SettingsEncoderID, Config::SettingsEncoderDefault) == boca.GetComponentID(i)) combo_encoder->SelectNthEntry(combo_encoder->Length() - 1); |
| 52 | } |
| 53 | |
| 54 | combo_encoder->onSelectEntry.Connect(&ConfigureEncoders::SelectEncoder, this); |
| 55 | |
| 56 | button_config = new Button(i18n->TranslateString("Configure encoder"), Point(412, 11), Size(130, 0)); |
| 57 | button_config->SetOrientation(OR_UPPERRIGHT); |
| 58 | button_config->onAction.Connect(&ConfigureEncoders::ConfigureEncoder, this); |
| 59 | |
| 60 | button_config->SetWidth(Math::Max(80, button_config->GetUnscaledTextWidth() + 14)); |
| 61 | button_config->SetX(button_config->GetWidth() + 10); |
| 62 | |
| 63 | SelectEncoder(); |
| 64 | |
| 65 | group_encoder->Add(combo_encoder); |
| 66 | group_encoder->Add(button_config); |
| 67 | |
| 68 | /* Options group. |
| 69 | */ |
| 70 | i18n->SetContext("Configuration::Encoders"); |
| 71 | |
| 72 | group_options = new GroupBox(i18n->TranslateString("Options"), Point(7, 66), Size(552, 88)); |
| 73 | |
| 74 | check_onTheFly = new CheckBox(i18n->TranslateString("Encode \'On-The-Fly\'"), Point(10, 37), Size(261, 0), &onTheFly); |
| 75 | check_onTheFly->onAction.Connect(&ConfigureEncoders::ToggleOnTheFly, this); |
| 76 | |
| 77 | check_keepWaves = new CheckBox(i18n->TranslateString("Keep ripped Wave files"), Point(27, 60), Size(244, 0), &keepWaves); |
| 78 | |
| 79 | ToggleOnTheFly(); |
| 80 | |
| 81 | check_singleFile = new CheckBox(i18n->TranslateString("Encode to a single file"), Point(10, 14), Size(261, 0), &singleFile); |
| 82 | check_singleFile->onAction.Connect(&ConfigureEncoders::ToggleEncodeToSingleFile, this); |
| 83 | |
| 84 | ToggleEncodeToSingleFile(); |
| 85 | |
| 86 | check_removeTracks = new CheckBox(i18n->TranslateString("Remove processed tracks from joblist"), Point(280, 37), Size(261, 0), &removeTracks); |
| 87 | check_removeTracks->onAction.Connect(&ConfigureEncoders::ToggleRemoveTracks, this); |
| 88 | |
| 89 | check_addEncodedTracks = new CheckBox(i18n->TranslateString("Add output files to joblist"), Point(297, 60), Size(244, 0), &addEncodedTracks); |
| 90 | |
| 91 | ToggleRemoveTracks(); |
| 92 | |
| 93 | group_options->Add(check_singleFile); |
| 94 | group_options->Add(check_onTheFly); |
| 95 | group_options->Add(check_keepWaves); |
| 96 | group_options->Add(check_removeTracks); |
| 97 | group_options->Add(check_addEncodedTracks); |
| 98 | |
| 99 | Add(group_encoder); |
| 100 | Add(group_options); |
| 101 | |
| 102 | /* Adjust element widths. |
| 103 | */ |
| 104 | Int maxTextSize = Math::Max(check_singleFile->GetUnscaledTextWidth(), Math::Max(Math::Max(check_onTheFly->GetUnscaledTextWidth(), check_keepWaves->GetUnscaledTextWidth() + 17), |
| 105 | Math::Max(check_removeTracks->GetUnscaledTextWidth(), check_addEncodedTracks->GetUnscaledTextWidth() + 17))); |
| 106 | |
| 107 | group_encoder->SetWidth(2 * Math::Max(261, maxTextSize + 21) + 30); |
| 108 | combo_encoder->SetWidth(group_encoder->GetWidth() - button_config->GetWidth() - 28); |
| 109 | |
| 110 | group_options->SetWidth(group_encoder->GetWidth()); |
| 111 | |
| 112 | check_onTheFly->SetWidth(Math::Max(261, maxTextSize + 21)); |
| 113 | check_keepWaves->SetWidth(check_onTheFly->GetWidth() - 17); |
| 114 | check_singleFile->SetWidth(check_onTheFly->GetWidth()); |
| 115 | |
| 116 | check_removeTracks->SetX(check_onTheFly->GetWidth() + 19); |
| 117 | check_removeTracks->SetWidth(check_onTheFly->GetWidth()); |
| 118 | |
| 119 | check_addEncodedTracks->SetX(check_onTheFly->GetWidth() + 36); |
| 120 | check_addEncodedTracks->SetWidth(check_onTheFly->GetWidth() - 17); |
| 121 | |
| 122 | SetSize(Size(14 + group_encoder->GetWidth(), 161)); |
| 123 | } |
| 124 | |
| 125 | freac::ConfigureEncoders::~ConfigureEncoders() |
| 126 | { |
| 127 | DeleteObject(group_encoder); |
| 128 | DeleteObject(combo_encoder); |
| 129 | DeleteObject(button_config); |
| 130 | |
| 131 | DeleteObject(group_options); |
| 132 | DeleteObject(check_singleFile); |
| 133 | DeleteObject(check_onTheFly); |
| 134 | DeleteObject(check_keepWaves); |
| 135 | DeleteObject(check_removeTracks); |
| 136 | DeleteObject(check_addEncodedTracks); |
| 137 | } |
| 138 | |
| 139 | String freac::ConfigureEncoders::GetSelectedEncoder() const |
| 140 | { |
| 141 | Registry &boca = Registry::Get(); |
| 142 | |
| 143 | for (Int i = 0, n = 0; i < boca.GetNumberOfComponents(); i++) |
| 144 | { |
| 145 | if (boca.GetComponentType(i) != BoCA::COMPONENT_TYPE_ENCODER) continue; |
| 146 | |
| 147 | if (n++ == combo_encoder->GetSelectedEntryNumber()) return boca.GetComponentID(i); |
| 148 | } |
| 149 | |
| 150 | return NIL; |
| 151 | } |
| 152 | |
| 153 | Void freac::ConfigureEncoders::SelectEncoder() |
| 154 | { |
| 155 | Registry &boca = Registry::Get(); |
| 156 | Component *component = boca.CreateComponentByID(GetSelectedEncoder()); |
| 157 | |
| 158 | if (component != NIL) |
| 159 | { |
| 160 | if (component->GetConfigurationLayer() != NIL) button_config->Activate(); |
| 161 | else button_config->Deactivate(); |
| 162 | |
| 163 | boca.DeleteComponent(component); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | Void freac::ConfigureEncoders::ConfigureEncoder() |
| 168 | { |
| 169 | Registry &boca = Registry::Get(); |
| 170 | Component *component = boca.CreateComponentByID(GetSelectedEncoder()); |
| 171 | |
| 172 | if (component != NIL) |
| 173 | { |
| 174 | ConfigComponentDialog(component).ShowDialog(); |
| 175 | |
| 176 | boca.DeleteComponent(component); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | Void freac::ConfigureEncoders::ToggleOnTheFly() |
| 181 | { |
| 182 | if (onTheFly) check_keepWaves->Deactivate(); |
| 183 | else check_keepWaves->Activate(); |
| 184 | } |
| 185 | |
| 186 | Void freac::ConfigureEncoders::ToggleRemoveTracks() |
| 187 | { |
| 188 | if (removeTracks) { check_addEncodedTracks->Activate(); } |
| 189 | else { addEncodedTracks = False; check_addEncodedTracks->Deactivate(); } |
| 190 | } |
| 191 | |
| 192 | Void freac::ConfigureEncoders::ToggleEncodeToSingleFile() |
| 193 | { |
| 194 | if (singleFile) { onTheFly = True; check_onTheFly->Deactivate(); } |
| 195 | else { check_onTheFly->Activate(); } |
| 196 | |
| 197 | ToggleOnTheFly(); |
| 198 | } |
| 199 | |
| 200 | Int freac::ConfigureEncoders::SaveSettings() |
| 201 | { |
| 202 | BoCA::Config *config = BoCA::Config::Get(); |
| 203 | |
| 204 | /* Save selected encoder. |
| 205 | */ |
| 206 | config->SetStringValue(Config::CategorySettingsID, Config::SettingsEncoderID, GetSelectedEncoder()); |
| 207 | |
| 208 | /* Save other settings. |
| 209 | */ |
| 210 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsEncodeToSingleFileID, singleFile); |
| 211 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsEncodeOnTheFlyID, onTheFly); |
| 212 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsKeepWaveFilesID, keepWaves); |
| 213 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsRemoveTracksID, removeTracks); |
| 214 | config->SetIntValue(Config::CategorySettingsID, Config::SettingsAddEncodedTracksID, addEncodedTracks); |
| 215 | |
| 216 | return Success(); |
| 217 | } |