From 5878fb7998ccacca4647319dd898a9b440dabbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 18 Apr 2007 12:00:07 +0000 Subject: [PATCH] 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 --- src/add-ons/translators/raw/RAWTranslator.cpp | 28 +++++++++++++------ src/apps/showimage/ProgressWindow.cpp | 4 +-- src/apps/showimage/ShowImageConstants.h | 1 + src/apps/showimage/ShowImageView.cpp | 6 ++-- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/add-ons/translators/raw/RAWTranslator.cpp b/src/add-ons/translators/raw/RAWTranslator.cpp index a35e11214e..17796c2170 100644 --- a/src/add-ons/translators/raw/RAWTranslator.cpp +++ b/src/add-ons/translators/raw/RAWTranslator.cpp @@ -8,6 +8,7 @@ #include "ConfigView.h" #include "RAW.h" +#include #include #include @@ -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); } } diff --git a/src/apps/showimage/ProgressWindow.cpp b/src/apps/showimage/ProgressWindow.cpp index f279a9cd01..5407583b11 100644 --- a/src/apps/showimage/ProgressWindow.cpp +++ b/src/apps/showimage/ProgressWindow.cpp @@ -5,6 +5,7 @@ #include "ProgressWindow.h" +#include "ShowImageConstants.h" #include #include @@ -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()); diff --git a/src/apps/showimage/ShowImageConstants.h b/src/apps/showimage/ShowImageConstants.h index 5ae6ef08c6..4aacd8380e 100644 --- a/src/apps/showimage/ShowImageConstants.h +++ b/src/apps/showimage/ShowImageConstants.h @@ -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 diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index 4612c3e0c5..6378d747cd 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -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();