mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
add support of smartctl (TODO remove qdbus calls)
end work on awesome-widget (prerelease state)
This commit is contained in:
parent
eac1319889
commit
f01fd96cf6
@ -17,6 +17,7 @@
|
||||
|
||||
import QtQuick 2.4
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
import QtQuick.Layouts 1.1
|
||||
import org.kde.plasma.plasmoid 2.0
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
@ -39,7 +40,7 @@ Item {
|
||||
property variant tooltipSettings: {
|
||||
"tooltipNumber": plasmoid.configuration.tooltipNumber,
|
||||
"useTooltipBackground": plasmoid.configuration.useTooltipBackground,
|
||||
"tooltipBackgroung": plasmoid.configuration.tooltipBackgroung,
|
||||
"tooltipBackground": plasmoid.configuration.tooltipBackground,
|
||||
"cpuTooltip": plasmoid.configuration.cpuTooltip,
|
||||
"cpuclTooltip": plasmoid.configuration.cpuclTooltip,
|
||||
"memTooltip": plasmoid.configuration.memTooltip,
|
||||
@ -61,6 +62,14 @@ Item {
|
||||
|
||||
|
||||
// init
|
||||
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
|
||||
Plasmoid.compactRepresentation: Plasmoid.fullRepresentation
|
||||
|
||||
Layout.fillWidth: plasmoid.formFactor != PlasmaCore.Planar
|
||||
Layout.fillHeight: plasmoid.formFactor != PlasmaCore.Planar
|
||||
Layout.minimumHeight: text.height
|
||||
Layout.minimumWidth: text.width
|
||||
|
||||
Plasmoid.icon: "utilities-system-monitor"
|
||||
Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground"
|
||||
Plasmoid.associatedApplication: "ksysguard"
|
||||
@ -68,18 +77,19 @@ Item {
|
||||
PlasmaCore.DataSource {
|
||||
id: systemmonitorDE
|
||||
engine: "systemmonitor"
|
||||
connectedSources: systemmonitorDE.sources
|
||||
interval: plasmoid.configuration.interval
|
||||
|
||||
onNewData: {
|
||||
if (debug) console.log("[main::onNewData] : Update source " + sourceName)
|
||||
|
||||
AWKeys.setDataBySource(sourceName, data, settings)
|
||||
if (AWKeys.setDataBySource(sourceName, data, settings)) disconnectSource(sourceName)
|
||||
}
|
||||
|
||||
onSourceAdded: {
|
||||
if (debug) console.log("[main::onSourceAdded] : Source " + source)
|
||||
|
||||
if (AWKeys.addDevice(source)) systemmonitorDE.connectSource(source)
|
||||
AWKeys.addDevice(source)
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,27 +120,35 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ui
|
||||
Grid {
|
||||
id: mainGrid
|
||||
columns: 1
|
||||
|
||||
Text {
|
||||
id: text
|
||||
height: contentHeight
|
||||
width: contentWidth
|
||||
textFormat: Text.RichText
|
||||
wrapMode: Text.NoWrap
|
||||
|
||||
horizontalAlignment: general.align[plasmoid.configuration.textAlign]
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
|
||||
color: plasmoid.configuration.fontColor
|
||||
font.family: plasmoid.configuration.fontFamily
|
||||
font.italic: plasmoid.configuration.fontStyle == "italic" ? true : false
|
||||
font.pointSize: plasmoid.configuration.fontSize
|
||||
font.weight: general.fontWeight[plasmoid.configuration.fontWeight]
|
||||
horizontalAlignment: general.align[plasmoid.configuration.textAlign]
|
||||
textFormat: Text.RichText
|
||||
|
||||
text: plasmoid.configuration.text
|
||||
|
||||
PlasmaCore.ToolTipArea {
|
||||
id: rootTooltip
|
||||
mainItem: Text {
|
||||
id: tooltip
|
||||
height: 100
|
||||
width: 500
|
||||
mainText: "Awesome Widget"
|
||||
textFormat: Text.RichText
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -138,25 +156,32 @@ Item {
|
||||
Component.onCompleted: {
|
||||
if (debug) console.log("[main::onCompleted]")
|
||||
|
||||
// init submodule
|
||||
AWKeys.initKeys(plasmoid.configuration.text, tooltipSettings)
|
||||
// actions
|
||||
plasmoid.setAction("requestKey", i18n("Request key"), "utilities-system-monitor")
|
||||
plasmoid.setAction("showReadme", i18n("Show README"), "text-x-readme")
|
||||
plasmoid.setAction("checkUpdates", i18n("Check updates"), "system-software-update")
|
||||
// plasmoid.setAction("report", i18n("Mail to developers"), "email")
|
||||
// init submodule
|
||||
Plasmoid.userConfiguringChanged(true)
|
||||
}
|
||||
|
||||
onNeedUpdate: {
|
||||
if (debug) console.log("[main::onNeedUpdate]")
|
||||
|
||||
text.text = AWKeys.parsePattern(plasmoid.configuration.text)
|
||||
// FIXME change to pixmap/image/etc
|
||||
tooltip.image = AWKeys.toolTipImage()
|
||||
tooltip.text = AWKeys.toolTipImage()
|
||||
// update geometry
|
||||
text.update()
|
||||
height = text.contentHeight
|
||||
width = text.contentWidth
|
||||
height = text.height
|
||||
width = text.width
|
||||
update()
|
||||
rootTooltip.height = AWKeys.toolTipSize().height
|
||||
rootTooltip.width = AWKeys.toolTipSize().width
|
||||
}
|
||||
|
||||
Plasmoid.onUserConfiguringChanged: {
|
||||
// init submodule
|
||||
AWKeys.initKeys(plasmoid.configuration.text, tooltipSettings)
|
||||
}
|
||||
|
||||
function action_checkUpdates() {
|
||||
@ -171,6 +196,12 @@ Item {
|
||||
AWActions.showReadme()
|
||||
}
|
||||
|
||||
function action_report() {
|
||||
if (debug) console.log("[main::action_report]")
|
||||
|
||||
AWActions.sendEmail()
|
||||
}
|
||||
|
||||
function action_requestKey() {
|
||||
if (debug) console.log("[main::action_requestKey]")
|
||||
|
||||
|
@ -64,7 +64,7 @@ Item {
|
||||
|
||||
Column {
|
||||
id: pageColumn
|
||||
width: units.gridUnit * 50
|
||||
width: units.gridUnit * 25
|
||||
QtControls.Label {
|
||||
width: parent.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
@ -78,6 +78,7 @@ Item {
|
||||
width: parent.width
|
||||
QtControls.Button {
|
||||
text: i18n("Font")
|
||||
iconName: "font"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.log("[widget::onClicked] : Font button")
|
||||
@ -207,12 +208,17 @@ Item {
|
||||
textPattern.insert(pos, "<p align=\"justify\">" + selected + "</p")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.ComboBox {
|
||||
id: tags
|
||||
model: AWKeys.dictKeys()
|
||||
width: parent.width - addTagButton.width - showValueButton.width
|
||||
}
|
||||
QtControls.Button {
|
||||
id: addTagButton
|
||||
text: i18n("Add")
|
||||
|
||||
onClicked: {
|
||||
@ -225,6 +231,7 @@ Item {
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
id: showValueButton
|
||||
text: i18n("Show value")
|
||||
|
||||
onClicked: {
|
||||
@ -293,5 +300,6 @@ Item {
|
||||
|
||||
// init submodule
|
||||
AWKeys.initKeys(plasmoid.configuration.text, tooltipSettings)
|
||||
tags.model = AWKeys.dictKeys()
|
||||
}
|
||||
}
|
||||
|
@ -79,14 +79,9 @@ void AWActions::runCmd(const QString cmd)
|
||||
}
|
||||
|
||||
|
||||
void AWActions::sendNotification(const QString eventId, const QString message)
|
||||
void AWActions::sendEmail()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Event" << eventId;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Message" << message;
|
||||
|
||||
KNotification *notification = KNotification::event(eventId, QString("Awesome Widget ::: ") + eventId, message);
|
||||
notification->setComponentName(QString("plasma-applet-org.kde.plasma.awesome-widget"));
|
||||
}
|
||||
|
||||
|
||||
@ -199,6 +194,13 @@ void AWActions::writeDataEngineConfiguration(const QMap<QString, QVariant> confi
|
||||
}
|
||||
|
||||
|
||||
void AWActions::sendNotification(const QString eventId, const QString message)
|
||||
{
|
||||
KNotification *notification = KNotification::event(eventId, QString("Awesome Widget ::: ") + eventId, message);
|
||||
notification->setComponentName(QString("plasma-applet-org.kde.plasma.awesome-widget"));
|
||||
}
|
||||
|
||||
|
||||
void AWActions::showUpdates(QString version)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
|
||||
Q_INVOKABLE void checkUpdates();
|
||||
Q_INVOKABLE void runCmd(const QString cmd = QString("/usr/bin/true"));
|
||||
Q_INVOKABLE void sendNotification(const QString eventId, const QString message);
|
||||
Q_INVOKABLE void sendEmail();
|
||||
Q_INVOKABLE void showReadme();
|
||||
// configuration slots
|
||||
Q_INVOKABLE QString getAboutText(const QString type = "header");
|
||||
@ -45,6 +45,9 @@ public:
|
||||
Q_INVOKABLE QMap<QString, QVariant> readDataEngineConfiguration();
|
||||
Q_INVOKABLE void writeDataEngineConfiguration(const QMap<QString, QVariant> configuration);
|
||||
|
||||
public slots:
|
||||
Q_INVOKABLE static void sendNotification(const QString eventId, const QString message);
|
||||
|
||||
private slots:
|
||||
void showUpdates(QString version);
|
||||
void versionReplyRecieved(QNetworkReply *reply);
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
// #include <QBuffer>
|
||||
#include <QBuffer>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
@ -80,15 +80,6 @@ AWKeys::~AWKeys()
|
||||
}
|
||||
|
||||
|
||||
bool AWKeys::checkKeys(const QMap<QString, QVariant> data)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Data" << data;
|
||||
|
||||
return (data.count() != 0);
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initKeys(const QString pattern,
|
||||
const QMap<QString, QVariant> tooltipParams)
|
||||
{
|
||||
@ -101,7 +92,7 @@ void AWKeys::initKeys(const QString pattern,
|
||||
keys.clear();
|
||||
foundBars.clear();
|
||||
foundKeys.clear();
|
||||
toolTip = nullptr;
|
||||
if (toolTip != nullptr) delete toolTip;
|
||||
|
||||
// init
|
||||
extScripts = getExtScripts();
|
||||
@ -130,6 +121,7 @@ QString AWKeys::parsePattern(const QString pattern)
|
||||
if (!ready) return pattern;
|
||||
|
||||
QString parsed = pattern;
|
||||
parsed.replace(QString(" "), QString(" "));
|
||||
parsed.replace(QString("$$"), QString("$\\$\\"));
|
||||
for (int i=0; i<foundKeys.count(); i++)
|
||||
parsed.replace(QString("$") + foundKeys[i], valueByKey(foundKeys[i]));
|
||||
@ -141,17 +133,26 @@ QString AWKeys::parsePattern(const QString pattern)
|
||||
}
|
||||
|
||||
|
||||
QPixmap AWKeys::toolTipImage()
|
||||
QString AWKeys::toolTipImage()
|
||||
{
|
||||
if(debug) qDebug() << PDEBUG;
|
||||
|
||||
if (!ready) return QPixmap();
|
||||
if (!ready) return QString();
|
||||
|
||||
return toolTip->image();
|
||||
// QByteArray byteArray;
|
||||
// QBuffer buffer(&byteArray);
|
||||
// tooltip.save(&buffer, "PNG");
|
||||
// return QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
|
||||
QPixmap tooltip = toolTip->image();
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
tooltip.save(&buffer, "PNG");
|
||||
|
||||
return QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
|
||||
}
|
||||
|
||||
|
||||
QSize AWKeys::toolTipSize()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return toolTip->getSize();
|
||||
}
|
||||
|
||||
|
||||
@ -672,6 +673,9 @@ bool AWKeys::setDataBySource(const QString sourceName,
|
||||
values[QString("cuptime")].replace(QString("$h"), QString("%1").arg(hours));
|
||||
values[QString("cuptime")].replace(QString("$mm"), QString("%1").arg(minutes, 2, 10, QChar('0')));
|
||||
values[QString("cuptime")].replace(QString("$m"), QString("%1").arg(minutes));
|
||||
} else {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Source not found";
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -954,6 +958,15 @@ void AWKeys::copyUpgrade(const QString original)
|
||||
}
|
||||
|
||||
|
||||
bool AWKeys::checkKeys(const QMap<QString, QVariant> data)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Data" << data;
|
||||
|
||||
return (data.count() != 0);
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::networkDevice()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QPixmap>
|
||||
#include <QPushButton>
|
||||
#include <QVariant>
|
||||
|
||||
@ -50,12 +49,12 @@ public:
|
||||
AWKeys(QObject *parent = 0);
|
||||
~AWKeys();
|
||||
|
||||
Q_INVOKABLE bool checkKeys(const QMap<QString, QVariant> data);
|
||||
Q_INVOKABLE void initKeys(const QString pattern,
|
||||
const QMap<QString, QVariant> tooltipParams);
|
||||
Q_INVOKABLE bool isDebugEnabled();
|
||||
Q_INVOKABLE QString parsePattern(const QString pattern);
|
||||
Q_INVOKABLE QPixmap toolTipImage();
|
||||
Q_INVOKABLE QString toolTipImage();
|
||||
Q_INVOKABLE QSize toolTipSize();
|
||||
// keys
|
||||
Q_INVOKABLE bool addDevice(const QString source);
|
||||
Q_INVOKABLE QStringList dictKeys();
|
||||
@ -82,6 +81,7 @@ private slots:
|
||||
|
||||
private:
|
||||
// methods
|
||||
bool checkKeys(const QMap<QString, QVariant> data);
|
||||
QString networkDevice();
|
||||
int numberCpus();
|
||||
float temperature(const float temp, const QString units = QString("Celsius"));
|
||||
|
@ -56,6 +56,8 @@ AWToolTip::AWToolTip(QObject *parent,
|
||||
boundaries[QString("downTooltip")] = 1.0;
|
||||
boundaries[QString("upTooltip")] = 1.0;
|
||||
boundaries[QString("batTooltip")] = 100.0;
|
||||
size.setHeight(105.0);
|
||||
size.setWidth(100.0 * counts);
|
||||
|
||||
if (configuration[QString("cpuTooltip")].toBool()) requiredKeys.append(QString("cpuTooltip"));
|
||||
if (configuration[QString("cpuclTooltip")].toBool()) requiredKeys.append(QString("cpuclTooltip"));
|
||||
@ -76,17 +78,25 @@ AWToolTip::~AWToolTip()
|
||||
}
|
||||
|
||||
|
||||
QSize AWToolTip::getSize()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
QPixmap AWToolTip::image()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
toolTipView->resize(100.0 * counts, 105.0);
|
||||
toolTipView->resize(size);
|
||||
// create image
|
||||
toolTipScene->clear();
|
||||
QPen pen = QPen();
|
||||
// background
|
||||
if (configuration[QString("useTooltipBackground")].toBool())
|
||||
toolTipScene->setBackgroundBrush(QColor(configuration[QString("tooltipBackground")].toString()));
|
||||
toolTipScene->setBackgroundBrush(QBrush(QColor(configuration[QString("tooltipBackground")].toString())));
|
||||
else
|
||||
toolTipScene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
bool down = false;
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
QMap<QString, QVariant> settings = QMap<QString, QVariant>());
|
||||
~AWToolTip();
|
||||
|
||||
QSize getSize();
|
||||
QPixmap image();
|
||||
void setData(const QString source, float value,
|
||||
const bool ac = true);
|
||||
@ -51,6 +52,7 @@ private:
|
||||
QMap<QString, float> boundaries;
|
||||
QMap<QString, QList<float>> data;
|
||||
QStringList requiredKeys;
|
||||
QSize size;
|
||||
};
|
||||
|
||||
|
||||
|
@ -449,11 +449,23 @@ float ExtendedSysMon::getHddTemp(const QString cmd, const QString device)
|
||||
if (process.exitCode != 0)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||
|
||||
bool smartctl = cmd.contains(QString("smartctl"));
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Define smartctl" << smartctl;
|
||||
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||
if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) {
|
||||
QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts)[2];
|
||||
temp.remove(QChar(0260)).remove(QChar('C'));
|
||||
value = temp.toFloat();
|
||||
if (smartctl) {
|
||||
for (int i=0; i<qoutput.split(QChar(':'), QString::SkipEmptyParts).count(); i++) {
|
||||
if (qoutput.split(QChar(':'), QString::SkipEmptyParts)[i].split(QChar(' '))[0] != QString("194")) continue;
|
||||
if (qoutput.split(QChar(':'), QString::SkipEmptyParts)[i].split(QChar(' '), QString::SkipEmptyParts).count() < 9) break;
|
||||
value = qoutput.split(QChar(':'), QString::SkipEmptyParts)[i].split(QChar(' '), QString::SkipEmptyParts)[9].toFloat();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() < 3) {
|
||||
QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts)[2];
|
||||
temp.remove(QChar(0260)).remove(QChar('C'));
|
||||
value = temp.toFloat();
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
|
Loading…
Reference in New Issue
Block a user