28 #include <hbinstance.h> |
28 #include <hbinstance.h> |
29 #include "hbtheme.h" |
29 #include "hbtheme.h" |
30 |
30 |
31 #include <QtCore/QDebug> |
31 #include <QtCore/QDebug> |
32 #include <QtCore/QDir> |
32 #include <QtCore/QDir> |
33 #include <hbstandarddirs_p.h> |
|
34 #include <hbiniparser_p.h> |
33 #include <hbiniparser_p.h> |
35 |
34 |
36 #define THEME_INDEX_FILE "index.theme" |
35 #define THEME_INDEX_FILE "index.theme" |
37 |
36 |
38 class HbIconThemePrivate |
37 class HbIconThemePrivate |
39 { |
38 { |
40 public: |
39 public: |
41 HbIconThemePrivate(); |
40 HbIconThemePrivate(); |
42 ~HbIconThemePrivate(); |
41 ~HbIconThemePrivate(); |
43 |
42 |
|
43 void loadThemeDescriptionFile(); |
|
44 |
|
45 public: |
44 QString m_theme; |
46 QString m_theme; |
45 QStringList m_dirList; |
|
46 QString m_description; |
47 QString m_description; |
|
48 QString m_name; |
47 bool loaded; |
49 bool loaded; |
48 void loadThemeDescriptionFile(const QString &themePath, int priority); |
|
49 void loadThemeDescriptionFiles(const QString &theme); |
|
50 bool addBaseThemePath(); |
|
51 }; |
50 }; |
52 |
|
53 void HbIconThemePrivate::loadThemeDescriptionFiles(const QString &theme) |
|
54 { |
|
55 const QString indextheme(THEME_INDEX_FILE); |
|
56 QString pathToTheme; |
|
57 QMap<int, QString> maplist = HbThemeUtils::constructHierarchyListWithPathInfo( |
|
58 QString(), theme, Hb::IconResource); |
|
59 QMapIterator<int, QString> i(maplist); |
|
60 i.toBack(); |
|
61 while (i.hasPrevious()) { |
|
62 i.previous(); |
|
63 pathToTheme = HbStandardDirs::findResource(i.value() + indextheme, Hb::IconResource); |
|
64 if (!pathToTheme.isEmpty()) { |
|
65 loadThemeDescriptionFile(pathToTheme, i.key()); |
|
66 } |
|
67 } |
|
68 if (!addBaseThemePath()) { |
|
69 qDebug() << "Can't find base theme"; |
|
70 } |
|
71 loaded = true; |
|
72 } |
|
73 |
51 |
74 HbIconThemePrivate::HbIconThemePrivate() : loaded(false) |
52 HbIconThemePrivate::HbIconThemePrivate() : loaded(false) |
75 { |
53 { |
76 } |
54 } |
77 |
55 |
78 HbIconThemePrivate::~HbIconThemePrivate() |
56 HbIconThemePrivate::~HbIconThemePrivate() |
79 { |
57 { |
80 } |
58 } |
81 |
59 |
82 void HbIconThemePrivate::loadThemeDescriptionFile(const QString &themePath, int priority) |
60 void HbIconThemePrivate::loadThemeDescriptionFile() |
83 { |
61 { |
|
62 // TODO: index file is accessed in several places, create utility |
|
63 HbThemeIndexInfo info = HbThemeUtils::getThemeIndexInfo(ActiveTheme); |
|
64 |
|
65 QString indexFileName; |
|
66 |
|
67 indexFileName.append(info.path); |
|
68 indexFileName.append("/icons/"); |
|
69 indexFileName.append(info.name); |
|
70 indexFileName.append("/" THEME_INDEX_FILE); |
|
71 |
84 HbIniParser iniParser; |
72 HbIniParser iniParser; |
85 QFile themeFile(themePath); |
73 QFile themeFile(indexFileName); |
86 |
74 |
87 if (!themeFile.open(QIODevice::ReadOnly) || !iniParser.read(&themeFile)) { |
75 if (!themeFile.open(QIODevice::ReadOnly) || !iniParser.read(&themeFile)) { |
88 qDebug() << "Can't access file : " << themePath; |
76 #ifdef HB_THEME_SERVER_TRACES |
|
77 qDebug() << "HbIconTheme: Can't access file: " << indexFileName; |
|
78 #endif |
89 return; |
79 return; |
90 } |
80 } |
91 if (priority == HbLayeredStyleLoader::Priority_Theme) { |
81 m_description = iniParser.value("Icon Theme", "Comment"); |
92 m_description = iniParser.value("Icon Theme", "Comment"); |
82 m_name = iniParser.value("Icon Theme", "Name"); |
93 #ifdef Q_OS_SYMBIAN |
83 #ifdef Q_OS_SYMBIAN |
94 m_description = m_description.left(m_description.indexOf("\n", 0)); |
84 m_description = m_description.left(m_description.indexOf("\n", 0)); |
|
85 m_name = m_name.left(m_name.indexOf("\n", 0)); |
95 #endif |
86 #endif |
96 } |
|
97 |
|
98 QString directories = iniParser.value("Icon Theme", "Directories"); |
|
99 QStringList dirList = directories.split( ',', QString::SkipEmptyParts ); |
|
100 QString indexThemeDir(themePath); |
|
101 indexThemeDir.chop(sizeof(THEME_INDEX_FILE) - 1); |
|
102 |
|
103 foreach (const QString &str, dirList) { |
|
104 m_dirList.append(QString(indexThemeDir + str + '/')); |
|
105 } |
|
106 } |
87 } |
107 |
|
108 bool HbIconThemePrivate::addBaseThemePath() |
|
109 { |
|
110 HbIniParser iniParser; |
|
111 const HbThemeInfo &baseThemeInfo = HbThemeUtils::baseTheme(); |
|
112 QString baseThemePath = baseThemeInfo.rootDir + "/themes/icons/" + baseThemeInfo.name + "/"THEME_INDEX_FILE; |
|
113 |
|
114 // Parse it |
|
115 QFile baseThemeFile(baseThemePath); |
|
116 if (!baseThemeFile.open(QIODevice::ReadOnly) || !iniParser.read(&baseThemeFile)) { |
|
117 qDebug() << "Can't access file"; |
|
118 return false; |
|
119 } |
|
120 |
|
121 if (m_theme == baseThemeInfo.name) { |
|
122 m_description = iniParser.value("Icon Theme", "Comment"); |
|
123 #ifdef Q_OS_SYMBIAN |
|
124 m_description = m_description.left(m_description.indexOf("\n", 0)); |
|
125 #endif |
|
126 } |
|
127 |
|
128 //Read parameters |
|
129 QString directories = iniParser.value("Icon Theme", "Directories"); |
|
130 QStringList dirList = directories.split(',', QString::SkipEmptyParts); |
|
131 baseThemePath.chop(sizeof(THEME_INDEX_FILE) - 1); |
|
132 // Save paths |
|
133 foreach (const QString &str, dirList) { |
|
134 m_dirList.append(QString(baseThemePath + str + '/')); |
|
135 } |
|
136 |
|
137 return true; |
|
138 } |
|
139 |
|
140 |
88 |
141 /*! |
89 /*! |
142 \class HbIconTheme |
90 \class HbIconTheme |
143 \brief HbIconTheme gives access to icon themes and stores icon theme properties |
91 \brief HbIconTheme gives access to icon themes and stores icon theme properties |
144 according to the Freedesktop Icon Theme Specification |
92 according to the Freedesktop Icon Theme Specification |
145 */ |
93 */ |
146 HbIconTheme::HbIconTheme() |
94 HbIconTheme::HbIconTheme() |
147 : d(new HbIconThemePrivate()) |
95 : d(new HbIconThemePrivate()) |
148 { |
96 { |