Patch by augiedoggie: Remove the hardcoded translator_id values from Screenshot.
Fixes ticket #5733. Thanks a lot! (Note: small coding style fixes by myself, so expect merge conflicts.) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36342 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -29,8 +29,7 @@ Screenshot::Screenshot()
|
|||||||
BApplication("application/x-vnd.Haiku-Screenshot"),
|
BApplication("application/x-vnd.Haiku-Screenshot"),
|
||||||
fArgvReceived(false),
|
fArgvReceived(false),
|
||||||
fRefsReceived(false),
|
fRefsReceived(false),
|
||||||
fImageFileType(B_PNG_FORMAT),
|
fImageFileType(B_PNG_FORMAT)
|
||||||
fTranslator(8)
|
|
||||||
{
|
{
|
||||||
be_locale->GetAppCatalog(&fCatalog);
|
be_locale->GetAppCatalog(&fCatalog);
|
||||||
}
|
}
|
||||||
@@ -136,7 +135,7 @@ Screenshot::ArgvReceived(int32 argc, char** argv)
|
|||||||
|
|
||||||
new ScreenshotWindow(delay, includeBorder, includeMouse, grabActiveWindow,
|
new ScreenshotWindow(delay, includeBorder, includeMouse, grabActiveWindow,
|
||||||
showConfigureWindow, saveScreenshotSilent, fImageFileType,
|
showConfigureWindow, saveScreenshotSilent, fImageFileType,
|
||||||
fTranslator, outputFilename);
|
outputFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -164,26 +163,20 @@ Screenshot::_ShowHelp() const
|
|||||||
void
|
void
|
||||||
Screenshot::_SetImageTypeSilence(const char* name)
|
Screenshot::_SetImageTypeSilence(const char* name)
|
||||||
{
|
{
|
||||||
if (strcmp(name, "bmp") == 0) {
|
if (strcmp(name, "bmp") == 0)
|
||||||
fImageFileType = B_BMP_FORMAT;
|
fImageFileType = B_BMP_FORMAT;
|
||||||
fTranslator = 1;
|
else if (strcmp(name, "gif") == 0)
|
||||||
} else if (strcmp(name, "gif") == 0) {
|
|
||||||
fImageFileType = B_GIF_FORMAT;
|
fImageFileType = B_GIF_FORMAT;
|
||||||
fTranslator = 3;
|
else if (strcmp(name, "jpg") == 0 || strcmp(name, "jpeg") == 0)
|
||||||
} else if (strcmp(name, "jpg") == 0) {
|
|
||||||
fImageFileType = B_JPEG_FORMAT;
|
fImageFileType = B_JPEG_FORMAT;
|
||||||
fTranslator = 6;
|
else if (strcmp(name, "ppm") == 0)
|
||||||
} else if (strcmp(name, "ppm") == 0) {
|
|
||||||
fImageFileType = B_PPM_FORMAT;
|
fImageFileType = B_PPM_FORMAT;
|
||||||
fTranslator = 9;
|
else if (strcmp(name, "targa") == 0 || strcmp(name, "tga") == 0)
|
||||||
} else if (strcmp(name, "targa") == 0) {
|
|
||||||
fImageFileType = B_TGA_FORMAT;
|
fImageFileType = B_TGA_FORMAT;
|
||||||
fTranslator = 14;
|
else if (strcmp(name, "tif") == 0 || strcmp(name, "tiff") == 0)
|
||||||
} else if (strcmp(name, "tif") == 0) {
|
|
||||||
fImageFileType = B_TIFF_FORMAT;
|
fImageFileType = B_TIFF_FORMAT;
|
||||||
fTranslator = 15;
|
else {
|
||||||
} else { //png
|
// Default to PNG.
|
||||||
fImageFileType = B_PNG_FORMAT;
|
fImageFileType = B_PNG_FORMAT;
|
||||||
fTranslator = 8;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ private:
|
|||||||
bool fArgvReceived;
|
bool fArgvReceived;
|
||||||
bool fRefsReceived;
|
bool fRefsReceived;
|
||||||
int32 fImageFileType;
|
int32 fImageFileType;
|
||||||
int32 fTranslator;
|
|
||||||
BCatalog fCatalog;
|
BCatalog fCatalog;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ public:
|
|||||||
|
|
||||||
ScreenshotWindow::ScreenshotWindow(bigtime_t delay, bool includeBorder,
|
ScreenshotWindow::ScreenshotWindow(bigtime_t delay, bool includeBorder,
|
||||||
bool includeMouse, bool grabActiveWindow, bool showConfigWindow,
|
bool includeMouse, bool grabActiveWindow, bool showConfigWindow,
|
||||||
bool saveScreenshotSilent, int32 imageFileType, int32 translator,
|
bool saveScreenshotSilent, int32 imageFileType, const char* outputFilename)
|
||||||
const char* outputFilename)
|
|
||||||
:
|
:
|
||||||
BWindow(BRect(0, 0, 200.0, 100.0), TR("Retake screenshot"), B_TITLED_WINDOW,
|
BWindow(BRect(0, 0, 200.0, 100.0), TR("Retake screenshot"), B_TITLED_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE |
|
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE |
|
||||||
@@ -117,7 +116,6 @@ ScreenshotWindow::ScreenshotWindow(bigtime_t delay, bool includeBorder,
|
|||||||
fSaveScreenshotSilent(saveScreenshotSilent),
|
fSaveScreenshotSilent(saveScreenshotSilent),
|
||||||
fOutputFilename(outputFilename),
|
fOutputFilename(outputFilename),
|
||||||
fExtension(""),
|
fExtension(""),
|
||||||
fTranslator(translator),
|
|
||||||
fImageFileType(imageFileType)
|
fImageFileType(imageFileType)
|
||||||
{
|
{
|
||||||
if (fSaveScreenshotSilent) {
|
if (fSaveScreenshotSilent) {
|
||||||
@@ -185,7 +183,6 @@ ScreenshotWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
case kImageOutputFormat:
|
case kImageOutputFormat:
|
||||||
message->FindInt32("be:type", &fImageFileType);
|
message->FindInt32("be:type", &fImageFileType);
|
||||||
message->FindInt32("be:translator", &fTranslator);
|
|
||||||
fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String());
|
fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String());
|
||||||
_UpdateFilenameSelection();
|
_UpdateFilenameSelection();
|
||||||
break;
|
break;
|
||||||
@@ -616,27 +613,32 @@ ScreenshotWindow::_FindValidFileName(const char* name)
|
|||||||
return baseName;
|
return baseName;
|
||||||
|
|
||||||
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||||
const translation_format* formats = NULL;
|
|
||||||
|
|
||||||
int32 numFormats;
|
translator_id id = 0;
|
||||||
if (roster->GetOutputFormats(fTranslator, &formats, &numFormats) == B_OK) {
|
if (_FindTranslator(fImageFileType, &id) == B_OK) {
|
||||||
for (int32 i = 0; i < numFormats; ++i) {
|
|
||||||
if (formats[i].type == uint32(fImageFileType)) {
|
const translation_format* formats = NULL;
|
||||||
BMimeType mimeType(formats[i].MIME);
|
|
||||||
BMessage msgExtensions;
|
int32 numFormats;
|
||||||
if (mimeType.GetFileExtensions(&msgExtensions) == B_OK) {
|
if (roster->GetOutputFormats(id, &formats, &numFormats) == B_OK) {
|
||||||
const char* extension;
|
for (int32 i = 0; i < numFormats; ++i) {
|
||||||
if (msgExtensions.FindString("extensions", 0, &extension) == B_OK) {
|
if (formats[i].type == uint32(fImageFileType)) {
|
||||||
fExtension.SetTo(extension);
|
BMimeType mimeType(formats[i].MIME);
|
||||||
fExtension.Prepend(".");
|
BMessage msgExtensions;
|
||||||
} else
|
if (mimeType.GetFileExtensions(&msgExtensions) == B_OK) {
|
||||||
fExtension.SetTo("");
|
const char* extension;
|
||||||
|
if (msgExtensions.FindString("extensions", 0, &extension) == B_OK) {
|
||||||
|
fExtension.SetTo(extension);
|
||||||
|
fExtension.Prepend(".");
|
||||||
|
} else
|
||||||
|
fExtension.SetTo("");
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BPath outputPath = orgPath;
|
BPath outputPath = orgPath;
|
||||||
BString fileName;
|
BString fileName;
|
||||||
fileName << baseName << fExtension;
|
fileName << baseName << fExtension;
|
||||||
@@ -855,10 +857,15 @@ ScreenshotWindow::_SaveScreenshot()
|
|||||||
if (nodeInfo.InitCheck() != B_OK)
|
if (nodeInfo.InitCheck() != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
|
translator_id id = 0;
|
||||||
|
if (_FindTranslator(fImageFileType, &id) != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
int32 numFormats;
|
int32 numFormats;
|
||||||
const translation_format* formats = NULL;
|
const translation_format* formats = NULL;
|
||||||
if (roster->GetOutputFormats(fTranslator, &formats, &numFormats) != B_OK)
|
|
||||||
return B_OK;
|
if (roster->GetOutputFormats(id, &formats, &numFormats) != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
for (int32 i = 0; i < numFormats; ++i) {
|
for (int32 i = 0; i < numFormats; ++i) {
|
||||||
if (formats[i].type == uint32(fImageFileType)) {
|
if (formats[i].type == uint32(fImageFileType)) {
|
||||||
@@ -866,6 +873,7 @@ ScreenshotWindow::_SaveScreenshot()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -958,3 +966,35 @@ ScreenshotWindow::_MakeTabSpaceTransparent(BRect* frame)
|
|||||||
}
|
}
|
||||||
fScreenshot->RemoveChild(&view);
|
fScreenshot->RemoveChild(&view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
ScreenshotWindow::_FindTranslator(uint32 imageType, translator_id* id)
|
||||||
|
{
|
||||||
|
translator_id* translators = NULL;
|
||||||
|
int32 numTranslators = 0;
|
||||||
|
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||||
|
status_t status = roster->GetAllTranslators(&translators, &numTranslators);
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
status = B_ERROR;
|
||||||
|
for (int32 x = 0; x < numTranslators && status != B_OK; x++) {
|
||||||
|
int32 numFormats;
|
||||||
|
const translation_format* formats = NULL;
|
||||||
|
|
||||||
|
if (roster->GetOutputFormats(x, &formats, &numFormats) == B_OK) {
|
||||||
|
for (int32 i = 0; i < numFormats; ++i) {
|
||||||
|
if (formats[i].type == imageType) {
|
||||||
|
*id = x;
|
||||||
|
status = B_OK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete [] translators;
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
#include <TranslationDefs.h>
|
||||||
#include <TranslatorFormats.h>
|
#include <TranslatorFormats.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -37,7 +38,6 @@ public:
|
|||||||
bool showConfigWindow = false,
|
bool showConfigWindow = false,
|
||||||
bool saveScreenshotSilent = false,
|
bool saveScreenshotSilent = false,
|
||||||
int32 imageFileType = B_PNG_FORMAT,
|
int32 imageFileType = B_PNG_FORMAT,
|
||||||
int32 translator = 8,
|
|
||||||
const char* outputFilename = NULL);
|
const char* outputFilename = NULL);
|
||||||
virtual ~ScreenshotWindow();
|
virtual ~ScreenshotWindow();
|
||||||
|
|
||||||
@@ -70,6 +70,8 @@ private:
|
|||||||
|
|
||||||
status_t _SaveScreenshot();
|
status_t _SaveScreenshot();
|
||||||
|
|
||||||
|
status_t _FindTranslator(uint32 imageType, translator_id* id);
|
||||||
|
|
||||||
PreviewView* fPreview;
|
PreviewView* fPreview;
|
||||||
BRadioButton* fActiveWindow;
|
BRadioButton* fActiveWindow;
|
||||||
BRadioButton* fWholeDesktop;
|
BRadioButton* fWholeDesktop;
|
||||||
@@ -97,7 +99,6 @@ private:
|
|||||||
BString fOutputFilename;
|
BString fOutputFilename;
|
||||||
BString fExtension;
|
BString fExtension;
|
||||||
|
|
||||||
int32 fTranslator;
|
|
||||||
int32 fImageFileType;
|
int32 fImageFileType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user