1 /* 2 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2021-2024, Andrew Lindesay <apl@lindesay.co.nz>. 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 #ifndef SCREENSHOT_WINDOW_H 7 #define SCREENSHOT_WINDOW_H 8 9 #include <Locker.h> 10 #include <Messenger.h> 11 #include <ToolBar.h> 12 #include <Window.h> 13 14 #include "PackageInfo.h" 15 16 17 class BarberPole; 18 class BitmapView; 19 class BStringView; 20 class Model; 21 22 23 enum { 24 MSG_NEXT_SCREENSHOT = 'nscr', 25 MSG_PREVIOUS_SCREENSHOT = 'pscr', 26 MSG_DOWNLOAD_START = 'dlst', 27 MSG_DOWNLOAD_STOP = 'dlsp', 28 }; 29 30 31 class ScreenshotWindow : public BWindow { 32 public: 33 ScreenshotWindow(BWindow* parent, BRect frame, Model* model); 34 virtual ~ScreenshotWindow(); 35 36 virtual bool QuitRequested(); 37 38 virtual void MessageReceived(BMessage* message); 39 40 void SetOnCloseMessage( 41 const BMessenger& messenger, 42 const BMessage& message); 43 44 void SetPackage(const PackageInfoRef& package); 45 46 static void CleanupIcons(); 47 48 private: 49 void _DownloadScreenshot(); 50 51 void _SetWorkerThread(thread_id thread); 52 53 static int32 _DownloadThreadEntry(void* data); 54 void _DownloadThread(); 55 56 BSize _MaxWidthAndHeightOfAllScreenshots(); 57 void _ResizeToFitAndCenter(); 58 void _UpdateToolBar(); 59 60 private: 61 enum { 62 kProgressIndicatorDelay = 200000 // us 63 }; 64 65 private: 66 BMessenger fOnCloseTarget; 67 BMessage fOnCloseMessage; 68 69 BToolBar* fToolBar; 70 BarberPole* fBarberPole; 71 bool fBarberPoleShown; 72 BStringView* fIndexView; 73 74 BitmapRef fScreenshot; 75 BitmapView* fScreenshotView; 76 77 int32 fCurrentScreenshotIndex; // atomic 78 79 PackageInfoRef fPackage; 80 bool fDownloadPending; 81 82 BLocker fLock; 83 thread_id fWorkerThread; 84 85 Model* fModel; 86 }; 87 88 89 #endif // SCREENSHOT_WINDOW_H 90