commit
7ee396503b
4 changed files with 9 additions and 11 deletions
|
@ -4,9 +4,8 @@
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
const QStringList DeckLoader::fileNameFilters = QStringList()
|
const QStringList DeckLoader::fileNameFilters = QStringList()
|
||||||
<< QObject::tr("All files (*.*)")
|
<< QObject::tr("Common deck formats (*.cod *.dec *.mwDeck)")
|
||||||
<< QObject::tr("Cockatrice decks (*.cod)")
|
<< QObject::tr("All files (*.*)");
|
||||||
<< QObject::tr("Plain text decks (*.dec *.mwDeck)");
|
|
||||||
|
|
||||||
DeckLoader::DeckLoader()
|
DeckLoader::DeckLoader()
|
||||||
: DeckList(),
|
: DeckList(),
|
||||||
|
@ -91,11 +90,10 @@ bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckLoader::FileFormat DeckLoader::getFormatFromNameFilter(const QString &selectedNameFilter)
|
DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
|
||||||
{
|
{
|
||||||
switch (fileNameFilters.indexOf(selectedNameFilter)) {
|
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {
|
||||||
case 1: return CockatriceFormat;
|
return CockatriceFormat;
|
||||||
case 2: return PlainTextFormat;
|
|
||||||
}
|
}
|
||||||
return PlainTextFormat;
|
return PlainTextFormat;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
FileFormat getLastFileFormat() const { return lastFileFormat; }
|
FileFormat getLastFileFormat() const { return lastFileFormat; }
|
||||||
int getLastRemoteDeckId() const { return lastRemoteDeckId; }
|
int getLastRemoteDeckId() const { return lastRemoteDeckId; }
|
||||||
|
|
||||||
static FileFormat getFormatFromNameFilter(const QString &selectedNameFilter);
|
static FileFormat getFormatFromName(const QString &fileName);
|
||||||
|
|
||||||
bool loadFromFile(const QString &fileName, FileFormat fmt);
|
bool loadFromFile(const QString &fileName, FileFormat fmt);
|
||||||
bool loadFromRemote(const QString &nativeString, int remoteDeckId);
|
bool loadFromRemote(const QString &nativeString, int remoteDeckId);
|
||||||
|
|
|
@ -385,7 +385,7 @@ void TabDeckEditor::actLoadDeck()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString fileName = dialog.selectedFiles().at(0);
|
QString fileName = dialog.selectedFiles().at(0);
|
||||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromNameFilter(dialog.selectedNameFilter());
|
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
||||||
|
|
||||||
DeckLoader *l = new DeckLoader;
|
DeckLoader *l = new DeckLoader;
|
||||||
if (l->loadFromFile(fileName, fmt))
|
if (l->loadFromFile(fileName, fmt))
|
||||||
|
@ -438,7 +438,7 @@ bool TabDeckEditor::actSaveDeckAs()
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QString fileName = dialog.selectedFiles().at(0);
|
QString fileName = dialog.selectedFiles().at(0);
|
||||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromNameFilter(dialog.selectedNameFilter());
|
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
||||||
|
|
||||||
if (!deckModel->getDeckList()->saveToFile(fileName, fmt)) {
|
if (!deckModel->getDeckList()->saveToFile(fileName, fmt)) {
|
||||||
QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved.\nPlease check that the directory is writable and try again."));
|
QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved.\nPlease check that the directory is writable and try again."));
|
||||||
|
|
|
@ -154,7 +154,7 @@ void DeckViewContainer::loadLocalDeck()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString fileName = dialog.selectedFiles().at(0);
|
QString fileName = dialog.selectedFiles().at(0);
|
||||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromNameFilter(dialog.selectedNameFilter());
|
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
||||||
DeckLoader deck;
|
DeckLoader deck;
|
||||||
if (!deck.loadFromFile(fileName, fmt)) {
|
if (!deck.loadFromFile(fileName, fmt)) {
|
||||||
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
|
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
|
||||||
|
|
Loading…
Reference in a new issue