| 1 | /* BoCA - BonkEnc Component Architecture |
| 2 | * Copyright (C) 2007-2024 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 "config.h" |
| 14 | |
| 15 | const String BoCA::ConfigureCDParanoia::ConfigID = "Ripper"; |
| 16 | |
| 17 | BoCA::ConfigureCDParanoia::ConfigureCDParanoia() |
| 18 | { |
| 19 | const Config *config = Config::Get(); |
| 20 | |
| 21 | Bool notificationAvailable = config->GetIntValue("Internal", "NotificationAvailable", False); |
| 22 | |
| 23 | autoRead = notificationAvailable && config->GetIntValue(ConfigID, "AutoReadContents", True); |
| 24 | autoRip = notificationAvailable && config->GetIntValue(ConfigID, "AutoRip", False); |
| 25 | |
| 26 | cdparanoia = config->GetIntValue(ConfigID, "CDParanoia", False); |
| 27 | |
| 28 | I18n *i18n = I18n::Get(); |
| 29 | |
| 30 | i18n->SetContext("Ripper"); |
| 31 | |
| 32 | group_drive = new GroupBox(i18n->TranslateString("Active CD-ROM drive"), Point(7, 11), Size(354, 121)); |
| 33 | |
| 34 | combo_drive = new ComboBox(Point(10, 12), Size(334, 0)); |
| 35 | |
| 36 | AS::Registry &boca = AS::Registry::Get(); |
| 37 | AS::DeviceInfoComponent *info = (AS::DeviceInfoComponent *) boca.CreateComponentByID("cdparanoia-info"); |
| 38 | |
| 39 | if (info != NIL) |
| 40 | { |
| 41 | if (info->GetNumberOfDevices() == 0) group_drive->Deactivate(); |
| 42 | |
| 43 | for (Int i = 0; i < info->GetNumberOfDevices(); i++) |
| 44 | { |
| 45 | const Device &device = info->GetNthDeviceInfo(i); |
| 46 | String deviceID = device.GetID(); |
| 47 | |
| 48 | combo_drive->AddEntry(device.GetName()); |
| 49 | |
| 50 | driveOffsetUsed.Add(config->GetIntValue(ConfigID, String("UseOffsetDrive-").Append(deviceID), 0)); |
| 51 | driveOffsets.Add(config->GetIntValue(ConfigID, String("ReadOffsetDrive-").Append(deviceID), 0)); |
| 52 | driveSpeeds.Add(config->GetIntValue(ConfigID, String("RippingSpeedDrive-").Append(deviceID), 0)); |
| 53 | driveSpinUpTimes.Add(config->GetIntValue(ConfigID, String("SpinUpTimeDrive-").Append(deviceID), -5)); |
| 54 | } |
| 55 | |
| 56 | boca.DeleteComponent(info); |
| 57 | } |
| 58 | |
| 59 | combo_drive->SelectNthEntry(config->GetIntValue(ConfigID, "ActiveDrive", 0)); |
| 60 | combo_drive->onSelectEntry.Connect(&ConfigureCDParanoia::SelectDrive, this); |
| 61 | |
| 62 | useoffset = driveOffsetUsed.GetNth(config->GetIntValue(ConfigID, "ActiveDrive", 0)); |
| 63 | spinup = driveSpinUpTimes.GetNth(config->GetIntValue(ConfigID, "ActiveDrive", 0)) > 0; |
| 64 | setspeed = driveSpeeds.GetNth(config->GetIntValue(ConfigID, "ActiveDrive", 0)); |
| 65 | |
| 66 | check_speed = new CheckBox(i18n->AddColon(i18n->TranslateString("Set drive speed limit")), Point(10, 40), Size(162, 0), &setspeed); |
| 67 | check_speed->onAction.Connect(&ConfigureCDParanoia::ToggleSetSpeed, this); |
| 68 | |
| 69 | check_spinup = new CheckBox(i18n->AddColon(i18n->TranslateString("Spin up before ripping")), Point(10, 67), Size(162, 0), &spinup); |
| 70 | check_spinup->onAction.Connect(&ConfigureCDParanoia::ToggleSpinUp, this); |
| 71 | |
| 72 | check_offset = new CheckBox(i18n->AddColon(i18n->TranslateString("Use read offset")), Point(10, 94), Size(162, 0), &useoffset); |
| 73 | check_offset->onAction.Connect(&ConfigureCDParanoia::ToggleUseOffset, this); |
| 74 | |
| 75 | Int maxTextSize = Math::Max(Math::Max(check_speed->GetUnscaledTextWidth(), check_spinup->GetUnscaledTextWidth()), check_offset->GetUnscaledTextWidth()); |
| 76 | |
| 77 | check_speed->SetWidth(maxTextSize + 21); |
| 78 | check_spinup->SetWidth(maxTextSize + 21); |
| 79 | check_offset->SetWidth(maxTextSize + 21); |
| 80 | |
| 81 | combo_speed = new ComboBox(Point(39 + maxTextSize, 39), Size(305 - maxTextSize, 0)); |
| 82 | combo_speed->onSelectEntry.Connect(&ConfigureCDParanoia::SelectSpeed, this); |
| 83 | |
| 84 | for (Int i = 48; i > 0; i -= 4) combo_speed->AddEntry(String::FromInt(i).Append("x")); |
| 85 | |
| 86 | text_spinup_seconds = new Text(i18n->TranslateString("%1 seconds").Replace("%1", "00"), Point(275, 69)); |
| 87 | text_spinup_seconds->SetX(343 - text_spinup_seconds->GetUnscaledTextWidth()); |
| 88 | |
| 89 | slider_spinup = new Slider(Point(39 + maxTextSize, 67), Size(86, 0), OR_HORZ, NIL, 1, 30); |
| 90 | slider_spinup->SetWidth(335 - slider_spinup->GetX() - text_spinup_seconds->GetUnscaledTextWidth()); |
| 91 | slider_spinup->onValueChange.Connect(&ConfigureCDParanoia::ChangeSpinUpTime, this); |
| 92 | |
| 93 | edit_offset = new EditBox(Point(39 + maxTextSize, 93), Size(36, 0), 5); |
| 94 | edit_offset->SetFlags(EDB_NUMERIC); |
| 95 | edit_offset->onInput.Connect(&ConfigureCDParanoia::ChangeOffset, this); |
| 96 | |
| 97 | text_offset_samples = new Text(i18n->TranslateString("samples"), Point(edit_offset->GetX() + edit_offset->GetWidth() + 8, 96)); |
| 98 | |
| 99 | SelectDrive(); |
| 100 | |
| 101 | group_drive->Add(combo_drive); |
| 102 | group_drive->Add(check_speed); |
| 103 | group_drive->Add(combo_speed); |
| 104 | group_drive->Add(check_spinup); |
| 105 | group_drive->Add(slider_spinup); |
| 106 | group_drive->Add(text_spinup_seconds); |
| 107 | group_drive->Add(check_offset); |
| 108 | group_drive->Add(edit_offset); |
| 109 | group_drive->Add(text_offset_samples); |
| 110 | |
| 111 | group_ripping = new GroupBox(i18n->TranslateString("Ripper settings"), Point(7, 144), Size(354, 42)); |
| 112 | |
| 113 | check_paranoia = new CheckBox(i18n->AddColon(i18n->TranslateString("Activate cdparanoia mode")), Point(10, 14), Size(162, 0), &cdparanoia); |
| 114 | check_paranoia->onAction.Connect(&ConfigureCDParanoia::ToggleParanoia, this); |
| 115 | |
| 116 | combo_paranoia_mode = new ComboBox(Point(181, 13), Size(162, 0)); |
| 117 | combo_paranoia_mode->AddEntry(i18n->TranslateString("Overlap only")); |
| 118 | combo_paranoia_mode->AddEntry(i18n->TranslateString("No verify")); |
| 119 | combo_paranoia_mode->AddEntry(i18n->TranslateString("No scratch repair")); |
| 120 | combo_paranoia_mode->AddEntry(i18n->TranslateString("Full cdparanoia mode")); |
| 121 | combo_paranoia_mode->SelectNthEntry(config->GetIntValue(ConfigID, "CDParanoiaMode", 3)); |
| 122 | |
| 123 | ToggleParanoia(); |
| 124 | |
| 125 | check_paranoia->SetWidth(Math::Max(162, check_paranoia->GetUnscaledTextWidth() + 21)); |
| 126 | combo_paranoia_mode->SetX(check_paranoia->GetWidth() + 19); |
| 127 | |
| 128 | group_ripping->SetWidth(check_paranoia->GetWidth() + combo_paranoia_mode->GetWidth() + 29); |
| 129 | |
| 130 | group_ripping->Add(check_paranoia); |
| 131 | group_ripping->Add(combo_paranoia_mode); |
| 132 | |
| 133 | group_drive->SetWidth(group_ripping->GetWidth()); |
| 134 | |
| 135 | combo_drive->SetWidth(group_drive->GetWidth() - 20); |
| 136 | combo_speed->SetWidth(group_drive->GetWidth() - check_speed->GetWidth() - 28); |
| 137 | slider_spinup->SetWidth(group_drive->GetWidth() - 24 - slider_spinup->GetX() - text_spinup_seconds->GetUnscaledTextWidth()); |
| 138 | text_spinup_seconds->SetX(group_drive->GetWidth() - 16 - text_spinup_seconds->GetUnscaledTextWidth()); |
| 139 | |
| 140 | group_automatization = new GroupBox(i18n->TranslateString("Automatization"), Point(group_drive->GetWidth() + 15, 11), Size(190, 68)); |
| 141 | |
| 142 | check_autoRead = new CheckBox(i18n->TranslateString("Read CD contents on insert"), Point(10, 14), Size(170, 0), &autoRead); |
| 143 | check_autoRead->onAction.Connect(&ConfigureCDParanoia::ToggleAutoRead, this); |
| 144 | |
| 145 | if (!notificationAvailable) check_autoRead->Deactivate(); |
| 146 | |
| 147 | check_autoRip = new CheckBox(i18n->TranslateString("Start ripping automatically"), check_autoRead->GetPosition() + Point(0, 26), Size(170, 0), &autoRip); |
| 148 | |
| 149 | group_automatization->Add(check_autoRead); |
| 150 | group_automatization->Add(check_autoRip); |
| 151 | |
| 152 | maxTextSize = Math::Max(check_autoRead->GetUnscaledTextWidth(), check_autoRip->GetUnscaledTextWidth()); |
| 153 | |
| 154 | check_autoRead->SetWidth(Math::Max(149, maxTextSize + 21)); |
| 155 | check_autoRip->SetWidth(check_autoRead->GetWidth()); |
| 156 | |
| 157 | group_automatization->SetWidth(check_autoRead->GetWidth() + 20); |
| 158 | |
| 159 | ToggleAutoRead(); |
| 160 | |
| 161 | Add(group_drive); |
| 162 | Add(group_ripping); |
| 163 | Add(group_automatization); |
| 164 | |
| 165 | SetSize(Size(group_drive->GetWidth() + group_automatization->GetWidth() + 22, 193)); |
| 166 | } |
| 167 | |
| 168 | BoCA::ConfigureCDParanoia::~ConfigureCDParanoia() |
| 169 | { |
| 170 | DeleteObject(group_drive); |
| 171 | DeleteObject(combo_drive); |
| 172 | DeleteObject(check_speed); |
| 173 | DeleteObject(combo_speed); |
| 174 | DeleteObject(check_spinup); |
| 175 | DeleteObject(slider_spinup); |
| 176 | DeleteObject(text_spinup_seconds); |
| 177 | DeleteObject(check_offset); |
| 178 | DeleteObject(edit_offset); |
| 179 | DeleteObject(text_offset_samples); |
| 180 | |
| 181 | DeleteObject(group_ripping); |
| 182 | DeleteObject(check_paranoia); |
| 183 | DeleteObject(combo_paranoia_mode); |
| 184 | |
| 185 | DeleteObject(group_automatization); |
| 186 | DeleteObject(check_autoRead); |
| 187 | DeleteObject(check_autoRip); |
| 188 | } |
| 189 | |
| 190 | Void BoCA::ConfigureCDParanoia::SelectDrive() |
| 191 | { |
| 192 | edit_offset->SetText(String::FromInt(driveOffsets.GetNth(combo_drive->GetSelectedEntryNumber()))); |
| 193 | combo_speed->SelectNthEntry((48 - driveSpeeds.GetNth(combo_drive->GetSelectedEntryNumber())) / 4); |
| 194 | |
| 195 | check_offset->SetChecked(driveOffsetUsed.GetNth(combo_drive->GetSelectedEntryNumber())); |
| 196 | check_speed->SetChecked(driveSpeeds.GetNth(combo_drive->GetSelectedEntryNumber())); |
| 197 | check_spinup->SetChecked(driveSpinUpTimes.GetNth(combo_drive->GetSelectedEntryNumber()) > 0); |
| 198 | |
| 199 | slider_spinup->SetValue(Math::Abs(driveSpinUpTimes.GetNth(combo_drive->GetSelectedEntryNumber()))); |
| 200 | |
| 201 | ToggleUseOffset(); |
| 202 | ToggleSetSpeed(); |
| 203 | ToggleSpinUp(); |
| 204 | } |
| 205 | |
| 206 | Void BoCA::ConfigureCDParanoia::ToggleUseOffset() |
| 207 | { |
| 208 | driveOffsetUsed.SetNth(combo_drive->GetSelectedEntryNumber(), useoffset); |
| 209 | |
| 210 | if (useoffset) |
| 211 | { |
| 212 | edit_offset->Activate(); |
| 213 | text_offset_samples->Activate(); |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | edit_offset->Deactivate(); |
| 218 | text_offset_samples->Deactivate(); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | Void BoCA::ConfigureCDParanoia::ChangeOffset() |
| 223 | { |
| 224 | if (!useoffset) return; |
| 225 | |
| 226 | driveOffsets.SetNth(combo_drive->GetSelectedEntryNumber(), edit_offset->GetText().ToInt()); |
| 227 | } |
| 228 | |
| 229 | Void BoCA::ConfigureCDParanoia::ToggleSpinUp() |
| 230 | { |
| 231 | driveSpinUpTimes.SetNth(combo_drive->GetSelectedEntryNumber(), slider_spinup->GetValue() * (spinup ? 1 : -1)); |
| 232 | |
| 233 | if (spinup) |
| 234 | { |
| 235 | slider_spinup->Activate(); |
| 236 | text_spinup_seconds->Activate(); |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | slider_spinup->Deactivate(); |
| 241 | text_spinup_seconds->Deactivate(); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | Void BoCA::ConfigureCDParanoia::ChangeSpinUpTime() |
| 246 | { |
| 247 | I18n *i18n = I18n::Get(); |
| 248 | |
| 249 | i18n->SetContext("Ripper"); |
| 250 | |
| 251 | text_spinup_seconds->SetText(i18n->TranslateString("%1 seconds").Replace("%1", String::FromInt(slider_spinup->GetValue()))); |
| 252 | |
| 253 | driveSpinUpTimes.SetNth(combo_drive->GetSelectedEntryNumber(), slider_spinup->GetValue() * (spinup ? 1 : -1)); |
| 254 | } |
| 255 | |
| 256 | Void BoCA::ConfigureCDParanoia::ToggleSetSpeed() |
| 257 | { |
| 258 | if (setspeed) |
| 259 | { |
| 260 | combo_speed->Activate(); |
| 261 | |
| 262 | driveSpeeds.SetNth(combo_drive->GetSelectedEntryNumber(), 48 - (combo_speed->GetSelectedEntryNumber() * 4)); |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | combo_speed->Deactivate(); |
| 267 | |
| 268 | driveSpeeds.SetNth(combo_drive->GetSelectedEntryNumber(), 0); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | Void BoCA::ConfigureCDParanoia::SelectSpeed() |
| 273 | { |
| 274 | if (!setspeed) return; |
| 275 | |
| 276 | driveSpeeds.SetNth(combo_drive->GetSelectedEntryNumber(), 48 - (combo_speed->GetSelectedEntryNumber() * 4)); |
| 277 | } |
| 278 | |
| 279 | Void BoCA::ConfigureCDParanoia::ToggleParanoia() |
| 280 | { |
| 281 | if (cdparanoia) combo_paranoia_mode->Activate(); |
| 282 | else combo_paranoia_mode->Deactivate(); |
| 283 | } |
| 284 | |
| 285 | Void BoCA::ConfigureCDParanoia::ToggleAutoRead() |
| 286 | { |
| 287 | if (autoRead) check_autoRip->Activate(); |
| 288 | else check_autoRip->Deactivate(); |
| 289 | } |
| 290 | |
| 291 | Int BoCA::ConfigureCDParanoia::SaveSettings() |
| 292 | { |
| 293 | Config *config = Config::Get(); |
| 294 | |
| 295 | if (driveSpeeds.Length() >= 1) config->SetIntValue(ConfigID, "ActiveDrive", combo_drive->GetSelectedEntryNumber()); |
| 296 | |
| 297 | AS::Registry &boca = AS::Registry::Get(); |
| 298 | AS::DeviceInfoComponent *info = (AS::DeviceInfoComponent *) boca.CreateComponentByID("cdparanoia-info"); |
| 299 | |
| 300 | if (info != NIL) |
| 301 | { |
| 302 | for (Int i = 0; i < info->GetNumberOfDevices(); i++) |
| 303 | { |
| 304 | const Device &device = info->GetNthDeviceInfo(i); |
| 305 | String deviceID = device.GetID(); |
| 306 | |
| 307 | config->SetIntValue(ConfigID, String("UseOffsetDrive-").Append(deviceID), driveOffsetUsed.GetNth(i)); |
| 308 | config->SetIntValue(ConfigID, String("ReadOffsetDrive-").Append(deviceID), driveOffsets.GetNth(i)); |
| 309 | config->SetIntValue(ConfigID, String("RippingSpeedDrive-").Append(deviceID), driveSpeeds.GetNth(i)); |
| 310 | config->SetIntValue(ConfigID, String("SpinUpTimeDrive-").Append(deviceID), driveSpinUpTimes.GetNth(i)); |
| 311 | } |
| 312 | |
| 313 | boca.DeleteComponent(info); |
| 314 | } |
| 315 | |
| 316 | if (config->GetIntValue("Internal", "NotificationAvailable", False)) |
| 317 | { |
| 318 | config->SetIntValue(ConfigID, "AutoReadContents", autoRead); |
| 319 | config->SetIntValue(ConfigID, "AutoRip", autoRip); |
| 320 | } |
| 321 | |
| 322 | config->SetIntValue(ConfigID, "CDParanoia", cdparanoia); |
| 323 | config->SetIntValue(ConfigID, "CDParanoiaMode", combo_paranoia_mode->GetSelectedEntryNumber()); |
| 324 | |
| 325 | return Success(); |
| 326 | } |