xref: /haiku/src/apps/haikudepot/ui/MainWindow.h (revision e661df29804f2703a65e23f5789c3c87c0915298)
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 
69 			void				_AdoptPackage(const PackageInfoRef& package);
70 			void				_ClearPackage();
71 
72 			void				_RefreshRepositories(bool force);
73 			void				_RefreshPackageList(bool force);
74 
75 			void				_StartRefreshWorker(bool force = false);
76 	static	status_t			_RefreshModelThreadWorker(void* arg);
77 	static	status_t			_PackageActionWorker(void* arg);
78 	static	status_t			_PopulatePackageWorker(void* arg);
79 
80 			void				_NotifyUser(const char* title,
81 									const char* message);
82 
83 			void				_OpenLoginWindow(
84 									const BMessage& onSuccessMessage);
85 			void				_UpdateAuthorization();
86 			void				_RatePackage();
87 			void				_ShowScreenshot();
88 
89 private:
90 			FilterView*			fFilterView;
91 			BCardLayout*		fListLayout;
92 			FeaturedPackagesView* fFeaturedPackagesView;
93 			PackageListView*	fPackageListView;
94 			PackageInfoView*	fPackageInfoView;
95 			BSplitView*			fSplitView;
96 
97 			ScreenshotWindow*	fScreenshotWindow;
98 
99 			BMenu*				fUserMenu;
100 			BMenuItem*			fLogInItem;
101 			BMenuItem*			fLogOutItem;
102 
103 			BMenuItem*			fShowFeaturedPackagesItem;
104 			BMenuItem*			fShowAvailablePackagesItem;
105 			BMenuItem*			fShowInstalledPackagesItem;
106 			BMenuItem*			fShowDevelopPackagesItem;
107 			BMenuItem*			fShowSourcePackagesItem;
108 
109 			Model				fModel;
110 			ModelListenerRef	fModelListener;
111 			PackageList			fVisiblePackages;
112 
113 			bool				fTerminating;
114 			bool				fSinglePackageMode;
115 			thread_id			fModelWorker;
116 
117 			thread_id			fPendingActionsWorker;
118 			PackageActionList	fPendingActions;
119 			BLocker				fPendingActionsLock;
120 			sem_id				fPendingActionsSem;
121 
122 			thread_id			fPopulatePackageWorker;
123 			PackageInfoRef		fPackageToPopulate;
124 			BLocker				fPackageToPopulateLock;
125 			sem_id				fPackageToPopulateSem;
126 };
127 
128 #endif // MAIN_WINDOW_H
129