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