Continued refactoring. Removed unneeded member variables, renamed members to fit style guidelines, simplified code. Still need to make more style changes, add error checking and comments.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9838 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber
2004-11-07 23:26:37 +00:00
parent 40c831ab93
commit 8b8d5f70ad
5 changed files with 99 additions and 105 deletions
@@ -56,7 +56,7 @@ DataTranslationsApplication::~DataTranslationsApplication()
void DataTranslationsApplication::Install_Done() void DataTranslationsApplication::Install_Done()
{ {
(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 in them.",
"OK"))->Go(); "OK"))->Go();
} }
@@ -6,17 +6,17 @@
#include <Application.h> #include <Application.h>
#include <Message.h> #include <Message.h>
#include <Screen.h> #include <Screen.h>
#include <TranslationDefs.h>
#include "DataTranslationsMessages.h" #include "DataTranslationsMessages.h"
#include "DataTranslationsWindow.h" #include "DataTranslationsWindow.h"
#include "DataTranslations.h" #include "DataTranslations.h"
#define DATA_TRANSLATIONS_WINDOW_RIGHT 400 #define DTW_RIGHT 400
#define DATA_TRANSLATIONS_WINDOW_BOTTOM 300 #define DTW_BOTTOM 300
DataTranslationsWindow::DataTranslationsWindow() DataTranslationsWindow::DataTranslationsWindow()
: BWindow(BRect(0,0,DATA_TRANSLATIONS_WINDOW_RIGHT,DATA_TRANSLATIONS_WINDOW_BOTTOM), "DataTranslations", B_TITLED_WINDOW, B_NOT_ZOOMABLE) : BWindow(BRect(0, 0, DTW_RIGHT, DTW_BOTTOM),
"DataTranslations", B_TITLED_WINDOW, B_NOT_ZOOMABLE)
{ {
BScreen screen; BScreen screen;
@@ -29,9 +29,11 @@ DataTranslationsWindow::DataTranslationsWindow()
BuildView(); BuildView();
Show(); Show();
} }
DataTranslationsWindow::~DataTranslationsWindow()
{
}
// Reads the installed translators and adds them to our BListView // Reads the installed translators and adds them to our BListView
int DataTranslationsWindow::WriteTrans() int DataTranslationsWindow::WriteTrans()
@@ -61,7 +63,8 @@ int DataTranslationsWindow::WriteTrans()
} }
// Finds a specific translator by it´s id // Finds a specific translator by it´s id
void DataTranslationsWindow::Trans_by_ID(int32 id) void DataTranslationsWindow::GetTranInfo(int32 id, const char *&tranName,
const char *&tranInfo, int32 &tranVersion, BPath &tranPath)
{ {
BTranslatorRoster *roster = BTranslatorRoster::Default(); BTranslatorRoster *roster = BTranslatorRoster::Default();
@@ -73,20 +76,25 @@ void DataTranslationsWindow::Trans_by_ID(int32 id)
roster->GetAllTranslators(&translators, &num_translators); roster->GetAllTranslators(&translators, &num_translators);
// Getting the first three Infos: Name, Info & Version // Getting the first three Infos: Name, Info & Version
roster->GetTranslatorInfo(translators[id], &translator_name,&translator_info, &translator_version); roster->GetTranslatorInfo(translators[id], &tranName, &tranInfo, &tranVersion);
roster->Archive(&fRosterArchive, true);
rBox->RemoveChild(Konf); // Get the translator's path
entry_ref tranRef;
roster->GetRefFor(translators[id], &tranRef);
BEntry tmpEntry(&tranRef);
tranPath.SetTo(&tmpEntry);
fConfigBox->RemoveChild(Konf);
if (roster->MakeConfigurationView( translators[id], new BMessage() , &Konf, new BRect( 0, 0, 200, 233)) != B_OK ) if (roster->MakeConfigurationView( translators[id], new BMessage() , &Konf, new BRect( 0, 0, 200, 233)) != B_OK )
{// be_app->PostMessage(B_QUIT_REQUESTED); // Something went wrong -> Quit {// be_app->PostMessage(B_QUIT_REQUESTED); // Something went wrong -> Quit
rBox->RemoveChild(Konf); fConfigBox->RemoveChild(Konf);
has_view = false; has_view = false;
} }
// Konf->SetViewColor(ui_color(B_BACKGROUND_COLOR)); // Konf->SetViewColor(ui_color(B_BACKGROUND_COLOR));
if (has_view) if (has_view)
{ {
BRect konfRect(rBox->Bounds()); BRect konfRect(fConfigBox->Bounds());
konfRect.InsetBy(3,3); konfRect.InsetBy(3,3);
konfRect.bottom -= 45; konfRect.bottom -= 45;
float width = 0, height = 0; float width = 0, height = 0;
@@ -100,7 +108,7 @@ void DataTranslationsWindow::Trans_by_ID(int32 id)
} }
Konf->MoveTo(konfRect.left,konfRect.top); Konf->MoveTo(konfRect.left,konfRect.top);
Konf->ResizeTo(konfRect.Width(), konfRect.Height()); Konf->ResizeTo(konfRect.Width(), konfRect.Height());
rBox->AddChild(Konf); fConfigBox->AddChild(Konf);
} }
UpdateIfNeeded(); UpdateIfNeeded();
@@ -111,49 +119,43 @@ void DataTranslationsWindow::Trans_by_ID(int32 id)
void DataTranslationsWindow::BuildView() void DataTranslationsWindow::BuildView()
{ {
BRect all(0, 0, 400, 300); // Fenster-Groesse BRect all(0, 0, 400, 300); // Fenster-Groesse
fBox = new BBox(all, "All_Window", B_FOLLOW_ALL_SIDES, BBox *mainBox = new BBox(all, "All_Window", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FRAME_EVENTS, B_WILL_DRAW | B_FRAME_EVENTS,
B_PLAIN_BORDER); B_PLAIN_BORDER);
AddChild(fBox); AddChild(mainBox);
BRect configView( 150, 10, 390, 290); BRect configView( 150, 10, 390, 290);
rBox = new BBox(configView, "Right_Side", B_FOLLOW_ALL_SIDES); fConfigBox = new BBox(configView, "Right_Side", B_FOLLOW_ALL_SIDES);
fBox->AddChild(rBox); mainBox->AddChild(fConfigBox);
BRect innerRect(rBox->Bounds()); BRect innerRect(fConfigBox->Bounds());
innerRect.InsetBy(8,8); innerRect.InsetBy(8,8);
BRect iconRect(0,0,31,31); BRect iconRect(0,0,31,31);
iconRect.OffsetTo(innerRect.left,innerRect.bottom-iconRect.Height()); iconRect.OffsetTo(innerRect.left,innerRect.bottom-iconRect.Height());
fIconView = new IconView(iconRect, "Ikon", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, fIconView = new IconView(iconRect, "Ikon", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
B_WILL_DRAW | B_FRAME_EVENTS); B_WILL_DRAW | B_FRAME_EVENTS);
//fIconView->SetDrawingMode(B_OP_OVER); fConfigBox->AddChild(fIconView);
// to preserve transparent areas of the icon
//fIconView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
//fIconView->SetViewColor(0, 255, 0);
//fIconView->SetHighColor(0, 0, 255);
rBox->AddChild(fIconView);
BRect infoRect(0,0,80,20); BRect infoRect(0,0,80,20);
infoRect.OffsetTo(innerRect.right-infoRect.Width(),innerRect.bottom-10-infoRect.Height()); infoRect.OffsetTo(innerRect.right-infoRect.Width(),innerRect.bottom-10-infoRect.Height());
dButton = new BButton(infoRect, "STD", "Info...", new BMessage(BUTTON_MSG), BButton *button = new BButton(infoRect, "STD", "Info...", new BMessage(BUTTON_MSG),
B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT, B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
rBox->AddChild(dButton); fConfigBox->AddChild(button);
BRect dataNameRect( iconRect.right+5 , iconRect.top, BRect dataNameRect( iconRect.right+5 , iconRect.top,
infoRect.left-5 , iconRect.bottom); infoRect.left-5 , iconRect.bottom);
DTN = new BStringView(dataNameRect, "DataName", "Test", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); fTranNameView = new BStringView(dataNameRect, "DataName", "Test", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
// DTN->SetViewColor(ui_color(B_BACKGROUND_COLOR)); // fTranNameView->SetViewColor(ui_color(B_BACKGROUND_COLOR));
rBox->AddChild(DTN); fConfigBox->AddChild(fTranNameView);
BRect konfRect(innerRect); BRect konfRect(innerRect);
konfRect.bottom = iconRect.top; konfRect.bottom = iconRect.top;
Konf = new BView(konfRect, "KONF", B_FOLLOW_ALL_SIDES, Konf = new BView(konfRect, "KONF", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FRAME_EVENTS ); B_WILL_DRAW | B_FRAME_EVENTS );
// Konf->SetViewColor(ui_color(B_BACKGROUND_COLOR)); // Konf->SetViewColor(ui_color(B_BACKGROUND_COLOR));
rBox->AddChild(Konf); fConfigBox->AddChild(Konf);
BRect listRect(10, 10, 120, 288); // List View BRect listRect(10, 10, 120, 288); // List View
fTranListView = new DataTranslationsView(listRect, "Transen", B_SINGLE_SELECTION_LIST); fTranListView = new DataTranslationsView(listRect, "Transen", B_SINGLE_SELECTION_LIST);
@@ -163,18 +165,16 @@ void DataTranslationsWindow::BuildView()
BScrollView *scrollView = new BScrollView("scroll_trans", fTranListView, BScrollView *scrollView = new BScrollView("scroll_trans", fTranListView,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW | B_FRAME_EVENTS, B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW | B_FRAME_EVENTS,
false, true, B_FANCY_BORDER); false, true, B_FANCY_BORDER);
fBox->AddChild(scrollView); mainBox->AddChild(scrollView);
// Here we add the names of all installed translators // Here we add the names of all installed translators
WriteTrans(); WriteTrans();
// Set the focus // Set the focus
fTranListView->MakeFocus(); fTranListView->MakeFocus();
// Select the first Translator in list // Select the first Translator in list
fTranListView->Select(0, false); fTranListView->Select(0, false);
fTranSelected = true;
} }
bool DataTranslationsWindow::QuitRequested() bool DataTranslationsWindow::QuitRequested()
@@ -189,66 +189,67 @@ bool DataTranslationsWindow::QuitRequested()
void void
DataTranslationsWindow::MessageReceived(BMessage *message) DataTranslationsWindow::MessageReceived(BMessage *message)
{ {
int32 selected; BPath tranPath;
BString strInfoMsg;
const char *tranName = NULL, *tranInfo = NULL;
int32 selected, tranVersion;
switch (message->what) {
switch(message->what) {
case BUTTON_MSG: case BUTTON_MSG:
selected=fTranListView->CurrentSelection(0); selected = fTranListView->CurrentSelection(0);
if (selected < 0) {
// Should we show translator info? // If no translator is selected, show a message explaining
if (!fTranSelected) // what the config panel is for
{ (new BAlert("yo!",
// No => Show standard box "Translation Settings\n\n"
(new BAlert("yo!", "Translation Settings\n\nUse this control panel to set values that various\ntranslators use when no other settings are specified\nin the application.", "OK"))->Go(); "Use this control panel to set values that various\n"
"translators use when no other settings are specified\n"
"in the application.",
"OK"))->Go();
break; break;
} }
// Yes => Show Translator info.
Trans_by_ID(selected); GetTranInfo(selected, tranName, tranInfo, tranVersion, tranPath);
fRosterArchive.FindString("be:translator_path", selected, &pfad); strInfoMsg << "Name: " << tranName << "\nVersion: ";
tex << "Name :" << translator_name << "\nVersion: " << (int32)translator_version << "\nInfo: " << translator_info << "\nPath: " << pfad << "\n"; if (tranVersion < 0x100)
(new BAlert("yo!", tex.String(), "OK"))->Go(); // If the version number doesn't follow the standard format,
tex.SetTo(""); // just print it as is
strInfoMsg << tranVersion;
else {
// Convert the version number into a readable format
strInfoMsg <<
static_cast<int>(B_TRANSLATION_MAJOR_VER(tranVersion)) << '.' <<
static_cast<int>(B_TRANSLATION_MINOR_VER(tranVersion)) << '.' <<
static_cast<int>(B_TRANSLATION_REVSN_VER(tranVersion));
}
strInfoMsg << "\nInfo: " << tranInfo <<
"\nPath: " << tranPath.Path() << "\n";
(new BAlert("yo!", strInfoMsg.String(), "OK"))->Go();
break; break;
case SEL_CHANGE: case SEL_CHANGE:
// Now we have to update Filename and Icon // Update the icon and translator info panel
// First we find the selected Translator // to match the new selection
selected=fTranListView->CurrentSelection(0); selected = fTranListView->CurrentSelection(0);
if (selected < 0) {
// If none selected, clear the old one // If none selected, clear the old one
if (selected < 0)
{
fIconView->DrawIcon(false); fIconView->DrawIcon(false);
DTN->SetText(""); fTranNameView->SetText("");
fTranSelected = false; fConfigBox->RemoveChild(Konf);
rBox->RemoveChild(Konf);
break; break;
} }
fTranSelected = true; GetTranInfo(selected, tranName, tranInfo, tranVersion, tranPath);
Trans_by_ID(selected); fTranNameView->SetText(tranPath.Leaf());
// Now we find the path, and update filename fIconView->SetIcon(tranPath);
fRosterArchive.FindString("be:translator_path", selected, &pfad);
tex.SetTo(pfad);
tex.Remove(0,tex.FindLast("/")+1);
DTN->SetText(tex.String());
entry.SetTo(pfad);
node.SetTo(&entry);
info.SetTo(&node);
fIconView->SetIconFromNodeInfo(info);
break; break;
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
} }
} }
DataTranslationsWindow::~DataTranslationsWindow()
{
}
@@ -16,7 +16,6 @@
#include <String.h> #include <String.h>
#include <StringView.h> #include <StringView.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <NodeInfo.h>
#include <storage/Path.h> #include <storage/Path.h>
#include <storage/Directory.h> #include <storage/Directory.h>
#include <storage/Entry.h> #include <storage/Entry.h>
@@ -35,34 +34,20 @@ virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
private: private:
const char *translator_name, *translator_info; BBox *fConfigBox;
int32 translator_version; // Box hosting Config View
const char* pfad;
BString tex;
bool fTranSelected;
// Indicates whether or not a translator is selected
// in the fTranListView
BButton* dButton; // Default-Button
BBox* fBox; // Full-Window Box
BBox* rBox; // Box hosting Config View
DataTranslationsView *fTranListView; DataTranslationsView *fTranListView;
// List of Translators (left pane of window) // List of Translators (left pane of window)
BStringView* DTN; // Display the DataTranslatorName BStringView *fTranNameView;
BMessage fRosterArchive; // Display the DataTranslatorName
// Archive of the current BTranslatorRoster
IconView *fIconView; IconView *fIconView;
BView* Konf; BView* Konf;
BEntry entry; void GetTranInfo(int32 id, const char *&tranName, const char *&tranInfo, int32 &tranVersion, BPath &tranPath);
BNode node;
BNodeInfo info;
void Trans_by_ID(int32 id);
int WriteTrans(); int WriteTrans();
void BuildView(); void BuildView();
+6 -1
View File
@@ -35,9 +35,14 @@ IconView::~IconView()
} }
bool bool
IconView::SetIconFromNodeInfo(BNodeInfo &info) IconView::SetIcon(const BPath &path)
{ {
fDrawIcon = false; fDrawIcon = false;
BEntry entry(path.Path());
BNode node(&entry);
BNodeInfo info(&node);
if (info.GetTrackerIcon(fIconBitmap) != B_OK) if (info.GetTrackerIcon(fIconBitmap) != B_OK)
return false; return false;
+4 -1
View File
@@ -13,6 +13,9 @@
#include <View.h> #include <View.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Path.h>
#include <Entry.h>
#include <Node.h>
#include <NodeInfo.h> #include <NodeInfo.h>
class IconView : public BView { class IconView : public BView {
@@ -23,7 +26,7 @@ public:
bool DrawIcon(bool draw); bool DrawIcon(bool draw);
bool SetIconFromNodeInfo(BNodeInfo &info); bool SetIcon(const BPath &path);
virtual void Draw(BRect area); virtual void Draw(BRect area);
// draws the icon // draws the icon