From 4018c9d88660fddcf0c883dfe15820526f4e0c9b Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 24 Apr 2022 10:03:52 +0000 Subject: [PATCH] knetpkg: new utility for NetBSD packages Signed-off-by: Ivailo Monev --- CMakeLists.txt | 3 +- knetpkg/CMakeLists.txt | 30 ++++++++ knetpkg/knetpkg.cpp | 110 +++++++++++++++++++++++++++ knetpkg/knetpkg.desktop | 12 +++ knetpkg/knetpkg.h | 48 ++++++++++++ knetpkg/knetpkg.ui | 159 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 361 insertions(+), 1 deletion(-) create mode 100644 knetpkg/CMakeLists.txt create mode 100644 knetpkg/knetpkg.cpp create mode 100755 knetpkg/knetpkg.desktop create mode 100644 knetpkg/knetpkg.h create mode 100644 knetpkg/knetpkg.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 98f083c9..09c7c54f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,4 +26,5 @@ macro_optional_add_subdirectory (zeroconf-ioslave) macro_optional_add_subdirectory (kdestopspy) macro_optional_add_subdirectory (kvolume) macro_optional_add_subdirectory (ksnapshot) -macro_optional_add_subdirectory (kupdatenotifier) \ No newline at end of file +macro_optional_add_subdirectory (kupdatenotifier) +macro_optional_add_subdirectory (knetpkg) diff --git a/knetpkg/CMakeLists.txt b/knetpkg/CMakeLists.txt new file mode 100644 index 00000000..caf57261 --- /dev/null +++ b/knetpkg/CMakeLists.txt @@ -0,0 +1,30 @@ +project(knetpkg) + +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + find_package(KDE4 4.21.0 REQUIRED) + include(KDE4Defaults) + include_directories(${KDE4_INCLUDES}) + add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) +endif() + +set(knetpkg_SRCS + knetpkg.cpp + knetpkg.ui +) + +add_executable(knetpkg ${knetpkg_SRCS}) + +target_link_libraries(knetpkg + ${KDE4_KDEUI_LIBS} + ${KDE4_KFILE_LIBS} + ${KDE4_KIO_LIBS} +) + +install(TARGETS knetpkg ${INSTALL_TARGETS_DEFAULT_ARGS}) + +########### install files ############### + +install( + PROGRAMS knetpkg.desktop + DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR} +) diff --git a/knetpkg/knetpkg.cpp b/knetpkg/knetpkg.cpp new file mode 100644 index 00000000..675ec0d2 --- /dev/null +++ b/knetpkg/knetpkg.cpp @@ -0,0 +1,110 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include + +#include "knetpkg.h" + +KNetPkg::KNetPkg(QWidget *parent) + : KMainWindow(parent) +{ + m_ui.setupUi(this); + + QDir netpkgdir("/usr/pkg/pkgdb"); + 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(); + } else { + kWarning() << "No description for" << netpkginfo.filePath(); + } + QFile netpkgrequiredby(netpkginfo.filePath() + QLatin1String("/+REQUIRED_BY")); + if (netpkgrequiredby.open(QFile::ReadOnly)) { + knetpkginfo.requiredby = netpkgrequiredby.readAll().trimmed(); + const QList requiredbylist = knetpkginfo.requiredby.split('\n'); + for (int i = 0; i < requiredbylist.size(); i++) { + if (i == 0) { + knetpkginfo.requiredby = requiredbylist.at(i); + } else { + knetpkginfo.requiredby.append(", "); + knetpkginfo.requiredby.append(requiredbylist.at(i)); + } + } + } else { + kDebug() << "No required by for" << netpkginfo.filePath(); + } + QFile netpkgsize(netpkginfo.filePath() + QLatin1String("/+SIZE_PKG")); + if (netpkgsize.open(QFile::ReadOnly)) { + knetpkginfo.size = netpkgsize.readAll().trimmed(); + } else { + kWarning() << "No size for" << netpkginfo.filePath(); + } + m_packages.append(knetpkginfo); + } + + foreach (const KNetPkgInfo &knetpkginfo, m_packages) { + QListWidgetItem* knetpkgitem = new QListWidgetItem(knetpkginfo.name, m_ui.klistwidget); + } + + m_ui.klistwidgetsearchline->setListWidget(m_ui.klistwidget); + connect(m_ui.klistwidget, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(slotItemChanged(QListWidgetItem*))); +} + +KNetPkg::~KNetPkg() +{ +} + +void KNetPkg::slotItemChanged(QListWidgetItem *knetpkgitem) +{ + // qDebug() << Q_FUNC_INFO << knetpkgitem->text(); + foreach (const KNetPkgInfo &knetpkginfo, m_packages) { + if (knetpkginfo.name == knetpkgitem->text()) { + m_ui.requiredbylabel->setText(knetpkginfo.requiredby); + m_ui.sizelabel->setText(KGlobal::locale()->formatByteSize(knetpkginfo.size.toDouble(), 1)); + m_ui.descriptionwidget->setText(knetpkginfo.description); + return; + } + } + Q_ASSERT(false); +} + +int main(int argc, char **argv) +{ + KAboutData aboutData("knetpkg", 0, ki18n("KNetPkg"), + "1.0.0", ki18n("NetBSD package information utility"), KAboutData::License_GPL, + ki18n("(c) 2022 Ivailo Monev")); + aboutData.addAuthor(ki18n("Ivailo Monev"), KLocalizedString(), "xakepa10@gmail.com"); + + KCmdLineArgs::init(argc, argv, &aboutData); + + KApplication app; + + KNetPkg* knetpkg = new KNetPkg(); + knetpkg->show(); + + return app.exec(); +} + +#include "moc_knetpkg.cpp" diff --git a/knetpkg/knetpkg.desktop b/knetpkg/knetpkg.desktop new file mode 100755 index 00000000..4685c430 --- /dev/null +++ b/knetpkg/knetpkg.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Name=KNetPkg +GenericName=NetBSD package information utility +Exec=knetpkg --icon '%i' --caption '%c' %U +Icon=package-x-generic +Type=Application +Terminal=false +StartupNotify=false +X-DocPath=knetpkg/index.html +X-KDE-StartupNotify=true +X-DBUS-StartupType=Multi +Categories=Qt;KDE;Utility; diff --git a/knetpkg/knetpkg.h b/knetpkg/knetpkg.h new file mode 100644 index 00000000..91456251 --- /dev/null +++ b/knetpkg/knetpkg.h @@ -0,0 +1,48 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KNETPKG_H +#define KNETPKG_H + +#include + +#include "ui_knetpkg.h" + +struct KNetPkgInfo { + QByteArray name; + QByteArray description; + QByteArray requiredby; + QByteArray size; +}; + +class KNetPkg : public KMainWindow +{ + Q_OBJECT +public: + explicit KNetPkg(QWidget *parent = 0); + ~KNetPkg(); + +public Q_SLOTS: + void slotItemChanged(QListWidgetItem *knetpkgitem); + +private: + Ui_KNetPkgWindow m_ui; + QList m_packages; +}; + +#endif // KNETPKG_H diff --git a/knetpkg/knetpkg.ui b/knetpkg/knetpkg.ui new file mode 100644 index 00000000..f9cbec7d --- /dev/null +++ b/knetpkg/knetpkg.ui @@ -0,0 +1,159 @@ + + + KNetPkgWindow + + + + 0 + 0 + 690 + 339 + + + + KNetPkg + + + + + + + + + + + + + + + + 0 + 0 + + + + Information + + + + + + true + + + true + + + + + + + + + + true + + + + + + + + 0 + 0 + + + + Required by: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + + + 0 + 0 + + + + Search: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + + + + + + 0 + 0 + 690 + 21 + + + + + + + + KListWidgetSearchLine + +
klistwidgetsearchline.h
+
+ + KListWidget + +
klistwidget.h
+
+ + KRichTextWidget + +
krichtextwidget.h
+
+
+ + +