xref: /haiku/src/apps/haikudepot/ui/MainWindow.h (revision 8c78892580f132d10e624aef96f835df8d94bf19)
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 			std::vector<DepotInfoRef>
75 								_CreateSnapshotOfDepots();
76 
77 			void				_AddProcessCoordinator(
78 									ProcessCoordinator* item);
79 			void				_StopProcessCoordinators();
80 			void				_SpinUntilProcessCoordinatorComplete();
81 
82 			bool				_SelectedPackageHasWebAppRepositoryCode();
83 
84 			void				_BuildMenu(BMenuBar* menuBar);
85 			void				_BuildUserMenu(BMenuBar* menuBar);
86 
87 			const char*			_WindowFrameName() const;
88 			void				_RestoreNickname(const BMessage& settings);
89 			void				_RestoreWindowFrame(const BMessage& settings);
90 			void				_RestoreModelSettings(const BMessage& settings);
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				_PopulatePackageAsync(bool forcePopulate);
102 			void				_StartBulkLoad(bool force = false);
103 			void				_BulkLoadCompleteReceived(status_t errorStatus);
104 
105 			void				_NotifyWorkStatusClear();
106 			void				_HandleWorkStatusClear();
107 
108 			void				_NotifyWorkStatusChange(const BString& text,
109 									float progress);
110 			void				_HandleWorkStatusChangeMessageReceived(
111 									const BMessage* message);
112 
113 			void				_HandleChangePackageListViewMode();
114 
115 	static	status_t			_RefreshModelThreadWorker(void* arg);
116 	static	status_t			_PackageActionWorker(void* arg);
117 	static	status_t			_PopulatePackageWorker(void* arg);
118 	static	status_t			_PackagesToShowWorker(void* arg);
119 
120 			void				_OpenLoginWindow(
121 									const BMessage& onSuccessMessage);
122 			void				_StartUserVerify();
123 			void				_UpdateAuthorization();
124 			void				_UpdateAvailableRepositories();
125 			void				_RatePackage();
126 			void				_ShowScreenshot();
127 
128 			void				_ViewUserUsageConditions(
129 									UserUsageConditionsSelectionMode mode);
130 
131 			void				_HandleUserUsageConditionsNotLatest(
132 									const UserDetail& userDetail);
133 
134 private:
135 			FilterView*			fFilterView;
136 			TabView*			fListTabs;
137 			FeaturedPackagesView* fFeaturedPackagesView;
138 			PackageListView*	fPackageListView;
139 			PackageInfoView*	fPackageInfoView;
140 			BSplitView*			fSplitView;
141 			WorkStatusView*		fWorkStatusView;
142 
143 			ScreenshotWindow*	fScreenshotWindow;
144 
145 			BMenu*				fUserMenu;
146 			BMenu*				fRepositoryMenu;
147 			BMenuItem*			fLogInItem;
148 			BMenuItem*			fLogOutItem;
149 			BMenuItem*			fUsersUserUsageConditionsMenuItem;
150 
151 			BMenuItem*			fShowAvailablePackagesItem;
152 			BMenuItem*			fShowInstalledPackagesItem;
153 			BMenuItem*			fShowDevelopPackagesItem;
154 			BMenuItem*			fShowSourcePackagesItem;
155 
156 			BMenuItem*			fRefreshRepositoriesItem;
157 
158 			Model				fModel;
159 			ModelListenerRef	fModelListener;
160 
161 			std::queue<BReference<ProcessCoordinator> >
162 								fCoordinatorQueue;
163 			BReference<ProcessCoordinator>
164 								fCoordinator;
165 			BLocker				fCoordinatorLock;
166 			sem_id				fCoordinatorRunningSem;
167 
168 			bool				fSinglePackageMode;
169 
170 			thread_id			fPendingActionsWorker;
171 			PackageActionList	fPendingActions;
172 			BLocker				fPendingActionsLock;
173 			sem_id				fPendingActionsSem;
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