diff --git a/src/apps/codycam/CodyCam.cpp b/src/apps/codycam/CodyCam.cpp index 2e361c75e1..fe3b57b472 100644 --- a/src/apps/codycam/CodyCam.cpp +++ b/src/apps/codycam/CodyCam.cpp @@ -595,6 +595,14 @@ VideoWindow::MessageReceived(BMessage* message) message->FindInt32("be:translator", &(fFtpInfo.translator)); break; + case msg_upl_client: + if (control != NULL) { + int32 client; + message->FindInt32("client", &(fFtpInfo.uploadClient)); + FTPINFO("upl client = %d\n", fFtpInfo.uploadClient);//XXX + } + break; + case msg_server: if (control != NULL) { strncpy(fFtpInfo.serverText, ((BTextControl*)control)->Text(), 64); @@ -737,7 +745,18 @@ VideoWindow::_BuildCaptureControls(BView* theView) aFrame.bottom -= kYBuffer; fFtpSetupBox = new BBox(aFrame, "Ftp Setup", B_FOLLOW_ALL, B_WILL_DRAW); - fFtpSetupBox->SetLabel("Ftp Setup"); + fUploadClientMenu = new BPopUpMenu("Send to..."); + for (int i = 0; kUploadClient[i]; i++) { + BMessage *m = new BMessage(msg_upl_client); + m->AddInt32("client", i); + fUploadClientMenu->AddItem(new BMenuItem(kUploadClient[i], m)); + } + fUploadClientMenu->SetTargetForItems(this); + //fUploadClientMenu->FindItem(fCaptureRateSetting->Value())->SetMarked(true); + fUploadClientSelector = new BMenuField(aFrame, "UploadClient", "", fUploadClientMenu); + fUploadClientSelector->SetDivider(0.0); + + fFtpSetupBox->SetLabel(fUploadClientSelector); theView->AddChild(fFtpSetupBox); aFrame = fFtpSetupBox->Bounds(); diff --git a/src/apps/codycam/CodyCam.h b/src/apps/codycam/CodyCam.h index d36643ee5d..a1706194bd 100644 --- a/src/apps/codycam/CodyCam.h +++ b/src/apps/codycam/CodyCam.h @@ -41,6 +41,7 @@ enum { msg_translate = 'tran', + msg_upl_client = 'ucli', msg_server = 'srvr', msg_login = 'lgin', msg_password = 'pswd', @@ -77,6 +78,13 @@ const char* kCaptureRate[] = { }; +const char* kUploadClient[] = { + "FTP", + "SFTP", + 0 +}; + + class CodyCam : public BApplication { public: CodyCam(); @@ -135,6 +143,8 @@ class VideoWindow : public BWindow { BMenuField* fCaptureRateSelector; BMenu* fImageFormatMenu; BMenuField* fImageFormatSelector; + BMenu* fUploadClientMenu; + BMenuField* fUploadClientSelector; BBox* fFtpSetupBox; BTextControl* fServerName; BTextControl* fLoginId; diff --git a/src/apps/codycam/Jamfile b/src/apps/codycam/Jamfile index c600cb8734..c1b703541e 100644 --- a/src/apps/codycam/Jamfile +++ b/src/apps/codycam/Jamfile @@ -5,7 +5,9 @@ SetSubDirSupportedPlatformsBeOSCompatible ; Application CodyCam : CodyCam.cpp FileUploadClient.cpp + SpawningUploadClient.cpp FtpClient.cpp + SftpClient.cpp Settings.cpp SettingsHandler.cpp VideoConsumer.cpp diff --git a/src/apps/codycam/VideoConsumer.cpp b/src/apps/codycam/VideoConsumer.cpp index 4e923e37bc..7d5953df22 100644 --- a/src/apps/codycam/VideoConsumer.cpp +++ b/src/apps/codycam/VideoConsumer.cpp @@ -3,7 +3,9 @@ // VideoConsumer.cpp +#include "FileUploadClient.h" #include "FtpClient.h" +#include "SftpClient.h" #include "VideoConsumer.h" #include @@ -53,6 +55,7 @@ VideoConsumer::VideoConsumer(const char* name, BView* view, BStringView* statusL fRate(1000000), fImageFormat(0), fTranslator(0), + fUploadClient(0), fPassiveFtp(true) { FUNCTION("VideoConsumer::VideoConsumer\n"); @@ -205,6 +208,7 @@ VideoConsumer::HandleMessage(int32 message, const void* data, size_t size) fImageFormat = info->imageFormat; fTranslator = info->translator; fPassiveFtp = info->passiveFtp; + fUploadClient = info->uploadClient; strcpy(fFileNameText, info->fileNameText); strcpy(fServerText, info->serverText); strcpy(fLoginText, info->loginText); @@ -230,7 +234,7 @@ VideoConsumer::HandleMessage(int32 message, const void* data, size_t size) void VideoConsumer::BufferReceived(BBuffer* buffer) { - LOOP("VideoConsumer::Buffer #%ld received\n", buffer->ID()); + LOOP("VideoConsumer::Buffer #%ld received, start_time %Ld\n", buffer->ID(), buffer->Header()->start_time); if (RunState() == B_STOPPED) { buffer->Recycle(); @@ -673,25 +677,37 @@ VideoConsumer::LocalSave(char* filename, BBitmap* bitmap) status_t VideoConsumer::FtpSave(char* filename) { - FtpClient ftp; + FileUploadClient *ftp; + + //XXX: make that cleaner + switch (fUploadClient) { + case 0: + ftp = new FtpClient; + break; + case 1: + ftp = new SftpClient; + break; + default: + return EINVAL; + } - ftp.SetPassive(fPassiveFtp); + ftp->SetPassive(fPassiveFtp); // ftp the local file to our web site UpdateFtpStatus("Logging in ..."); - if (ftp.Connect((string)fServerText, (string)fLoginText, (string)fPasswordText)) { + if (ftp->Connect((string)fServerText, (string)fLoginText, (string)fPasswordText)) { // connect to server UpdateFtpStatus("Connected ..."); - if (ftp.ChangeDir((string)fDirectoryText)) { + if (ftp->ChangeDir((string)fDirectoryText)) { // cd to the desired directory UpdateFtpStatus("Transmitting ..."); - if (ftp.PutFile((string)filename, (string)"temp")) { + if (ftp->PutFile((string)filename, (string)"temp")) { // send the file to the server UpdateFtpStatus("Renaming ..."); - if (ftp.MoveFile((string)"temp", (string)filename)) { + if (ftp->MoveFile((string)"temp", (string)filename)) { // change to the desired name uint32 time = real_time_clock(); char s[80]; @@ -699,6 +715,7 @@ VideoConsumer::FtpSave(char* filename) strcat(s, ctime((const long*)&time)); s[strlen(s) - 1] = 0; UpdateFtpStatus(s); + delete ftp; return B_OK; } else @@ -713,6 +730,7 @@ VideoConsumer::FtpSave(char* filename) else UpdateFtpStatus("Server login failed"); + delete ftp; return B_ERROR; } diff --git a/src/apps/codycam/VideoConsumer.h b/src/apps/codycam/VideoConsumer.h index d434f1a540..28c03b031c 100644 --- a/src/apps/codycam/VideoConsumer.h +++ b/src/apps/codycam/VideoConsumer.h @@ -20,6 +20,7 @@ typedef struct { bigtime_t rate; uint32 imageFormat; int32 translator; + int32 uploadClient; bool passiveFtp; char fileNameText[64]; char serverText[64]; @@ -137,6 +138,7 @@ class VideoConsumer : public BMediaEventLooper, public BBufferConsumer { bigtime_t fRate; uint32 fImageFormat; int32 fTranslator; + int32 fUploadClient; bool fPassiveFtp; char fFileNameText[64]; char fServerText[64];