xref: /haiku/src/apps/haikudepot/ui/MainWindow.h (revision efafab643ce980e3f3c916795ed302599f6b4f66)
1 /*
2  * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2013, Rene Gollent <rene@gollent.com>.
4  * Copyright 2017, Julian Harnath <julian.harnath@rwth-aachen.de>.
5  * Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>.
6  * All rights reserved. Distributed under the terms of the MIT License.
7  */
8 #ifndef MAIN_WINDOW_H
9 #define MAIN_WINDOW_H
10 
11 #include <Window.h>
12 
13 #include "TabView.h"
14 #include "BulkLoadStateMachine.h"
15 #include "Model.h"
16 #include "PackageAction.h"
17 #include "PackageActionHandler.h"
18 #include "PackageInfoListener.h"
19 #include "HaikuDepotConstants.h"
20 
21 
22 class BCardLayout;
23 class BMenu;
24 class BMenuItem;
25 class BSplitView;
26 class FeaturedPackagesView;
27 class FilterView;
28 class PackageActionsView;
29 class PackageInfoView;
30 class PackageListView;
31 class ScreenshotWindow;
32 class WorkStatusView;
33 
34 
35 class MainWindow : public BWindow, private PackageInfoListener,
36 	private PackageActionHandler {
37 public:
38 								MainWindow(const BMessage& settings);
39 								MainWindow(const BMessage& settings,
40 									const PackageInfoRef& package);
41 	virtual						~MainWindow();
42 
43 	// BWindow interface
44 	virtual	bool				QuitRequested();
45 	virtual	void				MessageReceived(BMessage* message);
46 
47 			void				StoreSettings(BMessage& message) const;
48 
49 private:
50 	// PackageInfoListener
51 	virtual	void				PackageChanged(
52 									const PackageInfoEvent& event);
53 
54 private:
55 	// PackageActionHandler
56 	virtual	status_t			SchedulePackageActions(
57 									PackageActionList& list);
58 	virtual	Model*				GetModel();
59 
60 private:
61 			bool				_SelectedPackageHasWebAppRepositoryCode();
62 
63 			void				_BuildMenu(BMenuBar* menuBar);
64 			void				_BuildUserMenu(BMenuBar* menuBar);
65 
66 			void				_RestoreUserName(const BMessage& settings);
67 			const char*			_WindowFrameName() const;
68 			void				_RestoreWindowFrame(const BMessage& settings);
69 
70 			void				_InitWorkerThreads();
71 			void				_AdoptModel();
72 
73 			void				_AdoptPackage(const PackageInfoRef& package);
74 			void				_ClearPackage();
75 
76 			void				_RefreshRepositories(bool force);
77 			void				_RefreshPackageList(bool force);
78 
79 			void				_PopulatePackageAsync(bool forcePopulate);
80 			void				_StartRefreshWorker(bool force = false);
81 	static	status_t			_RefreshModelThreadWorker(void* arg);
82 	static	status_t			_PackageActionWorker(void* arg);
83 	static	status_t			_PopulatePackageWorker(void* arg);
84 	static	status_t			_PackagesToShowWorker(void* arg);
85 
86 			void				_NotifyUser(const char* title,
87 									const char* message);
88 
89 			void				_OpenLoginWindow(
90 									const BMessage& onSuccessMessage);
91 			void				_UpdateAuthorization();
92 			void				_UpdateAvailableRepositories();
93 			void				_RatePackage();
94 			void				_ShowScreenshot();
95 
96 private:
97 			FilterView*			fFilterView;
98 			TabView*			fListTabs;
99 			FeaturedPackagesView* fFeaturedPackagesView;
100 			PackageListView*	fPackageListView;
101 			PackageInfoView*	fPackageInfoView;
102 			BSplitView*			fSplitView;
103 			WorkStatusView*		fWorkStatusView;
104 
105 			ScreenshotWindow*	fScreenshotWindow;
106 
107 			BMenu*				fUserMenu;
108 			BMenu*				fRepositoryMenu;
109 			BMenuItem*			fLogInItem;
110 			BMenuItem*			fLogOutItem;
111 
112 			BMenuItem*			fShowAvailablePackagesItem;
113 			BMenuItem*			fShowInstalledPackagesItem;
114 			BMenuItem*			fShowDevelopPackagesItem;
115 			BMenuItem*			fShowSourcePackagesItem;
116 
117 			Model				fModel;
118 			ModelListenerRef	fModelListener;
119 			PackageList			fVisiblePackages;
120 			BulkLoadStateMachine
121 								fBulkLoadStateMachine;
122 
123 			bool				fTerminating;
124 			bool				fSinglePackageMode;
125 			thread_id			fModelWorker;
126 
127 			thread_id			fPendingActionsWorker;
128 			PackageActionList	fPendingActions;
129 			BLocker				fPendingActionsLock;
130 			sem_id				fPendingActionsSem;
131 
132 			thread_id			fPopulatePackageWorker;
133 			PackageInfoRef		fPackageToPopulate;
134 			bool				fForcePopulatePackage;
135 			BLocker				fPackageToPopulateLock;
136 			sem_id				fPackageToPopulateSem;
137 
138 			thread_id			fShowPackagesWorker;
139 			PackageList			fPackagesToShowList;
140 			int32				fPackagesToShowListID;
141 				// atomic, counted up whenever fPackagesToShowList is refilled
142 			BLocker				fPackagesToShowListLock;
143 			sem_id				fNewPackagesToShowSem;
144 			sem_id				fShowPackagesAcknowledgeSem;
145 };
146 
147 #endif // MAIN_WINDOW_H
148