2010-11-25 01:23:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2011-01-01 17:04:25 +01:00
|
|
|
// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-25 01:23:48 +01:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Model_FileSystem.h"
|
2011-06-04 19:15:32 +02:00
|
|
|
#include "Global.h"
|
2010-11-25 01:23:48 +01:00
|
|
|
|
|
|
|
#include <QApplication>
|
2011-06-04 19:15:32 +02:00
|
|
|
#include <QFileIconProvider>
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Dummy QFileIconProvider class
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class QFileIconProviderEx : public QFileIconProvider
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QFileIconProviderEx();
|
|
|
|
virtual QIcon icon(IconType type) const { return (type == Drive) ? m_driveIcon : m_folderIcon; }
|
|
|
|
virtual QIcon icon(const QFileInfo &info) const;
|
|
|
|
virtual QString type (const QFileInfo &info) const { return info.isDir() ? m_folderType : m_emptyType; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const QIcon m_driveIcon;
|
|
|
|
const QIcon m_cdromIcon;
|
|
|
|
const QIcon m_networkIcon;
|
|
|
|
const QIcon m_floppyIcon;
|
|
|
|
const QIcon m_folderIcon;
|
|
|
|
const QIcon m_emptyIcon;
|
|
|
|
const QString m_folderType;
|
|
|
|
const QString m_emptyType;
|
|
|
|
};
|
|
|
|
|
|
|
|
QFileIconProviderEx::QFileIconProviderEx()
|
|
|
|
:
|
|
|
|
m_folderIcon(":/icons/folder.png"),
|
|
|
|
m_driveIcon(":/icons/drive.png"),
|
|
|
|
m_cdromIcon(":/icons/drive_cd.png"),
|
|
|
|
m_networkIcon(":/icons/drive_link.png"),
|
|
|
|
m_floppyIcon(":/icons/drive_disk.png"),
|
|
|
|
m_folderType("Folder")
|
|
|
|
{
|
|
|
|
/* Nothing to do! */
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon QFileIconProviderEx::icon(const QFileInfo &info) const
|
|
|
|
{
|
|
|
|
if(info.isRoot())
|
|
|
|
{
|
|
|
|
switch(GetDriveType(QWCHAR(QDir::toNativeSeparators(info.absoluteFilePath()))))
|
|
|
|
{
|
|
|
|
case DRIVE_CDROM:
|
|
|
|
return m_cdromIcon;
|
|
|
|
break;
|
|
|
|
case DRIVE_REMOVABLE:
|
|
|
|
return m_floppyIcon;
|
|
|
|
break;
|
|
|
|
case DRIVE_REMOTE:
|
|
|
|
return m_networkIcon;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return m_driveIcon;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return info.isFile() ? m_emptyIcon : m_folderIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Modified QFileSystemModel class
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-11-25 01:23:48 +01:00
|
|
|
|
|
|
|
QFileSystemModelEx::QFileSystemModelEx()
|
|
|
|
:
|
|
|
|
QFileSystemModel()
|
|
|
|
{
|
2011-06-04 19:15:32 +02:00
|
|
|
this->m_myIconProvider = new QFileIconProviderEx();
|
|
|
|
this->setIconProvider(m_myIconProvider);
|
2010-11-25 01:23:48 +01:00
|
|
|
this->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
|
2011-06-04 19:15:32 +02:00
|
|
|
this->setNameFilterDisables(false);
|
2010-11-25 01:23:48 +01:00
|
|
|
}
|
|
|
|
|
2011-06-04 19:15:32 +02:00
|
|
|
QFileSystemModelEx::~QFileSystemModelEx()
|
2010-11-25 01:23:48 +01:00
|
|
|
{
|
2011-06-04 19:15:32 +02:00
|
|
|
LAMEXP_DELETE(m_myIconProvider);
|
|
|
|
}
|
2010-11-25 01:23:48 +01:00
|
|
|
|
2011-06-04 19:15:32 +02:00
|
|
|
bool QFileSystemModelEx::hasChildren(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
if(parent.isValid())
|
2010-11-25 01:23:48 +01:00
|
|
|
{
|
2011-06-04 19:15:32 +02:00
|
|
|
QDir dir = QDir(QFileSystemModel::filePath(parent));
|
|
|
|
return dir.exists() && (dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot).count() > 0);
|
2010-11-25 01:23:48 +01:00
|
|
|
}
|
|
|
|
|
2011-06-04 19:15:32 +02:00
|
|
|
return true;
|
2010-11-25 01:23:48 +01:00
|
|
|
}
|