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();
212 text += package->group ();
216 text +=
"<b>" + _(
"Source Package: " ) +
"</b>";
217 text += package->sourcePkgName();
219 text += package->sourcePkgEdition().asString();
222 std::list<std::string> authors = package->authors();
223 if ( !authors.empty() )
225 std::string author_text;
228 author_text = createText( authors,
true );
230 boost::replace_all( author_text,
"<",
"<" );
231 boost::replace_all( author_text,
">",
">" );
240 void NCPkgPackageDetails::fileList( ZyppSel slbPtr )
242 std::string text =
"";
244 ZyppPkg
package = tryCastToZyppPkg (slbPtr->installedObj());
248 text += commonHeader( slbPtr->theObj() );
249 text += NCPkgStrings::ListOfFiles();
251 zypp::Package::FileList pkgfilelist( package->filelist() );
252 std::list<std::string> fileList( pkgfilelist.begin(), pkgfilelist.end() );
253 text += createText( fileList,
false ) ;
257 text = _(
"<i>This information is available for installed packages only.</i>" );
262 void NCPkgPackageDetails::dependencyList( ZyppObj pkgPtr, ZyppSel slbPtr )
264 std::string text = commonHeader( pkgPtr );
266 zypp::Dep deptypes[] = {
268 zypp::Dep::PREREQUIRES,
270 zypp::Dep::CONFLICTS,
271 zypp::Dep::OBSOLETES,
272 zypp::Dep::RECOMMENDS,
275 zypp::Dep::SUPPLEMENTS,
277 for (
size_t i = 0; i <
sizeof (deptypes)/
sizeof(deptypes[0]); ++i)
279 zypp::Dep deptype = deptypes[i];
280 zypp::Capabilities relations = pkgPtr->dep (deptype);
281 std::string relline = createRelLine (relations);
282 if (!relline.empty ())
285 text +=
"<b>" + deptype.asString () +
": </b>"
294 std::string NCPkgPackageDetails::createHtmlText( std::string value )
296 yuiDebug() <<
"Description: " << value << endl;
299 if ( value.find( std::string(DOCTYPETAG) ) != std::string::npos )
304 boost::replace_all( value,
"&",
"&" );
305 boost::replace_all( value,
"<",
"<" );
306 boost::replace_all( value,
">",
">" );
308 NCstring input( value );
309 NCtext descr( input );
310 NCtext html_descr( NCstring(
"<p>") );
311 std::string description =
"";
312 bool ul_begin =
false;
313 bool ul_found =
false;
314 std::list<NCstring>::const_iterator line;
316 for ( line = descr.Text().begin(); line != descr.Text().end(); ++line )
318 NCstring curr_line( *line );
320 if ( curr_line.Str().empty() )
324 html_descr.append( NCstring(
"</li></ul><p>") );
330 html_descr.append( NCstring(
"</p><p>") );
333 else if ( curr_line.Str().substr(0,2) ==
"- "
334 || curr_line.Str().substr(0,2) ==
"* ")
339 html_descr.append( NCstring(
"</p><ul><li>") );
344 html_descr.append( NCstring(
"</li><li>") );
346 html_descr.append( NCstring(curr_line.Str().substr(2)) );
348 else if ( curr_line.Str().substr(0,2) ==
" " )
351 html_descr.append( NCstring( curr_line.Str() ) );
357 html_descr.append( NCstring(
"</li></ul><p>") );
361 html_descr.append( NCstring(
" " + curr_line.Str()) );
366 html_descr.append( NCstring(
"</li></ul>") );
368 html_descr.append( NCstring(
"</p>") );
371 for ( line = html_descr.Text().begin(); line != html_descr.Text().end(); ++line )
373 NCstring curr_line( *line );
374 description += curr_line.Str();
377 boost::replace_all( description,
"</p><p></p>",
"</p>" );
382 bool NCPkgPackageDetails::patchDescription( ZyppObj objPtr, ZyppSel selectable )
384 ZyppPatch patchPtr = tryCastToZyppPatch( objPtr );
386 if ( !patchPtr || !selectable )
388 yuiError() <<
"Patch not valid" << endl;
395 descr += selectable->name();
401 descr += NCPkgStrings::PatchKind();
403 descr += patchPtr->category();
406 descr += patchPtr->edition().asString();
409 if ( !selectable->installedEmpty()
410 && selectable->installedObj().isBroken() )
412 descr += _(
"----- this patch is broken !!! -----" );
417 std::string value = patchPtr->description();
418 std::string html_text =
"";
419 const std::string htmlIdent(DOCTYPETAG);
421 if ( value.find( htmlIdent ) != std::string::npos )
428 boost::replace_all( value,
"&",
"&" );
429 boost::replace_all( value,
"<",
"<" );
430 boost::replace_all( value,
">",
">" );
431 html_text =
"<pre>" + value +
"</pre>";
436 descr += _(
"References:<br>" );
437 for ( zypp::Patch::ReferenceIterator rit = patchPtr->referencesBegin();
438 rit != patchPtr->referencesEnd();
441 descr += rit.id().c_str();
444 descr += rit.type().c_str();
447 descr += rit.title().c_str();