///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
+// it under the terms of the GNU GENERAL PUBLIC LICENSE as published by
// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
+// (at your option) any later version; always including the non-optional
+// LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "License.txt" file!
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "Model_FileList.h"
+//Internal
#include "Global.h"
+//MUtils
+#include <MUtils/Global.h>
+
+//Qt
#include <QFileInfo>
#include <QDir>
#include <QFile>
#define CHECK_HDR(STR,NAM) (!(STR).compare((NAM), Qt::CaseInsensitive))
#define MAKE_KEY(PATH) (QDir::fromNativeSeparators(PATH).toLower())
+static inline int LOG10(int x)
+{
+ int ret = 1;
+ while(x >= 10)
+ {
+ ret++; x /= 10;
+ }
+ return ret;
+}
+
////////////////////////////////////////////////////////////
// Constructor & Destructor
////////////////////////////////////////////////////////////
QVariant FileListModel::data(const QModelIndex &index, int role) const
{
- if((role == Qt::DisplayRole || role == Qt::ToolTipRole) && index.row() < m_fileList.count() && index.row() >= 0)
+ if(((role == Qt::DisplayRole) || (role == Qt::ToolTipRole)) && (index.row() < m_fileList.count()) && (index.row() >= 0))
{
switch(index.column())
{
break;
}
}
- else if(role == Qt::DecorationRole && index.column() == 0)
+ else if((role == Qt::DecorationRole) && (index.column() == 0))
{
return m_fileIcon;
}
}
else
{
- if(m_fileList.count() < 10)
- {
- return QVariant(QString().sprintf("%d", section + 1));
- }
- else if(m_fileList.count() < 100)
- {
- return QVariant(QString().sprintf("%02d", section + 1));
- }
- else if(m_fileList.count() < 1000)
- {
- return QVariant(QString().sprintf("%03d", section + 1));
- }
- else
- {
- return QVariant(QString().sprintf("%04d", section + 1));
- }
+ return int2str(section + 1);
}
}
else
bool FileListModel::removeFile(const QModelIndex &index)
{
- if(index.row() >= 0 && index.row() < m_fileList.count())
+ const int row = index.row();
+ if(row >= 0 && row < m_fileList.count())
{
beginResetModel();
- m_fileStore.remove(m_fileList.at(index.row()));
- m_fileList.removeAt(index.row());
+ m_fileStore.remove(m_fileList.at(row));
+ m_fileList.removeAt(row);
endResetModel();
return true;
}
- else
- {
- return false;
- }
+ return false;
}
void FileListModel::clearFiles(void)
QStringList codecList;
codecList.append(systemDefault);
- codecList.append(lamexp_available_codepages());
+ codecList.append(MUtils::available_codepages());
QInputDialog *input = new QInputDialog(parent);
input->setLabelText(EXPAND(tr("Select ANSI Codepage for CSV file:")));
if(input->exec() < 1)
{
- LAMEXP_DELETE(input);
+ MUTILS_DELETE(input);
return CsvError_Aborted;
}
codec = QTextCodec::codecForName("System");
}
- LAMEXP_DELETE(input);
+ MUTILS_DELETE(input);
}
bomCheck.clear();
{
if(stream.atEnd())
{
- LAMEXP_DELETE_ARRAY(ignore);
+ MUTILS_DELETE_ARRAY(ignore);
return CsvError_Incomplete;
}
}
else
{
- qWarning("Unkonw field '%s' will be ignored!", QUTF8(header.at(j)));
+ qWarning("Unkonw field '%s' will be ignored!", MUTILS_UTF8(header.at(j)));
ignore[j] = true;
if(!checkArray(ignore, false, nCols))
//----------------------//
- LAMEXP_DELETE_ARRAY(ignore);
+ MUTILS_DELETE_ARRAY(ignore);
return CsvError_OK;
}
return false;
}
+
+QString FileListModel::int2str(const int &value) const
+{
+ if(m_fileList.count() < 10)
+ {
+ return QString().sprintf("%d", value);
+ }
+ else
+ {
+ const QString format = QString().sprintf("%%0%dd", LOG10(m_fileList.count()));
+ return QString().sprintf(format.toLatin1().constData(), value);
+ }
+}