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> 122813f496SAdrien Destugues #include <Locale.h> 132813f496SAdrien Destugues #include <Window.h> 144af8c448SPhil Greenway 154af8c448SPhil Greenway #include "constants.h" 164af8c448SPhil Greenway #include "PoorManWindow.h" 174af8c448SPhil Greenway #include "PoorManApplication.h" 184af8c448SPhil Greenway #include "PoorManPreferencesWindow.h" 19000fe088SStephan Aßmus #include "PoorManServer.h" 204af8c448SPhil Greenway 212813f496SAdrien Destugues 222813f496SAdrien Destugues #undef B_TRANSLATE_CONTEXT 232813f496SAdrien Destugues #define B_TRANSLATE_CONTEXT "PoorMan" 242813f496SAdrien Destugues 252813f496SAdrien Destugues 264af8c448SPhil Greenway PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name) 27d939e03dSPhilippe Saint-Pierre : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE 28d939e03dSPhilippe Saint-Pierre | B_CLOSE_ON_ESCAPE), 29ebf84359SKarsten Heimrich webDirFilePanel(NULL), 30ebf84359SKarsten Heimrich logFilePanel(NULL) 314af8c448SPhil Greenway { 324af8c448SPhil Greenway frame = Bounds(); 334af8c448SPhil Greenway 344af8c448SPhil Greenway prefView = new PoorManView(frame, STR_WIN_NAME_PREF); 354af8c448SPhil Greenway //prefView->SetViewColor(216,216,216,255); 364af8c448SPhil Greenway prefView->SetViewColor(BACKGROUND_COLOR); 374af8c448SPhil Greenway AddChild(prefView); 384af8c448SPhil Greenway 394af8c448SPhil Greenway 404af8c448SPhil Greenway // Button View 414af8c448SPhil Greenway BRect buttonRect; 424af8c448SPhil Greenway buttonRect = Bounds(); 434af8c448SPhil Greenway buttonRect.top = buttonRect.bottom - 30; 444af8c448SPhil Greenway 454af8c448SPhil Greenway buttonView = new PoorManView(buttonRect, "Button View"); 464af8c448SPhil Greenway buttonView->SetViewColor(BACKGROUND_COLOR); 474af8c448SPhil Greenway prefView->AddChild(buttonView); 484af8c448SPhil Greenway 494af8c448SPhil Greenway // Buttons 504af8c448SPhil Greenway float buttonTop = 0.0f; 514af8c448SPhil Greenway float buttonHeight = 26.0f; 524af8c448SPhil Greenway 532813f496SAdrien Destugues float widthCancel = prefView->StringWidth(B_TRANSLATE("Cancel")) + 24.0f; 542813f496SAdrien Destugues float widthDone = prefView->StringWidth(B_TRANSLATE("Done")) + 24.0f; 554af8c448SPhil Greenway 56d939e03dSPhilippe Saint-Pierre float gap = 5.0f; 57d939e03dSPhilippe Saint-Pierre 58d939e03dSPhilippe Saint-Pierre BRect button1(prefView->Bounds().Width() - 2 * gap - widthCancel 59d939e03dSPhilippe Saint-Pierre - widthDone, buttonTop, prefView->Bounds().Width() - 2 * gap - widthDone, 60d939e03dSPhilippe Saint-Pierre buttonTop + buttonHeight); 612813f496SAdrien Destugues cancelButton = new BButton(button1, "Cancel Button", B_TRANSLATE("Cancel"), 62d939e03dSPhilippe Saint-Pierre new BMessage(MSG_PREF_BTN_CANCEL)); 63d939e03dSPhilippe Saint-Pierre 64d939e03dSPhilippe Saint-Pierre BRect button2(prefView->Bounds().Width() - gap - widthDone, buttonTop, 65d939e03dSPhilippe Saint-Pierre prefView->Bounds().Width() - gap, buttonTop + buttonHeight); 662813f496SAdrien Destugues doneButton = new BButton(button2, "Done Button", B_TRANSLATE("Done"), 67d939e03dSPhilippe Saint-Pierre new BMessage(MSG_PREF_BTN_DONE)); 684af8c448SPhil Greenway 694af8c448SPhil Greenway buttonView->AddChild(cancelButton); 704af8c448SPhil Greenway buttonView->AddChild(doneButton); 714af8c448SPhil Greenway 724af8c448SPhil Greenway // Create tabs 734af8c448SPhil Greenway BRect r; 744af8c448SPhil Greenway r = Bounds(); 754af8c448SPhil Greenway //r.InsetBy(5, 5); 764af8c448SPhil Greenway r.top += 8.0; 774af8c448SPhil Greenway r.bottom -= 38.0; 784af8c448SPhil Greenway 794af8c448SPhil Greenway prefTabView = new BTabView(r, "Pref Tab View"); 804af8c448SPhil Greenway prefTabView->SetViewColor(BACKGROUND_COLOR); 814af8c448SPhil Greenway 824af8c448SPhil Greenway r = prefTabView->Bounds(); 834af8c448SPhil Greenway r.InsetBy(5, 5); 844af8c448SPhil Greenway r.bottom -= prefTabView->TabHeight(); 854af8c448SPhil Greenway 864af8c448SPhil Greenway // Site Tab 874af8c448SPhil Greenway siteTab = new BTab(); 884af8c448SPhil Greenway siteView = new PoorManSiteView(r, "Site View"); 894af8c448SPhil Greenway prefTabView->AddTab(siteView, siteTab); 904af8c448SPhil Greenway siteTab->SetLabel(STR_TAB_SITE); 914af8c448SPhil Greenway 924af8c448SPhil Greenway // Logging Tab 934af8c448SPhil Greenway loggingTab = new BTab(); 944af8c448SPhil Greenway loggingView = new PoorManLoggingView(r, "Logging View"); 954af8c448SPhil Greenway prefTabView->AddTab(loggingView, loggingTab); 964af8c448SPhil Greenway loggingTab->SetLabel(STR_TAB_LOGGING); 974af8c448SPhil Greenway 984af8c448SPhil Greenway // Advanced Tab 994af8c448SPhil Greenway advancedTab = new BTab(); 1004af8c448SPhil Greenway advancedView = new PoorManAdvancedView(r, "Advanced View"); 1014af8c448SPhil Greenway prefTabView->AddTab(advancedView, advancedTab); 1024af8c448SPhil Greenway advancedTab->SetLabel(STR_TAB_ADVANCED); 1034af8c448SPhil Greenway 1044af8c448SPhil Greenway prefView->AddChild(prefTabView); 1054af8c448SPhil Greenway 1064af8c448SPhil Greenway // FilePanels 1074af8c448SPhil Greenway BWindow * change_title; 1084af8c448SPhil Greenway 109ebf84359SKarsten Heimrich BMessenger messenger(this); 110ebf84359SKarsten Heimrich BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR); 111ebf84359SKarsten Heimrich webDirFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL, 112000fe088SStephan Aßmus B_DIRECTORY_NODE, false, &message, NULL, true); 113ebf84359SKarsten Heimrich 1144af8c448SPhil Greenway webDirFilePanel->SetPanelDirectory(new BDirectory("/boot/home/public_html")); 1152813f496SAdrien Destugues webDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, B_TRANSLATE("Select")); 1164af8c448SPhil Greenway change_title = webDirFilePanel->Window(); 1174af8c448SPhil Greenway change_title->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR); 1184af8c448SPhil Greenway 119ebf84359SKarsten Heimrich message.what = MSG_FILE_PANEL_CREATE_LOG_FILE; 120ebf84359SKarsten Heimrich logFilePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL, 121ebf84359SKarsten Heimrich B_FILE_NODE, false, &message); 1222813f496SAdrien Destugues logFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, B_TRANSLATE("Create")); 1234af8c448SPhil Greenway change_title = logFilePanel->Window(); 1244af8c448SPhil Greenway change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE); 1254af8c448SPhil Greenway } 1264af8c448SPhil Greenway 127d939e03dSPhilippe Saint-Pierre 128ebf84359SKarsten Heimrich PoorManPreferencesWindow::~PoorManPreferencesWindow() 129ebf84359SKarsten Heimrich { 130ebf84359SKarsten Heimrich delete logFilePanel; 131ebf84359SKarsten Heimrich delete webDirFilePanel; 132ebf84359SKarsten Heimrich } 133ebf84359SKarsten Heimrich 134d939e03dSPhilippe Saint-Pierre 1354af8c448SPhil Greenway void 1364af8c448SPhil Greenway PoorManPreferencesWindow::MessageReceived(BMessage* message) 1374af8c448SPhil Greenway { 1384af8c448SPhil Greenway switch (message->what) { 1394af8c448SPhil Greenway case MSG_PREF_BTN_DONE: 1404af8c448SPhil Greenway PoorManWindow* win; 141000fe088SStephan Aßmus PoorManServer* server; 1424af8c448SPhil Greenway win = ((PoorManApplication *)be_app)->GetPoorManWindow(); 143000fe088SStephan Aßmus server = win->GetServer(); 1444af8c448SPhil Greenway 145d939e03dSPhilippe Saint-Pierre PRINT(("Pref Window: sendDir CheckBox: %d\n", 146d939e03dSPhilippe Saint-Pierre siteView->SendDirValue())); 147000fe088SStephan Aßmus server->SetListDir(siteView->SendDirValue()); 1484af8c448SPhil Greenway win->SetDirListFlag(siteView->SendDirValue()); 149d939e03dSPhilippe Saint-Pierre PRINT(("Pref Window: indexFileName TextControl: %s\n", 150d939e03dSPhilippe Saint-Pierre siteView->IndexFileName())); 151000fe088SStephan Aßmus if (server->SetIndexName(siteView->IndexFileName()) == B_OK) 1524af8c448SPhil Greenway win->SetIndexFileName(siteView->IndexFileName()); 153000fe088SStephan Aßmus PRINT(("Pref Window: webDir: %s\n", siteView->WebDir())); 154000fe088SStephan Aßmus if (server->SetWebDir(siteView->WebDir()) == B_OK) { 1554af8c448SPhil Greenway win->SetWebDir(siteView->WebDir()); 1564af8c448SPhil Greenway win->SetDirLabel(siteView->WebDir()); 157000fe088SStephan Aßmus } 1584af8c448SPhil Greenway 159d939e03dSPhilippe Saint-Pierre PRINT(("Pref Window: logConsole CheckBox: %d\n", 160d939e03dSPhilippe Saint-Pierre loggingView->LogConsoleValue())); 1614af8c448SPhil Greenway win->SetLogConsoleFlag(loggingView->LogConsoleValue()); 162d939e03dSPhilippe Saint-Pierre PRINT(("Pref Window: logFile CheckBox: %d\n", 163d939e03dSPhilippe Saint-Pierre loggingView->LogFileValue())); 1644af8c448SPhil Greenway win->SetLogFileFlag(loggingView->LogFileValue()); 165d939e03dSPhilippe Saint-Pierre PRINT(("Pref Window: logFileName: %s\n", 166d939e03dSPhilippe Saint-Pierre loggingView->LogFileName())); 1674af8c448SPhil Greenway win->SetLogPath(loggingView->LogFileName()); 1684af8c448SPhil Greenway 169d939e03dSPhilippe Saint-Pierre PRINT(("Pref Window: MaxConnections Slider: %ld\n", 170d939e03dSPhilippe Saint-Pierre advancedView->MaxSimultaneousConnections())); 171000fe088SStephan Aßmus server->SetMaxConns(advancedView->MaxSimultaneousConnections()); 172d939e03dSPhilippe Saint-Pierre win->SetMaxConnections( 173d939e03dSPhilippe Saint-Pierre (int16)advancedView->MaxSimultaneousConnections()); 1744af8c448SPhil Greenway 1754af8c448SPhil Greenway if (Lock()) 1764af8c448SPhil Greenway Quit(); 1774af8c448SPhil Greenway break; 1784af8c448SPhil Greenway case MSG_PREF_BTN_CANCEL: 1794af8c448SPhil Greenway if (Lock()) 1804af8c448SPhil Greenway Quit(); 1814af8c448SPhil Greenway break; 1824af8c448SPhil Greenway case MSG_PREF_SITE_BTN_SELECT: 1834af8c448SPhil Greenway // Select the Web Directory, root directory to look in. 184d939e03dSPhilippe Saint-Pierre webDirFilePanel->SetTarget(this); 185d939e03dSPhilippe Saint-Pierre webDirFilePanel->SetMessage(new BMessage(MSG_FILE_PANEL_SELECT_WEB_DIR)); 1864af8c448SPhil Greenway if (!webDirFilePanel->IsShowing()) 1874af8c448SPhil Greenway webDirFilePanel->Show(); 1884af8c448SPhil Greenway break; 1894af8c448SPhil Greenway case MSG_FILE_PANEL_SELECT_WEB_DIR: 1904af8c448SPhil Greenway // handle the open BMessage from the Select Web Directory File Panel 191000fe088SStephan Aßmus PRINT(("Select Web Directory:\n")); 1924af8c448SPhil Greenway SelectWebDir(message); 1934af8c448SPhil Greenway break; 1944af8c448SPhil Greenway case MSG_PREF_LOG_BTN_CREATE_FILE: 1954af8c448SPhil Greenway // Create the Log File 1964af8c448SPhil Greenway logFilePanel->Show(); 1974af8c448SPhil Greenway break; 1984af8c448SPhil Greenway case MSG_FILE_PANEL_CREATE_LOG_FILE: 1994af8c448SPhil Greenway // handle the save BMessage from the Create Log File Panel 200000fe088SStephan Aßmus PRINT(("Create Log File:\n")); 2014af8c448SPhil Greenway CreateLogFile(message); 2024af8c448SPhil Greenway break; 2034af8c448SPhil Greenway case MSG_PREF_ADV_SLD_MAX_CONNECTION: 2044af8c448SPhil Greenway max_connections = advancedView->MaxSimultaneousConnections(); 205000fe088SStephan Aßmus PRINT(("Max Connections: %ld\n", max_connections)); 2064af8c448SPhil Greenway break; 2074af8c448SPhil Greenway default: 2084af8c448SPhil Greenway BWindow::MessageReceived(message); 2094af8c448SPhil Greenway break; 2104af8c448SPhil Greenway } 2114af8c448SPhil Greenway } 2124af8c448SPhil Greenway 213d939e03dSPhilippe Saint-Pierre 2144af8c448SPhil Greenway void 2154af8c448SPhil Greenway PoorManPreferencesWindow::SelectWebDir(BMessage * message) 2164af8c448SPhil Greenway { 2174af8c448SPhil Greenway entry_ref ref; 2184af8c448SPhil Greenway const char * name; 2194af8c448SPhil Greenway BPath path; 2204af8c448SPhil Greenway BEntry entry; 2214af8c448SPhil Greenway 222*5c6b9eb0SJerome Duval if (message->FindRef("refs", &ref) != B_OK 223*5c6b9eb0SJerome Duval || message->FindString("name", &name) != B_OK 224*5c6b9eb0SJerome Duval || entry.SetTo(&ref) != B_OK) { 225*5c6b9eb0SJerome Duval return; 226*5c6b9eb0SJerome Duval } 2274af8c448SPhil Greenway entry.GetPath(&path); 2284af8c448SPhil Greenway 229000fe088SStephan Aßmus PRINT(("DIR: %s\n", path.Path())); 2304af8c448SPhil Greenway siteView->SetWebDir(path.Path()); 231000fe088SStephan Aßmus 232000fe088SStephan Aßmus bool temp; 233000fe088SStephan Aßmus if (message->FindBool("Default Dialog", &temp) == B_OK) { 234000fe088SStephan Aßmus PoorManWindow* win = ((PoorManApplication *)be_app)->GetPoorManWindow(); 235d939e03dSPhilippe Saint-Pierre win->StartServer(); 236000fe088SStephan Aßmus if (win->GetServer()->SetWebDir(siteView->WebDir()) == B_OK) { 237000fe088SStephan Aßmus win->SetWebDir(siteView->WebDir()); 238000fe088SStephan Aßmus win->SetDirLabel(siteView->WebDir()); 239d939e03dSPhilippe Saint-Pierre win->SaveSettings(); 240d939e03dSPhilippe Saint-Pierre win->Show(); 241000fe088SStephan Aßmus } 242000fe088SStephan Aßmus if (Lock()) 243000fe088SStephan Aßmus Quit(); 244000fe088SStephan Aßmus } 2454af8c448SPhil Greenway } 2464af8c448SPhil Greenway 247d939e03dSPhilippe Saint-Pierre 2484af8c448SPhil Greenway void 2494af8c448SPhil Greenway PoorManPreferencesWindow::CreateLogFile(BMessage * message) 2504af8c448SPhil Greenway { 2514af8c448SPhil Greenway entry_ref ref; 2524af8c448SPhil Greenway const char * name; 2534af8c448SPhil Greenway BPath path; 2544af8c448SPhil Greenway BEntry entry; 2554af8c448SPhil Greenway status_t err = B_OK; 2564af8c448SPhil Greenway 2574af8c448SPhil Greenway err = message->FindRef("directory", &ref) != B_OK; 2584af8c448SPhil Greenway //if (err = message->FindRef("directory", &ref) != B_OK) 2594af8c448SPhil Greenway //return err; 2604af8c448SPhil Greenway err = message->FindString("name", &name) != B_OK; 2614af8c448SPhil Greenway //if (err = message->FindString("name", &name) != B_OK) 2624af8c448SPhil Greenway // ;//return err; 2634af8c448SPhil Greenway err = entry.SetTo(&ref) != B_OK; 2644af8c448SPhil Greenway //if (err = entry.SetTo(&ref) != B_OK) 2654af8c448SPhil Greenway // ;//return err; 2664af8c448SPhil Greenway entry.GetPath(&path); 2674af8c448SPhil Greenway path.Append(name); 268000fe088SStephan Aßmus PRINT(("Log File: %s\n", path.Path())); 2694af8c448SPhil Greenway 270d939e03dSPhilippe Saint-Pierre if (err == B_OK) { 2714af8c448SPhil Greenway loggingView->SetLogFileName(path.Path()); 2724af8c448SPhil Greenway loggingView->SetLogFileValue(true); 2734af8c448SPhil Greenway } 2744af8c448SPhil Greenway 2754af8c448SPhil Greenway // mark the checkbox 2764af8c448SPhil Greenway } 277000fe088SStephan Aßmus 278d939e03dSPhilippe Saint-Pierre 279000fe088SStephan Aßmus /*A special version for "the default dialog", don't use it in MessageReceived()*/ 280000fe088SStephan Aßmus void 281000fe088SStephan Aßmus PoorManPreferencesWindow::ShowWebDirFilePanel() 282000fe088SStephan Aßmus { 283000fe088SStephan Aßmus BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR); 284000fe088SStephan Aßmus message.AddBool("Default Dialog", true); 285000fe088SStephan Aßmus 286d939e03dSPhilippe Saint-Pierre webDirFilePanel->SetTarget(be_app); 287000fe088SStephan Aßmus webDirFilePanel->SetMessage(&message); 288000fe088SStephan Aßmus if (!webDirFilePanel->IsShowing()) 289000fe088SStephan Aßmus webDirFilePanel->Show(); 290000fe088SStephan Aßmus } 291