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