Merge pull request #1796 from zebington/feat/custom-set-import
Add "Import custom set" function
This commit is contained in:
commit
bc79d9e2f8
5 changed files with 124 additions and 6 deletions
|
@ -7,6 +7,7 @@ PROJECT(cockatrice)
|
|||
SET(cockatrice_SOURCES
|
||||
src/abstractcounter.cpp
|
||||
src/counter_general.cpp
|
||||
src/dlg_add_set_result.cpp
|
||||
src/dlg_creategame.cpp
|
||||
src/dlg_filter_games.cpp
|
||||
src/dlg_connect.cpp
|
||||
|
|
38
cockatrice/src/dlg_add_set_result.cpp
Normal file
38
cockatrice/src/dlg_add_set_result.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "dlg_add_set_result.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DlgAddSetResult::DlgAddSetResult(QWidget *parent, bool success, QString msg) : QDialog(parent) {
|
||||
status = new QLabel(this);
|
||||
message = new QLabel(this);
|
||||
|
||||
if (success) {
|
||||
setWindowTitle(tr("Success"));
|
||||
status->setText(QString("Sets/cards added to Cockatrice."));
|
||||
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);
|
||||
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(message);
|
||||
parentLayout->addWidget(buttonBox);
|
||||
|
||||
setLayout(parentLayout);
|
||||
}
|
||||
|
||||
void DlgAddSetResult::closeDialog()
|
||||
{
|
||||
accept();
|
||||
}
|
19
cockatrice/src/dlg_add_set_result.h
Normal file
19
cockatrice/src/dlg_add_set_result.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef DLG_ADD_SET_RESULT_H
|
||||
#define DLG_ADD_SET_RESULT_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
#include <QString>
|
||||
|
||||
class DlgAddSetResult : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgAddSetResult(QWidget *parent, bool success, QString msg);
|
||||
private slots:
|
||||
void closeDialog();
|
||||
private:
|
||||
QLabel *status, *message;
|
||||
QPushButton *ok;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -32,6 +32,7 @@
|
|||
#include "cardinfowidget.h"
|
||||
#include "dlg_load_deck_from_clipboard.h"
|
||||
#include "dlg_edit_tokens.h"
|
||||
#include "dlg_add_set_result.h"
|
||||
#include "main.h"
|
||||
#include "settingscache.h"
|
||||
#include "priceupdater.h"
|
||||
|
@ -45,6 +46,10 @@
|
|||
#include "cardframe.h"
|
||||
#include "filterbuilder.h"
|
||||
|
||||
const QStringList TabDeckEditor::fileNameFilters = QStringList()
|
||||
<< QObject::tr("Cockatrice card database (*.xml)")
|
||||
<< QObject::tr("All files (*.*)");
|
||||
|
||||
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (treeView && ((event->key() == Qt::Key_Up) || (event->key() == Qt::Key_Down)))
|
||||
|
@ -267,6 +272,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()));
|
||||
|
||||
|
@ -303,11 +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);
|
||||
#endif
|
||||
dbMenu->addAction(aAddCustomSet);
|
||||
addTabMenu(dbMenu);
|
||||
|
||||
viewMenu = new QMenu(this);
|
||||
|
@ -584,7 +593,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 sets/cards"));
|
||||
aClose->setText(tr("&Close"));
|
||||
|
||||
aAddCard->setText(tr("Add card to &maindeck"));
|
||||
|
@ -704,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);
|
||||
|
@ -863,6 +870,55 @@ void TabDeckEditor::actOpenCustomsetsFolder() {
|
|||
|
||||
}
|
||||
|
||||
void TabDeckEditor::actAddCustomSet()
|
||||
{
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
||||
QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||
#else
|
||||
QString dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
|
||||
#endif
|
||||
|
||||
QFileDialog dialog(this, tr("Load sets/cards"));
|
||||
dialog.setDirectory(dataDir);
|
||||
dialog.setNameFilters(TabDeckEditor::fileNameFilters);
|
||||
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);
|
||||
|
||||
bool res = QFile::copy(
|
||||
fileName, dir.absolutePath() + "/" + (nextPrefix > 9 ? "" : "0") +
|
||||
QString::number(nextPrefix) + "." + QFileInfo(fileName).fileName()
|
||||
);
|
||||
|
||||
DlgAddSetResult dlg(this, res, QString());
|
||||
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;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "tab.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include <QDir>
|
||||
#include <QLineEdit>
|
||||
#include "keysignals.h"
|
||||
|
||||
|
@ -54,6 +55,7 @@ class TabDeckEditor : public Tab {
|
|||
void actAnalyzeDeck();
|
||||
void actOpenCustomFolder();
|
||||
void actOpenCustomsetsFolder();
|
||||
void actAddCustomSet();
|
||||
|
||||
void actEditSets();
|
||||
void actEditTokens();
|
||||
|
@ -88,11 +90,13 @@ 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);
|
||||
void decrementCardHelper(QString zoneName);
|
||||
void recursiveExpand(const QModelIndex &index);
|
||||
int getNextCustomSetPrefix(QDir dataDir);
|
||||
|
||||
CardDatabaseModel *databaseModel;
|
||||
CardDatabaseDisplayModel *databaseDisplayModel;
|
||||
|
@ -116,7 +120,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;
|
||||
|
|
Loading…
Reference in a new issue