diff --git a/CMakeLists.txt b/CMakeLists.txt index 98e84e7f..9a39f767 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,5 +31,5 @@ macro_optional_add_subdirectory (knetpkg) macro_optional_add_subdirectory (kfirewall) macro_optional_add_subdirectory (khash) macro_optional_add_subdirectory (kprintjobs) -macro_optional_add_subdirectory (plasma-wallpapers) +macro_optional_add_subdirectory (plasma) macro_optional_add_subdirectory (kdm) diff --git a/plasma-wallpapers/CMakeLists.txt b/plasma-wallpapers/CMakeLists.txt deleted file mode 100644 index 8e228c48..00000000 --- a/plasma-wallpapers/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -project(plasma-wallpapers) - -if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) - include(FeatureSummary) - - find_package(KDELibs4 4.23.0 REQUIRED) - - include_directories(${KDE4_INCLUDES}) - add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) -endif() - -add_subdirectory(anipaper) -add_subdirectory(xwallpaper) \ No newline at end of file diff --git a/plasma-runners/CMakeLists.txt b/plasma/CMakeLists.txt similarity index 76% rename from plasma-runners/CMakeLists.txt rename to plasma/CMakeLists.txt index 9c57001f..bf79f9a4 100644 --- a/plasma-runners/CMakeLists.txt +++ b/plasma/CMakeLists.txt @@ -9,4 +9,6 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) endif() -add_subdirectory(sleeper) +add_subdirectory(applets) +add_subdirectory(runners) +add_subdirectory(wallpapers) diff --git a/plasma/applets/CMakeLists.txt b/plasma/applets/CMakeLists.txt new file mode 100644 index 00000000..6a511b73 --- /dev/null +++ b/plasma/applets/CMakeLists.txt @@ -0,0 +1,3 @@ +project(plasma-applets) + +add_subdirectory(lsof) \ No newline at end of file diff --git a/plasma/applets/lsof/CMakeLists.txt b/plasma/applets/lsof/CMakeLists.txt new file mode 100644 index 00000000..47f2c843 --- /dev/null +++ b/plasma/applets/lsof/CMakeLists.txt @@ -0,0 +1,22 @@ +project(plasma-lsof) + +set(lsof_SRCS + lsof.cpp +) + +kde4_add_plugin(plasma_applet_lsof ${lsof_SRCS}) +target_link_libraries(plasma_applet_lsof + KDE4::plasma + KDE4::solid + ksgrd +) + +install( + TARGETS plasma_applet_lsof + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} +) + +install( + FILES plasma-applet-lsof.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR} +) diff --git a/plasma/applets/lsof/lsof.cpp b/plasma/applets/lsof/lsof.cpp new file mode 100644 index 00000000..fe248c31 --- /dev/null +++ b/plasma/applets/lsof/lsof.cpp @@ -0,0 +1,272 @@ +/* + This file is part of the KDE project + Copyright (C) 2024 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 "lsof.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// TODO: option for it +static const int s_updatetimeout = 2000; // ms +static const QStringList s_lsofargs = QStringList() << QLatin1String("-Fftn"); +// keeps things interactive, somewhat +static const int s_processtime = 50; + +class LsofData +{ +public: + LsofData(); + + QByteArray lsoffd; + QByteArray lsoftype; + QByteArray lsofpid; + QByteArray lsofname; + QTreeWidgetItem* lsofitem; + + bool operator==(const LsofData &other) const; +}; + +LsofData::LsofData() + : lsofitem(nullptr) +{ +} + +bool LsofData::operator==(const LsofData &other) const +{ + return ( + lsoffd == other.lsoffd && lsoftype == other.lsoftype + && lsofpid == other.lsofpid && lsofname == other.lsofname + && lsofitem == other.lsofitem + ); +} + +class LsofWidget : public QGraphicsWidget +{ + Q_OBJECT +public: + LsofWidget(Lsof* lsof); + ~LsofWidget(); + +public Q_SLOTS: + void slotUpdateLayout(); + +private Q_SLOTS: + void slotFinished(int exitcode); + void slotTimeout(); + +private: + QMutex m_mutex; + Lsof* m_lsof; + QGraphicsLinearLayout* m_layout; + Plasma::TreeWidget* m_treewidget; + QTreeWidget* m_treewidgetnative; + QProcess* m_lsofproc; + QTimer* m_timer; + QString m_lsofexe; + QList m_lsofdata; +}; + + +LsofWidget::LsofWidget(Lsof* lsof) + : QGraphicsWidget(lsof), + m_lsof(lsof), + m_layout(nullptr), + m_treewidget(nullptr), + m_treewidgetnative(nullptr), + m_lsofproc(nullptr) +{ + m_layout = new QGraphicsLinearLayout(this); + + const QStringList treeheaders = QStringList() + << i18n("File Descriptor") + << i18n("Type") + << i18n("PID") + << i18n("Name"); + m_treewidget = new Plasma::TreeWidget(this); + m_treewidgetnative = m_treewidget->nativeWidget(); + m_treewidgetnative->setHeaderLabels(treeheaders); + m_treewidgetnative->setRootIsDecorated(false); + m_treewidgetnative->header()->setMovable(false); + m_treewidgetnative->header()->setStretchLastSection(true); + m_treewidgetnative->header()->setResizeMode(0, QHeaderView::ResizeToContents); + m_treewidgetnative->header()->setResizeMode(1, QHeaderView::ResizeToContents); + m_treewidgetnative->header()->setResizeMode(2, QHeaderView::ResizeToContents); + m_treewidgetnative->header()->setResizeMode(3, QHeaderView::Stretch); + m_layout->addItem(m_treewidget); + + setLayout(m_layout); + + m_lsofproc = new QProcess(this); + connect(m_lsofproc, SIGNAL(finished(int)), this, SLOT(slotFinished(int))); + + m_timer = new QTimer(this); + m_timer->setInterval(s_updatetimeout); + connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout())); +} + +LsofWidget::~LsofWidget() +{ + m_timer->stop(); +} + +void LsofWidget::slotUpdateLayout() +{ + m_timer->stop(); + m_treewidgetnative->clear(); + m_lsofexe = KStandardDirs::findExe("lsof"); + if (m_lsofexe.isEmpty()) { + m_lsof->showMessage( + KIcon("dialog-warning"), + i18n("Could not find lsof program"), + Plasma::ButtonOk + ); + return; + } + m_timer->start(); +} + +void LsofWidget::slotFinished(int exitcode) +{ + kDebug() << "lsof finished" << exitcode; + m_timer->stop(); + int lsofcounter = 0; + LsofData lsofdata; + QList currentlsofdata; + QByteArray lsofline = m_lsofproc->readLine(); + while (!lsofline.isEmpty()) { + // qDebug() << Q_FUNC_INFO << lsofline; + const char lsoflinetype = lsofline.at(0); + switch (lsoflinetype) { + case 'f': { + lsofdata.lsoffd = lsofline.mid(1, lsofline.size() - 1); + lsofcounter++; + break; + } + case 't': { + lsofdata.lsoftype = lsofline.mid(1, lsofline.size() - 1); + lsofcounter++; + break; + } + case 'p': { + lsofdata.lsofpid = lsofline.mid(1, lsofline.size() - 1); + lsofcounter++; + break; + } + case 'n': { + lsofdata.lsofname = lsofline.mid(1, lsofline.size() - 1); + lsofcounter++; + break; + } + default: { + kWarning() << "invalid lsof line" << lsofline; + lsofcounter = 0; + lsofdata.lsoffd.clear(); + lsofdata.lsoftype.clear(); + lsofdata.lsofpid.clear(); + lsofdata.lsofname.clear(); + break; + } + } + if (lsofcounter >= 4) { + currentlsofdata.append(lsofdata); + } + QApplication::processEvents(QEventLoop::AllEvents, s_processtime); + lsofline = m_lsofproc->readLine(); + } + + QMutableListIterator iter(m_lsofdata); + while (iter.hasNext()) { + const LsofData itercurrent = iter.next(); + if (currentlsofdata.contains(itercurrent)) { + currentlsofdata.removeOne(itercurrent); + QApplication::processEvents(QEventLoop::AllEvents, s_processtime); + continue; + } + iter.remove(); + delete itercurrent.lsofitem; + QApplication::processEvents(QEventLoop::AllEvents, s_processtime); + } + + foreach (const LsofData lsofdata, currentlsofdata) { + const QStringList lsofitemstrings = QStringList() + << QString::fromLatin1(lsofdata.lsoffd.constData(), lsofdata.lsoffd.size()) + << QString::fromLatin1(lsofdata.lsoftype.constData(), lsofdata.lsoftype.size()) + << QString::fromLatin1(lsofdata.lsofpid.constData(), lsofdata.lsofpid.size()) + << QString::fromLatin1(lsofdata.lsofname.constData(), lsofdata.lsofname.size()); + QTreeWidgetItem* lsofitem = new QTreeWidgetItem(m_treewidgetnative, lsofitemstrings); + lsofitem->setTextAlignment(0, Qt::AlignLeft | Qt::AlignVCenter); + lsofitem->setTextAlignment(1, Qt::AlignLeft | Qt::AlignVCenter); + lsofitem->setTextAlignment(2, Qt::AlignLeft | Qt::AlignVCenter); + lsofitem->setTextAlignment(3, Qt::AlignLeft | Qt::AlignVCenter); + lsofitem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + m_treewidgetnative->addTopLevelItem(lsofitem); + QApplication::processEvents(QEventLoop::AllEvents, s_processtime); + } + + m_lsofdata = currentlsofdata; + m_timer->start(); +} + +void LsofWidget::slotTimeout() +{ + m_lsofproc->terminate(); + m_lsofproc->start(m_lsofexe, s_lsofargs); +} + +Lsof::Lsof(QObject *parent, const QVariantList &args) + : Plasma::PopupApplet(parent, args), + m_lsofwidget(nullptr) +{ + setAspectRatioMode(Plasma::IgnoreAspectRatio); + setPopupIcon("media-playlist-repeat"); + // NOTE: no check has to be done if it is installed + setAssociatedApplication("ksysguard"); + adjustSize(); +} + +Lsof::~Lsof() +{ + delete m_lsofwidget; +} + +void Lsof::init() +{ + Plasma::PopupApplet::init(); + m_lsofwidget = new LsofWidget(this); + QTimer::singleShot(500, m_lsofwidget, SLOT(slotUpdateLayout())); +} + +QGraphicsWidget *Lsof::graphicsWidget() +{ + return m_lsofwidget; +} + +K_EXPORT_PLASMA_APPLET(lsof, Lsof) + +#include "moc_lsof.cpp" +#include "lsof.moc" diff --git a/plasma/applets/lsof/lsof.h b/plasma/applets/lsof/lsof.h new file mode 100644 index 00000000..14924cd3 --- /dev/null +++ b/plasma/applets/lsof/lsof.h @@ -0,0 +1,45 @@ +/* + This file is part of the KDE project + Copyright (C) 2024 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 LSOF_H +#define LSOF_H + + +#include + +class LsofWidget; + +class Lsof : public Plasma::PopupApplet +{ + Q_OBJECT +public: + Lsof(QObject *parent, const QVariantList &args); + ~Lsof(); + + // Plasma::Applet reimplementations + void init() final; + // Plasma::PopupApplet reimplementation + QGraphicsWidget* graphicsWidget() final; + +private: + friend LsofWidget; + LsofWidget *m_lsofwidget; +}; + +#endif // LSOF_H diff --git a/plasma/applets/lsof/plasma-applet-lsof.desktop b/plasma/applets/lsof/plasma-applet-lsof.desktop new file mode 100644 index 00000000..2a45e17f --- /dev/null +++ b/plasma/applets/lsof/plasma-applet-lsof.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Name=Open Files +Comment=List of open files +Type=Service +Icon=media-playlist-repeat +ServiceTypes=Plasma/Applet + +X-KDE-Library=plasma_applet_lsof +X-KDE-PluginInfo-Author=Ivailo Monev +X-KDE-PluginInfo-Email=xakepa10@gmail.com +X-KDE-PluginInfo-Name=lsof_applet +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category=System Information +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true diff --git a/plasma/runners/CMakeLists.txt b/plasma/runners/CMakeLists.txt new file mode 100644 index 00000000..898cb860 --- /dev/null +++ b/plasma/runners/CMakeLists.txt @@ -0,0 +1,3 @@ +project(plasma-runners) + +add_subdirectory(sleeper) diff --git a/plasma-runners/sleeper/CMakeLists.txt b/plasma/runners/sleeper/CMakeLists.txt similarity index 100% rename from plasma-runners/sleeper/CMakeLists.txt rename to plasma/runners/sleeper/CMakeLists.txt diff --git a/plasma-runners/sleeper/krunner_sleeper.cpp b/plasma/runners/sleeper/krunner_sleeper.cpp similarity index 100% rename from plasma-runners/sleeper/krunner_sleeper.cpp rename to plasma/runners/sleeper/krunner_sleeper.cpp diff --git a/plasma-runners/sleeper/krunner_sleeper.h b/plasma/runners/sleeper/krunner_sleeper.h similarity index 100% rename from plasma-runners/sleeper/krunner_sleeper.h rename to plasma/runners/sleeper/krunner_sleeper.h diff --git a/plasma-runners/sleeper/plasma-runner-sleeper.desktop b/plasma/runners/sleeper/plasma-runner-sleeper.desktop similarity index 100% rename from plasma-runners/sleeper/plasma-runner-sleeper.desktop rename to plasma/runners/sleeper/plasma-runner-sleeper.desktop diff --git a/plasma/wallpapers/CMakeLists.txt b/plasma/wallpapers/CMakeLists.txt new file mode 100644 index 00000000..b1539a7f --- /dev/null +++ b/plasma/wallpapers/CMakeLists.txt @@ -0,0 +1,4 @@ +project(plasma-wallpapers) + +add_subdirectory(anipaper) +add_subdirectory(xwallpaper) \ No newline at end of file diff --git a/plasma-wallpapers/anipaper/CMakeLists.txt b/plasma/wallpapers/anipaper/CMakeLists.txt similarity index 100% rename from plasma-wallpapers/anipaper/CMakeLists.txt rename to plasma/wallpapers/anipaper/CMakeLists.txt diff --git a/plasma-wallpapers/anipaper/anipaper.cpp b/plasma/wallpapers/anipaper/anipaper.cpp similarity index 100% rename from plasma-wallpapers/anipaper/anipaper.cpp rename to plasma/wallpapers/anipaper/anipaper.cpp diff --git a/plasma-wallpapers/anipaper/anipaper.h b/plasma/wallpapers/anipaper/anipaper.h similarity index 100% rename from plasma-wallpapers/anipaper/anipaper.h rename to plasma/wallpapers/anipaper/anipaper.h diff --git a/plasma-wallpapers/anipaper/plasma-wallpaper-anipaper.desktop b/plasma/wallpapers/anipaper/plasma-wallpaper-anipaper.desktop similarity index 100% rename from plasma-wallpapers/anipaper/plasma-wallpaper-anipaper.desktop rename to plasma/wallpapers/anipaper/plasma-wallpaper-anipaper.desktop diff --git a/plasma-wallpapers/xwallpaper/CMakeLists.txt b/plasma/wallpapers/xwallpaper/CMakeLists.txt similarity index 100% rename from plasma-wallpapers/xwallpaper/CMakeLists.txt rename to plasma/wallpapers/xwallpaper/CMakeLists.txt diff --git a/plasma-wallpapers/xwallpaper/plasma-wallpaper-xwallpaper.desktop b/plasma/wallpapers/xwallpaper/plasma-wallpaper-xwallpaper.desktop similarity index 100% rename from plasma-wallpapers/xwallpaper/plasma-wallpaper-xwallpaper.desktop rename to plasma/wallpapers/xwallpaper/plasma-wallpaper-xwallpaper.desktop diff --git a/plasma-wallpapers/xwallpaper/xwallpaper.cpp b/plasma/wallpapers/xwallpaper/xwallpaper.cpp similarity index 100% rename from plasma-wallpapers/xwallpaper/xwallpaper.cpp rename to plasma/wallpapers/xwallpaper/xwallpaper.cpp diff --git a/plasma-wallpapers/xwallpaper/xwallpaper.h b/plasma/wallpapers/xwallpaper/xwallpaper.h similarity index 100% rename from plasma-wallpapers/xwallpaper/xwallpaper.h rename to plasma/wallpapers/xwallpaper/xwallpaper.h