1 /* 2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2013, Rene Gollent <rene@gollent.com>. 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 #ifndef MAIN_WINDOW_H 7 #define MAIN_WINDOW_H 8 9 #include <Window.h> 10 11 #include "Model.h" 12 #include "PackageAction.h" 13 #include "PackageActionHandler.h" 14 #include "PackageInfoListener.h" 15 16 17 class BCardLayout; 18 class BMenu; 19 class BMenuItem; 20 class BSplitView; 21 class FeaturedPackagesView; 22 class FilterView; 23 class PackageActionsView; 24 class PackageInfoView; 25 class PackageListView; 26 class ScreenshotWindow; 27 28 29 enum { 30 MSG_MAIN_WINDOW_CLOSED = 'mwcl', 31 MSG_PACKAGE_SELECTED = 'pkgs', 32 }; 33 34 35 class MainWindow : public BWindow, private PackageInfoListener, 36 private PackageActionHandler { 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 private: 50 // PackageInfoListener 51 virtual void PackageChanged( 52 const PackageInfoEvent& event); 53 54 private: 55 // PackageActionHandler 56 virtual status_t SchedulePackageActions( 57 PackageActionList& list); 58 virtual Model* GetModel(); 59 60 private: 61 void _BuildMenu(BMenuBar* menuBar); 62 void _BuildUserMenu(BMenuBar* menuBar); 63 64 void _RestoreUserName(const BMessage& settings); 65 const char* _WindowFrameName() const; 66 void _RestoreWindowFrame(const BMessage& settings); 67 68 void _InitWorkerThreads(); 69 void _AdoptModel(); 70 71 void _AdoptPackage(const PackageInfoRef& package); 72 void _ClearPackage(); 73 74 void _RefreshRepositories(bool force); 75 void _RefreshPackageList(bool force); 76 77 void _StartRefreshWorker(bool force = false); 78 static status_t _RefreshModelThreadWorker(void* arg); 79 static status_t _PackageActionWorker(void* arg); 80 static status_t _PopulatePackageWorker(void* arg); 81 82 void _NotifyUser(const char* title, 83 const char* message); 84 85 void _OpenLoginWindow( 86 const BMessage& onSuccessMessage); 87 void _UpdateAuthorization(); 88 void _RatePackage(); 89 void _ShowScreenshot(); 90 91 private: 92 FilterView* fFilterView; 93 BCardLayout* fListLayout; 94 FeaturedPackagesView* fFeaturedPackagesView; 95 PackageListView* fPackageListView; 96 PackageInfoView* fPackageInfoView; 97 BSplitView* fSplitView; 98 99 ScreenshotWindow* fScreenshotWindow; 100 101 BMenu* fUserMenu; 102 BMenuItem* fLogInItem; 103 BMenuItem* fLogOutItem; 104 105 BMenuItem* fShowFeaturedPackagesItem; 106 BMenuItem* fShowAvailablePackagesItem; 107 BMenuItem* fShowInstalledPackagesItem; 108 BMenuItem* fShowDevelopPackagesItem; 109 BMenuItem* fShowSourcePackagesItem; 110 111 Model fModel; 112 ModelListenerRef fModelListener; 113 PackageList fVisiblePackages; 114 115 bool fTerminating; 116 bool fSinglePackageMode; 117 thread_id fModelWorker; 118 119 thread_id fPendingActionsWorker; 120 PackageActionList fPendingActions; 121 BLocker fPendingActionsLock; 122 sem_id fPendingActionsSem; 123 124 thread_id fPopulatePackageWorker; 125 PackageInfoRef fPackageToPopulate; 126 BLocker fPackageToPopulateLock; 127 sem_id fPackageToPopulateSem; 128 }; 129 130 #endif // MAIN_WINDOW_H 131