Skip to content
This repository was archived by the owner on Sep 24, 2023. It is now read-only.

Commit 71b5416

Browse files
Fix idle detection logic
Do not assume that there is only one idle event at a time, the OS X idle detector can hold multiple events before the dialog becomes visible (as it can receive multiple wake-up events in a row). The old logic didn't show the dialog in that case at all. Fixes #220 Change-Id: I36b016634023ebe3132debd6ca78992a62fb0b64 Reviewed-on: https://codereview.kdab.com/32376 Tested-by: Continuous Integration <[email protected]> Reviewed-by: Hannah von Reth <[email protected]>
1 parent 6d52fc8 commit 71b5416

File tree

4 files changed

+25
-37
lines changed

4 files changed

+25
-37
lines changed

Charm/ApplicationCore.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "CharmCMake.h"
2727
#include "Data.h"
2828
#include "ViewHelpers.h"
29-
#include "Uniquifier.h"
3029

3130
#include "Core/CharmConstants.h"
3231
#include "Core/CharmExceptions.h"
@@ -803,9 +802,7 @@ void ApplicationCore::setHttpActionsVisible( bool visible )
803802
void ApplicationCore::slotMaybeIdle()
804803
{
805804
if ( DATAMODEL->activeEventCount() > 0 ) {
806-
if ( idleDetector()->idlePeriods().count() == 1 ) {
807-
m_timeTracker.maybeIdle( idleDetector() );
808-
} // otherwise, the dialog will be showing already
805+
m_timeTracker.maybeIdle( idleDetector() );
809806
}
810807
// there are four parameters to the idle property:
811808
// - the initial start time of the currently active event(s)
Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/*
2-
Uniquifier.h
3-
42
This file is part of Charm, a task-based time tracking application.
53
64
Copyright (C) 2009-2016 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
75
8-
Author: Mirko Boehm <mirko.boehm@kdab.com>
6+
Author: Frank Osterfeld <frank.osterfeld@kdab.com>
97
108
This program is free software; you can redistribute it and/or modify
119
it under the terms of the GNU General Public License as published by
@@ -21,28 +19,25 @@
2119
along with this program. If not, see <http://www.gnu.org/licenses/>.
2220
*/
2321

24-
#ifndef UNIQUIFIER_H
25-
#define UNIQUIFIER_H
26-
27-
// Usage:
28-
// void blurb() {
29-
// static bool inProgress = false;
30-
// if ( inProgress == true ) return;
31-
// Uniquifier u( &inProgress );
32-
// // ... this code will be called only once
33-
// }
34-
35-
class Uniquifier {
36-
public:
37-
explicit Uniquifier( bool* guard ) {
38-
m_guard = guard;
39-
*m_guard = true;
22+
#ifndef TEMPORARYVALUE_H
23+
#define TEMPORARYVALUE_H
24+
25+
template <typename T>
26+
struct TemporaryValue {
27+
explicit TemporaryValue(T& x, const T& value)
28+
: m_oldValue(x)
29+
, m_x(x)
30+
{
31+
m_x = value;
4032
}
41-
~Uniquifier() {
42-
*m_guard = false;
33+
34+
~TemporaryValue() {
35+
m_x = m_oldValue;
4336
}
44-
private:
45-
bool *m_guard;
37+
38+
T& m_x;
39+
const T m_oldValue;
4640
};
4741

4842
#endif
43+

Charm/Widgets/TimeTrackingWindow.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
#include "MessageBox.h"
3737
#include "MonthlyTimesheet.h"
3838
#include "MonthlyTimesheetConfigurationDialog.h"
39+
#include "TemporaryValue.h"
3940
#include "TimeTrackingView.h"
40-
#include "Uniquifier.h"
4141
#include "ViewHelpers.h"
4242
#include "WeeklyTimesheet.h"
4343

@@ -621,16 +621,12 @@ void TimeTrackingWindow::informUserAboutNewRelease( const QString& releaseVersio
621621
void TimeTrackingWindow::maybeIdle( IdleDetector* detector )
622622
{
623623
Q_ASSERT( detector );
624-
static bool inProgress = false;
624+
Q_ASSERT( !detector->idlePeriods().isEmpty() );
625625

626-
if ( inProgress == true ) return;
627-
Uniquifier u( &inProgress );
626+
if ( m_idleCorrectionDialogVisible )
627+
return;
628628

629-
Q_FOREACH( const IdleDetector::IdlePeriod& p, detector->idlePeriods() ) {
630-
qDebug() << "ApplicationCore::slotMaybeIdle: computer might be have been idle from"
631-
<< p.first
632-
<< "to" << p.second;
633-
}
629+
const TemporaryValue<bool> tempValue( m_idleCorrectionDialogVisible, true );
634630

635631
// handle idle merging:
636632
IdleCorrectionDialog dialog( this );
@@ -646,7 +642,6 @@ void TimeTrackingWindow::maybeIdle( IdleDetector* detector )
646642
// FIXME with this option, we can only change the events to
647643
// the start time of one idle period, I chose to use the last
648644
// one:
649-
Q_ASSERT( !detector->idlePeriods().isEmpty() );
650645
const IdleDetector::IdlePeriod period = detector->idlePeriods().last();
651646

652647
Q_FOREACH ( EventId eventId, activeEvents ) {

Charm/Widgets/TimeTrackingWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ private slots:
142142
QTimer m_checkCharmReleaseVersionTimer;
143143
QTimer m_updateUserInfoAndTasksDefinitionsTimer;
144144
BillDialog *m_billDialog;
145+
bool m_idleCorrectionDialogVisible = false;
145146
};
146147

147148
#endif

0 commit comments

Comments
 (0)