1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Model_FileList.h"
26 ////////////////////////////////////////////////////////////
27 // Constructor & Destructor
28 ////////////////////////////////////////////////////////////
30 FileListModel::FileListModel(void)
32 m_fileIcon(":/icons/page_white_cd.png")
36 FileListModel::~FileListModel(void)
40 ////////////////////////////////////////////////////////////
42 ////////////////////////////////////////////////////////////
44 int FileListModel::columnCount(const QModelIndex &parent) const
49 int FileListModel::rowCount(const QModelIndex &parent) const
51 return m_fileList.count();
54 QVariant FileListModel::data(const QModelIndex &index, int role) const
56 if((role == Qt::DisplayRole || role == Qt::ToolTipRole) && index.row() < m_fileList.count() && index.row() >= 0)
58 switch(index.column())
61 return m_fileList.at(index.row()).fileName();
64 return m_fileList.at(index.row()).filePath();
71 else if(role == Qt::DecorationRole && index.column() == 0)
81 QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role) const
83 if(role == Qt::DisplayRole)
85 if(orientation == Qt::Horizontal)
90 return QVariant(tr("Title"));
93 return QVariant(tr("Full Path"));
102 if(m_fileList.count() < 10)
104 return QVariant(QString().sprintf("%d", section + 1));
106 else if(m_fileList.count() < 100)
108 return QVariant(QString().sprintf("%02d", section + 1));
110 else if(m_fileList.count() < 1000)
112 return QVariant(QString().sprintf("%03d", section + 1));
116 return QVariant(QString().sprintf("%04d", section + 1));
126 void FileListModel::addFile(const QString &filePath)
128 QFileInfo fileInfo(filePath);
130 for(int i = 0; i < m_fileList.count(); i++)
132 if(m_fileList.at(i).filePath().compare(fileInfo.canonicalFilePath(), Qt::CaseInsensitive) == 0)
139 m_fileList.append(AudioFileModel(fileInfo.canonicalFilePath(), fileInfo.baseName()));
143 void FileListModel::addFile(const AudioFileModel &file)
145 for(int i = 0; i < m_fileList.count(); i++)
147 if(m_fileList.at(i).filePath().compare(file.filePath(), Qt::CaseInsensitive) == 0)
154 m_fileList.append(file);
158 bool FileListModel::removeFile(const QModelIndex &index)
160 if(index.row() >= 0 && index.row() < m_fileList.count())
163 m_fileList.removeAt(index.row());
173 void FileListModel::clearFiles(void)
180 bool FileListModel::moveFile(const QModelIndex &index, int delta)
182 if(delta != 0 && index.row() >= 0 && index.row() < m_fileList.count() && index.row() + delta >= 0 && index.row() + delta < m_fileList.count())
185 m_fileList.move(index.row(), index.row() + delta);
195 AudioFileModel FileListModel::getFile(const QModelIndex &index)
197 if(index.row() >= 0 && index.row() < m_fileList.count())
199 return m_fileList.at(index.row());
203 return AudioFileModel();
207 AudioFileModel &FileListModel::operator[] (const QModelIndex &index)
209 return m_fileList[index.row()];
212 bool FileListModel::setFile(const QModelIndex &index, const AudioFileModel &audioFile)
214 if(index.row() >= 0 && index.row() < m_fileList.count())
217 m_fileList.replace(index.row(), audioFile);