Skip to content

Commit

Permalink
Merge pull request #1419 from Zer0xFF/upstream_qt_addons
Browse files Browse the repository at this point in the history
Qt & build system improvements
  • Loading branch information
jpd002 authored Oct 25, 2024
2 parents 7fdf2f4 + c618861 commit 32d6e06
Show file tree
Hide file tree
Showing 25 changed files with 468 additions and 132 deletions.
76 changes: 76 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"version": 4,
"configurePresets": [
{
"name": "VS",
"displayName": "Visual Studio 17 2022",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/build_cmake/build/${presetName}",
"hidden": true
},
{
"name": "NINJA",
"displayName": "Ninja",
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/build_cmake/build/${presetName}",
"hidden": true
},
{
"name": "DEBUGGER",
"cacheVariables": {
"DEBUGGER_INCLUDED": {
"type": "BOOL",
"value": "ON"
}
},
"hidden": true
},
{
"name": "WIN32",
"architecture": {
"value": "x64",
"strategy": "set"
},
"cacheVariables": {
"USE_QT": {
"type": "BOOL",
"value": "ON"
}
},
"hidden": true
},
{
"name": "win32-vs",
"inherits": [
"WIN32",
"VS"
]
},
{
"name": "win32-vs-debugger",
"inherits": [
"WIN32",
"VS",
"DEBUGGER"
]
}
],
"buildPresets": [
{
"name": "win32-vs",
"configurePreset": "win32-vs",
"configuration": "RelWithDebInfo",
"targets": [
"Play",
"CodeGenTestSuite"
]
},
{
"name": "win32-vs-debugger",
"configurePreset": "win32-vs-debugger",
"targets": [
"Play"
]
}
]
}
3 changes: 2 additions & 1 deletion Source/ui_android/BootablesInterop.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../ui_shared/BootablesProcesses.h"
#include "../ui_shared/BootablesDbClient.h"
#include "ui_shared/BootableUtils.h"
#include "com_virtualapplications_play_Bootable.h"
#include "NativeShared.h"

Expand Down Expand Up @@ -108,7 +109,7 @@ extern "C" JNIEXPORT void Java_com_virtualapplications_play_BootablesInterop_set
extern "C" JNIEXPORT jboolean Java_com_virtualapplications_play_BootablesInterop_IsBootableExecutablePath(JNIEnv* env, jclass clazz, jstring bootablePathString)
{
auto bootablePath = fs::path(GetStringFromJstring(env, bootablePathString));
return IsBootableExecutablePath(bootablePath);
return BootableUtils::IsBootableExecutablePath(bootablePath);
}

extern "C" JNIEXPORT jboolean Java_com_virtualapplications_play_BootablesInterop_DoesBootableExist(JNIEnv* env, jclass clazz, jstring bootablePathString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class BootablesInterop
}

public static final int SORT_RECENT = 0;
public static final int SORT_HOMEBREW = 1;
public static final int SORT_NONE = 2;
public static final int SORT_NONE = 1;
public static final int SORT_HOMEBREW = 2;

public static native void scanBootables(String[] rootDirectories);
public static native void fullScanBootables(String[] rootDirectories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void Startup()
gameInfo = new GameInfo(MainActivity.this);

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
sortMethod = sp.getInt("sortMethod", SORT_NONE);
sortMethod = sp.getInt("sortMethod.v2", SORT_NONE);
onNavigationDrawerItemSelected(sortMethod);
sp.registerOnSharedPreferenceChangeListener(this);

Expand Down Expand Up @@ -339,7 +339,7 @@ public void onNavigationDrawerItemSelected(int position)
prepareFileListView(false);

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
sp.edit().putInt("sortMethod", sortMethod).apply();
sp.edit().putInt("sortMethod.v2", sortMethod).apply();
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions Source/ui_ios/EmulatorViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifdef HAS_GSH_VULKAN
#include "GSH_VulkaniOS.h"
#endif
#include "../ui_shared/BootablesProcesses.h"
#include "../ui_shared/BootableUtils.h"
#include "PH_Generic.h"
#include "../../tools/PsfPlayer/Source/SH_OpenAL.h"
#include "../ui_shared/StatsManager.h"
Expand Down Expand Up @@ -127,7 +127,7 @@ - (void)viewDidAppear:(BOOL)animated
g_virtualMachine->Reset();

auto bootablePath = fs::path([self.bootablePath fileSystemRepresentation]);
if(IsBootableExecutablePath(bootablePath))
if(BootableUtils::IsBootableExecutablePath(bootablePath))
{
g_virtualMachine->m_ee->m_os->BootFromFile(bootablePath);
}
Expand Down
8 changes: 8 additions & 0 deletions Source/ui_libretro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ project(Play_Libretro_Core)

add_definitions(-DPLAY_VERSION="${PROJECT_Version}")

if(NOT TARGET ui_shared)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/../ui_shared
${CMAKE_CURRENT_BINARY_DIR}/ui_shared
)
endif()
list(APPEND PROJECT_LIBS ui_shared)

if(NOT TARGET PlayCore)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/../
Expand Down
22 changes: 3 additions & 19 deletions Source/ui_libretro/main_libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Log.h"
#include "AppConfig.h"
#include "PS2VM.h"
#include "DiskUtils.h"
#include "ui_shared/BootableUtils.h"

#include "PS2VM_Preferences.h"
#include "GSH_OpenGL_Libretro.h"
Expand Down Expand Up @@ -473,22 +473,6 @@ void retro_reset(void)
first_run = false;
}

bool IsBootableExecutablePath(const fs::path& filePath)
{
auto extension = filePath.extension().string();
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
return (extension == ".elf");
}

bool IsBootableDiscImagePath(const fs::path& filePath)
{
const auto& supportedExtensions = DiskUtils::GetSupportedExtensions();
auto extension = filePath.extension().string();
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
auto extensionIterator = supportedExtensions.find(extension);
return extensionIterator != std::end(supportedExtensions);
}

bool retro_load_game(const retro_game_info* info)
{
CLog::GetInstance().Print(LOG_NAME, "%s\n", __FUNCTION__);
Expand All @@ -507,11 +491,11 @@ bool retro_load_game(const retro_game_info* info)
#endif

fs::path filePath = info->path;
if(IsBootableExecutablePath(filePath))
if(BootableUtils::IsBootableExecutablePath(filePath))
{
m_bootCommand = LastOpenCommand(BootType::ELF, filePath);
}
else if(IsBootableDiscImagePath(filePath))
else if(BootableUtils::IsBootableDiscImagePath(filePath))
{
m_bootCommand = LastOpenCommand(BootType::CD, filePath);
CAppConfig::GetInstance().SetPreferencePath(PREF_PS2_CDROM0_PATH, filePath);
Expand Down
10 changes: 8 additions & 2 deletions Source/ui_qt/BootableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ QVariant BootableModel::data(const QModelIndex& index, int role) const
{
int pos = index.row() + index.column();
auto bootable = m_bootables.at(static_cast<unsigned int>(pos));
return QVariant::fromValue(BootableCoverQVariant(bootable.discId, bootable.title, bootable.path, bootable.states));
return QVariant::fromValue(BootableCoverQVariant(bootable.discId, bootable.title, bootable.path, bootable.states, bootable.bootableType));
}
return QVariant();
}
Expand Down Expand Up @@ -69,11 +69,12 @@ void BootableModel::SetWidth(int width)
}

/* start of BootImageItemDelegate */
BootableCoverQVariant::BootableCoverQVariant(std::string key, std::string title, fs::path path, BootablesDb::BootableStateList states)
BootableCoverQVariant::BootableCoverQVariant(std::string key, std::string title, fs::path path, BootablesDb::BootableStateList states, BootableUtils::BOOTABLE_TYPE bootableType)
: m_key(key)
, m_title(title)
, m_path(path)
, m_states(states)
, m_bootableType(bootableType)
{
for(auto state : states)
{
Expand Down Expand Up @@ -171,6 +172,11 @@ fs::path BootableCoverQVariant::GetPath() const
return m_path;
}

int BootableCoverQVariant::GetBootableType() const
{
return m_bootableType;
}

bool BootableCoverQVariant::HasState(std::string state)
{
auto itr = std::find_if(std::begin(m_states), std::end(m_states), [state](BootablesDb::BootableState bootState) {
Expand Down
5 changes: 4 additions & 1 deletion Source/ui_qt/BootableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QAbstractTableModel>
#include <QStyledItemDelegate>
#include "ui_shared/BootablesDbClient.h"
#include "ui_shared/BootableUtils.h"

class BootableModel : public QAbstractTableModel
{
Expand All @@ -31,7 +32,7 @@ class BootableCoverQVariant
{

public:
explicit BootableCoverQVariant(std::string = "PH", std::string = "", fs::path = "", BootablesDb::BootableStateList = {});
explicit BootableCoverQVariant(std::string = "PH", std::string = "", fs::path = "", BootablesDb::BootableStateList = {}, BootableUtils::BOOTABLE_TYPE = BootableUtils::UNKNOWN);
~BootableCoverQVariant() = default;

void paint(QPainter* painter, const QRect& rect, const QPalette& palette, int mode) const;
Expand All @@ -41,6 +42,7 @@ class BootableCoverQVariant
std::string GetTitle() const;
fs::path GetPath() const;
bool HasState(std::string);
int GetBootableType() const;

private:
int GetPadding() const;
Expand All @@ -49,6 +51,7 @@ class BootableCoverQVariant
fs::path m_path;
std::string m_statusColor;
BootablesDb::BootableStateList m_states;
BootableUtils::BOOTABLE_TYPE m_bootableType;
};

Q_DECLARE_METATYPE(BootableCoverQVariant)
Expand Down
21 changes: 21 additions & 0 deletions Source/ui_qt/BootableModelProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ void BootableModelProxy::setFilterState(const QString& state)
invalidateFilter();
}

void BootableModelProxy::setBootableTypeFilterState(int bitIndex, bool value)
{
if(value)
m_bootableType |= bitIndex;
else
m_bootableType &= ~bitIndex;

invalidateFilter();
}

int BootableModelProxy::getBootableTypeFilterState()
{
return m_bootableType;
}

bool BootableModelProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
Expand All @@ -32,6 +47,7 @@ bool BootableModelProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sour
QString key = QString::fromStdString(bootablecover.GetKey());
QString title = QString::fromStdString(bootablecover.GetTitle());
QString path = PathToQString(bootablecover.GetPath());
auto bootableType = bootablecover.GetBootableType();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QRegularExpression regex = filterRegularExpression();
regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
Expand All @@ -47,6 +63,11 @@ bool BootableModelProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sour
{
res &= bootablecover.HasState(m_state);
}

if(m_bootableType != 0)
{
res &= (bootableType & m_bootableType) != 0;
}
return res;
}
return false;
Expand Down
5 changes: 4 additions & 1 deletion Source/ui_qt/BootableModelProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ class BootableModelProxy : public QSortFilterProxyModel
BootableModelProxy(QObject* parent);

void setFilterState(const QString&);
void setBootableTypeFilterState(int, bool);
int getBootableTypeFilterState();

protected:
bool filterAcceptsRow(int, const QModelIndex&) const override;

private:
std::string m_state;
std::string m_state = "";
int m_bootableType = 0;
};
39 changes: 35 additions & 4 deletions Source/ui_qt/QBootablesView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,37 @@ QBootablesView::QBootablesView(QWidget* parent)
m_proxyModel = new BootableModelProxy(this);
ui->listView->setModel(m_proxyModel);

CAppConfig::GetInstance().RegisterPreferenceInteger("ui.sortmethod", BootablesDb::CClient::SORT_METHOD_NONE);
m_sortingMethod = CAppConfig::GetInstance().GetPreferenceInteger("ui.sortmethod");
CAppConfig::GetInstance().RegisterPreferenceInteger("ui.sortmethod.v2", BootablesDb::CClient::SORT_METHOD_NONE);
m_sortingMethod = CAppConfig::GetInstance().GetPreferenceInteger("ui.sortmethod.v2") & BootablesDb::CClient::SORT_METHOD_NONE;
ui->comboBox->setCurrentIndex(m_sortingMethod);

CAppConfig::GetInstance().RegisterPreferenceInteger("ui.filterbootabletype", BootableUtils::PS2_DISC | BootableUtils::PS2_ARCADE | BootableUtils::PS2_ELF);
auto filter = CAppConfig::GetInstance().GetPreferenceInteger("ui.filterbootabletype");
ui->checkBox_ps2->setChecked(filter & BootableUtils::PS2_DISC);
ui->checkBox_ps2_arcade->setChecked(filter & BootableUtils::PS2_ARCADE);
ui->checkBox_ps2_elf->setChecked(filter & BootableUtils::PS2_ELF);

m_proxyModel->setBootableTypeFilterState(filter, 1);

auto updateFilterPref = [](auto proxyModel) {
CAppConfig::GetInstance().SetPreferenceInteger("ui.filterbootabletype", proxyModel->getBootableTypeFilterState());
};

connect(ui->checkBox_ps2, &QCheckBox::stateChanged, [this, updateFilterPref](int state) {
m_proxyModel->setBootableTypeFilterState(BootableUtils::PS2_DISC, state);
updateFilterPref(m_proxyModel);
});

connect(ui->checkBox_ps2_arcade, &QCheckBox::stateChanged, [this, updateFilterPref](int state) {
m_proxyModel->setBootableTypeFilterState(BootableUtils::PS2_ARCADE, state);
updateFilterPref(m_proxyModel);
});

connect(ui->checkBox_ps2_elf, &QCheckBox::stateChanged, [this, updateFilterPref](int state) {
m_proxyModel->setBootableTypeFilterState(BootableUtils::PS2_ELF, state);
updateFilterPref(m_proxyModel);
});

connect(ui->filterLineEdit, &QLineEdit::textChanged, m_proxyModel, &QSortFilterProxyModel::setFilterFixedString);
connect(ui->stateFilterComboBox, &QComboBox::currentTextChanged, m_proxyModel, &BootableModelProxy::setFilterState);
connect(ui->listView->selectionModel(), &QItemSelectionModel::currentChanged, this, &QBootablesView::SelectionChange);
Expand Down Expand Up @@ -178,7 +205,7 @@ void QBootablesView::BootBootables(const QModelIndex& index)
auto src_index = m_proxyModel->mapToSource(index);
assert(src_index.isValid());
auto bootable = static_cast<BootableModel*>(m_proxyModel->sourceModel())->GetBootable(src_index);
m_bootCallback(bootable.path);
m_bootCallback(bootable);
}

void QBootablesView::on_listView_doubleClicked(const QModelIndex& index)
Expand Down Expand Up @@ -222,7 +249,7 @@ void QBootablesView::on_refresh_button_clicked()

void QBootablesView::on_comboBox_currentIndexChanged(int index)
{
CAppConfig::GetInstance().SetPreferenceInteger("ui.sortmethod", index);
CAppConfig::GetInstance().SetPreferenceInteger("ui.sortmethod.v2", index);
m_sortingMethod = index;
resetModel();
}
Expand Down Expand Up @@ -315,6 +342,10 @@ void QBootablesView::on_reset_filter_button_clicked()
{
ui->filterLineEdit->clear();
ui->stateFilterComboBox->setCurrentIndex(0);

ui->checkBox_ps2->setChecked(true);
ui->checkBox_ps2_arcade->setChecked(true);
ui->checkBox_ps2_elf->setChecked(true);
}

bool QBootablesView::IsProcessing()
Expand Down
Loading

0 comments on commit 32d6e06

Please sign in to comment.