xref: /haiku/src/apps/installer/InstallerApp.cpp (revision 45bd7bb3db9d9e4dcb02b89a3e7c2bf382c0a88c)
1 /*
2  * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
3  * Copyright 2005, Jérôme DUVAL.
4  * All rights reserved. Distributed under the terms of the MIT License.
5  */
6 
7 #include "InstallerApp.h"
8 
9 #include <Alert.h>
10 #include <Button.h>
11 #include <GroupLayoutBuilder.h>
12 #include <Locale.h>
13 #include <ScrollView.h>
14 #include <TextView.h>
15 
16 
17 static const uint32 kMsgAgree = 'agre';
18 
19 //static const char* kEULAText =
20 //"NOTICE: READ THIS BEFORE INSTALLING OR USING HAIKU\n\n"
21 //
22 //"Copyright " B_UTF8_COPYRIGHT " 2001-2009 The Haiku Project. All rights "
23 //"reserved. The copyright to the Haiku code is property of Haiku, Inc. or of "
24 //"the respective authors where expressly noted in the source.\n\n"
25 //
26 //"Permission is hereby granted, free of charge, to any person obtaining a "
27 //"copy of this software and associated documentation files (the \"Software\"), "
28 //"to deal in the Software without restriction, including without limitation "
29 //"the rights to use, copy, modify, merge, publish, distribute, sublicense, "
30 //"and/or sell copies of the Software, and to permit persons to whom the "
31 //"Software is furnished to do so, subject to the following conditions:\n\n"
32 //"The above copyright notice and this permission notice shall be included in "
33 //"all copies or substantial portions of the Software.\n\n"
34 //
35 //"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS "
36 //"OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
37 //"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
38 //"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
39 //"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING "
40 //"FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS "
41 //"IN THE SOFTWARE.";
42 
43 
44 #undef B_TRANSLATE_CONTEXT
45 #define B_TRANSLATE_CONTEXT "InstallerApp"
46 
47 
48 int main(int, char **)
49 {
50 	InstallerApp theApp;
51 	theApp.Run();
52 	return 0;
53 }
54 
55 
56 InstallerApp::InstallerApp()
57 	:
58 	BApplication("application/x-vnd.Haiku-Installer")
59 {
60 }
61 
62 
63 void
64 InstallerApp::MessageReceived(BMessage* message)
65 {
66 	switch (message->what) {
67 		case kMsgAgree:
68 			fEULAWindow->Lock();
69 			fEULAWindow->Quit();
70 			new InstallerWindow();
71 			break;
72 
73 		default:
74 			BApplication::MessageReceived(message);
75 	}
76 }
77 
78 
79 void
80 InstallerApp::AboutRequested()
81 {
82 	BAlert *alert = new BAlert("about", B_TRANSLATE("Installer\n"
83 		"\twritten by Jérôme Duval and Stephan Aßmus\n"
84 		"\tCopyright 2005-2010, Haiku.\n\n"), B_TRANSLATE("OK"));
85 	BTextView *view = alert->TextView();
86 	BFont font;
87 
88 	view->SetStylable(true);
89 
90 	view->GetFont(&font);
91 	font.SetSize(18);
92 	font.SetFace(B_BOLD_FACE);
93 	view->SetFontAndColor(0, 9, &font);
94 
95 	alert->Go();
96 }
97 
98 
99 void
100 InstallerApp::ReadyToRun()
101 {
102 	// Initilialize the Locale Kit
103 	be_locale->GetAppCatalog(&fCatalog);
104 
105 	const char* infoText = B_TRANSLATE(
106 		"Welcome to the Haiku Installer!\n\n"
107 
108 		"IMPORTANT INFORMATION BEFORE INSTALLING HAIKU\n\n"
109 
110 		"This is alpha-quality software! It means there is a high risk of "
111 		"losing important data. Make frequent backups! You have been "
112 		"warned.\n\n"
113 
114 		"1)  If you are installing Haiku onto real hardware (not inside an "
115 		"emulator) it is recommended that you have already prepared a hard "
116 		"disk partition. The Installer and the DriveSetup tool offer to "
117 		"initialize existing partitions with the Haiku native file system, "
118 		"but the options to change the actual partition layout may not have "
119 		"been tested on a sufficiently great variety of computer "
120 		"installations so we do not recommend using it.\n"
121 		"If you have not created a partition yet, simply reboot, create the "
122 		"partition using whatever tool you feel most comfortable with, and "
123 		"reboot into Haiku to continue with the installation. You could for "
124 		"example use the GParted Live-CD, it can also resize existing "
125 		"partitions to make room.\n\n"
126 
127 		"2)  The Installer will take no steps to integrate Haiku into an "
128 		"existing boot menu. The Haiku partition itself will be made "
129 		"bootable. If you have GRUB already installed, edit your "
130 		"/boot/grub/menu.lst by launching your favorite editor from a "
131 		"Terminal like this:\n\n"
132 
133 		"\tsudo <your favorite text editor> /boot/grub/menu.lst\n\n"
134 
135 		"You'll note that GRUB uses a different naming strategy for hard "
136 		"drives than Linux.\n\n"
137 
138 		"With GRUB it's: (hdN,n)\n\n"
139 
140 		"All harddisks start with \"hd\"\n"
141 		"\"N\" is the hard disk number, starting with \"0\".\n"
142 		"\"n\" is the partition number, also starting with \"0\".\n"
143 		"The first logical partition always has the number 4, regardless of "
144 		"the number of primary partitions.\n\n"
145 
146 		"So behind the other menu entries towards the bottom of the file, add "
147 		"something similar to these lines:\n\n"
148 
149 		"\t# Haiku on /dev/sda7\n"
150 		"\ttitle\t\t\t\tHaiku\n"
151 		"\trootnoverify\t\t(hd0,6)\n"
152 		"\tchainloader\t\t+1\n\n"
153 
154 		"You can see the correct partition in GParted for example.\n\n"
155 
156 		"3)  When you successfully boot into Haiku for the first time, make "
157 		"sure to read our \"Welcome\" documentation, there is a link on the "
158 		"Desktop.\n\n"
159 
160 		"Have fun and thanks a lot for trying out Haiku! We hope you like it!"
161 	);
162 
163 #if 1
164 	// Show the EULA first.
165 	BTextView* textView = new BTextView("eula", be_plain_font, NULL,
166 		B_WILL_DRAW);
167 	textView->SetInsets(10, 10, 10, 10);
168 	textView->MakeEditable(false);
169 	textView->MakeSelectable(false);
170 	textView->SetText(infoText);
171 
172 	BScrollView* scrollView = new BScrollView("eulaScroll",
173 		textView, B_WILL_DRAW, false, true);
174 
175 	BButton* cancelButton = new BButton(B_TRANSLATE("Quit"),
176 		new BMessage(B_QUIT_REQUESTED));
177 	cancelButton->SetTarget(this);
178 
179 	BButton* continueButton = new BButton(B_TRANSLATE("Continue"),
180 		new BMessage(kMsgAgree));
181 	continueButton->SetTarget(this);
182 	continueButton->MakeDefault(true);
183 
184 	BRect eulaFrame = BRect(0, 0, 600, 450);
185 	fEULAWindow = new BWindow(eulaFrame, B_TRANSLATE("README"),
186 		B_MODAL_WINDOW, B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
187 			| B_AUTO_UPDATE_SIZE_LIMITS);
188 
189 	fEULAWindow->SetLayout(new BGroupLayout(B_HORIZONTAL));
190 	fEULAWindow->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
191 		.Add(scrollView)
192 		.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
193 			.AddGlue()
194 			.Add(cancelButton)
195 			.Add(continueButton)
196 		)
197 		.SetInsets(10, 10, 10, 10)
198 	);
199 
200 	fEULAWindow->CenterOnScreen();
201 	fEULAWindow->Show();
202 #else
203 	// Show the installer window without EULA.
204 	new InstallerWindow();
205 #endif
206 }
207 
208