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