Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt: gamelist improvements #391

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions DobieStation/DobieQt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@
<ClCompile Include="$(UIDir)emuwindow.cpp" />
<ClCompile Include="$(UIDir)renderwidget.cpp" />
<ClCompile Include="$(UIDir)settingswindow.cpp" />
<ClCompile Include="$(UIDir)gamelistwidget.cpp" />
<ClCompile Include="$(UIDir)bios.cpp" />
<ClCompile Include="$(UIDir)settings.cpp" />
<ClCompile Include="$(UIDir)main.cpp" />
<ClCompile Include="$(UIDir)gamelist/gamelistwidget.cpp" />
<ClCompile Include="$(UIDir)gamelist/gamelistmodel.cpp" />
<ClCompile Include="$(UIDir)gamelist/gamelistwatcher.cpp" />
<ClCompile Include="$(UIDir)gamelist/gamelistproxy.cpp" />
</ItemGroup>

<!-- headers -->
Expand All @@ -103,17 +106,23 @@
<QtMoc Include="$(UIDir)emuwindow.hpp" />
<QtMoc Include="$(UIDir)renderwidget.hpp" />
<QtMoc Include="$(UIDir)settingswindow.hpp" />
<QtMoc Include="$(UIDir)gamelistwidget.hpp" />
<QtMoc Include="$(UIDir)gamelist/gamelistwidget.hpp" />
<QtMoc Include="$(UIDir)gamelist/gamelistmodel.hpp" />
<QtMoc Include="$(UIDir)gamelist/gamelistwatcher.hpp" />
<QtMoc Include="$(UIDir)gamelist/gamelistproxy.hpp" />
</ItemGroup>

<!-- moc compile -->
<ItemGroup>
<ClCompile Include="$(QtMocOutPrefix)settings.cpp" />
<ClCompile Include="$(QtMocOutPrefix)emuthread.cpp" />
<ClCompile Include="$(QtMocOutPrefix)emuwindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)renderwidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)settingswindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)gamelistwidget.cpp" />
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)settings.cpp" />
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)emuthread.cpp" />
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)emuwindow.cpp" />
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)renderwidget.cpp" />
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)settingswindow.cpp" />
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)gamelistwidget.cpp" />
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)gamelistmodel.cpp" />
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)gamelistwatcher.cpp" />
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)gamelistproxy.cpp" />
</ItemGroup>

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
49 changes: 38 additions & 11 deletions DobieStation/DobieQt.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<ClCompile Include="$(UIDir)bios.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="$(UIDir)gamelistwidget.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="$(UIDir)emuwindow.cpp">
<Filter>Source</Filter>
</ClCompile>
Expand All @@ -40,25 +37,46 @@
<ClCompile Include="$(UIDir)main.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="$(UIDir)gamelist/gamelistwidget.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="$(UIDir)gamelist/gamelistmodel.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="$(UIDir)gamelist/gamelistwatcher.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="$(UIDir)gamelist/gamelistproxy.cpp">
<Filter>Source</Filter>
</ClCompile>
</ItemGroup>

<ItemGroup>
<ClCompile Include="$(QtMocOutPrefix)settingswindow.cpp">
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)settingswindow.cpp">
<Filter>Moc</Filter>
</ClCompile>
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)settings.cpp">
<Filter>Moc</Filter>
</ClCompile>
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)renderwidget.cpp">
<Filter>Moc</Filter>
</ClCompile>
<ClCompile Include="$(QtMocOutPrefix)settings.cpp">
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)emuwindow.cpp">
<Filter>Moc</Filter>
</ClCompile>
<ClCompile Include="$(QtMocOutPrefix)renderwidget.cpp">
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)emuthread.cpp">
<Filter>Moc</Filter>
</ClCompile>
<ClCompile Include="$(QtMocOutPrefix)gamelistwidget.cpp">
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)gamelistwidget.cpp">
<Filter>Moc</Filter>
</ClCompile>
<ClCompile Include="$(QtMocOutPrefix)emuwindow.cpp">
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)gamelistmodel.cpp">
<Filter>Moc</Filter>
</ClCompile>
<ClCompile Include="$(QtMocOutPrefix)emuthread.cpp">
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)gamelistwatcher.cpp">
<Filter>Moc</Filter>
</ClCompile>
<ClCompile Include="$(QtMocDir)$(QtMocPrefix)gamelistproxy.cpp">
<Filter>Moc</Filter>
</ClCompile>
</ItemGroup>
Expand All @@ -70,7 +88,7 @@
</ItemGroup>

<ItemGroup>
<QtMoc Include=".$(UIDir)renderwidget.hpp">
<QtMoc Include="$(UIDir)renderwidget.hpp">
<Filter>Headers</Filter>
</QtMoc>
<QtMoc Include="$(UIDir)settingswindow.hpp">
Expand All @@ -85,7 +103,16 @@
<QtMoc Include="$(UIDir)settings.hpp">
<Filter>Headers</Filter>
</QtMoc>
<QtMoc Include="$(UIDir)gamelistwidget.hpp">
<QtMoc Include="$(UIDir)gamelist/gamelistwidget.hpp">
<Filter>Headers</Filter>
</QtMoc>
<QtMoc Include="$(UIDir)gamelist/gamelistmodel.hpp">
<Filter>Headers</Filter>
</QtMoc>
<QtMoc Include="$(UIDir)gamelist/gamelistwatcher.hpp">
<Filter>Headers</Filter>
</QtMoc>
<QtMoc Include="$(UIDir)gamelist/gamelistproxy.hpp">
<Filter>Headers</Filter>
</QtMoc>
</ItemGroup>
Expand Down
10 changes: 8 additions & 2 deletions DobieStation/application/application.pro
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ SOURCES += ../../src/qt/main.cpp \
../../src/qt/renderwidget.cpp \
../../src/qt/settingswindow.cpp \
../../src/qt/bios.cpp \
../../src/qt/gamelistwidget.cpp \
../../src/qt/gamelist/gamelistmodel.cpp \
../../src/qt/gamelist/gamelistproxy.cpp \
../../src/qt/gamelist/gamelistwatcher.cpp \
../../src/qt/gamelist/gamelistwidget.cpp \
../../src/core/ee/ee_jittrans.cpp \
../../src/core/ee/ee_jit.cpp \
../../src/core/ee/ee_jit64.cpp \
Expand Down Expand Up @@ -171,7 +174,10 @@ HEADERS += \
../../src/qt/renderwidget.hpp \
../../src/qt/settingswindow.hpp \
../../src/qt/bios.hpp \
../../src/qt/gamelistwidget.hpp \
../../src/qt/gamelist/gamelistmodel.hpp \
../../src/qt/gamelist/gamelistproxy.hpp \
../../src/qt/gamelist/gamelistwatcher.hpp \
../../src/qt/gamelist/gamelistwidget.hpp \
../../src/core/ee/ee_jittrans.hpp \
../../src/core/ee/ee_jit.hpp \
../../src/core/ee/ee_jit64.hpp \
Expand Down
1 change: 0 additions & 1 deletion DobieStation/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<DisableSpecificWarnings>4577;4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>

<!-- includes -->
<AdditionalIncludeDirectories>$(UIDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExtDir)\libdeflate;$(ExtDir)\libdeflate\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

<!-- preprocessor-->
Expand Down
6 changes: 5 additions & 1 deletion DobieStation/qt.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<QtLibDir>$(QTDIR)lib\</QtLibDir>
<QtBinDir>$(QTDIR)bin\</QtBinDir>
<QtPluginsDir>$(QTDIR)plugins\</QtPluginsDir>
<QtMocOutPrefix>$(QtToolOutDir)moc_</QtMocOutPrefix>
<QtMocDir>$(QtToolOutDir)</QtMocDir>
<QtMocPrefix>moc_</QtMocPrefix>
<QtDebugSuffix>d</QtDebugSuffix>
<QtLibSuffix Condition="'$(Configuration)'=='Debug'">$(QtDebugSuffix)</QtLibSuffix>
<QtPluginFolder>QtPlugins</QtPluginFolder>
Expand All @@ -32,6 +33,8 @@
<PreprocessorDefinitions>QT_CORE_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>

<!-- includes -->
<AdditionalIncludeDirectories>$(UIDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(UIDir)gamelist;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(QtToolOutDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(QtIncludeDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(QtIncludeDir)QtCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand Down Expand Up @@ -76,6 +79,7 @@

<ItemGroup>
<MocOutputs Include="$(QtToolOutDir)moc_*.cpp" />
<MocOutputs Include="$(QtToolOutDir)gamelist/moc_*.cpp" />
</ItemGroup>

<Target Name="QtMocClean">
Expand Down
14 changes: 10 additions & 4 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@ set(SOURCES
emuwindow.cpp
settingswindow.cpp
renderwidget.cpp
gamelistwidget.cpp
main.cpp
settings.cpp
bios.cpp)
bios.cpp
gamelist/gamelistmodel.cpp
gamelist/gamelistproxy.cpp
gamelist/gamelistwatcher.cpp
gamelist/gamelistwidget.cpp)

set(HEADERS
emuthread.hpp
emuwindow.hpp
settingswindow.hpp
renderwidget.hpp
gamelistwidget.hpp
settings.hpp
bios.hpp)
bios.hpp
gamelist/gamelistmodel.hpp
gamelist/gamelistproxy.hpp
gamelist/gamelistwatcher.hpp
gamelist/gamelistwidget.hpp)

add_executable(${TARGET} ${SOURCES} ${HEADERS})
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME "DobieStation") # Output as "DobieStation" instead of "DobieQt"
Expand Down
3 changes: 2 additions & 1 deletion src/qt/emuwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
#include "emuwindow.hpp"
#include "settingswindow.hpp"
#include "renderwidget.hpp"
#include "gamelistwidget.hpp"
#include "bios.hpp"

#include "gamelist/gamelistwidget.hpp"

#include "arg.h"

using namespace std;
Expand Down
162 changes: 162 additions & 0 deletions src/qt/gamelist/gamelistmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#include <QDirIterator>
#include <QLocale>
#include <QDebug>

// For old Qt workaround
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
#include <cmath>
#endif

#include "../settings.hpp"
#include "gamelistmodel.hpp"

static QMap<QString, QString> s_file_type_desc{
{"elf", "PS2 Executable"},
{"iso", "ISO Image"},
{"cso", "Compressed ISO"},
{"gsd", "GSDump"},
{"bin", "BIN/CUE"}
};

GameListModel::GameListModel(QObject* parent)
: QAbstractTableModel(parent)
{
connect(&watcher, &GameListWatcher::game_loaded, this, &GameListModel::add_game);
connect(&watcher, &GameListWatcher::game_removed, this, &GameListModel::remove_game);
connect(&watcher, &GameListWatcher::directory_processed, [this]() {
emit directory_processed();
});

connect(&Settings::instance(), &Settings::rom_directory_committed,
&watcher, &GameListWatcher::add_directory);
connect(&Settings::instance(), &Settings::rom_directory_uncommitted,
&watcher, &GameListWatcher::remove_directory);

for (const auto& path : Settings::instance().rom_directories)
watcher.add_directory(path);
}

QVariant GameListModel::data(
const QModelIndex& index, int role
) const
{
// might be cool in the future
// but for now let's just focus
// on display role
if (!index.isValid())
return QVariant();

const auto& game = m_games.at(index.row());

switch (index.column())
{
case COLUMN_NAME:
if(role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
return game.name;
break;
case COLUMN_TYPE:
if (role == Qt::DisplayRole)
return s_file_type_desc[game.type];

// sort by the actual type and not
// the description
if (role == Qt::InitialSortOrderRole)
return game.type;
break;
case COLUMN_SIZE:
if(role == Qt::DisplayRole)
return get_formatted_data_size(game.size);

// sort by the actual size and not
// the human readable string
if (role == Qt::InitialSortOrderRole)
return game.size;
break;
}

return QVariant();
}

QVariant GameListModel::headerData(
int section, Qt::Orientation orientation, int role
) const
{
if (orientation == Qt::Vertical || role != Qt::DisplayRole)
return QVariant();

switch (section)
{
case COLUMN_NAME:
return tr("Name");
case COLUMN_TYPE:
return tr("Type");
case COLUMN_SIZE:
return tr("Size");
}

return QVariant();
}

int GameListModel::rowCount(const QModelIndex& index) const
{
if (index.isValid())
return 0;

return m_games.size();
}

int GameListModel::columnCount(const QModelIndex& index) const
{
return COLUMN_MAX;
}

GameInfo GameListModel::get_game_info(int index)
{
return m_games[index];
}

GameListWatcher* GameListModel::get_watcher()
{
return &watcher;
}

void GameListModel::add_game(const GameInfo game)
{
beginInsertRows(QModelIndex(), m_games.size(), m_games.size());
m_games.push_back(game);
endInsertRows();
}

void GameListModel::remove_game(const GameInfo game)
{
auto index = m_games.indexOf(game);

beginRemoveRows(QModelIndex(), index, index);
m_games.removeAt(index);
endRemoveRows();
}

QString GameListModel::get_formatted_data_size(uint64_t size) const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
// work around until ubuntu gets a new qt
// don't rely on this function for translations
const char* const quantifiers[] = {
"B",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB",
"EiB"
};
const int unit = std::log2(std::max<uint64_t>(size, 1)) / 10;
const double unit_size = size / std::pow(2, unit * 10);

return QString("%1 %2")
.arg(unit_size, 4, 'f', 2, '0')
.arg(quantifiers[unit]);
#else
return QLocale().formattedDataSize(size);
#endif
}
Loading