Ticket #5733: screenshot3.diff
File screenshot3.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),121 119 fImageFileType(imageFileType) 122 120 { 123 121 if (fSaveScreenshotSilent) { … … 185 183 186 184 case kImageOutputFormat: 187 185 message->FindInt32("be:type", &fImageFileType); 188 message->FindInt32("be:translator", &fTranslator);189 186 fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String()); 190 187 _UpdateFilenameSelection(); 191 188 break; … … 616 613 return baseName; 617 614 618 615 BTranslatorRoster* roster = BTranslatorRoster::Default(); 619 const translation_format* formats = NULL;620 616 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(""); 617 translator_id id = 0; 618 if (_FindTranslator(fImageFileType, &id) == B_OK) { 619 620 const translation_format* formats = NULL; 621 622 int32 numFormats; 623 if (roster->GetOutputFormats(id, &formats, &numFormats) == B_OK) { 624 for (int32 i = 0; i < numFormats; ++i) { 625 if (formats[i].type == uint32(fImageFileType)) { 626 BMimeType mimeType(formats[i].MIME); 627 BMessage msgExtensions; 628 if (mimeType.GetFileExtensions(&msgExtensions) == B_OK) { 629 const char* extension; 630 if (msgExtensions.FindString("extensions", 0, &extension) == B_OK) { 631 fExtension.SetTo(extension); 632 fExtension.Prepend("."); 633 } else 634 fExtension.SetTo(""); 635 } 636 break; 634 637 } 635 break;636 638 } 637 639 } 638 640 } 639 641 640 642 BPath outputPath = orgPath; 641 643 BString fileName; 642 644 fileName << baseName << fExtension; … … 855 857 if (nodeInfo.InitCheck() != B_OK) 856 858 return B_ERROR; 857 859 860 translator_id id = 0; 861 if (_FindTranslator(fImageFileType, &id) != B_OK) 862 return B_ERROR; 863 858 864 int32 numFormats; 859 865 const translation_format* formats = NULL; 860 if (roster->GetOutputFormats(fTranslator, &formats, &numFormats) != B_OK)861 return B_OK;862 866 867 if (roster->GetOutputFormats(id, &formats, &numFormats) != B_OK) 868 return B_ERROR; 869 863 870 for (int32 i = 0; i < numFormats; ++i) { 864 871 if (formats[i].type == uint32(fImageFileType)) { 865 872 nodeInfo.SetType(formats[i].MIME); 866 873 break; 867 874 } 868 875 } 876 869 877 return B_OK; 870 878 } 871 879 … … 958 966 } 959 967 fScreenshot->RemoveChild(&view); 960 968 } 969 970 971 status_t 972 ScreenshotWindow::_FindTranslator(uint32 imageType, translator_id* id) 973 { 974 status_t status = B_ERROR; 975 976 translator_id* translators = NULL; 977 int32 numTranslators = 0; 978 BTranslatorRoster* roster = BTranslatorRoster::Default(); 979 roster->GetAllTranslators(&translators, &numTranslators); 980 981 for (int32 x = 0; x < numTranslators && status != B_OK; x++) { 982 int32 numFormats; 983 const translation_format* formats = NULL; 984 985 if (roster->GetOutputFormats(x, &formats, &numFormats) == B_OK) { 986 for (int32 i = 0; i < numFormats; ++i) { 987 if (formats[i].type == imageType) { 988 *id = x; 989 status = B_OK; 990 break; 991 } 992 } 993 } 994 } 995 996 delete [] translators; 997 998 return status; 999 } -
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 int32 fTranslator;101 102 int32 fImageFileType; 102 103 }; 103 104 -
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 }