| 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/managesubmits.h> |
| 14 | |
| 15 | #include <config.h> |
| 16 | |
| 17 | freac::cddbManageSubmitsDlg::cddbManageSubmitsDlg() |
| 18 | { |
| 19 | BoCA::Config *config = BoCA::Config::Get(); |
| 20 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 21 | |
| 22 | i18n->SetContext("CDDB::Manage submits"); |
| 23 | |
| 24 | Point wndPos = Point(config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosXID, Config::SettingsWindowPosXDefault), config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosYID, Config::SettingsWindowPosYDefault)) + Point(40, 40); |
| 25 | Size wndSize = Size(config->GetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBManageSubmitsSizeXID, Config::DialogsCDDBManageSubmitsSizeXDefault), config->GetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBManageSubmitsSizeYID, Config::DialogsCDDBManageSubmitsSizeYDefault)); |
| 26 | |
| 27 | mainWnd = new Window(i18n->TranslateString("CDDB data"), wndPos, wndSize); |
| 28 | mainWnd->SetMinimumSize(Size(374, 200)); |
| 29 | mainWnd->SetRightToLeft(i18n->IsActiveLanguageRightToLeft()); |
| 30 | mainWnd->GetMainLayer()->onChangeSize.Connect(&cddbManageSubmitsDlg::OnChangeSize, this); |
| 31 | |
| 32 | mainWnd_titlebar = new Titlebar(TB_CLOSEBUTTON); |
| 33 | divbar = new Divider(39, OR_HORZ | OR_BOTTOM); |
| 34 | |
| 35 | btn_cancel = new Button(i18n->TranslateString("Close"), Point(87, 29), Size()); |
| 36 | btn_cancel->onAction.Connect(&cddbManageSubmitsDlg::Cancel, this); |
| 37 | btn_cancel->SetOrientation(OR_LOWERRIGHT); |
| 38 | |
| 39 | text_entries = new Text(i18n->AddColon(i18n->TranslateString("CDDB entries to submit")), Point(7, 10)); |
| 40 | |
| 41 | list_entries = new ListBox(Point(7, 29), Size(261, 213)); |
| 42 | list_entries->AddTab(i18n->TranslateString("Category"), 65); |
| 43 | list_entries->AddTab(i18n->TranslateString("Disc name"), 0); |
| 44 | list_entries->onSelectEntry.Connect(&cddbManageSubmitsDlg::SelectEntry, this); |
| 45 | |
| 46 | text_preview = new Text(i18n->AddColon(i18n->TranslateString("Preview")), Point(276, 10)); |
| 47 | |
| 48 | edit_preview = new MultiEdit(Point(276, 29), Size(261, 213), 0); |
| 49 | edit_preview->Deactivate(); |
| 50 | |
| 51 | btn_delete = new Button(i18n->TranslateString("Remove entry"), Point(188, 69), Size()); |
| 52 | btn_delete->onAction.Connect(&cddbManageSubmitsDlg::DeleteEntry, this); |
| 53 | btn_delete->SetWidth(Math::Max(80, btn_delete->GetUnscaledTextWidth() + 14)); |
| 54 | btn_delete->SetX(268 - btn_delete->GetWidth()); |
| 55 | btn_delete->SetOrientation(OR_LOWERLEFT); |
| 56 | |
| 57 | btn_send_all = new Button(i18n->TranslateString("Submit all"), Point(87, 69), Size()); |
| 58 | btn_send_all->onAction.Connect(&cddbManageSubmitsDlg::SendAllEntries, this); |
| 59 | btn_send_all->SetWidth(Math::Max(80, btn_send_all->GetUnscaledTextWidth() + 14)); |
| 60 | btn_send_all->SetX(btn_send_all->GetWidth() + 7); |
| 61 | btn_send_all->SetOrientation(OR_LOWERRIGHT); |
| 62 | |
| 63 | btn_send = new Button(i18n->TranslateString("Submit"), Point(175, 69), Size()); |
| 64 | btn_send->onAction.Connect(&cddbManageSubmitsDlg::SendEntry, this); |
| 65 | btn_send->SetWidth(Math::Max(80, btn_send->GetUnscaledTextWidth() + 14)); |
| 66 | btn_send->SetX(btn_send->GetWidth() + btn_send_all->GetWidth() + 15); |
| 67 | btn_send->SetOrientation(OR_LOWERRIGHT); |
| 68 | |
| 69 | text_status = new Text(NIL, Point(7, 26)); |
| 70 | text_status->SetOrientation(OR_LOWERLEFT); |
| 71 | |
| 72 | btn_delete->Deactivate(); |
| 73 | btn_send->Deactivate(); |
| 74 | |
| 75 | ReadEntries(); |
| 76 | |
| 77 | Add(mainWnd); |
| 78 | |
| 79 | mainWnd->Add(btn_cancel); |
| 80 | mainWnd->Add(mainWnd_titlebar); |
| 81 | mainWnd->Add(divbar); |
| 82 | mainWnd->Add(text_entries); |
| 83 | mainWnd->Add(list_entries); |
| 84 | mainWnd->Add(text_preview); |
| 85 | mainWnd->Add(edit_preview); |
| 86 | mainWnd->Add(btn_delete); |
| 87 | mainWnd->Add(btn_send); |
| 88 | mainWnd->Add(btn_send_all); |
| 89 | mainWnd->Add(text_status); |
| 90 | |
| 91 | mainWnd->SetFlags(WF_NOTASKBUTTON | WF_MODAL); |
| 92 | mainWnd->SetIcon(ImageLoader::Load(String(Config::Get()->resourcesPath).Append("icons/freac.png"))); |
| 93 | } |
| 94 | |
| 95 | freac::cddbManageSubmitsDlg::~cddbManageSubmitsDlg() |
| 96 | { |
| 97 | DeleteObject(mainWnd_titlebar); |
| 98 | DeleteObject(mainWnd); |
| 99 | DeleteObject(divbar); |
| 100 | DeleteObject(btn_cancel); |
| 101 | |
| 102 | DeleteObject(text_entries); |
| 103 | DeleteObject(list_entries); |
| 104 | |
| 105 | DeleteObject(text_preview); |
| 106 | DeleteObject(edit_preview); |
| 107 | |
| 108 | DeleteObject(btn_delete); |
| 109 | DeleteObject(btn_send); |
| 110 | DeleteObject(btn_send_all); |
| 111 | |
| 112 | DeleteObject(text_status); |
| 113 | } |
| 114 | |
| 115 | const Error &freac::cddbManageSubmitsDlg::ShowDialog() |
| 116 | { |
| 117 | mainWnd->WaitUntilClosed(); |
| 118 | |
| 119 | return error; |
| 120 | } |
| 121 | |
| 122 | Void freac::cddbManageSubmitsDlg::OnChangeSize(const Size &nSize) |
| 123 | { |
| 124 | BoCA::Config *config = BoCA::Config::Get(); |
| 125 | |
| 126 | config->SetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBManageSubmitsSizeXID, mainWnd->GetSize().cx); |
| 127 | config->SetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBManageSubmitsSizeYID, mainWnd->GetSize().cy); |
| 128 | |
| 129 | Rect clientRect = Rect(mainWnd->GetMainLayer()->GetPosition(), mainWnd->GetMainLayer()->GetSize()); |
| 130 | Size clientSize = Size(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); |
| 131 | |
| 132 | text_preview->SetX(clientSize.cx / 2 + 4); |
| 133 | edit_preview->SetMetrics(Point(clientSize.cx / 2 + 4, 29), Size((clientSize.cx - 22) / 2 + clientSize.cx % 2, clientSize.cy - 106)); |
| 134 | |
| 135 | list_entries->SetSize(Size((clientSize.cx - 22) / 2, clientSize.cy - 106)); |
| 136 | |
| 137 | btn_delete->SetX(clientSize.cx / 2 - btn_delete->GetWidth() - 4); |
| 138 | } |
| 139 | |
| 140 | Void freac::cddbManageSubmitsDlg::Cancel() |
| 141 | { |
| 142 | mainWnd->Close(); |
| 143 | } |
| 144 | |
| 145 | Void freac::cddbManageSubmitsDlg::SelectEntry() |
| 146 | { |
| 147 | const CDDBInfo &cddbInfo = cddbBatch.GetSubmits().GetNth(list_entries->GetSelectedEntryNumber()); |
| 148 | String preview = String(cddbInfo.dArtist).Append(" - ").Append(cddbInfo.dTitle).Append("\n\n"); |
| 149 | |
| 150 | for (Int i = 0; i < cddbInfo.trackTitles.Length(); i++) |
| 151 | { |
| 152 | preview.Append(i < 9 ? "0" : NIL).Append(String::FromInt(i + 1)).Append(": ").Append(cddbInfo.dArtist == CDDBInfo::VariousArtistsID ? cddbInfo.trackArtists.GetNth(i).Append(" - ") : String()).Append(cddbInfo.trackTitles.GetNth(i)).Append(i < cddbInfo.trackTitles.Length() - 1 ? "\n" : NIL); |
| 153 | } |
| 154 | |
| 155 | edit_preview->SetText(preview); |
| 156 | |
| 157 | btn_delete->Activate(); |
| 158 | btn_send->Activate(); |
| 159 | } |
| 160 | |
| 161 | Void freac::cddbManageSubmitsDlg::DeleteEntry() |
| 162 | { |
| 163 | cddbBatch.DeleteSubmit(cddbBatch.GetSubmits().GetNth(list_entries->GetSelectedEntryNumber())); |
| 164 | |
| 165 | list_entries->Remove(list_entries->GetSelectedEntry()); |
| 166 | |
| 167 | edit_preview->SetText(NIL); |
| 168 | |
| 169 | btn_delete->Deactivate(); |
| 170 | btn_send->Deactivate(); |
| 171 | } |
| 172 | |
| 173 | Void freac::cddbManageSubmitsDlg::ReadEntries() |
| 174 | { |
| 175 | /* Read all entries from the freedb queue. |
| 176 | */ |
| 177 | const Array<CDDBInfo> &entries = cddbBatch.GetSubmits(); |
| 178 | |
| 179 | for (Int i = 0; i < entries.Length(); i++) |
| 180 | { |
| 181 | const CDDBInfo &cddbInfo = entries.GetNth(i); |
| 182 | |
| 183 | list_entries->AddEntry(String(cddbInfo.category).Append(ListEntry::tabDelimiter).Append(cddbInfo.dArtist).Append(" - ").Append(cddbInfo.dTitle)); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | Void freac::cddbManageSubmitsDlg::SendEntry() |
| 188 | { |
| 189 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 190 | |
| 191 | i18n->SetContext("CDDB::Manage submits"); |
| 192 | |
| 193 | /* Submit selected entry to online CDDB. |
| 194 | */ |
| 195 | text_status->SetText(i18n->AddEllipsis(i18n->TranslateString("Submitting CD information"))); |
| 196 | |
| 197 | if (cddbBatch.Submit(cddbBatch.GetSubmits().GetNth(list_entries->GetSelectedEntryNumber()))) |
| 198 | { |
| 199 | list_entries->Remove(list_entries->GetSelectedEntry()); |
| 200 | |
| 201 | edit_preview->SetText(NIL); |
| 202 | |
| 203 | btn_delete->Deactivate(); |
| 204 | btn_send->Deactivate(); |
| 205 | } |
| 206 | |
| 207 | text_status->SetText(NIL); |
| 208 | } |
| 209 | |
| 210 | Void freac::cddbManageSubmitsDlg::SendAllEntries() |
| 211 | { |
| 212 | BoCA::I18n *i18n = BoCA::I18n::Get(); |
| 213 | |
| 214 | i18n->SetContext("CDDB::Manage submits"); |
| 215 | |
| 216 | /* Submit all entries to online CDDB. |
| 217 | */ |
| 218 | text_status->SetText(i18n->AddEllipsis(i18n->TranslateString("Submitting CD information"))); |
| 219 | |
| 220 | if (cddbBatch.SubmitAll()) mainWnd->Close(); |
| 221 | |
| 222 | text_status->SetText(NIL); |
| 223 | } |