1 /* 2 * Copyright 2013, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 */ 8 9 10 #include <Catalog.h> 11 12 #include <package/solver/SolverProblemSolution.h> 13 14 #include <package/solver/SolverPackage.h> 15 16 17 #undef B_TRANSLATION_CONTEXT 18 #define B_TRANSLATION_CONTEXT "SolverProblemSolution" 19 20 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 " 26 "\"%selection%\""), 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%") 44 }; 45 46 47 namespace BPackageKit { 48 49 50 // #pragma mark - BSolverProblemSolutionElement 51 52 53 BSolverProblemSolutionElement::BSolverProblemSolutionElement(BType type, 54 BSolverPackage* sourcePackage, BSolverPackage* targetPackage, 55 const BString& selection) 56 : 57 fType(type), 58 fSourcePackage(sourcePackage), 59 fTargetPackage(targetPackage), 60 fSelection(selection) 61 { 62 } 63 64 65 BSolverProblemSolutionElement::~BSolverProblemSolutionElement() 66 { 67 } 68 69 70 BSolverProblemSolutionElement::BType 71 BSolverProblemSolutionElement::Type() const 72 { 73 return fType; 74 } 75 76 77 BSolverPackage* 78 BSolverProblemSolutionElement::SourcePackage() const 79 { 80 return fSourcePackage; 81 } 82 83 84 BSolverPackage* 85 BSolverProblemSolutionElement::TargetPackage() const 86 { 87 return fTargetPackage; 88 } 89 90 91 const BString& 92 BSolverProblemSolutionElement::Selection() const 93 { 94 return fSelection; 95 } 96 97 98 BString 99 BSolverProblemSolutionElement::ToString() const 100 { 101 size_t index = fType; 102 if (index >= sizeof(kToStringTexts) / sizeof(kToStringTexts[0])) 103 index = 0; 104 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() : "?"); 119 } 120 121 122 // #pragma mark - BSolverProblemSolution 123 124 125 BSolverProblemSolution::BSolverProblemSolution() 126 : 127 fElements(10, true) 128 { 129 } 130 131 132 BSolverProblemSolution::~BSolverProblemSolution() 133 { 134 } 135 136 137 int32 138 BSolverProblemSolution::CountElements() const 139 { 140 return fElements.CountItems(); 141 } 142 143 144 const BSolverProblemSolution::Element* 145 BSolverProblemSolution::ElementAt(int32 index) const 146 { 147 return fElements.ItemAt(index); 148 } 149 150 151 bool 152 BSolverProblemSolution::AppendElement(const Element& element) 153 { 154 Element* newElement = new(std::nothrow) Element(element); 155 if (newElement == NULL || !fElements.AddItem(newElement)) { 156 delete newElement; 157 return false; 158 } 159 160 return true; 161 } 162 163 164 } // namespace BPackageKit 165