[UI] Remove DolphinQt

This commit is contained in:
Anthony Serna
2016-01-05 19:36:16 -06:00
parent f3098bf426
commit 2ee84a20fe
36 changed files with 0 additions and 3311 deletions

View File

@ -1,393 +0,0 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <algorithm>
#include <memory>
#include <QDataStream>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QXmlStreamReader>
#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/VolumeCreator.h"
#include "DolphinQt/GameList/GameFile.h"
static const u32 CACHE_REVISION = 0x00E; // Last changed in PR 3309
static const u32 DATASTREAM_REVISION = 15; // Introduced in Qt 5.2
static QMap<DiscIO::IVolume::ELanguage, QString> ConvertLocalizedStrings(std::map<DiscIO::IVolume::ELanguage, std::string> strings)
{
QMap<DiscIO::IVolume::ELanguage, QString> result;
for (auto entry : strings)
result.insert(entry.first, QString::fromStdString(entry.second).trimmed());
return result;
}
template<class to, class from>
static QMap<to, QString> CastLocalizedStrings(QMap<from, QString> strings)
{
QMap<to, QString> result;
auto end = strings.cend();
for (auto it = strings.cbegin(); it != end; ++it)
result.insert((to)it.key(), it.value());
return result;
}
static QString GetLanguageString(DiscIO::IVolume::ELanguage language, QMap<DiscIO::IVolume::ELanguage, QString> strings)
{
if (strings.contains(language))
return strings.value(language);
// English tends to be a good fallback when the requested language isn't available
if (language != DiscIO::IVolume::ELanguage::LANGUAGE_ENGLISH)
{
if (strings.contains(DiscIO::IVolume::ELanguage::LANGUAGE_ENGLISH))
return strings.value(DiscIO::IVolume::ELanguage::LANGUAGE_ENGLISH);
}
// If English isn't available either, just pick something
if (!strings.empty())
return strings.cbegin().value();
return QStringLiteral("");
}
GameFile::GameFile(const QString& fileName)
: m_file_name(fileName)
{
QFileInfo info(m_file_name);
QDir directory = info.absoluteDir();
m_folder_name = directory.dirName();
if (LoadFromCache())
{
m_valid = true;
// Wii banners can only be read if there is a savefile,
// so sometimes caches don't contain banners. Let's check
// if a banner has become available after the cache was made.
if (m_banner.isNull())
{
int width, height;
std::vector<u32> buffer = DiscIO::IVolume::GetWiiBanner(&width, &height, m_title_id);
ReadBanner(buffer, width, height);
if (!m_banner.isNull())
SaveToCache();
}
}
else
{
std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(fileName.toStdString()));
if (volume != nullptr)
{
m_platform = volume->GetVolumeType();
m_short_names = ConvertLocalizedStrings(volume->GetNames(false));
m_long_names = ConvertLocalizedStrings(volume->GetNames(true));
m_descriptions = ConvertLocalizedStrings(volume->GetDescriptions());
m_company = QString::fromStdString(volume->GetCompany());
m_country = volume->GetCountry();
m_blob_type = volume->GetBlobType();
m_file_size = volume->GetRawSize();
m_volume_size = volume->GetSize();
// A temporary variable is necessary here to convert between
// quint64 (needed by GameFile's cache code) and u64 (needed by GetTitleID)
u64 title_id;
volume->GetTitleID(&title_id);
m_title_id = title_id;
m_unique_id = QString::fromStdString(volume->GetUniqueID());
m_disc_number = volume->GetDiscNumber();
m_revision = volume->GetRevision();
int width, height;
std::vector<u32> buffer = volume->GetBanner(&width, &height);
ReadBanner(buffer, width, height);
m_valid = true;
SaveToCache();
}
}
if (m_company.isEmpty() && m_unique_id.size() >= 6)
m_company = QString::fromStdString(DiscIO::GetCompanyFromID(m_unique_id.mid(4, 2).toStdString()));
if (m_valid)
{
IniFile ini = SConfig::LoadGameIni(m_unique_id.toStdString(), m_revision);
std::string issues_temp;
ini.GetIfExists("EmuState", "EmulationStateId", &m_emu_state);
ini.GetIfExists("EmuState", "EmulationIssues", &issues_temp);
m_issues = QString::fromStdString(issues_temp);
}
if (!IsValid() && IsElfOrDol())
{
m_valid = true;
m_file_size = info.size();
m_platform = DiscIO::IVolume::ELF_DOL;
}
// Metadata can optionally be stored in XML and PNG files. Typical for DOLs and ELFs, but also works
// with volumes. icon.png and meta.xml are the file names used by Homebrew Channel. The ability to use
// files with the same name as the main file is provided as an alternative for those who want to have
// multiple files in one folder instead of having a Homebrew Channel-style folder structure.
if (!ReadXML(directory.filePath(info.baseName() + QStringLiteral(".xml"))))
ReadXML(directory.filePath(QStringLiteral("meta.xml")));
QImage banner(directory.filePath(info.baseName() + QStringLiteral(".png")));
if (banner.isNull())
banner.load(directory.filePath(QStringLiteral("icon.png")));
if (!banner.isNull())
m_banner = QPixmap::fromImage(banner);
}
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;
// Increment CACHE_REVISION if the code below is modified (GameFile.cpp)
QDataStream stream(&file);
stream.setVersion(DATASTREAM_REVISION);
u32 cache_rev;
stream >> cache_rev;
if (cache_rev != CACHE_REVISION)
return false;
u32 country;
u32 platform;
u32 blob_type;
QMap<u8, QString> short_names;
QMap<u8, QString> long_names;
QMap<u8, QString> descriptions;
stream >> short_names
>> long_names
>> descriptions
>> m_company
>> m_unique_id
>> m_title_id
>> blob_type
>> m_file_size
>> m_volume_size
>> country
>> m_banner
>> platform
>> m_disc_number
>> m_revision;
m_country = (DiscIO::IVolume::ECountry)country;
m_platform = (DiscIO::IVolume::EPlatform)platform;
m_blob_type = (DiscIO::BlobType)blob_type;
m_short_names = CastLocalizedStrings<DiscIO::IVolume::ELanguage>(short_names);
m_long_names = CastLocalizedStrings<DiscIO::IVolume::ELanguage>(long_names);
m_descriptions = CastLocalizedStrings<DiscIO::IVolume::ELanguage>(descriptions);
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;
// Increment CACHE_REVISION if the code below is modified (GameFile.cpp)
QDataStream stream(&file);
stream.setVersion(DATASTREAM_REVISION);
stream << CACHE_REVISION;
stream << CastLocalizedStrings<u8>(m_short_names)
<< CastLocalizedStrings<u8>(m_long_names)
<< CastLocalizedStrings<u8>(m_descriptions)
<< m_company
<< m_unique_id
<< m_title_id
<< (u32)m_blob_type
<< m_file_size
<< m_volume_size
<< (u32)m_country
<< m_banner
<< (u32)m_platform
<< m_disc_number
<< m_revision;
}
bool GameFile::IsElfOrDol() const
{
return m_file_name.endsWith(QStringLiteral(".elf"), Qt::CaseInsensitive) ||
m_file_name.endsWith(QStringLiteral(".dol"), Qt::CaseInsensitive);
}
QString GameFile::CreateCacheFilename() const
{
std::string filename, pathname, extension;
SplitPath(m_file_name.toStdString(), &pathname, &filename, &extension);
if (filename.empty())
return QStringLiteral(""); // 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_%llx.qcache",
extension.c_str(), HashFletcher((const u8*)pathname.c_str(), pathname.size()),
(unsigned long long)File::GetSize(m_file_name.toStdString())));
QString fullname = QString::fromStdString(File::GetUserPath(D_CACHE_IDX));
fullname += QString::fromStdString(filename);
return fullname;
}
// Outputs to m_banner
void GameFile::ReadBanner(const std::vector<u32>& buffer, int width, int 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())
m_banner = QPixmap::fromImage(banner);
}
// Outputs to m_short_names, m_long_names, m_descriptions, m_company.
// Returns whether a file was found, not whether it contained useful data.
bool GameFile::ReadXML(const QString& file_path)
{
// The format of Homebrew Channel XML metadata is described at:
// http://wiibrew.org/wiki/Homebrew_Channel#Adding_Text
QFile file(file_path);
if (!file.open(QIODevice::ReadOnly))
return false;
QXmlStreamReader reader(&file);
if (reader.readNextStartElement() && reader.name() == QStringLiteral("app"))
{
while (reader.readNextStartElement())
{
QStringRef name = reader.name();
if (name == QStringLiteral("name"))
{
m_short_names = { { DiscIO::IVolume::LANGUAGE_UNKNOWN, reader.readElementText() } };
m_long_names = m_short_names;
}
else if (name == QStringLiteral("short_description"))
{
m_descriptions = { { DiscIO::IVolume::LANGUAGE_UNKNOWN, reader.readElementText() } };
}
else if (name == QStringLiteral("coder"))
{
m_company = reader.readElementText();
}
else
{
reader.skipCurrentElement();
}
// Elements that we aren't using:
// version (can be written in any format)
// release_date (YYYYmmddHHMMSS format)
// long_description (can be several screens long!)
}
}
return true;
}
QString GameFile::GetDescription(DiscIO::IVolume::ELanguage language) const
{
return GetLanguageString(language, m_descriptions);
}
QString GameFile::GetDescription() const
{
bool wii = m_platform != DiscIO::IVolume::GAMECUBE_DISC;
return GetDescription(SConfig::GetInstance().GetCurrentLanguage(wii));
}
QString GameFile::GetName(bool prefer_long, DiscIO::IVolume::ELanguage language) const
{
return GetLanguageString(language, prefer_long ? m_long_names : m_short_names);
}
QString GameFile::GetName(bool prefer_long) const
{
bool wii = m_platform != DiscIO::IVolume::GAMECUBE_DISC;
QString name = GetName(prefer_long, SConfig::GetInstance().GetCurrentLanguage(wii));
if (name.isEmpty())
{
// No usable name, return filename (better than nothing)
std::string name_temp, extension;
SplitPath(m_file_name.toStdString(), nullptr, &name_temp, &extension);
name = QString::fromStdString(name_temp + extension);
}
return name;
}
const QString GameFile::GetWiiFSPath() const
{
std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(m_file_name.toStdString()));
QString ret;
if (volume == nullptr)
return ret;
if (volume->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC)
{
u64 title_id;
volume->GetTitleID(&title_id);
std::string path = StringFromFormat("%s/title/%08x/%08x/data/",
File::GetUserPath(D_WIIROOT_IDX).c_str(), (u32)(title_id >> 32), (u32)title_id);
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);
}
return ret;
}

View File

@ -1,95 +0,0 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <QMap>
#include <QPixmap>
#include <QString>
#include <string>
#include "DiscIO/Blob.h"
#include "DiscIO/Volume.h"
#include "DolphinQt/Utils/Resources.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 GetName(bool prefer_long, DiscIO::IVolume::ELanguage language) const;
QString GetName(bool prefer_long) const;
QString GetDescription(DiscIO::IVolume::ELanguage language) const;
QString GetDescription() const;
QString GetCompany() const { return m_company; }
u16 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; }
DiscIO::IVolume::EPlatform GetPlatform() const { return m_platform; }
DiscIO::BlobType GetBlobType() const { return m_blob_type; }
const QString GetIssues() const { return m_issues; }
int GetEmuState() const { return m_emu_state; }
bool IsCompressed() const
{
return m_blob_type == DiscIO::BlobType::GCZ || m_blob_type == DiscIO::BlobType::CISO ||
m_blob_type == DiscIO::BlobType::WBFS;
}
u64 GetFileSize() const { return m_file_size; }
u64 GetVolumeSize() const { return m_volume_size; }
// 0 is the first disc, 1 is the second disc
u8 GetDiscNumber() const { return m_disc_number; }
const QPixmap GetBitmap() const
{
if (m_banner.isNull())
return Resources::GetPixmap(Resources::BANNER_MISSING);
return m_banner;
}
private:
QString m_file_name;
QString m_folder_name;
QMap<DiscIO::IVolume::ELanguage, QString> m_short_names;
QMap<DiscIO::IVolume::ELanguage, QString> m_long_names;
QMap<DiscIO::IVolume::ELanguage, QString> m_descriptions;
QString m_company;
QString m_unique_id;
quint64 m_title_id;
QString m_issues;
int m_emu_state = 0;
quint64 m_file_size = 0;
quint64 m_volume_size = 0;
DiscIO::IVolume::ECountry m_country = DiscIO::IVolume::COUNTRY_UNKNOWN;
DiscIO::IVolume::EPlatform m_platform;
DiscIO::BlobType m_blob_type;
u16 m_revision = 0;
QPixmap m_banner;
bool m_valid = false;
u8 m_disc_number = 0;
bool LoadFromCache();
void SaveToCache();
bool IsElfOrDol() const;
QString CreateCacheFilename() const;
// Outputs to m_banner
void ReadBanner(const std::vector<u32>& buffer, int width, int height);
// Outputs to m_short_names, m_long_names, m_descriptions, m_company.
// Returns whether a file was found, not whether it contained useful data.
bool ReadXML(const QString& file_path);
};

View File

@ -1,95 +0,0 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <memory>
#include "ui_GameGrid.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<Ui::DGameGrid>();
m_ui->setupUi(this);
SetViewStyle(STYLE_GRID);
connect(this, &QListWidget::itemActivated, this, &DGameGrid::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* gameItem)
{
if (m_items.values().contains(gameItem))
return;
m_items.values().append(gameItem);
QListWidgetItem* i = new QListWidgetItem;
i->setIcon(QIcon(gameItem->GetBitmap()
.scaled(GRID_BANNER_WIDTH, GRID_BANNER_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
i->setText(gameItem->GetName(false));
if (gameItem->IsCompressed())
i->setTextColor(QColor("#00F"));
addItem(i);
m_items.insert(i, gameItem);
}
void DGameGrid::RemoveGame(GameFile* gameItem)
{
if (!m_items.values().contains(gameItem))
return;
QListWidgetItem* i = m_items.key(gameItem);
m_items.remove(i);
delete i;
}

View File

@ -1,44 +0,0 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <QListWidget>
#include "DolphinQt/GameList/GameTracker.h"
// Predefinitions
namespace Ui
{
class DGameGrid;
}
class DGameGrid final : 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* gameItem);
virtual void RemoveGame(GameFile* gameItem);
signals:
void StartGame();
private:
std::unique_ptr<Ui::DGameGrid> m_ui;
QMap<QListWidgetItem*, GameFile*> m_items;
GameListStyle m_current_style;
};

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DGameGrid</class>
<widget class="QListWidget" name="DGameGrid">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>254</width>
<height>190</height>
</rect>
</property>
<property name="isWrapping" stdset="0">
<bool>true</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,240 +0,0 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "Common/CDUtils.h"
#include "Common/FileSearch.h"
#include "Common/FileUtil.h"
#include "Core/ConfigManager.h"
#include "DolphinQt/GameList/GameGrid.h"
#include "DolphinQt/GameList/GameTracker.h"
#include "DolphinQt/GameList/GameTree.h"
void AbstractGameList::AddGames(QList<GameFile*> items)
{
for (GameFile* o : items)
AddGame(o);
}
void AbstractGameList::RemoveGames(QList<GameFile*> items)
{
for (GameFile* o : items)
RemoveGame(o);
}
DGameTracker::DGameTracker(QWidget* parent_widget)
: QStackedWidget(parent_widget),
m_watcher(new QFileSystemWatcher(this))
{
connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &DGameTracker::ScanForGames);
m_tree_widget = new DGameTree(this);
addWidget(m_tree_widget);
connect(m_tree_widget, &DGameTree::StartGame, this, &DGameTracker::StartGame);
m_grid_widget = new DGameGrid(this);
addWidget(m_grid_widget);
connect(m_grid_widget, &DGameGrid::StartGame, this, &DGameTracker::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);
delete m_watcher;
m_watcher = new QFileSystemWatcher(this);
for (std::string dir : SConfig::GetInstance().m_ISOFolder)
m_watcher->addPath(QString::fromStdString(dir));
if (SConfig::GetInstance().m_RecursiveISOFolder)
{
for (std::string dir : FindSubdirectories(SConfig::GetInstance().m_ISOFolder, /*recursive*/ true))
m_watcher->addPath(QString::fromStdString(dir));
}
std::vector<std::string> 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");
if (SConfig::GetInstance().m_ListElfDol)
{
exts.push_back(".dol");
exts.push_back(".elf");
}
auto rFilenames = DoFileSearch(exts, SConfig::GetInstance().m_ISOFolder, SConfig::GetInstance().m_RecursiveISOFolder);
QList<GameFile*> 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_EUROPE:
if (!SConfig::GetInstance().m_ListPal)
list = false;
break;
case DiscIO::IVolume::COUNTRY_FRANCE:
if (!SConfig::GetInstance().m_ListFrance)
list = false;
break;
case DiscIO::IVolume::COUNTRY_GERMANY:
if (!SConfig::GetInstance().m_ListGermany)
list = false;
break;
case DiscIO::IVolume::COUNTRY_ITALY:
if (!SConfig::GetInstance().m_ListItaly)
list = false;
break;
case DiscIO::IVolume::COUNTRY_JAPAN:
if (!SConfig::GetInstance().m_ListJap)
list = false;
break;
case DiscIO::IVolume::COUNTRY_KOREA:
if (!SConfig::GetInstance().m_ListKorea)
list = false;
break;
case DiscIO::IVolume::COUNTRY_NETHERLANDS:
if (!SConfig::GetInstance().m_ListNetherlands)
list = false;
break;
case DiscIO::IVolume::COUNTRY_RUSSIA:
if (!SConfig::GetInstance().m_ListRussia)
list = false;
break;
case DiscIO::IVolume::COUNTRY_SPAIN:
if (!SConfig::GetInstance().m_ListSpain)
list = false;
break;
case DiscIO::IVolume::COUNTRY_TAIWAN:
if (!SConfig::GetInstance().m_ListTaiwan)
list = false;
break;
case DiscIO::IVolume::COUNTRY_USA:
if (!SConfig::GetInstance().m_ListUsa)
list = false;
break;
case DiscIO::IVolume::COUNTRY_WORLD:
if (!SConfig::GetInstance().m_ListWorld)
list = false;
break;
case DiscIO::IVolume::COUNTRY_UNKNOWN:
default:
if (!SConfig::GetInstance().m_ListUnknown)
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<GameFile*> 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;
}
}
}
}

View File

@ -1,68 +0,0 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <QFileSystemWatcher>
#include <QList>
#include <QMap>
#include <QStackedWidget>
#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<GameFile*> items);
virtual void RemoveGame(GameFile* item) = 0;
void RemoveGames(QList<GameFile*> items);
};
class DGameTracker final : 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<QString, GameFile*> m_games;
QFileSystemWatcher* m_watcher;
GameListStyle m_current_style;
DGameGrid* m_grid_widget = nullptr;
DGameTree* m_tree_widget = nullptr;
};

View File

@ -1,167 +0,0 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <memory>
#include "ui_GameTree.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<Ui::DGameTree>();
m_ui->setupUi(this);
SetViewStyle(STYLE_TREE);
setIconSize(QSize(BANNER_WIDTH, BANNER_HEIGHT));
sortByColumn(COL_TITLE, Qt::AscendingOrder);
connect(this, &QTreeWidget::itemActivated, this, &DGameTree::ItemActivated);
}
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(true));
i->setText(COL_DESCRIPTION, item->GetDescription());
i->setIcon(COL_REGION, QIcon(Resources::GetRegionPixmap(item->GetCountry())));
i->setText(COL_SIZE, NiceSizeFormat(item->GetFileSize()));
i->setIcon(COL_STATE, QIcon(Resources::GetRatingPixmap(item->GetEmuState())));
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);
}

View File

@ -1,62 +0,0 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <QTreeWidget>
#include "DolphinQt/GameList/GameTracker.h"
// Predefinitions
namespace Ui
{
class DGameTree;
}
class DGameTree final : 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<Ui::DGameTree> m_ui;
GameListStyle m_current_style;
QMap<QTreeWidgetItem*, GameFile*> m_items;
QMap<QString, QTreeWidgetItem*> m_path_nodes;
void RebuildTree();
void ResizeAllCols();
};

View File

@ -1,54 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DGameTree</class>
<widget class="QTreeWidget" name="DGameTree">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>396</width>
<height>296</height>
</rect>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Banner</string>
</property>
</column>
<column>
<property name="text">
<string>Title</string>
</property>
</column>
<column>
<property name="text">
<string>Description</string>
</property>
</column>
<column>
<property name="text">
<string>Region</string>
</property>
</column>
<column>
<property name="text">
<string>Size</string>
</property>
</column>
<column>
<property name="text">
<string>State</string>
</property>
</column>
</widget>
<resources/>
<connections/>
</ui>