|
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: Mifconv converter manager class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "mifconv.h" |
|
20 #include "mifconv_convertermanager.h" |
|
21 #include "mifconv_argumentmanager.h" |
|
22 #include "mifconv_util.h" |
|
23 #include "mifconv_bitmapconverter.h" |
|
24 #include "mifconv_bitmapheaderconverter.h" |
|
25 #include "mifconv_iconbinaryconverter.h" |
|
26 #include "mifconv_mifconverter.h" |
|
27 |
|
28 // Static singleton initialization |
|
29 MifConvConverterManager* MifConvConverterManager::iInstance = 0; |
|
30 |
|
31 /** |
|
32 * Returns pointer to the singleton object |
|
33 */ |
|
34 MifConvConverterManager* MifConvConverterManager::Instance() |
|
35 { |
|
36 if( iInstance == 0 ) |
|
37 { |
|
38 iInstance = new MifConvConverterManager(); |
|
39 } |
|
40 return iInstance; |
|
41 } |
|
42 |
|
43 /** |
|
44 * Free the allocated memory |
|
45 */ |
|
46 void MifConvConverterManager::Reset() |
|
47 { |
|
48 delete iInstance; |
|
49 iInstance = 0; |
|
50 } |
|
51 |
|
52 /** |
|
53 * Constructor |
|
54 */ |
|
55 MifConvConverterManager::MifConvConverterManager() |
|
56 { |
|
57 |
|
58 } |
|
59 |
|
60 /** |
|
61 * |
|
62 */ |
|
63 void MifConvConverterManager::Init() |
|
64 { |
|
65 // Add bmp --> mbm converter: |
|
66 MifConvBitmapConverter* bitmapConverter = new MifConvBitmapConverter(); |
|
67 iAllConverters.push_back(bitmapConverter); |
|
68 |
|
69 // Add headerfile (mbg) converter: |
|
70 MifConvBitmapHeaderConverter* headerConverter = new MifConvBitmapHeaderConverter(); |
|
71 iAllConverters.push_back(headerConverter); |
|
72 |
|
73 // Add svg --> svgb converter: |
|
74 MifConvIconBinaryConverter* svgConverter = new MifConvIconBinaryConverter(); |
|
75 iAllConverters.push_back(svgConverter); |
|
76 |
|
77 // Add mif converter: |
|
78 MifConvMifConverter* mifConverter = new MifConvMifConverter(); |
|
79 iAllConverters.push_back(mifConverter); |
|
80 |
|
81 // Add file converters for .BMP files: |
|
82 MifConvFileConverterList bmpConverters; |
|
83 bmpConverters.push_back(bitmapConverter); |
|
84 bmpConverters.push_back(headerConverter); |
|
85 bmpConverters.push_back(mifConverter); |
|
86 iFileConverters.insert(std::make_pair(MifConvString(BMP_FILE_EXTENSION), bmpConverters)); |
|
87 |
|
88 // Add file converters for .SVG files: |
|
89 MifConvFileConverterList svgConverters; |
|
90 svgConverters.push_back(headerConverter); |
|
91 svgConverters.push_back(svgConverter); |
|
92 if( MifConvArgumentManager::Instance()->BooleanValue(MifConvDisableSvgCompression) ) |
|
93 { |
|
94 // SVG files will be added to mif-file without compression (i.e. don't use svgtbinencode for them). |
|
95 svgConverters.push_back(mifConverter); |
|
96 } |
|
97 iFileConverters.insert(std::make_pair(MifConvString(SVG_FILE_EXTENSION), svgConverters)); |
|
98 |
|
99 // Add file converters for .SVGB files: |
|
100 MifConvFileConverterList svgbConverters; |
|
101 svgbConverters.push_back(headerConverter); |
|
102 if( !MifConvArgumentManager::Instance()->BooleanValue(MifConvDisableSvgCompression) ) |
|
103 { |
|
104 // SVG files will be compressed first. |
|
105 svgbConverters.push_back(mifConverter); |
|
106 } |
|
107 iFileConverters.insert(std::make_pair(MifConvString(SVGB_BINARY_FILE_EXTENSION), svgbConverters)); |
|
108 |
|
109 // Initialize converters |
|
110 for( MifConvFileConverterList::iterator i = iAllConverters.begin(); i != iAllConverters.end(); ++i ) |
|
111 { |
|
112 (*i)->Init(); |
|
113 } |
|
114 } |
|
115 |
|
116 /** |
|
117 * Destructor |
|
118 */ |
|
119 MifConvConverterManager::~MifConvConverterManager() |
|
120 { |
|
121 for( MifConvFileConverterList::iterator conv = iAllConverters.begin(); conv != iAllConverters.end(); ++conv ) |
|
122 { |
|
123 delete *conv; |
|
124 } |
|
125 } |
|
126 |
|
127 /** |
|
128 * Adds source files to converters and converts them |
|
129 */ |
|
130 void MifConvConverterManager::ProcessIcons() |
|
131 { |
|
132 MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance(); |
|
133 // Loop all the source files and append them to correct converters: |
|
134 const MifConvSourceFileList& sourcefiles = argMgr->SourceFiles(); |
|
135 for( MifConvSourceFileList::const_iterator i = sourcefiles.begin(); i != sourcefiles.end(); ++i ) |
|
136 { |
|
137 MifConvFileConverterList& converters = GetConverters(*i); |
|
138 for( MifConvFileConverterList::iterator converter = converters.begin(); converter != converters.end(); ++converter ) |
|
139 { |
|
140 (*converter)->AppendFile(*i); |
|
141 } |
|
142 } |
|
143 |
|
144 // Run all the converters: |
|
145 for( MifConvFileConverterList::iterator conv = iAllConverters.begin(); conv != iAllConverters.end(); ++conv ) |
|
146 { |
|
147 (*conv)->Convert(); |
|
148 } |
|
149 } |
|
150 |
|
151 /** |
|
152 * |
|
153 */ |
|
154 void MifConvConverterManager::Cleanup(bool error) |
|
155 { |
|
156 for( MifConvFileConverterList::iterator conv = iAllConverters.begin(); conv != iAllConverters.end(); ++conv ) |
|
157 { |
|
158 try { |
|
159 (*conv)->Cleanup(error); |
|
160 } |
|
161 catch(...) { |
|
162 // Exception should not be thrown if cleaning after error situation |
|
163 if( !error ) |
|
164 throw; |
|
165 } |
|
166 } |
|
167 } |
|
168 |
|
169 /** |
|
170 * |
|
171 */ |
|
172 MifConvFileConverterList& MifConvConverterManager::GetConverters(const MifConvSourceFile& source) |
|
173 { |
|
174 return GetConverters(source.Filename()); |
|
175 } |
|
176 |
|
177 /** |
|
178 * |
|
179 */ |
|
180 MifConvFileConverterList& MifConvConverterManager::GetConverters(const MifConvString& filename) |
|
181 { |
|
182 MifConvString extension(MifConvUtil::FileExtension(filename)); |
|
183 FileConverterMap::iterator i = iFileConverters.find(extension); |
|
184 if( i != iFileConverters.end() ) |
|
185 { |
|
186 return i->second; |
|
187 } |
|
188 |
|
189 return iDummyConverterList; |
|
190 } |