1 /*
2  * %kadu copyright begin%
3  * Copyright 2011 Piotr Galiszewski (piotr.galiszewski@kadu.im)
4  * Copyright 2012 Wojciech Treter (juzefwt@gmail.com)
5  * Copyright 2010, 2012, 2013 Bartosz Brachaczek (b.brachaczek@gmail.com)
6  * Copyright 2010, 2011, 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
7  * %kadu copyright end%
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "icon-theme-manager.h"
24 
25 #include "configuration/configuration.h"
26 #include "configuration/deprecated-configuration-api.h"
27 #include "misc/paths-provider.h"
28 
29 #include <QtCore/QFileInfo>
30 #include <QtCore/QStringList>
31 
defaultTheme()32 QString IconThemeManager::defaultTheme()
33 {
34 	return QStringLiteral("default");
35 }
36 
IconThemeManager(QObject * parent)37 IconThemeManager::IconThemeManager(QObject *parent) :
38 		ThemeManager{parent}
39 {
40 }
41 
~IconThemeManager()42 IconThemeManager::~IconThemeManager()
43 {
44 }
45 
setConfiguration(Configuration * configuration)46 void IconThemeManager::setConfiguration(Configuration *configuration)
47 {
48 	m_configuration = configuration;
49 }
50 
setPathsProvider(PathsProvider * pathsProvider)51 void IconThemeManager::setPathsProvider(PathsProvider *pathsProvider)
52 {
53 	m_pathsProvider = pathsProvider;
54 }
55 
init()56 void IconThemeManager::init()
57 {
58 	loadThemes();
59 	setCurrentTheme(m_configuration->deprecatedApi()->readEntry("Look", "IconTheme"));
60 	m_configuration->deprecatedApi()->writeEntry("Look", "IconTheme", currentTheme().name());
61 }
62 
defaultThemeName() const63 QString IconThemeManager::defaultThemeName() const
64 {
65 	return defaultTheme();
66 }
67 
defaultThemePaths() const68 QStringList IconThemeManager::defaultThemePaths() const
69 {
70 	// Allow local themes to override global ones.
71 	auto result = getSubDirs(m_pathsProvider->profilePath() + QStringLiteral("icons"));
72 	result += getSubDirs(m_pathsProvider->dataPath() + QStringLiteral("themes/icons"));
73 
74 	return result;
75 }
76 
isValidThemePath(const QString & themePath) const77 bool IconThemeManager::isValidThemePath(const QString &themePath) const
78 {
79 	auto kaduIconFileName = themePath + "/kadu_icons/64x64/kadu.png";
80 	QFileInfo kaduIconFile(kaduIconFileName);
81 
82 	return kaduIconFile.exists();
83 }
84 
85 #include "moc_icon-theme-manager.cpp"
86