The ActiveTranslatorsWindow now allows you to select which Translators to be loaded, added ShowImage-like border around the image, changed a few member variable names to be more readable

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3877 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber 2003-07-06 20:31:31 +00:00
parent ea39092263
commit e5ef530596
9 changed files with 253 additions and 65 deletions

View File

@ -31,6 +31,7 @@
#include "Constants.h" #include "Constants.h"
#include "ActiveTranslatorsWindow.h" #include "ActiveTranslatorsWindow.h"
#include "TranslatorItem.h"
#include <Application.h> #include <Application.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <Message.h> #include <Message.h>
@ -41,22 +42,25 @@
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name) ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name,
: BWindow(rect, name, B_FLOATING_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) BList *plist)
: BWindow(rect, name, B_DOCUMENT_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
{ {
BRect rctframe = Bounds(); BRect rctframe = Bounds();
rctframe.InsetBy(5, 5); rctframe.InsetBy(5, 5);
rctframe.right -= B_V_SCROLL_BAR_WIDTH; rctframe.right -= B_V_SCROLL_BAR_WIDTH;
fplist = new BOutlineListView(rctframe, "translators_list", fpListView = new BOutlineListView(rctframe, "translators_list",
B_MULTIPLE_SELECTION_LIST); B_MULTIPLE_SELECTION_LIST);
fplist->AddItem(fpuserItem = new BStringItem("User Translators")); fpListView->AddItem(fpUserItem = new BStringItem("User Translators"));
fplist->AddItem(fpsystemItem = new BStringItem("System Translators")); fpUserItem->SetEnabled(false);
AddTranslatorsToList("/boot/home/config/add-ons/Translators", fpuserItem); fpListView->AddItem(fpSystemItem = new BStringItem("System Translators"));
AddTranslatorsToList("/system/add-ons/Translators", fpsystemItem); fpSystemItem->SetEnabled(false);
AddTranslatorsToList(plist, USER_TRANSLATOR, fpUserItem);
AddTranslatorsToList(plist, SYSTEM_TRANSLATOR, fpSystemItem);
AddChild(new BScrollView("scroll_list", fplist, B_FOLLOW_LEFT | B_FOLLOW_TOP, AddChild(new BScrollView("scroll_list", fpListView, B_FOLLOW_LEFT | B_FOLLOW_TOP,
0, false, true)); 0, false, true));
SetSizeLimits(100, 10000, 100, 10000); SetSizeLimits(100, 10000, 100, 10000);
@ -65,27 +69,15 @@ ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name)
} }
void void
ActiveTranslatorsWindow::AddTranslatorsToList(const char *path, ActiveTranslatorsWindow::AddTranslatorsToList(BList *plist, int32 group,
BStringItem *pparent) BStringItem *pparent)
{ {
DIR *dir = opendir(path); BTranslatorItem *pitem;
if (!dir) { for (int32 i = 0; i < plist->CountItems(); i++) {
return; pitem = static_cast<BTranslatorItem *>(plist->ItemAt(i));
if (pitem->Group() == group)
fpListView->AddUnder(pitem, pparent);
} }
struct dirent *dent;
struct stat stbuf;
char cwd[PATH_MAX] = "";
while (NULL != (dent = readdir(dir))) {
strcpy(cwd, path);
strcat(cwd, "/");
strcat(cwd, dent->d_name);
status_t err = stat(cwd, &stbuf);
if (!err && S_ISREG(stbuf.st_mode) &&
strcmp(dent->d_name, ".") && strcmp(dent->d_name, ".."))
fplist->AddUnder(new BStringItem(dent->d_name), pparent);
}
closedir(dir);
} }
ActiveTranslatorsWindow::~ActiveTranslatorsWindow() ActiveTranslatorsWindow::~ActiveTranslatorsWindow()

View File

@ -34,21 +34,22 @@
#include <Window.h> #include <Window.h>
#include <OutlineListView.h> #include <OutlineListView.h>
#include <List.h>
class ActiveTranslatorsWindow : public BWindow { class ActiveTranslatorsWindow : public BWindow {
public: public:
ActiveTranslatorsWindow(BRect rect, const char *name); ActiveTranslatorsWindow(BRect rect, const char *name, BList *plist);
~ActiveTranslatorsWindow(); ~ActiveTranslatorsWindow();
void FrameResized(float width, float height); void FrameResized(float width, float height);
void MessageReceived(BMessage *pmsg); void MessageReceived(BMessage *pmsg);
void Quit(); void Quit();
private: private:
void AddTranslatorsToList(const char *path, BStringItem *pparent); void AddTranslatorsToList(BList *plist, int32 group, BStringItem *pparent);
BOutlineListView *fplist; BOutlineListView *fpListView;
BStringItem *fpuserItem; BStringItem *fpUserItem;
BStringItem *fpsystemItem; BStringItem *fpSystemItem;
}; };
#endif // #ifndef ACTIVETRANSLATORSWINDOW_H #endif // #ifndef ACTIVETRANSLATORSWINDOW_H

View File

@ -34,8 +34,11 @@
#include "ImageView.h" #include "ImageView.h"
#include "Constants.h" #include "Constants.h"
#include "StatusCheck.h" #include "StatusCheck.h"
#include "InspectorApp.h"
#include "TranslatorItem.h"
#include <Application.h> #include <Application.h>
#include <Message.h> #include <Message.h>
#include <List.h>
#include <String.h> #include <String.h>
#include <TranslationUtils.h> #include <TranslationUtils.h>
#include <TranslatorRoster.h> #include <TranslatorRoster.h>
@ -52,12 +55,18 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#define BORDER_WIDTH 16
#define BORDER_HEIGHT 16
#define PEN_SIZE 1.0f
ImageView::ImageView(BRect rect, const char *name) ImageView::ImageView(BRect rect, const char *name)
: BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS) : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS)
{ {
fpbitmap = NULL; fpbitmap = NULL;
SetViewColor(255, 255, 255); SetViewColor(192, 192, 192);
SetHighColor(0, 0, 0);
SetPenSize(PEN_SIZE);
} }
ImageView::~ImageView() ImageView::~ImageView()
@ -75,21 +84,30 @@ ImageView::AttachedToWindow()
void void
ImageView::Draw(BRect rect) ImageView::Draw(BRect rect)
{ {
if (HasImage()) if (HasImage()) {
DrawBitmap(fpbitmap, BPoint(0, 0)); // Draw black rectangle around image
StrokeRect(
BRect(BORDER_WIDTH - PEN_SIZE,
BORDER_HEIGHT - PEN_SIZE,
fpbitmap->Bounds().Width() + BORDER_WIDTH + PEN_SIZE,
fpbitmap->Bounds().Height() + BORDER_HEIGHT + PEN_SIZE));
DrawBitmap(fpbitmap, BPoint(BORDER_WIDTH, BORDER_HEIGHT));
}
}
void
ImageView::ReDraw()
{
Draw(Bounds());
} }
void void
ImageView::FrameResized(float width, float height) ImageView::FrameResized(float width, float height)
{ {
AdjustScrollBars(); AdjustScrollBars();
// If there is a bitmap, draw it. if (!HasImage())
// If not, invalidate the entire view so that
// the advice text will be displayed
if (HasImage())
ReDraw();
else
Invalidate(); Invalidate();
} }
@ -186,9 +204,9 @@ ImageView::AdjustScrollBars()
float prop, range; float prop, range;
BScrollBar *psb = ScrollBar(B_HORIZONTAL); BScrollBar *psb = ScrollBar(B_HORIZONTAL);
if (psb) { if (psb) {
range = rctbitmap.Width() - rctview.Width(); range = rctbitmap.Width() + (BORDER_WIDTH * 2) - rctview.Width();
if (range < 0) range = 0; if (range < 0) range = 0;
prop = rctview.Width() / rctbitmap.Width(); prop = rctview.Width() / (rctbitmap.Width() + (BORDER_WIDTH * 2));
if (prop > 1.0f) prop = 1.0f; if (prop > 1.0f) prop = 1.0f;
psb->SetRange(0, range); psb->SetRange(0, range);
psb->SetProportion(prop); psb->SetProportion(prop);
@ -197,9 +215,9 @@ ImageView::AdjustScrollBars()
psb = ScrollBar(B_VERTICAL); psb = ScrollBar(B_VERTICAL);
if (psb) { if (psb) {
range = rctbitmap.Height() - rctview.Height(); range = rctbitmap.Height() + (BORDER_HEIGHT * 2) - rctview.Height();
if (range < 0) range = 0; if (range < 0) range = 0;
prop = rctview.Height() / rctbitmap.Height(); prop = rctview.Height() / (rctbitmap.Height() + (BORDER_HEIGHT * 2));
if (prop > 1.0f) prop = 1.0f; if (prop > 1.0f) prop = 1.0f;
psb->SetRange(0, range); psb->SetRange(0, range);
psb->SetProportion(prop); psb->SetProportion(prop);
@ -340,6 +358,33 @@ ImageView::UpdateInfoWindow(const BPath &path, const translator_info &tinfo,
be_app->PostMessage(&msg); be_app->PostMessage(&msg);
} }
BTranslatorRoster *
ImageView::SelectTranslatorRoster(BTranslatorRoster &roster)
{
bool bNoneSelected = true;
InspectorApp *papp;
papp = static_cast<InspectorApp *>(be_app);
if (papp) {
BList *plist = papp->GetTranslatorsList();
if (plist) {
for (int32 i = 0; i < plist->CountItems(); i++) {
BTranslatorItem *pitem =
static_cast<BTranslatorItem *>(plist->ItemAt(i));
if (pitem->IsSelected()) {
bNoneSelected = false;
roster.AddTranslators(pitem->Path());
}
}
}
}
if (bNoneSelected)
return BTranslatorRoster::Default();
else
return &roster;
}
void void
ImageView::SetImage(BMessage *pmsg) ImageView::SetImage(BMessage *pmsg)
{ {
@ -354,8 +399,9 @@ ImageView::SetImage(BMessage *pmsg)
BFile file(&ref, B_READ_ONLY); BFile file(&ref, B_READ_ONLY);
chk = file.InitCheck(); chk = file.InitCheck();
BTranslatorRoster *proster = BTranslatorRoster::Default(); BTranslatorRoster roster, *proster;
proster = SelectTranslatorRoster(roster);
if (!proster) if (!proster)
// throw exception // throw exception
chk = B_ERROR; chk = B_ERROR;
@ -398,9 +444,9 @@ ImageView::SetImage(BMessage *pmsg)
// reflect the size of the new bitmap // reflect the size of the new bitmap
float width, height; float width, height;
BMenuBar *pbar = pwin->KeyMenuBar(); BMenuBar *pbar = pwin->KeyMenuBar();
width = fpbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH; width = fpbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH + (BORDER_WIDTH * 2);
height = fpbitmap->Bounds().Height() + height = fpbitmap->Bounds().Height() +
pbar->Bounds().Height() + B_H_SCROLL_BAR_HEIGHT + 1; pbar->Bounds().Height() + B_H_SCROLL_BAR_HEIGHT + (BORDER_HEIGHT * 2) + 1;
BScreen *pscreen = new BScreen(pwin); BScreen *pscreen = new BScreen(pwin);
BRect rctscreen = pscreen->Frame(); BRect rctscreen = pscreen->Frame();
@ -424,8 +470,8 @@ ImageView::SetImage(BMessage *pmsg)
// for the current image // for the current image
// repaint view // repaint view
FillRect(Bounds()); Invalidate();
ReDraw();
} catch (StatusNotOKException) { } catch (StatusNotOKException) {
BAlert *palert = new BAlert(NULL, BAlert *palert = new BAlert(NULL,
"Sorry, unable to load the image.", "OK"); "Sorry, unable to load the image.", "OK");

View File

@ -36,6 +36,7 @@
#include <View.h> #include <View.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Path.h> #include <Path.h>
#include <TranslatorRoster.h>
class ImageView : public BView { class ImageView : public BView {
public: public:
@ -56,10 +57,12 @@ public:
private: private:
void UpdateInfoWindow(const BPath &path, const translator_info &info, void UpdateInfoWindow(const BPath &path, const translator_info &info,
const char *tranname, const char *traninfo, int32 tranversion); const char *tranname, const char *traninfo, int32 tranversion);
void ReDraw() { Draw(Bounds()); }; void ReDraw();
void AdjustScrollBars(); void AdjustScrollBars();
void SaveImageAtDropLocation(BMessage *pmsg); void SaveImageAtDropLocation(BMessage *pmsg);
BTranslatorRoster *SelectTranslatorRoster(BTranslatorRoster &roster);
BBitmap *fpbitmap; BBitmap *fpbitmap;
}; };

View File

@ -33,15 +33,22 @@
#include "InspectorApp.h" #include "InspectorApp.h"
#include "Constants.h" #include "Constants.h"
#include "ImageWindow.h" #include "ImageWindow.h"
#include "TranslatorItem.h"
#include <Window.h> #include <Window.h>
#include <Message.h> #include <Message.h>
#include <String.h> #include <String.h>
#include <Directory.h>
InspectorApp::InspectorApp() InspectorApp::InspectorApp()
: BApplication(APP_SIG) : BApplication(APP_SIG)
{ {
fpactiveswin = NULL; fpActivesWin = NULL;
fpinfowin = NULL; fpInfoWin = NULL;
AddToTranslatorsList("/system/add-ons/Translators",
SYSTEM_TRANSLATOR);
AddToTranslatorsList("/boot/home/config/add-ons/Translators",
USER_TRANSLATOR);
// Show application window // Show application window
BRect rect(100, 100, 500, 400); BRect rect(100, 100, 500, 400);
@ -49,33 +56,50 @@ InspectorApp::InspectorApp()
pwin->Show(); pwin->Show();
} }
void
InspectorApp::AddToTranslatorsList(const char *folder, int32 group)
{
BDirectory dir;
if (dir.SetTo(folder) == B_OK) {
BEntry ent;
while (dir.GetNextEntry(&ent) == B_OK) {
BPath path;
if (ent.GetPath(&path) == B_OK)
flstTranslators.AddItem(
new BTranslatorItem(path.Leaf(), path.Path(), group));
}
}
}
void void
InspectorApp::MessageReceived(BMessage *pmsg) InspectorApp::MessageReceived(BMessage *pmsg)
{ {
switch (pmsg->what) { switch (pmsg->what) {
case M_ACTIVE_TRANSLATORS_WINDOW: case M_ACTIVE_TRANSLATORS_WINDOW:
if (!fpactiveswin) if (!fpActivesWin)
fpactiveswin = new ActiveTranslatorsWindow( fpActivesWin = new ActiveTranslatorsWindow(
BRect(625, 350, 800, 600), "Active Translators"); BRect(625, 350, 800, 600), "Active Translators",
GetTranslatorsList());
break; break;
case M_ACTIVE_TRANSLATORS_WINDOW_QUIT: case M_ACTIVE_TRANSLATORS_WINDOW_QUIT:
fpactiveswin = NULL; fpActivesWin = NULL;
break; break;
case M_INFO_WINDOW: case M_INFO_WINDOW:
if (!fpinfowin) if (!fpInfoWin)
fpinfowin = new InfoWindow(BRect(625, 50, 800, 300), fpInfoWin = new InfoWindow(BRect(625, 50, 800, 300),
"Info Win", fbstrInfo.String()); "Info Win", fbstrInfo.String());
break; break;
case M_INFO_WINDOW_QUIT: case M_INFO_WINDOW_QUIT:
fpinfowin = NULL; fpInfoWin = NULL;
break; break;
case M_INFO_WINDOW_TEXT: case M_INFO_WINDOW_TEXT:
// If image view is telling me to // If image view is telling me to
// update the info window... // update the info window...
pmsg->FindString("text", &fbstrInfo); pmsg->FindString("text", &fbstrInfo);
if (fpinfowin) if (fpInfoWin)
fpinfowin->PostMessage(pmsg); fpInfoWin->PostMessage(pmsg);
break; break;
default: default:
@ -93,6 +117,12 @@ InspectorApp::RefsReceived(BMessage *pmsg)
pwin->PostMessage(pmsg); pwin->PostMessage(pmsg);
} }
BList *
InspectorApp::GetTranslatorsList()
{
return &flstTranslators;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
InspectorApp *papp = new InspectorApp(); InspectorApp *papp = new InspectorApp();

View File

@ -37,6 +37,7 @@
#include "InfoWindow.h" #include "InfoWindow.h"
#include <Application.h> #include <Application.h>
#include <String.h> #include <String.h>
#include <List.h>
class InspectorApp : public BApplication { class InspectorApp : public BApplication {
public: public:
@ -44,10 +45,15 @@ public:
void MessageReceived(BMessage *pmsg); void MessageReceived(BMessage *pmsg);
void RefsReceived(BMessage *pmsg); void RefsReceived(BMessage *pmsg);
BList *GetTranslatorsList();
private: private:
void AddToTranslatorsList(const char *folder, int32 group);
BString fbstrInfo; BString fbstrInfo;
ActiveTranslatorsWindow *fpactiveswin; BList flstTranslators;
InfoWindow *fpinfowin; ActiveTranslatorsWindow *fpActivesWin;
InfoWindow *fpInfoWin;
}; };
#endif // #ifndef INSPECTORAPP_H #endif // #ifndef INSPECTORAPP_H

View File

@ -3,6 +3,7 @@ SubDir OBOS_TOP src tools translation inspector ;
AddResources Inspector : Inspector.rsrc ; AddResources Inspector : Inspector.rsrc ;
App Inspector : App Inspector :
TranslatorItem.cpp
StatusCheck.cpp StatusCheck.cpp
ActiveTranslatorsWindow.cpp ActiveTranslatorsWindow.cpp
InfoWindow.cpp InfoWindow.cpp

View File

@ -0,0 +1,53 @@
/*****************************************************************************/
// BTranslatorItem
// Written by Michael Wilber, OBOS Translation Kit Team
//
// BTranslatorItem.cpp
//
// BStringItem based class for using a list of Translators in a BListView
//
//
// Copyright (c) 2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#include "TranslatorItem.h"
BTranslatorItem::BTranslatorItem(const char *text, const char *path, int32 group)
: BStringItem(text)
{
fpath.SetTo(path);
fgroup = UNKNOWN_GROUP;
if (group == SYSTEM_TRANSLATOR || group == USER_TRANSLATOR)
fgroup = group;
}
const char *
BTranslatorItem::Path() const
{
return fpath.String();
}
int32
BTranslatorItem::Group() const
{
return fgroup;
}

View File

@ -0,0 +1,56 @@
/*****************************************************************************/
// BTranslatorItem
// Written by Michael Wilber, OBOS Translation Kit Team
//
// BTranslatorItem.h
//
// BStringItem based class for using a list of Translators in a BListView
//
//
// Copyright (c) 2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#ifndef TRANSLATOR_ITEM_H
#define TRANSLATOR_ITEM_H
#include <ListItem.h>
#include <String.h>
// Group Options
enum {
UNKNOWN_GROUP = 0,
SYSTEM_TRANSLATOR = 1,
USER_TRANSLATOR = 2
};
class BTranslatorItem : public BStringItem {
public:
BTranslatorItem(const char *text, const char *path, int32 group);
const char *Path() const;
int32 Group() const;
private:
BString fpath;
int32 fgroup;
};
#endif // #ifndef TRANSLATOR_ITEM_H