NOISSUE tabs -> spaces

This commit is contained in:
Petr Mrázek
2018-07-15 14:51:05 +02:00
parent 03280cc62e
commit bbb3b3e6f6
577 changed files with 51938 additions and 51938 deletions

View File

@ -10,213 +10,213 @@
#include "FtbListModel.h"
FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
: QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
{
ftbFetchTask = new FtbPackFetchTask();
ftbFetchTask = new FtbPackFetchTask();
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
{
publicFilterModel = new FtbFilterModel(this);
publicListModel = new FtbListModel(this);
publicFilterModel->setSourceModel(publicListModel);
{
publicFilterModel = new FtbFilterModel(this);
publicListModel = new FtbListModel(this);
publicFilterModel->setSourceModel(publicListModel);
ui->publicPackList->setModel(publicFilterModel);
ui->publicPackList->setSortingEnabled(true);
ui->publicPackList->header()->hide();
ui->publicPackList->setIndentation(0);
ui->publicPackList->setIconSize(QSize(42, 42));
ui->publicPackList->setModel(publicFilterModel);
ui->publicPackList->setSortingEnabled(true);
ui->publicPackList->header()->hide();
ui->publicPackList->setIndentation(0);
ui->publicPackList->setIconSize(QSize(42, 42));
for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
{
ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
}
for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
{
ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
}
ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
}
ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
}
{
thirdPartyFilterModel = new FtbFilterModel(this);
thirdPartyModel = new FtbListModel(this);
thirdPartyFilterModel->setSourceModel(thirdPartyModel);
{
thirdPartyFilterModel = new FtbFilterModel(this);
thirdPartyModel = new FtbListModel(this);
thirdPartyFilterModel->setSourceModel(thirdPartyModel);
ui->thirdPartyPackList->setModel(thirdPartyFilterModel);
ui->thirdPartyPackList->setSortingEnabled(true);
ui->thirdPartyPackList->header()->hide();
ui->thirdPartyPackList->setIndentation(0);
ui->thirdPartyPackList->setIconSize(QSize(42, 42));
ui->thirdPartyPackList->setModel(thirdPartyFilterModel);
ui->thirdPartyPackList->setSortingEnabled(true);
ui->thirdPartyPackList->header()->hide();
ui->thirdPartyPackList->setIndentation(0);
ui->thirdPartyPackList->setIconSize(QSize(42, 42));
thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
}
thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
}
ui->packVersionSelection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->packVersionSelection->view()->parentWidget()->setMaximumHeight(300);
ui->packVersionSelection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->packVersionSelection->view()->parentWidget()->setMaximumHeight(300);
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
connect(ui->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
connect(ui->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
ui->modpackInfo->setOpenExternalLinks(true);
ui->modpackInfo->setOpenExternalLinks(true);
ui->publicPackList->selectionModel()->reset();
ui->thirdPartyPackList->selectionModel()->reset();
ui->publicPackList->selectionModel()->reset();
ui->thirdPartyPackList->selectionModel()->reset();
}
FTBPage::~FTBPage()
{
delete ui;
if(ftbFetchTask) {
ftbFetchTask->deleteLater();
}
delete ui;
if(ftbFetchTask) {
ftbFetchTask->deleteLater();
}
}
bool FTBPage::shouldDisplay() const
{
return true;
return true;
}
void FTBPage::openedImpl()
{
if(!initialized)
{
connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
ftbFetchTask->fetch();
initialized = true;
}
suggestCurrent();
if(!initialized)
{
connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
ftbFetchTask->fetch();
initialized = true;
}
suggestCurrent();
}
void FTBPage::suggestCurrent()
{
if(isOpened)
{
if(!selected.broken)
{
dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
if(selected.type == FtbPackType::Public) {
publicListModel->getLogo(selected.logo, [this](QString logo){
dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
});
} else if (selected.type == FtbPackType::ThirdParty) {
thirdPartyModel->getLogo(selected.logo, [this](QString logo){
dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
});
}
}
else
{
dialog->setSuggestedPack();
}
}
if(isOpened)
{
if(!selected.broken)
{
dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
if(selected.type == FtbPackType::Public) {
publicListModel->getLogo(selected.logo, [this](QString logo){
dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
});
} else if (selected.type == FtbPackType::ThirdParty) {
thirdPartyModel->getLogo(selected.logo, [this](QString logo){
dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
});
}
}
else
{
dialog->setSuggestedPack();
}
}
}
void FTBPage::ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks)
{
publicListModel->fill(publicPacks);
thirdPartyModel->fill(thirdPartyPacks);
publicListModel->fill(publicPacks);
thirdPartyModel->fill(thirdPartyPacks);
}
void FTBPage::ftbPackDataDownloadFailed(QString reason)
{
//TODO: Display the error
//TODO: Display the error
}
void FTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
{
if(!now.isValid())
{
onPackSelectionChanged();
return;
}
FtbModpack selectedPack = publicFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
onPackSelectionChanged(&selectedPack);
if(!now.isValid())
{
onPackSelectionChanged();
return;
}
FtbModpack selectedPack = publicFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
onPackSelectionChanged(&selectedPack);
}
void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
{
if(!now.isValid())
{
onPackSelectionChanged();
return;
}
FtbModpack selectedPack = thirdPartyFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
onPackSelectionChanged(&selectedPack);
if(!now.isValid())
{
onPackSelectionChanged();
return;
}
FtbModpack selectedPack = thirdPartyFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
onPackSelectionChanged(&selectedPack);
}
void FTBPage::onPackSelectionChanged(FtbModpack* pack)
{
ui->packVersionSelection->clear();
if(pack)
{
ui->modpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" + "<br>Minecraft " + pack->mcVersion + "<br>"
"<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>") + "</li></ul>");
bool currentAdded = false;
ui->packVersionSelection->clear();
if(pack)
{
ui->modpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" + "<br>Minecraft " + pack->mcVersion + "<br>"
"<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>") + "</li></ul>");
bool currentAdded = false;
for(int i = 0; i < pack->oldVersions.size(); i++)
{
if(pack->currentVersion == pack->oldVersions.at(i))
{
currentAdded = true;
}
ui->packVersionSelection->addItem(pack->oldVersions.at(i));
}
for(int i = 0; i < pack->oldVersions.size(); i++)
{
if(pack->currentVersion == pack->oldVersions.at(i))
{
currentAdded = true;
}
ui->packVersionSelection->addItem(pack->oldVersions.at(i));
}
if(!currentAdded)
{
ui->packVersionSelection->addItem(pack->currentVersion);
}
selected = *pack;
}
suggestCurrent();
if(!currentAdded)
{
ui->packVersionSelection->addItem(pack->currentVersion);
}
selected = *pack;
}
suggestCurrent();
}
void FTBPage::onVersionSelectionItemChanged(QString data)
{
if(data.isNull() || data.isEmpty())
{
selectedVersion = "";
return;
}
if(data.isNull() || data.isEmpty())
{
selectedVersion = "";
return;
}
selectedVersion = data;
suggestCurrent();
selectedVersion = data;
suggestCurrent();
}
void FTBPage::onSortingSelectionChanged(QString data)
{
FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
publicFilterModel->setSorting(toSet);
thirdPartyFilterModel->setSorting(toSet);
FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
publicFilterModel->setSorting(toSet);
thirdPartyFilterModel->setSorting(toSet);
}
void FTBPage::onTabChanged(int tab)
{
FtbFilterModel* currentModel = nullptr;
QTreeView* currentList = nullptr;
if (tab == 0)
{
currentModel = publicFilterModel;
currentList = ui->publicPackList;
}
else
{
currentModel = thirdPartyFilterModel;
currentList = ui->thirdPartyPackList;
}
QModelIndex idx = currentList->currentIndex();
if(idx.isValid())
{
auto pack = currentModel->data(idx, Qt::UserRole).value<FtbModpack>();
onPackSelectionChanged(&pack);
}
else
{
onPackSelectionChanged();
}
FtbFilterModel* currentModel = nullptr;
QTreeView* currentList = nullptr;
if (tab == 0)
{
currentModel = publicFilterModel;
currentList = ui->publicPackList;
}
else
{
currentModel = thirdPartyFilterModel;
currentList = ui->thirdPartyPackList;
}
QModelIndex idx = currentList->currentIndex();
if(idx.isValid())
{
auto pack = currentModel->data(idx, Qt::UserRole).value<FtbModpack>();
onPackSelectionChanged(&pack);
}
else
{
onPackSelectionChanged();
}
}

View File

@ -34,59 +34,59 @@ class NewInstanceDialog;
class FTBPage : public QWidget, public BasePage
{
Q_OBJECT
Q_OBJECT
public:
explicit FTBPage(NewInstanceDialog * dialog, QWidget *parent = 0);
virtual ~FTBPage();
QString displayName() const override
{
return tr("FTB Legacy");
}
QIcon icon() const override
{
return MMC->getThemedIcon("ftb_logo");
}
QString id() const override
{
return "ftb";
}
QString helpPage() const override
{
return "FTB-platform";
}
bool shouldDisplay() const override;
void openedImpl() override;
explicit FTBPage(NewInstanceDialog * dialog, QWidget *parent = 0);
virtual ~FTBPage();
QString displayName() const override
{
return tr("FTB Legacy");
}
QIcon icon() const override
{
return MMC->getThemedIcon("ftb_logo");
}
QString id() const override
{
return "ftb";
}
QString helpPage() const override
{
return "FTB-platform";
}
bool shouldDisplay() const override;
void openedImpl() override;
private:
void suggestCurrent();
void onPackSelectionChanged(FtbModpack *pack = nullptr);
void suggestCurrent();
void onPackSelectionChanged(FtbModpack *pack = nullptr);
private slots:
void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
void ftbPackDataDownloadFailed(QString reason);
void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
void ftbPackDataDownloadFailed(QString reason);
void onSortingSelectionChanged(QString data);
void onVersionSelectionItemChanged(QString data);
void onSortingSelectionChanged(QString data);
void onVersionSelectionItemChanged(QString data);
void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second);
void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second);
void onTabChanged(int tab);
void onTabChanged(int tab);
private:
bool initialized = false;
FtbModpack selected;
QString selectedVersion;
bool initialized = false;
FtbModpack selected;
QString selectedVersion;
FtbListModel* publicListModel = nullptr;
FtbFilterModel* publicFilterModel = nullptr;
FtbListModel* publicListModel = nullptr;
FtbFilterModel* publicFilterModel = nullptr;
FtbListModel *thirdPartyModel = nullptr;
FtbFilterModel *thirdPartyFilterModel = nullptr;
FtbListModel *thirdPartyModel = nullptr;
FtbFilterModel *thirdPartyFilterModel = nullptr;
FtbPackFetchTask *ftbFetchTask = nullptr;
NewInstanceDialog* dialog = nullptr;
FtbPackFetchTask *ftbFetchTask = nullptr;
NewInstanceDialog* dialog = nullptr;
Ui::FTBPage *ui = nullptr;
Ui::FTBPage *ui = nullptr;
};

View File

@ -12,54 +12,54 @@
FtbFilterModel::FtbFilterModel(QObject *parent) : QSortFilterProxyModel(parent)
{
currentSorting = Sorting::ByGameVersion;
sortings.insert(tr("Sort by name"), Sorting::ByName);
sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion);
currentSorting = Sorting::ByGameVersion;
sortings.insert(tr("Sort by name"), Sorting::ByName);
sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion);
}
bool FtbFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
FtbModpack leftPack = sourceModel()->data(left, Qt::UserRole).value<FtbModpack>();
FtbModpack rightPack = sourceModel()->data(right, Qt::UserRole).value<FtbModpack>();
FtbModpack leftPack = sourceModel()->data(left, Qt::UserRole).value<FtbModpack>();
FtbModpack rightPack = sourceModel()->data(right, Qt::UserRole).value<FtbModpack>();
if(currentSorting == Sorting::ByGameVersion) {
Version lv(leftPack.mcVersion);
Version rv(rightPack.mcVersion);
return lv < rv;
if(currentSorting == Sorting::ByGameVersion) {
Version lv(leftPack.mcVersion);
Version rv(rightPack.mcVersion);
return lv < rv;
} else if(currentSorting == Sorting::ByName) {
return Strings::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
}
} else if(currentSorting == Sorting::ByName) {
return Strings::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
}
//UHM, some inavlid value set?!
qWarning() << "Invalid sorting set!";
return true;
//UHM, some inavlid value set?!
qWarning() << "Invalid sorting set!";
return true;
}
bool FtbFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
return true;
return true;
}
const QMap<QString, FtbFilterModel::Sorting> FtbFilterModel::getAvailableSortings()
{
return sortings;
return sortings;
}
QString FtbFilterModel::translateCurrentSorting()
{
return sortings.key(currentSorting);
return sortings.key(currentSorting);
}
void FtbFilterModel::setSorting(Sorting s)
{
currentSorting = s;
invalidate();
currentSorting = s;
invalidate();
}
FtbFilterModel::Sorting FtbFilterModel::getCurrentSorting()
{
return currentSorting;
return currentSorting;
}
FtbListModel::FtbListModel(QObject *parent) : QAbstractListModel(parent)
@ -72,128 +72,128 @@ FtbListModel::~FtbListModel()
QString FtbListModel::translatePackType(FtbPackType type) const
{
if(type == FtbPackType::Public) {
return tr("Public Modpack");
} else if(type == FtbPackType::ThirdParty) {
return tr("Third Party Modpack");
} else if(type == FtbPackType::Private) {
return tr("Private Modpack");
} else {
return tr("Unknown Type");
}
if(type == FtbPackType::Public) {
return tr("Public Modpack");
} else if(type == FtbPackType::ThirdParty) {
return tr("Third Party Modpack");
} else if(type == FtbPackType::Private) {
return tr("Private Modpack");
} else {
return tr("Unknown Type");
}
}
int FtbListModel::rowCount(const QModelIndex &parent) const
{
return modpacks.size();
return modpacks.size();
}
int FtbListModel::columnCount(const QModelIndex &parent) const
{
return 1;
return 1;
}
QVariant FtbListModel::data(const QModelIndex &index, int role) const
{
int pos = index.row();
if(pos >= modpacks.size() || pos < 0 || !index.isValid()) {
return QString("INVALID INDEX %1").arg(pos);
}
int pos = index.row();
if(pos >= modpacks.size() || pos < 0 || !index.isValid()) {
return QString("INVALID INDEX %1").arg(pos);
}
FtbModpack pack = modpacks.at(pos);
if(role == Qt::DisplayRole) {
return pack.name + "\n" + translatePackType(pack.type);
} else if (role == Qt::ToolTipRole) {
if(pack.description.length() > 100) {
//some magic to prevent to long tooltips and replace html linebreaks
QString edit = pack.description.left(97);
edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
return edit;
FtbModpack pack = modpacks.at(pos);
if(role == Qt::DisplayRole) {
return pack.name + "\n" + translatePackType(pack.type);
} else if (role == Qt::ToolTipRole) {
if(pack.description.length() > 100) {
//some magic to prevent to long tooltips and replace html linebreaks
QString edit = pack.description.left(97);
edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
return edit;
}
return pack.description;
} else if(role == Qt::DecorationRole) {
if(m_logoMap.contains(pack.logo)) {
return (m_logoMap.value(pack.logo));
}
QIcon icon = MMC->getThemedIcon("screenshot-placeholder");
((FtbListModel *)this)->requestLogo(pack.logo);
return icon;
} else if(role == Qt::TextColorRole) {
if(pack.broken) {
//FIXME: Hardcoded color
return QColor(255, 0, 50);
} else if(pack.bugged) {
//FIXME: Hardcoded color
//bugged pack, currently only indicates bugged xml
return QColor(244, 229, 66);
}
} else if(role == Qt::UserRole) {
QVariant v;
v.setValue(pack);
return v;
}
}
return pack.description;
} else if(role == Qt::DecorationRole) {
if(m_logoMap.contains(pack.logo)) {
return (m_logoMap.value(pack.logo));
}
QIcon icon = MMC->getThemedIcon("screenshot-placeholder");
((FtbListModel *)this)->requestLogo(pack.logo);
return icon;
} else if(role == Qt::TextColorRole) {
if(pack.broken) {
//FIXME: Hardcoded color
return QColor(255, 0, 50);
} else if(pack.bugged) {
//FIXME: Hardcoded color
//bugged pack, currently only indicates bugged xml
return QColor(244, 229, 66);
}
} else if(role == Qt::UserRole) {
QVariant v;
v.setValue(pack);
return v;
}
return QVariant();
return QVariant();
}
void FtbListModel::fill(FtbModpackList modpacks)
{
beginResetModel();
this->modpacks = modpacks;
endResetModel();
beginResetModel();
this->modpacks = modpacks;
endResetModel();
}
FtbModpack FtbListModel::at(int row)
{
return modpacks.at(row);
return modpacks.at(row);
}
void FtbListModel::logoLoaded(QString logo, QIcon out)
{
m_loadingLogos.removeAll(logo);
m_logoMap.insert(logo, out);
emit dataChanged(createIndex(0, 0), createIndex(1, 0));
m_loadingLogos.removeAll(logo);
m_logoMap.insert(logo, out);
emit dataChanged(createIndex(0, 0), createIndex(1, 0));
}
void FtbListModel::logoFailed(QString logo)
{
m_failedLogos.append(logo);
m_loadingLogos.removeAll(logo);
m_failedLogos.append(logo);
m_loadingLogos.removeAll(logo);
}
void FtbListModel::requestLogo(QString file)
{
if(m_loadingLogos.contains(file) || m_failedLogos.contains(file)) {
return;
}
if(m_loadingLogos.contains(file) || m_failedLogos.contains(file)) {
return;
}
MetaEntryPtr entry = ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
NetJob *job = new NetJob(QString("FTB Icon Download for %1").arg(file));
job->addNetAction(Net::Download::makeCached(QUrl(QString("https://ftb.cursecdn.com/FTB2/static/%1").arg(file)), entry));
MetaEntryPtr entry = ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
NetJob *job = new NetJob(QString("FTB Icon Download for %1").arg(file));
job->addNetAction(Net::Download::makeCached(QUrl(QString("https://ftb.cursecdn.com/FTB2/static/%1").arg(file)), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]{
emit logoLoaded(file, QIcon(fullPath));
if(waitingCallbacks.contains(file)) {
waitingCallbacks.value(file)(fullPath);
}
});
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]{
emit logoLoaded(file, QIcon(fullPath));
if(waitingCallbacks.contains(file)) {
waitingCallbacks.value(file)(fullPath);
}
});
QObject::connect(job, &NetJob::failed, this, [this, file]{
emit logoFailed(file);
});
QObject::connect(job, &NetJob::failed, this, [this, file]{
emit logoFailed(file);
});
job->start();
job->start();
m_loadingLogos.append(file);
m_loadingLogos.append(file);
}
void FtbListModel::getLogo(const QString &logo, LogoCallback callback)
{
if(m_logoMap.contains(logo)) {
callback(ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
} else {
requestLogo(logo);
}
if(m_logoMap.contains(logo)) {
callback(ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
} else {
requestLogo(logo);
}
}

View File

@ -16,53 +16,53 @@ typedef std::function<void(QString)> LogoCallback;
class FtbFilterModel : public QSortFilterProxyModel
{
public:
FtbFilterModel(QObject* parent = Q_NULLPTR);
enum Sorting {
ByName,
ByGameVersion
};
const QMap<QString, Sorting> getAvailableSortings();
QString translateCurrentSorting();
void setSorting(Sorting sorting);
Sorting getCurrentSorting();
FtbFilterModel(QObject* parent = Q_NULLPTR);
enum Sorting {
ByName,
ByGameVersion
};
const QMap<QString, Sorting> getAvailableSortings();
QString translateCurrentSorting();
void setSorting(Sorting sorting);
Sorting getCurrentSorting();
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
private:
QMap<QString, Sorting> sortings;
Sorting currentSorting;
QMap<QString, Sorting> sortings;
Sorting currentSorting;
};
class FtbListModel : public QAbstractListModel
{
Q_OBJECT
Q_OBJECT
private:
FtbModpackList modpacks;
QStringList m_failedLogos;
QStringList m_loadingLogos;
FtbLogoMap m_logoMap;
QMap<QString, LogoCallback> waitingCallbacks;
FtbModpackList modpacks;
QStringList m_failedLogos;
QStringList m_loadingLogos;
FtbLogoMap m_logoMap;
QMap<QString, LogoCallback> waitingCallbacks;
void requestLogo(QString file);
QString translatePackType(FtbPackType type) const;
void requestLogo(QString file);
QString translatePackType(FtbPackType type) const;
private slots:
void logoFailed(QString logo);
void logoLoaded(QString logo, QIcon out);
void logoFailed(QString logo);
void logoLoaded(QString logo, QIcon out);
public:
FtbListModel(QObject *parent);
~FtbListModel();
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
FtbListModel(QObject *parent);
~FtbListModel();
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
void fill(FtbModpackList modpacks);
void fill(FtbModpackList modpacks);
FtbModpack at(int row);
void getLogo(const QString &logo, LogoCallback callback);
FtbModpack at(int row);
void getLogo(const QString &logo, LogoCallback callback);
};

View File

@ -13,114 +13,114 @@
class UrlValidator : public QValidator
{
public:
using QValidator::QValidator;
using QValidator::QValidator;
State validate(QString &in, int &pos) const
{
const QUrl url(in);
if (url.isValid() && !url.isRelative() && !url.isEmpty())
{
return Acceptable;
}
else if (QFile::exists(in))
{
return Acceptable;
}
else
{
return Intermediate;
}
}
State validate(QString &in, int &pos) const
{
const QUrl url(in);
if (url.isValid() && !url.isRelative() && !url.isEmpty())
{
return Acceptable;
}
else if (QFile::exists(in))
{
return Acceptable;
}
else
{
return Intermediate;
}
}
};
ImportPage::ImportPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), ui(new Ui::ImportPage), dialog(dialog)
: QWidget(parent), ui(new Ui::ImportPage), dialog(dialog)
{
ui->setupUi(this);
ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
connect(ui->modpackEdit, &QLineEdit::textChanged, this, &ImportPage::updateState);
ui->setupUi(this);
ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
connect(ui->modpackEdit, &QLineEdit::textChanged, this, &ImportPage::updateState);
}
ImportPage::~ImportPage()
{
delete ui;
delete ui;
}
bool ImportPage::shouldDisplay() const
{
return true;
return true;
}
void ImportPage::openedImpl()
{
updateState();
updateState();
}
void ImportPage::updateState()
{
if(!isOpened)
{
return;
}
if(ui->modpackEdit->hasAcceptableInput())
{
QString input = ui->modpackEdit->text();
auto url = QUrl::fromUserInput(input);
if(url.isLocalFile())
{
// FIXME: actually do some validation of what's inside here... this is fake AF
QFileInfo fi(input);
if(fi.exists() && fi.suffix() == "zip")
{
QFileInfo fi(url.fileName());
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
}
}
else
{
// hook, line and sinker.
QFileInfo fi(url.fileName());
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
}
}
else
{
dialog->setSuggestedPack();
}
if(!isOpened)
{
return;
}
if(ui->modpackEdit->hasAcceptableInput())
{
QString input = ui->modpackEdit->text();
auto url = QUrl::fromUserInput(input);
if(url.isLocalFile())
{
// FIXME: actually do some validation of what's inside here... this is fake AF
QFileInfo fi(input);
if(fi.exists() && fi.suffix() == "zip")
{
QFileInfo fi(url.fileName());
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
}
}
else
{
// hook, line and sinker.
QFileInfo fi(url.fileName());
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
}
}
else
{
dialog->setSuggestedPack();
}
}
void ImportPage::setUrl(const QString& url)
{
ui->modpackEdit->setText(url);
updateState();
ui->modpackEdit->setText(url);
updateState();
}
void ImportPage::on_modpackBtn_clicked()
{
const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), tr("Zip (*.zip)"));
if (url.isValid())
{
if (url.isLocalFile())
{
ui->modpackEdit->setText(url.toLocalFile());
}
else
{
ui->modpackEdit->setText(url.toString());
}
}
const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), tr("Zip (*.zip)"));
if (url.isValid())
{
if (url.isLocalFile())
{
ui->modpackEdit->setText(url.toLocalFile());
}
else
{
ui->modpackEdit->setText(url.toString());
}
}
}
QUrl ImportPage::modpackUrl() const
{
const QUrl url(ui->modpackEdit->text());
if (url.isValid() && !url.isRelative() && !url.host().isEmpty())
{
return url;
}
else
{
return QUrl::fromLocalFile(ui->modpackEdit->text());
}
const QUrl url(ui->modpackEdit->text());
if (url.isValid() && !url.isRelative() && !url.host().isEmpty())
{
return url;
}
else
{
return QUrl::fromLocalFile(ui->modpackEdit->text());
}
}

View File

@ -30,41 +30,41 @@ class NewInstanceDialog;
class ImportPage : public QWidget, public BasePage
{
Q_OBJECT
Q_OBJECT
public:
explicit ImportPage(NewInstanceDialog* dialog, QWidget *parent = 0);
virtual ~ImportPage();
virtual QString displayName() const override
{
return tr("Import from zip");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("viewfolder");
}
virtual QString id() const override
{
return "import";
}
virtual QString helpPage() const override
{
return "Zip-import";
}
virtual bool shouldDisplay() const override;
explicit ImportPage(NewInstanceDialog* dialog, QWidget *parent = 0);
virtual ~ImportPage();
virtual QString displayName() const override
{
return tr("Import from zip");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("viewfolder");
}
virtual QString id() const override
{
return "import";
}
virtual QString helpPage() const override
{
return "Zip-import";
}
virtual bool shouldDisplay() const override;
void setUrl(const QString & url);
void openedImpl() override;
void setUrl(const QString & url);
void openedImpl() override;
private slots:
void on_modpackBtn_clicked();
void updateState();
void on_modpackBtn_clicked();
void updateState();
private:
QUrl modpackUrl() const;
QUrl modpackUrl() const;
private:
Ui::ImportPage *ui = nullptr;
NewInstanceDialog* dialog = nullptr;
Ui::ImportPage *ui = nullptr;
NewInstanceDialog* dialog = nullptr;
};

View File

@ -8,22 +8,22 @@
#include "dialogs/NewInstanceDialog.h"
TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog)
: QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog)
{
ui->setupUi(this);
ui->setupUi(this);
}
TechnicPage::~TechnicPage()
{
delete ui;
delete ui;
}
bool TechnicPage::shouldDisplay() const
{
return true;
return true;
}
void TechnicPage::openedImpl()
{
dialog->setSuggestedPack();
dialog->setSuggestedPack();
}

View File

@ -30,32 +30,32 @@ class NewInstanceDialog;
class TechnicPage : public QWidget, public BasePage
{
Q_OBJECT
Q_OBJECT
public:
explicit TechnicPage(NewInstanceDialog* dialog, QWidget *parent = 0);
virtual ~TechnicPage();
virtual QString displayName() const override
{
return tr("Technic");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("technic");
}
virtual QString id() const override
{
return "technic";
}
virtual QString helpPage() const override
{
return "Technic-platform";
}
virtual bool shouldDisplay() const override;
explicit TechnicPage(NewInstanceDialog* dialog, QWidget *parent = 0);
virtual ~TechnicPage();
virtual QString displayName() const override
{
return tr("Technic");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("technic");
}
virtual QString id() const override
{
return "technic";
}
virtual QString helpPage() const override
{
return "Technic-platform";
}
virtual bool shouldDisplay() const override;
void openedImpl() override;
void openedImpl() override;
private:
Ui::TechnicPage *ui = nullptr;
NewInstanceDialog* dialog = nullptr;
Ui::TechnicPage *ui = nullptr;
NewInstanceDialog* dialog = nullptr;
};

View File

@ -8,22 +8,22 @@
#include "dialogs/NewInstanceDialog.h"
TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
: QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
{
ui->setupUi(this);
ui->setupUi(this);
}
TwitchPage::~TwitchPage()
{
delete ui;
delete ui;
}
bool TwitchPage::shouldDisplay() const
{
return false;
return false;
}
void TwitchPage::openedImpl()
{
dialog->setSuggestedPack();
dialog->setSuggestedPack();
}

View File

@ -30,32 +30,32 @@ class NewInstanceDialog;
class TwitchPage : public QWidget, public BasePage
{
Q_OBJECT
Q_OBJECT
public:
explicit TwitchPage(NewInstanceDialog* dialog, QWidget *parent = 0);
virtual ~TwitchPage();
virtual QString displayName() const override
{
return tr("Twitch");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("twitch");
}
virtual QString id() const override
{
return "twitch";
}
virtual QString helpPage() const override
{
return "Twitch-platform";
}
virtual bool shouldDisplay() const override;
explicit TwitchPage(NewInstanceDialog* dialog, QWidget *parent = 0);
virtual ~TwitchPage();
virtual QString displayName() const override
{
return tr("Twitch");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("twitch");
}
virtual QString id() const override
{
return "twitch";
}
virtual QString helpPage() const override
{
return "Twitch-platform";
}
virtual bool shouldDisplay() const override;
void openedImpl() override;
void openedImpl() override;
private:
Ui::TwitchPage *ui = nullptr;
NewInstanceDialog* dialog = nullptr;
Ui::TwitchPage *ui = nullptr;
NewInstanceDialog* dialog = nullptr;
};

View File

@ -15,81 +15,81 @@
#include <QTabBar>
VanillaPage::VanillaPage(NewInstanceDialog *dialog, QWidget *parent)
: QWidget(parent), dialog(dialog), ui(new Ui::VanillaPage)
: QWidget(parent), dialog(dialog), ui(new Ui::VanillaPage)
{
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
connect(ui->versionList, &VersionSelectWidget::selectedVersionChanged, this, &VanillaPage::setSelectedVersion);
filterChanged();
connect(ui->alphaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->betaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->snapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->oldSnapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->releaseFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->refreshBtn, &QPushButton::clicked, this, &VanillaPage::refresh);
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
connect(ui->versionList, &VersionSelectWidget::selectedVersionChanged, this, &VanillaPage::setSelectedVersion);
filterChanged();
connect(ui->alphaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->betaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->snapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->oldSnapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->releaseFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
connect(ui->refreshBtn, &QPushButton::clicked, this, &VanillaPage::refresh);
}
void VanillaPage::openedImpl()
{
if(!initialized)
{
auto vlist = ENV.metadataIndex()->get("net.minecraft");
ui->versionList->initialize(vlist.get());
initialized = true;
}
else
{
suggestCurrent();
}
if(!initialized)
{
auto vlist = ENV.metadataIndex()->get("net.minecraft");
ui->versionList->initialize(vlist.get());
initialized = true;
}
else
{
suggestCurrent();
}
}
void VanillaPage::refresh()
{
ui->versionList->loadList();
ui->versionList->loadList();
}
void VanillaPage::filterChanged()
{
QStringList out;
if(ui->alphaFilter->isChecked())
out << "(old_alpha)";
if(ui->betaFilter->isChecked())
out << "(old_beta)";
if(ui->snapshotFilter->isChecked())
out << "(snapshot)";
if(ui->oldSnapshotFilter->isChecked())
out << "(old_snapshot)";
if(ui->releaseFilter->isChecked())
out << "(release)";
auto regexp = out.join('|');
ui->versionList->setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false));
QStringList out;
if(ui->alphaFilter->isChecked())
out << "(old_alpha)";
if(ui->betaFilter->isChecked())
out << "(old_beta)";
if(ui->snapshotFilter->isChecked())
out << "(snapshot)";
if(ui->oldSnapshotFilter->isChecked())
out << "(old_snapshot)";
if(ui->releaseFilter->isChecked())
out << "(release)";
auto regexp = out.join('|');
ui->versionList->setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false));
}
VanillaPage::~VanillaPage()
{
delete ui;
delete ui;
}
bool VanillaPage::shouldDisplay() const
{
return true;
return true;
}
BaseVersionPtr VanillaPage::selectedVersion() const
{
return m_selectedVersion;
return m_selectedVersion;
}
void VanillaPage::suggestCurrent()
{
if(m_selectedVersion && isOpened)
{
dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion));
}
if(m_selectedVersion && isOpened)
{
dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion));
}
}
void VanillaPage::setSelectedVersion(BaseVersionPtr version)
{
m_selectedVersion = version;
suggestCurrent();
m_selectedVersion = version;
suggestCurrent();
}

View File

@ -30,46 +30,46 @@ class NewInstanceDialog;
class VanillaPage : public QWidget, public BasePage
{
Q_OBJECT
Q_OBJECT
public:
explicit VanillaPage(NewInstanceDialog *dialog, QWidget *parent = 0);
virtual ~VanillaPage();
virtual QString displayName() const override
{
return tr("Vanilla");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("minecraft");
}
virtual QString id() const override
{
return "vanilla";
}
virtual QString helpPage() const override
{
return "Vanilla-platform";
}
virtual bool shouldDisplay() const override;
void openedImpl() override;
explicit VanillaPage(NewInstanceDialog *dialog, QWidget *parent = 0);
virtual ~VanillaPage();
virtual QString displayName() const override
{
return tr("Vanilla");
}
virtual QIcon icon() const override
{
return MMC->getThemedIcon("minecraft");
}
virtual QString id() const override
{
return "vanilla";
}
virtual QString helpPage() const override
{
return "Vanilla-platform";
}
virtual bool shouldDisplay() const override;
void openedImpl() override;
BaseVersionPtr selectedVersion() const;
BaseVersionPtr selectedVersion() const;
public slots:
void setSelectedVersion(BaseVersionPtr version);
void setSelectedVersion(BaseVersionPtr version);
private slots:
void filterChanged();
void filterChanged();
private:
void refresh();
void suggestCurrent();
void refresh();
void suggestCurrent();
private:
bool initialized = false;
NewInstanceDialog *dialog = nullptr;
Ui::VanillaPage *ui = nullptr;
bool m_versionSetByUser = false;
BaseVersionPtr m_selectedVersion;
bool initialized = false;
NewInstanceDialog *dialog = nullptr;
Ui::VanillaPage *ui = nullptr;
bool m_versionSetByUser = false;
BaseVersionPtr m_selectedVersion;
};