PoorMan: Close the application when you choose Cancel on first launch.

* If you choose cancel on that first dialog, also don't save a config file
* Also fixes the button labelling in the preference panel (several were clipped)
* Allow the user to cancel the selection of the web folder and return to the initial dialog (to choose Default, for example)
* Make the preference panel closable with escape key
* Multiple coding style changes

(Ref: Ticket #4255)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32486 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Saint-Pierre
2009-08-18 00:32:57 +00:00
parent f940f1e99c
commit d939e03d05
8 changed files with 345 additions and 248 deletions
+41 -4
View File
@@ -26,15 +26,16 @@ PoorManApplication::PoorManApplication()
if (mainWindow->ReadSettings() != B_OK) { if (mainWindow->ReadSettings() != B_OK) {
if (webDir.SetTo(STR_DEFAULT_WEB_DIRECTORY) != B_OK) if (webDir.SetTo(STR_DEFAULT_WEB_DIRECTORY) != B_OK)
mainWindow->DefaultSettings(); mainWindow->DefaultSettings();
else
PostMessage(kStartServer);
} else { } else {
if (webDir.SetTo(mainWindow->WebDir()) != B_OK) if (webDir.SetTo(mainWindow->WebDir()) != B_OK)
mainWindow->DefaultSettings(); mainWindow->DefaultSettings();
else
PostMessage(kStartServer);
}
} }
mainWindow->StartServer();
mainWindow->SetDirLabel(mainWindow->WebDir());
mainWindow->Show();
}
void void
PoorManApplication::AboutRequested() PoorManApplication::AboutRequested()
@@ -43,3 +44,39 @@ PoorManApplication::AboutRequested()
STR_ABOUT_DESC, STR_ABOUT_BUTTON); STR_ABOUT_DESC, STR_ABOUT_BUTTON);
aboutBox->Go(); aboutBox->Go();
} }
void
PoorManApplication::MessageReceived(BMessage *message)
{
switch (message->what) {
case MSG_FILE_PANEL_SELECT_WEB_DIR:
mainWindow->MessageReceived(message);
break;
case kStartServer:
mainWindow->StartServer();
mainWindow->SetDirLabel(mainWindow->WebDir());
mainWindow->Show();
break;
case B_CANCEL: {
BDirectory webDir;
if (mainWindow->ReadSettings() != B_OK) {
if (webDir.SetTo(STR_DEFAULT_WEB_DIRECTORY) != B_OK)
mainWindow->DefaultSettings();
else
mainWindow->StartServer();
} else {
if (webDir.SetTo(mainWindow->WebDir()) != B_OK)
mainWindow->DefaultSettings();
else
mainWindow->StartServer();
}
}
break;
default:
BApplication::MessageReceived(message);
}
}
+1
View File
@@ -20,6 +20,7 @@ class PoorManApplication: public BApplication
public: public:
PoorManApplication(); PoorManApplication();
void AboutRequested(); void AboutRequested();
virtual void MessageReceived(BMessage *message);
PoorManWindow * GetPoorManWindow() { return mainWindow; } PoorManWindow * GetPoorManWindow() { return mainWindow; }
private: private:
PoorManWindow * mainWindow; PoorManWindow * mainWindow;
+3 -2
View File
@@ -67,7 +67,7 @@ PoorManLoggingView::PoorManLoggingView(BRect rect, const char *name)
logFileName = new BTextControl(tempRect, "File Name", STR_TXT_LOG_FILE_NAME, NULL, NULL); logFileName = new BTextControl(tempRect, "File Name", STR_TXT_LOG_FILE_NAME, NULL, NULL);
logFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); logFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
logFileName->SetDivider(73.0); logFileName->SetDivider(fileLogging->StringWidth(STR_TXT_LOG_FILE_NAME) + 8.0f);
SetLogFileName(win->LogPath()); SetLogFileName(win->LogPath());
fileLogging->AddChild(logFileName); fileLogging->AddChild(logFileName);
@@ -75,7 +75,8 @@ PoorManLoggingView::PoorManLoggingView(BRect rect, const char *name)
BRect createLogFileRect; BRect createLogFileRect;
createLogFileRect.top = tempRect.bottom + 13.0; createLogFileRect.top = tempRect.bottom + 13.0;
createLogFileRect.right = tempRect.right + 2.0; createLogFileRect.right = tempRect.right + 2.0;
createLogFileRect.left = createLogFileRect.right - 87.0; createLogFileRect.left = createLogFileRect.right
- fileLogging->StringWidth("Create Log File") - 24.0;
createLogFileRect.bottom = createLogFileRect.top + 19.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)); createLogFile = new BButton(createLogFileRect, "Create Log File", STR_BTN_CREATE_LOG_FILE, new BMessage(MSG_PREF_LOG_BTN_CREATE_FILE));
+42 -31
View File
@@ -17,11 +17,11 @@
#include "PoorManServer.h" #include "PoorManServer.h"
PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name) PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name)
: BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE), : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE
| B_CLOSE_ON_ESCAPE),
webDirFilePanel(NULL), webDirFilePanel(NULL),
logFilePanel(NULL) logFilePanel(NULL)
{ {
frame = Bounds(); frame = Bounds();
prefView = new PoorManView(frame, STR_WIN_NAME_PREF); prefView = new PoorManView(frame, STR_WIN_NAME_PREF);
@@ -30,7 +30,6 @@ PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name)
AddChild(prefView); AddChild(prefView);
// Button View // Button View
BRect buttonRect; BRect buttonRect;
buttonRect = Bounds(); buttonRect = Bounds();
@@ -42,26 +41,27 @@ PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name)
// Buttons // Buttons
float buttonTop = 0.0f; float buttonTop = 0.0f;
float buttonWidth = 52.0f;
float buttonHeight = 26.0f; float buttonHeight = 26.0f;
float buttonLeft = 265.0f;
BRect button1; float widthCancel = prefView->StringWidth("Cancel") + 24.0f;
button1 = buttonView->Bounds(); float widthDone = prefView->StringWidth("Done") + 24.0f;
button1.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight);
cancelButton = new BButton(button1, "Cancel Button", "Cancel", new BMessage(MSG_PREF_BTN_CANCEL));
buttonLeft = 325.0f; float gap = 5.0f;
BRect button2;
button2 = buttonView->Bounds(); BRect button1(prefView->Bounds().Width() - 2 * gap - widthCancel
button2.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight); - widthDone, buttonTop, prefView->Bounds().Width() - 2 * gap - widthDone,
doneButton = new BButton(button2, "Done Button", "Done", new BMessage(MSG_PREF_BTN_DONE)); buttonTop + buttonHeight);
cancelButton = new BButton(button1, "Cancel Button", "Cancel",
new BMessage(MSG_PREF_BTN_CANCEL));
BRect button2(prefView->Bounds().Width() - gap - widthDone, buttonTop,
prefView->Bounds().Width() - gap, buttonTop + buttonHeight);
doneButton = new BButton(button2, "Done Button", "Done",
new BMessage(MSG_PREF_BTN_DONE));
buttonView->AddChild(cancelButton); buttonView->AddChild(cancelButton);
buttonView->AddChild(doneButton); buttonView->AddChild(doneButton);
// Create tabs // Create tabs
BRect r; BRect r;
r = Bounds(); r = Bounds();
@@ -115,17 +115,16 @@ PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name)
logFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Create"); logFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Create");
change_title = logFilePanel->Window(); change_title = logFilePanel->Window();
change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE); change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE);
Show();
} }
PoorManPreferencesWindow::~PoorManPreferencesWindow() PoorManPreferencesWindow::~PoorManPreferencesWindow()
{ {
delete logFilePanel; delete logFilePanel;
delete webDirFilePanel; delete webDirFilePanel;
} }
void void
PoorManPreferencesWindow::MessageReceived(BMessage* message) PoorManPreferencesWindow::MessageReceived(BMessage* message)
{ {
@@ -136,10 +135,12 @@ PoorManPreferencesWindow::MessageReceived(BMessage* message)
win = ((PoorManApplication *)be_app)->GetPoorManWindow(); win = ((PoorManApplication *)be_app)->GetPoorManWindow();
server = win->GetServer(); server = win->GetServer();
PRINT(("Pref Window: sendDir CheckBox: %d\n", siteView->SendDirValue())); PRINT(("Pref Window: sendDir CheckBox: %d\n",
siteView->SendDirValue()));
server->SetListDir(siteView->SendDirValue()); server->SetListDir(siteView->SendDirValue());
win->SetDirListFlag(siteView->SendDirValue()); win->SetDirListFlag(siteView->SendDirValue());
PRINT(("Pref Window: indexFileName TextControl: %s\n", siteView->IndexFileName())); PRINT(("Pref Window: indexFileName TextControl: %s\n",
siteView->IndexFileName()));
if (server->SetIndexName(siteView->IndexFileName()) == B_OK) if (server->SetIndexName(siteView->IndexFileName()) == B_OK)
win->SetIndexFileName(siteView->IndexFileName()); win->SetIndexFileName(siteView->IndexFileName());
PRINT(("Pref Window: webDir: %s\n", siteView->WebDir())); PRINT(("Pref Window: webDir: %s\n", siteView->WebDir()));
@@ -148,17 +149,21 @@ PoorManPreferencesWindow::MessageReceived(BMessage* message)
win->SetDirLabel(siteView->WebDir()); win->SetDirLabel(siteView->WebDir());
} }
PRINT(("Pref Window: logConsole CheckBox: %d\n", loggingView->LogConsoleValue())); PRINT(("Pref Window: logConsole CheckBox: %d\n",
loggingView->LogConsoleValue()));
win->SetLogConsoleFlag(loggingView->LogConsoleValue()); win->SetLogConsoleFlag(loggingView->LogConsoleValue());
PRINT(("Pref Window: logFile CheckBox: %d\n", loggingView->LogFileValue())); PRINT(("Pref Window: logFile CheckBox: %d\n",
loggingView->LogFileValue()));
win->SetLogFileFlag(loggingView->LogFileValue()); win->SetLogFileFlag(loggingView->LogFileValue());
PRINT(("Pref Window: logFileName: %s\n", loggingView->LogFileName())); PRINT(("Pref Window: logFileName: %s\n",
loggingView->LogFileName()));
win->SetLogPath(loggingView->LogFileName()); win->SetLogPath(loggingView->LogFileName());
PRINT(("Pref Window: MaxConnections Slider: %ld\n", advancedView->MaxSimultaneousConnections())); PRINT(("Pref Window: MaxConnections Slider: %ld\n",
advancedView->MaxSimultaneousConnections()));
server->SetMaxConns(advancedView->MaxSimultaneousConnections()); server->SetMaxConns(advancedView->MaxSimultaneousConnections());
win->SetMaxConnections((int16)advancedView->MaxSimultaneousConnections()); win->SetMaxConnections(
(int16)advancedView->MaxSimultaneousConnections());
if (Lock()) if (Lock())
Quit(); Quit();
@@ -169,6 +174,8 @@ PoorManPreferencesWindow::MessageReceived(BMessage* message)
break; break;
case MSG_PREF_SITE_BTN_SELECT: case MSG_PREF_SITE_BTN_SELECT:
// Select the Web Directory, root directory to look in. // Select the Web Directory, root directory to look in.
webDirFilePanel->SetTarget(this);
webDirFilePanel->SetMessage(new BMessage(MSG_FILE_PANEL_SELECT_WEB_DIR));
if (!webDirFilePanel->IsShowing()) if (!webDirFilePanel->IsShowing())
webDirFilePanel->Show(); webDirFilePanel->Show();
break; break;
@@ -190,13 +197,13 @@ PoorManPreferencesWindow::MessageReceived(BMessage* message)
max_connections = advancedView->MaxSimultaneousConnections(); max_connections = advancedView->MaxSimultaneousConnections();
PRINT(("Max Connections: %ld\n", max_connections)); PRINT(("Max Connections: %ld\n", max_connections));
break; break;
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
} }
} }
void void
PoorManPreferencesWindow::SelectWebDir(BMessage * message) PoorManPreferencesWindow::SelectWebDir(BMessage * message)
{ {
@@ -223,16 +230,19 @@ PoorManPreferencesWindow::SelectWebDir(BMessage * message)
bool temp; bool temp;
if (message->FindBool("Default Dialog", &temp) == B_OK) { if (message->FindBool("Default Dialog", &temp) == B_OK) {
PoorManWindow* win = ((PoorManApplication *)be_app)->GetPoorManWindow(); PoorManWindow* win = ((PoorManApplication *)be_app)->GetPoorManWindow();
win->StartServer();
if (win->GetServer()->SetWebDir(siteView->WebDir()) == B_OK) { if (win->GetServer()->SetWebDir(siteView->WebDir()) == B_OK) {
win->SetWebDir(siteView->WebDir()); win->SetWebDir(siteView->WebDir());
win->SetDirLabel(siteView->WebDir()); win->SetDirLabel(siteView->WebDir());
win->SaveSettings();
win->Show();
} }
win->StartServer();
if (Lock()) if (Lock())
Quit(); Quit();
} }
} }
void void
PoorManPreferencesWindow::CreateLogFile(BMessage * message) PoorManPreferencesWindow::CreateLogFile(BMessage * message)
{ {
@@ -255,8 +265,7 @@ PoorManPreferencesWindow::CreateLogFile(BMessage * message)
path.Append(name); path.Append(name);
PRINT(("Log File: %s\n", path.Path())); PRINT(("Log File: %s\n", path.Path()));
if (err == B_OK) if (err == B_OK) {
{
loggingView->SetLogFileName(path.Path()); loggingView->SetLogFileName(path.Path());
loggingView->SetLogFileValue(true); loggingView->SetLogFileValue(true);
} }
@@ -264,6 +273,7 @@ PoorManPreferencesWindow::CreateLogFile(BMessage * message)
// mark the checkbox // mark the checkbox
} }
/*A special version for "the default dialog", don't use it in MessageReceived()*/ /*A special version for "the default dialog", don't use it in MessageReceived()*/
void void
PoorManPreferencesWindow::ShowWebDirFilePanel() PoorManPreferencesWindow::ShowWebDirFilePanel()
@@ -271,6 +281,7 @@ PoorManPreferencesWindow::ShowWebDirFilePanel()
BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR); BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR);
message.AddBool("Default Dialog", true); message.AddBool("Default Dialog", true);
webDirFilePanel->SetTarget(be_app);
webDirFilePanel->SetMessage(&message); webDirFilePanel->SetMessage(&message);
if (!webDirFilePanel->IsShowing()) if (!webDirFilePanel->IsShowing())
webDirFilePanel->Show(); webDirFilePanel->Show();
+21 -6
View File
@@ -28,6 +28,7 @@
#include "PoorManWindow.h" #include "PoorManWindow.h"
#include "libhttpd/libhttpd.h" #include "libhttpd/libhttpd.h"
PoorManServer::PoorManServer(const char* webDir, PoorManServer::PoorManServer(const char* webDir,
int32 maxConns, bool listDir,const char* idxName) int32 maxConns, bool listDir,const char* idxName)
:fIsRunning(false), :fIsRunning(false),
@@ -70,6 +71,7 @@ PoorManServer::PoorManServer(const char* webDir,
pthread_rwlock_init(&fIndexNameLock, NULL); pthread_rwlock_init(&fIndexNameLock, NULL);
} }
PoorManServer::~PoorManServer() PoorManServer::~PoorManServer()
{ {
Stop(); Stop();
@@ -79,6 +81,7 @@ PoorManServer::~PoorManServer()
pthread_rwlock_destroy(&fIndexNameLock); pthread_rwlock_destroy(&fIndexNameLock);
} }
status_t PoorManServer::Run() status_t PoorManServer::Run()
{ {
if (chdir(fHttpdServer->cwd) == -1) { if (chdir(fHttpdServer->cwd) == -1) {
@@ -115,6 +118,7 @@ status_t PoorManServer::Run()
return B_OK; return B_OK;
} }
status_t PoorManServer::Stop() status_t PoorManServer::Stop()
{ {
if (fIsRunning) { if (fIsRunning) {
@@ -124,6 +128,7 @@ status_t PoorManServer::Stop()
return B_OK; return B_OK;
} }
/*The Web Dir is not changed if an error occured. /*The Web Dir is not changed if an error occured.
*/ */
status_t PoorManServer::SetWebDir(const char* webDir) status_t PoorManServer::SetWebDir(const char* webDir)
@@ -152,18 +157,21 @@ status_t PoorManServer::SetWebDir(const char* webDir)
return B_OK; return B_OK;
} }
status_t PoorManServer::SetMaxConns(int32 count) status_t PoorManServer::SetMaxConns(int32 count)
{ {
fMaxConns = count; fMaxConns = count;
return B_OK; return B_OK;
} }
status_t PoorManServer::SetListDir(bool listDir) status_t PoorManServer::SetListDir(bool listDir)
{ {
fHttpdServer->do_list_dir = (listDir?1:0); fHttpdServer->do_list_dir = (listDir?1:0);
return B_OK; return B_OK;
} }
status_t PoorManServer::SetIndexName(const char* idxName) status_t PoorManServer::SetIndexName(const char* idxName)
{ {
size_t length = strlen(idxName); size_t length = strlen(idxName);
@@ -188,6 +196,7 @@ status_t PoorManServer::SetIndexName(const char* idxName)
return B_OK; return B_OK;
} }
int32 PoorManServer::_Listener(void* data) int32 PoorManServer::_Listener(void* data)
{ {
PRINT(("The listener thread is working.\n")); PRINT(("The listener thread is working.\n"));
@@ -210,11 +219,13 @@ int32 PoorManServer::_Listener(void* data)
delete hc; delete hc;
s->fIsRunning = false; s->fIsRunning = false;
return -1; return -1;
case GC_NO_MORE: //should not happen, since we have a blocking socket case GC_NO_MORE:
//should not happen, since we have a blocking socket
httpd_destroy_conn(hc); httpd_destroy_conn(hc);
continue; continue;
break; break;
default: //shouldn't happen default:
//shouldn't happen
continue; continue;
break; break;
} }
@@ -246,6 +257,7 @@ int32 PoorManServer::_Listener(void* data)
return 0; return 0;
} }
int32 PoorManServer::_Worker(void* data) int32 PoorManServer::_Worker(void* data)
{ {
static const struct timeval kTimeVal = {60, 0}; static const struct timeval kTimeVal = {60, 0};
@@ -318,8 +330,6 @@ int32 PoorManServer::_Worker(void* data)
case METHOD_POST: case METHOD_POST:
s->_HandlePost(hc); s->_HandlePost(hc);
break; break;
default:
break;
} }
cleanup: ; cleanup: ;
@@ -331,6 +341,7 @@ cleanup: ;
return 0; return 0;
} }
status_t PoorManServer::_HandleGet(httpd_conn* hc) status_t PoorManServer::_HandleGet(httpd_conn* hc)
{ {
PRINT(("HandleGet() called\n")); PRINT(("HandleGet() called\n"));
@@ -354,8 +365,8 @@ status_t PoorManServer::_HandleGet(httpd_conn* hc)
length = hc->sb.st_size; length = hc->sb.st_size;
static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->SetHits( static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->SetHits(
static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->GetHits()+1 static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->GetHits()
); + 1);
log.SetTo("Sending file: "); log.SetTo("Sending file: ");
if (pthread_rwlock_rdlock(&fWebDirLock) == 0) { if (pthread_rwlock_rdlock(&fWebDirLock) == 0) {
@@ -397,6 +408,7 @@ status_t PoorManServer::_HandleGet(httpd_conn* hc)
return B_OK; return B_OK;
} }
status_t PoorManServer::_HandleHead(httpd_conn* hc) status_t PoorManServer::_HandleHead(httpd_conn* hc)
{ {
int retval = send(hc->conn_fd,hc->response,hc->responselen,0); int retval = send(hc->conn_fd,hc->response,hc->responselen,0);
@@ -405,18 +417,21 @@ status_t PoorManServer::_HandleHead(httpd_conn* hc)
return B_OK; return B_OK;
} }
status_t PoorManServer::_HandlePost(httpd_conn* hc) status_t PoorManServer::_HandlePost(httpd_conn* hc)
{ {
//not implemented //not implemented
return B_OK; return B_OK;
} }
pthread_rwlock_t* get_web_dir_lock() pthread_rwlock_t* get_web_dir_lock()
{ {
return static_cast<PoorManApplication*>(be_app)-> return static_cast<PoorManApplication*>(be_app)->
GetPoorManWindow()->GetServer()->GetWebDirLock(); GetPoorManWindow()->GetServer()->GetWebDirLock();
} }
pthread_rwlock_t* get_index_name_lock() pthread_rwlock_t* get_index_name_lock()
{ {
return static_cast<PoorManApplication*>(be_app)-> return static_cast<PoorManApplication*>(be_app)->
+9 -4
View File
@@ -61,7 +61,8 @@ PoorManSiteView::PoorManSiteView(BRect rect, const char *name)
webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0; webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0;
// Web Directory Text Control // Web Directory Text Control
webDir = new BTextControl(webSiteLocationRect, "Web Dir", STR_TXT_DIRECTORY, NULL, NULL); webDir = new BTextControl(webSiteLocationRect, "Web Dir",
STR_TXT_DIRECTORY, NULL, NULL);
webDir->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); webDir->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
webDir->SetDivider(80.0); webDir->SetDivider(80.0);
SetWebDir(win->WebDir()); SetWebDir(win->WebDir());
@@ -69,12 +70,15 @@ PoorManSiteView::PoorManSiteView(BRect rect, const char *name)
// Select Web Directory Button // Select Web Directory Button
BRect selectWebDirRect; BRect selectWebDirRect;
selectWebDirRect.top = webSiteLocationRect.bottom + 5.0; selectWebDirRect.top = webSiteLocationRect.bottom + 5.0;
selectWebDirRect.right = webSiteLocationRect.right + 2.0; selectWebDirRect.right = webSiteLocationRect.right + 2.0;
selectWebDirRect.left = selectWebDirRect.right - 123.0; selectWebDirRect.left = selectWebDirRect.right
- webSiteLocation->StringWidth("Select Web Dir") - 24.0;
selectWebDirRect.bottom = selectWebDirRect.top + 19.0; selectWebDirRect.bottom = selectWebDirRect.top + 19.0;
selectWebDir = new BButton(selectWebDirRect, "Select Web Dir", STR_BTN_DIRECTORY, new BMessage(MSG_PREF_SITE_BTN_SELECT)); selectWebDir = new BButton(selectWebDirRect, "Select Web Dir",
STR_BTN_DIRECTORY, new BMessage(MSG_PREF_SITE_BTN_SELECT));
webSiteLocation->AddChild(selectWebDir); webSiteLocation->AddChild(selectWebDir);
// Index File Name Text Control // Index File Name Text Control
@@ -82,7 +86,8 @@ PoorManSiteView::PoorManSiteView(BRect rect, const char *name)
webSiteLocationRect.top += 63.0; webSiteLocationRect.top += 63.0;
webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0; webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0;
indexFileName = new BTextControl(webSiteLocationRect, "Index File Name", STR_TXT_INDEX, NULL, NULL); indexFileName = new BTextControl(webSiteLocationRect,
"Index File Name", STR_TXT_INDEX, NULL, NULL);
indexFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); indexFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
indexFileName->SetDivider(80.0); indexFileName->SetDivider(80.0);
SetIndexFileName(win->IndexFileName()); SetIndexFileName(win->IndexFileName());
+57 -33
View File
@@ -33,6 +33,7 @@
#include "PoorManLogger.h" #include "PoorManLogger.h"
#include "constants.h" #include "constants.h"
PoorManWindow::PoorManWindow(BRect frame) PoorManWindow::PoorManWindow(BRect frame)
: BWindow(frame, STR_APP_NAME, B_TITLED_WINDOW, 0), : BWindow(frame, STR_APP_NAME, B_TITLED_WINDOW, 0),
status(false), hits(0), prefWindow(NULL), fLogFile(NULL), fServer(NULL) status(false), hits(0), prefWindow(NULL), fLogFile(NULL), fServer(NULL)
@@ -188,8 +189,8 @@ PoorManWindow::PoorManWindow(BRect frame)
NULL, NULL,
B_FILE_NODE, B_FILE_NODE,
false, false,
new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE) new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE));
);
change_title = saveConsoleFilePanel->Window(); change_title = saveConsoleFilePanel->Window();
change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE); change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE);
@@ -199,8 +200,8 @@ PoorManWindow::PoorManWindow(BRect frame)
NULL, NULL,
B_FILE_NODE, B_FILE_NODE,
false, false,
new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION) new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION));
);
change_title = saveConsoleSelectionFilePanel->Window(); change_title = saveConsoleSelectionFilePanel->Window();
change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE_SELECTION); change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE_SELECTION);
@@ -210,6 +211,7 @@ PoorManWindow::PoorManWindow(BRect frame)
pthread_rwlock_init(&fLogFileLock, NULL); pthread_rwlock_init(&fLogFileLock, NULL);
} }
PoorManWindow::~PoorManWindow() PoorManWindow::~PoorManWindow()
{ {
delete fServer; delete fServer;
@@ -218,6 +220,7 @@ PoorManWindow::~PoorManWindow()
pthread_rwlock_destroy(&fLogFileLock); pthread_rwlock_destroy(&fLogFileLock);
} }
void void
PoorManWindow::MessageReceived(BMessage* message) PoorManWindow::MessageReceived(BMessage* message)
{ {
@@ -236,11 +239,14 @@ PoorManWindow::MessageReceived(BMessage* message)
printf("FilePanel: Save Console Selection\n"); printf("FilePanel: Save Console Selection\n");
SaveConsole(message, true); SaveConsole(message, true);
break; break;
case MSG_FILE_PANEL_SELECT_WEB_DIR:
prefWindow->MessageReceived(message);
break;
case MSG_MENU_EDIT_PREF: case MSG_MENU_EDIT_PREF:
prefWindow = new PoorManPreferencesWindow( prefWindow = new PoorManPreferencesWindow(
setwindow_frame, setwindow_frame,
STR_WIN_NAME_PREF STR_WIN_NAME_PREF);
); prefWindow->Show();
break; break;
case MSG_MENU_CTRL_RUN: case MSG_MENU_CTRL_RUN:
if (status) if (status)
@@ -261,8 +267,7 @@ PoorManWindow::MessageReceived(BMessage* message)
f = fopen(log_path.String(), "w"); f = fopen(log_path.String(), "w");
fclose(f); fclose(f);
break; break;
case MSG_LOG: case MSG_LOG: {
{
if (!log_console_flag && !log_file_flag) if (!log_console_flag && !log_file_flag)
break; break;
@@ -280,10 +285,12 @@ PoorManWindow::MessageReceived(BMessage* message)
time = -1; time = -1;
else else
time = *static_cast<const time_t*>(pointer); time = *static_cast<const time_t*>(pointer);
if (message->FindData("in_addr_t", B_ANY_TYPE, &pointer, &size) != B_OK) if (message->FindData("in_addr_t", B_ANY_TYPE, &pointer, &size) != B_OK)
address = INADDR_NONE; address = INADDR_NONE;
else else
address = *static_cast<const in_addr_t*>(pointer); address = *static_cast<const in_addr_t*>(pointer);
if (message->FindData("rgb_color", B_RGB_COLOR_TYPE, &pointer, &size) != B_OK) if (message->FindData("rgb_color", B_RGB_COLOR_TYPE, &pointer, &size) != B_OK)
color = BLACK; color = BLACK;
else else
@@ -344,6 +351,7 @@ PoorManWindow::MessageReceived(BMessage* message)
} }
} }
void void
PoorManWindow::FrameMoved(BPoint origin) PoorManWindow::FrameMoved(BPoint origin)
{ {
@@ -351,16 +359,17 @@ PoorManWindow::FrameMoved(BPoint origin)
frame.top = origin.y; frame.top = origin.y;
} }
void void
PoorManWindow::FrameResized(float width, float height) PoorManWindow::FrameResized(float width, float height)
{ {
if (is_zoomed) if (is_zoomed) {
{
last_width = width; last_width = width;
last_height = height; last_height = height;
} }
} }
bool bool
PoorManWindow::QuitRequested() PoorManWindow::QuitRequested()
{ {
@@ -395,21 +404,22 @@ PoorManWindow::QuitRequested()
return true; return true;
} }
void void
PoorManWindow::Zoom(BPoint origin, float width, float height) PoorManWindow::Zoom(BPoint origin, float width, float height)
{ {
if (is_zoomed) if (is_zoomed) {
{ // Change to the Minimal size // Change to the Minimal size
is_zoomed = false; is_zoomed = false;
ResizeTo(318, 53); ResizeTo(318, 53);
} } else {
else // Change to the Zoomed size
{ // Change to the Zoomed size
is_zoomed = true; is_zoomed = true;
ResizeTo(last_width, last_height); ResizeTo(last_width, last_height);
} }
} }
void void
PoorManWindow::SetHits(uint32 num) PoorManWindow::SetHits(uint32 num)
{ {
@@ -417,8 +427,10 @@ PoorManWindow::SetHits(uint32 num)
UpdateHitsLabel(); UpdateHitsLabel();
} }
// Private: Methods ------------------------------------------ // Private: Methods ------------------------------------------
BMenu * BMenu *
PoorManWindow::BuildFileMenu() const PoorManWindow::BuildFileMenu() const
{ {
@@ -447,6 +459,7 @@ PoorManWindow::BuildFileMenu() const
return ptrFileMenu; return ptrFileMenu;
} }
BMenu * BMenu *
PoorManWindow::BuildEditMenu() const PoorManWindow::BuildEditMenu() const
{ {
@@ -475,6 +488,7 @@ PoorManWindow::BuildEditMenu() const
return ptrEditMenu; return ptrEditMenu;
} }
BMenu * BMenu *
PoorManWindow::BuildControlsMenu() const PoorManWindow::BuildControlsMenu() const
{ {
@@ -502,24 +516,24 @@ PoorManWindow::BuildControlsMenu() const
return ptrControlMenu; return ptrControlMenu;
} }
void void
PoorManWindow::SetDirLabel(const char * name) PoorManWindow::SetDirLabel(const char * name)
{ {
BString dirPath("Directory: "); BString dirPath("Directory: ");
dirPath.Append(name); dirPath.Append(name);
if (Lock()) if (Lock()) {
{
dirView->SetText(dirPath.String()); dirView->SetText(dirPath.String());
Unlock(); Unlock();
} }
} }
void void
PoorManWindow::UpdateStatusLabelAndMenuItem() PoorManWindow::UpdateStatusLabelAndMenuItem()
{ {
if (Lock()) if (Lock()) {
{
if (status) if (status)
statusView->SetText("Status: Running"); statusView->SetText("Status: Running");
else else
@@ -529,11 +543,11 @@ PoorManWindow::UpdateStatusLabelAndMenuItem()
} }
} }
void void
PoorManWindow::UpdateHitsLabel() PoorManWindow::UpdateHitsLabel()
{ {
if (Lock()) if (Lock()) {
{
sprintf(hitsLabel, "Hits: %lu", GetHits()); sprintf(hitsLabel, "Hits: %lu", GetHits());
hitsView->SetText(hitsLabel); hitsView->SetText(hitsLabel);
@@ -541,6 +555,7 @@ PoorManWindow::UpdateHitsLabel()
} }
} }
status_t status_t
PoorManWindow::SaveConsole(BMessage * message, bool selection) PoorManWindow::SaveConsole(BMessage * message, bool selection)
{ {
@@ -566,8 +581,7 @@ PoorManWindow::SaveConsole(BMessage * message, bool selection)
if (!(f = fopen(path.Path(), "w"))) if (!(f = fopen(path.Path(), "w")))
return B_ERROR; return B_ERROR;
if (!selection) if (!selection) {
{
// write the data to the file // write the data to the file
err = fwrite(loggingView->Text(), 1, loggingView->TextLength(), f); err = fwrite(loggingView->Text(), 1, loggingView->TextLength(), f);
} else { } else {
@@ -600,25 +614,31 @@ PoorManWindow::DefaultSettings()
switch (buttonIndex) { switch (buttonIndex) {
case 0: case 0:
SetWebDir(""); if (Lock())
Quit();
be_app_messenger.SendMessage(B_QUIT_REQUESTED);
break; break;
case 1: case 1:
prefWindow = new PoorManPreferencesWindow( prefWindow = new PoorManPreferencesWindow(
setwindow_frame, setwindow_frame,
STR_WIN_NAME_PREF STR_WIN_NAME_PREF);
);
prefWindow->ShowWebDirFilePanel(); prefWindow->ShowWebDirFilePanel();
break; break;
case 2: case 2:
if (create_directory(STR_DEFAULT_WEB_DIRECTORY, 0755) != B_OK) { if (create_directory(STR_DEFAULT_WEB_DIRECTORY, 0755) != B_OK) {
serverAlert->Go(); serverAlert->Go();
SetWebDir(""); if (Lock())
Quit();
be_app_messenger.SendMessage(B_QUIT_REQUESTED);
break; break;
} }
BAlert* dirCreatedAlert = BAlert* dirCreatedAlert =
new BAlert("Dir Created", STR_DIR_CREATED, "OK"); new BAlert("Dir Created", STR_DIR_CREATED, "OK");
dirCreatedAlert->Go(); dirCreatedAlert->Go();
SetWebDir(STR_DEFAULT_WEB_DIRECTORY); SetWebDir(STR_DEFAULT_WEB_DIRECTORY);
be_app->PostMessage(kStartServer);
break; break;
} }
} }
@@ -680,7 +700,8 @@ PoorManWindow::ReadSettings()
is_zoomed?ResizeTo(last_width, last_height):ResizeTo(318, 53); is_zoomed?ResizeTo(last_width, last_height):ResizeTo(318, 53);
MoveTo(frame.left, frame.top); MoveTo(frame.left, frame.top);
fLogFile = new BFile(log_path.String(), B_CREATE_FILE|B_WRITE_ONLY|B_OPEN_AT_END); fLogFile = new BFile(log_path.String(), B_CREATE_FILE | B_WRITE_ONLY
| B_OPEN_AT_END);
if (fLogFile->InitCheck() != B_OK) { if (fLogFile->InitCheck() != B_OK) {
log_file_flag = false; log_file_flag = false;
//log it to console, "log to file unavailable." //log it to console, "log to file unavailable."
@@ -692,6 +713,7 @@ PoorManWindow::ReadSettings()
return B_OK; return B_OK;
} }
status_t status_t
PoorManWindow::SaveSettings() PoorManWindow::SaveSettings()
{ {
@@ -733,16 +755,16 @@ PoorManWindow::SaveSettings()
return B_OK; return B_OK;
} }
status_t status_t
PoorManWindow::StartServer() PoorManWindow::StartServer()
{ {
if(NULL == fServer) if (fServer == NULL)
fServer = new PoorManServer( fServer = new PoorManServer(
web_directory.String(), web_directory.String(),
max_connections, max_connections,
dir_list_flag, dir_list_flag,
index_file_name.String() index_file_name.String());
);
poorman_log("Starting up... "); poorman_log("Starting up... ");
if (fServer->Run() != B_OK) { if (fServer->Run() != B_OK) {
@@ -756,10 +778,11 @@ PoorManWindow::StartServer()
return B_OK; return B_OK;
} }
status_t status_t
PoorManWindow::StopServer() PoorManWindow::StopServer()
{ {
if(NULL == fServer) if (fServer == NULL)
return B_ERROR; return B_ERROR;
poorman_log("Shutting down.\n"); poorman_log("Shutting down.\n");
@@ -769,10 +792,11 @@ PoorManWindow::StopServer()
return B_OK; return B_OK;
} }
void void
PoorManWindow::SetLogPath(const char* str) PoorManWindow::SetLogPath(const char* str)
{ {
if(log_path == str) if (!strcmp(log_path, str))
return; return;
BFile* temp = new BFile(str, B_CREATE_FILE | B_WRITE_ONLY | B_OPEN_AT_END); BFile* temp = new BFile(str, B_CREATE_FILE | B_WRITE_ONLY | B_OPEN_AT_END);
+3
View File
@@ -35,6 +35,9 @@ const int32 MSG_PREF_ADV_SLD_MAX_CONNECTION = 'PASM';
// BMessage Preferences File // BMessage Preferences File
const uint32 MSG_PREF_FILE = 'pref'; const uint32 MSG_PREF_FILE = 'pref';
const uint32 kStartServer = 'strt';
//BMessage for Logger //BMessage for Logger
const int32 MSG_LOG = 'logg'; const int32 MSG_LOG = 'logg';
// ------------------------------------------------------ // ------------------------------------------------------