~ubuntu-branches/ubuntu/utopic/psi/utopic

« back to all changes in this revision

Viewing changes to src/tools/idle/idle_win.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2010-02-19 09:37:12 UTC
  • mfrom: (6.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100219093712-e225xvm1wjcf1cgi
Tags: 0.14-2
* comment out only function which uses va_list to work around build
  problems on armel
* Set Standards-Version to 3.8.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * idle_win.cpp - detect desktop idle time
3
 
 * Copyright (C) 2003  Justin Karneges
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2.1 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Lesser General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 *
19
 
 */
20
 
 
21
 
#include "idle.h"
22
 
 
23
 
#include <qlibrary.h>
24
 
#include <windows.h>
25
 
 
26
 
#if defined(Q_OS_WIN32) && !defined(Q_CC_GNU) && (_WIN32_WINNT < 0x0500)
27
 
typedef struct tagLASTINPUTINFO {
28
 
        UINT cbSize;
29
 
        DWORD dwTime;
30
 
} LASTINPUTINFO, *PLASTINPUTINFO;
31
 
#endif
32
 
 
33
 
class IdlePlatform::Private
34
 
{
35
 
public:
36
 
        Private()
37
 
        {
38
 
                GetLastInputInfo = 0;
39
 
                IdleUIGetLastInputTime = 0;
40
 
                lib = 0;
41
 
        }
42
 
 
43
 
        BOOL (__stdcall * GetLastInputInfo)(PLASTINPUTINFO);
44
 
        DWORD (__stdcall * IdleUIGetLastInputTime)(void);
45
 
        QLibrary *lib;
46
 
};
47
 
 
48
 
IdlePlatform::IdlePlatform()
49
 
{
50
 
        d = new Private;
51
 
}
52
 
 
53
 
IdlePlatform::~IdlePlatform()
54
 
{
55
 
        delete d->lib;
56
 
        delete d;
57
 
}
58
 
 
59
 
bool IdlePlatform::init()
60
 
{
61
 
        if(d->lib)
62
 
                return true;
63
 
        void *p;
64
 
 
65
 
        // try to find the built-in Windows 2000 function
66
 
        d->lib = new QLibrary("user32");
67
 
        if(d->lib->load() && (p = d->lib->resolve("GetLastInputInfo"))) {
68
 
                d->GetLastInputInfo = (BOOL (__stdcall *)(PLASTINPUTINFO))p;
69
 
                return true;
70
 
        }
71
 
        else {
72
 
                delete d->lib;
73
 
                d->lib = 0;
74
 
        }
75
 
 
76
 
        // fall back on idleui
77
 
        d->lib = new QLibrary("idleui");
78
 
        if(d->lib->load() && (p = d->lib->resolve("IdleUIGetLastInputTime"))) {
79
 
                d->IdleUIGetLastInputTime = (DWORD (__stdcall *)(void))p;
80
 
                return true;
81
 
        }
82
 
        else {
83
 
                delete d->lib;
84
 
                d->lib = 0;
85
 
        }
86
 
 
87
 
        return false;
88
 
}
89
 
 
90
 
int IdlePlatform::secondsIdle()
91
 
{
92
 
        int i;
93
 
        if(d->GetLastInputInfo) {
94
 
                LASTINPUTINFO li;
95
 
                li.cbSize = sizeof(LASTINPUTINFO);
96
 
                bool ok = d->GetLastInputInfo(&li);
97
 
                if(!ok)
98
 
                        return 0;
99
 
                i = li.dwTime;
100
 
        }
101
 
        else if(d->IdleUIGetLastInputTime) {
102
 
                i = d->IdleUIGetLastInputTime();
103
 
        }
104
 
        else
105
 
                return 0;
106
 
 
107
 
        return (GetTickCount() - i) / 1000;
108
 
}