diff --git a/cockatrice/src/client/menus/deck_editor/deck_editor_menu.cpp b/cockatrice/src/client/menus/deck_editor/deck_editor_menu.cpp index 73c76c807..306e63e32 100644 --- a/cockatrice/src/client/menus/deck_editor/deck_editor_menu.cpp +++ b/cockatrice/src/client/menus/deck_editor/deck_editor_menu.cpp @@ -55,6 +55,9 @@ DeckEditorMenu::DeckEditorMenu(QWidget *parent, AbstractTabDeckEditor *_deckEdit aExportDeckDecklist = new QAction(QString(), this); connect(aExportDeckDecklist, SIGNAL(triggered()), deckEditor, SLOT(actExportDeckDecklist())); + aExportDeckDecklistXyz = new QAction(QString(), this); + connect(aExportDeckDecklistXyz, SIGNAL(triggered()), deckEditor, SLOT(actExportDeckDecklistXyz())); + aAnalyzeDeckDeckstats = new QAction(QString(), this); connect(aAnalyzeDeckDeckstats, SIGNAL(triggered()), deckEditor, SLOT(actAnalyzeDeckDeckstats())); @@ -63,6 +66,8 @@ DeckEditorMenu::DeckEditorMenu(QWidget *parent, AbstractTabDeckEditor *_deckEdit analyzeDeckMenu = new QMenu(this); analyzeDeckMenu->addAction(aExportDeckDecklist); + analyzeDeckMenu->addAction(aExportDeckDecklistXyz); + analyzeDeckMenu->addSeparator(); analyzeDeckMenu->addAction(aAnalyzeDeckDeckstats); analyzeDeckMenu->addAction(aAnalyzeDeckTappedout); @@ -160,6 +165,7 @@ void DeckEditorMenu::retranslateUi() analyzeDeckMenu->setTitle(tr("&Send deck to online service")); aExportDeckDecklist->setText(tr("Create decklist (decklist.org)")); + aExportDeckDecklistXyz->setText(tr("Create decklist (decklist.xyz)")); aAnalyzeDeckDeckstats->setText(tr("Analyze deck (deckstats.net)")); aAnalyzeDeckTappedout->setText(tr("Analyze deck (tappedout.net)")); diff --git a/cockatrice/src/client/menus/deck_editor/deck_editor_menu.h b/cockatrice/src/client/menus/deck_editor/deck_editor_menu.h index 50ddc795a..a713b009f 100644 --- a/cockatrice/src/client/menus/deck_editor/deck_editor_menu.h +++ b/cockatrice/src/client/menus/deck_editor/deck_editor_menu.h @@ -17,7 +17,7 @@ public: QAction *aNewDeck, *aLoadDeck, *aClearRecents, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aEditDeckInClipboard, *aEditDeckInClipboardRaw, *aSaveDeckToClipboard, *aSaveDeckToClipboardNoSetInfo, *aSaveDeckToClipboardRaw, *aSaveDeckToClipboardRawNoSetInfo, *aPrintDeck, *aExportDeckDecklist, - *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout, *aClose; + *aExportDeckDecklistXyz, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout, *aClose; QMenu *loadRecentDeckMenu, *analyzeDeckMenu, *editDeckInClipboardMenu, *saveDeckToClipboardMenu; void setSaveStatus(bool newStatus); diff --git a/cockatrice/src/client/tabs/abstract_tab_deck_editor.cpp b/cockatrice/src/client/tabs/abstract_tab_deck_editor.cpp index 734ed1298..fe2148293 100644 --- a/cockatrice/src/client/tabs/abstract_tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/abstract_tab_deck_editor.cpp @@ -455,17 +455,12 @@ void AbstractTabDeckEditor::actPrintDeck() dlg->exec(); } -// Action called when export deck to decklist menu item is pressed. -void AbstractTabDeckEditor::actExportDeckDecklist() +void AbstractTabDeckEditor::exportToDecklistWebsite(DeckLoader::DecklistWebsite website) { - // 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 - if (deck) { + if (DeckLoader *const deck = getDeckList()) { // 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. if (QString::compare(decklistUrlString, "", Qt::CaseInsensitive) == 0) { // Show an error if the deck is empty, and return. @@ -481,10 +476,26 @@ void AbstractTabDeckEditor::actExportDeckDecklist() QDesktopServices::openUrl(decklistUrlString); } else { // 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() { auto *interface = new DeckStatsInterface(*databaseDisplayDockWidget->databaseModel->getDatabase(), diff --git a/cockatrice/src/client/tabs/abstract_tab_deck_editor.h b/cockatrice/src/client/tabs/abstract_tab_deck_editor.h index 9f3cca0e1..0a5f97f56 100644 --- a/cockatrice/src/client/tabs/abstract_tab_deck_editor.h +++ b/cockatrice/src/client/tabs/abstract_tab_deck_editor.h @@ -100,6 +100,7 @@ protected slots: void actSaveDeckToClipboardRawNoSetInfo(); void actPrintDeck(); void actExportDeckDecklist(); + void actExportDeckDecklistXyz(); void actAnalyzeDeckDeckstats(); void actAnalyzeDeckTappedout(); @@ -119,6 +120,7 @@ protected slots: private: virtual void setDeck(DeckLoader *_deck); void editDeckInClipboard(bool annotated); + void exportToDecklistWebsite(DeckLoader::DecklistWebsite website); protected: /** diff --git a/cockatrice/src/deck/deck_loader.cpp b/cockatrice/src/deck/deck_loader.cpp index 16132c571..8130752b7 100644 --- a/cockatrice/src/deck/deck_loader.cpp +++ b/cockatrice/src/deck/deck_loader.cpp @@ -226,6 +226,19 @@ bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, FileFormat f 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 // requires a function to be called for each card, and passes an inner node and a card for // 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 - QString deckString = "https://www.decklist.org/?"; + QString deckString = "https://" + getDomainForWebsite(website) + "/?"; // Create two strings to pass to function QString mainBoardCards, sideBoardCards; // Set up the struct to call. diff --git a/cockatrice/src/deck/deck_loader.h b/cockatrice/src/deck/deck_loader.h index c62fd45c9..53dd1f711 100644 --- a/cockatrice/src/deck/deck_loader.h +++ b/cockatrice/src/deck/deck_loader.h @@ -31,6 +31,12 @@ public: */ static const QStringList FILE_NAME_FILTERS; + enum DecklistWebsite + { + DecklistOrg, + DecklistXyz + }; + private: QString lastFileName; FileFormat lastFileFormat; @@ -71,7 +77,7 @@ public: bool loadFromRemote(const QString &nativeString, int remoteDeckId); bool saveToFile(const QString &fileName, FileFormat fmt); bool updateLastLoadedTimestamp(const QString &fileName, FileFormat fmt); - QString exportDeckToDecklist(); + QString exportDeckToDecklist(DecklistWebsite website); void resolveSetNameAndNumberToProviderID();