summaryrefslogtreecommitdiff
authoralwin <alwin>2004-02-26 22:26:20 (UTC)
committer alwin <alwin>2004-02-26 22:26:20 (UTC)
commitcb7a0156d641e96dfb6fe1cea6ca3a26e54ce6b2 (patch) (side-by-side diff)
tree90b117bd6df3cc7ead72d191e618655725f84dc2
parent303b5a8e72fe319e6123b01f104b7cb049599f6f (diff)
downloadopie-cb7a0156d641e96dfb6fe1cea6ca3a26e54ce6b2.zip
opie-cb7a0156d641e96dfb6fe1cea6ca3a26e54ce6b2.tar.gz
opie-cb7a0156d641e96dfb6fe1cea6ca3a26e54ce6b2.tar.bz2
flag ms_is_starting
it will be set true until the main eventloop is reached. Check it with ServerApp::isStarting()
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/serverapp.cpp14
-rw-r--r--core/launcher/serverapp.h4
2 files changed, 17 insertions, 1 deletions
diff --git a/core/launcher/serverapp.cpp b/core/launcher/serverapp.cpp
index 11381e6..f7c2341 100644
--- a/core/launcher/serverapp.cpp
+++ b/core/launcher/serverapp.cpp
@@ -73,407 +73,408 @@ QCString QCopKeyRegister::channel()const {
QCString QCopKeyRegister::message()const {
return m_message;
}
bool QCopKeyRegister::send() {
if (m_channel.isNull() )
return false;
QCopEnvelope( m_channel, m_message );
return true;
}
//---------------------------------------------------------------------------
/*
Priority is number of alerts that are needed to pop up
alert.
*/
class DesktopPowerAlerter : public QMessageBox
{
Q_OBJECT
public:
DesktopPowerAlerter( QWidget *parent, const char *name = 0 )
: QMessageBox( tr("Battery Status"), tr("Low Battery"),
QMessageBox::Critical,
QMessageBox::Ok | QMessageBox::Default,
QMessageBox::NoButton, QMessageBox::NoButton,
parent, name, FALSE )
{
currentPriority = INT_MAX;
alertCount = 0;
}
void alert( const QString &text, int priority );
void hideEvent( QHideEvent * );
private:
int currentPriority;
int alertCount;
};
void DesktopPowerAlerter::alert( const QString &text, int priority )
{
alertCount++;
if ( alertCount < priority )
return;
if ( priority > currentPriority )
return;
currentPriority = priority;
setText( text );
show();
}
void DesktopPowerAlerter::hideEvent( QHideEvent *e )
{
QMessageBox::hideEvent( e );
alertCount = 0;
currentPriority = INT_MAX;
}
//---------------------------------------------------------------------------
KeyFilter::KeyFilter(QObject* parent) : QObject(parent), held_tid(0), heldButton(0)
{
/* We don't do this cause it would interfere with ODevice */
#if 0
qwsServer->setKeyboardFilter(this);
#endif
}
void KeyFilter::timerEvent(QTimerEvent* e)
{
if ( e->timerId() == held_tid ) {
killTimer(held_tid);
// button held
if ( heldButton ) {
emit activate(heldButton, TRUE);
heldButton = 0;
}
held_tid = 0;
}
}
void KeyFilter::registerKey( const QCopKeyRegister& key ) {
m_keys.insert( key.keyCode(), key );
}
void KeyFilter::unregisterKey( const QCopKeyRegister& key ) {
m_keys.remove( key.keyCode() );
}
bool KeyFilter::keyRegistered( int key ) {
/*
* Check if we've a key registered
*/
if ( !m_keys[key].send())
return false;
else
return true;
}
bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat)
{
if ( !loggedin
// Permitted keys
&& keycode != Key_F34 // power
&& keycode != Key_F30 // select
&& keycode != Key_Enter
&& keycode != Key_Return
&& keycode != Key_Space
&& keycode != Key_Left
&& keycode != Key_Right
&& keycode != Key_Up
&& keycode != Key_Down )
return TRUE;
/* check if it was registered */
if (!db ) {
if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) )
return true;
}else {
// First check to see if DeviceButtonManager knows something about this button:
const Opie::ODeviceButton* button = Opie::ODevice::inst()->buttonForKeycode(keycode);
if (button && !autoRepeat) {
if ( held_tid ) {
killTimer(held_tid);
held_tid = 0;
}
if ( button->heldAction().isNull() ) {
if ( press )
emit activate(button, FALSE);
} else if ( press ) {
heldButton = button;
held_tid = startTimer( ODevice::inst ()->buttonHoldTime () );
} else if ( heldButton ) {
heldButton = 0;
emit activate(button, FALSE);
}
QWSServer::screenSaverActivate(FALSE);
return TRUE;
}
return false;
}
if ( keycode == HardKey_Suspend ) {
if ( press ) emit power();
return TRUE;
}
if ( keycode == HardKey_Backlight ) {
if ( press ) emit backlight();
return TRUE;
}
if ( keycode == Key_F32 ) {
#ifndef QT_NO_COP
if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" );
#endif
return TRUE;
}
if ( keycode == Key_F31 ) {
if ( press ) emit symbol();
QWSServer::screenSaverActivate(FALSE);
return TRUE;
}
if ( keycode == Key_NumLock )
if ( press ) emit numLockStateToggle();
if ( keycode == Key_CapsLock )
if ( press ) emit capsLockStateToggle();
if ( serverApp )
serverApp->keyClick(keycode,press,autoRepeat);
return FALSE;
}
enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown;
#if defined(QPE_HAVE_MEMALERTER)
QPE_MEMALERTER_IMPL
#endif
//---------------------------------------------------------------------------
bool ServerApplication::doRestart = FALSE;
bool ServerApplication::allowRestart = TRUE;
+bool ServerApplication::ms_is_starting = TRUE;
void ServerApplication::switchLCD( bool on ) {
if ( !qApp )
return;
ServerApplication *dapp = ServerApplication::me() ;
if ( !dapp-> m_screensaver )
return;
if ( on ) {
dapp-> m_screensaver-> setDisplayState ( true );
dapp-> m_screensaver-> setBacklight ( -3 );
}else
dapp-> m_screensaver-> setDisplayState ( false );
}
ServerApplication::ServerApplication( int& argc, char **argv, Type t )
: QPEApplication( argc, argv, t )
{
-
+ ms_is_starting = true;
// We know we'll have lots of cached pixmaps due to App/DocLnks
QPixmapCache::setCacheLimit(512);
m_ps = new PowerStatus;
m_ps_last = new PowerStatus;
pa = new DesktopPowerAlerter( 0 );
m_apm_timer = new QTimer( this );
connect(m_apm_timer, SIGNAL( timeout() ),
this, SLOT( apmTimeout() ) );
reloadPowerWarnSettings();
QCopChannel *channel = new QCopChannel( "QPE/System", this );
connect(channel, SIGNAL(received( const QCString&, const QByteArray& ) ),
this, SLOT(systemMessage(const QCString&, const QByteArray& ) ) );
channel = new QCopChannel("QPE/Launcher", this );
connect(channel, SIGNAL(received( const QCString&, const QByteArray& ) ),
this, SLOT(launcherMessage( const QCString&, const QByteArray& ) ) );
m_screensaver = new OpieScreenSaver();
m_screensaver->setInterval( -1 );
QWSServer::setScreenSaver( m_screensaver );
connect( qApp, SIGNAL( volumeChanged( bool ) ),
this, SLOT( rereadVolumes() ) );
/* ### PluginLoader libqtopia SafeMode */
#if 0
if ( PluginLoader::inSafeMode() )
QTimer::singleShot(500, this, SLOT(showSafeMode()) );
QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) );
#endif
kf = new KeyFilter(this);
connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) );
connect( kf, SIGNAL(power()), this, SIGNAL(power()) );
connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) );
connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol()));
connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle()));
connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle()));
connect( kf, SIGNAL(activate(const Opie::ODeviceButton*,bool)),
this,SIGNAL(activate(const Opie::ODeviceButton*,bool)));
connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) );
connect( this, SIGNAL(power() ),
SLOT(togglePower() ) );
rereadVolumes();
serverApp = this;
apmTimeout();
grabKeyboard();
/* make sure the event filter is installed */
const Opie::ODeviceButton* but = Opie::ODevice::inst()->buttonForKeycode( -1 );
}
ServerApplication::~ServerApplication()
{
ungrabKeyboard();
delete pa;
delete m_ps;
delete m_ps_last;
}
void ServerApplication::apmTimeout() {
serverApp-> checkMemory( ); // in case no events are generated
*m_ps_last = *m_ps;
*m_ps = PowerStatusManager::readStatus();
if ( m_ps->acStatus() != m_ps_last-> acStatus() )
m_screensaver-> powerStatusChanged( *m_ps );
if ( m_ps->acStatus() == PowerStatus::Online ) {
return;
}
int bat = m_ps-> batteryPercentRemaining();
if ( bat < m_ps_last-> batteryPercentRemaining() ) {
if ( bat <= m_powerCritical ) {
QMessageBox battlow(
tr("WARNING"),
tr("<p>The battery level is critical!"
"<p>Keep power off until AC is restored"),
QMessageBox::Warning,
QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
0, QString::null, TRUE, WStyle_StaysOnTop);
battlow.setButtonText(QMessageBox::Cancel, tr("Ok"));
battlow.exec();
} else if ( bat <= m_powerVeryLow )
pa->alert( tr( "The battery is running very low. "), 2 );
}
if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) {
QMessageBox battlow(
tr("WARNING"),
tr("<p>The Back-up battery is very low"
"<p>Please charge the back-up battery"),
QMessageBox::Warning,
QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
0, QString::null, TRUE, WStyle_StaysOnTop);
battlow.setButtonText(QMessageBox::Cancel, tr("Ok"));
battlow.exec();
}
}
void ServerApplication::systemMessage( const QCString& msg,
const QByteArray& data ) {
QDataStream stream ( data, IO_ReadOnly );
if ( msg == "setScreenSaverInterval(int)" ) {
int time;
stream >> time;
m_screensaver-> setInterval( time );
}
else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
int t1, t2, t3;
stream >> t1 >> t2 >> t3;
m_screensaver-> setIntervals( t1, t2, t3 );
}
else if ( msg == "setBacklight(int)" ) {
int bright;
stream >> bright;
m_screensaver-> setBacklight( bright );
}
else if ( msg == "setScreenSaverMode(int)" ) {
int mode;
stream >> mode;
m_screensaver-> setMode ( mode );
}
else if ( msg == "reloadPowerWarnSettings()" ) {
reloadPowerWarnSettings();
}
else if ( msg == "setDisplayState(int)" ) {
int state;
stream >> state;
m_screensaver-> setDisplayState ( state != 0 );
}
else if ( msg == "suspend()" ) {
emit power();
}
else if ( msg == "sendBusinessCard()" ) {
QString card = ::getenv ( "HOME" );
card += "/Applications/addressbook/businesscard.vcf";
if ( QFile::exists( card ) ) {
QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" );
QString mimetype = "text/x-vCard";
e << tr( "business card" ) << card << mimetype;
}
}
}
void ServerApplication::reloadPowerWarnSettings ( )
{
Config cfg ( "apm" );
cfg. setGroup ( "Warnings" );
int iv = cfg. readNumEntry ( "checkinterval", 10000 );
m_apm_timer-> stop ( );
if ( iv )
m_apm_timer-> start ( iv );
m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 );
m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 );
}
void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data )
{
QDataStream stream ( data, IO_ReadOnly );
if ( msg == "deviceButton(int,int,int)" ) {
int keycode, press, autoRepeat;
stream >> keycode >> press >> autoRepeat;
kf->checkButtonAction ( true, keycode, press, autoRepeat );
}
else if ( msg == "keyRegister(int,QCString,QCString)" ) {
int k;
@@ -657,194 +658,205 @@ bool ServerApplication::qwsEventFilter( QWSEvent *e )
ke-> simpleData.keycode,
ke-> simpleData.is_press,
ke-> simpleData.is_auto_repeat ) )
return true;
}
return QPEApplication::qwsEventFilter( e );
}
#endif
/* ### FIXME libqtopia Plugin Safe Mode */
void ServerApplication::showSafeMode()
{
#if 0
if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, "
"and the system is now in Safe Mode. "
"Plugins are not loaded in Safe Mode. "
"You can use the Plugin Manager to "
"disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) {
Global::execute( "pluginmanager" );
}
#endif
}
void ServerApplication::clearSafeMode()
{
#if 0
// If we've been running OK for a while then we won't bother going into
// safe mode immediately on the next crash.
Config cfg( "PluginLoader" );
cfg.setGroup( "Global" );
QString mode = cfg.readEntry( "Mode", "Normal" );
if ( mode == "MaybeSafe" ) {
cfg.writeEntry( "Mode", "Normal" );
}
#endif
}
void ServerApplication::shutdown()
{
if ( type() != GuiServer )
return;
ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)),
this, SLOT(shutdown(ShutdownImpl::Type)) );
QPEApplication::showWidget( sd );
}
void ServerApplication::shutdown( ShutdownImpl::Type t )
{
char *opt = 0;
switch ( t ) {
case ShutdownImpl::ShutdownSystem:
opt = "-h";
// fall through
case ShutdownImpl::RebootSystem:
if ( opt == 0 )
opt = "-r";
if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 )
perror("shutdown");
// ::syslog ( LOG_ERR, "Erroring execing shutdown\n" );
break;
case ShutdownImpl::RestartDesktop:
restart();
break;
case ShutdownImpl::TerminateDesktop:
prepareForTermination( FALSE );
// This is a workaround for a Qt bug
// clipboard applet has to stop its poll timer, or Qt/E
// will hang on quit() right before it emits aboutToQuit()
emit aboutToQuit ( );
quit();
break;
}
}
void ServerApplication::restart()
{
if ( allowRestart ) {
/*
* Applets and restart is a problem. Some applets delete
* their widgets even if ownership gets transfered to the
* parent (Systray ) but deleting the applet may be unsafe
* as well ( double deletion ). Some have topLevel widgets
* and when we dlclose and then delete the widget we will
* crash and an crash during restart is not nice
*/
#ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED
/* same as above */
emit aboutToQuit();
prepareForTermination(TRUE);
doRestart = TRUE;
quit();
#else
prepareForTermination( true );
for ( int fd = 3; fd < 100; fd++ )
close( fd );
execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 );
exit( 1 );
#endif
}
}
void ServerApplication::rereadVolumes()
{
Config cfg( "qpe" );
cfg. setGroup ( "Volume" );
m_screentap_sound = cfg. readBoolEntry ( "TouchSound" );
m_keyclick_sound = cfg. readBoolEntry ( "KeySound" );
m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" );
}
void ServerApplication::checkMemory()
{
#if defined(QPE_HAVE_MEMALERTER)
static bool ignoreNormal=TRUE;
static bool existingMessage=FALSE;
if(existingMessage)
return; // don't show a second message while still on first
existingMessage = TRUE;
switch ( memstate ) {
case MemUnknown:
break;
case MemLow:
memstate = MemUnknown;
if ( !recoverMemory() ) {
QMessageBox::warning( 0 , tr("Memory Status"),
tr("Memory Low\nPlease save data.") );
ignoreNormal = FALSE;
}
break;
case MemNormal:
memstate = MemUnknown;
if ( !ignoreNormal ) {
ignoreNormal = TRUE;
QMessageBox::information ( 0 , tr("Memory Status"),
"Memory OK" );
}
break;
case MemVeryLow:
memstate = MemUnknown;
QMessageBox::critical( 0 , tr("Memory Status"),
tr("Critical Memory Shortage\n"
"Please end this application\n"
"immediately.") );
recoverMemory();
}
existingMessage = FALSE;
#endif
}
bool ServerApplication::recoverMemory()
{
return FALSE;
}
void ServerApplication::keyClick(int , bool press, bool )
{
if ( press && m_keyclick_sound )
ODevice::inst() -> playKeySound();
}
void ServerApplication::screenClick(bool press)
{
if ( press && m_screentap_sound )
ODevice::inst() -> playTouchSound();
}
void ServerApplication::soundAlarm() {
if ( me ()->m_alarm_sound )
ODevice::inst()->playAlarmSound();
}
ServerApplication *ServerApplication::me ( )
{
return static_cast<ServerApplication*>( qApp );
}
+bool ServerApplication::isStarting()
+{
+ return ms_is_starting;
+}
+
+int ServerApplication::exec()
+{
+ ms_is_starting = true;
+ qDebug("Serverapp - exec");
+ return QPEApplication::exec();
+}
#include "serverapp.moc"
diff --git a/core/launcher/serverapp.h b/core/launcher/serverapp.h
index fe3f24a..4d9f808 100644
--- a/core/launcher/serverapp.h
+++ b/core/launcher/serverapp.h
@@ -1,165 +1,169 @@
/**********************************************************************
** 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 <qtopia/qpeapplication.h>
#include <qwidget.h>
#ifdef QWS
#include <qwindowsystem_qws.h>
#endif
#include "shutdownimpl.h"
class PowerStatus;
class DesktopPowerAlerter;
class OpieScreenSaver;
namespace Opie {
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::ODeviceButton*,bool);
private:
bool keyRegistered( int key );
int held_tid;
const Opie::ODeviceButton* heldButton;
KeyRegisterList m_keys;
};
class ServerApplication : public QPEApplication
{
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::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