xref: /haiku/src/apps/poorman/PoorManPreferencesWindow.cpp (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 /* PoorManPreferencesWindow.cpp
2  *
3  *	Philip Harrison
4  *	Started: 4/27/2004
5  *	Version: 0.1
6  */
7 
8 #include <Window.h>
9 #include <Box.h>
10 #include <Directory.h>
11 #include <iostream>
12 
13 #include "constants.h"
14 #include "PoorManWindow.h"
15 #include "PoorManApplication.h"
16 #include "PoorManPreferencesWindow.h"
17 
18 
19 PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name)
20 	: BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
21 {
22 
23 	frame = Bounds();
24 
25 	prefView = new PoorManView(frame, STR_WIN_NAME_PREF);
26 	//prefView->SetViewColor(216,216,216,255);
27 	prefView->SetViewColor(BACKGROUND_COLOR);
28 	AddChild(prefView);
29 
30 
31 
32 	// Button View
33 	BRect buttonRect;
34 	buttonRect = Bounds();
35 	buttonRect.top = buttonRect.bottom - 30;
36 
37 	buttonView = new PoorManView(buttonRect, "Button View");
38 	buttonView->SetViewColor(BACKGROUND_COLOR);
39 	prefView->AddChild(buttonView);
40 
41 	// Buttons
42 	float buttonTop = 0.0f;
43 	float buttonWidth = 52.0f;
44 	float buttonHeight = 26.0f;
45 	float buttonLeft = 265.0f;
46 
47 	BRect button1;
48 	button1 = buttonView->Bounds();
49 	button1.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight);
50 	cancelButton = new BButton(button1, "Cancel Button", "Cancel", new BMessage(MSG_PREF_BTN_CANCEL));
51 
52 	buttonLeft = 325.0f;
53 	BRect button2;
54 	button2 = buttonView->Bounds();
55 	button2.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight);
56 	doneButton = new BButton(button2, "Done Button", "Done", new BMessage(MSG_PREF_BTN_DONE));
57 
58 	buttonView->AddChild(cancelButton);
59 	buttonView->AddChild(doneButton);
60 
61 
62 
63 	// Create tabs
64 	BRect r;
65 	r = Bounds();
66 	//r.InsetBy(5, 5);
67 	r.top	 += 8.0;
68 	r.bottom -= 38.0;
69 
70 	prefTabView = new BTabView(r, "Pref Tab View");
71 	prefTabView->SetViewColor(BACKGROUND_COLOR);
72 
73 	r = prefTabView->Bounds();
74 	r.InsetBy(5, 5);
75 	r.bottom -= prefTabView->TabHeight();
76 
77 	// Site Tab
78 	siteTab = new BTab();
79 	siteView = new PoorManSiteView(r, "Site View");
80 	prefTabView->AddTab(siteView, siteTab);
81 	siteTab->SetLabel(STR_TAB_SITE);
82 
83 	// Logging Tab
84 	loggingTab = new BTab();
85 	loggingView = new PoorManLoggingView(r, "Logging View");
86 	prefTabView->AddTab(loggingView, loggingTab);
87 	loggingTab->SetLabel(STR_TAB_LOGGING);
88 
89 	// Advanced Tab
90 	advancedTab = new BTab();
91 	advancedView = new PoorManAdvancedView(r, "Advanced View");
92 	prefTabView->AddTab(advancedView, advancedTab);
93 	advancedTab->SetLabel(STR_TAB_ADVANCED);
94 
95 	prefView->AddChild(prefTabView);
96 
97 	// FilePanels
98 	BWindow * change_title;
99 
100 	webDirFilePanel = new BFilePanel(
101 						B_OPEN_PANEL,
102 						new BMessenger(this),
103 						NULL,
104 						B_DIRECTORY_NODE,
105 						false,
106 						new BMessage(MSG_FILE_PANEL_SELECT_WEB_DIR)
107 						);
108 	webDirFilePanel->SetPanelDirectory(new BDirectory("/boot/home/public_html"));
109 	webDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Select");
110 	change_title = webDirFilePanel->Window();
111 	change_title->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR);
112 
113 
114 	logFilePanel = new BFilePanel(
115 						B_SAVE_PANEL,
116 						new BMessenger(this),
117 						NULL,
118 						B_FILE_NODE,
119 						false,
120 						new BMessage(MSG_FILE_PANEL_CREATE_LOG_FILE)
121 						);
122 	logFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Create");
123 	change_title = logFilePanel->Window();
124 	change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE);
125 
126 
127 	Show();
128 
129 }
130 
131 void
132 PoorManPreferencesWindow::MessageReceived(BMessage* message)
133 {
134 	switch (message->what) {
135 	case MSG_PREF_BTN_DONE:
136 			PoorManWindow		*	win;
137 			win = ((PoorManApplication *)be_app)->GetPoorManWindow();
138 
139 			std::cout << "Pref Window: sendDir CheckBox: " << siteView->SendDirValue() << std::endl;
140 			win->SetDirListFlag(siteView->SendDirValue());
141 			std::cout << "Pref Window: indexFileName TextControl: " << siteView->IndexFileName() << std::endl;
142 			win->SetIndexFileName(siteView->IndexFileName());
143 			std::cout << "Pref Window: webDir: " << siteView->WebDir() << std::endl;
144 			win->SetWebDir(siteView->WebDir());
145 			win->SetDirLabel(siteView->WebDir());
146 
147 			std::cout << "Pref Window: logConsole CheckBox: " << loggingView->LogConsoleValue() << std::endl;
148 			win->SetLogConsoleFlag(loggingView->LogConsoleValue());
149 			std::cout << "Pref Window: logFile CheckBox: " << loggingView->LogFileValue() << std::endl;
150 			win->SetLogFileFlag(loggingView->LogFileValue());
151 			std::cout << "Pref Window: logFileName: " << loggingView->LogFileName() << std::endl;
152 			win->SetLogPath(loggingView->LogFileName());
153 
154 			std::cout << "Pref Window: MaxConnections Slider: " << advancedView->MaxSimultaneousConnections() << std::endl;
155 			win->SetMaxConnections(advancedView->MaxSimultaneousConnections());
156 
157 
158 			if (Lock())
159 				Quit();
160 		break;
161 	case MSG_PREF_BTN_CANCEL:
162 			if (Lock())
163 				Quit();
164 		break;
165 	case MSG_PREF_SITE_BTN_SELECT:
166 			// Select the Web Directory, root directory to look in.
167 			if (!webDirFilePanel->IsShowing())
168 				webDirFilePanel->Show();
169 		break;
170 	case MSG_FILE_PANEL_SELECT_WEB_DIR:
171 			// handle the open BMessage from the Select Web Directory File Panel
172 			std::cout << "Select Web Directory:\n" << std::endl;
173 			SelectWebDir(message);
174 		break;
175 	case MSG_PREF_LOG_BTN_CREATE_FILE:
176 			// Create the Log File
177 			logFilePanel->Show();
178 		break;
179 	case MSG_FILE_PANEL_CREATE_LOG_FILE:
180 			// handle the save BMessage from the Create Log File Panel
181 			std::cout << "Create Log File:\n" << std::endl;
182 			CreateLogFile(message);
183 		break;
184 	case MSG_PREF_ADV_SLD_MAX_CONNECTION:
185 			max_connections = advancedView->MaxSimultaneousConnections();
186 			std::cout << "Max Connections: " << max_connections << std::endl;
187 		break;
188 
189 	default:
190 		BWindow::MessageReceived(message);
191 		break;
192 	}
193 }
194 
195 void
196 PoorManPreferencesWindow::SelectWebDir(BMessage * message)
197 {
198 	entry_ref	ref;
199 	const char	* name;
200 	BPath		path;
201 	BEntry		entry;
202 	status_t	err = B_OK;
203 
204 	err = message->FindRef("refs", &ref) != B_OK;
205 	//if (err = message->FindRef("directory", &ref) != B_OK)
206 		//return err;
207 	err = message->FindString("name", &name) != B_OK;
208 	//if (err = message->FindString("name", &name) != B_OK)
209 	//	;//return err;
210 	err = entry.SetTo(&ref) != B_OK;
211 	//if (err = entry.SetTo(&ref) != B_OK)
212 	//	;//return err;
213 	entry.GetPath(&path);
214 
215 	std::cout << "DIR: " << path.Path() << std::endl;
216 	siteView->SetWebDir(path.Path());
217 }
218 
219 void
220 PoorManPreferencesWindow::CreateLogFile(BMessage * message)
221 {
222 	entry_ref	ref;
223 	const char	* name;
224 	BPath		path;
225 	BEntry		entry;
226 	status_t	err = B_OK;
227 
228 	err = message->FindRef("directory", &ref) != B_OK;
229 	//if (err = message->FindRef("directory", &ref) != B_OK)
230 		//return err;
231 	err = message->FindString("name", &name) != B_OK;
232 	//if (err = message->FindString("name", &name) != B_OK)
233 	//	;//return err;
234 	err = entry.SetTo(&ref) != B_OK;
235 	//if (err = entry.SetTo(&ref) != B_OK)
236 	//	;//return err;
237 	entry.GetPath(&path);
238 	path.Append(name);
239 	std::cout << "Log File: " << path.Path() << std::endl;
240 
241 	if (err == B_OK)
242 	{
243 		loggingView->SetLogFileName(path.Path());
244 		loggingView->SetLogFileValue(true);
245 	}
246 
247 	// mark the checkbox
248 }
249