2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file task_generate_config.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 #include "task_prepare_files.h"
25 #include <dpl/file_output.h>
26 #include <dpl/file_input.h>
28 #include <dpl/log/log.h>
29 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
30 #include <dpl/binary_queue.h> // config.xml logging only
31 #include <dpl/foreach.h>
32 #include <widget_install/widget_install_context.h>
33 #include <widget_install_errors.h>
34 #include <task_commons.h>
35 #include <config_generator/config_generator.h>
38 namespace WidgetInstall {
42 const std::string TIZEN_KEYWORD = "tizen";
43 const char* BACKKEY = "backbutton-presence";
44 const char* ENABLE = "enable";
45 const char* DISABLE = "disable";
46 const char* ROTATION = "rotation-lock";
47 const char* LANDSCAPE = "landscape";
48 const char* PORTRAIT = "portrait";
49 const char* INDICATOR = "indicator-presence";
51 const char* VIEWMODES[] = {
60 TaskPrepareFiles::TaskPrepareFiles(InstallerContext &installerContext) :
61 DPL::TaskDecl<TaskPrepareFiles>(this),
62 m_installerContext(installerContext)
65 AddStep(&TaskPrepareFiles::StepShowPopup);
66 AddStep(&TaskPrepareFiles::StepCreateTempPath);
67 AddStep(&TaskPrepareFiles::StepCopyIcon);
68 AddStep(&TaskPrepareFiles::StepCreateConfig);
70 AddAbortStep(&TaskPrepareFiles::StepAbort);
73 void TaskPrepareFiles::StepCreateTempPath()
75 m_installerContext.tempWidgetPath = createTempPath();
78 void TaskPrepareFiles::StepCopyIcon()
80 if(m_installerContext.iconPath.empty()) {
81 LogWarning("No icon specified");
85 DPL::String path = DPL::FromUTF8String(m_installerContext.iconPath);
86 std::string filename = m_installerContext.iconPath;
87 size_t last = m_installerContext.iconPath.find_last_of( "\\/" );
88 if(last != std::string::npos) {
89 filename = m_installerContext.iconPath.substr( last+1 );
91 std::string target = m_installerContext.tempWidgetPath + '/' + filename;
92 LogDebug("source " << m_installerContext.iconPath << "#");
93 LogDebug("target " << target);
97 DPL::FileInput input(m_installerContext.iconPath);
98 DPL::FileOutput output(target);
99 DPL::Copy(&input, &output);
100 m_installerContext.iconPath = target;
102 Catch(DPL::FileInput::Exception::Base)
104 LogError("File input error");
105 // Error while opening or closing source file
106 ReThrowMsg(Exceptions::CopyIconFailed, m_installerContext.iconPath);
108 Catch(DPL::FileOutput::Exception::Base)
110 LogError("File output error");
111 // Error while opening or closing target file
112 ReThrowMsg(Exceptions::CopyIconFailed, target);
114 Catch(DPL::CopyFailed)
116 LogError("File copy error");
117 // Error while copying
118 ReThrowMsg(Exceptions::CopyIconFailed, target);
122 void TaskPrepareFiles::StepShowPopup()
124 LogError("Not implemented");
126 * TODO show configuration popup, store results in installer context or
127 * abort. The icon path is stored in m_installerContext.iconPath. It should
128 * be updated if necessary.
131 // TODO get user options from popup
132 m_enableIndicator = true;
135 m_viewModes.push_back(FULLSCREEN);
136 m_viewModes.push_back(WINDOWED);
137 m_viewModes.push_back(FLOATING);
138 m_viewModes.unique();
142 void TaskPrepareFiles::StepCreateConfig()
144 LogInfo("creating config.xml...");
149 ConfigXml::DocumentPtr doc = ConfigXml::Document::Create();
153 FOREACH(it, m_viewModes) {
154 modes += VIEWMODES[*it];
157 ConfigXml::ElementPtr root = doc->Add<ConfigXml::WIDGET>(
158 m_installerContext.widgetSource.c_str(),
161 // access to all sites
162 root->Add<ConfigXml::ACCESS>("*");
166 using namespace WrtDB;
167 FeatureHandleList features = FeatureDAOReadOnly::GetHandleList();
168 FOREACH(it, features) {
169 FeatureDAOReadOnly feature(*it);
170 std::string name = feature.GetName();
172 if (std::string::npos != name.find(TIZEN_KEYWORD)) {
173 root->Add<ConfigXml::FEATURE>(name.c_str(), false);
179 if (!!m_enableIndicator) {
180 root->Add<ConfigXml::TIZEN_SETTING>(
182 (*m_enableIndicator ? ENABLE : DISABLE));
185 root->Add<ConfigXml::TIZEN_SETTING>(
187 (*m_backKey ? ENABLE : DISABLE));
190 root->Add<ConfigXml::TIZEN_SETTING>(
192 (*m_portrait ? PORTRAIT : LANDSCAPE));
198 std::unique_ptr<char[]> buffer(new char[bq.Size()]);
200 bq.FlattenConsume(buffer.get(),bq.Size());
201 LogInfo("Generated XML:\n\n" << buffer.get());
203 std::string configPath =
204 m_installerContext.tempWidgetPath + "/config.xml";
206 DPL::FileOutput fo(configPath);
211 LogInfo("Config xml created");
213 Catch(ConfigXml::Base)
215 LogError("Config xml creation failed");
216 ReThrowMsg(ConfigXml::Base, m_installerContext.widgetSource);
220 void TaskPrepareFiles::StepAbort()
222 removeTemporaryDir(m_installerContext.tempWidgetPath);
225 } // namespace WidgetInstall