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-2021, 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 SchedulePackageAction(PackageActionRef action); 70 virtual Model* GetModel(); 71 72 private: 73 std::vector<DepotInfoRef> 74 _CreateSnapshotOfDepots(); 75 76 void _AddProcessCoordinator( 77 ProcessCoordinator* item); 78 void _StopProcessCoordinators(); 79 void _SpinUntilProcessCoordinatorComplete(); 80 81 bool _SelectedPackageHasWebAppRepositoryCode(); 82 83 void _BuildMenu(BMenuBar* menuBar); 84 void _BuildUserMenu(BMenuBar* menuBar); 85 86 const char* _WindowFrameName() const; 87 void _RestoreNickname(const BMessage& settings); 88 void _RestoreWindowFrame(const BMessage& settings); 89 void _RestoreModelSettings(const BMessage& settings); 90 91 void _MaybePromptCanShareAnonymousUserData( 92 const BMessage& settings); 93 void _PromptCanShareAnonymousUserData(); 94 95 void _InitWorkerThreads(); 96 void _AdoptModelControls(); 97 void _AdoptModel(); 98 void _AddRemovePackageFromLists( 99 const PackageInfoRef& package); 100 101 void _AdoptPackage(const PackageInfoRef& package); 102 void _ClearPackage(); 103 104 void _IncrementViewCounter( 105 const PackageInfoRef& package); 106 107 void _PopulatePackageAsync(bool forcePopulate); 108 void _StartBulkLoad(bool force = false); 109 void _BulkLoadCompleteReceived(status_t errorStatus); 110 111 void _NotifyWorkStatusClear(); 112 void _HandleWorkStatusClear(); 113 114 void _NotifyWorkStatusChange(const BString& text, 115 float progress); 116 void _HandleWorkStatusChangeMessageReceived( 117 const BMessage* message); 118 119 void _HandleChangePackageListViewMode(); 120 121 static status_t _RefreshModelThreadWorker(void* arg); 122 static status_t _PackageActionWorker(void* arg); 123 static status_t _PopulatePackageWorker(void* arg); 124 static status_t _PackagesToShowWorker(void* arg); 125 126 void _OpenLoginWindow( 127 const BMessage& onSuccessMessage); 128 void _OpenSettingsWindow(); 129 void _StartUserVerify(); 130 void _UpdateAuthorization(); 131 void _UpdateAvailableRepositories(); 132 void _RatePackage(); 133 void _ShowScreenshot(); 134 135 void _ViewUserUsageConditions( 136 UserUsageConditionsSelectionMode mode); 137 138 void _HandleUserUsageConditionsNotLatest( 139 const UserDetail& userDetail); 140 141 private: 142 FilterView* fFilterView; 143 TabView* fListTabs; 144 FeaturedPackagesView* fFeaturedPackagesView; 145 PackageListView* fPackageListView; 146 PackageInfoView* fPackageInfoView; 147 BSplitView* fSplitView; 148 WorkStatusView* fWorkStatusView; 149 150 ScreenshotWindow* fScreenshotWindow; 151 152 BMenu* fUserMenu; 153 BMenu* fRepositoryMenu; 154 BMenuItem* fLogInItem; 155 BMenuItem* fLogOutItem; 156 BMenuItem* fUsersUserUsageConditionsMenuItem; 157 158 BMenuItem* fShowAvailablePackagesItem; 159 BMenuItem* fShowInstalledPackagesItem; 160 BMenuItem* fShowDevelopPackagesItem; 161 BMenuItem* fShowSourcePackagesItem; 162 163 BMenuItem* fRefreshRepositoriesItem; 164 165 Model fModel; 166 ModelListenerRef fModelListener; 167 168 std::queue<BReference<ProcessCoordinator> > 169 fCoordinatorQueue; 170 BReference<ProcessCoordinator> 171 fCoordinator; 172 BLocker fCoordinatorLock; 173 sem_id fCoordinatorRunningSem; 174 175 bool fSinglePackageMode; 176 177 thread_id fPendingActionsWorker; 178 std::queue<PackageActionRef> 179 fPendingActions; 180 BLocker fPendingActionsLock; 181 sem_id fPendingActionsSem; 182 183 thread_id fPopulatePackageWorker; 184 PackageInfoRef fPackageToPopulate; 185 bool fForcePopulatePackage; 186 BLocker fPackageToPopulateLock; 187 sem_id fPackageToPopulateSem; 188 }; 189 190 #endif // MAIN_WINDOW_H 191