-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
619 lines (564 loc) · 22.3 KB
/
mainwindow.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
#include "mainwindow.h"
SavedItems saved;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Furtherance");
resize(430,700);
mainWidget = new QWidget();
mainLayout = new QVBoxLayout();
mainWidget->setLayout(mainLayout);
listOfTasksLayout = new QVBoxLayout();
notifyOfIdle = 180;
getDesktopEnv();
databaseConnect();
databaseInit();
databaseRead();
taskListTree = new QTreeWidget();
taskListTree->setUniformRowHeights(true);
taskListTree->setHeaderLabels(QStringList() << tr("Task") << tr("Time") << tr("Start") << tr("End") << "ID");
taskListTree->header()->resizeSection(0, 170);
taskListTree->header()->resizeSection(1, 70);
taskListTree->header()->resizeSection(2, 85);
taskListTree->header()->resizeSection(3, 85);
taskListTree->hideColumn(4);
connect(taskListTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemEdited(QTreeWidgetItem*, int)));
// Add context menu to taskListTree
taskListMenu = new QMenu("Task menu", this);
deleteItemAction = new QAction("Delete");
connect(deleteItemAction, SIGNAL(triggered()), this, SLOT(deleteTask()));
taskListMenu->addAction(deleteItemAction);
taskListTree->setContextMenuPolicy(Qt::CustomContextMenu);
connect(taskListTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(taskListContextMenu(const QPoint &)));
timer = new QLabel();
timer->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
timerFont = timer->font();
timerFont.setPointSize(50);
timer->setFont(timerFont);
timer->setText("00:00");
timer->setHidden(true);
running = false;
startStopBtn = new QPushButton();
startStopFont = startStopBtn->font();
startStopFont.setPointSize(14);
startStopBtn->setFont(startStopFont);
startStopBtn->setText("Start");
startStopBtn->setFixedSize(160, 40);
connect(startStopBtn, SIGNAL(clicked()), this, SLOT(startStop()));
startStopBtn->setEnabled(false);
inputTask = new QLineEdit();
inputTask->setFixedSize(200, 40);
taskFont = inputTask->font();
taskFont.setPointSize(13);
inputTask->setFont(taskFont);
inputTask->setAlignment(Qt::AlignCenter);
inputTask->setPlaceholderText("Task Name");
connect(inputTask, SIGNAL(textChanged(QString)), this, SLOT(inputTaskChanged()));
// Notify of idle
#ifdef __linux__
if (kdePlasma)
{
// connect(KIdleTime::instance(), QOverload<int, int>::of(&KIdleTime::timeoutReached), this, &MainWindow::idleTimeReached);
// connect(KIdleTime::instance(), &KIdleTime::resumingFromIdle, this, &MainWindow::resumeFromIdle);
}
#endif
buildMenuBar();
createLayout();
setCentralWidget(mainWidget);
startTimer(100);
if (savedTimes.size() > 0) {
sortSavedByDay();
}
}
MainWindow::~MainWindow()
{
}
void MainWindow::createLayout() {
mainLayout->addWidget(timer);
mainLayout->addWidget(inputTask, 0, Qt::AlignCenter | Qt::AlignTop);
mainLayout->addWidget(startStopBtn, 0, Qt::AlignCenter | Qt::AlignTop);
mainLayout->addWidget(taskListTree);
}
void MainWindow::clearLayout(QLayout *layout) {
if (layout == NULL)
return;
QLayoutItem *item;
while((item = layout->takeAt(0))) {
if (item->layout()) {
clearLayout(item->layout());
delete item->layout();
}
if (item->widget()) {
delete item->widget();
}
delete item;
}
}
void MainWindow::buildMenuBar() {
fileMenu = menuBar()->addMenu("&File");
quitAction = new QAction("Quit", this);
quitAction->setShortcuts(QKeySequence::Quit);
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
fileMenu->addAction(quitAction);
editMenu = menuBar()->addMenu("Edit");
clearAction = new QAction("Clear All", this);
connect(clearAction, SIGNAL(triggered()), this, SLOT(clearDatabase()));
editMenu->addAction(clearAction);
}
void MainWindow::startStop() {
if (running) {
running = false;
timer->setHidden(true);
#ifdef __linux__
if (kdePlasma)
{
// KIdleTime::instance()->stopCatchingResumeEvent();
}
#endif
currentTimer = timer->text().toStdString();
saved.thisTask = inputTask->text().toStdString();
if (subtractIdle) {
// int currentTimeSecs = QDateTime::currentSecsSinceEpoch() - idleTime; TODO Remove this line
saved.stopTime = QDateTime::fromSecsSinceEpoch(idleStartTime);
subtractIdle = false;
} else {
saved.stopTime = QDateTime::currentDateTime();
}
databasePopulate();
saved.id = databaseGetLastID();
savedTimes.push_back(saved);
sortSavedByDay();
timer->setText("00:00");
inputTask->setText("");
inputTask->setReadOnly(false);
startStopBtn->setText("Start");
} else {
timer->setHidden(false);
saved.startTime = QDateTime::currentDateTime();
beginTime = QTime::currentTime();
#ifdef __linux__
if (kdePlasma)
{
// KIdleTime::instance()->addIdleTimeout(notifyOfIdle*1000);
}
#endif
running = true;
inputTask->setReadOnly(true);
startStopBtn->setText("Stop");
}
}
void MainWindow::timerEvent(QTimerEvent *) {
if (running) {
const QChar zero = '0';
qint64 ms = beginTime.msecsTo(QTime::currentTime());
int h = ms / 1000 / 60 / 60;
int m = (ms / 1000 / 60) - (h * 60);
int s = (ms / 1000) - (m * 60);
ms = ms - (s * 1000) - (m * 60000) - (h * 3600000);
if (h > 0) {
diff = QString("%1:%2:%3").
arg(h, 2, 10, zero).
arg(m, 2, 10, zero).
arg(s, 2, 10, zero);
} else {
diff = QString("%1:%2").
arg(m, 2, 10, zero).
arg(s, 2, 10, zero);
}
timer->setText(diff);
#ifdef __linux__
if (gnome)
{
// get idle time from d-bus
int currentIdle = getGnomeIdleTime();
// check if user is back from idle, and if so show the resume dialog
if (currentIdle < notifyOfIdle && idleTimeReachedBool && !idleNotified )
{
idleNotified = true;
resumeFromIdle();
}
// save the current idle time
storedIdleTime = currentIdle;
// check if the idle time has surpassed the set allowed idle time before user is shown dialog on return
if (storedIdleTime >= notifyOfIdle && !idleTimeReachedBool)
{
idleTimeReachedBool = true;
// store time user became idle
idleTimeReached();
}
}
#endif
}
}
void MainWindow::sortSavedByDay() {
taskListTree->clear();
tasksByDay.clear();
for (SavedItems stored : savedTimes) {
dayAndMonth = stored.startTime.toString("MMM d").toStdString();
bool daysMatch = false;
for (size_t i = 0; i < tasksByDay.size(); i++) {
if (tasksByDay[i][0].startTime.toString("MMM d").toStdString() == dayAndMonth) {
tasksByDay[i].push_back(stored);
daysMatch = true;
break;
}
} if (!daysMatch) {
std::vector<SavedItems> taskByDay;
taskByDay.push_back(stored);
tasksByDay.push_back(taskByDay);
}
}
createDayOverview();
}
void MainWindow::createDayOverview() {
taskListTree->blockSignals(true);
std::vector<QVBoxLayout*> dailyTaskLayouts;
for (size_t i = tasksByDay.size(); i-- > 0; ) {
// Create Day List
dayAndMonth = tasksByDay[i][0].startTime.toString("MMM d").toStdString();
if (QDateTime::currentDateTime().toString("MMM d").toStdString() == dayAndMonth) {
dayAndMonth = "Today";
} else if (QDateTime::currentDateTime().addDays(-1).toString("MMM d").toStdString() == dayAndMonth) {
dayAndMonth = "Yesterday";
}
// Day Label shows "date - total time recorded that day".
int differenceInSecs;
int totalDailyTime = 0;
for (SavedItems currTask : tasksByDay[i]) {
differenceInSecs = getTimeDifference(currTask.stopTime, currTask.startTime);
totalDailyTime += differenceInSecs;
}
QTreeWidgetItem *dayItem = new QTreeWidgetItem(taskListTree);
dayItem->setText(0, QString::fromStdString(dayAndMonth));
dayItem->setText(1, QDateTime::fromSecsSinceEpoch(totalDailyTime, Qt::UTC).toString("h:mm:ss"));
// Create Task List sorted by day
getSimilarTasks(tasksByDay[i]);
for (std::vector<SavedItems> thisTaskByTask : tasksByTask) {
std::string taskName = thisTaskByTask[0].thisTask;
// Task label shows total time recorded for that task that day
QTreeWidgetItem *taskItem = new QTreeWidgetItem(dayItem);
QList<QTreeWidgetItem *> sameTaskItemsVec;
int totalTaskTime = 0;
for (SavedItems currTask : thisTaskByTask) {
differenceInSecs = getTimeDifference(currTask.stopTime, currTask.startTime);
totalTaskTime += differenceInSecs;
QTreeWidgetItem *sameTaskItem = new QTreeWidgetItem(taskItem);
sameTaskItem->setFlags(sameTaskItem->flags() | Qt::ItemIsEditable);
sameTaskItem->setText(1, QDateTime::fromSecsSinceEpoch(differenceInSecs, Qt::UTC).toString("h:mm:ss"));
sameTaskItem->setText(2, currTask.startTime.toString("hh:mm:ss"));
sameTaskItem->setText(3, currTask.stopTime.toString("hh:mm:ss"));
sameTaskItem->setText(4, QString::number(currTask.id));
sameTaskItemsVec.append(sameTaskItem);
}
taskItem->setText(0, QString::fromStdString(taskName));
taskItem->setText(1, QDateTime::fromSecsSinceEpoch( totalTaskTime, Qt::UTC ).toString("h:mm:ss"));
taskListTree->addTopLevelItems(sameTaskItemsVec);
}
if (dayAndMonth == "Today") {
taskListTree->expandItem(dayItem);
}
}
taskListTree->blockSignals(false);
}
void MainWindow::getSimilarTasks(std::vector<SavedItems> tasksThisDay) {
tasksByTask.clear();
for (SavedItems stored : tasksThisDay) {
std::string taskName = stored.thisTask;
bool daysMatch = false;
for (size_t i = 0; i < tasksByTask.size(); i++) {
if (tasksByTask[i][0].thisTask == taskName) {
tasksByTask[i].push_back(stored);
daysMatch = true;
break;
}
}
if (!daysMatch) {
std::vector<SavedItems> thisTaskByTask;
thisTaskByTask.push_back(stored);
tasksByTask.push_back(thisTaskByTask);
}
}
}
void MainWindow::inputTaskChanged() {
if (inputTask->text() != "") {
startStopBtn->setEnabled(true);
} else {
startStopBtn->setEnabled(false);
}
}
void MainWindow::databaseConnect()
{
const QString DRIVER("QSQLITE");
if(QSqlDatabase::isDriverAvailable(DRIVER))
{
QSqlDatabase db = QSqlDatabase::addDatabase(DRIVER);
#ifdef _WIN32
QString furtheranceDir = QDir::homePath() + QDir::separator() + "Furtherance";
#elif __APPLE__
QString furtheranceDir = QDir::homePath() + QDir::separator() + ".Furtherance";
#else
QString furtheranceDir = QDir::homePath() + QDir::separator()+ ".config" + QDir::separator() + "Furtherance";
#endif
QDir dir(furtheranceDir);
if (!dir.exists()){
dir.mkpath(furtheranceDir);
}
QString timerDbPath = furtheranceDir + QDir::separator() + "furtherance_test.db";
db.setDatabaseName(timerDbPath);
if(!db.open())
qWarning() << "MainWindow::databaseConnect - ERROR: " << db.lastError().text();
}
else
qWarning() << "MainWindow::databaseConnect - ERROR: no driver " << DRIVER << " available";
}
void MainWindow::databaseInit()
{
QSqlQuery query("CREATE TABLE tasks (id INTEGER PRIMARY KEY, taskName TEXT, startTime TIMESTAMP, stopTime TIMESTAMP)");
}
void MainWindow::databasePopulate()
{
QSqlQuery query;
query.prepare("INSERT INTO tasks (taskName, startTime, stopTime) "
"VALUES(:taskName, :startTime, :stopTime)");
query.bindValue(":taskName", QString::fromStdString(saved.thisTask));
query.bindValue(":startTime", saved.startTime);
query.bindValue(":stopTime", saved.stopTime);
if(!query.exec())
qWarning() << "MainWindow::databasePopulate - ERROR: " << query.lastError().text();
}
void MainWindow::databaseRead()
{
QSqlQuery query("SELECT * FROM tasks ORDER BY startTime");
while (query.next())
{
saved.thisTask = query.value("taskName").toString().toStdString();
saved.startTime = query.value("startTime").toDateTime();
saved.stopTime = query.value("stopTime").toDateTime();
saved.id = query.value("id").toInt();;
savedTimes.push_back(saved);
}
}
int MainWindow::databaseGetLastID()
{
QSqlQuery query;
query.prepare("SELECT MAX(id) FROM tasks");
if(!query.exec())
qWarning() << "MainWindow::databaseGetLastID - ERROR: " << query.lastError().text();
query.next();
return query.value(0).toInt();
}
void MainWindow::itemEdited(QTreeWidgetItem * item, int column)
{
QSqlQuery query;
QSqlQuery queryWrite;
int currID = item->text(4).toInt();
query.prepare("SELECT * FROM tasks WHERE ID = :id");
query.bindValue(":id", currID);
if(!query.exec())
qWarning() << "MainWindow::itemEdited - ERROR: " << query.lastError().text();
query.next();
if (column == 2 || column == 3) {
// Get current column data.
QDateTime currData = query.value(column).toDateTime();
// Convert current data to yyyy-MM-dd
QString currTimeString = currData.toString("yyyy-MM-dd");
// create a string that assembles yyyy-MM-dd of existing with hh:mm:ss of new"
QString newData = item->text(column);
int newDataLength = newData.toStdString().length();
QString concatString;
if (newDataLength == 7) {
concatString = currTimeString + " 0" + item->text(column);
} else if (newDataLength == 4){
concatString = currTimeString + " 0" + item->text(column) + ":00";
} else if (newDataLength == 5){
concatString = currTimeString + " " + item->text(column) + ":00";
} else {
concatString = currTimeString + " " + item->text(column);
}
QDateTime editedTime = QDateTime::fromString(concatString, "yyyy-MM-dd hh:mm:ss");
// User cannot enter an invalid time, a time greater than the stop time, smaller than the stop time,
// or a time later than the current time.
int editedTimeInSecs = editedTime.toSecsSinceEpoch();
int timeNow = QDateTime::currentDateTime().toSecsSinceEpoch();
if (editedTime.isValid() &&
((column == 2 && editedTimeInSecs < query.value(3).toDateTime().toSecsSinceEpoch()) ||
(column == 3 && editedTimeInSecs > query.value(2).toDateTime().toSecsSinceEpoch())) &&
editedTimeInSecs < timeNow)
{
// Write to database
if (column == 2) {
queryWrite.prepare("UPDATE tasks SET startTime = :value WHERE id = :id ");
} else {
queryWrite.prepare("UPDATE tasks SET stopTime = :value WHERE id = :id ");
}
queryWrite.bindValue(":id", currID);
queryWrite.bindValue(":value", editedTime);
if(!queryWrite.exec())
qWarning() << "MainWindow::DatabasePopulate - ERROR: Write New" << queryWrite.lastError().text();
}
} else if (column == 0) {
QString editedTaskName = item->text(column);
if (!isWhitespace(editedTaskName.toStdString())) {
queryWrite.prepare("UPDATE tasks SET taskName = :value WHERE id = :id ");
queryWrite.bindValue(":id", currID);
queryWrite.bindValue(":value", editedTaskName);
if(!queryWrite.exec())
qWarning() << "MainWindow::DatabasePopulate - ERROR: Write Task Name" << queryWrite.lastError().text();
}
}
// Rebuild list
refreshTaskList();
QList<QTreeWidgetItem *> editedItemVec = taskListTree->findItems(QString::number(currID), Qt::MatchExactly|Qt::MatchRecursive, 4);
QTreeWidgetItem *editedItemParent = editedItemVec[0]->parent();
QTreeWidgetItem *editedItemParentOfParent = editedItemParent->parent();
taskListTree->expandItem(editedItemParentOfParent);
taskListTree->expandItem(editedItemParent);
}
int MainWindow::getTimeDifference(QDateTime stopTime, QDateTime startTime) {
return stopTime.toSecsSinceEpoch() - startTime.toSecsSinceEpoch();
}
void MainWindow::taskListContextMenu(const QPoint &point)
{
QTreeWidgetItem *item = taskListTree->itemAt(point);
if (item) {
if (item->childCount() == 0) {
taskListMenu->exec(taskListTree->viewport()->mapToGlobal(point));
}
}
}
void MainWindow::deleteTask()
{
QTreeWidgetItem *currentSelection = taskListTree->currentItem();
int currentSelectionIndex = currentSelection->text(4).toInt();
QSqlQuery query;
query.prepare("DELETE FROM tasks WHERE ID = :id");
query.bindValue(":id", currentSelectionIndex);
if(!query.exec())
qWarning() << "MainWindow::deleteTask - ERROR: " << query.lastError().text();
refreshTaskList();
}
// Thank you to Tyler Davis on Stack Overflow for this function.
bool MainWindow::isWhitespace(std::string s){
for(size_t index = 0; index < s.length(); index++){
if(!std::isspace(s[index]))
return false;
}
return true;
}
void MainWindow::clearDatabase() {
bool ok;
QString text = QInputDialog::getText(this, tr("Delete Database"),
tr("Are you sure you want to delete all saved data? If so, type DELETE."),
QLineEdit::Normal,
"", &ok);
// If user entered DELETE (case insensitive) erase the database
std::string textStr = text.toStdString();
std::transform(textStr.begin(), textStr.end(),textStr.begin(), ::toupper);
if (ok && textStr == "DELETE")
{
QSqlQuery query;
query.prepare("DELETE FROM tasks");
if(!query.exec())
qWarning() << "MainWindow::clearDatabase - ERROR: " << query.lastError().text();
refreshTaskList();
}
return;
}
void MainWindow::refreshTaskList() {
savedTimes.clear();
databaseRead();
sortSavedByDay();
}
void MainWindow::idleTimeReached()
{
idleStartTime = QDateTime::currentSecsSinceEpoch();
idleStartTime -= (notifyOfIdle);
#ifdef __linux__
if (kdePlasma)
{
// KIdleTime::instance()->removeAllIdleTimeouts();
// KIdleTime::instance()->catchNextResumeEvent();
}
#endif
}
void MainWindow::resumeFromIdle()
{
// -Record how long the system was idle
int resumeTime = QDateTime::currentSecsSinceEpoch();
idleTime = resumeTime - idleStartTime;
const QChar zero = '0';
QString idleMessage;
int h = idleTime / 60 / 60;
int m = (idleTime / 60) - (h * 60);
int s = idleTime - (m * 60);
// -Display total time idle in the message box to show
if (h > 0) {
idleMessage = QString("You were idle for %1:%2:%3").
arg(h, 2, 10, zero).
arg(m, 2, 10, zero).
arg(s, 2, 10, zero);
} else {
idleMessage = QString("You were idle for %1:%2").
arg(m, 2, 10, zero).
arg(s, 2, 10, zero);
}
// user how long they were idle and ask if they would like to remove that time from the record
QMessageBox msgBox;
msgBox.setText(idleMessage);
msgBox.setInformativeText("Do you want to discard that time, or continue the clock?");
QPushButton *continueButton = msgBox.addButton(tr("Continue"), QMessageBox::NoRole);
QPushButton *discardButton = msgBox.addButton(QMessageBox::Discard);
msgBox.setDefaultButton(QMessageBox::Discard);
msgBox.exec();
if (msgBox.clickedButton() == continueButton) {
// continue running clock and make sure we catch the next resume event
#ifdef __linux__
if (kdePlasma)
{
// KIdleTime::instance()->addIdleTimeout(notifyOfIdle * 1000);
}
if (gnome)
{
// TODO If continue
storedIdleTime = 0;
idleTimeReachedBool = false;
idleNotified = false;
}
#endif
} else if (msgBox.clickedButton() == discardButton) {
// stop the clock and subtract the idle time from current time to get stop time
#ifdef __linux__
if (gnome)
{
storedIdleTime = 0;
idleTimeReachedBool = false;
idleNotified = false;
}
#endif
subtractIdle = true;
startStop();
}
}
void MainWindow::getDesktopEnv() {
#ifdef __linux__
std::string desktopEnv = getenv("DESKTOP_SESSION");
std::transform(desktopEnv.begin(), desktopEnv.end(),desktopEnv.begin(), ::toupper);
int plasmaPos = desktopEnv.find("PLASMA");
int kdePos = desktopEnv.find("KDE");
int gnomePos = desktopEnv.find("GNOME");
if (plasmaPos >= 0 || kdePos >= 0)
{
kdePlasma = true;
} else if (gnomePos >= 0) {
gnome = true;
}
#endif
}
int MainWindow::getGnomeIdleTime()
{
QDBusInterface interface( "org.gnome.Mutter.IdleMonitor",
"/org/gnome/Mutter/IdleMonitor/Core",
"org.gnome.Mutter.IdleMonitor");
QDBusReply<qulonglong> reply = interface.call("GetIdletime");
return reply.value() / 1000;
}