Debian Codegraph @

src/dialogs/cddb/manage.cpp

raw symbols SCIP
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/manage.h>
14
15 #include <config.h>
16 #include <dllinterfaces.h>
17 #include <utilities.h>
18
19 #include <joblist.h>
20
21 #include <cddb/cddb.h>
22 #include <cddb/cddbcache.h>
23
24 using namespace BoCA;
25
26 freac::cddbManageDlg::cddbManageDlg()
27 {
28 BoCA::Config *config = BoCA::Config::Get();
29 BoCA::I18n *i18n = BoCA::I18n::Get();
30
31 i18n->SetContext("CDDB::Manage cache");
32
33 updateJoblist = config->GetIntValue(Config::CategoryFreedbID, Config::FreedbUpdateJoblistID, Config::FreedbUpdateJoblistDefault);
34
35 Point wndPos = Point(config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosXID, Config::SettingsWindowPosXDefault), config->GetIntValue(Config::CategorySettingsID, Config::SettingsWindowPosYID, Config::SettingsWindowPosYDefault)) + Point(40, 40);
36 Size wndSize = Size(config->GetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBManageCacheSizeXID, Config::DialogsCDDBManageCacheSizeXDefault), config->GetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBManageCacheSizeYID, Config::DialogsCDDBManageCacheSizeYDefault));
37
38 mainWnd = new Window(i18n->TranslateString("CDDB data"), wndPos, wndSize);
39 mainWnd->SetRightToLeft(i18n->IsActiveLanguageRightToLeft());
40 mainWnd->GetMainLayer()->onChangeSize.Connect(&cddbManageDlg::OnChangeSize, this);
41
42 mainWnd_titlebar = new Titlebar(TB_CLOSEBUTTON);
43 divbar = new Divider(39, OR_HORZ | OR_BOTTOM);
44
45 btn_cancel = new Button(i18n->TranslateString("Cancel"), Point(175, 29), Size());
46 btn_cancel->onAction.Connect(&cddbManageDlg::Cancel, this);
47 btn_cancel->SetOrientation(OR_LOWERRIGHT);
48
49 btn_ok = new Button(i18n->TranslateString("OK"), Point(87, 29), Size());
50 btn_ok->onAction.Connect(&cddbManageDlg::OK, this);
51 btn_ok->SetOrientation(OR_LOWERRIGHT);
52
53 check_updateJoblist = new CheckBox(i18n->TranslateString("Update joblist with this information"), Point(7, 27), Size(), &updateJoblist);
54 check_updateJoblist->SetWidth(check_updateJoblist->GetUnscaledTextWidth() + 21);
55 check_updateJoblist->SetOrientation(OR_LOWERLEFT);
56
57 text_entries = new Text(i18n->AddColon(i18n->TranslateString("Downloaded CDDB entries")), Point(7, 10));
58
59 list_entries = new ListBox(Point(7, 29), Size(261, 213));
60 list_entries->AddTab(i18n->TranslateString("Disc name"), 0);
61 list_entries->AddTab(i18n->TranslateString("Charset"), 100);
62 list_entries->onSelectEntry.Connect(&cddbManageDlg::SelectEntry, this);
63
64 for (Int i = 0; i < CDDBCache::Get()->GetNOfEntries(); i++)
65 {
66 const CDDBInfo &entry = CDDBCache::Get()->GetNthEntry(i);
67
68 list_entries->AddEntry(String(entry.dArtist).Append(" - ").Append(entry.dTitle).Append(ListEntry::tabDelimiter).Append(entry.charset));
69 }
70
71 text_preview = new Text(i18n->AddColon(i18n->TranslateString("Preview")), Point(276, 10));
72
73 edit_preview = new MultiEdit(Point(276, 29), Size(261, 186), 0);
74 edit_preview->Deactivate();
75
76 text_charset = new Text(i18n->AddColon(i18n->TranslateString("Charset")), Point(276, 226));
77
78 list_charset = new List();
79 list_charset->AddEntry("UTF-8");
80 list_charset->AddSeparator();
81 list_charset->AddEntry("ISO-8859-1");
82 list_charset->AddEntry("ISO-8859-2");
83 list_charset->AddEntry("ISO-8859-5");
84 list_charset->AddEntry("ISO-8859-7");
85 list_charset->AddSeparator();
86 list_charset->AddEntry("CP1251");
87 list_charset->AddSeparator();
88 list_charset->AddEntry("SHIFT-JIS");
89 list_charset->AddEntry("GBK");
90 list_charset->AddEntry("BIG-5");
91
92 edit_charset = new EditBox(Point(283 + text_charset->GetUnscaledTextWidth(), 223), Size(254 - text_charset->GetUnscaledTextWidth(), 0), 0);
93 edit_charset->SetDropDownList(list_charset);
94 edit_charset->onInput.Connect(&cddbManageDlg::SetCharset, this);
95
96 btn_delete = new Button(i18n->TranslateString("Remove entry"), Point(188, 69), Size());
97 btn_delete->onAction.Connect(&cddbManageDlg::DeleteEntry, this);
98 btn_delete->SetWidth(Math::Max(80, btn_delete->GetUnscaledTextWidth() + 14));
99 btn_delete->SetX(268 - btn_delete->GetWidth());
100 btn_delete->SetOrientation(OR_LOWERLEFT);
101
102 btn_save = new Button(i18n->TranslateString("Save entry"), Point(87, 69), Size());
103 btn_save->onAction.Connect(&cddbManageDlg::SaveEntry, this);
104 btn_save->SetWidth(Math::Max(80, btn_save->GetUnscaledTextWidth() + 14));
105 btn_save->SetX(btn_save->GetWidth() + 7);
106 btn_save->SetOrientation(OR_LOWERRIGHT);
107
108 edit_charset->Deactivate();
109 btn_delete->Deactivate();
110 btn_save->Deactivate();
111
112 Add(mainWnd);
113
114 mainWnd->Add(btn_ok);
115 mainWnd->Add(btn_cancel);
116 mainWnd->Add(check_updateJoblist);
117 mainWnd->Add(mainWnd_titlebar);
118 mainWnd->Add(divbar);
119 mainWnd->Add(text_entries);
120 mainWnd->Add(list_entries);
121 mainWnd->Add(text_charset);
122 mainWnd->Add(edit_charset);
123 mainWnd->Add(text_preview);
124 mainWnd->Add(edit_preview);
125 mainWnd->Add(btn_delete);
126 mainWnd->Add(btn_save);
127
128 mainWnd->SetFlags(WF_NOTASKBUTTON | WF_MODAL);
129 mainWnd->SetMinimumSize(Size(Math::Max(374, check_updateJoblist->GetWidth() + 206), 210));
130 mainWnd->SetIcon(ImageLoader::Load(String(Config::Get()->resourcesPath).Append("icons/freac.png")));
131 }
132
133 freac::cddbManageDlg::~cddbManageDlg()
134 {
135 DeleteObject(mainWnd_titlebar);
136 DeleteObject(mainWnd);
137 DeleteObject(divbar);
138 DeleteObject(btn_ok);
139 DeleteObject(btn_cancel);
140
141 DeleteObject(text_entries);
142 DeleteObject(list_entries);
143
144 DeleteObject(text_charset);
145 DeleteObject(edit_charset);
146 DeleteObject(list_charset);
147 DeleteObject(text_preview);
148 DeleteObject(edit_preview);
149
150 DeleteObject(btn_delete);
151 DeleteObject(btn_save);
152
153 DeleteObject(check_updateJoblist);
154 }
155
156 const Error &freac::cddbManageDlg::ShowDialog()
157 {
158 mainWnd->WaitUntilClosed();
159
160 return error;
161 }
162
163 Void freac::cddbManageDlg::OnChangeSize(const Size &nSize)
164 {
165 BoCA::Config *config = BoCA::Config::Get();
166
167 config->SetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBManageCacheSizeXID, mainWnd->GetSize().cx);
168 config->SetIntValue(Config::CategoryDialogsID, Config::DialogsCDDBManageCacheSizeYID, mainWnd->GetSize().cy);
169
170 Rect clientRect = Rect(mainWnd->GetMainLayer()->GetPosition(), mainWnd->GetMainLayer()->GetSize());
171 Size clientSize = Size(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
172
173 text_preview->SetX(clientSize.cx / 2 + 4);
174 edit_preview->SetMetrics(Point(clientSize.cx / 2 + 4, 29), Size((clientSize.cx - 22) / 2 + clientSize.cx % 2, clientSize.cy - 133));
175
176 text_charset->SetPosition(Point(clientSize.cx / 2 + 4, edit_preview->GetHeight() + 40));
177 edit_charset->SetPosition(text_charset->GetPosition() + Point(text_charset->GetUnscaledTextWidth() + 7, -3));
178 edit_charset->SetWidth(edit_preview->GetWidth() - text_charset->GetUnscaledTextWidth() - 7);
179
180 list_entries->SetSize(Size((clientSize.cx - 22) / 2, clientSize.cy - 106));
181
182 btn_delete->SetX(clientSize.cx / 2 - btn_delete->GetWidth() - 4);
183 }
184
185 Void freac::cddbManageDlg::OK()
186 {
187 if (updateJoblist)
188 {
189 const Array<Track> *joblist = BoCA::JobList::Get()->getTrackList.Call();
190
191 for (Int i = 0; i < CDDBCache::Get()->GetNOfEntries(); i++)
192 {
193 const CDDBInfo &cddbInfo = CDDBCache::Get()->GetNthEntry(i);
194
195 for (Int j = 0; j < joblist->Length(); j++)
196 {
197 const Track &trackInfo = joblist->GetNth(j);
198
199 if (trackInfo.discid != cddbInfo.discID) continue;
200
201 for (Int k = 0; k < cddbInfo.trackTitles.Length(); k++)
202 {
203 if (trackInfo.cdTrack != k + 1) continue;
204
205 Track track = joblist->GetNth(j);
206 Info info = track.GetInfo();
207
208 info.artist = cddbInfo.GetTrackArtist(trackInfo.cdTrack);
209 info.title = cddbInfo.trackTitles.GetNth(k);
210 info.album = cddbInfo.dTitle;
211 info.year = cddbInfo.dYear;
212 info.genre = cddbInfo.dGenre;
213 info.comment = cddbInfo.trackComments.GetNth(k);
214
215 track.SetInfo(info);
216
217 BoCA::JobList::Get()->onComponentModifyTrack.Emit(track);
218
219 break;
220 }
221 }
222 }
223 }
224
225 BoCA::Config *config = BoCA::Config::Get();
226
227 config->SetIntValue(Config::CategoryFreedbID, Config::FreedbUpdateJoblistID, updateJoblist);
228
229 mainWnd->Close();
230 }
231
232 Void freac::cddbManageDlg::Cancel()
233 {
234 mainWnd->Close();
235 }
236
237 Void freac::cddbManageDlg::SetCharset()
238 {
239 const CDDBInfo &entry = CDDBCache::Get()->GetNthEntry(list_entries->GetSelectedEntryNumber());
240 String dArtist;
241 String dTitle;
242
243 dArtist.ImportFrom(edit_charset->GetText(), entry.oDArtist);
244 dTitle.ImportFrom(edit_charset->GetText(), entry.oDTitle);
245
246 String preview = String(dArtist).Append(" - ").Append(dTitle).Append("\n\n");
247
248 for (Int i = 0; i < entry.oTrackTitles.Length(); i++)
249 {
250 String artist;
251 String title;
252
253 artist.ImportFrom(edit_charset->GetText(), entry.oTrackArtists.GetNth(i));
254 title.ImportFrom(edit_charset->GetText(), entry.oTrackTitles.GetNth(i));
255
256 preview.Append(i < 9 ? "0" : NIL).Append(String::FromInt(i + 1)).Append(": ").Append(entry.oDArtist == CDDBInfo::VariousArtistsID ? String(artist).Append(" - ") : String()).Append(title).Append("\n");
257 }
258
259 edit_preview->SetText(preview);
260 }
261
262 Void freac::cddbManageDlg::SelectEntry()
263 {
264 const CDDBInfo &entry = CDDBCache::Get()->GetNthEntry(list_entries->GetSelectedEntryNumber());
265 String preview = String(entry.dArtist).Append(" - ").Append(entry.dTitle).Append("\n\n");
266
267 for (Int i = 0; i < entry.trackTitles.Length(); i++)
268 {
269 preview.Append(i < 9 ? "0" : NIL).Append(String::FromInt(i + 1)).Append(": ").Append(entry.dArtist == CDDBInfo::VariousArtistsID ? entry.trackArtists.GetNth(i).Append(" - ") : String()).Append(entry.trackTitles.GetNth(i)).Append(i < entry.trackTitles.Length() - 1 ? "\n" : NIL);
270 }
271
272 edit_preview->SetText(preview);
273 edit_charset->SetText(entry.charset);
274
275 edit_charset->Activate();
276 btn_delete->Activate();
277 btn_save->Activate();
278 }
279
280 Void freac::cddbManageDlg::DeleteEntry()
281 {
282 CDDBCache::Get()->RemoveNthEntry(list_entries->GetSelectedEntryNumber());
283
284 list_entries->Remove(list_entries->GetSelectedEntry());
285
286 edit_preview->SetText(NIL);
287
288 edit_charset->Deactivate();
289 btn_delete->Deactivate();
290 btn_save->Deactivate();
291 }
292
293 Void freac::cddbManageDlg::SaveEntry()
294 {
295 CDDBInfo entry = CDDBCache::Get()->GetNthEntry(list_entries->GetSelectedEntryNumber());
296
297 entry.dArtist.ImportFrom(edit_charset->GetText(), entry.oDArtist);
298 entry.dTitle.ImportFrom(edit_charset->GetText(), entry.oDTitle);
299 entry.dGenre.ImportFrom(edit_charset->GetText(), entry.oDGenre);
300 entry.comment.ImportFrom(edit_charset->GetText(), entry.oComment);
301
302 for (Int i = 0; i < entry.trackArtists.Length(); i++)
303 {
304 String artist;
305 String title;
306 String comment;
307
308 artist.ImportFrom(edit_charset->GetText(), entry.oTrackArtists.GetNth(i));
309 title.ImportFrom(edit_charset->GetText(), entry.oTrackTitles.GetNth(i));
310 comment.ImportFrom(edit_charset->GetText(), entry.oTrackComments.GetNth(i));
311
312 entry.trackArtists.Set(entry.trackArtists.GetNthIndex(i), artist);
313 entry.trackTitles.Set(entry.trackTitles.GetNthIndex(i), title);
314 entry.trackComments.Set(entry.trackComments.GetNthIndex(i), comment);
315 }
316
317 entry.charset = edit_charset->GetText();
318
319 list_entries->GetSelectedEntry()->SetText(String(entry.dArtist).Append(" - ").Append(entry.dTitle).Append(ListEntry::tabDelimiter).Append(entry.charset));
320
321 /* Save modified entry back to cache (necessary to make changes persistant)
322 */
323 CDDBCache::Get()->AddCacheEntry(entry);
324 }