Support exporting to decklist.xyz website (#5756)

* Support exporting to decklist.xyz

* fix typo
This commit is contained in:
RickyRister 2025-03-20 17:28:15 -07:00 committed by GitHub
parent be28d50997
commit 99376e75d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 55 additions and 14 deletions

View file

@ -55,6 +55,9 @@ DeckEditorMenu::DeckEditorMenu(QWidget *parent, AbstractTabDeckEditor *_deckEdit
aExportDeckDecklist = new QAction(QString(), this); aExportDeckDecklist = new QAction(QString(), this);
connect(aExportDeckDecklist, SIGNAL(triggered()), deckEditor, SLOT(actExportDeckDecklist())); connect(aExportDeckDecklist, SIGNAL(triggered()), deckEditor, SLOT(actExportDeckDecklist()));
aExportDeckDecklistXyz = new QAction(QString(), this);
connect(aExportDeckDecklistXyz, SIGNAL(triggered()), deckEditor, SLOT(actExportDeckDecklistXyz()));
aAnalyzeDeckDeckstats = new QAction(QString(), this); aAnalyzeDeckDeckstats = new QAction(QString(), this);
connect(aAnalyzeDeckDeckstats, SIGNAL(triggered()), deckEditor, SLOT(actAnalyzeDeckDeckstats())); connect(aAnalyzeDeckDeckstats, SIGNAL(triggered()), deckEditor, SLOT(actAnalyzeDeckDeckstats()));
@ -63,6 +66,8 @@ DeckEditorMenu::DeckEditorMenu(QWidget *parent, AbstractTabDeckEditor *_deckEdit
analyzeDeckMenu = new QMenu(this); analyzeDeckMenu = new QMenu(this);
analyzeDeckMenu->addAction(aExportDeckDecklist); analyzeDeckMenu->addAction(aExportDeckDecklist);
analyzeDeckMenu->addAction(aExportDeckDecklistXyz);
analyzeDeckMenu->addSeparator();
analyzeDeckMenu->addAction(aAnalyzeDeckDeckstats); analyzeDeckMenu->addAction(aAnalyzeDeckDeckstats);
analyzeDeckMenu->addAction(aAnalyzeDeckTappedout); analyzeDeckMenu->addAction(aAnalyzeDeckTappedout);
@ -160,6 +165,7 @@ void DeckEditorMenu::retranslateUi()
analyzeDeckMenu->setTitle(tr("&Send deck to online service")); analyzeDeckMenu->setTitle(tr("&Send deck to online service"));
aExportDeckDecklist->setText(tr("Create decklist (decklist.org)")); aExportDeckDecklist->setText(tr("Create decklist (decklist.org)"));
aExportDeckDecklistXyz->setText(tr("Create decklist (decklist.xyz)"));
aAnalyzeDeckDeckstats->setText(tr("Analyze deck (deckstats.net)")); aAnalyzeDeckDeckstats->setText(tr("Analyze deck (deckstats.net)"));
aAnalyzeDeckTappedout->setText(tr("Analyze deck (tappedout.net)")); aAnalyzeDeckTappedout->setText(tr("Analyze deck (tappedout.net)"));

View file

@ -17,7 +17,7 @@ public:
QAction *aNewDeck, *aLoadDeck, *aClearRecents, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, QAction *aNewDeck, *aLoadDeck, *aClearRecents, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard,
*aEditDeckInClipboard, *aEditDeckInClipboardRaw, *aSaveDeckToClipboard, *aSaveDeckToClipboardNoSetInfo, *aEditDeckInClipboard, *aEditDeckInClipboardRaw, *aSaveDeckToClipboard, *aSaveDeckToClipboardNoSetInfo,
*aSaveDeckToClipboardRaw, *aSaveDeckToClipboardRawNoSetInfo, *aPrintDeck, *aExportDeckDecklist, *aSaveDeckToClipboardRaw, *aSaveDeckToClipboardRawNoSetInfo, *aPrintDeck, *aExportDeckDecklist,
*aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout, *aClose; *aExportDeckDecklistXyz, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout, *aClose;
QMenu *loadRecentDeckMenu, *analyzeDeckMenu, *editDeckInClipboardMenu, *saveDeckToClipboardMenu; QMenu *loadRecentDeckMenu, *analyzeDeckMenu, *editDeckInClipboardMenu, *saveDeckToClipboardMenu;
void setSaveStatus(bool newStatus); void setSaveStatus(bool newStatus);

View file

@ -455,17 +455,12 @@ void AbstractTabDeckEditor::actPrintDeck()
dlg->exec(); dlg->exec();
} }
// Action called when export deck to decklist menu item is pressed. void AbstractTabDeckEditor::exportToDecklistWebsite(DeckLoader::DecklistWebsite website)
void AbstractTabDeckEditor::actExportDeckDecklist()
{ {
// Get the decklist class for the deck.
DeckLoader *const deck = getDeckList();
// create a string to load the decklist url into.
QString decklistUrlString;
// check if deck is not null // check if deck is not null
if (deck) { if (DeckLoader *const deck = getDeckList()) {
// Get the decklist url string from the deck loader class. // Get the decklist url string from the deck loader class.
decklistUrlString = deck->exportDeckToDecklist(); QString decklistUrlString = deck->exportDeckToDecklist(website);
// Check to make sure the string isn't empty. // Check to make sure the string isn't empty.
if (QString::compare(decklistUrlString, "", Qt::CaseInsensitive) == 0) { if (QString::compare(decklistUrlString, "", Qt::CaseInsensitive) == 0) {
// Show an error if the deck is empty, and return. // Show an error if the deck is empty, and return.
@ -481,10 +476,26 @@ void AbstractTabDeckEditor::actExportDeckDecklist()
QDesktopServices::openUrl(decklistUrlString); QDesktopServices::openUrl(decklistUrlString);
} else { } else {
// if there's no deck loader object, return an error // if there's no deck loader object, return an error
QMessageBox::critical(this, tr("Error"), tr("No deck was selected to be saved.")); QMessageBox::critical(this, tr("Error"), tr("No deck was selected to be exported."));
} }
} }
/**
* Exports the deck to www.decklist.org (the old website)
*/
void AbstractTabDeckEditor::actExportDeckDecklist()
{
exportToDecklistWebsite(DeckLoader::DecklistOrg);
}
/**
* Exports the deck to www.decklist.xyz (the new website)
*/
void AbstractTabDeckEditor::actExportDeckDecklistXyz()
{
exportToDecklistWebsite(DeckLoader::DecklistXyz);
}
void AbstractTabDeckEditor::actAnalyzeDeckDeckstats() void AbstractTabDeckEditor::actAnalyzeDeckDeckstats()
{ {
auto *interface = new DeckStatsInterface(*databaseDisplayDockWidget->databaseModel->getDatabase(), auto *interface = new DeckStatsInterface(*databaseDisplayDockWidget->databaseModel->getDatabase(),

View file

@ -100,6 +100,7 @@ protected slots:
void actSaveDeckToClipboardRawNoSetInfo(); void actSaveDeckToClipboardRawNoSetInfo();
void actPrintDeck(); void actPrintDeck();
void actExportDeckDecklist(); void actExportDeckDecklist();
void actExportDeckDecklistXyz();
void actAnalyzeDeckDeckstats(); void actAnalyzeDeckDeckstats();
void actAnalyzeDeckTappedout(); void actAnalyzeDeckTappedout();
@ -119,6 +120,7 @@ protected slots:
private: private:
virtual void setDeck(DeckLoader *_deck); virtual void setDeck(DeckLoader *_deck);
void editDeckInClipboard(bool annotated); void editDeckInClipboard(bool annotated);
void exportToDecklistWebsite(DeckLoader::DecklistWebsite website);
protected: protected:
/** /**

View file

@ -226,6 +226,19 @@ bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, FileFormat f
return result; return result;
} }
static QString getDomainForWebsite(DeckLoader::DecklistWebsite website)
{
switch (website) {
case DeckLoader::DecklistOrg:
return "www.decklist.org";
case DeckLoader::DecklistXyz:
return "www.decklist.xyz";
default:
qCWarning(DeckLoaderLog) << "Invalid decklist website enum:" << website;
return "";
}
}
// This struct is here to support the forEachCard function call, defined in decklist. It // This struct is here to support the forEachCard function call, defined in decklist. It
// requires a function to be called for each card, and passes an inner node and a card for // requires a function to be called for each card, and passes an inner node and a card for
// each card in the decklist. // each card in the decklist.
@ -275,11 +288,14 @@ struct FormatDeckListForExport
} }
}; };
// Export deck to decklist function, called to format the deck in a way to be sent to a server /**
QString DeckLoader::exportDeckToDecklist() * Export deck to decklist function, called to format the deck in a way to be sent to a server
* @param website The website we're sending the deck to
*/
QString DeckLoader::exportDeckToDecklist(DecklistWebsite website)
{ {
// Add the base url // Add the base url
QString deckString = "https://www.decklist.org/?"; QString deckString = "https://" + getDomainForWebsite(website) + "/?";
// Create two strings to pass to function // Create two strings to pass to function
QString mainBoardCards, sideBoardCards; QString mainBoardCards, sideBoardCards;
// Set up the struct to call. // Set up the struct to call.

View file

@ -31,6 +31,12 @@ public:
*/ */
static const QStringList FILE_NAME_FILTERS; static const QStringList FILE_NAME_FILTERS;
enum DecklistWebsite
{
DecklistOrg,
DecklistXyz
};
private: private:
QString lastFileName; QString lastFileName;
FileFormat lastFileFormat; FileFormat lastFileFormat;
@ -71,7 +77,7 @@ public:
bool loadFromRemote(const QString &nativeString, int remoteDeckId); bool loadFromRemote(const QString &nativeString, int remoteDeckId);
bool saveToFile(const QString &fileName, FileFormat fmt); bool saveToFile(const QString &fileName, FileFormat fmt);
bool updateLastLoadedTimestamp(const QString &fileName, FileFormat fmt); bool updateLastLoadedTimestamp(const QString &fileName, FileFormat fmt);
QString exportDeckToDecklist(); QString exportDeckToDecklist(DecklistWebsite website);
void resolveSetNameAndNumberToProviderID(); void resolveSetNameAndNumberToProviderID();