From 24324917c4ee3bd323b427388c19f4c861e91211 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 30 Jan 2014 16:28:25 +0400 Subject: [PATCH] edited file tree --- PKGBUILD | 16 +- kdeplasma-applets-netctl-monitor.install | 13 + sources/CMakeLists.txt | 15 +- sources/netctl-dataengine/CMakeLists.txt | 27 ++ sources/netctl-dataengine/extsysmon.conf | 13 + sources/netctl-dataengine/extsysmon.cpp | 329 ++++++++++++++++++ sources/netctl-dataengine/extsysmon.h | 45 +++ .../plasma-engine-extsysmon.desktop | 20 ++ 8 files changed, 465 insertions(+), 13 deletions(-) create mode 100644 kdeplasma-applets-netctl-monitor.install create mode 100644 sources/netctl-dataengine/CMakeLists.txt create mode 100644 sources/netctl-dataengine/extsysmon.conf create mode 100644 sources/netctl-dataengine/extsysmon.cpp create mode 100644 sources/netctl-dataengine/extsysmon.h create mode 100644 sources/netctl-dataengine/plasma-engine-extsysmon.desktop diff --git a/PKGBUILD b/PKGBUILD index 03d6933..9307d3a 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,5 +1,4 @@ -# Author: Evgeniy "arcanis" Alexeev -# Maintainer: Evgeniy "arcanis" Alexeev +# Maintainer: Evgeniy "arcanis" Alexeev pkgname=kdeplasma-applets-netctl-monitor _pkgname=netctl-monitor @@ -14,16 +13,21 @@ makedepends=('cmake' 'automoc4') source=(https://github.com/arcan1s/netctlmonitor/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz) install=${pkgname}.install md5sums=('d3ab03ddea1e4793cfc5f35a0f7a5ff1') +_cmakekeys="-DCMAKE_INSTALL_PREFIX=$(kde4-config --prefix) + -DBUILD_GUI:BOOL=1 + -DBUILD_PLASMOID:BOOL=1 + -DCMAKE_BUILD_TYPE=Release" -build () { +prepare() { if [[ -d ${srcdir}/build ]]; then rm -rf "${srcdir}/build" fi mkdir "${srcdir}/build" +} + +build () { cd "${srcdir}/build" - cmake -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` \ - ../${_pkgname} + cmake ${_cmakekeys} ../${_pkgname} make } diff --git a/kdeplasma-applets-netctl-monitor.install b/kdeplasma-applets-netctl-monitor.install new file mode 100644 index 0000000..f90717c --- /dev/null +++ b/kdeplasma-applets-netctl-monitor.install @@ -0,0 +1,13 @@ +post_install() { + kbuildsycoca4 > /dev/null 2>&1 + xdg-icon-resource forceupdate --theme hicolor 2> /dev/null + update-desktop-database -q +} + +post_upgrade() { + post_install +} + +post_remove() { + post_install +} diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 316e23f..8e2a6f0 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -14,9 +14,6 @@ configure_file (${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/ver message (STATUS "Version ${PROJECT_VERSION}") -set (COMPS netctl-gui - netctl-monitor) - # install options option (WITH_DEBUG_MODE "Build with debug mode" OFF) option (BUILD_GUI "Build GUI" ON) @@ -29,7 +26,7 @@ set (CMAKE_VERBOSE_MAKEFILE ON) if ( WITH_DEBUG_MODE ) add_definitions ( -DDEBUG_MODE=1 ) endif () -if ( CMAKE_COMPILER_IS_GNUCXX ) +if (CMAKE_COMPILER_IS_GNUCXX) set (ADD_CXX_FLAGS "-Wall") set (CMAKE_CXX_FLAGS "-O0 ${ADD_CXX_FLAGS}") set (CMAKE_CXX_FLAGS_DEBUG "-g -O0") @@ -38,6 +35,10 @@ else () message ("Unknown compiler") endif () -foreach (COMP ${COMPS}) - add_subdirectory (${COMP}) -endforeach () +if (BUILD_GUI) + add_subdirectory (netctl-gui) +endif () +if (BUILD_PLASMOID) + add_subdirectory (netctl-dataengine) + add_subdirectory (netctl-monitor) +endif () diff --git a/sources/netctl-dataengine/CMakeLists.txt b/sources/netctl-dataengine/CMakeLists.txt new file mode 100644 index 0000000..c0a2cc2 --- /dev/null +++ b/sources/netctl-dataengine/CMakeLists.txt @@ -0,0 +1,27 @@ +# set project name +set (SUBPROJECT plasma_engine_netctl-dataengine) + +# find required libaries +find_package (KDE4 REQUIRED) +include (KDE4Defaults) + +add_definitions (${QT_DEFINITIONS} + ${KDE4_DEFINITIONS}) +include_directories (${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${KDE4_INCLUDES} + ${CMAKE_CURRENT_BINARY_DIR}/../) + +set (PLUGIN_NAME ${SUBPROJECT}) +file (GLOB SUBPROJECT_DESKTOP *.desktop) +file (GLOB SUBPROJECT_SOURCE *.cpp) +file (GLOB SUBPROJECT_CONF *.conf) + +# make +kde4_add_plugin (${PLUGIN_NAME} ${SUBPROJECT_SOURCE}) +target_link_libraries (${PLUGIN_NAME} ${KDE4_KDECORE_LIBS} ${KDE4_PLASMA_LIBS}) + +# install +install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR}) +install (FILES ${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR}) +install (FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR}) diff --git a/sources/netctl-dataengine/extsysmon.conf b/sources/netctl-dataengine/extsysmon.conf new file mode 100644 index 0000000..8bcaf13 --- /dev/null +++ b/sources/netctl-dataengine/extsysmon.conf @@ -0,0 +1,13 @@ +# Configuration file for Extended Systemmonitor DataEngine (v.1.6) +# Uncomment needed lines + +# Set GPU device +# May be 'nvidia' (for nvidia), 'ati' (for ATI RADEON), 'ignore' or 'auto' +#GPUDEV=auto + +# Set block device for hddtemp comma separated or use 'all' +#HDDDEV=all + +# Set MPD settings +#MPDADDRESS=localhost +#MPDPORT=6600 diff --git a/sources/netctl-dataengine/extsysmon.cpp b/sources/netctl-dataengine/extsysmon.cpp new file mode 100644 index 0000000..4d37ef8 --- /dev/null +++ b/sources/netctl-dataengine/extsysmon.cpp @@ -0,0 +1,329 @@ +/*************************************************************************** + * Copyright (C) 2013 by Evgeniy Alekseev * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "extsysmon.h" + +#include +#include +#include + +#include +#include + + +ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args) + : Plasma::DataEngine(parent, args) +{ + Q_UNUSED(args) + + setMinimumPollingInterval(333); + readConfiguration(); +} + +QStringList ExtendedSysMon::sources() const +{ + QStringList source; + source.append(QString("gpu")); + source.append(QString("gputemp")); + source.append(QString("hddtemp")); + source.append(QString("player")); + return source; +} + +bool ExtendedSysMon::readConfiguration() +{ + // pre-setup + FILE *f_out; + f_out = popen("lspci 2> /dev/null", "r"); + char device[256]; + QString dev; + while (fgets(device, 256, f_out) != NULL) + { + dev = QString(device); + if (dev.toLower().contains("nvidia")) + gpudev = QString("nvidia"); + else if (dev.toLower().contains("radeon")) + gpudev = QString("ati"); + } + pclose(f_out); + + f_out = popen("ls -1 /dev/sd[a-z] 2> /dev/null ; ls -1 /dev/hd[a-z] 2> /dev/null", "r"); + while (fgets(device, 256, f_out) != NULL) + { + dev = QString(device).split("\n")[0]; + if (dev[0] == '/') + hdddev.append(dev); + } + pclose(f_out); + + mpdAddress = QString("localhost"); + mpdPort = QString("6600"); + + QString fileStr; + // FIXME: define configuration file + QString confFileName = QString(getenv("HOME")) + QString("/.kde4/share/config/extsysmon.conf"); + QFile confFile(confFileName); + bool exists = confFile.open(QIODevice::ReadOnly); + if (!exists) + { + confFileName = QString("/usr/share/config/extsysmon.conf"); + confFile.setFileName(confFileName); + exists = confFile.open(QIODevice::ReadOnly); + if (!exists) + return false; + } + + while (true) + { + fileStr = QString(confFile.readLine()); + if (confFile.atEnd()) + break; + else if (fileStr[0] != '#') + { + if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) + { + if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("GPUDEV")) + { + if (fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0] == QString("ati")) + gpudev = fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0]; + else if (fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0] == QString("nvidia")) + gpudev = fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0]; + else if (fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0] != QString("auto")) + gpudev = QString("ignore"); + } + else if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("HDDDEV")) + { + if (fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0] != QString("all")) + { + hdddev.clear(); + for (int i=0; i /dev/null | grep Gpu | tail -n1", "r"); + fgets (output, 256, f_out); + if ((output[0] == '\0') || + (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 2)) + value = QString(" N\\A"); + else + { + out = QString(output).split(QString(" "), QString::SkipEmptyParts)[2]; + sprintf (val, "%5.1f", out.left(out.count()-2).toFloat(&ok)); + value = QString(val); + } + pclose(f_out); + } + else if (gpudev == QString("ati")) + { + f_out = popen("aticonfig --od-getclocks 2> /dev/null | grep load | tail -n1", "r"); + fgets (output, 256, f_out); + if ((output[0] == '\0') || + (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 3)) + value = QString(" N\\A"); + else + { + out = QString(output).split(QString(" "), QString::SkipEmptyParts)[3]; + sprintf (val, "%5.1f", out.left(out.count()-2).toFloat(&ok)); + value = QString(val); + } + pclose(f_out); + } + else + { + value = QString(" N\\A"); + } + if (ok == false) + value = QString(" N\\A"); + value = value.split(QString(","), QString::SkipEmptyParts).join(QString(".")); + setData(source, key, value); + } + else if (source == QString("gputemp")) + { + key = QString("GPUTemp"); + if (gpudev == QString("nvidia")) + { + f_out = popen("nvidia-smi -q -d TEMPERATURE 2> /dev/null | grep Gpu | tail -n1", "r"); + fgets (output, 256, f_out); + if ((output[0] == '\0') || + (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 2)) + value = QString(" N\\A"); + else + { + out = QString(output).split(QString(" "), QString::SkipEmptyParts)[2]; + sprintf (val, "%4.1f", out.toFloat(&ok)); + value = QString(val); + } + pclose(f_out); + } + else if (gpudev == QString("ati")) + { + f_out = popen("aticonfig --od-gettemperature 2> /dev/null | grep Temperature | tail -n1", "r"); + fgets (output, 256, f_out); + if ((output[0] == '\0') || + (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 4)) + value = QString(" N\\A"); + else + { + out = QString(output).split(QString(" "), QString::SkipEmptyParts)[4]; + sprintf (val, "%4.1f", out.toFloat(&ok)); + value = QString(val); + } + pclose(f_out); + } + else + { + value = QString(" N\\A"); + } + if (ok == false) + value = QString(" N\\A"); + value = value.split(QString(","), QString::SkipEmptyParts).join(QString(".")); + setData(source, key, value); + } + else if (source == QString("hddtemp")) + { + char command[256], *dev; + QByteArray qb; + for (int i=0; i /dev/null", dev); + f_out = popen(command, "r"); + fgets(output, 256, f_out); + if ((output[0] == '\0') || + (QString(output).split(QString(":"), QString::SkipEmptyParts).count() < 3)) + value = QString(" N\\A"); + else + { + out = QString(output).split(QString(":"), QString::SkipEmptyParts)[2]; + sprintf (val, "%4.1f", out.left(out.count()-4).toFloat(&ok)); + value = QString(val); + } + pclose(f_out); + if (ok == false) + value = QString(" N\\A"); + value = value.split(QString(","), QString::SkipEmptyParts).join(QString(".")); + setData(source, hdddev[i], value); + } + } + else if (source == QString("player")) + { + QProcess player; + QString qoutput; + // qmmp + qoutput = QString(""); + key = QString("qmmp_artist"); + player.start("qmmp --nowplaying %if(%p,%p,Unknown)"); + player.waitForFinished(-1); + qoutput = player.readAllStandardOutput(); + if (qoutput == QString("")) + value = QString("N\\A"); + else + value = qoutput.split(QString("\n"), QString::SkipEmptyParts)[0]; + setData(source, key, value); + qoutput = QString(""); + key = QString("qmmp_title"); + player.start("qmmp --nowplaying %if(%t,%t,Unknown)"); + player.waitForFinished(-1); + qoutput = player.readAllStandardOutput(); + if (qoutput == QString("")) + value = QString("N\\A"); + else + value = qoutput.split(QString("\n"), QString::SkipEmptyParts)[0]; + setData(source, key, value); + // amarok + QString value_artist, qstr; + qoutput = QString(""); + value = QString("N\\A"); + value_artist = QString("N\\A"); + player.start("qdbus org.kde.amarok /Player GetMetadata"); + player.waitForFinished(-1); + qoutput = player.readAllStandardOutput(); + for (int i=0; i /dev/null", \ + mpdAddress.toUtf8().data(), mpdPort.toUtf8().data()); + qoutput = QString(""); + player.start(QString(commandStr)); + player.waitForFinished(-1); + qoutput = player.readAllStandardOutput(); + for (int i=0; i * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef EXTSYSMON_H +#define EXTSYSMON_H + +#include + +class ExtendedSysMon : public Plasma::DataEngine +{ + Q_OBJECT + +public: + ExtendedSysMon(QObject *parent, const QVariantList &args); + +protected: + bool sourceRequestEvent(const QString &name); + bool updateSourceEvent(const QString &source); + bool readConfiguration(); + QStringList sources() const; +// main configuration + QStringList hdddev; + QString gpudev; +// configuration + QString mpdAddress; + QString mpdPort; +}; + +#endif // EXTSYSMON_H diff --git a/sources/netctl-dataengine/plasma-engine-extsysmon.desktop b/sources/netctl-dataengine/plasma-engine-extsysmon.desktop new file mode 100644 index 0000000..caa4567 --- /dev/null +++ b/sources/netctl-dataengine/plasma-engine-extsysmon.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Extended SystemMonitor DataEngine +Comment=Adds gpu, gputemp and hddtemp to DataEngine +ServiceTypes=Plasma/DataEngine +Type=Service +Icon=utilities-system-monitor + +X-KDE-ServiceTypes=Plasma/DataEngine +X-KDE-Library=plasma_engine_extsysmon +X-Plasma-EngineName=ext-sysmon + +X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis +X-KDE-PluginInfo-Email=esalexeev@gmail.com +X-KDE-PluginInfo-Name=ext-sysmon +X-KDE-PluginInfo-Version=1.6 +X-KDE-PluginInfo-Category=System Information +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true