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-2023, 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 "ProcessCoordinator.h" 18 #include "PackageInfoListener.h" 19 #include "TabView.h" 20 #include "UserDetail.h" 21 #include "UserDetailVerifierProcess.h" 22 23 24 class BCardLayout; 25 class BMenu; 26 class BMenuItem; 27 class BSplitView; 28 class FeaturedPackagesView; 29 class FilterView; 30 class PackageActionsView; 31 class PackageInfoView; 32 class PackageListView; 33 class ScreenshotWindow; 34 class ShuttingDownWindow; 35 class WorkStatusView; 36 37 38 class MainWindow : 39 private ProcessCoordinatorConsumer, public ProcessCoordinatorListener, 40 public UserDetailVerifierListener, public BWindow { 41 public: 42 MainWindow(const BMessage& settings); 43 MainWindow(const BMessage& settings, 44 PackageInfoRef& package); 45 virtual ~MainWindow(); 46 47 // BWindow interface 48 virtual bool QuitRequested(); 49 virtual void MessageReceived(BMessage* message); 50 51 void StoreSettings(BMessage& message); 52 53 // ProcessCoordinatorConsumer 54 virtual void Consume(ProcessCoordinator *item); 55 56 // ProcessCoordinatorListener 57 virtual void CoordinatorChanged( 58 ProcessCoordinatorState& coordinatorState); 59 60 // UserDetailVerifierProcessListener 61 virtual void UserCredentialsFailed(); 62 virtual void UserUsageConditionsNotLatest( 63 const UserDetail& userDetail); 64 65 // services PackageInfoListener via MainWindowPackageInfoListener 66 void PackageChanged( 67 const PackageInfoEvent& event); 68 69 private: 70 std::vector<DepotInfoRef> 71 _CreateSnapshotOfDepots(); 72 73 void _AddProcessCoordinator( 74 ProcessCoordinator* item); 75 void _StopProcessCoordinators(); 76 void _SpinUntilProcessCoordinatorComplete(); 77 78 bool _SelectedPackageHasWebAppRepositoryCode(); 79 80 void _BuildMenu(BMenuBar* menuBar); 81 void _BuildUserMenu(BMenuBar* menuBar); 82 83 const char* _WindowFrameName() const; 84 void _RestoreNickname(const BMessage& settings); 85 void _RestoreWindowFrame(const BMessage& settings); 86 void _RestoreModelSettings(const BMessage& settings); 87 88 void _MaybePromptCanShareAnonymousUserData( 89 const BMessage& settings); 90 void _PromptCanShareAnonymousUserData(); 91 92 void _InitWorkerThreads(); 93 void _AdoptModelControls(); 94 void _AdoptModel(); 95 void _AddRemovePackageFromLists( 96 const PackageInfoRef& package); 97 98 void _AdoptPackage(const PackageInfoRef& package); 99 void _ClearPackage(); 100 101 void _SetupDelayedIncrementViewCounter( 102 const PackageInfoRef package); 103 void _HandleIncrementViewCounter( 104 const BMessage* message); 105 void _IncrementViewCounter( 106 const PackageInfoRef package); 107 108 void _PopulatePackageAsync(bool forcePopulate); 109 void _StartBulkLoad(bool force = false); 110 void _BulkLoadCompleteReceived(status_t errorStatus); 111 112 void _NotifyWorkStatusClear(); 113 void _HandleWorkStatusClear(); 114 115 void _NotifyWorkStatusChange(const BString& text, 116 float progress); 117 void _HandleWorkStatusChangeMessageReceived( 118 const BMessage* message); 119 120 void _HandleExternalPackageUpdateMessageReceived( 121 const BMessage* message); 122 123 void _HandleChangePackageListViewMode(); 124 125 void _HandleProcessCoordinatorChanged( 126 ProcessCoordinatorState& coordinatorState); 127 128 static status_t _RefreshModelThreadWorker(void* arg); 129 static status_t _PopulatePackageWorker(void* arg); 130 static status_t _PackagesToShowWorker(void* arg); 131 132 void _OpenLoginWindow( 133 const BMessage& onSuccessMessage); 134 void _OpenSettingsWindow(); 135 void _StartUserVerify(); 136 void _UpdateAuthorization(); 137 void _UpdateAvailableRepositories(); 138 void _RatePackage(); 139 void _ShowScreenshot(); 140 141 void _ViewUserUsageConditions( 142 UserUsageConditionsSelectionMode mode); 143 144 void _HandleUserUsageConditionsNotLatest( 145 const UserDetail& userDetail); 146 147 private: 148 FilterView* fFilterView; 149 TabView* fListTabs; 150 FeaturedPackagesView* fFeaturedPackagesView; 151 PackageListView* fPackageListView; 152 PackageInfoView* fPackageInfoView; 153 BSplitView* fSplitView; 154 WorkStatusView* fWorkStatusView; 155 156 ScreenshotWindow* fScreenshotWindow; 157 ShuttingDownWindow* fShuttingDownWindow; 158 159 BMenu* fUserMenu; 160 BMenu* fRepositoryMenu; 161 BMenuItem* fLogInItem; 162 BMenuItem* fLogOutItem; 163 BMenuItem* fUsersUserUsageConditionsMenuItem; 164 165 BMenuItem* fShowAvailablePackagesItem; 166 BMenuItem* fShowInstalledPackagesItem; 167 BMenuItem* fShowDevelopPackagesItem; 168 BMenuItem* fShowSourcePackagesItem; 169 170 BMenuItem* fRefreshRepositoriesItem; 171 172 Model fModel; 173 ModelListenerRef fModelListener; 174 175 std::queue<ProcessCoordinator*> 176 fCoordinatorQueue; 177 ProcessCoordinator* fCoordinator; 178 BLocker fCoordinatorLock; 179 sem_id fCoordinatorRunningSem; 180 bool fShouldCloseWhenNoProcessesToCoordinate; 181 182 bool fSinglePackageMode; 183 184 thread_id fPopulatePackageWorker; 185 PackageInfoRef fPackageToPopulate; 186 bool fForcePopulatePackage; 187 BLocker fPackageToPopulateLock; 188 sem_id fPackageToPopulateSem; 189 190 PackageInfoListenerRef 191 fPackageInfoListener; 192 193 BMessageRunner* fIncrementViewCounterDelayedRunner; 194 }; 195 196 197 198 #endif // MAIN_WINDOW_H 199