Author: wim Date: 2010-06-25 15:12:15 +0200 (Fri, 25 Jun 2010) New Revision: 37252 Changeset: http://dev.haiku-os.org/changeset/37252/haiku Modified: haiku/trunk/src/apps/screenshot/Jamfile haiku/trunk/src/apps/screenshot/Screenshot.cpp haiku/trunk/src/apps/screenshot/Screenshot.h haiku/trunk/src/apps/screenshot/ScreenshotApp.cpp haiku/trunk/src/apps/screenshot/ScreenshotApp.h haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp haiku/trunk/src/apps/screenshot/ScreenshotWindow.h haiku/trunk/src/apps/screenshot/Utility.cpp haiku/trunk/src/kits/interface/Window.cpp Log: * Modified PtrScr key behaviour: - No modifiers: take a screenshot with zero delay and launch the GUI - Shift-PrtScr: Silent screenshot using the saved GUI settings - Ctrl-PrtScr: Take a screenshot using the saved GUI settings and copy the screenshot to the system clipboard * A few locale related changes (I am not sure how this works when a class is shared between two applications, I hope I got everything right) Modified: haiku/trunk/src/apps/screenshot/Jamfile =================================================================== --- haiku/trunk/src/apps/screenshot/Jamfile 2010-06-25 08:35:02 UTC (rev 37251) +++ haiku/trunk/src/apps/screenshot/Jamfile 2010-06-25 13:12:15 UTC (rev 37252) @@ -24,3 +24,9 @@ : be locale translation $(TARGET_LIBSUPC++) : Screenshot.rdef ; + +DoCatalogs screenshot : + x-vnd.haiku-screenshot-cli + : + Utility.cpp +; Modified: haiku/trunk/src/apps/screenshot/Screenshot.cpp =================================================================== --- haiku/trunk/src/apps/screenshot/Screenshot.cpp 2010-06-25 08:35:02 UTC (rev 37251) +++ haiku/trunk/src/apps/screenshot/Screenshot.cpp 2010-06-25 13:12:15 UTC (rev 37252) @@ -19,6 +19,7 @@ #include <AppDefs.h> #include <Bitmap.h> +#include <Catalog.h> #include <Locale.h> #include <Roster.h> #include <Screen.h> @@ -29,6 +30,10 @@ #include "Utility.h" +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Screenshot" + + Screenshot::Screenshot() : BApplication("application/x-vnd.haiku-screenshot-cli"), @@ -56,7 +61,6 @@ bool saveScreenshotSilent = false; bool copyToClipboard = false; uint32 imageFileType = B_PNG_FORMAT; - for (int32 i = 0; i < argc; i++) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) _ShowHelp(); @@ -98,8 +102,7 @@ outputFilename = argv[i]; } - if (argc > 1) - _New(delay); + _New(delay); if (copyToClipboard || saveScreenshotSilent) { fLaunchGui = false; @@ -125,35 +128,32 @@ Screenshot::ReadyToRun() { if (fLaunchGui) { - // Launch the GUI application - if (fUtility->wholeScreen == NULL) { - // No command line parameters were given - be_roster->Launch("application/x-vnd.haiku-screenshot"); - } else { - // Send the utility data and the command line settings to the GUI - BMessage message; - message.what = SS_UTILITY_DATA; + // Get a screenshot if we don't have one + if (fUtility->wholeScreen == NULL) + _New(0); - BMessage* bitmap = new BMessage(); - fUtility->wholeScreen->Archive(bitmap); - message.AddMessage("wholeScreen", bitmap); + // Send the screenshot data to the GUI + BMessage message; + message.what = SS_UTILITY_DATA; - bitmap = new BMessage(); - fUtility->cursorBitmap->Archive(bitmap); - message.AddMessage("cursorBitmap", bitmap); + BMessage* bitmap = new BMessage(); + fUtility->wholeScreen->Archive(bitmap); + message.AddMessage("wholeScreen", bitmap); - bitmap = new BMessage(); - fUtility->cursorAreaBitmap->Archive(bitmap); - message.AddMessage("cursorAreaBitmap", bitmap); + bitmap = new BMessage(); + fUtility->cursorBitmap->Archive(bitmap); + message.AddMessage("cursorBitmap", bitmap); - message.AddPoint("cursorPosition", fUtility->cursorPosition); - message.AddRect("activeWindowFrame", fUtility->activeWindowFrame); - message.AddRect("tabFrame", fUtility->tabFrame); - message.AddFloat("borderSize", fUtility->borderSize); + bitmap = new BMessage(); + fUtility->cursorAreaBitmap->Archive(bitmap); + message.AddMessage("cursorAreaBitmap", bitmap); - be_roster->Launch("application/x-vnd.haiku-screenshot", - &message); - } + message.AddPoint("cursorPosition", fUtility->cursorPosition); + message.AddRect("activeWindowFrame", fUtility->activeWindowFrame); + message.AddRect("tabFrame", fUtility->tabFrame); + message.AddFloat("borderSize", fUtility->borderSize); + + be_roster->Launch("application/x-vnd.haiku-screenshot", &message); } be_app->PostMessage(B_QUIT_REQUESTED); Modified: haiku/trunk/src/apps/screenshot/Screenshot.h =================================================================== --- haiku/trunk/src/apps/screenshot/Screenshot.h 2010-06-25 08:35:02 UTC (rev 37251) +++ haiku/trunk/src/apps/screenshot/Screenshot.h 2010-06-25 13:12:15 UTC (rev 37252) @@ -27,7 +27,7 @@ void _New(bigtime_t delay); status_t _GetActiveWindowFrame(); int32 _GetImageType(const char* name) const; - + Utility* fUtility; BCatalog fCatalog; Modified: haiku/trunk/src/apps/screenshot/ScreenshotApp.cpp =================================================================== --- haiku/trunk/src/apps/screenshot/ScreenshotApp.cpp 2010-06-25 08:35:02 UTC (rev 37251) +++ haiku/trunk/src/apps/screenshot/ScreenshotApp.cpp 2010-06-25 13:12:15 UTC (rev 37252) @@ -12,6 +12,7 @@ #include <stdlib.h> #include <Bitmap.h> +#include <Catalog.h> #include <Locale.h> #include <Roster.h> @@ -22,7 +23,9 @@ ScreenshotApp::ScreenshotApp() : BApplication("application/x-vnd.haiku-screenshot"), - fUtility(new Utility) + fUtility(new Utility), + fSilent(false), + fClipboard(false) { be_locale->GetAppCatalog(&fCatalog); } @@ -92,9 +95,23 @@ void +ScreenshotApp::ArgvReceived(int32 argc, char** argv) +{ + for (int32 i = 0; i < argc; i++) { + if (strcmp(argv[i], "-s") == 0 + || strcmp(argv[i], "--silent") == 0) + fSilent = true; + else if (strcmp(argv[i], "-c") == 0 + || strcmp(argv[i], "--clipboard") == 0) + fClipboard = true; + } +} + + +void ScreenshotApp::ReadyToRun() { - new ScreenshotWindow(*fUtility); + new ScreenshotWindow(*fUtility, fSilent, fClipboard); } Modified: haiku/trunk/src/apps/screenshot/ScreenshotApp.h =================================================================== --- haiku/trunk/src/apps/screenshot/ScreenshotApp.h 2010-06-25 08:35:02 UTC (rev 37251) +++ haiku/trunk/src/apps/screenshot/ScreenshotApp.h 2010-06-25 13:12:15 UTC (rev 37252) @@ -22,11 +22,14 @@ ~ScreenshotApp(); void MessageReceived(BMessage* message); + void ArgvReceived(int32 argc, char** argv); void ReadyToRun(); private: BCatalog fCatalog; Utility* fUtility; + bool fSilent; + bool fClipboard; }; Modified: haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp =================================================================== --- haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp 2010-06-25 08:35:02 UTC (rev 37251) +++ haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp 2010-06-25 13:12:15 UTC (rev 37252) @@ -27,6 +27,7 @@ #include <FindDirectory.h> #include <GridLayoutBuilder.h> #include <GroupLayoutBuilder.h> +#include <Locale.h> #include <Menu.h> #include <MenuField.h> #include <MenuItem.h> @@ -71,7 +72,8 @@ #define B_TRANSLATE_CONTEXT "ScreenshotWindow" -ScreenshotWindow::ScreenshotWindow(const Utility& utility) +ScreenshotWindow::ScreenshotWindow(const Utility& utility, bool silent, + bool clipboard) : BWindow(BRect(0, 0, 200.0, 100.0), B_TRANSLATE("Screenshot"), B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AVOID_FRONT @@ -90,17 +92,22 @@ fExtension(""), fImageFileType(B_PNG_FORMAT) { + // _ReadSettings() needs a valid fOutputPathMenu + fOutputPathMenu = new BMenu(B_TRANSLATE("Please select")); + _ReadSettings(); + + // _NewScreenshot() needs a valid fNameControl + BString name(B_TRANSLATE(fUtility.sDefaultFileNameBase)); + name << 1; + name = _FindValidFileName(name.String()); + fNameControl = new BTextControl("", B_TRANSLATE("Name:"), name, NULL); + // Check if fUtility contains valid data if (fUtility.wholeScreen == NULL) { - // New screenshot using zero delay - _NewScreenshot(); + _NewScreenshot(silent, clipboard); return; } - // _ReadSettings() needs a valid fOutputPathMenu - fOutputPathMenu = new BMenu(B_TRANSLATE("Please select")); - _ReadSettings(); - fScreenshot = fUtility.MakeScreenshot(fIncludeCursor, fGrabActiveWindow, fIncludeBorder); @@ -130,11 +137,6 @@ BStringView* seconds = new BStringView("", B_TRANSLATE("seconds")); seconds->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); - BString name(fUtility.sDefaultFileNameBase); - name << 1; - name = _FindValidFileName(name.String()); - fNameControl = new BTextControl("", B_TRANSLATE("Name:"), name, NULL); - BMenuField* menuField2 = new BMenuField(B_TRANSLATE("Save in:"), fOutputPathMenu); @@ -318,21 +320,49 @@ void -ScreenshotWindow::_NewScreenshot() +ScreenshotWindow::_NewScreenshot(bool silent, bool clipboard) { + BMessage message(B_ARGV_RECEIVED); int32 argc = 3; - char* argv[3]; - argv[0] = "Screenshot"; - argv[1] = "--delay"; - BString delay; delay << fDelay / 1000000; - int32 charCount = delay.Length(); - argv[2] = (char*)malloc(charCount + 1); - delay.CopyInto(argv[2], 0, charCount); - argv[2][charCount] = '\0'; + message.AddString("argv", "screenshot"); + message.AddString("argv", "--delay"); + message.AddString("argv", delay); + + if (silent || clipboard) { + if (silent) { + argc++; + message.AddString("argv", "--silent"); + } + if (clipboard) { + argc++; + message.AddString("argv", "--clipboard"); + } + if (fIncludeBorder) { + argc++; + message.AddString("argv", "--border"); + } + if (fIncludeCursor) { + argc++; + message.AddString("argv", "--mouse-pointer"); + } + if (fGrabActiveWindow) { + argc++; + message.AddString("argv", "--window"); + } + if (fLastSelectedPath) { + BPath path(_GetDirectory()); + if (path != NULL) { + path.Append(fNameControl->Text()); + argc++; + message.AddString("argv", path.Path()); + } + } + } + message.AddInt32("argc", argc); - be_roster->Launch("application/x-vnd.haiku-screenshot-cli", argc, argv); + be_roster->Launch("application/x-vnd.haiku-screenshot-cli", &message); be_app->PostMessage(B_QUIT_REQUESTED); } @@ -538,7 +568,7 @@ if (!BEntry(outputPath.Path()).Exists()) return fileName; - if (baseName.FindFirst(fUtility.sDefaultFileNameBase) == 0) + if (baseName.FindFirst(B_TRANSLATE(fUtility.sDefaultFileNameBase)) == 0) baseName.SetTo(fUtility.sDefaultFileNameBase); BEntry entry; Modified: haiku/trunk/src/apps/screenshot/ScreenshotWindow.h =================================================================== --- haiku/trunk/src/apps/screenshot/ScreenshotWindow.h 2010-06-25 08:35:02 UTC (rev 37251) +++ haiku/trunk/src/apps/screenshot/ScreenshotWindow.h 2010-06-25 13:12:15 UTC (rev 37252) @@ -32,14 +32,16 @@ class ScreenshotWindow : public BWindow { public: - ScreenshotWindow(const Utility& utility); + ScreenshotWindow(const Utility& utility, + bool silent, bool clipboard); ~ScreenshotWindow(); void MessageReceived(BMessage* message); void Quit(); private: - void _NewScreenshot(); + void _NewScreenshot(bool silent = false, + bool clipboard = false); void _UpdatePreviewPanel(); void _DisallowChar(BTextView* textView); void _SetupOutputPathMenu(const BMessage& settings); Modified: haiku/trunk/src/apps/screenshot/Utility.cpp =================================================================== --- haiku/trunk/src/apps/screenshot/Utility.cpp 2010-06-25 08:35:02 UTC (rev 37251) +++ haiku/trunk/src/apps/screenshot/Utility.cpp 2010-06-25 13:12:15 UTC (rev 37252) @@ -20,6 +20,7 @@ #include <Entry.h> #include <File.h> #include <FindDirectory.h> +#include <Locale.h> #include <Looper.h> #include <MimeType.h> #include <NodeInfo.h> @@ -96,7 +97,7 @@ BString extension = GetFileNameExtension(imageType); do { fileNameString.SetTo(homePath.Path()); - fileNameString << "/" << sDefaultFileNameBase << index++ + fileNameString << "/" << B_TRANSLATE(sDefaultFileNameBase) << index++ << extension; entry.SetTo(fileNameString.String()); } while (entry.Exists()); @@ -204,7 +205,7 @@ const char* Utility::_GetMimeString(uint32 imageType) const { - char dummy[] = ""; + const char *dummy = ""; translator_id* translators = NULL; int32 numTranslators = 0; BTranslatorRoster* roster = BTranslatorRoster::Default(); Modified: haiku/trunk/src/kits/interface/Window.cpp =================================================================== --- haiku/trunk/src/kits/interface/Window.cpp 2010-06-25 08:35:02 UTC (rev 37251) +++ haiku/trunk/src/kits/interface/Window.cpp 2010-06-25 13:12:15 UTC (rev 37252) @@ -3608,17 +3608,30 @@ return true; } + // PrtScr key takes a screenshot if (key == B_FUNCTION_KEY && rawKey == B_PRINT_KEY) { - BMessage message(B_REFS_RECEIVED); - message.AddBool("silent", true); + // With no modifier keys the best way to get a screenshot is by + // calling the screenshot CLI + if (modifiers == 0) { + be_roster->Launch("application/x-vnd.haiku-screenshot-cli"); + return true; + } - if ((modifiers & B_CONTROL_KEY) != 0) - message.AddBool("window", true); - - if ((modifiers & B_SHIFT_KEY) != 0 || (modifiers & B_OPTION_KEY) != 0) - message.ReplaceBool("silent", false); - - be_roster->Launch("application/x-vnd.haiku-screenshot-cli", &message); + // Prepare a message based on the modifier keys pressed and launch the + // screenshot GUI + BMessage message(B_ARGV_RECEIVED); + int32 argc = 1; + message.AddString("argv", "Screenshot"); + if ((modifiers & B_CONTROL_KEY) != 0) { + argc++; + message.AddString("argv", "--clipboard"); + } + if ((modifiers & B_SHIFT_KEY) != 0) { + argc++; + message.AddString("argv", "--silent"); + } + message.AddInt32("argc", argc); + be_roster->Launch("application/x-vnd.haiku-screenshot", &message); return true; }