Ticket #3787: poorman.diff
File poorman.diff, 68.2 KB (added by , 15 years ago) |
---|
-
src/apps/poorman/PoorManSiteView.h
14 14 #include <CheckBox.h> 15 15 16 16 17 class PoorManSiteView: public BView 18 { 17 class PoorManSiteView: public BView { 19 18 public: 20 PoorManSiteView(BRect, const char *name); 21 void SetSendDirValue(bool state) {if (state) sendDir->SetValue(B_CONTROL_ON); 22 else sendDir->SetValue(B_CONTROL_OFF); } 23 bool SendDirValue() { return (sendDir->Value() == B_CONTROL_ON) ? true : false; } 24 const char * IndexFileName() { return indexFileName->Text(); } 25 void SetIndexFileName(const char * name) { indexFileName->SetText(name); } 26 const char * WebDir() { return webDir->Text(); } 27 void SetWebDir(const char * dir) { webDir->SetText(dir); } 19 PoorManSiteView(const char *name); 20 21 void SetSendDirValue(bool state) 22 { if (state) fSendDir->SetValue(B_CONTROL_ON); 23 else fSendDir->SetValue(B_CONTROL_OFF); } 24 bool SendDirValue() 25 { return (fSendDir->Value() == B_CONTROL_ON) 26 ? true : false; } 27 const char* IndexFileName() 28 { return fIndexFileName->Text(); } 29 void SetIndexFileName(const char* name) 30 { fIndexFileName->SetText(name); } 31 const char* WebDir() 32 { return fWebDir->Text(); } 33 void SetWebDir(const char* dir) 34 { fWebDir->SetText(dir); } 35 28 36 private: 29 37 // Site Tab 30 38 // Web Site Location 31 BTextControl * webDir;32 BTextControl * indexFileName;33 BButton * selectWebDir;39 BTextControl* fWebDir; 40 BTextControl* fIndexFileName; 41 BButton* fSelectWebDir; 34 42 35 43 // Web Site Options 36 BCheckBox * sendDir;44 BCheckBox* fSendDir; 37 45 38 46 }; 39 47 -
src/apps/poorman/PoorManAdvancedView.h
13 13 #include "StatusSlider.h" 14 14 15 15 16 class PoorManAdvancedView: public BView 17 { 16 class PoorManAdvancedView: public BView { 18 17 public: 19 PoorManAdvancedView(BRect, const char *name); 20 int32 MaxSimultaneousConnections() { return maxConnections->Value(); } 21 void SetMaxSimutaneousConnections(int32 num); 18 PoorManAdvancedView(const char *name); 19 20 int32 MaxSimultaneousConnections() 21 { return fMaxConnections->Value(); } 22 void SetMaxSimutaneousConnections(int32 num); 22 23 private: 23 // Advanced Tab24 // Advanced Tab 24 25 // Connections Options 25 StatusSlider * maxConnections;26 StatusSlider* fMaxConnections; 26 27 }; 27 28 28 29 #endif -
src/apps/poorman/PoorManWindow.cpp
16 16 #include <Directory.h> 17 17 #include <File.h> 18 18 #include <FindDirectory.h> 19 #include <GroupLayoutBuilder.h> 19 20 #include <Menu.h> 20 21 #include <MenuBar.h> 21 22 #include <MenuItem.h> … … 34 35 #include "constants.h" 35 36 36 37 PoorManWindow::PoorManWindow(BRect frame) 37 : BWindow(frame, STR_APP_NAME, B_TITLED_WINDOW, 0), 38 status(false), hits(0), prefWindow(NULL), fLogFile(NULL), fServer(NULL) 38 : 39 BWindow(frame, STR_APP_NAME, B_TITLED_WINDOW, 0), 40 fStatus(false), 41 fHits(0), 42 fPrefWindow(NULL), 43 fLogFile(NULL), 44 fServer(NULL) 39 45 { 40 46 //preferences init 41 web_directory.SetTo(STR_DEFAULT_WEB_DIRECTORY);42 index_file_name.SetTo("index.html");43 dir_list_flag = false;47 fWebDirectory.SetTo(STR_DEFAULT_WEB_DIRECTORY); 48 fIndexFileName.SetTo("index.html"); 49 fDirListFlag = false; 44 50 45 log_console_flag = true;46 log_file_flag = false;47 log_path.SetTo("");51 fLogConsoleFlag = true; 52 fLogFileFlag = false; 53 fLogPath.SetTo(""); 48 54 49 max_connections = (int16)32;55 fMaxConnections = (int16)32; 50 56 51 is_zoomed = true;52 last_width = 318.0f;53 last_height = 320.0f;54 this->f rame = frame;55 setwindow_frame.Set(112.0f, 60.0f, 492.0f, 340.0f);57 fIsZoomed = true; 58 fLastWidth = 318.0f; 59 fLastHeight = 320.0f; 60 this->fFrame = frame; 61 fSetwindowFrame.Set(112.0f, 60.0f, 492.0f, 340.0f); 56 62 57 63 // PoorMan Window 58 64 SetSizeLimits(318, 1600, 53, 1200); … … 61 67 //SetZoomLimits(1024, 768); 62 68 63 69 //frame.Set(30.0f, 30.0f, 355.0f, 185.0f); 64 frame.OffsetTo(B_ORIGIN);65 frame = Bounds();66 frame.top += 19.0;67 70 68 mainView = new PoorManView(frame, STR_APP_NAME); 69 mainView->SetViewColor(216,216,216,255); 70 71 mainView->SetFont(be_bold_font); 72 mainView->SetFontSize(12); 73 AddChild(mainView); 74 75 // BBox tests 76 BRect br; 77 br = mainView->Bounds(); 78 br.top = 1.0; 71 SetLayout(new BGroupLayout(B_VERTICAL)); 79 72 80 BBox * bb = new BBox(br, "Background", B_FOLLOW_ALL_SIDES,81 B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE);82 bb->SetHighColor(WHITE);83 bb->SetLowColor(GRAY);84 bb->SetBorder(B_PLAIN_BORDER);85 mainView->AddChild(bb);86 87 73 // ----------------------------------------------------------------- 88 74 // Three Labels 89 75 90 76 // Status String 91 BRect statusRect; 92 statusRect = Bounds(); 93 statusRect.left += 5; 94 statusRect.top += 3; 95 statusRect.bottom = statusRect.top + 15; 96 statusRect.right = statusRect.left + 100; // make the width wide enough for the string to display 97 98 statusView = new BStringView(statusRect, "Status View", "Status: Stopped"); 99 bb->AddChild(statusView); 77 fStatusView = new BStringView("Status View", "Status: Stopped"); 100 78 101 79 // Directory String 102 BRect dirRect; 103 dirRect = Bounds(); 104 dirRect.top = statusRect.bottom - 1; 105 dirRect.bottom = dirRect.top + 15; 106 dirRect.left = statusRect.left; 107 dirRect.right -= 5; 80 fDirView = new BStringView("Dir View", "Directory: (none)"); 108 81 109 dirView = new BStringView(dirRect, "Dir View", "Directory: (none)", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);110 bb->AddChild(dirView);111 112 82 // Hits String 113 BRect hitsRect; 114 hitsRect = bb->Bounds(); 115 hitsRect.InsetBy(5.0f, 5.0f); 116 hitsRect.top = statusRect.top; 117 hitsRect.bottom = statusRect.bottom; 118 hitsRect.left = statusRect.right + 20; 83 fHitsView = new BStringView("Hit View", "Hits: 0"); 119 84 120 hitsView = new BStringView(hitsRect, "Hit View", "Hits: 0", B_FOLLOW_RIGHT | B_FOLLOW_TOP);121 hitsView->SetAlignment(B_ALIGN_RIGHT);122 bb->AddChild(hitsView);123 85 124 86 // ----------------------------------------------------------------- 125 87 // Logging View 126 88 127 // logRect 128 BRect logRect = bb->Bounds();//(5.0, 36.0, 306.0, 131.0); 129 logRect.InsetBy(5, 5); 130 logRect.top = 36.0f; 131 logRect.right -= B_V_SCROLL_BAR_WIDTH; 132 133 // textRect 134 BRect textRect; //(1.0, 1.0, 175.0, 75.0); 135 textRect = logRect; 136 textRect.top = 0.0; 137 textRect.left = 2.0; 138 textRect.right = logRect.right - logRect.left - 2.0; 139 textRect.bottom = logRect.bottom - logRect.top; 89 fLoggingView = new BTextView(STR_TXT_VIEW, B_WILL_DRAW ); 140 90 141 fLogViewFont = new BFont(be_plain_font); 142 fLogViewFont->SetSize(11.0); 143 144 loggingView = new BTextView(logRect, STR_TXT_VIEW, textRect, 145 fLogViewFont, NULL, B_FOLLOW_ALL_SIDES, B_WILL_DRAW ); 146 147 loggingView->MakeEditable(false); // user cannot change the text 148 loggingView->MakeSelectable(true); 149 loggingView->SetViewColor(WHITE); 150 loggingView->SetStylable(true); 91 fLoggingView->MakeEditable(false); // user cannot change the text 92 fLoggingView->MakeSelectable(true); 93 fLoggingView->SetViewColor(WHITE); 94 fLoggingView->SetStylable(true); 151 95 152 96 // create the scroll view 153 scrollView = new BScrollView("Scroll View", loggingView, B_FOLLOW_ALL_SIDES,97 fScrollView = new BScrollView("Scroll View", fLoggingView, 154 98 B_WILL_DRAW | B_FRAME_EVENTS, 155 99 // Make sure articles on border do not occur when resizing 156 100 false, true); 157 bb->AddChild(scrollView); 158 loggingView->MakeFocus(true); 101 fLoggingView->MakeFocus(true); 159 102 160 103 161 104 // ----------------------------------------------------------------- 162 105 // menu bar 163 BRect menuRect; 164 menuRect = Bounds(); 165 menuRect.bottom = 18.0f; 106 fFileMenuBar = new BMenuBar("File Menu Bar"); 166 107 167 FileMenuBar = new BMenuBar(menuRect, "File Menu Bar");168 169 108 // menus 170 FileMenu = BuildFileMenu();171 if ( FileMenu)172 FileMenuBar->AddItem(FileMenu);109 fFileMenu = BuildfFileMenu(); 110 if (fFileMenu) 111 fFileMenuBar->AddItem(fFileMenu); 173 112 174 EditMenu = BuildEditMenu();175 if ( EditMenu)176 FileMenuBar->AddItem(EditMenu);113 fEditMenu = BuildEditMenu(); 114 if (fEditMenu) 115 fFileMenuBar->AddItem(fEditMenu); 177 116 178 ControlsMenu = BuildControlsMenu();179 if ( ControlsMenu)180 FileMenuBar->AddItem(ControlsMenu);117 fControlsMenu = BuildControlsMenu(); 118 if (fControlsMenu) 119 fFileMenuBar->AddItem(fControlsMenu); 181 120 182 121 // File Panels 183 BWindow 122 BWindow* change_title; 184 123 185 saveConsoleFilePanel = new BFilePanel( 186 B_SAVE_PANEL, 187 new BMessenger(this), 188 NULL, 189 B_FILE_NODE, 190 false, 191 new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE) 192 ); 193 change_title = saveConsoleFilePanel->Window(); 124 fSaveConsoleFilePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), 125 NULL, B_FILE_NODE, false, 126 new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE)); 127 change_title = fSaveConsoleFilePanel->Window(); 194 128 change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE); 195 129 196 saveConsoleSelectionFilePanel = new BFilePanel( 197 B_SAVE_PANEL, 198 new BMessenger(this), 199 NULL, 200 B_FILE_NODE, 201 false, 202 new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION) 203 ); 204 change_title = saveConsoleSelectionFilePanel->Window(); 130 fSaveConsoleSelectionFilePanel = new BFilePanel(B_SAVE_PANEL, 131 new BMessenger(this), NULL, B_FILE_NODE, false, 132 new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION)); 133 change_title = fSaveConsoleSelectionFilePanel->Window(); 205 134 change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE_SELECTION); 206 135 136 AddChild(BGroupLayoutBuilder(B_VERTICAL) 137 .Add(fFileMenuBar) 138 .Add(BGroupLayoutBuilder(B_VERTICAL, 5) 139 .Add(BGroupLayoutBuilder(B_HORIZONTAL) 140 .Add(fStatusView) 141 .AddGlue() 142 .Add(fHitsView)) 143 .Add(BGroupLayoutBuilder(B_HORIZONTAL) 144 .Add(fDirView) 145 .AddGlue()) 146 .Add(fScrollView) 147 .SetInsets(10, 10, 10, 10))); 207 148 208 AddChild(FileMenuBar);209 210 149 pthread_rwlock_init(&fLogFileLock, NULL); 211 150 } 212 151 152 213 153 PoorManWindow::~PoorManWindow() 214 154 { 215 155 delete fServer; 216 delete fLogViewFont;217 156 delete fLogFile; 218 157 pthread_rwlock_destroy(&fLogFileLock); 219 158 } 220 159 160 221 161 void 222 162 PoorManWindow::MessageReceived(BMessage* message) 223 163 { 224 164 switch (message->what) { 225 case MSG_MENU_FILE_SAVE_AS: 226 saveConsoleFilePanel->Show(); 227 break; 228 case MSG_FILE_PANEL_SAVE_CONSOLE: 229 printf("FilePanel: Save Console\n"); 230 SaveConsole(message, false); 231 break; 232 case MSG_MENU_FILE_SAVE_SELECTION: 233 saveConsoleSelectionFilePanel->Show(); 234 break; 235 case MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION: 236 printf("FilePanel: Save Console Selection\n"); 237 SaveConsole(message, true); 238 break; 239 case MSG_MENU_EDIT_PREF: 240 prefWindow = new PoorManPreferencesWindow( 241 setwindow_frame, 242 STR_WIN_NAME_PREF 243 ); 244 break; 245 case MSG_MENU_CTRL_RUN: 246 if(status) 247 StopServer(); 248 else 249 StartServer(); 250 break; 251 case MSG_MENU_CTRL_CLEAR_HIT: 252 SetHits(0); 253 //UpdateHitsLabel(); 254 break; 255 case MSG_MENU_CTRL_CLEAR_CONSOLE: 256 loggingView->SelectAll(); 257 loggingView->Delete(); 258 break; 259 case MSG_MENU_CTRL_CLEAR_LOG: 260 FILE * f; 261 f = fopen(log_path.String(), "w"); 262 fclose(f); 263 break; 264 case MSG_LOG: 265 { 266 if(!log_console_flag && !log_file_flag) 267 break; 165 case MSG_MENU_FILE_SAVE_AS: 166 fSaveConsoleFilePanel->Show(); 167 break; 168 169 case MSG_FILE_PANEL_SAVE_CONSOLE: 170 printf("FilePanel: Save Console\n"); 171 SaveConsole(message, false); 172 break; 173 174 case MSG_MENU_FILE_SAVE_SELECTION: 175 fSaveConsoleSelectionFilePanel->Show(); 176 break; 177 178 case MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION: 179 printf("FilePanel: Save Console Selection\n"); 180 SaveConsole(message, true); 181 break; 182 183 case MSG_MENU_EDIT_PREF: 184 fPrefWindow = new PoorManPreferencesWindow(fSetwindowFrame, 185 STR_WIN_NAME_PREF); 186 break; 187 188 case MSG_MENU_CTRL_RUN: 189 if(fStatus) 190 StopServer(); 191 else 192 StartServer(); 193 break; 194 195 case MSG_MENU_CTRL_CLEAR_HIT: 196 SetHits(0); 197 //UpdateHitsLabel(); 198 break; 199 200 case MSG_MENU_CTRL_CLEAR_CONSOLE: 201 fLoggingView->SelectAll(); 202 fLoggingView->Delete(); 203 break; 204 205 case MSG_MENU_CTRL_CLEAR_LOG: 206 FILE * f; 207 f = fopen(fLogPath.String(), "w"); 208 fclose(f); 209 break; 210 211 case MSG_LOG: 212 { 213 if (!fLogConsoleFlag && !fLogFileFlag) 214 break; 268 215 269 time_t time;270 in_addr_t address;271 rgb_color color;272 const void* pointer;273 ssize_t size;274 const char* msg;275 BString line;216 time_t time; 217 in_addr_t address; 218 rgb_color color; 219 const void* pointer; 220 ssize_t size; 221 const char* msg; 222 BString line; 276 223 277 if(message->FindString("cstring", &msg) != B_OK) 278 break; 279 if(message->FindData("time_t", B_TIME_TYPE, &pointer, &size) != B_OK) 280 time = -1; 281 else 282 time = *static_cast<const time_t*>(pointer); 283 if(message->FindData("in_addr_t", B_ANY_TYPE, &pointer, &size) != B_OK) 284 address = INADDR_NONE; 285 else 286 address = *static_cast<const in_addr_t*>(pointer); 287 if(message->FindData("rgb_color", B_RGB_COLOR_TYPE, &pointer, &size) != B_OK) 288 color = BLACK; 289 else 290 color = *static_cast<const rgb_color*>(pointer); 224 if (message->FindString("cstring", &msg) != B_OK) 225 break; 226 227 if (message->FindData("time_t", B_TIME_TYPE, &pointer, &size) != B_OK) 228 time = -1; 229 else 230 time = *static_cast<const time_t*>(pointer); 231 232 if (message->FindData("in_addr_t", B_ANY_TYPE, &pointer, &size) != B_OK) 233 address = INADDR_NONE; 234 else 235 address = *static_cast<const in_addr_t*>(pointer); 236 237 if (message->FindData("rgb_color", B_RGB_COLOR_TYPE, &pointer, &size) != B_OK) 238 color = BLACK; 239 else 240 color = *static_cast<const rgb_color*>(pointer); 291 241 292 if(time != -1){ 293 char timeString[26]; 294 if(ctime_r(&time, timeString) != NULL){ 295 timeString[24] = '\0'; 296 line << '[' << timeString << "]: "; 242 if (time != -1) { 243 char timeString[26]; 244 if (ctime_r(&time, timeString) != NULL) { 245 timeString[24] = '\0'; 246 line << '[' << timeString << "]: "; 247 } 297 248 } 298 }299 249 300 if(address != INADDR_NONE){ 301 char addr[INET_ADDRSTRLEN]; 302 struct in_addr sin_addr; 303 sin_addr.s_addr = address; 304 if(inet_ntop(AF_INET, &sin_addr, addr, sizeof(addr)) != NULL){ 305 addr[strlen(addr)] = '\0'; 306 line << '(' << addr << ") "; 250 if(address != INADDR_NONE){ 251 char addr[INET_ADDRSTRLEN]; 252 struct in_addr sin_addr; 253 sin_addr.s_addr = address; 254 if (inet_ntop(AF_INET, &sin_addr, addr, sizeof(addr)) != NULL) { 255 addr[strlen(addr)] = '\0'; 256 line << '(' << addr << ") "; 257 } 307 258 } 308 }309 259 310 line << msg; 260 line << msg; 261 262 text_run run; 263 text_run_array runs; 311 264 312 text_run run; 313 text_run_array runs; 265 run.offset = 0; 266 run.font = be_plain_font; 267 run.color = color; 314 268 315 run.offset = 0; 316 run.font = *fLogViewFont; 317 run.color = color; 269 runs.count = 1; 270 runs.runs[0] = run; 318 271 319 runs.count = 1; 320 runs.runs[0] = run; 272 if (Lock()) { 273 if(fLogConsoleFlag) { 274 fLoggingView->Insert(fLoggingView->TextLength(), 275 line.String(), line.Length(), &runs); 276 fLoggingView->ScrollToOffset(fLoggingView->TextLength()); 277 } 321 278 322 if(Lock()){ 323 if(log_console_flag){ 324 loggingView->Insert(loggingView->TextLength(), 325 line.String(), line.Length(), &runs); 326 loggingView->ScrollToOffset(loggingView->TextLength()); 327 } 328 329 if(log_file_flag){ 330 if(pthread_rwlock_rdlock(&fLogFileLock) == 0){ 331 fLogFile->Write(line.String(), line.Length()); 332 pthread_rwlock_unlock(&fLogFileLock); 279 if (fLogFileFlag) { 280 if (pthread_rwlock_rdlock(&fLogFileLock) == 0) { 281 fLogFile->Write(line.String(), line.Length()); 282 pthread_rwlock_unlock(&fLogFileLock); 283 } 333 284 } 334 }335 285 336 Unlock(); 286 Unlock(); 287 } 288 289 break; 337 290 } 338 291 339 break; 292 default: 293 BWindow::MessageReceived(message); 294 break; 340 295 } 341 default:342 BWindow::MessageReceived(message);343 break;344 }345 296 } 346 297 347 298 void 348 299 PoorManWindow::FrameMoved(BPoint origin) 349 300 { 350 f rame.left = origin.x;351 f rame.top = origin.y;301 fFrame.left = origin.x; 302 fFrame.top = origin.y; 352 303 } 353 304 354 305 void 355 306 PoorManWindow::FrameResized(float width, float height) 356 307 { 357 if (is_zoomed) 358 { 359 last_width = width; 360 last_height = height; 308 if (fIsZoomed) { 309 fLastWidth = width; 310 fLastHeight = height; 361 311 } 362 312 } 363 313 364 314 bool 365 315 PoorManWindow::QuitRequested() 366 316 { 367 if (status){317 if (fStatus) { 368 318 time_t now = time(NULL); 369 319 char line[] = "[Thu Jan 1 00:00:00 1970]: Shutting down.\n"; 370 320 … … 372 322 line[25] = ']'; 373 323 line[26] = ' '; 374 324 375 if (log_console_flag){376 loggingView->Insert(loggingView->TextLength(),377 378 loggingView->ScrollToOffset(loggingView->TextLength());325 if (fLogConsoleFlag) { 326 fLoggingView->Insert(fLoggingView->TextLength(), 327 line, strlen(line)); 328 fLoggingView->ScrollToOffset(fLoggingView->TextLength()); 379 329 } 380 330 381 if (log_file_flag){382 if (pthread_rwlock_rdlock(&fLogFileLock) == 0){383 384 331 if (fLogFileFlag) { 332 if (pthread_rwlock_rdlock(&fLogFileLock) == 0) { 333 fLogFile->Write(line, strlen(line)); 334 pthread_rwlock_unlock(&fLogFileLock); 385 335 } 386 336 } 387 337 388 338 fServer->Stop(); 389 status = false;339 fStatus = false; 390 340 UpdateStatusLabelAndMenuItem(); 391 341 } 392 342 … … 398 348 void 399 349 PoorManWindow::Zoom(BPoint origin, float width, float height) 400 350 { 401 if ( is_zoomed)402 {// Change to the Minimal size403 is_zoomed = false;351 if (fIsZoomed) { 352 // Change to the Minimal size 353 fIsZoomed = false; 404 354 ResizeTo(318, 53); 355 } else { 356 // Change to the Zoomed size 357 fIsZoomed = true; 358 ResizeTo(fLastWidth, fLastHeight); 405 359 } 406 else407 { // Change to the Zoomed size408 is_zoomed = true;409 ResizeTo(last_width, last_height);410 }411 360 } 412 361 413 362 void 414 363 PoorManWindow::SetHits(uint32 num) 415 364 { 416 hits = num;365 fHits = num; 417 366 UpdateHitsLabel(); 418 367 } 419 368 420 369 // Private: Methods ------------------------------------------ 421 370 422 BMenu 423 PoorManWindow::Build FileMenu() const371 BMenu* 372 PoorManWindow::BuildfFileMenu() const 424 373 { 425 BMenu * ptrFileMenu = new BMenu(STR_MNU_FILE);374 BMenu* ptrfFileMenu = new BMenu(STR_MNU_FILE); 426 375 427 ptr FileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_AS,376 ptrfFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_AS, 428 377 new BMessage(MSG_MENU_FILE_SAVE_AS), CMD_FILE_SAVE_AS)); 429 378 430 ptr FileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_SELECTION,379 ptrfFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_SELECTION, 431 380 new BMessage(MSG_MENU_FILE_SAVE_SELECTION))); 432 381 433 ptr FileMenu->AddSeparatorItem();382 ptrfFileMenu->AddSeparatorItem(); 434 383 435 384 // about box 436 BMenuItem 385 BMenuItem* AboutItem = new BMenuItem(STR_MNU_FILE_ABOUT, 437 386 new BMessage(B_ABOUT_REQUESTED)); 438 387 AboutItem->SetTarget(NULL, be_app); 439 ptr FileMenu->AddItem(AboutItem);388 ptrfFileMenu->AddItem(AboutItem); 440 389 441 ptr FileMenu->AddSeparatorItem();390 ptrfFileMenu->AddSeparatorItem(); 442 391 443 392 444 ptr FileMenu->AddItem(new BMenuItem(STR_MNU_FILE_QUIT,393 ptrfFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_QUIT, 445 394 new BMessage(B_QUIT_REQUESTED), CMD_FILE_QUIT)); 446 395 447 return ptr FileMenu;396 return ptrfFileMenu; 448 397 } 449 398 450 BMenu *399 BMenu* 451 400 PoorManWindow::BuildEditMenu() const 452 401 { 453 BMenu 402 BMenu* ptrEditMenu = new BMenu(STR_MNU_EDIT); 454 403 455 BMenuItem 404 BMenuItem* CopyMenuItem = new BMenuItem(STR_MNU_EDIT_COPY, 456 405 new BMessage(B_COPY), CMD_EDIT_COPY); 457 406 458 407 ptrEditMenu->AddItem(CopyMenuItem); 459 CopyMenuItem->SetTarget( loggingView, NULL);408 CopyMenuItem->SetTarget(fLoggingView, NULL); 460 409 461 410 ptrEditMenu->AddSeparatorItem(); 462 411 463 BMenuItem 412 BMenuItem* SelectAllMenuItem = new BMenuItem(STR_MNU_EDIT_SELECT_ALL, 464 413 new BMessage(B_SELECT_ALL), CMD_EDIT_SELECT_ALL); 465 414 466 415 ptrEditMenu->AddItem(SelectAllMenuItem); 467 SelectAllMenuItem->SetTarget( loggingView, NULL);416 SelectAllMenuItem->SetTarget(fLoggingView, NULL); 468 417 469 418 ptrEditMenu->AddSeparatorItem(); 470 419 471 BMenuItem 420 BMenuItem* PrefMenuItem = new BMenuItem(STR_MNU_EDIT_PREF, 472 421 new BMessage(MSG_MENU_EDIT_PREF)); 473 422 ptrEditMenu->AddItem(PrefMenuItem); 474 423 475 424 return ptrEditMenu; 476 425 } 477 426 478 BMenu *427 BMenu* 479 428 PoorManWindow::BuildControlsMenu() const 480 429 { 481 BMenu 430 BMenu* ptrControlMenu = new BMenu(STR_MNU_CTRL); 482 431 483 BMenuItem 432 BMenuItem* RunServerMenuItem = new BMenuItem(STR_MNU_CTRL_RUN_SERVER, 484 433 new BMessage(MSG_MENU_CTRL_RUN)); 485 434 RunServerMenuItem->SetMarked(false); 486 435 ptrControlMenu->AddItem(RunServerMenuItem); 487 436 488 BMenuItem 437 BMenuItem* ClearHitCounterMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_HIT_COUNTER, 489 438 new BMessage(MSG_MENU_CTRL_CLEAR_HIT)); 490 439 ptrControlMenu->AddItem(ClearHitCounterMenuItem); 491 440 492 441 ptrControlMenu->AddSeparatorItem(); 493 442 494 BMenuItem 443 BMenuItem* ClearConsoleLogMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_CONSOLE, 495 444 new BMessage(MSG_MENU_CTRL_CLEAR_CONSOLE)); 496 445 ptrControlMenu->AddItem(ClearConsoleLogMenuItem); 497 446 498 BMenuItem * ClearLogFileMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_LOG_FILE,447 BMenuItem* ClearLogfFileMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_LOG_FILE, 499 448 new BMessage(MSG_MENU_CTRL_CLEAR_LOG)); 500 ptrControlMenu->AddItem(ClearLog FileMenuItem);449 ptrControlMenu->AddItem(ClearLogfFileMenuItem); 501 450 502 451 return ptrControlMenu; 503 452 } 504 453 505 454 void 506 PoorManWindow::SetDirLabel(const char 455 PoorManWindow::SetDirLabel(const char* name) 507 456 { 508 457 BString dirPath("Directory: "); 509 458 dirPath.Append(name); 510 459 511 if (Lock()) 512 { 513 dirView->SetText(dirPath.String()); 460 if (Lock()) { 461 fDirView->SetText(dirPath.String()); 514 462 Unlock(); 515 463 } 516 464 } … … 518 466 void 519 467 PoorManWindow::UpdateStatusLabelAndMenuItem() 520 468 { 521 if (Lock()) 522 { 523 if (status) 524 statusView->SetText("Status: Running"); 469 if (Lock()) { 470 if (fStatus) 471 fStatusView->SetText("Status: Running"); 525 472 else 526 statusView->SetText("Status: Stopped");527 ControlsMenu->FindItem(STR_MNU_CTRL_RUN_SERVER)->SetMarked(status);473 fStatusView->SetText("Status: Stopped"); 474 fControlsMenu->FindItem(STR_MNU_CTRL_RUN_SERVER)->SetMarked(fStatus); 528 475 Unlock(); 529 476 } 530 477 } … … 532 479 void 533 480 PoorManWindow::UpdateHitsLabel() 534 481 { 535 if (Lock()) 536 { 537 sprintf(hitsLabel, "Hits: %lu", GetHits()); 538 hitsView->SetText(hitsLabel); 482 if (Lock()) { 483 sprintf(fHitsLabel, "Hits: %lu", GetHits()); 484 fHitsView->SetText(fHitsLabel); 539 485 540 486 Unlock(); 541 487 } 542 488 } 543 489 544 490 status_t 545 PoorManWindow::SaveConsole(BMessage 491 PoorManWindow::SaveConsole(BMessage* message, bool selection) 546 492 { 547 493 entry_ref ref; 548 const char 494 const char* name; 549 495 BPath path; 550 496 BEntry entry; 551 497 status_t err = B_OK; 552 FILE *f;498 FILE* f; 553 499 554 if ((err = message->FindRef("directory", &ref)) != B_OK) 500 err = message->FindRef("directory", &ref); 501 if (err != B_OK) 555 502 return err; 556 557 if ((err = message->FindString("name", &name)) != B_OK) 503 504 err = message->FindString("name", &name); 505 if (err != B_OK) 558 506 return err; 559 560 if ((err = entry.SetTo(&ref)) != B_OK) 507 508 err = entry.SetTo(&ref); 509 if (err != B_OK) 561 510 return err; 562 511 563 512 entry.GetPath(&path); … … 566 515 if (!(f = fopen(path.Path(), "w"))) 567 516 return B_ERROR; 568 517 569 if (!selection) 570 { 518 if (!selection) { 571 519 // write the data to the file 572 err = fwrite( loggingView->Text(), 1, loggingView->TextLength(), f);520 err = fwrite(fLoggingView->Text(), 1, fLoggingView->TextLength(), f); 573 521 } else { 574 522 // find the selected text and write it to a file 575 523 int32 start = 0, end = 0; 576 loggingView->GetSelection(&start, &end);524 fLoggingView->GetSelection(&start, &end); 577 525 578 526 BString buffer; 579 char 527 char* buffData = buffer.LockBuffer(end - start + 1); 580 528 // copy the selected text from the TextView to the buffer 581 loggingView->GetText(start, end - start, buffData);529 fLoggingView->GetText(start, end - start, buffData); 582 530 buffer.UnlockBuffer(end - start + 1); 583 531 584 532 err = fwrite(buffer.String(), 1, end - start + 1, f); 585 533 } 534 586 535 fclose(f); 587 536 588 537 return err; … … 599 548 int32 buttonIndex = dirAlert->Go(); 600 549 601 550 switch (buttonIndex){ 602 case 0: 603 serverAlert->Go(); 604 SetWebDir(""); 605 break; 606 case 1: 607 prefWindow = new PoorManPreferencesWindow( 608 setwindow_frame, 609 STR_WIN_NAME_PREF 610 ); 611 serverAlert->Go(); 612 prefWindow->ShowWebDirFilePanel(); 613 break; 614 case 2: 615 if(create_directory(STR_DEFAULT_WEB_DIRECTORY, 0755) != B_OK){ 551 case 0: 616 552 serverAlert->Go(); 617 553 SetWebDir(""); 618 554 break; 619 } 620 BAlert* dirCreatedAlert = 621 new BAlert("Dir Created",STR_DIR_CREATED,"OK"); 622 dirCreatedAlert->Go(); 623 SetWebDir(STR_DEFAULT_WEB_DIRECTORY); 624 break; 555 556 case 1: 557 fPrefWindow = new PoorManPreferencesWindow(fSetwindowFrame, 558 STR_WIN_NAME_PREF); 559 serverAlert->Go(); 560 fPrefWindow->ShowWebDirFilePanel(); 561 break; 562 563 case 2: 564 if (create_directory(STR_DEFAULT_WEB_DIRECTORY, 0755) != B_OK) { 565 serverAlert->Go(); 566 SetWebDir(""); 567 break; 568 } 569 BAlert* dirCreatedAlert = new BAlert("Dir Created", 570 STR_DIR_CREATED,"OK"); 571 dirCreatedAlert->Go(); 572 SetWebDir(STR_DEFAULT_WEB_DIRECTORY); 573 break; 625 574 } 626 575 } 627 576 … … 632 581 BFile f; 633 582 BMessage m; 634 583 635 if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK)584 if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK) 636 585 return B_ERROR; 637 586 p.Append(STR_SETTINGS_FILE_NAME); 638 587 639 588 f.SetTo(p.Path(), B_READ_ONLY); 640 if (f.InitCheck()!=B_OK)589 if (f.InitCheck()!= B_OK) 641 590 return B_ERROR; 642 591 643 if (m.Unflatten(&f)!=B_OK)592 if (m.Unflatten(&f)!= B_OK) 644 593 return B_ERROR; 645 594 646 if (MSG_PREF_FILE != m.what)595 if (MSG_PREF_FILE != m.what) 647 596 return B_ERROR; 648 597 649 598 //site tab 650 if (m.FindString("web_directory", &web_directory) != B_OK)651 web_directory.SetTo(STR_DEFAULT_WEB_DIRECTORY);652 if (m.FindString("index_file_name", &index_file_name) != B_OK)653 index_file_name.SetTo("index.html");654 if (m.FindBool("dir_list_flag", &dir_list_flag) != B_OK)655 dir_list_flag = false;599 if (m.FindString("web_directory", &fWebDirectory) != B_OK) 600 fWebDirectory.SetTo(STR_DEFAULT_WEB_DIRECTORY); 601 if (m.FindString("index_file_name", &fIndexFileName) != B_OK) 602 fIndexFileName.SetTo("index.html"); 603 if (m.FindBool("dir_list_flag", &fDirListFlag) != B_OK) 604 fDirListFlag = false; 656 605 657 606 //logging tab 658 if (m.FindBool("log_console_flag", &log_console_flag) != B_OK)659 log_console_flag = true;660 if (m.FindBool("log_file_flag", &log_file_flag) != B_OK)661 log_file_flag = false;662 if (m.FindString("log_path", &log_path) != B_OK)663 log_path.SetTo("");607 if (m.FindBool("log_console_flag", &fLogConsoleFlag) != B_OK) 608 fLogConsoleFlag = true; 609 if (m.FindBool("log_file_flag", &fLogFileFlag) != B_OK) 610 fLogFileFlag = false; 611 if (m.FindString("log_path", &fLogPath) != B_OK) 612 fLogPath.SetTo(""); 664 613 665 614 //advance tab 666 if(m.FindInt16("max_connections", & max_connections) != B_OK)667 max_connections = (int16)32;615 if(m.FindInt16("max_connections", &fMaxConnections) != B_OK) 616 fMaxConnections = (int16)32; 668 617 669 618 //windows' position and size 670 if(m.FindRect("frame", &f rame) != B_OK)671 f rame.Set(82.0f, 30.0f, 400.0f, 350.0f);672 if(m.FindRect("setwindow_frame", & setwindow_frame) != B_OK)673 setwindow_frame.Set(112.0f, 60.0f, 492.0f, 340.0f);674 if(m.FindBool("is_zoomed", & is_zoomed) != B_OK)675 is_zoomed = true;676 if(m.FindFloat("last_width", & last_width) != B_OK)677 last_width = 318.0f;678 if(m.FindFloat("last_height", & last_height) != B_OK)679 last_height = 320.0f;619 if(m.FindRect("frame", &fFrame) != B_OK) 620 fFrame.Set(82.0f, 30.0f, 400.0f, 350.0f); 621 if(m.FindRect("setwindow_frame", &fSetwindowFrame) != B_OK) 622 fSetwindowFrame.Set(112.0f, 60.0f, 492.0f, 340.0f); 623 if(m.FindBool("is_zoomed", &fIsZoomed) != B_OK) 624 fIsZoomed = true; 625 if(m.FindFloat("last_width", &fLastWidth) != B_OK) 626 fLastWidth = 318.0f; 627 if(m.FindFloat("last_height", &fLastHeight) != B_OK) 628 fLastHeight = 320.0f; 680 629 681 is_zoomed?ResizeTo(last_width, last_height):ResizeTo(318, 53);682 MoveTo(f rame.left, frame.top);630 fIsZoomed ? ResizeTo(fLastWidth, fLastHeight) : ResizeTo(318, 53); 631 MoveTo(fFrame.left, fFrame.top); 683 632 684 fLogFile = new BFile(log_path.String(), B_CREATE_FILE|B_WRITE_ONLY|B_OPEN_AT_END); 633 fLogFile = new BFile(fLogPath.String(), 634 B_CREATE_FILE|B_WRITE_ONLY | B_OPEN_AT_END); 685 635 if(fLogFile->InitCheck() != B_OK){ 686 log_file_flag = false;636 fLogFileFlag = false; 687 637 //log it to console, "log to file unavailable." 688 638 return B_OK; 689 639 } 690 640 691 SetDirLabel( web_directory.String());641 SetDirLabel(fWebDirectory.String()); 692 642 693 643 return B_OK; 694 644 } … … 701 651 BMessage m(MSG_PREF_FILE); 702 652 703 653 //site tab 704 m.AddString("web_directory", web_directory);705 m.AddString("index_file_name", index_file_name);706 m.AddBool("dir_list_flag", dir_list_flag);654 m.AddString("web_directory", fWebDirectory); 655 m.AddString("index_file_name", fIndexFileName); 656 m.AddBool("dir_list_flag", fDirListFlag); 707 657 708 658 //logging tab 709 m.AddBool("log_console_flag", log_console_flag);710 m.AddBool("log_file_flag", log_file_flag);711 m.AddString("log_path", log_path);659 m.AddBool("log_console_flag", fLogConsoleFlag); 660 m.AddBool("log_file_flag", fLogFileFlag); 661 m.AddString("log_path", fLogPath); 712 662 713 663 //advance tab 714 m.AddInt16("max_connections", max_connections);664 m.AddInt16("max_connections", fMaxConnections); 715 665 716 666 //windows' position and size 717 m.AddRect("frame", f rame);718 m.AddRect("setwindow_frame", setwindow_frame);719 m.AddBool("is_zoomed", is_zoomed);720 m.AddFloat("last_width", last_width);721 m.AddFloat("last_height", last_height);667 m.AddRect("frame", fFrame); 668 m.AddRect("setwindow_frame", fSetwindowFrame); 669 m.AddBool("is_zoomed", fIsZoomed); 670 m.AddFloat("last_width", fLastWidth); 671 m.AddFloat("last_height", fLastHeight); 722 672 723 if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK)673 if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK) 724 674 return B_ERROR; 725 675 p.Append(STR_SETTINGS_FILE_NAME); 726 676 727 677 f.SetTo(p.Path(), B_WRITE_ONLY| B_ERASE_FILE| B_CREATE_FILE); 728 if (f.InitCheck()!=B_OK)678 if (f.InitCheck()!= B_OK) 729 679 return B_ERROR; 730 680 731 if(m.Flatten(&f)!= B_OK)681 if(m.Flatten(&f)!= B_OK) 732 682 return B_ERROR; 733 683 734 684 return B_OK; … … 737 687 status_t 738 688 PoorManWindow::StartServer() 739 689 { 740 if(NULL == fServer) 741 fServer = new PoorManServer( 742 web_directory.String(), 743 max_connections, 744 dir_list_flag, 745 index_file_name.String() 746 ); 690 if(fServer == NULL) 691 fServer = new PoorManServer(fWebDirectory.String(), fMaxConnections, 692 fDirListFlag, fIndexFileName.String()); 747 693 748 694 poorman_log("Starting up... "); 749 if (fServer->Run() != B_OK){695 if (fServer->Run() != B_OK) { 750 696 return B_ERROR; 751 697 } 752 698 753 status = true;699 fStatus = true; 754 700 UpdateStatusLabelAndMenuItem(); 755 701 poorman_log("done.\n", false, INADDR_NONE, GREEN); 756 702 … … 760 706 status_t 761 707 PoorManWindow::StopServer() 762 708 { 763 if( NULL == fServer)709 if(fServer == NULL) 764 710 return B_ERROR; 765 711 766 712 poorman_log("Shutting down.\n"); 767 713 fServer->Stop(); 768 status = false;714 fStatus = false; 769 715 UpdateStatusLabelAndMenuItem(); 770 716 return B_OK; 771 717 } … … 773 719 void 774 720 PoorManWindow::SetLogPath(const char* str) 775 721 { 776 if (log_path == str)722 if (fLogPath == str) 777 723 return; 778 724 779 BFile* temp = new BFile(str, B_CREATE_FILE |B_WRITE_ONLY|B_OPEN_AT_END);725 BFile* temp = new BFile(str, B_CREATE_FILE | B_WRITE_ONLY | B_OPEN_AT_END); 780 726 781 if (temp->InitCheck() != B_OK){727 if (temp->InitCheck() != B_OK) { 782 728 delete temp; 783 729 return; 784 730 } 785 731 786 if (pthread_rwlock_wrlock(&fLogFileLock) == 0){732 if (pthread_rwlock_wrlock(&fLogFileLock) == 0) { 787 733 delete fLogFile; 788 734 fLogFile = temp; 789 735 pthread_rwlock_unlock(&fLogFileLock); … … 792 738 return; 793 739 } 794 740 795 log_path.SetTo(str);741 fLogPath.SetTo(str); 796 742 } -
src/apps/poorman/PoorManView.cpp
10 10 #endif 11 11 12 12 PoorManView::PoorManView(BRect rect, char *name) 13 : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW ) 13 : 14 BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) 14 15 { 15 16 } 16 17 -
src/apps/poorman/PoorManWindow.h
33 33 class PoorManWindow: public BWindow 34 34 { 35 35 public: 36 PoorManWindow(BRect frame);37 virtual~PoorManWindow();38 virtual void MessageReceived(BMessage* message);36 PoorManWindow(BRect frame); 37 virtual ~PoorManWindow(); 38 virtual void MessageReceived(BMessage* message); 39 39 40 virtual voidFrameMoved(BPoint origin);41 virtual voidFrameResized(float width, float height);42 virtual boolQuitRequested();43 virtual voidZoom(BPoint origin, float width, float height);40 virtual void FrameMoved(BPoint origin); 41 virtual void FrameResized(float width, float height); 42 virtual bool QuitRequested(); 43 virtual void Zoom(BPoint origin, float width, float height); 44 44 45 45 // ------------------------------------------- 46 46 // Public PoorMan Window Methods 47 void SetDirLabel(const char* name);48 voidSetHits(uint32 num);49 uint32 GetHits() { return hits; }50 status_t SaveConsole(BMessage* message, bool);47 void SetDirLabel(const char* name); 48 void SetHits(uint32 num); 49 uint32 GetHits() { return fHits; } 50 status_t SaveConsole(BMessage* message, bool); 51 51 52 status_tSaveSettings();53 status_tReadSettings();54 voidDefaultSettings();52 status_t SaveSettings(); 53 status_t ReadSettings(); 54 void DefaultSettings(); 55 55 56 status_tStartServer();57 status_tStopServer();56 status_t StartServer(); 57 status_t StopServer(); 58 58 59 PoorManServer* GetServer()const{return fServer;}59 PoorManServer* GetServer() const { return fServer;} 60 60 // ------------------------------------------- 61 61 // Preferences and Settings 62 62 // Site Tab 63 bool DirListFlag() { return dir_list_flag; } 64 void SetDirListFlag(bool flag) { dir_list_flag = flag; } 65 const char * IndexFileName() { return index_file_name.String(); } 66 void SetIndexFileName(const char * str) { index_file_name.SetTo(str); } 67 const char * WebDir() { return web_directory.String(); } 68 void SetWebDir(const char * str) { web_directory.SetTo(str); } 63 bool DirListFlag() 64 { return fDirListFlag; } 65 void SetDirListFlag(bool flag) 66 { fDirListFlag = flag; } 67 const char* IndexFileName() 68 { return fIndexFileName.String(); } 69 void SetIndexFileName(const char* str) 70 { fIndexFileName.SetTo(str); } 71 const char* WebDir() 72 { return fWebDirectory.String(); } 73 void SetWebDir(const char* str) 74 { fWebDirectory.SetTo(str); } 69 75 // Logging Tab 70 bool LogConsoleFlag() { return log_console_flag; } 71 void SetLogConsoleFlag(bool flag) { log_console_flag = flag; } 72 bool LogFileFlag() { return log_file_flag; } 73 void SetLogFileFlag(bool flag) { log_file_flag = flag; } 74 const char * LogPath() { return log_path.String(); } 75 void SetLogPath(const char * str); 76 bool LogConsoleFlag() 77 { return fLogConsoleFlag; } 78 void SetLogConsoleFlag(bool flag) 79 { fLogConsoleFlag = flag; } 80 bool LogFileFlag() 81 { return fLogFileFlag; } 82 void SetLogFileFlag(bool flag) 83 { fLogFileFlag = flag; } 84 const char* LogPath() 85 { return fLogPath.String(); } 86 void SetLogPath(const char* str); 76 87 // Advanced Tab 77 int16 MaxConnections() { return max_connections; } 78 void SetMaxConnections(int16 num) { max_connections = num; } 88 int16 MaxConnections() 89 { return fMaxConnections; } 90 void SetMaxConnections(int16 num) 91 { fMaxConnections = num; } 79 92 80 81 93 private: 82 94 // ------------------------------------------- 83 95 // PoorMan Window Methods 84 voidUpdateStatusLabelAndMenuItem();85 voidUpdateHitsLabel();96 void UpdateStatusLabelAndMenuItem(); 97 void UpdateHitsLabel(); 86 98 87 99 private: 88 100 // ------------------------------------------- 89 // PoorMan Window90 PoorManView * mainView;91 92 // -------------------------------------------93 101 // Build Menu Methods 94 BMenu * BuildFileMenu() const;95 BMenu *BuildEditMenu() const;96 BMenu *BuildControlsMenu() const;102 BMenu* BuildfFileMenu() const; 103 BMenu* BuildEditMenu() const; 104 BMenu* BuildControlsMenu() const; 97 105 98 106 // -------------------------------------------- 99 107 // MenuBar & Menu items 100 BMenuBar *FileMenuBar;101 BMenu *FileMenu;102 BMenu *EditMenu;103 BMenu *ControlsMenu;108 BMenuBar* fFileMenuBar; 109 BMenu* fFileMenu; 110 BMenu* fEditMenu; 111 BMenu* fControlsMenu; 104 112 105 113 // -------------------------------------------- 106 114 // Status, Hits, Directory 107 BStringView * statusView;108 BStringView * hitsView;109 BStringView * dirView;115 BStringView* fStatusView; 116 BStringView* fHitsView; 117 BStringView* fDirView; 110 118 111 bool status;112 uint32 hits;113 char hitsLabel[25];119 bool fStatus; 120 uint32 fHits; 121 char fHitsLabel[25]; 114 122 115 123 // -------------------------------------------- 116 124 // Logging View 117 BScrollView * scrollView;118 BTextView * loggingView;125 BScrollView* fScrollView; 126 BTextView* fLoggingView; 119 127 // use asctime() for format of [Date/Time]: 120 128 121 129 122 130 // ------------------------------------------- 123 131 // PoorMan Preference Window 124 PoorManPreferencesWindow * prefWindow;132 PoorManPreferencesWindow * fPrefWindow; 125 133 126 134 // site tab 127 BString web_directory;128 BString index_file_name;129 bool dir_list_flag;135 BString fWebDirectory; 136 BString fIndexFileName; 137 bool fDirListFlag; 130 138 131 139 // logging tab 132 bool log_console_flag;133 bool log_file_flag;134 BString log_path;140 bool fLogConsoleFlag; 141 bool fLogFileFlag; 142 BString fLogPath; 135 143 136 144 // advanced tab 137 int16 max_connections;145 int16 fMaxConnections; 138 146 139 bool is_zoomed;140 float last_width;141 float last_height;142 BRect frame;143 BRect setwindow_frame;147 bool fIsZoomed; 148 float fLastWidth; 149 float fLastHeight; 150 BRect fFrame; 151 BRect fSetwindowFrame; 144 152 145 153 // File Panels 146 BFilePanel * saveConsoleFilePanel;147 BFilePanel * saveConsoleSelectionFilePanel;154 BFilePanel* fSaveConsoleFilePanel; 155 BFilePanel* fSaveConsoleSelectionFilePanel; 148 156 149 BFile* fLogFile; 150 BFont* fLogViewFont; 157 BFile* fLogFile; 151 158 152 PoorManServer*fServer;159 PoorManServer* fServer; 153 160 154 pthread_rwlock_t fLogFileLock;161 pthread_rwlock_t fLogFileLock; 155 162 }; 156 163 157 164 #endif -
src/apps/poorman/PoorManView.h
12 12 #include <View.h> 13 13 #endif 14 14 15 class PoorManView: public BView 16 { 15 class PoorManView: public BView { 17 16 public: 18 PoorManView(BRect, char *name); 19 virtual void AttachedToWindow(); 17 PoorManView(BRect, char *name); 18 19 virtual void AttachedToWindow(); 20 20 }; 21 21 22 22 #endif -
src/apps/poorman/PoorManLoggingView.cpp
6 6 */ 7 7 8 8 #include <Box.h> 9 #include <GroupLayoutBuilder.h> 9 10 10 11 #include "constants.h" 11 12 #include "PoorManWindow.h" 12 13 #include "PoorManApplication.h" 13 14 #include "PoorManLoggingView.h" 14 15 15 PoorManLoggingView::PoorManLoggingView(BRect rect, const char *name) 16 : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) 16 PoorManLoggingView::PoorManLoggingView(const char* name) 17 : 18 BView(name, B_WILL_DRAW, NULL) 17 19 { 18 PoorManWindow *win;19 win = ((PoorManApplication 20 PoorManWindow* win; 21 win = ((PoorManApplication*)be_app)->GetPoorManWindow(); 20 22 21 Set ViewColor(BACKGROUND_COLOR);23 SetLayout(new BGroupLayout(B_VERTICAL)); 22 24 23 25 // Console Logging BBox 24 BRect consoleLoggingRect; 25 consoleLoggingRect = rect; 26 consoleLoggingRect.top -= 5.0; 27 consoleLoggingRect.left -= 5.0; 28 consoleLoggingRect.right -= 7.0; 29 consoleLoggingRect.bottom -= 118.0; 30 31 BBox * consoleLogging = new BBox(consoleLoggingRect, "Console Logging"); 26 BBox* consoleLogging = new BBox("Console Logging"); 32 27 consoleLogging->SetLabel(STR_BBX_CONSOLE_LOGGING); 33 AddChild(consoleLogging);34 35 28 36 29 // File Logging BBox 37 BRect fileLoggingRect; 38 fileLoggingRect = consoleLoggingRect; 39 fileLoggingRect.top = consoleLoggingRect.bottom + 10.0; 40 fileLoggingRect.bottom = fileLoggingRect.top + 100.0; 41 42 BBox * fileLogging = new BBox(fileLoggingRect, "File Logging"); 30 BBox* fileLogging = new BBox("File Logging"); 43 31 fileLogging->SetLabel(STR_BBX_FILE_LOGGING); 44 AddChild(fileLogging);45 32 46 float left = 10.0;47 float top = 20.0;48 float box_size = 13.0;49 BRect tempRect(left, top, consoleLoggingRect.Width() - 5.0, top + box_size);50 51 33 // Console Logging 52 logConsole = new BCheckBox(tempRect, "Log To Console", STR_CBX_LOG_CONSOLE, new BMessage(MSG_PREF_LOG_CBX_CONSOLE)); 34 fLogConsole = new BCheckBox("Log To Console", STR_CBX_LOG_CONSOLE, 35 new BMessage(MSG_PREF_LOG_CBX_CONSOLE)); 53 36 // set the checkbox to the value the program has 54 37 SetLogConsoleValue(win->LogConsoleFlag()); 55 consoleLogging->AddChild(logConsole);56 38 57 39 // File Logging 58 logFile = new BCheckBox(tempRect, "Log To File", STR_CBX_LOG_FILE, new BMessage(MSG_PREF_LOG_CBX_FILE)); 40 fLogFile = new BCheckBox("Log To File", STR_CBX_LOG_FILE, 41 new BMessage(MSG_PREF_LOG_CBX_FILE)); 59 42 // set the checkbox to the value the program has 60 43 SetLogFileValue(win->LogFileFlag()); 61 fileLogging->AddChild(logFile);62 44 63 45 // File Name 64 tempRect.top = tempRect.bottom + 10.0; 65 tempRect.bottom = tempRect.top + box_size; 66 tempRect.right -= 5.0; 67 68 logFileName = new BTextControl(tempRect, "File Name", STR_TXT_LOG_FILE_NAME, NULL, NULL); 69 logFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 70 logFileName->SetDivider(73.0); 46 fLogFileName = new BTextControl("File Name", STR_TXT_LOG_FILE_NAME, 47 NULL, NULL); 71 48 SetLogFileName(win->LogPath()); 72 fileLogging->AddChild(logFileName);73 49 74 50 // Create Log File 75 BRect createLogFileRect; 76 createLogFileRect.top = tempRect.bottom + 13.0; 77 createLogFileRect.right = tempRect.right + 2.0; 78 createLogFileRect.left = createLogFileRect.right - 87.0; 79 createLogFileRect.bottom = createLogFileRect.top + 19.0; 80 81 createLogFile = new BButton(createLogFileRect, "Create Log File", STR_BTN_CREATE_LOG_FILE, new BMessage(MSG_PREF_LOG_BTN_CREATE_FILE)); 82 fileLogging->AddChild(createLogFile); 51 fCreateLogFile = new BButton("Create Log File", STR_BTN_CREATE_LOG_FILE, 52 new BMessage(MSG_PREF_LOG_BTN_CREATE_FILE)); 83 53 54 consoleLogging->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 55 .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) 56 .Add(fLogConsole) 57 .AddGlue()) 58 .SetInsets(5, 5, 5, 5)); 59 60 fileLogging->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 61 .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) 62 .Add(fLogFile) 63 .AddGlue()) 64 .Add(fLogFileName) 65 .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) 66 .AddGlue() 67 .Add(fCreateLogFile)) 68 .SetInsets(5, 5, 5, 5)); 69 70 AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 71 .Add(consoleLogging) 72 .Add(fileLogging) 73 .SetInsets(5, 5, 5, 5)); 84 74 } -
src/apps/poorman/PoorManLoggingView.h
14 14 #include <CheckBox.h> 15 15 16 16 17 class PoorManLoggingView: public BView 18 { 17 class PoorManLoggingView: public BView { 19 18 public: 20 PoorManLoggingView(BRect, const char *name);19 PoorManLoggingView(const char* name); 21 20 22 void SetLogConsoleValue(bool state) {if (state) logConsole->SetValue(B_CONTROL_ON); 23 else logConsole->SetValue(B_CONTROL_OFF); } 24 bool LogConsoleValue() { return (logConsole->Value() == B_CONTROL_ON) ? true : false; } 25 void SetLogFileValue(bool state) {if (state) logFile->SetValue(B_CONTROL_ON); 26 else logFile->SetValue(B_CONTROL_OFF); } 27 bool LogFileValue() { return (logFile->Value() == B_CONTROL_ON) ? true : false; } 28 const char * LogFileName() { return logFileName->Text(); } 29 void SetLogFileName(const char * log) { logFileName->SetText(log); } 21 void SetLogConsoleValue(bool state) 22 { if (state) 23 fLogConsole->SetValue(B_CONTROL_ON); 24 else fLogConsole->SetValue(B_CONTROL_OFF); } 25 bool LogConsoleValue() 26 { return (fLogConsole->Value() == B_CONTROL_ON) 27 ? true : false; } 28 void SetLogFileValue(bool state) 29 { if (state) fLogFile->SetValue(B_CONTROL_ON); 30 else fLogFile->SetValue(B_CONTROL_OFF); } 31 bool LogFileValue() 32 { return (fLogFile->Value() == B_CONTROL_ON) 33 ? true : false; } 34 const char* LogFileName() 35 { return fLogFileName->Text(); } 36 void SetLogFileName(const char* log) 37 { fLogFileName->SetText(log); } 38 30 39 private: 31 // Logging Tab 32 40 // Logging Tab 33 41 // Console Logging 34 BCheckBox * logConsole;42 BCheckBox* fLogConsole; 35 43 // File Logging 36 BCheckBox * logFile;37 BTextControl * logFileName;38 BButton * createLogFile;44 BCheckBox* fLogFile; 45 BTextControl* fLogFileName; 46 BButton * fCreateLogFile; 39 47 }; 40 48 41 49 #endif -
src/apps/poorman/PoorManPreferencesWindow.cpp
9 9 #include <Box.h> 10 10 #include <Directory.h> 11 11 #include <Debug.h> 12 #include <GroupLayoutBuilder.h> 13 #include <GroupView.h> 14 #include <SpaceLayoutItem.h> 12 15 13 16 #include "constants.h" 14 17 #include "PoorManWindow.h" … … 16 19 #include "PoorManPreferencesWindow.h" 17 20 #include "PoorManServer.h" 18 21 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) 22 PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char* name) 23 : 24 BWindow(frame, name, B_TITLED_WINDOW, 25 B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS), 26 fWebDirFilePanel(NULL), 27 fLogFilePanel(NULL) 23 28 { 29 SetLayout(new BGroupLayout(B_VERTICAL)); 24 30 25 frame = Bounds(); 31 fCancelButton = new BButton("Cancel Button", "Cancel", 32 new BMessage(MSG_PREF_BTN_CANCEL)); 33 fDoneButton = new BButton("Done Button", "Done", 34 new BMessage(MSG_PREF_BTN_DONE)); 26 35 27 prefView = new PoorManView(frame, STR_WIN_NAME_PREF); 28 //prefView->SetViewColor(216,216,216,255); 29 prefView->SetViewColor(BACKGROUND_COLOR); 30 AddChild(prefView); 36 fPrefTabView = new BTabView("Pref Tab View"); 31 37 32 33 34 // Button View35 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 // Buttons44 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 tabs66 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 38 // Site Tab 80 siteTab = new BTab();81 siteView = new PoorManSiteView(r,"Site View");82 prefTabView->AddTab(siteView, siteTab);83 siteTab->SetLabel(STR_TAB_SITE);39 fSiteTab = new BTab(); 40 fSiteView = new PoorManSiteView("Site View"); 41 fPrefTabView->AddTab(fSiteView, fSiteTab); 42 fSiteTab->SetLabel(STR_TAB_SITE); 84 43 85 44 // Logging Tab 86 loggingTab = new BTab();87 loggingView = new PoorManLoggingView(r,"Logging View");88 prefTabView->AddTab(loggingView, loggingTab);89 loggingTab->SetLabel(STR_TAB_LOGGING);45 fLoggingTab = new BTab(); 46 fLoggingView = new PoorManLoggingView("Logging View"); 47 fPrefTabView->AddTab(fLoggingView, fLoggingTab); 48 fLoggingTab->SetLabel(STR_TAB_LOGGING); 90 49 91 50 // Advanced Tab 92 advancedTab = new BTab();93 advancedView = new PoorManAdvancedView(r,"Advanced View");94 prefTabView->AddTab(advancedView, advancedTab);95 advancedTab->SetLabel(STR_TAB_ADVANCED);51 fAdvancedTab = new BTab(); 52 fAdvancedView = new PoorManAdvancedView("Advanced View"); 53 fPrefTabView->AddTab(fAdvancedView, fAdvancedTab); 54 fAdvancedTab->SetLabel(STR_TAB_ADVANCED); 96 55 97 prefView->AddChild(prefTabView);98 99 56 // FilePanels 100 57 BWindow * change_title; 101 58 102 59 BMessenger messenger(this); 103 60 BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR); 104 webDirFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL,61 fWebDirFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL, 105 62 B_DIRECTORY_NODE, false, &message, NULL, true); 106 63 107 webDirFilePanel->SetPanelDirectory(new BDirectory("/boot/home/public_html")); 108 webDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Select"); 109 change_title = webDirFilePanel->Window(); 64 fWebDirFilePanel->SetPanelDirectory( 65 new BDirectory("/boot/home/public_html")); 66 fWebDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Select"); 67 change_title = fWebDirFilePanel->Window(); 110 68 change_title->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR); 111 69 112 70 message.what = MSG_FILE_PANEL_CREATE_LOG_FILE; 113 logFilePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL,71 fLogFilePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL, 114 72 B_FILE_NODE, false, &message); 115 logFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Create");116 change_title = logFilePanel->Window();73 fLogFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Create"); 74 change_title = fLogFilePanel->Window(); 117 75 change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE); 76 77 AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 78 .Add(fPrefTabView) 79 .Add(BGroupLayoutBuilder(B_HORIZONTAL) 80 .AddGlue() 81 .Add(fCancelButton) 82 .Add(fDoneButton)) 83 .SetInsets(5, 5, 5, 5)); 118 84 119 85 Show(); 120 121 86 } 122 87 123 88 PoorManPreferencesWindow::~PoorManPreferencesWindow() 124 89 { 125 delete logFilePanel;126 delete webDirFilePanel;90 delete fLogFilePanel; 91 delete fWebDirFilePanel; 127 92 } 128 93 129 94 void 130 95 PoorManPreferencesWindow::MessageReceived(BMessage* message) 131 96 { 132 97 switch (message->what) { 133 case MSG_PREF_BTN_DONE:134 PoorManWindow *win;98 case MSG_PREF_BTN_DONE: 99 PoorManWindow* win; 135 100 PoorManServer* server; 136 win = ((PoorManApplication 101 win = ((PoorManApplication*)be_app)->GetPoorManWindow(); 137 102 server = win->GetServer(); 138 103 139 PRINT(("Pref Window: sendDir CheckBox: %d\n", siteView->SendDirValue())); 140 server->SetListDir(siteView->SendDirValue()); 141 win->SetDirListFlag(siteView->SendDirValue()); 142 PRINT(("Pref Window: indexFileName TextControl: %s\n", siteView->IndexFileName())); 143 if(server->SetIndexName(siteView->IndexFileName()) == B_OK) 144 win->SetIndexFileName(siteView->IndexFileName()); 145 PRINT(("Pref Window: webDir: %s\n", siteView->WebDir())); 146 if(server->SetWebDir(siteView->WebDir()) == B_OK){ 147 win->SetWebDir(siteView->WebDir()); 148 win->SetDirLabel(siteView->WebDir()); 104 PRINT(("Pref Window: sendDir CheckBox: %d\n", 105 siteView->SendDirValue())); 106 server->SetListDir(fSiteView->SendDirValue()); 107 win->SetDirListFlag(fSiteView->SendDirValue()); 108 109 PRINT(("Pref Window: indexFileName TextControl: %s\n", 110 fSiteView->IndexFileName())); 111 if(server->SetIndexName(fSiteView->IndexFileName()) == B_OK) 112 win->SetIndexFileName(fSiteView->IndexFileName()); 113 114 PRINT(("Pref Window: webDir: %s\n", fSiteView->WebDir())); 115 if(server->SetWebDir(fSiteView->WebDir()) == B_OK){ 116 win->SetWebDir(fSiteView->WebDir()); 117 win->SetDirLabel(fSiteView->WebDir()); 149 118 } 150 119 151 PRINT(("Pref Window: logConsole CheckBox: %d\n", loggingView->LogConsoleValue())); 152 win->SetLogConsoleFlag(loggingView->LogConsoleValue()); 153 PRINT(("Pref Window: logFile CheckBox: %d\n", loggingView->LogFileValue())); 154 win->SetLogFileFlag(loggingView->LogFileValue()); 155 PRINT(("Pref Window: logFileName: %s\n", loggingView->LogFileName())); 156 win->SetLogPath(loggingView->LogFileName()); 120 PRINT(("Pref Window: logConsole CheckBox: %d\n", 121 fLoggingView->LogConsoleValue())); 122 win->SetLogConsoleFlag(fLoggingView->LogConsoleValue()); 123 124 PRINT(("Pref Window: logFile CheckBox: %d\n", 125 fLoggingView->LogFileValue())); 126 win->SetLogFileFlag(fLoggingView->LogFileValue()); 127 128 PRINT(("Pref Window: logFileName: %s\n", 129 fLoggingView->LogFileName())); 130 win->SetLogPath(fLoggingView->LogFileName()); 157 131 158 PRINT(("Pref Window: MaxConnections Slider: %ld\n", advancedView->MaxSimultaneousConnections())); 159 server->SetMaxConns(advancedView->MaxSimultaneousConnections()); 160 win->SetMaxConnections((int16)advancedView->MaxSimultaneousConnections()); 132 PRINT(("Pref Window: MaxConnections Slider: %ld\n", 133 fAdvancedView->MaxSimultaneousConnections())); 134 server->SetMaxConns(fAdvancedView->MaxSimultaneousConnections()); 135 win->SetMaxConnections( 136 (int16)fAdvancedView->MaxSimultaneousConnections()); 161 137 162 163 138 if (Lock()) 164 139 Quit(); 165 break; 166 case MSG_PREF_BTN_CANCEL: 140 break; 141 142 case MSG_PREF_BTN_CANCEL: 167 143 if (Lock()) 168 144 Quit(); 169 break; 170 case MSG_PREF_SITE_BTN_SELECT: 145 break; 146 147 case MSG_PREF_SITE_BTN_SELECT: 171 148 // Select the Web Directory, root directory to look in. 172 if (!webDirFilePanel->IsShowing()) 173 webDirFilePanel->Show(); 174 break; 175 case MSG_FILE_PANEL_SELECT_WEB_DIR: 149 if (!fWebDirFilePanel->IsShowing()) 150 fWebDirFilePanel->Show(); 151 break; 152 153 case MSG_FILE_PANEL_SELECT_WEB_DIR: 176 154 // handle the open BMessage from the Select Web Directory File Panel 177 155 PRINT(("Select Web Directory:\n")); 178 156 SelectWebDir(message); 179 break; 180 case MSG_PREF_LOG_BTN_CREATE_FILE: 157 break; 158 159 case MSG_PREF_LOG_BTN_CREATE_FILE: 181 160 // Create the Log File 182 logFilePanel->Show(); 183 break; 184 case MSG_FILE_PANEL_CREATE_LOG_FILE: 161 fLogFilePanel->Show(); 162 break; 163 164 case MSG_FILE_PANEL_CREATE_LOG_FILE: 185 165 // handle the save BMessage from the Create Log File Panel 186 166 PRINT(("Create Log File:\n")); 187 167 CreateLogFile(message); 188 break; 189 case MSG_PREF_ADV_SLD_MAX_CONNECTION: 190 max_connections = advancedView->MaxSimultaneousConnections(); 191 PRINT(("Max Connections: %ld\n", max_connections)); 192 break; 168 break; 193 169 194 default: 195 BWindow::MessageReceived(message); 196 break; 170 case MSG_PREF_ADV_SLD_MAX_CONNECTION: 171 fMaxConnections = fAdvancedView->MaxSimultaneousConnections(); 172 PRINT(("Max Connections: %ld\n", fMaxConnections)); 173 break; 174 175 default: 176 BWindow::MessageReceived(message); 177 break; 197 178 } 198 179 } 199 180 200 181 void 201 PoorManPreferencesWindow::SelectWebDir(BMessage 182 PoorManPreferencesWindow::SelectWebDir(BMessage* message) 202 183 { 203 184 entry_ref ref; 204 const char 185 const char* name; 205 186 BPath path; 206 187 BEntry entry; 207 188 status_t err = B_OK; … … 218 199 entry.GetPath(&path); 219 200 220 201 PRINT(("DIR: %s\n", path.Path())); 221 siteView->SetWebDir(path.Path());202 fSiteView->SetWebDir(path.Path()); 222 203 223 204 bool temp; 224 if(message->FindBool("Default Dialog", &temp) == B_OK){ 225 PoorManWindow* win = ((PoorManApplication *)be_app)->GetPoorManWindow(); 226 if(win->GetServer()->SetWebDir(siteView->WebDir()) == B_OK){ 227 win->SetWebDir(siteView->WebDir()); 228 win->SetDirLabel(siteView->WebDir()); 205 if (message->FindBool("Default Dialog", &temp) == B_OK) { 206 PoorManWindow* win = 207 ((PoorManApplication *)be_app)->GetPoorManWindow(); 208 209 if (win->GetServer()->SetWebDir(fSiteView->WebDir()) == B_OK) { 210 win->SetWebDir(fSiteView->WebDir()); 211 win->SetDirLabel(fSiteView->WebDir()); 229 212 } 213 230 214 win->StartServer(); 215 231 216 if(Lock()) 232 217 Quit(); 233 218 } 234 219 } 235 220 236 221 void 237 PoorManPreferencesWindow::CreateLogFile(BMessage 222 PoorManPreferencesWindow::CreateLogFile(BMessage* message) 238 223 { 239 224 entry_ref ref; 240 const char 225 const char* name; 241 226 BPath path; 242 227 BEntry entry; 243 228 status_t err = B_OK; … … 255 240 path.Append(name); 256 241 PRINT(("Log File: %s\n", path.Path())); 257 242 258 if (err == B_OK) 259 { 260 loggingView->SetLogFileName(path.Path()); 261 loggingView->SetLogFileValue(true); 243 if (err == B_OK) { 244 fLoggingView->SetLogFileName(path.Path()); 245 fLoggingView->SetLogFileValue(true); 262 246 } 263 247 264 248 // mark the checkbox … … 271 255 BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR); 272 256 message.AddBool("Default Dialog", true); 273 257 274 webDirFilePanel->SetMessage(&message);275 if(! webDirFilePanel->IsShowing())276 webDirFilePanel->Show();258 fWebDirFilePanel->SetMessage(&message); 259 if(!fWebDirFilePanel->IsShowing()) 260 fWebDirFilePanel->Show(); 277 261 } -
src/apps/poorman/StatusSlider.cpp
11 11 #include <stdio.h> 12 12 13 13 14 StatusSlider::StatusSlider (BRect frame, 15 const char *name, 16 const char *label, 17 char *statusPrefix, 18 BMessage *message, 19 int32 minValue, 20 int32 maxValue) 21 22 : BSlider(frame, 23 name, 24 label, 25 message, 26 minValue, 27 maxValue 28 ), 29 StatusPrefix(statusPrefix) 14 StatusSlider::StatusSlider(const char* name, const char* label, 15 char* statusPrefix, BMessage* message, int32 minValue, int32 maxValue) 16 : 17 BSlider(name, label, message, minValue, maxValue, B_HORIZONTAL), 18 fStatusPrefix(statusPrefix) 30 19 { 31 temp = str;20 fTemp = fStr; 32 21 } 33 22 23 34 24 char* 35 25 StatusSlider::UpdateText() const 36 26 { 37 38 sprintf(temp, "%ld %s", Value(), StatusPrefix); 39 40 return temp; 27 sprintf(fTemp, "%ld %s", Value(), fStatusPrefix); 28 29 return fTemp; 41 30 } -
src/apps/poorman/PoorManPreferencesWindow.h
22 22 #include "PoorManAdvancedView.h" 23 23 24 24 25 class PoorManPreferencesWindow: public BWindow { 26 public: 27 PoorManPreferencesWindow(BRect frame, char* name); 28 ~PoorManPreferencesWindow(); 25 29 30 virtual void MessageReceived(BMessage* message); 26 31 27 class PoorManPreferencesWindow: public BWindow 28 { 32 void ShowWebDirFilePanel(); 33 void SelectWebDir(BMessage* message); 34 void CreateLogFile(BMessage* message); 35 29 36 private: 37 PoorManView* fPrefView; 38 PoorManView* fButtonView; 30 39 31 PoorManView * prefView; 32 PoorManView * buttonView; 40 // ------------------------------------------------ 41 // Tabs 42 BTabView* fPrefTabView; 43 BTab* fSiteTab; 44 BTab* fLoggingTab; 45 BTab* fAdvancedTab; 46 // Tab Views 47 PoorManSiteView* fSiteView; 48 PoorManLoggingView* fLoggingView; 49 PoorManAdvancedView* fAdvancedView; 33 50 34 // ------------------------------------------------ 35 // Tabs 36 BTabView * prefTabView; 37 BTab * siteTab; 38 BTab * loggingTab; 39 BTab * advancedTab; 40 // Tab Views 41 PoorManSiteView * siteView; 42 PoorManLoggingView * loggingView; 43 PoorManAdvancedView * advancedView; 51 // ------------------------------------------------ 52 // Buttons 53 BButton* fCancelButton; 54 BButton* fDoneButton; 44 55 45 46 // Buttons47 BButton * cancelButton;48 BButton * doneButton;56 // ------------------------------------------------ 57 // FilePanels 58 BFilePanel* fWebDirFilePanel; 59 BFilePanel* fLogFilePanel; 49 60 50 // ------------------------------------------------51 // FilePanels52 BFilePanel * webDirFilePanel;53 BFilePanel * logFilePanel;54 61 55 56 62 // ------------------------------------------------ 57 // temporary preference variables used to save and 58 // set the application to 59 // site tab 60 char web_directory[B_FILE_NAME_LENGTH]; 61 char index_file_name[64]; 62 bool send_dir; 63 // logging tab 64 bool log_to_console; 65 bool log_to_file; 66 char log_file_name[B_FILE_NAME_LENGTH]; 67 // advanced tab 68 int32 max_connections; 69 public: 70 PoorManPreferencesWindow(BRect frame, char * name); 71 ~PoorManPreferencesWindow(); 72 73 virtual void MessageReceived(BMessage * message); 74 75 void ShowWebDirFilePanel(); 76 void SelectWebDir(BMessage * message); 77 void CreateLogFile(BMessage * message); 63 // temporary preference variables used to save and 64 // set the application to 65 // site tab 66 char fWebDirectory[B_FILE_NAME_LENGTH]; 67 char fIndexFileName[64]; 68 bool fSendDir; 69 // logging tab 70 bool flogToConsole; 71 bool fLogToFile; 72 char fLogFileName[B_FILE_NAME_LENGTH]; 73 // advanced tab 74 int32 fMaxConnections; 78 75 }; 79 76 80 77 #endif -
src/apps/poorman/PoorManSiteView.cpp
6 6 */ 7 7 8 8 #include <Box.h> 9 #include <GroupLayoutBuilder.h> 9 10 10 11 #include "constants.h" 11 12 #include "PoorManSiteView.h" 12 13 #include "PoorManWindow.h" 13 14 #include "PoorManApplication.h" 14 15 15 PoorManSiteView::PoorManSiteView(BRect rect, const char *name) 16 : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) 16 PoorManSiteView::PoorManSiteView(const char* name) 17 : 18 BView(name, B_WILL_DRAW, NULL) 17 19 { 18 PoorManWindow *win;20 PoorManWindow* win; 19 21 win = ((PoorManApplication *)be_app)->GetPoorManWindow(); 20 22 21 Set ViewColor(BACKGROUND_COLOR);23 SetLayout(new BGroupLayout(B_VERTICAL)); 22 24 23 25 // Web Site Location BBox 24 BRect webLocationRect; 25 webLocationRect = rect; 26 webLocationRect.top -= 5.0; 27 webLocationRect.left -= 5.0; 28 webLocationRect.right -= 7.0; 29 webLocationRect.bottom -= 98.0; 30 31 BBox * webSiteLocation = new BBox(webLocationRect, "Web Location"); 26 BBox* webSiteLocation = new BBox("Web Location"); 32 27 webSiteLocation->SetLabel(STR_BBX_LOCATION); 33 AddChild(webSiteLocation);34 28 35 29 // Web Site Options BBox 36 BRect webOptionsRect; 37 webOptionsRect = webLocationRect; 38 webOptionsRect.top = webOptionsRect.bottom + 10.0; 39 webOptionsRect.bottom = webOptionsRect.top + 80.0; 40 41 BBox * webSiteOptions = new BBox(webOptionsRect, "Web Options"); 30 BBox* webSiteOptions = new BBox("Web Options"); 42 31 webSiteOptions->SetLabel(STR_BBX_OPTIONS); 43 AddChild(webSiteOptions);44 32 45 33 // Send Directory List if No Index 46 float left = 10.0; 47 float top = 20.0; 48 float box_size = 13.0; 49 BRect sendDirRect(left, top, webOptionsRect.Width() - 5.0, top + box_size); 50 sendDir = new BCheckBox(sendDirRect, "Send Dir", STR_CBX_DIR_LIST_LABEL, new BMessage(MSG_PREF_SITE_CBX_INDEX)); 34 fSendDir = new BCheckBox("Send Dir", STR_CBX_DIR_LIST_LABEL, 35 new BMessage(MSG_PREF_SITE_CBX_INDEX)); 51 36 // set the checkbox to the value the program has 52 37 SetSendDirValue(win->DirListFlag()); 53 webSiteOptions->AddChild(sendDir);54 38 55 56 // Finish the Web Site Location Section57 BRect webSiteLocationRect;58 webSiteLocationRect = webLocationRect;59 webSiteLocationRect.InsetBy(10.0, 7.0);60 webSiteLocationRect.top += 13.0;61 webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0;62 63 39 // Web Directory Text Control 64 webDir = new BTextControl(webSiteLocationRect, "Web Dir", STR_TXT_DIRECTORY, NULL, NULL); 65 webDir->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 66 webDir->SetDivider(80.0); 40 fWebDir = new BTextControl("Web Dir", STR_TXT_DIRECTORY, NULL); 67 41 SetWebDir(win->WebDir()); 68 webSiteLocation->AddChild(webDir);69 42 70 43 // Select Web Directory Button 71 BRect selectWebDirRect; 72 selectWebDirRect.top = webSiteLocationRect.bottom + 5.0; 73 selectWebDirRect.right = webSiteLocationRect.right + 2.0; 74 selectWebDirRect.left = selectWebDirRect.right - 123.0; 75 selectWebDirRect.bottom = selectWebDirRect.top + 19.0; 44 fSelectWebDir = new BButton("Select Web Dir", STR_BTN_DIRECTORY, 45 new BMessage(MSG_PREF_SITE_BTN_SELECT)); 76 46 77 selectWebDir = new BButton(selectWebDirRect, "Select Web Dir", STR_BTN_DIRECTORY, new BMessage(MSG_PREF_SITE_BTN_SELECT));78 webSiteLocation->AddChild(selectWebDir);79 80 47 // Index File Name Text Control 81 //webDirRect.InsetBy(10.0, 7.0); 82 webSiteLocationRect.top += 63.0; 83 webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0; 84 85 indexFileName = new BTextControl(webSiteLocationRect, "Index File Name", STR_TXT_INDEX, NULL, NULL); 86 indexFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 87 indexFileName->SetDivider(80.0); 48 fIndexFileName = new BTextControl("Index File Name", STR_TXT_INDEX, NULL); 88 49 SetIndexFileName(win->IndexFileName()); 89 webSiteLocation->AddChild(indexFileName);90 50 51 webSiteOptions->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 52 .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) 53 .Add(fSendDir) 54 .AddGlue()) 55 .SetInsets(5, 5, 5, 5)); 56 57 webSiteLocation->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 58 .Add(fWebDir) 59 .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) 60 .AddGlue() 61 .Add(fSelectWebDir)) 62 .Add(fIndexFileName) 63 .SetInsets(5, 5, 5, 5)); 64 65 AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 66 .Add(webSiteLocation) 67 .Add(webSiteOptions) 68 .SetInsets(5, 5, 5, 5)); 91 69 } -
src/apps/poorman/StatusSlider.h
13 13 #include <Slider.h> 14 14 15 15 16 class StatusSlider: public BSlider 17 { 16 class StatusSlider: public BSlider { 18 17 public: 19 StatusSlider(BRect frame, 20 const char *name, 21 const char *label, 22 char *statusPrefix, 23 BMessage *message, 24 int32 minValue, 25 int32 maxValue); 26 virtual char* UpdateText() const; 18 StatusSlider(const char* name, 19 const char* label, 20 char* statusPrefix, 21 BMessage* message, 22 int32 minValue, 23 int32 maxValue); 24 25 virtual char* UpdateText() const; 26 27 27 private: 28 char *StatusPrefix;29 char * temp;30 char str[128];28 char* fStatusPrefix; 29 char* fTemp; 30 char fStr[128]; 31 31 }; 32 32 33 33 #endif -
src/apps/poorman/PoorManAdvancedView.cpp
6 6 */ 7 7 8 8 #include <Box.h> 9 9 #include <GroupLayoutBuilder.h> 10 10 11 #include "constants.h" 11 12 #include "PoorManAdvancedView.h" 12 13 #include "PoorManWindow.h" 13 14 #include "PoorManApplication.h" 14 15 15 PoorManAdvancedView::PoorManAdvancedView(BRect rect, const char *name) 16 : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) 16 17 PoorManAdvancedView::PoorManAdvancedView(const char* name) 18 : 19 BView(name, B_WILL_DRAW, NULL) 17 20 { 18 PoorManWindow *win;19 win = ((PoorManApplication 21 PoorManWindow* win; 22 win = ((PoorManApplication*)be_app)->GetPoorManWindow(); 20 23 21 Set ViewColor(BACKGROUND_COLOR);24 SetLayout(new BGroupLayout(B_VERTICAL)); 22 25 23 // Console Logging BBox 24 BRect maxRect; 25 maxRect = rect; 26 maxRect.top -= 5.0; 27 maxRect.left -= 5.0; 28 maxRect.right -= 7.0; 29 maxRect.bottom -= 118.0; 30 31 BBox * connectionOptions = new BBox(maxRect, "Connection Options"); 26 BBox* connectionOptions = new BBox("Connection Options"); 32 27 connectionOptions->SetLabel(STR_BBX_CONNECTION); 33 AddChild(connectionOptions);34 28 35 BRect sliderRect; 36 sliderRect = connectionOptions->Bounds(); 37 sliderRect.InsetBy(10.0f, 10.0f); 38 sliderRect.top += 10; 39 sliderRect.bottom = sliderRect.top + 50.0; 29 fMaxConnections = new StatusSlider("Max Slider", STR_SLD_LABEL, 30 STR_SLD_STATUS_LABEL, 31 new BMessage(MSG_PREF_ADV_SLD_MAX_CONNECTION), 1, 200); 40 32 41 maxConnections = new StatusSlider(sliderRect, "Max Slider", STR_SLD_LABEL,42 STR_SLD_STATUS_LABEL, new BMessage(MSG_PREF_ADV_SLD_MAX_CONNECTION), 1, 200);43 44 33 // labels below the slider 1 and 200 45 maxConnections->SetLimitLabels("1", "200");34 fMaxConnections->SetLimitLabels("1", "200"); 46 35 SetMaxSimutaneousConnections(win->MaxConnections()); 47 connectionOptions->AddChild(maxConnections); 36 37 connectionOptions->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 38 .Add(fMaxConnections) 39 .SetInsets(5, 5, 5, 5)); 40 41 AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 42 .Add(connectionOptions) 43 .AddGlue() 44 .SetInsets(5, 5, 5, 5)); 48 45 } 49 46 50 47 void 51 48 PoorManAdvancedView::SetMaxSimutaneousConnections(int32 num) 52 49 { 53 50 if (num <= 0 || num > 200) 54 maxConnections->SetValue(32);51 fMaxConnections->SetValue(32); 55 52 else 56 maxConnections->SetValue(num);53 fMaxConnections->SetValue(num); 57 54 }