summaryrefslogtreecommitdiff
path: root/core/launcher/qrr.cpp
Unidiff
Diffstat (limited to 'core/launcher/qrr.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/qrr.cpp220
1 files changed, 220 insertions, 0 deletions
diff --git a/core/launcher/qrr.cpp b/core/launcher/qrr.cpp
new file mode 100644
index 0000000..5809ca9
--- a/dev/null
+++ b/core/launcher/qrr.cpp
@@ -0,0 +1,220 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "qrr.h"
22
23#include <qtopia/qcopenvelope_qws.h>
24#include <qfile.h>
25#include <qtimer.h>
26#include <qdialog.h>
27#include <qlayout.h>
28#include <qlabel.h>
29#include <qprogressbar.h>
30#include <qapplication.h>
31#include <qevent.h>
32
33
34class CenteringDialog : public QDialog
35{
36public:
37 CenteringDialog( QWidget *parent = 0, char *name = 0, bool modal = FALSE, WFlags f = 0 );
38 virtual ~CenteringDialog();
39
40protected:
41 void resizeEvent( QResizeEvent *e );
42};
43
44CenteringDialog::CenteringDialog( QWidget *parent, char *name, bool modal, WFlags f )
45 : QDialog( parent, name, modal, f )
46{
47}
48
49CenteringDialog::~CenteringDialog()
50{
51}
52
53void CenteringDialog::resizeEvent( QResizeEvent *e )
54{
55 int dist = -((width() - e->oldSize().width()) / 2);
56 qDebug( "move %d", dist );
57 move( pos().x() + dist, pos().y() );
58}
59
60// =====================================================================
61
62QueuedRequestRunner::QueuedRequestRunner( QFile *f, QWidget *parent )
63 : readyToDelete( FALSE ), waitingForMessages( FALSE ), file( 0 )
64{
65 file = f;
66 waitMsgs.setAutoDelete( TRUE );
67 if ( parent ) {
68 progressDialog = new CenteringDialog( parent, 0, TRUE );
69 QVBoxLayout *l = new QVBoxLayout( progressDialog );
70 l->setMargin( 6 );
71 l->setSpacing( 6 );
72 progressLabel = new QLabel( progressDialog );
73 progressLabel->setText( tr("Processing Queued Requests") );
74 progressBar = new QProgressBar( progressDialog );
75 l->addWidget( progressLabel );
76 l->addWidget( progressBar );
77 //progressDialog->setFixedSize( qApp->desktop()->width(), qApp->desktop()->height() );
78 progressDialog->show();
79 }
80 int totalSteps = countSteps();
81 if ( parent ) {
82 qDebug( "%d steps", totalSteps );
83 progressBar->setTotalSteps( totalSteps );
84 progressBar->setProgress( 0 );
85 }
86 file->open( IO_ReadOnly );
87}
88
89QueuedRequestRunner::~QueuedRequestRunner()
90{
91 delete progressDialog;
92 delete file;
93}
94
95void QueuedRequestRunner::process()
96{
97 if ( process( FALSE ) ) {
98 if ( !waitingForMessages || action == "wait" )
99 QTimer::singleShot( 100, this, SLOT(process()) );
100 } else {
101 file->remove();
102 emit finished();
103 }
104
105}
106
107int QueuedRequestRunner::countSteps()
108{
109 int totalSteps = 0;
110 bool more = TRUE;
111 file->open( IO_ReadOnly );
112 while ( more ) {
113 steps = 0;
114 more = process( TRUE );
115 totalSteps += steps;
116 }
117 file->close();
118 waitingForMessages = FALSE;
119 return totalSteps;
120}
121
122bool QueuedRequestRunner::process( bool counting )
123{
124 QDataStream stream( file );
125 stream >> action;
126 if ( action == "info" ) {
127 QString message;
128 stream >> message;
129 qDebug( "info %s", message.latin1() );
130 if ( counting ) {
131 steps++;
132 } else {
133 progressLabel->setText( message );
134 }
135 } else if ( action == "qcop" ) {
136 QCString channel;
137 QCString message;
138 int args;
139 stream >> channel >> message >> args;
140 qDebug( "qcop %s %s", channel.data(), message.data() );
141#ifndef QT_NO_COP
142 QCopEnvelope *e = 0;
143 if ( !counting ) {
144 e = new QCopEnvelope( channel, message );
145 }
146#endif
147 QCString type;
148 for ( int i = 0; i < args; ++i ) {
149 stream >> type;
150 if ( type == "QString" ) {
151 QString arg;
152 stream >> arg;
153 qDebug( " %s %s", type.data(), arg.latin1() );
154#ifndef QT_NO_COP
155 if ( !counting )
156 (*e) << arg;
157#endif
158 } else if ( type == "int" ) {
159 int arg;
160 stream >> arg;
161 qDebug( " %s %d", type.data(), arg );
162#ifndef QT_NO_COP
163 if ( !counting )
164 (*e) << arg;
165#endif
166 } else {
167 qDebug( "\tBUG unknown type '%s'!", type.data() );
168 }
169 }
170 if ( counting ) {
171 steps++;
172 } else {
173#ifndef QT_NO_COP
174 // this causes the QCop message to be sent
175 delete e;
176#endif
177 }
178 } else if ( action == "wait" ) {
179 int messageCount;
180 QCString message;
181 waitMsgs.clear();
182 stream >> messageCount;
183 for ( int i = 0; i < messageCount; ++i ) {
184 stream >> message;
185 qDebug( "wait %s", message.data() );
186 if ( !counting ) {
187 waitMsgs.append( new QCString( message ) );
188 }
189 }
190 if ( counting )
191 steps++;
192 waitingForMessages = TRUE;
193 } else {
194 qDebug( "\tBUG unknown action '%s'!", action.data() );
195 }
196
197 if ( !counting ) {
198 progressBar->setProgress( progressBar->progress() + 1 );
199 }
200
201 return !file->atEnd();
202}
203
204void QueuedRequestRunner::desktopMessage( const QCString &message, const QByteArray & )
205{
206 bool found = FALSE;
207 QCString *msg;
208 for ( QListIterator<QCString> iter( waitMsgs ); ( msg = iter.current() ) != 0; ++iter ) {
209 if ( *msg == message ) {
210 found = TRUE;
211 break;
212 }
213 }
214 if ( found ) {
215 waitMsgs.clear();
216 waitingForMessages = FALSE;
217 QTimer::singleShot( 100, this, SLOT(process()) );
218 }
219}
220