1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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_FileSystem.h"
25 #include <QApplication>
26 #include <QFileIconProvider>
27 #include <QDesktopServices>
29 ///////////////////////////////////////////////////////////////////////////////
30 // Dummy QFileIconProvider class
31 ///////////////////////////////////////////////////////////////////////////////
33 class QFileIconProviderEx : public QFileIconProvider
36 QFileIconProviderEx();
37 virtual QIcon icon(IconType type) const { return (type == Drive) ? m_driveIcon : m_folderIcon; }
38 virtual QIcon icon(const QFileInfo &info) const;
39 virtual QString type (const QFileInfo &info) const { return info.isDir() ? m_folderType : m_emptyType; }
42 const QIcon m_driveIcon;
43 const QIcon m_cdromIcon;
44 const QIcon m_networkIcon;
45 const QIcon m_floppyIcon;
46 const QIcon m_folderIcon;
47 const QIcon m_homeIcon;
48 const QIcon m_desktopIcon;
49 const QIcon m_musicIcon;
50 const QIcon m_moviesIcon;
51 const QIcon m_picturesIcon;
52 const QIcon m_emptyIcon;
53 const QString m_folderType;
54 const QString m_emptyType;
55 const QString m_homeDir;
56 const QString m_desktopDir;
57 const QString m_musicDir;
58 const QString m_moviesDir;
59 const QString m_picturesDir;
62 QFileIconProviderEx::QFileIconProviderEx()
64 m_folderIcon(":/icons/folder.png"),
65 m_driveIcon(":/icons/drive.png"),
66 m_cdromIcon(":/icons/drive_cd.png"),
67 m_networkIcon(":/icons/drive_link.png"),
68 m_floppyIcon(":/icons/drive_disk.png"),
69 m_homeIcon(":/icons/house.png"),
70 m_desktopIcon(":/icons/monitor.png"),
71 m_musicIcon(":/icons/music.png"),
72 m_moviesIcon(":/icons/film.png"),
73 m_picturesIcon(":/icons/picture.png"),
74 m_homeDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::HomeLocation))),
75 m_desktopDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation))),
76 m_musicDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MusicLocation))),
77 m_moviesDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation))),
78 m_picturesDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation))),
79 m_folderType("Folder")
84 QIcon QFileIconProviderEx::icon(const QFileInfo &info) const
90 else if(info.isRoot())
92 switch(GetDriveType(QWCHAR(QDir::toNativeSeparators(info.absoluteFilePath()))))
101 return m_networkIcon;
108 else if(!info.filePath().compare(m_homeDir, Qt::CaseInsensitive))
112 else if(!info.filePath().compare(m_desktopDir, Qt::CaseInsensitive))
114 return m_desktopIcon;
116 else if(!info.filePath().compare(m_musicDir, Qt::CaseInsensitive))
120 else if(!info.filePath().compare(m_moviesDir, Qt::CaseInsensitive))
124 else if(!info.filePath().compare(m_picturesDir, Qt::CaseInsensitive))
126 return m_picturesIcon;
134 ///////////////////////////////////////////////////////////////////////////////
135 // Modified QFileSystemModel class
136 ///////////////////////////////////////////////////////////////////////////////
138 QFileSystemModelEx::QFileSystemModelEx()
142 this->m_myIconProvider = new QFileIconProviderEx();
143 this->setIconProvider(m_myIconProvider);
144 this->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
145 this->setNameFilterDisables(false);
148 QFileSystemModelEx::~QFileSystemModelEx()
150 LAMEXP_DELETE(m_myIconProvider);
153 bool QFileSystemModelEx::hasChildren(const QModelIndex &parent) const
157 return (QDir(QFileSystemModel::filePath(parent)).entryList(QDir::Dirs | QDir::NoDotAndDotDot).count() > 0);