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-2019, 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 "HaikuDepotConstants.h" 14 #include "Model.h" 15 #include "PackageAction.h" 16 #include "PackageActionHandler.h" 17 #include "ProcessCoordinator.h" 18 #include "PackageInfoListener.h" 19 #include "TabView.h" 20 21 22 class BCardLayout; 23 class BMenu; 24 class BMenuItem; 25 class BSplitView; 26 class FeaturedPackagesView; 27 class FilterView; 28 class PackageActionsView; 29 class PackageInfoView; 30 class PackageListView; 31 class ScreenshotWindow; 32 class WorkStatusView; 33 34 35 class MainWindow : public BWindow, private PackageInfoListener, 36 private PackageActionHandler, public ProcessCoordinatorListener { 37 public: 38 MainWindow(const BMessage& settings); 39 MainWindow(const BMessage& settings, 40 const PackageInfoRef& package); 41 virtual ~MainWindow(); 42 43 // BWindow interface 44 virtual bool QuitRequested(); 45 virtual void MessageReceived(BMessage* message); 46 47 void StoreSettings(BMessage& message) const; 48 49 // ProcessCoordinatorListener 50 virtual void CoordinatorChanged( 51 ProcessCoordinatorState& coordinatorState); 52 private: 53 // PackageInfoListener 54 virtual void PackageChanged( 55 const PackageInfoEvent& event); 56 57 private: 58 // PackageActionHandler 59 virtual status_t SchedulePackageActions( 60 PackageActionList& list); 61 virtual Model* GetModel(); 62 63 private: 64 void _BulkLoadProcessCoordinatorFinished( 65 ProcessCoordinatorState& 66 processCoordinatorState); 67 bool _SelectedPackageHasWebAppRepositoryCode(); 68 69 void _BuildMenu(BMenuBar* menuBar); 70 void _BuildUserMenu(BMenuBar* menuBar); 71 72 void _RestoreNickname(const BMessage& settings); 73 const char* _WindowFrameName() const; 74 void _RestoreWindowFrame(const BMessage& settings); 75 76 void _InitWorkerThreads(); 77 void _AdoptModel(); 78 79 void _AdoptPackage(const PackageInfoRef& package); 80 void _ClearPackage(); 81 82 void _PopulatePackageAsync(bool forcePopulate); 83 void _StopBulkLoad(); 84 void _StartBulkLoad(bool force = false); 85 void _BulkLoadCompleteReceived(); 86 87 void _NotifyWorkStatusChange(const BString& text, 88 float progress); 89 void _HandleWorkStatusChangeMessageReceived( 90 const BMessage* message); 91 92 static status_t _RefreshModelThreadWorker(void* arg); 93 static status_t _PackageActionWorker(void* arg); 94 static status_t _PopulatePackageWorker(void* arg); 95 static status_t _PackagesToShowWorker(void* arg); 96 97 void _OpenLoginWindow( 98 const BMessage& onSuccessMessage); 99 void _UpdateAuthorization(); 100 void _UpdateAvailableRepositories(); 101 void _RatePackage(); 102 void _ShowScreenshot(); 103 104 void _ViewUserUsageConditions( 105 UserUsageConditionsSelectionMode mode); 106 107 private: 108 FilterView* fFilterView; 109 TabView* fListTabs; 110 FeaturedPackagesView* fFeaturedPackagesView; 111 PackageListView* fPackageListView; 112 PackageInfoView* fPackageInfoView; 113 BSplitView* fSplitView; 114 WorkStatusView* fWorkStatusView; 115 116 ScreenshotWindow* fScreenshotWindow; 117 118 BMenu* fUserMenu; 119 BMenu* fRepositoryMenu; 120 BMenuItem* fLogInItem; 121 BMenuItem* fLogOutItem; 122 BMenuItem* fUsersUserUsageConditionsMenuItem; 123 124 BMenuItem* fShowAvailablePackagesItem; 125 BMenuItem* fShowInstalledPackagesItem; 126 BMenuItem* fShowDevelopPackagesItem; 127 BMenuItem* fShowSourcePackagesItem; 128 129 BMenuItem* fRefreshRepositoriesItem; 130 131 Model fModel; 132 ModelListenerRef fModelListener; 133 PackageList fVisiblePackages; 134 ProcessCoordinator* fBulkLoadProcessCoordinator; 135 BLocker fBulkLoadProcessCoordinatorLock; 136 137 bool fSinglePackageMode; 138 139 thread_id fPendingActionsWorker; 140 PackageActionList fPendingActions; 141 BLocker fPendingActionsLock; 142 sem_id fPendingActionsSem; 143 144 thread_id fPopulatePackageWorker; 145 PackageInfoRef fPackageToPopulate; 146 bool fForcePopulatePackage; 147 BLocker fPackageToPopulateLock; 148 sem_id fPackageToPopulateSem; 149 150 thread_id fShowPackagesWorker; 151 PackageList fPackagesToShowList; 152 int32 fPackagesToShowListID; 153 // atomic, counted up whenever fPackagesToShowList is refilled 154 BLocker fPackagesToShowListLock; 155 sem_id fNewPackagesToShowSem; 156 sem_id fShowPackagesAcknowledgeSem; 157 }; 158 159 #endif // MAIN_WINDOW_H 160