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