Applied latest source code
[apps/native/preloaded/Installer.git] / Installer / src / IstInstallerApp.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 /**
18  * @file                IstInstallerApp.cpp
19  * @brief               This file contains the declaration of InstallerApp Class,
20  *                              which provides basic features necessary to define an UiApp.
21  */
22
23 #include "IstInstallerApp.h"
24 #include "IstMainFrame.h"
25 #include "AppResourceId.h"
26
27 using namespace Tizen::App;
28 using namespace Tizen::App::Package;
29 using namespace Tizen::Base;
30 using namespace Tizen::Ui::Controls;
31
32 InstallerApp::InstallerApp(void)
33         : __pPackageInfo(null)
34 {
35 }
36
37 InstallerApp::~InstallerApp(void)
38 {
39 }
40
41 Tizen::App::UiApp*
42 InstallerApp::CreateInstance(void)
43 {
44         return new (std::nothrow) InstallerApp();
45 }
46
47 const Tizen::App::Package::PackageInfo*
48 InstallerApp::GetPackageInfo(void) const
49 {
50         return __pPackageInfo;
51 }
52
53 Tizen::Base::String
54 InstallerApp::GetPackageFilePath(void) const
55 {
56         return __packageFilePath;
57 }
58
59
60 bool
61 InstallerApp::OnAppInitializing(Tizen::App::AppRegistry& appRegistry)
62 {
63         AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);
64
65         return true;
66 }
67
68 bool
69 InstallerApp::OnAppInitialized(void)
70 {
71         MainFrame* pMainFrame = new (std::nothrow) MainFrame();
72         pMainFrame->Construct();
73         result r = AddFrame(*pMainFrame);
74         if (IsFailed(r))
75         {
76                 return false;
77         }
78         else
79         {
80                 return true;
81         }
82 }
83
84 bool
85 InstallerApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
86 {
87         return true;
88 }
89
90 void
91 InstallerApp::OnBackground(void)
92 {
93         AppLogDebug("Enter");
94         Terminate();
95 }
96
97 void
98 InstallerApp::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId,
99                 const Tizen::Base::String* pUriData, const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData)
100 {
101         if (pExtraData)
102         {
103                 const String* pFilePath = static_cast<const String*>(pExtraData->GetValue(String(L"http://tizen.org/appcontrol/data/notification")));
104                 if (pFilePath)
105                 {
106                         __packageFilePath = *pFilePath;
107                 }
108         }
109         else if (!pUriData || !pUriData->StartsWith(L"file://", 0))
110         {
111                 AppLogException("Invalid URI date.");
112                 return;
113         }
114         else
115         {
116                 __packageFilePath = *pUriData;
117                 __packageFilePath.Replace(L"file://", L"");
118         }
119
120         AppLogDebug("file path: %ls", __packageFilePath.GetPointer());
121         __pPackageInfo = PackageManager::GetInstance()->GetPackageInfoFromFileN(__packageFilePath);
122         AppLogExceptionIf(GetLastResult() != E_SUCCESS, "[%s] Failed to get package information - %ls", GetErrorMessage(GetLastResult()), __packageFilePath.GetPointer());
123 }