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