Commit 2148352c authored by Àlex Fiestas's avatar Àlex Fiestas

Implement "listen" command

This command will connect to all signals from Solid::Power and reprot
any change that is detected in the system.
parent f1f672fc
......@@ -67,5 +67,11 @@ int main(int argc, char **argv)
if (command == QLatin1String("show")) {
power.show();
} else if(command == QLatin1String("listen")) {
sOut << "Listening to events:" << endl;
power.listen();
app.exec();
} else {
sOut << "Not recognized command" << endl;
}
}
\ No newline at end of file
......@@ -44,4 +44,15 @@ void SolidPower::show()
QString status = job->isPlugged() ? "yes" : "no";
sCout << "is AC plugged:\t" << status << endl;
}
void SolidPower::listen()
{
auto power = Power::self();
connect(power, &Power::acPluggedChanged, [](bool plugged){
QTextStream lOut(stdout);
QString status = plugged ? "yes" : "no";
lOut << "\tAC plugged changed:\t" << status << endl;
});
}
\ No newline at end of file
......@@ -31,6 +31,7 @@ public:
explicit SolidPower(QObject *parent = 0);
void show();
void listen();
};
#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