vfs: check userland buffers before reading them.
[haiku.git] / src / apps / haikudepot / ui / MainWindow.h
blob152b46c1c371df5da02dbb8b315da817638b8f02
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
11 #include <Window.h>
13 #include "BulkLoadStateMachine.h"
14 #include "Model.h"
15 #include "PackageAction.h"
16 #include "PackageActionHandler.h"
17 #include "PackageInfoListener.h"
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;
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',
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();
51 // BWindow interface
52 virtual bool QuitRequested();
53 virtual void MessageReceived(BMessage* message);
55 void StoreSettings(BMessage& message) const;
57 private:
58 // PackageInfoListener
59 virtual void PackageChanged(
60 const PackageInfoEvent& event);
62 private:
63 // PackageActionHandler
64 virtual status_t SchedulePackageActions(
65 PackageActionList& list);
66 virtual Model* GetModel();
68 private:
69 void _BuildMenu(BMenuBar* menuBar);
70 void _BuildUserMenu(BMenuBar* menuBar);
72 void _RestoreUserName(const BMessage& settings);
73 const char* _WindowFrameName() const;
74 void _RestoreWindowFrame(const BMessage& settings);
76 void _InitWorkerThreads();
77 void _AdoptModel();
79 void _AdoptPackage(const PackageInfoRef& package);
80 void _ClearPackage();
82 void _RefreshRepositories(bool force);
83 void _RefreshPackageList(bool force);
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);
91 void _NotifyUser(const char* title,
92 const char* message);
94 void _OpenLoginWindow(
95 const BMessage& onSuccessMessage);
96 void _UpdateAuthorization();
97 void _RatePackage();
98 void _ShowScreenshot();
100 private:
101 FilterView* fFilterView;
102 BCardLayout* fListLayout;
103 FeaturedPackagesView* fFeaturedPackagesView;
104 PackageListView* fPackageListView;
105 PackageInfoView* fPackageInfoView;
106 BSplitView* fSplitView;
107 WorkStatusView* fWorkStatusView;
109 ScreenshotWindow* fScreenshotWindow;
111 BMenu* fUserMenu;
112 BMenuItem* fLogInItem;
113 BMenuItem* fLogOutItem;
115 BMenuItem* fShowFeaturedPackagesItem;
116 BMenuItem* fShowAvailablePackagesItem;
117 BMenuItem* fShowInstalledPackagesItem;
118 BMenuItem* fShowDevelopPackagesItem;
119 BMenuItem* fShowSourcePackagesItem;
121 Model fModel;
122 ModelListenerRef fModelListener;
123 PackageList fVisiblePackages;
124 BulkLoadStateMachine
125 fBulkLoadStateMachine;
127 bool fTerminating;
128 bool fSinglePackageMode;
129 thread_id fModelWorker;
131 thread_id fPendingActionsWorker;
132 PackageActionList fPendingActions;
133 BLocker fPendingActionsLock;
134 sem_id fPendingActionsSem;
136 thread_id fPopulatePackageWorker;
137 PackageInfoRef fPackageToPopulate;
138 BLocker fPackageToPopulateLock;
139 sem_id fPackageToPopulateSem;
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;
150 #endif // MAIN_WINDOW_H