OSDN Git Service

Update MediaInfo binaries to v0.7.53 (2012-01-24), compiled with ICL 12.1.6 and MSVC...
[lamexp/LameXP.git] / src / Model_FileSystem.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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.
14 //
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.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Model_FileSystem.h"
23 #include "Global.h"
24
25 #include <QApplication>
26 #include <QFileIconProvider>
27 #include <QDesktopServices>
28
29 ///////////////////////////////////////////////////////////////////////////////
30 // Dummy QFileIconProvider class
31 ///////////////////////////////////////////////////////////////////////////////
32
33 class QFileIconProviderEx : public QFileIconProvider
34 {
35 public:
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; }
40
41 private:
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;
60 };
61
62 QFileIconProviderEx::QFileIconProviderEx()
63 :
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")
80 {
81         /* Nothing to do! */
82 }
83
84 QIcon QFileIconProviderEx::icon(const QFileInfo &info) const
85 {
86         if(info.isFile())
87         {
88                 return m_emptyIcon;
89         }
90         else if(info.isRoot())
91         {
92                 switch(GetDriveType(QWCHAR(QDir::toNativeSeparators(info.absoluteFilePath()))))
93                 {
94                 case DRIVE_CDROM:
95                         return m_cdromIcon;
96                         break;
97                 case DRIVE_REMOVABLE:
98                         return m_floppyIcon;
99                         break;
100                 case DRIVE_REMOTE:
101                         return m_networkIcon;
102                         break;
103                 default:
104                         return m_driveIcon;
105                         break;
106                 }
107         }
108         else if(!info.filePath().compare(m_homeDir, Qt::CaseInsensitive))
109         {
110                 return m_homeIcon;
111         }
112         else if(!info.filePath().compare(m_desktopDir, Qt::CaseInsensitive))
113         {
114                 return m_desktopIcon;
115         }
116         else if(!info.filePath().compare(m_musicDir, Qt::CaseInsensitive))
117         {
118                 return m_musicIcon;
119         }
120         else if(!info.filePath().compare(m_moviesDir, Qt::CaseInsensitive))
121         {
122                 return m_moviesIcon;
123         }
124         else if(!info.filePath().compare(m_picturesDir, Qt::CaseInsensitive))
125         {
126                 return m_picturesIcon;
127         }
128         else
129         {
130                 return  m_folderIcon;
131         }
132 }
133
134 ///////////////////////////////////////////////////////////////////////////////
135 // Modified QFileSystemModel class
136 ///////////////////////////////////////////////////////////////////////////////
137
138 QFileSystemModelEx::QFileSystemModelEx()
139 :
140         QFileSystemModel()
141 {
142         this->m_myIconProvider = new QFileIconProviderEx();
143         this->setIconProvider(m_myIconProvider);
144         this->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
145         this->setNameFilterDisables(false);
146 }
147
148 QFileSystemModelEx::~QFileSystemModelEx()
149 {
150         LAMEXP_DELETE(m_myIconProvider);
151 }
152
153 bool QFileSystemModelEx::hasChildren(const QModelIndex &parent) const
154 {
155         if(parent.isValid())
156         {
157                 QDir dir = QDir(QFileSystemModel::filePath(parent));
158                 return dir.exists() && (dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot).count() > 0);
159         }
160         
161         return true;
162 }