PackageInstaller: Yet more cleanup and code simplifications
This commit is contained in:
@@ -25,21 +25,19 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ImageView::ImageView(BPositionIO *image)
|
ImageView::ImageView(BPositionIO* imageIO)
|
||||||
:
|
:
|
||||||
BView(BRect(0, 0, 1, 1), "image_view", B_FOLLOW_NONE, B_WILL_DRAW),
|
BView(BRect(0, 0, 1, 1), "image_view", B_FOLLOW_NONE, B_WILL_DRAW),
|
||||||
fSuccess(true)
|
fImage(NULL)
|
||||||
{
|
{
|
||||||
if (!image) {
|
if (imageIO == NULL)
|
||||||
fSuccess = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
// Initialize and translate the image
|
// Initialize and translate the image
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||||
BBitmapStream stream;
|
BBitmapStream stream;
|
||||||
if (roster->Translate(image, NULL, NULL, &stream, B_TRANSLATOR_BITMAP)
|
if (roster->Translate(imageIO, NULL, NULL, &stream, B_TRANSLATOR_BITMAP)
|
||||||
< B_OK) {
|
!= B_OK) {
|
||||||
fSuccess = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stream.DetachBitmap(&fImage);
|
stream.DetachBitmap(&fImage);
|
||||||
@@ -48,13 +46,14 @@ ImageView::ImageView(BPositionIO *image)
|
|||||||
|
|
||||||
ImageView::~ImageView()
|
ImageView::~ImageView()
|
||||||
{
|
{
|
||||||
|
delete fImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ImageView::AttachedToWindow()
|
ImageView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
if (!fSuccess) {
|
if (fImage == NULL) {
|
||||||
ResizeTo(75, 75);
|
ResizeTo(75, 75);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -77,12 +76,12 @@ ImageView::AttachedToWindow()
|
|||||||
void
|
void
|
||||||
ImageView::Draw(BRect updateRect)
|
ImageView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
if (fSuccess)
|
if (fImage != NULL)
|
||||||
DrawBitmapAsync(fImage, Bounds());
|
DrawBitmapAsync(fImage, Bounds());
|
||||||
else {
|
else {
|
||||||
float length = StringWidth(B_TRANSLATE("Image not loaded correctly"));
|
const char* message = B_TRANSLATE("Image not loaded correctly");
|
||||||
DrawString(B_TRANSLATE("Image not loaded correctly"),
|
float width = StringWidth(message);
|
||||||
BPoint((Bounds().Width() - length) / 2.0f, 30.0f));
|
DrawString(message, BPoint((Bounds().Width() - width) / 2.0f, 30.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +89,7 @@ ImageView::Draw(BRect updateRect)
|
|||||||
void
|
void
|
||||||
ImageView::MouseUp(BPoint point)
|
ImageView::MouseUp(BPoint point)
|
||||||
{
|
{
|
||||||
BWindow *parent = Window();
|
BWindow* parent = Window();
|
||||||
if (parent)
|
if (parent)
|
||||||
parent->PostMessage(P_MSG_CLOSE);
|
parent->PostMessage(P_MSG_CLOSE);
|
||||||
}
|
}
|
||||||
@@ -99,12 +98,12 @@ ImageView::MouseUp(BPoint point)
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
PackageImageViewer::PackageImageViewer(BPositionIO *image)
|
PackageImageViewer::PackageImageViewer(BPositionIO* imageIO)
|
||||||
:
|
:
|
||||||
BWindow(BRect(100, 100, 100, 100), "", B_MODAL_WINDOW,
|
BWindow(BRect(100, 100, 100, 100), "", B_MODAL_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE)
|
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE)
|
||||||
{
|
{
|
||||||
fBackground = new ImageView(image);
|
fBackground = new ImageView(imageIO);
|
||||||
AddChild(fBackground);
|
AddChild(fBackground);
|
||||||
|
|
||||||
ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height());
|
ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height());
|
||||||
@@ -112,7 +111,7 @@ PackageImageViewer::PackageImageViewer(BPositionIO *image)
|
|||||||
BScreen screen(this);
|
BScreen screen(this);
|
||||||
BRect frame = screen.Frame();
|
BRect frame = screen.Frame();
|
||||||
MoveTo((frame.Width() - Bounds().Width()) / 2.0f,
|
MoveTo((frame.Width() - Bounds().Width()) / 2.0f,
|
||||||
(frame.Height() - Bounds().Height()) / 2.0f);
|
(frame.Height() - Bounds().Height()) / 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,6 +120,19 @@ PackageImageViewer::~PackageImageViewer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageImageViewer::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
if (message->what == P_MSG_CLOSE) {
|
||||||
|
if (fSemaphore >= B_OK) {
|
||||||
|
delete_sem(fSemaphore);
|
||||||
|
fSemaphore = -1;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
BWindow::MessageReceived(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageImageViewer::Go()
|
PackageImageViewer::Go()
|
||||||
{
|
{
|
||||||
@@ -133,11 +145,14 @@ PackageImageViewer::Go()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BWindow *parent =
|
thread_id callingThread = find_thread(NULL);
|
||||||
dynamic_cast<BWindow *>(BLooper::LooperForThread(find_thread(NULL)));
|
BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(
|
||||||
|
callingThread));
|
||||||
Show();
|
Show();
|
||||||
|
|
||||||
if (parent) {
|
if (window != NULL) {
|
||||||
|
// Make sure calling window thread, which is blocked here, is updating
|
||||||
|
// the window from time to time.
|
||||||
status_t ret;
|
status_t ret;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
do {
|
do {
|
||||||
@@ -146,10 +161,9 @@ PackageImageViewer::Go()
|
|||||||
|
|
||||||
if (ret == B_BAD_SEM_ID)
|
if (ret == B_BAD_SEM_ID)
|
||||||
break;
|
break;
|
||||||
parent->UpdateIfNeeded();
|
window->UpdateIfNeeded();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Since there are no spinlocks, wait until the semaphore is free
|
// Since there are no spinlocks, wait until the semaphore is free
|
||||||
while (acquire_sem(fSemaphore) == B_INTERRUPTED) {
|
while (acquire_sem(fSemaphore) == B_INTERRUPTED) {
|
||||||
}
|
}
|
||||||
@@ -159,16 +173,3 @@ PackageImageViewer::Go()
|
|||||||
Quit();
|
Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PackageImageViewer::MessageReceived(BMessage *msg)
|
|
||||||
{
|
|
||||||
if (msg->what == P_MSG_CLOSE) {
|
|
||||||
if (fSemaphore >= B_OK) {
|
|
||||||
delete_sem(fSemaphore);
|
|
||||||
fSemaphore = -1;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
BWindow::MessageReceived(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
* Author:
|
* Author:
|
||||||
* Łukasz 'Sil2100' Zemczak <[email protected]>
|
* Łukasz 'Sil2100' Zemczak <[email protected]>
|
||||||
*/
|
*/
|
||||||
#ifndef PACKAGEIMAGEVIEWER_H
|
#ifndef PACKAGE_IMAGE_VIEWER_H
|
||||||
#define PACKAGEIMAGEVIEWER_H
|
#define PACKAGE_IMAGE_VIEWER_H
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
@@ -16,35 +16,34 @@
|
|||||||
|
|
||||||
|
|
||||||
class ImageView : public BView {
|
class ImageView : public BView {
|
||||||
public:
|
public:
|
||||||
ImageView(BPositionIO *image);
|
ImageView(BPositionIO* image);
|
||||||
~ImageView();
|
virtual ~ImageView();
|
||||||
|
|
||||||
void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
void MouseUp(BPoint point);
|
virtual void MouseUp(BPoint point);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BBitmap *fImage;
|
BBitmap* fImage;
|
||||||
bool fSuccess;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PackageImageViewer : public BWindow {
|
class PackageImageViewer : public BWindow {
|
||||||
public:
|
public:
|
||||||
PackageImageViewer(BPositionIO *image);
|
PackageImageViewer(BPositionIO* image);
|
||||||
~PackageImageViewer();
|
virtual ~PackageImageViewer();
|
||||||
|
|
||||||
void Go();
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
void MessageReceived(BMessage *msg);
|
|
||||||
|
|
||||||
private:
|
void Go();
|
||||||
ImageView *fBackground;
|
|
||||||
|
|
||||||
sem_id fSemaphore;
|
private:
|
||||||
|
ImageView* fBackground;
|
||||||
|
|
||||||
|
sem_id fSemaphore;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // PACKAGE_IMAGE_VIEWER_H
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user