| 1 | /* fre:ac - free audio converter |
| 2 | * Copyright (C) 2001-2021 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/cddb/submit.h> |
| 14 | #include <dialogs/cddb/query.h> |
| 15 | |
| 16 | #include <config.h> |
| 17 | #include <utilities.h> |
| 18 | #include <startgui.h> |
| 19 | |
| 20 | #include <joblist.h> |
| 21 | |
| 22 | #include <cddb/cddblocal.h> |
| 23 | #include <cddb/cddbremote.h> |
| 24 | #include <cddb/cddbbatch.h> |
| 25 | #include <cddb/cddbcache.h> |
| 26 | |
| 27 | using namespace BoCA; |
| 28 | using namespace BoCA::AS; |
| 29 | |
| 30 | using namespace smooth::GUI::Dialogs; |
| 31 | |
| 32 | freac::cddbSubmitDlg::cddbSubmitDlg() |
| 33 | { |
| 34 | BoCA::Config *config = BoCA::Config::Get(); |
| 35 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 36 | |
| 37 | i18n->SetContext("CDDB::Submit"); |
| 38 | |
| 39 | activedrive = config->GetIntValue(Config::CategoryRipperID, Config::RipperActiveDriveID, Config::RipperActiveDriveDefault); |
| 40 | updateJoblist = config->GetIntValue(Config::CategoryFreedbID, Config::FreedbUpdateJoblistID, Config::FreedbUpdateJoblistDefault); |
| 41 | |
| 42 | submitLater = !config->GetIntValue(Config::CategoryFreedbID, Config::FreedbEnableRemoteID, Config::FreedbEnableRemoteDefault); |
| 43 | |
| 44 | dontUpdateInfo = False; |
| 45 | finishedArtist = False; |
| 46 | |
| 47 | Point wndPos = Point(config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosXID, Config::SettingsWindowPosXDefault), config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosYID, Config::SettingsWindowPosYDefault)) + Point(40, 40); |
| 48 | Size wndSize = Size(config->GetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBSubmitSizeXID, Config::DialogsCDDBSubmitSizeXDefault), config->GetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBSubmitSizeYID, Config::DialogsCDDBSubmitSizeYDefault)); |
| 49 | |
| 50 | mainWnd = new Window(i18n->TranslateString("CDDB data"), wndPos, wndSize); |
| 51 | mainWnd->SetMinimumSize(Size(510, 461)); |
| 52 | mainWnd->SetRightToLeft(i18n->IsActiveLanguageRightToLeft()); |
| 53 | mainWnd->GetMainLayer()->onChangeSize.Connect(&cddbSubmitDlg::OnChangeSize, this); |
| 54 | |
| 55 | mainWnd_titlebar = new Titlebar(TB_CLOSEBUTTON); |
| 56 | divbar = new Divider(45, OR_HORZ | OR_BOTTOM); |
| 57 | |
| 58 | btn_cancel = new Button(i18n->TranslateString("Cancel"), Point(175, 32), Size()); |
| 59 | btn_cancel->onAction.Connect(&cddbSubmitDlg::Cancel, this); |
| 60 | btn_cancel->SetOrientation(OR_LOWERRIGHT); |
| 61 | |
| 62 | btn_submit = new Button(i18n->TranslateString("Submit"), Point(87, 32), Size()); |
| 63 | btn_submit->onAction.Connect(&cddbSubmitDlg::Submit, this); |
| 64 | btn_submit->SetOrientation(OR_LOWERRIGHT); |
| 65 | |
| 66 | if (!config->GetIntValue(Config::CategoryFreedbID, Config::FreedbEnableRemoteID, Config::FreedbEnableRemoteDefault)) btn_submit->SetText(i18n->TranslateString("Save entry")); |
| 67 | |
| 68 | check_updateJoblist = new CheckBox(i18n->TranslateString("Update joblist with this information"), Point(3, 39), Size(), &updateJoblist); |
| 69 | check_updateJoblist->SetOrientation(OR_LOWERLEFT); |
| 70 | |
| 71 | check_submitLater = new CheckBox(i18n->TranslateString("Submit to online database later"), Point(3, 20), Size(), &submitLater); |
| 72 | check_submitLater->onAction.Connect(&cddbSubmitDlg::ToggleSubmitLater, this); |
| 73 | check_submitLater->SetOrientation(OR_LOWERLEFT); |
| 74 | |
| 75 | check_updateJoblist->SetWidth(Math::Max(check_updateJoblist->GetUnscaledTextWidth(), check_submitLater->GetUnscaledTextWidth()) + 21); |
| 76 | check_submitLater->SetWidth(Math::Max(check_updateJoblist->GetUnscaledTextWidth(), check_submitLater->GetUnscaledTextWidth()) + 21); |
| 77 | |
| 78 | group_drive = new GroupBox(i18n->TranslateString("Active CD-ROM drive"), Point(7, 11), Size(480, 43)); |
| 79 | |
| 80 | combo_drive = new ComboBox(Point(10, 12), Size(260, 0)); |
| 81 | |
| 82 | Registry &boca = Registry::Get(); |
| 83 | DeviceInfoComponent *info = boca.CreateDeviceInfoComponent(); |
| 84 | |
| 85 | if (info != NIL) |
| 86 | { |
| 87 | for (Int i = 0; i < info->GetNumberOfDevices(); i++) |
| 88 | { |
| 89 | const Device &device = info->GetNthDeviceInfo(i); |
| 90 | |
| 91 | combo_drive->AddEntry(device.GetName()); |
| 92 | } |
| 93 | |
| 94 | boca.DeleteComponent(info); |
| 95 | } |
| 96 | |
| 97 | combo_drive->SelectNthEntry(activedrive); |
| 98 | combo_drive->onSelectEntry.Connect(&cddbSubmitDlg::ChangeDrive, this); |
| 99 | |
| 100 | text_cdstatus = new Text(i18n->AddColon(i18n->TranslateString("Status")), Point(277, 15)); |
| 101 | |
| 102 | group_drive->Add(combo_drive); |
| 103 | group_drive->Add(text_cdstatus); |
| 104 | |
| 105 | text_artist = new Text(i18n->AddColon(i18n->TranslateString("Artist")), Point(7, 65)); |
| 106 | text_album = new Text(i18n->AddColon(i18n->TranslateString("Album")), Point(7, 92)); |
| 107 | |
| 108 | Int maxTextSize = Math::Max(text_artist->GetUnscaledTextWidth(), text_album->GetUnscaledTextWidth()); |
| 109 | |
| 110 | edit_artist = new EditBox(Point(14 + maxTextSize, 62), Size(200 - maxTextSize, 0), 0); |
| 111 | |
| 112 | list_artist = new List(); |
| 113 | list_artist->AddEntry(i18n->TranslateString("Various artists")); |
| 114 | |
| 115 | edit_artist->SetDropDownList(list_artist); |
| 116 | edit_artist->onInput.Connect(&cddbSubmitDlg::SetArtist, this); |
| 117 | |
| 118 | edit_album = new EditBox(Point(14 + maxTextSize, 89), Size(200 - maxTextSize, 0), 0); |
| 119 | |
| 120 | list_genre = new List(); |
| 121 | Utilities::FillGenreList(list_genre); |
| 122 | |
| 123 | text_year = new Text(i18n->AddColon(i18n->TranslateString("Year")), Point(221, 65)); |
| 124 | |
| 125 | text_disccomment= new Text(i18n->AddColon(i18n->TranslateString("Comment")), Point(221, 92)); |
| 126 | |
| 127 | maxTextSize = Math::Max(text_year->GetUnscaledTextWidth(), text_disccomment->GetUnscaledTextWidth()); |
| 128 | |
| 129 | edit_year = new EditBox(Point(228 + maxTextSize, 62), Size(31, 0), 4); |
| 130 | edit_year->SetFlags(EDB_NUMERIC); |
| 131 | |
| 132 | text_genre = new Text(i18n->AddColon(i18n->TranslateString("Genre")), Point(266 + maxTextSize, 65)); |
| 133 | |
| 134 | edit_genre = new EditBox(Point(273 + maxTextSize + text_genre->GetUnscaledTextWidth(), 62), Size(214 - maxTextSize - text_genre->GetUnscaledTextWidth(), 0), 0); |
| 135 | edit_genre->SetDropDownList(list_genre); |
| 136 | |
| 137 | edit_disccomment= new MultiEdit(Point(228 + maxTextSize, 89), Size(259 - maxTextSize, 34), 0); |
| 138 | |
| 139 | list_tracks = new ListBox(Point(7, 131), Size(480, 140)); |
| 140 | list_tracks->SetFlags(LF_ALLOWRESELECT); |
| 141 | list_tracks->AddTab(i18n->TranslateString("Track"), 50); |
| 142 | list_tracks->AddTab(i18n->TranslateString("Title")); |
| 143 | list_tracks->onSelectEntry.Connect(&cddbSubmitDlg::SelectTrack, this); |
| 144 | |
| 145 | shortcut_previous = new Shortcut(0, Input::Keyboard::KeyUp, list_tracks); |
| 146 | shortcut_previous->onKeyDown.Connect(&cddbSubmitDlg::OnShortcutPrevious, this); |
| 147 | |
| 148 | shortcut_next = new Shortcut(0, Input::Keyboard::KeyDown, list_tracks); |
| 149 | shortcut_next->onKeyDown.Connect(&cddbSubmitDlg::OnShortcutNext, this); |
| 150 | |
| 151 | shortcut_first = new Shortcut(0, Input::Keyboard::KeyHome, list_tracks); |
| 152 | shortcut_first->onKeyDown.Connect(&cddbSubmitDlg::OnShortcutFirst, this); |
| 153 | |
| 154 | shortcut_last = new Shortcut(0, Input::Keyboard::KeyEnd, list_tracks); |
| 155 | shortcut_last->onKeyDown.Connect(&cddbSubmitDlg::OnShortcutLast, this); |
| 156 | |
| 157 | text_track = new Text(i18n->AddColon(i18n->TranslateString("Track")), Point(7, 138)); |
| 158 | text_track->SetOrientation(OR_LOWERLEFT); |
| 159 | |
| 160 | edit_track = new EditBox(Point(13 + text_track->GetUnscaledTextWidth(), 141), Size(25, 0), 3); |
| 161 | edit_track->SetOrientation(OR_LOWERLEFT); |
| 162 | edit_track->SetFlags(EDB_NUMERIC); |
| 163 | edit_track->Deactivate(); |
| 164 | |
| 165 | text_trackartist= new Text(i18n->AddColon(i18n->TranslateString("Artist")), Point(45 + text_track->GetUnscaledTextWidth(), 138)); |
| 166 | text_trackartist->SetOrientation(OR_LOWERLEFT); |
| 167 | |
| 168 | text_title = new Text(i18n->AddColon(i18n->TranslateString("Title")), Point(45 + text_track->GetUnscaledTextWidth(), 111)); |
| 169 | text_title->SetOrientation(OR_LOWERLEFT); |
| 170 | |
| 171 | text_comment = new Text(i18n->AddColon(i18n->TranslateString("Comment")), Point(45 + text_track->GetUnscaledTextWidth(), 84)); |
| 172 | text_comment->SetOrientation(OR_LOWERLEFT); |
| 173 | |
| 174 | maxTextSize = Math::Max(text_title->GetUnscaledTextWidth(), text_comment->GetUnscaledTextWidth()); |
| 175 | |
| 176 | edit_trackartist= new EditBox(Point(52 + text_track->GetUnscaledTextWidth() + maxTextSize, 141), Size(435 - text_track->GetUnscaledTextWidth() - maxTextSize, 0), 0); |
| 177 | edit_trackartist->SetOrientation(OR_LOWERLEFT); |
| 178 | edit_trackartist->Deactivate(); |
| 179 | edit_trackartist->onInput.Connect(&cddbSubmitDlg::UpdateTrack, this); |
| 180 | edit_trackartist->onEnter.Connect(&cddbSubmitDlg::FinishArtist, this); |
| 181 | |
| 182 | edit_title = new EditBox(Point(52 + text_track->GetUnscaledTextWidth() + maxTextSize, 114), Size(435 - text_track->GetUnscaledTextWidth() - maxTextSize, 0), 0); |
| 183 | edit_title->SetOrientation(OR_LOWERLEFT); |
| 184 | edit_title->Deactivate(); |
| 185 | edit_title->onInput.Connect(&cddbSubmitDlg::UpdateTrack, this); |
| 186 | edit_title->onEnter.Connect(&cddbSubmitDlg::FinishTrack, this); |
| 187 | |
| 188 | edit_comment = new MultiEdit(Point(52 + text_track->GetUnscaledTextWidth() + maxTextSize, 87), Size(435 - text_track->GetUnscaledTextWidth() - maxTextSize, 34), 0); |
| 189 | edit_comment->SetOrientation(OR_LOWERLEFT); |
| 190 | edit_comment->Deactivate(); |
| 191 | edit_comment->onInput.Connect(&cddbSubmitDlg::UpdateComment, this); |
| 192 | |
| 193 | text_status = new Text(NIL, Point(7, 28)); |
| 194 | text_status->SetOrientation(OR_LOWERLEFT); |
| 195 | |
| 196 | SetArtist(); |
| 197 | |
| 198 | Add(mainWnd); |
| 199 | |
| 200 | mainWnd->Add(btn_submit); |
| 201 | mainWnd->Add(btn_cancel); |
| 202 | |
| 203 | mainWnd->Add(check_updateJoblist); |
| 204 | mainWnd->Add(check_submitLater); |
| 205 | |
| 206 | mainWnd->Add(group_drive); |
| 207 | |
| 208 | mainWnd->Add(text_artist); |
| 209 | mainWnd->Add(edit_artist); |
| 210 | mainWnd->Add(list_artist); |
| 211 | mainWnd->Add(text_album); |
| 212 | mainWnd->Add(edit_album); |
| 213 | mainWnd->Add(text_year); |
| 214 | mainWnd->Add(edit_year); |
| 215 | mainWnd->Add(text_genre); |
| 216 | mainWnd->Add(edit_genre); |
| 217 | mainWnd->Add(text_disccomment); |
| 218 | mainWnd->Add(edit_disccomment); |
| 219 | |
| 220 | mainWnd->Add(text_track); |
| 221 | mainWnd->Add(edit_track); |
| 222 | mainWnd->Add(text_trackartist); |
| 223 | mainWnd->Add(edit_trackartist); |
| 224 | mainWnd->Add(text_title); |
| 225 | mainWnd->Add(edit_title); |
| 226 | mainWnd->Add(text_comment); |
| 227 | mainWnd->Add(edit_comment); |
| 228 | |
| 229 | mainWnd->Add(list_tracks); |
| 230 | |
| 231 | mainWnd->Add(shortcut_previous); |
| 232 | mainWnd->Add(shortcut_next); |
| 233 | mainWnd->Add(shortcut_first); |
| 234 | mainWnd->Add(shortcut_last); |
| 235 | |
| 236 | mainWnd->Add(text_status); |
| 237 | |
| 238 | mainWnd->Add(mainWnd_titlebar); |
| 239 | mainWnd->Add(divbar); |
| 240 | |
| 241 | mainWnd->SetFlags(WF_NOTASKBUTTON | WF_MODAL); |
| 242 | mainWnd->SetIcon(ImageLoader::Load(String(Config::Get()->resourcesPath).Append("icons/freac.png"))); |
| 243 | } |
| 244 | |
| 245 | freac::cddbSubmitDlg::~cddbSubmitDlg() |
| 246 | { |
| 247 | DeleteObject(mainWnd_titlebar); |
| 248 | DeleteObject(mainWnd); |
| 249 | |
| 250 | DeleteObject(divbar); |
| 251 | |
| 252 | DeleteObject(group_drive); |
| 253 | DeleteObject(combo_drive); |
| 254 | DeleteObject(text_cdstatus); |
| 255 | |
| 256 | DeleteObject(text_artist); |
| 257 | DeleteObject(edit_artist); |
| 258 | DeleteObject(list_artist); |
| 259 | DeleteObject(text_album); |
| 260 | DeleteObject(edit_album); |
| 261 | DeleteObject(text_year); |
| 262 | DeleteObject(edit_year); |
| 263 | DeleteObject(text_genre); |
| 264 | DeleteObject(edit_genre); |
| 265 | DeleteObject(list_genre); |
| 266 | DeleteObject(text_disccomment); |
| 267 | DeleteObject(edit_disccomment); |
| 268 | |
| 269 | DeleteObject(list_tracks); |
| 270 | |
| 271 | DeleteObject(shortcut_previous); |
| 272 | DeleteObject(shortcut_next); |
| 273 | DeleteObject(shortcut_first); |
| 274 | DeleteObject(shortcut_last); |
| 275 | |
| 276 | DeleteObject(text_track); |
| 277 | DeleteObject(edit_track); |
| 278 | DeleteObject(text_trackartist); |
| 279 | DeleteObject(edit_trackartist); |
| 280 | DeleteObject(text_title); |
| 281 | DeleteObject(edit_title); |
| 282 | DeleteObject(text_comment); |
| 283 | DeleteObject(edit_comment); |
| 284 | |
| 285 | DeleteObject(text_status); |
| 286 | |
| 287 | DeleteObject(check_updateJoblist); |
| 288 | DeleteObject(check_submitLater); |
| 289 | |
| 290 | DeleteObject(btn_submit); |
| 291 | DeleteObject(btn_cancel); |
| 292 | } |
| 293 | |
| 294 | const Error &freac::cddbSubmitDlg::ShowDialog() |
| 295 | { |
| 296 | ChangeDrive(); |
| 297 | |
| 298 | mainWnd->WaitUntilClosed(); |
| 299 | |
| 300 | return error; |
| 301 | } |
| 302 | |
| 303 | Void freac::cddbSubmitDlg::OnChangeSize(const Size &nSize) |
| 304 | { |
| 305 | BoCA::Config *config = BoCA::Config::Get(); |
| 306 | |
| 307 | config->SetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBSubmitSizeXID, mainWnd->GetSize().cx); |
| 308 | config->SetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBSubmitSizeYID, mainWnd->GetSize().cy); |
| 309 | |
| 310 | Rect clientRect = Rect(mainWnd->GetMainLayer()->GetPosition(), mainWnd->GetMainLayer()->GetSize()); |
| 311 | Size clientSize = Size(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); |
| 312 | |
| 313 | group_drive->SetWidth(clientSize.cx - 14); |
| 314 | |
| 315 | text_cdstatus->SetX(group_drive->GetWidth() - 203); |
| 316 | combo_drive->SetWidth(group_drive->GetWidth() - 220); |
| 317 | |
| 318 | Int textSize = Math::Max(text_artist->GetUnscaledTextWidth(), text_album->GetUnscaledTextWidth()) + Math::Max(text_year->GetUnscaledTextWidth(), text_disccomment->GetUnscaledTextWidth()); |
| 319 | |
| 320 | edit_artist->SetWidth((clientSize.cx - textSize - 34) / 2); |
| 321 | edit_album->SetWidth(edit_artist->GetWidth()); |
| 322 | |
| 323 | text_year->SetX(edit_artist->GetX() + edit_artist->GetWidth() + 7); |
| 324 | text_disccomment->SetX(text_year->GetX()); |
| 325 | |
| 326 | edit_year->SetX(text_year->GetX() + Math::Max(text_year->GetUnscaledTextWidth(), text_disccomment->GetUnscaledTextWidth()) + 7); |
| 327 | |
| 328 | edit_disccomment->SetX(edit_year->GetX()); |
| 329 | edit_disccomment->SetWidth(edit_artist->GetWidth() - (clientSize.cx - 1) % 2); |
| 330 | |
| 331 | text_genre->SetX(edit_year->GetX() + 38); |
| 332 | |
| 333 | edit_genre->SetX(text_genre->GetX() + text_genre->GetUnscaledTextWidth() + 7); |
| 334 | edit_genre->SetWidth(edit_disccomment->GetWidth() - text_genre->GetUnscaledTextWidth() - 45); |
| 335 | |
| 336 | list_tracks->SetSize(clientSize - Size(14, 280)); |
| 337 | |
| 338 | edit_trackartist->SetWidth(clientSize.cx - 59 - Math::Max(text_title->GetUnscaledTextWidth(), text_comment->GetUnscaledTextWidth()) - text_track->GetUnscaledTextWidth()); |
| 339 | edit_title->SetWidth(edit_trackartist->GetWidth()); |
| 340 | edit_comment->SetWidth(edit_trackartist->GetWidth()); |
| 341 | } |
| 342 | |
| 343 | Void freac::cddbSubmitDlg::Submit() |
| 344 | { |
| 345 | BoCA::Config *config = BoCA::Config::Get(); |
| 346 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 347 | |
| 348 | i18n->SetContext("CDDB::Submit"); |
| 349 | |
| 350 | if (!IsDataValid()) |
| 351 | { |
| 352 | i18n->SetContext("CDDB::Submit::Errors"); |
| 353 | |
| 354 | BoCA::Utilities::ErrorMessage(i18n->TranslateString("Please fill all fields and track titles before submitting.")); |
| 355 | |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | /* Prepare CDDB info. |
| 360 | */ |
| 361 | String variousArtists = i18n->TranslateString("Various artists"); |
| 362 | |
| 363 | cddbInfo.dArtist = IsVariousArtists() ? CDDBInfo::VariousArtistsID : edit_artist->GetText(); |
| 364 | |
| 365 | cddbInfo.dTitle = edit_album->GetText(); |
| 366 | cddbInfo.dYear = edit_year->GetText().ToInt(); |
| 367 | cddbInfo.dGenre = edit_genre->GetText(); |
| 368 | cddbInfo.comment = edit_disccomment->GetText(); |
| 369 | |
| 370 | cddbInfo.trackArtists.RemoveAll(); |
| 371 | cddbInfo.trackTitles.RemoveAll(); |
| 372 | cddbInfo.trackComments.RemoveAll(); |
| 373 | |
| 374 | foreach (const String &artist, artists ) cddbInfo.trackArtists.Add(artist); |
| 375 | foreach (const String &title, titles ) cddbInfo.trackTitles.Add(title == i18n->TranslateString("Data track") ? CDDBInfo::DataTrackID : title); |
| 376 | foreach (const String &comment, comments) cddbInfo.trackComments.Add(comment); |
| 377 | |
| 378 | if (cddbInfo.category == NIL) cddbInfo.category = GetCDDBGenre(edit_genre->GetText()); |
| 379 | |
| 380 | cddbInfo.revision++; |
| 381 | |
| 382 | /* Submit CDDB info. |
| 383 | */ |
| 384 | check_updateJoblist->Hide(); |
| 385 | check_submitLater->Hide(); |
| 386 | text_status->SetText(i18n->AddEllipsis(i18n->TranslateString("Submitting CD information"))); |
| 387 | |
| 388 | Int revision = cddbInfo.revision; |
| 389 | |
| 390 | if (config->GetIntValue(Config::CategoryFreedbID, Config::FreedbEnableLocalID, Config::FreedbEnableLocalDefault)) |
| 391 | { |
| 392 | CDDBLocal().Submit(cddbInfo); |
| 393 | } |
| 394 | |
| 395 | if (submitLater) |
| 396 | { |
| 397 | cddbInfo.revision = revision; |
| 398 | |
| 399 | CDDBBatch().AddSubmit(cddbInfo); |
| 400 | } |
| 401 | else if (config->GetIntValue(Config::CategoryFreedbID, Config::FreedbEnableRemoteID, Config::FreedbEnableRemoteDefault)) |
| 402 | { |
| 403 | cddbInfo.revision = revision; |
| 404 | |
| 405 | if (!CDDBRemote().Submit(cddbInfo)) |
| 406 | { |
| 407 | i18n->SetContext("CDDB::Submit::Errors"); |
| 408 | |
| 409 | BoCA::Utilities::ErrorMessage(i18n->TranslateString("Some error occurred trying to connect to the freedb server.")); |
| 410 | |
| 411 | text_status->SetText(NIL); |
| 412 | check_updateJoblist->Show(); |
| 413 | check_submitLater->Show(); |
| 414 | |
| 415 | cddbInfo.revision--; |
| 416 | |
| 417 | return; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | /* Save modified entry to CDDB cache |
| 422 | */ |
| 423 | CDDBCache::Get()->AddCacheEntry(cddbInfo); |
| 424 | |
| 425 | text_status->SetText(NIL); |
| 426 | |
| 427 | /* Update joblist with new track info. |
| 428 | */ |
| 429 | if (updateJoblist) |
| 430 | { |
| 431 | const Array<Track> *joblist = BoCA::JobList::Get()->getTrackList.Call(); |
| 432 | |
| 433 | for (Int i = 0; i < joblist->Length(); i++) |
| 434 | { |
| 435 | const Track &trackInfo = joblist->GetNth(i); |
| 436 | |
| 437 | if (trackInfo.discid != cddbInfo.discID) continue; |
| 438 | |
| 439 | for (Int j = 0; j < titles.Length(); j++) |
| 440 | { |
| 441 | if (trackInfo.cdTrack != list_tracks->GetNthEntry(j)->GetText().ToInt()) continue; |
| 442 | |
| 443 | Track track = trackInfo; |
| 444 | Info info = track.GetInfo(); |
| 445 | |
| 446 | if (IsVariousArtists()) info.artist = artists.GetNth(j); |
| 447 | else info.artist = edit_artist->GetText(); |
| 448 | |
| 449 | info.title = titles.GetNth(j); |
| 450 | info.album = edit_album->GetText(); |
| 451 | info.year = edit_year->GetText().ToInt(); |
| 452 | info.genre = edit_genre->GetText(); |
| 453 | info.comment = comments.GetNth(j); |
| 454 | |
| 455 | track.SetInfo(info); |
| 456 | |
| 457 | BoCA::JobList::Get()->onComponentModifyTrack.Emit(track); |
| 458 | |
| 459 | break; |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | config->SetIntValue(Config::CategoryFreedbID, Config::FreedbUpdateJoblistID, updateJoblist); |
| 465 | |
| 466 | mainWnd->Close(); |
| 467 | } |
| 468 | |
| 469 | Void freac::cddbSubmitDlg::Cancel() |
| 470 | { |
| 471 | mainWnd->Close(); |
| 472 | } |
| 473 | |
| 474 | Void freac::cddbSubmitDlg::SetArtist() |
| 475 | { |
| 476 | if (dontUpdateInfo) return; |
| 477 | |
| 478 | Bool dataTrack = list_tracks->GetSelectedEntry() != NIL ? data.Get(list_tracks->GetSelectedEntry()->GetHandle()) : False; |
| 479 | |
| 480 | if (IsVariousArtists() && !dataTrack) |
| 481 | { |
| 482 | if (list_tracks->GetSelectedEntry() != NIL) |
| 483 | { |
| 484 | edit_trackartist->SetText(artists.Get(list_tracks->GetSelectedEntry()->GetHandle())); |
| 485 | edit_trackartist->Activate(); |
| 486 | } |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | edit_trackartist->SetText(NIL); |
| 491 | edit_trackartist->Deactivate(); |
| 492 | } |
| 493 | |
| 494 | UpdateTrackList(); |
| 495 | } |
| 496 | |
| 497 | Void freac::cddbSubmitDlg::UpdateTrackList() |
| 498 | { |
| 499 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 500 | |
| 501 | i18n->SetContext("CDDB::Submit"); |
| 502 | |
| 503 | for (Int i = 0; i < list_tracks->Length(); i++) |
| 504 | { |
| 505 | if (IsVariousArtists() && data.GetNth(i) == False) list_tracks->GetNthEntry(i)->SetText(String(i < 9 ? "0" : NIL).Append(String::FromInt(i + 1)).Append(ListEntry::tabDelimiter).Append(artists.GetNth(i).Length() > 0 ? artists.GetNth(i) : i18n->TranslateString("unknown artist")).Append(" - ").Append(titles.GetNth(i).Length() > 0 ? titles.GetNth(i) : i18n->TranslateString("unknown title"))); |
| 506 | else list_tracks->GetNthEntry(i)->SetText(String(i < 9 ? "0" : NIL).Append(String::FromInt(i + 1)).Append(ListEntry::tabDelimiter).Append(titles.GetNth(i).Length() > 0 ? titles.GetNth(i) : i18n->TranslateString("unknown title"))); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | Void freac::cddbSubmitDlg::ChangeDrive() |
| 511 | { |
| 512 | BoCA::Config *config = BoCA::Config::Get(); |
| 513 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 514 | |
| 515 | i18n->SetContext("CDDB::Submit"); |
| 516 | |
| 517 | activedrive = combo_drive->GetSelectedEntryNumber(); |
| 518 | |
| 519 | Registry &boca = Registry::Get(); |
| 520 | DeviceInfoComponent *info = boca.CreateDeviceInfoComponent(); |
| 521 | |
| 522 | if (info == NIL) return; |
| 523 | |
| 524 | const MCDI &mcdi = info->GetNthDeviceMCDI(activedrive); |
| 525 | |
| 526 | Int numTocEntries = mcdi.GetNumberOfEntries(); |
| 527 | Int numAudioTracks = mcdi.GetNumberOfAudioTracks(); |
| 528 | |
| 529 | if (numAudioTracks <= 0) |
| 530 | { |
| 531 | boca.DeleteComponent(info); |
| 532 | |
| 533 | text_cdstatus->SetText(i18n->AddColon(i18n->TranslateString("Status")).Append(" ").Append(i18n->TranslateString("No audio CD in drive!"))); |
| 534 | |
| 535 | dontUpdateInfo = True; |
| 536 | |
| 537 | edit_artist->SetText(NIL); |
| 538 | edit_album->SetText(NIL); |
| 539 | edit_year->SetText(NIL); |
| 540 | edit_genre->SetText(NIL); |
| 541 | edit_disccomment->SetText(NIL); |
| 542 | |
| 543 | list_tracks->RemoveAllEntries(); |
| 544 | titles.RemoveAll(); |
| 545 | artists.RemoveAll(); |
| 546 | comments.RemoveAll(); |
| 547 | data.RemoveAll(); |
| 548 | |
| 549 | edit_track->SetText(NIL); |
| 550 | edit_trackartist->SetText(NIL); |
| 551 | edit_title->SetText(NIL); |
| 552 | edit_comment->SetText(NIL); |
| 553 | |
| 554 | edit_trackartist->Deactivate(); |
| 555 | edit_title->Deactivate(); |
| 556 | edit_comment->Deactivate(); |
| 557 | |
| 558 | dontUpdateInfo = False; |
| 559 | |
| 560 | btn_submit->Deactivate(); |
| 561 | |
| 562 | return; |
| 563 | } |
| 564 | else |
| 565 | { |
| 566 | text_cdstatus->SetText(i18n->AddColon(i18n->TranslateString("Status")).Append(" ").Append(i18n->TranslateString("Successfully read CD!"))); |
| 567 | |
| 568 | btn_submit->Activate(); |
| 569 | } |
| 570 | |
| 571 | Int oDrive = config->GetIntValue(Config::CategoryRipperID, Config::RipperActiveDriveID, Config::RipperActiveDriveDefault); |
| 572 | |
| 573 | config->SetIntValue(Config::CategoryRipperID, Config::RipperActiveDriveID, activedrive); |
| 574 | |
| 575 | String queryString = CDDB::QueryStringFromMCDI(mcdi); |
| 576 | CDDBInfo cdInfo; |
| 577 | |
| 578 | if (config->GetIntValue(Config::CategoryFreedbID, Config::FreedbEnableCacheID, Config::FreedbEnableCacheDefault)) cdInfo = CDDBCache::Get()->GetCacheEntry(queryString); |
| 579 | |
| 580 | if (cdInfo == NIL) |
| 581 | { |
| 582 | if (config->GetIntValue(Config::CategoryFreedbID, Config::FreedbEnableLocalID, Config::FreedbEnableLocalDefault) || |
| 583 | config->GetIntValue(Config::CategoryFreedbID, Config::FreedbEnableRemoteID, Config::FreedbEnableRemoteDefault)) |
| 584 | { |
| 585 | cddbQueryDlg dlg(queryString); |
| 586 | |
| 587 | if (dlg.ShowDialog() == Error()) |
| 588 | { |
| 589 | /* Ask whether to perform this query later. |
| 590 | */ |
| 591 | if (QuickMessage(dlg.GetErrorString().Append("\n\n").Append(i18n->TranslateString("Would you like to perform this query again later?", "CDDB::Query::Errors")), i18n->TranslateString("Error"), Message::Buttons::YesNo, Message::Icon::Error) == Message::Button::Yes) |
| 592 | { |
| 593 | CDDBBatch().AddQuery(queryString); |
| 594 | } |
| 595 | } |
| 596 | else if (dlg.GetErrorString() != NIL) |
| 597 | { |
| 598 | /* Display info message if any. |
| 599 | */ |
| 600 | BoCA::Utilities::InfoMessage(dlg.GetErrorString()); |
| 601 | } |
| 602 | |
| 603 | cdInfo = dlg.GetCDDBInfo(); |
| 604 | } |
| 605 | |
| 606 | if (cdInfo != NIL) CDDBCache::Get()->AddCacheEntry(cdInfo); |
| 607 | } |
| 608 | |
| 609 | i18n->SetContext("CDDB::Submit"); |
| 610 | |
| 611 | config->SetIntValue(Config::CategoryRipperID, Config::RipperActiveDriveID, oDrive); |
| 612 | |
| 613 | dontUpdateInfo = True; |
| 614 | |
| 615 | Array<String> albums; |
| 616 | Array<String> genres; |
| 617 | Array<String> years; |
| 618 | |
| 619 | titles.RemoveAll(); |
| 620 | artists.RemoveAll(); |
| 621 | comments.RemoveAll(); |
| 622 | data.RemoveAll(); |
| 623 | |
| 624 | list_tracks->RemoveAllEntries(); |
| 625 | |
| 626 | if (cdInfo != NIL) |
| 627 | { |
| 628 | cddbInfo = cdInfo; |
| 629 | cddbInfo.trackOffsets.RemoveAll(); |
| 630 | |
| 631 | cddbInfo.discID = CDDB::DiscIDFromMCDI(mcdi); |
| 632 | cddbInfo.discLength = mcdi.GetNthEntryOffset(numTocEntries) / 75 + 2; |
| 633 | |
| 634 | for (Int i = 0; i < numTocEntries; i++) |
| 635 | { |
| 636 | cddbInfo.trackOffsets.Add(mcdi.GetNthEntryOffset(i) + 150, i); |
| 637 | |
| 638 | Int handle = list_tracks->AddEntry(NIL)->GetHandle(); |
| 639 | |
| 640 | if (mcdi.GetNthEntryType(i) == ENTRY_AUDIO && mcdi.GetNthEntryTrackNumber(i) == i + 1) |
| 641 | { |
| 642 | artists.Add(cdInfo.trackArtists.GetNth(i) != NIL ? cdInfo.trackArtists.GetNth(i) : cdInfo.dArtist, handle); |
| 643 | titles.Add(cdInfo.trackTitles.GetNth(i), handle); |
| 644 | comments.Add(cdInfo.trackComments.GetNth(i), handle); |
| 645 | albums.Add(cdInfo.dTitle, handle); |
| 646 | genres.Add(cdInfo.dGenre, handle); |
| 647 | years.Add(cdInfo.dYear > 0 ? String::FromInt(cdInfo.dYear) : String(), handle); |
| 648 | data.Add(False, handle); |
| 649 | } |
| 650 | else |
| 651 | { |
| 652 | artists.Add(NIL, handle); |
| 653 | titles.Add(cdInfo.trackTitles.GetNth(i) != NIL && cdInfo.trackTitles.GetNth(i) != CDDBInfo::DataTrackID ? cdInfo.trackTitles.GetNth(i) : i18n->TranslateString("Data track"), handle); |
| 654 | comments.Add(cdInfo.trackComments.GetNth(i), handle); |
| 655 | albums.Add(NIL, handle); |
| 656 | genres.Add(NIL, handle); |
| 657 | years.Add(NIL, handle); |
| 658 | data.Add(True, handle); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | else |
| 663 | { |
| 664 | cddbInfo = NIL; |
| 665 | |
| 666 | cddbInfo.discID = CDDB::DiscIDFromMCDI(mcdi); |
| 667 | cddbInfo.discLength = mcdi.GetNthEntryOffset(numTocEntries) / 75 + 2; |
| 668 | cddbInfo.revision = -1; |
| 669 | |
| 670 | for (Int i = 0; i < numTocEntries; i++) |
| 671 | { |
| 672 | cddbInfo.trackOffsets.Add(mcdi.GetNthEntryOffset(i) + 150, i); |
| 673 | |
| 674 | Int handle = list_tracks->AddEntry(NIL)->GetHandle(); |
| 675 | |
| 676 | if (mcdi.GetNthEntryType(i) == ENTRY_AUDIO && mcdi.GetNthEntryTrackNumber(i) == i + 1) |
| 677 | { |
| 678 | /* Get CD track info using a device:// URI |
| 679 | */ |
| 680 | String uri = String("device://cdda:") |
| 681 | .Append(String::FromInt(activedrive)) |
| 682 | .Append("/") |
| 683 | .Append(String::FromInt(mcdi.GetNthEntryTrackNumber(i))); |
| 684 | DecoderComponent *decoder = boca.CreateDecoderForStream(uri); |
| 685 | Track track; |
| 686 | const Info &info = track.GetInfo(); |
| 687 | |
| 688 | decoder->GetStreamInfo(uri, track); |
| 689 | |
| 690 | boca.DeleteComponent(decoder); |
| 691 | |
| 692 | artists.Add(info.artist, handle); |
| 693 | titles.Add(info.title, handle); |
| 694 | comments.Add(NIL, handle); |
| 695 | albums.Add(info.album, handle); |
| 696 | genres.Add(info.genre, handle); |
| 697 | years.Add(info.year, handle); |
| 698 | data.Add(False, handle); |
| 699 | } |
| 700 | else |
| 701 | { |
| 702 | artists.Add(NIL, handle); |
| 703 | titles.Add(i18n->TranslateString("Data track"), handle); |
| 704 | comments.Add(NIL, handle); |
| 705 | albums.Add(NIL, handle); |
| 706 | genres.Add(NIL, handle); |
| 707 | years.Add(NIL, handle); |
| 708 | data.Add(True, handle); |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | boca.DeleteComponent(info); |
| 714 | |
| 715 | /* Update tracks with information from joblist. |
| 716 | */ |
| 717 | const Array<Track> *joblist = BoCA::JobList::Get()->getTrackList.Call(); |
| 718 | |
| 719 | for (Int i = 0; i < joblist->Length(); i++) |
| 720 | { |
| 721 | const Track &trackInfo = joblist->GetNth(i); |
| 722 | |
| 723 | if (trackInfo.discid != CDDB::DiscIDFromMCDI(mcdi)) continue; |
| 724 | |
| 725 | if (list_tracks->GetNthEntry(trackInfo.cdTrack - 1) != NIL) |
| 726 | { |
| 727 | const Info &info = trackInfo.GetInfo(); |
| 728 | |
| 729 | if (info.artist != NIL) artists.Set(artists.GetNthIndex(trackInfo.cdTrack - 1), info.artist); |
| 730 | if (info.title != NIL) titles.Set(titles.GetNthIndex(trackInfo.cdTrack - 1), info.title); |
| 731 | if (info.album != NIL) albums.Set(albums.GetNthIndex(trackInfo.cdTrack - 1), info.album); |
| 732 | if (info.genre != NIL) genres.Set(genres.GetNthIndex(trackInfo.cdTrack - 1), info.genre); |
| 733 | if (info.year > 0) years.Set(years.GetNthIndex(trackInfo.cdTrack - 1), String::FromInt(info.year)); |
| 734 | if (info.comment != NIL) comments.Set(comments.GetNthIndex(trackInfo.cdTrack - 1), info.comment); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | /* Set edit fields. |
| 739 | */ |
| 740 | edit_artist->SetText(artists.GetNth(0)); |
| 741 | edit_album->SetText(albums.GetNth(0)); |
| 742 | edit_genre->SetText(genres.GetNth(0)); |
| 743 | edit_year->SetText(years.GetNth(0)); |
| 744 | |
| 745 | edit_disccomment->SetText(cdInfo.comment); |
| 746 | |
| 747 | edit_track->SetText(NIL); |
| 748 | edit_trackartist->SetText(NIL); |
| 749 | edit_title->SetText(NIL); |
| 750 | edit_comment->SetText(NIL); |
| 751 | |
| 752 | edit_trackartist->Deactivate(); |
| 753 | edit_title->Deactivate(); |
| 754 | edit_comment->Deactivate(); |
| 755 | |
| 756 | for (Int i = 1; i < list_tracks->Length(); i++) |
| 757 | { |
| 758 | if (mcdi.GetNthEntryType(i) != ENTRY_AUDIO) continue; |
| 759 | |
| 760 | if (artists.GetNth(i) != artists.GetNth(i - 1)) |
| 761 | { |
| 762 | edit_artist->SetText(i18n->TranslateString("Various artists")); |
| 763 | edit_trackartist->Activate(); |
| 764 | } |
| 765 | |
| 766 | if (albums.GetNth(i) != albums.GetNth(i - 1)) edit_album->SetText(NIL); |
| 767 | if (genres.GetNth(i) != genres.GetNth(i - 1)) edit_genre->SetText(NIL); |
| 768 | if (years.GetNth(i) != years.GetNth(i - 1)) edit_year->SetText(NIL); |
| 769 | } |
| 770 | |
| 771 | UpdateTrackList(); |
| 772 | |
| 773 | dontUpdateInfo = False; |
| 774 | } |
| 775 | |
| 776 | Void freac::cddbSubmitDlg::SelectTrack() |
| 777 | { |
| 778 | if (list_tracks->GetSelectedEntry() == NIL) return; |
| 779 | |
| 780 | String artist = artists.Get(list_tracks->GetSelectedEntry()->GetHandle()); |
| 781 | String title = titles.Get(list_tracks->GetSelectedEntry()->GetHandle()); |
| 782 | String comment = comments.Get(list_tracks->GetSelectedEntry()->GetHandle()); |
| 783 | Bool dataTrack = data.Get(list_tracks->GetSelectedEntry()->GetHandle()); |
| 784 | Int track = list_tracks->GetSelectedEntry()->GetText().ToInt(); |
| 785 | |
| 786 | dontUpdateInfo = True; |
| 787 | |
| 788 | edit_title->SetText(title); |
| 789 | edit_comment->SetText(comment); |
| 790 | edit_track->SetText(NIL); |
| 791 | |
| 792 | edit_title->Activate(); |
| 793 | edit_comment->Activate(); |
| 794 | |
| 795 | if (track > 0 && track < 10) edit_track->SetText(String("0").Append(String::FromInt(track))); |
| 796 | else if (track >= 10) edit_track->SetText(String::FromInt(track)); |
| 797 | |
| 798 | if (IsVariousArtists() && !dataTrack) |
| 799 | { |
| 800 | edit_trackartist->SetText(artist); |
| 801 | edit_trackartist->Activate(); |
| 802 | edit_trackartist->MarkAll(); |
| 803 | } |
| 804 | else |
| 805 | { |
| 806 | edit_trackartist->SetText(NIL); |
| 807 | edit_trackartist->Deactivate(); |
| 808 | edit_title->MarkAll(); |
| 809 | } |
| 810 | |
| 811 | dontUpdateInfo = False; |
| 812 | } |
| 813 | |
| 814 | Void freac::cddbSubmitDlg::UpdateTrack() |
| 815 | { |
| 816 | if (dontUpdateInfo) return; |
| 817 | if (list_tracks->GetSelectedEntry() == NIL) return; |
| 818 | |
| 819 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 820 | |
| 821 | i18n->SetContext("CDDB::Submit"); |
| 822 | |
| 823 | Int track = edit_track->GetText().ToInt(); |
| 824 | Bool dataTrack = data.Get(list_tracks->GetSelectedEntry()->GetHandle()); |
| 825 | |
| 826 | if (IsVariousArtists() && !dataTrack) list_tracks->GetSelectedEntry()->SetText(String(track < 10 ? "0" : NIL).Append(String::FromInt(track)).Append(ListEntry::tabDelimiter).Append(edit_trackartist->GetText() == NIL ? i18n->TranslateString("unknown artist") : edit_trackartist->GetText()).Append(" - ").Append(edit_title->GetText() == NIL ? i18n->TranslateString("unknown title") : edit_title->GetText())); |
| 827 | else list_tracks->GetSelectedEntry()->SetText(String(track < 10 ? "0" : NIL).Append(String::FromInt(track)).Append(ListEntry::tabDelimiter).Append(edit_title->GetText() == NIL ? i18n->TranslateString("unknown title") : edit_title->GetText())); |
| 828 | |
| 829 | artists.Set(list_tracks->GetSelectedEntry()->GetHandle(), edit_trackartist->GetText()); |
| 830 | titles.Set(list_tracks->GetSelectedEntry()->GetHandle(), edit_title->GetText()); |
| 831 | } |
| 832 | |
| 833 | Void freac::cddbSubmitDlg::FinishArtist() |
| 834 | { |
| 835 | edit_title->MarkAll(); |
| 836 | |
| 837 | finishedArtist = True; |
| 838 | } |
| 839 | |
| 840 | Void freac::cddbSubmitDlg::FinishTrack() |
| 841 | { |
| 842 | if (finishedArtist) |
| 843 | { |
| 844 | edit_title->MarkAll(); |
| 845 | |
| 846 | finishedArtist = False; |
| 847 | |
| 848 | return; |
| 849 | } |
| 850 | |
| 851 | for (Int i = 0; i < list_tracks->Length() - 1; i++) |
| 852 | { |
| 853 | if (list_tracks->GetSelectedEntry() == list_tracks->GetNthEntry(i)) |
| 854 | { |
| 855 | list_tracks->SelectEntry(list_tracks->GetNthEntry(i + 1)); |
| 856 | |
| 857 | SelectTrack(); |
| 858 | |
| 859 | break; |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | Widget *freac::cddbSubmitDlg::GetActiveEditBox() |
| 865 | { |
| 866 | if (edit_artist->IsFocussed()) return edit_artist; |
| 867 | else if (edit_trackartist->IsFocussed()) return edit_trackartist; |
| 868 | else if (edit_title->IsFocussed()) return edit_title; |
| 869 | else if (edit_album->IsFocussed()) return edit_album; |
| 870 | else if (edit_track->IsFocussed()) return edit_track; |
| 871 | else if (edit_year->IsFocussed()) return edit_year; |
| 872 | else if (edit_genre->IsFocussed()) return edit_genre; |
| 873 | else if (edit_comment->IsFocussed()) return edit_comment; |
| 874 | else if (edit_disccomment->IsFocussed()) return edit_disccomment; |
| 875 | |
| 876 | return NIL; |
| 877 | } |
| 878 | |
| 879 | Void freac::cddbSubmitDlg::OnShortcutPrevious() |
| 880 | { |
| 881 | if (edit_comment->IsFocussed()) return; |
| 882 | |
| 883 | if (list_tracks->GetSelectedEntryNumber() == -1) list_tracks->SelectNthEntry(list_tracks->Length() - 1); |
| 884 | else list_tracks->SelectNthEntry(list_tracks->GetSelectedEntryNumber() - 1); |
| 885 | } |
| 886 | |
| 887 | Void freac::cddbSubmitDlg::OnShortcutNext() |
| 888 | { |
| 889 | if (edit_comment->IsFocussed()) return; |
| 890 | |
| 891 | list_tracks->SelectNthEntry(list_tracks->GetSelectedEntryNumber() + 1); |
| 892 | } |
| 893 | |
| 894 | Void freac::cddbSubmitDlg::OnShortcutFirst() |
| 895 | { |
| 896 | if (GetActiveEditBox() != NIL) return; |
| 897 | |
| 898 | list_tracks->SelectNthEntry(0); |
| 899 | } |
| 900 | |
| 901 | Void freac::cddbSubmitDlg::OnShortcutLast() |
| 902 | { |
| 903 | if (GetActiveEditBox() != NIL) return; |
| 904 | |
| 905 | list_tracks->SelectNthEntry(list_tracks->Length() - 1); |
| 906 | } |
| 907 | |
| 908 | Void freac::cddbSubmitDlg::UpdateComment() |
| 909 | { |
| 910 | if (dontUpdateInfo) return; |
| 911 | if (list_tracks->GetSelectedEntry() == NIL) return; |
| 912 | |
| 913 | comments.Set(list_tracks->GetSelectedEntry()->GetHandle(), edit_comment->GetText()); |
| 914 | } |
| 915 | |
| 916 | Void freac::cddbSubmitDlg::ToggleSubmitLater() |
| 917 | { |
| 918 | BoCA::Config *config = BoCA::Config::Get(); |
| 919 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 920 | |
| 921 | i18n->SetContext("CDDB::Submit"); |
| 922 | |
| 923 | if (!submitLater && config->GetIntValue(Config::CategoryFreedbID, Config::FreedbEnableRemoteID, Config::FreedbEnableRemoteDefault)) btn_submit->SetText(i18n->TranslateString("Submit")); |
| 924 | else btn_submit->SetText(i18n->TranslateString("Save entry")); |
| 925 | } |
| 926 | |
| 927 | Bool freac::cddbSubmitDlg::IsVariousArtists() const |
| 928 | { |
| 929 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 930 | |
| 931 | i18n->SetContext("CDDB::Submit"); |
| 932 | |
| 933 | return edit_artist->GetText() == i18n->TranslateString("Various artists") || |
| 934 | edit_artist->GetText() == CDDBInfo::VariousArtistsID; |
| 935 | } |
| 936 | |
| 937 | Bool freac::cddbSubmitDlg::IsDataValid() const |
| 938 | { |
| 939 | Bool sane = True; |
| 940 | |
| 941 | if (!IsStringValid(edit_artist->GetText()) || |
| 942 | !IsStringValid(edit_album->GetText())) sane = False; |
| 943 | |
| 944 | for (Int i = 0; i < titles.Length(); i++) |
| 945 | { |
| 946 | if (IsVariousArtists() && data.GetNth(i) == False && |
| 947 | !IsStringValid(artists.GetNth(i))) sane = False; |
| 948 | |
| 949 | if (!IsStringValid(titles.GetNth(i))) sane = False; |
| 950 | } |
| 951 | |
| 952 | return sane; |
| 953 | } |
| 954 | |
| 955 | Bool freac::cddbSubmitDlg::IsStringValid(const String &text) |
| 956 | { |
| 957 | Bool valid = False; |
| 958 | |
| 959 | for (Int i = 0; i < text.Length(); i++) |
| 960 | { |
| 961 | if (text[i] != ' ' && |
| 962 | text[i] != '\t' && |
| 963 | text[i] != '\n' && |
| 964 | text[i] != '\r') |
| 965 | { |
| 966 | valid = True; |
| 967 | |
| 968 | break; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | if ( text.ToLower() == "new artist" || |
| 973 | text.ToLower() == "new title" || |
| 974 | text == "-" || |
| 975 | text == "--" || |
| 976 | (text.ToLower().StartsWith("audiotrack") && text.Length() <= 13) || |
| 977 | (text.ToLower().StartsWith("track") && text.Length() <= 8)) valid = False; |
| 978 | |
| 979 | return valid; |
| 980 | } |
| 981 | |
| 982 | String freac::cddbSubmitDlg::GetCDDBGenre(const String &genre) |
| 983 | { |
| 984 | String cddbGenre = "misc"; |
| 985 | |
| 986 | if (genre == "Alt. Rock") cddbGenre = "rock"; |
| 987 | if (genre == "Anime") cddbGenre = "soundtrack"; |
| 988 | if (genre == "Big Band") cddbGenre = "jazz"; |
| 989 | if (genre == "Black Metal") cddbGenre = "rock"; |
| 990 | if (genre == "Blues") cddbGenre = "blues"; |
| 991 | if (genre == "BritPop") cddbGenre = "rock"; |
| 992 | if (genre == "Celtic") cddbGenre = "folk"; |
| 993 | if (genre == "Chamber Music") cddbGenre = "classical"; |
| 994 | if (genre == "Christian Rock") cddbGenre = "rock"; |
| 995 | if (genre == "Classic Rock") cddbGenre = "rock"; |
| 996 | if (genre == "Classical") cddbGenre = "classical"; |
| 997 | if (genre == "Country") cddbGenre = "country"; |
| 998 | if (genre == "Death Metal") cddbGenre = "rock"; |
| 999 | if (genre == "Ethnic") cddbGenre = "folk"; |
| 1000 | if (genre == "Folk") cddbGenre = "folk"; |
| 1001 | if (genre == "Folk/Rock") cddbGenre = "folk"; |
| 1002 | if (genre == "Folklore") cddbGenre = "folk"; |
| 1003 | if (genre == "Garage Rock") cddbGenre = "rock"; |
| 1004 | if (genre == "Gothic Rock") cddbGenre = "rock"; |
| 1005 | if (genre == "Hard Rock") cddbGenre = "rock"; |
| 1006 | if (genre == "Heavy Metal") cddbGenre = "rock"; |
| 1007 | if (genre == "Indie Rock") cddbGenre = "rock"; |
| 1008 | if (genre == "Instrumental Pop") cddbGenre = "rock"; |
| 1009 | if (genre == "Instrumental Rock") cddbGenre = "rock"; |
| 1010 | if (genre == "Jazz") cddbGenre = "jazz"; |
| 1011 | if (genre == "Jazz+Funk") cddbGenre = "jazz"; |
| 1012 | if (genre == "JPop") cddbGenre = "rock"; |
| 1013 | if (genre == "Krautrock") cddbGenre = "rock"; |
| 1014 | if (genre == "Metal") cddbGenre = "rock"; |
| 1015 | if (genre == "National Folk") cddbGenre = "folk"; |
| 1016 | if (genre == "Native American") cddbGenre = "folk"; |
| 1017 | if (genre == "New Age") cddbGenre = "newage"; |
| 1018 | if (genre == "Pop") cddbGenre = "rock"; |
| 1019 | if (genre == "Pop/Funk") cddbGenre = "rock"; |
| 1020 | if (genre == "Pop-Folk") cddbGenre = "folk"; |
| 1021 | if (genre == "Progressive Rock") cddbGenre = "rock"; |
| 1022 | if (genre == "Psychedelic Rock") cddbGenre = "rock"; |
| 1023 | if (genre == "Punk") cddbGenre = "rock"; |
| 1024 | if (genre == "Punk Rock") cddbGenre = "rock"; |
| 1025 | if (genre == "Reggae") cddbGenre = "reggae"; |
| 1026 | if (genre == "Rock") cddbGenre = "rock"; |
| 1027 | if (genre == "Rock & Roll") cddbGenre = "rock"; |
| 1028 | if (genre == "Slow Rock") cddbGenre = "rock"; |
| 1029 | if (genre == "Soundtrack") cddbGenre = "soundtrack"; |
| 1030 | if (genre == "Southern Rock") cddbGenre = "rock"; |
| 1031 | if (genre == "Symphonic Rock") cddbGenre = "rock"; |
| 1032 | if (genre == "Symphony") cddbGenre = "classical"; |
| 1033 | if (genre == "Thrash-Metal") cddbGenre = "rock"; |
| 1034 | if (genre == "Top 40") cddbGenre = "rock"; |
| 1035 | if (genre == "Tribal") cddbGenre = "folk"; |
| 1036 | |
| 1037 | return cddbGenre; |
| 1038 | } |