diff --git a/src/apps/codycam/CodyCam.cpp b/src/apps/codycam/CodyCam.cpp index faaa685bd5..f3d8b10e8f 100644 --- a/src/apps/codycam/CodyCam.cpp +++ b/src/apps/codycam/CodyCam.cpp @@ -25,6 +25,9 @@ #include +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "CodyCam" + #define VIDEO_SIZE_X 320 #define VIDEO_SIZE_Y 240 @@ -57,7 +60,7 @@ static status_t AddTranslationItems(BMenu* intoMenu, uint32 fromType); static void ErrorAlert(const char* message, status_t err, BWindow *window = NULL) { - BAlert *alert = new BAlert("", message, "OK"); + BAlert *alert = new BAlert("", message, B_TRANSLATE("OK")); if (window != NULL) alert->CenterIn(window->Frame()); alert->Go(); @@ -127,8 +130,31 @@ CodyCam::CodyCam() fVideoConsumer(NULL), fWindow(NULL), fPort(0), - fVideoControlWindow(NULL) + fVideoControlWindow(NULL), + fAppCatalog(NULL) { + be_locale->GetAppCatalog(&fAppCatalog); + + int32 index = 0; + kCaptureRate[index++] = B_TRANSLATE("Every 15 seconds"); + kCaptureRate[index++] = B_TRANSLATE("Every 30 seconds"); + kCaptureRate[index++] = B_TRANSLATE("Every minute"); + kCaptureRate[index++] = B_TRANSLATE("Every 5 minutes"); + kCaptureRate[index++] = B_TRANSLATE("Every 10 minutes"); + kCaptureRate[index++] = B_TRANSLATE("Every 15 minutes"); + kCaptureRate[index++] = B_TRANSLATE("Every 30 minutes"); + kCaptureRate[index++] = B_TRANSLATE("Every hour"); + kCaptureRate[index++] = B_TRANSLATE("Every 2 hours"); + kCaptureRate[index++] = B_TRANSLATE("Every 4 hours"); + kCaptureRate[index++] = B_TRANSLATE("Every 8 hours"); + kCaptureRate[index++] = B_TRANSLATE("Every 24 hours"); + kCaptureRate[index++] = B_TRANSLATE("Never"); + + index = 0; + kUploadClient[index++] = B_TRANSLATE("FTP"); + kUploadClient[index++] = B_TRANSLATE("SFTP"); + kUploadClient[index++] = B_TRANSLATE("Local"); + chdir("/boot/home"); } @@ -152,7 +178,7 @@ void CodyCam::ReadyToRun() { fWindow = new VideoWindow(BRect(28, 28, 28, 28), - (const char*) "CodyCam", B_TITLED_WINDOW, + (const char*) B_TRANSLATE("CodyCam"), B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, &fPort); _SetUpNodes(); @@ -178,7 +204,8 @@ CodyCam::MessageReceived(BMessage *message) switch (message->what) { case msg_start: { - BTimeSource* timeSource = fMediaRoster->MakeTimeSourceFor(fTimeSourceNode); + BTimeSource* timeSource = fMediaRoster->MakeTimeSourceFor( + fTimeSourceNode); bigtime_t real = BTimeSource::RealTime(); bigtime_t perf = timeSource->PerformanceTimeFor(real) + 10000; status_t status = fMediaRoster->StartNode(fProducerNode, perf); @@ -208,16 +235,16 @@ CodyCam::MessageReceived(BMessage *message) BRect(2 * WINDOW_OFFSET_X + WINDOW_SIZE_X, WINDOW_OFFSET_Y, 2 * WINDOW_OFFSET_X + WINDOW_SIZE_X + view->Bounds().right, WINDOW_OFFSET_Y + view->Bounds().bottom), view, node); - fMediaRoster->StartWatching(BMessenger(NULL, fVideoControlWindow), node, - B_MEDIA_WEB_CHANGED); + fMediaRoster->StartWatching(BMessenger(NULL, + fVideoControlWindow), node, B_MEDIA_WEB_CHANGED); fVideoControlWindow->Show(); } break; } case msg_about: - (new BAlert("About CodyCam", "CodyCam\n\nThe Original BeOS webcam", - "Close"))->Go(); + (new BAlert(B_TRANSLATE("About CodyCam"), B_TRANSLATE("CodyCam\n\n" + "The Original BeOS webcam"), B_TRANSLATE("Close")))->Go(); break; case msg_control_win: @@ -241,14 +268,15 @@ CodyCam::_SetUpNodes() /* find the media roster */ fMediaRoster = BMediaRoster::Roster(&status); if (status != B_OK) { - ErrorAlert("Cannot find the media roster", status, fWindow); + ErrorAlert(B_TRANSLATE("Cannot find the media roster"), status, + fWindow); return status; } /* find the time source */ status = fMediaRoster->GetTimeSource(&fTimeSourceNode); if (status != B_OK) { - ErrorAlert("Cannot get a time source", status, fWindow); + ErrorAlert(B_TRANSLATE("Cannot get a time source"), status, fWindow); return status; } @@ -256,43 +284,49 @@ CodyCam::_SetUpNodes() INFO("CodyCam acquiring VideoInput node\n"); status = fMediaRoster->GetVideoInput(&fProducerNode); if (status != B_OK) { - ErrorAlert("Cannot find a video source. You need a webcam to use CodyCam.", status, fWindow); + ErrorAlert(B_TRANSLATE("Cannot find a video source. You need a webcam " + "to use CodyCam."), status, fWindow); return status; } /* create the video consumer node */ - fVideoConsumer = new VideoConsumer("CodyCam", ((VideoWindow*)fWindow)->VideoView(), + fVideoConsumer = new VideoConsumer("CodyCam", + ((VideoWindow*)fWindow)->VideoView(), ((VideoWindow*)fWindow)->StatusLine(), NULL, 0); if (!fVideoConsumer) { - ErrorAlert("Cannot create a video window", B_ERROR, fWindow); + ErrorAlert(B_TRANSLATE("Cannot create a video window"), B_ERROR, + fWindow); return B_ERROR; } /* register the node */ status = fMediaRoster->RegisterNode(fVideoConsumer); if (status != B_OK) { - ErrorAlert("Cannot register the video window", status, fWindow); + ErrorAlert(B_TRANSLATE("Cannot register the video window"), status, + fWindow); return status; } fPort = fVideoConsumer->ControlPort(); /* find free producer output */ int32 cnt = 0; - status = fMediaRoster->GetFreeOutputsFor(fProducerNode, &fProducerOut, 1, &cnt, - B_MEDIA_RAW_VIDEO); + status = fMediaRoster->GetFreeOutputsFor(fProducerNode, &fProducerOut, 1, + &cnt, B_MEDIA_RAW_VIDEO); if (status != B_OK || cnt < 1) { status = B_RESOURCE_UNAVAILABLE; - ErrorAlert("Cannot find an available video stream", status, fWindow); + ErrorAlert(B_TRANSLATE("Cannot find an available video stream"), + status, fWindow); return status; } /* find free consumer input */ cnt = 0; - status = fMediaRoster->GetFreeInputsFor(fVideoConsumer->Node(), &fConsumerIn, 1, - &cnt, B_MEDIA_RAW_VIDEO); + status = fMediaRoster->GetFreeInputsFor(fVideoConsumer->Node(), + &fConsumerIn, 1, &cnt, B_MEDIA_RAW_VIDEO); if (status != B_OK || cnt < 1) { status = B_RESOURCE_UNAVAILABLE; - ErrorAlert("Can't find an available connection to the video window", status, fWindow); + ErrorAlert(B_TRANSLATE("Can't find an available connection to the " + "video window"), status, fWindow); return status; } @@ -304,24 +338,29 @@ CodyCam::_SetUpNodes() format.u.raw_video = vid_format; /* connect producer to consumer */ - status = fMediaRoster->Connect(fProducerOut.source, fConsumerIn.destination, - &format, &fProducerOut, &fConsumerIn); + status = fMediaRoster->Connect(fProducerOut.source, + fConsumerIn.destination, &format, &fProducerOut, &fConsumerIn); if (status != B_OK) { - ErrorAlert("Cannot connect the video source to the video window", status); + ErrorAlert(B_TRANSLATE("Cannot connect the video source to the video " + "window"), status); return status; } /* set time sources */ - status = fMediaRoster->SetTimeSourceFor(fProducerNode.node, fTimeSourceNode.node); + status = fMediaRoster->SetTimeSourceFor(fProducerNode.node, + fTimeSourceNode.node); if (status != B_OK) { - ErrorAlert("Cannot set the time source for the video source", status); + ErrorAlert(B_TRANSLATE("Cannot set the time source for the video " + "source"), status); return status; } - status = fMediaRoster->SetTimeSourceFor(fVideoConsumer->ID(), fTimeSourceNode.node); + status = fMediaRoster->SetTimeSourceFor(fVideoConsumer->ID(), + fTimeSourceNode.node); if (status != B_OK) { - ErrorAlert("Cannot set the time source for the video window", status); + ErrorAlert(B_TRANSLATE("Cannot set the time source for the video " + "window"), status); return status; } @@ -334,7 +373,8 @@ CodyCam::_SetUpNodes() bigtime_t initLatency = 0; status = fMediaRoster->GetInitialLatencyFor(fProducerNode, &initLatency); if (status < B_OK) { - ErrorAlert("Error getting initial latency for the capture node", status); + ErrorAlert(B_TRANSLATE("Error getting initial latency for the capture " + "node"), status); return status; } @@ -350,29 +390,30 @@ CodyCam::_SetUpNodes() status = fMediaRoster->StartTimeSource(fTimeSourceNode, real); if (status != B_OK) { timeSource->Release(); - ErrorAlert("Cannot start time source!", status); + ErrorAlert(B_TRANSLATE("Cannot start time source!"), status); return status; } status = fMediaRoster->SeekTimeSource(fTimeSourceNode, 0, real); if (status != B_OK) { timeSource->Release(); - ErrorAlert("Cannot seek time source!", status); + ErrorAlert(B_TRANSLATE("Cannot seek time source!"), status); return status; } } - bigtime_t perf = timeSource->PerformanceTimeFor(real + latency + initLatency); + bigtime_t perf = timeSource->PerformanceTimeFor(real + latency + + initLatency); timeSource->Release(); /* start the nodes */ status = fMediaRoster->StartNode(fProducerNode, perf); if (status != B_OK) { - ErrorAlert("Cannot start the video source", status); + ErrorAlert(B_TRANSLATE("Cannot start the video source"), status); return status; } status = fMediaRoster->StartNode(fVideoConsumer->Node(), perf); if (status != B_OK) { - ErrorAlert("Cannot start the video window", status); + ErrorAlert(B_TRANSLATE("Cannot start the video window"), status); return status; } @@ -436,39 +477,43 @@ VideoWindow::VideoWindow(BRect frame, const char* title, window_type type, BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "menu bar"); BMenuItem* menuItem; - BMenu* menu = new BMenu("File"); + BMenu* menu = new BMenu(B_TRANSLATE("File")); - menuItem = new BMenuItem("Video settings", new BMessage(msg_video), 'P'); + menuItem = new BMenuItem(B_TRANSLATE("Video settings"), + new BMessage(msg_video), 'P'); menuItem->SetTarget(be_app); menu->AddItem(menuItem); menu->AddSeparatorItem(); - menuItem = new BMenuItem("Start video", new BMessage(msg_start), 'A'); + menuItem = new BMenuItem(B_TRANSLATE("Start video"), + new BMessage(msg_start), 'A'); menuItem->SetTarget(be_app); menu->AddItem(menuItem); - menuItem = new BMenuItem("Stop video", new BMessage(msg_stop), 'O'); + menuItem = new BMenuItem(B_TRANSLATE("Stop video"), + new BMessage(msg_stop), 'O'); menuItem->SetTarget(be_app); menu->AddItem(menuItem); menu->AddSeparatorItem(); - menuItem = new BMenuItem("About Codycam" B_UTF8_ELLIPSIS, + menuItem = new BMenuItem(B_TRANSLATE("About Codycam" B_UTF8_ELLIPSIS), new BMessage(msg_about), 'B'); menuItem->SetTarget(be_app); menu->AddItem(menuItem); menu->AddSeparatorItem(); - menuItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); + menuItem = new BMenuItem(B_TRANSLATE("Quit"), + new BMessage(B_QUIT_REQUESTED), 'Q'); menuItem->SetTarget(be_app); menu->AddItem(menuItem); menuBar->AddItem(menu); /* give it a gray background view */ - fView = new BView("Background View", B_WILL_DRAW); + fView = new BView(B_TRANSLATE("Background View"), B_WILL_DRAW); fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); /* add some controls */ @@ -659,17 +704,17 @@ VideoWindow::_BuildCaptureControls(BView* theView) // Capture controls fCaptureSetupBox = new BBox("Capture Controls", B_WILL_DRAW); - fCaptureSetupBox->SetLabel("Capture controls"); + fCaptureSetupBox->SetLabel(B_TRANSLATE("Capture controls")); BGridLayout *controlsLayout = new BGridLayout(kXBuffer, 0); controlsLayout->SetInsets(10, 15, 5, 5); fCaptureSetupBox->SetLayout(controlsLayout); - fFileName = new BTextControl("File Name", "File name:", + fFileName = new BTextControl("File Name", B_TRANSLATE("File name:"), fFilenameSetting->Value(), new BMessage(msg_filename)); fFileName->SetTarget(BMessenger(NULL, this)); - fImageFormatMenu = new BPopUpMenu("Image Format Menu"); + fImageFormatMenu = new BPopUpMenu(B_TRANSLATE("Image Format Menu")); AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP); fImageFormatMenu->SetTargetForItems(this); @@ -682,53 +727,57 @@ VideoWindow::_BuildCaptureControls(BView* theView) else fImageFormatMenu->ItemAt(0)->SetMarked(true); - fImageFormatSelector = new BMenuField("Format", "Format:", + fImageFormatSelector = new BMenuField("Format", B_TRANSLATE("Format:"), fImageFormatMenu, NULL); - fCaptureRateMenu = new BPopUpMenu("Capture Rate Menu"); - fCaptureRateMenu->AddItem(new BMenuItem("Every 15 seconds", + fCaptureRateMenu = new BPopUpMenu(B_TRANSLATE("Capture Rate Menu")); + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[0], new BMessage(msg_rate_15s))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 30 seconds", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[1], new BMessage(msg_rate_30s))); - fCaptureRateMenu->AddItem(new BMenuItem("Every minute", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[2], new BMessage(msg_rate_1m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 5 minutes", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[3], new BMessage(msg_rate_5m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 10 minutes", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[4], new BMessage(msg_rate_10m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 15 minutes", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[5], new BMessage(msg_rate_15m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 30 minutes", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[6], new BMessage(msg_rate_30m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every hour", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[7], new BMessage(msg_rate_1h))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 2 hours", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[8], new BMessage(msg_rate_2h))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 4 hours", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[9], new BMessage(msg_rate_4h))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 8 hours", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[10], new BMessage(msg_rate_8h))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 24 hours", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[11], new BMessage(msg_rate_24h))); - fCaptureRateMenu->AddItem(new BMenuItem("Never", + fCaptureRateMenu->AddItem(new BMenuItem(kCaptureRate[12], new BMessage(msg_rate_never))); fCaptureRateMenu->SetTargetForItems(this); fCaptureRateMenu->FindItem(fCaptureRateSetting->Value())->SetMarked(true); - fCaptureRateSelector = new BMenuField("Rate", "Rate:", + fCaptureRateSelector = new BMenuField("Rate", B_TRANSLATE("Rate:"), fCaptureRateMenu, NULL); controlsLayout->AddItem(fFileName->CreateLabelLayoutItem(), 0, 0); controlsLayout->AddItem(fFileName->CreateTextViewLayoutItem(), 1, 0); - controlsLayout->AddItem(fImageFormatSelector->CreateLabelLayoutItem(), 0, 1); - controlsLayout->AddItem(fImageFormatSelector->CreateMenuBarLayoutItem(), 1, 1); - controlsLayout->AddItem(fCaptureRateSelector->CreateLabelLayoutItem(), 0, 2); - controlsLayout->AddItem(fCaptureRateSelector->CreateMenuBarLayoutItem(), 1, 2); + controlsLayout->AddItem(fImageFormatSelector->CreateLabelLayoutItem(), 0, + 1); + controlsLayout->AddItem(fImageFormatSelector->CreateMenuBarLayoutItem(), 1, + 1); + controlsLayout->AddItem(fCaptureRateSelector->CreateLabelLayoutItem(), 0, + 2); + controlsLayout->AddItem(fCaptureRateSelector->CreateMenuBarLayoutItem(), 1, + 2); controlsLayout->AddItem(BSpaceLayoutItem::CreateGlue(), 0, 3, 2); // FTP setup box - fFtpSetupBox = new BBox("FTP Setup", B_WILL_DRAW); + fFtpSetupBox = new BBox(B_TRANSLATE("FTP Setup"), B_WILL_DRAW); - fUploadClientMenu = new BPopUpMenu("Send to" B_UTF8_ELLIPSIS); + fUploadClientMenu = new BPopUpMenu(B_TRANSLATE("Send to" B_UTF8_ELLIPSIS)); for (int i = 0; kUploadClient[i]; i++) { BMessage *m = new BMessage(msg_upl_client); m->AddInt32("client", i); @@ -739,35 +788,35 @@ VideoWindow::_BuildCaptureControls(BView* theView) fUploadClientSelector = new BMenuField("UploadClient", NULL, fUploadClientMenu, NULL); - fFtpSetupBox->SetLabel("Output"); + fFtpSetupBox->SetLabel(B_TRANSLATE("Output")); // this doesn't work with the layout manager // fFtpSetupBox->SetLabel(fUploadClientSelector); - fUploadClientSelector->SetLabel("Type:"); + fUploadClientSelector->SetLabel(B_TRANSLATE("Type:")); BGridLayout *ftpLayout = new BGridLayout(kXBuffer, 0); ftpLayout->SetInsets(10, 15, 5, 5); fFtpSetupBox->SetLayout(ftpLayout); - fServerName = new BTextControl("Server", "Server:", + fServerName = new BTextControl("Server", B_TRANSLATE("Server:"), fServerSetting->Value(), new BMessage(msg_server)); fServerName->SetTarget(this); - fLoginId = new BTextControl("Login", "Login:", + fLoginId = new BTextControl("Login", B_TRANSLATE("Login:"), fLoginSetting->Value(), new BMessage(msg_login)); fLoginId->SetTarget(this); - fPassword = new BTextControl("Password", "Password:", + fPassword = new BTextControl("Password", B_TRANSLATE("Password:"), fPasswordSetting->Value(), new BMessage(msg_password)); fPassword->SetTarget(this); fPassword->TextView()->HideTyping(true); // BeOS HideTyping() seems broken, it empties the text fPassword->SetText(fPasswordSetting->Value()); - fDirectory = new BTextControl("Directory", "Directory:", + fDirectory = new BTextControl("Directory", B_TRANSLATE("Directory:"), fDirectorySetting->Value(), new BMessage(msg_directory)); fDirectory->SetTarget(this); - fPassiveFtp = new BCheckBox("Passive FTP", "Passive FTP", + fPassiveFtp = new BCheckBox("Passive FTP", B_TRANSLATE("Passive FTP"), new BMessage(msg_passiveftp)); fPassiveFtp->SetTarget(this); fPassiveFtp->SetValue(fPassiveFtpSetting->Value()); @@ -784,7 +833,7 @@ VideoWindow::_BuildCaptureControls(BView* theView) ftpLayout->AddItem(fDirectory->CreateTextViewLayoutItem(), 1, 4); ftpLayout->AddView(fPassiveFtp, 0, 5, 2); - fStatusLine = new BStringView("Status Line", "Waiting" B_UTF8_ELLIPSIS); + fStatusLine = new BStringView("Status Line", B_TRANSLATE("Waiting" B_UTF8_ELLIPSIS)); BGroupLayout *groupLayout = new BGroupLayout(B_VERTICAL); groupLayout->SetInsets(kXBuffer, kYBuffer, kXBuffer, kYBuffer); @@ -834,24 +883,26 @@ VideoWindow::_SetUpSettings(const char* filename, const char* dirname) fSettings = new Settings(filename, dirname); fServerSetting = new StringValueSetting("Server", "ftp.my.server", - "server address expected", ""); + B_TRANSLATE("server address expected"), ""); fLoginSetting = new StringValueSetting("Login", "loginID", - "login ID expected", ""); - fPasswordSetting = new StringValueSetting("Password", "password", - "password expected", ""); + B_TRANSLATE("login ID expected"), ""); + fPasswordSetting = new StringValueSetting("Password", + B_TRANSLATE("password"), B_TRANSLATE("password expected"), ""); fDirectorySetting = new StringValueSetting("Directory", "web/images", - "destination directory expected", ""); + B_TRANSLATE("destination directory expected"), ""); fPassiveFtpSetting = new BooleanValueSetting("PassiveFtp", 1); fFilenameSetting = new StringValueSetting("StillImageFilename", - "codycam.jpg", "still image filename expected", ""); + "codycam.jpg", B_TRANSLATE("still image filename expected"), ""); fImageFormatSettings = new StringValueSetting("ImageFileFormat", - "JPEG image", "image file format expected", ""); + B_TRANSLATE("JPEG image"), B_TRANSLATE("image file format expected"), + ""); fCaptureRateSetting = new EnumeratedStringValueSetting("CaptureRate", - "Every 5 minutes", kCaptureRate, "capture rate expected", + kCaptureRate[3], kCaptureRate, B_TRANSLATE("capture rate expected"), "unrecognized capture rate specified"); fUploadClientSetting = new EnumeratedStringValueSetting("UploadClient", - "FTP", kUploadClient, "upload client name expected", - "unrecognized upload client specified"); + B_TRANSLATE("FTP"), kUploadClient, + B_TRANSLATE("upload client name expected"), + B_TRANSLATE("unrecognized upload client specified")); fSettings->Add(fServerSetting); fSettings->Add(fLoginSetting); @@ -900,8 +951,10 @@ VideoWindow::_QuitSettings() // #pragma mark - -ControlWindow::ControlWindow(const BRect& frame, BView* controls, media_node node) - : BWindow(frame, "Video settings", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) +ControlWindow::ControlWindow(const BRect& frame, BView* controls, + media_node node) + : BWindow(frame, B_TRANSLATE("Video settings"), B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS) { fView = controls; fNode = node; diff --git a/src/apps/codycam/CodyCam.h b/src/apps/codycam/CodyCam.h index 6daf494e03..3cfea00557 100644 --- a/src/apps/codycam/CodyCam.h +++ b/src/apps/codycam/CodyCam.h @@ -9,7 +9,9 @@ #include #include +#include #include +#include #include #include #include @@ -59,6 +61,7 @@ enum { const char* kCaptureRate[] = { + // NOTE: These are translated once the app catalog is loaded. "Every 15 seconds", "Every 30 seconds", "Every minute", @@ -77,6 +80,7 @@ const char* kCaptureRate[] = { const char* kUploadClient[] = { + // NOTE: These are translated once the app catalog is loaded. "FTP", "SFTP", "Local", @@ -106,6 +110,7 @@ private: BWindow* fWindow; port_id fPort; BWindow* fVideoControlWindow; + BCatalog fAppCatalog; }; diff --git a/src/apps/codycam/FtpClient.cpp b/src/apps/codycam/FtpClient.cpp index e29d29eecf..cafd7aa794 100644 --- a/src/apps/codycam/FtpClient.cpp +++ b/src/apps/codycam/FtpClient.cpp @@ -3,6 +3,14 @@ #include #include +#include +#include + + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "FtpClient" + + FtpClient::FtpClient() : FileUploadClient(), fState(0), @@ -373,10 +381,10 @@ FtpClient::Chmod(const string& path, const string& mod) if (path.length() == 0) cmd += '/'; -printf("cmd: '%s'\n", cmd.c_str()); +printf(B_TRANSLATE("cmd: '%s'\n"), cmd.c_str()); if (_SendRequest(cmd) == true) { if (_GetReply(replyString, code, codeType) == true) { -printf("reply: %d, %d\n", code, codeType); +printf(B_TRANSLATE("reply: %d, %d\n"), code, codeType); if (codeType == 2) rc = true; } @@ -424,7 +432,7 @@ FtpClient::_SendRequest(const string& cmd) if (fControl != 0) { if (cmd.find("PASS") != string::npos) - printf("PASS (real password sent)\n"); + printf(B_TRANSLATE("PASS (real password sent)\n")); else printf("%s\n", ccmd.c_str()); @@ -540,7 +548,7 @@ FtpClient::_GetReply(string& outString, int& outCode, int& codeType) } if (!rc && outCode != 421) { - outString += "Remote host has closed the connection.\n"; + outString += B_TRANSLATE("Remote host has closed the connection.\n"); outCode = 421; } diff --git a/src/apps/codycam/Jamfile b/src/apps/codycam/Jamfile index c1b703541e..c374670f84 100644 --- a/src/apps/codycam/Jamfile +++ b/src/apps/codycam/Jamfile @@ -11,7 +11,17 @@ Application CodyCam : Settings.cpp SettingsHandler.cpp VideoConsumer.cpp - : be media translation $(TARGET_NETAPI_LIB) $(TARGET_LIBSTDC++) + : be locale media translation $(TARGET_NETAPI_LIB) $(TARGET_LIBSTDC++) : CodyCam.rdef ; +DoCatalogs CodyCam : + x-vnd.Haiku.CodyCam + : + CodyCam.cpp + FtpClient.cpp + Settings.cpp + SettingsHandler.cpp + SftpClient.cpp + VideoConsumer.cpp +; diff --git a/src/apps/codycam/Settings.cpp b/src/apps/codycam/Settings.cpp index 96267323bb..ec6277814f 100644 --- a/src/apps/codycam/Settings.cpp +++ b/src/apps/codycam/Settings.cpp @@ -4,7 +4,13 @@ #include #include +#include #include +#include + + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Settings" Settings* settings = NULL; @@ -229,15 +235,19 @@ BooleanValueSetting::Value() const const char* BooleanValueSetting::Handle(const char *const *argv) { - if (!*++argv) - return "on or off expected"; + if (!*++argv) { + return B_TRANSLATE_COMMENT("on or off expected","Do not translate " + "'on' and 'off'"); + } if (strcmp(*argv, "on") == 0) fValue = true; else if (strcmp(*argv, "off") == 0) fValue = false; - else - return "on or off expected"; + else { + return B_TRANSLATE_COMMENT("on or off expected", "Do not translate " + "'on' and 'off'"); + } return 0; } diff --git a/src/apps/codycam/SettingsHandler.cpp b/src/apps/codycam/SettingsHandler.cpp index 1d58f247d1..b40a66deac 100644 --- a/src/apps/codycam/SettingsHandler.cpp +++ b/src/apps/codycam/SettingsHandler.cpp @@ -5,15 +5,21 @@ #include #include +#include #include #include #include #include #include +#include #include #include +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "SettingsHandler" + + #if 0 static int Compare(const SettingsArgvDispatcher* p1, const SettingsArgvDispatcher* p2) @@ -56,7 +62,7 @@ ArgvParser::ArgvParser(const char* name) { fFile = fopen(fFileName, "r"); if (!fFile) { - PRINT(("Error opening %s\n", fFileName)); + PRINT((B_TRANSLATE("Error opening %s\n"), fFileName)); return; } fBuffer = new char [kBufferSize]; @@ -95,7 +101,7 @@ ArgvParser::SendArgv(ArgvHandler argvHandlerFunc, void* passThru) fCurrentArgv[fArgc] = 0; const char *result = (argvHandlerFunc)(fArgc, fCurrentArgv, passThru); if (result) - printf("File %s; Line %ld # %s", fFileName, fLineNo, result); + printf(B_TRANSLATE("File %s; Line %ld # %s"), fFileName, fLineNo, result); MakeArgvEmpty(); if (result) return B_ERROR; @@ -148,7 +154,8 @@ ArgvParser::GetCh() status_t -ArgvParser::EachArgv(const char* name, ArgvHandler argvHandlerFunc, void* passThru) +ArgvParser::EachArgv(const char* name, ArgvHandler argvHandlerFunc, + void* passThru) { ArgvParser parser(name); return parser.EachArgvPrivate(name, argvHandlerFunc, passThru); @@ -166,7 +173,8 @@ ArgvParser::EachArgvPrivate(const char* name, ArgvHandler argvHandlerFunc, if (ch == EOF) { // done with file if (fInDoubleQuote || fInSingleQuote) { - printf("File %s # unterminated quote at end of file\n", name); + printf(B_TRANSLATE("File %s # unterminated quote at end of " + "file\n"), name); result = B_ERROR; break; } @@ -178,7 +186,8 @@ ArgvParser::EachArgvPrivate(const char* name, ArgvHandler argvHandlerFunc, // handle new line fEatComment = false; if (!fSawBackslash && (fInDoubleQuote || fInSingleQuote)) { - printf("File %s ; Line %ld # unterminated quote\n", name, fLineNo); + printf(B_TRANSLATE("File %s ; Line %ld # unterminated " + "quote\n"), name, fLineNo); result = B_ERROR; break; } @@ -350,7 +359,7 @@ Settings::_ParseUserSettings(int, const char* const *argv, void* castToThis) SettingsArgvDispatcher* handler = settings->_Find(*argv); if (!handler) - return "unknown command"; + return B_TRANSLATE("unknown command"); return handler->Handle(argv); } diff --git a/src/apps/codycam/SftpClient.cpp b/src/apps/codycam/SftpClient.cpp index 713d751037..fb82b3a617 100644 --- a/src/apps/codycam/SftpClient.cpp +++ b/src/apps/codycam/SftpClient.cpp @@ -26,10 +26,10 @@ SftpClient::ChangeDir(const string& dir) cmd << " " << dir.c_str() << "\n"; SendCommand(cmd.String()); if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %d\n", len); + fprintf(stderr, _GetReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; rc = true; @@ -46,10 +46,10 @@ SftpClient::ListDirContents(string& listing) BString reply; do { if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %d\n", len); + fprintf(stderr, _GetReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); printf("%s", reply.String()); if (reply.FindFirst("sftp>") == 0) return true; @@ -69,7 +69,8 @@ SftpClient::PrintWorkingDir(string& dir) bool -SftpClient::Connect(const string& server, const string& login, const string& passwd) +SftpClient::Connect(const string& server, const string& login, + const string& passwd) { bool rc = false; BString cmd("sftp "); @@ -89,18 +90,18 @@ SftpClient::Connect(const string& server, const string& login, const string& pas ssize_t len; if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %ld\n", len); + fprintf(stderr, _GetLongReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("Connecting to ") != 0) return false; if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %ld\n", len); + fprintf(stderr, _GetLongReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst(/*[pP]*/"assword:") < 0) return false; @@ -108,18 +109,18 @@ SftpClient::Connect(const string& server, const string& login, const string& pas write(OutputPipe(), "\n", 1); if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %ld\n", len); + fprintf(stderr, _GetLongReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply != "\n") return false; if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %ld\n", len); + fprintf(stderr, _GetLongReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; return rc; @@ -138,18 +139,18 @@ SftpClient::PutFile(const string& local, const string& remote, ftp_mode mode) BString reply; if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %d\n", len); + fprintf(stderr, _GetReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("Uploading") < 0) return false; if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %d\n", len); + fprintf(stderr, _GetReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; @@ -183,19 +184,19 @@ SftpClient::MoveFile(const string& oldPath, const string& newPath) BString reply; if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %d\n", len); + fprintf(stderr, _GetReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); // we don't care if it worked or not. //if (reply.FindFirst("Removing") != 0 && reply.FindFirst("Couldn't") ) // return false; if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %d\n", len); + fprintf(stderr, _GetReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; @@ -203,10 +204,10 @@ SftpClient::MoveFile(const string& oldPath, const string& newPath) cmd << " " << oldPath.c_str() << " " << newPath.c_str() << "\n"; SendCommand(cmd.String()); if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %d\n", len); + fprintf(stderr, _GetReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; rc = true; @@ -226,18 +227,18 @@ SftpClient::Chmod(const string& path, const string& mod) BString reply; if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %d\n", len); + fprintf(stderr, _GetReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("Changing") < 0) return false; if ((len = ReadReply(&reply)) < 0) { - fprintf(stderr, "read: %d\n", len); + fprintf(stderr, _GetReadText(), len); return false; } - fprintf(stderr, "reply: '%s'\n", reply.String()); + fprintf(stderr, _GetReplyText(), reply.String()); if (reply.FindFirst("sftp>") < 0) return false; @@ -252,3 +253,24 @@ SftpClient::SetPassive(bool on) } +const char* +SftpClient::_GetLongReadText() const +{ + return B_TRANSLATE("read: %ld\n"); +} + + +const char* +SftpClient::_GetReadText() const +{ + return B_TRANSLATE("read: %d\n"); +} + + +const char* +SftpClient::_GetReplyText() const +{ + return B_TRANSLATE("reply: '%s'\n"); +} + + diff --git a/src/apps/codycam/SftpClient.h b/src/apps/codycam/SftpClient.h index 7376019bb4..7e13c63607 100644 --- a/src/apps/codycam/SftpClient.h +++ b/src/apps/codycam/SftpClient.h @@ -5,36 +5,50 @@ #include #include +#include #include +#include + #include "SpawningUploadClient.h" + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "SftpClient" + + using std::string; class SftpClient : public SpawningUploadClient { - public: - SftpClient(); - ~SftpClient(); +public: + SftpClient(); + virtual ~SftpClient(); -virtual bool Connect(const string& server, const string& login, - const string& passwd); + virtual bool Connect(const string& server, + const string& login, + const string& passwd); - bool PutFile(const string& local, const string& remote, - ftp_mode mode = binary_mode); + bool PutFile(const string& local, + const string& remote, + ftp_mode mode = binary_mode); - bool GetFile(const string& remote, const string& local, - ftp_mode mode = binary_mode); + bool GetFile(const string& remote, + const string& local, + ftp_mode mode = binary_mode); - bool MoveFile(const string& oldPath, const string& newPath); - bool ChangeDir(const string& dir); - bool PrintWorkingDir(string& dir); - bool ListDirContents(string& listing); - bool Chmod(const string& path, const string& mod); + bool MoveFile(const string& oldPath, + const string& newPath); + bool ChangeDir(const string& dir); + bool PrintWorkingDir(string& dir); + bool ListDirContents(string& listing); + bool Chmod(const string& path, const string& mod); - void SetPassive(bool on); + void SetPassive(bool on); - protected: - +private: + const char* _GetLongReadText() const; + const char* _GetReadText() const; + const char* _GetReplyText() const; }; #endif // SFTP_CLIENT_H diff --git a/src/apps/codycam/VideoConsumer.cpp b/src/apps/codycam/VideoConsumer.cpp index 06e17d0798..5b5778b69c 100644 --- a/src/apps/codycam/VideoConsumer.cpp +++ b/src/apps/codycam/VideoConsumer.cpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include #include @@ -24,6 +26,9 @@ #include +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "VideoConsumer.cpp" + #define M1 ((double)1000000.0) #define JITTER 20000 @@ -32,15 +37,19 @@ #define PROGRESS printf #define LOOP printf + static status_t SetFileType(BFile* file, int32 translator, uint32 type); -const media_raw_video_format vid_format = {29.97, 1, 0, 239, B_VIDEO_TOP_LEFT_RIGHT, - 1, 1, {B_RGB16, 320, 240, 320 * 4, 0, 0}}; +const media_raw_video_format vid_format = {29.97, 1, 0, 239, + B_VIDEO_TOP_LEFT_RIGHT, 1, 1, {B_RGB16, 320, 240, 320 * 4, 0, 0}}; -VideoConsumer::VideoConsumer(const char* name, BView* view, BStringView* statusLine, +VideoConsumer::VideoConsumer(const char* name, BView* view, + BStringView* statusLine, BMediaAddOn* addon, const uint32 internalId) - : BMediaNode(name), BMediaEventLooper(), BBufferConsumer(B_MEDIA_RAW_VIDEO), + : BMediaNode(name), + BMediaEventLooper(), + BBufferConsumer(B_MEDIA_RAW_VIDEO), fStatusLine(statusLine), fInternalID(internalId), fAddOn(addon), @@ -86,9 +95,9 @@ VideoConsumer::~VideoConsumer() Quit(); if (fWindow) { - printf("Locking the window\n"); + printf(B_TRANSLATE("Locking the window\n")); if (fWindow->Lock()) { - printf("Closing the window\n"); + printf(B_TRANSLATE("Closing the window\n")); fWindow->Close(); fWindow = 0; } @@ -652,7 +661,7 @@ VideoConsumer::LocalSave(char* filename, BBitmap* bitmap) { BFile* output; - UpdateFtpStatus("Capturing Image" B_UTF8_ELLIPSIS); + UpdateFtpStatus(B_TRANSLATE("Capturing Image" B_UTF8_ELLIPSIS)); /* save a local copy of the image in the requested format */ output = new BFile(); @@ -663,17 +672,17 @@ VideoConsumer::LocalSave(char* filename, BBitmap* bitmap) if (err == B_OK) { err = SetFileType(output, fTranslator, fImageFormat); if (err != B_OK) - UpdateFtpStatus("Error setting type of output file"); + UpdateFtpStatus(B_TRANSLATE("Error setting type of output file")); } else - UpdateFtpStatus("Error writing output file"); + UpdateFtpStatus(B_TRANSLATE("Error writing output file")); input.DetachBitmap(&bitmap); output->Unset(); delete output; return B_OK; } else { - UpdateFtpStatus("Error creating output file"); + UpdateFtpStatus(B_TRANSLATE("Error creating output file")); return B_ERROR; } } @@ -695,21 +704,23 @@ VideoConsumer::FtpSave(char* filename) case 2: return B_OK; default: - fprintf(stderr, "invalid upload client %ld\n", fUploadClient); + fprintf(stderr, B_TRANSLATE("invalid upload client %ld\n"), + fUploadClient); return EINVAL; } ftp->SetPassive(fPassiveFtp); // ftp the local file to our web site - UpdateFtpStatus("Logging in" B_UTF8_ELLIPSIS); - if (ftp->Connect((string)fServerText, (string)fLoginText, (string)fPasswordText)) { + UpdateFtpStatus(B_TRANSLATE("Logging in" B_UTF8_ELLIPSIS)); + if (ftp->Connect((string)fServerText, (string)fLoginText, + (string)fPasswordText)) { // connect to server - UpdateFtpStatus("Connected" B_UTF8_ELLIPSIS); + UpdateFtpStatus(B_TRANSLATE("Connected" B_UTF8_ELLIPSIS)); if (ftp->ChangeDir((string)fDirectoryText)) { // cd to the desired directory - UpdateFtpStatus("Transmitting" B_UTF8_ELLIPSIS); + UpdateFtpStatus(B_TRANSLATE("Transmitting" B_UTF8_ELLIPSIS)); if (ftp->PutFile((string)filename, (string)"temp")) { // send the file to the server @@ -717,13 +728,13 @@ VideoConsumer::FtpSave(char* filename) ftp->Chmod((string)"temp", (string)"644"); // make it world readable - UpdateFtpStatus("Renaming" B_UTF8_ELLIPSIS); + UpdateFtpStatus(B_TRANSLATE("Renaming" B_UTF8_ELLIPSIS)); if (ftp->MoveFile((string)"temp", (string)filename)) { // change to the desired name uint32 time = real_time_clock(); char s[80]; - strcpy(s, "Last Capture: "); + strcpy(s, B_TRANSLATE("Last Capture: ")); strcat(s, ctime((const long*)&time)); s[strlen(s) - 1] = 0; UpdateFtpStatus(s); @@ -731,16 +742,17 @@ VideoConsumer::FtpSave(char* filename) return B_OK; } else - UpdateFtpStatus("Rename failed"); + UpdateFtpStatus(B_TRANSLATE("Rename failed")); } else - UpdateFtpStatus("File transmission failed"); + UpdateFtpStatus(B_TRANSLATE("File transmission failed")); } else - UpdateFtpStatus("Couldn't find requested directory on server"); + UpdateFtpStatus(B_TRANSLATE("Couldn't find requested directory on " + "server")); } else - UpdateFtpStatus("Server login failed"); + UpdateFtpStatus(B_TRANSLATE("Server login failed")); delete ftp; return B_ERROR;