2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
12 #include <package/solver/SolverProblemSolution.h>
14 #include <package/solver/SolverPackage.h>
17 #undef B_TRANSLATION_CONTEXT
18 #define B_TRANSLATION_CONTEXT "SolverProblemSolution"
21 static const char* const kToStringTexts
[] = {
22 B_TRANSLATE_MARK("do something"),
23 B_TRANSLATE_MARK("do not keep %source% installed"),
24 B_TRANSLATE_MARK("do not install \"%selection%\""),
25 B_TRANSLATE_MARK("do not install the most recent version of "
27 B_TRANSLATE_MARK("do not forbid installation of %source%"),
28 B_TRANSLATE_MARK("do not deinstall \"%selection%\""),
29 B_TRANSLATE_MARK("do not deinstall all resolvables \"%selection%\""),
30 B_TRANSLATE_MARK("do not lock \"%selection%\""),
31 B_TRANSLATE_MARK("keep %source% despite its inferior architecture"),
32 B_TRANSLATE_MARK("keep %source% from excluded repository"),
33 B_TRANSLATE_MARK("keep old %source%"),
34 B_TRANSLATE_MARK("install %source% despite its inferior architecture"),
35 B_TRANSLATE_MARK("install %source% from excluded repository"),
36 B_TRANSLATE_MARK("install %selection% despite its old version"),
37 B_TRANSLATE_MARK("allow downgrade of %source% to %target%"),
38 B_TRANSLATE_MARK("allow name change of %source% to %target%"),
39 B_TRANSLATE_MARK("allow architecture change of %source% to %target%"),
40 B_TRANSLATE_MARK("allow vendor change from \"%sourceVendor%\" (%source%) "
41 "to \"%targetVendor%\" (%target%)"),
42 B_TRANSLATE_MARK("allow replacement of %source% with %target%"),
43 B_TRANSLATE_MARK("allow deinstallation of %source%")
47 namespace BPackageKit
{
50 // #pragma mark - BSolverProblemSolutionElement
53 BSolverProblemSolutionElement::BSolverProblemSolutionElement(BType type
,
54 BSolverPackage
* sourcePackage
, BSolverPackage
* targetPackage
,
55 const BString
& selection
)
58 fSourcePackage(sourcePackage
),
59 fTargetPackage(targetPackage
),
65 BSolverProblemSolutionElement::~BSolverProblemSolutionElement()
70 BSolverProblemSolutionElement::BType
71 BSolverProblemSolutionElement::Type() const
78 BSolverProblemSolutionElement::SourcePackage() const
80 return fSourcePackage
;
85 BSolverProblemSolutionElement::TargetPackage() const
87 return fTargetPackage
;
92 BSolverProblemSolutionElement::Selection() const
99 BSolverProblemSolutionElement::ToString() const
101 size_t index
= fType
;
102 if (index
>= sizeof(kToStringTexts
) / sizeof(kToStringTexts
[0]))
105 return BString(B_TRANSLATE_NOCOLLECT(kToStringTexts
[index
]))
106 .ReplaceAll("%source%",
107 fSourcePackage
!= NULL
108 ? fSourcePackage
->VersionedName().String() : "?")
109 .ReplaceAll("%target%",
110 fTargetPackage
!= NULL
111 ? fTargetPackage
->VersionedName().String() : "?")
112 .ReplaceAll("%selection%", fSelection
)
113 .ReplaceAll("%sourceVendor%",
114 fSourcePackage
!= NULL
115 ? fSourcePackage
->Info().Vendor().String() : "?")
116 .ReplaceAll("%targetVendor%",
117 fTargetPackage
!= NULL
118 ? fTargetPackage
->Info().Vendor().String() : "?");
122 // #pragma mark - BSolverProblemSolution
125 BSolverProblemSolution::BSolverProblemSolution()
132 BSolverProblemSolution::~BSolverProblemSolution()
138 BSolverProblemSolution::CountElements() const
140 return fElements
.CountItems();
144 const BSolverProblemSolution::Element
*
145 BSolverProblemSolution::ElementAt(int32 index
) const
147 return fElements
.ItemAt(index
);
152 BSolverProblemSolution::AppendElement(const Element
& element
)
154 Element
* newElement
= new(std::nothrow
) Element(element
);
155 if (newElement
== NULL
|| !fElements
.AddItem(newElement
)) {
164 } // namespace BPackageKit