Qt: show time of day in 'last played' game info, log current time when RPCS3 boots (#11220)

This commit is contained in:
Eladash 2022-02-24 00:40:18 +02:00 committed by GitHub
parent f3823232e0
commit 86a04a867b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 15 deletions

View file

@ -2,6 +2,9 @@
// by Sacha Refshauge, Megamouse and flash-fire // by Sacha Refshauge, Megamouse and flash-fire
#include <iostream> #include <iostream>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
@ -362,6 +365,16 @@ void log_q_debug(QtMsgType type, const QMessageLogContext& context, const QStrin
} }
} }
template <>
void fmt_class_string<std::chrono::sys_time<typename std::chrono::system_clock::duration>>::format(std::string& out, u64 arg)
{
std::ostringstream ss;
const std::time_t dateTime = std::chrono::system_clock::to_time_t(get_object(arg));
const std::tm tm = *std::localtime(&dateTime);
ss << std::put_time(&tm, "%Y-%m-%eT%H:%M:%S");
out += ss.str();
}
int main(int argc, char** argv) int main(int argc, char** argv)
@ -474,7 +487,10 @@ int main(int argc, char** argv)
logs::stored_message qt{(strcmp(QT_VERSION_STR, qVersion()) != 0) ? sys_log.error : sys_log.notice}; logs::stored_message qt{(strcmp(QT_VERSION_STR, qVersion()) != 0) ? sys_log.error : sys_log.notice};
qt.text = fmt::format("Qt version: Compiled against Qt %s | Run-time uses Qt %s", QT_VERSION_STR, qVersion()); qt.text = fmt::format("Qt version: Compiled against Qt %s | Run-time uses Qt %s", QT_VERSION_STR, qVersion());
logs::set_init({std::move(ver), std::move(sys), std::move(os), std::move(qt)}); logs::stored_message time{sys_log.always()};
time.text = fmt::format("Current Time: %s", std::chrono::system_clock::now());
logs::set_init({std::move(ver), std::move(sys), std::move(os), std::move(qt), std::move(time)});
} }
#ifdef _WIN32 #ifdef _WIN32

View file

@ -2401,16 +2401,16 @@ void game_list_frame::PopulateGameList()
const quint64 elapsed_ms = m_persistent_settings->GetPlaytime(serial); const quint64 elapsed_ms = m_persistent_settings->GetPlaytime(serial);
// Last played (support outdated values) // Last played (support outdated values)
QDate last_played; QDateTime last_played;
const QString last_played_str = GetLastPlayedBySerial(serial); const QString last_played_str = GetLastPlayedBySerial(serial);
if (!last_played_str.isEmpty()) if (!last_played_str.isEmpty())
{ {
last_played = QDate::fromString(last_played_str, gui::persistent::last_played_date_format); last_played = QDateTime::fromString(last_played_str, gui::persistent::last_played_date_format);
if (!last_played.isValid()) if (!last_played.isValid())
{ {
last_played = QDate::fromString(last_played_str, gui::persistent::last_played_date_format_old); last_played = QDateTime::fromString(last_played_str, gui::persistent::last_played_date_format_old);
} }
} }
@ -2425,7 +2425,7 @@ void game_list_frame::PopulateGameList()
m_game_list->setItem(row, gui::column_resolution, new custom_table_widget_item(GetStringFromU32(game->info.resolution, localized.resolution.mode, true))); m_game_list->setItem(row, gui::column_resolution, new custom_table_widget_item(GetStringFromU32(game->info.resolution, localized.resolution.mode, true)));
m_game_list->setItem(row, gui::column_sound, new custom_table_widget_item(GetStringFromU32(game->info.sound_format, localized.sound.format, true))); m_game_list->setItem(row, gui::column_sound, new custom_table_widget_item(GetStringFromU32(game->info.sound_format, localized.sound.format, true)));
m_game_list->setItem(row, gui::column_parental, new custom_table_widget_item(GetStringFromU32(game->info.parental_lvl, localized.parental.level), Qt::UserRole, game->info.parental_lvl)); m_game_list->setItem(row, gui::column_parental, new custom_table_widget_item(GetStringFromU32(game->info.parental_lvl, localized.parental.level), Qt::UserRole, game->info.parental_lvl));
m_game_list->setItem(row, gui::column_last_play, new custom_table_widget_item(locale.toString(last_played, gui::persistent::last_played_date_format_new), Qt::UserRole, last_played)); m_game_list->setItem(row, gui::column_last_play, new custom_table_widget_item(locale.toString(last_played, last_played >= QDateTime::currentDateTime().addDays(-7) ? gui::persistent::last_played_date_with_time_of_day_format : gui::persistent::last_played_date_format_new), Qt::UserRole, last_played));
m_game_list->setItem(row, gui::column_playtime, new custom_table_widget_item(elapsed_ms == 0 ? tr("Never played") : localized.GetVerboseTimeByMs(elapsed_ms), Qt::UserRole, elapsed_ms)); m_game_list->setItem(row, gui::column_playtime, new custom_table_widget_item(elapsed_ms == 0 ? tr("Never played") : localized.GetVerboseTimeByMs(elapsed_ms), Qt::UserRole, elapsed_ms));
m_game_list->setItem(row, gui::column_compat, compat_item); m_game_list->setItem(row, gui::column_compat, compat_item);

View file

@ -449,7 +449,7 @@ void gui_application::StartPlaytime(bool start_playtime = true)
return; return;
} }
m_persistent_settings->SetLastPlayed(serial, QDate::currentDate().toString(gui::persistent::last_played_date_format)); m_persistent_settings->SetLastPlayed(serial, QDateTime::currentDateTime().toString(gui::persistent::last_played_date_format));
m_timer_playtime.start(); m_timer_playtime.start();
m_timer.start(10000); // Update every 10 seconds in case the emulation crashes m_timer.start(10000); // Update every 10 seconds in case the emulation crashes
} }
@ -471,7 +471,7 @@ void gui_application::UpdatePlaytime()
} }
m_persistent_settings->AddPlaytime(serial, m_timer_playtime.restart()); m_persistent_settings->AddPlaytime(serial, m_timer_playtime.restart());
m_persistent_settings->SetLastPlayed(serial, QDate::currentDate().toString(gui::persistent::last_played_date_format)); m_persistent_settings->SetLastPlayed(serial, QDateTime::currentDateTime().toString(gui::persistent::last_played_date_format));
} }
void gui_application::StopPlaytime() void gui_application::StopPlaytime()
@ -489,7 +489,7 @@ void gui_application::StopPlaytime()
} }
m_persistent_settings->AddPlaytime(serial, m_timer_playtime.restart()); m_persistent_settings->AddPlaytime(serial, m_timer_playtime.restart());
m_persistent_settings->SetLastPlayed(serial, QDate::currentDate().toString(gui::persistent::last_played_date_format)); m_persistent_settings->SetLastPlayed(serial, QDateTime::currentDateTime().toString(gui::persistent::last_played_date_format));
m_timer_playtime.invalidate(); m_timer_playtime.invalidate();
} }

View file

@ -18,6 +18,7 @@ namespace gui
// Date format // Date format
const QString last_played_date_format_old = "MMMM d yyyy"; const QString last_played_date_format_old = "MMMM d yyyy";
const QString last_played_date_format_new = "MMMM d, yyyy"; const QString last_played_date_format_new = "MMMM d, yyyy";
const QString last_played_date_with_time_of_day_format = "MMMM d, yyyy HH:mm";
const Qt::DateFormat last_played_date_format = Qt::DateFormat::ISODate; const Qt::DateFormat last_played_date_format = Qt::DateFormat::ISODate;
// GUI Saves // GUI Saves