Commit 96fbad1f authored by Ira Aspen's avatar Ira Aspen
Browse files

Moved get next set index code to own function

parent 829f84fe
......@@ -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;
......
......@@ -3,6 +3,7 @@
#include "tab.h"
#include <QAbstractItemModel>
#include <QDir>
#include <QLineEdit>
#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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment