#include "task_prepare_files.h"
#include <memory>
#include <string>
+#include <iostream>
#include <dpl/file_output.h>
#include <dpl/file_input.h>
#include <dpl/copy.h>
#include <dpl/log/log.h>
#include <dpl/wrt-dao-ro/feature_dao_read_only.h>
-#include <dpl/binary_queue.h> // config.xml logging only
#include <dpl/foreach.h>
#include <widget_install/widget_install_context.h>
#include <widget_install_errors.h>
#include <task_commons.h>
-#include <config_generator/config_generator.h>
namespace Jobs {
namespace WidgetInstall {
-
-namespace {
-
-const std::string TIZEN_KEYWORD = "tizen";
-const char* BACKKEY = "backbutton-presence";
-const char* ENABLE = "enable";
-const char* DISABLE = "disable";
-const char* ROTATION = "rotation-lock";
-const char* LANDSCAPE = "landscape";
-const char* PORTRAIT = "portrait";
-const char* INDICATOR = "indicator-presence";
-
-const char* VIEWMODES[] = {
- "windowed ",
- "floating ",
- "fullscreen ",
- "maximized ",
- "minimized "};
-
-} // namespace
-
TaskPrepareFiles::TaskPrepareFiles(InstallerContext &installerContext) :
DPL::TaskDecl<TaskPrepareFiles>(this),
m_installerContext(installerContext)
{
- // Install steps
- AddStep(&TaskPrepareFiles::StepShowPopup);
- AddStep(&TaskPrepareFiles::StepCreateTempPath);
- AddStep(&TaskPrepareFiles::StepCopyIcon);
- AddStep(&TaskPrepareFiles::StepCreateConfig);
-
- AddAbortStep(&TaskPrepareFiles::StepAbort);
+ AddStep(&TaskPrepareFiles::StartStep);
+ AddStep(&TaskPrepareFiles::StepCopyFiles);
+ AddStep(&TaskPrepareFiles::EndStep);
}
-void TaskPrepareFiles::StepCreateTempPath()
+void TaskPrepareFiles::CopyFile(const std::string& source)
{
- m_installerContext.tempWidgetPath = createTempPath();
-}
-
-void TaskPrepareFiles::StepCopyIcon()
-{
- if(m_installerContext.iconPath.empty()) {
- LogWarning("No icon specified");
+ if (source.empty()) {
+ LogWarning("No source file specified");
return;
}
- DPL::String path = DPL::FromUTF8String(m_installerContext.iconPath);
- std::string filename = m_installerContext.iconPath;
- size_t last = m_installerContext.iconPath.find_last_of( "\\/" );
- if(last != std::string::npos) {
- filename = m_installerContext.iconPath.substr( last+1 );
+ std::string filename = source;
+ size_t last = source.find_last_of("\\/");
+ if (last != std::string::npos) {
+ filename = source.substr(last + 1);
}
- std::string target = m_installerContext.tempWidgetPath + '/' + filename;
- LogDebug("source " << m_installerContext.iconPath << "#");
+ std::string target =
+ m_installerContext.locations->getTemporaryPackageDir() + '/' +
+ filename;
+ LogDebug("source " << source);
LogDebug("target " << target);
Try
{
- DPL::FileInput input(m_installerContext.iconPath);
+ DPL::FileInput input(source);
DPL::FileOutput output(target);
DPL::Copy(&input, &output);
- m_installerContext.iconPath = target;
}
Catch(DPL::FileInput::Exception::Base)
{
LogError("File input error");
// Error while opening or closing source file
- ReThrowMsg(Exceptions::CopyIconFailed, m_installerContext.iconPath);
+ ReThrowMsg(Exceptions::CopyIconFailed, source);
}
Catch(DPL::FileOutput::Exception::Base)
{
}
}
-void TaskPrepareFiles::StepShowPopup()
+void TaskPrepareFiles::StepCopyFiles()
{
- LogError("Not implemented");
- /*
- * TODO show configuration popup, store results in installer context or
- * abort. The icon path is stored in m_installerContext.iconPath. It should
- * be updated if necessary.
- */
+ CopyFile(m_installerContext.locations->getWidgetSource());
+
+ size_t last = m_installerContext.locations->getWidgetSource().find_last_of(
+ "\\/");
+ std::string sourceDir = "";
+ if (last != std::string::npos) {
+ sourceDir = m_installerContext.locations->getWidgetSource().substr(
+ 0,
+ last
+ + 1);
+ }
- // TODO get user options from popup
- m_enableIndicator = true;
- m_backKey = false;
- (void)m_portrait;
- m_viewModes.push_back(FULLSCREEN);
- m_viewModes.push_back(WINDOWED);
- m_viewModes.push_back(FLOATING);
- m_viewModes.unique();
+ LogDebug("Icons copy...");
+ FOREACH(it, m_installerContext.widgetConfig.configInfo.iconsList) {
+ std::ostringstream os;
+ LogDebug("Coping: " << sourceDir << DPL::ToUTF8String(it->src));
+ os << sourceDir << DPL::ToUTF8String(it->src);
+ CopyFile(os.str());
+ }
}
-
-void TaskPrepareFiles::StepCreateConfig()
+void TaskPrepareFiles::StartStep()
{
- LogInfo("creating config.xml...");
-
- Try
- {
- // create document
- ConfigXml::DocumentPtr doc = ConfigXml::Document::Create();
-
- // setup view modes
- std::string modes;
- FOREACH(it, m_viewModes) {
- modes += VIEWMODES[*it];
- }
-
- ConfigXml::ElementPtr root = doc->Add<ConfigXml::WIDGET>(
- m_installerContext.widgetSource.c_str(),
- modes.c_str());
-
- // access to all sites
- root->Add<ConfigXml::ACCESS>("*");
-
- // add features
- {
- using namespace WrtDB;
- FeatureHandleList features = FeatureDAOReadOnly::GetHandleList();
- FOREACH(it, features) {
- FeatureDAOReadOnly feature(*it);
- std::string name = feature.GetName();
- // tizen only
- if (std::string::npos != name.find(TIZEN_KEYWORD)) {
- root->Add<ConfigXml::FEATURE>(name.c_str(), false);
- }
- }
- }
-
- // add settings
- if (!!m_enableIndicator) {
- root->Add<ConfigXml::TIZEN_SETTING>(
- INDICATOR,
- (*m_enableIndicator ? ENABLE : DISABLE));
- }
- if (!!m_backKey) {
- root->Add<ConfigXml::TIZEN_SETTING>(
- BACKKEY,
- (*m_backKey ? ENABLE : DISABLE));
- }
- if (!!m_portrait) {
- root->Add<ConfigXml::TIZEN_SETTING>(
- ROTATION,
- (*m_portrait ? PORTRAIT : LANDSCAPE));
- }
-
- DPL::BinaryQueue bq;
- doc->Write(bq);
-
- std::unique_ptr<char[]> buffer(new char[bq.Size()]);
-
- bq.FlattenConsume(buffer.get(),bq.Size());
- LogInfo("Generated XML:\n\n" << buffer.get());
-
- std::string configPath =
- m_installerContext.tempWidgetPath + "/config.xml";
-
- DPL::FileOutput fo(configPath);
- doc->Write(fo);
- fo.Close();
-
- // Done
- LogInfo("Config xml created");
- }
- Catch(ConfigXml::Base)
- {
- LogError("Config xml creation failed");
- ReThrowMsg(ConfigXml::Base, m_installerContext.widgetSource);
- }
+ LogDebug("--------- <TaskPrepareFiles> : START ----------");
}
-void TaskPrepareFiles::StepAbort()
+void TaskPrepareFiles::EndStep()
{
- removeTemporaryDir(m_installerContext.tempWidgetPath);
+ LogDebug("--------- <TaskPrepareFiles> : END ----------");
}
-
} // namespace WidgetInstall
} // namespace Jobs