xref: /haiku/src/apps/installer/InstallerApp.cpp (revision a1163de83ea633463a79de234b8742ee106531b2)
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 <Screen.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 static const char* kInfoText =
45 "IMPORTANT INFORMATION BEFORE INSTALLING HAIKU\n\n"
46 
47 "This is alpha-quality software! It means there is a high risk of losing "
48 "important data. Make frequent backups! You have been warned.\n\n"
49 
50 "1)  If you are installing Haiku onto real hardware (not inside an emulator) "
51 "you need to have prepared a harddisk partition. The Installer and the "
52 "DriveSetup tool will only offer to initialize existing partitions with the "
53 "Haiku native filesystem. We recommend using the GParted Live-CD, it can also "
54 "resize partitions to make room. We do not feel confident in enabling our own "
55 "code to mess with your harddisk partition table. If you have not created a "
56 "partition yet, simply reboot, create the partition using whatever tool you "
57 "feel most comfortable with, and reboot into Haiku to continue with the "
58 "installation.\n\n"
59 
60 "2)  The Installer will take no steps to integrate Haiku into an existig boot "
61 "menu. The Haiku partition itself will be made bootable. If you have GRUB "
62 "already installed, edit your /boot/grub/menu.1st by launching your favorite "
63 "editor from a Terminal like this:\n\n"
64 
65 "\tsudo <your favorite text editor> /boot/grub/menu.lst\n\n"
66 
67 "You'll note that GRUB uses a different naming strategy for hard drives than "
68 "Linux.\n\n"
69 
70 "With GRUB it's: (hdN,n)\n\n"
71 
72 "All harddisks start with \"hd\"\n"
73 "\"N\" is the hard disk number, starting with \"0\".\n"
74 "\"n\" is the partition number, also starting with \"0\".\n"
75 "The first logical partition always has the number 4, regardless of the "
76 "number of primary partitions.\n\n"
77 
78 "So behind the other menu entries towards the bottom of the file, add "
79 "something similar to these lines:\n\n"
80 
81 "\t# Haiku on /dev/sda7\n"
82 "\ttitle\t\t\t\tHaiku\n"
83 "\trootnoverify\t\t(hd0,6)\n"
84 "\tchainloader\t\t+1\n\n"
85 
86 "You can see the correct partition in gparted for example.\n\n"
87 
88 "3)  When you successfully boot into Haiku for the first time, make sure to read "
89 "our \"Welcome\" documentation, there is a link on the Desktop.\n\n"
90 
91 "Have fun and thanks a lot for trying out Haiku! We hope you like it!"
92 ;
93 
94 
95 int main(int, char **)
96 {
97 	InstallerApp theApp;
98 	theApp.Run();
99 	return 0;
100 }
101 
102 
103 InstallerApp::InstallerApp()
104 	: BApplication("application/x-vnd.Haiku-Installer")
105 {
106 }
107 
108 
109 void
110 InstallerApp::MessageReceived(BMessage* message)
111 {
112 	switch (message->what) {
113 		case kMsgAgree:
114 			fEULAWindow->Lock();
115 			fEULAWindow->Quit();
116 			new InstallerWindow();
117 			break;
118 
119 		default:
120 			BApplication::MessageReceived(message);
121 	}
122 }
123 
124 
125 void
126 InstallerApp::AboutRequested()
127 {
128 	BAlert *alert = new BAlert("about", "Installer\n"
129 		"\twritten by Jérôme Duval\n"
130 		"\tCopyright 2005, Haiku.\n\n", "Ok");
131 	BTextView *view = alert->TextView();
132 	BFont font;
133 
134 	view->SetStylable(true);
135 
136 	view->GetFont(&font);
137 	font.SetSize(18);
138 	font.SetFace(B_BOLD_FACE);
139 	view->SetFontAndColor(0, 14, &font);
140 
141 	alert->Go();
142 }
143 
144 
145 void
146 InstallerApp::ReadyToRun()
147 {
148 #if 1
149 	// Show the EULA first.
150 	BTextView* textView = new BTextView("eula", be_plain_font, NULL,
151 		B_WILL_DRAW);
152 	textView->SetInsets(10, 10, 10, 10);
153 	textView->MakeEditable(false);
154 	textView->MakeSelectable(false);
155 	textView->SetText(kInfoText);
156 
157 	BScrollView* scrollView = new BScrollView("eulaScroll",
158 		textView, B_WILL_DRAW, false, true);
159 
160 	BButton* cancelButton = new BButton("Quit",
161 		new BMessage(B_QUIT_REQUESTED));
162 	cancelButton->SetTarget(this);
163 
164 	BButton* continueButton = new BButton("Continue",
165 		new BMessage(kMsgAgree));
166 	continueButton->SetTarget(this);
167 	continueButton->MakeDefault(true);
168 
169 	BRect eulaFrame = BRect(0, 0, 600, 450);
170 	fEULAWindow = new BWindow(eulaFrame, "README",
171 		B_MODAL_WINDOW, B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
172 			| B_AUTO_UPDATE_SIZE_LIMITS);
173 
174 	fEULAWindow->SetLayout(new BGroupLayout(B_HORIZONTAL));
175 	fEULAWindow->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
176 		.Add(scrollView)
177 		.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
178 			.AddGlue()
179 			.Add(cancelButton)
180 			.Add(continueButton)
181 		)
182 		.SetInsets(10, 10, 10, 10)
183 	);
184 
185 	BRect frame = BScreen().Frame();
186 	fEULAWindow->MoveTo(frame.left + (frame.Width() - eulaFrame.Width()) / 2,
187 		frame.top + (frame.Height() - eulaFrame.Height()) / 2);
188 
189 	fEULAWindow->Show();
190 #else
191 	// Show the installer window without EULA.
192 	new InstallerWindow();
193 #endif
194 }
195 
196