1/* 2 * Copyright 2010 Wim van der Meer <WPJvanderMeer@gmail.com> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Wim van der Meer 7 */ 8 9 10#include "ScreenshotApp.h" 11 12#include <stdlib.h> 13 14#include <Bitmap.h> 15#include <Catalog.h> 16#include <Locale.h> 17#include <Roster.h> 18 19#include "ScreenshotWindow.h" 20#include "Utility.h" 21 22 23ScreenshotApp::ScreenshotApp() 24 : 25 BApplication("application/x-vnd.haiku-screenshot"), 26 fUtility(new Utility), 27 fSilent(false), 28 fClipboard(false) 29{ 30} 31 32 33ScreenshotApp::~ScreenshotApp() 34{ 35 delete fUtility; 36} 37 38 39void 40ScreenshotApp::MessageReceived(BMessage* message) 41{ 42 status_t status = B_OK; 43 switch (message->what) { 44 case SS_UTILITY_DATA: 45 { 46 BMessage bitmap; 47 status = message->FindMessage("wholeScreen", &bitmap); 48 if (status != B_OK) 49 break; 50 51 fUtility->wholeScreen = new BBitmap(&bitmap); 52 53 status = message->FindMessage("cursorBitmap", &bitmap); 54 if (status != B_OK) 55 break; 56 57 fUtility->cursorBitmap = new BBitmap(&bitmap); 58 59 status = message->FindMessage("cursorAreaBitmap", &bitmap); 60 if (status != B_OK) 61 break; 62 63 fUtility->cursorAreaBitmap = new BBitmap(&bitmap); 64 65 status = message->FindPoint("cursorPosition", 66 &fUtility->cursorPosition); 67 if (status != B_OK) 68 break; 69 70 status = message->FindRect("activeWindowFrame", 71 &fUtility->activeWindowFrame); 72 if (status != B_OK) 73 break; 74 75 status = message->FindRect("tabFrame", &fUtility->tabFrame); 76 if (status != B_OK) 77 break; 78 79 status = message->FindFloat("borderSize", &fUtility->borderSize); 80 if (status != B_OK) 81 break; 82 83 break; 84 } 85 86 default: 87 BApplication::MessageReceived(message); 88 break; 89 } 90 91 if (status != B_OK) 92 be_app->PostMessage(B_QUIT_REQUESTED); 93} 94 95 96void 97ScreenshotApp::ArgvReceived(int32 argc, char** argv) 98{ 99 for (int32 i = 0; i < argc; i++) { 100 if (strcmp(argv[i], "-s") == 0 101 || strcmp(argv[i], "--silent") == 0) 102 fSilent = true; 103 else if (strcmp(argv[i], "-c") == 0 104 || strcmp(argv[i], "--clipboard") == 0) 105 fClipboard = true; 106 } 107} 108 109 110void 111ScreenshotApp::ReadyToRun() 112{ 113 new ScreenshotWindow(*fUtility, fSilent, fClipboard); 114} 115 116 117int 118main() 119{ 120 ScreenshotApp app; 121 return app.Run(); 122} 123