Patch by Jorma Karvonen (#6075): translate Inspector application. Thanks!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37208 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues 2010-06-21 19:10:46 +00:00
parent bf48aa4321
commit 6e608fa5fb
6 changed files with 213 additions and 78 deletions

View File

@ -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 @@ ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name,
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);

View File

@ -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 @@ ImageView::ImageView(BRect rect, const char *name)
SetPenSize(PEN_SIZE);
}
ImageView::~ImageView()
{
delete fpbitmap;
fpbitmap = NULL;
}
void
ImageView::AttachedToWindow()
{
AdjustScrollBars();
}
void
ImageView::Draw(BRect rect)
{
@ -98,12 +106,14 @@ ImageView::Draw(BRect rect)
}
}
void
ImageView::ReDraw()
{
Draw(Bounds());
}
void
ImageView::FrameResized(float width, float height)
{
@ -113,6 +123,7 @@ ImageView::FrameResized(float width, float height)
Invalidate();
}
void
ImageView::MouseDown(BPoint point)
{
@ -139,16 +150,19 @@ ImageView::MouseDown(BPoint point)
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 @@ ImageView::MessageReceived(BMessage *pmsg)
}
}
void
ImageView::SaveImageAtDropLocation(BMessage *pmsg)
{
@ -189,13 +204,15 @@ ImageView::SaveImageAtDropLocation(BMessage *pmsg)
} 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 @@ ImageView::AdjustScrollBars()
}
}
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 @@ get_color_space_name(color_space colors)
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 @@ hex_format(uint32 num)
return str;
}
// convert passed number to a string of 4 characters
// and return that string
const char *
@ -319,22 +340,40 @@ char_format(uint32 num)
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 @@ ImageView::UpdateInfoWindow(const BPath &path, BMessage &ioExtension,
{
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 @@ ImageView::SelectTranslatorRoster(BTranslatorRoster &roster)
return &roster;
}
void
ImageView::SetImage(BMessage *pmsg)
{
@ -454,7 +552,6 @@ ImageView::SetImage(BMessage *pmsg)
if (!proster)
// throw exception
chk = B_ERROR;
// determine what type the image is
translator_info tinfo;
BMessage ioExtension;
@ -494,9 +591,8 @@ ImageView::SetImage(BMessage *pmsg)
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 @@ ImageView::SetImage(BMessage *pmsg)
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 @@ ImageView::SetImage(BMessage *pmsg)
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 @@ ImageView::SetImage(BMessage *pmsg)
} 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 @@ ImageView::FirstPage()
}
}
void
ImageView::LastPage()
{
@ -554,6 +651,7 @@ ImageView::LastPage()
}
}
void
ImageView::NextPage()
{
@ -563,6 +661,7 @@ ImageView::NextPage()
}
}
void
ImageView::PrevPage()
{

View File

@ -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 @@ ImageWindow::ImageWindow(BRect rect, const char *name)
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 @@ ImageWindow::ImageWindow(BRect rect, const char *name)
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 @@ ImageWindow::ImageWindow(BRect rect, const char *name)
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 @@ ImageWindow::MessageReceived(BMessage *pmsg)
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;

View File

@ -30,14 +30,19 @@
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#include "InspectorApp.h"
#include "Constants.h"
#include "InspectorApp.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)
@ -45,6 +50,8 @@ InspectorApp::InspectorApp()
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 @@ InspectorApp::MessageReceived(BMessage *pmsg)
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 @@ InspectorApp::MessageReceived(BMessage *pmsg)
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 @@ InspectorApp::GetTranslatorsList()
int main(int argc, char **argv)
{
InspectorApp *papp = new InspectorApp();
papp->Run();
delete papp;

View File

@ -36,8 +36,11 @@
#include "ActiveTranslatorsWindow.h"
#include "InfoWindow.h"
#include <Application.h>
#include <String.h>
#include <Catalog.h>
#include <Locale.h>
#include <List.h>
#include <String.h>
class InspectorApp : public BApplication {
public:
@ -54,6 +57,7 @@ private:
BList flstTranslators;
ActiveTranslatorsWindow *fpActivesWin;
InfoWindow *fpInfoWin;
BCatalog fAppCatalog;
};
#endif // #ifndef INSPECTORAPP_H

View File

@ -11,5 +11,14 @@ Application Inspector :
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++) ;