* Loading and saving the settings was completely broken. I've moved to a different
file and put the window position there; loading/saving of the translators settings looks broken in (or rather, missing from) the Translation Kit as well. * Now uses the new watching mechanism of BTranslatorRoster to keep track of new translators. * Installing translators now gives better error requests, it now no longer uses undocumented BTranslatorRoster functionality, but the new IsTranslator() method to check if a certain file is a translator. * Copying translators is disabled for now, though. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17292 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -15,9 +15,15 @@
|
|||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
#include <String.h>
|
||||||
#include <TranslatorRoster.h>
|
#include <TranslatorRoster.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
const char* kApplicationSignature = "application/x-vnd.haiku-translations";
|
const char* kApplicationSignature = "application/x-vnd.haiku-translations";
|
||||||
|
|
||||||
@@ -64,112 +70,36 @@ DataTranslationsApplication::AboutRequested()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DataTranslationsApplication::InstallDone()
|
DataTranslationsApplication::_InstallError(const char* name, status_t status)
|
||||||
{
|
{
|
||||||
(new BAlert("",
|
BString text;
|
||||||
"You have to quit and restart running applications\n"
|
text << "Could not install " << name << ":\n" << strerror(status);
|
||||||
"for the installed Translators to be available for them.",
|
(new BAlert("DataTranslations - Error", text.String(), "Stop"))->Go();
|
||||||
"OK"))->Go();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Installs the given entry in the target directory either by moving
|
||||||
|
or copying the entry.
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
DataTranslationsApplication::_Install(BDirectory& target, BEntry& entry)
|
||||||
|
{
|
||||||
|
// Find out wether we need to copy it
|
||||||
|
status_t status = entry.MoveTo(&target, NULL, true);
|
||||||
|
|
||||||
|
if (status == B_OK)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
// we need to copy the file
|
||||||
|
|
||||||
|
// TODO!
|
||||||
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DataTranslationsApplication::RefsReceived(BMessage *message)
|
DataTranslationsApplication::_NoTranslatorError(const char* name)
|
||||||
{
|
|
||||||
uint32 type;
|
|
||||||
int32 count;
|
|
||||||
entry_ref ref;
|
|
||||||
BPath path;
|
|
||||||
BString newfile;
|
|
||||||
|
|
||||||
char e_name[B_FILE_NAME_LENGTH];
|
|
||||||
|
|
||||||
message->GetInfo("refs", &type, &count);
|
|
||||||
if (type != B_REF_TYPE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (message->FindRef("refs", &ref) == B_OK) {
|
|
||||||
BEntry entry(&ref, true);
|
|
||||||
entry.GetName(e_name);
|
|
||||||
|
|
||||||
if (entry.IsFile() && entry.GetPath(&path) == B_OK) {
|
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
|
||||||
if (roster->AddTranslators(path.Path()) == B_OK) {
|
|
||||||
BDirectory dirt("/boot/home/config/add-ons/Translators/");
|
|
||||||
newfile.SetTo("/boot/home/config/add-ons/Translators/");
|
|
||||||
newfile << e_name; // Newfile with full path.
|
|
||||||
|
|
||||||
// Find out wether we need to copy it
|
|
||||||
string.SetTo("");
|
|
||||||
string << "The item '" << e_name << "' is now copied into the right place.\nWhat do you want to do with the original?";
|
|
||||||
BAlert *keep = new BAlert("keep", string.String() , "Remove", "Keep");
|
|
||||||
keep->SetShortcut(1, B_ESCAPE);
|
|
||||||
if (keep->Go() == 0)
|
|
||||||
moveit = true;
|
|
||||||
|
|
||||||
if (moveit) {
|
|
||||||
// Just a quick move
|
|
||||||
if (dirt.Contains(newfile.String())) {
|
|
||||||
string.SetTo("");
|
|
||||||
string << "An item named '" << e_name <<"' already is in the \nTranslators folder";
|
|
||||||
BAlert *myAlert = new BAlert("title", string.String() , "Overwrite", "Stop");
|
|
||||||
myAlert->SetShortcut(1, B_ESCAPE);
|
|
||||||
|
|
||||||
if (myAlert->Go() != 0)
|
|
||||||
return;
|
|
||||||
// File exists, we are still here. Kill it.
|
|
||||||
BEntry dele;
|
|
||||||
dirt.FindEntry(e_name, &dele);
|
|
||||||
dele.Remove();
|
|
||||||
}
|
|
||||||
entry.MoveTo(&dirt); // Move it.
|
|
||||||
InstallDone(); // Installation done
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dirt.Contains(newfile.String())) {
|
|
||||||
// File exists, What are we supposed to do now (Overwrite/_Stopp_?)
|
|
||||||
string.SetTo("");
|
|
||||||
string << "An item named '" << e_name <<"' already is in the \nTranslators folder";
|
|
||||||
BAlert *myAlert = new BAlert("title", string.String() , "Overwrite", "Stop");
|
|
||||||
myAlert->SetShortcut(1, B_ESCAPE);
|
|
||||||
|
|
||||||
if (myAlert->Go() != 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string.SetTo(path.Path()); // Fullpath+Filename
|
|
||||||
|
|
||||||
BString command;
|
|
||||||
#ifdef __HAIKU__
|
|
||||||
command = "cp ";
|
|
||||||
#else
|
|
||||||
command = "copyattr -d -r ";
|
|
||||||
#endif
|
|
||||||
command << string.String() << " " << newfile.String(); // Prepare Copy
|
|
||||||
|
|
||||||
system(command.String()); // Execute copy command
|
|
||||||
|
|
||||||
string.SetTo("");
|
|
||||||
string << "Filename: " << e_name << "\nPath: " << path.Path() ;
|
|
||||||
|
|
||||||
// The new Translator has been installed by now.
|
|
||||||
// And done we are
|
|
||||||
InstallDone();
|
|
||||||
} else {
|
|
||||||
// Not a Translator
|
|
||||||
NoTranslatorError(e_name);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Not even a file...
|
|
||||||
NoTranslatorError(e_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
DataTranslationsApplication::NoTranslatorError(const char* name)
|
|
||||||
{
|
{
|
||||||
BString text;
|
BString text;
|
||||||
text.SetTo("The item '");
|
text.SetTo("The item '");
|
||||||
@@ -178,6 +108,71 @@ DataTranslationsApplication::NoTranslatorError(const char* name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DataTranslationsApplication::RefsReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||||
|
|
||||||
|
BPath path;
|
||||||
|
status_t status = find_directory(B_USER_ADDONS_DIRECTORY, &path, true);
|
||||||
|
if (status != B_OK) {
|
||||||
|
_InstallError("translator", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BDirectory target;
|
||||||
|
status = target.SetTo(path.Path());
|
||||||
|
if (status == B_OK) {
|
||||||
|
if (!target.Contains("Translators"))
|
||||||
|
status = target.CreateDirectory("Translators", &target);
|
||||||
|
else
|
||||||
|
status = target.SetTo(&target, "Translators");
|
||||||
|
}
|
||||||
|
if (status != B_OK) {
|
||||||
|
_InstallError("translator", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
int32 i = 0;
|
||||||
|
while (message->FindRef("refs", i++, &ref) == B_OK) {
|
||||||
|
if (!roster->IsTranslator(&ref))
|
||||||
|
_NoTranslatorError(ref.name);
|
||||||
|
|
||||||
|
BEntry entry(&ref, true);
|
||||||
|
status = entry.InitCheck();
|
||||||
|
if (status != B_OK) {
|
||||||
|
_InstallError(ref.name, status);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target.Contains(ref.name)) {
|
||||||
|
BString string;
|
||||||
|
string << "An item named '" << ref.name
|
||||||
|
<< "' already exists in the Translators folder";
|
||||||
|
|
||||||
|
BAlert* alert = new BAlert("DataTranslations - Note", string.String(),
|
||||||
|
"Overwrite", "Stop");
|
||||||
|
alert->SetShortcut(1, B_ESCAPE);
|
||||||
|
if (alert->Go() != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// the original file will be replaced
|
||||||
|
}
|
||||||
|
|
||||||
|
// find out wether we need to copy it or not
|
||||||
|
|
||||||
|
status = _Install(target, entry);
|
||||||
|
if (status == B_OK) {
|
||||||
|
(new BAlert("DataTranslations - Note",
|
||||||
|
"The new translator has been installed successfully",
|
||||||
|
"OK"))->Go(NULL);
|
||||||
|
} else
|
||||||
|
_InstallError(ref.name, status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,6 @@
|
|||||||
#include "DataTranslationsSettings.h"
|
#include "DataTranslationsSettings.h"
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <String.h>
|
|
||||||
#include <Alert.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
|
||||||
class DataTranslationsApplication : public BApplication {
|
class DataTranslationsApplication : public BApplication {
|
||||||
@@ -33,13 +29,11 @@ class DataTranslationsApplication : public BApplication {
|
|||||||
void SetWindowCorner(BPoint corner);
|
void SetWindowCorner(BPoint corner);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InstallDone();
|
void _InstallError(const char* name, status_t status);
|
||||||
void NoTranslatorError(const char* name);
|
status_t _Install(BDirectory& target, BEntry& entry);
|
||||||
|
void _NoTranslatorError(const char* name);
|
||||||
|
|
||||||
DataTranslationsSettings* fSettings;
|
DataTranslationsSettings* fSettings;
|
||||||
|
|
||||||
bool overwrite, moveit;
|
|
||||||
BString string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATA_TRANSLATIONS_H
|
#endif // DATA_TRANSLATIONS_H
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2006, Haiku, Inc.
|
|
||||||
* Distributed under the terms of the MIT license.
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Unknown?
|
|
||||||
* Michael Wilber
|
|
||||||
*/
|
|
||||||
#ifndef DATA_TRANSLATIONS_MESSAGES_H
|
|
||||||
#define DATA_TRANSLATIONS_MESSAGES_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define BUTTON_MSG 'PRES'
|
|
||||||
|
|
||||||
const uint32 SEL_CHANGE = 'SEch';
|
|
||||||
const uint32 ERROR_DETECTED = 'ERor';
|
|
||||||
|
|
||||||
#endif // DATA_TRANSLATIONS_MESSAGES_H
|
|
||||||
@@ -1,67 +1,63 @@
|
|||||||
/*
|
/*
|
||||||
* DataTranslationsSettings.cpp
|
* Copyright 2002-2006, Haiku, Inc.
|
||||||
* DataTranslations Oliver Siebenmarck
|
* Distributed under the terms of the MIT license.
|
||||||
*
|
*
|
||||||
|
* Authors:
|
||||||
|
* Oliver Siebenmarck
|
||||||
|
* Axel Dörfler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "DataTranslationsSettings.h"
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Debug.h>
|
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <String.h>
|
#include <Message.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "DataTranslationsSettings.h"
|
|
||||||
#include "DataTranslationsMessages.h"
|
|
||||||
|
|
||||||
const char DataTranslationsSettings::kDataTranslationsSettingsFile[] = "Translation Settings";
|
|
||||||
|
|
||||||
DataTranslationsSettings::DataTranslationsSettings()
|
DataTranslationsSettings::DataTranslationsSettings()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) {
|
fCorner = BPoint(50, 50);
|
||||||
path.Append(kDataTranslationsSettingsFile);
|
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
path.Append("system/DataTranslations settings");
|
||||||
if (file.InitCheck() == B_OK) {
|
BFile file(path.Path(), B_READ_ONLY);
|
||||||
// Now read in the data
|
BMessage settings;
|
||||||
file.Seek(-8,SEEK_END); // Skip over the first 497 bytes to just the window
|
|
||||||
// position.
|
if (file.InitCheck() == B_OK
|
||||||
if (file.Read(&fCorner, sizeof(BPoint)) != sizeof(BPoint)) {
|
&& settings.Unflatten(&file) == B_OK) {
|
||||||
fCorner.x=50;
|
BPoint corner;
|
||||||
fCorner.y=50;
|
if (settings.FindPoint("window corner", &corner) == B_OK)
|
||||||
};
|
fCorner = corner;
|
||||||
}
|
|
||||||
else {
|
|
||||||
fCorner.x=50;
|
|
||||||
fCorner.y=50;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
be_app->PostMessage(ERROR_DETECTED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DataTranslationsSettings::~DataTranslationsSettings()
|
DataTranslationsSettings::~DataTranslationsSettings()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path.Append(kDataTranslationsSettingsFile);
|
BMessage settings;
|
||||||
|
settings.AddPoint("window corner", fCorner);
|
||||||
|
|
||||||
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
|
path.Append("system/DataTranslations settings");
|
||||||
if (file.InitCheck() == B_OK) {
|
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
file.Seek(-8,SEEK_END); // Skip over the first 497 bytes to just the window
|
if (file.InitCheck() == B_OK)
|
||||||
// position.
|
settings.Flatten(&file);
|
||||||
PRINT_OBJECT(fCorner);
|
|
||||||
file.Write(&fCorner, sizeof(BPoint));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DataTranslationsSettings::SetWindowCorner(BPoint corner)
|
DataTranslationsSettings::SetWindowCorner(BPoint corner)
|
||||||
{
|
{
|
||||||
fCorner=corner;
|
fCorner = corner;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,27 @@
|
|||||||
#ifndef DATA_TRANSLATIONS_SETTINGS_H_
|
/*
|
||||||
#define DATA_TRANSLATIONS_SETTINGS_H_
|
* Copyright 2002-2006, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Oliver Siebenmarck
|
||||||
|
*/
|
||||||
|
#ifndef DATA_TRANSLATIONS_SETTINGS_H
|
||||||
|
#define DATA_TRANSLATIONS_SETTINGS_H
|
||||||
|
|
||||||
class DataTranslationsSettings{
|
|
||||||
public :
|
|
||||||
DataTranslationsSettings();
|
|
||||||
~DataTranslationsSettings();
|
|
||||||
|
|
||||||
BPoint WindowCorner() const { return fCorner; }
|
#include <Point.h>
|
||||||
void SetWindowCorner(BPoint corner);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static const char kDataTranslationsSettingsFile[];
|
class DataTranslationsSettings {
|
||||||
BPoint fCorner;
|
public:
|
||||||
|
DataTranslationsSettings();
|
||||||
|
~DataTranslationsSettings();
|
||||||
|
|
||||||
|
BPoint WindowCorner() const { return fCorner; }
|
||||||
|
void SetWindowCorner(BPoint corner);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BPoint fCorner;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // DATA_TRANSLATIONS_SETTINGS_H
|
||||||
|
|||||||
@@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "DataTranslations.h"
|
#include "DataTranslations.h"
|
||||||
#include "DataTranslationsMessages.h"
|
|
||||||
#include "DataTranslationsSettings.h"
|
|
||||||
#include "DataTranslationsWindow.h"
|
#include "DataTranslationsWindow.h"
|
||||||
#include "IconView.h"
|
#include "IconView.h"
|
||||||
#include "TranslatorListView.h"
|
#include "TranslatorListView.h"
|
||||||
@@ -35,6 +33,10 @@
|
|||||||
#define DTW_BOTTOM 300
|
#define DTW_BOTTOM 300
|
||||||
|
|
||||||
|
|
||||||
|
const uint32 kMsgTranslatorInfo = 'trin';
|
||||||
|
const uint32 kMsgSelectedTranslator = 'trsl';
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -61,12 +63,18 @@ DataTranslationsWindow::DataTranslationsWindow()
|
|||||||
MoveTo(x, y);
|
MoveTo(x, y);
|
||||||
|
|
||||||
_SetupViews();
|
_SetupViews();
|
||||||
|
|
||||||
|
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
||||||
|
roster->StartWatching(this);
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DataTranslationsWindow::~DataTranslationsWindow()
|
DataTranslationsWindow::~DataTranslationsWindow()
|
||||||
{
|
{
|
||||||
|
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
||||||
|
roster->StopWatching(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +95,7 @@ DataTranslationsWindow::_PopulateListView()
|
|||||||
int32 version;
|
int32 version;
|
||||||
const char *name, *info;
|
const char *name, *info;
|
||||||
roster->GetTranslatorInfo(translators[i], &name, &info, &version);
|
roster->GetTranslatorInfo(translators[i], &name, &info, &version);
|
||||||
fTranslatorListView->AddItem(new BStringItem(name));
|
fTranslatorListView->AddItem(new TranslatorItem(translators[i], name));
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] translators;
|
delete[] translators;
|
||||||
@@ -96,32 +104,25 @@ DataTranslationsWindow::_PopulateListView()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DataTranslationsWindow::_GetTranslatorInfo(int32 id, const char *&tranName,
|
DataTranslationsWindow::_GetTranslatorInfo(int32 id, const char*& name,
|
||||||
const char *&tranInfo, int32 &tranVersion, BPath &tranPath)
|
const char*& info, int32& version, BPath& path)
|
||||||
{
|
{
|
||||||
// Returns information about the translator with the given id
|
// Returns information about the translator with the given id
|
||||||
|
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
int32 numTranslators = 0;
|
|
||||||
translator_id tid = 0, *translators = NULL;
|
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
||||||
roster->GetAllTranslators(&translators, &numTranslators);
|
if (roster->GetTranslatorInfo(id, &name, &info, &version) != B_OK)
|
||||||
tid = ((id < numTranslators) ? translators[id] : 0);
|
return B_ERROR;
|
||||||
delete[] translators;
|
|
||||||
|
|
||||||
if (id >= numTranslators)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
// Getting the first three Infos: Name, Info & Version
|
|
||||||
roster->GetTranslatorInfo(tid, &tranName, &tranInfo, &tranVersion);
|
|
||||||
|
|
||||||
// Get the translator's path
|
// Get the translator's path
|
||||||
entry_ref tranRef;
|
entry_ref ref;
|
||||||
roster->GetRefFor(tid, &tranRef);
|
if (roster->GetRefFor(id, &ref) == B_OK) {
|
||||||
BEntry tmpEntry(&tranRef);
|
BEntry entry(&ref);
|
||||||
tranPath.SetTo(&tmpEntry);
|
path.SetTo(&entry);
|
||||||
|
} else
|
||||||
|
path.Unset();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -135,23 +136,16 @@ DataTranslationsWindow::_ShowConfigView(int32 id)
|
|||||||
if (id < 0)
|
if (id < 0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
int32 numTranslators = 0;
|
|
||||||
translator_id tid = 0, *translators = NULL;
|
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
||||||
roster->GetAllTranslators(&translators, &numTranslators);
|
|
||||||
tid = ((id < numTranslators) ? translators[id] : 0);
|
|
||||||
delete[] translators;
|
|
||||||
|
|
||||||
if (id >= numTranslators)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
// fConfigView is NULL the first time this function
|
// fConfigView is NULL the first time this function
|
||||||
// is called, prevent a segment fault
|
// is called, prevent a segment fault
|
||||||
if (fConfigView)
|
if (fConfigView)
|
||||||
fRightBox->RemoveChild(fConfigView);
|
fRightBox->RemoveChild(fConfigView);
|
||||||
|
|
||||||
BMessage emptyMsg;
|
BMessage emptyMsg;
|
||||||
BRect rect(0, 0, 200, 233);
|
BRect rect(0, 0, 200, 233);
|
||||||
status_t ret = roster->MakeConfigurationView(tid, &emptyMsg, &fConfigView, &rect);
|
status_t ret = roster->MakeConfigurationView(id, &emptyMsg, &fConfigView, &rect);
|
||||||
if (ret != B_OK) {
|
if (ret != B_OK) {
|
||||||
fRightBox->RemoveChild(fConfigView);
|
fRightBox->RemoveChild(fConfigView);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -175,8 +169,6 @@ DataTranslationsWindow::_ShowConfigView(int32 id)
|
|||||||
// force config views to all have the same color
|
// force config views to all have the same color
|
||||||
fRightBox->AddChild(fConfigView);
|
fRightBox->AddChild(fConfigView);
|
||||||
|
|
||||||
UpdateIfNeeded();
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +188,7 @@ DataTranslationsWindow::_SetupViews()
|
|||||||
// Add the translators list view
|
// Add the translators list view
|
||||||
fTranslatorListView = new TranslatorListView(BRect(10, 10, 120, Bounds().Height() - 10),
|
fTranslatorListView = new TranslatorListView(BRect(10, 10, 120, Bounds().Height() - 10),
|
||||||
"TransList", B_SINGLE_SELECTION_LIST);
|
"TransList", B_SINGLE_SELECTION_LIST);
|
||||||
fTranslatorListView->SetSelectionMessage(new BMessage(SEL_CHANGE));
|
fTranslatorListView->SetSelectionMessage(new BMessage(kMsgSelectedTranslator));
|
||||||
|
|
||||||
BScrollView *scrollView = new BScrollView("scroll_trans", fTranslatorListView,
|
BScrollView *scrollView = new BScrollView("scroll_trans", fTranslatorListView,
|
||||||
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,
|
||||||
@@ -219,7 +211,7 @@ DataTranslationsWindow::_SetupViews()
|
|||||||
// Add the translator info button
|
// Add the translator info button
|
||||||
BRect infoRect(0, 0, 80, 20);
|
BRect infoRect(0, 0, 80, 20);
|
||||||
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(kMsgTranslatorInfo), 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->ResizeToPreferred();
|
||||||
button->MoveTo(fRightBox->Bounds().Width() - button->Bounds().Width() - 10.0f,
|
button->MoveTo(fRightBox->Bounds().Width() - button->Bounds().Width() - 10.0f,
|
||||||
@@ -262,13 +254,13 @@ DataTranslationsWindow::_ShowInfoAlert(int32 id)
|
|||||||
_GetTranslatorInfo(id, name, info, version, path);
|
_GetTranslatorInfo(id, name, info, version, path);
|
||||||
|
|
||||||
BString message;
|
BString message;
|
||||||
message << "Name:\t" << name << "\nVersion:\t";
|
message << "Name: " << name << "\nVersion: ";
|
||||||
|
|
||||||
// Convert the version number into a readable format
|
// Convert the version number into a readable format
|
||||||
message << (int)B_TRANSLATION_MAJOR_VERSION(version)
|
message << (int)B_TRANSLATION_MAJOR_VERSION(version)
|
||||||
<< '.' << (int)B_TRANSLATION_MINOR_VERSION(version)
|
<< '.' << (int)B_TRANSLATION_MINOR_VERSION(version)
|
||||||
<< '.' << (int)B_TRANSLATION_REVISION_VERSION(version);
|
<< '.' << (int)B_TRANSLATION_REVISION_VERSION(version);
|
||||||
message << "\nInfo:\t\t" << info <<
|
message << "\nInfo: " << info <<
|
||||||
"\n\nPath:\n" << path.Path() << "\n";
|
"\n\nPath:\n" << path.Path() << "\n";
|
||||||
|
|
||||||
BAlert *alert = new BAlert("info", message.String(), "OK");
|
BAlert *alert = new BAlert("info", message.String(), "OK");
|
||||||
@@ -294,7 +286,7 @@ void
|
|||||||
DataTranslationsWindow::MessageReceived(BMessage *message)
|
DataTranslationsWindow::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case BUTTON_MSG:
|
case kMsgTranslatorInfo:
|
||||||
{
|
{
|
||||||
int32 selected = fTranslatorListView->CurrentSelection(0);
|
int32 selected = fTranslatorListView->CurrentSelection(0);
|
||||||
if (selected < 0) {
|
if (selected < 0) {
|
||||||
@@ -309,11 +301,13 @@ DataTranslationsWindow::MessageReceived(BMessage *message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ShowInfoAlert(selected);
|
TranslatorItem* item = dynamic_cast<TranslatorItem*>(fTranslatorListView->ItemAt(selected));
|
||||||
|
if (item != NULL)
|
||||||
|
_ShowInfoAlert(item->ID());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SEL_CHANGE:
|
case kMsgSelectedTranslator:
|
||||||
{
|
{
|
||||||
// Update the icon and translator info panel
|
// Update the icon and translator info panel
|
||||||
// to match the new selection
|
// to match the new selection
|
||||||
@@ -327,18 +321,57 @@ DataTranslationsWindow::MessageReceived(BMessage *message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ShowConfigView(selected);
|
TranslatorItem* item = dynamic_cast<TranslatorItem*>(fTranslatorListView->ItemAt(selected));
|
||||||
|
if (item == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
_ShowConfigView(item->ID());
|
||||||
|
|
||||||
const char* name = NULL;
|
const char* name = NULL;
|
||||||
const char* info = NULL;
|
const char* info = NULL;
|
||||||
int32 version = 0;
|
int32 version = 0;
|
||||||
BPath path;
|
BPath path;
|
||||||
_GetTranslatorInfo(selected, name, info, version, path);
|
_GetTranslatorInfo(item->ID(), name, info, version, path);
|
||||||
fTranslatorNameView->SetText(path.Leaf());
|
fTranslatorNameView->SetText(path.Leaf());
|
||||||
fIconView->SetIcon(path);
|
fIconView->SetIcon(path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case B_TRANSLATOR_ADDED:
|
||||||
|
{
|
||||||
|
int32 index = 0, id;
|
||||||
|
while (message->FindInt32("translator_id", index++, &id) == B_OK) {
|
||||||
|
const char* name;
|
||||||
|
const char* info;
|
||||||
|
int32 version;
|
||||||
|
BPath path;
|
||||||
|
if (_GetTranslatorInfo(id, name, info, version, path) == B_OK)
|
||||||
|
fTranslatorListView->AddItem(new TranslatorItem(id, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
fTranslatorListView->SortItems();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case B_TRANSLATOR_REMOVED:
|
||||||
|
{
|
||||||
|
int32 index = 0, id;
|
||||||
|
while (message->FindInt32("translator_id", index++, &id) == B_OK) {
|
||||||
|
for (int32 i = 0; i < fTranslatorListView->CountItems(); i++) {
|
||||||
|
TranslatorItem* item = dynamic_cast<TranslatorItem*>(fTranslatorListView->ItemAt(i));
|
||||||
|
if (item == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (item->ID() == (translator_id)id) {
|
||||||
|
fTranslatorListView->RemoveItem(i);
|
||||||
|
delete item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#define DATA_TRANSLATIONS_WINDOW_H
|
#define DATA_TRANSLATIONS_WINDOW_H
|
||||||
|
|
||||||
|
|
||||||
//#include "DataTranslationsSettings.h"
|
|
||||||
#include "IconView.h"
|
#include "IconView.h"
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|||||||
@@ -14,6 +14,33 @@
|
|||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
compare_items(const void* a, const void* b)
|
||||||
|
{
|
||||||
|
const BStringItem* stringA = *(const BStringItem**)a;
|
||||||
|
const BStringItem* stringB = *(const BStringItem**)b;
|
||||||
|
|
||||||
|
return strcmp(stringA->Text(), stringB->Text());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
TranslatorItem::TranslatorItem(translator_id id, const char* name)
|
||||||
|
: BStringItem(name),
|
||||||
|
fID(id)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TranslatorItem::~TranslatorItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
TranslatorListView::TranslatorListView(BRect rect, const char *name,
|
TranslatorListView::TranslatorListView(BRect rect, const char *name,
|
||||||
list_view_type type)
|
list_view_type type)
|
||||||
@@ -66,3 +93,10 @@ TranslatorListView::MouseMoved(BPoint point, uint32 transit, const BMessage *dra
|
|||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TranslatorListView::SortItems()
|
||||||
|
{
|
||||||
|
BListView::SortItems(&compare_items);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,20 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
|
#include <TranslationDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
class TranslatorItem : public BStringItem {
|
||||||
|
public:
|
||||||
|
TranslatorItem(translator_id id, const char* name);
|
||||||
|
virtual ~TranslatorItem();
|
||||||
|
|
||||||
|
translator_id ID() const { return fID; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
translator_id fID;
|
||||||
|
};
|
||||||
|
|
||||||
class TranslatorListView : public BListView {
|
class TranslatorListView : public BListView {
|
||||||
public:
|
public:
|
||||||
TranslatorListView(BRect rect, const char *name,
|
TranslatorListView(BRect rect, const char *name,
|
||||||
@@ -22,6 +34,8 @@ class TranslatorListView : public BListView {
|
|||||||
|
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *msg);
|
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *msg);
|
||||||
|
|
||||||
|
void SortItems();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRANSLATOR_LIST_VIEW_H
|
#endif // TRANSLATOR_LIST_VIEW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user