File indexing completed on 2024-04-28 04:00:50
0001 /* 0002 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "solid-power.h" 0008 0009 #include <QCommandLineParser> 0010 #include <QCoreApplication> 0011 #include <QTextStream> 0012 0013 static QTextStream sOut(stdout); 0014 int main(int argc, char **argv) 0015 { 0016 qputenv("SOLID_POWER_BACKEND", "FREE_DESKTOP"); 0017 0018 QCoreApplication app(argc, argv); 0019 app.setApplicationName(QLatin1String("solid-power")); 0020 0021 QCommandLineParser parser; 0022 parser.setApplicationDescription(QCoreApplication::translate("solid-power", "Tool to know and set the power management state of your device")); 0023 parser.addHelpOption(); 0024 parser.addPositionalArgument("command", QCoreApplication::translate("solid-power", "Command to execute")); 0025 0026 QCommandLineOption commands("commands", QCoreApplication::translate("solid-power", "Show available commands")); 0027 parser.addOption(commands); 0028 0029 parser.process(app); 0030 0031 if (parser.isSet(commands)) { 0032 sOut << Qt::endl << QCoreApplication::translate("solid-hardware", "Syntax:") << Qt::endl << Qt::endl; 0033 0034 sOut << " solid-power show" << Qt::endl; 0035 sOut << QCoreApplication::translate("solid-power", 0036 " # Show all the power management information from the system.\n" 0037 " # - acPlugged: whether the device is connected to the AC or not\n") 0038 << Qt::endl; 0039 return 1; 0040 } 0041 0042 SolidPower power; 0043 0044 QStringList args = parser.positionalArguments(); 0045 if (args.count() < 1) { 0046 parser.showHelp(1); 0047 return 1; 0048 } 0049 0050 parser.clearPositionalArguments(); 0051 0052 QString command(args.at(0)); 0053 0054 if (command == QLatin1String("show")) { 0055 power.show(); 0056 } else if (command == QLatin1String("listen")) { 0057 sOut << "Listening to events:" << Qt::endl; 0058 power.listen(); 0059 app.exec(); 0060 } else { 0061 sOut << "Not recognized command" << Qt::endl; 0062 } 0063 }