|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cpthemeinfo.h" |
|
19 #include "cpthemeutil.h" |
|
20 |
|
21 #include <QStringList> |
|
22 #include <QSettings> |
|
23 #include <QFileInfoList> |
|
24 #include <QDir> |
|
25 #include <QList> |
|
26 |
|
27 #include <hbicon.h> |
|
28 #include <hbinstance.h> |
|
29 #include <restricted/hbthemeservices_r.h> |
|
30 |
|
31 /*! |
|
32 * This class provides utility function to get Theme information. |
|
33 */ |
|
34 |
|
35 #if defined(Q_OS_SYMBIAN) |
|
36 #include <e32std.h> |
|
37 #include <centralrepository.h> |
|
38 static const TUid KServerUid3={0x20022E82}; |
|
39 static const TUint32 KDefaultThemeNameKey = 0x2; |
|
40 |
|
41 #endif |
|
42 |
|
43 |
|
44 //Location of theme preview and background icons. |
|
45 static const QString KPreviewThumbnailNVG = "/scalable/qtg_graf_theme_preview_thumbnail.nvg"; |
|
46 static const QString KPreviewThumbnailSVG = "/scalable/qtg_graf_theme_preview_thumbnail.svg"; |
|
47 |
|
48 static const QString KBackgroundPrtNVG = "/scalable/qtg_graf_screen_bg_prt.nvg"; |
|
49 static const QString KBackgroundLscNVG = "/scalable/qtg_graf_screen_bg_lsc.nvg"; |
|
50 static const QString KBackgroundPrtSVG = "/scalable/qtg_graf_screen_bg_prt.svg"; |
|
51 static const QString KBackgroundLscSVG = "/scalable/qtg_graf_screen_bg_lsc.svg"; |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 /* |
|
58 * Builds a CpThemeInfo object given theme path and theme name. It creates the name and |
|
59 * preview icons for the object. Creates a new CpThemeInfo objects. Caller takes ownership. |
|
60 * Returns NULL if can't build the object. |
|
61 */ |
|
62 CpThemeInfo* CpThemeUtil::buildThemeInfo(const QString& themePath, const QString& themeName) |
|
63 { |
|
64 CpThemeInfo *themeInfo = new CpThemeInfo(); |
|
65 QString iconPath; |
|
66 |
|
67 QString name = themeName; |
|
68 QString hidden = ""; |
|
69 |
|
70 //first look into the index.theme file to get theme information. |
|
71 |
|
72 if(QFileInfo(themePath + "/index.theme").exists()) { |
|
73 QSettings iniSetting(themePath + "/index.theme", QSettings::IniFormat); |
|
74 iniSetting.beginGroup("Icon Theme"); |
|
75 name = iniSetting.value("Name").toString(); |
|
76 hidden = iniSetting.value("Hidden").toString(); |
|
77 iconPath = iniSetting.value("PreviewThumbnailPath").toString(); |
|
78 iniSetting.endGroup(); |
|
79 |
|
80 } |
|
81 |
|
82 if(name.isEmpty() || (hidden == "true") ||( hidden == "")) { |
|
83 return NULL; |
|
84 } |
|
85 |
|
86 themeInfo->setName(name); |
|
87 themeInfo->setItemType(CpThemeInfo::ThemeListItemType_default); |
|
88 themeInfo->setItemData(themePath); |
|
89 |
|
90 //Get the icons. Logic is as follow: |
|
91 /* 1. If the icon path is in index.theme and the icon exist, use it. |
|
92 * 2. Otherwise look for the icon in the theme folder. |
|
93 * 2. If preview icon doesn't exist, use background icon. |
|
94 * 3. If no icon exist (background or preview),use default theme icon. |
|
95 */ |
|
96 if(iconPath.isEmpty() || !QFileInfo(themePath + iconPath).exists()){ |
|
97 //Set thumbnail |
|
98 HbIcon themeIcon = getPreviewIcon(themePath); |
|
99 if(themeIcon.isNull()){ |
|
100 QString defaultThemePath = defaultTheme(); |
|
101 if(!defaultThemePath.isEmpty()) { |
|
102 themeIcon = getPreviewIcon(defaultThemePath); |
|
103 } |
|
104 } |
|
105 themeInfo->setIcon(themeIcon); |
|
106 } else { |
|
107 themeInfo->setIcon(HbIcon(themePath + iconPath)); |
|
108 } |
|
109 |
|
110 return themeInfo; |
|
111 |
|
112 } |
|
113 |
|
114 /*! |
|
115 * given a path to the theme, returns the preview icon or just a Null icon |
|
116 * if it doesn't exist. |
|
117 */ |
|
118 HbIcon CpThemeUtil::getPreviewIcon(const QString& themePath) |
|
119 { |
|
120 HbIcon themeIcon; |
|
121 if(QFileInfo(themePath + KPreviewThumbnailNVG).exists()){ |
|
122 themeIcon = HbIcon(themePath + KPreviewThumbnailNVG); |
|
123 }else if(QFileInfo(themePath + KPreviewThumbnailSVG).exists()){ |
|
124 themeIcon = HbIcon(themePath + KPreviewThumbnailSVG); |
|
125 }else if(QFileInfo(themePath + KBackgroundPrtNVG).exists()){ |
|
126 themeIcon = HbIcon(themePath + KBackgroundPrtNVG); |
|
127 }else if(QFileInfo(themePath + KBackgroundPrtSVG).exists()){ |
|
128 themeIcon = HbIcon(themePath + KBackgroundPrtSVG); |
|
129 } |
|
130 return themeIcon; |
|
131 |
|
132 } |
|
133 |
|
134 /*! Creates a list of CpThemeInfo objects representing theme information. |
|
135 * |
|
136 */ |
|
137 QList<CpThemeInfo> CpThemeUtil::buildThemeList() |
|
138 { |
|
139 QList<CpThemeInfo> themeList; |
|
140 |
|
141 QList<QPair<QString, QString> > mThemesPathList = availableThemes(); |
|
142 QPair<QString, QString>pair; |
|
143 foreach (pair, mThemesPathList) { |
|
144 QDir themeDir; |
|
145 QString name = pair.first; |
|
146 QString path = pair.second; |
|
147 themeDir.setPath( path ) ; |
|
148 CpThemeInfo* themeInfo; |
|
149 if(themeDir.exists("index.theme") && |
|
150 (themeDir.exists("scalable") || themeDir.exists("pixmap") )) { |
|
151 themeInfo = buildThemeInfo(path, name); |
|
152 if(themeInfo && !themeInfo->name().isEmpty()) { |
|
153 themeList.append(*themeInfo); |
|
154 } |
|
155 } |
|
156 } |
|
157 qSort( themeList ); |
|
158 return themeList; |
|
159 } |
|
160 |
|
161 /*! |
|
162 * Returns the default theme path. |
|
163 */ |
|
164 QString CpThemeUtil::defaultTheme() |
|
165 { |
|
166 //static because default theme doesn't change. |
|
167 static QString defaultThemePath(""); |
|
168 |
|
169 if(defaultThemePath.isEmpty()) { |
|
170 |
|
171 |
|
172 #ifdef Q_OS_SYMBIAN |
|
173 CRepository *repository = 0; |
|
174 TRAP_IGNORE(repository = CRepository::NewL(KServerUid3)); |
|
175 if (repository) { |
|
176 TBuf<256> value; |
|
177 if (KErrNone == repository->Get((TUint32)KDefaultThemeNameKey, value)) { |
|
178 QString qvalue((QChar*)value.Ptr(), value.Length()); |
|
179 defaultThemePath = qvalue.trimmed(); |
|
180 } |
|
181 value.Zero(); |
|
182 delete repository; |
|
183 } |
|
184 |
|
185 #endif |
|
186 |
|
187 } |
|
188 return defaultThemePath; |
|
189 } |
|
190 |
|
191 |
|
192 const QStringList CpThemeUtil::themeDirectories(const QList<CpThemeInfo>& themeInfoList) |
|
193 { |
|
194 QStringList themeDirs; |
|
195 |
|
196 foreach(const CpThemeInfo& themeInfo, themeInfoList) { |
|
197 QDir themePath(themeInfo.itemData()); |
|
198 QString topDir; |
|
199 if(themePath.cdUp()) { |
|
200 topDir = themePath.path(); |
|
201 if(!themeDirs.contains(topDir)) { |
|
202 themeDirs.append(topDir); |
|
203 } |
|
204 } |
|
205 } |
|
206 return themeDirs; |
|
207 } |
|
208 |
|
209 const QList< QPair< QString, QString > > CpThemeUtil::availableThemes( ) |
|
210 { |
|
211 |
|
212 QList<QPair<QString, QString> > result = HbThemeServices::availableThemes(); |
|
213 return result; |
|
214 |
|
215 } |
|
216 |
|
217 |