xref: /haiku/src/apps/haikudepot/ui/MainWindow.h (revision c0936b5a0384bc6fe654d296ee54222a0f45d2b6)
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, 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 "BulkLoadStateMachine.h"
14 #include "Model.h"
15 #include "PackageAction.h"
16 #include "PackageActionHandler.h"
17 #include "PackageInfoListener.h"
18 
19 
20 class BCardLayout;
21 class BMenu;
22 class BMenuItem;
23 class BSplitView;
24 class FeaturedPackagesView;
25 class FilterView;
26 class PackageActionsView;
27 class PackageInfoView;
28 class PackageListView;
29 class ScreenshotWindow;
30 class WorkStatusView;
31 
32 
33 enum {
34 	MSG_MAIN_WINDOW_CLOSED		= 'mwcl',
35 	MSG_PACKAGE_SELECTED		= 'pkgs',
36 	MSG_PACKAGE_WORKER_BUSY		= 'pkwb',
37 	MSG_PACKAGE_WORKER_IDLE		= 'pkwi',
38 	MSG_ADD_VISIBLE_PACKAGES	= 'avpk',
39 	MSG_UPDATE_SELECTED_PACKAGE	= 'uspk',
40 };
41 
42 
43 class MainWindow : public BWindow, private PackageInfoListener,
44 	private PackageActionHandler {
45 public:
46 								MainWindow(const BMessage& settings);
47 								MainWindow(const BMessage& settings,
48 									const PackageInfoRef& package);
49 	virtual						~MainWindow();
50 
51 	// BWindow interface
52 	virtual	bool				QuitRequested();
53 	virtual	void				MessageReceived(BMessage* message);
54 
55 			void				StoreSettings(BMessage& message) const;
56 
57 private:
58 	// PackageInfoListener
59 	virtual	void				PackageChanged(
60 									const PackageInfoEvent& event);
61 
62 private:
63 	// PackageActionHandler
64 	virtual	status_t			SchedulePackageActions(
65 									PackageActionList& list);
66 	virtual	Model*				GetModel();
67 
68 private:
69 			void				_BuildMenu(BMenuBar* menuBar);
70 			void				_BuildUserMenu(BMenuBar* menuBar);
71 
72 			void				_RestoreUserName(const BMessage& settings);
73 			const char*			_WindowFrameName() const;
74 			void				_RestoreWindowFrame(const BMessage& settings);
75 
76 			void				_InitWorkerThreads();
77 			void				_AdoptModel();
78 
79 			void				_AdoptPackage(const PackageInfoRef& package);
80 			void				_ClearPackage();
81 
82 			void				_RefreshRepositories(bool force);
83 			void				_RefreshPackageList(bool force);
84 
85 			void				_StartRefreshWorker(bool force = false);
86 	static	status_t			_RefreshModelThreadWorker(void* arg);
87 	static	status_t			_PackageActionWorker(void* arg);
88 	static	status_t			_PopulatePackageWorker(void* arg);
89 	static	status_t			_PackagesToShowWorker(void* arg);
90 
91 			void				_NotifyUser(const char* title,
92 									const char* message);
93 
94 			void				_OpenLoginWindow(
95 									const BMessage& onSuccessMessage);
96 			void				_UpdateAuthorization();
97 			void				_RatePackage();
98 			void				_ShowScreenshot();
99 
100 private:
101 			FilterView*			fFilterView;
102 			BCardLayout*		fListLayout;
103 			FeaturedPackagesView* fFeaturedPackagesView;
104 			PackageListView*	fPackageListView;
105 			PackageInfoView*	fPackageInfoView;
106 			BSplitView*			fSplitView;
107 			WorkStatusView*		fWorkStatusView;
108 
109 			ScreenshotWindow*	fScreenshotWindow;
110 
111 			BMenu*				fUserMenu;
112 			BMenuItem*			fLogInItem;
113 			BMenuItem*			fLogOutItem;
114 
115 			BMenuItem*			fShowFeaturedPackagesItem;
116 			BMenuItem*			fShowAvailablePackagesItem;
117 			BMenuItem*			fShowInstalledPackagesItem;
118 			BMenuItem*			fShowDevelopPackagesItem;
119 			BMenuItem*			fShowSourcePackagesItem;
120 
121 			Model				fModel;
122 			ModelListenerRef	fModelListener;
123 			PackageList			fVisiblePackages;
124 			BulkLoadStateMachine
125 								fBulkLoadStateMachine;
126 
127 			bool				fTerminating;
128 			bool				fSinglePackageMode;
129 			thread_id			fModelWorker;
130 
131 			thread_id			fPendingActionsWorker;
132 			PackageActionList	fPendingActions;
133 			BLocker				fPendingActionsLock;
134 			sem_id				fPendingActionsSem;
135 
136 			thread_id			fPopulatePackageWorker;
137 			PackageInfoRef		fPackageToPopulate;
138 			BLocker				fPackageToPopulateLock;
139 			sem_id				fPackageToPopulateSem;
140 
141 			thread_id			fShowPackagesWorker;
142 			PackageList			fPackagesToShowList;
143 			int32				fPackagesToShowListID;
144 				// atomic, counted up whenever fPackagesToShowList is refilled
145 			BLocker				fPackagesToShowListLock;
146 			sem_id				fNewPackagesToShowSem;
147 			sem_id				fShowPackagesAcknowledgeSem;
148 };
149 
150 #endif // MAIN_WINDOW_H
151