summaryrefslogtreecommitdiff
path: root/core/launcher/serverapp.h
blob: 98c563384f6421905b2bfa711bc80cee1d9d29ee (plain)
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
/**********************************************************************
** Copyright (C) 2000-2003 Trolltech AS.  All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/

#ifndef SERVERAPP_H
#define SERVERAPP_H

#include <opie2/oapplication.h>

#include <qwidget.h>
#ifdef QWS
#include <qwindowsystem_qws.h>
#endif

#include "shutdownimpl.h"

class PowerStatus;
class DesktopPowerAlerter;

class OpieScreenSaver;
namespace Opie {
namespace Core {
    class ODeviceButton;
}
}

struct QCopKeyRegister {
    QCopKeyRegister();
    QCopKeyRegister( int k, const QCString&, const QCString& );
    int keyCode()const;
    QCString channel()const;
    QCString message()const;
    inline bool send();

private:
    int m_keyCode;
    QCString m_channel, m_message;
};

typedef QMap<int, QCopKeyRegister> KeyRegisterList;

class KeyFilter : public QObject {
    Q_OBJECT
public:
    KeyFilter(QObject* parent);
    void registerKey( const QCopKeyRegister& );
    void unregisterKey( const QCopKeyRegister& );
    bool checkButtonAction( bool, int, int, int );



protected:
    void timerEvent(QTimerEvent*);

signals:
    void launch();
    void power();
    void backlight();
    void symbol();
    void numLockStateToggle();
    void capsLockStateToggle();
    void activate(const Opie::Core::ODeviceButton*,bool);


private:
    bool keyRegistered( int key );
    int held_tid;
    const Opie::Core::ODeviceButton* heldButton,*firedHeldButton;
    KeyRegisterList m_keys;
};

class ServerApplication : public Opie::Core::OApplication
{
    Q_OBJECT
public:
    ServerApplication( int& argc, char **argv, Type t );
    ~ServerApplication();

    static bool doRestart;
    static bool allowRestart;
    static bool screenLocked();
    static void login(bool at_poweron);

    static bool isStarting();

    static void switchLCD ( bool on ); // only for togglePower in Desktop
    static void soundAlarm(); // only because QCop soundAlarm() is defined in QPE/TaskBar

    void restart();
    int exec();

signals:
    void menu();
    void home();
    void launch();
    void power();
    void backlight();
    void symbol();
    void numLockStateToggle();
    void capsLockStateToggle();
    void prepareForRestart();
    void activate(const Opie::Core::ODeviceButton*,bool);

public slots:
    virtual void systemMessage( const QCString& msg, const QByteArray& );
    virtual void launcherMessage( const QCString& msg, const QByteArray& );
    void rereadVolumes();

protected:
    bool eventFilter( QObject*,  QEvent* );
#ifdef Q_WS_QWS
    bool qwsEventFilter( QWSEvent * );
#endif
    void shutdown();
    void checkMemory();
    bool recoverMemory();
    void keyClick(int keycode, bool press, bool repeat);
    void screenClick(bool press);

protected slots:
    void shutdown(ShutdownImpl::Type);
    void apmTimeout();
    void showSafeMode();
    void clearSafeMode();
    void togglePower();
    void toggleLight();

private:
    static ServerApplication *me ();
    void reloadPowerWarnSettings();
    KeyFilter *kf;


private:
    DesktopPowerAlerter *pa;
    PowerStatus *m_ps,  *m_ps_last;
    OpieScreenSaver *m_screensaver;
    QTimer *m_apm_timer;
    QDateTime m_suspendTime;
    int m_powerVeryLow;
    int m_powerCritical;
    int m_currentPowerLevel;

    bool m_keyclick_sound  : 1;
    bool m_screentap_sound : 1;
    bool m_alarm_sound     : 1;
    static bool ms_is_starting;


    friend class KeyFilter;
};


#endif // SERVERAPP_H