-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (42 loc) · 1.2 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (42 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
#include "date_process.cpp"
#include <ctime>
using namespace std;
bool is_in_past(string date, string time) {
string input_time = date + " " + time;
char now_buf[20];
time_t now = std::time(nullptr);
strftime(now_buf, sizeof(now_buf), "%Y-%m-%d %H:%M:%S", std::localtime(&now));
return input_time < now_buf;
}
int main(int argc, char* argv[]) {
if (argc != 4 && argc != 5) {
cout << "There are less than 4 arguments" << endl;
return 1;
}
stringstream result;
string date = argv[1];
date_processing(date);
string time = argv[2];
if (time.length() == 5) time += ":00";
if (is_in_past(date, time)) {
cout << "You can't set a reminder in the past. Sorry :(" << endl;
return 1;
}
string head;
string info;
if (argc == 4) {
head = "Reminder";
info = argv[3];
}
else {
head = argv[3];
info = argv[4];
}
result << "systemd-run --user --on-calendar=\"" << date << " " << time
<< "\" notify-send \"" << head << "\" \"" << info << "\"";
return system(result.str().c_str());
}