summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/applauncher.cpp1
-rw-r--r--core/launcher/documentlist.cpp1
-rw-r--r--core/launcher/main.cpp2
-rw-r--r--core/launcher/qcopbridge.cpp1
-rw-r--r--core/launcher/screensaver.cpp20
-rw-r--r--core/launcher/server.cpp10
-rw-r--r--core/launcher/server.h4
-rw-r--r--core/launcher/serverapp.cpp9
-rw-r--r--core/launcher/serverapp.h10
-rw-r--r--core/launcher/transferserver.cpp1
-rw-r--r--core/launcher/wait.cpp1
-rw-r--r--core/launcher/wait.h4
12 files changed, 37 insertions, 27 deletions
diff --git a/core/launcher/applauncher.cpp b/core/launcher/applauncher.cpp
index efbf426..5a5517c 100644
--- a/core/launcher/applauncher.cpp
+++ b/core/launcher/applauncher.cpp
@@ -1,252 +1,253 @@
/**********************************************************************
** Copyright (C) 2000-2002 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 QTOPIA_INTERNAL_PRELOADACCESS
#define QTOPIA_INTERNAL_PRELOADACCESS
#endif
#ifndef QTOPIA_INTERNAL_FILEOPERATIONS
#define QTOPIA_INTERNAL_FILEOPERATIONS
#endif
#ifndef QTOPIA_PROGRAM_MONITOR
#define QTOPIA_PROGRAM_MONITOR
#endif
#include <opie2/oglobal.h>
#ifndef Q_OS_WIN32
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/file.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
#else
#include <process.h>
#include <windows.h>
#include <winbase.h>
#endif
#include <signal.h>
#include <sys/types.h>
#include <stdlib.h>
#include <qtimer.h>
#include <qwindowsystem_qws.h>
#include <qmessagebox.h>
#include <qfileinfo.h>
#include <qtopia/qcopenvelope_qws.h>
#include <qtopia/qpeapplication.h>
#include "applauncher.h"
#include "documentlist.h"
+using namespace Opie::Core;
const int AppLauncher::RAISE_TIMEOUT_MS = 5000;
//---------------------------------------------------------------------------
static AppLauncher* appLauncherPtr;
const int appStopEventID = 1290;
class AppStoppedEvent : public QCustomEvent
{
public:
AppStoppedEvent(int pid, int status)
: QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { }
int pid() { return mPid; }
int status() { return mStatus; }
private:
int mPid, mStatus;
};
AppLauncher::AppLauncher(QObject *parent, const char *name)
: QObject(parent, name), qlPid(0), qlReady(FALSE),
appKillerBox(0)
{
connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&)));
connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&)));
QCopChannel* channel = new QCopChannel( "QPE/System", this );
connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
this, SLOT(received(const QCString&,const QByteArray&)) );
channel = new QCopChannel( "QPE/Server", this );
connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
this, SLOT(received(const QCString&,const QByteArray&)) );
#ifndef Q_OS_WIN32
signal(SIGCHLD, signalHandler);
#else
runningAppsProc.setAutoDelete( TRUE );
#endif
QString tmp = qApp->argv()[0];
int pos = tmp.findRev('/');
if ( pos > -1 )
tmp = tmp.mid(++pos);
runningApps[::getpid()] = tmp;
appLauncherPtr = this;
QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) );
}
AppLauncher::~AppLauncher()
{
appLauncherPtr = 0;
#ifndef Q_OS_WIN32
signal(SIGCHLD, SIG_DFL);
#endif
if ( qlPid ) {
int status;
::kill( qlPid, SIGTERM );
waitpid( qlPid, &status, 0 );
}
}
/* We use the QCopChannel of the app as an indicator of when it has been launched
so that we can disable the busy indicators */
void AppLauncher::newQcopChannel(const QString& channelName)
{
// qDebug("channel %s added", channelName.data() );
QString prefix("QPE/Application/");
if (channelName.startsWith(prefix)) {
{
QCopEnvelope e("QPE/System", "newChannel(QString)");
e << channelName;
}
QString appName = channelName.mid(prefix.length());
if ( appName != "quicklauncher" ) {
emit connected( appName );
QCopEnvelope e("QPE/System", "notBusy(QString)");
e << appName;
}
} else if (channelName.startsWith("QPE/QuickLauncher-")) {
qDebug("Registered %s", channelName.latin1());
int pid = channelName.mid(18).toInt();
if (pid == qlPid)
qlReady = TRUE;
}
}
void AppLauncher::removedQcopChannel(const QString& channelName)
{
if (channelName.startsWith("QPE/Application/")) {
QCopEnvelope e("QPE/System", "removedChannel(QString)");
e << channelName;
}
}
void AppLauncher::received(const QCString& msg, const QByteArray& data)
{
QDataStream stream( data, IO_ReadOnly );
if ( msg == "execute(QString)" ) {
QString t;
stream >> t;
if ( !executeBuiltin( t, QString::null ) )
execute(t, QString::null);
} else if ( msg == "execute(QString,QString)" ) {
QString t,d;
stream >> t >> d;
if ( !executeBuiltin( t, d ) )
execute( t, d );
} else if ( msg == "processQCop(QString)" ) { // from QPE/Server
QString t;
stream >> t;
if ( !executeBuiltin( t, QString::null ) )
execute( t, QString::null, TRUE);
} else if ( msg == "raise(QString)" ) {
QString appName;
stream >> appName;
if ( !executeBuiltin( appName, QString::null ) ) {
if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) {
//qDebug( "Raising: %s", appName.latin1() );
QCString channel = "QPE/Application/";
channel += appName.latin1();
// Need to lock it to avoid race conditions with QPEApplication::processQCopFile
QFile f("/tmp/qcop-msg-" + appName);
if ( f.open(IO_WriteOnly | IO_Append) ) {
#ifndef Q_OS_WIN32
flock(f.handle(), LOCK_EX);
#endif
QDataStream ds(&f);
QByteArray b;
QDataStream bstream(b, IO_WriteOnly);
ds << channel << QCString("raise()") << b;
f.flush();
#ifndef Q_OS_WIN32
flock(f.handle(), LOCK_UN);
#endif
f.close();
}
bool alreadyRunning = isRunning( appName );
if ( execute(appName, QString::null) ) {
int id = startTimer(RAISE_TIMEOUT_MS + alreadyRunning?2000:0);
waitingHeartbeat.insert( appName, id );
}
}
}
} else if ( msg == "sendRunningApps()" ) {
QStringList apps;
QMap<int,QString>::Iterator it;
for( it = runningApps.begin(); it != runningApps.end(); ++it )
apps.append( *it );
QCopEnvelope e( "QPE/Desktop", "runningApps(QStringList)" );
e << apps;
} else if ( msg == "appRaised(QString)" ) {
QString appName;
stream >> appName;
qDebug("Got a heartbeat from %s", appName.latin1());
QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName);
if ( it != waitingHeartbeat.end() ) {
killTimer( *it );
waitingHeartbeat.remove(it);
}
// Check to make sure we're not waiting on user input...
if ( appKillerBox && appName == appKillerName ) {
// If we are, we kill the dialog box, and the code waiting on the result
// will clean us up (basically the user said "no").
delete appKillerBox;
appKillerBox = 0;
appKillerName = QString::null;
}
}
}
void AppLauncher::signalHandler(int)
{
#ifndef Q_OS_WIN32
int status;
pid_t pid = waitpid(-1, &status, WNOHANG);
/* if (pid == 0 || &status == 0 ) {
qDebug("hmm, could not get return value from signal");
}
*/
QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) );
#else
qDebug("Unhandled signal see by AppLauncher::signalHandler(int)");
#endif
}
bool AppLauncher::event(QEvent *e)
{
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index 63f853e..3e0a96c 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -1,241 +1,242 @@
/**********************************************************************
** Copyright (C) 2000-2002 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.
**
**********************************************************************/
#include "documentlist.h"
#include "serverinterface.h"
#include "mediadlg.h"
#include <opie2/oglobal.h>
#include <qtopia/config.h>
#include <qtopia/mimetype.h>
#include <qtopia/resource.h>
#include <qtopia/private/categories.h>
#include <qtopia/qpeapplication.h>
#include <qtopia/applnk.h>
#include <qtopia/storage.h>
#ifdef Q_WS_QWS
#include <qtopia/qcopenvelope_qws.h>
#endif
#include <qtimer.h>
#include <qfileinfo.h>
#include <qtextstream.h>
#include <qfile.h>
#include <qdir.h>
#include <qpainter.h>
#include <qimage.h>
#include <qcopchannel_qws.h>
#include <qlistview.h>
#include <qlist.h>
#include <qpixmap.h>
+using namespace Opie::Core;
AppLnkSet *DocumentList::appLnkSet = 0;
static const int MAX_SEARCH_DEPTH = 10;
class DocumentListPrivate : public QObject {
Q_OBJECT
public:
DocumentListPrivate( ServerInterface *gui );
~DocumentListPrivate();
void initialize();
const QString nextFile();
const DocLnk *iterate();
bool store( DocLnk* dl );
void estimatedPercentScanned();
void appendDocpath(FileSystem*);
DocLnkSet dls;
QDict<void> reference;
QDictIterator<void> *dit;
enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state;
QStringList docPaths;
unsigned int docPathsSearched;
int searchDepth;
QDir *listDirs[MAX_SEARCH_DEPTH];
const QFileInfoList *lists[MAX_SEARCH_DEPTH];
unsigned int listPositions[MAX_SEARCH_DEPTH];
StorageInfo *storage;
int tid;
ServerInterface *serverGui;
bool needToSendAllDocLinks;
bool sendAppLnks;
bool sendDocLnks;
bool scanDocs;
};
/*
* scandocs will be read from Config
*/
DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/,
QObject *parent, const char *name )
: QObject( parent, name )
{
appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
d = new DocumentListPrivate( serverGui );
d->needToSendAllDocLinks = false;
Config cfg( "Launcher" );
cfg.setGroup( "DocTab" );
d->scanDocs = cfg.readBoolEntry( "Enable", true );
qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs );
QTimer::singleShot( 10, this, SLOT( startInitialScan() ) );
}
void DocumentList::startInitialScan()
{
reloadAppLnks();
reloadDocLnks();
}
DocumentList::~DocumentList()
{
delete appLnkSet;
delete d;
}
void DocumentList::add( const DocLnk& doc )
{
if ( d->serverGui && QFile::exists( doc.file() ) )
d->serverGui->documentAdded( doc );
}
void DocumentList::start()
{
resume();
}
void DocumentList::pause()
{
//qDebug("pause %i", d->tid);
killTimer( d->tid );
d->tid = 0;
}
void DocumentList::resume()
{
if ( d->tid == 0 ) {
d->tid = startTimer( 20 );
//qDebug("resumed %i", d->tid);
}
}
/*
void DocumentList::resend()
{
// Re-emits all the added items to the list (firstly letting everyone know to
// clear what they have as it is being sent again)
pause();
emit allRemoved();
QTimer::singleShot( 5, this, SLOT( resendWorker() ) );
}
void DocumentList::resendWorker()
{
const QList<DocLnk> &list = d->dls.children();
for ( QListIterator<DocLnk> it( list ); it.current(); ++it )
add( *(*it) );
resume();
}
*/
void DocumentList::rescan()
{
//qDebug("rescan");
pause();
d->initialize();
resume();
}
void DocumentList::timerEvent( QTimerEvent *te )
{
if ( te->timerId() == d->tid ) {
// Do 3 at a time
for (int i = 0; i < 3; i++ ) {
const DocLnk *lnk = d->iterate();
if ( lnk ) {
add( *lnk );
} else {
// stop when done
pause();
if ( d->serverGui )
d->serverGui->documentScanningProgress( 100 );
if ( d->needToSendAllDocLinks )
sendAllDocLinks();
break;
}
}
}
}
void DocumentList::reloadAppLnks()
{
if ( d->sendAppLnks && d->serverGui ) {
d->serverGui->applicationScanningProgress( 0 );
d->serverGui->allApplicationsRemoved();
}
delete appLnkSet;
appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
if ( d->sendAppLnks && d->serverGui ) {
static QStringList prevTypeList;
QStringList types = appLnkSet->types();
for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) {
if ( !(*ittypes).isEmpty() ) {
if ( !prevTypeList.contains(*ittypes) ) {
QString name = appLnkSet->typeName(*ittypes);
QPixmap pm = appLnkSet->typePixmap(*ittypes);
QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes);
if (pm.isNull()) {
QImage img( Resource::loadImage( "UnknownDocument" ) );
pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() );
}
//qDebug("adding type %s", (*ittypes).latin1());
// ### our current launcher expects docs tab to be last
d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
}
prevTypeList.remove(*ittypes);
}
}
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
index c136bd9..3e7e0d2 100644
--- a/core/launcher/main.cpp
+++ b/core/launcher/main.cpp
@@ -1,257 +1,257 @@
/**********************************************************************
** Copyright (C) 2000-2002 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 QTOPIA_INTERNAL_FILEOPERATIONS
#define QTOPIA_INTERNAL_FILEOPERATIONS
#endif
#include "server.h"
#include "serverapp.h"
#include "stabmon.h"
#include "firstuse.h"
#include <opie2/oglobal.h>
#include <qtopia/network.h>
//#include <qtopia/custom.h>
#include <qdir.h>
#ifdef QWS
#include <qwindowsystem_qws.h>
#include <qtopia/qcopenvelope_qws.h>
#endif
#include <qtopia/alarmserver.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#ifndef Q_OS_WIN32
#include <unistd.h>
#else
#include <process.h>
#endif
#include "calibrate.h"
#ifdef QT_QWS_LOGIN
#include "../login/qdmdialogimpl.h"
#endif
#ifdef Q_WS_QWS
#include <qkeyboard_qws.h>
#endif
#include <qmessagebox.h>
#include <opie2/odevice.h>
-using namespace Opie;
+using namespace Opie::Core;
static void cleanup()
{
QDir dir( "/tmp", "qcop-msg-*" );
QStringList stale = dir.entryList();
QStringList::Iterator it;
for ( it = stale.begin(); it != stale.end(); ++it ) {
dir.remove( *it );
}
}
static void refreshTimeZoneConfig()
{
/* ### FIXME timezone handling */
#if 0
// We need to help WorldTime in setting up its configuration for
// the current translation
// BEGIN no tr
const char *defaultTz[] = {
"America/New_York",
"America/Los_Angeles",
"Europe/Oslo",
"Asia/Tokyo",
"Asia/Hong_Kong",
"Australia/Brisbane",
0
};
// END no tr
TimeZone curZone;
QString zoneID;
int zoneIndex;
Config cfg = Config( "WorldTime" );
cfg.setGroup( "TimeZones" );
if (!cfg.hasKey( "Zone0" )){
// We have no existing timezones use the defaults which are untranslated strings
QString currTz = TimeZone::current().id();
QStringList zoneDefaults;
zoneDefaults.append( currTz );
for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) {
if ( defaultTz[i] != currTz )
zoneDefaults.append( defaultTz[i] );
}
zoneIndex = 0;
for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){
cfg.writeEntry( "Zone" + QString::number( zoneIndex ) , *it);
zoneIndex++;
}
}
// We have an existing list of timezones refresh the
// translations of TimeZone name
zoneIndex = 0;
while (cfg.hasKey( "Zone"+ QString::number( zoneIndex ))){
zoneID = cfg.readEntry( "Zone" + QString::number( zoneIndex ));
curZone = TimeZone( zoneID );
if ( !curZone.isValid() ){
qDebug( "initEnvironment() Invalid TimeZone %s", zoneID.latin1() );
break;
}
cfg.writeEntry( "ZoneName" + QString::number( zoneIndex ), curZone.city() );
zoneIndex++;
}
#endif
}
void initEnvironment()
{
#ifdef Q_OS_WIN32
// Config file requires HOME dir which uses QDir which needs the winver
qt_init_winver();
#endif
Config config("locale");
config.setGroup( "Location" );
QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace();
// if not timezone set, pick New York
if (tz.isNull() || tz.isEmpty())
tz = "America/New_York";
setenv( "TZ", tz, 1 );
config.writeEntry( "Timezone", tz);
config.setGroup( "Language" );
QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace();
if( lang.isNull() || lang.isEmpty())
lang = "en_US";
setenv( "LANG", lang, 1 );
config.writeEntry("Language", lang);
config.write();
#if 0
setenv( "QWS_SIZE", "240x320", 0 );
#endif
QString env(getenv("QWS_DISPLAY"));
if (env.contains("Transformed")) {
int rot;
// transformed driver default rotation is controlled by the hardware.
Config config("qpe");
config.setGroup( "Rotation" );
if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 )
rot = ODevice::inst ( )-> rotation ( ) * 90;
setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */
}
}
static void initKeyboard()
{
Config config("qpe");
config.setGroup( "Keyboard" );
int ard = config.readNumEntry( "RepeatDelay" );
int arp = config.readNumEntry( "RepeatPeriod" );
if ( ard > 0 && arp > 0 )
qwsSetKeyboardAutoRepeat( ard, arp );
QString layout = config.readEntry( "Layout", "us101" );
Server::setKeyboardLayout( layout );
}
static bool firstUse()
{
bool needFirstUse = FALSE;
if ( QWSServer::mouseHandler() &&
QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) {
if ( !QFile::exists( "/etc/pointercal" ) )
needFirstUse = TRUE;
}
{
Config config( "qpe" );
config.setGroup( "Startup" );
needFirstUse |= config.readBoolEntry( "FirstUse", TRUE );
}
if ( !needFirstUse )
return FALSE;
FirstUse *fu = new FirstUse();
fu->exec();
bool rs = fu->restartNeeded();
delete fu;
return rs;
}
int initApplication( int argc, char ** argv )
{
cleanup();
initEnvironment();
//Don't flicker at startup:
#ifdef QWS
QWSServer::setDesktopBackground( QImage() );
#endif
ServerApplication a( argc, argv, QApplication::GuiServer );
refreshTimeZoneConfig();
initKeyboard();
// Don't use first use under Windows
if ( firstUse() ) {
a.restart();
return 0;
}
ODevice::inst ( )-> setSoftSuspend ( true );
{
QCopEnvelope e("QPE/System", "setBacklight(int)" );
e << -3; // Forced on
}
AlarmServer::initialize();
Server *s = new Server();
(void)new SysFileMonitor(s);
#ifdef QWS
Network::createServer(s);
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 53efba4..33df6c4 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,248 +1,249 @@
/**********************************************************************
** Copyright (C) 2000-2002 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.
**
**********************************************************************/
#include "qcopbridge.h"
#include "transferserver.h"
#include <opie2/oglobal.h>
#ifdef Q_WS_QWS
#include <qtopia/qcopenvelope_qws.h>
#endif
#include <qtopia/qpeapplication.h>
#include <qtopia/version.h>
#include <qtextstream.h>
#include <qtimer.h>
#ifdef Q_WS_QWS
#include <qcopchannel_qws.h>
#endif
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE
#endif
#ifndef Q_OS_WIN32
#include <pwd.h>
#include <unistd.h>
#include <sys/types.h>
#endif
#if defined(_OS_LINUX_)
#include <shadow.h>
#endif
//#define INSECURE
const int block_size = 51200;
+using namespace Opie::Core;
QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
const char* name )
: QServerSocket( port, 1, parent, name ),
desktopChannel( 0 ),
cardChannel( 0 )
{
if ( !ok() )
qWarning( "Failed to bind to port %d", port );
else {
#ifndef QT_NO_COP
desktopChannel = new QCopChannel( "QPE/Desktop", this );
connect( desktopChannel, SIGNAL(received(const QCString&,const QByteArray&)),
this, SLOT(desktopMessage(const QCString&,const QByteArray&)) );
cardChannel = new QCopChannel( "QPE/Card", this );
connect( cardChannel, SIGNAL(received(const QCString&,const QByteArray&)),
this, SLOT(desktopMessage(const QCString&,const QByteArray&)) );
#endif
}
sendSync = FALSE;
openConnections.setAutoDelete( TRUE );
authorizeConnections();
}
QCopBridge::~QCopBridge()
{
#ifndef QT_NO_COP
delete desktopChannel;
#endif
}
void QCopBridge::authorizeConnections()
{
Config cfg("Security");
cfg.setGroup("SyncMode");
m_mode = Mode(cfg.readNumEntry("Mode", Sharp ));
QListIterator<QCopBridgePI> it(openConnections);
while ( it.current() ) {
if ( !it.current()->verifyAuthorised() ) {
disconnect ( it.current(), SIGNAL( connectionClosed(QCopBridgePI*) ), this, SLOT( closed(QCopBridgePI*) ) );
openConnections.removeRef( it.current() );
} else
++it;
}
}
void QCopBridge::newConnection( int socket )
{
QCopBridgePI *pi = new QCopBridgePI( socket, this );
openConnections.append( pi );
connect ( pi, SIGNAL( connectionClosed(QCopBridgePI*) ), this, SLOT( closed(QCopBridgePI*) ) );
/* ### libqtopia merge FIXME */
#if 0
QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend );
#endif
#ifndef QT_NO_COP
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
#endif
if ( sendSync ) {
pi ->startSync();
sendSync = FALSE;
}
}
void QCopBridge::closed( QCopBridgePI *pi )
{
emit connectionClosed( pi->peerAddress() );
openConnections.removeRef( pi );
if ( openConnections.count() == 0 ) {
/* ### FIXME libqtopia merge */
#if 0
QPEApplication::setTempScreenSaverMode( QPEApplication::Enable );
#endif
#ifndef QT_NO_COP
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
#endif
}
}
void QCopBridge::closeOpenConnections()
{
QCopBridgePI *pi;
for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
pi->close();
}
void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data )
{
if ( command == "startSync()" ) {
// we need to buffer it a bit
sendSync = TRUE;
startTimer( 20000 );
}
if ( m_mode & Qtopia1_7 ) {
// send the command to all open connections
QCopBridgePI *pi;
for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
pi->sendDesktopMessage( command, data );
}
}
if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) )
sendDesktopMessageOld( command, data );
}
#ifndef OPIE_NO_OLD_SYNC_CODE
/*
* Old compat mode
*/
void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) {
command.stripWhiteSpace();
int paren = command.find( "(" );
if ( paren <= 0 ) {
qDebug("DesktopMessage: bad qcop syntax");
return;
}
QString params = command.mid( paren + 1 );
if ( params[params.length()-1] != ')' ) {
qDebug("DesktopMessage: bad qcop syntax");
return;
}
params.truncate( params.length()-1 );
QStringList paramList = QStringList::split( ",", params );
QString data;
if ( paramList.count() ) {
QDataStream stream( args, IO_ReadOnly );
for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
QString str;
if ( *it == "QString" ) {
stream >> str;
} else if ( *it == "QCString" ) {
QCString cstr;
stream >> cstr;
str = QString::fromLocal8Bit( cstr );
} else if ( *it == "int" ) {
int i;
stream >> i;
str = QString::number( i );
} else if ( *it == "bool" ) {
int i;
stream >> i;
str = QString::number( i );
} else {
qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
return;
}
QString estr;
for (int i=0; i<(int)str.length(); i++) {
QChar ch = str[i];
if ( ch.row() )
goto quick;
switch (ch.cell()) {
case '&':
estr.append( "&amp;" );
break;
case ' ':
estr.append( "&0x20;" );
break;
case '\n':
estr.append( "&0x0d;" );
break;
case '\r':
estr.append( "&0x0a;" );
break;
default: quick:
estr.append(ch);
}
}
data += " " + estr;
}
}
QString sendCommand = QString(command.data()) + data;
// send the command to all open connections
QCopBridgePI *pi;
for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
pi->sendDesktopMessage( sendCommand );
}
#endif
void QCopBridge::timerEvent( QTimerEvent * )
{
sendSync = FALSE;
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp
index e544c61..6aaab3a 100644
--- a/core/launcher/screensaver.cpp
+++ b/core/launcher/screensaver.cpp
@@ -1,328 +1,328 @@
#include "screensaver.h"
#include <qpe/config.h>
#include <qpe/network.h>
#include <opie2/odevice.h>
-using namespace Opie;
+using namespace Opie::Core;
OpieScreenSaver::OpieScreenSaver ( )
: QObject ( 0, "screensaver" ), QWSScreenSaver ( )
{
m_disable_suspend = 100;
m_enable_dim = false;
m_enable_lightoff = false;
m_enable_suspend = false;
m_onlylcdoff = false;
m_enable_dim_ac = false;
m_enable_lightoff_ac = false;
m_enable_suspend_ac = false;
m_onlylcdoff_ac = false;
m_use_light_sensor = false;
m_backlight_sensor = -1;
::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] ));
m_lcd_status = true;
m_backlight_normal = -1;
m_backlight_current = -1;
m_backlight_forcedoff = false;
m_on_ac = false;
m_level = -1;
// Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
ODevice::inst ( )-> setDisplayStatus ( true );
setBacklight ( -1 );
}
/**
* Stops the screen saver
*/
void OpieScreenSaver::restore()
{
m_level = -1;
if ( !m_lcd_status ) { // We must have turned it off
ODevice::inst ( ) -> setDisplayStatus ( true );
m_lcd_status = true;
}
setBacklightInternal ( -1 );
}
/**
* Starts the screen saver
*
* @param level what level of screen saving should happen (0=lowest non-off, 1=off,
* 2=suspend whole machine)
* @returns true on success
*/
bool OpieScreenSaver::save( int level )
{
m_level = level;
switch ( level ) {
case 0:
if (( m_on_ac && m_enable_dim_ac ) ||
( !m_on_ac && m_enable_dim )) {
if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor )
setBacklightInternal ( 1 ); // lowest non-off
}
return true;
break;
case 1:
if (( m_on_ac && m_enable_lightoff_ac ) ||
( !m_on_ac && m_enable_lightoff )) {
if ( m_disable_suspend > 1 )
setBacklightInternal ( 0 ); // off
}
return true;
break;
case 2:
if (( m_on_ac && !m_enable_suspend_ac ) ||
( !m_on_ac && !m_enable_suspend )) {
return true;
}
if (( m_on_ac && m_onlylcdoff_ac ) ||
( !m_on_ac && m_onlylcdoff )) {
ODevice::inst ( ) -> setDisplayStatus ( false );
m_lcd_status = false;
return true;
}
// We're going to suspend the whole machine
if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) {
// TODO: why is this key F34 hard coded? -- schurig
// Does this now only work an devices with a ODevice::filter?
QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
return true;
}
break;
}
return false;
}
/**
* Set intervals in seconds for automatic dimming, light off and suspend
*
* This function also sets the member variables m_m_enable_dim[_ac],
* m_enable_lightoff[_ac], m_enable_suspend[_ac], m_onlylcdoff[_ac]
*
* @param dim time in seconds to dim, -1 to read value from config file,
* 0 to disable
* @param lightoff time in seconds to turn LCD backlight off, -1 to
* read value from config file, 0 to disable
* @param suspend time in seconds to do an APM suspend, -1 to
* read value from config file, 0 to disable
*/
void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend )
{
Config config ( "apm" );
config. setGroup ( m_on_ac ? "AC" : "Battery" );
int v[ 4 ];
if ( dim < 0 )
dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 );
if ( lightoff < 0 )
lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 );
if ( suspend < 0 )
suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 );
if ( m_on_ac ) {
m_enable_dim_ac = ( dim > 0 );
m_enable_lightoff_ac = ( lightoff > 0 );
m_enable_suspend_ac = ( suspend > 0 );
m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false );
}
else {
m_enable_dim = ( dim > 0 );
m_enable_lightoff = ( lightoff > 0 );
m_enable_suspend = ( suspend > 0 );
m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false );
}
-
+
//qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend);
v [ 0 ] = QMAX( 1000 * dim, 100 );
v [ 1 ] = QMAX( 1000 * lightoff, 100 );
v [ 2 ] = QMAX( 1000 * suspend, 100 );
v [ 3 ] = 0;
if ( !dim && !lightoff && !suspend )
QWSServer::setScreenSaverInterval( 0 );
else
QWSServer::setScreenSaverIntervals( v );
}
/**
* Set suspend time. Will read the dim and lcd-off times from the config file.
*
* @param suspend time in seconds to go into APM suspend, -1 to
* read value from config file, 0 to disable
*/
void OpieScreenSaver::setInterval ( int interval )
{
setIntervals ( -1, -1, interval );
}
void OpieScreenSaver::setMode ( int mode )
{
if ( mode > m_disable_suspend )
setInterval ( -1 );
m_disable_suspend = mode;
}
/**
* Set display brightness
*
* Get's default values for backlight, contrast and light sensor from config file.
*
* @param bright desired brighness (-1 to use automatic sensor data or value
* from config file, -2 to toggle backlight on and off, -3 to
* force backlight off)
*/
void OpieScreenSaver::setBacklight ( int bright )
{
// Read from config
Config config ( "apm" );
config. setGroup ( m_on_ac ? "AC" : "Battery" );
m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 );
int contrast = config. readNumEntry ( "Contrast", 127);
m_use_light_sensor = config. readBoolEntry ( "LightSensor", false );
//qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 );
killTimers ( );
if (( bright < 0 ) && m_use_light_sensor ) {
QStringList sl = config. readListEntry ( "LightSensorData", ';' );
-
+
m_sensordata [LS_SensorMin] = 40;
m_sensordata [LS_SensorMax] = 215;
m_sensordata [LS_LightMin] = 1;
m_sensordata [LS_LightMax] = 255;
m_sensordata [LS_Steps] = 12;
- m_sensordata [LS_Interval] = 2000;
-
+ m_sensordata [LS_Interval] = 2000;
+
for ( uint i = 0; i < LS_Count; i++ ) {
if ( i < sl. count ( ))
m_sensordata [i] = sl [i]. toInt ( );
}
if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE
m_sensordata [LS_Steps] = 2;
timerEvent ( 0 );
startTimer ( m_sensordata [LS_Interval] );
}
setBacklightInternal ( bright );
ODevice::inst ( )-> setDisplayContrast(contrast);
}
/**
* Internal brightness setting method
*
* Get's default values for backlight and light sensor from config file.
*
* @param bright desired brighness (-1 to use automatic sensor data or value
* from config file, -2 to toggle backlight on and off, -3 to
* force backlight off)
*/
void OpieScreenSaver::setBacklightInternal ( int bright )
{
if ( bright == -3 ) {
// Forced on
m_backlight_forcedoff = false;
bright = -1;
}
if ( m_backlight_forcedoff && bright != -2 )
return ;
if ( bright == -2 ) {
// Toggle between off and on
bright = m_backlight_current ? 0 : -1;
m_backlight_forcedoff = !bright;
}
if ( bright == -1 )
bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal;
if ( bright != m_backlight_current ) {
ODevice::inst ( )-> setDisplayBrightness ( bright );
m_backlight_current = bright;
}
}
/**
* Timer event used for automatic setting the backlight according to a light sensor
* and to set the default brightness
*/
void OpieScreenSaver::timerEvent ( QTimerEvent * )
{
int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( );
-
+
if ( s < m_sensordata [LS_SensorMin] )
m_backlight_sensor = m_sensordata [LS_LightMax];
else if ( s >= m_sensordata [LS_SensorMax] )
m_backlight_sensor = m_sensordata [LS_LightMin];
else {
int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin];
int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin];
-
+
int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0
-
+
m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 );
}
//qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] );
if ( m_level <= 0 )
setBacklightInternal ( -1 );
}
/**
* Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status.
*/
void OpieScreenSaver::setDisplayState ( bool on )
{
if ( m_lcd_status != on ) {
ODevice::inst ( ) -> setDisplayStatus ( on );
m_lcd_status = on;
}
}
/**
* Set display to default ac/battery settings when power status changed.
*/
void OpieScreenSaver::powerStatusChanged ( PowerStatus ps )
{
bool newonac = ( ps. acStatus ( ) == PowerStatus::Online );
-
+
if ( newonac != m_on_ac ) {
m_on_ac = newonac;
setInterval ( -1 );
setBacklight ( -1 );
- restore ( );
+ restore ( );
}
}
diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp
index ea0b792..634082b 100644
--- a/core/launcher/server.cpp
+++ b/core/launcher/server.cpp
@@ -1,419 +1,419 @@
/**********************************************************************
** Copyright (C) 2000-2002 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.
**
**********************************************************************/
#include "server.h"
#include "serverapp.h"
#include "startmenu.h"
#include "launcher.h"
#include "transferserver.h"
#include "qcopbridge.h"
#include "irserver.h"
#include "packageslave.h"
#include "calibrate.h"
#include "qrsync.h"
#include "syncdialog.h"
#include "shutdownimpl.h"
#include "applauncher.h"
#if 0
#include "suspendmonitor.h"
#endif
#include "documentlist.h"
#include <qtopia/applnk.h>
#include <qtopia/private/categories.h>
#include <qtopia/mimetype.h>
#include <qtopia/config.h>
#include <qtopia/resource.h>
#include <qtopia/version.h>
#include <qtopia/storage.h>
#include <qtopia/qcopenvelope_qws.h>
#include <qwindowsystem_qws.h>
#include <qgfx_qws.h>
#include <qtopia/global.h>
//#include <qtopia/custom.h>
#include <opie2/odevicebutton.h>
#include <opie2/odevice.h>
#include <unistd.h>
#include <qmainwindow.h>
#include <qmessagebox.h>
#include <qtimer.h>
#include <qtextstream.h>
#include <stdlib.h>
extern QRect qt_maxWindowRect;
-using namespace Opie;
+using namespace Opie::Core;
static QWidget *calibrate(bool)
{
#ifdef Q_WS_QWS
Calibrate *c = new Calibrate;
c->show();
return c;
#else
return 0;
#endif
}
#define FACTORY(T) \
static QWidget *new##T( bool maximized ) { \
QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \
if ( maximized ) { \
if ( qApp->desktop()->width() <= 350 ) { \
w->showMaximized(); \
} else { \
w->resize( QSize( 300, 300 ) ); \
} \
} \
w->show(); \
return w; \
}
#ifdef SINGLE_APP
#define APP(a,b,c,d) FACTORY(b)
#include "apps.h"
#undef APP
#endif // SINGLE_APP
static Global::Command builtins[] = {
#ifdef SINGLE_APP
#define APP(a,b,c,d) { a, new##b, c, d },
#include "apps.h"
#undef APP
#endif
/* FIXME defines need to be defined*/
#if !defined(OPIE_NO_BUILTIN_CALIBRATE)
{ "calibrate", calibrate, 1, 0 }, // No tr
#endif
#if !defined(OPIE_NO_BUILTIN_SHUTDOWN)
{ "shutdown", Global::shutdown, 1, 0 }, // No tr
// { "run", run, 1, 0 }, // No tr
#endif
{ 0, calibrate, 0, 0 },
};
//---------------------------------------------------------------------------
//===========================================================================
Server::Server() :
QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
qcopBridge( 0 ),
transferServer( 0 ),
packageHandler( 0 ),
syncDialog( 0 )
{
Global::setBuiltinCommands(builtins);
tid_xfer = 0;
/* ### FIXME ### */
/* tid_today = startTimer(3600*2*1000);*/
last_today_show = QDate::currentDate();
#if 0
tsmMonitor = new TempScreenSaverMode();
connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) );
#endif
serverGui = new Launcher;
serverGui->createGUI();
docList = new DocumentList( serverGui );
appLauncher = new AppLauncher(this);
connect(appLauncher, SIGNAL(launched(int,const QString&)), this, SLOT(applicationLaunched(int,const QString&)) );
connect(appLauncher, SIGNAL(terminated(int,const QString&)), this, SLOT(applicationTerminated(int,const QString&)) );
connect(appLauncher, SIGNAL(connected(const QString&)), this, SLOT(applicationConnected(const QString&)) );
storage = new StorageInfo( this );
connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) );
// start services
startTransferServer();
(void) new IrServer( this );
packageHandler = new PackageHandler( this );
- connect(qApp, SIGNAL(activate(const Opie::ODeviceButton*,bool)),
- this,SLOT(activate(const Opie::ODeviceButton*,bool)));
+ connect(qApp, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)),
+ this,SLOT(activate(const Opie::Core::ODeviceButton*,bool)));
setGeometry( -10, -10, 9, 9 );
QCopChannel *channel = new QCopChannel("QPE/System", this);
connect(channel, SIGNAL(received(const QCString&,const QByteArray&)),
this, SLOT(systemMsg(const QCString&,const QByteArray&)) );
QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this );
connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)),
this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) );
connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) );
connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) );
preloadApps();
}
void Server::show()
{
ServerApplication::login(TRUE);
QWidget::show();
}
Server::~Server()
{
serverGui->destroyGUI();
delete docList;
delete qcopBridge;
delete transferServer;
delete serverGui;
#if 0
delete tsmMonitor;
#endif
}
static bool hasVisibleWindow(const QString& clientname, bool partial)
{
#ifdef QWS
const QList<QWSWindow> &list = qwsServer->clientWindows();
QWSWindow* w;
for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
if ( w->client()->identity() == clientname ) {
if ( partial && !w->isFullyObscured() )
return TRUE;
if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) {
# if QT_VERSION < 0x030000
QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect,
QSize(qt_screen->width(),qt_screen->height()) );
# else
QRect mwr = qt_maxWindowRect;
# endif
if ( mwr.contains(w->requested().boundingRect()) )
return TRUE;
}
}
}
#endif
return FALSE;
}
-void Server::activate(const Opie::ODeviceButton* button, bool held)
+void Server::activate(const ODeviceButton* button, bool held)
{
Global::terminateBuiltin("calibrate"); // No tr
- Opie::OQCopMessage om;
+ OQCopMessage om;
if ( held ) {
om = button->heldAction();
} else {
om = button->pressedAction();
}
if ( om.channel() != "ignore" )
om.send();
// A button with no action defined, will return a null ServiceRequest. Don't attempt
// to send/do anything with this as it will crash
/* ### FIXME */
#if 0
if ( !sr.isNull() ) {
QString app = sr.app();
bool vis = hasVisibleWindow(app, app != "qpe");
if ( sr.message() == "raise()" && vis ) {
sr.setMessage("nextView()");
} else {
// "back door"
sr << (int)vis;
}
sr.send();
}
#endif
}
#ifdef Q_WS_QWS
typedef struct KeyOverride {
ushort scan_code;
QWSServer::KeyMap map;
};
static const KeyOverride jp109keys[] = {
{ 0x03, { Qt::Key_2, '2' , 0x22 , 0xffff } },
{ 0x07, { Qt::Key_6, '6' , '&' , 0xffff } },
{ 0x08, { Qt::Key_7, '7' , '\'' , 0xffff } },
{ 0x09, { Qt::Key_8, '8' , '(' , 0xffff } },
{ 0x0a, { Qt::Key_9, '9' , ')' , 0xffff } },
{ 0x0b, { Qt::Key_0, '0' , 0xffff , 0xffff } },
{ 0x0c, { Qt::Key_Minus, '-' , '=' , 0xffff } },
{ 0x0d, { Qt::Key_AsciiCircum,'^' , '~' , '^' - 64 } },
{ 0x1a, { Qt::Key_At, '@' , '`' , 0xffff } },
{ 0x1b, { Qt::Key_BraceLeft, '[' , '{' , '[' - 64 } },
{ 0x27, { Qt::Key_Semicolon, ';' , '+' , 0xffff } },
{ 0x28, { Qt::Key_Colon, ':' , '*' , 0xffff } },
{ 0x29, { Qt::Key_Zenkaku_Hankaku, 0xffff , 0xffff , 0xffff } },
{ 0x2b, { Qt::Key_BraceRight, ']' , '}' , ']'-64 } },
{ 0x70, { Qt::Key_Hiragana_Katakana, 0xffff , 0xffff , 0xffff } },
{ 0x73, { Qt::Key_Backslash, '\\' , '_' , 0xffff } },
{ 0x79, { Qt::Key_Henkan, 0xffff , 0xffff , 0xffff } },
{ 0x7b, { Qt::Key_Muhenkan, 0xffff , 0xffff , 0xffff } },
{ 0x7d, { Qt::Key_yen, 0x00a5 , '|' , 0xffff } },
{ 0x00, { 0, 0xffff , 0xffff , 0xffff } }
};
bool Server::setKeyboardLayout( const QString &kb )
{
//quick demo version that can be extended
QIntDict<QWSServer::KeyMap> *om = 0;
if ( kb == "us101" ) { // No tr
om = 0;
} else if ( kb == "jp109" ) {
om = new QIntDict<QWSServer::KeyMap>(37);
const KeyOverride *k = jp109keys;
while ( k->scan_code ) {
om->insert( k->scan_code, &k->map );
k++;
}
}
QWSServer::setOverrideKeys( om );
return TRUE;
}
#endif
void Server::systemMsg(const QCString &msg, const QByteArray &data)
{
QDataStream stream( data, IO_ReadOnly );
if ( msg == "securityChanged()" ) {
if ( transferServer )
transferServer->authorizeConnections();
if ( qcopBridge )
qcopBridge->authorizeConnections();
}
/* ### FIXME support TempScreenSaverMode */
#if 0
else if ( msg == "setTempScreenSaverMode(int,int)" ) {
int mode, pid;
stream >> mode >> pid;
tsmMonitor->setTempMode(mode, pid);
}
#endif
else if ( msg == "linkChanged(QString)" ) {
QString link;
stream >> link;
qDebug( "desktop.cpp systemMsg -> linkchanged( %s )", link.latin1() );
docList->linkChanged(link);
} else if ( msg == "serviceChanged(QString)" ) {
MimeType::updateApplications();
} else if ( msg == "mkdir(QString)" ) {
QString dir;
stream >> dir;
if ( !dir.isEmpty() )
mkdir( dir );
} else if ( msg == "rdiffGenSig(QString,QString)" ) {
QString baseFile, sigFile;
stream >> baseFile >> sigFile;
QRsync::generateSignature( baseFile, sigFile );
} else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) {
QString baseFile, sigFile, deltaFile;
stream >> baseFile >> sigFile >> deltaFile;
QRsync::generateDiff( baseFile, sigFile, deltaFile );
} else if ( msg == "rdiffApplyPatch(QString,QString)" ) {
QString baseFile, deltaFile;
stream >> baseFile >> deltaFile;
if ( !QFile::exists( baseFile ) ) {
QFile f( baseFile );
f.open( IO_WriteOnly );
f.close();
}
QRsync::applyDiff( baseFile, deltaFile );
#ifndef QT_NO_COP
QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" );
e << baseFile;
#endif
} else if ( msg == "rdiffCleanup()" ) {
mkdir( "/tmp/rdiff" );
QDir dir;
dir.setPath( "/tmp/rdiff" );
QStringList entries = dir.entryList();
for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it )
dir.remove( *it );
} else if ( msg == "sendHandshakeInfo()" ) {
QString home = getenv( "HOME" );
#ifndef QT_NO_COP
QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" );
e << home;
int locked = (int) ServerApplication::screenLocked();
e << locked;
#endif
}
/*
* QtopiaDesktop relies on the major number
* to start with 1. We're at 0.9
* so wee need to fake at least 1.4 to be able
* to sync with QtopiaDesktop1.6
*/
else if ( msg == "sendVersionInfo()" ) {
QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" );
/* ### FIXME Architecture ### */
e << QString::fromLatin1("1.7") << "Uncustomized Device";
} else if ( msg == "sendCardInfo()" ) {
#ifndef QT_NO_COP
QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" );
#endif
storage->update();
const QList<FileSystem> &fs = storage->fileSystems();
QListIterator<FileSystem> it ( fs );
QString s;
QString homeDir = getenv("HOME");
QString homeFs, homeFsPath;
for ( ; it.current(); ++it ) {
int k4 = (*it)->blockSize()/256;
if ( (*it)->isRemovable() ) {
s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr
+ QString::number( (*it)->availBlocks() * k4/4 )
+ "K " + (*it)->options() + ";";
} else if ( homeDir.contains( (*it)->path() ) &&
(*it)->path().length() > homeFsPath.length() ) {
homeFsPath = (*it)->path();
homeFs =
(*it)->name() + "=" + homeDir + "/Documents " // No tr
+ QString::number( (*it)->availBlocks() * k4/4 )
+ "K " + (*it)->options() + ";";
}
}
if ( !homeFs.isEmpty() )
s += homeFs;
#ifndef QT_NO_COP
e << s;
#endif
diff --git a/core/launcher/server.h b/core/launcher/server.h
index 91bf883..1dc5e7e 100644
--- a/core/launcher/server.h
+++ b/core/launcher/server.h
@@ -1,97 +1,99 @@
/**********************************************************************
** Copyright (C) 2000-2002 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 DESKTOP_H
#define DESKTOP_H
#include <qwidget.h>
#include <qdatetime.h>
//#include "qcopbridge.h"
class QCopBridge;
class QHostAddress;
class TransferServer;
class PackageHandler;
class ServiceRequest;
class TempScreenSaverMonitor;
class AppLauncher;
class AppLnkSet;
class StorageInfo;
class SyncDialog;
class DocumentList;
class ServerInterface;
namespace Opie {
+namespace Core {
class ODeviceButton;
}
+}
class Server : public QWidget {
Q_OBJECT
public:
Server();
~Server();
static bool mkdir(const QString &path);
void show();
static bool setKeyboardLayout( const QString &kb );
public slots:
void systemMsg(const QCString &, const QByteArray &);
void receiveTaskBar(const QCString &msg, const QByteArray &data);
void terminateServers();
void pokeTimeMonitors();
private slots:
- void activate(const Opie::ODeviceButton*,bool);
+ void activate(const Opie::Core::ODeviceButton*,bool);
void syncConnectionClosed( const QHostAddress & );
void applicationLaunched(int pid, const QString &app);
void applicationTerminated(int pid, const QString &app);
void applicationConnected(const QString &app);
void storageChanged();
void cancelSync();
protected:
void styleChange( QStyle & );
void timerEvent( QTimerEvent *e );
private:
void layout();
void startTransferServer();
void preloadApps();
QCopBridge *qcopBridge;
TransferServer *transferServer;
PackageHandler *packageHandler;
QDate last_today_show;
int tid_xfer;
/* ### FIXME two below### */
// int tid_today;
// TempScreenSaverMonitor *tsmMonitor;
StorageInfo *storage;
SyncDialog *syncDialog;
AppLauncher *appLauncher;
DocumentList *docList;
ServerInterface *serverGui;
};
#endif // DESKTOP_H
diff --git a/core/launcher/serverapp.cpp b/core/launcher/serverapp.cpp
index d38dd97..e4e16f2 100644
--- a/core/launcher/serverapp.cpp
+++ b/core/launcher/serverapp.cpp
@@ -1,543 +1,544 @@
/**********************************************************************
** 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.
**
**********************************************************************/
#include "serverapp.h"
#include <opie2/odevice.h>
#include <qtopia/password.h>
#include <qtopia/config.h>
#include <qtopia/power.h>
#ifdef Q_WS_QWS
#include <qtopia/qcopenvelope_qws.h>
#endif
#include <qtopia/global.h>
//#include <qtopia/custom.h>
#ifdef Q_WS_QWS
#include <qgfx_qws.h>
#endif
#ifdef Q_OS_WIN32
#include <io.h>
#include <process.h>
#else
#include <unistd.h>
#endif
#include <qmessagebox.h>
#include <qtimer.h>
#include <qpainter.h>
#include <qfile.h>
#include <qpixmapcache.h>
#include <stdlib.h>
#include "screensaver.h"
static ServerApplication *serverApp = 0;
static int loggedin=0;
using namespace Opie;
+using namespace Opie::Core;
QCopKeyRegister::QCopKeyRegister()
: m_keyCode( 0 ) {
}
QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m )
:m_keyCode( k ), m_channel( c ), m_message( m ) {
}
int QCopKeyRegister::keyCode()const {
return m_keyCode;
}
QCString QCopKeyRegister::channel()const {
return m_channel;
}
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);
+ const ODeviceButton* button = 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(activate(const Opie::Core::ODeviceButton*,bool)),
+ this,SIGNAL(activate(const Opie::Core::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 );
+ const ODeviceButton* but = 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;
QCString c, m;
stream >> k >> c >> m;
kf -> registerKey( QCopKeyRegister(k, c, m) );
}
}
bool ServerApplication::screenLocked()
{
return loggedin == 0;
}
void ServerApplication::login(bool at_poweron)
{
if ( !loggedin ) {
Global::terminateBuiltin("calibrate"); // No tr
Password::authenticate(at_poweron);
loggedin=1;
#ifndef QT_NO_COP
QCopEnvelope e( "QPE/Desktop", "unlocked()" );
#endif
}
}
#if defined(QPE_HAVE_TOGGLELIGHT)
#include <qtopia/config.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <linux/ioctl.h>
#include <time.h>
#endif
#if 0
static bool blanked=FALSE;
static void blankScreen()
{
#ifdef QWS
QWidget w(0, 0, Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool | Qt::WStyle_StaysOnTop | Qt::WPaintUnclipped);
w.resize( qt_screen->width(), qt_screen->height() );
w.move(0, 0);
QPainter p(&w);
p.fillRect(w.rect(), QBrush(QColor(255,255,255)) );
p.end();
w.repaint();
blanked = TRUE;
#endif
}
static void darkScreen()
{
/* ### Screen blanking ODevice */
#if 0
qpe_setBacklight(0); // force off
#endif
}
diff --git a/core/launcher/serverapp.h b/core/launcher/serverapp.h
index 4d9f808..916d83c 100644
--- a/core/launcher/serverapp.h
+++ b/core/launcher/serverapp.h
@@ -1,169 +1,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 <qtopia/qpeapplication.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::ODeviceButton*,bool);
+ void activate(const Opie::Core::ODeviceButton*,bool);
private:
bool keyRegistered( int key );
int held_tid;
- const Opie::ODeviceButton* heldButton;
+ const Opie::Core::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);
+ 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
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index a5e20b2..e32cf41 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,253 +1,254 @@
/**********************************************************************
** Copyright (C) 2000-2002 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.
**
**********************************************************************/
//#define _XOPEN_SOURCE
#include <opie2/oglobal.h>
#ifndef Q_OS_WIN32
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#ifndef Q_OS_MACX
#include <shadow.h>
#include <crypt.h>
#endif /* Q_OS_MACX */
#else
#include <stdlib.h>
#include <time.h>
#endif
#if defined(_OS_LINUX_)
#include <shadow.h>
#endif
#include <qtextstream.h>
#include <qmessagebox.h>
//#include <qtopia/qcopchannel_qws.h>
#include <qtopia/process.h>
#include <qtopia/private/contact.h>
#include <qtopia/version.h>
#ifdef Q_WS_QWS
#include <qtopia/qcopenvelope_qws.h>
#endif
#include "transferserver.h"
#include <qtopia/qprocess.h>
const int block_size = 51200;
+using namespace Opie::Core;
TransferServer::TransferServer( Q_UINT16 port, QObject *parent,
const char* name)
: QServerSocket( port, 1, parent, name )
{
connections.setAutoDelete( TRUE );
if ( !ok() )
qWarning( "Failed to bind to port %d", port );
}
void TransferServer::authorizeConnections()
{
QListIterator<ServerPI> it(connections);
while ( it.current() ) {
if ( !it.current()->verifyAuthorised() ) {
disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) );
connections.removeRef( it.current() );
} else
++it;
}
}
void TransferServer::closed(ServerPI *item)
{
connections.removeRef(item);
}
TransferServer::~TransferServer()
{
}
void TransferServer::newConnection( int socket )
{
ServerPI *ptr = new ServerPI( socket, this );
connect( ptr, SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) );
connections.append( ptr );
}
QString SyncAuthentication::serverId()
{
Config cfg("Security");
cfg.setGroup("Sync");
QString r = cfg.readEntry("serverid");
if ( r.isEmpty() ) {
r = OGlobal::generateUuid();
cfg.writeEntry("serverid", r );
}
return r;
}
QString SyncAuthentication::ownerName()
{
QString vfilename = Global::applicationFileName("addressbook",
"businesscard.vcf");
if (QFile::exists(vfilename)) {
Contact c;
c = Contact::readVCard( vfilename )[0];
return c.fullName();
}
return QString::null;
}
QString SyncAuthentication::loginName()
{
struct passwd *pw = 0L;
#ifndef Q_OS_WIN32
pw = getpwuid( geteuid() );
return QString::fromLocal8Bit( pw->pw_name );
#else
//### revise
return QString();
#endif
}
int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
{
Config cfg("Security");
cfg.setGroup("Sync");
// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
// QHostAddress allowed;
// allowed.setAddress(allowedstr);
// uint auth_peer = allowed.ip4Addr();
uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
return (peeraddress.ip4Addr() & mask) == auth_peer;
}
bool SyncAuthentication::checkUser( const QString& user )
{
if ( user.isEmpty() ) return FALSE;
QString euser = loginName();
return user == euser;
}
bool SyncAuthentication::checkPassword( const QString& password )
{
#ifdef ALLOW_UNIX_USER_FTP
// First, check system password...
struct passwd *pw = 0;
struct spwd *spw = 0;
pw = getpwuid( geteuid() );
spw = getspnam( pw->pw_name );
QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
if ( cpwd == "x" && spw )
cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
// Note: some systems use more than crypt for passwords.
QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
if ( cpwd == cpassword )
return TRUE;
#endif
static int lastdenial=0;
static int denials=0;
int now = time(0);
Config cfg("Security");
cfg.setGroup("SyncMode");
int mode = cfg.readNumEntry("Mode", 0x02 );
//No pass word needed if the user really needs it
if (mode & 0x04) {
QMessageBox unauth(
tr("Sync Connection"),
tr("<qt><p>An unauthorized system is requesting access to this device."
"<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ),
QMessageBox::Warning,
QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton,
0, QString::null, TRUE, WStyle_StaysOnTop);
unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) );
unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
switch( unauth.exec() ) {
case QMessageBox::Ok:
return TRUE;
break;
case QMessageBox::Cancel:
default:
denials++;
lastdenial=now;
return FALSE;
}
}
// Detect old Qtopia Desktop (no password) and fail
if ( password.isEmpty() ) {
if ( denials < 3 || now > lastdenial+600 ) {
QMessageBox unauth(
tr("Sync Connection"),
tr("<p>An unauthorized system is requesting access to this device."
"<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
"please upgrade or change the security setting to use IntelliSync." ),
QMessageBox::Warning,
QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
0, QString::null, TRUE, WStyle_StaysOnTop);
unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
unauth.exec();
denials++;
lastdenial=now;
}
return FALSE;
}
// Second, check sync password...
static int lock=0;
if ( lock ) return FALSE;
++lock;
/*
* we need to support old Sync software and QtopiaDesktop
*/
if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) {
Config cfg( "Security" );
cfg.setGroup("Sync");
QStringList pwds = cfg.readListEntry("Passwords",' ');
for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
#ifndef Q_OS_WIN32
QString cpassword = QString::fromLocal8Bit(
crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
#else
// ### revise
diff --git a/core/launcher/wait.cpp b/core/launcher/wait.cpp
index 4148e57..a5b329d 100644
--- a/core/launcher/wait.cpp
+++ b/core/launcher/wait.cpp
@@ -1,74 +1,75 @@
/**********************************************************************
** Copyright (C) 2000-2002 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.
**
**********************************************************************/
#include "wait.h"
#include <qtopia/config.h>
#include <opie2/owait.h>
Wait *lastWaitObject = NULL;
+using namespace Opie::Ui;
Wait::Wait( QWidget *parent ) : QWidget( parent ),
pm( Resource::loadPixmap( "wait" ) ), waiting( FALSE )
{
setFixedSize( pm.size() );
lastWaitObject = this;
m_centralWait = new OWait( 0l );
m_centralWait->hide();
hide();
}
Wait *Wait::getWaitObject()
{
return lastWaitObject;
}
void Wait::setWaiting( bool w )
{
Config cfg ( "Launcher" );
cfg.setGroup("GUI");
waiting = w;
if ( w ) {
if ( cfg. readBoolEntry( "BigBusy" ) )
m_centralWait->show();
else
show();
}else{
m_centralWait->hide();
hide();
}
}
void Wait::paintEvent( QPaintEvent * )
{
QPainter p( this );
p.drawPixmap( 0, 0, pm );
}
diff --git a/core/launcher/wait.h b/core/launcher/wait.h
index e7294d2..010fcc3 100644
--- a/core/launcher/wait.h
+++ b/core/launcher/wait.h
@@ -1,46 +1,46 @@
/**********************************************************************
** Copyright (C) 2000-2002 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 __WAIT_H__
#define __WAIT_H__
#include <qtopia/resource.h>
#include <qwidget.h>
#include <qpixmap.h>
#include <qpainter.h>
-class OWait;
+namespace Opie {namespace Ui {class OWait;}}
class Wait : public QWidget
{
public:
Wait( QWidget *parent );
void setWaiting( bool w );
void paintEvent( QPaintEvent * );
static Wait *getWaitObject();
private:
QPixmap pm;
bool waiting;
- OWait* m_centralWait;
+ Opie::Ui::OWait* m_centralWait;
};
#endif // __WAIT_H__