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-2024, 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 _InitPreferredLanguage(); 93 94 void _AdoptModelControls(); 95 void _AdoptModel(); 96 void _AddRemovePackageFromLists( 97 const PackageInfoRef& package); 98 99 void _AdoptPackage(const PackageInfoRef& package); 100 void _ClearPackage(); 101 102 void _SetupDelayedIncrementViewCounter( 103 const PackageInfoRef package); 104 void _HandleIncrementViewCounter( 105 const BMessage* message); 106 void _IncrementViewCounter( 107 const PackageInfoRef package); 108 109 void _PopulatePackageAsync(bool forcePopulate); 110 void _StartBulkLoad(bool force = false); 111 void _BulkLoadCompleteReceived(status_t errorStatus); 112 113 void _NotifyWorkStatusClear(); 114 void _HandleWorkStatusClear(); 115 116 void _NotifyWorkStatusChange(const BString& text, 117 float progress); 118 void _HandleWorkStatusChangeMessageReceived( 119 const BMessage* message); 120 121 void _HandleExternalPackageUpdateMessageReceived( 122 const BMessage* message); 123 124 void _HandleChangePackageListViewMode(); 125 126 void _HandleProcessCoordinatorChanged( 127 ProcessCoordinatorState& coordinatorState); 128 129 static status_t _RefreshModelThreadWorker(void* arg); 130 static status_t _PopulatePackageWorker(void* arg); 131 static status_t _PackagesToShowWorker(void* arg); 132 133 void _OpenLoginWindow( 134 const BMessage& onSuccessMessage); 135 void _OpenSettingsWindow(); 136 void _StartUserVerify(); 137 void _UpdateAuthorization(); 138 void _UpdateAvailableRepositories(); 139 void _RatePackage(); 140 void _ShowScreenshot(); 141 142 void _ViewUserUsageConditions( 143 UserUsageConditionsSelectionMode mode); 144 145 void _HandleUserUsageConditionsNotLatest( 146 const UserDetail& userDetail); 147 148 void _HandleScreenshotCached(const BMessage* message); 149 150 private: 151 FilterView* fFilterView; 152 TabView* fListTabs; 153 FeaturedPackagesView* fFeaturedPackagesView; 154 PackageListView* fPackageListView; 155 PackageInfoView* fPackageInfoView; 156 BSplitView* fSplitView; 157 WorkStatusView* fWorkStatusView; 158 159 ScreenshotWindow* fScreenshotWindow; 160 ShuttingDownWindow* fShuttingDownWindow; 161 162 BMenu* fUserMenu; 163 BMenu* fRepositoryMenu; 164 BMenuItem* fLogInItem; 165 BMenuItem* fLogOutItem; 166 BMenuItem* fUsersUserUsageConditionsMenuItem; 167 168 BMenuItem* fShowAvailablePackagesItem; 169 BMenuItem* fShowInstalledPackagesItem; 170 BMenuItem* fShowDevelopPackagesItem; 171 BMenuItem* fShowSourcePackagesItem; 172 173 BMenuItem* fRefreshRepositoriesItem; 174 175 Model fModel; 176 ModelListenerRef fModelListener; 177 178 std::queue<ProcessCoordinator*> 179 fCoordinatorQueue; 180 ProcessCoordinator* fCoordinator; 181 BLocker fCoordinatorLock; 182 sem_id fCoordinatorRunningSem; 183 bool fShouldCloseWhenNoProcessesToCoordinate; 184 185 bool fSinglePackageMode; 186 187 PackageInfoListenerRef 188 fPackageInfoListener; 189 190 BMessageRunner* fIncrementViewCounterDelayedRunner; 191 }; 192 193 194 195 #endif // MAIN_WINDOW_H 196