* Applied a slightly edited patch by Christophe Huriaux, as part of ticket

#5724: this adds a settable filename for the silent invocation, thanks!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36312 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-04-15 18:25:51 +00:00
parent e3ce6e4be5
commit 362b036d1a
3 changed files with 35 additions and 17 deletions
+7 -4
View File
@@ -85,6 +85,7 @@ Screenshot::ArgvReceived(int32 argc, char** argv)
{ {
bigtime_t delay = 0; bigtime_t delay = 0;
const char* outputFilename = NULL;
bool includeBorder = false; bool includeBorder = false;
bool includeMouse = false; bool includeMouse = false;
bool grabActiveWindow = false; bool grabActiveWindow = false;
@@ -127,22 +128,24 @@ Screenshot::ArgvReceived(int32 argc, char** argv)
, argv[i]); , argv[i]);
exit(0); exit(0);
} }
} } else if (i == argc - 1)
outputFilename = argv[i];
} }
fArgvReceived = true; fArgvReceived = true;
new ScreenshotWindow(delay, includeBorder, includeMouse, grabActiveWindow, new ScreenshotWindow(delay, includeBorder, includeMouse, grabActiveWindow,
showConfigureWindow, saveScreenshotSilent, fImageFileType, showConfigureWindow, saveScreenshotSilent, fImageFileType,
fTranslator); fTranslator, outputFilename);
} }
void void
Screenshot::_ShowHelp() const Screenshot::_ShowHelp() const
{ {
printf("Screenshot [OPTION]... Creates a bitmap of the current screen\n\n"); printf("Screenshot [OPTIONS] [FILE] Creates a bitmap of the current screen\n\n");
printf("OPTION\n"); printf("FILE is the optional output path / filename used in silent mode. If FILE is not given, a default filename will be generated in the prefered directory.\n\n");
printf("OPTIONS\n");
printf(" -o, --options Show options window first\n"); printf(" -o, --options Show options window first\n");
printf(" -m, --mouse-pointer Include the mouse pointer\n"); printf(" -m, --mouse-pointer Include the mouse pointer\n");
printf(" -b, --border Include the window border\n"); printf(" -b, --border Include the window border\n");
+25 -12
View File
@@ -5,8 +5,10 @@
* Authors: * Authors:
* Karsten Heimrich * Karsten Heimrich
* Fredrik Modéen * Fredrik Modéen
* Christophe Huriaux
*/ */
#include "ScreenshotWindow.h" #include "ScreenshotWindow.h"
@@ -75,23 +77,29 @@ enum {
class DirectoryRefFilter : public BRefFilter { class DirectoryRefFilter : public BRefFilter {
public: public:
virtual ~DirectoryRefFilter() {} virtual ~DirectoryRefFilter()
bool Filter(const entry_ref* ref, BNode* node, {
struct stat_beos* stat, const char* filetype) }
{
return node->IsDirectory(); virtual bool Filter(const entry_ref* ref, BNode* node,
} struct stat_beos* stat, const char* filetype)
{
return node->IsDirectory();
}
}; };
// #pragma mark - ScreenshotWindow // #pragma mark - ScreenshotWindow
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "ScreenshotWindow" #define TR_CONTEXT "ScreenshotWindow"
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, int32 translator,
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 |
@@ -107,6 +115,7 @@ ScreenshotWindow::ScreenshotWindow(bigtime_t delay, bool includeBorder,
fGrabActiveWindow(grabActiveWindow), fGrabActiveWindow(grabActiveWindow),
fShowConfigWindow(showConfigWindow), fShowConfigWindow(showConfigWindow),
fSaveScreenshotSilent(saveScreenshotSilent), fSaveScreenshotSilent(saveScreenshotSilent),
fOutputFilename(outputFilename),
fExtension(""), fExtension(""),
fTranslator(translator), fTranslator(translator),
fImageFileType(imageFileType) fImageFileType(imageFileType)
@@ -805,10 +814,13 @@ ScreenshotWindow::_SaveScreenshot()
if (path == NULL) if (path == NULL)
return B_ERROR; return B_ERROR;
if (fSaveScreenshotSilent) if (fSaveScreenshotSilent) {
path.Append(_FindValidFileName( if (!fOutputFilename.Compare("")) {
TR_CMT("screenshot1", "!! Filename of first screenshot !!")).String()); path.Append(_FindValidFileName(TR_CMT("screenshot1",
else "!! Filename of first screenshot !!")).String());
} else
path.SetTo(fOutputFilename);
} else
path.Append(fNameControl->Text()); path.Append(fNameControl->Text());
BEntry entry; BEntry entry;
@@ -817,7 +829,8 @@ ScreenshotWindow::_SaveScreenshot()
if (!fSaveScreenshotSilent) { if (!fSaveScreenshotSilent) {
if (entry.Exists()) { if (entry.Exists()) {
BAlert* overwriteAlert = new BAlert(TR("overwrite"), BAlert* overwriteAlert = new BAlert(TR("overwrite"),
TR("This file already exists.\n Are you sure would you like to overwrite it?"), TR("This file already exists.\n Are you sure would you like "
"to overwrite it?"),
TR("Cancel"), TR("Overwrite"), NULL, B_WIDTH_AS_USUAL, TR("Cancel"), TR("Overwrite"), NULL, B_WIDTH_AS_USUAL,
B_EVEN_SPACING, B_WARNING_ALERT); B_EVEN_SPACING, B_WARNING_ALERT);
+3 -1
View File
@@ -37,7 +37,8 @@ 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); int32 translator = 8,
const char* outputFilename = NULL);
virtual ~ScreenshotWindow(); virtual ~ScreenshotWindow();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
@@ -93,6 +94,7 @@ private:
bool fGrabActiveWindow; bool fGrabActiveWindow;
bool fShowConfigWindow; bool fShowConfigWindow;
bool fSaveScreenshotSilent; bool fSaveScreenshotSilent;
BString fOutputFilename;
BString fExtension; BString fExtension;
int32 fTranslator; int32 fTranslator;