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 "ActiveTranslatorsWindow.h"
#include "TranslatorItem.h"
#include <Application.h>
#include <ScrollView.h>
#include <Message.h>
@ -41,22 +42,25 @@
#include <unistd.h>
#include <sys/stat.h>
ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name)
: BWindow(rect, name, B_FLOATING_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name,
BList *plist)
: BWindow(rect, name, B_DOCUMENT_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
{
BRect rctframe = Bounds();
rctframe.InsetBy(5, 5);
rctframe.right -= B_V_SCROLL_BAR_WIDTH;
fplist = new BOutlineListView(rctframe, "translators_list",
fpListView = new BOutlineListView(rctframe, "translators_list",
B_MULTIPLE_SELECTION_LIST);
fplist->AddItem(fpuserItem = new BStringItem("User Translators"));
fplist->AddItem(fpsystemItem = new BStringItem("System Translators"));
AddTranslatorsToList("/boot/home/config/add-ons/Translators", fpuserItem);
AddTranslatorsToList("/system/add-ons/Translators", fpsystemItem);
fpListView->AddItem(fpUserItem = new BStringItem("User Translators"));
fpUserItem->SetEnabled(false);
fpListView->AddItem(fpSystemItem = new BStringItem("System Translators"));
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));
SetSizeLimits(100, 10000, 100, 10000);
@ -65,27 +69,15 @@ ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name)
}
void
ActiveTranslatorsWindow::AddTranslatorsToList(const char *path,
ActiveTranslatorsWindow::AddTranslatorsToList(BList *plist, int32 group,
BStringItem *pparent)
{
DIR *dir = opendir(path);
if (!dir) {
return;
BTranslatorItem *pitem;
for (int32 i = 0; i < plist->CountItems(); i++) {
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()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,6 +3,7 @@ SubDir OBOS_TOP src tools translation inspector ;
AddResources Inspector : Inspector.rsrc ;
App Inspector :
TranslatorItem.cpp
StatusCheck.cpp
ActiveTranslatorsWindow.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