diff --git a/src/apps/poorman/Jamfile b/src/apps/poorman/Jamfile new file mode 100644 index 0000000000..b58052568b --- /dev/null +++ b/src/apps/poorman/Jamfile @@ -0,0 +1,19 @@ +SubDir OBOS_TOP src apps poorman ; + +AddResources PoorMan : PoorMan.rsrc ; + +App People : PoorMan.cpp + PoorManMainView.cpp + PoorManWindow.cpp + PoorManView.cpp + PoorManAdvancedView.cpp + StatusSlider.cpp + PoorManSiteView.cpp + PoorManLoggingView.cpp + PoorManPreferencesWindow.cpp + PoorManApplication.cpp + constants.cpp + ; + +LinkSharedOSLibs People : be tracker ; + diff --git a/src/apps/poorman/PoorMan.cpp b/src/apps/poorman/PoorMan.cpp new file mode 100644 index 0000000000..48a8b1ba83 --- /dev/null +++ b/src/apps/poorman/PoorMan.cpp @@ -0,0 +1,21 @@ +/* PoorMan.cpp + * + * Philip Harrison + * Started: 4/25/2004 + * Version: 0.1 + */ +//#include + +#include "PoorManApplication.h" + +int +main() +{ + PoorManApplication webServer; + webServer.Run(); + + //printf("webServer: %p", &webServer); + //printf("be_app: %p", be_app); + + return 0; +} \ No newline at end of file diff --git a/src/apps/poorman/PoorMan.rsrc b/src/apps/poorman/PoorMan.rsrc new file mode 100644 index 0000000000..2c4aefbc5c Binary files /dev/null and b/src/apps/poorman/PoorMan.rsrc differ diff --git a/src/apps/poorman/PoorManAdvancedView.cpp b/src/apps/poorman/PoorManAdvancedView.cpp new file mode 100644 index 0000000000..b5c19422cd --- /dev/null +++ b/src/apps/poorman/PoorManAdvancedView.cpp @@ -0,0 +1,57 @@ +/* PoorManAdvancedView.cpp + * + * Philip Harrison + * Started: 5/12/2004 + * Version: 0.1 + */ + +#include + +#include "constants.h" +#include "PoorManAdvancedView.h" +#include "PoorManWindow.h" +#include "PoorManApplication.h" + +PoorManAdvancedView::PoorManAdvancedView(BRect rect, const char *name) + : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) +{ + PoorManWindow * win; + win = ((PoorManApplication *)be_app)->GetPoorManWindow(); + + SetViewColor(BACKGROUND_COLOR); + + // Console Logging BBox + BRect maxRect; + maxRect = rect; + maxRect.top -= 5.0; + maxRect.left -= 5.0; + maxRect.right -= 7.0; + maxRect.bottom -= 118.0; + + BBox * connectionOptions = new BBox(maxRect, "Connection Options"); + connectionOptions->SetLabel(STR_BBX_CONNECTION); + AddChild(connectionOptions); + + BRect sliderRect; + sliderRect = connectionOptions->Bounds(); + sliderRect.InsetBy(10.0f, 10.0f); + sliderRect.top += 10; + sliderRect.bottom = sliderRect.top + 50.0; + + maxConnections = new StatusSlider(sliderRect, "Max Slider", STR_SLD_LABEL, + STR_SLD_STATUS_LABEL, new BMessage(MSG_PREF_ADV_SLD_MAX_CONNECTION), 1, 200); + + // labels below the slider 1 and 200 + maxConnections->SetLimitLabels("1", "200"); + SetMaxSimutaneousConnections(win->MaxConnections()); + connectionOptions->AddChild(maxConnections); +} + +void +PoorManAdvancedView::SetMaxSimutaneousConnections(int32 num) +{ + if (num <= 0 || num > 200) + maxConnections->SetValue(32); + else + maxConnections->SetValue(num); +} diff --git a/src/apps/poorman/PoorManAdvancedView.h b/src/apps/poorman/PoorManAdvancedView.h new file mode 100644 index 0000000000..fd693a77f1 --- /dev/null +++ b/src/apps/poorman/PoorManAdvancedView.h @@ -0,0 +1,28 @@ +/* PoorManAdvancedView.h + * + * Philip Harrison + * Started: 5/12/2004 + * Version: 0.1 + */ + +#ifndef POOR_MAN_ADVANCED_VIEW_H +#define POOR_MAN_ADVANCED_VIEW_H + +#include + +#include "StatusSlider.h" + + +class PoorManAdvancedView: public BView +{ +public: + PoorManAdvancedView(BRect, const char *name); + int32 MaxSimultaneousConnections() { return maxConnections->Value(); } + void SetMaxSimutaneousConnections(int32 num); +private: + // Advanced Tab + // Connections Options + StatusSlider * maxConnections; +}; + +#endif diff --git a/src/apps/poorman/PoorManApplication.cpp b/src/apps/poorman/PoorManApplication.cpp new file mode 100644 index 0000000000..ab46c70b0b --- /dev/null +++ b/src/apps/poorman/PoorManApplication.cpp @@ -0,0 +1,40 @@ +/* PoorManApplication.cpp + * + * Philip Harrison + * Started: 4/25/2004 + * Version: 0.1 + */ + +#include + +#include "constants.h" +#include "PoorManView.h" +#include "PoorManApplication.h" + + +PoorManApplication::PoorManApplication() + : BApplication(STR_APP_SIG), + status(false), hits(0) +{ + // ------------------------------------------- + // Main Window + //PoorManView * mainView; + BRect mainRect; + + mainRect.Set(30.0f, 30.0f, 355.0f, 185.0f); + mainWindow = new PoorManWindow(mainRect); + + //mainRect.OffsetTo(B_ORIGIN); + //mainView = new PoorManView(mainRect, STR_APP_NAME); + //mainView->SetViewColor(216,216,216,255); + + mainWindow->Show(); +} + +void +PoorManApplication::AboutRequested() +{ + BAlert* aboutBox = new BAlert(STR_ABOUT_TITLE, + STR_ABOUT_DESC, STR_ABOUT_BUTTON); + aboutBox->Go(); +} diff --git a/src/apps/poorman/PoorManApplication.h b/src/apps/poorman/PoorManApplication.h new file mode 100644 index 0000000000..71f92f9f81 --- /dev/null +++ b/src/apps/poorman/PoorManApplication.h @@ -0,0 +1,36 @@ +/* PoorManApplication.h + * + * Philip Harrison + * Started: 4/25/2004 + * Version: 0.1 + */ + +#ifndef POOR_MAN_APPLICATION_H +#define POOR_MAN_APPLICATION_H + + +#include + +#include "PoorManWindow.h" +#include "PoorManPreferencesWindow.h" + + +class PoorManApplication: public BApplication +{ +public: + PoorManApplication(); + void AboutRequested(); +PoorManWindow * GetPoorManWindow() { return mainWindow; } +private: + PoorManWindow * mainWindow; + PoorManPreferencesWindow * prefWindow; + + // -------------------------------------------- + // settings variables + bool status; + char directory[512]; + uint32 hits; + +}; + +#endif diff --git a/src/apps/poorman/PoorManLoggingView.cpp b/src/apps/poorman/PoorManLoggingView.cpp new file mode 100644 index 0000000000..873c07fbb6 --- /dev/null +++ b/src/apps/poorman/PoorManLoggingView.cpp @@ -0,0 +1,84 @@ +/* PoorManLoggingView.cpp + * + * Philip Harrison + * Started: 5/12/2004 + * Version: 0.1 + */ + +#include + +#include "constants.h" +#include "PoorManWindow.h" +#include "PoorManApplication.h" +#include "PoorManLoggingView.h" + +PoorManLoggingView::PoorManLoggingView(BRect rect, const char *name) + : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) +{ + PoorManWindow * win; + win = ((PoorManApplication *)be_app)->GetPoorManWindow(); + + SetViewColor(BACKGROUND_COLOR); + + // Console Logging BBox + BRect consoleLoggingRect; + consoleLoggingRect = rect; + consoleLoggingRect.top -= 5.0; + consoleLoggingRect.left -= 5.0; + consoleLoggingRect.right -= 7.0; + consoleLoggingRect.bottom -= 118.0; + + BBox * consoleLogging = new BBox(consoleLoggingRect, "Console Logging"); + consoleLogging->SetLabel(STR_BBX_CONSOLE_LOGGING); + AddChild(consoleLogging); + + + // File Logging BBox + BRect fileLoggingRect; + fileLoggingRect = consoleLoggingRect; + fileLoggingRect.top = consoleLoggingRect.bottom + 10.0; + fileLoggingRect.bottom = fileLoggingRect.top + 100.0; + + BBox * fileLogging = new BBox(fileLoggingRect, "File Logging"); + fileLogging->SetLabel(STR_BBX_FILE_LOGGING); + AddChild(fileLogging); + + float left = 10.0; + float top = 20.0; + float box_size = 13.0; + BRect tempRect(left, top, consoleLoggingRect.Width() - 5.0, top + box_size); + + // Console Logging + logConsole = new BCheckBox(tempRect, "Log To Console", STR_CBX_LOG_CONSOLE, new BMessage(MSG_PREF_LOG_CBX_CONSOLE)); + // set the checkbox to the value the program has + SetLogConsoleValue(win->LogConsoleFlag()); + consoleLogging->AddChild(logConsole); + + // File Logging + logFile = new BCheckBox(tempRect, "Log To File", STR_CBX_LOG_FILE, new BMessage(MSG_PREF_LOG_CBX_FILE)); + // set the checkbox to the value the program has + SetLogFileValue(win->LogFileFlag()); + fileLogging->AddChild(logFile); + + // File Name + tempRect.top = tempRect.bottom + 10.0; + tempRect.bottom = tempRect.top + box_size; + tempRect.right -= 5.0; + + logFileName = new BTextControl(tempRect, "File Name", STR_TXT_LOG_FILE_NAME, NULL, NULL); + logFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); + logFileName->SetDivider(73.0); + SetLogFileName(win->LogPath()); + fileLogging->AddChild(logFileName); + + // Create Log File + BRect createLogFileRect; + createLogFileRect.top = tempRect.bottom + 13.0; + createLogFileRect.right = tempRect.right + 2.0; + createLogFileRect.left = createLogFileRect.right - 87.0; + createLogFileRect.bottom = createLogFileRect.top + 19.0; + + createLogFile = new BButton(createLogFileRect, "Create Log File", STR_BTN_CREATE_LOG_FILE, new BMessage(MSG_PREF_LOG_BTN_CREATE_FILE)); + fileLogging->AddChild(createLogFile); + +} diff --git a/src/apps/poorman/PoorManLoggingView.h b/src/apps/poorman/PoorManLoggingView.h new file mode 100644 index 0000000000..2ffa367606 --- /dev/null +++ b/src/apps/poorman/PoorManLoggingView.h @@ -0,0 +1,41 @@ +/* PoorManLoggingView.h + * + * Philip Harrison + * Started: 5/12/2004 + * Version: 0.1 + */ + +#ifndef POOR_MAN_LOGGING_VIEW_H +#define POOR_MAN_LOGGING_VIEW_H + +#include +#include +#include +#include + + +class PoorManLoggingView: public BView +{ +public: + PoorManLoggingView(BRect, const char *name); + + void SetLogConsoleValue(bool state) {if (state) logConsole->SetValue(B_CONTROL_ON); + else logConsole->SetValue(B_CONTROL_OFF); } + bool LogConsoleValue() { return (logConsole->Value() == B_CONTROL_ON) ? true : false; } + void SetLogFileValue(bool state) {if (state) logFile->SetValue(B_CONTROL_ON); + else logFile->SetValue(B_CONTROL_OFF); } + bool LogFileValue() { return (logFile->Value() == B_CONTROL_ON) ? true : false; } +const char * LogFileName() { return logFileName->Text(); } + void SetLogFileName(const char * log) { logFileName->SetText(log); } +private: + // Logging Tab + + // Console Logging + BCheckBox * logConsole; + // File Logging + BCheckBox * logFile; + BTextControl * logFileName; + BButton * createLogFile; +}; + +#endif diff --git a/src/apps/poorman/PoorManMainView.cpp b/src/apps/poorman/PoorManMainView.cpp new file mode 100644 index 0000000000..13529b1fe3 --- /dev/null +++ b/src/apps/poorman/PoorManMainView.cpp @@ -0,0 +1,29 @@ +/* PoorManMainView.cpp + * + * Philip Harrison + * Started: 5/13/2004 + * Version: 0.1 + */ + + +#include "PoorManMainView.h" + +PoorManMainView::PoorManMainView(BRect rect, char *name) + : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) +{ +} + +void +PoorManMainView::AttachedToWindow() +{ + SetPenSize(1); +} + +void +PoorManMainView::Draw(BRect updateRect) +{ + BRect tempRect; + tempRect = updateRect; + + StrokeRect(tempRect, B_SOLID_HIGH); +} diff --git a/src/apps/poorman/PoorManMainView.h b/src/apps/poorman/PoorManMainView.h new file mode 100644 index 0000000000..2270a1d9ed --- /dev/null +++ b/src/apps/poorman/PoorManMainView.h @@ -0,0 +1,21 @@ +/* PoorManMainView.h + * + * Philip Harrison + * Started: 5/13/2004 + * Version: 0.1 + */ + +#ifndef POOR_MAN_MAIN_VIEW_H +#define POOR_MAN_MAIN_VIEW_H + +#include + +class PoorManMainView: public BView +{ +public: + PoorManMainView(BRect, char *name); +virtual void AttachedToWindow(); +virtual void Draw(BRect updateRect); +}; + +#endif diff --git a/src/apps/poorman/PoorManPreferencesWindow.cpp b/src/apps/poorman/PoorManPreferencesWindow.cpp new file mode 100644 index 0000000000..2d9ef55098 --- /dev/null +++ b/src/apps/poorman/PoorManPreferencesWindow.cpp @@ -0,0 +1,248 @@ +/* PoorManPreferencesWindow.cpp + * + * Philip Harrison + * Started: 4/27/2004 + * Version: 0.1 + */ + +#include +#include +#include +#include + +#include "constants.h" +#include "PoorManWindow.h" +#include "PoorManApplication.h" +#include "PoorManPreferencesWindow.h" + + +PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name) + : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE) +{ + + frame = Bounds(); + + prefView = new PoorManView(frame, STR_WIN_NAME_PREF); + //prefView->SetViewColor(216,216,216,255); + prefView->SetViewColor(BACKGROUND_COLOR); + AddChild(prefView); + + + + // Button View + BRect buttonRect; + buttonRect = Bounds(); + buttonRect.top = buttonRect.bottom - 30; + + buttonView = new PoorManView(buttonRect, "Button View"); + buttonView->SetViewColor(BACKGROUND_COLOR); + prefView->AddChild(buttonView); + + // Buttons + float buttonTop = 0.0f; + float buttonWidth = 52.0f; + float buttonHeight = 26.0f; + float buttonLeft = 265.0f; + + BRect button1; + button1 = buttonView->Bounds(); + button1.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight); + cancelButton = new BButton(button1, "Cancel Button", "Cancel", new BMessage(MSG_PREF_BTN_CANCEL)); + + buttonLeft = 325.0f; + BRect button2; + button2 = buttonView->Bounds(); + button2.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight); + doneButton = new BButton(button2, "Done Button", "Done", new BMessage(MSG_PREF_BTN_DONE)); + + buttonView->AddChild(cancelButton); + buttonView->AddChild(doneButton); + + + + // Create tabs + BRect r; + r = Bounds(); + //r.InsetBy(5, 5); + r.top += 8.0; + r.bottom -= 38.0; + + prefTabView = new BTabView(r, "Pref Tab View"); + prefTabView->SetViewColor(BACKGROUND_COLOR); + + r = prefTabView->Bounds(); + r.InsetBy(5, 5); + r.bottom -= prefTabView->TabHeight(); + + // Site Tab + siteTab = new BTab(); + siteView = new PoorManSiteView(r, "Site View"); + prefTabView->AddTab(siteView, siteTab); + siteTab->SetLabel(STR_TAB_SITE); + + // Logging Tab + loggingTab = new BTab(); + loggingView = new PoorManLoggingView(r, "Logging View"); + prefTabView->AddTab(loggingView, loggingTab); + loggingTab->SetLabel(STR_TAB_LOGGING); + + // Advanced Tab + advancedTab = new BTab(); + advancedView = new PoorManAdvancedView(r, "Advanced View"); + prefTabView->AddTab(advancedView, advancedTab); + advancedTab->SetLabel(STR_TAB_ADVANCED); + + prefView->AddChild(prefTabView); + + // FilePanels + BWindow * change_title; + + webDirFilePanel = new BFilePanel( + B_OPEN_PANEL, + new BMessenger(this), + NULL, + B_DIRECTORY_NODE, + false, + new BMessage(MSG_FILE_PANEL_SELECT_WEB_DIR) + ); + webDirFilePanel->SetPanelDirectory(new BDirectory("/boot/home/public_html")); + webDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Select"); + change_title = webDirFilePanel->Window(); + change_title->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR); + + + logFilePanel = new BFilePanel( + B_SAVE_PANEL, + new BMessenger(this), + NULL, + B_FILE_NODE, + false, + new BMessage(MSG_FILE_PANEL_CREATE_LOG_FILE) + ); + logFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Create"); + change_title = logFilePanel->Window(); + change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE); + + + Show(); + +} + +void +PoorManPreferencesWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_PREF_BTN_DONE: + PoorManWindow * win; + win = ((PoorManApplication *)be_app)->GetPoorManWindow(); + + std::cout << "Pref Window: sendDir CheckBox: " << siteView->SendDirValue() << std::endl; + win->SetDirListFlag(siteView->SendDirValue()); + std::cout << "Pref Window: indexFileName TextControl: " << siteView->IndexFileName() << std::endl; + win->SetIndexFileName(siteView->IndexFileName()); + std::cout << "Pref Window: webDir: " << siteView->WebDir() << std::endl; + win->SetWebDir(siteView->WebDir()); + win->SetDirLabel(siteView->WebDir()); + + std::cout << "Pref Window: logConsole CheckBox: " << loggingView->LogConsoleValue() << std::endl; + win->SetLogConsoleFlag(loggingView->LogConsoleValue()); + std::cout << "Pref Window: logFile CheckBox: " << loggingView->LogFileValue() << std::endl; + win->SetLogFileFlag(loggingView->LogFileValue()); + std::cout << "Pref Window: logFileName: " << loggingView->LogFileName() << std::endl; + win->SetLogPath(loggingView->LogFileName()); + + std::cout << "Pref Window: MaxConnections Slider: " << advancedView->MaxSimultaneousConnections() << std::endl; + win->SetMaxConnections(advancedView->MaxSimultaneousConnections()); + + + if (Lock()) + Quit(); + break; + case MSG_PREF_BTN_CANCEL: + if (Lock()) + Quit(); + break; + case MSG_PREF_SITE_BTN_SELECT: + // Select the Web Directory, root directory to look in. + if (!webDirFilePanel->IsShowing()) + webDirFilePanel->Show(); + break; + case MSG_FILE_PANEL_SELECT_WEB_DIR: + // handle the open BMessage from the Select Web Directory File Panel + std::cout << "Select Web Directory:\n" << std::endl; + SelectWebDir(message); + break; + case MSG_PREF_LOG_BTN_CREATE_FILE: + // Create the Log File + logFilePanel->Show(); + break; + case MSG_FILE_PANEL_CREATE_LOG_FILE: + // handle the save BMessage from the Create Log File Panel + std::cout << "Create Log File:\n" << std::endl; + CreateLogFile(message); + break; + case MSG_PREF_ADV_SLD_MAX_CONNECTION: + max_connections = advancedView->MaxSimultaneousConnections(); + std::cout << "Max Connections: " << max_connections << std::endl; + break; + + default: + BWindow::MessageReceived(message); + break; + } +} + +void +PoorManPreferencesWindow::SelectWebDir(BMessage * message) +{ + entry_ref ref; + const char * name; + BPath path; + BEntry entry; + status_t err = B_OK; + + err = message->FindRef("refs", &ref) != B_OK; + //if (err = message->FindRef("directory", &ref) != B_OK) + //return err; + err = message->FindString("name", &name) != B_OK; + //if (err = message->FindString("name", &name) != B_OK) + // ;//return err; + err = entry.SetTo(&ref) != B_OK; + //if (err = entry.SetTo(&ref) != B_OK) + // ;//return err; + entry.GetPath(&path); + + std::cout << "DIR: " << path.Path() << std::endl; + siteView->SetWebDir(path.Path()); +} + +void +PoorManPreferencesWindow::CreateLogFile(BMessage * message) +{ + entry_ref ref; + const char * name; + BPath path; + BEntry entry; + status_t err = B_OK; + + err = message->FindRef("directory", &ref) != B_OK; + //if (err = message->FindRef("directory", &ref) != B_OK) + //return err; + err = message->FindString("name", &name) != B_OK; + //if (err = message->FindString("name", &name) != B_OK) + // ;//return err; + err = entry.SetTo(&ref) != B_OK; + //if (err = entry.SetTo(&ref) != B_OK) + // ;//return err; + entry.GetPath(&path); + path.Append(name); + std::cout << "Log File: " << path.Path() << std::endl; + + if (err == B_OK) + { + loggingView->SetLogFileName(path.Path()); + loggingView->SetLogFileValue(true); + } + + // mark the checkbox +} diff --git a/src/apps/poorman/PoorManPreferencesWindow.h b/src/apps/poorman/PoorManPreferencesWindow.h new file mode 100644 index 0000000000..8093130921 --- /dev/null +++ b/src/apps/poorman/PoorManPreferencesWindow.h @@ -0,0 +1,78 @@ +/* PoorManPreferencesWindow.h + * + * Philip Harrison + * Started: 4/27/2004 + * Version: 0.1 + */ + + +#ifndef POOR_MAN_PREFERENCES_WINDOW_H +#define POOR_MAN_PREFERENCES_WINDOW_H + +#include +#include +#include +#include +#include +#include + +#include "PoorManView.h" +#include "PoorManSiteView.h" +#include "PoorManLoggingView.h" +#include "PoorManAdvancedView.h" + + + + +class PoorManPreferencesWindow: public BWindow +{ +private: + + PoorManView * prefView; + PoorManView * buttonView; + + // ------------------------------------------------ + // Tabs + BTabView * prefTabView; + BTab * siteTab; + BTab * loggingTab; + BTab * advancedTab; + // Tab Views + PoorManSiteView * siteView; + PoorManLoggingView * loggingView; + PoorManAdvancedView * advancedView; + + // ------------------------------------------------ + // Buttons + BButton * cancelButton; + BButton * doneButton; + + // ------------------------------------------------ + // FilePanels + BFilePanel * webDirFilePanel; + BFilePanel * logFilePanel; + + + // ------------------------------------------------ + // temporary preference variables used to save and + // set the application to + // site tab + char web_directory[B_FILE_NAME_LENGTH]; + char index_file_name[64]; + bool send_dir; + // logging tab + bool log_to_console; + bool log_to_file; + char log_file_name[B_FILE_NAME_LENGTH]; + // advanced tab + int32 max_connections; +public: + PoorManPreferencesWindow(BRect frame, char * name); +virtual void MessageReceived(BMessage * message); + + void ShowWebDirFilePanel() { if (!webDirFilePanel->IsShowing()) webDirFilePanel->Show(); } + void SelectWebDir(BMessage * message); + void CreateLogFile(BMessage * message); +}; + +#endif diff --git a/src/apps/poorman/PoorManSiteView.cpp b/src/apps/poorman/PoorManSiteView.cpp new file mode 100644 index 0000000000..eaf8e9f5f8 --- /dev/null +++ b/src/apps/poorman/PoorManSiteView.cpp @@ -0,0 +1,91 @@ +/* PoorManSiteView.cpp + * + * Philip Harrison + * Started: 5/07/2004 + * Version: 0.1 + */ + +#include + +#include "constants.h" +#include "PoorManSiteView.h" +#include "PoorManWindow.h" +#include "PoorManApplication.h" + +PoorManSiteView::PoorManSiteView(BRect rect, const char *name) + : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) +{ + PoorManWindow * win; + win = ((PoorManApplication *)be_app)->GetPoorManWindow(); + + SetViewColor(BACKGROUND_COLOR); + + // Web Site Location BBox + BRect webLocationRect; + webLocationRect = rect; + webLocationRect.top -= 5.0; + webLocationRect.left -= 5.0; + webLocationRect.right -= 7.0; + webLocationRect.bottom -= 98.0; + + BBox * webSiteLocation = new BBox(webLocationRect, "Web Location"); + webSiteLocation->SetLabel(STR_BBX_LOCATION); + AddChild(webSiteLocation); + + // Web Site Options BBox + BRect webOptionsRect; + webOptionsRect = webLocationRect; + webOptionsRect.top = webOptionsRect.bottom + 10.0; + webOptionsRect.bottom = webOptionsRect.top + 80.0; + + BBox * webSiteOptions = new BBox(webOptionsRect, "Web Options"); + webSiteOptions->SetLabel(STR_BBX_OPTIONS); + AddChild(webSiteOptions); + + // Send Directory List if No Index + float left = 10.0; + float top = 20.0; + float box_size = 13.0; + BRect sendDirRect(left, top, webOptionsRect.Width() - 5.0, top + box_size); + sendDir = new BCheckBox(sendDirRect, "Send Dir", STR_CBX_DIR_LIST_LABEL, new BMessage(MSG_PREF_SITE_CBX_INDEX)); + // set the checkbox to the value the program has + SetSendDirValue(win->DirListFlag()); + webSiteOptions->AddChild(sendDir); + + + // Finish the Web Site Location Section + BRect webSiteLocationRect; + webSiteLocationRect = webLocationRect; + webSiteLocationRect.InsetBy(10.0, 7.0); + webSiteLocationRect.top += 13.0; + webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0; + + // Web Directory Text Control + webDir = new BTextControl(webSiteLocationRect, "Web Dir", STR_TXT_DIRECTORY, NULL, NULL); + webDir->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); + webDir->SetDivider(80.0); + SetWebDir(win->WebDir()); + webSiteLocation->AddChild(webDir); + + // Select Web Directory Button + BRect selectWebDirRect; + selectWebDirRect.top = webSiteLocationRect.bottom + 5.0; + selectWebDirRect.right = webSiteLocationRect.right + 2.0; + selectWebDirRect.left = selectWebDirRect.right - 123.0; + selectWebDirRect.bottom = selectWebDirRect.top + 19.0; + + selectWebDir = new BButton(selectWebDirRect, "Select Web Dir", STR_BTN_DIRECTORY, new BMessage(MSG_PREF_SITE_BTN_SELECT)); + webSiteLocation->AddChild(selectWebDir); + + // Index File Name Text Control + //webDirRect.InsetBy(10.0, 7.0); + webSiteLocationRect.top += 63.0; + webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0; + + indexFileName = new BTextControl(webSiteLocationRect, "Index File Name", STR_TXT_INDEX, NULL, NULL); + indexFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); + indexFileName->SetDivider(80.0); + SetIndexFileName(win->IndexFileName()); + webSiteLocation->AddChild(indexFileName); + +} diff --git a/src/apps/poorman/PoorManSiteView.h b/src/apps/poorman/PoorManSiteView.h new file mode 100644 index 0000000000..2fecd8f86c --- /dev/null +++ b/src/apps/poorman/PoorManSiteView.h @@ -0,0 +1,40 @@ +/* PoorManView.h + * + * Philip Harrison + * Started: 5/07/2004 + * Version: 0.1 + */ + +#ifndef POOR_MAN_SITE_VIEW_H +#define POOR_MAN_SITE_VIEW_H + +#include +#include +#include +#include + + +class PoorManSiteView: public BView +{ +public: + PoorManSiteView(BRect, const char *name); + void SetSendDirValue(bool state) {if (state) sendDir->SetValue(B_CONTROL_ON); + else sendDir->SetValue(B_CONTROL_OFF); } + bool SendDirValue() { return (sendDir->Value() == B_CONTROL_ON) ? true : false; } +const char * IndexFileName() { return indexFileName->Text(); } + void SetIndexFileName(const char * name) { indexFileName->SetText(name); } +const char * WebDir() { return webDir->Text(); } + void SetWebDir(const char * dir) { webDir->SetText(dir); } +private: + // Site Tab + // Web Site Location + BTextControl * webDir; + BTextControl * indexFileName; + BButton * selectWebDir; + + // Web Site Options + BCheckBox * sendDir; + +}; + +#endif diff --git a/src/apps/poorman/PoorManView.cpp b/src/apps/poorman/PoorManView.cpp new file mode 100644 index 0000000000..f18a7679e0 --- /dev/null +++ b/src/apps/poorman/PoorManView.cpp @@ -0,0 +1,20 @@ +/* PoorManView.cpp + * + * Philip Harrison + * Started: 4/25/2004 + * Version: 0.1 + */ + +#ifndef POOR_MAN_VIEW_H +#include "PoorManView.h" +#endif + +PoorManView::PoorManView(BRect rect, char *name) + : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW ) +{ +} + +void +PoorManView::AttachedToWindow() +{ +} diff --git a/src/apps/poorman/PoorManView.h b/src/apps/poorman/PoorManView.h new file mode 100644 index 0000000000..24faa2b6dd --- /dev/null +++ b/src/apps/poorman/PoorManView.h @@ -0,0 +1,22 @@ +/* PoorManView.h + * + * Philip Harrison + * Started: 4/25/2004 + * Version: 0.1 + */ + +#ifndef POOR_MAN_VIEW_H +#define POOR_MAN_VIEW_H + +#ifndef _VIEW_H +#include +#endif + +class PoorManView: public BView +{ +public: + PoorManView(BRect, char *name); +virtual void AttachedToWindow(); +}; + +#endif diff --git a/src/apps/poorman/PoorManWindow.cpp b/src/apps/poorman/PoorManWindow.cpp new file mode 100644 index 0000000000..6938b495de --- /dev/null +++ b/src/apps/poorman/PoorManWindow.cpp @@ -0,0 +1,542 @@ +/* PoorManWindow.cpp + * + * Philip Harrison + * Started: 4/25/2004 + * Version: 0.1 + */ + +#include "PoorManApplication.h" +#include "PoorManPreferencesWindow.h" +#include "PoorManWindow.h" +#include "constants.h" + + +#include +#include +#include + +#include + + +//#include + +PoorManWindow::PoorManWindow(BRect frame) + : BWindow(frame, STR_APP_NAME, B_TITLED_WINDOW, 0), + status(false), hits(0), last_width(325), last_height(155) +{ + DefaultSettings(); + + + + // PoorMan Window + SetSizeLimits(318, 1600, 53, 1200); + // limit the size of the size of the window + + //SetZoomLimits(1024, 768); + + //frame.Set(30.0f, 30.0f, 355.0f, 185.0f); + frame.OffsetTo(B_ORIGIN); + frame = Bounds(); + frame.top += 19.0; + + mainView = new PoorManView(frame, STR_APP_NAME); + mainView->SetViewColor(216,216,216,255); + + mainView->SetFont(be_bold_font); + mainView->SetFontSize(12); + AddChild(mainView); + + // BBox tests + BRect br; + br = frame; + br.top = 1.0; + + BBox * bb = new BBox(br, "Background", B_FOLLOW_ALL_SIDES, + B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE); + bb->SetHighColor(WHITE); + bb->SetLowColor(GRAY); + bb->SetBorder(B_PLAIN_BORDER); + mainView->AddChild(bb); + + // ----------------------------------------------------------------- + // Three Labels + + // Status String + BRect statusRect; + statusRect = Bounds(); + statusRect.left += 5; + statusRect.top += 3; + statusRect.bottom = statusRect.top + 15; + statusRect.right = statusRect.left + 75; // make the width wide enough for the string to display + + statusView = new BStringView(statusRect, "Status View", "Status: Stopped"); + bb->AddChild(statusView); + + // Directory String + BRect dirRect; + dirRect = Bounds(); + dirRect.top = statusRect.bottom - 1; + dirRect.bottom = dirRect.top + 15; + dirRect.left = statusRect.left; + dirRect.right -= 5; + + dirView = new BStringView(dirRect, "Dir View", "Directory: /boot/home/", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + bb->AddChild(dirView); + + // Hits String + BRect hitsRect; + hitsRect = bb->Bounds(); + hitsRect.InsetBy(5, 5); + hitsRect.top = statusRect.top; + hitsRect.bottom = statusRect.bottom; + hitsRect.left = statusRect.right + 20; + + hitsView = new BStringView(hitsRect, "Hit View", "Hits: 0", B_FOLLOW_RIGHT | B_FOLLOW_TOP); + hitsView->SetAlignment(B_ALIGN_RIGHT); + bb->AddChild(hitsView); + + // ----------------------------------------------------------------- + // Logging View + + // logRect + BRect logRect(5.0, 36.0, 306.0, 131.0); + + // textRect + BRect textRect; //(1.0, 1.0, 175.0, 75.0); + textRect = logRect; + textRect.InsetBy(1.0, 1.0); + textRect.top = 0.0; + textRect.left = 0.0; + + loggingView = new BTextView(logRect, STR_TXT_VIEW, textRect, + B_FOLLOW_ALL_SIDES, B_WILL_DRAW ); + + loggingView->MakeEditable(false); // user cannot change the text + loggingView->MakeSelectable(true); + loggingView->SetViewColor(WHITE); + + loggingView->Insert("This is PoorMan.\n"); // text_run_array + //loggingView->MakeFocus(true); + //AddChild(loggingView); + + + // create the scroll view + scrollView = new BScrollView("Scroll View", loggingView, B_FOLLOW_ALL_SIDES, + B_WILL_DRAW | B_FRAME_EVENTS, + // Make sure articles on border do not occur when resizing + false, true); + bb->AddChild(scrollView); + + + + // ----------------------------------------------------------------- + // menu bar + BRect menuRect; + menuRect = Bounds(); + menuRect.bottom = 18.0f; + + FileMenuBar = new BMenuBar(menuRect, "File Menu Bar"); + + // menus + FileMenu = BuildFileMenu(); + if (FileMenu) + FileMenuBar->AddItem(FileMenu); + + EditMenu = BuildEditMenu(); + if (EditMenu) + FileMenuBar->AddItem(EditMenu); + + ControlsMenu = BuildControlsMenu(); + if (ControlsMenu) + FileMenuBar->AddItem(ControlsMenu); + + // File Panels + BWindow * change_title; + + saveConsoleFilePanel = new BFilePanel( + B_SAVE_PANEL, + new BMessenger(this), + NULL, + B_FILE_NODE, + false, + new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE) + ); + change_title = saveConsoleFilePanel->Window(); + change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE); + + saveConsoleSelectionFilePanel = new BFilePanel( + B_SAVE_PANEL, + new BMessenger(this), + NULL, + B_FILE_NODE, + false, + new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION) + ); + change_title = saveConsoleSelectionFilePanel->Window(); + change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE_SELECTION); + + + AddChild(FileMenuBar); +} + +void +PoorManWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_MENU_FILE_SAVE_AS: + saveConsoleFilePanel->Show(); + break; + case MSG_FILE_PANEL_SAVE_CONSOLE: + printf("FilePanel: Save Console\n"); + SaveConsole(message, false); + break; + case MSG_MENU_FILE_SAVE_SELECTION: + saveConsoleSelectionFilePanel->Show(); + break; + case MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION: + printf("FilePanel: Save Console Selection\n"); + SaveConsole(message, true); + break; + case MSG_MENU_EDIT_PREF: + prefWindow = new PoorManPreferencesWindow(BRect(30.0f, 30.0f, 410.0f, 310.0f), STR_WIN_NAME_PREF); + break; + case MSG_MENU_CTRL_RUN: + BMenuItem * RunServer; + RunServer = ControlsMenu->FindItem(STR_MNU_CTRL_RUN_SERVER); + if (RunServer) + { + //status = httpd->Run(); + /* For Testing + if (status) + status = false; + else + status = true; + */ + + UpdateStatusLabel(status); + if (status) + { + RunServer->SetMarked(true); + } else { + RunServer->SetMarked(false); + } + } + break; + case MSG_MENU_CTRL_CLEAR_HIT: + SetHits(0); + UpdateHitsLabel(); + break; + case MSG_MENU_CTRL_CLEAR_CONSOLE: + loggingView->SelectAll(); + loggingView->Delete(); + break; + case MSG_MENU_CTRL_CLEAR_LOG: + FILE * f; + f = fopen(log_path.String(), "w"); + fclose(f); + break; + default: + BWindow::MessageReceived(message); + break; + } +} + + +void +PoorManWindow::FrameResized(float width, float height) +{ + if (is_zoomed) + { + last_width = width; + last_height = height; + } + printf("(%f, %f)\n", width, height); +} + +bool +PoorManWindow::QuitRequested() +{ + SaveSettings(); + be_app->PostMessage(B_QUIT_REQUESTED); + return (true); +} + +void +PoorManWindow::Zoom(BPoint origin, float width, float height) +{ + printf("Zoom: Is Zoomed before: %d (%f, %f)\n", is_zoomed, width, height); + if (is_zoomed) + { // Change to the Minimal size + is_zoomed = false; + ResizeTo(318, 53); + printf("ResizedTo(318, 53)\n"); + } + else + { // Change to the Zoomed size + is_zoomed = true; + ResizeTo(last_width, last_height); + printf("ResizedTo(%f, %f)\n", last_width, last_height); + } +} + +// Private: Methods ------------------------------------------ + +BMenu * +PoorManWindow::BuildFileMenu() const +{ + BMenu * ptrFileMenu = new BMenu(STR_MNU_FILE); + + ptrFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_AS, + new BMessage(MSG_MENU_FILE_SAVE_AS), CMD_FILE_SAVE_AS)); + + ptrFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_SELECTION, + new BMessage(MSG_MENU_FILE_SAVE_SELECTION))); + + ptrFileMenu->AddSeparatorItem(); + + // about box + BMenuItem * AboutItem = new BMenuItem(STR_MNU_FILE_ABOUT, + new BMessage(B_ABOUT_REQUESTED)); + AboutItem->SetTarget(NULL, be_app); + ptrFileMenu->AddItem(AboutItem); + + ptrFileMenu->AddSeparatorItem(); + + + ptrFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_QUIT, + new BMessage(B_QUIT_REQUESTED), CMD_FILE_QUIT)); + + return ptrFileMenu; +} + +BMenu * +PoorManWindow::BuildEditMenu() const +{ + BMenu * ptrEditMenu = new BMenu(STR_MNU_EDIT); + + BMenuItem * CopyMenuItem = new BMenuItem(STR_MNU_EDIT_COPY, + new BMessage(B_COPY), CMD_EDIT_COPY); + + ptrEditMenu->AddItem(CopyMenuItem); + CopyMenuItem->SetTarget(loggingView, NULL); + + ptrEditMenu->AddSeparatorItem(); + + BMenuItem * SelectAllMenuItem = new BMenuItem(STR_MNU_EDIT_SELECT_ALL, + new BMessage(B_SELECT_ALL), CMD_EDIT_SELECT_ALL); + + ptrEditMenu->AddItem(SelectAllMenuItem); + SelectAllMenuItem->SetTarget(loggingView, NULL); + + ptrEditMenu->AddSeparatorItem(); + + BMenuItem * PrefMenuItem = new BMenuItem(STR_MNU_EDIT_PREF, + new BMessage(MSG_MENU_EDIT_PREF)); + ptrEditMenu->AddItem(PrefMenuItem); + + return ptrEditMenu; +} + +BMenu * +PoorManWindow::BuildControlsMenu() const +{ + BMenu * ptrControlMenu = new BMenu(STR_MNU_CTRL); + + BMenuItem * RunServerMenuItem = new BMenuItem(STR_MNU_CTRL_RUN_SERVER, + new BMessage(MSG_MENU_CTRL_RUN)); + RunServerMenuItem->SetMarked(false); + ptrControlMenu->AddItem(RunServerMenuItem); + + BMenuItem * ClearHitCounterMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_HIT_COUNTER, + new BMessage(MSG_MENU_CTRL_CLEAR_HIT)); + ptrControlMenu->AddItem(ClearHitCounterMenuItem); + + ptrControlMenu->AddSeparatorItem(); + + BMenuItem * ClearConsoleLogMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_CONSOLE, + new BMessage(MSG_MENU_CTRL_CLEAR_CONSOLE)); + ptrControlMenu->AddItem(ClearConsoleLogMenuItem); + + BMenuItem * ClearLogFileMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_LOG_FILE, + new BMessage(MSG_MENU_CTRL_CLEAR_LOG)); + ptrControlMenu->AddItem(ClearLogFileMenuItem); + + return ptrControlMenu; +} + +void +PoorManWindow::SetDirLabel(const char * name) +{ + BString dirPath("Directory: "); + int32 length = dirPath.Length() + 1; + dirPath.LockBuffer(length); + dirPath.Append(name); + + dirPath.UnlockBuffer(length + strlen(name)); + + if (Lock()) + { + dirView->SetText(dirPath.String()); + Unlock(); + } +} + +void +PoorManWindow::UpdateStatusLabel(bool set) +{ + if (Lock()) + { + if (set) + statusView->SetText("Status: Running"); + else + statusView->SetText("Status: Stopped"); + + Unlock(); + } +} + +void +PoorManWindow::UpdateHitsLabel() +{ + if (Lock()) + { + sprintf(hitsLabel, "Hits: %lu", GetHits()); + hitsView->SetText(hitsLabel); + + Unlock(); + } +} + +status_t +PoorManWindow::SaveConsole(BMessage * message, bool selection) +{ + entry_ref ref; + const char * name; + BPath path; + BEntry entry; + status_t err = B_OK; + FILE *f; + + if (err = message->FindRef("directory", &ref) != B_OK) + return err; + + if (err = message->FindString("name", &name) != B_OK) + return err; + + if (err = entry.SetTo(&ref) != B_OK) + return err; + + entry.GetPath(&path); + path.Append(name); + + if (!(f = fopen(path.Path(), "w"))) + return B_ERROR; + + if (!selection) + { + // write the data to the file + err = fwrite(loggingView->Text(), 1, loggingView->TextLength(), f); + } else { + // find the selected text and write it to a file + int32 start = 0, end = 0; + loggingView->GetSelection(&start, &end); + + BString buffer; + char * buffData = buffer.LockBuffer(end - start + 1); + // copy the selected text from the TextView to the buffer + loggingView->GetText(start, end - start, buffData); + buffer.UnlockBuffer(end - start + 1); + + err = fwrite(buffer.String(), 1, end - start + 1, f); + } + fclose(f); + + return err; +} + + +void +PoorManWindow::DefaultSettings() +{ + // Site Tab + SetIndexFileName("index.html"); + SetDirListFlag(false); + // Logging Tab + SetLogConsoleFlag(true); + SetLogFileFlag(false); + // Advanced Tab + SetMaxConnections(32); + + BDirectory webDir; + if (!webDir.Contains("/boot/home/public_html", B_DIRECTORY_NODE)) + { + BAlert * serverAlert = new BAlert("Error Server", STR_ERR_CANT_START, "OK"); + + BAlert * dirAlert = new BAlert("Error Dir", STR_ERR_WEB_DIR, + "Cancel", "Select", "Default", B_WIDTH_AS_USUAL, B_OFFSET_SPACING); + dirAlert->SetShortcut(0, B_ESCAPE); + int32 buttonIndex = dirAlert->Go(); + + + + // process dirAlert + switch (buttonIndex) + { + case 0: + serverAlert->Go(); + QuitRequested(); + break; + case 1: + serverAlert->Go(); + prefWindow = new PoorManPreferencesWindow(BRect(30.0f, 30.0f, 410.0f, 310.0f), STR_WIN_NAME_PREF); + prefWindow->ShowWebDirFilePanel(); + break; + case 2: + + break; + } + } else { + printf("BDirectory contains: /boot/home/public_html\n"); + SetWebDir("/boot/home/public_html"); + } + +} + +status_t +PoorManWindow::ReadSettings() +{ +} + +status_t +PoorManWindow::SaveSettings() +{ + FILE * f; + size_t s; + + f = fopen(STR_SETTINGS_NEW_FILE_PATH, "wb"); + if (f) + { + // Need to rewrite + /* + //fprintf(f, "%s", web_directory.String()); + s = fwrite(web_directory.String(), sizeof(char), web_directory.Length() + 1, f); + + fprintf(f, "%s", index_file_name.String()); + fwrite(dir_list_flag, sizeof(bool), 1, f); + //fprintf(f, "%uc", dir_list_flag); + + // logging tab + fwrite(log_file_flag, sizeof(bool), 1, f); + //fprintf(f, "%uc", log_console_flag); + fprintf(f, "%uc", log_file_flag); + fprintf(f, "%s", log_path.String()); + // advanced tab + fprintf(f, "%ld", max_connections); + + fprintf(f, "%uc", is_zoomed); + fprintf(f, "%f", last_width); + fprintf(f, "%f", last_height); + */ + } + fclose(f); +} diff --git a/src/apps/poorman/PoorManWindow.h b/src/apps/poorman/PoorManWindow.h new file mode 100644 index 0000000000..6fc2d0bef7 --- /dev/null +++ b/src/apps/poorman/PoorManWindow.h @@ -0,0 +1,142 @@ +/* PoorManWindow.h + * + * Philip Harrison + * Started: 4/25/2004 + * Version: 0.1 + */ + + +#include + +#ifndef POOR_MAN_WINDOW_H +#define POOR_MAN_WINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "PoorManView.h" +#include "PoorManPreferencesWindow.h" + +class PoorManWindow: public BWindow +{ +public: + PoorManWindow(BRect frame); +virtual void MessageReceived(BMessage * message); + +virtual void FrameResized(float width, float height); +virtual bool QuitRequested(); +virtual void Zoom(BPoint origin, float width, float height); + + // ------------------------------------------- + // Public PoorMan Window Methods + void SetDirLabel(const char * name); + void SetHits(uint32 num) { hits = num;} + uint32 GetHits() { return hits; } + status_t SaveConsole(BMessage * message, bool); + status_t SaveSettings(); + + // ------------------------------------------- + // Preferences and Settings + // Site Tab + bool DirListFlag() { return dir_list_flag; } + void SetDirListFlag(bool flag) { dir_list_flag = flag; } + const char * IndexFileName() { return index_file_name.String(); } + void SetIndexFileName(const char * str) { index_file_name.SetTo(str); } + const char * WebDir() { return web_directory.String(); } + void SetWebDir(const char * str) { web_directory.SetTo(str); } + // Logging Tab + bool LogConsoleFlag() { return log_console_flag; } + void SetLogConsoleFlag(bool flag) { log_console_flag = flag; } + bool LogFileFlag() { return log_file_flag; } + void SetLogFileFlag(bool flag) { log_file_flag = flag; } + const char * LogPath() { return log_path.String(); } + void SetLogPath(const char * str) { log_path.SetTo(str); } + // Advanced Tab + int32 MaxConnections() { return max_connections; } + void SetMaxConnections(int32 num) { max_connections = num; } + + +private: + // ------------------------------------------- + // PoorMan Window Methods + status_t ReadSettings(); + void DefaultSettings(); + + void UpdateStatusLabel(bool); + void UpdateHitsLabel(); + +private: + // ------------------------------------------- + // PoorMan Window + PoorManView * mainView; + + // ------------------------------------------- + // Build Menu Methods + BMenu * BuildFileMenu() const; + BMenu * BuildEditMenu() const; + BMenu * BuildControlsMenu() const; + + // -------------------------------------------- + // MenuBar & Menu items + BMenuBar * FileMenuBar; + BMenu * FileMenu; + BMenu * EditMenu; + BMenu * ControlsMenu; + + // -------------------------------------------- + // Status, Hits, Directory + BStringView * statusView; + BStringView * hitsView; + BStringView * dirView; + + bool status; + uint32 hits; + char hitsLabel[25]; + + // -------------------------------------------- + // Logging View + BScrollView * scrollView; + BTextView * loggingView; + // use asctime() for format of [Date/Time]: + + + // ------------------------------------------- + // PoorMan Preference Window + PoorManPreferencesWindow * prefWindow; + + // site tab + BString web_directory; + BString index_file_name; + bool dir_list_flag; + + // logging tab + bool log_console_flag; + bool log_file_flag; + BString log_path; + // advanced tab + int32 max_connections; + + bool is_zoomed; + float last_width; + float last_height; + BRect frame; + BRect setwindow_frame; + + + // File Panels + BFilePanel * saveConsoleFilePanel; + BFilePanel * saveConsoleSelectionFilePanel; + +}; + +#endif diff --git a/src/apps/poorman/StatusSlider.cpp b/src/apps/poorman/StatusSlider.cpp new file mode 100644 index 0000000000..13ce45f092 --- /dev/null +++ b/src/apps/poorman/StatusSlider.cpp @@ -0,0 +1,41 @@ +/* PoorManView.cpp + * + * Philip Harrison + * Started: 5/14/2004 + * Version: 0.1 + */ + + +#include "StatusSlider.h" + +#include + + +StatusSlider::StatusSlider (BRect frame, + const char *name, + const char *label, + char *statusPrefix, + BMessage *message, + int32 minValue, + int32 maxValue) + + : BSlider(frame, + name, + label, + message, + minValue, + maxValue + ), + StatusPrefix(statusPrefix) +{ + temp = str; +} + +char* +StatusSlider::UpdateText() const +{ + + sprintf(temp, "%ld %s", Value(), StatusPrefix); + + return temp; +} \ No newline at end of file diff --git a/src/apps/poorman/StatusSlider.h b/src/apps/poorman/StatusSlider.h new file mode 100644 index 0000000000..f706d6d894 --- /dev/null +++ b/src/apps/poorman/StatusSlider.h @@ -0,0 +1,31 @@ +/* StatusSlider.h + * + * Philip Harrison + * Started: 5/14/2004 + * Version: 0.1 + */ + +#ifndef STATUS_SLIDER +#define STATUS_SLIDER + +#include + + +class StatusSlider: public BSlider +{ +public: + StatusSlider(BRect frame, + const char *name, + const char *label, + char *statusPrefix, + BMessage *message, + int32 minValue, + int32 maxValue); +virtual char* UpdateText() const; +private: + char * StatusPrefix; + char * temp; + char str[128]; +}; + +#endif diff --git a/src/apps/poorman/constants.cpp b/src/apps/poorman/constants.cpp new file mode 100644 index 0000000000..ee80abc7a0 --- /dev/null +++ b/src/apps/poorman/constants.cpp @@ -0,0 +1,132 @@ +#include "constants.h" + +// ------------------------------------------------------ +// PoorMan Window +extern const char* STR_APP_SIG + = "application/x-vnd.OpenBeOS-PoorMan"; + char* STR_APP_NAME + = "PoorMan"; +extern const char* STR_ERR_WEB_DIR + = "You have not yet selected the folder you want PoorMan " + "to publish on the Web. PoorMan can create a " + "\"public_html\" folder in your home folder or you can select " + "one of your own folders to publish.\n\n" + "Do you wish to select a folder to publish on the Web?"; +extern const char* STR_ERR_CANT_START + = "Can't Start the Server"; + +extern const char* STR_MNU_FILE + = "File"; +extern const char* STR_MNU_FILE_SAVE_AS + = "Save Console As..."; +extern const char* STR_MNU_FILE_SAVE_SELECTION + = "Save Console Selections As..."; +extern const char* STR_MNU_FILE_ABOUT + = "About PoorMan"; +extern const char* STR_MNU_FILE_QUIT + = "Quit"; +extern const char* STR_MNU_EDIT + = "Edit"; +extern const char* STR_MNU_EDIT_COPY + = "Copy"; +extern const char* STR_MNU_EDIT_SELECT_ALL + = "Select All"; +extern const char* STR_MNU_EDIT_PREF + = "Preferences..."; +extern const char* STR_MNU_CTRL + = "Controls"; +extern const char* STR_MNU_CTRL_RUN_SERVER + = "Run Server"; +extern const char* STR_MNU_CTRL_CLEAR_HIT_COUNTER + = "Clear Hit Counter"; +extern const char* STR_MNU_CTRL_CLEAR_CONSOLE + = "Clear Console Log"; +extern const char* STR_MNU_CTRL_CLEAR_LOG_FILE + = "Clear Log File"; + +extern const char* STR_FILEPANEL_SAVE_CONSOLE + = "Save Log Console"; +extern const char* STR_FILEPANEL_SAVE_CONSOLE_SELECTION + = "Save Log Console Selection"; +extern const char* STR_TXT_VIEW + = "Logging View"; + +// ------------------------------------------------------ +// Preferences Window + char* STR_WIN_NAME_PREF + = "PoorMan Settings"; + +extern const char* STR_SETTINGS_FILE_PATH + = "/boot/home/config/settings/PoorMan Settings"; +extern const char* STR_SETTINGS_NEW_FILE_PATH + = "/boot/home/config/settings/OBOS PoorMan Settings"; + +extern const char* STR_TAB_SITE + = "Site"; +extern const char* STR_BBX_LOCATION + = "Web Site Location"; +extern const char* STR_TXT_DIRECTORY + = "Web Directory:"; +extern const char* STR_BTN_DIRECTORY + = "Select Web Directory"; +extern const char* STR_TXT_INDEX + = "Index File Name:"; +extern const char* STR_BBX_OPTIONS + = "Web Site Options"; +extern const char* STR_CBX_DIR_LIST + = "Send Directory List if No Index"; +extern const char* STR_CBX_DIR_LIST_LABEL + = "Send Directory List if No Index"; +extern const char* STR_FILEPANEL_SELECT_WEB_DIR + = "Select Web Directory"; + +extern const char* STR_TAB_LOGGING + = "Logging"; +extern const char* STR_BBX_CONSOLE_LOGGING + = "Console Logging"; +extern const char* STR_CBX_LOG_CONSOLE + = "Log to Console"; +extern const char* STR_BBX_FILE_LOGGING + = "File Logging"; +extern const char* STR_CBX_LOG_FILE + = "Log to File"; +extern const char* STR_TXT_LOG_FILE_NAME + = "Log File Name:"; +extern const char* STR_BTN_CREATE_LOG_FILE + = "Create Log File"; +extern const char* STR_FILEPANEL_CREATE_LOG_FILE + = "Create Poor Man Log"; + +extern const char* STR_TAB_ADVANCED + = "Advanced"; +extern const char* STR_BBX_CONNECTION + = "Connections Options"; +extern const char* STR_SLD_LABEL + = "Maximum Simultaneous Connections:"; + char* STR_SLD_STATUS_LABEL + = "connections"; + +extern const char CMD_FILE_SAVE_AS + = 'S'; +extern const char CMD_FILE_QUIT + = 'Q'; +extern const char CMD_EDIT_COPY + = 'C'; +extern const char CMD_EDIT_SELECT_ALL + = 'A'; + +extern const char* STR_ABOUT_TITLE + = "About PoorMan"; +extern const char* STR_ABOUT_BUTTON + = "OK"; +extern const char* STR_ABOUT_DESC + = "Poor Man's Web Server\n" + "Copyright © 2004 Haiku\n" + "All rights reserved.\n\n" + "Written by: Philip Harrison"; + +// -------------------------------- +extern const rgb_color WHITE = { 255, 255, 255, 255 }; +extern const rgb_color GRAY = { 184, 184, 184, 255 }; +extern const rgb_color BACKGROUND_COLOR = { 216, 216, 216, 255 }; +extern const rgb_color BLACK = { 0, 0, 0, 255 }; diff --git a/src/apps/poorman/constants.h b/src/apps/poorman/constants.h new file mode 100644 index 0000000000..797570b077 --- /dev/null +++ b/src/apps/poorman/constants.h @@ -0,0 +1,107 @@ +#ifndef CONSTANTS_H +#define CONSTANTS_H + +#include + +// ------------------------------------------------------ +// BMessages +const int32 MSG_MENU_FILE_SAVE_AS = 'oMSA'; +const int32 MSG_MENU_FILE_SAVE_SELECTION = 'oMSS'; +const int32 MSG_MENU_EDIT_COPY = 'oMCP'; +const int32 MSG_MENU_EDIT_SELECT_ALL = 'oMSE'; +const int32 MSG_MENU_EDIT_PREF = 'oMPR'; +const int32 MSG_MENU_CTRL_RUN = 'oMRN'; +const int32 MSG_MENU_CTRL_CLEAR_HIT = 'oMCH'; +const int32 MSG_MENU_CTRL_CLEAR_CONSOLE = 'oMCC'; +const int32 MSG_MENU_CTRL_CLEAR_LOG = 'oMCL'; +const int32 MSG_FILE_PANEL_SAVE_CONSOLE = 'oSAV'; +const int32 MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION = 'SAVS'; + +// BMessages Preferences Window +const int32 MSG_PREF_BTN_DONE = 'oPBD'; +const int32 MSG_PREF_BTN_CANCEL = 'oPBC'; + // Site Tab +const int32 MSG_PREF_SITE_BTN_SELECT = 'PSBS'; +const int32 MSG_PREF_SITE_CBX_INDEX = 'PSCI'; +const int32 MSG_FILE_PANEL_SELECT_WEB_DIR = 'oSWD'; + // Logging Tab +const int32 MSG_PREF_LOG_CBX_CONSOLE = 'PLCC'; +const int32 MSG_PREF_LOG_CBX_FILE = 'PLCF'; +const int32 MSG_PREF_LOG_BTN_CREATE_FILE = 'PLBF'; +const int32 MSG_FILE_PANEL_CREATE_LOG_FILE = 'oCLF'; + // Advanced Tab +const int32 MSG_PREF_ADV_SLD_MAX_CONNECTION = 'PASM'; + +// ------------------------------------------------------ +// PoorMan Window +extern const char* STR_APP_SIG; +extern char* STR_APP_NAME; +extern const char* STR_ERR_WEB_DIR; // Alert Box +extern const char* STR_ERR_CANT_START; + +extern const char* STR_MNU_FILE; +extern const char* STR_MNU_FILE_SAVE_AS; +extern const char* STR_MNU_FILE_SAVE_SELECTION; +extern const char* STR_MNU_FILE_ABOUT; +extern const char* STR_MNU_FILE_QUIT; +extern const char* STR_MNU_EDIT; +extern const char* STR_MNU_EDIT_COPY; +extern const char* STR_MNU_EDIT_SELECT_ALL; +extern const char* STR_MNU_EDIT_PREF; +extern const char* STR_MNU_CTRL; +extern const char* STR_MNU_CTRL_RUN_SERVER; +extern const char* STR_MNU_CTRL_CLEAR_HIT_COUNTER; +extern const char* STR_MNU_CTRL_CLEAR_CONSOLE; +extern const char* STR_MNU_CTRL_CLEAR_LOG_FILE; + +extern const char* STR_FILEPANEL_SAVE_CONSOLE; +extern const char* STR_FILEPANEL_SAVE_CONSOLE_SELECTION; +extern const char* STR_TXT_VIEW; + +// ------------------------------------------------------ +// Preferences Window +extern char* STR_WIN_NAME_PREF; +extern const char* STR_SETTINGS_FILE_PATH; +extern const char* STR_SETTINGS_NEW_FILE_PATH; + + +extern const char* STR_TAB_SITE; +extern const char* STR_BBX_LOCATION; +extern const char* STR_TXT_DIRECTORY; +extern const char* STR_BTN_DIRECTORY; +extern const char* STR_TXT_INDEX; +extern const char* STR_BBX_OPTIONS; +extern const char* STR_CBX_DIR_LIST; +extern const char* STR_CBX_DIR_LIST_LABEL; +extern const char* STR_FILEPANEL_SELECT_WEB_DIR; + +extern const char* STR_TAB_LOGGING; +extern const char* STR_BBX_CONSOLE_LOGGING; +extern const char* STR_CBX_LOG_CONSOLE; +extern const char* STR_BBX_FILE_LOGGING; +extern const char* STR_CBX_LOG_FILE; +extern const char* STR_TXT_LOG_FILE_NAME; +extern const char* STR_BTN_CREATE_LOG_FILE; +extern const char* STR_FILEPANEL_CREATE_LOG_FILE; + +extern const char* STR_TAB_ADVANCED; +extern const char* STR_BBX_CONNECTION; +extern const char* STR_SLD_LABEL; +extern char* STR_SLD_STATUS_LABEL; + +extern const char CMD_FILE_SAVE_AS; +extern const char CMD_FILE_QUIT; +extern const char CMD_EDIT_COPY; +extern const char CMD_EDIT_SELECT_ALL; + +extern const char* STR_ABOUT_TITLE; +extern const char* STR_ABOUT_DESC; +extern const char* STR_ABOUT_BUTTON; + + +/* Colors */ +extern const rgb_color WHITE; +extern const rgb_color GRAY; +extern const rgb_color BACKGROUND_COLOR; +extern const rgb_color BLACK; +#endif