1 /* PoorManPreferencesWindow.cpp
11 #include <Directory.h>
12 #include <LayoutBuilder.h>
16 #include "constants.h"
17 #include "PoorManWindow.h"
18 #include "PoorManApplication.h"
19 #include "PoorManPreferencesWindow.h"
20 #include "PoorManServer.h"
23 #undef B_TRANSLATION_CONTEXT
24 #define B_TRANSLATION_CONTEXT "PoorMan"
27 PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame
, char * name
)
28 : BWindow(frame
, name
, B_TITLED_WINDOW
, B_NOT_ZOOMABLE
| B_NOT_RESIZABLE
29 | B_CLOSE_ON_ESCAPE
| B_AUTO_UPDATE_SIZE_LIMITS
),
30 fWebDirFilePanel(NULL
),
33 fCancelButton
= new BButton("Cancel Button", B_TRANSLATE("Cancel"),
34 new BMessage(MSG_PREF_BTN_CANCEL
));
35 fDoneButton
= new BButton("Done Button", B_TRANSLATE("Done"),
36 new BMessage(MSG_PREF_BTN_DONE
));
38 fPrefTabView
= new BTabView("Pref Tab View", B_WIDTH_FROM_WIDEST
);
39 fPrefTabView
->SetBorder(B_NO_BORDER
);
42 fSiteTab
= new BTab();
43 fSiteView
= new PoorManSiteView("Site View");
44 fPrefTabView
->AddTab(fSiteView
, fSiteTab
);
45 fSiteTab
->SetLabel(STR_TAB_SITE
);
48 fLoggingTab
= new BTab();
49 fLoggingView
= new PoorManLoggingView("Logging View");
50 fPrefTabView
->AddTab(fLoggingView
, fLoggingTab
);
51 fLoggingTab
->SetLabel(STR_TAB_LOGGING
);
54 fAdvancedTab
= new BTab();
55 fAdvancedView
= new PoorManAdvancedView("Advanced View");
56 fPrefTabView
->AddTab(fAdvancedView
, fAdvancedTab
);
57 fAdvancedTab
->SetLabel(STR_TAB_ADVANCED
);
60 BWindow
* change_title
;
62 BMessenger
messenger(this);
63 BMessage
message(MSG_FILE_PANEL_SELECT_WEB_DIR
);
64 fWebDirFilePanel
= new BFilePanel(B_OPEN_PANEL
, &messenger
, NULL
,
65 B_DIRECTORY_NODE
, false, &message
, NULL
, true);
67 fWebDirFilePanel
->SetPanelDirectory(
68 new BDirectory("/boot/home/public_html"));
69 fWebDirFilePanel
->SetButtonLabel(B_DEFAULT_BUTTON
, B_TRANSLATE("Select"));
70 change_title
= fWebDirFilePanel
->Window();
71 change_title
->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR
);
73 message
.what
= MSG_FILE_PANEL_CREATE_LOG_FILE
;
74 fLogFilePanel
= new BFilePanel(B_SAVE_PANEL
, &messenger
, NULL
,
75 B_FILE_NODE
, false, &message
);
76 fLogFilePanel
->SetButtonLabel(B_DEFAULT_BUTTON
, B_TRANSLATE("Create"));
77 change_title
= fLogFilePanel
->Window();
78 change_title
->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE
);
81 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0)
82 .SetInsets(0, B_USE_DEFAULT_SPACING
, 0, B_USE_WINDOW_SPACING
)
84 .AddGroup(B_HORIZONTAL
)
88 .SetInsets(B_USE_WINDOW_SPACING
, 0, B_USE_WINDOW_SPACING
, 0);
92 PoorManPreferencesWindow::~PoorManPreferencesWindow()
95 delete fWebDirFilePanel
;
100 PoorManPreferencesWindow::MessageReceived(BMessage
* message
)
102 switch (message
->what
) {
103 case MSG_PREF_BTN_DONE
:
105 PoorManServer
* server
;
106 win
= ((PoorManApplication
*)be_app
)->GetPoorManWindow();
107 server
= win
->GetServer();
109 PRINT(("Pref Window: sendDir CheckBox: %d\n",
110 fSiteView
->SendDirValue()));
111 server
->SetListDir(fSiteView
->SendDirValue());
112 win
->SetDirListFlag(fSiteView
->SendDirValue());
113 PRINT(("Pref Window: indexFileName TextControl: %s\n",
114 fSiteView
->IndexFileName()));
115 if (server
->SetIndexName(fSiteView
->IndexFileName()) == B_OK
)
116 win
->SetIndexFileName(fSiteView
->IndexFileName());
117 PRINT(("Pref Window: webDir: %s\n", fSiteView
->WebDir()));
118 if (server
->SetWebDir(fSiteView
->WebDir()) == B_OK
) {
119 win
->SetWebDir(fSiteView
->WebDir());
120 win
->SetDirLabel(fSiteView
->WebDir());
123 PRINT(("Pref Window: logConsole CheckBox: %d\n",
124 fLoggingView
->LogConsoleValue()));
125 win
->SetLogConsoleFlag(fLoggingView
->LogConsoleValue());
126 PRINT(("Pref Window: logFile CheckBox: %d\n",
127 fLoggingView
->LogFileValue()));
128 win
->SetLogFileFlag(fLoggingView
->LogFileValue());
129 PRINT(("Pref Window: logFileName: %s\n",
130 fLoggingView
->LogFileName()));
131 win
->SetLogPath(fLoggingView
->LogFileName());
133 PRINT(("Pref Window: MaxConnections Slider: %" B_PRId32
"\n",
134 fAdvancedView
->MaxSimultaneousConnections()));
135 server
->SetMaxConns(fAdvancedView
->MaxSimultaneousConnections());
136 win
->SetMaxConnections(
137 (int16
)fAdvancedView
->MaxSimultaneousConnections());
142 case MSG_PREF_BTN_CANCEL
:
146 case MSG_PREF_SITE_BTN_SELECT
:
148 // Select the Web Directory, root directory to look in.
149 fWebDirFilePanel
->SetTarget(this);
150 BMessage
webDirSelectedMsg(MSG_FILE_PANEL_SELECT_WEB_DIR
);
151 fWebDirFilePanel
->SetMessage(&webDirSelectedMsg
);
152 if (!fWebDirFilePanel
->IsShowing())
153 fWebDirFilePanel
->Show();
156 case MSG_FILE_PANEL_SELECT_WEB_DIR
:
157 // handle the open BMessage from the Select Web Directory File Panel
158 PRINT(("Select Web Directory:\n"));
159 SelectWebDir(message
);
161 case MSG_PREF_LOG_BTN_CREATE_FILE
:
162 // Create the Log File
163 fLogFilePanel
->Show();
165 case MSG_FILE_PANEL_CREATE_LOG_FILE
:
166 // handle the save BMessage from the Create Log File Panel
167 PRINT(("Create Log File:\n"));
168 CreateLogFile(message
);
170 case MSG_PREF_ADV_SLD_MAX_CONNECTION
:
171 fMaxConnections
= fAdvancedView
->MaxSimultaneousConnections();
172 PRINT(("Max Connections: %" B_PRId32
"\n", fMaxConnections
));
175 BWindow::MessageReceived(message
);
182 PoorManPreferencesWindow::SelectWebDir(BMessage
* message
)
188 if (message
->FindRef("refs", &ref
) != B_OK
|| entry
.SetTo(&ref
) != B_OK
) {
191 entry
.GetPath(&path
);
193 PRINT(("DIR: %s\n", path
.Path()));
194 fSiteView
->SetWebDir(path
.Path());
197 if (message
->FindBool("Default Dialog", &temp
) == B_OK
) {
198 PoorManWindow
* win
= ((PoorManApplication
*)be_app
)->GetPoorManWindow();
200 if (win
->GetServer()->SetWebDir(fSiteView
->WebDir()) == B_OK
) {
201 win
->SetWebDir(fSiteView
->WebDir());
202 win
->SetDirLabel(fSiteView
->WebDir());
213 PoorManPreferencesWindow::CreateLogFile(BMessage
* message
)
221 err
= message
->FindRef("directory", &ref
) != B_OK
;
222 //if (err = message->FindRef("directory", &ref) != B_OK)
224 err
= message
->FindString("name", &name
) != B_OK
;
225 //if (err = message->FindString("name", &name) != B_OK)
227 err
= entry
.SetTo(&ref
) != B_OK
;
228 //if (err = entry.SetTo(&ref) != B_OK)
230 entry
.GetPath(&path
);
232 PRINT(("Log File: %s\n", path
.Path()));
235 fLoggingView
->SetLogFileName(path
.Path());
236 fLoggingView
->SetLogFileValue(true);
243 /*A special version for "the default dialog", don't use it in MessageReceived()*/
245 PoorManPreferencesWindow::ShowWebDirFilePanel()
247 BMessage
message(MSG_FILE_PANEL_SELECT_WEB_DIR
);
248 message
.AddBool("Default Dialog", true);
250 fWebDirFilePanel
->SetTarget(be_app
);
251 fWebDirFilePanel
->SetMessage(&message
);
252 if (!fWebDirFilePanel
->IsShowing())
253 fWebDirFilePanel
->Show();