1 /* PoorManPreferencesWindow.cpp 2 * 3 * Philip Harrison 4 * Started: 4/27/2004 5 * Version: 0.1 6 */ 7 8 #include <Box.h> 9 #include <Catalog.h> 10 #include <Debug.h> 11 #include <Directory.h> 12 #include <LayoutBuilder.h> 13 #include <Locale.h> 14 #include <Window.h> 15 16 #include "constants.h" 17 #include "PoorManWindow.h" 18 #include "PoorManApplication.h" 19 #include "PoorManPreferencesWindow.h" 20 #include "PoorManServer.h" 21 22 23 #undef B_TRANSLATION_CONTEXT 24 #define B_TRANSLATION_CONTEXT "PoorMan" 25 26 27 PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name) 28 : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE 29 | B_CLOSE_ON_ESCAPE | B_AUTO_UPDATE_SIZE_LIMITS), 30 fWebDirFilePanel(NULL), 31 fLogFilePanel(NULL) 32 { 33 fCancelButton = new BButton("Cancel Button", B_TRANSLATE("Cancel"), 34 new BMessage(MSG_PREF_BTN_CANCEL)); 35 fDoneButton = new BButton("Done Button", B_TRANSLATE("Done"), 36 new BMessage(MSG_PREF_BTN_DONE)); 37 38 fPrefTabView = new BTabView("Pref Tab View", B_WIDTH_FROM_WIDEST); 39 fPrefTabView->SetBorder(B_NO_BORDER); 40 41 // Site Tab 42 fSiteTab = new BTab(); 43 fSiteView = new PoorManSiteView("Site View"); 44 fPrefTabView->AddTab(fSiteView, fSiteTab); 45 fSiteTab->SetLabel(STR_TAB_SITE); 46 47 // Logging Tab 48 fLoggingTab = new BTab(); 49 fLoggingView = new PoorManLoggingView("Logging View"); 50 fPrefTabView->AddTab(fLoggingView, fLoggingTab); 51 fLoggingTab->SetLabel(STR_TAB_LOGGING); 52 53 // Advanced Tab 54 fAdvancedTab = new BTab(); 55 fAdvancedView = new PoorManAdvancedView("Advanced View"); 56 fPrefTabView->AddTab(fAdvancedView, fAdvancedTab); 57 fAdvancedTab->SetLabel(STR_TAB_ADVANCED); 58 59 // FilePanels 60 BWindow * change_title; 61 62 BMessenger messenger(this); 63 BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR); 64 fWebDirFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL, 65 B_DIRECTORY_NODE, false, &message, NULL, true); 66 67 fWebDirFilePanel->SetPanelDirectory( 68 new BDirectory("/boot/home/public_html")); 69 fWebDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, B_TRANSLATE("Select")); 70 change_title = fWebDirFilePanel->Window(); 71 change_title->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR); 72 73 message.what = MSG_FILE_PANEL_CREATE_LOG_FILE; 74 fLogFilePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL, 75 B_FILE_NODE, false, &message); 76 fLogFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, B_TRANSLATE("Create")); 77 change_title = fLogFilePanel->Window(); 78 change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE); 79 80 81 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 82 .SetInsets(0, B_USE_DEFAULT_SPACING, 0, B_USE_WINDOW_SPACING) 83 .Add(fPrefTabView) 84 .AddGroup(B_HORIZONTAL) 85 .AddGlue() 86 .Add(fCancelButton) 87 .Add(fDoneButton) 88 .SetInsets(B_USE_WINDOW_SPACING, 0, B_USE_WINDOW_SPACING, 0); 89 } 90 91 92 PoorManPreferencesWindow::~PoorManPreferencesWindow() 93 { 94 delete fLogFilePanel; 95 delete fWebDirFilePanel; 96 } 97 98 99 void 100 PoorManPreferencesWindow::MessageReceived(BMessage* message) 101 { 102 switch (message->what) { 103 case MSG_PREF_BTN_DONE: 104 PoorManWindow* win; 105 PoorManServer* server; 106 win = ((PoorManApplication*)be_app)->GetPoorManWindow(); 107 server = win->GetServer(); 108 109 PRINT(("Pref Window: sendDir CheckBox: %d\n", 110 fSiteView->SendDirValue())); 111 server->SetListDir(fSiteView->SendDirValue()); 112 win->SetDirListFlag(fSiteView->SendDirValue()); 113 PRINT(("Pref Window: indexFileName TextControl: %s\n", 114 fSiteView->IndexFileName())); 115 if (server->SetIndexName(fSiteView->IndexFileName()) == B_OK) 116 win->SetIndexFileName(fSiteView->IndexFileName()); 117 PRINT(("Pref Window: webDir: %s\n", fSiteView->WebDir())); 118 if (server->SetWebDir(fSiteView->WebDir()) == B_OK) { 119 win->SetWebDir(fSiteView->WebDir()); 120 win->SetDirLabel(fSiteView->WebDir()); 121 } 122 123 PRINT(("Pref Window: logConsole CheckBox: %d\n", 124 fLoggingView->LogConsoleValue())); 125 win->SetLogConsoleFlag(fLoggingView->LogConsoleValue()); 126 PRINT(("Pref Window: logFile CheckBox: %d\n", 127 fLoggingView->LogFileValue())); 128 win->SetLogFileFlag(fLoggingView->LogFileValue()); 129 PRINT(("Pref Window: logFileName: %s\n", 130 fLoggingView->LogFileName())); 131 win->SetLogPath(fLoggingView->LogFileName()); 132 133 PRINT(("Pref Window: MaxConnections Slider: %" B_PRId32 "\n", 134 fAdvancedView->MaxSimultaneousConnections())); 135 server->SetMaxConns(fAdvancedView->MaxSimultaneousConnections()); 136 win->SetMaxConnections( 137 (int16)fAdvancedView->MaxSimultaneousConnections()); 138 139 if (Lock()) 140 Quit(); 141 break; 142 case MSG_PREF_BTN_CANCEL: 143 if (Lock()) 144 Quit(); 145 break; 146 case MSG_PREF_SITE_BTN_SELECT: 147 { 148 // Select the Web Directory, root directory to look in. 149 fWebDirFilePanel->SetTarget(this); 150 BMessage webDirSelectedMsg(MSG_FILE_PANEL_SELECT_WEB_DIR); 151 fWebDirFilePanel->SetMessage(&webDirSelectedMsg); 152 if (!fWebDirFilePanel->IsShowing()) 153 fWebDirFilePanel->Show(); 154 break; 155 } 156 case MSG_FILE_PANEL_SELECT_WEB_DIR: 157 // handle the open BMessage from the Select Web Directory File Panel 158 PRINT(("Select Web Directory:\n")); 159 SelectWebDir(message); 160 break; 161 case MSG_PREF_LOG_BTN_CREATE_FILE: 162 // Create the Log File 163 fLogFilePanel->Show(); 164 break; 165 case MSG_FILE_PANEL_CREATE_LOG_FILE: 166 // handle the save BMessage from the Create Log File Panel 167 PRINT(("Create Log File:\n")); 168 CreateLogFile(message); 169 break; 170 case MSG_PREF_ADV_SLD_MAX_CONNECTION: 171 fMaxConnections = fAdvancedView->MaxSimultaneousConnections(); 172 PRINT(("Max Connections: %" B_PRId32 "\n", fMaxConnections)); 173 break; 174 default: 175 BWindow::MessageReceived(message); 176 break; 177 } 178 } 179 180 181 void 182 PoorManPreferencesWindow::SelectWebDir(BMessage* message) 183 { 184 entry_ref ref; 185 BPath path; 186 BEntry entry; 187 188 if (message->FindRef("refs", &ref) != B_OK || entry.SetTo(&ref) != B_OK) { 189 return; 190 } 191 entry.GetPath(&path); 192 193 PRINT(("DIR: %s\n", path.Path())); 194 fSiteView->SetWebDir(path.Path()); 195 196 bool temp; 197 if (message->FindBool("Default Dialog", &temp) == B_OK) { 198 PoorManWindow* win = ((PoorManApplication *)be_app)->GetPoorManWindow(); 199 win->StartServer(); 200 if (win->GetServer()->SetWebDir(fSiteView->WebDir()) == B_OK) { 201 win->SetWebDir(fSiteView->WebDir()); 202 win->SetDirLabel(fSiteView->WebDir()); 203 win->SaveSettings(); 204 win->Show(); 205 } 206 if (Lock()) 207 Quit(); 208 } 209 } 210 211 212 void 213 PoorManPreferencesWindow::CreateLogFile(BMessage* message) 214 { 215 entry_ref ref; 216 const char * name; 217 BPath path; 218 BEntry entry; 219 status_t err = B_OK; 220 221 err = message->FindRef("directory", &ref) != B_OK; 222 //if (err = message->FindRef("directory", &ref) != B_OK) 223 //return err; 224 err = message->FindString("name", &name) != B_OK; 225 //if (err = message->FindString("name", &name) != B_OK) 226 // ;//return err; 227 err = entry.SetTo(&ref) != B_OK; 228 //if (err = entry.SetTo(&ref) != B_OK) 229 // ;//return err; 230 entry.GetPath(&path); 231 path.Append(name); 232 PRINT(("Log File: %s\n", path.Path())); 233 234 if (err == B_OK) { 235 fLoggingView->SetLogFileName(path.Path()); 236 fLoggingView->SetLogFileValue(true); 237 } 238 239 // mark the checkbox 240 } 241 242 243 /*A special version for "the default dialog", don't use it in MessageReceived()*/ 244 void 245 PoorManPreferencesWindow::ShowWebDirFilePanel() 246 { 247 BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR); 248 message.AddBool("Default Dialog", true); 249 250 fWebDirFilePanel->SetTarget(be_app); 251 fWebDirFilePanel->SetMessage(&message); 252 if (!fWebDirFilePanel->IsShowing()) 253 fWebDirFilePanel->Show(); 254 } 255