Поглядел с notify-send только через system можно работать,
Kernel ops почти правильно написал, только один момент мне не нравится, то что директория пользователя не определяется сама, например через getenv("HOME"), как-то так, думаю можно и улучшить код
#include <iostream>
#include <fstream>
#include <cstring>
#include <stdlib.h>
#include <unistd.h>
using namespace std;
const int size=20;
const char chargingIsTrue[]="Charging";
string Path = getenv("HOME") + string("/status");
bool isCharging() {
char *status;
status=new char [size];
ifstream file;
file.open(Path.c_str());
while(file >> status);
file.close();
if(!strcmp(status, chargingIsTrue)) {
delete [] status;
return true;
}
else {
delete [] status;
return false;
}
}
void printStatus(bool nowStatus) {
if(nowStatus) system("notify-send \"Battery is charging!\"");
else system("notify-send \"Battery is discharging!\"");
}
int main() {
bool lastStatus=isCharging();
bool nowStatus;
printStatus(lastStatus);
for(;;) {
nowStatus=isCharging();
if(lastStatus!=nowStatus) {
printStatus(nowStatus);
lastStatus=nowStatus;
}
sleep(5);
}
return 0;
}
А вообще надо на классы переписать, а то на СИ очень смахивает.
