xref: /haiku/src/apps/haikudepot/ui/MainWindow.h (revision 3d4afef9cba2f328e238089d4609d00d4b1524f3)
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-2021, 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 <queue>
14 
15 #include "HaikuDepotConstants.h"
16 #include "Model.h"
17 #include "ProcessCoordinator.h"
18 #include "PackageInfoListener.h"
19 #include "TabView.h"
20 #include "UserDetail.h"
21 #include "UserDetailVerifierProcess.h"
22 
23 
24 class BCardLayout;
25 class BMenu;
26 class BMenuItem;
27 class BSplitView;
28 class FeaturedPackagesView;
29 class FilterView;
30 class PackageActionsView;
31 class PackageInfoView;
32 class PackageListView;
33 class ScreenshotWindow;
34 class ShuttingDownWindow;
35 class WorkStatusView;
36 
37 
38 class MainWindow : public BWindow, private PackageInfoListener,
39 	private ProcessCoordinatorConsumer, public ProcessCoordinatorListener,
40 	public UserDetailVerifierListener {
41 public:
42 								MainWindow(const BMessage& settings);
43 								MainWindow(const BMessage& settings,
44 									PackageInfoRef& package);
45 	virtual						~MainWindow();
46 
47 	// BWindow interface
48 	virtual	bool				QuitRequested();
49 	virtual	void				MessageReceived(BMessage* message);
50 
51 			void				StoreSettings(BMessage& message) const;
52 
53 	// ProcessCoordinatorConsumer
54 	virtual	void				Consume(ProcessCoordinator *item);
55 
56 	// ProcessCoordinatorListener
57 	virtual void				CoordinatorChanged(
58 									ProcessCoordinatorState& coordinatorState);
59 
60 	// UserDetailVerifierProcessListener
61 	virtual	void				UserCredentialsFailed();
62 	virtual void				UserUsageConditionsNotLatest(
63 									const UserDetail& userDetail);
64 private:
65 	// PackageInfoListener
66 	virtual	void				PackageChanged(
67 									const PackageInfoEvent& event);
68 
69 private:
70 			std::vector<DepotInfoRef>
71 								_CreateSnapshotOfDepots();
72 
73 			void				_AddProcessCoordinator(
74 									ProcessCoordinator* item);
75 			void				_StopProcessCoordinators();
76 			void				_SpinUntilProcessCoordinatorComplete();
77 
78 			bool				_SelectedPackageHasWebAppRepositoryCode();
79 
80 			void				_BuildMenu(BMenuBar* menuBar);
81 			void				_BuildUserMenu(BMenuBar* menuBar);
82 
83 			const char*			_WindowFrameName() const;
84 			void				_RestoreNickname(const BMessage& settings);
85 			void				_RestoreWindowFrame(const BMessage& settings);
86 			void				_RestoreModelSettings(const BMessage& settings);
87 
88 			void				_MaybePromptCanShareAnonymousUserData(
89 									const BMessage& settings);
90 			void				_PromptCanShareAnonymousUserData();
91 
92 			void				_InitWorkerThreads();
93 			void				_AdoptModelControls();
94 			void				_AdoptModel();
95 			void				_AddRemovePackageFromLists(
96 									const PackageInfoRef& package);
97 
98 			void				_AdoptPackage(const PackageInfoRef& package);
99 			void				_ClearPackage();
100 
101 			void				_IncrementViewCounter(
102 									const PackageInfoRef& package);
103 
104 			void				_PopulatePackageAsync(bool forcePopulate);
105 			void				_StartBulkLoad(bool force = false);
106 			void				_BulkLoadCompleteReceived(status_t errorStatus);
107 
108 			void				_NotifyWorkStatusClear();
109 			void				_HandleWorkStatusClear();
110 
111 			void				_NotifyWorkStatusChange(const BString& text,
112 									float progress);
113 			void				_HandleWorkStatusChangeMessageReceived(
114 									const BMessage* message);
115 
116 			void				_HandleExternalPackageUpdateMessageReceived(
117 									const BMessage* message);
118 
119 			void				_HandleChangePackageListViewMode();
120 
121 	static	status_t			_RefreshModelThreadWorker(void* arg);
122 	static	status_t			_PopulatePackageWorker(void* arg);
123 	static	status_t			_PackagesToShowWorker(void* arg);
124 
125 			void				_OpenLoginWindow(
126 									const BMessage& onSuccessMessage);
127 			void				_OpenSettingsWindow();
128 			void				_StartUserVerify();
129 			void				_UpdateAuthorization();
130 			void				_UpdateAvailableRepositories();
131 			void				_RatePackage();
132 			void				_ShowScreenshot();
133 
134 			void				_ViewUserUsageConditions(
135 									UserUsageConditionsSelectionMode mode);
136 
137 			void				_HandleUserUsageConditionsNotLatest(
138 									const UserDetail& userDetail);
139 
140 private:
141 			FilterView*			fFilterView;
142 			TabView*			fListTabs;
143 			FeaturedPackagesView* fFeaturedPackagesView;
144 			PackageListView*	fPackageListView;
145 			PackageInfoView*	fPackageInfoView;
146 			BSplitView*			fSplitView;
147 			WorkStatusView*		fWorkStatusView;
148 
149 			ScreenshotWindow*	fScreenshotWindow;
150 			ShuttingDownWindow*	fShuttingDownWindow;
151 
152 			BMenu*				fUserMenu;
153 			BMenu*				fRepositoryMenu;
154 			BMenuItem*			fLogInItem;
155 			BMenuItem*			fLogOutItem;
156 			BMenuItem*			fUsersUserUsageConditionsMenuItem;
157 
158 			BMenuItem*			fShowAvailablePackagesItem;
159 			BMenuItem*			fShowInstalledPackagesItem;
160 			BMenuItem*			fShowDevelopPackagesItem;
161 			BMenuItem*			fShowSourcePackagesItem;
162 
163 			BMenuItem*			fRefreshRepositoriesItem;
164 
165 			Model				fModel;
166 			ModelListenerRef	fModelListener;
167 
168 			std::queue<BReference<ProcessCoordinator> >
169 								fCoordinatorQueue;
170 			BReference<ProcessCoordinator>
171 								fCoordinator;
172 			BLocker				fCoordinatorLock;
173 			sem_id				fCoordinatorRunningSem;
174 			bool				fShouldCloseWhenNoProcessesToCoordinate;
175 
176 			bool				fSinglePackageMode;
177 
178 			thread_id			fPopulatePackageWorker;
179 			PackageInfoRef		fPackageToPopulate;
180 			bool				fForcePopulatePackage;
181 			BLocker				fPackageToPopulateLock;
182 			sem_id				fPackageToPopulateSem;
183 };
184 
185 #endif // MAIN_WINDOW_H
186