Updated FAQ document + small installer fix.
[LameXP.git] / src / Model_FileList.cpp
blob99bd729a554b3fce6ab523f0074be22cd71f81ad
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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"
24 #include <QFileInfo>
25 #include <QDir>
27 ////////////////////////////////////////////////////////////
28 // Constructor & Destructor
29 ////////////////////////////////////////////////////////////
31 FileListModel::FileListModel(void)
33 m_fileIcon(":/icons/page_white_cd.png")
37 FileListModel::~FileListModel(void)
41 ////////////////////////////////////////////////////////////
42 // Public Functions
43 ////////////////////////////////////////////////////////////
45 int FileListModel::columnCount(const QModelIndex &parent) const
47 return 2;
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())
61 case 0:
62 return m_fileList.at(index.row()).fileName();
63 break;
64 case 1:
65 return QDir::toNativeSeparators(m_fileList.at(index.row()).filePath());
66 break;
67 default:
68 return QVariant();
69 break;
72 else if(role == Qt::DecorationRole && index.column() == 0)
74 return m_fileIcon;
76 else
78 return QVariant();
82 QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role) const
84 if(role == Qt::DisplayRole)
86 if(orientation == Qt::Horizontal)
88 switch(section)
90 case 0:
91 return QVariant(tr("Title"));
92 break;
93 case 1:
94 return QVariant(tr("Full Path"));
95 break;
96 default:
97 return QVariant();
98 break;
101 else
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));
115 else
117 return QVariant(QString().sprintf("%04d", section + 1));
121 else
123 return QVariant();
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)
135 return;
139 beginResetModel();
140 m_fileList.append(AudioFileModel(fileInfo.canonicalFilePath(), fileInfo.baseName()));
141 endResetModel();
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)
150 return;
154 beginResetModel();
155 m_fileList.append(file);
156 endResetModel();
159 bool FileListModel::removeFile(const QModelIndex &index)
161 if(index.row() >= 0 && index.row() < m_fileList.count())
163 beginResetModel();
164 m_fileList.removeAt(index.row());
165 endResetModel();
166 return true;
168 else
170 return false;
174 void FileListModel::clearFiles(void)
176 beginResetModel();
177 m_fileList.clear();
178 endResetModel();
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())
185 beginResetModel();
186 m_fileList.move(index.row(), index.row() + delta);
187 endResetModel();
188 return true;
190 else
192 return false;
196 AudioFileModel FileListModel::getFile(const QModelIndex &index)
198 if(index.row() >= 0 && index.row() < m_fileList.count())
200 return m_fileList.at(index.row());
202 else
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())
217 beginResetModel();
218 m_fileList.replace(index.row(), audioFile);
219 endResetModel();
220 return true;
222 else
224 return false;