[Release] wrt-installer_0.1.114
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_manifest_file.h
1 /*
2  * Copyright (c) 2011 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_manifest_file.h
18  * @author  Pawel Sikorski (p.sikorski@samgsung.com)
19  * @version
20  * @brief
21  */
22
23 #ifndef INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_DESKTOP_FILE_H
24 #define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_DESKTOP_FILE_H
25
26 //SYSTEM INCLUDES
27 #include <fstream>
28
29 //WRT INCLUDES
30 #include <dpl/task.h>
31 #include <dpl/localization/localization_utils.h>
32
33 #include <libxml2/libxml/xmlwriter.h>
34
35 #include <libxml_utils.h>
36 #include <widget_install/manifest.h>
37 #include <dpl/localization/localization_utils.h>
38
39 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
40
41 class InstallerContext;
42
43 namespace Jobs {
44 namespace WidgetInstall {
45 class TaskManifestFile :
46     public DPL::TaskDecl<TaskManifestFile>
47 {
48   public:
49
50     DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
51     DECLARE_EXCEPTION_TYPE(Base, ManifestValidationError)
52     DECLARE_EXCEPTION_TYPE(Base, ManifestParsingError)
53
54     TaskManifestFile(InstallerContext &inCont);
55     virtual ~TaskManifestFile();
56
57   private:
58     //context data
59     InstallerContext &m_context;
60
61     //TODO stepAbort
62     //steps
63     void stepCreateExecFile();
64     void stepCopyIconFiles();
65     void stepCopyLiveboxFiles();
66     void stepGenerateManifest();
67
68     void stepAbortParseManifest();
69
70     //For widget update
71     void stepBackupIconFiles();
72     void stepAbortIconFiles();
73
74     void StartStep();
75     void EndStep();
76
77     //private data
78     std::list<std::string> icon_list; //TODO: this should be registered as
79                                       // external files
80     std::ostringstream backup_dir;
81     xmlTextWriterPtr writer;
82     DPL::String manifest_name;
83     DPL::String manifest_file;
84     std::string commit_manifest;
85
86     //private methods
87
88     void writeManifest(const DPL::String & path);
89     void commitManifest();
90
91     void setWidgetExecPath(UiApplication & uiApp,
92                            const std::string &postfix = std::string());
93     void setWidgetName(Manifest & manifest,
94                        UiApplication & uiApp);
95     void setWidgetIds(Manifest & manifest,
96                        UiApplication & uiApp,
97                        const std::string &postfix = std::string());
98     void setWidgetIcons(UiApplication & uiApp);
99     void setWidgetDescription(Manifest & manifest);
100     void setWidgetManifest(Manifest & manifest);
101     void setWidgetOtherInfo(UiApplication & uiApp);
102     void setAppControlsInfo(UiApplication & uiApp);
103     void setAppControlInfo(UiApplication & uiApp,
104                            const WrtDB::ConfigParserData::AppControlInfo & service);
105     void setAppCategory(UiApplication & uiApp);
106     void setMetadata(UiApplication & uiApp);
107     void setLiveBoxInfo(Manifest& manifest);
108     void setAccount(Manifest& uiApp);
109     void setPrivilege(Manifest& manifest);
110
111     void generateWidgetName(Manifest & manifest,
112                             UiApplication &uiApp,
113                             const DPL::OptionalString& tag,
114                             DPL::OptionalString name,
115                             bool & defaultNameSaved);
116     void generateWidgetDescription(Manifest & manifest,
117                                    const DPL::OptionalString& tag,
118                                    DPL::OptionalString description);
119     void generateWidgetIcon(UiApplication & uiApp,
120                             const DPL::OptionalString& tag,
121                             const DPL::String& language,
122                             bool & defaultIconSaved);
123     void DynamicBoxFileCopy(const std::string& sourceFile,
124                             const std::string& targetFile);
125
126     //for widget update
127     void backupIconFiles();
128     void getFileList(const char* path, std::list<std::string> &list);
129     DPL::String getIconTargetFilename(const DPL::String& languageTag) const;
130
131     static void saveLocalizedKey(std::ofstream &file,
132                                  const DPL::String& key,
133                                  const DPL::String& languageTag);
134
135     static const char * encoding;
136 };
137 } //namespace WidgetInstall
138 } //namespace Jobs
139
140 #endif /* INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_DESKTOP_FILE_H */