xref: /haiku/src/apps/poorman/PoorManApplication.cpp (revision d939e03d05cfde5de7e3191d519dd10b69f348c6)
1 /* PoorManApplication.cpp
2  *
3  *	Philip Harrison
4  *	Started: 4/25/2004
5  *	Version: 0.1
6  */
7 
8 #include <Application.h>
9 #include <Alert.h>
10 #include <Directory.h>
11 
12 #include "constants.h"
13 #include "PoorManApplication.h"
14 #include "PoorManWindow.h"
15 
16 PoorManApplication::PoorManApplication()
17 	: BApplication(STR_APP_SIG),
18 	  mainWindow(NULL)
19 {
20 	BRect mainRect(82.0f, 30.0f, 400.0f, 350.0f);
21 	mainWindow = new PoorManWindow(mainRect);
22 	mainWindow->Hide();
23 	mainWindow->Show();
24 
25 	BDirectory webDir;
26 	if (mainWindow->ReadSettings() != B_OK) {
27 		if (webDir.SetTo(STR_DEFAULT_WEB_DIRECTORY) != B_OK)
28 			mainWindow->DefaultSettings();
29 		else
30 			PostMessage(kStartServer);
31 	} else {
32 		if (webDir.SetTo(mainWindow->WebDir()) != B_OK)
33 			mainWindow->DefaultSettings();
34 		else
35 			PostMessage(kStartServer);
36 	}
37 }
38 
39 
40 void
41 PoorManApplication::AboutRequested()
42 {
43 	BAlert* aboutBox = new BAlert(STR_ABOUT_TITLE,
44 		STR_ABOUT_DESC, STR_ABOUT_BUTTON);
45 	aboutBox->Go();
46 }
47 
48 
49 void
50 PoorManApplication::MessageReceived(BMessage *message)
51 {
52 	switch (message->what) {
53 		case MSG_FILE_PANEL_SELECT_WEB_DIR:
54 			mainWindow->MessageReceived(message);
55 			break;
56 
57 		case kStartServer:
58 			mainWindow->StartServer();
59 			mainWindow->SetDirLabel(mainWindow->WebDir());
60 			mainWindow->Show();
61 			break;
62 
63 		case B_CANCEL: {
64 			BDirectory webDir;
65 			if (mainWindow->ReadSettings() != B_OK) {
66 				if (webDir.SetTo(STR_DEFAULT_WEB_DIRECTORY) != B_OK)
67 					mainWindow->DefaultSettings();
68 				else
69 					mainWindow->StartServer();
70 			} else {
71 				if (webDir.SetTo(mainWindow->WebDir()) != B_OK)
72 					mainWindow->DefaultSettings();
73 				else
74 					mainWindow->StartServer();
75 			}
76 		}
77 			break;
78 		default:
79 			BApplication::MessageReceived(message);
80 	}
81 }
82 
83