From d1360823ff122e2862b640e20481fd273a9d5dbe Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Tue, 1 Jul 2003 03:48:17 +0000 Subject: [PATCH] Added beginnings of Active Translators window -- allows the user to select which translators will be active when an image is opened or saved git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3782 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../inspector/ActiveTranslatorsWindow.cpp | 116 ++++++++++++++++++ .../inspector/ActiveTranslatorsWindow.h | 54 ++++++++ src/tools/translation/inspector/Constants.h | 14 ++- src/tools/translation/inspector/ImageView.cpp | 2 +- .../translation/inspector/ImageWindow.cpp | 5 + .../translation/inspector/InspectorApp.cpp | 24 ++-- .../translation/inspector/InspectorApp.h | 2 + src/tools/translation/inspector/Jamfile | 1 + 8 files changed, 203 insertions(+), 15 deletions(-) create mode 100644 src/tools/translation/inspector/ActiveTranslatorsWindow.cpp create mode 100644 src/tools/translation/inspector/ActiveTranslatorsWindow.h diff --git a/src/tools/translation/inspector/ActiveTranslatorsWindow.cpp b/src/tools/translation/inspector/ActiveTranslatorsWindow.cpp new file mode 100644 index 0000000000..359ed6c68c --- /dev/null +++ b/src/tools/translation/inspector/ActiveTranslatorsWindow.cpp @@ -0,0 +1,116 @@ +/*****************************************************************************/ +// ActiveTranslatorsWindow +// Written by Michael Wilber, OBOS Translation Kit Team +// +// ActiveTranslatorsWindow.cpp +// +// BWindow class for displaying information about the currently open +// document +// +// +// 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 "Constants.h" +#include "ActiveTranslatorsWindow.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name) + : BWindow(rect, name, B_FLOATING_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", + 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); + + AddChild(new BScrollView("scroll_list", fplist, B_FOLLOW_LEFT | B_FOLLOW_TOP, + 0, false, true)); + + SetSizeLimits(100, 10000, 100, 10000); + + Show(); +} + +void +ActiveTranslatorsWindow::AddTranslatorsToList(const char *path, + BStringItem *pparent) +{ + DIR *dir = opendir(path); + if (!dir) { + return; + } + 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() +{ +} + +void +ActiveTranslatorsWindow::FrameResized(float width, float height) +{ +} + +void +ActiveTranslatorsWindow::MessageReceived(BMessage *pmsg) +{ + switch (pmsg->what) { + default: + BWindow::MessageReceived(pmsg); + break; + } +} + +void +ActiveTranslatorsWindow::Quit() +{ + // tell the app to forget about this window + be_app->PostMessage(M_ACTIVE_TRANSLATORS_WINDOW_QUIT); + BWindow::Quit(); +} diff --git a/src/tools/translation/inspector/ActiveTranslatorsWindow.h b/src/tools/translation/inspector/ActiveTranslatorsWindow.h new file mode 100644 index 0000000000..63dd75d645 --- /dev/null +++ b/src/tools/translation/inspector/ActiveTranslatorsWindow.h @@ -0,0 +1,54 @@ +/*****************************************************************************/ +// ActiveTranslatorsWindow +// Written by Michael Wilber, OBOS Translation Kit Team +// +// ActiveTranslatorsWindow.h +// +// BWindow class for displaying information about the currently open +// document +// +// +// 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 ACTIVETRANSLATORSWINDOW_H +#define ACTIVETRANSLATORSWINDOW_H + +#include +#include + +class ActiveTranslatorsWindow : public BWindow { +public: + ActiveTranslatorsWindow(BRect rect, const char *name); + ~ActiveTranslatorsWindow(); + void FrameResized(float width, float height); + void MessageReceived(BMessage *pmsg); + void Quit(); + +private: + void AddTranslatorsToList(const char *path, BStringItem *pparent); + + BOutlineListView *fplist; + BStringItem *fpuserItem; + BStringItem *fpsystemItem; +}; + +#endif // #ifndef ACTIVETRANSLATORSWINDOW_H diff --git a/src/tools/translation/inspector/Constants.h b/src/tools/translation/inspector/Constants.h index 8a04e8f18c..19dec94c08 100644 --- a/src/tools/translation/inspector/Constants.h +++ b/src/tools/translation/inspector/Constants.h @@ -32,12 +32,14 @@ #define MESSAGES_H // BMessage 'what' values -#define M_OPEN_IMAGE 'opim' -#define M_SAVE_IMAGE 'saim' -#define M_OPEN_FILE_PANEL 'ofpl' -#define M_INFO_WINDOW 'infw' -#define M_INFO_WINDOW_QUIT 'infq' -#define M_INFO_WINDOW_TEXT 'inft' +#define M_OPEN_IMAGE 'opim' +#define M_SAVE_IMAGE 'saim' +#define M_OPEN_FILE_PANEL 'ofpl' +#define M_ACTIVE_TRANSLATORS_WINDOW 'atrn' +#define M_ACTIVE_TRANSLATORS_WINDOW_QUIT 'atrq' +#define M_INFO_WINDOW 'infw' +#define M_INFO_WINDOW_QUIT 'infq' +#define M_INFO_WINDOW_TEXT 'inft' // String constants diff --git a/src/tools/translation/inspector/ImageView.cpp b/src/tools/translation/inspector/ImageView.cpp index f675855fa2..5bbe8276ab 100644 --- a/src/tools/translation/inspector/ImageView.cpp +++ b/src/tools/translation/inspector/ImageView.cpp @@ -414,7 +414,7 @@ ImageView::SetImage(BMessage *pmsg) AdjustScrollBars(); - pwin->Zoom(); + //pwin->Zoom(); // Perform all of the hard work of resizing the // window while taking into account the size of // the screen, the tab and borders of the window diff --git a/src/tools/translation/inspector/ImageWindow.cpp b/src/tools/translation/inspector/ImageWindow.cpp index 4b6316534e..841456c0f1 100644 --- a/src/tools/translation/inspector/ImageWindow.cpp +++ b/src/tools/translation/inspector/ImageWindow.cpp @@ -62,10 +62,15 @@ ImageWindow::ImageWindow(BRect rect, const char *name) pbar->AddItem(pmnufile); BMenu *pmnuwindow = new BMenu("Window"); + BMenuItem *pitmactives = new BMenuItem("Active Translators", + new BMessage(M_ACTIVE_TRANSLATORS_WINDOW), 'T', 0); + pitmactives->SetTarget(be_app); + BMenuItem *pitminfo = new BMenuItem("Info", new BMessage(M_INFO_WINDOW), 'I', 0); pitminfo->SetTarget(be_app); + pmnuwindow->AddItem(pitmactives); pmnuwindow->AddItem(pitminfo); pbar->AddItem(pmnuwindow); diff --git a/src/tools/translation/inspector/InspectorApp.cpp b/src/tools/translation/inspector/InspectorApp.cpp index a9145443bc..58c5a304b5 100644 --- a/src/tools/translation/inspector/InspectorApp.cpp +++ b/src/tools/translation/inspector/InspectorApp.cpp @@ -40,6 +40,7 @@ InspectorApp::InspectorApp() : BApplication(APP_SIG) { + fpactiveswin = NULL; fpinfowin = NULL; // Show application window @@ -52,12 +53,23 @@ void InspectorApp::MessageReceived(BMessage *pmsg) { switch (pmsg->what) { - case M_INFO_WINDOW: - if (!fpinfowin) - fpinfowin = new InfoWindow(BRect(50, 50, 150, 150), - "Info Win", fbstrInfo.String()); + case M_ACTIVE_TRANSLATORS_WINDOW: + if (!fpactiveswin) + fpactiveswin = new ActiveTranslatorsWindow( + BRect(625, 350, 800, 600), "Active Translators"); + break; + case M_ACTIVE_TRANSLATORS_WINDOW_QUIT: + fpactiveswin = NULL; break; + case M_INFO_WINDOW: + if (!fpinfowin) + fpinfowin = new InfoWindow(BRect(625, 50, 800, 300), + "Info Win", fbstrInfo.String()); + break; + case M_INFO_WINDOW_QUIT: + fpinfowin = NULL; + break; case M_INFO_WINDOW_TEXT: // If image view is telling me to // update the info window... @@ -66,10 +78,6 @@ InspectorApp::MessageReceived(BMessage *pmsg) fpinfowin->PostMessage(pmsg); break; - case M_INFO_WINDOW_QUIT: - fpinfowin = NULL; - break; - default: BApplication::MessageReceived(pmsg); break; diff --git a/src/tools/translation/inspector/InspectorApp.h b/src/tools/translation/inspector/InspectorApp.h index c1dcecb32b..95ce04631e 100644 --- a/src/tools/translation/inspector/InspectorApp.h +++ b/src/tools/translation/inspector/InspectorApp.h @@ -33,6 +33,7 @@ #ifndef INSPECTORAPP_H #define INSPECTORAPP_H +#include "ActiveTranslatorsWindow.h" #include "InfoWindow.h" #include #include @@ -45,6 +46,7 @@ public: private: BString fbstrInfo; + ActiveTranslatorsWindow *fpactiveswin; InfoWindow *fpinfowin; }; diff --git a/src/tools/translation/inspector/Jamfile b/src/tools/translation/inspector/Jamfile index 13d7bc4ef8..0074769576 100644 --- a/src/tools/translation/inspector/Jamfile +++ b/src/tools/translation/inspector/Jamfile @@ -4,6 +4,7 @@ AddResources Inspector : Inspector.rsrc ; App Inspector : StatusCheck.cpp + ActiveTranslatorsWindow.cpp InfoWindow.cpp ImageView.cpp ImageWindow.cpp