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