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