Ticket #3814: screenshot-wim.patch
File screenshot-wim.patch, 13.2 KB (added by , 14 years ago) |
---|
-
ScreenshotWindow.cpp
6 6 * Karsten Heimrich 7 7 * Fredrik Modéen 8 8 * Christophe Huriaux 9 * Wim van der Meer, WPJvanderMeer@gmail.com 9 10 */ 10 11 11 12 … … 96 97 #define TR_CONTEXT "ScreenshotWindow" 97 98 98 99 100 ScreenshotWindow::ScreenshotWindow() 101 : 102 BWindow(BRect(0, 0, 200.0, 100.0), TR("Retake screenshot"), B_TITLED_WINDOW, 103 B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE 104 | B_AVOID_FRONT | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), 105 fDelayControl(NULL), 106 fScreenshot(NULL), 107 fOutputPathPanel(NULL), 108 fLastSelectedPath(NULL), 109 fDelay(0), 110 fTabHeight(0), 111 fIncludeBorder(false), 112 fIncludeMouse(false), 113 fGrabActiveWindow(false), 114 fShowConfigWindow(false), 115 fSaveScreenshotSilent(false), 116 fOutputFilename(NULL), 117 fExtension(""), 118 fImageFileType(B_PNG_FORMAT) 119 { 120 BMessage settings = _ReadSettings(); 121 122 if (settings.FindInt32("type", &fImageFileType) != B_OK) 123 fImageFileType = B_PNG_FORMAT; 124 settings.FindBool("includeBorder", &fIncludeBorder); 125 settings.FindBool("includeMouse", &fIncludeMouse); 126 settings.FindBool("grabActiveWindow", &fGrabActiveWindow); 127 settings.FindInt64("delay", &fDelay); 128 settings.FindString("outputFilename", &fOutputFilename); 129 130 _InitWindow(settings); 131 CenterOnScreen(); 132 Show(); 133 } 134 135 99 136 ScreenshotWindow::ScreenshotWindow(bigtime_t delay, bool includeBorder, 100 137 bool includeMouse, bool grabActiveWindow, bool showConfigWindow, 101 138 bool saveScreenshotSilent, int32 imageFileType, const char* outputFilename) 102 139 : 103 140 BWindow(BRect(0, 0, 200.0, 100.0), TR("Retake screenshot"), B_TITLED_WINDOW, 104 B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE |105 B_AVOID_FRONT | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),141 B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE 142 | B_AVOID_FRONT | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), 106 143 fDelayControl(NULL), 107 144 fScreenshot(NULL), 108 145 fOutputPathPanel(NULL), … … 119 156 fImageFileType(imageFileType) 120 157 { 121 158 if (fSaveScreenshotSilent) { 122 _TakeScreenshot( );159 _TakeScreenshot(fDelay); 123 160 _SaveScreenshot(); 124 161 be_app_messenger.SendMessage(B_QUIT_REQUESTED); 125 162 } else { 126 _InitWindow(); 163 BMessage settings = _ReadSettings(); 164 _InitWindow(settings); 127 165 CenterOnScreen(); 128 166 Show(); 129 167 } … … 157 195 break; 158 196 159 197 case kShowMouse: 160 printf("kShowMouse\n");161 198 fIncludeMouse = (fShowMouse->Value() == B_CONTROL_ON); 162 199 break; 163 200 … … 174 211 } 175 212 176 213 case kTakeScreenshot: 214 fDelay = (atoi(fDelayControl->Text()) * 1000000) + 50000; 177 215 Hide(); 178 _TakeScreenshot( );216 _TakeScreenshot(fDelay); 179 217 _UpdatePreviewPanel(); 180 218 Show(); 181 219 _UpdateFilenameSelection(); … … 183 221 184 222 case kImageOutputFormat: 185 223 message->FindInt32("be:type", &fImageFileType); 186 fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String()); 224 fNameControl->SetText(_FindValidFileName( 225 fNameControl->Text()).String()); 187 226 _UpdateFilenameSelection(); 188 227 break; 189 228 … … 193 232 if (message->FindPointer("source", &source) == B_OK) 194 233 fLastSelectedPath = static_cast<BMenuItem*> (source); 195 234 196 fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String()); 235 fNameControl->SetText(_FindValidFileName( 236 fNameControl->Text()).String()); 197 237 _UpdateFilenameSelection(); 198 238 break; 199 239 } … … 202 242 { 203 243 if (!fOutputPathPanel) { 204 244 BMessenger target(this); 205 fOutputPathPanel = new BFilePanel(B_OPEN_PANEL, &target, 206 NULL,B_DIRECTORY_NODE, false, NULL, new DirectoryRefFilter());245 fOutputPathPanel = new BFilePanel(B_OPEN_PANEL, &target, NULL, 246 B_DIRECTORY_NODE, false, NULL, new DirectoryRefFilter()); 207 247 fOutputPathPanel->Window()->SetTitle(TR("Choose folder")); 208 fOutputPathPanel->SetButtonLabel(B_DEFAULT_BUTTON, TR("Select")); 248 fOutputPathPanel->SetButtonLabel(B_DEFAULT_BUTTON, 249 TR("Select")); 209 250 fOutputPathPanel->SetButtonLabel(B_CANCEL_BUTTON, TR("Cancel")); 210 251 } 211 252 fOutputPathPanel->Show(); … … 238 279 239 280 // fall through 240 281 case B_QUIT_REQUESTED: 282 _WriteSettings(); 241 283 be_app_messenger.SendMessage(B_QUIT_REQUESTED); 242 284 break; 243 285 … … 281 323 282 324 283 325 void 284 ScreenshotWindow::_InitWindow( )326 ScreenshotWindow::_InitWindow(const BMessage& settings) 285 327 { 286 328 BCardLayout* layout = new BCardLayout(); 287 329 SetLayout(layout); 288 330 289 331 _SetupFirstLayoutItem(layout); 290 _SetupSecondLayoutItem(layout );332 _SetupSecondLayoutItem(layout, settings); 291 333 292 334 if (!fShowConfigWindow) { 293 _TakeScreenshot( );335 _TakeScreenshot(0); 294 336 _UpdatePreviewPanel(); 295 337 layout->SetVisibleItem(1L); 296 338 fSaveScreenshot->MakeDefault(true); … … 316 358 317 359 BString delay; 318 360 delay << fDelay / 1000000; 319 fDelayControl = new BTextControl("", TR("Take screenshot after a delay of"),320 delay.String(), NULL);361 fDelayControl = new BTextControl("", 362 TR("Take screenshot after a delay of"), delay.String(), NULL); 321 363 _DisallowChar(fDelayControl->TextView()); 322 364 fDelayControl->TextView()->SetAlignment(B_ALIGN_RIGHT); 323 365 … … 335 377 BBox* divider = new BBox(B_FANCY_BORDER, NULL); 336 378 divider->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); 337 379 338 fBackToSave = new BButton("", TR("Back to saving"), new BMessage(kBackToSave)); 380 fBackToSave = new BButton("", TR("Back to saving"), 381 new BMessage(kBackToSave)); 339 382 fBackToSave->SetEnabled(false); 340 383 341 384 fTakeScreenshot = new BButton("", TR("Take screenshot"), … … 387 430 388 431 389 432 void 390 ScreenshotWindow::_SetupSecondLayoutItem(BCardLayout* layout) 433 ScreenshotWindow::_SetupSecondLayoutItem(BCardLayout* layout, 434 const BMessage& settings) 391 435 { 392 436 fPreview = new PreviewView(); 393 437 394 438 fNameControl = new BTextControl("", TR("Name:"), 395 439 TR_CMT("screenshot1", "!! Filename of first screenshot !!"), NULL); 396 440 397 BMessage settings(_ReadSettings());441 _SetupOutputPathMenu(new BMenu(TR("Please select")), settings); 398 442 399 _SetupOutputPathMenu(new BMenu(TR("Please select")), settings);400 443 BMenuField* menuField2 = new BMenuField(TR("Save in:"), fOutputPathMenu); 401 444 402 445 fNameControl->SetText(_FindValidFileName( 403 446 TR_CMT("screenshot1", "!! Filename of first screenshot !!")).String()); 404 447 405 _SetupTranslatorMenu(new BMenu(TR("Please select")) , settings);448 _SetupTranslatorMenu(new BMenu(TR("Please select"))); 406 449 BMenuField* menuField = new BMenuField(TR("Save as:"), fTranslatorMenu); 407 450 408 451 BBox* divider = new BBox(B_FANCY_BORDER, NULL); … … 454 497 455 498 456 499 void 457 ScreenshotWindow::_SetupTranslatorMenu(BMenu* translatorMenu, 458 const BMessage& settings) 500 ScreenshotWindow::_SetupTranslatorMenu(BMenu* translatorMenu) 459 501 { 460 502 fTranslatorMenu = translatorMenu; 461 503 … … 469 511 if (fTranslatorMenu->ItemAt(0)) 470 512 fTranslatorMenu->ItemAt(0)->SetMarked(true); 471 513 472 if (settings.FindInt32("be:type", &fImageFileType) != B_OK)473 fImageFileType = B_PNG_FORMAT;474 475 514 int32 imageFileType; 476 515 for (int32 i = 0; i < fTranslatorMenu->CountItems(); ++i) { 477 516 BMenuItem* item = fTranslatorMenu->ItemAt(i); … … 501 540 find_directory(B_USER_DIRECTORY, &path); 502 541 503 542 BString label(TR("Home folder")); 504 _AddItemToPathMenu(path.Path(), label, 0, (path.Path() == lastSelectedPath)); 543 _AddItemToPathMenu(path.Path(), label, 0, 544 (path.Path() == lastSelectedPath)); 505 545 506 546 path.Append("Desktop"); 507 547 label.SetTo(TR("Desktop")); 508 _AddItemToPathMenu(path.Path(), label, 0, (path.Path() == lastSelectedPath)); 548 _AddItemToPathMenu(path.Path(), label, 0, ( 549 path.Path() == lastSelectedPath)); 509 550 510 551 find_directory(B_BEOS_ETC_DIRECTORY, &path); 511 552 path.Append("artwork"); 512 553 513 554 label.SetTo(TR("Artwork folder")); 514 _AddItemToPathMenu(path.Path(), label, 2, (path.Path() == lastSelectedPath)); 555 _AddItemToPathMenu(path.Path(), label, 2, 556 (path.Path() == lastSelectedPath)); 515 557 516 558 int32 i = 0; 517 559 BString userPath; … … 559 601 { 560 602 float height = 150.0f; 561 603 562 float width = (fScreenshot->Bounds().Width() /563 fScreenshot->Bounds().Height()) * height;604 float width = (fScreenshot->Bounds().Width() 605 / fScreenshot->Bounds().Height()) * height; 564 606 565 607 // to prevent a preview way too wide 566 608 if (width > 400.0f) { 567 609 width = 400.0f; 568 height = (fScreenshot->Bounds().Height() /569 fScreenshot->Bounds().Width()) * width;610 height = (fScreenshot->Bounds().Height() 611 / fScreenshot->Bounds().Width()) * width; 570 612 } 571 613 572 614 fPreview->SetExplicitMinSize(BSize(width, height)); … … 591 633 { 592 634 fNameControl->MakeFocus(true); 593 635 fNameControl->TextView()->Select(0, 594 fNameControl->TextView()->TextLength() -595 fExtension.Length());636 fNameControl->TextView()->TextLength() 637 - fExtension.Length()); 596 638 fNameControl->TextView()->ScrollToSelection(); 597 639 } 598 640 … … 627 669 BMessage msgExtensions; 628 670 if (mimeType.GetFileExtensions(&msgExtensions) == B_OK) { 629 671 const char* extension; 630 if (msgExtensions.FindString("extensions", 0, &extension) == B_OK) { 672 if (msgExtensions.FindString("extensions", 0, 673 &extension) == B_OK) { 631 674 fExtension.SetTo(extension); 632 675 fExtension.Prepend("."); 633 676 } else … … 647 690 if (!BEntry(outputPath.Path()).Exists()) 648 691 return fileName; 649 692 650 if (baseName.FindFirst(TR_CMT("screenshot", "!! Basename of screenshot files. !!")) == 0) 651 baseName.SetTo(TR_CMT("screenshot", "!! Basename of screenshot files. !!" )); 693 if (baseName.FindFirst(TR_CMT("screenshot", 694 "!! Basename of screenshot files. !!")) == 0) 695 baseName.SetTo(TR_CMT("screenshot", 696 "!! Basename of screenshot files. !!")); 652 697 653 698 BEntry entry; 654 699 int32 index = 1; … … 684 729 BMessage 685 730 ScreenshotWindow::_ReadSettings() const 686 731 { 732 BMessage settings; 733 687 734 BPath settingsPath; 688 find_directory(B_USER_SETTINGS_DIRECTORY, &settingsPath); 689 settingsPath.Append("screenshot"); 735 if (find_directory(B_USER_SETTINGS_DIRECTORY, &settingsPath) != B_OK) 736 return settings; 737 settingsPath.Append("Screenshot_settings"); 690 738 691 BMessage settings;692 693 739 BFile file(settingsPath.Path(), B_READ_ONLY); 694 740 if (file.InitCheck() == B_OK) 695 741 settings.Unflatten(&file); … … 702 748 ScreenshotWindow::_WriteSettings() const 703 749 { 704 750 BMessage settings; 705 settings.AddInt32("be:type", fImageFileType);706 751 752 settings.AddInt32("type", fImageFileType); 753 settings.AddBool("includeBorder", fIncludeBorder); 754 settings.AddBool("includeMouse", fIncludeMouse); 755 settings.AddBool("grabActiveWindow", fGrabActiveWindow); 756 settings.AddInt64("delay", fDelay); 757 settings.AddString("outputFilename", fOutputFilename); 758 707 759 BString path; 708 760 int32 count = fOutputPathMenu->CountItems(); 709 761 if (count > 5) { … … 724 776 } 725 777 726 778 BPath settingsPath; 727 find_directory(B_USER_SETTINGS_DIRECTORY, &settingsPath); 728 settingsPath.Append("screenshot"); 779 if (find_directory(B_USER_SETTINGS_DIRECTORY, &settingsPath) != B_OK) 780 return; 781 settingsPath.Append("Screenshot_settings"); 729 782 730 BFile file(settingsPath.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); 783 BFile file(settingsPath.Path(), B_CREATE_FILE | B_ERASE_FILE 784 | B_WRITE_ONLY); 731 785 if (file.InitCheck() == B_OK) { 732 786 ssize_t size; 733 787 settings.Flatten(&file, &size); … … 736 790 737 791 738 792 void 739 ScreenshotWindow::_TakeScreenshot( )793 ScreenshotWindow::_TakeScreenshot(bigtime_t delay) 740 794 { 741 if (fDelayControl) 742 snooze((atoi(fDelayControl->Text()) * 1000000) + 50000); 743 else if (fDelay > 0) 744 snooze(fDelay); 795 if (delay > 0) 796 snooze(delay); 745 797 746 798 BRect frame; 747 799 delete fScreenshot; -
ScreenshotWindow.h
5 5 * Authors: 6 6 * Karsten Heimrich 7 7 * Fredrik Modéen 8 * Wim van der Meer, WPJvanderMeer@gmail.com 8 9 */ 9 10 #ifndef SCREENSHOT_WINDOW_H 10 11 #define SCREENSHOT_WINDOW_H … … 31 32 32 33 class ScreenshotWindow : public BWindow { 33 34 public: 34 ScreenshotWindow(bigtime_t delay = 0, 35 bool includeBorder = false, 36 bool includeMouse = false, 37 bool grabActiveWindow = false, 38 bool showConfigWindow = false, 39 bool saveScreenshotSilent = false, 35 ScreenshotWindow(); 36 ScreenshotWindow(bigtime_t delay, 37 bool includeBorder, 38 bool includeMouse, 39 bool grabActiveWindow, 40 bool showConfigWindow, 41 bool saveScreenshotSilent, 40 42 int32 imageFileType = B_PNG_FORMAT, 41 43 const char* outputFilename = NULL); 42 44 virtual ~ScreenshotWindow(); … … 44 46 virtual void MessageReceived(BMessage* message); 45 47 46 48 private: 47 void _InitWindow( );49 void _InitWindow(const BMessage& settings); 48 50 BPath _GetDirectory(); 49 51 void _SetupFirstLayoutItem(BCardLayout* layout); 50 void _SetupSecondLayoutItem(BCardLayout* layout); 52 void _SetupSecondLayoutItem(BCardLayout* layout, 53 const BMessage& settings); 51 54 void _DisallowChar(BTextView* textView); 52 void _SetupTranslatorMenu(BMenu* translatorMenu, 53 const BMessage& settings); 55 void _SetupTranslatorMenu(BMenu* translatorMenu); 54 56 void _SetupOutputPathMenu(BMenu* outputPathMenu, 55 57 const BMessage& settings); 56 58 void _AddItemToPathMenu(const char* path, … … 64 66 BMessage _ReadSettings() const; 65 67 void _WriteSettings() const; 66 68 67 void _TakeScreenshot( );69 void _TakeScreenshot(bigtime_t delay); 68 70 status_t _GetActiveWindowFrame(BRect* frame); 69 71 void _MakeTabSpaceTransparent(BRect* frame); 70 72