Mercurial > minori
changeset 197:c4ca035c565d
*: misc. patches
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 08 Dec 2023 11:19:54 -0500 |
parents | f0ff06a45c42 |
children | bc1ae1810855 |
files | dep/animia/src/win/quartz.cc include/core/date.h src/core/anime_db.cc src/core/date.cc src/gui/pages/anime_list.cc src/gui/widgets/anime_info.cc src/sys/osx/filesystem.cc |
diffstat | 7 files changed, 45 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- a/dep/animia/src/win/quartz.cc Thu Dec 07 16:28:11 2023 -0500 +++ b/dep/animia/src/win/quartz.cc Fri Dec 08 11:19:54 2023 -0500 @@ -61,6 +61,22 @@ return osx::util::StringFromCFString(bundle_id, result); } +template<typename T> +static bool CFDictionaryGetValue(CFDictionaryRef thedict, CFStringRef key, T& out) { + CFTypeRef data = nullptr; + if (!CFDictionaryGetValueIfPresent(thedict, key, reinterpret_cast<const void**>(&data)) || !data) + return false; + + if constexpr (std::is_arithmetic<T>::value) + osx::util::GetCFNumber(reinterpret_cast<CFNumberRef>(data), out); + else if constexpr (std::is_same<T, std::string>::value) + osx::util::StringFromCFString(reinterpret_cast<CFStringRef>(data), out); + else + return false; + + return true; +} + bool QuartzWinTools::EnumerateWindows(window_proc_t window_proc) { if (!window_proc) return false; @@ -77,34 +93,21 @@ Process proc; { - { - CFNumberRef num = nullptr; - if (CFDictionaryGetValueIfPresent(window, CFSTR("kCGWindowOwnerPID"), reinterpret_cast<const void**>(&num)) && num) - osx::util::GetCFNumber(num, proc.pid); - } - { - CFStringRef str = nullptr; - if (CFDictionaryGetValueIfPresent(window, CFSTR("kCGWindowOwnerName"), reinterpret_cast<const void**>(&str)) && str) - osx::util::StringFromCFString(str, proc.name); - } - if (proc.name.empty()) + CFDictionaryGetValue(window, CFSTR("kCGWindowOwnerPID"), proc.pid); + if (!CFDictionaryGetValue(window, CFSTR("kCGWindowOwnerName"), proc.name)) osx::util::GetProcessName(proc.pid, proc.name); } Window win; { - { - CFNumberRef num = nullptr; - if (CFDictionaryGetValueIfPresent(window, CFSTR("kCGWindowNumber"), reinterpret_cast<const void**>(&num)) && num) - osx::util::GetCFNumber(num, win.id); - } + CFDictionaryGetValue(window, CFSTR("kCGWindowNumber"), win.id); + if (!GetProcessBundleIdentifier(proc.pid, win.class_name)) { // Fallback to the Quartz window name, which is unlikely to be filled, but it // *could* be. - CFStringRef str = nullptr; - if (CFDictionaryGetValueIfPresent(window, CFSTR("kCGWindowName"), reinterpret_cast<const void**>(&str)) && str) - osx::util::StringFromCFString(str, win.class_name); + CFDictionaryGetValue(window, CFSTR("kCGWindowName"), win.class_name); } + GetWindowTitle(win.id, win.text); }
--- a/include/core/date.h Thu Dec 07 16:28:11 2023 -0500 +++ b/include/core/date.h Fri Dec 08 11:19:54 2023 -0500 @@ -21,15 +21,11 @@ void VoidYear(); void VoidMonth(); void VoidDay(); - unsigned int GetYear() const; - unsigned int GetMonth() const; - unsigned int GetDay() const; + std::optional<unsigned int> GetYear() const; + std::optional<unsigned int> GetMonth() const; + std::optional<unsigned int> GetDay() const; QDate GetAsQDate() const; nlohmann::json GetAsAniListJson() const; - bool operator<(const Date& other) const; - bool operator>(const Date& other) const; - bool operator<=(const Date& other) const; - bool operator>=(const Date& other) const; private: std::optional<unsigned int> year;
--- a/src/core/anime_db.cc Thu Dec 07 16:28:11 2023 -0500 +++ b/src/core/anime_db.cc Fri Dec 08 11:19:54 2023 -0500 @@ -252,7 +252,7 @@ anime.SetUserProgress(JSON::GetNumber(json, "/progress"_json_pointer, 0)); anime.SetUserScore(JSON::GetNumber(json, "/score"_json_pointer, 0)); anime.SetUserDateStarted(Date(JSON::GetValue(json, "/started"_json_pointer))); - anime.SetUserDateStarted(Date(JSON::GetValue(json, "/completed"_json_pointer))); + anime.SetUserDateCompleted(Date(JSON::GetValue(json, "/completed"_json_pointer))); anime.SetUserIsPrivate(JSON::GetBoolean(json, "/private"_json_pointer, false)); anime.SetUserRewatchedTimes(JSON::GetNumber(json, "/rewatched_times"_json_pointer, 0)); anime.SetUserIsRewatching(JSON::GetBoolean(json, "/rewatching"_json_pointer, false));
--- a/src/core/date.cc Thu Dec 07 16:28:11 2023 -0500 +++ b/src/core/date.cc Fri Dec 08 11:19:54 2023 -0500 @@ -8,11 +8,6 @@ /* An implementation of AniList's "fuzzy date" */ -template<typename T> -bool CLAMP(T x, T low, T high) { - return std::max(low, std::min(high, x)); -} - Date::Date() { } @@ -57,52 +52,33 @@ } void Date::SetYear(unsigned int y) { - year = y; + year.emplace(y); } void Date::SetMonth(unsigned int m) { - month = CLAMP(m, 1U, 12U); + month.emplace(std::clamp(m, 1U, 12U)); } void Date::SetDay(unsigned int d) { - day = CLAMP(d, 1U, 31U); + day.emplace(std::clamp(d, 1U, 31U)); } -unsigned int Date::GetYear() const { - return year.value_or(-1); +std::optional<unsigned int> Date::GetYear() const { + return year; } -unsigned int Date::GetMonth() const { - return month.value_or(-1); +std::optional<unsigned int> Date::GetMonth() const { + return month; } -unsigned int Date::GetDay() const { - return day.value_or(-1); +std::optional<unsigned int> Date::GetDay() const { + return day; } bool Date::IsValid() const { return year.has_value() && month.has_value() && day.has_value(); } -bool Date::operator<(const Date& other) const { - const unsigned int y = GetYear(), m = GetMonth(), d = GetDay(); - const unsigned int o_y = other.GetYear(), o_m = other.GetMonth(), o_d = other.GetDay(); - - return (y < o_y && m < o_m && d < o_d); -} - -bool Date::operator>(const Date& other) const { - return other < (*this); -} - -bool Date::operator<=(const Date& other) const { - return !((*this) > other); -} - -bool Date::operator>=(const Date& other) const { - return !((*this) < other); -} - QDate Date::GetAsQDate() const { /* QDate doesn't support "missing" values (for good reason), * so we do our best and return what we can.
--- a/src/gui/pages/anime_list.cc Thu Dec 07 16:28:11 2023 -0500 +++ b/src/gui/pages/anime_list.cc Fri Dec 08 11:19:54 2023 -0500 @@ -115,9 +115,11 @@ case AL_EPISODES: return list[index.row()].GetEpisodes(); case AL_SCORE: return Strings::ToQString(list[index.row()].GetUserPresentableScore()); case AL_TYPE: return Strings::ToQString(Translate::ToString(list[index.row()].GetFormat())); - case AL_SEASON: - return Strings::ToQString(Translate::ToString(list[index.row()].GetSeason())) + " " + - QString::number(list[index.row()].GetAirDate().GetYear()); + case AL_SEASON: { + const std::optional<unsigned int> year = list[index.row()].GetAirDate().GetYear(); + if (year.has_value()) + return Strings::ToQString(Translate::ToString(list[index.row()].GetSeason()) + " " + std::to_string(year.value())); + } case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%"; case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate(); case AL_COMPLETED: return list[index.row()].GetUserDateCompleted().GetAsQDate();
--- a/src/gui/widgets/anime_info.cc Thu Dec 07 16:28:11 2023 -0500 +++ b/src/gui/widgets/anime_info.cc Fri Dec 08 11:19:54 2023 -0500 @@ -35,11 +35,11 @@ * QString because QTextStream sucks and assumes * Latin1 (on Windows?) */ - details_data_s << Strings::ToQString(Translate::ToString(anime.GetFormat())) << "\n" + details_data_s << Strings::ToQString(Translate::ToLocalString(anime.GetFormat())) << "\n" << anime.GetEpisodes() << "\n" - << Strings::ToQString(Translate::ToString(anime.GetUserStatus())) << "\n" - << Strings::ToQString(Translate::ToString(anime.GetSeason())) << " " - << anime.GetAirDate().GetYear() << "\n" + << Strings::ToQString(Translate::ToLocalString(anime.GetUserStatus())) << "\n" + << Strings::ToQString(Translate::ToLocalString(anime.GetSeason())) << " " + << anime.GetAirDate().GetYear().value_or(2000) << "\n" << Strings::ToQString(Strings::Implode(anime.GetGenres(), ", ")) << "\n" << anime.GetAudienceScore() << "%"; _details->GetParagraph()->SetText(details_data);
--- a/src/sys/osx/filesystem.cc Thu Dec 07 16:28:11 2023 -0500 +++ b/src/sys/osx/filesystem.cc Fri Dec 08 11:19:54 2023 -0500 @@ -19,7 +19,7 @@ bool GetApplicationSupportDirectory(std::string& result) { // NSArray* strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, ON); - const CFArrayRef strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, ON); + const CFArrayRef strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true); if (!strings) return false;