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

Commit

Permalink
Fix idle detection logic
Browse files Browse the repository at this point in the history
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 <build@kdab.com>
Reviewed-by: Hannah von Reth <hannah.vonreth@kdab.com>
  • Loading branch information
frankosterfeld committed Apr 21, 2016
1 parent 6d52fc8 commit 71b5416
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 37 deletions.
5 changes: 1 addition & 4 deletions Charm/ApplicationCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "CharmCMake.h"
#include "Data.h"
#include "ViewHelpers.h"
#include "Uniquifier.h"

#include "Core/CharmConstants.h"
#include "Core/CharmExceptions.h"
Expand Down Expand Up @@ -803,9 +802,7 @@ void ApplicationCore::setHttpActionsVisible( bool visible )
void ApplicationCore::slotMaybeIdle()
{
if ( DATAMODEL->activeEventCount() > 0 ) {
if ( idleDetector()->idlePeriods().count() == 1 ) {
m_timeTracker.maybeIdle( idleDetector() );
} // otherwise, the dialog will be showing already
m_timeTracker.maybeIdle( idleDetector() );
}
// there are four parameters to the idle property:
// - the initial start time of the currently active event(s)
Expand Down
41 changes: 18 additions & 23 deletions Charm/Uniquifier.h → Charm/TemporaryValue.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/*
Uniquifier.h
This file is part of Charm, a task-based time tracking application.
Copyright (C) 2009-2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Mirko Boehm <mirko.boehm@kdab.com>
Author: Frank Osterfeld <frank.osterfeld@kdab.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -21,28 +19,25 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef UNIQUIFIER_H
#define UNIQUIFIER_H

// Usage:
// void blurb() {
// static bool inProgress = false;
// if ( inProgress == true ) return;
// Uniquifier u( &inProgress );
// // ... this code will be called only once
// }

class Uniquifier {
public:
explicit Uniquifier( bool* guard ) {
m_guard = guard;
*m_guard = true;
#ifndef TEMPORARYVALUE_H
#define TEMPORARYVALUE_H

template <typename T>
struct TemporaryValue {
explicit TemporaryValue(T& x, const T& value)
: m_oldValue(x)
, m_x(x)
{
m_x = value;
}
~Uniquifier() {
*m_guard = false;

~TemporaryValue() {
m_x = m_oldValue;
}
private:
bool *m_guard;

T& m_x;
const T m_oldValue;
};

#endif

15 changes: 5 additions & 10 deletions Charm/Widgets/TimeTrackingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#include "MessageBox.h"
#include "MonthlyTimesheet.h"
#include "MonthlyTimesheetConfigurationDialog.h"
#include "TemporaryValue.h"
#include "TimeTrackingView.h"
#include "Uniquifier.h"
#include "ViewHelpers.h"
#include "WeeklyTimesheet.h"

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

if ( inProgress == true ) return;
Uniquifier u( &inProgress );
if ( m_idleCorrectionDialogVisible )
return;

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

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

Q_FOREACH ( EventId eventId, activeEvents ) {
Expand Down
1 change: 1 addition & 0 deletions Charm/Widgets/TimeTrackingWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private slots:
QTimer m_checkCharmReleaseVersionTimer;
QTimer m_updateUserInfoAndTasksDefinitionsTimer;
BillDialog *m_billDialog;
bool m_idleCorrectionDialogVisible = false;
};

#endif

0 comments on commit 71b5416

Please sign in to comment.