Mercurial > minori
changeset 65:26721c28bf22
*: avoid usage of (to|from)StdString
in Qt5 (and probably Qt6 as well) these functions are only
available (or even usable) if Qt and Minori were built with the
*same standard headers*, which may not be the case in some
circumstances. hence, we'll use our own conversion functions,
which we probably should use anyway.
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 23:26:35 -0400 |
parents | fe719c109dbc |
children | 6481c5aed3e1 |
files | src/gui/dialog/information.cpp src/gui/dialog/settings/services.cpp src/gui/pages/anime_list.cpp src/gui/translate/anime.cpp src/services/anilist.cpp |
diffstat | 5 files changed, 39 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gui/dialog/information.cpp Sun Oct 01 23:15:43 2023 -0400 +++ b/src/gui/dialog/information.cpp Sun Oct 01 23:26:35 2023 -0400 @@ -67,7 +67,7 @@ id = anime.GetId(); /* anime title header text */ TextWidgets::Title* anime_title = - new TextWidgets::Title(QString::fromStdString(anime.GetUserPreferredTitle()), main_widget); + new TextWidgets::Title(Strings::ToQString(anime.GetUserPreferredTitle()), main_widget); /* tabbed widget */ QTabWidget* tabbed_widget = new QTabWidget(main_widget); @@ -150,7 +150,7 @@ QStringList string_list; for (unsigned int i = 0; i < ARRAYSIZE(Anime::ListStatuses); i++) - string_list.append(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i]))); + string_list.append(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i]))); QComboBox* combo_box = new QComboBox(subsection); combo_box->addItems(string_list); @@ -178,9 +178,9 @@ QLineEdit* line_edit = new QLineEdit(subsection); connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { /* this sucks but I don't really want to implement anything smarter :) */ - notes = text.toStdString(); + notes = Strings::ToUtf8String(text); }); - line_edit->setText(QString::fromStdString(notes = anime.GetUserNotes())); + line_edit->setText(Strings::ToQString(notes = anime.GetUserNotes())); line_edit->setPlaceholderText(tr("Enter your notes about this anime")); subsection->layout()->addWidget(line_edit); }); @@ -230,7 +230,7 @@ CREATE_FULL_WIDTH_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr("Alternative titles:"), subsection)); - QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); + QLineEdit* line_edit = new QLineEdit(Strings::ToQString(anime.GetUserNotes()), subsection); line_edit->setPlaceholderText( tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); subsection->layout()->addWidget(line_edit);
--- a/src/gui/dialog/settings/services.cpp Sun Oct 01 23:15:43 2023 -0400 +++ b/src/gui/dialog/settings/services.cpp Sun Oct 01 23:26:35 2023 -0400 @@ -1,5 +1,6 @@ #include "core/anime.h" #include "core/session.h" +#include "core/strings.h" #include "gui/dialog/settings.h" #include "services/anilist.h" #include <QComboBox> @@ -84,7 +85,7 @@ } void SettingsPageServices::SaveInfo() { - session.config.anilist.username = username.toStdString(); + session.config.anilist.username = Strings::ToUtf8String(username); session.config.service = service; }
--- a/src/gui/pages/anime_list.cpp Sun Oct 01 23:15:43 2023 -0400 +++ b/src/gui/pages/anime_list.cpp Sun Oct 01 23:26:35 2023 -0400 @@ -14,6 +14,7 @@ #include "core/array.h" #include "core/session.h" #include "core/time.h" +#include "core/strings.h" #include "gui/dialog/information.h" #include "gui/translate/anime.h" #include "services/services.h" @@ -143,9 +144,9 @@ QString::number(list[index.row()].GetEpisodes()); case AL_EPISODES: return list[index.row()].GetEpisodes(); case AL_SCORE: return list[index.row()].GetUserScore(); - case AL_TYPE: return QString::fromStdString(Translate::ToString(list[index.row()].GetFormat())); + case AL_TYPE: return Strings::ToQString(Translate::ToString(list[index.row()].GetFormat())); case AL_SEASON: - return QString::fromStdString(Translate::ToString(list[index.row()].GetSeason())) + " " + + return Strings::ToQString(Translate::ToString(list[index.row()].GetSeason())) + " " + QString::number(list[index.row()].GetAirDate().GetYear()); case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%"; case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate(); @@ -441,7 +442,7 @@ tree_view->setFrameShape(QFrame::NoFrame); for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) { - tab_bar->addTab(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + + tab_bar->addTab(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" + QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); sort_models[i] = new AnimeListPageSortFilter(tree_view); sort_models[i]->setSourceModel(new AnimeListPageModel(this, Anime::ListStatuses[i])); @@ -486,7 +487,7 @@ void AnimeListPage::RefreshTabs() { for (unsigned int i = 0; i < ARRAYSIZE(sort_models); i++) - tab_bar->setTabText(i, QString::fromStdString(Translate::ToString(Anime::ListStatuses[i])) + " (" + + tab_bar->setTabText(i, Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" + QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")"); }
--- a/src/gui/translate/anime.cpp Sun Oct 01 23:15:43 2023 -0400 +++ b/src/gui/translate/anime.cpp Sun Oct 01 23:26:35 2023 -0400 @@ -1,4 +1,5 @@ #include "core/anime.h" +#include "core/strings.h" #include "gui/translate/anime.h" #include <QCoreApplication> @@ -6,49 +7,49 @@ std::string ToString(const Anime::ListStatus status) { switch (status) { - case Anime::ListStatus::NOT_IN_LIST: return QCoreApplication::tr("Not in list").toStdString(); - case Anime::ListStatus::CURRENT: return QCoreApplication::tr("Currently watching").toStdString(); - case Anime::ListStatus::PLANNING: return QCoreApplication::tr("Plan to watch").toStdString(); - case Anime::ListStatus::COMPLETED: return QCoreApplication::tr("Completed").toStdString(); - case Anime::ListStatus::DROPPED: return QCoreApplication::tr("Dropped").toStdString(); - case Anime::ListStatus::PAUSED: return QCoreApplication::tr("On hold").toStdString(); + case Anime::ListStatus::NOT_IN_LIST: return Strings::ToUtf8String(QCoreApplication::tr("Not in list")); + case Anime::ListStatus::CURRENT: return Strings::ToUtf8String(QCoreApplication::tr("Currently watching")); + case Anime::ListStatus::PLANNING: return Strings::ToUtf8String(QCoreApplication::tr("Plan to watch")); + case Anime::ListStatus::COMPLETED: return Strings::ToUtf8String(QCoreApplication::tr("Completed")); + case Anime::ListStatus::DROPPED: return Strings::ToUtf8String(QCoreApplication::tr("Dropped")); + case Anime::ListStatus::PAUSED: return Strings::ToUtf8String(QCoreApplication::tr("On hold")); default: return ""; } } std::string ToString(const Anime::SeriesFormat format) { switch (format) { - case Anime::SeriesFormat::UNKNOWN: return QCoreApplication::tr("Unknown").toStdString(); - case Anime::SeriesFormat::TV: return QCoreApplication::tr("TV").toStdString(); - case Anime::SeriesFormat::TV_SHORT: return QCoreApplication::tr("TV short").toStdString(); - case Anime::SeriesFormat::OVA: return QCoreApplication::tr("OVA").toStdString(); - case Anime::SeriesFormat::MOVIE: return QCoreApplication::tr("Movie").toStdString(); - case Anime::SeriesFormat::SPECIAL: return QCoreApplication::tr("Special").toStdString(); - case Anime::SeriesFormat::ONA: return QCoreApplication::tr("ONA").toStdString(); - case Anime::SeriesFormat::MUSIC: return QCoreApplication::tr("Music").toStdString(); + case Anime::SeriesFormat::UNKNOWN: return Strings::ToUtf8String(QCoreApplication::tr("Unknown")); + case Anime::SeriesFormat::TV: return Strings::ToUtf8String(QCoreApplication::tr("TV")); + case Anime::SeriesFormat::TV_SHORT: return Strings::ToUtf8String(QCoreApplication::tr("TV short")); + case Anime::SeriesFormat::OVA: return Strings::ToUtf8String(QCoreApplication::tr("OVA")); + case Anime::SeriesFormat::MOVIE: return Strings::ToUtf8String(QCoreApplication::tr("Movie")); + case Anime::SeriesFormat::SPECIAL: return Strings::ToUtf8String(QCoreApplication::tr("Special")); + case Anime::SeriesFormat::ONA: return Strings::ToUtf8String(QCoreApplication::tr("ONA")); + case Anime::SeriesFormat::MUSIC: return Strings::ToUtf8String(QCoreApplication::tr("Music")); default: return ""; } } std::string ToString(const Anime::SeriesSeason season) { switch (season) { - case Anime::SeriesSeason::UNKNOWN: return QCoreApplication::tr("Unknown").toStdString(); - case Anime::SeriesSeason::WINTER: return QCoreApplication::tr("Winter").toStdString(); - case Anime::SeriesSeason::SUMMER: return QCoreApplication::tr("Summer").toStdString(); - case Anime::SeriesSeason::FALL: return QCoreApplication::tr("Fall").toStdString(); - case Anime::SeriesSeason::SPRING: return QCoreApplication::tr("Spring").toStdString(); + case Anime::SeriesSeason::UNKNOWN: return Strings::ToUtf8String(QCoreApplication::tr("Unknown")); + case Anime::SeriesSeason::WINTER: return Strings::ToUtf8String(QCoreApplication::tr("Winter")); + case Anime::SeriesSeason::SUMMER: return Strings::ToUtf8String(QCoreApplication::tr("Summer")); + case Anime::SeriesSeason::FALL: return Strings::ToUtf8String(QCoreApplication::tr("Fall")); + case Anime::SeriesSeason::SPRING: return Strings::ToUtf8String(QCoreApplication::tr("Spring")); default: return ""; } } std::string ToString(const Anime::SeriesStatus status) { switch (status) { - case Anime::SeriesStatus::UNKNOWN: return QCoreApplication::tr("Unknown").toStdString(); - case Anime::SeriesStatus::RELEASING: return QCoreApplication::tr("Currently airing").toStdString(); - case Anime::SeriesStatus::FINISHED: return QCoreApplication::tr("Finished airing").toStdString(); - case Anime::SeriesStatus::NOT_YET_RELEASED: return QCoreApplication::tr("Not yet aired").toStdString(); - case Anime::SeriesStatus::CANCELLED: return QCoreApplication::tr("Cancelled").toStdString(); - case Anime::SeriesStatus::HIATUS: return QCoreApplication::tr("On hiatus").toStdString(); + case Anime::SeriesStatus::UNKNOWN: return Strings::ToUtf8String(QCoreApplication::tr("Unknown")); + case Anime::SeriesStatus::RELEASING: return Strings::ToUtf8String(QCoreApplication::tr("Currently airing")); + case Anime::SeriesStatus::FINISHED: return Strings::ToUtf8String(QCoreApplication::tr("Finished airing")); + case Anime::SeriesStatus::NOT_YET_RELEASED: return Strings::ToUtf8String(QCoreApplication::tr("Not yet aired")); + case Anime::SeriesStatus::CANCELLED: return Strings::ToUtf8String(QCoreApplication::tr("Cancelled")); + case Anime::SeriesStatus::HIATUS: return Strings::ToUtf8String(QCoreApplication::tr("On hiatus")); default: return ""; } }
--- a/src/services/anilist.cpp Sun Oct 01 23:15:43 2023 -0400 +++ b/src/services/anilist.cpp Sun Oct 01 23:26:35 2023 -0400 @@ -322,7 +322,7 @@ 0, "Credentials needed!", "Please enter the code given to you after logging in to AniList:", QLineEdit::Normal, "", &ok); if (ok && !token.isEmpty()) - account.SetAuthToken(token.toStdString()); + account.SetAuthToken(Strings::ToUtf8String(token)); else // fail return false; const std::string query = "query {\n"