42 #define YUILogComponent "qt-pkg"
49 #include "zypp/VendorSupportOptions.h"
50 #include "YQPkgDescriptionView.h"
51 #include "YQPkgDescriptionDialog.h"
55 #define DESKTOP_TRANSLATIONS "desktop_translations"
56 #define DESKTOPFILEDIR "\\/share\\/applications\\/.*\\.desktop$" // RegExp
57 #define ICONSIZE "32x32"
58 #define ICONPATH "/usr/share/icons/locolor/" ICONSIZE "/apps/" \
59 << "/usr/share/icons/hicolor/" ICONSIZE "/apps/" \
60 << "/usr/share/icons/oxygen/" ICONSIZE "/apps/" \
61 << "/usr/share/icons/Tango/" ICONSIZE "/apps/" \
62 << "/usr/share/icons/gnome/" ICONSIZE "/apps/" \
63 << "/opt/kde3/share/icons/hicolor/" ICONSIZE "/apps/";
74 , _showSupportability ( showSupportability )
90 _selectable = selectable;
102 QString description = fromUTF8( selectable->theObj()->description() );
104 if ( ! description.contains(
"<!-- DT:Rich -->" ) )
107 html_text += (
"<p>" + description +
"</p>");
110 Patch::constPtr patch = asKind<Patch>(selectable->theObj());
114 html_text += _(
"References:");
118 for ( Patch::ReferenceIterator rit = patch->referencesBegin();
119 rit != patch->referencesEnd();
122 html_text += QString().sprintf(
"<li>%s (%s) : %s</li>", rit.id().c_str(), rit.type().c_str(), rit.title().c_str() );
124 html_text +=
"</ul>";
128 Package::constPtr
package = asKind<Package>(selectable->theObj());
129 if ( _showSupportability && package )
133 html_text += _(
"Supportability: %1").arg( fromUTF8(asUserString(package->vendorSupport()).c_str() ));
138 ZyppPkg installed = tryCastToZyppPkg( selectable->installedObj() );
144 zypp::Package::FileList f( installed->filelist() );
145 std::list<std::string> tmp( f.begin(), f.end() );
149 html_text += htmlEnd();
150 setHtml( html_text );
158 bool foundAuthorsList =
false;
159 QString html_text =
"<p>";
161 QStringList lines = text.trimmed().split(
'\n', QString::KeepEmptyParts );
162 QStringList::const_iterator it = lines.begin();
164 while ( it != lines.end() )
168 if ( line.startsWith(
"* ") || line.startsWith(
"- ") || line.startsWith(
"# ") )
170 line =
"<li>" + line +
"</li>";
173 if ( line.startsWith(
"Authors:" ) )
175 line =
"<p><b>" + line +
"</b><ul>";
176 foundAuthorsList =
true;
179 if ( foundAuthorsList )
181 if ( ! line.startsWith(
"-----" ) && ! line.isEmpty() )
182 html_text +=
"<li>" + line +
"</li>";
186 if ( line.isEmpty() )
187 html_text +=
"</p><p>";
189 html_text +=
" " + line;
198 if ( foundAuthorsList )
199 html_text +=
"</ul>";
210 if ( url.scheme() ==
"pkg" )
212 QString pkgName = url.authority();
213 yuiMilestone() <<
"Hyperlinking to package \"" << pkgName <<
"\"" << endl;
218 yuiError() <<
"Protocol not supported - can't follow hyperlink \""
219 << url.toString() <<
"\"" << endl;
235 QMap<QString, QString> desktopEntries;
239 if ( desktopFiles.size() == 0 )
244 for (
int i = 0; i < desktopFiles.size(); ++i )
250 if ( ! desktopIcon.isEmpty() )
252 html +=
"<tr><td valign='middle' align='center'>";
253 html += QString(
"<img src=\"" ) + desktopIcon + QString(
"\">" );
254 html +=
"</td><td valign='middle' align='left'>";
255 html +=
"<b>" + desktopEntries[
"Name"] +
"</b>";
256 html +=
"</td></tr>";
260 if ( ! html.isEmpty() )
262 html = _(
"This package contains: ")
263 +
"<table border='0'>"
268 return "<p>" + html +
"</p>";
278 for (
int i=0; i < path.size(); ++i )
280 QString fullName = path[i] + iconName +
".png";
281 QFile file(fullName);
290 QMap<QString, QString>
293 QMap<QString, QString> desktopEntries;
294 QString name, genericName;
296 QSettings file( fileName, QSettings::IniFormat );
297 file.setIniCodec(
"UTF-8");
298 file.beginGroup(
"Desktop Entry" );
299 desktopEntries[
"Icon"] = file.value(
"Icon" ).toString();
300 desktopEntries[
"Exec"] = file.value(
"Exec" ).toString();
303 name = file.value( QString(
"Name[%1]" ).arg( langWithCountry ) ).toString();
305 if ( name.isEmpty() )
306 name= file.value( QString(
"Name[%1]" ).arg( lang ) ).toString() ;
308 if ( name.isEmpty() )
310 QFileInfo fileInfo (fileName);
311 QString msgid = QString(
"Name(%1)" ).arg( fileInfo.fileName() );
313 msgid += file.value( QString(
"Name" )).toString();
314 name = QString::fromUtf8( dgettext( DESKTOP_TRANSLATIONS, msgid.toLatin1() ) );
319 if ( name.isEmpty() )
320 name= file.value( QString(
"Name" ) ).toString() ;
321 desktopEntries[
"Name"] = name;
325 return desktopEntries;
332 QStringList desktopFiles;
334 for ( list<string>::const_iterator it = fileList.begin();
335 it != fileList.end(); ++it )
337 QString line = fromUTF8( *it );
339 if ( line.contains( QRegExp( DESKTOPFILEDIR ) ) )
340 desktopFiles << line;
349 const char *lang_cstr = getenv(
"LANG" );
353 langWithCountry = lang_cstr;
354 langWithCountry.replace( QRegExp(
"[@\\.].*$" ),
"" );
356 lang = langWithCountry;
357 lang.replace( QRegExp(
"_.*$" ),
"" );
362 #include "YQPkgDescriptionView.moc"
QStringList findDesktopFiles(const list< string > &fileList) const
Search for all desktop files in a file list.
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.
Abstract base class for details views.
QString findDesktopIcon(const QString &iconName) const
Find absolute file name (incl.
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: '<' -> '<' '>' -> '>' '&' -> ...
QMap< QString, QString > readDesktopFile(const QString &fileName) const
Extract name, icon and exec attributes from a desktop file.
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.
QString applicationIconList(const list< string > &fileList) const
Return html text that contains a list of application icons.