Continued refactoring. Made style changes, fixed memory leak, added more error checking, moved view changing co
de out of GetTranInfo function. Still need to resolve color issue. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9876 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -36,87 +36,114 @@ 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()
|
||||||
{
|
{
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
||||||
|
|
||||||
int32 num_translators, i;
|
|
||||||
translator_id *translators;
|
|
||||||
const char *tname, *tinfo;
|
|
||||||
|
|
||||||
int32 tversion;
|
|
||||||
|
|
||||||
// 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;
|
||||||
|
translator_id *translators;
|
||||||
roster->GetAllTranslators(&translators, &num_translators);
|
roster->GetAllTranslators(&translators, &num_translators);
|
||||||
|
|
||||||
for (i=0;i<num_translators;i++) {
|
for (int32 i = 0; i < num_translators; i++) {
|
||||||
// Getting the first three Infos: Name, Info & Version
|
// Getting the first three Infos: Name, Info & Version
|
||||||
roster->GetTranslatorInfo(translators[i], &tname,&tinfo, &tversion);
|
int32 tversion;
|
||||||
|
const char *tname, *tinfo;
|
||||||
|
roster->GetTranslatorInfo(translators[i], &tname, &tinfo, &tversion);
|
||||||
fTranListView->AddItem(new BStringItem(tname));
|
fTranListView->AddItem(new BStringItem(tname));
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] translators; // Garbage collection
|
delete[] translators;
|
||||||
|
translators = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finds a specific translator by it´s id
|
status_t
|
||||||
void DataTranslationsWindow::GetTranInfo(int32 id, const char *&tranName,
|
DataTranslationsWindow::GetTranInfo(int32 id, const char *&tranName,
|
||||||
const char *&tranInfo, int32 &tranVersion, BPath &tranPath)
|
const char *&tranInfo, int32 &tranVersion, BPath &tranPath)
|
||||||
{
|
{
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
// Returns information about the translator with the given id
|
||||||
|
|
||||||
int32 num_translators;
|
if (id < 0)
|
||||||
translator_id *translators;
|
return B_BAD_VALUE;
|
||||||
bool has_view;
|
|
||||||
|
int32 num_translators = 0;
|
||||||
has_view = true;
|
translator_id tid = 0, *translators = NULL;
|
||||||
|
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
||||||
roster->GetAllTranslators(&translators, &num_translators);
|
roster->GetAllTranslators(&translators, &num_translators);
|
||||||
|
tid = ((id < num_translators) ? translators[id] : 0);
|
||||||
|
delete[] translators;
|
||||||
|
translators = NULL;
|
||||||
|
|
||||||
|
if (id >= num_translators)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
// Getting the first three Infos: Name, Info & Version
|
// Getting the first three Infos: Name, Info & Version
|
||||||
roster->GetTranslatorInfo(translators[id], &tranName, &tranInfo, &tranVersion);
|
roster->GetTranslatorInfo(tid, &tranName, &tranInfo, &tranVersion);
|
||||||
|
|
||||||
// Get the translator's path
|
// Get the translator's path
|
||||||
entry_ref tranRef;
|
entry_ref tranRef;
|
||||||
roster->GetRefFor(translators[id], &tranRef);
|
roster->GetRefFor(tid, &tranRef);
|
||||||
BEntry tmpEntry(&tranRef);
|
BEntry tmpEntry(&tranRef);
|
||||||
tranPath.SetTo(&tmpEntry);
|
tranPath.SetTo(&tmpEntry);
|
||||||
|
|
||||||
fConfigBox->RemoveChild(Konf);
|
return 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
|
|
||||||
fConfigBox->RemoveChild(Konf);
|
|
||||||
has_view = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Konf->SetViewColor(ui_color(B_BACKGROUND_COLOR));
|
|
||||||
if (has_view)
|
|
||||||
{
|
|
||||||
BRect konfRect(fConfigBox->Bounds());
|
|
||||||
konfRect.InsetBy(3,3);
|
|
||||||
konfRect.bottom -= 45;
|
|
||||||
float width = 0, height = 0;
|
|
||||||
Konf->GetPreferredSize(&width,&height);
|
|
||||||
float widen = max_c(0,width-konfRect.Width());
|
|
||||||
float heighten = max_c(0,height-konfRect.Height());
|
|
||||||
if ((widen > 0) || (heighten > 0)) {
|
|
||||||
ResizeBy(widen,heighten);
|
|
||||||
konfRect.right += widen;
|
|
||||||
konfRect.bottom += heighten;
|
|
||||||
}
|
|
||||||
Konf->MoveTo(konfRect.left,konfRect.top);
|
|
||||||
Konf->ResizeTo(konfRect.Width(), konfRect.Height());
|
|
||||||
fConfigBox->AddChild(Konf);
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateIfNeeded();
|
|
||||||
|
|
||||||
delete [] translators; // Garbage collection
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataTranslationsWindow::BuildView()
|
status_t
|
||||||
|
DataTranslationsWindow::ShowConfigView(int32 id)
|
||||||
|
{
|
||||||
|
// Shows the config panel for the translator with the given id
|
||||||
|
|
||||||
|
if (id < 0)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
int32 num_translators = 0;
|
||||||
|
translator_id tid = 0, *translators = NULL;
|
||||||
|
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
||||||
|
roster->GetAllTranslators(&translators, &num_translators);
|
||||||
|
tid = ((id < num_translators) ? translators[id] : 0);
|
||||||
|
delete[] translators;
|
||||||
|
translators = NULL;
|
||||||
|
|
||||||
|
if (id >= num_translators)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
fConfigBox->RemoveChild(fConfigView);
|
||||||
|
BMessage emptyMsg;
|
||||||
|
BRect rect(0, 0, 200, 233);
|
||||||
|
status_t ret = roster->MakeConfigurationView(tid, &emptyMsg, &fConfigView, &rect);
|
||||||
|
if (ret != B_OK) {
|
||||||
|
fConfigBox->RemoveChild(fConfigView);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
BRect konfRect(fConfigBox->Bounds());
|
||||||
|
konfRect.InsetBy(3, 3);
|
||||||
|
konfRect.bottom -= 45;
|
||||||
|
float width = 0, height = 0;
|
||||||
|
fConfigView->GetPreferredSize(&width, &height);
|
||||||
|
float widen = max_c(0, width - konfRect.Width());
|
||||||
|
float heighten = max_c(0, height - konfRect.Height());
|
||||||
|
if (widen > 0 || heighten > 0) {
|
||||||
|
ResizeBy(widen, heighten);
|
||||||
|
konfRect.right += widen;
|
||||||
|
konfRect.bottom += heighten;
|
||||||
|
}
|
||||||
|
fConfigView->MoveTo(konfRect.left, konfRect.top);
|
||||||
|
fConfigView->ResizeTo(konfRect.Width(), konfRect.Height());
|
||||||
|
fConfigBox->AddChild(fConfigView);
|
||||||
|
|
||||||
|
UpdateIfNeeded();
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DataTranslationsWindow::BuildView()
|
||||||
{
|
{
|
||||||
BRect all(0, 0, 400, 300); // Fenster-Groesse
|
BRect all(0, 0, 400, 300); // Fenster-Groesse
|
||||||
BBox *mainBox = new BBox(all, "All_Window", B_FOLLOW_ALL_SIDES,
|
BBox *mainBox = new BBox(all, "All_Window", B_FOLLOW_ALL_SIDES,
|
||||||
@@ -152,10 +179,10 @@ void DataTranslationsWindow::BuildView()
|
|||||||
|
|
||||||
BRect konfRect(innerRect);
|
BRect konfRect(innerRect);
|
||||||
konfRect.bottom = iconRect.top;
|
konfRect.bottom = iconRect.top;
|
||||||
Konf = new BView(konfRect, "KONF", B_FOLLOW_ALL_SIDES,
|
fConfigView = 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));
|
// fConfigView->SetViewColor(ui_color(B_BACKGROUND_COLOR));
|
||||||
fConfigBox->AddChild(Konf);
|
fConfigBox->AddChild(fConfigView);
|
||||||
|
|
||||||
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);
|
||||||
@@ -177,14 +204,14 @@ void DataTranslationsWindow::BuildView()
|
|||||||
fTranListView->Select(0, false);
|
fTranListView->Select(0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DataTranslationsWindow::QuitRequested()
|
bool
|
||||||
|
DataTranslationsWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
|
BPoint pt(Frame().left, Frame().top);
|
||||||
dynamic_cast<DataTranslationsApplication *>(be_app)->SetWindowCorner(BPoint(Frame().left,Frame().top));
|
dynamic_cast<DataTranslationsApplication *>(be_app)->SetWindowCorner(pt);
|
||||||
|
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
|
||||||
return(true);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -193,7 +220,7 @@ DataTranslationsWindow::MessageReceived(BMessage *message)
|
|||||||
BPath tranPath;
|
BPath tranPath;
|
||||||
BString strInfoMsg;
|
BString strInfoMsg;
|
||||||
const char *tranName = NULL, *tranInfo = NULL;
|
const char *tranName = NULL, *tranInfo = NULL;
|
||||||
int32 selected, tranVersion;
|
int32 selected = -1, tranVersion = 0;
|
||||||
|
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
|
||||||
@@ -238,10 +265,11 @@ DataTranslationsWindow::MessageReceived(BMessage *message)
|
|||||||
// If none selected, clear the old one
|
// If none selected, clear the old one
|
||||||
fIconView->DrawIcon(false);
|
fIconView->DrawIcon(false);
|
||||||
fTranNameView->SetText("");
|
fTranNameView->SetText("");
|
||||||
fConfigBox->RemoveChild(Konf);
|
fConfigBox->RemoveChild(fConfigView);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShowConfigView(selected);
|
||||||
GetTranInfo(selected, tranName, tranInfo, tranVersion, tranPath);
|
GetTranInfo(selected, tranName, tranInfo, tranVersion, tranPath);
|
||||||
fTranNameView->SetText(tranPath.Leaf());
|
fTranNameView->SetText(tranPath.Leaf());
|
||||||
fIconView->SetIcon(tranPath);
|
fIconView->SetIcon(tranPath);
|
||||||
|
|||||||
@@ -19,38 +19,42 @@
|
|||||||
#include <storage/Path.h>
|
#include <storage/Path.h>
|
||||||
#include <storage/Directory.h>
|
#include <storage/Directory.h>
|
||||||
#include <storage/Entry.h>
|
#include <storage/Entry.h>
|
||||||
|
|
||||||
#include "DataTranslationsSettings.h"
|
#include "DataTranslationsSettings.h"
|
||||||
#include "DataTranslationsView.h"
|
#include "DataTranslationsView.h"
|
||||||
#include "IconView.h"
|
#include "IconView.h"
|
||||||
|
|
||||||
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:
|
||||||
BBox *fConfigBox;
|
status_t GetTranInfo(int32 id, const char *&tranName, const char *&tranInfo,
|
||||||
// Box hosting Config View
|
int32 &tranVersion, BPath &tranPath);
|
||||||
|
|
||||||
DataTranslationsView *fTranListView;
|
|
||||||
// List of Translators (left pane of window)
|
|
||||||
|
|
||||||
BStringView *fTranNameView;
|
|
||||||
// Display the DataTranslatorName
|
|
||||||
|
|
||||||
IconView *fIconView;
|
|
||||||
|
|
||||||
BView* Konf;
|
|
||||||
|
|
||||||
void GetTranInfo(int32 id, const char *&tranName, const char *&tranInfo, int32 &tranVersion, BPath &tranPath);
|
|
||||||
int WriteTrans();
|
|
||||||
void BuildView();
|
|
||||||
|
|
||||||
|
status_t ShowConfigView(int32 id);
|
||||||
|
|
||||||
|
int WriteTrans();
|
||||||
|
void BuildView();
|
||||||
|
|
||||||
|
DataTranslationsView *fTranListView;
|
||||||
|
// List of Translators (left pane of window)
|
||||||
|
|
||||||
|
BBox *fConfigBox;
|
||||||
|
// Box hosting Config View
|
||||||
|
|
||||||
|
BView *fConfigView;
|
||||||
|
// the translator config view
|
||||||
|
|
||||||
|
IconView *fIconView;
|
||||||
|
// icon in the info panel
|
||||||
|
|
||||||
|
BStringView *fTranNameView;
|
||||||
|
// the translator name, in the info panel
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATATRANSLATIONS_WINDOW_H
|
#endif // DATATRANSLATIONS_WINDOW_H
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user