xref: /haiku/src/apps/installer/InstallerApp.cpp (revision a3e6f7e1df1e7c4fe0c9f5f2b24ba96964af8c4f)
16ffb6a6eSJérôme Duval /*
27ff74a7bSStephan Aßmus  * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
37ff74a7bSStephan Aßmus  * Copyright 2005, Jérôme DUVAL.
47ff74a7bSStephan Aßmus  * All rights reserved. Distributed under the terms of the MIT License.
56ffb6a6eSJérôme Duval  */
66ffb6a6eSJérôme Duval 
77ff74a7bSStephan Aßmus #include "InstallerApp.h"
87ff74a7bSStephan Aßmus 
96ffb6a6eSJérôme Duval #include <Alert.h>
107ff74a7bSStephan Aßmus #include <Button.h>
117ff74a7bSStephan Aßmus #include <GroupLayoutBuilder.h>
124a2da425SStephan Aßmus #include <Locale.h>
1335d3acb2SJérôme Duval #include <ScrollView.h>
146ffb6a6eSJérôme Duval #include <TextView.h>
156ffb6a6eSJérôme Duval 
166ffb6a6eSJérôme Duval 
177ff74a7bSStephan Aßmus static const uint32 kMsgAgree = 'agre';
187ff74a7bSStephan Aßmus 
193ac4a739SStephan Aßmus //static const char* kEULAText =
203ac4a739SStephan Aßmus //"NOTICE: READ THIS BEFORE INSTALLING OR USING HAIKU\n\n"
213ac4a739SStephan Aßmus //
223ac4a739SStephan Aßmus //"Copyright " B_UTF8_COPYRIGHT " 2001-2009 The Haiku Project. All rights "
233ac4a739SStephan Aßmus //"reserved. The copyright to the Haiku code is property of Haiku, Inc. or of "
243ac4a739SStephan Aßmus //"the respective authors where expressly noted in the source.\n\n"
253ac4a739SStephan Aßmus //
263ac4a739SStephan Aßmus //"Permission is hereby granted, free of charge, to any person obtaining a "
273ac4a739SStephan Aßmus //"copy of this software and associated documentation files (the \"Software\"), "
283ac4a739SStephan Aßmus //"to deal in the Software without restriction, including without limitation "
293ac4a739SStephan Aßmus //"the rights to use, copy, modify, merge, publish, distribute, sublicense, "
303ac4a739SStephan Aßmus //"and/or sell copies of the Software, and to permit persons to whom the "
313ac4a739SStephan Aßmus //"Software is furnished to do so, subject to the following conditions:\n\n"
323ac4a739SStephan Aßmus //"The above copyright notice and this permission notice shall be included in "
333ac4a739SStephan Aßmus //"all copies or substantial portions of the Software.\n\n"
343ac4a739SStephan Aßmus //
353ac4a739SStephan Aßmus //"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS "
363ac4a739SStephan Aßmus //"OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
373ac4a739SStephan Aßmus //"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
383ac4a739SStephan Aßmus //"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
393ac4a739SStephan Aßmus //"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING "
403ac4a739SStephan Aßmus //"FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS "
413ac4a739SStephan Aßmus //"IN THE SOFTWARE.";
427ff74a7bSStephan Aßmus 
437ff74a7bSStephan Aßmus 
444eb0cbb0SMatt Madia #undef B_TRANSLATE_CONTEXT
454eb0cbb0SMatt Madia #define B_TRANSLATE_CONTEXT "InstallerApp"
467ff74a7bSStephan Aßmus 
4735d3acb2SJérôme Duval 
486ffb6a6eSJérôme Duval int main(int, char **)
496ffb6a6eSJérôme Duval {
506ffb6a6eSJérôme Duval 	InstallerApp theApp;
516ffb6a6eSJérôme Duval 	theApp.Run();
526ffb6a6eSJérôme Duval 	return 0;
536ffb6a6eSJérôme Duval }
546ffb6a6eSJérôme Duval 
557ff74a7bSStephan Aßmus 
566ffb6a6eSJérôme Duval InstallerApp::InstallerApp()
574a2da425SStephan Aßmus 	:
584a2da425SStephan Aßmus 	BApplication("application/x-vnd.Haiku-Installer")
596ffb6a6eSJérôme Duval {
6053ad1814SJérôme Duval }
6153ad1814SJérôme Duval 
627ff74a7bSStephan Aßmus 
637ff74a7bSStephan Aßmus void
647ff74a7bSStephan Aßmus InstallerApp::MessageReceived(BMessage* message)
657ff74a7bSStephan Aßmus {
667ff74a7bSStephan Aßmus 	switch (message->what) {
677ff74a7bSStephan Aßmus 		case kMsgAgree:
687ff74a7bSStephan Aßmus 			fEULAWindow->Lock();
697ff74a7bSStephan Aßmus 			fEULAWindow->Quit();
707ff74a7bSStephan Aßmus 			new InstallerWindow();
717ff74a7bSStephan Aßmus 			break;
727ff74a7bSStephan Aßmus 
737ff74a7bSStephan Aßmus 		default:
747ff74a7bSStephan Aßmus 			BApplication::MessageReceived(message);
756ffb6a6eSJérôme Duval 	}
767ff74a7bSStephan Aßmus }
777ff74a7bSStephan Aßmus 
786ffb6a6eSJérôme Duval 
796ffb6a6eSJérôme Duval void
806ffb6a6eSJérôme Duval InstallerApp::AboutRequested()
816ffb6a6eSJérôme Duval {
82e904ecc9SMatt Madia 	BAlert *alert = new BAlert("about", B_TRANSLATE("Installer\n"
834a2da425SStephan Aßmus 		"\twritten by Jérôme Duval and Stephan Aßmus\n"
84e904ecc9SMatt Madia 		"\tCopyright 2005-2010, Haiku.\n\n"), B_TRANSLATE("OK"));
856ffb6a6eSJérôme Duval 	BTextView *view = alert->TextView();
866ffb6a6eSJérôme Duval 	BFont font;
876ffb6a6eSJérôme Duval 
886ffb6a6eSJérôme Duval 	view->SetStylable(true);
896ffb6a6eSJérôme Duval 
906ffb6a6eSJérôme Duval 	view->GetFont(&font);
916ffb6a6eSJérôme Duval 	font.SetSize(18);
926ffb6a6eSJérôme Duval 	font.SetFace(B_BOLD_FACE);
9337895b5dSJoachim Seemer 	view->SetFontAndColor(0, 9, &font);
946ffb6a6eSJérôme Duval 
956ffb6a6eSJérôme Duval 	alert->Go();
966ffb6a6eSJérôme Duval }
976ffb6a6eSJérôme Duval 
986ffb6a6eSJérôme Duval 
996ffb6a6eSJérôme Duval void
1006ffb6a6eSJérôme Duval InstallerApp::ReadyToRun()
1016ffb6a6eSJérôme Duval {
102*a3e6f7e1SJoachim Seemer 	BString infoText;
103*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
104*a3e6f7e1SJoachim Seemer 		"Welcome to the Haiku Installer!\n\n");
105*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
106*a3e6f7e1SJoachim Seemer 		"IMPORTANT INFORMATION BEFORE INSTALLING HAIKU\n\n");
107*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1084a2da425SStephan Aßmus 		"This is alpha-quality software! It means there is a high risk of "
1094a2da425SStephan Aßmus 		"losing important data. Make frequent backups! You have been "
110*a3e6f7e1SJoachim Seemer 		"warned.\n\n\n");
111*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1124a2da425SStephan Aßmus 		"1)   If you are installing Haiku onto real hardware (not inside an "
1134a2da425SStephan Aßmus 		"emulator) it is recommended that you have already prepared a hard "
1144a2da425SStephan Aßmus 		"disk partition. The Installer and the DriveSetup tool offer to "
1154a2da425SStephan Aßmus 		"initialize existing partitions with the Haiku native file system, "
1164a2da425SStephan Aßmus 		"but the options to change the actual partition layout may not have "
1174a2da425SStephan Aßmus 		"been tested on a sufficiently great variety of computer "
118*a3e6f7e1SJoachim Seemer 		"configurations so we do not recommend using it.\n");
119*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1204a2da425SStephan Aßmus 		"If you have not created a partition yet, simply reboot, create the "
1214a2da425SStephan Aßmus 		"partition using whatever tool you feel most comfortable with, and "
1224a2da425SStephan Aßmus 		"reboot into Haiku to continue with the installation. You could for "
1234a2da425SStephan Aßmus 		"example use the GParted Live-CD, it can also resize existing "
124*a3e6f7e1SJoachim Seemer 		"partitions to make room.\n\n\n");
125*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1263fa60838SJoachim Seemer 		"2)   The Installer will make the Haiku partition itself bootable, "
1273fa60838SJoachim Seemer 		"but takes no steps to integrate Haiku into an existing boot menu. "
1283fa60838SJoachim Seemer 		"If you have GRUB already installed, you can add Haiku to its boot "
1293fa60838SJoachim Seemer 		"menu. Depending on what version of GRUB you use, this is done "
130*a3e6f7e1SJoachim Seemer 		"differently.\n\n\n");
131*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
132*a3e6f7e1SJoachim Seemer 		"2.1) GRUB 1\n");
133*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1343fa60838SJoachim Seemer 		"Configure your /boot/grub/menu.lst by launching your favorite "
135*a3e6f7e1SJoachim Seemer 		"editor from a Terminal like this:\n\n");
136*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
137*a3e6f7e1SJoachim Seemer 		"\tsudo <your favorite text editor> /boot/grub/menu.lst\n\n");
138*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1394a2da425SStephan Aßmus 		"You'll note that GRUB uses a different naming strategy for hard "
140*a3e6f7e1SJoachim Seemer 		"drives than Linux.\n\n");
141*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
142*a3e6f7e1SJoachim Seemer 		"With GRUB it's: (hdN,n)\n\n");
143*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
144*a3e6f7e1SJoachim Seemer 		"All hard disks start with \"hd\".\n");
145*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
146*a3e6f7e1SJoachim Seemer 		"\"N\" is the hard disk number, starting with \"0\".\n");
147*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
148*a3e6f7e1SJoachim Seemer 		"\"n\" is the partition number, also starting with \"0\".\n");
149*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1503fa60838SJoachim Seemer 		"The first logical partition always has the number \"4\", regardless "
151*a3e6f7e1SJoachim Seemer 		"of the number of primary partitions.\n\n");
152*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1534a2da425SStephan Aßmus 		"So behind the other menu entries towards the bottom of the file, add "
154*a3e6f7e1SJoachim Seemer 		"something similar to these lines:\n\n");
155*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
156*a3e6f7e1SJoachim Seemer 		"\t# Haiku on /dev/sda7\n");
157*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
158*a3e6f7e1SJoachim Seemer 		"\ttitle\t\t\t\tHaiku\n");
159*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
160*a3e6f7e1SJoachim Seemer 		"\trootnoverify\t\t(hd0,6)\n");
161*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
162*a3e6f7e1SJoachim Seemer 		"\tchainloader\t\t+1\n\n");
163*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
164*a3e6f7e1SJoachim Seemer 		"You can see the correct partition in GParted for example.\n\n\n");
165*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
166*a3e6f7e1SJoachim Seemer 		"2.2) GRUB 2\n");
167*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1683fa60838SJoachim Seemer 		"Newer versions of GRUB use an extra configuration file to add "
1693fa60838SJoachim Seemer 		"custom entries to the boot menu. To add them to the top, you have "
1703fa60838SJoachim Seemer 		"to create/edit a file by launching your favorite editor from a "
171*a3e6f7e1SJoachim Seemer 		"Terminal like this:\n\n");
172*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
173*a3e6f7e1SJoachim Seemer 		"\tsudo <your favorite text editor> /etc/grub.d/40_custom\n\n");
174*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1753fa60838SJoachim Seemer 		"NOTE: While the naming strategy for hard disks is still as described "
176*a3e6f7e1SJoachim Seemer 		"under 2.1) the naming scheme for partitions has changed.\n\n");
177*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
178*a3e6f7e1SJoachim Seemer 		"GRUB's naming scheme is still: (hdN,n)\n\n");
179*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
180*a3e6f7e1SJoachim Seemer 		"All hard disks start with \"hd\".\n");
181*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
182*a3e6f7e1SJoachim Seemer 		"\"N\" is the hard disk number, starting with \"0\".\n");
183*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
184*a3e6f7e1SJoachim Seemer 		"\"n\" is the partition number, which for GRUB 2 starts with \"1\"\n");
185*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1863fa60838SJoachim Seemer 		"With GRUB 2 the first logical partition always has the number \"5\", "
187*a3e6f7e1SJoachim Seemer 		"regardless of the number of primary partitions.\n\n");
188*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1893fa60838SJoachim Seemer 		"So below the heading that must not be edited, add something similar "
190*a3e6f7e1SJoachim Seemer 		"to these lines:\n\n");
191*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
192*a3e6f7e1SJoachim Seemer 		"\t# Haiku on /dev/sda7\n");
193*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
194*a3e6f7e1SJoachim Seemer 		"\tmenuentry \"Haiku Alpha\" {\n");
195*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
196*a3e6f7e1SJoachim Seemer 		"\t\tset root=(hd0,7)\n");
197*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
198*a3e6f7e1SJoachim Seemer 		"\t\tchainloader +1\n");
199*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
200*a3e6f7e1SJoachim Seemer 		"\t}\n\n");
201*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
2023fa60838SJoachim Seemer 		"Additionally you have to edit another file to actually display the "
203*a3e6f7e1SJoachim Seemer 		"boot menu:\n\n");
204*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
205*a3e6f7e1SJoachim Seemer 		"\tsudo <your favorite text editor> /etc/default/grub\n\n");
206*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
2073fa60838SJoachim Seemer 		"Here you have to comment out the line \"GRUB_HIDDEN_TIMEOUT=0\" by "
2083fa60838SJoachim Seemer 		"putting a \"#\" in front of it in order to actually display the "
209*a3e6f7e1SJoachim Seemer 		"boot menu.\n\n");
210*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
211*a3e6f7e1SJoachim Seemer 		"Finally, you have to update the boot menu by entering:\n\n");
212*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
213*a3e6f7e1SJoachim Seemer 		"\tsudo update-grub\n\n\n");
214*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
2154a2da425SStephan Aßmus 		"3)   When you successfully boot into Haiku for the first time, make "
2164a2da425SStephan Aßmus 		"sure to read our \"Welcome\" documentation, there is a link on the "
217*a3e6f7e1SJoachim Seemer 		"Desktop.\n\n");
218*a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
219*a3e6f7e1SJoachim Seemer 		"Have fun and thanks a lot for trying out Haiku! We hope you like it!");
2204a2da425SStephan Aßmus 
2217ff74a7bSStephan Aßmus #if 1
2227ff74a7bSStephan Aßmus 	// Show the EULA first.
2237ff74a7bSStephan Aßmus 	BTextView* textView = new BTextView("eula", be_plain_font, NULL,
2247ff74a7bSStephan Aßmus 		B_WILL_DRAW);
2257ff74a7bSStephan Aßmus 	textView->SetInsets(10, 10, 10, 10);
2267ff74a7bSStephan Aßmus 	textView->MakeEditable(false);
2277ff74a7bSStephan Aßmus 	textView->MakeSelectable(false);
2284a2da425SStephan Aßmus 	textView->SetText(infoText);
2296ffb6a6eSJérôme Duval 
2307ff74a7bSStephan Aßmus 	BScrollView* scrollView = new BScrollView("eulaScroll",
2317ff74a7bSStephan Aßmus 		textView, B_WILL_DRAW, false, true);
2327ff74a7bSStephan Aßmus 
233e904ecc9SMatt Madia 	BButton* cancelButton = new BButton(B_TRANSLATE("Quit"),
2347ff74a7bSStephan Aßmus 		new BMessage(B_QUIT_REQUESTED));
2353ac4a739SStephan Aßmus 	cancelButton->SetTarget(this);
2367ff74a7bSStephan Aßmus 
237e904ecc9SMatt Madia 	BButton* continueButton = new BButton(B_TRANSLATE("Continue"),
2387ff74a7bSStephan Aßmus 		new BMessage(kMsgAgree));
2393ac4a739SStephan Aßmus 	continueButton->SetTarget(this);
2403ac4a739SStephan Aßmus 	continueButton->MakeDefault(true);
2417ff74a7bSStephan Aßmus 
2427ff74a7bSStephan Aßmus 	BRect eulaFrame = BRect(0, 0, 600, 450);
243e904ecc9SMatt Madia 	fEULAWindow = new BWindow(eulaFrame, B_TRANSLATE("README"),
2447ff74a7bSStephan Aßmus 		B_MODAL_WINDOW, B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
2457ff74a7bSStephan Aßmus 			| B_AUTO_UPDATE_SIZE_LIMITS);
2467ff74a7bSStephan Aßmus 
2477ff74a7bSStephan Aßmus 	fEULAWindow->SetLayout(new BGroupLayout(B_HORIZONTAL));
2487ff74a7bSStephan Aßmus 	fEULAWindow->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
2497ff74a7bSStephan Aßmus 		.Add(scrollView)
2507ff74a7bSStephan Aßmus 		.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
2517ff74a7bSStephan Aßmus 			.AddGlue()
2523ac4a739SStephan Aßmus 			.Add(cancelButton)
2533ac4a739SStephan Aßmus 			.Add(continueButton)
2547ff74a7bSStephan Aßmus 		)
2557ff74a7bSStephan Aßmus 		.SetInsets(10, 10, 10, 10)
2567ff74a7bSStephan Aßmus 	);
2577ff74a7bSStephan Aßmus 
258e9953d08SJonas Sundström 	fEULAWindow->CenterOnScreen();
2597ff74a7bSStephan Aßmus 	fEULAWindow->Show();
2607ff74a7bSStephan Aßmus #else
2617ff74a7bSStephan Aßmus 	// Show the installer window without EULA.
2627ff74a7bSStephan Aßmus 	new InstallerWindow();
2637ff74a7bSStephan Aßmus #endif
2646ffb6a6eSJérôme Duval }
2656ffb6a6eSJérôme Duval 
266