From 646c4b4197fea6f49234c2492f5d8d7de21299db Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Fri, 5 Feb 2016 20:32:40 +0000 Subject: [PATCH 01/14] Added functionless menu button for adding a set. --- cockatrice/src/tab_deck_editor.cpp | 12 +++++++++++- cockatrice/src/tab_deck_editor.h | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 736a1297..55beba78 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -267,6 +267,9 @@ void TabDeckEditor::createMenus() aOpenCustomFolder = new QAction(QString(), this); connect(aOpenCustomFolder, SIGNAL(triggered()), this, SLOT(actOpenCustomFolder())); + aAddCustomSet = new QAction(QString(), this); + connect(aAddCustomSet, SIGNAL(triggered()), this, SLOT(actAddCustomSet())); + aEditSets = new QAction(QString(), this); connect(aEditSets, SIGNAL(triggered()), this, SLOT(actEditSets())); @@ -307,6 +310,7 @@ void TabDeckEditor::createMenus() dbMenu->addSeparator(); dbMenu->addAction(aOpenCustomFolder); dbMenu->addAction(aOpenCustomsetsFolder); + dbMenu->addAction(aAddCustomSet); #endif addTabMenu(dbMenu); @@ -584,7 +588,8 @@ void TabDeckEditor::retranslateUi() aPrintDeck->setText(tr("&Print deck...")); aAnalyzeDeck->setText(tr("&Analyze deck on deckstats.net")); aOpenCustomFolder->setText(tr("Open custom image folder")); - aOpenCustomsetsFolder->setText(tr("Open custom sets folder")); + aOpenCustomsetsFolder->setText(tr("Open custom sets folder")); + aAddCustomSet->setText(tr("Add custom set")); aClose->setText(tr("&Close")); aAddCard->setText(tr("Add card to &maindeck")); @@ -863,6 +868,11 @@ void TabDeckEditor::actOpenCustomsetsFolder() { } +void TabDeckEditor::actAddCustomSet() +{ + +} + void TabDeckEditor::actEditSets() { WndSets *w = new WndSets; diff --git a/cockatrice/src/tab_deck_editor.h b/cockatrice/src/tab_deck_editor.h index 123dee55..6e580ca8 100644 --- a/cockatrice/src/tab_deck_editor.h +++ b/cockatrice/src/tab_deck_editor.h @@ -54,6 +54,7 @@ class TabDeckEditor : public Tab { void actAnalyzeDeck(); void actOpenCustomFolder(); void actOpenCustomsetsFolder(); + void actAddCustomSet(); void actEditSets(); void actEditTokens(); @@ -116,7 +117,7 @@ private: QWidget *filterBox; QMenu *deckMenu, *dbMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu; - QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aAnalyzeDeck, *aClose, *aOpenCustomFolder, *aOpenCustomsetsFolder; + QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aAnalyzeDeck, *aClose, *aOpenCustomFolder, *aOpenCustomsetsFolder, *aAddCustomSet; QAction *aEditSets, *aEditTokens, *aClearFilterAll, *aClearFilterOne; QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;// *aUpdatePrices; QAction *aResetLayout; From 2960cba12b578686602fcee2ae089e374e927178 Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Fri, 5 Feb 2016 21:09:24 +0000 Subject: [PATCH 02/14] Added a file picker to the add set menu item. --- cockatrice/src/tab_deck_editor.cpp | 20 ++++++++++++++++++++ cockatrice/src/tab_deck_editor.h | 1 + 2 files changed, 21 insertions(+) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 55beba78..3138e8e1 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -45,6 +45,10 @@ #include "cardframe.h" #include "filterbuilder.h" +const QStringList TabDeckEditor::fileNameFilters = QStringList() + << QObject::tr("Cockatrice set format (*.xml)") + << QObject::tr("All files (*.*)"); + void SearchLineEdit::keyPressEvent(QKeyEvent *event) { if (treeView && ((event->key() == Qt::Key_Up) || (event->key() == Qt::Key_Down))) @@ -871,6 +875,22 @@ void TabDeckEditor::actOpenCustomsetsFolder() { void TabDeckEditor::actAddCustomSet() { +#if QT_VERSION < 0x050000 + QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); +#else + QString dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first(); +#endif + + if (!confirmClose()) + return; + + QFileDialog dialog(this, tr("Load set")); + dialog.setDirectory(dataDir); + dialog.setNameFilters(TabDeckEditor::fileNameFilters); + if (!dialog.exec()) + return; + + QString fileName = dialog.selectedFiles().at(0); } void TabDeckEditor::actEditSets() diff --git a/cockatrice/src/tab_deck_editor.h b/cockatrice/src/tab_deck_editor.h index 6e580ca8..57152408 100644 --- a/cockatrice/src/tab_deck_editor.h +++ b/cockatrice/src/tab_deck_editor.h @@ -89,6 +89,7 @@ class TabDeckEditor : public Tab { void dockFloatingTriggered(); void dockTopLevelChanged(bool topLevel); private: + static const QStringList fileNameFilters; CardInfo *currentCardInfo() const; void addCardHelper(QString zoneName); void offsetCountAtIndex(const QModelIndex &idx, int offset); From c9143952361e64fdf989545b1b7879e751e7b517 Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Sat, 6 Feb 2016 01:33:43 +0000 Subject: [PATCH 03/14] Finished add set functionality. --- cockatrice/src/tab_deck_editor.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 3138e8e1..b8448440 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -891,6 +891,19 @@ void TabDeckEditor::actAddCustomSet() return; QString fileName = dialog.selectedFiles().at(0); + QDir dir(dataDir.append("/customsets")); + QStringList files = dir.entryList(); + int maxIndex = 0; + for (int i = 0; i < files.size(); ++i) { + int fileIndex = files.at(i).split(".").at(0).toInt(); + if (fileIndex > maxIndex) + maxIndex = fileIndex; + } + maxIndex++; + bool res = QFile::copy( + fileName, dir.absolutePath() + "/" + (maxIndex > 9 ? "" : "0") + + QString::number(maxIndex) + "." + QFileInfo(fileName).fileName() + ); } void TabDeckEditor::actEditSets() From 54a759497f26f9b2bb85a05f9d92c20746f7e1d6 Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Sat, 6 Feb 2016 02:29:09 +0000 Subject: [PATCH 04/14] Added confirmation dialogue when set added. --- cockatrice/CMakeLists.txt | 1 + cockatrice/src/dlg_add_set.cpp | 39 ++++++++++++++++++++++++++++++ cockatrice/src/dlg_add_set.h | 18 ++++++++++++++ cockatrice/src/tab_deck_editor.cpp | 3 +++ 4 files changed, 61 insertions(+) create mode 100644 cockatrice/src/dlg_add_set.cpp create mode 100644 cockatrice/src/dlg_add_set.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 03573cc6..155cdcb4 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -7,6 +7,7 @@ PROJECT(cockatrice) SET(cockatrice_SOURCES src/abstractcounter.cpp src/counter_general.cpp + src/dlg_add_set.cpp src/dlg_creategame.cpp src/dlg_filter_games.cpp src/dlg_connect.cpp diff --git a/cockatrice/src/dlg_add_set.cpp b/cockatrice/src/dlg_add_set.cpp new file mode 100644 index 00000000..2d37d6c6 --- /dev/null +++ b/cockatrice/src/dlg_add_set.cpp @@ -0,0 +1,39 @@ +#include "dlg_add_set.h" + +#include +#include +#include + +DlgAddSet::DlgAddSet(QWidget *parent, bool success) : QDialog(parent) { + status = new QLabel(this); + restart = new QLabel(this); + + if (success) { + setWindowTitle(tr("Success")); + status->setText(QString("Set added to Cockatrice.")); + restart->setText(QString("You must restart to use your new set.")); + } + else { + setWindowTitle(tr("Failed")); + status->setText(QString("Set failed to import.")); + } + + QDialogButtonBox *buttonBox = new QDialogButtonBox(this); + ok = new QPushButton(tr("Ok"), this); + buttonBox->addButton(ok, QDialogButtonBox::AcceptRole); + connect(ok, SIGNAL(clicked()), this, SLOT(closeDialog())); + + QVBoxLayout *parentLayout = new QVBoxLayout(this); + parentLayout->addWidget(status); + parentLayout->addWidget(restart); + parentLayout->addWidget(buttonBox); + + setLayout(parentLayout); + + exec(); +} + +void DlgAddSet::closeDialog() +{ + accept(); +} \ No newline at end of file diff --git a/cockatrice/src/dlg_add_set.h b/cockatrice/src/dlg_add_set.h new file mode 100644 index 00000000..cd8e4d32 --- /dev/null +++ b/cockatrice/src/dlg_add_set.h @@ -0,0 +1,18 @@ +#ifndef DLG_ADD_SET_H +#define DLG_ADD_SET_H + +#include +#include + +class DlgAddSet : public QDialog { +Q_OBJECT +public: + DlgAddSet(QWidget *parent, bool success); +private slots: + void closeDialog(); +private: + QLabel *status, *restart; + QPushButton *ok; +}; + +#endif \ No newline at end of file diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index b8448440..a1426632 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -32,6 +32,7 @@ #include "cardinfowidget.h" #include "dlg_load_deck_from_clipboard.h" #include "dlg_edit_tokens.h" +#include "dlg_add_set.h" #include "main.h" #include "settingscache.h" #include "priceupdater.h" @@ -904,6 +905,8 @@ void TabDeckEditor::actAddCustomSet() fileName, dir.absolutePath() + "/" + (maxIndex > 9 ? "" : "0") + QString::number(maxIndex) + "." + QFileInfo(fileName).fileName() ); + + DlgAddSet dlg(this, res); } void TabDeckEditor::actEditSets() From de388a74bda9c0e98299917409ce0539f5f84b3e Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Sat, 6 Feb 2016 02:32:04 +0000 Subject: [PATCH 05/14] Moved exec statement. --- cockatrice/src/dlg_add_set.cpp | 2 -- cockatrice/src/tab_deck_editor.cpp | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cockatrice/src/dlg_add_set.cpp b/cockatrice/src/dlg_add_set.cpp index 2d37d6c6..b019e883 100644 --- a/cockatrice/src/dlg_add_set.cpp +++ b/cockatrice/src/dlg_add_set.cpp @@ -29,8 +29,6 @@ DlgAddSet::DlgAddSet(QWidget *parent, bool success) : QDialog(parent) { parentLayout->addWidget(buttonBox); setLayout(parentLayout); - - exec(); } void DlgAddSet::closeDialog() diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index a1426632..ca5e7ee9 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -907,6 +907,7 @@ void TabDeckEditor::actAddCustomSet() ); DlgAddSet dlg(this, res); + dlg.exec(); } void TabDeckEditor::actEditSets() From 927226633d5e767c2edb5d9f0696f18ad9dd05a9 Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Sat, 6 Feb 2016 02:37:34 +0000 Subject: [PATCH 06/14] Moved menu item decleration to work on all OSs. --- cockatrice/src/tab_deck_editor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index ca5e7ee9..2aaad708 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -311,12 +311,12 @@ void TabDeckEditor::createMenus() dbMenu->addSeparator(); dbMenu->addAction(aClearFilterOne); dbMenu->addAction(aClearFilterAll); -#if defined(Q_OS_WIN) || defined(Q_OS_MAC) dbMenu->addSeparator(); +#if defined(Q_OS_WIN) || defined(Q_OS_MAC) dbMenu->addAction(aOpenCustomFolder); dbMenu->addAction(aOpenCustomsetsFolder); - dbMenu->addAction(aAddCustomSet); #endif + dbMenu->addAction(aAddCustomSet); addTabMenu(dbMenu); viewMenu = new QMenu(this); From b5363f47abc926ebb9c0c56275b77d1bd0cc5aa6 Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Sat, 6 Feb 2016 12:42:45 +0000 Subject: [PATCH 07/14] Updated message. --- cockatrice/src/dlg_add_set.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/dlg_add_set.cpp b/cockatrice/src/dlg_add_set.cpp index b019e883..e4dd784f 100644 --- a/cockatrice/src/dlg_add_set.cpp +++ b/cockatrice/src/dlg_add_set.cpp @@ -11,7 +11,7 @@ DlgAddSet::DlgAddSet(QWidget *parent, bool success) : QDialog(parent) { if (success) { setWindowTitle(tr("Success")); status->setText(QString("Set added to Cockatrice.")); - restart->setText(QString("You must restart to use your new set.")); + restart->setText(QString("You must restart Cockatrice to use the new set.")); } else { setWindowTitle(tr("Failed")); From 9d3c4f20a1ecc8627ca5aebfc2f44a5ceb0bfe07 Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Sun, 7 Feb 2016 01:41:35 +0000 Subject: [PATCH 08/14] Changed strings referencing a set to say sets/cards. --- cockatrice/src/dlg_add_set.cpp | 6 +++--- cockatrice/src/tab_deck_editor.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cockatrice/src/dlg_add_set.cpp b/cockatrice/src/dlg_add_set.cpp index e4dd784f..8ccbafbe 100644 --- a/cockatrice/src/dlg_add_set.cpp +++ b/cockatrice/src/dlg_add_set.cpp @@ -10,12 +10,12 @@ DlgAddSet::DlgAddSet(QWidget *parent, bool success) : QDialog(parent) { if (success) { setWindowTitle(tr("Success")); - status->setText(QString("Set added to Cockatrice.")); - restart->setText(QString("You must restart Cockatrice to use the new set.")); + status->setText(QString("Sets/cards added to Cockatrice.")); + restart->setText(QString("You must restart Cockatrice to use the new sets/cards.")); } else { setWindowTitle(tr("Failed")); - status->setText(QString("Set failed to import.")); + status->setText(QString("Sets/cards failed to import.")); } QDialogButtonBox *buttonBox = new QDialogButtonBox(this); diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 2aaad708..33eb42d7 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -47,7 +47,7 @@ #include "filterbuilder.h" const QStringList TabDeckEditor::fileNameFilters = QStringList() - << QObject::tr("Cockatrice set format (*.xml)") + << QObject::tr("Cockatrice card database (*.xml)") << QObject::tr("All files (*.*)"); void SearchLineEdit::keyPressEvent(QKeyEvent *event) @@ -594,7 +594,7 @@ void TabDeckEditor::retranslateUi() aAnalyzeDeck->setText(tr("&Analyze deck on deckstats.net")); aOpenCustomFolder->setText(tr("Open custom image folder")); aOpenCustomsetsFolder->setText(tr("Open custom sets folder")); - aAddCustomSet->setText(tr("Add custom set")); + aAddCustomSet->setText(tr("Add custom sets/cards")); aClose->setText(tr("&Close")); aAddCard->setText(tr("Add card to &maindeck")); @@ -885,7 +885,7 @@ void TabDeckEditor::actAddCustomSet() if (!confirmClose()) return; - QFileDialog dialog(this, tr("Load set")); + QFileDialog dialog(this, tr("Load sets/cards")); dialog.setDirectory(dataDir); dialog.setNameFilters(TabDeckEditor::fileNameFilters); if (!dialog.exec()) From 5a975831d486128a5777e450a2b13e8ffb5d978e Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Tue, 9 Feb 2016 01:40:21 +0000 Subject: [PATCH 09/14] Renamed "dlg_add_set.*" to "dlg_add_set_result.*" and updated references. --- cockatrice/CMakeLists.txt | 2 +- cockatrice/src/{dlg_add_set.cpp => dlg_add_set_result.cpp} | 2 +- cockatrice/src/{dlg_add_set.h => dlg_add_set_result.h} | 0 cockatrice/src/tab_deck_editor.cpp | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename cockatrice/src/{dlg_add_set.cpp => dlg_add_set_result.cpp} (96%) rename cockatrice/src/{dlg_add_set.h => dlg_add_set_result.h} (100%) diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 155cdcb4..205d1874 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -7,7 +7,7 @@ PROJECT(cockatrice) SET(cockatrice_SOURCES src/abstractcounter.cpp src/counter_general.cpp - src/dlg_add_set.cpp + src/dlg_add_set_result.cpp src/dlg_creategame.cpp src/dlg_filter_games.cpp src/dlg_connect.cpp diff --git a/cockatrice/src/dlg_add_set.cpp b/cockatrice/src/dlg_add_set_result.cpp similarity index 96% rename from cockatrice/src/dlg_add_set.cpp rename to cockatrice/src/dlg_add_set_result.cpp index 8ccbafbe..9b995ec7 100644 --- a/cockatrice/src/dlg_add_set.cpp +++ b/cockatrice/src/dlg_add_set_result.cpp @@ -1,4 +1,4 @@ -#include "dlg_add_set.h" +#include "dlg_add_set_result.h" #include #include diff --git a/cockatrice/src/dlg_add_set.h b/cockatrice/src/dlg_add_set_result.h similarity index 100% rename from cockatrice/src/dlg_add_set.h rename to cockatrice/src/dlg_add_set_result.h diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 33eb42d7..bfd050c9 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -32,7 +32,7 @@ #include "cardinfowidget.h" #include "dlg_load_deck_from_clipboard.h" #include "dlg_edit_tokens.h" -#include "dlg_add_set.h" +#include "dlg_add_set_result.h" #include "main.h" #include "settingscache.h" #include "priceupdater.h" From 0ef2b48902ec0425f727a7cde3c88eabc35194ba Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Tue, 9 Feb 2016 01:52:09 +0000 Subject: [PATCH 10/14] Refactored DlgAddSet class/functions to DlgAddSetResult --- cockatrice/src/dlg_add_set_result.cpp | 4 ++-- cockatrice/src/dlg_add_set_result.h | 8 ++++---- cockatrice/src/tab_deck_editor.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/dlg_add_set_result.cpp b/cockatrice/src/dlg_add_set_result.cpp index 9b995ec7..03645408 100644 --- a/cockatrice/src/dlg_add_set_result.cpp +++ b/cockatrice/src/dlg_add_set_result.cpp @@ -4,7 +4,7 @@ #include #include -DlgAddSet::DlgAddSet(QWidget *parent, bool success) : QDialog(parent) { +DlgAddSetResult::DlgAddSetResult(QWidget *parent, bool success) : QDialog(parent) { status = new QLabel(this); restart = new QLabel(this); @@ -31,7 +31,7 @@ DlgAddSet::DlgAddSet(QWidget *parent, bool success) : QDialog(parent) { setLayout(parentLayout); } -void DlgAddSet::closeDialog() +void DlgAddSetResult::closeDialog() { accept(); } \ No newline at end of file diff --git a/cockatrice/src/dlg_add_set_result.h b/cockatrice/src/dlg_add_set_result.h index cd8e4d32..6a30af24 100644 --- a/cockatrice/src/dlg_add_set_result.h +++ b/cockatrice/src/dlg_add_set_result.h @@ -1,13 +1,13 @@ -#ifndef DLG_ADD_SET_H -#define DLG_ADD_SET_H +#ifndef DLG_ADD_SET_RESULT_H +#define DLG_ADD_SET_RESULT_H #include #include -class DlgAddSet : public QDialog { +class DlgAddSetResult : public QDialog { Q_OBJECT public: - DlgAddSet(QWidget *parent, bool success); + DlgAddSetResult(QWidget *parent, bool success); private slots: void closeDialog(); private: diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index bfd050c9..c960faf9 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -906,7 +906,7 @@ void TabDeckEditor::actAddCustomSet() QString::number(maxIndex) + "." + QFileInfo(fileName).fileName() ); - DlgAddSet dlg(this, res); + DlgAddSetResult dlg(this, res); dlg.exec(); } From 829f84fe500f7ec8f1aed79fcd0f55badc0f4555 Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Tue, 9 Feb 2016 01:56:24 +0000 Subject: [PATCH 11/14] Moved from using hex QT version checks to QT_VERSION_CHECK(). --- cockatrice/src/tab_deck_editor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index c960faf9..47b6f3ac 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -876,7 +876,7 @@ void TabDeckEditor::actOpenCustomsetsFolder() { void TabDeckEditor::actAddCustomSet() { -#if QT_VERSION < 0x050000 +#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); #else QString dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first(); From 96fbad1f0cefc0044abfcfb75a68c45ed42a6bb8 Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Tue, 9 Feb 2016 02:55:52 +0000 Subject: [PATCH 12/14] Moved get next set index code to own function --- cockatrice/src/tab_deck_editor.cpp | 33 +++++++++++++++++------------- cockatrice/src/tab_deck_editor.h | 2 ++ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 47b6f3ac..4f6344a1 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -714,9 +714,6 @@ void TabDeckEditor::actNewDeck() void TabDeckEditor::actLoadDeck() { - if (!confirmClose()) - return; - QFileDialog dialog(this, tr("Load deck")); dialog.setDirectory(settingsCache->getDeckPath()); dialog.setNameFilters(DeckLoader::fileNameFilters); @@ -891,25 +888,33 @@ void TabDeckEditor::actAddCustomSet() if (!dialog.exec()) return; + QDir dir(dataDir + "/customsets"); + int nextPrefix = getNextCustomSetPrefix(dir); + QString fileName = dialog.selectedFiles().at(0); - QDir dir(dataDir.append("/customsets")); - QStringList files = dir.entryList(); - int maxIndex = 0; - for (int i = 0; i < files.size(); ++i) { - int fileIndex = files.at(i).split(".").at(0).toInt(); - if (fileIndex > maxIndex) - maxIndex = fileIndex; - } - maxIndex++; bool res = QFile::copy( - fileName, dir.absolutePath() + "/" + (maxIndex > 9 ? "" : "0") + - QString::number(maxIndex) + "." + QFileInfo(fileName).fileName() + fileName, dir.absolutePath() + "/" + (nextPrefix > 9 ? "" : "0") + + QString::number(nextPrefix) + "." + QFileInfo(fileName).fileName() ); DlgAddSetResult dlg(this, res); dlg.exec(); } +int TabDeckEditor::getNextCustomSetPrefix(QDir dataDir) { + QStringList files = dataDir.entryList(); + int maxIndex = 0; + + QStringList::const_iterator filesIterator; + for (filesIterator = files.constBegin(); filesIterator != files.constEnd(); ++filesIterator) { + int fileIndex = (*filesIterator).split(".").at(0).toInt(); + if (fileIndex > maxIndex) + maxIndex = fileIndex; + } + + return maxIndex + 1; +} + void TabDeckEditor::actEditSets() { WndSets *w = new WndSets; diff --git a/cockatrice/src/tab_deck_editor.h b/cockatrice/src/tab_deck_editor.h index 57152408..13e4203c 100644 --- a/cockatrice/src/tab_deck_editor.h +++ b/cockatrice/src/tab_deck_editor.h @@ -3,6 +3,7 @@ #include "tab.h" #include +#include #include #include "keysignals.h" @@ -95,6 +96,7 @@ private: void offsetCountAtIndex(const QModelIndex &idx, int offset); void decrementCardHelper(QString zoneName); void recursiveExpand(const QModelIndex &index); + int getNextCustomSetPrefix(QDir dataDir); CardDatabaseModel *databaseModel; CardDatabaseDisplayModel *databaseDisplayModel; From d078cf52c982e3eff6eb06b80216040edfe4bc11 Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Tue, 9 Feb 2016 02:57:23 +0000 Subject: [PATCH 13/14] Removed unnecessary confirmClose() call. --- cockatrice/src/tab_deck_editor.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 4f6344a1..7c170181 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -879,9 +879,6 @@ void TabDeckEditor::actAddCustomSet() QString dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first(); #endif - if (!confirmClose()) - return; - QFileDialog dialog(this, tr("Load sets/cards")); dialog.setDirectory(dataDir); dialog.setNameFilters(TabDeckEditor::fileNameFilters); From aa658f95f6c47385f9bbb310a5c80550b1511d5b Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Tue, 9 Feb 2016 03:10:57 +0000 Subject: [PATCH 14/14] Gave error dlg a description of the error for the user. --- cockatrice/src/dlg_add_set_result.cpp | 9 +++++---- cockatrice/src/dlg_add_set_result.h | 5 +++-- cockatrice/src/tab_deck_editor.cpp | 11 +++++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cockatrice/src/dlg_add_set_result.cpp b/cockatrice/src/dlg_add_set_result.cpp index 03645408..ca5107be 100644 --- a/cockatrice/src/dlg_add_set_result.cpp +++ b/cockatrice/src/dlg_add_set_result.cpp @@ -4,18 +4,19 @@ #include #include -DlgAddSetResult::DlgAddSetResult(QWidget *parent, bool success) : QDialog(parent) { +DlgAddSetResult::DlgAddSetResult(QWidget *parent, bool success, QString msg) : QDialog(parent) { status = new QLabel(this); - restart = new QLabel(this); + message = new QLabel(this); if (success) { setWindowTitle(tr("Success")); status->setText(QString("Sets/cards added to Cockatrice.")); - restart->setText(QString("You must restart Cockatrice to use the new sets/cards.")); + message->setText(QString("You must restart Cockatrice to use the new sets/cards.")); } else { setWindowTitle(tr("Failed")); status->setText(QString("Sets/cards failed to import.")); + message->setText(msg); } QDialogButtonBox *buttonBox = new QDialogButtonBox(this); @@ -25,7 +26,7 @@ DlgAddSetResult::DlgAddSetResult(QWidget *parent, bool success) : QDialog(parent QVBoxLayout *parentLayout = new QVBoxLayout(this); parentLayout->addWidget(status); - parentLayout->addWidget(restart); + parentLayout->addWidget(message); parentLayout->addWidget(buttonBox); setLayout(parentLayout); diff --git a/cockatrice/src/dlg_add_set_result.h b/cockatrice/src/dlg_add_set_result.h index 6a30af24..d7645313 100644 --- a/cockatrice/src/dlg_add_set_result.h +++ b/cockatrice/src/dlg_add_set_result.h @@ -3,15 +3,16 @@ #include #include +#include class DlgAddSetResult : public QDialog { Q_OBJECT public: - DlgAddSetResult(QWidget *parent, bool success); + DlgAddSetResult(QWidget *parent, bool success, QString msg); private slots: void closeDialog(); private: - QLabel *status, *restart; + QLabel *status, *message; QPushButton *ok; }; diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 7c170181..a874f22f 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -885,16 +885,23 @@ void TabDeckEditor::actAddCustomSet() if (!dialog.exec()) return; + QString fileName = dialog.selectedFiles().at(0); + + if (!QFile::exists(fileName)) { + DlgAddSetResult dlg(this, false, QString("Selected file cannot be found.")); + dlg.exec(); + return; + } + QDir dir(dataDir + "/customsets"); int nextPrefix = getNextCustomSetPrefix(dir); - QString fileName = dialog.selectedFiles().at(0); bool res = QFile::copy( fileName, dir.absolutePath() + "/" + (nextPrefix > 9 ? "" : "0") + QString::number(nextPrefix) + "." + QFileInfo(fileName).fileName() ); - DlgAddSetResult dlg(this, res); + DlgAddSetResult dlg(this, res, QString()); dlg.exec(); }