1
/**************************************************************************
3
* Copyright 2014 Canonical Ltd.
4
* Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; version 3.
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 Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
29
bool FMUtil::m_triedThemeName = false;
37
* \brief FMUtil::setThemeName() tries to set a theme name in order to get icons
39
void FMUtil::setThemeName()
42
//set saying we have tried to set ThemeName
43
m_triedThemeName = true;
44
QLatin1String ubuntu_mobileTheme("ubuntu-mobile");
45
QStringList paths(QIcon::themeSearchPaths());
46
#if defined(Q_OS_UNIX)
49
paths.append(QLatin1String("/usr/share/icons"));
52
foreach (const QString& dir, paths)
58
qDebug() << Q_FUNC_INFO << "trying theme on Dir" << D.path();
60
QFileInfoList inf = D.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::System );
61
int counter = inf.count();
65
if (inf.at(counter).fileName() == ubuntu_mobileTheme)
67
if (testThemeName(ubuntu_mobileTheme))
73
inf.removeAt(counter);
78
counter = inf.count();
81
if (inf.at(counter).isSymLink())
83
if (testThemeName(inf.at(counter).fileName()))
89
inf.removeAt(counter);
93
//try common directories
94
counter = inf.count();
97
if (testThemeName(inf.at(counter).fileName()))
105
QIcon::setThemeName(name);
109
bool FMUtil::testThemeName(const QString& themeName)
111
QMimeDatabase mimeBase;
112
QStringList mimesToTest = QStringList()
116
<< "application/postscript"
117
<< "application/x-gzip";
119
QIcon::setThemeName(themeName);
120
bool hasTheme = true;
121
int counter = mimesToTest.count();
122
while(hasTheme && counter--)
124
QMimeType mimetype = mimeBase.mimeTypeForName(mimesToTest.at(counter));
125
hasTheme = QIcon::hasThemeIcon( mimetype.iconName() ) ||
126
QIcon::hasThemeIcon( mimetype.genericIconName() ) ;
129
qDebug() << Q_FUNC_INFO << "trying theme name" << themeName << "ret=" << hasTheme;