1 | /*
|
---|
2 | * systemwatch_mac.cpp - Detect changes in the system state (Windows).
|
---|
3 | * Copyright (C) 2005 James Chaldecott
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU General Public License
|
---|
7 | * as published by the Free Software Foundation; either version 2
|
---|
8 | * of the License, or (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program 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
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * 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 "systemwatch_win.h"
|
---|
22 |
|
---|
23 | #include <qwidget.h>
|
---|
24 | #include <qt_windows.h>
|
---|
25 |
|
---|
26 |
|
---|
27 | // -----------------------------------------------------------------------------
|
---|
28 | // WinSystemWatchPrivate
|
---|
29 | // -----------------------------------------------------------------------------
|
---|
30 |
|
---|
31 | class WinSystemWatch::WinSystemWatchPrivate : public QWidget
|
---|
32 | {
|
---|
33 | Q_OBJECT
|
---|
34 |
|
---|
35 | public:
|
---|
36 | WinSystemWatchPrivate( ) : QWidget( 0 ) { }
|
---|
37 | ~WinSystemWatchPrivate() { }
|
---|
38 |
|
---|
39 | bool winEvent( MSG * );
|
---|
40 |
|
---|
41 | signals:
|
---|
42 | void sleep();
|
---|
43 | void wakeup();
|
---|
44 | };
|
---|
45 |
|
---|
46 |
|
---|
47 | bool WinSystemWatch::WinSystemWatchPrivate::winEvent( MSG *m )
|
---|
48 | {
|
---|
49 | if(WM_POWERBROADCAST == m->message) {
|
---|
50 | switch (m->wParam) {
|
---|
51 | case PBT_APMSUSPEND:
|
---|
52 | emit sleep();
|
---|
53 | break;
|
---|
54 |
|
---|
55 | case PBT_APMRESUMESUSPEND:
|
---|
56 | emit wakeup();
|
---|
57 | break;
|
---|
58 |
|
---|
59 | case PBT_APMRESUMECRITICAL:
|
---|
60 | // The system previously went into SUSPEND state (suddenly)
|
---|
61 | // without sending PBT_APMSUSPEND. Net connections are
|
---|
62 | // probably invalid. Not sure what to do about this.
|
---|
63 | // Maybe:
|
---|
64 | emit sleep();
|
---|
65 | emit wakeup();
|
---|
66 | break;
|
---|
67 |
|
---|
68 | case PBT_APMQUERYSUSPEND:
|
---|
69 | // TODO: Check if file transfers are running, and don't go
|
---|
70 | // to sleep if there are. To refuse to suspend, we somehow
|
---|
71 | // need to return BROADCAST_QUERY_DENY from the actual
|
---|
72 | // windows procedure.
|
---|
73 | break;
|
---|
74 |
|
---|
75 | case WM_QUERYENDSESSION:
|
---|
76 | // TODO : If we allow the user to cancel suspend if they
|
---|
77 | // are doing a file transfer, we should probably also give
|
---|
78 | // them the chance to cancel a shutdown or log-off
|
---|
79 | break;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | return QWidget::winEvent( m );
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | // -----------------------------------------------------------------------------
|
---|
87 | // WinSystemWatch
|
---|
88 | // -----------------------------------------------------------------------------
|
---|
89 |
|
---|
90 | WinSystemWatch::WinSystemWatch()
|
---|
91 | {
|
---|
92 | d = new WinSystemWatchPrivate();
|
---|
93 | connect(d,SIGNAL(sleep()),this,SIGNAL(sleep()));
|
---|
94 | connect(d,SIGNAL(wakeup()),this,SIGNAL(wakeup()));
|
---|
95 | }
|
---|
96 |
|
---|
97 | WinSystemWatch::~WinSystemWatch()
|
---|
98 | {
|
---|
99 | disconnect(d,SIGNAL(sleep()),this,SIGNAL(sleep()));
|
---|
100 | disconnect(d,SIGNAL(wakeup()),this,SIGNAL(wakeup()));
|
---|
101 | delete d;
|
---|
102 | }
|
---|
103 |
|
---|
104 | WinSystemWatch* WinSystemWatch::instance()
|
---|
105 | {
|
---|
106 | if (!instance_)
|
---|
107 | instance_ = new WinSystemWatch();
|
---|
108 |
|
---|
109 | return instance_;
|
---|
110 | }
|
---|
111 |
|
---|
112 | WinSystemWatch* WinSystemWatch::instance_ = 0;
|
---|
113 |
|
---|
114 | // -----------------------------------------------------------------------------
|
---|
115 |
|
---|
116 | #include "systemwatch_win.moc"
|
---|
117 |
|
---|