diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index 98dafbeac6..69d0f659b7 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -323,6 +323,8 @@ private: } }; +// NOTE: this class is only used in DolphinWX/ISOFile.cpp for caching loaded +// ISO data. It will be removed when DolphinWX is, so please don't use it. class CChunkFileReader { public: diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index cce40889d9..6f25f894b4 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -12,6 +12,10 @@ set(SRCS MainWindow.cpp MainWindow.h SystemInfo.cpp + GameList/GameFile.cpp + GameList/GameGrid.cpp + GameList/GameTracker.cpp + GameList/GameTree.cpp Utils/Resources.cpp Utils/Utils.cpp VideoInterface/RenderWidget.cpp @@ -21,6 +25,8 @@ set(UIS AboutDialog.ui MainWindow.ui SystemInfo.ui + GameList/GameGrid.ui + GameList/GameTree.ui ) list(APPEND LIBS core uicommon) diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj b/Source/Core/DolphinQt/DolphinQt.vcxproj index bc5482a1b4..d60849aeae 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj @@ -49,7 +49,7 @@ iphlpapi.lib;winmm.lib;setupapi.lib;vfw32.lib;opengl32.lib;glu32.lib;rpcrt4.lib;comctl32.lib;%(AdditionalDependencies) - $(ProjectDir)\VideoInterface;%(AdditionalIncludeDirectories) + $(ProjectDir)\VideoInterface;$(ProjectDir)\GameList;%(AdditionalIncludeDirectories) @@ -58,6 +58,7 @@ + @@ -66,6 +67,10 @@ + + + + @@ -73,6 +78,13 @@ + + + + + + + @@ -155,6 +167,10 @@ + + + + diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj.filters b/Source/Core/DolphinQt/DolphinQt.vcxproj.filters index e415c300a5..368869def9 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj.filters +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj.filters @@ -27,6 +27,27 @@ Generated Files + + GameList + + + GameList + + + GameList + + + GameList + + + Generated Files + + + Generated Files + + + Generated Files + @@ -36,6 +57,9 @@ + + GameList + @@ -50,6 +74,9 @@ {c18a1fb3-64ff-4249-b808-d73a56ea3a2d} + + {be9925db-448c-46d8-a5a3-fb957490d3ef} + @@ -61,5 +88,17 @@ VideoInterface + + GameList + + + GameList + + + GameList + + + GameList + \ No newline at end of file diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj.user b/Source/Core/DolphinQt/DolphinQt.vcxproj.user index 422ab248b9..5804e0cf2d 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj.user +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj.user @@ -1,4 +1,4 @@ - + diff --git a/Source/Core/DolphinQt/GameList/GameFile.cpp b/Source/Core/DolphinQt/GameList/GameFile.cpp new file mode 100644 index 0000000000..70cd91b64c --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameFile.cpp @@ -0,0 +1,329 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include + +#include +#include +#include +#include + +#include "Common/Common.h" +#include "Common/CommonPaths.h" +#include "Common/FileUtil.h" +#include "Common/Hash.h" +#include "Common/IniFile.h" +#include "Common/StringUtil.h" + +#include "Core/ConfigManager.h" + +#include "DiscIO/BannerLoader.h" +#include "DiscIO/CompressedBlob.h" +#include "DiscIO/Filesystem.h" + +#include "DolphinQt/GameList/GameFile.h" +#include "DolphinQt/Utils/Resources.h" +#include "DolphinQt/Utils/Utils.h" + +static const u32 CACHE_REVISION = 0x003; +static const u32 DATASTREAM_REVISION = 15; // Introduced in Qt 5.2 + +static QStringList VectorToStringList(std::vector vec, bool trim = false) +{ + QStringList result; + if (trim) + { + for (const std::string& member : vec) + result.append(QString::fromStdString(member).trimmed()); + } + else + { + for (const std::string& member : vec) + result.append(QString::fromStdString(member)); + } + return result; +} + +GameFile::GameFile(const QString& fileName) + : m_file_name(fileName) +{ + bool hasBanner = false; + + if (LoadFromCache()) + { + m_valid = true; + hasBanner = true; + } + else + { + DiscIO::IVolume* volume = DiscIO::CreateVolumeFromFilename(fileName.toStdString()); + + if (volume != nullptr) + { + if (!DiscIO::IsVolumeWadFile(volume)) + m_platform = DiscIO::IsVolumeWiiDisc(volume) ? WII_DISC : GAMECUBE_DISC; + else + m_platform = WII_WAD; + + m_volume_names = VectorToStringList(volume->GetNames()); + + m_country = volume->GetCountry(); + m_file_size = volume->GetRawSize(); + m_volume_size = volume->GetSize(); + + m_unique_id = QString::fromStdString(volume->GetUniqueID()); + m_compressed = DiscIO::IsCompressedBlob(fileName.toStdString()); + m_is_disc_two = volume->IsDiscTwo(); + m_revision = volume->GetRevision(); + + QFileInfo info(m_file_name); + m_folder_name = info.absoluteDir().dirName(); + + // check if we can get some info from the banner file too + DiscIO::IFileSystem* fileSystem = DiscIO::CreateFileSystem(volume); + + if (fileSystem != nullptr || m_platform == WII_WAD) + { + std::unique_ptr bannerLoader(DiscIO::CreateBannerLoader(*fileSystem, volume)); + + if (bannerLoader != nullptr) + { + if (bannerLoader->IsValid()) + { + if (m_platform != WII_WAD) + m_names = VectorToStringList(bannerLoader->GetNames()); + m_company = QString::fromStdString(bannerLoader->GetCompany()); + m_descriptions = VectorToStringList(bannerLoader->GetDescriptions(), true); + + int width, height; + std::vector buffer = bannerLoader->GetBanner(&width, &height); + QImage banner(width, height, QImage::Format_RGB888); + for (int i = 0; i < width * height; i++) + { + int x = i % width, y = i / width; + banner.setPixel(x, y, qRgb((buffer[i] & 0xFF0000) >> 16, + (buffer[i] & 0x00FF00) >> 8, + (buffer[i] & 0x0000FF) >> 0)); + } + + if (!banner.isNull()) + { + hasBanner = true; + m_banner = QPixmap::fromImage(banner); + } + } + } + delete fileSystem; + } + delete volume; + + m_valid = true; + if (hasBanner) + SaveToCache(); + } + } + + if (m_valid) + { + IniFile ini; + ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + m_unique_id.toStdString() + ".ini"); + ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_unique_id.toStdString() + ".ini", true); + + std::string issues_temp; + ini.GetIfExists("EmuState", "EmulationStateId", &m_emu_state); + ini.GetIfExists("EmuState", "EmulationIssues", &issues_temp); + m_issues = QString::fromStdString(issues_temp); + } + + if (!hasBanner) + m_banner = Resources::GetPixmap(Resources::BANNER_MISSING); +} + +bool GameFile::LoadFromCache() +{ + QString filename = CreateCacheFilename(); + if (filename.isEmpty()) + return false; + + QFile file(filename); + if (!file.exists()) + return false; + if (!file.open(QFile::ReadOnly)) + return false; + + // If you modify the code below, you MUST bump the CACHE_REVISION! + QDataStream stream(&file); + stream.setVersion(DATASTREAM_REVISION); + + u32 cache_rev; + stream >> cache_rev; + if (cache_rev != CACHE_REVISION) + return false; + + int country; + stream >> m_folder_name + >> m_volume_names + >> m_company + >> m_descriptions + >> m_unique_id + >> m_file_size + >> m_volume_size + >> country + >> m_banner + >> m_compressed + >> m_platform + >> m_is_disc_two + >> m_revision; + m_country = (DiscIO::IVolume::ECountry)country; + file.close(); + return true; +} + +void GameFile::SaveToCache() +{ + if (!File::IsDirectory(File::GetUserPath(D_CACHE_IDX))) + File::CreateDir(File::GetUserPath(D_CACHE_IDX)); + + QString filename = CreateCacheFilename(); + if (filename.isEmpty()) + return; + if (QFile::exists(filename)) + QFile::remove(filename); + + QFile file(filename); + if (!file.open(QFile::WriteOnly)) + return; + + // If you modify the code below, you MUST bump the CACHE_REVISION! + QDataStream stream(&file); + stream.setVersion(DATASTREAM_REVISION); + stream << CACHE_REVISION; + + stream << m_folder_name + << m_volume_names + << m_company + << m_descriptions + << m_unique_id + << m_file_size + << m_volume_size + << (int)m_country + << m_banner + << m_compressed + << m_platform + << m_is_disc_two + << m_revision; +} + +QString GameFile::CreateCacheFilename() +{ + std::string filename, pathname, extension; + SplitPath(m_file_name.toStdString(), &pathname, &filename, &extension); + + if (filename.empty()) + return SL(""); // must be a disc drive + + // Filename.extension_HashOfFolderPath_Size.cache + // Append hash to prevent ISO name-clashing in different folders. + filename.append(StringFromFormat("%s_%x_%lx.qcache", + extension.c_str(), HashFletcher((const u8*)pathname.c_str(), pathname.size()), + File::GetSize(m_file_name.toStdString()))); + + QString fullname = QString::fromStdString(File::GetUserPath(D_CACHE_IDX)); + fullname += QString::fromStdString(filename); + return fullname; +} + +QString GameFile::GetCompany() const +{ + if (m_company.isEmpty()) + return QObject::tr("N/A"); + else + return m_company; +} + +// For all of the following functions that accept an "index" parameter, +// (-1 = Japanese, 0 = English, etc)? + +QString GameFile::GetDescription(int index) const +{ + if (index < m_descriptions.size()) + return m_descriptions[index]; + + if (!m_descriptions.empty()) + return m_descriptions[0]; + + return SL(""); +} + +QString GameFile::GetVolumeName(int index) const +{ + if (index < m_volume_names.size() && !m_volume_names[index].isEmpty()) + return m_volume_names[index]; + + if (!m_volume_names.isEmpty()) + return m_volume_names[0]; + + return SL(""); +} + +QString GameFile::GetBannerName(int index) const +{ + if (index < m_names.size() && !m_names[index].isEmpty()) + return m_names[index]; + + if (!m_names.isEmpty()) + return m_names[0]; + + return SL(""); +} + +QString GameFile::GetName(int index) const +{ + // Prefer name from banner, fallback to name from volume, fallback to filename + QString name = GetBannerName(index); + + if (name.isEmpty()) + name = GetVolumeName(index); + + if (name.isEmpty()) + { + // No usable name, return filename (better than nothing) + std::string nametemp; + SplitPath(m_file_name.toStdString(), nullptr, &nametemp, nullptr); + name = QString::fromStdString(nametemp); + } + + return name; +} + +const QString GameFile::GetWiiFSPath() const +{ + DiscIO::IVolume* volume = DiscIO::CreateVolumeFromFilename(m_file_name.toStdString()); + QString ret; + + if (volume == nullptr) + return ret; + + if (DiscIO::IsVolumeWiiDisc(volume) || DiscIO::IsVolumeWadFile(volume)) + { + std::string path; + u64 title; + + volume->GetTitleID((u8*)&title); + title = Common::swap64(title); + + path = StringFromFormat("%stitle/%08x/%08x/data/", File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(title >> 32), (u32)title); + + if (!File::Exists(path)) + File::CreateFullPath(path); + + if (path[0] == '.') + ret = QDir::currentPath() + QString::fromStdString(path).mid((int)strlen(ROOT_DIR)); + else + ret = QString::fromStdString(path); + } + delete volume; + + return ret; +} diff --git a/Source/Core/DolphinQt/GameList/GameFile.h b/Source/Core/DolphinQt/GameList/GameFile.h new file mode 100644 index 0000000000..bc6e0ea17a --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameFile.h @@ -0,0 +1,83 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#include + +#include "DiscIO/Volume.h" +#include "DiscIO/VolumeCreator.h" + +class GameFile final +{ +public: + GameFile(const QString& fileName); + GameFile(const std::string& fileName) : GameFile(QString::fromStdString(fileName)) {} + + bool IsValid() const { return m_valid; } + QString GetFileName() { return m_file_name; } + QString GetFolderName() { return m_folder_name; } + QString GetBannerName(int index) const; + QString GetVolumeName(int index) const; + QString GetName(int index) const; + QString GetCompany() const; + QString GetDescription(int index = 0) const; + int GetRevision() const { return m_revision; } + const QString GetUniqueID() const { return m_unique_id; } + const QString GetWiiFSPath() const; + DiscIO::IVolume::ECountry GetCountry() const { return m_country; } + int GetPlatform() const { return m_platform; } + const QString GetIssues() const { return m_issues; } + int GetEmuState() const { return m_emu_state; } + bool IsCompressed() const { return m_compressed; } + u64 GetFileSize() const { return m_file_size; } + u64 GetVolumeSize() const { return m_volume_size; } + bool IsDiscTwo() const { return m_is_disc_two; } + const QPixmap GetBitmap() const { return m_banner; } + + enum + { + GAMECUBE_DISC = 0, + WII_DISC, + WII_WAD, + NUMBER_OF_PLATFORMS + }; + +private: + QString m_file_name; + QString m_folder_name; + + // TODO: eliminate this and overwrite with names from banner when available? + QStringList m_volume_names; + + QString m_company; + QStringList m_names; + QStringList m_descriptions; + + QString m_unique_id; + + QString m_issues; + int m_emu_state = 0; + + quint64 m_file_size = 0; + quint64 m_volume_size = 0; + + DiscIO::IVolume::ECountry m_country; + int m_platform; + int m_revision = 0; + + QPixmap m_banner; + bool m_valid = false; + bool m_compressed = false; + bool m_is_disc_two = false; + + bool LoadFromCache(); + void SaveToCache(); + + QString CreateCacheFilename(); +}; diff --git a/Source/Core/DolphinQt/GameList/GameGrid.cpp b/Source/Core/DolphinQt/GameList/GameGrid.cpp new file mode 100644 index 0000000000..408fba7b03 --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameGrid.cpp @@ -0,0 +1,95 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "ui_GameGrid.h" + +#include "Common/StdMakeUnique.h" + +#include "DolphinQt/GameList/GameGrid.h" + +// Game banner image size +static const u32 GRID_BANNER_WIDTH = 144; +static const u32 GRID_BANNER_HEIGHT = 48; + +static const u32 ICON_BANNER_WIDTH = 64; +static const u32 ICON_BANNER_HEIGHT = 64; + +DGameGrid::DGameGrid(QWidget* parent_widget) : + QListWidget(parent_widget) +{ + m_ui = std::make_unique(); + m_ui->setupUi(this); + SetViewStyle(STYLE_GRID); + + connect(this, SIGNAL(itemActivated(QListWidgetItem*)), this, SIGNAL(StartGame())); +} + +DGameGrid::~DGameGrid() +{ + for (QListWidgetItem* i : m_items.keys()) + delete i; +} + +GameFile* DGameGrid::SelectedGame() +{ + if (!selectedItems().empty()) + return m_items.value(selectedItems().at(0)); + else + return nullptr; +} + +void DGameGrid::SelectGame(GameFile* game) +{ + if (game == nullptr) + return; + if (!selectedItems().empty()) + selectedItems().at(0)->setSelected(false); + m_items.key(game)->setSelected(true); +} + +void DGameGrid::SetViewStyle(GameListStyle newStyle) +{ + if (newStyle == STYLE_GRID) + { + m_current_style = STYLE_GRID; + setIconSize(QSize(GRID_BANNER_WIDTH, GRID_BANNER_HEIGHT)); + setViewMode(QListView::IconMode); + } + else + { + m_current_style = STYLE_ICON; + setIconSize(QSize(ICON_BANNER_WIDTH, ICON_BANNER_HEIGHT)); + setViewMode(QListView::ListMode); + } + + // QListView resets this when you change the view mode, so let's set it again + setDragEnabled(false); +} + +void DGameGrid::AddGame(GameFile* item) +{ + if (m_items.values().contains(item)) + return; + m_items.values().append(item); + + QListWidgetItem* i = new QListWidgetItem; + i->setIcon(QIcon(item->GetBitmap() + .scaled(GRID_BANNER_WIDTH, GRID_BANNER_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation))); + i->setText(item->GetName(0)); + if (item->IsCompressed()) + i->setTextColor(QColor("#00F")); + + addItem(i); + m_items.insert(i, item); +} + +void DGameGrid::RemoveGame(GameFile* item) +{ + if (!m_items.values().contains(item)) + return; + + QListWidgetItem* i = m_items.key(item); + m_items.remove(i); + delete i; +} diff --git a/Source/Core/DolphinQt/GameList/GameGrid.h b/Source/Core/DolphinQt/GameList/GameGrid.h new file mode 100644 index 0000000000..2c89ef94c4 --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameGrid.h @@ -0,0 +1,44 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include + +#include + +#include "DolphinQt/GameList/GameTracker.h" + +// Predefinitions +namespace Ui +{ +class DGameGrid; +} + +class DGameGrid : public QListWidget, public AbstractGameList +{ + Q_OBJECT + +public: + explicit DGameGrid(QWidget* parent_widget = nullptr); + ~DGameGrid(); + + // AbstractGameList stuff + virtual GameFile* SelectedGame(); + virtual void SelectGame(GameFile* game); + + virtual void SetViewStyle(GameListStyle newStyle); + + virtual void AddGame(GameFile* item); + virtual void RemoveGame(GameFile* item); + +signals: + void StartGame(); + +private: + std::unique_ptr m_ui; + + QMap m_items; + GameListStyle m_current_style; +}; diff --git a/Source/Core/DolphinQt/GameList/GameGrid.ui b/Source/Core/DolphinQt/GameList/GameGrid.ui new file mode 100644 index 0000000000..742435b22a --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameGrid.ui @@ -0,0 +1,22 @@ + + + DGameGrid + + + + 0 + 0 + 256 + 192 + + + + true + + + QListView::Adjust + + + + + diff --git a/Source/Core/DolphinQt/GameList/GameTracker.cpp b/Source/Core/DolphinQt/GameList/GameTracker.cpp new file mode 100644 index 0000000000..a3994548c6 --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameTracker.cpp @@ -0,0 +1,252 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "Common/CDUtils.h" +#include "Common/FileSearch.h" +#include "Core/ConfigManager.h" + +#include "DolphinQt/GameList/GameGrid.h" +#include "DolphinQt/GameList/GameTracker.h" +#include "DolphinQt/GameList/GameTree.h" + +void AbstractGameList::AddGames(QList items) +{ + for (GameFile* o : items) + AddGame(o); +} +void AbstractGameList::RemoveGames(QList items) +{ + for (GameFile* o : items) + RemoveGame(o); +} + + +DGameTracker::DGameTracker(QWidget* parent_widget) + : QStackedWidget(parent_widget), + m_watcher(this) +{ + connect(&m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(ScanForGames())); + + m_tree_widget = new DGameTree(this); + addWidget(m_tree_widget); + connect(m_tree_widget, SIGNAL(StartGame()), this, SIGNAL(StartGame())); + + m_grid_widget = new DGameGrid(this); + addWidget(m_grid_widget); + connect(m_grid_widget, SIGNAL(StartGame()), this, SIGNAL(StartGame())); + + SetViewStyle(STYLE_LIST); +} + +DGameTracker::~DGameTracker() +{ + for (GameFile* file : m_games.values()) + delete file; +} + +void DGameTracker::SetViewStyle(GameListStyle newStyle) +{ + if (newStyle == m_current_style) + return; + m_current_style = newStyle; + + if (newStyle == STYLE_LIST || newStyle == STYLE_TREE) + { + m_tree_widget->SelectGame(SelectedGame()); + setCurrentWidget(m_tree_widget); + m_tree_widget->SetViewStyle(newStyle); + } + else + { + m_grid_widget->SelectGame(SelectedGame()); + setCurrentWidget(m_grid_widget); + m_grid_widget->SetViewStyle(newStyle); + } +} + +GameFile* DGameTracker::SelectedGame() +{ + if (currentWidget() == m_grid_widget) + return m_grid_widget->SelectedGame(); + else + return m_tree_widget->SelectedGame(); +} + +void DGameTracker::ScanForGames() +{ + setDisabled(true); + + CFileSearch::XStringVector dirs(SConfig::GetInstance().m_ISOFolder); + + if (SConfig::GetInstance().m_RecursiveISOFolder) + { + for (u32 i = 0; i < dirs.size(); i++) + { + File::FSTEntry FST_Temp; + File::ScanDirectoryTree(dirs[i], FST_Temp); + for (auto& entry : FST_Temp.children) + { + if (entry.isDirectory) + { + bool duplicate = false; + for (auto& dir : dirs) + { + if (dir == entry.physicalName) + { + duplicate = true; + break; + } + } + if (!duplicate) + dirs.push_back(entry.physicalName); + } + } + } + } + + for (std::string& dir : dirs) + m_watcher.addPath(QString::fromStdString(dir)); + + CFileSearch::XStringVector exts; + if (SConfig::GetInstance().m_ListGC) + { + exts.push_back("*.gcm"); + exts.push_back("*.gcz"); + } + if (SConfig::GetInstance().m_ListWii || SConfig::GetInstance().m_ListGC) + { + exts.push_back("*.iso"); + exts.push_back("*.ciso"); + exts.push_back("*.wbfs"); + } + if (SConfig::GetInstance().m_ListWad) + exts.push_back("*.wad"); + + CFileSearch FileSearch(exts, dirs); + const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames(); + QList newItems; + QStringList allItems; + + if (!rFilenames.empty()) + { + for (u32 i = 0; i < rFilenames.size(); i++) + { + std::string FileName; + SplitPath(rFilenames[i], nullptr, &FileName, nullptr); + QString NameAndPath = QString::fromStdString(rFilenames[i]); + allItems.append(NameAndPath); + + if (m_games.keys().contains(NameAndPath)) + continue; + + GameFile* obj = new GameFile(rFilenames[i]); + if (obj->IsValid()) + { + bool list = true; + + switch(obj->GetCountry()) + { + case DiscIO::IVolume::COUNTRY_AUSTRALIA: + if (!SConfig::GetInstance().m_ListAustralia) + list = false; + break; + case DiscIO::IVolume::COUNTRY_GERMANY: + if (!SConfig::GetInstance().m_ListGermany) + list = false; + break; + case DiscIO::IVolume::COUNTRY_RUSSIA: + if (!SConfig::GetInstance().m_ListRussia) + list = false; + break; + case DiscIO::IVolume::COUNTRY_UNKNOWN: + if (!SConfig::GetInstance().m_ListUnknown) + list = false; + break; + case DiscIO::IVolume::COUNTRY_TAIWAN: + if (!SConfig::GetInstance().m_ListTaiwan) + list = false; + break; + case DiscIO::IVolume::COUNTRY_KOREA: + if (!SConfig::GetInstance().m_ListKorea) + list = false; + break; + case DiscIO::IVolume::COUNTRY_JAPAN: + if (!SConfig::GetInstance().m_ListJap) + list = false; + break; + case DiscIO::IVolume::COUNTRY_USA: + if (!SConfig::GetInstance().m_ListUsa) + list = false; + break; + case DiscIO::IVolume::COUNTRY_FRANCE: + if (!SConfig::GetInstance().m_ListFrance) + list = false; + break; + case DiscIO::IVolume::COUNTRY_ITALY: + if (!SConfig::GetInstance().m_ListItaly) + list = false; + break; + case DiscIO::IVolume::COUNTRY_SPAIN: + if (!SConfig::GetInstance().m_ListSpain) + list = false; + break; + case DiscIO::IVolume::COUNTRY_NETHERLANDS: + if (!SConfig::GetInstance().m_ListNetherlands) + list = false; + break; + default: + if (!SConfig::GetInstance().m_ListPal) + list = false; + break; + } + + if (list) + newItems.append(obj); + } + } + } + + // Process all the new GameFiles + for (GameFile* o : newItems) + m_games.insert(o->GetFileName(), o); + + // Check for games that were removed + QList removedGames; + for (QString& path : m_games.keys()) + { + if (!allItems.contains(path)) + { + removedGames.append(m_games.value(path)); + m_games.remove(path); + } + } + + m_tree_widget->AddGames(newItems); + m_grid_widget->AddGames(newItems); + + m_tree_widget->RemoveGames(removedGames); + m_grid_widget->RemoveGames(removedGames); + + for (GameFile* file : removedGames) + delete file; + + setDisabled(false); +} + +void DGameTracker::SelectLastBootedGame() +{ + if (!SConfig::GetInstance().m_LastFilename.empty() && File::Exists(SConfig::GetInstance().m_LastFilename)) + { + QString lastfilename = QString::fromStdString(SConfig::GetInstance().m_LastFilename); + for (GameFile* game : m_games.values()) + { + if (game->GetFileName() == lastfilename) + { + m_tree_widget->SelectGame(game); + break; + } + + } + } +} diff --git a/Source/Core/DolphinQt/GameList/GameTracker.h b/Source/Core/DolphinQt/GameList/GameTracker.h new file mode 100644 index 0000000000..770f197864 --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameTracker.h @@ -0,0 +1,68 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include + +#include "DolphinQt/GameList/GameFile.h" + +// Predefinitions +class DGameGrid; +class DGameTree; + +enum GameListStyle +{ + STYLE_LIST, + STYLE_TREE, + STYLE_GRID, + STYLE_ICON +}; + +class AbstractGameList +{ +public: + virtual GameFile* SelectedGame() = 0; + virtual void SelectGame(GameFile* game) = 0; + + virtual void SetViewStyle(GameListStyle newStyle) = 0; + + virtual void AddGame(GameFile* item) = 0; + void AddGames(QList items); + + virtual void RemoveGame(GameFile* item) = 0; + void RemoveGames(QList items); +}; + +class DGameTracker : public QStackedWidget +{ + Q_OBJECT + +public: + DGameTracker(QWidget* parent_widget = nullptr); + ~DGameTracker(); + + GameListStyle ViewStyle() const { return m_current_style; } + void SetViewStyle(GameListStyle newStyle); + + GameFile* SelectedGame(); + void SelectLastBootedGame(); + +signals: + void StartGame(); + +public slots: + void ScanForGames(); + +private: + QMap m_games; + QFileSystemWatcher m_watcher; + + GameListStyle m_current_style; + DGameGrid* m_grid_widget = nullptr; + DGameTree* m_tree_widget = nullptr; +}; diff --git a/Source/Core/DolphinQt/GameList/GameTree.cpp b/Source/Core/DolphinQt/GameList/GameTree.cpp new file mode 100644 index 0000000000..fa3d5babe4 --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameTree.cpp @@ -0,0 +1,167 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "ui_GameTree.h" + +#include "Common/StdMakeUnique.h" + +#include "DolphinQt/GameList/GameTree.h" + +#include "DolphinQt/Utils/Resources.h" +#include "DolphinQt/Utils/Utils.h" + +// Game banner image size +static const u32 BANNER_WIDTH = 96; +static const u32 BANNER_HEIGHT = 32; + +DGameTree::DGameTree(QWidget* parent_widget) : + QTreeWidget(parent_widget) +{ + m_ui = std::make_unique(); + m_ui->setupUi(this); + + SetViewStyle(STYLE_TREE); + setIconSize(QSize(BANNER_WIDTH, BANNER_HEIGHT)); + sortByColumn(COL_TITLE); + + connect(this, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(ItemActivated(QTreeWidgetItem*))); +} + +DGameTree::~DGameTree() +{ + int count = topLevelItemCount(); + for (int a = 0; a < count; a++) + takeTopLevelItem(0); + + for (QTreeWidgetItem* i : m_path_nodes.values()) + { + count = i->childCount(); + for (int a = 0; a < count; a++) + i->takeChild(0); + } + + for (QTreeWidgetItem* i : m_path_nodes.values()) + delete i; + for (QTreeWidgetItem* i : m_items.keys()) + delete i; +} + +void DGameTree::ResizeAllCols() +{ + for (int i = 0; i < columnCount(); i++) + resizeColumnToContents(i); +} + +void DGameTree::ItemActivated(QTreeWidgetItem* item) +{ + if (!m_path_nodes.values().contains(item)) + emit StartGame(); +} + +GameFile* DGameTree::SelectedGame() +{ + if (!selectedItems().empty()) + return m_items.value(selectedItems().at(0)); + else + return nullptr; +} + +void DGameTree::SelectGame(GameFile* game) +{ + if (game == nullptr) + return; + if (!selectedItems().empty()) + selectedItems().at(0)->setSelected(false); + m_items.key(game)->setSelected(true); +} + +void DGameTree::SetViewStyle(GameListStyle newStyle) +{ + if (newStyle == STYLE_LIST) + { + m_current_style = STYLE_LIST; + setIndentation(0); + RebuildTree(); + } + else + { + m_current_style = STYLE_TREE; + setIndentation(20); + RebuildTree(); + } +} + +void DGameTree::AddGame(GameFile* item) +{ + if (m_items.values().contains(item)) + return; + + QString folder = item->GetFolderName(); + if (!m_path_nodes.contains(folder)) + { + QTreeWidgetItem* i = new QTreeWidgetItem; + i->setText(0, folder); + m_path_nodes.insert(folder, i); + if (m_current_style == STYLE_TREE) + addTopLevelItem(i); + } + + QTreeWidgetItem* i = new QTreeWidgetItem; + i->setIcon(COL_TYPE, QIcon(Resources::GetPlatformPixmap(item->GetPlatform()))); + i->setIcon(COL_BANNER, QIcon(item->GetBitmap())); + i->setText(COL_TITLE, item->GetName(0)); + i->setText(COL_DESCRIPTION, item->GetDescription()); + i->setIcon(COL_REGION, QIcon(Resources::GetRegionPixmap(item->GetCountry()))); + i->setText(COL_SIZE, NiceSizeFormat(item->GetFileSize())); + if (item->IsCompressed()) + { + for (int col = 0; col < columnCount(); col++) + i->setTextColor(col, QColor("#00F")); + } + m_items.insert(i, item); + + RebuildTree(); // TODO: only call this once per group of items added +} + +void DGameTree::RemoveGame(GameFile* item) +{ + if (!m_items.values().contains(item)) + return; + QTreeWidgetItem* i = m_items.key(item); + m_items.remove(i); + delete i; +} + +void DGameTree::RebuildTree() +{ + GameFile* currentGame = SelectedGame(); + + int count = topLevelItemCount(); + for (int a = 0; a < count; a++) + takeTopLevelItem(0); + + for (QTreeWidgetItem* i : m_path_nodes.values()) + { + count = i->childCount(); + for (int a = 0; a < count; a++) + i->takeChild(0); + } + + if (m_current_style == STYLE_TREE) + { + for (QTreeWidgetItem* i : m_path_nodes.values()) + addTopLevelItem(i); + for (QTreeWidgetItem* i : m_items.keys()) + m_path_nodes.value(m_items.value(i)->GetFolderName())->addChild(i); + } + else + { + for (QTreeWidgetItem* i : m_items.keys()) + addTopLevelItem(i); + } + + expandAll(); + ResizeAllCols(); + SelectGame(currentGame); +} diff --git a/Source/Core/DolphinQt/GameList/GameTree.h b/Source/Core/DolphinQt/GameList/GameTree.h new file mode 100644 index 0000000000..ef7708b554 --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameTree.h @@ -0,0 +1,62 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include + +#include + +#include "DolphinQt/GameList/GameTracker.h" + +// Predefinitions +namespace Ui +{ +class DGameTree; +} + +class DGameTree : public QTreeWidget, public AbstractGameList +{ + Q_OBJECT + +public: + explicit DGameTree(QWidget* parent_widget = nullptr); + ~DGameTree(); + + // AbstractGameList stuff + virtual GameFile* SelectedGame(); + virtual void SelectGame(GameFile* game); + + virtual void SetViewStyle(GameListStyle newStyle); + + virtual void AddGame(GameFile* item); + virtual void RemoveGame(GameFile* item); + +signals: + void StartGame(); + +private slots: + void ItemActivated(QTreeWidgetItem* item); + +private: + enum Columns + { + COL_TYPE = 0, + COL_BANNER = 1, + COL_TITLE = 2, + COL_DESCRIPTION = 3, + COL_REGION = 4, + COL_SIZE = 5, + COL_STATE = 6 + }; + + std::unique_ptr m_ui; + GameListStyle m_current_style; + + QMap m_items; + QMap m_path_nodes; + + void RebuildTree(); + void ResizeAllCols(); +}; diff --git a/Source/Core/DolphinQt/GameList/GameTree.ui b/Source/Core/DolphinQt/GameList/GameTree.ui new file mode 100644 index 0000000000..22b63d82c3 --- /dev/null +++ b/Source/Core/DolphinQt/GameList/GameTree.ui @@ -0,0 +1,54 @@ + + + DGameTree + + + + 0 + 0 + 396 + 296 + + + + true + + + + Type + + + + + Banner + + + + + Title + + + + + Description + + + + + Region + + + + + Size + + + + + State + + + + + + diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 7fcdfd09b7..4bb13e29e2 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include #include #include #include @@ -28,20 +29,40 @@ DMainWindow::DMainWindow(QWidget* parent_widget) { m_ui = std::make_unique(); m_ui->setupUi(this); -#ifdef Q_OS_MACX - m_ui->toolbar->setMovable(false); -#endif Resources::Init(); UpdateIcons(); setWindowIcon(Resources::GetIcon(Resources::DOLPHIN_LOGO)); + // Create the GameList + m_game_tracker = new DGameTracker(this); + m_ui->centralWidget->addWidget(m_game_tracker); + m_game_tracker->ScanForGames(); + m_game_tracker->SelectLastBootedGame(); + + // Setup the GameList style switching actions + QActionGroup* gamelistGroup = new QActionGroup(this); + gamelistGroup->addAction(m_ui->actionListView); + gamelistGroup->addAction(m_ui->actionTreeView); + gamelistGroup->addAction(m_ui->actionGridView); + gamelistGroup->addAction(m_ui->actionIconView); + + // TODO: save/load this from user prefs! + m_ui->actionListView->setChecked(true); + OnGameListStyleChanged(); + // Connect all the signals/slots connect(this, SIGNAL(CoreStateChanged(Core::EState)), this, SLOT(OnCoreStateChanged(Core::EState))); connect(m_ui->actionOpen, SIGNAL(triggered()), this, SLOT(OnOpen())); + connect(m_ui->actionListView, SIGNAL(triggered()), this, SLOT(OnGameListStyleChanged())); + connect(m_ui->actionTreeView, SIGNAL(triggered()), this, SLOT(OnGameListStyleChanged())); + connect(m_ui->actionGridView, SIGNAL(triggered()), this, SLOT(OnGameListStyleChanged())); + connect(m_ui->actionIconView, SIGNAL(triggered()), this, SLOT(OnGameListStyleChanged())); + connect(m_ui->actionPlay, SIGNAL(triggered()), this, SLOT(OnPlay())); + connect(m_game_tracker, SIGNAL(StartGame()), this, SLOT(OnPlay())); connect(m_ui->actionStop, SIGNAL(triggered()), this, SLOT(OnStop())); connect(m_ui->actionWebsite, SIGNAL(triggered()), this, SLOT(OnOpenWebsite())); @@ -52,6 +73,11 @@ DMainWindow::DMainWindow(QWidget* parent_widget) // Update GUI items emit CoreStateChanged(Core::CORE_UNINITIALIZED); + + // Platform-specific stuff +#ifdef Q_OS_MACX + m_ui->toolbar->setMovable(false); +#endif } DMainWindow::~DMainWindow() @@ -69,7 +95,7 @@ void DMainWindow::StartGame(const QString filename) // TODO: When rendering to main, this won't resize the parent window.. if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain) { - connect(m_render_widget.get(), SIGNAL(Closed()), this, SLOT(on_actStop_triggered())); + connect(m_render_widget.get(), SIGNAL(Closed()), this, SLOT(OnStop())); m_render_widget->move(SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos, SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos); m_render_widget->resize(SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth, // TODO: Make sure these are client sizes! @@ -106,7 +132,8 @@ void DMainWindow::StartGame(const QString filename) QString DMainWindow::RequestBootFilename() { // If a game is already selected, just return the filename - // ... TODO + if (m_game_tracker->SelectedGame() != nullptr) + return m_game_tracker->SelectedGame()->GetFileName(); return ShowFileDialog(); } @@ -198,6 +225,18 @@ void DMainWindow::OnStop() m_isStopping = false; } +void DMainWindow::OnGameListStyleChanged() +{ + if (m_ui->actionListView->isChecked()) + m_game_tracker->SetViewStyle(STYLE_LIST); + else if (m_ui->actionTreeView->isChecked()) + m_game_tracker->SetViewStyle(STYLE_TREE); + else if (m_ui->actionGridView->isChecked()) + m_game_tracker->SetViewStyle(STYLE_GRID); + else if (m_ui->actionIconView->isChecked()) + m_game_tracker->SetViewStyle(STYLE_ICON); +} + void DMainWindow::OnCoreStateChanged(Core::EState state) { bool is_not_initialized = (state == Core::CORE_UNINITIALIZED); @@ -219,6 +258,7 @@ void DMainWindow::OnCoreStateChanged(Core::EState state) m_ui->actionStop->setEnabled(!is_not_initialized); m_ui->actionOpen->setEnabled(is_not_initialized); + m_game_tracker->setEnabled(is_not_initialized); } bool DMainWindow::RenderWidgetHasFocus() diff --git a/Source/Core/DolphinQt/MainWindow.h b/Source/Core/DolphinQt/MainWindow.h index 86cc37a0ca..e8fa97c8ba 100644 --- a/Source/Core/DolphinQt/MainWindow.h +++ b/Source/Core/DolphinQt/MainWindow.h @@ -9,6 +9,7 @@ #include "Core/Core.h" +#include "DolphinQt/GameList/GameTracker.h" #include "DolphinQt/VideoInterface/RenderWidget.h" // Predefinitions @@ -42,6 +43,9 @@ private slots: void OnPlay(); void OnStop(); + // View menu + void OnGameListStyleChanged(); + // Help menu void OnOpenWebsite(); void OnOpenDocs(); @@ -54,13 +58,14 @@ private slots: private: std::unique_ptr m_ui; + DGameTracker* m_game_tracker; // Emulation QString RequestBootFilename(); QString ShowFileDialog(); void DoStartPause(); - std::unique_ptr m_render_widget; + std::unique_ptr m_render_widget; // TODO: just create this once and reuse it bool m_isStopping = false; }; diff --git a/Source/Core/DolphinQt/MainWindow.ui b/Source/Core/DolphinQt/MainWindow.ui index 4deb07dbc8..f0b65dee2e 100644 --- a/Source/Core/DolphinQt/MainWindow.ui +++ b/Source/Core/DolphinQt/MainWindow.ui @@ -60,6 +60,16 @@ &View + + + Gamelist view style + + + + + + + @@ -79,11 +89,11 @@ + - @@ -157,6 +167,38 @@ QAction::AboutQtRole + + + true + + + List view + + + + + true + + + Tree view + + + + + true + + + Grid view + + + + + true + + + Icon view + +