|
1 /* |
|
2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.mj.impl.installer.ui.eswt2; |
|
20 |
|
21 import com.nokia.mj.impl.installer.ui.ApplicationInfo; |
|
22 import com.nokia.mj.impl.installer.ui.InstallInfo; |
|
23 |
|
24 import java.io.InputStream; |
|
25 |
|
26 import org.eclipse.swt.SWT; |
|
27 import org.eclipse.swt.SWTException; |
|
28 import org.eclipse.swt.graphics.Image; |
|
29 import org.eclipse.swt.graphics.Point; |
|
30 import org.eclipse.swt.layout.GridData; |
|
31 import org.eclipse.swt.widgets.Combo; |
|
32 import org.eclipse.swt.widgets.Composite; |
|
33 import org.eclipse.swt.widgets.Button; |
|
34 import org.eclipse.swt.widgets.Event; |
|
35 import org.eclipse.swt.widgets.Label; |
|
36 import org.eclipse.swt.widgets.Link; |
|
37 import org.eclipse.swt.widgets.Listener; |
|
38 import org.eclipse.swt.widgets.Shell; |
|
39 import org.eclipse.swt.widgets.Text; |
|
40 |
|
41 /** |
|
42 * InstallConfirmationView asks installation confirmation |
|
43 * from the user. |
|
44 */ |
|
45 public class InstallConfirmationView extends ConfirmationViewBase |
|
46 { |
|
47 private InstallInfo iInstallInfo = null; |
|
48 private Combo iDriveSelector = null; |
|
49 private Button iRetainDataButton = null; |
|
50 |
|
51 /** Constructor */ |
|
52 protected InstallConfirmationView() |
|
53 { |
|
54 super(); |
|
55 } |
|
56 |
|
57 /** Constructor */ |
|
58 protected InstallConfirmationView(InstallerUiEswt aInstaller, Composite aParent) |
|
59 { |
|
60 super(aInstaller, aParent, 8); |
|
61 setTitle(InstallerUiTexts.get(InstallerUiTexts.INSTALL)); |
|
62 setCommands(InstallerUiTexts.get(InstallerUiTexts.OK), |
|
63 InstallerUiTexts.get(InstallerUiTexts.CANCEL)); |
|
64 } |
|
65 |
|
66 /** |
|
67 * Synchoronous method for asking user confirmation. |
|
68 */ |
|
69 public boolean confirm(InstallInfo aInstallInfo) |
|
70 { |
|
71 iInstallInfo = aInstallInfo; |
|
72 boolean result = confirm(); |
|
73 if (result) |
|
74 { |
|
75 log("installConfirmationView confirmed"); |
|
76 } |
|
77 else |
|
78 { |
|
79 log("installConfirmationView cancelled"); |
|
80 } |
|
81 return result; |
|
82 } |
|
83 |
|
84 /** |
|
85 * Calls setVisible method for superclass and calls |
|
86 * InstallerUiListener.uiIsReady when this view is |
|
87 * set visible for the first time, |
|
88 */ |
|
89 private boolean iUiListenerNotified = false; |
|
90 public void setVisible(boolean aVisible) |
|
91 { |
|
92 super.setVisible(aVisible); |
|
93 if (aVisible && !iUiListenerNotified && |
|
94 iInstallerUi.getListener() != null) |
|
95 { |
|
96 // Tell installer that UI is now ready and |
|
97 // "preparing installation" indicator can be hidden. |
|
98 iInstallerUi.getListener().uiIsReady(); |
|
99 iUiListenerNotified = true; |
|
100 } |
|
101 } |
|
102 |
|
103 /** |
|
104 * This method is called once before view is opened. |
|
105 */ |
|
106 protected void createView() |
|
107 { |
|
108 // Add header. |
|
109 String title = "Install?"; |
|
110 if (iInstallInfo != null) |
|
111 { |
|
112 if (iInstallInfo.getOldVersion() != null) |
|
113 { |
|
114 title = "Update?"; |
|
115 } |
|
116 } |
|
117 addHeader(title, iInstallInfo, null); |
|
118 |
|
119 GridData gridData = null; |
|
120 int horizontalSpan = getColumns(); |
|
121 int labelStyle = SWT.WRAP; |
|
122 |
|
123 // Begin user selection widgets creation. |
|
124 int[] driveIds = iInstallInfo.getDriveIds(); |
|
125 if (driveIds != null && driveIds.length > 0) |
|
126 { |
|
127 // Add installation drive selector. |
|
128 //Label drivesLabel = createLabel( |
|
129 // InstallerUiTexts.get(InstallerUiTexts.INSTALL_TO_DRIVE), |
|
130 // horizontalSpan, labelStyle); |
|
131 iDriveSelector = new Combo(getComposite(), SWT.READ_ONLY); |
|
132 gridData = new GridData(GridData.FILL_HORIZONTAL); |
|
133 gridData.horizontalSpan = horizontalSpan; |
|
134 iDriveSelector.setLayoutData(gridData); |
|
135 int[] driveTypes = iInstallInfo.getDriveTypes(); |
|
136 long[] driveFreeSpaces = iInstallInfo.getDriveFreeSpaces(); |
|
137 int driveIndex = 0; |
|
138 if (driveTypes != null && driveFreeSpaces != null) |
|
139 { |
|
140 for (int i = 0; i < driveIds.length && |
|
141 i < driveTypes.length && |
|
142 i < driveFreeSpaces.length; i++) |
|
143 { |
|
144 iDriveSelector.add(getDriveString(driveIds[i], |
|
145 driveTypes[i], |
|
146 driveFreeSpaces[i])); |
|
147 if (iInstallInfo.getDriveId() == driveIds[i]) |
|
148 { |
|
149 driveIndex = i; |
|
150 } |
|
151 } |
|
152 iDriveSelector.select(driveIndex); |
|
153 } |
|
154 addSoftKeyListenerFor(iDriveSelector); |
|
155 } |
|
156 |
|
157 if (iInstallInfo.getRetainData() != null) |
|
158 { |
|
159 // Add retain user data option. |
|
160 iRetainDataButton = new Button(getComposite(), SWT.CHECK); |
|
161 gridData = new GridData(GridData.FILL_HORIZONTAL); |
|
162 gridData.horizontalSpan = horizontalSpan; |
|
163 iRetainDataButton.setLayoutData(gridData); |
|
164 iRetainDataButton.setSelection |
|
165 (iInstallInfo.getRetainData().booleanValue()); |
|
166 iRetainDataButton.setText(InstallerUiTexts.get |
|
167 (InstallerUiTexts.RETAIN_USER_DATA)); |
|
168 addSoftKeyListenerFor(iRetainDataButton); |
|
169 } |
|
170 // End of user selection widgets creation. |
|
171 |
|
172 // After other widgets have been added, add content to |
|
173 // application info Composite. |
|
174 addAppInfo(iInstallInfo, true); |
|
175 } |
|
176 |
|
177 /** |
|
178 * This method is called after user has answered |
|
179 * to confirmation. |
|
180 */ |
|
181 protected void getDataFromView() |
|
182 { |
|
183 if (iDriveSelector != null && !iDriveSelector.isDisposed()) |
|
184 { |
|
185 int selectionIndex = iDriveSelector.getSelectionIndex(); |
|
186 int drive = -1; |
|
187 if (selectionIndex >= 0) |
|
188 { |
|
189 drive = iInstallInfo.getDriveIds()[selectionIndex]; |
|
190 } |
|
191 iInstallInfo.setDriveId(drive); |
|
192 log("Selected drive: " + drive); |
|
193 } |
|
194 if (iRetainDataButton != null && !iRetainDataButton.isDisposed()) |
|
195 { |
|
196 boolean selection = iRetainDataButton.getSelection(); |
|
197 iInstallInfo.setRetainData(selection); |
|
198 log("RetainData: " + selection); |
|
199 } |
|
200 } |
|
201 |
|
202 /** |
|
203 * Returns SWT style for this view. |
|
204 */ |
|
205 protected int getStyle() |
|
206 { |
|
207 return SWT.V_SCROLL; |
|
208 } |
|
209 |
|
210 /** |
|
211 * Returns drive name to be displayed in the UI. |
|
212 */ |
|
213 private String getDriveString(int aId, int aType, long aFreeSpace) |
|
214 { |
|
215 // Choose drive letter to be displayed. |
|
216 String driveLetter = "0"; |
|
217 if (aId >= 0 || aId < 26) |
|
218 { |
|
219 driveLetter = new String(new char[] {(char)('A' + aId) }); |
|
220 } |
|
221 |
|
222 // Choose amount of free space to be displayed and |
|
223 // kb, MB or GB prefix for disk space unit. |
|
224 int freeSpace = (int)aFreeSpace; |
|
225 int prefix = 0; |
|
226 if (aFreeSpace >= 1024*1024*1024) |
|
227 { |
|
228 freeSpace = (int)(aFreeSpace / (1024*1024*1024)); |
|
229 prefix = 3; |
|
230 } |
|
231 else if (aFreeSpace >= 1024*1024) |
|
232 { |
|
233 freeSpace = (int)(aFreeSpace / (1024*1024)); |
|
234 prefix = 2; |
|
235 } |
|
236 else |
|
237 { |
|
238 freeSpace = (int)(aFreeSpace / 1024); |
|
239 prefix = 1; |
|
240 } |
|
241 |
|
242 // Choose text id and text parameters. |
|
243 String textId = null; |
|
244 Object[] textParams = new Object[] |
|
245 { |
|
246 driveLetter, new Integer(freeSpace) |
|
247 }; |
|
248 switch (aType) |
|
249 { |
|
250 case InstallInfo.DRIVE_TYPE_UNKNOWN: |
|
251 switch (prefix) |
|
252 { |
|
253 case 0: |
|
254 textId = InstallerUiTexts.DRIVE_TYPE_UNKNOWN; |
|
255 textParams = new String[] { driveLetter }; |
|
256 break; |
|
257 case 1: |
|
258 textId = InstallerUiTexts.DRIVE_TYPE_UNKNOWN_KB; |
|
259 break; |
|
260 case 2: |
|
261 textId = InstallerUiTexts.DRIVE_TYPE_UNKNOWN_MB; |
|
262 break; |
|
263 case 3: |
|
264 textId = InstallerUiTexts.DRIVE_TYPE_UNKNOWN_GB; |
|
265 break; |
|
266 } |
|
267 break; |
|
268 case InstallInfo.DRIVE_TYPE_PHONE_MEMORY: |
|
269 switch (prefix) |
|
270 { |
|
271 case 0: |
|
272 textId = InstallerUiTexts.DRIVE_TYPE_PHONE_MEMORY; |
|
273 textParams = new String[] { driveLetter }; |
|
274 break; |
|
275 case 1: |
|
276 textId = InstallerUiTexts.DRIVE_TYPE_PHONE_MEMORY_KB; |
|
277 break; |
|
278 case 2: |
|
279 textId = InstallerUiTexts.DRIVE_TYPE_PHONE_MEMORY_MB; |
|
280 break; |
|
281 case 3: |
|
282 textId = InstallerUiTexts.DRIVE_TYPE_PHONE_MEMORY_GB; |
|
283 break; |
|
284 } |
|
285 break; |
|
286 case InstallInfo.DRIVE_TYPE_MEMORY_CARD: |
|
287 switch (prefix) |
|
288 { |
|
289 case 0: |
|
290 textId = InstallerUiTexts.DRIVE_TYPE_MEMORY_CARD; |
|
291 textParams = new String[] { driveLetter }; |
|
292 break; |
|
293 case 1: |
|
294 textId = InstallerUiTexts.DRIVE_TYPE_MEMORY_CARD_KB; |
|
295 break; |
|
296 case 2: |
|
297 textId = InstallerUiTexts.DRIVE_TYPE_MEMORY_CARD_MB; |
|
298 break; |
|
299 case 3: |
|
300 textId = InstallerUiTexts.DRIVE_TYPE_MEMORY_CARD_GB; |
|
301 break; |
|
302 } |
|
303 break; |
|
304 case InstallInfo.DRIVE_TYPE_INTERNAL_MASS_STORAGE: |
|
305 switch (prefix) |
|
306 { |
|
307 case 0: |
|
308 textId = InstallerUiTexts.DRIVE_TYPE_INTERNAL_MASS_STORAGE; |
|
309 textParams = new String[] { driveLetter }; |
|
310 break; |
|
311 case 1: |
|
312 textId = InstallerUiTexts.DRIVE_TYPE_INTERNAL_MASS_STORAGE_KB; |
|
313 break; |
|
314 case 2: |
|
315 textId = InstallerUiTexts.DRIVE_TYPE_INTERNAL_MASS_STORAGE_MB; |
|
316 break; |
|
317 case 3: |
|
318 textId = InstallerUiTexts.DRIVE_TYPE_INTERNAL_MASS_STORAGE_GB; |
|
319 break; |
|
320 } |
|
321 break; |
|
322 } |
|
323 return InstallerUiTexts.get(textId, textParams); |
|
324 } |
|
325 } |