xref: /haiku/src/apps/haikudepot/ui/ScreenshotWindow.h (revision 909af08f4328301fbdef1ffb41f566c3b5bec0c7)
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 "BitmapHolder.h"
15 #include "PackageInfo.h"
16 
17 
18 class BarberPole;
19 class BitmapView;
20 class BStringView;
21 class Model;
22 
23 
24 enum {
25 	MSG_NEXT_SCREENSHOT     = 'nscr',
26 	MSG_PREVIOUS_SCREENSHOT = 'pscr',
27 	MSG_DOWNLOAD_START      = 'dlst',
28 	MSG_DOWNLOAD_STOP       = 'dlsp',
29 };
30 
31 
32 class ScreenshotWindow : public BWindow {
33 public:
34 								ScreenshotWindow(BWindow* parent, BRect frame, Model* model);
35 	virtual						~ScreenshotWindow();
36 
37 	virtual bool				QuitRequested();
38 
39 	virtual	void				MessageReceived(BMessage* message);
40 
41 			void				SetOnCloseMessage(
42 									const BMessenger& messenger,
43 									const BMessage& message);
44 
45 			void				SetPackage(const PackageInfoRef& package);
46 
47 private:
48 			void				_DownloadScreenshot();
49 
50 			void				_SetWorkerThread(thread_id thread);
51 
52 	static	int32				_DownloadThreadEntry(void* data);
53 			void				_DownloadThread();
54 
55 			BSize				_MaxWidthAndHeightOfAllScreenshots();
56 			void				_ResizeToFitAndCenter();
57 			void				_UpdateToolBar();
58 
59 private:
60 	enum {
61 		kProgressIndicatorDelay = 200000 // us
62 	};
63 
64 private:
65 			BMessenger			fOnCloseTarget;
66 			BMessage			fOnCloseMessage;
67 
68 			BToolBar*			fToolBar;
69 			BarberPole*			fBarberPole;
70 			bool				fBarberPoleShown;
71 			BStringView*		fIndexView;
72 
73 			BitmapHolderRef		fScreenshot;
74 			BitmapView*			fScreenshotView;
75 
76 			int32				fCurrentScreenshotIndex; // atomic
77 
78 			PackageInfoRef		fPackage;
79 			bool				fDownloadPending;
80 
81 			BLocker				fLock;
82 			thread_id			fWorkerThread;
83 
84 			Model*				fModel;
85 };
86 
87 
88 #endif // SCREENSHOT_WINDOW_H
89