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