109812b4e8eeda45965fbb36c42fbcfc18c73923
[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
42 class InstallerContext;
43
44 namespace Jobs {
45 namespace WidgetInstall {
46 class TaskManifestFile :
47     public DPL::TaskDecl<TaskManifestFile>
48 {
49   public:
50
51     DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
52     DECLARE_EXCEPTION_TYPE(Base, ManifestValidationError)
53     DECLARE_EXCEPTION_TYPE(Base, ManifestParsingError)
54
55     TaskManifestFile(InstallerContext &inCont);
56     virtual ~TaskManifestFile();
57
58   private:
59     //context data
60     InstallerContext &m_context;
61
62     //TODO stepAbort
63     //steps
64     void stepCreateDesktopFile();
65     void stepCreateExecFile();
66     void stepFinalize();
67     void stepCopyIconFiles();
68     void stepGenerateManifest();
69     void stepParseManifest();
70     void stepParseUpgradedManifest();
71
72     //For widget update
73     void stepBackupIconFiles();
74     void stepUpdateDesktopFile();
75     void stepUpdateFinalize();
76
77     void stepAbortIconFiles();
78     void stepAbortDesktopFile();
79
80     //private data
81     std::ostringstream desktop_name;
82     std::ostringstream desktop_file;
83     std::ostringstream bp_desktop_file;
84     std::list<std::string> icon_list;
85     std::ostringstream backup_dir;
86     xmlTextWriterPtr writer;
87     DPL::String manifest_name;
88     DPL::String manifest_file;
89
90     //private methods
91     void moveDesktopFile();
92     void saveWidgetType(std::ofstream &file);
93     void saveWidgetExecPath(std::ofstream &file);
94     void saveWidgetName(std::ofstream &file);
95     void saveWidgetIcons(std::ofstream &file);
96     void saveWidgetVersion(std::ofstream &file);
97     void saveWidgetOtherInfo(std::ofstream &file);
98     void saveAppServiceInfo(std::ofstream &file);
99     void updateAilInfo();
100
101     void writeManifest(const DPL::String & path);
102     void validateManifest();
103     void commitManifest();
104
105     void setWidgetExecPath(UiApplication & uiApp);
106     void setWidgetName(Manifest & manifest, UiApplication & uiApp);
107     void setWidgetIcons(UiApplication & uiApp);
108     void setWidgetManifest(Manifest & manifest);
109     void setWidgetOtherInfo(UiApplication & uiApp);
110     void setAppServiceInfo(UiApplication & uiApp);
111
112     void generateWidgetName(Manifest & manifest, UiApplication &uiApp, const DPL::OptionalString& tag, DPL::OptionalString name, bool & defaultNameSaved);
113     void generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag, const DPL::String& language, int iconId, const WrtDB::WidgetDAOReadOnly::WidgetIconList & list, bool & defaultIconSaved);
114
115     //for widget update
116     void backupDesktopFile();
117     void backupIconFiles();
118     void getFileList(const char* path, std::list<std::string> &list);
119
120     static void saveLocalizedKey(std::ofstream &file,
121             const DPL::String& key,
122             const DPL::String& languageTag);
123     DPL::String getIconTargetFilename(const DPL::String& languageTag) const;
124
125     static const char * encoding;
126
127 };
128 } //namespace WidgetInstall
129 } //namespace Jobs
130
131 #endif /* INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_DESKTOP_FILE_H */