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().sprintf(
"<li>%s (%s) : %s</li>", rit.id().c_str(), rit.type().c_str(), rit.title().c_str() );
119 html_text +=
"</ul>";
123 Package::constPtr
package = asKind<Package>(selectable->theObj());
124 if ( _showSupportability && package )
128 html_text += _(
"Supportability: %1").arg( fromUTF8(asUserString(package->vendorSupport()).c_str() ));
133 ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
139 zypp::Package::FileList f( installed->filelist() );
140 std::list<std::string> tmp( f.begin(), f.end() );
144 html_text += htmlEnd();
145 setHtml( html_text );
153 bool foundAuthorsList =
false;
154 QString html_text =
"<p>";
156 QStringList lines = text.trimmed().split(
'\n', QString::KeepEmptyParts );
157 QStringList::const_iterator it = lines.begin();
159 while ( it != lines.end() )
163 if ( line.startsWith(
"* ") || line.startsWith(
"- ") || line.startsWith(
"# ") )
165 line =
"<li>" + line +
"</li>";
168 if ( line.startsWith(
"Authors:" ) )
170 line =
"<p><b>" + line +
"</b><ul>";
171 foundAuthorsList =
true;
174 if ( foundAuthorsList )
176 if ( ! line.startsWith(
"-----" ) && ! line.isEmpty() )
177 html_text +=
"<li>" + line +
"</li>";
181 if ( line.isEmpty() )
182 html_text +=
"</p><p>";
184 html_text +=
" " + line;
193 if ( foundAuthorsList )
194 html_text +=
"</ul>";
205 if ( url.scheme() ==
"pkg" )
207 QString pkgName = url.authority();
208 yuiMilestone() <<
"Hyperlinking to package \"" << pkgName <<
"\"" << endl;
213 yuiError() <<
"Protocol not supported - can't follow hyperlink \"" 214 << url.toString() <<
"\"" << endl;
230 QMap<QString, QString> desktopEntries;
234 if ( desktopFiles.size() == 0 )
239 for (
int i = 0; i < desktopFiles.size(); ++i )
243 QIcon icon = YQUI::ui()->loadIcon( desktopEntries[
"Icon"].toStdString() );
245 if ( ! icon.isNull() )
247 QPixmap pixmap = icon.pixmap(32);
248 QByteArray byteArray;
249 QBuffer buffer(&byteArray);
250 pixmap.save(&buffer,
"PNG");
251 html +=
"<tr><td valign='middle' align='center'>";
252 html += QString(
"<td><img src=\"data:image/png;base64,") + byteArray.toBase64() + QString(
"\">" );
253 html +=
"</td><td valign='middle' align='left'>";
254 html +=
"<b>" + desktopEntries[
"Name"] +
"</b>";
255 html +=
"</td></tr>";
259 if ( ! html.isEmpty() )
261 html = _(
"This package contains: ")
262 +
"<table border='0'>" 267 return "<p>" + html +
"</p>";
271 QMap<QString, QString>
274 QMap<QString, QString> desktopEntries;
275 QString name, genericName;
277 QSettings file( fileName, QSettings::IniFormat );
278 file.setIniCodec(
"UTF-8");
279 file.beginGroup(
"Desktop Entry" );
280 desktopEntries[
"Icon"] = file.value(
"Icon" ).toString();
281 desktopEntries[
"Exec"] = file.value(
"Exec" ).toString();
284 name = file.value( QString(
"Name[%1]" ).arg( langWithCountry ) ).toString();
286 if ( name.isEmpty() )
287 name= file.value( QString(
"Name[%1]" ).arg( lang ) ).toString() ;
289 if ( name.isEmpty() )
291 QFileInfo fileInfo (fileName);
292 QString msgid = QString(
"Name(%1)" ).arg( fileInfo.fileName() );
294 msgid += file.value( QString(
"Name" )).toString();
295 name = QString::fromUtf8( dgettext( DESKTOP_TRANSLATIONS, msgid.toLatin1() ) );
300 if ( name.isEmpty() )
301 name= file.value( QString(
"Name" ) ).toString() ;
302 desktopEntries[
"Name"] = name;
306 return desktopEntries;
313 QStringList desktopFiles;
315 for ( list<string>::const_iterator it = fileList.begin();
316 it != fileList.end(); ++it )
318 QString line = fromUTF8( *it );
320 if ( line.contains( QRegExp( DESKTOPFILEDIR ) ) )
321 desktopFiles << line;
330 const char *lang_cstr = getenv(
"LANG" );
334 langWithCountry = lang_cstr;
335 langWithCountry.replace( QRegExp(
"[@\\.].*$" ),
"" );
337 lang = langWithCountry;
338 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.