knetpkg: display the contents information instead of the description

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-04-24 13:48:01 +00:00
parent c73a5eef40
commit 8d192bc45b
3 changed files with 53 additions and 21 deletions

View file

@ -39,11 +39,11 @@ KNetPkg::KNetPkg(QWidget *parent)
foreach (const QFileInfo &netpkginfo, netpkgdir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs)) {
KNetPkgInfo knetpkginfo;
knetpkginfo.name = netpkginfo.fileName().toLocal8Bit();
QFile netpkgdesc(netpkginfo.filePath() + QLatin1String("/+DESC"));
if (netpkgdesc.open(QFile::ReadOnly)) {
knetpkginfo.description = netpkgdesc.readAll();
QFile netpkgcomment(netpkginfo.filePath() + QLatin1String("/+COMMENT"));
if (netpkgcomment.open(QFile::ReadOnly)) {
knetpkginfo.comment = netpkgcomment.readAll().trimmed();
} else {
kWarning() << "No description for" << netpkginfo.filePath();
kWarning() << "No comment for" << netpkginfo.filePath();
}
QFile netpkgrequiredby(netpkginfo.filePath() + QLatin1String("/+REQUIRED_BY"));
if (netpkgrequiredby.open(QFile::ReadOnly)) {
@ -66,6 +66,22 @@ KNetPkg::KNetPkg(QWidget *parent)
} else {
kWarning() << "No size for" << netpkginfo.filePath();
}
QFile netpkgcontents(netpkginfo.filePath() + QLatin1String("/+CONTENTS"));
if (netpkgcontents.open(QFile::ReadOnly)) {
knetpkginfo.contents = netpkgcontents.readAll().trimmed();
const QList<QByteArray> contentslist = knetpkginfo.contents.split('\n');
knetpkginfo.contents.clear();
for (int i = 0; i < contentslist.size(); i++) {
const QByteArray contentsline = contentslist.at(i);
if (contentsline.isEmpty() || contentsline.startsWith('@') || contentsline.startsWith('+')) {
continue;
}
knetpkginfo.contents.append(contentsline);
knetpkginfo.contents.append('\n');
}
} else {
kWarning() << "No comment for" << netpkginfo.filePath();
}
m_packages.append(knetpkginfo);
}
@ -93,9 +109,10 @@ void KNetPkg::slotCurrentTextChanged(const QString &netpkg)
// qDebug() << Q_FUNC_INFO << netpkg;
foreach (const KNetPkgInfo &knetpkginfo, m_packages) {
if (knetpkginfo.name == netpkg) {
m_ui.commentlabel->setText(knetpkginfo.comment);
m_ui.requiredbylabel->setText(knetpkginfo.requiredby);
m_ui.sizelabel->setText(KGlobal::locale()->formatByteSize(knetpkginfo.size.toDouble(), 1));
m_ui.descriptionwidget->setText(knetpkginfo.description);
m_ui.contentswidget->setText(knetpkginfo.contents);
return;
}
}

View file

@ -25,9 +25,10 @@
struct KNetPkgInfo {
QByteArray name;
QByteArray description;
QByteArray comment;
QByteArray requiredby;
QByteArray size;
QByteArray contents;
};
class KNetPkg : public KMainWindow

View file

@ -42,17 +42,7 @@
<string>Information</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0" colspan="2">
<widget class="KRichTextWidget" name="descriptionwidget">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="acceptRichText">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QLabel" name="requiredbylabel">
<property name="text">
<string/>
@ -62,7 +52,21 @@
</property>
</widget>
</item>
<item row="0" column="0">
<item row="3" column="0" colspan="2">
<widget class="KRichTextWidget" name="contentswidget">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="sizelabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
@ -78,7 +82,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@ -94,8 +98,18 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="sizelabel">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Comment:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="commentlabel">
<property name="text">
<string/>
</property>