Changed the progress monitor protocol to path a basic message that will be sent back

instead of having a fixed message code.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20746 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-04-18 12:00:07 +00:00
parent a1c0361478
commit 5878fb7998
4 changed files with 26 additions and 13 deletions

View File

@ -8,6 +8,7 @@
#include "ConfigView.h"
#include "RAW.h"
#include <Messenger.h>
#include <TranslatorRoster.h>
#include <stdlib.h>
@ -32,12 +33,16 @@ class FreeAllocation {
void* fBuffer;
};
struct progress_data {
BMessenger monitor;
BMessage message;
};
// Extensions that ShowImage supports
const char* kDocumentCount = "/documentCount";
const char* kDocumentIndex = "/documentIndex";
const char* kProgressMonitor = "/progressMonitor";
const uint32 kMsgProgressMonitorUpdate = 'SIup';
const char* kProgressMessage = "/progressMessage";
// The input formats that this translator supports.
translation_format sInputFormats[] = {
@ -158,16 +163,16 @@ RAWTranslator::DerivedIdentify(BPositionIO *stream,
/*static*/ void
RAWTranslator::_ProgressMonitor(const char* message, float percentage,
void* data)
void* _data)
{
BMessenger& messenger = *(BMessenger*)data;
progress_data& data = *(progress_data*)_data;
BMessage update(kMsgProgressMonitorUpdate);
BMessage update(data.message);
update.AddString("message", message);
update.AddFloat("percent", percentage);
update.AddInt64("time", system_time());
messenger.SendMessage(&update);
data.monitor.SendMessage(&update);
}
@ -184,14 +189,19 @@ RAWTranslator::DerivedTranslate(BPositionIO* source,
DCRaw raw(*source);
bool headerOnly = false;
progress_data progressData;
BMessenger monitor;
if (settings != NULL) {
settings->FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &headerOnly);
if (settings->FindMessenger(kProgressMonitor, &monitor) == B_OK) {
raw.SetProgressMonitor(&_ProgressMonitor, &monitor);
_ProgressMonitor("Reading Image Data", 0, &monitor);
if (settings->FindMessenger(kProgressMonitor,
&progressData.monitor) == B_OK
&& settings->FindMessage(kProgressMessage,
&progressData.message) == B_OK) {
raw.SetProgressMonitor(&_ProgressMonitor, &progressData);
_ProgressMonitor("Reading Image Data", 0, &progressData);
}
}

View File

@ -5,6 +5,7 @@
#include "ProgressWindow.h"
#include "ShowImageConstants.h"
#include <Autolock.h>
#include <MessageRunner.h>
@ -15,7 +16,6 @@
static const uint32 kMsgShow = 'show';
static const uint32 kMsgStatusUpdate = 'SIup';
ProgressWindow::ProgressWindow(BWindow* referenceWindow)
@ -92,7 +92,7 @@ ProgressWindow::MessageReceived(BMessage *message)
fRetrievedShow = true;
break;
case kMsgStatusUpdate:
case kMsgProgressStatusUpdate:
float percent;
if (message->FindFloat("percent", &percent) == B_OK)
fStatusBar->Update(percent - fStatusBar->CurrentValue());

View File

@ -63,6 +63,7 @@ enum {
MSG_OPEN_RESIZER_WINDOW = 'mORS',
MSG_RESIZER_WINDOW_QUIT = 'mRSQ',
MSG_RESIZE = 'mRSZ',
kMsgProgressStatusUpdate = 'SIup'
};
#endif // SHOW_IMAGE_CONSTANTS_H

View File

@ -494,7 +494,9 @@ ShowImageView::SetImage(const entry_ref *ref)
if (ioExtension.AddInt32("/documentIndex", fDocumentIndex) != B_OK)
return B_ERROR;
if (ioExtension.AddMessenger("/progressMonitor", fProgressWindow) == B_OK)
BMessage progress(kMsgProgressStatusUpdate);
if (ioExtension.AddMessenger("/progressMonitor", fProgressWindow) == B_OK
&& ioExtension.AddMessage("/progressMessage", &progress) == B_OK)
fProgressWindow->Start();
// Translate image data and create a new ShowImage window
@ -1228,7 +1230,7 @@ ShowImageView::SaveToFile(BDirectory* dir, const char* name, BBitmap* bitmap,
}
BBitmapStream stream(bitmap);
bool loop = true;
while (loop) {
BTranslatorRoster *roster = BTranslatorRoster::Default();