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"
27 ////////////////////////////////////////////////////////////
28 // Constructor & Destructor
29 ////////////////////////////////////////////////////////////
31 FileListModel::FileListModel(void)
33 m_fileIcon(":/icons/page_white_cd.png")
37 FileListModel::~FileListModel(void)
41 ////////////////////////////////////////////////////////////
43 ////////////////////////////////////////////////////////////
45 int FileListModel::columnCount(const QModelIndex
&parent
) const
50 int FileListModel::rowCount(const QModelIndex
&parent
) const
52 return m_fileList
.count();
55 QVariant
FileListModel::data(const QModelIndex
&index
, int role
) const
57 if((role
== Qt::DisplayRole
|| role
== Qt::ToolTipRole
) && index
.row() < m_fileList
.count() && index
.row() >= 0)
59 switch(index
.column())
62 return m_fileList
.at(index
.row()).fileName();
65 return QDir::toNativeSeparators(m_fileList
.at(index
.row()).filePath());
72 else if(role
== Qt::DecorationRole
&& index
.column() == 0)
82 QVariant
FileListModel::headerData(int section
, Qt::Orientation orientation
, int role
) const
84 if(role
== Qt::DisplayRole
)
86 if(orientation
== Qt::Horizontal
)
91 return QVariant(tr("Title"));
94 return QVariant(tr("Full Path"));
103 if(m_fileList
.count() < 10)
105 return QVariant(QString().sprintf("%d", section
+ 1));
107 else if(m_fileList
.count() < 100)
109 return QVariant(QString().sprintf("%02d", section
+ 1));
111 else if(m_fileList
.count() < 1000)
113 return QVariant(QString().sprintf("%03d", section
+ 1));
117 return QVariant(QString().sprintf("%04d", section
+ 1));
127 void FileListModel::addFile(const QString
&filePath
)
129 QFileInfo
fileInfo(filePath
);
131 for(int i
= 0; i
< m_fileList
.count(); i
++)
133 if(m_fileList
.at(i
).filePath().compare(fileInfo
.canonicalFilePath(), Qt::CaseInsensitive
) == 0)
140 m_fileList
.append(AudioFileModel(fileInfo
.canonicalFilePath(), fileInfo
.baseName()));
144 void FileListModel::addFile(const AudioFileModel
&file
)
146 for(int i
= 0; i
< m_fileList
.count(); i
++)
148 if(m_fileList
.at(i
).filePath().compare(file
.filePath(), Qt::CaseInsensitive
) == 0)
155 m_fileList
.append(file
);
159 bool FileListModel::removeFile(const QModelIndex
&index
)
161 if(index
.row() >= 0 && index
.row() < m_fileList
.count())
164 m_fileList
.removeAt(index
.row());
174 void FileListModel::clearFiles(void)
181 bool FileListModel::moveFile(const QModelIndex
&index
, int delta
)
183 if(delta
!= 0 && index
.row() >= 0 && index
.row() < m_fileList
.count() && index
.row() + delta
>= 0 && index
.row() + delta
< m_fileList
.count())
186 m_fileList
.move(index
.row(), index
.row() + delta
);
196 AudioFileModel
FileListModel::getFile(const QModelIndex
&index
)
198 if(index
.row() >= 0 && index
.row() < m_fileList
.count())
200 return m_fileList
.at(index
.row());
204 return AudioFileModel();
208 AudioFileModel
&FileListModel::operator[] (const QModelIndex
&index
)
210 return m_fileList
[index
.row()];
213 bool FileListModel::setFile(const QModelIndex
&index
, const AudioFileModel
&audioFile
)
215 if(index
.row() >= 0 && index
.row() < m_fileList
.count())
218 m_fileList
.replace(index
.row(), audioFile
);