comparison src/gui/pages/anime_list.cc @ 305:91ac90a34003

core/time: remove Duration class, use regular functions instead this class was pretty useless anyway
author Paper <paper@paper.us.eu.org>
date Sun, 19 May 2024 15:56:20 -0400
parents 9a88e1725fd2
children 8769c5d50b06
comparison
equal deleted inserted replaced
304:2115488eb302 305:91ac90a34003
138 case AL_SCORE: return Strings::ToQString(list[index.row()].GetUserPresentableScore()); 138 case AL_SCORE: return Strings::ToQString(list[index.row()].GetUserPresentableScore());
139 case AL_TYPE: return Strings::ToQString(Translate::ToString(list[index.row()].GetFormat())); 139 case AL_TYPE: return Strings::ToQString(Translate::ToString(list[index.row()].GetFormat()));
140 case AL_SEASON: { 140 case AL_SEASON: {
141 std::optional<unsigned int> year = list[index.row()].GetAirDate().GetYear(); 141 std::optional<unsigned int> year = list[index.row()].GetAirDate().GetYear();
142 if (!year) 142 if (!year)
143 return "Unknown Unknown"; 143 return tr("Unknown Unknown");
144 return Strings::ToQString(Translate::ToLocalString(list[index.row()].GetSeason()) + " " + 144 return Strings::ToQString(Translate::ToLocalString(list[index.row()].GetSeason()) + " " +
145 Strings::ToUtf8String(year.value())); 145 Strings::ToUtf8String(year.value()));
146 } 146 }
147 case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%"; 147 case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%";
148 case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate(); 148 case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate();
149 case AL_COMPLETED: return list[index.row()].GetUserDateCompleted().GetAsQDate(); 149 case AL_COMPLETED: return list[index.row()].GetUserDateCompleted().GetAsQDate();
150 case AL_UPDATED: { 150 case AL_UPDATED: {
151 if (list[index.row()].GetUserTimeUpdated() == 0) 151 if (list[index.row()].GetUserTimeUpdated() == 0)
152 return QString("-"); 152 return QString("-");
153 Time::Duration duration(Time::GetSystemTime() - list[index.row()].GetUserTimeUpdated()); 153 return Strings::ToQString(Time::GetSecondsAsRelativeString(Time::GetSystemTime() - list[index.row()].GetUserTimeUpdated()));
154 return Strings::ToQString(duration.AsRelativeString());
155 } 154 }
156 case AL_NOTES: return Strings::ToQString(list[index.row()].GetUserNotes()); 155 case AL_NOTES: return Strings::ToQString(list[index.row()].GetUserNotes());
157 default: return ""; 156 default: return "";
158 } 157 }
159 break; 158 break;
201 200
202 beginResetModel(); 201 beginResetModel();
203 202
204 list.clear(); 203 list.clear();
205 204
206 for (const auto& a : Anime::db.items) { 205 for (const auto& a : Anime::db.items)
207 if (a.second.IsInUserList() && a.second.GetUserStatus() == status) { 206 if (a.second.IsInUserList() && a.second.GetUserStatus() == status)
208 list.push_back(a.second); 207 list.push_back(a.second);
209 }
210 }
211 208
212 endResetModel(); 209 endResetModel();
213 } 210 }
214 211
215 /* ----------------------------------------------------------------- */ 212 /* ----------------------------------------------------------------- */
313 } 310 }
314 311
315 menu->addAction(tr("Information"), [this, animes] { 312 menu->addAction(tr("Information"), [this, animes] {
316 for (auto& anime : animes) { 313 for (auto& anime : animes) {
317 InformationDialog* dialog = new InformationDialog( 314 InformationDialog* dialog = new InformationDialog(
318 *anime, [this, anime] { UpdateAnime(anime->GetId()); }, InformationDialog::PAGE_MAIN_INFO, this); 315 anime, [this](Anime::Anime* anime) { UpdateAnime(anime->GetId()); }, InformationDialog::PAGE_MAIN_INFO, this);
319 316
320 dialog->show(); 317 dialog->show();
321 dialog->raise(); 318 dialog->raise();
322 dialog->activateWindow(); 319 dialog->activateWindow();
323 connect(dialog, &InformationDialog::finished, dialog, &InformationDialog::deleteLater); 320 connect(dialog, &InformationDialog::finished, dialog, &InformationDialog::deleteLater);
325 }); 322 });
326 menu->addSeparator(); 323 menu->addSeparator();
327 menu->addAction(tr("Edit"), [this, animes] { 324 menu->addAction(tr("Edit"), [this, animes] {
328 for (auto& anime : animes) { 325 for (auto& anime : animes) {
329 InformationDialog* dialog = new InformationDialog( 326 InformationDialog* dialog = new InformationDialog(
330 *anime, [this, anime] { UpdateAnime(anime->GetId()); }, InformationDialog::PAGE_MY_LIST, this); 327 anime, [this](Anime::Anime* anime) { UpdateAnime(anime->GetId()); }, InformationDialog::PAGE_MY_LIST, this);
331 328
332 dialog->show(); 329 dialog->show();
333 dialog->raise(); 330 dialog->raise();
334 dialog->activateWindow(); 331 dialog->activateWindow();
335 connect(dialog, &InformationDialog::finished, dialog, &InformationDialog::deleteLater); 332 connect(dialog, &InformationDialog::finished, dialog, &InformationDialog::deleteLater);
356 353
357 const QModelIndex index = source_model->index(selection.indexes().first().row()); 354 const QModelIndex index = source_model->index(selection.indexes().first().row());
358 Anime::Anime* anime = source_model->GetAnimeFromIndex(index); 355 Anime::Anime* anime = source_model->GetAnimeFromIndex(index);
359 356
360 InformationDialog* dialog = new InformationDialog( 357 InformationDialog* dialog = new InformationDialog(
361 *anime, [this, anime] { UpdateAnime(anime->GetId()); }, InformationDialog::PAGE_MAIN_INFO, this); 358 anime, [this](Anime::Anime* anime) { UpdateAnime(anime->GetId()); }, InformationDialog::PAGE_MAIN_INFO, this);
362 359
363 dialog->show(); 360 dialog->show();
364 dialog->raise(); 361 dialog->raise();
365 dialog->activateWindow(); 362 dialog->activateWindow();
366 connect(dialog, &InformationDialog::finished, dialog, &InformationDialog::deleteLater); 363 connect(dialog, &InformationDialog::finished, dialog, &InformationDialog::deleteLater);