* Fixed various minor font sensitivity/resize problems.

* Fixed translator version info; didn't correctly displayed versions < 1.
* Drastically improved looks of that info alert.
* Nicer version alert.
* Renamed class DataTranslationsView to TranslatorListView.
* Added license.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16722 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-03-11 20:14:13 +00:00
parent e7df4a4829
commit 5ac11f960a
10 changed files with 381 additions and 299 deletions
@@ -1,67 +1,80 @@
/* /*
* DataTranslations.cpp * Copyright 2002-2006, Haiku, Inc.
* DataTranslations [email protected] * Distributed under the terms of the MIT license.
* *
* Authors:
* Oliver Siebenmarck
* Andrew McCall, [email protected]
* Michael Wilber
*/ */
#include <Alert.h>
#include <Screen.h>
#include "DataTranslations.h" #include "DataTranslations.h"
#include "DataTranslationsWindow.h" #include "DataTranslationsWindow.h"
#include "DataTranslationsSettings.h" #include "DataTranslationsSettings.h"
#include "DataTranslationsMessages.h"
const char DataTranslationsApplication::kDataTranslationsApplicationSig[] = "application/x-vnd.OpenBeOS-prefs-translations"; #include <Alert.h>
#include <Directory.h>
#include <TranslatorRoster.h>
#include <TextView.h>
int main(int, char**)
{
DataTranslationsApplication myApplication;
myApplication.Run(); const char* kApplicationSignature = "application/x-vnd.haiku-translations";
return(0);
}
DataTranslationsApplication::DataTranslationsApplication() DataTranslationsApplication::DataTranslationsApplication()
:BApplication(kDataTranslationsApplicationSig) : BApplication(kApplicationSignature)
{ {
DataTranslationsWindow *window;
fSettings = new DataTranslationsSettings(); fSettings = new DataTranslationsSettings();
new DataTranslationsWindow();
window = new DataTranslationsWindow();
} }
DataTranslationsApplication::~DataTranslationsApplication()
{
delete fSettings;
}
void void
DataTranslationsApplication::SetWindowCorner(BPoint corner) DataTranslationsApplication::SetWindowCorner(BPoint corner)
{ {
fSettings->SetWindowCorner(corner); fSettings->SetWindowCorner(corner);
} }
void void
DataTranslationsApplication::AboutRequested(void) DataTranslationsApplication::AboutRequested()
{ {
(new BAlert("", "... written by Oliver Siebenmarck", "Cool!"))->Go(); BAlert *alert = new BAlert("about", "DataTranslations\n"
return; "\twritten by Oliver Siebenmarck and others\n"
"\tCopyright 2002-2006, Haiku.\n", "Ok");
BTextView *view = alert->TextView();
BFont font;
view->SetStylable(true);
view->GetFont(&font);
font.SetSize(18);
font.SetFace(B_BOLD_FACE);
view->SetFontAndColor(0, 16, &font);
alert->Go();
} }
DataTranslationsApplication::~DataTranslationsApplication()
{
delete fSettings;
}
void DataTranslationsApplication::Install_Done() void
DataTranslationsApplication::InstallDone()
{ {
(new BAlert("", (new BAlert("",
"You have to quit and restart running applications\n" "You have to quit and restart running applications\n"
"for the installed Translators to be available in them.", "for the installed Translators to be available for them.",
"OK"))->Go(); "OK"))->Go();
} }
void DataTranslationsApplication::RefsReceived(BMessage *message)
void
DataTranslationsApplication::RefsReceived(BMessage *message)
{ {
uint32 type; uint32 type;
int32 count; int32 count;
@@ -94,10 +107,9 @@ void DataTranslationsApplication::RefsReceived(BMessage *message)
if (keep->Go() == 0) if (keep->Go() == 0)
moveit = true; moveit = true;
if (moveit) // Just a quick move if (moveit) {
{ // Just a quick move
if (dirt.Contains(newfile.String())) if (dirt.Contains(newfile.String())) {
{
string.SetTo(""); string.SetTo("");
string << "An item named '" << e_name <<"' already is in the \nTranslators folder"; string << "An item named '" << e_name <<"' already is in the \nTranslators folder";
BAlert *myAlert = new BAlert("title", string.String() , "Overwrite", "Stop"); BAlert *myAlert = new BAlert("title", string.String() , "Overwrite", "Stop");
@@ -111,12 +123,11 @@ void DataTranslationsApplication::RefsReceived(BMessage *message)
dele.Remove(); dele.Remove();
} }
entry.MoveTo(&dirt); // Move it. entry.MoveTo(&dirt); // Move it.
Install_Done(); // Installation done InstallDone(); // Installation done
return; return;
} }
if (dirt.Contains(newfile.String())) if (dirt.Contains(newfile.String())) {
{
// File exists, What are we supposed to do now (Overwrite/_Stopp_?) // File exists, What are we supposed to do now (Overwrite/_Stopp_?)
string.SetTo(""); string.SetTo("");
string << "An item named '" << e_name <<"' already is in the \nTranslators folder"; string << "An item named '" << e_name <<"' already is in the \nTranslators folder";
@@ -129,8 +140,12 @@ void DataTranslationsApplication::RefsReceived(BMessage *message)
string.SetTo(path.Path()); // Fullpath+Filename string.SetTo(path.Path()); // Fullpath+Filename
BString BString command;
#ifdef __HAIKU__
command = "cp ";
#else
command = "copyattr -d -r "; command = "copyattr -d -r ";
#endif
command << string.String() << " " << newfile.String(); // Prepare Copy command << string.String() << " " << newfile.String(); // Prepare Copy
system(command.String()); // Execute copy command system(command.String()); // Execute copy command
@@ -140,29 +155,38 @@ void DataTranslationsApplication::RefsReceived(BMessage *message)
// The new Translator has been installed by now. // The new Translator has been installed by now.
// And done we are // And done we are
Install_Done(); InstallDone();
return; } else {
}
else
{
// Not a Translator // Not a Translator
no_trans(e_name); NoTranslatorError(e_name);
} }
} } else {
else
{
// Not even a file... // Not even a file...
no_trans(e_name); NoTranslatorError(e_name);
} }
} }
} }
void DataTranslationsApplication::no_trans(char item_name[B_FILE_NAME_LENGTH])
void
DataTranslationsApplication::NoTranslatorError(const char* name)
{ {
BString text; BString text;
text.SetTo("The item '"); text.SetTo("The item '");
text << item_name << "' does not appear to be a Translator and will not be installed"; text << name << "' does not appear to be a Translator and will not be installed.";
(new BAlert("", text.String(), "Stop"))->Go(); (new BAlert("", text.String(), "Stop"))->Go();
return; }
// #pragma mark -
int
main(int, char**)
{
DataTranslationsApplication app;
app.Run();
return 0;
} }
@@ -1,41 +1,45 @@
/*
* Copyright 2002-2006, Haiku, Inc.
* Distributed under the terms of the MIT license.
*
* Authors:
* Oliver Siebenmarck
* Andrew McCall, [email protected]
* Michael Wilber
*/
#ifndef DATA_TRANSLATIONS_H #ifndef DATA_TRANSLATIONS_H
#define DATA_TRANSLATIONS_H #define DATA_TRANSLATIONS_H
#include "DataTranslationsWindow.h"
#include "DataTranslationsSettings.h"
#include <Application.h> #include <Application.h>
#include <String.h> #include <String.h>
#include <Alert.h> #include <Alert.h>
#include <stdlib.h> #include <stdlib.h>
#include "DataTranslationsWindow.h"
#include "DataTranslationsView.h"
#include "DataTranslationsSettings.h"
class DataTranslationsApplication : public BApplication class DataTranslationsApplication : public BApplication {
{ public:
public:
DataTranslationsApplication(); DataTranslationsApplication();
virtual ~DataTranslationsApplication(); virtual ~DataTranslationsApplication();
// void MessageReceived(BMessage *message);
virtual void RefsReceived(BMessage *message); virtual void RefsReceived(BMessage *message);
virtual void AboutRequested(void);
BPoint WindowCorner() const {return fSettings->WindowCorner(); } BPoint WindowCorner() const {return fSettings->WindowCorner(); }
void SetWindowCorner(BPoint corner); void SetWindowCorner(BPoint corner);
void AboutRequested(void); private:
void InstallDone();
void NoTranslatorError(const char* name);
private: DataTranslationsSettings* fSettings;
void Install_Done();
static const char kDataTranslationsApplicationSig[];
DataTranslationsSettings *fSettings;
// Tell User our installation is done
void no_trans(char item_name[B_FILE_NAME_LENGTH]);
// Tell User he didn´t drop a translator
bool overwrite, moveit; bool overwrite, moveit;
BString string; BString string;
}; };
#endif #endif // DATA_TRANSLATIONS_H
@@ -1,4 +1,6 @@
resource(1, "BEOS:APP_SIG") #'MIMS' "application/x-vnd.haiku-translations";
resource(1, "BEOS:FILE_TYPES") message; resource(1, "BEOS:FILE_TYPES") message;
resource(101, "BEOS:L:STD_ICON") #'ICON' array resource(101, "BEOS:L:STD_ICON") #'ICON' array
@@ -57,8 +59,6 @@ resource(101, "BEOS:M:STD_ICON") #'MICN' array
$"FFFFFFFFFFFFFFFFFF00000E0F0F0F0F" $"FFFFFFFFFFFFFFFFFF00000E0F0F0F0F"
}; };
resource(1, "BEOS:APP_SIG") #'MIMS' "application/x-vnd.OpenBeOS-prefs-translations";
resource(1, "BEOS:APP_VERSION") #'APPV' array resource(1, "BEOS:APP_VERSION") #'APPV' array
{ {
$"00000000000000000100000001000000010000004F70656E42654F5300000000" $"00000000000000000100000001000000010000004F70656E42654F5300000000"
@@ -1,15 +1,21 @@
/* /*
* Copyright 2003-2006, Haiku, Inc.
DataTranslationsMessages.h * Distributed under the terms of the MIT license.
*
*/ * Authors:
* Unknown?
* Michael Wilber
*/
#ifndef DATA_TRANSLATIONS_MESSAGES_H #ifndef DATA_TRANSLATIONS_MESSAGES_H
#define DATA_TRANSLATIONS_MESSAGES_H #define DATA_TRANSLATIONS_MESSAGES_H
#include <SupportDefs.h>
#define BUTTON_MSG 'PRES' #define BUTTON_MSG 'PRES'
const uint32 SEL_CHANGE = 'SEch'; const uint32 SEL_CHANGE = 'SEch';
const uint32 ERROR_DETECTED = 'ERor'; const uint32 ERROR_DETECTED = 'ERor';
#endif #endif // DATA_TRANSLATIONS_MESSAGES_H
@@ -1,26 +0,0 @@
/*
*
* DataTranslationsView.h
*
* by Oliver Siebenmarck
*/
#ifndef DATA_TRANSLATIONS_VIEW_H
#define DATA_TRANSLATIONS_VIEW_H
#include <interface/View.h>
#include <interface/ListView.h>
class DataTranslationsView : public BListView {
public:
DataTranslationsView(BRect rect, const char *name,
list_view_type type = B_SINGLE_SELECTION_LIST);
~DataTranslationsView();
void MessageReceived(BMessage *message);
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *msg);
};
#endif
@@ -1,22 +1,43 @@
/* /*
* DataTranslationsWindow.cpp * Copyright 2002-2006, Haiku, Inc.
* Distributed under the terms of the MIT license.
* *
* Authors:
* Oliver Siebenmarck
* Andrew McCall, [email protected]
* Michael Wilber
*/ */
#include <Application.h>
#include <Message.h>
#include <Screen.h>
#include <TranslationDefs.h>
#include "DataTranslationsMessages.h"
#include "DataTranslationsWindow.h"
#include "DataTranslations.h" #include "DataTranslations.h"
#include "DataTranslationsMessages.h"
#include "DataTranslationsSettings.h"
#include "DataTranslationsWindow.h"
#include "IconView.h"
#include "TranslatorListView.h"
#include <Application.h>
#include <Screen.h>
#include <Alert.h>
#include <Bitmap.h>
#include <Box.h>
#include <Button.h>
#include <ListView.h>
#include <Path.h>
#include <ScrollView.h>
#include <String.h>
#include <StringView.h>
#include <TextView.h>
#include <TranslationDefs.h>
#include <TranslatorRoster.h>
#define DTW_RIGHT 400 #define DTW_RIGHT 400
#define DTW_BOTTOM 300 #define DTW_BOTTOM 300
DataTranslationsWindow::DataTranslationsWindow() DataTranslationsWindow::DataTranslationsWindow()
: BWindow(BRect(0, 0, DTW_RIGHT, DTW_BOTTOM), : BWindow(BRect(0, 0, DTW_RIGHT, DTW_BOTTOM),
"DataTranslations", B_TITLED_WINDOW, B_NOT_ZOOMABLE|B_NOT_RESIZABLE) "DataTranslations", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
{ {
MoveTo(dynamic_cast<DataTranslationsApplication *>(be_app)->WindowCorner()); MoveTo(dynamic_cast<DataTranslationsApplication *>(be_app)->WindowCorner());
@@ -39,42 +60,43 @@ DataTranslationsWindow::DataTranslationsWindow()
if (x != winf.left || y != winf.top) if (x != winf.left || y != winf.top)
MoveTo(x, y); MoveTo(x, y);
SetupViews(); _SetupViews();
Show(); Show();
} }
DataTranslationsWindow::~DataTranslationsWindow() DataTranslationsWindow::~DataTranslationsWindow()
{ {
} }
// Reads the installed translators and adds them to our BListView // Reads the installed translators and adds them to our BListView
status_t status_t
DataTranslationsWindow::PopulateListView() DataTranslationsWindow::_PopulateListView()
{ {
BTranslatorRoster *roster = BTranslatorRoster::Default(); BTranslatorRoster *roster = BTranslatorRoster::Default();
// Get all Translators on the system. Gives us the number of translators // Get all Translators on the system. Gives us the number of translators
// installed in num_translators and a reference to the first one // installed in num_translators and a reference to the first one
int32 num_translators; int32 numTranslators;
translator_id *translators; translator_id *translators = NULL;
roster->GetAllTranslators(&translators, &num_translators); roster->GetAllTranslators(&translators, &numTranslators);
for (int32 i = 0; i < num_translators; i++) { for (int32 i = 0; i < numTranslators; i++) {
// Getting the first three Infos: Name, Info & Version // Getting the first three Infos: Name, Info & Version
int32 tversion; int32 version;
const char *tname, *tinfo; const char *name, *info;
roster->GetTranslatorInfo(translators[i], &tname, &tinfo, &tversion); roster->GetTranslatorInfo(translators[i], &name, &info, &version);
fTranListView->AddItem(new BStringItem(tname)); fTranslatorListView->AddItem(new BStringItem(name));
} }
delete[] translators; delete[] translators;
translators = NULL;
return B_OK; return B_OK;
} }
status_t status_t
DataTranslationsWindow::GetTranInfo(int32 id, const char *&tranName, DataTranslationsWindow::_GetTranslatorInfo(int32 id, const char *&tranName,
const char *&tranInfo, int32 &tranVersion, BPath &tranPath) const char *&tranInfo, int32 &tranVersion, BPath &tranPath)
{ {
// Returns information about the translator with the given id // Returns information about the translator with the given id
@@ -82,15 +104,14 @@ DataTranslationsWindow::GetTranInfo(int32 id, const char *&tranName,
if (id < 0) if (id < 0)
return B_BAD_VALUE; return B_BAD_VALUE;
int32 num_translators = 0; int32 numTranslators = 0;
translator_id tid = 0, *translators = NULL; translator_id tid = 0, *translators = NULL;
BTranslatorRoster *roster = BTranslatorRoster::Default(); BTranslatorRoster *roster = BTranslatorRoster::Default();
roster->GetAllTranslators(&translators, &num_translators); roster->GetAllTranslators(&translators, &numTranslators);
tid = ((id < num_translators) ? translators[id] : 0); tid = ((id < numTranslators) ? translators[id] : 0);
delete[] translators; delete[] translators;
translators = NULL;
if (id >= num_translators) if (id >= numTranslators)
return B_BAD_VALUE; return B_BAD_VALUE;
// Getting the first three Infos: Name, Info & Version // Getting the first three Infos: Name, Info & Version
@@ -105,23 +126,23 @@ DataTranslationsWindow::GetTranInfo(int32 id, const char *&tranName,
return B_OK; return B_OK;
} }
status_t status_t
DataTranslationsWindow::ShowConfigView(int32 id) DataTranslationsWindow::_ShowConfigView(int32 id)
{ {
// Shows the config panel for the translator with the given id // Shows the config panel for the translator with the given id
if (id < 0) if (id < 0)
return B_BAD_VALUE; return B_BAD_VALUE;
int32 num_translators = 0; int32 numTranslators = 0;
translator_id tid = 0, *translators = NULL; translator_id tid = 0, *translators = NULL;
BTranslatorRoster *roster = BTranslatorRoster::Default(); BTranslatorRoster *roster = BTranslatorRoster::Default();
roster->GetAllTranslators(&translators, &num_translators); roster->GetAllTranslators(&translators, &numTranslators);
tid = ((id < num_translators) ? translators[id] : 0); tid = ((id < numTranslators) ? translators[id] : 0);
delete[] translators; delete[] translators;
translators = NULL;
if (id >= num_translators) if (id >= numTranslators)
return B_BAD_VALUE; return B_BAD_VALUE;
// fConfigView is NULL the first time this function // fConfigView is NULL the first time this function
@@ -159,23 +180,33 @@ DataTranslationsWindow::ShowConfigView(int32 id)
return B_OK; return B_OK;
} }
void void
DataTranslationsWindow::SetupViews() DataTranslationsWindow::_SetupViews()
{ {
fConfigView = NULL; fConfigView = NULL;
// This is NULL until a translator is // This is NULL until a translator is
// selected from the listview // selected from the listview
// Window box // Window box
BBox *mainBox = new BBox(BRect(0, 0, DTW_RIGHT, DTW_BOTTOM), BView* mainView = new BView(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS);
"All_Window", B_FOLLOW_ALL_SIDES, mainView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER); AddChild(mainView);
AddChild(mainBox);
// Add the translators list view
fTranslatorListView = new TranslatorListView(BRect(10, 10, 120, Bounds().Height() - 10),
"TransList", B_SINGLE_SELECTION_LIST);
fTranslatorListView->SetSelectionMessage(new BMessage(SEL_CHANGE));
BScrollView *scrollView = new BScrollView("scroll_trans", fTranslatorListView,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW | B_FRAME_EVENTS,
false, true, B_FANCY_BORDER);
mainView->AddChild(scrollView);
// Box around the config and info panels // Box around the config and info panels
fRightBox = new BBox(BRect(150, 10, 390, 290), "Right_Side", fRightBox = new BBox(BRect(130 + B_V_SCROLL_BAR_WIDTH, 10, Bounds().Width() - 10,
B_FOLLOW_ALL_SIDES); Bounds().Height() - 10), "Right_Side", B_FOLLOW_ALL);
mainBox->AddChild(fRightBox); mainView->AddChild(fRightBox);
// Add the translator icon view // Add the translator icon view
BRect rightRect(fRightBox->Bounds()), iconRect(0, 0, 31, 31); BRect rightRect(fRightBox->Bounds()), iconRect(0, 0, 31, 31);
@@ -187,40 +218,29 @@ DataTranslationsWindow::SetupViews()
// Add the translator info button // Add the translator info button
BRect infoRect(0, 0, 80, 20); BRect infoRect(0, 0, 80, 20);
infoRect.OffsetTo(rightRect.right - infoRect.Width(),
rightRect.bottom - 10 - infoRect.Height());
BButton *button = new BButton(infoRect, "STD", "Info...", BButton *button = new BButton(infoRect, "STD", "Info...",
new BMessage(BUTTON_MSG), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT, new BMessage(BUTTON_MSG), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
button->ResizeToPreferred();
button->MoveTo(fRightBox->Bounds().Width() - button->Bounds().Width() - 10.0f,
fRightBox->Bounds().Height() - button->Bounds().Height() - 10.0f);
fRightBox->AddChild(button); fRightBox->AddChild(button);
// Add the translator name view // Add the translator name view
BRect tranNameRect(iconRect.right + 5, iconRect.top, BRect tranNameRect(iconRect.right + 5, iconRect.top,
infoRect.left - 5, iconRect.bottom); infoRect.left - 5, iconRect.bottom);
fTranNameView = new BStringView(tranNameRect, "TranName", "None", fTranslatorNameView = new BStringView(tranNameRect, "TranName", "None",
B_FOLLOW_LEFT | B_FOLLOW_V_CENTER); B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
fRightBox->AddChild(fTranNameView); fRightBox->AddChild(fTranslatorNameView);
// Add the translators list view
fTranListView = new DataTranslationsView(BRect(10, 10, 120, 288),
"TransList", B_SINGLE_SELECTION_LIST);
fTranListView->SetSelectionMessage(new BMessage(SEL_CHANGE));
BScrollView *scrollView = new BScrollView("scroll_trans", fTranListView,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW | B_FRAME_EVENTS,
false, true, B_FANCY_BORDER);
mainBox->AddChild(scrollView);
// Populate the translators list view // Populate the translators list view
PopulateListView(); _PopulateListView();
// Set the focus fTranslatorListView->MakeFocus();
fTranListView->MakeFocus(); fTranslatorListView->Select(0, false);
// Select the first Translator in list
fTranListView->Select(0, false);
} }
bool bool
DataTranslationsWindow::QuitRequested() DataTranslationsWindow::QuitRequested()
{ {
@@ -231,18 +251,52 @@ DataTranslationsWindow::QuitRequested()
return true; return true;
} }
void
DataTranslationsWindow::_ShowInfoAlert(int32 id)
{
const char* name = NULL;
const char* info = NULL;
BPath path;
int32 version = 0;
_GetTranslatorInfo(id, name, info, version, path);
BString message;
message << "Name:\t" << name << "\nVersion:\t";
// Convert the version number into a readable format
message << (int)B_TRANSLATION_MAJOR_VERSION(version)
<< '.' << (int)B_TRANSLATION_MINOR_VERSION(version)
<< '.' << (int)B_TRANSLATION_REVISION_VERSION(version);
message << "\nInfo:\t\t" << info <<
"\n\nPath:\n" << path.Path() << "\n";
BAlert *alert = new BAlert("info", message.String(), "OK");
BTextView *view = alert->TextView();
BFont font;
view->SetStylable(true);
view->GetFont(&font);
font.SetFace(B_BOLD_FACE);
const char* labels[] = {"Name:", "Version:", "Info:", "Path:", NULL};
for (int32 i = 0; labels[i]; i++) {
int32 index = message.FindFirst(labels[i]);
view->SetFontAndColor(index, index + strlen(labels[i]), &font);
}
alert->Go();
}
void void
DataTranslationsWindow::MessageReceived(BMessage *message) DataTranslationsWindow::MessageReceived(BMessage *message)
{ {
BPath tranPath;
BString strInfoMsg;
const char *tranName = NULL, *tranInfo = NULL;
int32 selected = -1, tranVersion = 0;
switch (message->what) { switch (message->what) {
case BUTTON_MSG: case BUTTON_MSG:
selected = fTranListView->CurrentSelection(0); {
int32 selected = fTranslatorListView->CurrentSelection(0);
if (selected < 0) { if (selected < 0) {
// If no translator is selected, show a message explaining // If no translator is selected, show a message explaining
// what the config panel is for // what the config panel is for
@@ -255,42 +309,35 @@ DataTranslationsWindow::MessageReceived(BMessage *message)
break; break;
} }
GetTranInfo(selected, tranName, tranInfo, tranVersion, tranPath); _ShowInfoAlert(selected);
strInfoMsg << "Name: " << tranName << "\nVersion: ";
if (tranVersion < 0x100)
// If the version number doesn't follow the standard format,
// just print it as is
strInfoMsg << tranVersion;
else {
// Convert the version number into a readable format
strInfoMsg <<
static_cast<int>(B_TRANSLATION_MAJOR_VERSION(tranVersion)) << '.' <<
static_cast<int>(B_TRANSLATION_MINOR_VERSION(tranVersion)) << '.' <<
static_cast<int>(B_TRANSLATION_REVISION_VERSION(tranVersion));
}
strInfoMsg << "\nInfo: " << tranInfo <<
"\nPath: " << tranPath.Path() << "\n";
(new BAlert("Panel Info", strInfoMsg.String(), "OK"))->Go();
break; break;
}
case SEL_CHANGE: case SEL_CHANGE:
{
// Update the icon and translator info panel // Update the icon and translator info panel
// to match the new selection // to match the new selection
selected = fTranListView->CurrentSelection(0);
int32 selected = fTranslatorListView->CurrentSelection(0);
if (selected < 0) { if (selected < 0) {
// If none selected, clear the old one // If none selected, clear the old one
fIconView->DrawIcon(false); fIconView->DrawIcon(false);
fTranNameView->SetText(""); fTranslatorNameView->SetText("");
fRightBox->RemoveChild(fConfigView); fRightBox->RemoveChild(fConfigView);
break; break;
} }
ShowConfigView(selected); _ShowConfigView(selected);
GetTranInfo(selected, tranName, tranInfo, tranVersion, tranPath);
fTranNameView->SetText(tranPath.Leaf()); const char* name = NULL;
fIconView->SetIcon(tranPath); const char* info = NULL;
int32 version = 0;
BPath path;
_GetTranslatorInfo(selected, name, info, version, path);
fTranslatorNameView->SetText(path.Leaf());
fIconView->SetIcon(path);
break; break;
}
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
@@ -1,47 +1,45 @@
#ifndef DATATRANSLATIONS_WINDOW_H /*
#define DATATRANSLATIONS_WINDOW_H * Copyright 2002-2006, Haiku, Inc.
* Distributed under the terms of the MIT license.
*
* Authors:
* Oliver Siebenmarck
* Andrew McCall, mccall@digitalparadise.co.uk
* Michael Wilber
*/
#ifndef DATA_TRANSLATIONS_WINDOW_H
#define DATA_TRANSLATIONS_WINDOW_H
#ifndef _WINDOW_H
#include <Window.h>
#endif
#include <Box.h> //#include "DataTranslationsSettings.h"
#include <Button.h>
#include <SupportDefs.h>
#include <ListView.h>
#include <TranslatorRoster.h>
#include <TranslationDefs.h>
#include <ScrollView.h>
#include <Alert.h>
#include <String.h>
#include <StringView.h>
#include <Bitmap.h>
#include <storage/Path.h>
#include <storage/Directory.h>
#include <storage/Entry.h>
#include "DataTranslationsSettings.h"
#include "DataTranslationsView.h"
#include "IconView.h" #include "IconView.h"
#include <Window.h>
class BBox;
class BView;
class IconView;
class TranslatorListView;
class DataTranslationsWindow : public BWindow { class DataTranslationsWindow : public BWindow {
public: public:
DataTranslationsWindow(); DataTranslationsWindow();
~DataTranslationsWindow(); ~DataTranslationsWindow();
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
private: private:
status_t GetTranInfo(int32 id, const char *&tranName, const char *&tranInfo, status_t _GetTranslatorInfo(int32 id, const char *&name, const char *&info,
int32 &tranVersion, BPath &tranPath); int32 &version, BPath &path);
void _ShowInfoAlert(int32 id);
status_t _ShowConfigView(int32 id);
status_t _PopulateListView();
void _SetupViews();
status_t ShowConfigView(int32 id); TranslatorListView *fTranslatorListView;
status_t PopulateListView();
void SetupViews();
DataTranslationsView *fTranListView;
// List of Translators (left pane of window)
BBox *fRightBox; BBox *fRightBox;
// Box hosting fConfigView, fIconView, // Box hosting fConfigView, fIconView,
@@ -51,11 +49,8 @@ private:
// the translator config view // the translator config view
IconView *fIconView; IconView *fIconView;
// icon in the info panel BStringView *fTranslatorNameView;
BStringView *fTranNameView;
// the translator name, in the info panel
}; };
#endif // DATATRANSLATIONS_WINDOW_H #endif // DATA_TRANSLATIONS_WINDOW_H
+3 -3
View File
@@ -3,10 +3,10 @@ SubDir HAIKU_TOP src preferences datatranslations ;
Preference DataTranslations : Preference DataTranslations :
DataTranslations.cpp DataTranslations.cpp
DataTranslationsWindow.cpp DataTranslationsWindow.cpp
DataTranslationsView.cpp
DataTranslationsSettings.cpp DataTranslationsSettings.cpp
IconView.cpp IconView.cpp
: libbe.so libtranslation.so TranslatorListView.cpp
: be translation
: DataTranslations.rdef : DataTranslations.rdef
; ;
@@ -1,28 +1,34 @@
/* /*
* Copyright 2002-2006, Haiku, Inc.
* Distributed under the terms of the MIT license.
*
* Authors:
* Oliver Siebenmarck
* Andrew McCall, mccall@digitalparadise.co.uk
* Michael Wilber
*/
DataTranslationsView.cpp
*/ #include "TranslatorListView.h"
#ifndef _APPLICATION_H
#include <Application.h> #include <Application.h>
#endif
#include "DataTranslationsView.h"
DataTranslationsView::DataTranslationsView(BRect rect, const char *name,
TranslatorListView::TranslatorListView(BRect rect, const char *name,
list_view_type type) list_view_type type)
: BListView(rect, name, B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES) : BListView(rect, name, B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES)
{ {
} }
DataTranslationsView::~DataTranslationsView()
TranslatorListView::~TranslatorListView()
{ {
} }
void void
DataTranslationsView::MessageReceived(BMessage *message) TranslatorListView::MessageReceived(BMessage *message)
{ {
uint32 type; uint32 type;
int32 count; int32 count;
@@ -45,19 +51,18 @@ DataTranslationsView::MessageReceived(BMessage *message)
} }
} }
void void
DataTranslationsView::MouseMoved(BPoint point, uint32 transit, const BMessage *msg) TranslatorListView::MouseMoved(BPoint point, uint32 transit, const BMessage *dragMessage)
{ {
if (msg && transit == B_ENTERED_VIEW) { if (dragMessage != NULL && transit == B_ENTERED_VIEW) {
// Draw a red box around the inside of the view // Draw a red box around the inside of the view
// to tell the user that this view accepts drops // to tell the user that this view accepts drops
SetHighColor(220,0,0); SetHighColor(220,0,0);
SetPenSize(4); SetPenSize(4);
StrokeRect(Bounds()); StrokeRect(Bounds());
SetHighColor(0,0,0); SetHighColor(0,0,0);
} else if (dragMessage != NULL && transit == B_EXITED_VIEW)
} else if (msg && transit == B_EXITED_VIEW)
Invalidate(); Invalidate();
} }
@@ -0,0 +1,27 @@
/*
* Copyright 2002-2006, Haiku, Inc.
* Distributed under the terms of the MIT license.
*
* Authors:
* Oliver Siebenmarck
* Andrew McCall, mccall@digitalparadise.co.uk
* Michael Wilber
*/
#ifndef TRANSLATOR_LIST_VIEW_H
#define TRANSLATOR_LIST_VIEW_H
#include <ListView.h>
class TranslatorListView : public BListView {
public:
TranslatorListView(BRect rect, const char *name,
list_view_type type = B_SINGLE_SELECTION_LIST);
virtual ~TranslatorListView();
virtual void MessageReceived(BMessage *message);
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *msg);
};
#endif // TRANSLATOR_LIST_VIEW_H