Applied latest source code
[apps/native/preloaded/Installer.git] / Installer / src / IstInstalledPopup.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                InstalledPopup.cpp
19  * @brief               This is the implementation file for InstalledPopup class.
20  */
21
22 #include <FApp.h>
23 #include <FBase.h>
24 #include <FUi.h>
25 #include "AppResourceId.h"
26 #include "IstInstalledPopup.h"
27
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Ui;
32 using namespace Tizen::Ui::Controls;
33
34 InstalledPopup::InstalledPopup()
35         : __pTarget(null)
36         , __isLaunchable(true)
37 {
38 }
39
40 InstalledPopup::~InstalledPopup()
41 {
42 }
43
44 result
45 InstalledPopup::Initialize(Tizen::Ui::Control* pTarget)
46 {
47         result r = Construct(IDL_INSTALLED_POPUP);
48         if (IsFailed(r))
49         {
50                 AppLogException("[%s] Failed to construct popup.", GetErrorMessage(r));
51                 return r;
52         }
53
54         __pTarget = pTarget;
55
56         return r;
57 }
58
59 result
60 InstalledPopup::RequestPopup(const Tizen::Base::String& appName, const Tizen::Base::String& installedVersion,
61                 const Tizen::Base::String& downloadedVersion, bool isLaunchable)
62 {
63         AppResource* pAppResource = AppResource::GetInstance();
64         int compare = downloadedVersion.CompareTo(installedVersion);
65         if (compare > 0)
66         {
67                 pAppResource->GetString(IDS_APINST_POP_AN_OLDER_VERSION_IS_ALREADY_INSTALLED_ON_YOUR_DEVICE_IT_WILL_BE_UPDATED, __installMessage);
68
69                 String buttonString;
70                 pAppResource->GetString(IDS_APINST_BUTTON_UPDATE, buttonString);
71                 static_cast<Button*>(GetControl(IDC_BUTTON_REINSTALL, true))->SetText(buttonString);
72         }
73         else if (compare < 0)
74         {
75                 pAppResource->GetString(IDS_APINST_POP_A_NEWER_VERSION_IS_ALREADY_INSTALLED_ON_YOUR_DEVICE_IT_WILL_BE_REPLACED_WITH_THE_OLDER_VERSION, __installMessage);
76         }
77         else
78         {
79                 pAppResource->GetString(IDS_APINST_POP_THIS_VERSION_IS_ALREADY_INSTALLED_ON_YOUR_DEVICE_IT_WILL_BE_REINSTALLED, __installMessage);
80         }
81
82         String version;
83         pAppResource->GetString(IDS_APINST_BODY_INSTALLED_VERSION_C_ABB, version);
84         version.Format(version.GetLength() + installedVersion.GetLength(), version.GetPointer(), installedVersion.GetPointer());
85         __versionMessage = version;
86         __versionMessage.Append(L"\n");
87
88         pAppResource->GetString(IDS_APINST_BODY_DOWNLOADED_VERSION_C_ABB, version);
89         version.Format(version.GetLength() + downloadedVersion.GetLength(), version.GetPointer(), downloadedVersion.GetPointer());
90         __versionMessage.Append(version);
91
92         __isLaunchable = isLaunchable;
93
94         SetShowState(true);
95         return Show();
96 }
97
98 result
99 InstalledPopup::OnInitializing(void)
100 {
101         AppLogDebug("Enter");
102         SetPropagatedKeyEventListener(this);
103
104         Label* pMessage = static_cast<Label*>(GetControl(IDC_LABEL_MESSAGE));
105         pMessage->SetText(__installMessage);
106
107         Label* pVersionInfo = static_cast<Label*>(GetControl(IDC_LABEL_VERSION));
108         pVersionInfo->SetText(__versionMessage);
109
110         Button* pReInstallButton = static_cast<Button*>(GetControl(IDC_BUTTON_REINSTALL, true));
111         pReInstallButton->SetActionId(IDA_BUTTON_REINSTALL);
112         pReInstallButton->AddActionEventListener(*this);
113
114         Button* pLaunchButton = static_cast<Button*>(GetControl(IDC_BUTTON_LAUNCH, true));
115         pLaunchButton->SetActionId(IDA_BUTTON_LAUNCH);
116         pLaunchButton->AddActionEventListener(*this);
117
118         Button* pCancelButton = static_cast<Button*>(GetControl(IDC_BUTTON_CANCEL, true));
119         pCancelButton->SetActionId(IDA_BUTTON_CANCEL);
120         pCancelButton->AddActionEventListener(*this);
121
122         if (!__isLaunchable)
123         {
124                 GridLayout* pLayout = static_cast<GridLayout*>(static_cast<Panel*>(GetControl(IDC_PANEL))->GetLandscapeLayoutN());
125                 pLayout->SetColumnCollapsed(2, true);
126                 pLayout->Update();
127                 delete pLayout;
128                 pLayout = static_cast<GridLayout*>(static_cast<Panel*>(GetControl(IDC_PANEL))->GetPortraitLayoutN());
129                 pLayout->SetColumnCollapsed(2, true);
130                 pLayout->Update();
131                 delete pLayout;
132         }
133
134         return E_SUCCESS;
135 }
136
137 result
138 InstalledPopup::OnTerminating(void)
139 {
140         AppLogDebug("Enter");
141         SetPropagatedKeyEventListener(null);
142         return E_SUCCESS;
143 }
144
145 void
146 InstalledPopup::OnActionPerformed(const Control& source, int actionId)
147 {
148         SetShowState(false);
149
150         if (__pTarget)
151         {
152                 __pTarget->SendUserEvent(actionId, null);
153         }
154 }
155
156 bool
157 InstalledPopup::OnKeyReleased(Tizen::Ui::Control &source, const Tizen::Ui::KeyEventInfo &keyEventInfo)
158 {
159         AppLogDebug("%d", keyEventInfo.GetKeyCode());
160         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
161         {
162                 SetShowState(false);
163                 if (__pTarget)
164                 {
165                         __pTarget->SendUserEvent(IDA_BUTTON_CANCEL, null);
166                 }
167         }
168
169         return false;
170 }