xref: /haiku/src/apps/haikudepot/packagemanagement/PackageManager.h (revision a18f873f8b884375ea8278f3c9df0e433b822262)
1 /*
2  * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2011, Ingo Weinhold, <ingo_weinhold@gmx.de>
4  * Copyright 2013, Rene Gollent, <rene@gollent.com>
5  * Copyright 2017, Julian Harnath <julian.harnath@rwth-aachen.de>.
6  * Copyright 2021, Andrew Lindesay <apl@lindesay.co.nz>.
7  *
8  * All rights reserved. Distributed under the terms of the MIT License.
9  */
10 #ifndef PACKAGE_MANAGER_H
11 #define PACKAGE_MANAGER_H
12 
13 #include <Locker.h>
14 
15 #include <package/DaemonClient.h>
16 #include <package/manager/PackageManager.h>
17 
18 #include "Collector.h"
19 #include "DecisionProvider.h"
20 #include "DeskbarLink.h"
21 #include "JobStateListener.h"
22 #include "PackageAction.h"
23 #include "PackageInfo.h"
24 #include "PackageProgressListener.h"
25 
26 
27 namespace BPackageKit {
28 	class BSolverPackage;
29 }
30 
31 class PackageManager;
32 class ProblemWindow;
33 class ResultWindow;
34 
35 
36 using BPackageKit::BCommitTransactionResult;
37 using BPackageKit::BContext;
38 using BPackageKit::BPackageInstallationLocation;
39 using BPackageKit::BRepositoryConfig;
40 using BPackageKit::BPrivate::BDaemonClient;
41 using BPackageKit::BManager::BPrivate::BPackageManager;
42 
43 
44 class PackageManager : public BPackageManager,
45 	private BPackageManager::UserInteractionHandler {
46 public:
47 								PackageManager(
48 									BPackageInstallationLocation location);
49 	virtual						~PackageManager();
50 
51 	virtual	PackageState		GetPackageState(const PackageInfo& package);
52 	virtual	void				CollectPackageActions(PackageInfoRef package,
53 									Collector<PackageActionRef>& actionList);
54 
55 			void				SetCurrentActionPackage(
56 									PackageInfoRef package,
57 									bool install);
58 
59 	virtual	status_t			RefreshRepository(
60 									const BRepositoryConfig& repoConfig);
61 	virtual	status_t			DownloadPackage(const BString& fileURL,
62 									const BEntry& targetEntry,
63 									const BString& checksum);
64 
65 			void				AddProgressListener(
66 									PackageProgressListener* listener);
67 			void				RemoveProgressListener(
68 									PackageProgressListener* listener);
69 
70 private:
71 	// UserInteractionHandler
72 	virtual	void				HandleProblems();
73 	virtual	void				ConfirmChanges(bool fromMostSpecific);
74 
75 	virtual	void				Warn(status_t error, const char* format, ...);
76 
77 	virtual	void				ProgressPackageDownloadStarted(
78 									const char* packageName);
79 	virtual	void				ProgressPackageDownloadActive(
80 									const char* packageName,
81 									float completionPercentage,
82 									off_t bytes, off_t totalBytes);
83 
84 	virtual	void				ProgressPackageDownloadComplete(
85 									const char* packageName);
86 	virtual	void				ProgressPackageChecksumStarted(
87 									const char* title);
88 	virtual	void				ProgressPackageChecksumComplete(
89 									const char* title);
90 
91 	virtual	void				ProgressStartApplyingChanges(
92 									InstalledRepository& repository);
93 	virtual	void				ProgressTransactionCommitted(
94 									InstalledRepository& repository,
95 									const BCommitTransactionResult& result);
96 	virtual	void				ProgressApplyingChangesDone(
97 									InstalledRepository& repository);
98 
99 private:
100 			PackageActionRef	_CreateUninstallPackageAction(
101 									const PackageInfoRef& package);
102 			PackageActionRef	_CreateInstallPackageAction(
103 									const PackageInfoRef& package);
104 			PackageActionRef	_CreateOpenPackageAction(
105 									const PackageInfoRef& package,
106 									const DeskbarLink& link);
107 
108 			void				_CollectPackageActionsForActivatedOrInstalled(
109 									PackageInfoRef package,
110 									Collector<PackageActionRef>& actionList);
111 			bool				_AddResults(
112 									BPackageManager::InstalledRepository&
113 										repository,
114 									ResultWindow* window);
115 			void				_NotifyChangesConfirmed();
116 
117 			BPackageKit::BSolverPackage*
118 								_GetSolverPackage(PackageInfoRef package);
119 
120 private:
121 			DecisionProvider	fDecisionProvider;
122 			BPackageManager::ClientInstallationInterface
123 								fClientInstallationInterface;
124 
125 			ProblemWindow*		fProblemWindow;
126 			BPackageKit::BSolverPackage*
127 								fCurrentInstallPackage;
128 			BPackageKit::BSolverPackage*
129 								fCurrentUninstallPackage;
130 
131 			PackageProgressListenerList
132 								fPackageProgressListeners;
133 };
134 
135 #endif // PACKAGE_MANAGER_H
136