xref: /haiku/src/apps/poorman/PoorManPreferencesWindow.cpp (revision c302a243e15e640fae0f689e32cdf0c18749afee)
14af8c448SPhil Greenway /* PoorManPreferencesWindow.cpp
24af8c448SPhil Greenway  *
34af8c448SPhil Greenway  *	Philip Harrison
44af8c448SPhil Greenway  *	Started: 4/27/2004
54af8c448SPhil Greenway  *	Version: 0.1
64af8c448SPhil Greenway  */
74af8c448SPhil Greenway 
84af8c448SPhil Greenway #include <Box.h>
92813f496SAdrien Destugues #include <Catalog.h>
10000fe088SStephan Aßmus #include <Debug.h>
112813f496SAdrien Destugues #include <Directory.h>
12c5a09a88SAlex Wilson #include <LayoutBuilder.h>
132813f496SAdrien Destugues #include <Locale.h>
142813f496SAdrien Destugues #include <Window.h>
154af8c448SPhil Greenway 
164af8c448SPhil Greenway #include "constants.h"
174af8c448SPhil Greenway #include "PoorManWindow.h"
184af8c448SPhil Greenway #include "PoorManApplication.h"
194af8c448SPhil Greenway #include "PoorManPreferencesWindow.h"
20000fe088SStephan Aßmus #include "PoorManServer.h"
214af8c448SPhil Greenway 
222813f496SAdrien Destugues 
23546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
24546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "PoorMan"
252813f496SAdrien Destugues 
262813f496SAdrien Destugues 
PoorManPreferencesWindow(BRect frame,char * name)274af8c448SPhil Greenway PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name)
28d939e03dSPhilippe Saint-Pierre 	: BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE
29a1ae8022SAlex Wilson 		| B_CLOSE_ON_ESCAPE | B_AUTO_UPDATE_SIZE_LIMITS),
30a1ae8022SAlex Wilson 	fWebDirFilePanel(NULL),
31a1ae8022SAlex Wilson 	fLogFilePanel(NULL)
324af8c448SPhil Greenway {
33a1ae8022SAlex Wilson 	fCancelButton = new BButton("Cancel Button", B_TRANSLATE("Cancel"),
34d939e03dSPhilippe Saint-Pierre 		new BMessage(MSG_PREF_BTN_CANCEL));
35a1ae8022SAlex Wilson 	fDoneButton = new BButton("Done Button", B_TRANSLATE("Done"),
36d939e03dSPhilippe Saint-Pierre 		new BMessage(MSG_PREF_BTN_DONE));
374af8c448SPhil Greenway 
38*40afabe6SAdrien Destugues 	fPrefTabView = new BTabView("Pref Tab View", B_WIDTH_FROM_WIDEST);
393c5208e4SHumdinger 	fPrefTabView->SetBorder(B_NO_BORDER);
404af8c448SPhil Greenway 
414af8c448SPhil Greenway 	// Site Tab
42a1ae8022SAlex Wilson 	fSiteTab = new BTab();
43a1ae8022SAlex Wilson 	fSiteView = new PoorManSiteView("Site View");
44a1ae8022SAlex Wilson 	fPrefTabView->AddTab(fSiteView, fSiteTab);
45a1ae8022SAlex Wilson 	fSiteTab->SetLabel(STR_TAB_SITE);
464af8c448SPhil Greenway 
474af8c448SPhil Greenway 	// Logging Tab
48a1ae8022SAlex Wilson 	fLoggingTab = new BTab();
49a1ae8022SAlex Wilson 	fLoggingView = new PoorManLoggingView("Logging View");
50a1ae8022SAlex Wilson 	fPrefTabView->AddTab(fLoggingView, fLoggingTab);
51a1ae8022SAlex Wilson 	fLoggingTab->SetLabel(STR_TAB_LOGGING);
524af8c448SPhil Greenway 
534af8c448SPhil Greenway 	// Advanced Tab
54a1ae8022SAlex Wilson 	fAdvancedTab = new BTab();
55a1ae8022SAlex Wilson 	fAdvancedView = new PoorManAdvancedView("Advanced View");
56a1ae8022SAlex Wilson 	fPrefTabView->AddTab(fAdvancedView, fAdvancedTab);
57a1ae8022SAlex Wilson 	fAdvancedTab->SetLabel(STR_TAB_ADVANCED);
584af8c448SPhil Greenway 
594af8c448SPhil Greenway 	// FilePanels
604af8c448SPhil Greenway 	BWindow * change_title;
614af8c448SPhil Greenway 
62ebf84359SKarsten Heimrich 	BMessenger messenger(this);
63ebf84359SKarsten Heimrich 	BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR);
64a1ae8022SAlex Wilson 	fWebDirFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL,
65000fe088SStephan Aßmus 		B_DIRECTORY_NODE, false, &message, NULL, true);
66ebf84359SKarsten Heimrich 
67a1ae8022SAlex Wilson 	fWebDirFilePanel->SetPanelDirectory(
68a1ae8022SAlex Wilson 		new BDirectory("/boot/home/public_html"));
69a1ae8022SAlex Wilson 	fWebDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, B_TRANSLATE("Select"));
70a1ae8022SAlex Wilson 	change_title = fWebDirFilePanel->Window();
714af8c448SPhil Greenway 	change_title->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR);
724af8c448SPhil Greenway 
73ebf84359SKarsten Heimrich 	message.what = MSG_FILE_PANEL_CREATE_LOG_FILE;
74a1ae8022SAlex Wilson 	fLogFilePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL,
75ebf84359SKarsten Heimrich 		B_FILE_NODE, false, &message);
76a1ae8022SAlex Wilson 	fLogFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, B_TRANSLATE("Create"));
77a1ae8022SAlex Wilson 	change_title = fLogFilePanel->Window();
784af8c448SPhil Greenway 	change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE);
79a1ae8022SAlex Wilson 
80c5a09a88SAlex Wilson 
813c5208e4SHumdinger 	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
823c5208e4SHumdinger 		.SetInsets(0, B_USE_DEFAULT_SPACING, 0, B_USE_WINDOW_SPACING)
83a1ae8022SAlex Wilson 		.Add(fPrefTabView)
84c5a09a88SAlex Wilson 		.AddGroup(B_HORIZONTAL)
85a1ae8022SAlex Wilson 			.AddGlue()
86a1ae8022SAlex Wilson 			.Add(fCancelButton)
873c5208e4SHumdinger 			.Add(fDoneButton)
883c5208e4SHumdinger 			.SetInsets(B_USE_WINDOW_SPACING, 0, B_USE_WINDOW_SPACING, 0);
894af8c448SPhil Greenway }
904af8c448SPhil Greenway 
91d939e03dSPhilippe Saint-Pierre 
~PoorManPreferencesWindow()92ebf84359SKarsten Heimrich PoorManPreferencesWindow::~PoorManPreferencesWindow()
93ebf84359SKarsten Heimrich {
94a1ae8022SAlex Wilson 	delete fLogFilePanel;
95a1ae8022SAlex Wilson 	delete fWebDirFilePanel;
96ebf84359SKarsten Heimrich }
97ebf84359SKarsten Heimrich 
98d939e03dSPhilippe Saint-Pierre 
994af8c448SPhil Greenway void
MessageReceived(BMessage * message)1004af8c448SPhil Greenway PoorManPreferencesWindow::MessageReceived(BMessage* message)
1014af8c448SPhil Greenway {
1024af8c448SPhil Greenway 	switch (message->what) {
1034af8c448SPhil Greenway 		case MSG_PREF_BTN_DONE:
1044af8c448SPhil Greenway 			PoorManWindow* win;
105000fe088SStephan Aßmus 			PoorManServer* server;
1064af8c448SPhil Greenway 			win = ((PoorManApplication*)be_app)->GetPoorManWindow();
107000fe088SStephan Aßmus 			server = win->GetServer();
1084af8c448SPhil Greenway 
109d939e03dSPhilippe Saint-Pierre 			PRINT(("Pref Window: sendDir CheckBox: %d\n",
110a1ae8022SAlex Wilson 				fSiteView->SendDirValue()));
111a1ae8022SAlex Wilson 			server->SetListDir(fSiteView->SendDirValue());
112a1ae8022SAlex Wilson 			win->SetDirListFlag(fSiteView->SendDirValue());
113d939e03dSPhilippe Saint-Pierre 			PRINT(("Pref Window: indexFileName TextControl: %s\n",
114a1ae8022SAlex Wilson 				fSiteView->IndexFileName()));
115a1ae8022SAlex Wilson 			if (server->SetIndexName(fSiteView->IndexFileName()) == B_OK)
116a1ae8022SAlex Wilson 				win->SetIndexFileName(fSiteView->IndexFileName());
117a1ae8022SAlex Wilson 			PRINT(("Pref Window: webDir: %s\n", fSiteView->WebDir()));
118a1ae8022SAlex Wilson 			if (server->SetWebDir(fSiteView->WebDir()) == B_OK) {
119a1ae8022SAlex Wilson 				win->SetWebDir(fSiteView->WebDir());
120a1ae8022SAlex Wilson 				win->SetDirLabel(fSiteView->WebDir());
121000fe088SStephan Aßmus 			}
1224af8c448SPhil Greenway 
123d939e03dSPhilippe Saint-Pierre 			PRINT(("Pref Window: logConsole CheckBox: %d\n",
124a1ae8022SAlex Wilson 				fLoggingView->LogConsoleValue()));
125a1ae8022SAlex Wilson 			win->SetLogConsoleFlag(fLoggingView->LogConsoleValue());
126d939e03dSPhilippe Saint-Pierre 			PRINT(("Pref Window: logFile CheckBox: %d\n",
127a1ae8022SAlex Wilson 				fLoggingView->LogFileValue()));
128a1ae8022SAlex Wilson 			win->SetLogFileFlag(fLoggingView->LogFileValue());
129d939e03dSPhilippe Saint-Pierre 			PRINT(("Pref Window: logFileName: %s\n",
130a1ae8022SAlex Wilson 				fLoggingView->LogFileName()));
131a1ae8022SAlex Wilson 			win->SetLogPath(fLoggingView->LogFileName());
1324af8c448SPhil Greenway 
1331a7bcf69SOliver Tappe 			PRINT(("Pref Window: MaxConnections Slider: %" B_PRId32 "\n",
134a1ae8022SAlex Wilson 				fAdvancedView->MaxSimultaneousConnections()));
135a1ae8022SAlex Wilson 			server->SetMaxConns(fAdvancedView->MaxSimultaneousConnections());
136d939e03dSPhilippe Saint-Pierre 			win->SetMaxConnections(
137a1ae8022SAlex Wilson 				(int16)fAdvancedView->MaxSimultaneousConnections());
1384af8c448SPhil Greenway 
1394af8c448SPhil Greenway 			if (Lock())
1404af8c448SPhil Greenway 				Quit();
1414af8c448SPhil Greenway 			break;
1424af8c448SPhil Greenway 		case MSG_PREF_BTN_CANCEL:
1434af8c448SPhil Greenway 			if (Lock())
1444af8c448SPhil Greenway 				Quit();
1454af8c448SPhil Greenway 			break;
1464af8c448SPhil Greenway 		case MSG_PREF_SITE_BTN_SELECT:
1473bbf781cSAlex Wilson 		{
1484af8c448SPhil Greenway 			// Select the Web Directory, root directory to look in.
149a1ae8022SAlex Wilson 			fWebDirFilePanel->SetTarget(this);
1503bbf781cSAlex Wilson 			BMessage webDirSelectedMsg(MSG_FILE_PANEL_SELECT_WEB_DIR);
1513bbf781cSAlex Wilson 			fWebDirFilePanel->SetMessage(&webDirSelectedMsg);
152a1ae8022SAlex Wilson 			if (!fWebDirFilePanel->IsShowing())
153a1ae8022SAlex Wilson 				fWebDirFilePanel->Show();
1544af8c448SPhil Greenway 			break;
1553bbf781cSAlex Wilson 		}
1564af8c448SPhil Greenway 		case MSG_FILE_PANEL_SELECT_WEB_DIR:
1574af8c448SPhil Greenway 			// handle the open BMessage from the Select Web Directory File Panel
158000fe088SStephan Aßmus 			PRINT(("Select Web Directory:\n"));
1594af8c448SPhil Greenway 			SelectWebDir(message);
1604af8c448SPhil Greenway 			break;
1614af8c448SPhil Greenway 		case MSG_PREF_LOG_BTN_CREATE_FILE:
1624af8c448SPhil Greenway 			// Create the Log File
163a1ae8022SAlex Wilson 			fLogFilePanel->Show();
1644af8c448SPhil Greenway 			break;
1654af8c448SPhil Greenway 		case MSG_FILE_PANEL_CREATE_LOG_FILE:
1664af8c448SPhil Greenway 			// handle the save BMessage from the Create Log File Panel
167000fe088SStephan Aßmus 			PRINT(("Create Log File:\n"));
1684af8c448SPhil Greenway 			CreateLogFile(message);
1694af8c448SPhil Greenway 			break;
1704af8c448SPhil Greenway 		case MSG_PREF_ADV_SLD_MAX_CONNECTION:
171a1ae8022SAlex Wilson 			fMaxConnections = fAdvancedView->MaxSimultaneousConnections();
1721a7bcf69SOliver Tappe 			PRINT(("Max Connections: %" B_PRId32 "\n", fMaxConnections));
1734af8c448SPhil Greenway 			break;
1744af8c448SPhil Greenway 		default:
1754af8c448SPhil Greenway 			BWindow::MessageReceived(message);
1764af8c448SPhil Greenway 			break;
1774af8c448SPhil Greenway 	}
1784af8c448SPhil Greenway }
1794af8c448SPhil Greenway 
180d939e03dSPhilippe Saint-Pierre 
1814af8c448SPhil Greenway void
SelectWebDir(BMessage * message)1824af8c448SPhil Greenway PoorManPreferencesWindow::SelectWebDir(BMessage* message)
1834af8c448SPhil Greenway {
1844af8c448SPhil Greenway 	entry_ref	ref;
1854af8c448SPhil Greenway 	BPath		path;
1864af8c448SPhil Greenway 	BEntry		entry;
1874af8c448SPhil Greenway 
1883bbf781cSAlex Wilson 	if (message->FindRef("refs", &ref) != B_OK || entry.SetTo(&ref) != B_OK) {
1895c6b9eb0SJerome Duval 		return;
1905c6b9eb0SJerome Duval 	}
1914af8c448SPhil Greenway 	entry.GetPath(&path);
1924af8c448SPhil Greenway 
193000fe088SStephan Aßmus 	PRINT(("DIR: %s\n", path.Path()));
194a1ae8022SAlex Wilson 	fSiteView->SetWebDir(path.Path());
195000fe088SStephan Aßmus 
196000fe088SStephan Aßmus 	bool temp;
197000fe088SStephan Aßmus 	if (message->FindBool("Default Dialog", &temp) == B_OK) {
198000fe088SStephan Aßmus 		PoorManWindow* win = ((PoorManApplication *)be_app)->GetPoorManWindow();
199d939e03dSPhilippe Saint-Pierre 		win->StartServer();
200a1ae8022SAlex Wilson 		if (win->GetServer()->SetWebDir(fSiteView->WebDir()) == B_OK) {
201a1ae8022SAlex Wilson 			win->SetWebDir(fSiteView->WebDir());
202a1ae8022SAlex Wilson 			win->SetDirLabel(fSiteView->WebDir());
203d939e03dSPhilippe Saint-Pierre 			win->SaveSettings();
204d939e03dSPhilippe Saint-Pierre 			win->Show();
205000fe088SStephan Aßmus 		}
206000fe088SStephan Aßmus 		if (Lock())
207000fe088SStephan Aßmus 			Quit();
208000fe088SStephan Aßmus 	}
2094af8c448SPhil Greenway }
2104af8c448SPhil Greenway 
211d939e03dSPhilippe Saint-Pierre 
2124af8c448SPhil Greenway void
CreateLogFile(BMessage * message)2134af8c448SPhil Greenway PoorManPreferencesWindow::CreateLogFile(BMessage* message)
2144af8c448SPhil Greenway {
2154af8c448SPhil Greenway 	entry_ref	ref;
2164af8c448SPhil Greenway 	const char	* name;
2174af8c448SPhil Greenway 	BPath		path;
2184af8c448SPhil Greenway 	BEntry		entry;
2194af8c448SPhil Greenway 	status_t	err = B_OK;
2204af8c448SPhil Greenway 
2214af8c448SPhil Greenway 	err = message->FindRef("directory", &ref) != B_OK;
2224af8c448SPhil Greenway 	//if (err = message->FindRef("directory", &ref) != B_OK)
2234af8c448SPhil Greenway 		//return err;
2244af8c448SPhil Greenway 	err = message->FindString("name", &name) != B_OK;
2254af8c448SPhil Greenway 	//if (err = message->FindString("name", &name) != B_OK)
2264af8c448SPhil Greenway 	//	;//return err;
2274af8c448SPhil Greenway 	err = entry.SetTo(&ref) != B_OK;
2284af8c448SPhil Greenway 	//if (err = entry.SetTo(&ref) != B_OK)
2294af8c448SPhil Greenway 	//	;//return err;
2304af8c448SPhil Greenway 	entry.GetPath(&path);
2314af8c448SPhil Greenway 	path.Append(name);
232000fe088SStephan Aßmus 	PRINT(("Log File: %s\n", path.Path()));
2334af8c448SPhil Greenway 
234d939e03dSPhilippe Saint-Pierre 	if (err == B_OK) {
235a1ae8022SAlex Wilson 		fLoggingView->SetLogFileName(path.Path());
236a1ae8022SAlex Wilson 		fLoggingView->SetLogFileValue(true);
2374af8c448SPhil Greenway 	}
2384af8c448SPhil Greenway 
2394af8c448SPhil Greenway 	// mark the checkbox
2404af8c448SPhil Greenway }
241000fe088SStephan Aßmus 
242d939e03dSPhilippe Saint-Pierre 
243000fe088SStephan Aßmus /*A special version for "the default dialog", don't use it in MessageReceived()*/
244000fe088SStephan Aßmus void
ShowWebDirFilePanel()245000fe088SStephan Aßmus PoorManPreferencesWindow::ShowWebDirFilePanel()
246000fe088SStephan Aßmus {
247000fe088SStephan Aßmus 	BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR);
248000fe088SStephan Aßmus 	message.AddBool("Default Dialog", true);
249000fe088SStephan Aßmus 
250a1ae8022SAlex Wilson 	fWebDirFilePanel->SetTarget(be_app);
251a1ae8022SAlex Wilson 	fWebDirFilePanel->SetMessage(&message);
252a1ae8022SAlex Wilson 	if (!fWebDirFilePanel->IsShowing())
253a1ae8022SAlex Wilson 		fWebDirFilePanel->Show();
254000fe088SStephan Aßmus }
255