Skip to content

Commit

Permalink
Qt: show time of day in 'last played' game info, log current time whe…
Browse files Browse the repository at this point in the history
…n RPCS3 boots
  • Loading branch information
elad335 committed Dec 2, 2021
1 parent 0ab36ef commit ebe91eb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
15 changes: 14 additions & 1 deletion rpcs3/main.cpp
Expand Up @@ -2,6 +2,8 @@
// by Sacha Refshauge, Megamouse and flash-fire

#include <iostream>
#include <chrono>
#include <sstream>

#include <QApplication>
#include <QCommandLineParser>
Expand Down Expand Up @@ -359,6 +361,14 @@ 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;
ss << get_object(arg);
out += ss.str();
}



int main(int argc, char** argv)
Expand Down Expand Up @@ -471,7 +481,10 @@ int main(int argc, char** argv)
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());

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
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/rpcs3qt/game_list_frame.cpp
Expand Up @@ -2370,16 +2370,16 @@ void game_list_frame::PopulateGameList()
const quint64 elapsed_ms = m_persistent_settings->GetPlaytime(serial);

// Last played (support outdated values)
QDate last_played;
QDateTime last_played;
const QString last_played_str = GetLastPlayedBySerial(serial);

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())
{
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);
}
}

Expand All @@ -2394,7 +2394,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_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_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_compat, compat_item);

Expand Down
6 changes: 3 additions & 3 deletions rpcs3/rpcs3qt/gui_application.cpp
Expand Up @@ -435,7 +435,7 @@ void gui_application::StartPlaytime(bool start_playtime = true)
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.start(10000); // Update every 10 seconds in case the emulation crashes
}
Expand All @@ -457,7 +457,7 @@ void gui_application::UpdatePlaytime()
}

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()
Expand All @@ -475,7 +475,7 @@ void gui_application::StopPlaytime()
}

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();
}

Expand Down
7 changes: 4 additions & 3 deletions rpcs3/rpcs3qt/persistent_settings.h
Expand Up @@ -16,9 +16,10 @@ namespace gui
const QString titles = "Titles";

// Date format
const QString last_played_date_format_old = "MMMM d yyyy";
const QString last_played_date_format_new = "MMMM d, yyyy";
const Qt::DateFormat last_played_date_format = Qt::DateFormat::ISODate;
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_with_time_of_day_format = "MMMM d, yyyy HH:mm";
const Qt::DateFormat last_played_date_format = Qt::DateFormat::ISODate;

// GUI Saves
const gui_save save_notes = gui_save(savedata, "notes", QVariantMap());
Expand Down

0 comments on commit ebe91eb

Please sign in to comment.