Ticket #5733: screenshot2.diff
File screenshot2.diff, 6.7 KB (added by , 15 years ago) |
---|
-
src/apps/screenshot/Screenshot.h
30 30 bool fArgvReceived; 31 31 bool fRefsReceived; 32 32 int32 fImageFileType; 33 int32 fTranslator;34 33 BCatalog fCatalog; 35 34 }; 36 35 -
src/apps/screenshot/ScreenshotWindow.cpp
98 98 99 99 ScreenshotWindow::ScreenshotWindow(bigtime_t delay, bool includeBorder, 100 100 bool includeMouse, bool grabActiveWindow, bool showConfigWindow, 101 bool saveScreenshotSilent, int32 imageFileType, int32 translator, 102 const char* outputFilename) 101 bool saveScreenshotSilent, int32 imageFileType, const char* outputFilename) 103 102 : 104 103 BWindow(BRect(0, 0, 200.0, 100.0), TR("Retake screenshot"), B_TITLED_WINDOW, 105 104 B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE | … … 117 116 fSaveScreenshotSilent(saveScreenshotSilent), 118 117 fOutputFilename(outputFilename), 119 118 fExtension(""), 120 fTranslator( translator),119 fTranslator(0), 121 120 fImageFileType(imageFileType) 122 121 { 123 122 if (fSaveScreenshotSilent) { … … 185 184 186 185 case kImageOutputFormat: 187 186 message->FindInt32("be:type", &fImageFileType); 188 message->FindInt32("be:translator", &fTranslator);187 message->FindInt32("be:translator", (int32*)&fTranslator); 189 188 fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String()); 190 189 _UpdateFilenameSelection(); 191 190 break; … … 616 615 return baseName; 617 616 618 617 BTranslatorRoster* roster = BTranslatorRoster::Default(); 619 const translation_format* formats = NULL;620 618 621 int32 numFormats; 622 if (roster->GetOutputFormats(fTranslator, &formats, &numFormats) == B_OK) { 623 for (int32 i = 0; i < numFormats; ++i) { 624 if (formats[i].type == uint32(fImageFileType)) { 625 BMimeType mimeType(formats[i].MIME); 626 BMessage msgExtensions; 627 if (mimeType.GetFileExtensions(&msgExtensions) == B_OK) { 628 const char* extension; 629 if (msgExtensions.FindString("extensions", 0, &extension) == B_OK) { 630 fExtension.SetTo(extension); 631 fExtension.Prepend("."); 632 } else 633 fExtension.SetTo(""); 619 if (fTranslator != 0 620 || _FindTranslator(fImageFileType, &fTranslator) == B_OK) { 621 622 const translation_format* formats = NULL; 623 624 int32 numFormats; 625 if (roster->GetOutputFormats(fTranslator, &formats, &numFormats) == B_OK) { 626 for (int32 i = 0; i < numFormats; ++i) { 627 if (formats[i].type == uint32(fImageFileType)) { 628 BMimeType mimeType(formats[i].MIME); 629 BMessage msgExtensions; 630 if (mimeType.GetFileExtensions(&msgExtensions) == B_OK) { 631 const char* extension; 632 if (msgExtensions.FindString("extensions", 0, &extension) == B_OK) { 633 fExtension.SetTo(extension); 634 fExtension.Prepend("."); 635 } else 636 fExtension.SetTo(""); 637 } 638 break; 634 639 } 635 break;636 640 } 637 641 } 638 642 } 639 643 640 644 BPath outputPath = orgPath; 641 645 BString fileName; 642 646 fileName << baseName << fExtension; … … 855 859 if (nodeInfo.InitCheck() != B_OK) 856 860 return B_ERROR; 857 861 862 863 if (fTranslator == 0 864 && _FindTranslator(fImageFileType, &fTranslator) != B_OK) 865 return B_ERROR; 866 858 867 int32 numFormats; 859 868 const translation_format* formats = NULL; 869 860 870 if (roster->GetOutputFormats(fTranslator, &formats, &numFormats) != B_OK) 861 return B_ OK;871 return B_ERROR; 862 872 863 873 for (int32 i = 0; i < numFormats; ++i) { 864 874 if (formats[i].type == uint32(fImageFileType)) { … … 866 876 break; 867 877 } 868 878 } 879 869 880 return B_OK; 870 881 } 871 882 … … 958 969 } 959 970 fScreenshot->RemoveChild(&view); 960 971 } 972 973 974 status_t 975 ScreenshotWindow::_FindTranslator(uint32 imageType, translator_id* id) 976 { 977 status_t status = B_ERROR; 978 979 translator_id* translators = NULL; 980 int32 numTranslators = 0; 981 BTranslatorRoster* roster = BTranslatorRoster::Default(); 982 roster->GetAllTranslators(&translators, &numTranslators); 983 984 for (int32 x = 0; x < numTranslators && status != B_OK; x++) { 985 int32 numFormats; 986 const translation_format* formats = NULL; 987 988 if (roster->GetOutputFormats(x, &formats, &numFormats) == B_OK) { 989 for (int32 i = 0; i < numFormats; ++i) { 990 if (formats[i].type == imageType) { 991 *id = x; 992 status = B_OK; 993 break; 994 } 995 } 996 } 997 } 998 999 delete [] translators; 1000 1001 return status; 1002 } -
src/apps/screenshot/ScreenshotWindow.h
12 12 13 13 #include <String.h> 14 14 #include <Window.h> 15 #include <TranslationDefs.h> 15 16 #include <TranslatorFormats.h> 16 17 17 18 … … 37 38 bool showConfigWindow = false, 38 39 bool saveScreenshotSilent = false, 39 40 int32 imageFileType = B_PNG_FORMAT, 40 int32 translator = 8,41 41 const char* outputFilename = NULL); 42 42 virtual ~ScreenshotWindow(); 43 43 … … 70 70 71 71 status_t _SaveScreenshot(); 72 72 73 status_t _FindTranslator(uint32 imageType, translator_id* id); 74 73 75 PreviewView* fPreview; 74 76 BRadioButton* fActiveWindow; 75 77 BRadioButton* fWholeDesktop; … … 97 99 BString fOutputFilename; 98 100 BString fExtension; 99 101 100 int32fTranslator;102 translator_id fTranslator; 101 103 int32 fImageFileType; 102 104 }; 103 105 -
src/apps/screenshot/Screenshot.cpp
29 29 BApplication("application/x-vnd.Haiku-Screenshot"), 30 30 fArgvReceived(false), 31 31 fRefsReceived(false), 32 fImageFileType(B_PNG_FORMAT), 33 fTranslator(8) 32 fImageFileType(B_PNG_FORMAT) 34 33 { 35 34 be_locale->GetAppCatalog(&fCatalog); 36 35 } … … 136 135 137 136 new ScreenshotWindow(delay, includeBorder, includeMouse, grabActiveWindow, 138 137 showConfigureWindow, saveScreenshotSilent, fImageFileType, 139 fTranslator,outputFilename);138 outputFilename); 140 139 } 141 140 142 141 … … 166 165 { 167 166 if (strcmp(name, "bmp") == 0) { 168 167 fImageFileType = B_BMP_FORMAT; 169 fTranslator = 1;170 168 } else if (strcmp(name, "gif") == 0) { 171 169 fImageFileType = B_GIF_FORMAT; 172 fTranslator = 3;173 170 } else if (strcmp(name, "jpg") == 0) { 174 171 fImageFileType = B_JPEG_FORMAT; 175 fTranslator = 6;176 172 } else if (strcmp(name, "ppm") == 0) { 177 173 fImageFileType = B_PPM_FORMAT; 178 fTranslator = 9;179 174 } else if (strcmp(name, "targa") == 0) { 180 175 fImageFileType = B_TGA_FORMAT; 181 fTranslator = 14;182 176 } else if (strcmp(name, "tif") == 0) { 183 177 fImageFileType = B_TIFF_FORMAT; 184 fTranslator = 15;185 178 } else { //png 186 179 fImageFileType = B_PNG_FORMAT; 187 fTranslator = 8;188 180 } 189 181 }