cc20d7656a6fb23e44b434d39f8fc268812c6402
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_livebox_conf.cpp
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file    task_livebox_conf.cpp
18  * @author  Tomasz Iwanek (t.iwanek@samsung.com)
19  * @version 1.0
20  * @brief   Livebox support task
21  */
22
23 #include "task_livebox_conf.h"
24
25 #include <dpl/log/log.h>
26 #include <dpl/string.h>
27 #include <dpl/utils/wrt_utility.h>
28 #include <dpl/wrt-dao-rw/widget_dao.h>
29 #include <dpl/file_input.h>
30 #include <dpl/file_output.h>
31 #include <dpl/copy.h>
32 #include <dpl/utils/wrt_utility.h>
33
34 #include <widget_install_context.h>
35
36 TaskLiveboxConf::TaskLiveboxConf(InstallerContext &inCont) :
37     DPL::TaskDecl<TaskLiveboxConf>(this),
38     m_context(inCont)
39 {
40     AddStep(&TaskLiveboxConf::StepConfigureLivebox);
41 }
42
43 void TaskLiveboxConf::StepConfigureLivebox()
44 {
45     const std::string confFile = getLiveboxConfiguration();
46     const std::string liveboxDir = std::string("/opt/live/")
47             + DPL::ToUTF8String(*m_context.widgetConfig.pkgname);
48     const std::string destination = liveboxDir + "/etc/";
49     const std::string targetFile = destination + getLiveboxConfigurationFile();
50
51     if(WrtUtilFileExists(confFile))
52     {
53         WrtUtilMakeDir(destination);
54
55         LogDebug("Registering widget's livebox directory under /opt/live/");
56         m_context.locations->registerExternalLocation(liveboxDir);
57
58         LogInfo("Coping livebox configuration file: " << confFile << " -> " << targetFile);
59         DPL::FileInput input(confFile);
60         DPL::FileOutput output(targetFile);
61         DPL::Copy(&input, &output);
62     }
63     else
64     {
65         LogInfo("No livebox configuration file: " << confFile);
66     }
67 }
68
69 std::string TaskLiveboxConf::getLiveboxConfigurationDirectory() const
70 {
71     return m_context.locations->getSourceDir() + "/livebox/";
72 }
73
74 std::string TaskLiveboxConf::getLiveboxConfigurationFile() const
75 {
76     return DPL::ToUTF8String(*m_context.widgetConfig.pkgname) + ".conf";
77 }
78
79 std::string TaskLiveboxConf::getLiveboxConfiguration() const
80 {
81     return getLiveboxConfigurationDirectory() + getLiveboxConfigurationFile();
82 }