Solid

main.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "solid-power.h"
8
9#include <QCommandLineParser>
10#include <QCoreApplication>
11#include <QTextStream>
12
13static QTextStream sOut(stdout);
14int main(int argc, char **argv)
15{
16 qputenv("SOLID_POWER_BACKEND", "FREE_DESKTOP");
17
18 QCoreApplication app(argc, argv);
19 app.setApplicationName(QLatin1String("solid-power"));
20
21 QCommandLineParser parser;
22 parser.setApplicationDescription(QCoreApplication::translate("solid-power", "Tool to know and set the power management state of your device"));
23 parser.addHelpOption();
24 parser.addPositionalArgument("command", QCoreApplication::translate("solid-power", "Command to execute"));
25
26 QCommandLineOption commands("commands", QCoreApplication::translate("solid-power", "Show available commands"));
27 parser.addOption(commands);
28
29 parser.process(app);
30
31 if (parser.isSet(commands)) {
32 sOut << Qt::endl << QCoreApplication::translate("solid-hardware", "Syntax:") << Qt::endl << Qt::endl;
33
34 sOut << " solid-power show" << Qt::endl;
35 sOut << QCoreApplication::translate("solid-power",
36 " # Show all the power management information from the system.\n"
37 " # - acPlugged: whether the device is connected to the AC or not\n")
38 << Qt::endl;
39 return 1;
40 }
41
42 SolidPower power;
43
44 QStringList args = parser.positionalArguments();
45 if (args.count() < 1) {
46 parser.showHelp(1);
47 return 1;
48 }
49
51
52 QString command(args.at(0));
53
54 if (command == QLatin1String("show")) {
55 power.show();
56 } else if (command == QLatin1String("listen")) {
57 sOut << "Listening to events:" << Qt::endl;
58 power.listen();
59 app.exec();
60 } else {
61 sOut << "Not recognized command" << Qt::endl;
62 }
63}
QCommandLineOption addHelpOption()
bool addOption(const QCommandLineOption &option)
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
void clearPositionalArguments()
bool isSet(const QCommandLineOption &option) const const
QStringList positionalArguments() const const
void process(const QCoreApplication &app)
void setApplicationDescription(const QString &description)
void showHelp(int exitCode)
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
const_reference at(qsizetype i) const const
qsizetype count() const const
QTextStream & endl(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:47:59 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.