1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qfileiconprovider.h"
|
---|
43 |
|
---|
44 | #ifndef QT_NO_FILEICONPROVIDER
|
---|
45 | #include <qstyle.h>
|
---|
46 | #include <qapplication.h>
|
---|
47 | #include <qdir.h>
|
---|
48 | #include <qpixmapcache.h>
|
---|
49 | #if defined(Q_WS_WIN)
|
---|
50 | # define _WIN32_IE 0x0500
|
---|
51 | # include <qt_windows.h>
|
---|
52 | # include <commctrl.h>
|
---|
53 | # include <objbase.h>
|
---|
54 | #elif defined(Q_WS_PM)
|
---|
55 | # define INCL_DOSDEVIOCTL
|
---|
56 | # include <qt_os2.h>
|
---|
57 | #elif defined(Q_WS_MAC)
|
---|
58 | # include <private/qt_cocoa_helpers_mac_p.h>
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | #include <private/qfunctions_p.h>
|
---|
62 | #include <private/qguiplatformplugin_p.h>
|
---|
63 |
|
---|
64 | #if defined(Q_WS_X11) && !defined(Q_NO_STYLE_GTK)
|
---|
65 | # include <private/qgtkstyle_p.h>
|
---|
66 | # include <private/qt_x11_p.h>
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | #ifndef SHGFI_ADDOVERLAYS
|
---|
70 | # define SHGFI_ADDOVERLAYS 0x000000020
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | QT_BEGIN_NAMESPACE
|
---|
74 |
|
---|
75 | /*!
|
---|
76 | \class QFileIconProvider
|
---|
77 |
|
---|
78 | \brief The QFileIconProvider class provides file icons for the QDirModel class.
|
---|
79 | */
|
---|
80 |
|
---|
81 | /*!
|
---|
82 | \enum QFileIconProvider::IconType
|
---|
83 | \value Computer
|
---|
84 | \value Desktop
|
---|
85 | \value Trashcan
|
---|
86 | \value Network
|
---|
87 | \value Drive
|
---|
88 | \value Folder
|
---|
89 | \value File
|
---|
90 | */
|
---|
91 |
|
---|
92 | class QFileIconProviderPrivate
|
---|
93 | {
|
---|
94 | Q_DECLARE_PUBLIC(QFileIconProvider)
|
---|
95 |
|
---|
96 | public:
|
---|
97 | QFileIconProviderPrivate();
|
---|
98 | QIcon getIcon(QStyle::StandardPixmap name) const;
|
---|
99 | #ifdef Q_WS_WIN
|
---|
100 | QIcon getWinIcon(const QFileInfo &fi) const;
|
---|
101 | #elif defined(Q_WS_PM)
|
---|
102 | QIcon getPmIcon(const QFileInfo &fi) const;
|
---|
103 | #elif defined(Q_WS_MAC)
|
---|
104 | QIcon getMacIcon(const QFileInfo &fi) const;
|
---|
105 | #endif
|
---|
106 | QFileIconProvider *q_ptr;
|
---|
107 | QString homePath;
|
---|
108 |
|
---|
109 | private:
|
---|
110 | QIcon file;
|
---|
111 | QIcon fileLink;
|
---|
112 | QIcon directory;
|
---|
113 | QIcon directoryLink;
|
---|
114 | QIcon harddisk;
|
---|
115 | QIcon floppy;
|
---|
116 | QIcon cdrom;
|
---|
117 | QIcon ram;
|
---|
118 | QIcon network;
|
---|
119 | QIcon computer;
|
---|
120 | QIcon desktop;
|
---|
121 | QIcon trashcan;
|
---|
122 | QIcon generic;
|
---|
123 | QIcon home;
|
---|
124 | };
|
---|
125 |
|
---|
126 | QFileIconProviderPrivate::QFileIconProviderPrivate()
|
---|
127 | {
|
---|
128 | QStyle *style = QApplication::style();
|
---|
129 | file = style->standardIcon(QStyle::SP_FileIcon);
|
---|
130 | directory = style->standardIcon(QStyle::SP_DirIcon);
|
---|
131 | fileLink = style->standardIcon(QStyle::SP_FileLinkIcon);
|
---|
132 | directoryLink = style->standardIcon(QStyle::SP_DirLinkIcon);
|
---|
133 | harddisk = style->standardIcon(QStyle::SP_DriveHDIcon);
|
---|
134 | floppy = style->standardIcon(QStyle::SP_DriveFDIcon);
|
---|
135 | cdrom = style->standardIcon(QStyle::SP_DriveCDIcon);
|
---|
136 | network = style->standardIcon(QStyle::SP_DriveNetIcon);
|
---|
137 | computer = style->standardIcon(QStyle::SP_ComputerIcon);
|
---|
138 | desktop = style->standardIcon(QStyle::SP_DesktopIcon);
|
---|
139 | trashcan = style->standardIcon(QStyle::SP_TrashIcon);
|
---|
140 | home = style->standardIcon(QStyle::SP_DirHomeIcon);
|
---|
141 | homePath = QDir::home().absolutePath();
|
---|
142 | }
|
---|
143 |
|
---|
144 | QIcon QFileIconProviderPrivate::getIcon(QStyle::StandardPixmap name) const
|
---|
145 | {
|
---|
146 | switch (name) {
|
---|
147 | case QStyle::SP_FileIcon:
|
---|
148 | return file;
|
---|
149 | case QStyle::SP_FileLinkIcon:
|
---|
150 | return fileLink;
|
---|
151 | case QStyle::SP_DirIcon:
|
---|
152 | return directory;
|
---|
153 | case QStyle::SP_DirLinkIcon:
|
---|
154 | return directoryLink;
|
---|
155 | case QStyle::SP_DriveHDIcon:
|
---|
156 | return harddisk;
|
---|
157 | case QStyle::SP_DriveFDIcon:
|
---|
158 | return floppy;
|
---|
159 | case QStyle::SP_DriveCDIcon:
|
---|
160 | return cdrom;
|
---|
161 | case QStyle::SP_DriveNetIcon:
|
---|
162 | return network;
|
---|
163 | case QStyle::SP_ComputerIcon:
|
---|
164 | return computer;
|
---|
|
---|