xref: /haiku/src/apps/poorman/PoorManPreferencesWindow.cpp (revision 4f2fd49bdc6078128b1391191e4edac647044c3d)
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 	webDirFilePanel(NULL),
22 	logFilePanel(NULL)
23 {
24 
25 	frame = Bounds();
26 
27 	prefView = new PoorManView(frame, STR_WIN_NAME_PREF);
28 	//prefView->SetViewColor(216,216,216,255);
29 	prefView->SetViewColor(BACKGROUND_COLOR);
30 	AddChild(prefView);
31 
32 
33 
34 	// Button View
35 	BRect buttonRect;
36 	buttonRect = Bounds();
37 	buttonRect.top = buttonRect.bottom - 30;
38 
39 	buttonView = new PoorManView(buttonRect, "Button View");
40 	buttonView->SetViewColor(BACKGROUND_COLOR);
41 	prefView->AddChild(buttonView);
42 
43 	// Buttons
44 	float buttonTop = 0.0f;
45 	float buttonWidth = 52.0f;
46 	float buttonHeight = 26.0f;
47 	float buttonLeft = 265.0f;
48 
49 	BRect button1;
50 	button1 = buttonView->Bounds();
51 	button1.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight);
52 	cancelButton = new BButton(button1, "Cancel Button", "Cancel", new BMessage(MSG_PREF_BTN_CANCEL));
53 
54 	buttonLeft = 325.0f;
55 	BRect button2;
56 	button2 = buttonView->Bounds();
57 	button2.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight);
58 	doneButton = new BButton(button2, "Done Button", "Done", new BMessage(MSG_PREF_BTN_DONE));
59 
60 	buttonView->AddChild(cancelButton);
61 	buttonView->AddChild(doneButton);
62 
63 
64 
65 	// Create tabs
66 	BRect r;
67 	r = Bounds();
68 	//r.InsetBy(5, 5);
69 	r.top	 += 8.0;
70 	r.bottom -= 38.0;
71 
72 	prefTabView = new BTabView(r, "Pref Tab View");
73 	prefTabView->SetViewColor(BACKGROUND_COLOR);
74 
75 	r = prefTabView->Bounds();
76 	r.InsetBy(5, 5);
77 	r.bottom -= prefTabView->TabHeight();
78 
79 	// Site Tab
80 	siteTab = new BTab();
81 	siteView = new PoorManSiteView(r, "Site View");
82 	prefTabView->AddTab(siteView, siteTab);
83 	siteTab->SetLabel(STR_TAB_SITE);
84 
85 	// Logging Tab
86 	loggingTab = new BTab();
87 	loggingView = new PoorManLoggingView(r, "Logging View");
88 	prefTabView->AddTab(loggingView, loggingTab);
89 	loggingTab->SetLabel(STR_TAB_LOGGING);
90 
91 	// Advanced Tab
92 	advancedTab = new BTab();
93 	advancedView = new PoorManAdvancedView(r, "Advanced View");
94 	prefTabView->AddTab(advancedView, advancedTab);
95 	advancedTab->SetLabel(STR_TAB_ADVANCED);
96 
97 	prefView->AddChild(prefTabView);
98 
99 	// FilePanels
100 	BWindow * change_title;
101 
102 	BMessenger messenger(this);
103 	BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR);
104 	webDirFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL,
105 		B_DIRECTORY_NODE, false, &message);
106 
107 	webDirFilePanel->SetPanelDirectory(new BDirectory("/boot/home/public_html"));
108 	webDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Select");
109 	change_title = webDirFilePanel->Window();
110 	change_title->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR);
111 
112 	message.what = MSG_FILE_PANEL_CREATE_LOG_FILE;
113 	logFilePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL,
114 		B_FILE_NODE, false, &message);
115 	logFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Create");
116 	change_title = logFilePanel->Window();
117 	change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE);
118 
119 	Show();
120 
121 }
122 
123 
124 PoorManPreferencesWindow::~PoorManPreferencesWindow()
125 {
126 	delete logFilePanel;
127 	delete webDirFilePanel;
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