OSDN Git Service

Bump version.
[lamexp/LameXP.git] / src / Model_FileList.cpp
index f2ad11d..a022be2 100644 (file)
@@ -1,11 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // 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
 ////////////////////////////////////////////////////////////
@@ -65,7 +81,7 @@ int FileListModel::rowCount(const QModelIndex &parent) const
 
 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())
                {
@@ -80,7 +96,7 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
                        break;
                }               
        }
-       else if(role == Qt::DecorationRole && index.column() == 0)
+       else if((role == Qt::DecorationRole) && (index.column() == 0))
        {
                return m_fileIcon;
        }
@@ -111,22 +127,7 @@ QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int
                }
                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
@@ -170,18 +171,16 @@ void FileListModel::addFile(const AudioFileModel &file)
 
 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)
@@ -349,7 +348,7 @@ int FileListModel::importFromCsv(QWidget *parent, const QString &inFile)
 
                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:")));
@@ -360,7 +359,7 @@ int FileListModel::importFromCsv(QWidget *parent, const QString &inFile)
        
                if(input->exec() < 1)
                {
-                       LAMEXP_DELETE(input);
+                       MUTILS_DELETE(input);
                        return CsvError_Aborted;
                }
        
@@ -375,7 +374,7 @@ int FileListModel::importFromCsv(QWidget *parent, const QString &inFile)
                        codec = QTextCodec::codecForName("System");
                }
 
-               LAMEXP_DELETE(input);
+               MUTILS_DELETE(input);
        }
 
        bomCheck.clear();
@@ -427,7 +426,7 @@ int FileListModel::importFromCsv(QWidget *parent, const QString &inFile)
        {
                if(stream.atEnd())
                {
-                       LAMEXP_DELETE_ARRAY(ignore);
+                       MUTILS_DELETE_ARRAY(ignore);
                        return CsvError_Incomplete;
                }
                
@@ -494,7 +493,7 @@ int FileListModel::importFromCsv(QWidget *parent, const QString &inFile)
                        }
                        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))
@@ -508,7 +507,7 @@ int FileListModel::importFromCsv(QWidget *parent, const QString &inFile)
 
        //----------------------//
 
-       LAMEXP_DELETE_ARRAY(ignore);
+       MUTILS_DELETE_ARRAY(ignore);
        return CsvError_OK;
 }
 
@@ -521,3 +520,16 @@ bool FileListModel::checkArray(const bool *a, const bool val, size_t len)
 
        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);
+       }
+}