summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
Side-by-side diff
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp152
1 files changed, 125 insertions, 27 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index d1a7cd2..b1b7ed4 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -30,48 +30,51 @@
#define private public
#define sendLocally processEvent
#include "qcopenvelope_qws.h"
#undef private
#else
#include "qcopenvelope_qws.h"
#endif
#endif
#include <qwindowsystem_qws.h>
#endif
#include <qtextstream.h>
#include <qpalette.h>
#include <qbuffer.h>
#include <qptrdict.h>
#include <qregexp.h>
#include <qdir.h>
#include <qlabel.h>
#include <qdialog.h>
#include <qdragobject.h>
#include <qtextcodec.h>
#include <qevent.h>
#include <qtooltip.h>
#include <qsignal.h>
#include <qmainwindow.h>
+
+#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
+#define QTOPIA_INTERNAL_INITAPP
#include "qpeapplication.h"
#include "qpestyle.h"
#include "styleinterface.h"
#if QT_VERSION >= 300
#include <qstylefactory.h>
#else
#include <qplatinumstyle.h>
#include <qwindowsstyle.h>
#include <qmotifstyle.h>
#include <qmotifplusstyle.h>
#include "lightstyle.h"
#include <qpe/qlibrary.h>
#endif
#include "global.h"
#include "resource.h"
#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
#include "qutfcodec.h"
#endif
#include "config.h"
#include "network.h"
#ifdef QWS
#include "fontmanager.h"
#endif
@@ -284,48 +287,58 @@ public:
const QMimeSource * r = QMimeSourceFactory::data( abs_name );
if ( !r ) {
int sl = abs_name.length();
do {
sl = abs_name.findRev( '/', sl - 1 );
QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
int dot = name.findRev( '.' );
if ( dot >= 0 )
name = name.left( dot );
QImage img = Resource::loadImage( name );
if ( !img.isNull() ) {
delete resImage;
resImage = new QImageDrag( img );
r = resImage;
}
}
while ( !r && sl > 0 );
}
return r;
}
private:
mutable QImageDrag *resImage;
};
+static int& hack(int& i)
+{
+#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
+ // These should be created, but aren't in Qt 2.3.0
+ (void)new QUtf8Codec;
+ (void)new QUtf16Codec;
+#endif
+ return i;
+}
+
static int muted = 0;
static int micMuted = 0;
static void setVolume( int t = 0, int percent = -1 )
{
switch ( t ) {
case 0: {
Config cfg( "qpe" );
cfg.setGroup( "Volume" );
if ( percent < 0 )
percent = cfg.readNumEntry( "VolumePercent", 50 );
int fd = 0;
if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
int vol = muted ? 0 : percent;
// set both channels to same volume
vol |= vol << 8;
ioctl( fd, MIXER_WRITE( 0 ), &vol );
::close( fd );
}
}
break;
}
}
@@ -465,212 +478,293 @@ static void setTreble( int t = 0, int percent = -1 )
This signal is emitted if the week start day is changed. If \a
startOnMonday is TRUE then the first day of the week is Monday; if
\a startOnMonday is FALSE then the first day of the week is
Sunday.
*/
/*!
\fn void QPEApplication::dateFormatChanged(DateFormat)
This signal is emitted whenever the date format is changed.
*/
/*!
\fn void QPEApplication::flush()
###
*/
/*!
\fn void QPEApplication::reload()
*/
+
+
+void QPEApplication::processQCopFile()
+{
+ QString qcopfn("/tmp/qcop-msg-");
+ qcopfn += d->appName; // append command name
+
+ QFile f(qcopfn);
+ if ( f.open(IO_ReadWrite) ) {
+#ifndef Q_OS_WIN32
+ flock(f.handle(), LOCK_EX);
+#endif
+ QDataStream ds(&f);
+ QCString channel, message;
+ QByteArray data;
+ while(!ds.atEnd()) {
+ ds >> channel >> message >> data;
+ d->enqueueQCop(channel,message,data);
+ }
+ ::ftruncate(f.handle(), 0);
+#ifndef Q_OS_WIN32
+ f.flush();
+ flock(f.handle(), LOCK_UN);
+#endif
+ }
+#endif
+}
+
+
/*!
\fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
This signal is emitted when a message is received on this
application's QPE/Application/<i>appname</i> \link qcop.html
QCop\endlink channel.
The slot to which you connect this signal uses \a msg and \a data
in the following way:
\code
void MyWidget::receive( const QCString& msg, const QByteArray& data )
{
QDataStream stream( data, IO_ReadOnly );
if ( msg == "someMessage(int,int,int)" ) {
int a,b,c;
stream >> a >> b >> c;
...
} else if ( msg == "otherMessage(QString)" ) {
...
}
}
\endcode
\sa qcop.html
Note that messages received here may be processed by qpe application
and emitted as signals, such as flush() and reload().
*/
/*!
Constructs a QPEApplication just as you would construct
a QApplication, passing \a argc, \a argv, and \a t.
For applications, \a t should be the default, GuiClient. Only
the Qtopia server passes GuiServer.
*/
QPEApplication::QPEApplication( int & argc, char **argv, Type t )
- : QApplication( argc, argv, t )
+ : QApplication( hack(argc), argv, t ), pidChannel( 0 )
{
d = new QPEApplicationData;
d->loadTextCodecs();
d->loadImageCodecs();
int dw = desktop() ->width();
if ( dw < 200 ) {
setFont( QFont( "vera", 8 ) );
AppLnk::setSmallIconSize( 10 );
AppLnk::setBigIconSize( 28 );
}
#ifndef QT_QWS_SIMPAD
else if ( dw > 600 ) {
setFont( QFont( "vera", 16 ) );
AppLnk::setSmallIconSize( 24 );
AppLnk::setBigIconSize( 48 );
}
#endif
else if ( dw > 200 ) {
setFont( QFont( "vera", 10 ) );
AppLnk::setSmallIconSize( 14 );
AppLnk::setBigIconSize( 32 );
}
QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
+
+
+ sysChannel = new QCopChannel( "QPE/System", this );
+ connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
+ this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
+
+/* COde now in initapp */
+#if 0
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
QString qcopfn( "/tmp/qcop-msg-" );
qcopfn += QString( argv[ 0 ] ); // append command name
QFile f( qcopfn );
if ( f.open( IO_ReadOnly ) ) {
flock( f.handle(), LOCK_EX );
}
- sysChannel = new QCopChannel( "QPE/System", this );
- connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
- this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
+
QCString channel = QCString( argv[ 0 ] );
channel.replace( QRegExp( ".*/" ), "" );
d->appName = channel;
channel = "QPE/Application/" + channel;
pidChannel = new QCopChannel( channel, this );
connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) );
if ( f.isOpen() ) {
d->keep_running = FALSE;
QDataStream ds( &f );
QCString channel, message;
QByteArray data;
while ( !ds.atEnd() ) {
ds >> channel >> message >> data;
d->enqueueQCop( channel, message, data );
}
flock( f.handle(), LOCK_UN );
f.close();
f.remove();
}
for ( int a = 0; a < argc; a++ ) {
if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
argv[ a ] = argv[ a + 1 ];
a++;
d->preloaded = TRUE;
argc -= 1;
}
else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
argv[ a ] = argv[ a + 1 ];
a++;
d->preloaded = TRUE;
d->forceshow = TRUE;
argc -= 1;
}
}
/* overide stored arguments */
setArgs( argc, argv );
#endif
-
+#else
+ initApp( argc, argv );
+#endif
// qwsSetDecoration( new QPEDecoration() );
#ifndef QT_NO_TRANSLATION
QStringList langs = Global::languageList();
for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) {
QString lang = *it;
installTranslation( lang + "/libopie.qm");
installTranslation( lang + "/libqpe.qm" );
installTranslation( lang + "/" + d->appName + ".qm" );
//###language/font hack; should look it up somewhere
#ifdef QWS
- if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
- QFont fn = FontManager::unicodeFont( FontManager::Proportional );
- setFont( fn );
- }
+ if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
+ QFont fn = FontManager::unicodeFont( FontManager::Proportional );
+ setFont( fn );
+ }
#endif
-
- }
+ }
#endif
applyStyle();
if ( type() == GuiServer ) {
setVolume();
}
installEventFilter( this );
QPEMenuToolFocusManager::initialize();
#ifdef QT_NO_QWS_CURSOR
// if we have no cursor, probably don't want tooltips
QToolTip::setEnabled( FALSE );
#endif
}
+
+#ifdef QTOPIA_INTERNAL_INITAPP
+void QPEApplication::initApp( int argc, char **argv )
+{
+ delete pidChannel;
+ d->keep_running = TRUE;
+ d->preloaded = FALSE;
+ d->forceshow = FALSE;
+
+ QCString channel = QCString(argv[0]);
+
+ channel.replace(QRegExp(".*/"),"");
+ d->appName = channel;
+
+ qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
+
+ channel = "QPE/Application/" + channel;
+ pidChannel = new QCopChannel( channel, this);
+ connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)),
+ this, SLOT(pidMessage(const QCString &, const QByteArray &)));
+
+ processQCopFile();
+ d->keep_running = d->qcopq.isEmpty();
+
+ for (int a=0; a<argc; a++) {
+ if ( qstrcmp(argv[a],"-preload")==0 ) {
+ argv[a] = argv[a+1];
+ a++;
+ d->preloaded = TRUE;
+ argc-=1;
+ } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
+ argv[a] = argv[a+1];
+ a++;
+ d->preloaded = TRUE;
+ d->forceshow = TRUE;
+ argc-=1;
+ }
+ }
+
+ /* overide stored arguments */
+ setArgs(argc, argv);
+}
+#endif
+
+
static QPtrDict<void>* inputMethodDict = 0;
static void createInputMethodDict()
{
if ( !inputMethodDict )
inputMethodDict = new QPtrDict<void>;
}
/*!
Returns the currently set hint to the system as to whether
widget \a w has any use for text input methods.
\sa setInputMethodHint() InputMethodHint
*/
QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
{
if ( inputMethodDict && w )
return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
return Normal;
}
/*!
\enum QPEApplication::InputMethodHint
@@ -1103,62 +1197,48 @@ void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data
else if ( msg == "language(QString)" ) {
if ( type() == GuiServer ) {
QString l;
stream >> l;
QString cl = getenv( "LANG" );
if ( cl != l ) {
if ( l.isNull() )
unsetenv( "LANG" );
else
setenv( "LANG", l.latin1(), 1 );
restart();
}
}
}
else if ( msg == "timeChange(QString)" ) {
QString t;
stream >> t;
if ( t.isNull() )
unsetenv( "TZ" );
else
setenv( "TZ", t.latin1(), 1 );
// emit the signal so everyone else knows...
emit timeChanged();
}
- else if ( msg == "execute(QString)" ) {
- if ( type() == GuiServer ) {
- QString t;
- stream >> t;
- Global::execute( t );
- }
- }
- else if ( msg == "execute(QString,QString)" ) {
- if ( type() == GuiServer ) {
- QString t, d;
- stream >> t >> d;
- Global::execute( t, d );
- }
- }
else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
if ( type() == GuiServer ) {
QDateTime when;
QCString channel, message;
int data;
stream >> when >> channel >> message >> data;
AlarmServer::addAlarm( when, channel, message, data );
}
}
else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
if ( type() == GuiServer ) {
QDateTime when;
QCString channel, message;
int data;
stream >> when >> channel >> message >> data;
AlarmServer::deleteAlarm( when, channel, message, data );
}
}
else if ( msg == "clockChange(bool)" ) {
int tmp;
stream >> tmp;
emit clockChanged( tmp );
}
else if ( msg == "weekChange(bool)" ) {
@@ -1187,50 +1267,64 @@ void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data
stream >> t >> v;
setMic( t, v );
emit micChanged( micMuted );
}
else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
stream >> micMuted;
setMic();
emit micChanged( micMuted );
}
else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
int t, v;
stream >> t >> v;
setBass( t, v );
}
else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
setBass();
}
else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
int t, v;
stream >> t >> v;
setTreble( t, v );
}
else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
setTreble();
+ } else if ( msg == "getMarkedText()" ) {
+ if ( type() == GuiServer ) {
+ const ushort unicode = 'C'-'@';
+ const int scan = Key_C;
+ qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
+ qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
+ }
+ } else if ( msg == "newChannel(QString)") {
+ QString myChannel = "QPE/Application/" + d->appName;
+ QString channel;
+ stream >> channel;
+ if (channel == myChannel) {
+ processQCopFile();
+ d->sendQCopQ();
}
-
+ }
#endif
}
/*!
\internal
*/
bool QPEApplication::raiseAppropriateWindow()
{
bool r = FALSE;
// ########## raise()ing main window should raise and set active
// ########## it and then all childen. This belongs in Qt/Embedded
QWidget *top = d->qpe_main_widget;
if ( !top )
top = mainWidget();
if ( top && d->keep_running ) {
if ( top->isVisible() )
r = TRUE;
else if (d->preloaded) {
// We are preloaded and not visible.. pretend we just started..
QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
e << d->appName;
}
@@ -1285,49 +1379,53 @@ void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
raiseAppropriateWindow();
// Tell the system we're still chugging along...
QCopEnvelope e("QPE/System", "appRaised(QString)");
e << d->appName;
}
else if ( msg == "flush()" ) {
emit flush();
// we need to tell the desktop
QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
e << d->appName;
}
else if ( msg == "reload()" ) {
emit reload();
}
else if ( msg == "setDocument(QString)" ) {
d->keep_running = TRUE;
QDataStream stream( data, IO_ReadOnly );
QString doc;
stream >> doc;
QWidget *mw = mainWidget();
if ( !mw )
mw = d->qpe_main_widget;
if ( mw )
Global::setDocument( mw, doc );
- } else {
+ } else if ( msg == "QPEProcessQCop()" ) {
+ processQCopFile();
+ d->sendQCopQ();
+ }
+ {
bool p = d->keep_running;
d->keep_running = FALSE;
emit appMessage( msg, data);
if ( d->keep_running ) {
d->notbusysent = FALSE;
raiseAppropriateWindow();
if ( !p ) {
// Tell the system we're still chugging along...
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "appRaised(QString)");
e << d->appName;
#endif
}
}
if ( p )
d->keep_running = p;
}
#endif
}
/*!
Sets widget \a mw as the mainWidget() and shows it. For small windows,
consider passing TRUE for \a nomaximize rather than the default FALSE.