Commit 2c1c0eb4 authored by Àlex Fiestas's avatar Àlex Fiestas

Add solid-power, a small tool to query power stuff

Small tool that will be able to report anything related (and supported)
to power using Solid::Power.

At the moment it only implements Show which reports wether the ac is
plugged or not.

TODO for the tool is:
-Listen to events
-Implement all other commands.
parent 6761ed50
add_subdirectory(solid-hardware)
if(WITH_NEW_SOLID_JOB AND WITH_NEW_POWER_ASYNC_API)
add_subdirectory(solid-power)
endif()
\ No newline at end of file
add_executable(solid-power main.cpp solid-power.cpp)
ecm_mark_nongui_executable(solid-power)
target_link_libraries(solid-power Qt5::Core KF5::Solid)
install(TARGETS solid-power ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
/*
Copyright 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "solid-power.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QCommandLineParser>
#include <QTextStream>
int main(int argc, char **argv)
{
qputenv("SOLID_POWER_BACKEND", "FREE_DESKTOP");
QCoreApplication app(argc, argv);
app.setApplicationName(QLatin1Literal("solid-power"));
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::translate("solid-power", "Tool to know and set the power management state of your device"));
parser.addHelpOption();
parser.addPositionalArgument("command", QCoreApplication::translate("solid-power", "Command to execute"));
QCommandLineOption commands("commands", QCoreApplication::translate("solid-power", "Show available commands"));
parser.addOption(commands);
parser.process(app);
if (parser.isSet(commands))
{
QTextStream sOut(stdout);
sOut << endl << QCoreApplication::translate("solid-hardware", "Syntax:") << endl << endl;
sOut << " solid-power show" << endl;
sOut << QCoreApplication::translate("solid-power",
" # Show all the power management information from the system.\n"
" # - acPlugged: wether the device is connected to the AC or not\n") << endl;
return 1;
}
SolidPower power;
QStringList args = parser.positionalArguments();
if (args.count() < 1) {
parser.showHelp(1);
return 1;
}
parser.clearPositionalArguments();
QString command(args.at(0));
if (command == QLatin1String("show")) {
power.show();
}
}
\ No newline at end of file
/*
Copyright 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "solid-power.h"
#include <solid/power.h>
#include <solid/acpluggedjob.h>
#include <QDebug>
#include <QCoreApplication>
#include <QTextStream>
using namespace Solid;
using namespace std;
SolidPower::SolidPower(QObject* parent) : QObject(parent)
{
mCout = new QTextStream(stdout);
}
void SolidPower::show()
{
auto job = Solid::Power::isAcPlugged(this);
job->exec();
QString status = job->isPlugged() ? "yes" : "no";
QTextStream sOut(stdout);
sOut << "is AC plugged:\t" << status << endl;
}
\ No newline at end of file
/*
Copyright 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_POWER_TOOL_H
#define SOLID_POWER_TOOL_H
#include <QObject>
#include <QTextStream>
class SolidPower : public QObject
{
Q_OBJECT
public:
explicit SolidPower(QObject *parent = 0);
void show();
QTextStream *mCout;
};
#endif //SOLID_POWER_TOOL_H
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment