Make use of BWindow::CenterIn() for placing the error alert. Partial clean-up.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33605 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström
2009-10-15 22:09:37 +00:00
parent 51f2ac8647
commit 18ba9ea5c9
2 changed files with 107 additions and 106 deletions
+31 -34
View File
@@ -58,15 +58,8 @@ static void
ErrorAlert(const char* message, status_t err, BWindow *window = NULL) ErrorAlert(const char* message, status_t err, BWindow *window = NULL)
{ {
BAlert *alert = new BAlert("", message, "OK"); BAlert *alert = new BAlert("", message, "OK");
if (window != NULL) { if (window != NULL)
alert->MoveTo( alert->CenterIn(window->Frame());
window->Frame().left +
window->Bounds().right / 2 -
alert->Bounds().right / 2,
window->Frame().top +
window->Bounds().bottom / 2 -
alert->Bounds().bottom / 2);
}
alert->Go(); alert->Go();
printf("%s\n%s [%lx]", message, strerror(err), err); printf("%s\n%s [%lx]", message, strerror(err), err);
@@ -158,19 +151,13 @@ CodyCam::~CodyCam()
void void
CodyCam::ReadyToRun() CodyCam::ReadyToRun()
{ {
/* create the window for the app */
fWindow = new VideoWindow(BRect(28, 28, 28, 28), fWindow = new VideoWindow(BRect(28, 28, 28, 28),
(const char*) "CodyCam", B_TITLED_WINDOW, (const char*) "CodyCam", B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, &fPort); B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, &fPort);
/* set up the node connections */
status_t status = _SetUpNodes(); status_t status = _SetUpNodes();
if (status != B_OK) { if (status != B_OK)
// This error is not needed because _SetUpNodes handles displaying any
// errors it runs into.
// ErrorAlert("Error setting up nodes", status);
return; return;
}
((VideoWindow*)fWindow)->ApplyControls(); ((VideoWindow*)fWindow)->ApplyControls();
@@ -329,7 +316,6 @@ CodyCam::_SetUpNodes()
/* set time sources */ /* set time sources */
status = fMediaRoster->SetTimeSourceFor(fProducerNode.node, fTimeSourceNode.node); status = fMediaRoster->SetTimeSourceFor(fProducerNode.node, fTimeSourceNode.node);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert("Can't set the timesource for the video source", status); ErrorAlert("Can't set the timesource for the video source", status);
@@ -833,25 +819,35 @@ VideoWindow::_SetUpSettings(const char* filename, const char* dirname)
{ {
fSettings = new Settings(filename, dirname); fSettings = new Settings(filename, dirname);
fSettings->Add(fServerSetting = new StringValueSetting("Server", "ftp.my.server", fServerSetting = new StringValueSetting("Server", "ftp.my.server",
"server address expected", "")); "server address expected", "");
fSettings->Add(fLoginSetting = new StringValueSetting("Login", "loginID", fLoginSetting = new StringValueSetting("Login", "loginID",
"login ID expected", "")); "login ID expected", "");
fSettings->Add(fPasswordSetting = new StringValueSetting("Password", "password", fPasswordSetting = new StringValueSetting("Password", "password",
"password expected", "")); "password expected", "");
fSettings->Add(fDirectorySetting = new StringValueSetting("Directory", "web/images", fDirectorySetting = new StringValueSetting("Directory", "web/images",
"destination directory expected", "")); "destination directory expected", "");
fSettings->Add(fPassiveFtpSetting = new BooleanValueSetting("PassiveFtp", 1)); fPassiveFtpSetting = new BooleanValueSetting("PassiveFtp", 1);
fSettings->Add(fFilenameSetting = new StringValueSetting("StillImageFilename", fFilenameSetting = new StringValueSetting("StillImageFilename",
"codycam.jpg", "still image filename expected", "")); "codycam.jpg", "still image filename expected", "");
fSettings->Add(fImageFormatSettings = new StringValueSetting("ImageFileFormat", fImageFormatSettings = new StringValueSetting("ImageFileFormat",
"JPEG Image", "image file format expected", "")); "JPEG Image", "image file format expected", "");
fSettings->Add(fCaptureRateSetting = new EnumeratedStringValueSetting("CaptureRate", fCaptureRateSetting = new EnumeratedStringValueSetting("CaptureRate",
"Every 5 minutes", kCaptureRate, "capture rate expected", "Every 5 minutes", kCaptureRate, "capture rate expected",
"unrecognized capture rate specified")); "unrecognized capture rate specified");
fSettings->Add(fUploadClientSetting = new EnumeratedStringValueSetting("UploadClient", fUploadClientSetting = new EnumeratedStringValueSetting("UploadClient",
"FTP", kUploadClient, "upload client name expected", "FTP", kUploadClient, "upload client name expected",
"unrecognized upload client specified")); "unrecognized upload client specified");
fSettings->Add(fServerSetting);
fSettings->Add(fLoginSetting);
fSettings->Add(fPasswordSetting);
fSettings->Add(fDirectorySetting);
fSettings->Add(fPassiveFtpSetting);
fSettings->Add(fFilenameSetting);
fSettings->Add(fImageFormatSettings);
fSettings->Add(fCaptureRateSetting);
fSettings->Add(fUploadClientSetting);
fSettings->TryReadingSettings(); fSettings->TryReadingSettings();
} }
@@ -945,3 +941,4 @@ int main() {
app.Run(); app.Run();
return 0; return 0;
} }
+17 -13
View File
@@ -1,4 +1,3 @@
/* CodyCam.h */
#ifndef CODYCAM_H #ifndef CODYCAM_H
#define CODYCAM_H #define CODYCAM_H
@@ -18,7 +17,6 @@
#include <Window.h> #include <Window.h>
class BMediaRoster; class BMediaRoster;
@@ -86,7 +84,7 @@ const char* kUploadClient[] = {
class CodyCam : public BApplication { class CodyCam : public BApplication {
public: public:
CodyCam(); CodyCam();
virtual ~CodyCam(); virtual ~CodyCam();
@@ -94,7 +92,7 @@ class CodyCam : public BApplication {
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
private: private:
status_t _SetUpNodes(); status_t _SetUpNodes();
void _TearDownNodes(); void _TearDownNodes();
@@ -111,9 +109,10 @@ class CodyCam : public BApplication {
class VideoWindow : public BWindow { class VideoWindow : public BWindow {
public: public:
VideoWindow(BRect frame, const char* title, window_type type, VideoWindow(BRect frame, const char* title,
uint32 flags, port_id* consumerport); window_type type, uint32 flags,
port_id* consumerport);
~VideoWindow(); ~VideoWindow();
virtual bool QuitRequested(); virtual bool QuitRequested();
@@ -124,13 +123,14 @@ class VideoWindow : public BWindow {
BView* VideoView(); BView* VideoView();
BStringView* StatusLine(); BStringView* StatusLine();
private: private:
void _BuildCaptureControls(BView* theView); void _BuildCaptureControls(BView* theView);
void _SetUpSettings(const char* filename, const char* dirname); void _SetUpSettings(const char* filename,
const char* dirname);
void _QuitSettings(); void _QuitSettings();
private: private:
media_node* fProducer; media_node* fProducer;
port_id* fPortPtr; port_id* fPortPtr;
@@ -157,6 +157,7 @@ class VideoWindow : public BWindow {
ftp_msg_info fFtpInfo; ftp_msg_info fFtpInfo;
Settings* fSettings; Settings* fSettings;
StringValueSetting* fServerSetting; StringValueSetting* fServerSetting;
StringValueSetting* fLoginSetting; StringValueSetting* fLoginSetting;
StringValueSetting* fPasswordSetting; StringValueSetting* fPasswordSetting;
@@ -164,20 +165,23 @@ class VideoWindow : public BWindow {
BooleanValueSetting* fPassiveFtpSetting; BooleanValueSetting* fPassiveFtpSetting;
StringValueSetting* fFilenameSetting; StringValueSetting* fFilenameSetting;
StringValueSetting* fImageFormatSettings; StringValueSetting* fImageFormatSettings;
EnumeratedStringValueSetting* fUploadClientSetting; EnumeratedStringValueSetting* fUploadClientSetting;
EnumeratedStringValueSetting* fCaptureRateSetting; EnumeratedStringValueSetting* fCaptureRateSetting;
}; };
class ControlWindow : public BWindow { class ControlWindow : public BWindow {
public: public:
ControlWindow(const BRect& frame, BView* controls, media_node node); ControlWindow(const BRect& frame, BView* controls,
media_node node);
void MessageReceived(BMessage* message); void MessageReceived(BMessage* message);
bool QuitRequested(); bool QuitRequested();
private: private:
BView* fView; BView* fView;
media_node fNode; media_node fNode;
}; };
#endif // CODYCAM_H #endif // CODYCAM_H