0
|
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 |
import os
|
|
18 |
import unzip
|
|
19 |
import shutil
|
|
20 |
import logging
|
|
21 |
from themeplugin import theme_function
|
|
22 |
from theme_resource import ThemeResource
|
|
23 |
from cone.storage import filestorage
|
|
24 |
from cone.public import plugin
|
|
25 |
|
|
26 |
class ThemeContainer:
|
|
27 |
"""
|
|
28 |
This class provides extracts *.tpf files, convertts to *.mbm,*.pkg, ... files and set UID(PID)
|
|
29 |
to the setting values in the model
|
|
30 |
"""
|
|
31 |
|
|
32 |
def __init__(self, list_tpf, configuration):
|
|
33 |
self.list_tpf=list_tpf
|
|
34 |
self.configuration=configuration
|
|
35 |
self.list_theme=[]
|
|
36 |
self.logger = logging.getLogger('cone.thememl')
|
|
37 |
self.carbide = None
|
|
38 |
|
|
39 |
def create_themes(self):
|
|
40 |
"""
|
|
41 |
extractes tpf file to the temporary directory and creates Theme objects
|
|
42 |
"""
|
|
43 |
|
|
44 |
for tpf in self.list_tpf:
|
|
45 |
logging.getLogger('cone.thememl').info("Creating temp folder for %s" % tpf)
|
|
46 |
theme = Theme()
|
|
47 |
theme.set_tpf_path(tpf)
|
|
48 |
|
|
49 |
temp_tdf = os.tempnam("Theme")
|
|
50 |
os.mkdir(temp_tdf)
|
|
51 |
temp_theme = os.path.join(temp_tdf,"__temp__")
|
|
52 |
os.mkdir(temp_theme)
|
|
53 |
theme.set_temp_theme(temp_theme)
|
|
54 |
theme.set_temp_tdf(temp_tdf)
|
|
55 |
|
|
56 |
self.list_theme.append(theme)
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
def build_theme(self, theme_version):
|
|
61 |
"""
|
|
62 |
converts *.tpf files to *.mbm, *.skn, ...
|
|
63 |
"""
|
|
64 |
for theme in self.list_theme:
|
|
65 |
self.make_theme(theme, theme_version)
|
|
66 |
|
|
67 |
|
|
68 |
def prepare_active_themes(self,list_active_theme):
|
|
69 |
"""
|
|
70 |
goes through the active themes and sets theme in the list of all themes as active {set the name and
|
|
71 |
the uid number of the platform setting}
|
|
72 |
"""
|
|
73 |
default_view = self.configuration.get_default_view()
|
|
74 |
for active_theme in list_active_theme:
|
|
75 |
if active_theme.get_setting_ref():
|
|
76 |
path=active_theme.get_setting_ref().replace("/",".")
|
|
77 |
setting = default_view.get_feature(path+".localPath").get_data()
|
|
78 |
if setting != None and setting.get_value():
|
|
79 |
setting_value = setting.get_value()
|
|
80 |
self.set_settinguid_to_theme(active_theme,setting_value)
|
|
81 |
|
|
82 |
def set_settinguid_to_theme(self,active_theme, path):
|
|
83 |
"""
|
|
84 |
finds out the active theme and set the name and the uid of the platform setting
|
|
85 |
"""
|
|
86 |
path = "/content/"+path
|
|
87 |
for theme in self.list_theme:
|
|
88 |
tpf_path = theme.get_tpf_path()
|
|
89 |
|
|
90 |
if tpf_path.endswith(path):
|
|
91 |
for setting_uid in active_theme.get_setting_uids():
|
|
92 |
setting_uid_value = setting_uid.replace("/",".")
|
|
93 |
theme.set_setting_uids(setting_uid_value)
|
|
94 |
theme.set_uid(active_theme.get_uid())
|
|
95 |
|
|
96 |
def set_active_PID_to_model(self):
|
|
97 |
"""
|
|
98 |
finds active theme, gets PID from pkg file, convert PID from hexadecimal to decimal formal
|
|
99 |
and set decimal PID to the aknskins setting in the model
|
|
100 |
"""
|
|
101 |
l = len (self.list_theme)
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
for theme in self.list_theme:
|
|
106 |
|
|
107 |
|
|
108 |
default_view = self.configuration.get_default_view()
|
|
109 |
|
|
110 |
for setting_uid in theme.get_setting_uids():
|
|
111 |
aknskins_setting = default_view.get_feature(setting_uid)
|
|
112 |
if(theme.get_uid()):
|
|
113 |
uid = int(theme.get_uid(),16)
|
|
114 |
aknskins_setting.set_value(str(uid))
|
|
115 |
else:
|
|
116 |
PID = theme_function.find_text_in_file(os.path.join(theme.get_temp_theme(), "themepackage.pkg"), "!:\\resource\\skins\\", "\\")
|
|
117 |
dec_PID = theme_function.convert_hexa_to_decimal(PID)
|
|
118 |
if dec_PID and aknskins_setting:
|
|
119 |
dec_PID = theme_function.convert_hexa_to_decimal(PID)
|
|
120 |
aknskins_setting.set_value(str(dec_PID))
|
|
121 |
|
|
122 |
def make_theme(self, theme, theme_version):
|
|
123 |
"""
|
|
124 |
converts the *tdf, *. svg files to *.mbm, *.pkg files, ...
|
|
125 |
The first this method extracts tpf file and then calls carbide.ui command-line
|
|
126 |
which converts theme.
|
|
127 |
"""
|
|
128 |
output_path = theme.get_temp_theme()
|
|
129 |
|
|
130 |
if not os.path.exists(output_path):
|
|
131 |
os.makedirs(output_path)
|
|
132 |
|
|
133 |
storagepath = self.configuration.get_storage().get_path()
|
|
134 |
|
|
135 |
input_path = theme.get_tpf_path().replace("/","\\")
|
|
136 |
|
|
137 |
zip_output= theme.get_temp_tdf() + "\\"
|
|
138 |
self.unzip_tpf(theme,zip_output)
|
|
139 |
|
|
140 |
name_tdf = theme_function.get_tdf_file(zip_output)
|
|
141 |
name_tdf = os.path.join(name_tdf,name_tdf+".tdf")
|
|
142 |
input_tdf = os.path.join(zip_output,name_tdf)
|
|
143 |
|
|
144 |
command_line = "makepackage -input " + input_tdf + " -output " + output_path
|
|
145 |
|
|
146 |
if len(theme_version) != 0:
|
|
147 |
command_line = command_line + " -ver "+ theme_version
|
|
148 |
|
|
149 |
if theme.get_uid() != None:
|
|
150 |
command_line = command_line + " -uid " + theme.get_uid()
|
|
151 |
|
|
152 |
logging.getLogger('cone.thememl').info("Building theme: %s" % command_line)
|
|
153 |
current_dir = os.getcwd()
|
|
154 |
os.chdir(self.carbide)
|
|
155 |
os.system(command_line)
|
|
156 |
os.chdir(current_dir)
|
|
157 |
|
|
158 |
|
|
159 |
def unzip_tpf(self, theme, zip_output):
|
|
160 |
"""
|
|
161 |
unzip the tpf file to output directory
|
|
162 |
"""
|
|
163 |
f_storage = filestorage.FileStorage(theme.get_temp_tdf(), 'wb')
|
|
164 |
list=[]
|
|
165 |
list.append(theme.get_tpf_path())
|
|
166 |
storage = self.configuration.get_storage()
|
|
167 |
storage.export_resources(list, f_storage)
|
|
168 |
|
|
169 |
tpf_file = os.path.join(theme.get_temp_tdf(),theme.get_tpf_path().replace("/","\\"))
|
|
170 |
|
|
171 |
unzip.unzip_file_into_dir(tpf_file,zip_output)
|
|
172 |
|
|
173 |
|
|
174 |
def copy_resources_to_output(self,output):
|
|
175 |
"""
|
|
176 |
copies *.mbm, *.skn ... to respective directories in the output directory
|
|
177 |
"""
|
|
178 |
for theme in self.list_theme:
|
|
179 |
#gets list of path where *.mbm, *.skn, ... will be copied
|
|
180 |
theme_resource = ThemeResource()
|
|
181 |
theme_resource.parse_pkg_file(os.path.join(theme.get_temp_theme(), "themepackage.pkg"))
|
|
182 |
|
|
183 |
# copies *.mbm, *.skn ... to target paths
|
|
184 |
theme_resource.copy_files_from_theme(theme.get_temp_theme(), output)
|
|
185 |
|
|
186 |
|
|
187 |
def removeTempDirs(self):
|
|
188 |
"""
|
|
189 |
remove temporary directories
|
|
190 |
"""
|
|
191 |
|
|
192 |
for theme in self.list_theme:
|
|
193 |
shutil.rmtree(theme.get_temp_tdf())
|
|
194 |
|
|
195 |
class Theme:
|
|
196 |
"""
|
|
197 |
This class has information about theme. It contains path of tpf file and temporary directories
|
|
198 |
where the theme was extracted and builded
|
|
199 |
Ans also it contains information about the name of setting which has value as UID. The theme
|
|
200 |
hasn't to have this the name of setting.
|
|
201 |
"""
|
|
202 |
def __init__(self):
|
|
203 |
#where the theme was extracted
|
|
204 |
self.temp_tdf = ""
|
|
205 |
#where the theme was builded
|
|
206 |
self.temp_theme = ""
|
|
207 |
#the path of tpf file
|
|
208 |
self.tpf_path = ""
|
|
209 |
# the name of the setting which contains UID
|
|
210 |
self.setting_uids = []
|
|
211 |
self.uids = []
|
|
212 |
self.uid = None
|
|
213 |
|
|
214 |
def set_tpf_path(self, tpf_path):
|
|
215 |
self.tpf_path = tpf_path
|
|
216 |
|
|
217 |
def get_tpf_path(self):
|
|
218 |
return self.tpf_path
|
|
219 |
|
|
220 |
def set_temp_tdf(self, temp_tdf):
|
|
221 |
self.temp_tdf = temp_tdf
|
|
222 |
|
|
223 |
def get_temp_tdf(self):
|
|
224 |
return self.temp_tdf
|
|
225 |
|
|
226 |
def set_temp_theme(self, temp_theme):
|
|
227 |
self.temp_theme = temp_theme
|
|
228 |
|
|
229 |
def get_temp_theme(self):
|
|
230 |
return self.temp_theme
|
|
231 |
|
|
232 |
def set_setting_uids(self, setting_uid):
|
|
233 |
self.setting_uids.append(setting_uid)
|
|
234 |
|
|
235 |
def get_setting_uids(self):
|
|
236 |
return self.setting_uids
|
|
237 |
|
|
238 |
def set_uid(self, uid):
|
|
239 |
self.uid = uid
|
|
240 |
|
|
241 |
def get_uid(self):
|
|
242 |
return self.uid
|
|
243 |
|
|
244 |
class ActiveTheme(object):
|
|
245 |
"""
|
|
246 |
This class performs information from thememl file.
|
|
247 |
It contains the name of settig (its value contains the path of tpf file) and
|
|
248 |
the name of setting which contains UID
|
|
249 |
|
|
250 |
"""
|
|
251 |
|
|
252 |
def __init__(self):
|
|
253 |
self.ref_setting = None
|
|
254 |
self.setting_uids = []
|
|
255 |
self.uid = None
|
|
256 |
|
|
257 |
def set_setting_ref(self, ref_setting):
|
|
258 |
self.ref_setting = ref_setting
|
|
259 |
|
|
260 |
def set_setting_uids(self, setting_uid):
|
|
261 |
self.setting_uids.append(setting_uid)
|
|
262 |
|
|
263 |
def get_setting_ref(self):
|
|
264 |
return self.ref_setting
|
|
265 |
|
|
266 |
def get_setting_uids(self):
|
|
267 |
return self.setting_uids
|
|
268 |
|
|
269 |
def get_uid(self):
|
|
270 |
return self.uid
|
|
271 |
|
|
272 |
def set_uid(self,uid):
|
|
273 |
self.uid = uid |