Author: pulkomandy Date: 2010-06-21 21:10:46 +0200 (Mon, 21 Jun 2010) New Revision: 37208 Changeset: http://dev.haiku-os.org/changeset/37208/haiku Ticket: http://dev.haiku-os.org/ticket/6075 Modified: haiku/trunk/src/tools/translation/inspector/ActiveTranslatorsWindow.cpp haiku/trunk/src/tools/translation/inspector/ImageView.cpp haiku/trunk/src/tools/translation/inspector/ImageWindow.cpp haiku/trunk/src/tools/translation/inspector/InspectorApp.cpp haiku/trunk/src/tools/translation/inspector/InspectorApp.h haiku/trunk/src/tools/translation/inspector/Jamfile Log: Patch by Jorma Karvonen (#6075): translate Inspector application. Thanks! Modified: haiku/trunk/src/tools/translation/inspector/ActiveTranslatorsWindow.cpp =================================================================== --- haiku/trunk/src/tools/translation/inspector/ActiveTranslatorsWindow.cpp 2010-06-21 18:50:51 UTC (rev 37207) +++ haiku/trunk/src/tools/translation/inspector/ActiveTranslatorsWindow.cpp 2010-06-21 19:10:46 UTC (rev 37208) @@ -33,7 +33,9 @@ #include "ActiveTranslatorsWindow.h" #include "TranslatorItem.h" #include <Application.h> +#include <Catalog.h> #include <ScrollView.h> +#include <Locale.h> #include <Message.h> #include <String.h> #include <stdlib.h> @@ -42,6 +44,9 @@ #include <unistd.h> #include <sys/stat.h> +#define B_TRANSLATE_CONTEXT "ActiveTranslatorsWindow" + + ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name, BList *plist) : BWindow(rect, name, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) @@ -52,9 +57,9 @@ fpListView = new BOutlineListView(rctframe, "translators_list", B_MULTIPLE_SELECTION_LIST); - fpListView->AddItem(fpUserItem = new BStringItem("User Translators")); + fpListView->AddItem(fpUserItem = new BStringItem(B_TRANSLATE("User Translators"))); fpUserItem->SetEnabled(false); - fpListView->AddItem(fpSystemItem = new BStringItem("System Translators")); + fpListView->AddItem(fpSystemItem = new BStringItem(B_TRANSLATE("System Translators"))); fpSystemItem->SetEnabled(false); AddTranslatorsToList(plist, USER_TRANSLATOR, fpUserItem); AddTranslatorsToList(plist, SYSTEM_TRANSLATOR, fpSystemItem); Modified: haiku/trunk/src/tools/translation/inspector/ImageView.cpp =================================================================== --- haiku/trunk/src/tools/translation/inspector/ImageView.cpp 2010-06-21 18:50:51 UTC (rev 37207) +++ haiku/trunk/src/tools/translation/inspector/ImageView.cpp 2010-06-21 19:10:46 UTC (rev 37208) @@ -37,7 +37,9 @@ #include "InspectorApp.h" #include "TranslatorItem.h" #include <Application.h> +#include <Catalog.h> #include <Message.h> +#include <Locale.h> #include <List.h> #include <String.h> #include <TranslationUtils.h> @@ -59,6 +61,9 @@ #define BORDER_HEIGHT 16 #define PEN_SIZE 1.0f +#define B_TRANSLATE_CONTEXT "ImageView" + + ImageView::ImageView(BRect rect, const char *name) : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS) { @@ -71,18 +76,21 @@ SetPenSize(PEN_SIZE); } + ImageView::~ImageView() { delete fpbitmap; fpbitmap = NULL; } + void ImageView::AttachedToWindow() { AdjustScrollBars(); } + void ImageView::Draw(BRect rect) { @@ -98,12 +106,14 @@ } } + void ImageView::ReDraw() { Draw(Bounds()); } + void ImageView::FrameResized(float width, float height) { @@ -113,6 +123,7 @@ Invalidate(); } + void ImageView::MouseDown(BPoint point) { @@ -139,16 +150,19 @@ DragMessage(&msg, Bounds()); } + void ImageView::MouseMoved(BPoint point, uint32 state, const BMessage *pmsg) { } + void ImageView::MouseUp(BPoint point) { } + void ImageView::MessageReceived(BMessage *pmsg) { @@ -163,6 +177,7 @@ } } + void ImageView::SaveImageAtDropLocation(BMessage *pmsg) { @@ -189,13 +204,15 @@ } catch (StatusNotOKException) { BAlert *palert = new BAlert(NULL, - "Sorry, unable to write the image file.", "OK"); + B_TRANSLATE("Sorry, unable to write the image file."), + B_TRANSLATE("OK")); palert->Go(); } stream.DetachBitmap(&fpbitmap); } + void ImageView::AdjustScrollBars() { @@ -227,12 +244,14 @@ } } + struct ColorSpaceName { color_space id; const char *name; }; #define COLORSPACENAME(id) {id, #id} + // convert colorspace numerical value to // a string value const char * @@ -293,9 +312,10 @@ return kcolorspaces[i].name; } - return "Unknown"; + return B_TRANSLATE("Unknown"); } + // return a string of the passed number formated // as a hexadecimal number in lowercase with a leading "0x" const char * @@ -307,6 +327,7 @@ return str; } + // convert passed number to a string of 4 characters // and return that string const char * @@ -319,22 +340,40 @@ return str; } + void dump_translation_formats(BString &bstr, const translation_format *pfmts, int32 nfmts) { + BString *str1 = NULL; for (int i = 0; i < nfmts; i++) { - bstr << "\nType: '" << char_format(pfmts[i].type) << "' (" << - hex_format(pfmts[i].type) << ")\n"; - bstr << "Group: '" << char_format(pfmts[i].group) << "' (" << - hex_format(pfmts[i].group) << ")\n"; - bstr << "Quality: " << pfmts[i].quality << "\n"; - bstr << "Capability: " << pfmts[i].capability << "\n"; - bstr << "MIME Type: " << pfmts[i].MIME << "\n"; - bstr << "Name: " << pfmts[i].name << "\n"; + BString string = B_TRANSLATE("\nType: '%1' (%2)\n" + "Group: '%3' (%4)\n" + "Quality: %5\n" + "Capability: %6\n" + "MIME Type: %7\n" + "Name: %8\n"); + string.ReplaceFirst("%1", char_format(pfmts[i].type)); + string.ReplaceFirst("%2", hex_format(pfmts[i].type)); + string.ReplaceFirst("%3", char_format(pfmts[i].group)); + string.ReplaceFirst("%4", hex_format(pfmts[i].group)); + char str2[127] = { 0 }; + sprintf(str2, "%f", pfmts[i].quality); + string.ReplaceFirst("%5", str2 ); + str2[0] = '\0'; + sprintf(str2, "%f", pfmts[i].capability); + string.ReplaceFirst("%6", str2 ); + string.ReplaceFirst("%7", pfmts[i].MIME); + string.ReplaceFirst("%8", pfmts[i].name); + if (i == 0) + str1 = new BString(string); + else + str1->Append(string); } + bstr = str1->String(); } + // Send information about the currently open image to the // BApplication object so it can send it to the InfoWindow void @@ -343,66 +382,124 @@ { BMessage msg(M_INFO_WINDOW_TEXT); BString bstr; - - // Bitmap Info - bstr << "Image: " << path.Path() << "\n"; + + bstr = B_TRANSLATE("Image: %1\n" + "Color Space: %2 (%3)\n" + "Dimensions: %4 x %5\n" + "Bytes per Row: %6\n" + "Total Bytes: %7\n" + "\nIdentify Info:\n" + "ID String: %8\n" + "MIME Type: %9\n" + "Type: '%10' (%11)\n" + "Translator ID: %12\n" + "Group: '%13' (%14)\n" + "Quality: %15\n" + "Capability: %16\n" + "\nExtension Info:\n"); + bstr.ReplaceFirst("%1", path.Path()); color_space cs = fpbitmap->ColorSpace(); - bstr << "Color Space: " << get_color_space_name(cs) << " (" << - hex_format(static_cast<uint32>(cs)) << ")\n"; - bstr << "Dimensions: " << fpbitmap->Bounds().IntegerWidth() + 1 << " x " << - fpbitmap->Bounds().IntegerHeight() + 1 << "\n"; - bstr << "Bytes per Row: " << fpbitmap->BytesPerRow() << "\n"; - bstr << "Total Bytes: " << fpbitmap->BitsLength() << "\n"; + bstr.ReplaceFirst("%2", get_color_space_name(cs)); + bstr.ReplaceFirst("%3", hex_format(static_cast<uint32>(cs))); + char str2[127] = { 0 }; + sprintf(str2, "%ld", fpbitmap->Bounds().IntegerWidth() + 1); + bstr.ReplaceFirst("%4", str2); + str2[0] = '\0'; + sprintf(str2, "%ld", fpbitmap->Bounds().IntegerHeight() + 1); + bstr.ReplaceFirst("%5", str2); + str2[0] = '\0'; + sprintf(str2, "%ld", fpbitmap->BytesPerRow()); + bstr.ReplaceFirst("%6", str2); + str2[0] = '\0'; + sprintf(str2, "%ld", fpbitmap->BitsLength()); + bstr.ReplaceFirst("%7", str2); + bstr.ReplaceFirst("%8", tinfo.name); + bstr.ReplaceFirst("%9", tinfo.MIME); + bstr.ReplaceFirst("%10", char_format(tinfo.type)); + bstr.ReplaceFirst("%11", hex_format(tinfo.type)); + str2[0] = '\0'; + sprintf(str2, "%ld", tinfo.translator); + bstr.ReplaceFirst("%12", str2); + bstr.ReplaceFirst("%13", char_format(tinfo.group)); + bstr.ReplaceFirst("%14", hex_format(tinfo.group)); + str2[0] = '\0'; + sprintf(str2, "%f", tinfo.quality); + bstr.ReplaceFirst("%15", str2); + str2[0] = '\0'; + sprintf(str2, "%f", tinfo.capability); + bstr.ReplaceFirst("%16", str2); - // Identify Info - bstr << "\nIdentify Info:\n"; - bstr << "ID String: " << tinfo.name << "\n"; - bstr << "MIME Type: " << tinfo.MIME << "\n"; - bstr << "Type: '" << char_format(tinfo.type) << "' (" << - hex_format(tinfo.type) << ")\n"; - bstr << "Translator ID: " << tinfo.translator << "\n"; - bstr << "Group: '" << char_format(tinfo.group) << "' (" << - hex_format(tinfo.group) << ")\n"; - bstr << "Quality: " << tinfo.quality << "\n"; - bstr << "Capability: " << tinfo.capability << "\n"; - - // Extension Info - bstr << "\nExtension Info:\n"; int32 document_count = 0, document_index = 0; - if (ioExtension.FindInt32("/documentCount", &document_count) == B_OK) - bstr << "Number of Documents: " << document_count << "\n"; - if (ioExtension.FindInt32("/documentIndex", &document_index) == B_OK) - bstr << "Selected Document: " << document_index << "\n"; - // Translator Info const char *tranname = NULL, *traninfo = NULL; int32 tranversion = 0; - if (proster->GetTranslatorInfo(tinfo.translator, &tranname, &traninfo, - &tranversion) == B_OK) { - bstr << "\nTranslator Used:\n"; - bstr << "Name: " << tranname << "\n"; - bstr << "Info: " << traninfo << "\n"; - bstr << "Version: " << tranversion << "\n"; + + if (ioExtension.FindInt32("/documentCount", &document_count) == B_OK) { + BString str = B_TRANSLATE("Number of Documents: %1\n" + "\nTranslator Used:\n" + "Name: %2\n" + "Info: %3\n" + "Version: %4\n"); + char str2[127] = { 0 }; + sprintf(str2, "%ld", document_count); + str.ReplaceFirst("%1", str2); + str.ReplaceFirst("%2", tranname); + str.ReplaceFirst("%3", traninfo); + str2[0] = '\0'; + sprintf(str2, "%d", (int)tranversion); + str.ReplaceFirst("%4", str2); + bstr.Append(str.String()); } - + else + if (ioExtension.FindInt32("/documentIndex", &document_index) == B_OK) { + BString str = B_TRANSLATE("Selected Document: %1\n" + "\nTranslator Used:\n" + "Name: %2\n" + "Info: %3\n" + "Version: %4\n"); + char str2[127] = { 0 }; + sprintf(str2, "%ld", document_index); + str.ReplaceFirst("%1", str2); + str.ReplaceFirst("%2", tranname); + str.ReplaceFirst("%3", traninfo); + str2[0] = '\0'; + sprintf(str2, "%d", (int)tranversion); + str.ReplaceFirst("%4", str2); + bstr.Append(str.String()); + } + else + if (proster->GetTranslatorInfo(tinfo.translator, &tranname, + &traninfo, &tranversion) == B_OK) { + BString str = B_TRANSLATE("\nTranslator Used:\n" + "Name: %1\n" + "Info: %2\n" + "Version: %3\n"); + str.ReplaceFirst("%1", tranname); + str.ReplaceFirst("%2", traninfo); + char str2[127] = { 0 }; + sprintf(str2, "%d", (int)tranversion); + str.ReplaceFirst("%3", str2); + bstr.Append(str.String()); + } + // Translator Input / Output Formats int32 nins = 0, nouts = 0; const translation_format *pins = NULL, *pouts = NULL; if (proster->GetInputFormats(tinfo.translator, &pins, &nins) == B_OK) { - bstr << "\nInput Formats:"; + bstr << B_TRANSLATE("\nInput Formats:"); dump_translation_formats(bstr, pins, nins); pins = NULL; } if (proster->GetOutputFormats(tinfo.translator, &pouts, &nouts) == B_OK) { - bstr << "\nOutput Formats:"; + bstr << B_TRANSLATE("\nOutput Formats:"); dump_translation_formats(bstr, pouts, nouts); pouts = NULL; } - msg.AddString("text", bstr); be_app->PostMessage(&msg); } + BTranslatorRoster * ImageView::SelectTranslatorRoster(BTranslatorRoster &roster) { @@ -430,6 +527,7 @@ return &roster; } + void ImageView::SetImage(BMessage *pmsg) { @@ -454,7 +552,6 @@ if (!proster) // throw exception chk = B_ERROR; - // determine what type the image is translator_info tinfo; BMessage ioExtension; @@ -494,9 +591,8 @@ pwin->SetTitle(IMAGEWINDOW_TITLE); } else pwin->SetTitle(IMAGEWINDOW_TITLE); - UpdateInfoWindow(path, ioExtension, tinfo, proster); - + // Resize parent window and set size limits to // reflect the size of the new bitmap float width, height; @@ -504,7 +600,6 @@ width = fpbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH + (BORDER_WIDTH * 2); height = fpbitmap->Bounds().Height() + pbar->Bounds().Height() + B_H_SCROLL_BAR_HEIGHT + (BORDER_HEIGHT * 2) + 1; - BScreen *pscreen = new BScreen(pwin); BRect rctscreen = pscreen->Frame(); if (width > rctscreen.Width()) @@ -514,9 +609,8 @@ pwin->SetSizeLimits(B_V_SCROLL_BAR_WIDTH * 4, width, pbar->Bounds().Height() + (B_H_SCROLL_BAR_HEIGHT * 4) + 1, height); pwin->SetZoomLimits(width, height); - AdjustScrollBars(); - + //pwin->Zoom(); // Perform all of the hard work of resizing the // window while taking into account the size of @@ -531,11 +625,13 @@ } catch (StatusNotOKException) { BAlert *palert = new BAlert(NULL, - "Sorry, unable to load the image.", "OK"); + B_TRANSLATE("Sorry, unable to load the image."), + B_TRANSLATE("OK")); palert->Go(); } } + void ImageView::FirstPage() { @@ -545,6 +641,7 @@ } } + void ImageView::LastPage() { @@ -554,6 +651,7 @@ } } + void ImageView::NextPage() { @@ -563,6 +661,7 @@ } } + void ImageView::PrevPage() { Modified: haiku/trunk/src/tools/translation/inspector/ImageWindow.cpp =================================================================== --- haiku/trunk/src/tools/translation/inspector/ImageWindow.cpp 2010-06-21 18:50:51 UTC (rev 37207) +++ haiku/trunk/src/tools/translation/inspector/ImageWindow.cpp 2010-06-21 19:10:46 UTC (rev 37208) @@ -32,12 +32,17 @@ #include "ImageWindow.h" #include "Constants.h" #include <Application.h> +#include <Catalog.h> +#include <Locale.h> #include <MenuBar.h> #include <MenuItem.h> #include <Menu.h> #include <ScrollView.h> #include <Alert.h> +#define B_TRANSLATE_CONTEXT "ImageWindow" + + ImageWindow::ImageWindow(BRect rect, const char *name) : BWindow(rect, name, B_DOCUMENT_WINDOW, 0) { @@ -45,14 +50,14 @@ BRect rctbar(0, 0, 100, 10); BMenuBar *pbar = new BMenuBar(rctbar, "MenuBar"); - BMenu *pmnufile = new BMenu("File"); - BMenuItem *pitmopen = new BMenuItem("Open...", + BMenu *pmnufile = new BMenu(B_TRANSLATE("File")); + BMenuItem *pitmopen = new BMenuItem(B_TRANSLATE("Open..."), new BMessage(M_OPEN_IMAGE), 'O', 0); - BMenuItem *pitmsave = new BMenuItem("Save...", + BMenuItem *pitmsave = new BMenuItem(B_TRANSLATE("Save..."), new BMessage(M_SAVE_IMAGE), 'S', 0); - BMenuItem *pitmquit = new BMenuItem("Quit", + BMenuItem *pitmquit = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q', 0); pmnufile->AddItem(pitmopen); @@ -61,17 +66,17 @@ pmnufile->AddItem(pitmquit); pbar->AddItem(pmnufile); - BMenu *pmnuview = new BMenu("View"); - BMenuItem *pitmfirst = new BMenuItem("First Page", + BMenu *pmnuview = new BMenu(B_TRANSLATE("View")); + BMenuItem *pitmfirst = new BMenuItem(B_TRANSLATE("First Page"), new BMessage(M_VIEW_FIRST_PAGE), 'F', 0); - BMenuItem *pitmlast = new BMenuItem("Last Page", + BMenuItem *pitmlast = new BMenuItem(B_TRANSLATE("Last Page"), new BMessage(M_VIEW_LAST_PAGE), 'L', 0); - BMenuItem *pitmnext = new BMenuItem("Next Page", + BMenuItem *pitmnext = new BMenuItem(B_TRANSLATE("Next Page"), new BMessage(M_VIEW_NEXT_PAGE), 'N', 0); - BMenuItem *pitmprev = new BMenuItem("Previous Page", + BMenuItem *pitmprev = new BMenuItem(B_TRANSLATE("Previous Page"), new BMessage(M_VIEW_PREV_PAGE), 'P', 0); pmnuview->AddItem(pitmfirst); @@ -81,12 +86,12 @@ pbar->AddItem(pmnuview); - BMenu *pmnuwindow = new BMenu("Window"); - BMenuItem *pitmactives = new BMenuItem("Active Translators", + BMenu *pmnuwindow = new BMenu(B_TRANSLATE("Window")); + BMenuItem *pitmactives = new BMenuItem(B_TRANSLATE("Active Translators"), new BMessage(M_ACTIVE_TRANSLATORS_WINDOW), 'T', 0); pitmactives->SetTarget(be_app); - BMenuItem *pitminfo = new BMenuItem("Info", + BMenuItem *pitminfo = new BMenuItem(B_TRANSLATE("Info"), new BMessage(M_INFO_WINDOW), 'I', 0); pitminfo->SetTarget(be_app); @@ -133,11 +138,13 @@ case M_SAVE_IMAGE: if (fpimageView->HasImage()) { BAlert *palert = new BAlert(NULL, - "Save feature not implemented yet.", "Bummer"); + B_TRANSLATE("Save feature not implemented yet."), + B_TRANSLATE("Bummer")); palert->Go(); } else { BAlert *palert = new BAlert(NULL, - "No image available to save.", "OK"); + B_TRANSLATE("No image available to save."), + B_TRANSLATE("OK")); palert->Go(); } break; Modified: haiku/trunk/src/tools/translation/inspector/InspectorApp.cpp =================================================================== --- haiku/trunk/src/tools/translation/inspector/InspectorApp.cpp 2010-06-21 18:50:51 UTC (rev 37207) +++ haiku/trunk/src/tools/translation/inspector/InspectorApp.cpp 2010-06-21 19:10:46 UTC (rev 37208) @@ -30,21 +30,28 @@ // DEALINGS IN THE SOFTWARE. /*****************************************************************************/ +#include "Constants.h" #include "InspectorApp.h" -#include "Constants.h" #include "ImageWindow.h" #include "TranslatorItem.h" -#include <Window.h> + +#include <Directory.h> #include <Message.h> #include <String.h> -#include <Directory.h> +#include <Window.h> +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "InspectorApp" + + InspectorApp::InspectorApp() : BApplication(APP_SIG) { fpActivesWin = NULL; fpInfoWin = NULL; + be_locale->GetAppCatalog(&fAppCatalog); + AddToTranslatorsList("/system/add-ons/Translators", SYSTEM_TRANSLATOR); AddToTranslatorsList("/boot/home/config/add-ons/Translators", @@ -79,7 +86,8 @@ case M_ACTIVE_TRANSLATORS_WINDOW: if (!fpActivesWin) fpActivesWin = new ActiveTranslatorsWindow( - BRect(625, 350, 800, 600), "Active Translators", + BRect(625, 350, 800, 600), + B_TRANSLATE("Active Translators"), GetTranslatorsList()); break; case M_ACTIVE_TRANSLATORS_WINDOW_QUIT: @@ -89,7 +97,9 @@ case M_INFO_WINDOW: if (!fpInfoWin) fpInfoWin = new InfoWindow(BRect(625, 50, 800, 300), - "Info Win", fbstrInfo.String()); + B_TRANSLATE_COMMENT("Info Win", + "This is a quite narrow info window and title 'Info Win' " + "is therefore shortened."), fbstrInfo.String()); break; case M_INFO_WINDOW_QUIT: fpInfoWin = NULL; @@ -126,6 +136,7 @@ int main(int argc, char **argv) { InspectorApp *papp = new InspectorApp(); + papp->Run(); delete papp; Modified: haiku/trunk/src/tools/translation/inspector/InspectorApp.h =================================================================== --- haiku/trunk/src/tools/translation/inspector/InspectorApp.h 2010-06-21 18:50:51 UTC (rev 37207) +++ haiku/trunk/src/tools/translation/inspector/InspectorApp.h 2010-06-21 19:10:46 UTC (rev 37208) @@ -36,9 +36,12 @@ #include "ActiveTranslatorsWindow.h" #include "InfoWindow.h" #include <Application.h> +#include <Catalog.h> +#include <Locale.h> +#include <List.h> #include <String.h> -#include <List.h> + class InspectorApp : public BApplication { public: InspectorApp(); @@ -54,6 +57,7 @@ BList flstTranslators; ActiveTranslatorsWindow *fpActivesWin; InfoWindow *fpInfoWin; + BCatalog fAppCatalog; }; #endif // #ifndef INSPECTORAPP_H Modified: haiku/trunk/src/tools/translation/inspector/Jamfile =================================================================== --- haiku/trunk/src/tools/translation/inspector/Jamfile 2010-06-21 18:50:51 UTC (rev 37207) +++ haiku/trunk/src/tools/translation/inspector/Jamfile 2010-06-21 19:10:46 UTC (rev 37208) @@ -11,5 +11,14 @@ ImageWindow.cpp InspectorApp.cpp ; -LinkAgainst Inspector : be tracker translation $(TARGET_LIBSUPC++) ; +DoCatalogs Inspector : + x.vnd.OBOS-Inspector + : + InspectorApp.cpp + ImageWindow.cpp + ImageView.cpp + ActiveTranslatorsWindow.cpp +; +LinkAgainst Inspector : be tracker locale translation $(TARGET_LIBSUPC++) ; +