summaryrefslogtreecommitdiff
path: root/x11/libqpe-x11
authorzecke <zecke>2002-10-16 13:04:20 (UTC)
committer zecke <zecke>2002-10-16 13:04:20 (UTC)
commitee8da0d0b70318c24ee2417bbccd9b7cd6e1404e (patch) (unidiff)
tree7d566843eb9fe423fbc8a8734abaa0ebcb127d16 /x11/libqpe-x11
parentfdc4abb0d38e6d5dce98961e47b552ff56c89976 (diff)
downloadopie-ee8da0d0b70318c24ee2417bbccd9b7cd6e1404e.zip
opie-ee8da0d0b70318c24ee2417bbccd9b7cd6e1404e.tar.gz
opie-ee8da0d0b70318c24ee2417bbccd9b7cd6e1404e.tar.bz2
More implementation for X11
Hey this QPEApplication looks much better.... There still needs to be some stuff to be implemented InputMethods, eventFilter, hideOrQuit, Styles but they should be copy and paste I'll implement these and then take care of IPC...
Diffstat (limited to 'x11/libqpe-x11') (more/less context) (ignore whitespace changes)
-rw-r--r--x11/libqpe-x11/qpe/qpeapplication.cpp491
-rw-r--r--x11/libqpe-x11/qpe/qpeapplication.h12
2 files changed, 502 insertions, 1 deletions
diff --git a/x11/libqpe-x11/qpe/qpeapplication.cpp b/x11/libqpe-x11/qpe/qpeapplication.cpp
new file mode 100644
index 0000000..891e132
--- a/dev/null
+++ b/x11/libqpe-x11/qpe/qpeapplication.cpp
@@ -0,0 +1,491 @@
1#define QTOPIA_INTERNAL_LANGLIST
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <unistd.h>
6#include <sys/file.h>
7
8#include <qdir.h>
9#include <qdialog.h>
10#include <qdragobject.h>
11#include <qevent.h>
12#include <qlabel.h>
13#include <qlist.h>
14#include <qtextstream.h>
15#include <qtextcodec.h>
16#include <qpalette.h>
17#include <qptrdict.h>
18#include <qregexp.h>
19
20#include <qpe/alarmserver.h>
21#include <qpe/applnk.h>
22#include <qpe/qpemenubar.h>
23#include <qpe/textcodecinterface.h>
24#include <qpe/imagecodecinterface.h>
25#include <qpe/qlibrary.h>
26#include <qpe/qpestyle.h>
27#include <qpe/styleinterface.h>
28#include <qpe/global.h>
29#include <qpe/resource.h>
30#include <qpe/config.h>
31#include <qpe/network.h>
32
33#include <qpe/qpeapplication.h>
34#include <qpe/timestring.h>
35#include <qpe/qcopenvelope_qws.h>
36
37namespace {
38 struct QCopRec{
39 QCopRec( const QCString& ch, const QCString& msg, const QByteArray& ar )
40 : channel(ch), message(msg), data(ar) {
41
42 }
43 QCString channel;
44 QCString message;
45 QByteArray data;
46 };
47};
48
49
50class QPEApplication::Private {
51public:
52 Private();
53 ~Private();
54 void enqueueQCop( const QCString& ch, const QCString& msg,
55 const QByteArray& );
56 void sendQCopQ();
57 static void show_mx(QWidget* mw, bool nomaximize );
58 void show( QWidget* mw, bool nomax );
59 void loadTextCodecs();
60 void loadImageCodecs();
61
62 int kbgrabber;
63 int presstimer;
64
65 bool rightpressed : 1;
66 bool kbregrab : 1;
67 bool notbusysent : 1;
68 bool preloaded : 1;
69 bool forceshow : 1;
70 bool nomaximize : 1;
71 bool keep_running : 1;
72
73 QWidget* presswidget;
74 QPoint presspos;
75 QWidget* qpe_main_widget;
76 QString appName;
77 QString styleName;
78 QString decorationName;
79
80private:
81 QList<QCopRec> qcopq;
82};
83QPEApplication::Private::~Private() {
84}
85QPEApplication::Private::Private()
86 : kbgrabber(0 ), presstimer(0 ), rightpressed( FALSE ), kbregrab( FALSE ), notbusysent( FALSE ),
87 preloaded( FALSE ), forceshow( FALSE ), nomaximize( FALSE ), keep_running( TRUE ),
88 presswidget( 0 ), qpe_main_widget(0 ) {
89
90 qcopq.setAutoDelete( TRUE );
91}
92void QPEApplication::Private::enqueueQCop( const QCString& chan, const QCString& msg,
93 const QByteArray& ar ) {
94 qcopq.append( new QCopRec(chan, msg, ar ) );
95}
96void QPEApplication::Private::sendQCopQ() {
97 QCopRec* r;
98 for ( r = qcopq.first(); r; r = qcopq.next() ) {
99 QCopChannel::sendLocally( r->channel, r->message, r->data );
100 }
101 qcopq.clear();
102}
103void QPEApplication::Private::show_mx(QWidget* mw, bool nomaximize ) {
104 if (mw->layout() && mw->inherits("QDialog") ) {
105 QPEApplication::showDialog( (QDialog*)mw, nomaximize );
106 }else {
107 if (!nomaximize )
108 mw->showMaximized();
109 else
110 mw->show();
111 }
112}
113void QPEApplication::Private::show( QWidget* mw, bool nomax ) {
114 nomaximize = nomax;
115 qpe_main_widget = mw;
116
117 sendQCopQ();
118
119 if ( preloaded ) {
120 if (forceshow )
121 show_mx(mw, nomax );
122 }else if ( keep_running )
123 show_mx( mw, nomax );
124}
125void QPEApplication::Private::loadTextCodecs() {
126 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
127 QDir dir( path, "lib*.so" );
128 QStringList list = dir.entryList();
129 QStringList::Iterator it;
130 for ( it = list.begin(); it != list.end(); ++it ) {
131 TextCodecInterface *iface = 0;
132 QLibrary *lib = new QLibrary( path + "/" + *it );
133 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
134 QValueList<int> mibs = iface->mibEnums();
135 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
136 (void)iface->createForMib(*i);
137 // ### it exists now; need to remember if we can delete it
138 }
139 }
140 else {
141 lib->unload();
142 delete lib;
143 }
144 }
145}
146void QPEApplication::Private::loadImageCodecs() {
147 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
148 QDir dir( path, "lib*.so" );
149 QStringList list = dir.entryList();
150 QStringList::Iterator it;
151 for ( it = list.begin(); it != list.end(); ++it ) {
152 ImageCodecInterface *iface = 0;
153 QLibrary *lib = new QLibrary( path + "/" + *it );
154 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
155 QStringList formats = iface->keys();
156 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
157 (void)iface->installIOHandler(*i);
158 // ### it exists now; need to remember if we can delete it
159 }
160 }
161 else {
162 lib->unload();
163 delete lib;
164 }
165 }
166}
167
168// The Help System hook
169namespace {
170 class ResourceMimeFactory : public QMimeSourceFactory
171 {
172 public:
173 ResourceMimeFactory();
174 ~ResourceMimeFactory();
175 const QMimeSource* data( const QString& abs_name )const;
176 };
177 ResourceMimeFactory::ResourceMimeFactory()
178 {
179 setFilePath( Global::helpPath() );
180 setExtensionType( "html", "text/html;charset=UTF-8" );
181 }
182 ResourceMimeFactory::~ResourceMimeFactory() {
183 }
184
185 const QMimeSource* ResourceMimeFactory::data( const QString& abs_name ) const
186 {
187 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
188 if ( !r ) {
189 int sl = abs_name.length();
190 do {
191 sl = abs_name.findRev( '/', sl - 1 );
192 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
193 int dot = name.findRev( '.' );
194 if ( dot >= 0 )
195 name = name.left( dot );
196 QImage img = Resource::loadImage( name );
197 if ( !img.isNull() )
198 r = new QImageDrag( img );
199 }
200 while ( !r && sl > 0 );
201 }
202 return r;
203 };
204};
205// QPEApplication
206QPEApplication::QPEApplication(int &arg, char** argv, Type t)
207 : QApplication( arg, argv, t ) {
208 d = new Private;
209 d->loadTextCodecs();
210 d->loadImageCodecs();
211
212 int dw = desktop()->width();
213 if ( dw < 200 ) {
214 setFont( QFont( "helvetica", 8 ) );
215 AppLnk::setSmallIconSize( 10 );
216 AppLnk::setBigIconSize( 28 );
217 }else if ( dw > 600 ) {
218 setFont( QFont( "helvetica", 12 ) );
219 AppLnk::setSmallIconSize( 24 );
220 AppLnk::setBigIconSize( 48 );
221 }else if ( dw > 200 ) {
222 setFont( QFont( "helvetica", 10 ) );
223 AppLnk::setSmallIconSize( 16 );
224 AppLnk::setBigIconSize( 32 );
225 }
226 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
227
228 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT(hideOrQuit() ) );
229
230 QString qcopfn( "/tmp/qcop-msg-" );
231 qcopfn += QString( argv[0] ); // append command name to the QCOP name
232 QFile file( qcopfn );
233 if (file.open(IO_ReadOnly ) ) {
234 flock( file.handle(), LOCK_EX );
235 }
236
237 m_sys = new QCopChannel( "QPE/System", this );
238 connect(m_sys, SIGNAL( received( const QCString&, const QByteArray& ) ),
239 this, SLOT(systemMessage( const QCString&, const QByteArray& ) ) );
240
241 // private channel QPE/Application/appname
242 QCString channel = QCString( argv[0] );
243 channel.replace( QRegExp( ".*/"), "" );
244 d->appName = channel;
245 channel = "QPE/Application/"+ channel;
246 m_pid = new QCopChannel( channel, this );
247 connect(m_pid, SIGNAL( received( const QCString&, const QByteArray& ) ),
248 this, SLOT( pidMessage( const QCString&, const QByteArray& ) ) );
249
250 // read the Pre QCOP Stuff from the file
251 if ( file.isOpen() ) {
252 d->keep_running = FALSE;
253 QDataStream ds( &file );
254 QCString chanel, message;
255 QByteArray data;
256 while (!ds.atEnd() ) {
257 ds >> chanel >> message >> data;
258 d->enqueueQCop( chanel, message, data );
259 }
260 flock( file.handle(), LOCK_UN );
261 file.close();
262 file.remove();
263 }
264
265 // read in some stuff from the command line
266 // we do not have setArgs so we need to take
267 // care of that
268 for ( int a = 0; a < arg; a++ ) {
269 if ( qstrcmp( argv[a], "-preload" ) == 0 ) {
270 d->preloaded = TRUE;
271 }else if ( qstrcmp( argv[a ] , "-preload-show" ) == 0 ) {
272 d->preloaded = TRUE;
273 d->forceshow = TRUE;
274 }
275 }
276 initTranslations();
277 applyStyle();
278
279 if ( type() == GuiServer )
280 ;
281
282 installEventFilter( this );
283 QPEMenuToolFocusManager::initialize();
284}
285void QPEApplication::initTranslations() {
286 // Translations add it
287 QStringList langs = Global::languageList();
288 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) {
289 QString lang = *it;
290
291 QTranslator * trans;
292 QString tfn;
293
294 trans = new QTranslator( this );
295 tfn = qpeDir() + "/i18n/" + lang + "/libqpe.qm";
296 if ( trans->load( tfn ) )
297 installTranslator( trans );
298 else
299 delete trans;
300
301 trans = new QTranslator( this );
302 tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm";
303 if ( trans->load( tfn ) )
304 installTranslator( trans );
305 else
306 delete trans;
307 }
308}
309QPEApplication::~QPEApplication() {
310 delete d;
311}
312QString QPEApplication::qpeDir() {
313 const char * base = getenv( "OPIEDIR" );
314 if ( base )
315 return QString( base ) + "/";
316
317 return QString( "../" );
318}
319QString QPEApplication::documentDir() {
320 const char* base = getenv( "HOME");
321 if ( base )
322 return QString( base ) + "/Documents";
323
324 return QString( "../Documents" );
325}
326void QPEApplication::applyStyle() {
327 Config config( "qpe" );
328
329 config.setGroup( "Appearance" );
330
331 // Widget style
332 QString style = config.readEntry( "Style", "Light" );
333 internalSetStyle( style );
334
335 // Colors
336 QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) );
337 QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) );
338 QPalette pal( btncolor, bgcolor );
339 QString color = config.readEntry( "Highlight", "#800000" );
340 pal.setColor( QColorGroup::Highlight, QColor( color ) );
341 color = config.readEntry( "HighlightedText", "#FFFFFF" );
342 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
343 color = config.readEntry( "Text", "#000000" );
344 pal.setColor( QColorGroup::Text, QColor( color ) );
345 color = config.readEntry( "ButtonText", "#000000" );
346 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
347 color = config.readEntry( "Base", "#FFFFFF" );
348 pal.setColor( QColorGroup::Base, QColor( color ) );
349
350 pal.setColor( QPalette::Disabled, QColorGroup::Text,
351 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
352
353 setPalette( pal, TRUE );
354
355
356
357 // Font
358 QString ff = config.readEntry( "FontFamily", font().family() );
359 int fs = config.readNumEntry( "FontSize", font().pointSize() );
360 setFont( QFont(ff, fs) );
361}
362int QPEApplication::defaultRotation() {
363 return 0;
364}
365void QPEApplication::setDefaultRotation(int r ) {
366
367}
368void QPEApplication::grabKeyboard() {
369 QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d;
370 if ( qApp->type() == QApplication::GuiServer )
371 d->kbgrabber = 0;
372 else {
373 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
374 e << d->appName;
375
376 d->kbgrabber = 2; // me
377 }
378}
379void QPEApplication::ungrabKeyboard() {
380 QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d;
381 if ( d->kbgrabber == 2 ) {
382 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
383 e << QString::null;
384
385 d->kbregrab = FALSE;
386 d->kbgrabber = 0;
387 }
388}
389void QPEApplication::setStylusOperation( QWidget*, StylusMode ) {
390
391}
392QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* ) {
393
394}
395void QPEApplication::showMainWidget( QWidget* wid, bool b) {
396 d->show(wid, b );
397}
398void QPEApplication::showMainDocumentWidget( QWidget* mw, bool m) {
399 if ( mw && argc() == 2 )
400 Global::setDocument( mw, QString::fromUtf8(argv()[1] ) );
401
402 d->show(mw, m );
403}
404void QPEApplication::showDialog( QDialog* d, bool nomax ) {
405 QSize sh = d->sizeHint();
406 int w = QMAX(sh.width(),d->width());
407 int h = QMAX(sh.height(),d->height());
408 if ( !nomax
409 && ( w > qApp->desktop()->width()*3/4
410 || h > qApp->desktop()->height()*3/4 ) )
411 {
412 d->showMaximized();
413 } else {
414 d->resize(w,h);
415 d->show();
416 }
417}
418int QPEApplication::execDialog( QDialog* d, bool nomax) {
419 showDialog(d,nomax);
420 return d->exec();
421}
422void QPEApplication::setKeepRunning() {
423 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
424 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
425 qpeApp->d->keep_running = TRUE;
426 }
427}
428bool QPEApplication::keepRunning()const {
429 return d->keep_running;
430}
431bool QPEApplication::keyboardGrabbed()const {
432 return d->kbgrabber;
433}
434int QPEApplication::exec() {
435 /* now send the QCOP stuff gotten from the file */
436 d->sendQCopQ();
437
438 if ( d->keep_running )
439 return QApplication::exec();
440
441 {
442 QCopEnvelope e( "QPE/System", "closing(QString)" );
443 e << d->appName;
444 }
445 processEvents();
446 return 0;
447}
448void QPEApplication::internalSetStyle( const QString& ) {
449
450}
451
452
453
454#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
455
456// The libraries with the skiff package (and possibly others) have
457// completely useless implementations of builtin new and delete that
458// use about 50% of your CPU. Here we revert to the simple libc
459// functions.
460
461void* operator new[]( size_t size )
462{
463 return malloc( size );
464}
465
466void* operator new( size_t size )
467{
468 return malloc( size );
469}
470
471void operator delete[]( void* p )
472{
473 free( p );
474}
475
476void operator delete[]( void* p, size_t /*size*/ )
477{
478 free( p );
479}
480
481void operator delete( void* p )
482{
483 free( p );
484}
485
486void operator delete( void* p, size_t /*size*/ )
487{
488 free( p );
489}
490
491#endif
diff --git a/x11/libqpe-x11/qpe/qpeapplication.h b/x11/libqpe-x11/qpe/qpeapplication.h
index 3713251..cd385db 100644
--- a/x11/libqpe-x11/qpe/qpeapplication.h
+++ b/x11/libqpe-x11/qpe/qpeapplication.h
@@ -9,6 +9,7 @@
9 9
10#include <qpe/timestring.h> 10#include <qpe/timestring.h>
11 11
12class QCopChannel;
12class QPEApplication : public QApplication { 13class QPEApplication : public QApplication {
13 Q_OBJECT 14 Q_OBJECT
14public: 15public:
@@ -35,7 +36,7 @@ public:
35 void showMainDocumentWidget( QWidget*, bool nomax = FALSE ); 36 void showMainDocumentWidget( QWidget*, bool nomax = FALSE );
36 37
37 static void showDialog( QDialog*, bool nomax = FALSE ); 38 static void showDialog( QDialog*, bool nomax = FALSE );
38 static void execDialog( QDialog*, bool nomax = FALSE ); 39 static int execDialog( QDialog*, bool nomax = FALSE );
39 40
40 static void setKeepRunning(); 41 static void setKeepRunning();
41 bool keepRunning()const; 42 bool keepRunning()const;
@@ -55,6 +56,15 @@ signals:
55 void flush(); 56 void flush();
56 void reload(); 57 void reload();
57 58
59private:
60 void initTranslations();
61 void internalSetStyle(const QString&);
62
63private:
64 class Private;
65 Private* d;
66 QCopChannel *m_sys;
67 QCopChannel *m_pid;
58}; 68};
59 69
60#endif 70#endif