mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 10:22:50 +00:00
knetpkg: new utility for NetBSD packages
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
065131867d
commit
4018c9d886
6 changed files with 361 additions and 1 deletions
|
@ -26,4 +26,5 @@ macro_optional_add_subdirectory (zeroconf-ioslave)
|
||||||
macro_optional_add_subdirectory (kdestopspy)
|
macro_optional_add_subdirectory (kdestopspy)
|
||||||
macro_optional_add_subdirectory (kvolume)
|
macro_optional_add_subdirectory (kvolume)
|
||||||
macro_optional_add_subdirectory (ksnapshot)
|
macro_optional_add_subdirectory (ksnapshot)
|
||||||
macro_optional_add_subdirectory (kupdatenotifier)
|
macro_optional_add_subdirectory (kupdatenotifier)
|
||||||
|
macro_optional_add_subdirectory (knetpkg)
|
||||||
|
|
30
knetpkg/CMakeLists.txt
Normal file
30
knetpkg/CMakeLists.txt
Normal file
|
@ -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}
|
||||||
|
)
|
110
knetpkg/knetpkg.cpp
Normal file
110
knetpkg/knetpkg.cpp
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/* This file is part of the KDE project
|
||||||
|
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||||
|
|
||||||
|
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 <QDir>
|
||||||
|
#include <kapplication.h>
|
||||||
|
#include <klocale.h>
|
||||||
|
#include <kcmdlineargs.h>
|
||||||
|
#include <kaboutdata.h>
|
||||||
|
#include <kdebug.h>
|
||||||
|
|
||||||
|
#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<QByteArray> 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"
|
12
knetpkg/knetpkg.desktop
Executable file
12
knetpkg/knetpkg.desktop
Executable file
|
@ -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;
|
48
knetpkg/knetpkg.h
Normal file
48
knetpkg/knetpkg.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/* This file is part of the KDE project
|
||||||
|
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||||
|
|
||||||
|
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 <kmainwindow.h>
|
||||||
|
|
||||||
|
#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<KNetPkgInfo> m_packages;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // KNETPKG_H
|
159
knetpkg/knetpkg.ui
Normal file
159
knetpkg/knetpkg.ui
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
<?xml version="1.0" encoding="System"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>KNetPkgWindow</class>
|
||||||
|
<widget class="QMainWindow" name="KNetPkgWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>690</width>
|
||||||
|
<height>339</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>KNetPkg</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset theme="package-x-generic">
|
||||||
|
<normaloff/>
|
||||||
|
</iconset>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="1" colspan="2">
|
||||||
|
<widget class="KListWidgetSearchLine" name="klistwidgetsearchline"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<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">
|
||||||
|
<widget class="QLabel" name="requiredbylabel">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Required by:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Size:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLabel" name="sizelabel">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Search:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="KListWidget" name="klistwidget">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>690</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>KListWidgetSearchLine</class>
|
||||||
|
<extends></extends>
|
||||||
|
<header>klistwidgetsearchline.h</header>
|
||||||
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>KListWidget</class>
|
||||||
|
<extends></extends>
|
||||||
|
<header>klistwidget.h</header>
|
||||||
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>KRichTextWidget</class>
|
||||||
|
<extends></extends>
|
||||||
|
<header>krichtextwidget.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Add table
Reference in a new issue