summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-16 15:34:05 (UTC)
committer zecke <zecke>2002-10-16 15:34:05 (UTC)
commit321cea04e34658fde3de47c104682b5cefce6eeb (patch) (unidiff)
treeabdf45ae54d24dedfd20e4e40371df5f39687139
parent61f2f6ef32685002710f197dc8990fd9e99d83a5 (diff)
downloadopie-321cea04e34658fde3de47c104682b5cefce6eeb.zip
opie-321cea04e34658fde3de47c104682b5cefce6eeb.tar.gz
opie-321cea04e34658fde3de47c104682b5cefce6eeb.tar.bz2
more implementation!!
OCOPClient now tries to start the server
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--x11/ipc/client/ocopclient.cpp25
-rw-r--r--x11/ipc/client/ocopclient.h4
-rw-r--r--x11/libqpe-x11/qpe/qpeapplication.cpp207
-rw-r--r--x11/libqpe-x11/qpe/qpeapplication.h23
4 files changed, 243 insertions, 16 deletions
diff --git a/x11/ipc/client/ocopclient.cpp b/x11/ipc/client/ocopclient.cpp
index 43e426c..ac6e4a3 100644
--- a/x11/ipc/client/ocopclient.cpp
+++ b/x11/ipc/client/ocopclient.cpp
@@ -3,6 +3,7 @@
3#include <stdio.h> 3#include <stdio.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <sys/socket.h> 5#include <sys/socket.h>
6#include <sys/types.h>
6#include <sys/un.h> 7#include <sys/un.h>
7 8
8 9
@@ -16,16 +17,26 @@
16OCOPClient::OCOPClient( const QString& path, QObject* obj ) 17OCOPClient::OCOPClient( const QString& path, QObject* obj )
17 : QObject( obj ) 18 : QObject( obj )
18{ 19{
20 m_tries = 0;
19 init(QFile::encodeName(path) ); 21 init(QFile::encodeName(path) );
20} 22}
21OCOPClient::~OCOPClient() { 23OCOPClient::~OCOPClient() {
24 delete m_notify;
22 close( m_socket ); 25 close( m_socket );
23} 26}
27void OCOPClient::init() {
28 // failed start ther server NOW!!!
29 startUP();
30 QCString str;
31 init(str );
32}
24void OCOPClient::init( const QCString& ) { 33void OCOPClient::init( const QCString& ) {
34 m_tries++;
25 struct sockaddr_un unix_adr; 35 struct sockaddr_un unix_adr;
26 if ( (m_socket = socket(PF_UNIX, SOCK_STREAM, 0) ) < 0 ) { 36 if ( (m_socket = socket(PF_UNIX, SOCK_STREAM, 0) ) < 0 ) {
27 qWarning("could not socket"); 37 qWarning("could not socket");
28 QTimer::singleShot(400, this,SLOT(init() ) ); 38 if ( m_tries < 8 )
39 QTimer::singleShot(400, this,SLOT(init() ) );
29 return; 40 return;
30 } 41 }
31 memset(&unix_adr, 0, sizeof(unix_adr ) ); 42 memset(&unix_adr, 0, sizeof(unix_adr ) );
@@ -36,7 +47,8 @@ void OCOPClient::init( const QCString& ) {
36 if ( ::connect(m_socket, (struct sockaddr*)&unix_adr, length ) < 0 ) { 47 if ( ::connect(m_socket, (struct sockaddr*)&unix_adr, length ) < 0 ) {
37 qWarning("could not connect %d", errno ); 48 qWarning("could not connect %d", errno );
38 close( m_socket ); 49 close( m_socket );
39 QTimer::singleShot(400, this, SLOT(init() ) ); 50 if ( m_tries < 8 )
51 QTimer::singleShot(400, this, SLOT(init() ) );
40 return; 52 return;
41 } 53 }
42 m_notify = new QSocketNotifier(m_socket, QSocketNotifier::Read, this ); 54 m_notify = new QSocketNotifier(m_socket, QSocketNotifier::Read, this );
@@ -127,3 +139,12 @@ void OCOPClient::call( const OCOPPacket& pack ) {
127 write(m_socket, pack.header().data(), pack.header().size() ); 139 write(m_socket, pack.header().data(), pack.header().size() );
128 write(m_socket, pack.content().data(), pack.content().size() ); 140 write(m_socket, pack.content().data(), pack.content().size() );
129} 141}
142void OCOPClient::startUP() {
143 qWarning("Start me up");
144 pid_t pi = fork();
145 if ( pi == 0 ) {
146 setsid();
147 execlp("opie-ipc", "opie-ipc", NULL );
148 _exit(1);
149 }
150}
diff --git a/x11/ipc/client/ocopclient.h b/x11/ipc/client/ocopclient.h
index e9544b9..53018a5 100644
--- a/x11/ipc/client/ocopclient.h
+++ b/x11/ipc/client/ocopclient.h
@@ -44,15 +44,17 @@ public:
44signals: 44signals:
45 void called(const QCString&, const QCString&, const QByteArray& ); 45 void called(const QCString&, const QCString&, const QByteArray& );
46private slots: 46private slots:
47 void init();
47 void init(const QCString& pa); 48 void init(const QCString& pa);
48 void newData(); 49 void newData();
49private: 50private:
51 void startUP();
50 OCOPPacket packet()const; 52 OCOPPacket packet()const;
51 void call( const OCOPPacket& ); 53 void call( const OCOPPacket& );
52 54
53 QSocketNotifier* m_notify; 55 QSocketNotifier* m_notify;
54 int m_socket; 56 int m_socket;
55private slots: 57 int m_tries;
56 58
57}; 59};
58 60
diff --git a/x11/libqpe-x11/qpe/qpeapplication.cpp b/x11/libqpe-x11/qpe/qpeapplication.cpp
index 891e132..6e4a96c 100644
--- a/x11/libqpe-x11/qpe/qpeapplication.cpp
+++ b/x11/libqpe-x11/qpe/qpeapplication.cpp
@@ -203,6 +203,16 @@ namespace {
203 }; 203 };
204}; 204};
205// QPEApplication 205// QPEApplication
206QPEApplication::~QPEApplication() {
207 qWarning("~QPEApplication");
208 ungrabKeyboard();
209 qWarning("UngrabKeyboard");
210
211// delete m_sys;
212// delete m_pid;
213
214 delete d;
215}
206QPEApplication::QPEApplication(int &arg, char** argv, Type t) 216QPEApplication::QPEApplication(int &arg, char** argv, Type t)
207 : QApplication( arg, argv, t ) { 217 : QApplication( arg, argv, t ) {
208 d = new Private; 218 d = new Private;
@@ -234,7 +244,10 @@ QPEApplication::QPEApplication(int &arg, char** argv, Type t)
234 flock( file.handle(), LOCK_EX ); 244 flock( file.handle(), LOCK_EX );
235 } 245 }
236 246
237 m_sys = new QCopChannel( "QPE/System", this ); 247 /* Hmmm damn we need to make the parent 0l otherwise it get's deleted
248 * past the QApplication
249 */
250 m_sys = new QCopChannel( "QPE/System", 0l);
238 connect(m_sys, SIGNAL( received( const QCString&, const QByteArray& ) ), 251 connect(m_sys, SIGNAL( received( const QCString&, const QByteArray& ) ),
239 this, SLOT(systemMessage( const QCString&, const QByteArray& ) ) ); 252 this, SLOT(systemMessage( const QCString&, const QByteArray& ) ) );
240 253
@@ -243,7 +256,7 @@ QPEApplication::QPEApplication(int &arg, char** argv, Type t)
243 channel.replace( QRegExp( ".*/"), "" ); 256 channel.replace( QRegExp( ".*/"), "" );
244 d->appName = channel; 257 d->appName = channel;
245 channel = "QPE/Application/"+ channel; 258 channel = "QPE/Application/"+ channel;
246 m_pid = new QCopChannel( channel, this ); 259 m_pid = new QCopChannel( channel, 0l );
247 connect(m_pid, SIGNAL( received( const QCString&, const QByteArray& ) ), 260 connect(m_pid, SIGNAL( received( const QCString&, const QByteArray& ) ),
248 this, SLOT( pidMessage( const QCString&, const QByteArray& ) ) ); 261 this, SLOT( pidMessage( const QCString&, const QByteArray& ) ) );
249 262
@@ -306,9 +319,6 @@ void QPEApplication::initTranslations() {
306 delete trans; 319 delete trans;
307 } 320 }
308} 321}
309QPEApplication::~QPEApplication() {
310 delete d;
311}
312QString QPEApplication::qpeDir() { 322QString QPEApplication::qpeDir() {
313 const char * base = getenv( "OPIEDIR" ); 323 const char * base = getenv( "OPIEDIR" );
314 if ( base ) 324 if ( base )
@@ -386,12 +396,6 @@ void QPEApplication::ungrabKeyboard() {
386 d->kbgrabber = 0; 396 d->kbgrabber = 0;
387 } 397 }
388} 398}
389void QPEApplication::setStylusOperation( QWidget*, StylusMode ) {
390
391}
392QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* ) {
393
394}
395void QPEApplication::showMainWidget( QWidget* wid, bool b) { 399void QPEApplication::showMainWidget( QWidget* wid, bool b) {
396 d->show(wid, b ); 400 d->show(wid, b );
397} 401}
@@ -435,21 +439,198 @@ int QPEApplication::exec() {
435 /* now send the QCOP stuff gotten from the file */ 439 /* now send the QCOP stuff gotten from the file */
436 d->sendQCopQ(); 440 d->sendQCopQ();
437 441
438 if ( d->keep_running ) 442 if ( d->keep_running ) {
439 return QApplication::exec(); 443 qWarning("going to exec");
444 int a = QApplication::exec();
445 qWarning("left");
446 return a;
447 }
440 448
441 { 449 {
442 QCopEnvelope e( "QPE/System", "closing(QString)" ); 450 QCopEnvelope e( "QPE/System", "closing(QString)" );
443 e << d->appName; 451 e << d->appName;
444 } 452 }
453 qWarning("processing events!");
445 processEvents(); 454 processEvents();
446 return 0; 455 return 0;
447} 456}
448void QPEApplication::internalSetStyle( const QString& ) { 457void QPEApplication::internalSetStyle( const QString& ) {
449 458
450} 459}
460void QPEApplication::systemMessage( const QCString&, const QByteArray& ) {
461
462}
463void QPEApplication::pidMessage( const QCString&, const QByteArray& ) {
464
465}
466void QPEApplication::timerEvent( QTimerEvent* e ) {
467 if ( e->timerId() == d->presstimer && d->presswidget ) {
468 // Right pressed
469 postEvent( d->presswidget,
470 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
471 RightButton, LeftButton ) );
472 killTimer( d->presstimer );
473 d->presstimer = 0;
474 }
475}
476
477// InputMethods Hints
478namespace {
479 static QPtrDict<void>* inputMethodDict = 0;
480 static void createInputMethodDict(){
481 if ( !inputMethodDict )
482 inputMethodDict = new QPtrDict<void>;
483 }
484
485 static QPtrDict<void>* stylusDict = 0;
486 static void createDict() {
487 if ( !stylusDict )
488 stylusDict = new QPtrDict<void>;
489 }
490};
491
492void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode ) {
493 createInputMethodDict();
494 if ( mode == Normal ) {
495 inputMethodDict->remove
496 ( w );
497 }else {
498 inputMethodDict->insert( w, ( void* ) mode );
499 }
500}
501QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w) {
502 if ( inputMethodDict && w )
503 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
504 return Normal;
505}
506
507
508void QPEApplication::removeSenderFromStylusDict() {
509 stylusDict->remove( ( void* ) sender() );
510 if ( d->presswidget == sender() )
511 d->presswidget = 0;
512}
513void QPEApplication::setStylusOperation( QWidget* w, StylusMode mode) {
514 createDict();
515 if ( mode == LeftOnly ) {
516 stylusDict->remove
517 ( w );
518 w->removeEventFilter( qApp );
519 }else {
520 stylusDict->insert( w, ( void* ) mode );
521 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
522 w->installEventFilter( qApp );
523 }
524}
525QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w) {
526 if ( stylusDict )
527 return ( StylusMode ) ( int ) stylusDict->find( w );
528 return LeftOnly;
529}
530
531// eventFilter......
532bool QPEApplication::eventFilter( QObject* o, QEvent* e ) {
533 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
534 QMouseEvent * me = ( QMouseEvent* ) e;
535 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
536 switch (mode) {
537 case RightOnHold:
538 switch ( me->type() ) {
539 case QEvent::MouseButtonPress:
540 if ( me->button() == LeftButton ) {
541 d->presstimer = startTimer(500); // #### pref.
542 d->presswidget = (QWidget*)o;
543 d->presspos = me->pos();
544 d->rightpressed = FALSE;
545 }
546 break;
547 case QEvent::MouseMove:
548 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
549 killTimer(d->presstimer);
550 d->presstimer = 0;
551 }
552 break;
553 case QEvent::MouseButtonRelease:
554 if ( me->button() == LeftButton ) {
555 if ( d->presstimer ) {
556 killTimer(d->presstimer);
557 d->presstimer = 0;
558 }
559 if ( d->rightpressed && d->presswidget ) {
560 // Right released
561 postEvent( d->presswidget,
562 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
563 RightButton, LeftButton + RightButton ) );
564 // Left released, off-widget
565 postEvent( d->presswidget,
566 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
567 LeftButton, LeftButton ) );
568 postEvent( d->presswidget,
569 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
570 LeftButton, LeftButton ) );
571 d->rightpressed = FALSE;
572 return TRUE; // don't send the real Left release
573 }
574 }
575 break;
576 default:
577 break;
578 }
579 break;
580 default:
581 ;
582 }
583 }
584 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
585 QKeyEvent *ke = (QKeyEvent *)e;
586 if ( ke->key() == Key_Enter ) {
587 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
588 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
589 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
590 return TRUE;
591 }
592 }
593 }
594 return FALSE;
595}
596
597// Quit stuff
598void QPEApplication::restart() {
599
600}
601void QPEApplication::shutdown() {
451 602
603}
604void QPEApplication::tryQuit() {
605 qWarning("TryQuit!!");
606 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
607 return ; // Inside modal loop or konsole. Too hard to save state.
608 {
609 QCopEnvelope e( "QPE/System", "closing(QString)" );
610 e << d->appName;
611 }
612 processEvents();
452 613
614 quit();
615}
616void QPEApplication::hideOrQuit() {
617 qWarning("hide or close");
618 processEvents();
619 qWarning("past processing");
620
621 // If we are a preloaded application we don't actually quit, so emit
622 // a System message indicating we're quasi-closing.
623 if ( d->preloaded && d->qpe_main_widget )
624
625 {
626 qWarning("hiding");
627 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
628 e << d->appName;
629 d->qpe_main_widget->hide();
630 }
631 else
632 quit();
633}
453 634
454#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 635#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
455 636
diff --git a/x11/libqpe-x11/qpe/qpeapplication.h b/x11/libqpe-x11/qpe/qpeapplication.h
index cd385db..2af1c66 100644
--- a/x11/libqpe-x11/qpe/qpeapplication.h
+++ b/x11/libqpe-x11/qpe/qpeapplication.h
@@ -6,6 +6,7 @@
6 */ 6 */
7 7
8#include <qapplication.h> 8#include <qapplication.h>
9#include <qevent.h>
9 10
10#include <qpe/timestring.h> 11#include <qpe/timestring.h>
11 12
@@ -16,6 +17,7 @@ public:
16 QPEApplication(int& argc, char** argv, Type=GuiClient ); 17 QPEApplication(int& argc, char** argv, Type=GuiClient );
17 ~QPEApplication(); 18 ~QPEApplication();
18 19
20
19 static QString qpeDir(); 21 static QString qpeDir();
20 static QString documentDir(); 22 static QString documentDir();
21 void applyStyle(); 23 void applyStyle();
@@ -32,6 +34,14 @@ public:
32 static void setStylusOperation( QWidget*, StylusMode ); 34 static void setStylusOperation( QWidget*, StylusMode );
33 static StylusMode stylusOperation( QWidget* ); 35 static StylusMode stylusOperation( QWidget* );
34 36
37 enum InputMethodHint {
38 Normal,
39 AlwaysOff,
40 AlwaysOn
41 };
42 static void setInputMethodHint( QWidget*, InputMethodHint );
43 static InputMethodHint inputMethodHint( QWidget* );
44
35 void showMainWidget( QWidget*, bool nomax = FALSE ); 45 void showMainWidget( QWidget*, bool nomax = FALSE );
36 void showMainDocumentWidget( QWidget*, bool nomax = FALSE ); 46 void showMainDocumentWidget( QWidget*, bool nomax = FALSE );
37 47
@@ -60,6 +70,19 @@ private:
60 void initTranslations(); 70 void initTranslations();
61 void internalSetStyle(const QString&); 71 void internalSetStyle(const QString&);
62 72
73private slots:
74 void hideOrQuit();
75 void systemMessage( const QCString&, const QByteArray& );
76 void pidMessage( const QCString&, const QByteArray& );
77 void removeSenderFromStylusDict();
78protected:
79 virtual void restart();
80 virtual void shutdown();
81 bool eventFilter( QObject*, QEvent* );
82 void timerEvent( QTimerEvent* );
83 void raiseAppropriateWindow();
84 virtual void tryQuit();
85
63private: 86private:
64 class Private; 87 class Private;
65 Private* d; 88 Private* d;