42 #define YUILogComponent "qt-pkg" 49 #include "zypp/VendorSupportOptions.h" 50 #include "YQPkgDescriptionView.h" 51 #include "YQPkgDescriptionDialog.h" 57 #define DESKTOP_TRANSLATIONS "desktop_translations" 58 #define DESKTOPFILEDIR "\\/share\\/applications\\/.*\\.desktop$" // RegExp 69 , _showSupportability ( showSupportability )
85 _selectable = selectable;
97 QString description = fromUTF8( selectable->theObj()->description() );
99 if ( ! description.contains(
"<!-- DT:Rich -->" ) )
102 html_text += (
"<p>" + description +
"</p>");
105 Patch::constPtr patch = asKind<Patch>(selectable->theObj());
109 html_text += _(
"References:");
113 for ( Patch::ReferenceIterator rit = patch->referencesBegin();
114 rit != patch->referencesEnd();
117 html_text += QString(
"<li>%1 (%2) : %3</li>" )
118 .arg( rit.id().c_str() )
119 .arg( rit.type().c_str() )
120 .arg( rit.title().c_str() );
122 html_text +=
"</ul>";
126 Package::constPtr
package = asKind<Package>(selectable->theObj());
127 if ( _showSupportability && package )
131 html_text += _(
"Supportability: %1").arg( fromUTF8(asUserString(package->vendorSupport()).c_str() ));
136 ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
142 zypp::Package::FileList f( installed->filelist() );
143 std::list<std::string> tmp( f.begin(), f.end() );
147 html_text += htmlEnd();
148 setHtml( html_text );
156 bool foundAuthorsList =
false;
157 QString html_text =
"<p>";
159 QStringList lines = text.trimmed().split(
'\n', QString::KeepEmptyParts );
160 QStringList::const_iterator it = lines.begin();
162 while ( it != lines.end() )
166 if ( line.startsWith(
"* ") || line.startsWith(
"- ") || line.startsWith(
"# ") )
168 line =
"<li>" + line +
"</li>";
171 if ( line.startsWith(
"Authors:" ) )
173 line =
"<p><b>" + line +
"</b><ul>";
174 foundAuthorsList =
true;
177 if ( foundAuthorsList )
179 if ( ! line.startsWith(
"-----" ) && ! line.isEmpty() )
180 html_text +=
"<li>" + line +
"</li>";
184 if ( line.isEmpty() )
185 html_text +=
"</p><p>";
187 html_text +=
" " + line;
196 if ( foundAuthorsList )
197 html_text +=
"</ul>";
208 if ( url.scheme() ==
"pkg" )
210 QString pkgName = url.authority();
211 yuiMilestone() <<
"Hyperlinking to package \"" << pkgName <<
"\"" << endl;
216 yuiError() <<
"Protocol not supported - can't follow hyperlink \"" 217 << url.toString() <<
"\"" << endl;
233 QMap<QString, QString> desktopEntries;
237 if ( desktopFiles.size() == 0 )
242 for (
int i = 0; i < desktopFiles.size(); ++i )
246 QIcon icon = YQUI::ui()->loadIcon( desktopEntries[
"Icon"].toStdString() );
248 if ( ! icon.isNull() )
250 QPixmap pixmap = icon.pixmap(32);
251 QByteArray byteArray;
252 QBuffer buffer(&byteArray);
253 pixmap.save(&buffer,
"PNG");
254 html +=
"<tr><td valign='middle' align='center'>";
255 html += QString(
"<td><img src=\"data:image/png;base64,") + byteArray.toBase64() + QString(
"\">" );
256 html +=
"</td><td valign='middle' align='left'>";
257 html +=
"<b>" + desktopEntries[
"Name"] +
"</b>";
258 html +=
"</td></tr>";
262 if ( ! html.isEmpty() )
264 html = _(
"This package contains: ")
265 +
"<table border='0'>" 270 return "<p>" + html +
"</p>";
274 QMap<QString, QString>
277 QMap<QString, QString> desktopEntries;
278 QString name, genericName;
280 QSettings file( fileName, QSettings::IniFormat );
281 file.setIniCodec(
"UTF-8");
282 file.beginGroup(
"Desktop Entry" );
283 desktopEntries[
"Icon"] = file.value(
"Icon" ).toString();
284 desktopEntries[
"Exec"] = file.value(
"Exec" ).toString();
287 name = file.value( QString(
"Name[%1]" ).arg( langWithCountry ) ).toString();
289 if ( name.isEmpty() )
290 name= file.value( QString(
"Name[%1]" ).arg( lang ) ).toString() ;
292 if ( name.isEmpty() )
294 QFileInfo fileInfo (fileName);
295 QString msgid = QString(
"Name(%1)" ).arg( fileInfo.fileName() );
297 msgid += file.value( QString(
"Name" )).toString();
298 name = QString::fromUtf8( dgettext( DESKTOP_TRANSLATIONS, msgid.toLatin1() ) );
303 if ( name.isEmpty() )
304 name= file.value( QString(
"Name" ) ).toString() ;
305 desktopEntries[
"Name"] = name;
309 return desktopEntries;
316 QStringList desktopFiles;
318 for ( list<string>::const_iterator it = fileList.begin();
319 it != fileList.end(); ++it )
321 QString line = fromUTF8( *it );
323 if ( line.contains( QRegExp( DESKTOPFILEDIR ) ) )
324 desktopFiles << line;
333 const char *lang_cstr = getenv(
"LANG" );
337 langWithCountry = lang_cstr;
338 langWithCountry.replace( QRegExp(
"[@\\.].*$" ),
"" );
340 lang = langWithCountry;
341 lang.replace( QRegExp(
"_.*$" ),
"" );
QMap< QString, QString > readDesktopFile(const QString &fileName) const
Extract name, icon and exec attributes from a desktop file.
QString simpleHtmlParagraphs(QString text)
Format a multi-line text into paragraphs.
YQPkgDescriptionView(QWidget *parent, bool showSupportability=true)
Constructor.
static QString htmlHeading(ZyppSel selectable, bool showVersion=false)
Returns a uniform heading in HTML format for the specified selectable: name and summary or name...
virtual void setSource(const QUrl &name)
Get the document pointed to by a hyperlink.
QString applicationIconList(const list< string > &fileList) const
Return html text that contains a list of application icons.
QStringList findDesktopFiles(const list< string > &fileList) const
Search for all desktop files in a file list.
Abstract base class for details views.
void initLang()
Initialize the language code (lang).
static QString htmlEscape(const QString &plainText)
Escapes characters special to HTML in a ( plain text ) string, such as: '<' -> '<' '>' -> '>' '&' -> ...
static void showDescriptionDialog(const QString &pkgName)
Static convenience method: Post a description dialog for pkg 'pkgName'.
void showLink(const QUrl &url)
Show information for a hyperlinked object, e.g., a "pkg:somepkg" link to another package.
virtual ~YQPkgDescriptionView()
Destructor.
static QString htmlStart()
starts the html tag and set the style
virtual void showDetails(ZyppSel selectable)
Show details for the specified package: In this case the package description.