39 #define YUILogComponent "ncurses-pkg" 42 #include "NCPkgTable.h" 43 #include "NCPkgPackageDetails.h" 44 #include "NCPackageSelector.h" 46 #include <boost/algorithm/string.hpp> 54 NCPkgPackageDetails::NCPkgPackageDetails ( YWidget *parent, std::string initial_text,
NCPackageSelector *pkger)
55 : NCRichText (parent, initial_text)
61 std::string NCPkgPackageDetails::createRelLine(
const zypp::Capabilities & info )
63 std::string text =
"";
64 zypp::Capabilities::const_iterator
68 unsigned int i, n = info.size();
70 for ( it = b, i = 0; it != e; ++it, ++i )
72 text = text + (*it).asString();
82 std::string NCPkgPackageDetails::createText( std::list<std::string> info,
bool oneline )
84 std::list<std::string>::iterator it;
85 std::string text =
"";
88 for ( i = 0, it = info.begin(); it != info.end() && i < 1000; ++it, i++ )
91 if ( i < info.size()-1 )
93 if ( oneline && i < 999 )
95 if ( boost::ends_with( text,
":" ) )
114 std::string NCPkgPackageDetails::commonHeader( ZyppObj pkgPtr )
116 std::string text =
"";
121 text +=
"<h3>" + pkgPtr->name() +
" - ";
122 text += pkgPtr->summary() +
"</h3>";
127 void NCPkgPackageDetails::longDescription ( ZyppObj pkgPtr )
129 std::string text =
"";
135 text += pkgPtr->description();
138 setValue( createHtmlText(text) );
141 void NCPkgPackageDetails::technicalData( ZyppObj pkgPtr, ZyppSel slbPtr )
143 std::string instVersion =
"";
144 std::string version =
"";
145 std::string text =
"";
147 if ( !pkgPtr || !slbPtr )
150 text += commonHeader( pkgPtr );
152 if ( slbPtr->hasBothObjects() )
154 ZyppObj io = slbPtr->installedObj();
155 instVersion = io->edition().version();
157 instVersion += io->edition().release();
158 ZyppObj co = slbPtr->candidateObj();
159 version = co->edition().version();
161 version += co->edition().release();
165 version = pkgPtr->edition().version();
167 version += pkgPtr->edition().release();
172 if ( instVersion !=
"" )
182 text += pkgPtr->installSize().asString();
185 ZyppPkg
package = tryCastToZyppPkg( pkgPtr );
186 ZyppPkg candidate = tryCastToZyppPkg( slbPtr->candidateObj() );
187 ZyppPkg installed = tryCastToZyppPkg( slbPtr->installedObj() );
191 else if ( candidate )
199 int medianr = package->mediaNr();
200 sprintf( num,
"%d", medianr );
206 text += package->license();
211 text +=
"<b>" + _(
"Source Package: " ) +
"</b>";
212 text += package->sourcePkgName();
214 text += package->sourcePkgEdition().asString();
217 std::list<std::string> authors = package->authors();
218 if ( !authors.empty() )
220 std::string author_text;
223 author_text = createText( authors,
true );
225 boost::replace_all( author_text,
"<",
"<" );
226 boost::replace_all( author_text,
">",
">" );
235 void NCPkgPackageDetails::fileList( ZyppSel slbPtr )
237 std::string text =
"";
239 ZyppPkg
package = tryCastToZyppPkg (slbPtr->installedObj());
243 text += commonHeader( slbPtr->theObj() );
244 text += NCPkgStrings::ListOfFiles();
246 zypp::Package::FileList pkgfilelist( package->filelist() );
247 std::list<std::string> fileList( pkgfilelist.begin(), pkgfilelist.end() );
248 text += createText( fileList,
false );
252 text = _(
"<i>This information is available for installed packages only.</i>" );
257 void NCPkgPackageDetails::dependencyList( ZyppObj pkgPtr, ZyppSel slbPtr )
259 std::string text = commonHeader( pkgPtr );
261 zypp::Dep deptypes[] = {
263 zypp::Dep::PREREQUIRES,
265 zypp::Dep::CONFLICTS,
266 zypp::Dep::OBSOLETES,
267 zypp::Dep::RECOMMENDS,
270 zypp::Dep::SUPPLEMENTS,
272 for (
size_t i = 0; i <
sizeof (deptypes)/
sizeof(deptypes[0]); ++i)
274 zypp::Dep deptype = deptypes[i];
275 zypp::Capabilities relations = pkgPtr->dep (deptype);
276 std::string relline = createRelLine (relations);
277 if (!relline.empty())
280 text +=
"<b>" + deptype.asString() +
": </b>" 289 std::string NCPkgPackageDetails::createHtmlText( std::string value )
291 yuiDebug() <<
"Description: " << value << endl;
294 if ( value.find( std::string(DOCTYPETAG) ) != std::string::npos )
299 boost::replace_all( value,
"&",
"&" );
300 boost::replace_all( value,
"<",
"<" );
301 boost::replace_all( value,
">",
">" );
303 NCstring input( value );
304 NCtext descr( input );
305 NCtext html_descr( NCstring(
"<p>") );
306 std::string description =
"";
307 bool ul_begin =
false;
308 bool ul_found =
false;
309 std::list<NCstring>::const_iterator line;
311 for ( line = descr.Text().begin(); line != descr.Text().end(); ++line )
313 NCstring curr_line( *line );
315 if ( curr_line.Str().empty() )
319 html_descr.append( NCstring(
"</li></ul><p>") );
325 html_descr.append( NCstring(
"</p><p>") );
328 else if ( curr_line.Str().substr(0, 2) ==
"- " 329 || curr_line.Str().substr(0, 2) ==
"* ")
334 html_descr.append( NCstring(
"</p><ul><li>") );
339 html_descr.append( NCstring(
"</li><li>") );
341 html_descr.append( NCstring(curr_line.Str().substr(2)) );
343 else if ( curr_line.Str().substr(0, 2) ==
" " )
346 html_descr.append( NCstring( curr_line.Str() ) );
352 html_descr.append( NCstring(
"</li></ul><p>") );
356 html_descr.append( NCstring(
" " + curr_line.Str()) );
361 html_descr.append( NCstring(
"</li></ul>") );
363 html_descr.append( NCstring(
"</p>") );
366 for ( line = html_descr.Text().begin(); line != html_descr.Text().end(); ++line )
368 NCstring curr_line( *line );
369 description += curr_line.Str();
372 boost::replace_all( description,
"</p><p></p>",
"</p>" );
377 bool NCPkgPackageDetails::patchDescription( ZyppObj objPtr, ZyppSel selectable )
379 ZyppPatch patchPtr = tryCastToZyppPatch( objPtr );
381 if ( !patchPtr || !selectable )
383 yuiError() <<
"Patch not valid" << endl;
390 descr += selectable->name();
396 descr += NCPkgStrings::PatchKind();
398 descr += patchPtr->category();
401 descr += patchPtr->edition().asString();
405 std::string value = patchPtr->description();
406 std::string html_text =
"";
407 const std::string htmlIdent(DOCTYPETAG);
409 if ( value.find( htmlIdent ) != std::string::npos )
416 boost::replace_all( value,
"&",
"&" );
417 boost::replace_all( value,
"<",
"<" );
418 boost::replace_all( value,
">",
">" );
419 html_text =
"<pre>" + value +
"</pre>";
424 descr += _(
"References:<br>" );
425 for ( zypp::Patch::ReferenceIterator rit = patchPtr->referencesBegin();
426 rit != patchPtr->referencesEnd();
429 descr += rit.id().c_str();
432 descr += rit.type().c_str();
435 descr += rit.title().c_str();
static const std::string MediaNo()
bold text Media No.
static const std::string Authors()
bold text Authors: (richtext)
static const std::string Patch()
bold text Patch: (richtext)
static const std::string InstVersion()
bold text Installed version: (richtext)
static const std::string License()
bold text License: (richtext)
static const std::string Size()
bold text Size: (richtext)
static const std::string Version()
bold text Version: (richtext)