xref: /haiku/src/apps/haikudepot/ui/MainWindow.h (revision 529cd177b573aaba391c8adc9c9f5ad76a14bf81)
1 /*
2  * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2013, Rene Gollent <rene@gollent.com>.
4  * All rights reserved. Distributed under the terms of the MIT License.
5  */
6 #ifndef MAIN_WINDOW_H
7 #define MAIN_WINDOW_H
8 
9 #include <Window.h>
10 
11 #include "Model.h"
12 #include "PackageAction.h"
13 #include "PackageActionHandler.h"
14 #include "PackageInfoListener.h"
15 
16 
17 class BCardLayout;
18 class BMenu;
19 class BMenuItem;
20 class BSplitView;
21 class FeaturedPackagesView;
22 class FilterView;
23 class PackageActionsView;
24 class PackageInfoView;
25 class PackageListView;
26 class ScreenshotWindow;
27 
28 
29 enum {
30 	MSG_MAIN_WINDOW_CLOSED		= 'mwcl',
31 	MSG_PACKAGE_SELECTED		= 'pkgs',
32 };
33 
34 
35 class MainWindow : public BWindow, private PackageInfoListener,
36 	private PackageActionHandler {
37 public:
38 								MainWindow(BRect frame,
39 									const BMessage& settings);
40 								MainWindow(BRect frame,
41 									const BMessage& settings,
42 									const PackageInfoRef& package);
43 	virtual						~MainWindow();
44 
45 	// BWindow interface
46 	virtual	bool				QuitRequested();
47 	virtual	void				MessageReceived(BMessage* message);
48 
49 			void				StoreSettings(BMessage& message) const;
50 
51 private:
52 	// PackageInfoListener
53 	virtual	void				PackageChanged(
54 									const PackageInfoEvent& event);
55 
56 private:
57 	// PackageActionHandler
58 	virtual	status_t			SchedulePackageActions(
59 									PackageActionList& list);
60 	virtual	Model*				GetModel();
61 
62 private:
63 			void				_BuildMenu(BMenuBar* menuBar);
64 			void				_BuildUserMenu(BMenuBar* menuBar);
65 
66 			void				_InitWorkerThreads();
67 			void				_AdoptModel();
68 			bool				_IsProminentPackage(
69 									const PackageInfoRef& package) const;
70 
71 			void				_AdoptPackage(const PackageInfoRef& package);
72 			void				_ClearPackage();
73 
74 			void				_RefreshRepositories(bool force);
75 			void				_RefreshPackageList();
76 
77 			void				_StartRefreshWorker(bool force = false);
78 	static	status_t			_RefreshModelThreadWorker(void* arg);
79 	static	status_t			_PackageActionWorker(void* arg);
80 	static	status_t			_PopulatePackageWorker(void* arg);
81 
82 			void				_NotifyUser(const char* title,
83 									const char* message);
84 
85 			void				_OpenLoginWindow(
86 									const BMessage& onSuccessMessage);
87 			void				_UpdateAuthorization();
88 			void				_RatePackage();
89 			void				_ShowScreenshot();
90 
91 private:
92 			FilterView*			fFilterView;
93 			BCardLayout*		fListLayout;
94 			FeaturedPackagesView* fFeaturedPackagesView;
95 			PackageListView*	fPackageListView;
96 			PackageInfoView*	fPackageInfoView;
97 			BSplitView*			fSplitView;
98 
99 			ScreenshotWindow*	fScreenshotWindow;
100 
101 			BMenu*				fUserMenu;
102 			BMenuItem*			fLogInItem;
103 			BMenuItem*			fLogOutItem;
104 
105 			BMenuItem*			fShowAvailablePackagesItem;
106 			BMenuItem*			fShowInstalledPackagesItem;
107 			BMenuItem*			fShowDevelopPackagesItem;
108 			BMenuItem*			fShowSourcePackagesItem;
109 
110 			Model				fModel;
111 			ModelListenerRef	fModelListener;
112 			PackageList			fVisiblePackages;
113 
114 			bool				fTerminating;
115 			bool				fSinglePackageMode;
116 			thread_id			fModelWorker;
117 
118 			thread_id			fPendingActionsWorker;
119 			PackageActionList	fPendingActions;
120 			BLocker				fPendingActionsLock;
121 			sem_id				fPendingActionsSem;
122 
123 			thread_id			fPopulatePackageWorker;
124 			PackageInfoRef		fPackageToPopulate;
125 			BLocker				fPackageToPopulateLock;
126 			sem_id				fPackageToPopulateSem;
127 };
128 
129 #endif // MAIN_WINDOW_H
130