Applied patch by gamblore, which adds a Local mode to CodyCam and resolves ticket #3395. I've extended the patch to disable the FTP controls in Local mode and fix bugs which prevented this from working correctly. Some coding style fixes as well... Thanks a lot, gamblore!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33682 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-10-20 19:58:12 +00:00
parent 432cc51cc7
commit f5e3b4741a
3 changed files with 73 additions and 38 deletions
+59 -32
View File
@@ -155,12 +155,9 @@ CodyCam::ReadyToRun()
(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);
status_t status = _SetUpNodes(); _SetUpNodes();
if (status != B_OK)
return;
((VideoWindow*)fWindow)->ApplyControls(); ((VideoWindow*)fWindow)->ApplyControls();
} }
@@ -414,9 +411,10 @@ CodyCam::_TearDownNodes()
// #pragma mark - Video Window Class // #pragma mark - Video Window Class
VideoWindow::VideoWindow (BRect frame, const char* title, window_type type, uint32 flags, VideoWindow::VideoWindow(BRect frame, const char* title, window_type type,
port_id* consumerPort) uint32 flags, port_id* consumerPort)
: BWindow(frame,title,type,flags), :
BWindow(frame, title, type, flags),
fPortPtr(consumerPort), fPortPtr(consumerPort),
fView(NULL), fView(NULL),
fVideoView(NULL) fVideoView(NULL)
@@ -469,7 +467,7 @@ VideoWindow::VideoWindow (BRect frame, const char* title, window_type type, uint
menuBar->AddItem(menu); menuBar->AddItem(menu);
/* give it a gray background view */ /* give it a gray background view */
fView = new BView("Background View", B_WILL_DRAW, NULL); fView = new BView("Background View", B_WILL_DRAW);
fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
/* add some controls */ /* add some controls */
@@ -502,9 +500,7 @@ VideoWindow::QuitRequested()
void void
VideoWindow::MessageReceived(BMessage* message) VideoWindow::MessageReceived(BMessage* message)
{ {
BControl* control; BControl* control = NULL;
control = NULL;
message->FindPointer((const char*)"source", (void **)&control); message->FindPointer((const char*)"source", (void **)&control);
switch (message->what) { switch (message->what) {
@@ -586,10 +582,9 @@ VideoWindow::MessageReceived(BMessage* message)
break; break;
case msg_upl_client: case msg_upl_client:
if (control != NULL) {
message->FindInt32("client", &(fFtpInfo.uploadClient)); message->FindInt32("client", &(fFtpInfo.uploadClient));
FTPINFO("upl client = %ld\n", fFtpInfo.uploadClient); FTPINFO("upl client = %ld\n", fFtpInfo.uploadClient);
} _UploadClientChanged();
break; break;
case msg_server: case msg_server:
@@ -677,9 +672,11 @@ VideoWindow::_BuildCaptureControls(BView* theView)
AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP); AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP);
fImageFormatMenu->SetTargetForItems(this); fImageFormatMenu->SetTargetForItems(this);
if (fImageFormatSettings->Value() && fImageFormatMenu->FindItem(fImageFormatSettings->Value()) != NULL) if (fImageFormatSettings->Value()
fImageFormatMenu->FindItem(fImageFormatSettings->Value())->SetMarked(true); && fImageFormatMenu->FindItem(fImageFormatSettings->Value()) != NULL) {
else if (fImageFormatMenu->FindItem("JPEG Image") != NULL) fImageFormatMenu->FindItem(
fImageFormatSettings->Value())->SetMarked(true);
} else if (fImageFormatMenu->FindItem("JPEG Image") != NULL)
fImageFormatMenu->FindItem("JPEG Image")->SetMarked(true); fImageFormatMenu->FindItem("JPEG Image")->SetMarked(true);
else if (fImageFormatMenu->FindItem("JPEG image") != NULL) else if (fImageFormatMenu->FindItem("JPEG image") != NULL)
fImageFormatMenu->FindItem("JPEG image")->SetMarked(true); fImageFormatMenu->FindItem("JPEG image")->SetMarked(true);
@@ -690,19 +687,32 @@ VideoWindow::_BuildCaptureControls(BView* theView)
fImageFormatMenu, NULL); fImageFormatMenu, NULL);
fCaptureRateMenu = new BPopUpMenu("Capture Rate Menu"); fCaptureRateMenu = new BPopUpMenu("Capture Rate Menu");
fCaptureRateMenu->AddItem(new BMenuItem("Every 15 seconds", new BMessage(msg_rate_15s))); fCaptureRateMenu->AddItem(new BMenuItem("Every 15 seconds",
fCaptureRateMenu->AddItem(new BMenuItem("Every 30 seconds", new BMessage(msg_rate_30s))); new BMessage(msg_rate_15s)));
fCaptureRateMenu->AddItem(new BMenuItem("Every minute", new BMessage(msg_rate_1m))); fCaptureRateMenu->AddItem(new BMenuItem("Every 30 seconds",
fCaptureRateMenu->AddItem(new BMenuItem("Every 5 minutes", new BMessage(msg_rate_5m))); new BMessage(msg_rate_30s)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 10 minutes", new BMessage(msg_rate_10m))); fCaptureRateMenu->AddItem(new BMenuItem("Every minute",
fCaptureRateMenu->AddItem(new BMenuItem("Every 15 minutes", new BMessage(msg_rate_15m))); new BMessage(msg_rate_1m)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 30 minutes", new BMessage(msg_rate_30m))); fCaptureRateMenu->AddItem(new BMenuItem("Every 5 minutes",
fCaptureRateMenu->AddItem(new BMenuItem("Every hour", new BMessage(msg_rate_1h))); new BMessage(msg_rate_5m)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 2 hours", new BMessage(msg_rate_2h))); fCaptureRateMenu->AddItem(new BMenuItem("Every 10 minutes",
fCaptureRateMenu->AddItem(new BMenuItem("Every 4 hours", new BMessage(msg_rate_4h))); new BMessage(msg_rate_10m)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 8 hours", new BMessage(msg_rate_8h))); fCaptureRateMenu->AddItem(new BMenuItem("Every 15 minutes",
fCaptureRateMenu->AddItem(new BMenuItem("Every 24 hours", new BMessage(msg_rate_24h))); new BMessage(msg_rate_15m)));
fCaptureRateMenu->AddItem(new BMenuItem("Never", new BMessage(msg_rate_never))); fCaptureRateMenu->AddItem(new BMenuItem("Every 30 minutes",
new BMessage(msg_rate_30m)));
fCaptureRateMenu->AddItem(new BMenuItem("Every hour",
new BMessage(msg_rate_1h)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 2 hours",
new BMessage(msg_rate_2h)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 4 hours",
new BMessage(msg_rate_4h)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 8 hours",
new BMessage(msg_rate_8h)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 24 hours",
new BMessage(msg_rate_24h)));
fCaptureRateMenu->AddItem(new BMenuItem("Never",
new BMessage(msg_rate_never)));
fCaptureRateMenu->SetTargetForItems(this); fCaptureRateMenu->SetTargetForItems(this);
fCaptureRateMenu->FindItem(fCaptureRateSetting->Value())->SetMarked(true); fCaptureRateMenu->FindItem(fCaptureRateSetting->Value())->SetMarked(true);
fCaptureRateSelector = new BMenuField("Rate", "Rate:", fCaptureRateSelector = new BMenuField("Rate", "Rate:",
@@ -730,10 +740,10 @@ VideoWindow::_BuildCaptureControls(BView* theView)
fUploadClientSelector = new BMenuField("UploadClient", NULL, fUploadClientSelector = new BMenuField("UploadClient", NULL,
fUploadClientMenu, NULL); fUploadClientMenu, NULL);
fFtpSetupBox->SetLabel("FTP"); fFtpSetupBox->SetLabel("Output");
// this doesn't work with the layout manager // this doesn't work with the layout manager
// fFtpSetupBox->SetLabel(fUploadClientSelector); // fFtpSetupBox->SetLabel(fUploadClientSelector);
fUploadClientSelector->SetLabel("Type:"); fUploadClientSelector->SetLabel("Type:");
BGridLayout *ftpLayout = new BGridLayout(kXBuffer, 0); BGridLayout *ftpLayout = new BGridLayout(kXBuffer, 0);
ftpLayout->SetInsets(10, 15, 5, 5); ftpLayout->SetInsets(10, 15, 5, 5);
@@ -801,6 +811,9 @@ fUploadClientSelector->SetLabel("Type:");
void void
VideoWindow::ApplyControls() VideoWindow::ApplyControls()
{ {
if (!Lock())
return;
// apply controls // apply controls
fFileName->Invoke(); fFileName->Invoke();
PostMessage(fImageFormatMenu->FindMarked()->Message()); PostMessage(fImageFormatMenu->FindMarked()->Message());
@@ -811,6 +824,8 @@ VideoWindow::ApplyControls()
fPassword->Invoke(); fPassword->Invoke();
fDirectory->Invoke(); fDirectory->Invoke();
fPassiveFtp->Invoke(); fPassiveFtp->Invoke();
Unlock();
} }
@@ -853,6 +868,18 @@ VideoWindow::_SetUpSettings(const char* filename, const char* dirname)
} }
void
VideoWindow::_UploadClientChanged()
{
bool enableServerControls = fFtpInfo.uploadClient < 2;
fServerName->SetEnabled(enableServerControls);
fLoginId->SetEnabled(enableServerControls);
fPassword->SetEnabled(enableServerControls);
fDirectory->SetEnabled(enableServerControls);
fPassiveFtp->SetEnabled(enableServerControls);
}
void void
VideoWindow::_QuitSettings() VideoWindow::_QuitSettings()
{ {
+2
View File
@@ -79,6 +79,7 @@ const char* kCaptureRate[] = {
const char* kUploadClient[] = { const char* kUploadClient[] = {
"FTP", "FTP",
"SFTP", "SFTP",
"Local",
0 0
}; };
@@ -128,6 +129,7 @@ private:
void _SetUpSettings(const char* filename, void _SetUpSettings(const char* filename,
const char* dirname); const char* dirname);
void _UploadClientChanged();
void _QuitSettings(); void _QuitSettings();
private: private:
+8 -2
View File
@@ -606,9 +606,13 @@ VideoConsumer::FtpRun(void* data)
void void
VideoConsumer::FtpThread() VideoConsumer::FtpThread()
{ {
char fullPath[B_PATH_NAME_LENGTH];
FUNCTION("VideoConsumer::FtpThread\n"); FUNCTION("VideoConsumer::FtpThread\n");
if (fUploadClient == 2) {
if (LocalSave(fFileNameText, fFtpBitmap) == B_OK) // 64 + 64 = 128 max
snprintf(fullPath, B_PATH_NAME_LENGTH, "%s/%s", fDirectoryText, fFileNameText);
LocalSave(fullPath, fFtpBitmap);
} else if (LocalSave(fFileNameText, fFtpBitmap) == B_OK)
FtpSave(fFileNameText); FtpSave(fFileNameText);
#if 0 #if 0
@@ -688,6 +692,8 @@ VideoConsumer::FtpSave(char* filename)
case 1: case 1:
ftp = new SftpClient; ftp = new SftpClient;
break; break;
case 2:
return B_OK;
default: default:
fprintf(stderr, "invalid upload client %ld\n", fUploadClient); fprintf(stderr, "invalid upload client %ld\n", fUploadClient);
return EINVAL; return EINVAL;