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-2018, 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 "TabView.h" 14 #include "Model.h" 15 #include "PackageAction.h" 16 #include "PackageActionHandler.h" 17 #include "PackageInfoListener.h" 18 #include "ProcessCoordinator.h" 19 #include "HaikuDepotConstants.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 _RestoreUserName(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 private: 105 FilterView* fFilterView; 106 TabView* fListTabs; 107 FeaturedPackagesView* fFeaturedPackagesView; 108 PackageListView* fPackageListView; 109 PackageInfoView* fPackageInfoView; 110 BSplitView* fSplitView; 111 WorkStatusView* fWorkStatusView; 112 113 ScreenshotWindow* fScreenshotWindow; 114 115 BMenu* fUserMenu; 116 BMenu* fRepositoryMenu; 117 BMenuItem* fLogInItem; 118 BMenuItem* fLogOutItem; 119 120 BMenuItem* fShowAvailablePackagesItem; 121 BMenuItem* fShowInstalledPackagesItem; 122 BMenuItem* fShowDevelopPackagesItem; 123 BMenuItem* fShowSourcePackagesItem; 124 125 BMenuItem* fRefreshRepositoriesItem; 126 127 Model fModel; 128 ModelListenerRef fModelListener; 129 PackageList fVisiblePackages; 130 ProcessCoordinator* fBulkLoadProcessCoordinator; 131 BLocker fBulkLoadProcessCoordinatorLock; 132 133 bool fSinglePackageMode; 134 135 thread_id fPendingActionsWorker; 136 PackageActionList fPendingActions; 137 BLocker fPendingActionsLock; 138 sem_id fPendingActionsSem; 139 140 thread_id fPopulatePackageWorker; 141 PackageInfoRef fPackageToPopulate; 142 bool fForcePopulatePackage; 143 BLocker fPackageToPopulateLock; 144 sem_id fPackageToPopulateSem; 145 146 thread_id fShowPackagesWorker; 147 PackageList fPackagesToShowList; 148 int32 fPackagesToShowListID; 149 // atomic, counted up whenever fPackagesToShowList is refilled 150 BLocker fPackagesToShowListLock; 151 sem_id fNewPackagesToShowSem; 152 sem_id fShowPackagesAcknowledgeSem; 153 }; 154 155 #endif // MAIN_WINDOW_H 156