summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp10
-rw-r--r--core/launcher/launcher.cpp2
-rw-r--r--core/launcher/main.cpp7
-rw-r--r--core/launcher/qcopbridge.cpp2
-rw-r--r--core/launcher/runningappbar.cpp2
-rw-r--r--core/launcher/transferserver.cpp2
6 files changed, 12 insertions, 13 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index d74b745..1fd3f6a 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -1,1051 +1,1053 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "desktop.h" 21#include "desktop.h"
22#include "info.h" 22#include "info.h"
23#include "launcher.h" 23#include "launcher.h"
24//#include "mrulist.h" 24//#include "mrulist.h"
25#include "qcopbridge.h" 25#include "qcopbridge.h"
26#include "shutdownimpl.h" 26#include "shutdownimpl.h"
27#include "startmenu.h" 27#include "startmenu.h"
28#include "taskbar.h" 28#include "taskbar.h"
29#include "transferserver.h" 29#include "transferserver.h"
30#include "irserver.h" 30#include "irserver.h"
31#include "packageslave.h" 31#include "packageslave.h"
32 32
33#include <qpe/applnk.h> 33#include <qpe/applnk.h>
34#include <qpe/mimetype.h> 34#include <qpe/mimetype.h>
35#include <qpe/password.h> 35#include <qpe/password.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <qpe/power.h> 37#include <qpe/power.h>
38#include <qpe/timeconversion.h> 38#include <qpe/timeconversion.h>
39#include <qpe/qcopenvelope_qws.h> 39#include <qpe/qcopenvelope_qws.h>
40#include <qpe/network.h> 40#include <qpe/network.h>
41#include <qpe/global.h> 41#include <qpe/global.h>
42 42
43#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) 43#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ )
44#include <qpe/custom.h> 44#include <qpe/custom.h>
45#endif 45#endif
46 46
47#include <opie/odevice.h> 47#include <opie/odevice.h>
48 48
49#include <qgfx_qws.h> 49#include <qgfx_qws.h>
50#include <qmainwindow.h> 50#include <qmainwindow.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qtimer.h> 52#include <qtimer.h>
53#include <qwindowsystem_qws.h> 53#include <qwindowsystem_qws.h>
54 54
55#include <qvaluelist.h> 55#include <qvaluelist.h>
56 56
57#include <stdlib.h> 57#include <stdlib.h>
58#include <unistd.h> 58#include <unistd.h>
59#include <fcntl.h> 59#include <fcntl.h>
60 60
61using namespace Opie; 61using namespace Opie;
62 62
63class QCopKeyRegister 63class QCopKeyRegister
64{ 64{
65public: 65public:
66 QCopKeyRegister() : keyCode( 0 ) 66 QCopKeyRegister() : keyCode( 0 )
67 { } 67 { }
68 QCopKeyRegister( int k, const QString &c, const QString &m ) 68 QCopKeyRegister( int k, const QString &c, const QString &m )
69 : keyCode( k ), channel( c ), message( m ) 69 : keyCode( k ), channel( c ), message( m )
70 { } 70 { }
71 71
72 int getKeyCode() const 72 int getKeyCode() const
73 { 73 {
74 return keyCode; 74 return keyCode;
75 } 75 }
76 QString getChannel() const 76 QString getChannel() const
77 { 77 {
78 return channel; 78 return channel;
79 } 79 }
80 QString getMessage() const 80 QString getMessage() const
81 { 81 {
82 return message; 82 return message;
83 } 83 }
84 84
85private: 85private:
86 int keyCode; 86 int keyCode;
87 QString channel, message; 87 QString channel, message;
88}; 88};
89 89
90typedef QValueList<QCopKeyRegister> KeyRegisterList; 90typedef QValueList<QCopKeyRegister> KeyRegisterList;
91KeyRegisterList keyRegisterList; 91KeyRegisterList keyRegisterList;
92 92
93static Desktop* qpedesktop = 0; 93static Desktop* qpedesktop = 0;
94static int loggedin = 0; 94static int loggedin = 0;
95static void login( bool at_poweron ) 95static void login( bool at_poweron )
96{ 96{
97 if ( !loggedin ) { 97 if ( !loggedin ) {
98 Global::terminateBuiltin( "calibrate" ); 98 Global::terminateBuiltin( "calibrate" );
99 Password::authenticate( at_poweron ); 99 Password::authenticate( at_poweron );
100 loggedin = 1; 100 loggedin = 1;
101 QCopEnvelope e( "QPE/Desktop", "unlocked()" ); 101 QCopEnvelope e( "QPE/Desktop", "unlocked()" );
102 } 102 }
103} 103}
104 104
105bool Desktop::screenLocked() 105bool Desktop::screenLocked()
106{ 106{
107 return loggedin == 0; 107 return loggedin == 0;
108} 108}
109 109
110/* 110/*
111 Priority is number of alerts that are needed to pop up 111 Priority is number of alerts that are needed to pop up
112 alert. 112 alert.
113 */ 113 */
114class DesktopPowerAlerter : public QMessageBox 114class DesktopPowerAlerter : public QMessageBox
115{ 115{
116public: 116public:
117 DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) 117 DesktopPowerAlerter( QWidget *parent, const char *name = 0 )
118 : QMessageBox( tr( "Battery Status" ), "Low Battery", 118 : QMessageBox( tr( "Battery Status" ), "Low Battery",
119 QMessageBox::Critical, 119 QMessageBox::Critical,
120 QMessageBox::Ok | QMessageBox::Default, 120 QMessageBox::Ok | QMessageBox::Default,
121 QMessageBox::NoButton, QMessageBox::NoButton, 121 QMessageBox::NoButton, QMessageBox::NoButton,
122 parent, name, FALSE ) 122 parent, name, FALSE )
123 { 123 {
124 currentPriority = INT_MAX; 124 currentPriority = INT_MAX;
125 alertCount = 0; 125 alertCount = 0;
126 } 126 }
127 127
128 void alert( const QString &text, int priority ); 128 void alert( const QString &text, int priority );
129 void hideEvent( QHideEvent * ); 129 void hideEvent( QHideEvent * );
130private: 130private:
131 int currentPriority; 131 int currentPriority;
132 int alertCount; 132 int alertCount;
133}; 133};
134 134
135void DesktopPowerAlerter::alert( const QString &text, int priority ) 135void DesktopPowerAlerter::alert( const QString &text, int priority )
136{ 136{
137 alertCount++; 137 alertCount++;
138 if ( alertCount < priority ) 138 if ( alertCount < priority )
139 return ; 139 return ;
140 if ( priority > currentPriority ) 140 if ( priority > currentPriority )
141 return ; 141 return ;
142 currentPriority = priority; 142 currentPriority = priority;
143 setText( text ); 143 setText( text );
144 show(); 144 show();
145} 145}
146 146
147 147
148void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 148void DesktopPowerAlerter::hideEvent( QHideEvent *e )
149{ 149{
150 QMessageBox::hideEvent( e ); 150 QMessageBox::hideEvent( e );
151 alertCount = 0; 151 alertCount = 0;
152 currentPriority = INT_MAX; 152 currentPriority = INT_MAX;
153} 153}
154 154
155
156class QPEScreenSaver : public QWSScreenSaver 155class QPEScreenSaver : public QWSScreenSaver
157{ 156{
158private: 157private:
159 int LcdOn; 158 int LcdOn;
160 159
161public: 160public:
162 QPEScreenSaver() 161 QPEScreenSaver()
163 { 162 {
164 m_disable_suspend = 100; 163 m_disable_suspend = 100;
165 m_enable_dim = false; 164 m_enable_dim = false;
166 m_enable_lightoff = false; 165 m_enable_lightoff = false;
167 m_enable_onlylcdoff = false; 166 m_enable_onlylcdoff = false;
168 167
169 m_lcd_status = true; 168 m_lcd_status = true;
170 169
171 m_backlight_bright = -1; 170 m_backlight_bright = -1;
172 m_backlight_forcedoff = false; 171 m_backlight_forcedoff = false;
173 172
174 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 173 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
175 ODevice::inst ( ) -> setDisplayStatus ( true ); 174 ODevice::inst ( ) -> setDisplayStatus ( true );
176 } 175 }
177 void restore() 176 void restore()
178 { 177 {
179 if ( !m_lcd_status ) { // We must have turned it off 178 if ( !m_lcd_status ) { // We must have turned it off
180 ODevice::inst ( ) -> setDisplayStatus ( true ); 179 ODevice::inst ( ) -> setDisplayStatus ( true );
181 m_lcd_status = true; 180 m_lcd_status = true;
182 } 181 }
183 182
184 setBacklight ( -1 ); 183 setBacklight ( -1 );
185 } 184 }
186 bool save( int level ) 185 bool save( int level )
187 { 186 {
188 switch ( level ) { 187 switch ( level ) {
189 case 0: 188 case 0:
190 if ( m_disable_suspend > 0 && m_enable_dim ) { 189 if ( m_disable_suspend > 0 && m_enable_dim ) {
191 if ( backlight() > 1 ) 190 if ( backlight() > 1 )
192 setBacklight( 1 ); // lowest non-off 191 setBacklight( 1 ); // lowest non-off
193 } 192 }
194 return true; 193 return true;
195 break; 194 break;
196 case 1: 195 case 1:
197 if ( m_disable_suspend > 1 && m_enable_lightoff ) { 196 if ( m_disable_suspend > 1 && m_enable_lightoff ) {
198 setBacklight( 0 ); // off 197 setBacklight( 0 ); // off
199 } 198 }
200 return true; 199 return true;
201 break; 200 break;
202 case 2: 201 case 2:
203 if ( m_enable_onlylcdoff ) { 202 if ( m_enable_onlylcdoff ) {
204 ODevice::inst ( ) -> setDisplayStatus ( false ); 203 ODevice::inst ( ) -> setDisplayStatus ( false );
205 m_lcd_status = false; 204 m_lcd_status = false;
206 return true; 205 return true;
207 } 206 }
208 else // We're going to suspend the whole machine 207 else // We're going to suspend the whole machine
209 { 208 {
210 if ( ( m_disable_suspend > 2 ) && 209 if ( ( m_disable_suspend > 2 ) &&
211 ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) && 210 ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) &&
212 ( !Network::networkOnline ( ) ) ) { 211 ( !Network::networkOnline ( ) ) ) {
213 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 212 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
214 return true; 213 return true;
215 } 214 }
216 } 215 }
217 break; 216 break;
218 } 217 }
219 return false; 218 return false;
220 } 219 }
221 220
222private: 221private:
223 static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def ) 222 static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def )
224 { 223 {
225 if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 ) 224 if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 )
226 return 0; 225 return 0;
227 226
228 if ( interval < 0 ) { 227 if ( interval < 0 ) {
229 // Restore screen blanking and power saving state 228 // Restore screen blanking and power saving state
230 interval = config.readNumEntry( value, def ); 229 interval = config.readNumEntry( value, def );
231 } 230 }
232 return interval; 231 return interval;
233 } 232 }
234 233
235public: 234public:
236 void setIntervals( int i1, int i2, int i3 ) 235 void setIntervals( int i1, int i2, int i3 )
237 { 236 {
238 Config config( "qpe" ); 237 Config config( "qpe" );
239 config.setGroup( "Screensaver" ); 238 config.setGroup( "Screensaver" );
240 239
241 int v[ 4 ]; 240 int v[ 4 ];
242 i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 ); 241 i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 );
243 i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 ); 242 i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 );
244 i3 = ssi( i3, config, "", "Interval", 60 ); 243 i3 = ssi( i3, config, "", "Interval", 60 );
245 244
246 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); 245 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
247 246
248 v [ 0 ] = QMAX( 1000 * i1, 100 ); 247 v [ 0 ] = QMAX( 1000 * i1, 100 );
249 v [ 1 ] = QMAX( 1000 * i2, 100 ); 248 v [ 1 ] = QMAX( 1000 * i2, 100 );
250 v [ 2 ] = QMAX( 1000 * i3, 100 ); 249 v [ 2 ] = QMAX( 1000 * i3, 100 );
251 v [ 3 ] = 0; 250 v [ 3 ] = 0;
252 m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false ); 251 m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false );
253 m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false ); 252 m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false );
254 m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 ); 253 m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 );
255 254
256 if ( !i1 && !i2 && !i3 ) 255 if ( !i1 && !i2 && !i3 )
257 QWSServer::setScreenSaverInterval( 0 ); 256 QWSServer::setScreenSaverInterval( 0 );
258 else 257 else
259 QWSServer::setScreenSaverIntervals( v ); 258 QWSServer::setScreenSaverIntervals( v );
260 } 259 }
261 260
262 void setInterval ( int interval ) 261 void setInterval ( int interval )
263 { 262 {
264 setIntervals ( -1, -1, interval ); 263 setIntervals ( -1, -1, interval );
265 } 264 }
266 265
267 void setMode ( int mode ) 266 void setMode ( int mode )
268 { 267 {
269 if ( mode > m_disable_suspend ) 268 if ( mode > m_disable_suspend )
270 setInterval( -1 ); 269 setInterval( -1 );
271 m_disable_suspend = mode; 270 m_disable_suspend = mode;
272 } 271 }
273 272
274 int backlight ( ) 273 int backlight ( )
275 { 274 {
276 if ( m_backlight_bright == -1 ) { 275 if ( m_backlight_bright == -1 ) {
277 // Read from config 276 // Read from config
278 Config config ( "qpe" ); 277 Config config ( "qpe" );
279 config. setGroup ( "Screensaver" ); 278 config. setGroup ( "Screensaver" );
280 m_backlight_bright = config. readNumEntry ( "Brightness", 255 ); 279 m_backlight_bright = config. readNumEntry ( "Brightness", 255 );
281 } 280 }
282 return m_backlight_bright; 281 return m_backlight_bright;
283 } 282 }
284 283
285 void setBacklight ( int bright ) 284 void setBacklight ( int bright )
286 { 285 {
287 if ( bright == -3 ) { 286 if ( bright == -3 ) {
288 // Forced on 287 // Forced on
289 m_backlight_forcedoff = false; 288 m_backlight_forcedoff = false;
290 bright = -1; 289 bright = -1;
291 } 290 }
292 if ( m_backlight_forcedoff && bright != -2 ) 291 if ( m_backlight_forcedoff && bright != -2 )
293 return ; 292 return ;
294 if ( bright == -2 ) { 293 if ( bright == -2 ) {
295 // Toggle between off and on 294 // Toggle between off and on
296 bright = m_backlight_bright ? 0 : -1; 295 bright = m_backlight_bright ? 0 : -1;
297 m_backlight_forcedoff = !bright; 296 m_backlight_forcedoff = !bright;
298 } 297 }
299 298
300 m_backlight_bright = bright; 299 m_backlight_bright = bright;
301 300
302 bright = backlight ( ); 301 bright = backlight ( );
303 ODevice::inst ( ) -> setDisplayBrightness ( bright ); 302 ODevice::inst ( ) -> setDisplayBrightness ( bright );
304 303
305 m_backlight_bright = bright; 304 m_backlight_bright = bright;
306 } 305 }
307 306
308 void setDisplayState ( bool on ) 307 void setDisplayState ( bool on )
309 { 308 {
310 if ( m_lcd_status != on ) { 309 if ( m_lcd_status != on ) {
311 ODevice::inst ( ) -> setDisplayStatus ( on ); 310 ODevice::inst ( ) -> setDisplayStatus ( on );
312 m_lcd_status = on; 311 m_lcd_status = on;
313 } 312 }
314 } 313 }
315 314
316private: 315private:
317 int m_disable_suspend; 316 int m_disable_suspend;
318 bool m_enable_dim; 317 bool m_enable_dim;
319 bool m_enable_lightoff; 318 bool m_enable_lightoff;
320 bool m_enable_onlylcdoff; 319 bool m_enable_onlylcdoff;
321 320
322 bool m_lcd_status; 321 bool m_lcd_status;
323 322
324 int m_backlight_bright; 323 int m_backlight_bright;
325 bool m_backlight_forcedoff; 324 bool m_backlight_forcedoff;
326}; 325};
327 326
328
329void DesktopApplication::switchLCD ( bool on ) 327void DesktopApplication::switchLCD ( bool on )
330{ 328{
331 if ( qApp ) { 329 if ( qApp ) {
332 DesktopApplication *dapp = (DesktopApplication *) qApp; 330 DesktopApplication *dapp = (DesktopApplication *) qApp;
333 331
334 if ( dapp-> m_screensaver ) { 332 if ( dapp-> m_screensaver ) {
335 if ( on ) { 333 if ( on ) {
336 dapp-> m_screensaver-> setDisplayState ( true ); 334 dapp-> m_screensaver-> setDisplayState ( true );
337 dapp-> m_screensaver-> setBacklight ( -3 ); 335 dapp-> m_screensaver-> setBacklight ( -3 );
338 } 336 }
339 else { 337 else {
340 dapp-> m_screensaver-> setDisplayState ( false ); 338 dapp-> m_screensaver-> setDisplayState ( false );
341 } 339 }
342 } 340 }
343 } 341 }
344} 342}
345 343
346 344
347DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) 345DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType )
348 : QPEApplication( argc, argv, appType ) 346 : QPEApplication( argc, argv, appType )
349{ 347{
350 348
351 QTimer * t = new QTimer( this ); 349 QTimer * t = new QTimer( this );
352 connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); 350 connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) );
353 t->start( 10000 ); 351 t->start( 10000 );
354 ps = new PowerStatus; 352 ps = new PowerStatus;
355 pa = new DesktopPowerAlerter( 0 ); 353 pa = new DesktopPowerAlerter( 0 );
356 354
357 channel = new QCopChannel( "QPE/Desktop", this ); 355 channel = new QCopChannel( "QPE/Desktop", this );
358 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), 356 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ),
359 this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); 357 this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) );
360 358
361 channel = new QCopChannel( "QPE/System", this ); 359 channel = new QCopChannel( "QPE/System", this );
362 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), 360 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ),
363 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); 361 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) );
364 362
365 m_screensaver = new QPEScreenSaver; 363 m_screensaver = new QPEScreenSaver;
366 364
367 m_screensaver-> setInterval ( -1 ); 365 m_screensaver-> setInterval ( -1 );
368 QWSServer::setScreenSaver( m_screensaver ); 366 QWSServer::setScreenSaver( m_screensaver );
369} 367}
370 368
371 369
372DesktopApplication::~DesktopApplication() 370DesktopApplication::~DesktopApplication()
373{ 371{
374 delete ps; 372 delete ps;
375 delete pa; 373 delete pa;
376} 374}
377 375
378void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) 376void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data )
379{ 377{
380#ifdef Q_WS_QWS 378#ifdef Q_WS_QWS
381 QDataStream stream( data, IO_ReadOnly ); 379 QDataStream stream( data, IO_ReadOnly );
382 if ( msg == "keyRegister(int key, QString channel, QString message)" ) { 380 if ( msg == "keyRegister(int key, QString channel, QString message)" ) {
383 int k; 381 int k;
384 QString c, m; 382 QString c, m;
385 stream >> k; 383 stream >> k;
386 stream >> c; 384 stream >> c;
387 stream >> m; 385 stream >> m;
388 386
389 qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); 387 qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m );
390 keyRegisterList.append( QCopKeyRegister( k, c, m ) ); 388 keyRegisterList.append( QCopKeyRegister( k, c, m ) );
391 } 389 }
392#endif 390#endif
393} 391}
394 392
395 393
396void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) 394void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data )
397{ 395{
398#ifdef Q_WS_QWS 396#ifdef Q_WS_QWS
399 QDataStream stream ( data, IO_ReadOnly ); 397 QDataStream stream ( data, IO_ReadOnly );
400 398
401 if ( msg == "setScreenSaverInterval(int)" ) { 399 if ( msg == "setScreenSaverInterval(int)" ) {
402 int time; 400 int time;
403 stream >> time; 401 stream >> time;
404 m_screensaver-> setInterval( time ); 402 m_screensaver-> setInterval( time );
405 } 403 }
406 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { 404 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
407 int t1, t2, t3; 405 int t1, t2, t3;
408 stream >> t1 >> t2 >> t3; 406 stream >> t1 >> t2 >> t3;
409 m_screensaver-> setIntervals( t1, t2, t3 ); 407 m_screensaver-> setIntervals( t1, t2, t3 );
410 } 408 }
411 else if ( msg == "setBacklight(int)" ) { 409 else if ( msg == "setBacklight(int)" ) {
412 int bright; 410 int bright;
413 stream >> bright; 411 stream >> bright;
414 m_screensaver-> setBacklight( bright ); 412 m_screensaver-> setBacklight( bright );
415 } 413 }
416 else if ( msg == "setScreenSaverMode(int)" ) { 414 else if ( msg == "setScreenSaverMode(int)" ) {
417 int mode; 415 int mode;
418 stream >> mode; 416 stream >> mode;
419 m_screensaver-> setMode ( mode ); 417 m_screensaver-> setMode ( mode );
420 } 418 }
421 else if ( msg == "setDisplayState(int)" ) { 419 else if ( msg == "setDisplayState(int)" ) {
422 int state; 420 int state;
423 stream >> state; 421 stream >> state;
424 m_screensaver-> setDisplayState ( state != 0 ); 422 m_screensaver-> setDisplayState ( state != 0 );
425 } 423 }
426 else if ( msg == "suspend()" ) { 424 else if ( msg == "suspend()" ) {
427 emit power(); 425 emit power();
428 } 426 }
429#endif 427#endif
430} 428}
431 429
432enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; 430enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown;
433 431
434#ifdef Q_WS_QWS 432#ifdef Q_WS_QWS
435bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 433bool DesktopApplication::qwsEventFilter( QWSEvent *e )
436{ 434{
437 qpedesktop->checkMemory(); 435 qpedesktop->checkMemory();
438 436
439 if ( e->type == QWSEvent::Key ) { 437 if ( e->type == QWSEvent::Key ) {
440 QWSKeyEvent * ke = ( QWSKeyEvent * ) e; 438 QWSKeyEvent * ke = ( QWSKeyEvent * ) e;
441 if ( !loggedin && ke->simpleData.keycode != Key_F34 ) 439 if ( !loggedin && ke->simpleData.keycode != Key_F34 )
442 return TRUE; 440 return TRUE;
443 bool press = ke->simpleData.is_press; 441 bool press = ke->simpleData.is_press;
444 bool autoRepeat = ke->simpleData.is_auto_repeat; 442 bool autoRepeat = ke->simpleData.is_auto_repeat;
445 443
446 /* 444 /*
447 app that registers key/message to be sent back to the app, when it doesn't have focus, 445 app that registers key/message to be sent back to the app, when it doesn't have focus,
448 when user presses key, unless keyboard has been requested from app. 446 when user presses key, unless keyboard has been requested from app.
449 will not send multiple repeats if user holds key 447 will not send multiple repeats if user holds key
450 i.e. one shot 448 i.e. one shot
451 */ 449 */
452 if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) { 450 if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) {
453// qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode); 451// qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode);
454 KeyRegisterList::Iterator it; 452 KeyRegisterList::Iterator it;
455 for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { 453 for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) {
456 if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) { 454 if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) {
457 if ( press ) 455 if ( press )
458 qDebug( "press" ); 456 qDebug( "press" );
459 else 457 else
460 qDebug( "release" ); 458 qDebug( "release" );
461 QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); 459 QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() );
462 } 460 }
463 } 461 }
464 } 462 }
465 463
466 if ( !keyboardGrabbed() ) { 464 if ( !keyboardGrabbed() ) {
467 if ( ke->simpleData.keycode == Key_F9 ) { 465 if ( ke->simpleData.keycode == Key_F9 ) {
468 if ( press ) 466 if ( press )
469 emit datebook(); 467 emit datebook();
470 return TRUE; 468 return TRUE;
471 } 469 }
472 if ( ke->simpleData.keycode == Key_F10 ) { 470 if ( ke->simpleData.keycode == Key_F10 ) {
473 if ( !press && cardSendTimer ) { 471 if ( !press && cardSendTimer ) {
474 emit contacts(); 472 emit contacts();
475 delete cardSendTimer; 473 delete cardSendTimer;
476 } 474 }
477 else if ( press ) { 475 else if ( press ) {
478 cardSendTimer = new QTimer(); 476 cardSendTimer = new QTimer();
479 cardSendTimer->start( 2000, TRUE ); 477 cardSendTimer->start( 2000, TRUE );
480 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); 478 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) );
481 } 479 }
482 return TRUE; 480 return TRUE;
483 } 481 }
484 /* menu key now opens application menu/toolbar 482 /* menu key now opens application menu/toolbar
485 if ( ke->simpleData.keycode == Key_F11 ) { 483 if ( ke->simpleData.keycode == Key_F11 ) {
486 if ( press ) emit menu(); 484 if ( press ) emit menu();
487 return TRUE; 485 return TRUE;
488 } 486 }
489 */ 487 */
490 if ( ke->simpleData.keycode == Key_F12 ) { 488 if ( ke->simpleData.keycode == Key_F12 ) {
491 while ( activePopupWidget() ) 489 while ( activePopupWidget() )
492 activePopupWidget() ->close(); 490 activePopupWidget() ->close();
493 if ( press ) 491 if ( press )
494 emit launch(); 492 emit launch();
495 return TRUE; 493 return TRUE;
496 } 494 }
497 if ( ke->simpleData.keycode == Key_F13 ) { 495 if ( ke->simpleData.keycode == Key_F13 ) {
498 if ( press ) 496 if ( press )
499 emit email(); 497 emit email();
500 return TRUE; 498 return TRUE;
501 } 499 }
502 } 500 }
503 501
504 if ( ke->simpleData.keycode == Key_F34 ) { 502 if ( ke->simpleData.keycode == Key_F34 ) {
505 if ( press ) 503 if ( press )
506 emit power(); 504 emit power();
507 return TRUE; 505 return TRUE;
508 } 506 }
509 // This was used for the iPAQ PowerButton 507 // This was used for the iPAQ PowerButton
510 // See main.cpp for new KeyboardFilter 508 // See main.cpp for new KeyboardFilter
511 // 509 //
512 // if ( ke->simpleData.keycode == Key_SysReq ) { 510 // if ( ke->simpleData.keycode == Key_SysReq ) {
513 // if ( press ) emit power(); 511 // if ( press ) emit power();
514 // return TRUE; 512 // return TRUE;
515 // } 513 // }
516 if ( ke->simpleData.keycode == Key_F35 ) { 514 if ( ke->simpleData.keycode == Key_F35 ) {
517 if ( press ) 515 if ( press )
518 emit backlight(); 516 emit backlight();
519 return TRUE; 517 return TRUE;
520 } 518 }
521 if ( ke->simpleData.keycode == Key_F32 ) { 519 if ( ke->simpleData.keycode == Key_F32 ) {
522 if ( press ) 520 if ( press )
523 QCopEnvelope e( "QPE/Desktop", "startSync()" ); 521 QCopEnvelope e( "QPE/Desktop", "startSync()" );
524 return TRUE; 522 return TRUE;
525 } 523 }
526 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { 524 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) {
527 if ( press ) 525 if ( press )
528 emit symbol(); 526 emit symbol();
529 return TRUE; 527 return TRUE;
530 } 528 }
531 if ( ke->simpleData.keycode == Key_NumLock ) { 529 if ( ke->simpleData.keycode == Key_NumLock ) {
532 if ( press ) 530 if ( press )
533 emit numLockStateToggle(); 531 emit numLockStateToggle();
534 } 532 }
535 if ( ke->simpleData.keycode == Key_CapsLock ) { 533 if ( ke->simpleData.keycode == Key_CapsLock ) {
536 if ( press ) 534 if ( press )
537 emit capsLockStateToggle(); 535 emit capsLockStateToggle();
538 } 536 }
539 if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) 537 if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) )
540 qpedesktop->keyClick(); 538 qpedesktop->keyClick();
541 } 539 }
542 else { 540 else {
543 if ( e->type == QWSEvent::Mouse ) { 541 if ( e->type == QWSEvent::Mouse ) {
544 QWSMouseEvent * me = ( QWSMouseEvent * ) e; 542 QWSMouseEvent * me = ( QWSMouseEvent * ) e;
545 static bool up = TRUE; 543 static bool up = TRUE;
546 if ( me->simpleData.state & LeftButton ) { 544 if ( me->simpleData.state & LeftButton ) {
547 if ( up ) { 545 if ( up ) {
548 up = FALSE; 546 up = FALSE;
549 qpedesktop->screenClick(); 547 qpedesktop->screenClick();
550 } 548 }
551 } 549 }
552 else { 550 else {
553 up = TRUE; 551 up = TRUE;
554 } 552 }
555 } 553 }
556 } 554 }
557 555
558 return QPEApplication::qwsEventFilter( e ); 556 return QPEApplication::qwsEventFilter( e );
559} 557}
560#endif 558#endif
561 559
562void DesktopApplication::psTimeout() 560void DesktopApplication::psTimeout()
563{ 561{
564 qpedesktop->checkMemory(); // in case no events are being generated 562 qpedesktop->checkMemory(); // in case no events are being generated
565 563
566 *ps = PowerStatusManager::readStatus(); 564 *ps = PowerStatusManager::readStatus();
567 565
568 if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) { 566 if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) {
569 pa->alert( tr( "Battery is running very low." ), 6 ); 567 pa->alert( tr( "Battery is running very low." ), 6 );
570 } 568 }
571 569
572 if ( ps->batteryStatus() == PowerStatus::Critical ) { 570 if ( ps->batteryStatus() == PowerStatus::Critical ) {
573 pa->alert( tr( "Battery level is critical!\n" 571 pa->alert( tr( "Battery level is critical!\n"
574 "Keep power off until power restored!" ), 1 ); 572 "Keep power off until power restored!" ), 1 );
575 } 573 }
576 574
577 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { 575 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) {
578 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); 576 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 );
579 } 577 }
580} 578}
581 579
582 580
583void DesktopApplication::sendCard() 581void DesktopApplication::sendCard()
584{ 582{
585 delete cardSendTimer; 583 delete cardSendTimer;
586 cardSendTimer = 0; 584 cardSendTimer = 0;
587 QString card = getenv( "HOME" ); 585 QString card = getenv( "HOME" );
588 card += "/Applications/addressbook/businesscard.vcf"; 586 card += "/Applications/addressbook/businesscard.vcf";
589 587
590 if ( QFile::exists( card ) ) { 588 if ( QFile::exists( card ) ) {
591 QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); 589 QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" );
592 QString mimetype = "text/x-vCard"; 590 QString mimetype = "text/x-vCard";
593 e << tr( "business card" ) << card << mimetype; 591 e << tr( "business card" ) << card << mimetype;
594 } 592 }
595} 593}
596 594
597#if defined(QPE_HAVE_MEMALERTER) 595#if defined(QPE_HAVE_MEMALERTER)
598QPE_MEMALERTER_IMPL 596QPE_MEMALERTER_IMPL
599#endif 597#endif
600 598
601//=========================================================================== 599//===========================================================================
602 600
603Desktop::Desktop() : 601Desktop::Desktop() :
604 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 602 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
605 qcopBridge( 0 ), 603 qcopBridge( 0 ),
606 transferServer( 0 ), 604 transferServer( 0 ),
607 packageSlave( 0 ) 605 packageSlave( 0 )
608{ 606{
609 qpedesktop = this; 607 qpedesktop = this;
610 608
611 // bg = new Info( this ); 609 // bg = new Info( this );
612 tb = new TaskBar; 610 tb = new TaskBar;
613 611
614 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); 612 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader );
615 613
616 connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); 614 connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) );
617 connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); 615 connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) );
618 616
619 int displayw = qApp->desktop() ->width(); 617 int displayw = qApp->desktop() ->width();
620 int displayh = qApp->desktop() ->height(); 618 int displayh = qApp->desktop() ->height();
621 619
622 620
623 QSize sz = tb->sizeHint(); 621 QSize sz = tb->sizeHint();
624 622
625 setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); 623 setGeometry( 0, displayh - sz.height(), displayw, sz.height() );
626 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); 624 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() );
627 625
628 tb->show(); 626 tb->show();
629 launcher->showMaximized(); 627 launcher->showMaximized();
630 launcher->show(); 628 launcher->show();
631 launcher->raise(); 629 launcher->raise();
632#if defined(QPE_HAVE_MEMALERTER) 630#if defined(QPE_HAVE_MEMALERTER)
633 631
634 initMemalerter(); 632 initMemalerter();
635#endif 633#endif
636 // start services 634 // start services
637 startTransferServer(); 635 startTransferServer();
638 ( void ) new IrServer( this ); 636 ( void ) new IrServer( this );
639 rereadVolumes(); 637 rereadVolumes();
640 638
641 packageSlave = new PackageSlave( this ); 639 packageSlave = new PackageSlave( this );
642 connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); 640 connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) );
643 641
644 qApp->installEventFilter( this ); 642 qApp->installEventFilter( this );
645 643
646 qApp-> setMainWidget ( launcher ); 644 qApp-> setMainWidget ( launcher );
647} 645}
648 646
649void Desktop::show() 647void Desktop::show()
650{ 648{
651 login( TRUE ); 649 login( TRUE );
652 QWidget::show(); 650 QWidget::show();
653} 651}
654 652
655Desktop::~Desktop() 653Desktop::~Desktop()
656{ 654{
657 delete launcher; 655 delete launcher;
658 delete tb; 656 delete tb;
659 delete qcopBridge; 657 delete qcopBridge;
660 delete transferServer; 658 delete transferServer;
661} 659}
662 660
663bool Desktop::recoverMemory() 661bool Desktop::recoverMemory()
664{ 662{
665 return tb->recoverMemory(); 663 return tb->recoverMemory();
666} 664}
667 665
668void Desktop::checkMemory() 666void Desktop::checkMemory()
669{ 667{
670#if defined(QPE_HAVE_MEMALERTER) 668#if defined(QPE_HAVE_MEMALERTER)
671 static bool ignoreNormal = FALSE; 669 static bool ignoreNormal = FALSE;
672 static bool existingMessage = FALSE; 670 static bool existingMessage = FALSE;
673 671
674 if ( existingMessage ) 672 if ( existingMessage )
675 return ; // don't show a second message while still on first 673 return ; // don't show a second message while still on first
676 674
677 existingMessage = TRUE; 675 existingMessage = TRUE;
678 switch ( memstate ) { 676 switch ( memstate ) {
679 case Unknown: 677 case Unknown:
680 break; 678 break;
681 case Low: 679 case Low:
682 memstate = Unknown; 680 memstate = Unknown;
683 if ( recoverMemory() ) 681 if ( recoverMemory() )
684 ignoreNormal = TRUE; 682 ignoreNormal = TRUE;
685 else 683 else
686 QMessageBox::warning( 0 , "Memory Status", 684 QMessageBox::warning( 0 , "Memory Status",
687 "The memory smacks of shortage. \n" 685 "The memory smacks of shortage. \n"
688 "Please save data. " ); 686 "Please save data. " );
689 break; 687 break;
690 case Normal: 688 case Normal:
691 memstate = Unknown; 689 memstate = Unknown;
692 if ( ignoreNormal ) 690 if ( ignoreNormal )
693 ignoreNormal = FALSE; 691 ignoreNormal = FALSE;
694// else 692// else
695// QMessageBox::information ( 0 , "Memory Status", 693// QMessageBox::information ( 0 , "Memory Status",
696// "There is enough memory again." ); 694// "There is enough memory again." );
697 break; 695 break;
698 case VeryLow: 696 case VeryLow:
699 memstate = Unknown; 697 memstate = Unknown;
700 QMessageBox::critical( 0 , "Memory Status", 698 QMessageBox::critical( 0 , "Memory Status",
701 "The memory is very low. \n" 699 "The memory is very low. \n"
702 "Please end this application \n" 700 "Please end this application \n"
703 "immediately." ); 701 "immediately." );
704 recoverMemory(); 702 recoverMemory();
705 } 703 }
706 existingMessage = FALSE; 704 existingMessage = FALSE;
707#endif 705#endif
708} 706}
709 707
710static bool isVisibleWindow( int wid ) 708static bool isVisibleWindow( int wid )
711{ 709{
710#ifdef QWS
712 const QList<QWSWindow> &list = qwsServer->clientWindows(); 711 const QList<QWSWindow> &list = qwsServer->clientWindows();
713 QWSWindow* w; 712 QWSWindow* w;
714 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { 713 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) {
715 if ( w->winId() == wid ) 714 if ( w->winId() == wid )
716 return !w->isFullyObscured(); 715 return !w->isFullyObscured();
717 } 716 }
717#endif
718 return FALSE; 718 return FALSE;
719} 719}
720 720
721static bool hasVisibleWindow( const QString& clientname ) 721static bool hasVisibleWindow( const QString& clientname )
722{ 722{
723#ifdef QWS
723 const QList<QWSWindow> &list = qwsServer->clientWindows(); 724 const QList<QWSWindow> &list = qwsServer->clientWindows();
724 QWSWindow* w; 725 QWSWindow* w;
725 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { 726 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) {
726 if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) 727 if ( w->client() ->identity() == clientname && !w->isFullyObscured() )
727 return TRUE; 728 return TRUE;
728 } 729 }
730#endif
729 return FALSE; 731 return FALSE;
730} 732}
731 733
732void Desktop::raiseLauncher() 734void Desktop::raiseLauncher()
733{ 735{
734 Config cfg( "qpe" ); //F12 'Home' 736 Config cfg( "qpe" ); //F12 'Home'
735 cfg.setGroup( "AppsKey" ); 737 cfg.setGroup( "AppsKey" );
736 QString tempItem; 738 QString tempItem;
737 tempItem = cfg.readEntry( "Middle", "Home" ); 739 tempItem = cfg.readEntry( "Middle", "Home" );
738 if ( tempItem == "Home" || tempItem.isEmpty() ) { 740 if ( tempItem == "Home" || tempItem.isEmpty() ) {
739 home ( ); 741 home ( );
740 } 742 }
741 else { 743 else {
742 QCopEnvelope e( "QPE/System", "execute(QString)" ); 744 QCopEnvelope e( "QPE/System", "execute(QString)" );
743 e << tempItem; 745 e << tempItem;
744 } 746 }
745} 747}
746 748
747void Desktop::home ( ) 749void Desktop::home ( )
748{ 750{
749 if ( isVisibleWindow( launcher->winId() ) ) 751 if ( isVisibleWindow( launcher->winId() ) )
750 launcher->nextView(); 752 launcher->nextView();
751 else 753 else
752 launcher->raise(); 754 launcher->raise();
753} 755}
754 756
755void Desktop::executeOrModify( const QString& appLnkFile ) 757void Desktop::executeOrModify( const QString& appLnkFile )
756{ 758{
757 AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); 759 AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile );
758 if ( lnk.isValid() ) { 760 if ( lnk.isValid() ) {
759 QCString app = lnk.exec().utf8(); 761 QCString app = lnk.exec().utf8();
760 Global::terminateBuiltin( "calibrate" ); 762 Global::terminateBuiltin( "calibrate" );
761 if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { 763 if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) {
762 // MRUList::addTask( &lnk ); 764 // MRUList::addTask( &lnk );
763 if ( hasVisibleWindow( app ) ) 765 if ( hasVisibleWindow( app ) )
764 QCopChannel::send( "QPE/Application/" + app, "nextView()" ); 766 QCopChannel::send( "QPE/Application/" + app, "nextView()" );
765 else 767 else
766 QCopChannel::send( "QPE/Application/" + app, "raise()" ); 768 QCopChannel::send( "QPE/Application/" + app, "raise()" );
767 } 769 }
768 else { 770 else {
769 lnk.execute(); 771 lnk.execute();
770 } 772 }
771 } 773 }
772} 774}
773 775
774void Desktop::raiseDatebook() 776void Desktop::raiseDatebook()
775{ 777{
776 Config cfg( "qpe" ); //F9 'Activity' 778 Config cfg( "qpe" ); //F9 'Activity'
777 cfg.setGroup( "AppsKey" ); 779 cfg.setGroup( "AppsKey" );
778 QString tempItem; 780 QString tempItem;
779 tempItem = cfg.readEntry( "LeftEnd" , "Calendar" ); 781 tempItem = cfg.readEntry( "LeftEnd" , "Calendar" );
780 if ( tempItem == "Calendar" || tempItem.isEmpty() ) { 782 if ( tempItem == "Calendar" || tempItem.isEmpty() ) {
781 tempItem = "datebook"; 783 tempItem = "datebook";
782 } 784 }
783 QCopEnvelope e( "QPE/System", "execute(QString)" ); 785 QCopEnvelope e( "QPE/System", "execute(QString)" );
784 e << tempItem; 786 e << tempItem;
785} 787}
786 788
787void Desktop::raiseContacts() 789void Desktop::raiseContacts()
788{ 790{
789 Config cfg( "qpe" ); //F10, 'Contacts' 791 Config cfg( "qpe" ); //F10, 'Contacts'
790 cfg.setGroup( "AppsKey" ); 792 cfg.setGroup( "AppsKey" );
791 QString tempItem; 793 QString tempItem;
792 tempItem = cfg.readEntry( "Left2nd", "Address Book" ); 794 tempItem = cfg.readEntry( "Left2nd", "Address Book" );
793 if ( tempItem == "Address Book" || tempItem.isEmpty() ) { 795 if ( tempItem == "Address Book" || tempItem.isEmpty() ) {
794 tempItem = "addressbook"; 796 tempItem = "addressbook";
795 } 797 }
796 QCopEnvelope e( "QPE/System", "execute(QString)" ); 798 QCopEnvelope e( "QPE/System", "execute(QString)" );
797 e << tempItem; 799 e << tempItem;
798} 800}
799 801
800void Desktop::raiseMenu() 802void Desktop::raiseMenu()
801{ 803{
802 Config cfg( "qpe" ); //F11, 'Menu 804 Config cfg( "qpe" ); //F11, 'Menu
803 cfg.setGroup( "AppsKey" ); 805 cfg.setGroup( "AppsKey" );
804 QString tempItem; 806 QString tempItem;
805 tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" ); 807 tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" );
806 if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) { 808 if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) {
807 Global::terminateBuiltin( "calibrate" ); 809 Global::terminateBuiltin( "calibrate" );
808 tb->startMenu() ->launch(); 810 tb->startMenu() ->launch();
809 } 811 }
810 else { 812 else {
811 QCopEnvelope e( "QPE/System", "execute(QString)" ); 813 QCopEnvelope e( "QPE/System", "execute(QString)" );
812 e << tempItem; 814 e << tempItem;
813 } 815 }
814} 816}
815 817
816void Desktop::raiseEmail() 818void Desktop::raiseEmail()
817{ 819{
818 Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11 820 Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11
819 cfg.setGroup( "AppsKey" ); 821 cfg.setGroup( "AppsKey" );
820 QString tempItem; 822 QString tempItem;
821 tempItem = cfg.readEntry( "RightEnd", "Mail" ); 823 tempItem = cfg.readEntry( "RightEnd", "Mail" );
822 if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) { 824 if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) {
823 tempItem = "mail"; 825 tempItem = "mail";
824 } 826 }
825 QCopEnvelope e( "QPE/System", "execute(QString)" ); 827 QCopEnvelope e( "QPE/System", "execute(QString)" );
826 e << tempItem; 828 e << tempItem;
827} 829}
828 830
829// autoStarts apps on resume and start 831// autoStarts apps on resume and start
830void Desktop::execAutoStart() 832void Desktop::execAutoStart()
831{ 833{
832 QString appName; 834 QString appName;
833 int delay; 835 int delay;
834 QDateTime now = QDateTime::currentDateTime(); 836 QDateTime now = QDateTime::currentDateTime();
835 Config cfg( "autostart" ); 837 Config cfg( "autostart" );
836 cfg.setGroup( "AutoStart" ); 838 cfg.setGroup( "AutoStart" );
837 appName = cfg.readEntry( "Apps", "" ); 839 appName = cfg.readEntry( "Apps", "" );
838 delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); 840 delay = ( cfg.readEntry( "Delay", "0" ) ).toInt();
839 // If the time between suspend and resume was longer then the 841 // If the time between suspend and resume was longer then the
840 // value saved as delay, start the app 842 // value saved as delay, start the app
841 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { 843 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) {
842 QCopEnvelope e( "QPE/System", "execute(QString)" ); 844 QCopEnvelope e( "QPE/System", "execute(QString)" );
843 e << QString( appName ); 845 e << QString( appName );
844 } 846 }
845} 847}
846 848
847#if defined(QPE_HAVE_TOGGLELIGHT) 849#if defined(QPE_HAVE_TOGGLELIGHT)
848#include <qpe/config.h> 850#include <qpe/config.h>
849 851
850#include <sys/ioctl.h> 852#include <sys/ioctl.h>
851#include <sys/types.h> 853#include <sys/types.h>
852#include <fcntl.h> 854#include <fcntl.h>
853#include <unistd.h> 855#include <unistd.h>
854#include <errno.h> 856#include <errno.h>
855#include <linux/ioctl.h> 857#include <linux/ioctl.h>
856#include <time.h> 858#include <time.h>
857#endif 859#endif
858 860
859 861
860void Desktop::togglePower() 862void Desktop::togglePower()
861{ 863{
862 static bool excllock = false; 864 static bool excllock = false;
863 865
864 qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 ); 866 qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 );
865 867
866 if ( excllock ) 868 if ( excllock )
867 return; 869 return;
868 870
869 excllock = true; 871 excllock = true;
870 872
871 bool wasloggedin = loggedin; 873 bool wasloggedin = loggedin;
872 loggedin = 0; 874 loggedin = 0;
873 suspendTime = QDateTime::currentDateTime(); 875 suspendTime = QDateTime::currentDateTime();
874 876
875#ifdef QWS 877#ifdef QWS
876 if ( Password::needToAuthenticate ( true ) && qt_screen ) { 878 if ( Password::needToAuthenticate ( true ) && qt_screen ) {
877 // Should use a big black window instead. 879 // Should use a big black window instead.
878 // But this would not show up fast enough 880 // But this would not show up fast enough
879 QGfx *g = qt_screen-> screenGfx ( ); 881 QGfx *g = qt_screen-> screenGfx ( );
880 g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); 882 g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( ));
881 delete g; 883 delete g;
882 } 884 }
883#endif 885#endif
884 886
885 ODevice::inst ( )-> suspend ( ); 887 ODevice::inst ( )-> suspend ( );
886 888
887 DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call 889 DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call
888 QWSServer::screenSaverActivate ( false ); 890 QWSServer::screenSaverActivate ( false );
889 891
890 { 892 {
891 QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep 893 QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep
892 } 894 }
893 895
894 if ( wasloggedin ) 896 if ( wasloggedin )
895 login ( true ); 897 login ( true );
896 898
897 execAutoStart(); 899 execAutoStart();
898 //qcopBridge->closeOpenConnections(); 900 //qcopBridge->closeOpenConnections();
899 901
900 excllock = false; 902 excllock = false;
901} 903}
902 904
903void Desktop::toggleLight() 905void Desktop::toggleLight()
904{ 906{
905 QCopEnvelope e( "QPE/System", "setBacklight(int)" ); 907 QCopEnvelope e( "QPE/System", "setBacklight(int)" );
906 e << -2; // toggle 908 e << -2; // toggle
907} 909}
908 910
909void Desktop::toggleSymbolInput() 911void Desktop::toggleSymbolInput()
910{ 912{
911 tb->toggleSymbolInput(); 913 tb->toggleSymbolInput();
912} 914}
913 915
914void Desktop::toggleNumLockState() 916void Desktop::toggleNumLockState()
915{ 917{
916 tb->toggleNumLockState(); 918 tb->toggleNumLockState();
917} 919}
918 920
919void Desktop::toggleCapsLockState() 921void Desktop::toggleCapsLockState()
920{ 922{
921 tb->toggleCapsLockState(); 923 tb->toggleCapsLockState();
922} 924}
923 925
924void Desktop::styleChange( QStyle &s ) 926void Desktop::styleChange( QStyle &s )
925{ 927{
926 QWidget::styleChange( s ); 928 QWidget::styleChange( s );
927 int displayw = qApp->desktop() ->width(); 929 int displayw = qApp->desktop() ->width();
928 int displayh = qApp->desktop() ->height(); 930 int displayh = qApp->desktop() ->height();
929 931
930 QSize sz = tb->sizeHint(); 932 QSize sz = tb->sizeHint();
931 933
932 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); 934 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() );
933} 935}
934 936
935void DesktopApplication::shutdown() 937void DesktopApplication::shutdown()
936{ 938{
937 if ( type() != GuiServer ) 939 if ( type() != GuiServer )
938 return ; 940 return ;
939 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 941 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
940 connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), 942 connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ),
941 this, SLOT( shutdown( ShutdownImpl::Type ) ) ); 943 this, SLOT( shutdown( ShutdownImpl::Type ) ) );
942 sd->showMaximized(); 944 sd->showMaximized();
943} 945}
944 946
945void DesktopApplication::shutdown( ShutdownImpl::Type t ) 947void DesktopApplication::shutdown( ShutdownImpl::Type t )
946{ 948{
947 switch ( t ) { 949 switch ( t ) {
948 case ShutdownImpl::ShutdownSystem: 950 case ShutdownImpl::ShutdownSystem:
949 execlp( "shutdown", "shutdown", "-h", "now", ( void* ) 0 ); 951 execlp( "shutdown", "shutdown", "-h", "now", ( void* ) 0 );
950 break; 952 break;
951 case ShutdownImpl::RebootSystem: 953 case ShutdownImpl::RebootSystem:
952 execlp( "shutdown", "shutdown", "-r", "now", ( void* ) 0 ); 954 execlp( "shutdown", "shutdown", "-r", "now", ( void* ) 0 );
953 break; 955 break;
954 case ShutdownImpl::RestartDesktop: 956 case ShutdownImpl::RestartDesktop:
955 restart(); 957 restart();
956 break; 958 break;
957 case ShutdownImpl::TerminateDesktop: 959 case ShutdownImpl::TerminateDesktop:
958 prepareForTermination( FALSE ); 960 prepareForTermination( FALSE );
959 961
960 // This is a workaround for a Qt bug 962 // This is a workaround for a Qt bug
961 // clipboard applet has to stop its poll timer, or Qt/E 963 // clipboard applet has to stop its poll timer, or Qt/E
962 // will hang on quit() right before it emits aboutToQuit() 964 // will hang on quit() right before it emits aboutToQuit()
963 emit aboutToQuit ( ); 965 emit aboutToQuit ( );
964 966
965 quit(); 967 quit();
966 break; 968 break;
967 } 969 }
968} 970}
969 971
970void DesktopApplication::restart() 972void DesktopApplication::restart()
971{ 973{
972 prepareForTermination( TRUE ); 974 prepareForTermination( TRUE );
973 975
974#ifdef Q_WS_QWS 976#ifdef Q_WS_QWS
975 977
976 for ( int fd = 3; fd < 100; fd++ ) 978 for ( int fd = 3; fd < 100; fd++ )
977 close( fd ); 979 close( fd );
978#if defined(QT_DEMO_SINGLE_FLOPPY) 980#if defined(QT_DEMO_SINGLE_FLOPPY)
979 981
980 execl( "/sbin/init", "qpe", 0 ); 982 execl( "/sbin/init", "qpe", 0 );
981#elif defined(QT_QWS_CASSIOPEIA) 983#elif defined(QT_QWS_CASSIOPEIA)
982 984
983 execl( "/bin/sh", "sh", 0 ); 985 execl( "/bin/sh", "sh", 0 );
984#else 986#else
985 987
986 execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); 988 execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 );
987#endif 989#endif
988 990
989 exit( 1 ); 991 exit( 1 );
990#endif 992#endif
991} 993}
992 994
993void Desktop::startTransferServer() 995void Desktop::startTransferServer()
994{ 996{
995 // start qcop bridge server 997 // start qcop bridge server
996 qcopBridge = new QCopBridge( 4243 ); 998 qcopBridge = new QCopBridge( 4243 );
997 if ( !qcopBridge->ok() ) { 999 if ( !qcopBridge->ok() ) {
998 delete qcopBridge; 1000 delete qcopBridge;
999 qcopBridge = 0; 1001 qcopBridge = 0;
1000 } 1002 }
1001 // start transfer server 1003 // start transfer server
1002 transferServer = new TransferServer( 4242 ); 1004 transferServer = new TransferServer( 4242 );
1003 if ( !transferServer->ok() ) { 1005 if ( !transferServer->ok() ) {
1004 delete transferServer; 1006 delete transferServer;
1005 transferServer = 0; 1007 transferServer = 0;
1006 } 1008 }
1007 if ( !transferServer || !qcopBridge ) 1009 if ( !transferServer || !qcopBridge )
1008 startTimer( 2000 ); 1010 startTimer( 2000 );
1009} 1011}
1010 1012
1011void Desktop::timerEvent( QTimerEvent *e ) 1013void Desktop::timerEvent( QTimerEvent *e )
1012{ 1014{
1013 killTimer( e->timerId() ); 1015 killTimer( e->timerId() );
1014 startTransferServer(); 1016 startTransferServer();
1015} 1017}
1016 1018
1017void Desktop::terminateServers() 1019void Desktop::terminateServers()
1018{ 1020{
1019 delete transferServer; 1021 delete transferServer;
1020 delete qcopBridge; 1022 delete qcopBridge;
1021 transferServer = 0; 1023 transferServer = 0;
1022 qcopBridge = 0; 1024 qcopBridge = 0;
1023} 1025}
1024 1026
1025void Desktop::rereadVolumes() 1027void Desktop::rereadVolumes()
1026{ 1028{
1027 Config cfg( "qpe" ); 1029 Config cfg( "qpe" );
1028 cfg.setGroup( "Volume" ); 1030 cfg.setGroup( "Volume" );
1029 touchclick = cfg.readBoolEntry( "TouchSound" ); 1031 touchclick = cfg.readBoolEntry( "TouchSound" );
1030 keyclick = cfg.readBoolEntry( "KeySound" ); 1032 keyclick = cfg.readBoolEntry( "KeySound" );
1031 alarmsound = cfg.readBoolEntry( "AlarmSound" ); 1033 alarmsound = cfg.readBoolEntry( "AlarmSound" );
1032} 1034}
1033 1035
1034void Desktop::keyClick() 1036void Desktop::keyClick()
1035{ 1037{
1036 if ( keyclick ) 1038 if ( keyclick )
1037 ODevice::inst ( ) -> keySound ( ); 1039 ODevice::inst ( ) -> keySound ( );
1038} 1040}
1039 1041
1040void Desktop::screenClick() 1042void Desktop::screenClick()
1041{ 1043{
1042 if ( touchclick ) 1044 if ( touchclick )
1043 ODevice::inst ( ) -> touchSound ( ); 1045 ODevice::inst ( ) -> touchSound ( );
1044} 1046}
1045 1047
1046void Desktop::soundAlarm() 1048void Desktop::soundAlarm()
1047{ 1049{
1048 if ( qpedesktop-> alarmsound ) 1050 if ( qpedesktop-> alarmsound )
1049 ODevice::inst ( ) -> alarmSound ( ); 1051 ODevice::inst ( ) -> alarmSound ( );
1050} 1052}
1051 1053
diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp
index 66cc3e6..a5955a4 100644
--- a/core/launcher/launcher.cpp
+++ b/core/launcher/launcher.cpp
@@ -1,795 +1,793 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT 21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT
22// have this class. 22// have this class.
23#define QTOPIA_INTERNAL_FSLP 23#define QTOPIA_INTERNAL_FSLP
24 24
25#ifdef QWS
26#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
27#endif
28#include <qpe/resource.h> 26#include <qpe/resource.h>
29#include <qpe/applnk.h> 27#include <qpe/applnk.h>
30#include <qpe/config.h> 28#include <qpe/config.h>
31#include <qpe/global.h> 29#include <qpe/global.h>
32#include <qpe/qpeapplication.h> 30#include <qpe/qpeapplication.h>
33#include <qpe/mimetype.h> 31#include <qpe/mimetype.h>
34#include <qpe/storage.h> 32#include <qpe/storage.h>
35#include <qpe/palmtoprecord.h> 33#include <qpe/palmtoprecord.h>
36 34
37#include <qpe/version.h> 35#include <qpe/version.h>
38 36
39#include <qdir.h> 37#include <qdir.h>
40#ifdef QWS 38#ifdef QWS
41#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
42#endif 40#endif
43#include <qtimer.h> 41#include <qtimer.h>
44#include <qcombobox.h> 42#include <qcombobox.h>
45#include <qvbox.h> 43#include <qvbox.h>
46#include <qlayout.h> 44#include <qlayout.h>
47#include <qstyle.h> 45#include <qstyle.h>
48#include <qpushbutton.h> 46#include <qpushbutton.h>
49#include <qtabbar.h> 47#include <qtabbar.h>
50#include <qwidgetstack.h> 48#include <qwidgetstack.h>
51#include <qlayout.h> 49#include <qlayout.h>
52#include <qregexp.h> 50#include <qregexp.h>
53#include <qmessagebox.h> 51#include <qmessagebox.h>
54#include <qframe.h> 52#include <qframe.h>
55#include <qpainter.h> 53#include <qpainter.h>
56#include <qlabel.h> 54#include <qlabel.h>
57#include <qtextstream.h> 55#include <qtextstream.h>
58#include <qpopupmenu.h> 56#include <qpopupmenu.h>
59 57
60#include "launcherview.h" 58#include "launcherview.h"
61#include "launcher.h" 59#include "launcher.h"
62#include "syncdialog.h" 60#include "syncdialog.h"
63#include "desktop.h" 61#include "desktop.h"
64#include <qpe/lnkproperties.h> 62#include <qpe/lnkproperties.h>
65//#include "mrulist.h" 63//#include "mrulist.h"
66#include "qrsync.h" 64#include "qrsync.h"
67#include <stdlib.h> 65#include <stdlib.h>
68#include <unistd.h> 66#include <unistd.h>
69 67
70#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 68#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
71#include <stdio.h> 69#include <stdio.h>
72#include <sys/vfs.h> 70#include <sys/vfs.h>
73#include <mntent.h> 71#include <mntent.h>
74#endif 72#endif
75 73
76#include <qpe/storage.h> 74#include <qpe/storage.h>
77#include "mediummountgui.h" 75#include "mediummountgui.h"
78 76
79namespace { 77namespace {
80 QStringList configToMime( Config *cfg ){ 78 QStringList configToMime( Config *cfg ){
81 QStringList mimes; 79 QStringList mimes;
82 bool tmpMime = true; 80 bool tmpMime = true;
83 cfg->setGroup("mimetypes" ); 81 cfg->setGroup("mimetypes" );
84 tmpMime = cfg->readBoolEntry("all" ,true); 82 tmpMime = cfg->readBoolEntry("all" ,true);
85 if( tmpMime ){ 83 if( tmpMime ){
86 mimes << QString::null; 84 mimes << QString::null;
87 return mimes; 85 return mimes;
88 }else{ 86 }else{
89 tmpMime = cfg->readBoolEntry("audio", true ); 87 tmpMime = cfg->readBoolEntry("audio", true );
90 if(tmpMime ) 88 if(tmpMime )
91 mimes.append("audio/*" ); 89 mimes.append("audio/*" );
92 90
93 tmpMime = cfg->readBoolEntry("image", true ); 91 tmpMime = cfg->readBoolEntry("image", true );
94 if(tmpMime ) 92 if(tmpMime )
95 mimes.append("image/*" ); 93 mimes.append("image/*" );
96 94
97 tmpMime = cfg->readBoolEntry("text", true ); 95 tmpMime = cfg->readBoolEntry("text", true );
98 if(tmpMime ) 96 if(tmpMime )
99 mimes.append("text/*"); 97 mimes.append("text/*");
100 98
101 tmpMime = cfg->readBoolEntry("video", true ); 99 tmpMime = cfg->readBoolEntry("video", true );
102 if(tmpMime ) 100 if(tmpMime )
103 mimes.append("video/*" ); 101 mimes.append("video/*" );
104 } 102 }
105 return mimes; 103 return mimes;
106 } 104 }
107 105
108} 106}
109 107
110 108
111 109
112//#define SHOW_ALL 110//#define SHOW_ALL
113 111
114class CategoryTab : public QTab 112class CategoryTab : public QTab
115{ 113{
116public: 114public:
117 CategoryTab( const QIconSet &icon, const QString &text=QString::null ) 115 CategoryTab( const QIconSet &icon, const QString &text=QString::null )
118 : QTab( icon, text ) 116 : QTab( icon, text )
119 { 117 {
120 } 118 }
121 119
122 QColor bgColor; 120 QColor bgColor;
123 QColor fgColor; 121 QColor fgColor;
124}; 122};
125 123
126//=========================================================================== 124//===========================================================================
127 125
128CategoryTabWidget::CategoryTabWidget( QWidget* parent ) : 126CategoryTabWidget::CategoryTabWidget( QWidget* parent ) :
129 QVBox( parent ) 127 QVBox( parent )
130{ 128{
131 categoryBar = 0; 129 categoryBar = 0;
132 stack = 0; 130 stack = 0;
133} 131}
134 132
135void CategoryTabWidget::prevTab() 133void CategoryTabWidget::prevTab()
136{ 134{
137 if ( categoryBar ) { 135 if ( categoryBar ) {
138 int n = categoryBar->count(); 136 int n = categoryBar->count();
139 int tab = categoryBar->currentTab(); 137 int tab = categoryBar->currentTab();
140 if ( tab >= 0 ) 138 if ( tab >= 0 )
141 categoryBar->setCurrentTab( (tab - 1 + n)%n ); 139 categoryBar->setCurrentTab( (tab - 1 + n)%n );
142 } 140 }
143} 141}
144 142
145void CategoryTabWidget::nextTab() 143void CategoryTabWidget::nextTab()
146{ 144{
147 if ( categoryBar ) { 145 if ( categoryBar ) {
148 int n = categoryBar->count(); 146 int n = categoryBar->count();
149 int tab = categoryBar->currentTab(); 147 int tab = categoryBar->currentTab();
150 categoryBar->setCurrentTab( (tab + 1)%n ); 148 categoryBar->setCurrentTab( (tab + 1)%n );
151 } 149 }
152} 150}
153 151
154void CategoryTabWidget::addItem( const QString& linkfile ) 152void CategoryTabWidget::addItem( const QString& linkfile )
155{ 153{
156 int i=0; 154 int i=0;
157 AppLnk *app = new AppLnk(linkfile); 155 AppLnk *app = new AppLnk(linkfile);
158 if ( !app->isValid() ) { 156 if ( !app->isValid() ) {
159 delete app; 157 delete app;
160 app=0; 158 app=0;
161 } 159 }
162 if ( !app || !app->file().isEmpty() ) { 160 if ( !app || !app->file().isEmpty() ) {
163 // A document 161 // A document
164 delete app; 162 delete app;
165 app = new DocLnk(linkfile); 163 app = new DocLnk(linkfile);
166 if ( app->fileKnown() ) { 164 if ( app->fileKnown() ) {
167 ((LauncherView*)(stack->widget(ids.count()-1)))->addItem(app); 165 ((LauncherView*)(stack->widget(ids.count()-1)))->addItem(app);
168 } else { 166 } else {
169 ((LauncherView*)(stack->widget(ids.count()-1)))->sort(); 167 ((LauncherView*)(stack->widget(ids.count()-1)))->sort();
170 delete app; 168 delete app;
171 } 169 }
172 return; 170 return;
173 } 171 }
174 // An application 172 // An application
175 for ( QStringList::Iterator it=ids.begin(); it!=ids.end(); ++it) { 173 for ( QStringList::Iterator it=ids.begin(); it!=ids.end(); ++it) {
176 if ( !(*it).isEmpty() ) { 174 if ( !(*it).isEmpty() ) {
177 QRegExp tf(*it,FALSE,TRUE); 175 QRegExp tf(*it,FALSE,TRUE);
178 if ( tf.match(app->type()) >= 0 ) { 176 if ( tf.match(app->type()) >= 0 ) {
179 ((LauncherView*)stack->widget(i))->addItem(app); 177 ((LauncherView*)stack->widget(i))->addItem(app);
180 return; 178 return;
181 } 179 }
182 i++; 180 i++;
183 } 181 }
184 } 182 }
185 183
186 QCopEnvelope e("QPE/TaskBar","reloadApps()"); 184 QCopEnvelope e("QPE/TaskBar","reloadApps()");
187} 185}
188 186
189void CategoryTabWidget::initializeCategories(AppLnkSet* rootFolder, 187void CategoryTabWidget::initializeCategories(AppLnkSet* rootFolder,
190 AppLnkSet* docFolder, const QList<FileSystem> &fs) 188 AppLnkSet* docFolder, const QList<FileSystem> &fs)
191{ 189{
192 delete categoryBar; 190 delete categoryBar;
193 categoryBar = new CategoryTabBar( this ); 191 categoryBar = new CategoryTabBar( this );
194 QPalette pal = categoryBar->palette(); 192 QPalette pal = categoryBar->palette();
195 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); 193 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
196 pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); 194 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
197 categoryBar->setPalette( pal ); 195 categoryBar->setPalette( pal );
198 196
199 delete stack; 197 delete stack;
200 stack = new QWidgetStack(this); 198 stack = new QWidgetStack(this);
201 tabs=0; 199 tabs=0;
202 200
203 ids.clear(); 201 ids.clear();
204 202
205 Config cfg("Launcher"); 203 Config cfg("Launcher");
206 204
207 QStringList types = rootFolder->types(); 205 QStringList types = rootFolder->types();
208 for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) { 206 for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) {
209 if ( !(*it).isEmpty() ) { 207 if ( !(*it).isEmpty() ) {
210 (void)newView(*it,rootFolder->typePixmap(*it),rootFolder->typeName(*it)); 208 (void)newView(*it,rootFolder->typePixmap(*it),rootFolder->typeName(*it));
211 setTabAppearance( *it, cfg ); 209 setTabAppearance( *it, cfg );
212 } 210 }
213 } 211 }
214 QListIterator<AppLnk> it( rootFolder->children() ); 212 QListIterator<AppLnk> it( rootFolder->children() );
215 AppLnk* l; 213 AppLnk* l;
216 while ( (l=it.current()) ) { 214 while ( (l=it.current()) ) {
217 if ( l->type() == "Separator" ) { // No tr 215 if ( l->type() == "Separator" ) { // No tr
218 rootFolder->remove(l); 216 rootFolder->remove(l);
219 delete l; 217 delete l;
220 } else { 218 } else {
221 int i=0; 219 int i=0;
222 for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) { 220 for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) {
223 if ( *it == l->type() ) 221 if ( *it == l->type() )
224 ((LauncherView*)stack->widget(i))->addItem(l,FALSE); 222 ((LauncherView*)stack->widget(i))->addItem(l,FALSE);
225 i++; 223 i++;
226 } 224 }
227 } 225 }
228 ++it; 226 ++it;
229 } 227 }
230 rootFolder->detachChildren(); 228 rootFolder->detachChildren();
231 for (int i=0; i<tabs; i++) 229 for (int i=0; i<tabs; i++)
232 ((LauncherView*)stack->widget(i))->sort(); 230 ((LauncherView*)stack->widget(i))->sort();
233 231
234 // all documents 232 // all documents
235 QImage img( Resource::loadImage( "DocsIcon" ) ); 233 QImage img( Resource::loadImage( "DocsIcon" ) );
236 QPixmap pm; 234 QPixmap pm;
237 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 235 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
238 docview = newView( "Documents", // No tr 236 docview = newView( "Documents", // No tr
239 pm, tr("Documents")); 237 pm, tr("Documents"));
240 docview->populate( docFolder, QString::null ); 238 docview->populate( docFolder, QString::null );
241 docFolder->detachChildren(); 239 docFolder->detachChildren();
242 docview->setFileSystems(fs); 240 docview->setFileSystems(fs);
243 docview->setToolsEnabled(TRUE); 241 docview->setToolsEnabled(TRUE);
244 setTabAppearance( "Documents", cfg ); // No tr 242 setTabAppearance( "Documents", cfg ); // No tr
245 243
246 connect( categoryBar, SIGNAL(selected(int)), stack, SLOT(raiseWidget(int)) ); 244 connect( categoryBar, SIGNAL(selected(int)), stack, SLOT(raiseWidget(int)) );
247 245
248 ((LauncherView*)stack->widget(0))->setFocus(); 246 ((LauncherView*)stack->widget(0))->setFocus();
249 247
250 cfg. setGroup ( "GUI" ); 248 cfg. setGroup ( "GUI" );
251 setBusyIndicatorType ( cfg. readEntry ( "BusyType", QString::null )); 249 setBusyIndicatorType ( cfg. readEntry ( "BusyType", QString::null ));
252 250
253 categoryBar->show(); 251 categoryBar->show();
254 stack->show(); 252 stack->show();
255} 253}
256 254
257void CategoryTabWidget::setTabAppearance( const QString &id, Config &cfg ) 255void CategoryTabWidget::setTabAppearance( const QString &id, Config &cfg )
258{ 256{
259 QString grp( "Tab %1" ); // No tr 257 QString grp( "Tab %1" ); // No tr
260 cfg.setGroup( grp.arg(id) ); 258 cfg.setGroup( grp.arg(id) );
261 LauncherView *v = view( id ); 259 LauncherView *v = view( id );
262 int idx = ids.findIndex( id ); 260 int idx = ids.findIndex( id );
263 CategoryTab *tab = (CategoryTab *)categoryBar->tab( idx ); 261 CategoryTab *tab = (CategoryTab *)categoryBar->tab( idx );
264 262
265 // View 263 // View
266 QString view = cfg.readEntry( "View", "Icon" ); 264 QString view = cfg.readEntry( "View", "Icon" );
267 if ( view == "List" ) // No tr 265 if ( view == "List" ) // No tr
268 v->setViewMode( LauncherView::List ); 266 v->setViewMode( LauncherView::List );
269 QString bgType = cfg.readEntry( "BackgroundType", "Image" ); 267 QString bgType = cfg.readEntry( "BackgroundType", "Image" );
270 if ( bgType == "Image" ) { // No tr 268 if ( bgType == "Image" ) { // No tr
271 QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" ); 269 QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" );
272 v->setBackgroundType( LauncherView::Image, pm ); 270 v->setBackgroundType( LauncherView::Image, pm );
273 } else if ( bgType == "SolidColor" ) { 271 } else if ( bgType == "SolidColor" ) {
274 QString c = cfg.readEntry( "BackgroundColor" ); 272 QString c = cfg.readEntry( "BackgroundColor" );
275 v->setBackgroundType( LauncherView::SolidColor, c ); 273 v->setBackgroundType( LauncherView::SolidColor, c );
276 } 274 }
277 QString textCol = cfg.readEntry( "TextColor" ); 275 QString textCol = cfg.readEntry( "TextColor" );
278 if ( textCol.isEmpty() ) 276 if ( textCol.isEmpty() )
279 v->setTextColor( QColor() ); 277 v->setTextColor( QColor() );
280 else 278 else
281 v->setTextColor( QColor(textCol) ); 279 v->setTextColor( QColor(textCol) );
282 QStringList font = cfg.readListEntry( "Font", ',' ); 280 QStringList font = cfg.readListEntry( "Font", ',' );
283 if ( font.count() == 4 ) 281 if ( font.count() == 4 )
284 v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) ); 282 v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) );
285 283
286 // Tabs 284 // Tabs
287 QString tabCol = cfg.readEntry( "TabColor" ); 285 QString tabCol = cfg.readEntry( "TabColor" );
288 if ( tabCol.isEmpty() ) 286 if ( tabCol.isEmpty() )
289 tab->bgColor = QColor(); 287 tab->bgColor = QColor();
290 else 288 else
291 tab->bgColor = QColor(tabCol); 289 tab->bgColor = QColor(tabCol);
292 QString tabTextCol = cfg.readEntry( "TabTextColor" ); 290 QString tabTextCol = cfg.readEntry( "TabTextColor" );
293 if ( tabTextCol.isEmpty() ) 291 if ( tabTextCol.isEmpty() )
294 tab->fgColor = QColor(); 292 tab->fgColor = QColor();
295 else 293 else
296 tab->fgColor = QColor(tabTextCol); 294 tab->fgColor = QColor(tabTextCol);
297} 295}
298 296
299void CategoryTabWidget::updateDocs(AppLnkSet* docFolder, const QList<FileSystem> &fs) 297void CategoryTabWidget::updateDocs(AppLnkSet* docFolder, const QList<FileSystem> &fs)
300{ 298{
301 docview->populate( docFolder, QString::null ); 299 docview->populate( docFolder, QString::null );
302 docFolder->detachChildren(); 300 docFolder->detachChildren();
303 docview->setFileSystems(fs); 301 docview->setFileSystems(fs);
304 docview->updateTools(); 302 docview->updateTools();
305} 303}
306 304
307void CategoryTabWidget::tabProperties() 305void CategoryTabWidget::tabProperties()
308{ 306{
309 LauncherView *view = (LauncherView*)stack->widget( categoryBar->currentTab() ); 307 LauncherView *view = (LauncherView*)stack->widget( categoryBar->currentTab() );
310 QPopupMenu *m = new QPopupMenu( this ); 308 QPopupMenu *m = new QPopupMenu( this );
311 m->insertItem( tr("Icon View"), LauncherView::Icon ); 309 m->insertItem( tr("Icon View"), LauncherView::Icon );
312 m->insertItem( tr("List View"), LauncherView::List ); 310 m->insertItem( tr("List View"), LauncherView::List );
313 m->setItemChecked( (int)view->viewMode(), TRUE ); 311 m->setItemChecked( (int)view->viewMode(), TRUE );
314 int rv = m->exec( QCursor::pos() ); 312 int rv = m->exec( QCursor::pos() );
315 if ( rv >= 0 && rv != view->viewMode() ) { 313 if ( rv >= 0 && rv != view->viewMode() ) {
316 view->setViewMode( (LauncherView::ViewMode)rv ); 314 view->setViewMode( (LauncherView::ViewMode)rv );
317 } 315 }
318 316
319 delete m; 317 delete m;
320} 318}
321 319
322QString CategoryTabWidget::getAllDocLinkInfo() const 320QString CategoryTabWidget::getAllDocLinkInfo() const
323{ 321{
324 return docview->getAllDocLinkInfo(); 322 return docview->getAllDocLinkInfo();
325} 323}
326 324
327LauncherView* CategoryTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label ) 325LauncherView* CategoryTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label )
328{ 326{
329 LauncherView* view = new LauncherView( stack ); 327 LauncherView* view = new LauncherView( stack );
330 connect( view, SIGNAL(clicked(const AppLnk*)), 328 connect( view, SIGNAL(clicked(const AppLnk*)),
331 this, SIGNAL(clicked(const AppLnk*))); 329 this, SIGNAL(clicked(const AppLnk*)));
332 connect( view, SIGNAL(rightPressed(AppLnk*)), 330 connect( view, SIGNAL(rightPressed(AppLnk*)),
333 this, SIGNAL(rightPressed(AppLnk*))); 331 this, SIGNAL(rightPressed(AppLnk*)));
334 ids.append(id); 332 ids.append(id);
335 categoryBar->addTab( new CategoryTab( pm, label ) ); 333 categoryBar->addTab( new CategoryTab( pm, label ) );
336 stack->addWidget( view, tabs++ ); 334 stack->addWidget( view, tabs++ );
337 return view; 335 return view;
338} 336}
339 337
340void CategoryTabWidget::updateLink(const QString& linkfile) 338void CategoryTabWidget::updateLink(const QString& linkfile)
341{ 339{
342 int i=0; 340 int i=0;
343 LauncherView* view; 341 LauncherView* view;
344 while ((view = (LauncherView*)stack->widget(i++))) { 342 while ((view = (LauncherView*)stack->widget(i++))) {
345 if ( view->removeLink(linkfile) ) 343 if ( view->removeLink(linkfile) )
346 break; 344 break;
347 } 345 }
348 addItem(linkfile); 346 addItem(linkfile);
349 docview->updateTools(); 347 docview->updateTools();
350} 348}
351 349
352void CategoryTabWidget::paletteChange( const QPalette &p ) 350void CategoryTabWidget::paletteChange( const QPalette &p )
353{ 351{
354 QVBox::paletteChange( p ); 352 QVBox::paletteChange( p );
355 QPalette pal = palette(); 353 QPalette pal = palette();
356 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); 354 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
357 pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); 355 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
358 categoryBar->setPalette( pal ); 356 categoryBar->setPalette( pal );
359 categoryBar->update(); 357 categoryBar->update();
360} 358}
361 359
362void CategoryTabWidget::setBusy(bool on) 360void CategoryTabWidget::setBusy(bool on)
363{ 361{
364 if ( on ) 362 if ( on )
365 ((LauncherView*)stack->visibleWidget())->setBusy(TRUE); 363 ((LauncherView*)stack->visibleWidget())->setBusy(TRUE);
366 else 364 else
367 for (int i=0; i<tabs; i++) 365 for (int i=0; i<tabs; i++)
368 ((LauncherView*)stack->widget(i))->setBusy(FALSE); 366 ((LauncherView*)stack->widget(i))->setBusy(FALSE);
369} 367}
370 368
371LauncherView *CategoryTabWidget::view( const QString &id ) 369LauncherView *CategoryTabWidget::view( const QString &id )
372{ 370{
373 int idx = ids.findIndex( id ); 371 int idx = ids.findIndex( id );
374 return (LauncherView *)stack->widget(idx); 372 return (LauncherView *)stack->widget(idx);
375} 373}
376 374
377void CategoryTabWidget::setBusyIndicatorType ( const QString &type ) 375void CategoryTabWidget::setBusyIndicatorType ( const QString &type )
378{ 376{
379 for ( QStringList::Iterator it = ids. begin ( ); it != ids. end ( ); ++it ) 377 for ( QStringList::Iterator it = ids. begin ( ); it != ids. end ( ); ++it )
380 view ( *it )-> setBusyIndicatorType ( type ); 378 view ( *it )-> setBusyIndicatorType ( type );
381} 379}
382 380
383//=========================================================================== 381//===========================================================================
384 382
385CategoryTabBar::CategoryTabBar( QWidget *parent, const char *name ) 383CategoryTabBar::CategoryTabBar( QWidget *parent, const char *name )
386 : QTabBar( parent, name ) 384 : QTabBar( parent, name )
387{ 385{
388 setFocusPolicy( NoFocus ); 386 setFocusPolicy( NoFocus );
389 connect( this, SIGNAL( selected(int) ), this, SLOT( layoutTabs() ) ); 387 connect( this, SIGNAL( selected(int) ), this, SLOT( layoutTabs() ) );
390} 388}
391 389
392CategoryTabBar::~CategoryTabBar() 390CategoryTabBar::~CategoryTabBar()
393{ 391{
394} 392}
395 393
396void CategoryTabBar::layoutTabs() 394void CategoryTabBar::layoutTabs()
397{ 395{
398 if ( !count() ) 396 if ( !count() )
399 return; 397 return;
400 398
401// int percentFalloffTable[] = { 100, 70, 40, 12, 6, 3, 1, 0 }; 399// int percentFalloffTable[] = { 100, 70, 40, 12, 6, 3, 1, 0 };
402 int available = width()-1; 400 int available = width()-1;
403 QFontMetrics fm = fontMetrics(); 401 QFontMetrics fm = fontMetrics();
404 int hiddenTabWidth = -7; 402 int hiddenTabWidth = -7;
405 int middleTab = currentTab(); 403 int middleTab = currentTab();
406 int hframe, vframe, overlap; 404 int hframe, vframe, overlap;
407 style().tabbarMetrics( this, hframe, vframe, overlap ); 405 style().tabbarMetrics( this, hframe, vframe, overlap );
408 int x = 0; 406 int x = 0;
409 QRect r; 407 QRect r;
410 QTab *t; 408 QTab *t;
411 int required = 0; 409 int required = 0;
412 int eventabwidth = (width()-1)/count(); 410 int eventabwidth = (width()-1)/count();
413 enum Mode { HideBackText, Pack, Even } mode=Even; 411 enum Mode { HideBackText, Pack, Even } mode=Even;
414 for ( int i = 0; i < count(); i++ ) { 412 for ( int i = 0; i < count(); i++ ) {
415 t = tab(i); 413 t = tab(i);
416 int iw = fm.width( t->text() ) + hframe - overlap; 414 int iw = fm.width( t->text() ) + hframe - overlap;
417 if ( i != middleTab ) { 415 if ( i != middleTab ) {
418 available -= hiddenTabWidth + hframe - overlap; 416 available -= hiddenTabWidth + hframe - overlap;
419 if ( t->iconSet() != 0 ) 417 if ( t->iconSet() != 0 )
420 available -= t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); 418 available -= t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
421 } 419 }
422 if ( t->iconSet() != 0 ) 420 if ( t->iconSet() != 0 )
423 iw += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); 421 iw += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
424 required += iw; 422 required += iw;
425 // As space gets tight, packed looks better than even. "10" must be at least 0. 423 // As space gets tight, packed looks better than even. "10" must be at least 0.
426 if ( iw >= eventabwidth-10 ) 424 if ( iw >= eventabwidth-10 )
427 mode = Pack; 425 mode = Pack;
428 } 426 }
429 if ( mode == Pack && required > width()-1 ) 427 if ( mode == Pack && required > width()-1 )
430 mode = HideBackText; 428 mode = HideBackText;
431 for ( int i = 0; i < count(); i++ ) { 429 for ( int i = 0; i < count(); i++ ) {
432 t = tab(i); 430 t = tab(i);
433 if ( mode != HideBackText ) { 431 if ( mode != HideBackText ) {
434 int w = fm.width( t->text() ); 432 int w = fm.width( t->text() );
435 int ih = 0; 433 int ih = 0;
436 if ( t->iconSet() != 0 ) { 434 if ( t->iconSet() != 0 ) {
437 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); 435 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
438 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); 436 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
439 } 437 }
440 int h = QMAX( fm.height(), ih ); 438 int h = QMAX( fm.height(), ih );
441 h = QMAX( h, QApplication::globalStrut().height() ); 439 h = QMAX( h, QApplication::globalStrut().height() );
442 440
443 h += vframe; 441 h += vframe;
444 w += hframe; 442 w += hframe;
445 443
446 QRect tr(x, 0, 444 QRect tr(x, 0,
447 mode == Even ? eventabwidth : w * (width()-1)/required, h); 445 mode == Even ? eventabwidth : w * (width()-1)/required, h);
448 t->setRect(tr); 446 t->setRect(tr);
449 x += tr.width() - overlap; 447 x += tr.width() - overlap;
450 r = r.unite(tr); 448 r = r.unite(tr);
451 } else if ( i != middleTab ) { 449 } else if ( i != middleTab ) {
452 int w = hiddenTabWidth; 450 int w = hiddenTabWidth;
453 int ih = 0; 451 int ih = 0;
454 if ( t->iconSet() != 0 ) { 452 if ( t->iconSet() != 0 ) {
455 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); 453 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
456 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); 454 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
457 } 455 }
458 int h = QMAX( fm.height(), ih ); 456 int h = QMAX( fm.height(), ih );
459 h = QMAX( h, QApplication::globalStrut().height() ); 457 h = QMAX( h, QApplication::globalStrut().height() );
460 458
461 h += vframe; 459 h += vframe;
462 w += hframe; 460 w += hframe;
463 461
464 t->setRect( QRect(x, 0, w, h) ); 462 t->setRect( QRect(x, 0, w, h) );
465 x += t->rect().width() - overlap; 463 x += t->rect().width() - overlap;
466 r = r.unite( t->rect() ); 464 r = r.unite( t->rect() );
467 } else { 465 } else {
468 int ih = 0; 466 int ih = 0;
469 if ( t->iconSet() != 0 ) { 467 if ( t->iconSet() != 0 ) {
470 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); 468 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
471 } 469 }
472 int h = QMAX( fm.height(), ih ); 470 int h = QMAX( fm.height(), ih );
473 h = QMAX( h, QApplication::globalStrut().height() ); 471 h = QMAX( h, QApplication::globalStrut().height() );
474 472
475 h += vframe; 473 h += vframe;
476 474
477 t->setRect( QRect(x, 0, available, h) ); 475 t->setRect( QRect(x, 0, available, h) );
478 x += t->rect().width() - overlap; 476 x += t->rect().width() - overlap;
479 r = r.unite( t->rect() ); 477 r = r.unite( t->rect() );
480 } 478 }
481 } 479 }
482 480
483 QRect rr = tab(count()-1)->rect(); 481 QRect rr = tab(count()-1)->rect();
484 rr.setRight(width()-1); 482 rr.setRight(width()-1);
485 tab(count()-1)->setRect( rr ); 483 tab(count()-1)->setRect( rr );
486 484
487 for ( t = tabList()->first(); t; t = tabList()->next() ) { 485 for ( t = tabList()->first(); t; t = tabList()->next() ) {
488 QRect tr = t->rect(); 486 QRect tr = t->rect();
489 tr.setHeight( r.height() ); 487 tr.setHeight( r.height() );
490 t->setRect( tr ); 488 t->setRect( tr );
491 } 489 }
492 490
493 update(); 491 update();
494} 492}
495 493
496 494
497void CategoryTabBar::paint( QPainter * p, QTab * t, bool selected ) const 495void CategoryTabBar::paint( QPainter * p, QTab * t, bool selected ) const
498{ 496{
499 CategoryTabBar *that = (CategoryTabBar *) this; 497 CategoryTabBar *that = (CategoryTabBar *) this;
500 CategoryTab *ct = (CategoryTab *)t; 498 CategoryTab *ct = (CategoryTab *)t;
501 QPalette pal = palette(); 499 QPalette pal = palette();
502 bool setPal = FALSE; 500 bool setPal = FALSE;
503 if ( ct->bgColor.isValid() ) { 501 if ( ct->bgColor.isValid() ) {
504 pal.setColor( QPalette::Active, QColorGroup::Background, ct->bgColor ); 502 pal.setColor( QPalette::Active, QColorGroup::Background, ct->bgColor );
505 pal.setColor( QPalette::Active, QColorGroup::Button, ct->bgColor ); 503 pal.setColor( QPalette::Active, QColorGroup::Button, ct->bgColor );
506 pal.setColor( QPalette::Inactive, QColorGroup::Background, ct->bgColor ); 504 pal.setColor( QPalette::Inactive, QColorGroup::Background, ct->bgColor );
507 pal.setColor( QPalette::Inactive, QColorGroup::Button, ct->bgColor ); 505 pal.setColor( QPalette::Inactive, QColorGroup::Button, ct->bgColor );
508 that->setUpdatesEnabled( FALSE ); 506 that->setUpdatesEnabled( FALSE );
509 that->setPalette( pal ); 507 that->setPalette( pal );
510 setPal = TRUE; 508 setPal = TRUE;
511 } 509 }
512#if QT_VERSION >= 300 510#if QT_VERSION >= 300
513 QStyle::SFlags flags = QStyle::Style_Default; 511 QStyle::SFlags flags = QStyle::Style_Default;
514 if ( selected ) 512 if ( selected )
515 flags |= QStyle::Style_Selected; 513 flags |= QStyle::Style_Selected;
516 style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(), 514 style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(),
517 colorGroup(), flags, QStyleOption(t) ); 515 colorGroup(), flags, QStyleOption(t) );
518#else 516#else
519 style().drawTab( p, this, t, selected ); 517 style().drawTab( p, this, t, selected );
520#endif 518#endif
521 519
522 QRect r( t->rect() ); 520 QRect r( t->rect() );
523 QFont f( font() ); 521 QFont f( font() );
524 if ( selected ) 522 if ( selected )
525 f.setBold( TRUE ); 523 f.setBold( TRUE );
526 p->setFont( f ); 524 p->setFont( f );
527 525
528 if ( ct->fgColor.isValid() ) { 526 if ( ct->fgColor.isValid() ) {
529 pal.setColor( QPalette::Active, QColorGroup::Foreground, ct->fgColor ); 527 pal.setColor( QPalette::Active, QColorGroup::Foreground, ct->fgColor );
530 pal.setColor( QPalette::Inactive, QColorGroup::Foreground, ct->fgColor ); 528 pal.setColor( QPalette::Inactive, QColorGroup::Foreground, ct->fgColor );
531 that->setUpdatesEnabled( FALSE ); 529 that->setUpdatesEnabled( FALSE );
532 that->setPalette( pal ); 530 that->setPalette( pal );
533 setPal = TRUE; 531 setPal = TRUE;
534 } 532 }
535 int iw = 0; 533 int iw = 0;
536 int ih = 0; 534 int ih = 0;
537 if ( t->iconSet() != 0 ) { 535 if ( t->iconSet() != 0 ) {
538 iw = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 2; 536 iw = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 2;
539 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); 537 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
540 } 538 }
541 int w = iw + p->fontMetrics().width( t->text() ) + 4; 539 int w = iw + p->fontMetrics().width( t->text() ) + 4;
542 int h = QMAX(p->fontMetrics().height() + 4, ih ); 540 int h = QMAX(p->fontMetrics().height() + 4, ih );
543 paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3, 541 paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3,
544 r.top() + (r.height()-h)/2, w, h ), t, 542 r.top() + (r.height()-h)/2, w, h ), t,
545#if QT_VERSION >= 300 543#if QT_VERSION >= 300
546 t->identifier() == keyboardFocusTab() 544 t->identifier() == keyboardFocusTab()
547#else 545#else
548 t->identitifer() == keyboardFocusTab() 546 t->identitifer() == keyboardFocusTab()
549#endif 547#endif
550 ); 548 );
551 if ( setPal ) { 549 if ( setPal ) {
552 that->unsetPalette(); 550 that->unsetPalette();
553 that->setUpdatesEnabled( TRUE ); 551 that->setUpdatesEnabled( TRUE );
554 } 552 }
555} 553}
556 554
557 555
558void CategoryTabBar::paintLabel( QPainter* p, const QRect&, 556void CategoryTabBar::paintLabel( QPainter* p, const QRect&,
559 QTab* t, bool has_focus ) const 557 QTab* t, bool has_focus ) const
560{ 558{
561 QRect r = t->rect(); 559 QRect r = t->rect();
562 // if ( t->id != currentTab() ) 560 // if ( t->id != currentTab() )
563 //r.moveBy( 1, 1 ); 561 //r.moveBy( 1, 1 );
564 // 562 //
565 if ( t->iconSet() ) { 563 if ( t->iconSet() ) {
566 // the tab has an iconset, draw it in the right mode 564 // the tab has an iconset, draw it in the right mode
567 QIconSet::Mode mode = (t->isEnabled() && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled; 565 QIconSet::Mode mode = (t->isEnabled() && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled;
568 if ( mode == QIconSet::Normal && has_focus ) 566 if ( mode == QIconSet::Normal && has_focus )
569 mode = QIconSet::Active; 567 mode = QIconSet::Active;
570 QPixmap pixmap = t->iconSet()->pixmap( QIconSet::Small, mode ); 568 QPixmap pixmap = t->iconSet()->pixmap( QIconSet::Small, mode );
571 int pixw = pixmap.width(); 569 int pixw = pixmap.width();
572 int pixh = pixmap.height(); 570 int pixh = pixmap.height();
573 p->drawPixmap( r.left() + 6, r.center().y() - pixh / 2 + 1, pixmap ); 571 p->drawPixmap( r.left() + 6, r.center().y() - pixh / 2 + 1, pixmap );
574 r.setLeft( r.left() + pixw + 5 ); 572 r.setLeft( r.left() + pixw + 5 );
575 } 573 }
576 574
577 QRect tr = r; 575 QRect tr = r;
578 576
579 if ( r.width() < 20 ) 577 if ( r.width() < 20 )
580 return; 578 return;
581 579
582 if ( t->isEnabled() && isEnabled() ) { 580 if ( t->isEnabled() && isEnabled() ) {
583#if defined(_WS_WIN32_) 581#if defined(_WS_WIN32_)
584 if ( colorGroup().brush( QColorGroup::Button ) == colorGroup().brush( QColorGroup::Background ) ) 582 if ( colorGroup().brush( QColorGroup::Button ) == colorGroup().brush( QColorGroup::Background ) )
585 p->setPen( colorGroup().buttonText() ); 583 p->setPen( colorGroup().buttonText() );
586 else 584 else
587 p->setPen( colorGroup().foreground() ); 585 p->setPen( colorGroup().foreground() );
588#else 586#else
589 p->setPen( colorGroup().foreground() ); 587 p->setPen( colorGroup().foreground() );
590#endif 588#endif
591 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() ); 589 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() );
592 } else { 590 } else {
593 p->setPen( palette().disabled().foreground() ); 591 p->setPen( palette().disabled().foreground() );
594 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() ); 592 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() );
595 } 593 }
596} 594}
597 595
598//--------------------------------------------------------------------------- 596//---------------------------------------------------------------------------
599 597
600Launcher::Launcher( QWidget* parent, const char* name, WFlags fl ) 598Launcher::Launcher( QWidget* parent, const char* name, WFlags fl )
601 : QMainWindow( parent, name, fl ) 599 : QMainWindow( parent, name, fl )
602{ 600{
603 setCaption( tr("Launcher") ); 601 setCaption( tr("Launcher") );
604 602
605 syncDialog = 0; 603 syncDialog = 0;
606 604
607 // we have a pretty good idea how big we'll be 605 // we have a pretty good idea how big we'll be
608 setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() ); 606 setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() );
609 607
610 tabs = 0; 608 tabs = 0;
611 rootFolder = 0; 609 rootFolder = 0;
612 docsFolder = 0; 610 docsFolder = 0;
613 611
614 int stamp = uidgen.generate(); // this is our timestamp to see which devices we know 612 int stamp = uidgen.generate(); // this is our timestamp to see which devices we know
615 //uidgen.store( stamp ); 613 //uidgen.store( stamp );
616 m_timeStamp = QString::number( stamp ); 614 m_timeStamp = QString::number( stamp );
617 615
618 tabs = new CategoryTabWidget( this ); 616 tabs = new CategoryTabWidget( this );
619 tabs->setMaximumWidth( qApp->desktop()->width() ); 617 tabs->setMaximumWidth( qApp->desktop()->width() );
620 setCentralWidget( tabs ); 618 setCentralWidget( tabs );
621 619
622 connect( tabs, SIGNAL(selected(const QString&)), 620 connect( tabs, SIGNAL(selected(const QString&)),
623 this, SLOT(viewSelected(const QString&)) ); 621 this, SLOT(viewSelected(const QString&)) );
624 connect( tabs, SIGNAL(clicked(const AppLnk*)), 622 connect( tabs, SIGNAL(clicked(const AppLnk*)),
625 this, SLOT(select(const AppLnk*))); 623 this, SLOT(select(const AppLnk*)));
626 connect( tabs, SIGNAL(rightPressed(AppLnk*)), 624 connect( tabs, SIGNAL(rightPressed(AppLnk*)),
627 this, SLOT(properties(AppLnk*))); 625 this, SLOT(properties(AppLnk*)));
628 626
629#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 627#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
630 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); 628 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this );
631 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), 629 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)),
632 this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); 630 this, SLOT(systemMessage( const QCString &, const QByteArray &)) );
633 QCopChannel *channel = new QCopChannel( "QPE/Launcher", this ); 631 QCopChannel *channel = new QCopChannel( "QPE/Launcher", this );
634 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 632 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
635 this, SLOT(launcherMessage(const QCString&, const QByteArray&)) ); 633 this, SLOT(launcherMessage(const QCString&, const QByteArray&)) );
636#endif 634#endif
637 635
638 storage = new StorageInfo( this ); 636 storage = new StorageInfo( this );
639 connect( storage, SIGNAL( disksChanged() ), SLOT( storageChanged() ) ); 637 connect( storage, SIGNAL( disksChanged() ), SLOT( storageChanged() ) );
640 638
641 updateTabs(); 639 updateTabs();
642 640
643 preloadApps(); 641 preloadApps();
644 642
645 in_lnk_props = FALSE; 643 in_lnk_props = FALSE;
646 got_lnk_change = FALSE; 644 got_lnk_change = FALSE;
647} 645}
648 646
649Launcher::~Launcher() 647Launcher::~Launcher()
650{ 648{
651 delete rootFolder; 649 delete rootFolder;
652 delete docsFolder; 650 delete docsFolder;
653} 651}
654 652
655static bool isVisibleWindow(int wid) 653static bool isVisibleWindow(int wid)
656{ 654{
657#ifdef QWS 655#ifdef QWS
658 const QList<QWSWindow> &list = qwsServer->clientWindows(); 656 const QList<QWSWindow> &list = qwsServer->clientWindows();
659 QWSWindow* w; 657 QWSWindow* w;
660 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 658 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
661 if ( w->winId() == wid ) 659 if ( w->winId() == wid )
662 return !w->isFullyObscured(); 660 return !w->isFullyObscured();
663 } 661 }
664#endif 662#endif
665 return FALSE; 663 return FALSE;
666} 664}
667 665
668void Launcher::showMaximized() 666void Launcher::showMaximized()
669{ 667{
670 if ( isVisibleWindow( winId() ) ) 668 if ( isVisibleWindow( winId() ) )
671 doMaximize(); 669 doMaximize();
672 else 670 else
673 QTimer::singleShot( 20, this, SLOT(doMaximize()) ); 671 QTimer::singleShot( 20, this, SLOT(doMaximize()) );
674} 672}
675 673
676void Launcher::doMaximize() 674void Launcher::doMaximize()
677{ 675{
678 QMainWindow::showMaximized(); 676 QMainWindow::showMaximized();
679} 677}
680 678
681void Launcher::updateMimeTypes() 679void Launcher::updateMimeTypes()
682{ 680{
683 MimeType::clear(); 681 MimeType::clear();
684 updateMimeTypes(rootFolder); 682 updateMimeTypes(rootFolder);
685} 683}
686 684
687void Launcher::updateMimeTypes(AppLnkSet* folder) 685void Launcher::updateMimeTypes(AppLnkSet* folder)
688{ 686{
689 for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) { 687 for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) {
690 AppLnk *app = it.current(); 688 AppLnk *app = it.current();
691 if ( app->type() == "Folder" ) // No tr 689 if ( app->type() == "Folder" ) // No tr
692 updateMimeTypes((AppLnkSet *)app); 690 updateMimeTypes((AppLnkSet *)app);
693 else { 691 else {
694 MimeType::registerApp(*app); 692 MimeType::registerApp(*app);
695 } 693 }
696 } 694 }
697} 695}
698 696
699/** This is a HACK.... 697/** This is a HACK....
700 * Reason: scanning huge mediums, microdirvers for examples 698 * Reason: scanning huge mediums, microdirvers for examples
701 * consomes time. To avoid that we invented the MediumMountCheck 699 * consomes time. To avoid that we invented the MediumMountCheck
702 * 700 *
703 * a) the user globally disabled medium checking. We can ignore 701 * a) the user globally disabled medium checking. We can ignore
704 * all removable medium 702 * all removable medium
705 * b) the user enabled medium checking globally and we need to use this mimefilter 703 * b) the user enabled medium checking globally and we need to use this mimefilter
706 * c) the user enabled medium checking on a per medium bases 704 * c) the user enabled medium checking on a per medium bases
707 * c1) we already checked and its not ask again turns 705 * c1) we already checked and its not ask again turns
708 * c2) we need to ask and then apply the mimefilter 706 * c2) we need to ask and then apply the mimefilter
709 */ 707 */
710void Launcher::loadDocs() // ok here comes a hack belonging to Global:: 708void Launcher::loadDocs() // ok here comes a hack belonging to Global::
711{ 709{
712 delete docsFolder; 710 delete docsFolder;
713 docsFolder = new DocLnkSet; 711 docsFolder = new DocLnkSet;
714 712
715 DocLnkSet *tmp = 0; 713 DocLnkSet *tmp = 0;
716 QString home = QString(getenv("HOME")) + "/Documents"; 714 QString home = QString(getenv("HOME")) + "/Documents";
717 tmp = new DocLnkSet( home , QString::null); 715 tmp = new DocLnkSet( home , QString::null);
718 docsFolder->appendFrom( *tmp ); 716 docsFolder->appendFrom( *tmp );
719 delete tmp; 717 delete tmp;
720 718
721 // RAM documents 719 // RAM documents
722 StorageInfo storage; 720 StorageInfo storage;
723 const QList<FileSystem> &fileSystems = storage.fileSystems(); 721 const QList<FileSystem> &fileSystems = storage.fileSystems();
724 QListIterator<FileSystem> it ( fileSystems ); 722 QListIterator<FileSystem> it ( fileSystems );
725 723
726 for ( ; it.current(); ++it ) { 724 for ( ; it.current(); ++it ) {
727 if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { 725 if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) {
728 tmp = new DocLnkSet( (*it)->path(), QString::null ); 726 tmp = new DocLnkSet( (*it)->path(), QString::null );
729 docsFolder->appendFrom( *tmp ); 727 docsFolder->appendFrom( *tmp );
730 delete tmp; 728 delete tmp;
731 } 729 }
732 } 730 }
733 731
734 Config mediumCfg( "medium"); 732 Config mediumCfg( "medium");
735 mediumCfg.setGroup("main"); 733 mediumCfg.setGroup("main");
736 // a) -zecke we don't want to check 734 // a) -zecke we don't want to check
737 if(!mediumCfg.readBoolEntry("use", true ) ) 735 if(!mediumCfg.readBoolEntry("use", true ) )
738 return; 736 return;
739 737
740 // find out wich filesystems are new in this round 738 // find out wich filesystems are new in this round
741 // We will do this by having a timestamp inside each mountpoint 739 // We will do this by having a timestamp inside each mountpoint
742 // if the current timestamp doesn't match this is a new file system and 740 // if the current timestamp doesn't match this is a new file system and
743 // come up with our MediumMountGui :) let the hacking begin 741 // come up with our MediumMountGui :) let the hacking begin
744 int stamp = uidgen.generate(); 742 int stamp = uidgen.generate();
745 743
746 QString newStamp = QString::number( stamp ); // generates newtime Stamp 744 QString newStamp = QString::number( stamp ); // generates newtime Stamp
747 745
748 // b) 746 // b)
749 if( mediumCfg.readBoolEntry("global", true ) ){ 747 if( mediumCfg.readBoolEntry("global", true ) ){
750 QString mime = configToMime(&mediumCfg).join(";"); 748 QString mime = configToMime(&mediumCfg).join(";");
751 for( it.toFirst(); it.current(); ++it ){ 749 for( it.toFirst(); it.current(); ++it ){
752 if( (*it)->isRemovable() ){ 750 if( (*it)->isRemovable() ){
753 tmp = new DocLnkSet( (*it)->path(), mime ); 751 tmp = new DocLnkSet( (*it)->path(), mime );
754 docsFolder->appendFrom( *tmp ); 752 docsFolder->appendFrom( *tmp );
755 delete tmp; 753 delete tmp;
756 } 754 }
757 } // done 755 } // done
758 return; // save the else 756 return; // save the else
759 } 757 }
760 // c) zecke 758 // c) zecke
761 for ( it.toFirst(); it.current(); ++it ) { 759 for ( it.toFirst(); it.current(); ++it ) {
762 if ( (*it)->isRemovable() ) { // let's find out if we should search on it 760 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
763 Config cfg( (*it)->path() + "/.opiestorage.cf", Config::File); 761 Config cfg( (*it)->path() + "/.opiestorage.cf", Config::File);
764 cfg.setGroup("main"); 762 cfg.setGroup("main");
765 QString stamp = cfg.readEntry("timestamp", QDateTime::currentDateTime().toString() ); 763 QString stamp = cfg.readEntry("timestamp", QDateTime::currentDateTime().toString() );
766 /** This medium is uptodate 764 /** This medium is uptodate
767 */ 765 */
768 if( stamp == m_timeStamp ){ // ok we know this card 766 if( stamp == m_timeStamp ){ // ok we know this card
769 cfg.writeEntry("timestamp", newStamp ); //just write a new timestamp 767 cfg.writeEntry("timestamp", newStamp ); //just write a new timestamp
770 // we need to scan the list now. Hopefully the cache will be there 768 // we need to scan the list now. Hopefully the cache will be there
771 // read the mimetypes from the config and search for documents 769 // read the mimetypes from the config and search for documents
772 QStringList mimetypes = configToMime( &cfg); 770 QStringList mimetypes = configToMime( &cfg);
773 tmp = new DocLnkSet( (*it)->path(), mimetypes.join(";") ); 771 tmp = new DocLnkSet( (*it)->path(), mimetypes.join(";") );
774 docsFolder->appendFrom( *tmp ); 772 docsFolder->appendFrom( *tmp );
775 delete tmp; 773 delete tmp;
776 774
777 }else{ // come up with the gui cause this a new card 775 }else{ // come up with the gui cause this a new card
778 MediumMountGui medium(&cfg, (*it)->path() ); 776 MediumMountGui medium(&cfg, (*it)->path() );
779 if( medium.check() ){ // we did not ask before or ask again is off 777 if( medium.check() ){ // we did not ask before or ask again is off
780 /** c2) */ 778 /** c2) */
781 if( medium.exec() ){ // he clicked yes so search it 779 if( medium.exec() ){ // he clicked yes so search it
782 // speicher 780 // speicher
783 //cfg.read(); // cause of a race we need to reread - fixed 781 //cfg.read(); // cause of a race we need to reread - fixed
784 cfg.setGroup("main"); 782 cfg.setGroup("main");
785 cfg.writeEntry("timestamp", newStamp ); 783 cfg.writeEntry("timestamp", newStamp );
786 cfg.write(); 784 cfg.write();
787 tmp = new DocLnkSet( (*it)->path(), medium.mimeTypes().join(";" ) ); 785 tmp = new DocLnkSet( (*it)->path(), medium.mimeTypes().join(";" ) );
788 docsFolder->appendFrom( *tmp ); 786 docsFolder->appendFrom( *tmp );
789 delete tmp; 787 delete tmp;
790 }// no else 788 }// no else
791 /** c1) */ 789 /** c1) */
792 }else{ // we checked 790 }else{ // we checked
793 // do something different see what we need to do 791 // do something different see what we need to do
794 // let's see if we should check the device 792 // let's see if we should check the device
795 cfg.setGroup("main" ); 793 cfg.setGroup("main" );
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
index 073e19a..762a596 100644
--- a/core/launcher/main.cpp
+++ b/core/launcher/main.cpp
@@ -1,172 +1,173 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "desktop.h" 21#include "desktop.h"
22#include "taskbar.h" 22#include "taskbar.h"
23#include "stabmon.h" 23#include "stabmon.h"
24 24
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/network.h> 26#include <qpe/network.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) 28#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ )
29#include <qpe/custom.h> 29#include <qpe/custom.h>
30#endif 30#endif
31 31
32#include <opie/odevice.h> 32#include <opie/odevice.h>
33 33
34#include <qfile.h> 34#include <qfile.h>
35#include <qimage.h>
35#include <qwindowsystem_qws.h> 36#include <qwindowsystem_qws.h>
36#include <qpe/qcopenvelope_qws.h> 37#include <qpe/qcopenvelope_qws.h>
37#include <qpe/alarmserver.h> 38#include <qpe/alarmserver.h>
38 39
39#include <stdlib.h> 40#include <stdlib.h>
40#include <stdio.h> 41#include <stdio.h>
41#include <signal.h> 42#include <signal.h>
42#include <unistd.h> 43#include <unistd.h>
43 44
44#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 45#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
45#include "../calibrate/calibrate.h" 46#include "../calibrate/calibrate.h"
46#endif 47#endif
47 48
48using namespace Opie; 49using namespace Opie;
49 50
50void initEnvironment() 51void initEnvironment()
51{ 52{
52 Config config("locale"); 53 Config config("locale");
53 config.setGroup( "Location" ); 54 config.setGroup( "Location" );
54 QString tz = config.readEntry( "Timezone", getenv("TZ") ); 55 QString tz = config.readEntry( "Timezone", getenv("TZ") );
55 56
56 // if not timezone set, pick New York 57 // if not timezone set, pick New York
57 if (tz.isNull()) 58 if (tz.isNull())
58 tz = "America/New_York"; 59 tz = "America/New_York";
59 60
60 setenv( "TZ", tz, 1 ); 61 setenv( "TZ", tz, 1 );
61 config.writeEntry( "Timezone", tz); 62 config.writeEntry( "Timezone", tz);
62 63
63 config.setGroup( "Language" ); 64 config.setGroup( "Language" );
64 QString lang = config.readEntry( "Language", getenv("LANG") ); 65 QString lang = config.readEntry( "Language", getenv("LANG") );
65 if ( !lang.isNull() ) 66 if ( !lang.isNull() )
66 setenv( "LANG", lang, 1 ); 67 setenv( "LANG", lang, 1 );
67} 68}
68 69
69 70
70int initApplication( int argc, char ** argv ) 71int initApplication( int argc, char ** argv )
71{ 72{
72 initEnvironment(); 73 initEnvironment();
73 74
74#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX) 75#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX)
75 setenv( "QWS_SIZE", "240x320", 0 ); 76 setenv( "QWS_SIZE", "240x320", 0 );
76#endif 77#endif
77 78
78 //Don't flicker at startup: 79 //Don't flicker at startup:
79 QWSServer::setDesktopBackground( QImage() ); 80 QWSServer::setDesktopBackground( QImage() );
80 DesktopApplication a( argc, argv, QApplication::GuiServer ); 81 DesktopApplication a( argc, argv, QApplication::GuiServer );
81 82
82 ODevice::inst ( )-> setSoftSuspend ( true ); 83 ODevice::inst ( )-> setSoftSuspend ( true );
83 84
84 { // init backlight 85 { // init backlight
85 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 86 QCopEnvelope e("QPE/System", "setBacklight(int)" );
86 e << -3; // Forced on 87 e << -3; // Forced on
87 } 88 }
88 89
89 AlarmServer::initialize(); 90 AlarmServer::initialize();
90 91
91 Desktop *d = new Desktop(); 92 Desktop *d = new Desktop();
92 93
93 QObject::connect( &a, SIGNAL(datebook()), d, SLOT(raiseDatebook()) ); 94 QObject::connect( &a, SIGNAL(datebook()), d, SLOT(raiseDatebook()) );
94 QObject::connect( &a, SIGNAL(contacts()), d, SLOT(raiseContacts()) ); 95 QObject::connect( &a, SIGNAL(contacts()), d, SLOT(raiseContacts()) );
95 QObject::connect( &a, SIGNAL(launch()), d, SLOT(raiseLauncher()) ); 96 QObject::connect( &a, SIGNAL(launch()), d, SLOT(raiseLauncher()) );
96 QObject::connect( &a, SIGNAL(email()), d, SLOT(raiseEmail()) ); 97 QObject::connect( &a, SIGNAL(email()), d, SLOT(raiseEmail()) );
97 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) ); 98 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) );
98 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) ); 99 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) );
99 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) ); 100 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) );
100 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) ); 101 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) );
101 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) ); 102 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) );
102 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) ); 103 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) );
103 104
104 (void)new SysFileMonitor(d); 105 (void)new SysFileMonitor(d);
105 Network::createServer(d); 106 Network::createServer(d);
106 107
107#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 108#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
108 if ( !QFile::exists( "/etc/pointercal" ) ) { 109 if ( !QFile::exists( "/etc/pointercal" ) ) {
109 // Make sure calibration widget starts on top. 110 // Make sure calibration widget starts on top.
110 Calibrate *cal = new Calibrate; 111 Calibrate *cal = new Calibrate;
111 cal->exec(); 112 cal->exec();
112 delete cal; 113 delete cal;
113 } 114 }
114#endif 115#endif
115 116
116 d->show(); 117 d->show();
117 118
118 int rv = a.exec(); 119 int rv = a.exec();
119 120
120 delete d; 121 delete d;
121 122
122 ODevice::inst ( )-> setSoftSuspend ( false ); 123 ODevice::inst ( )-> setSoftSuspend ( false );
123 124
124 return rv; 125 return rv;
125} 126}
126 127
127static const char *pidfile_path = "/var/run/opie.pid"; 128static const char *pidfile_path = "/var/run/opie.pid";
128 129
129void create_pidfile ( ) 130void create_pidfile ( )
130{ 131{
131 FILE *f; 132 FILE *f;
132 133
133 if (( f = ::fopen ( pidfile_path, "w" ))) { 134 if (( f = ::fopen ( pidfile_path, "w" ))) {
134 ::fprintf ( f, "%d", getpid ( )); 135 ::fprintf ( f, "%d", getpid ( ));
135 ::fclose ( f ); 136 ::fclose ( f );
136 } 137 }
137} 138}
138 139
139void remove_pidfile ( ) 140void remove_pidfile ( )
140{ 141{
141 ::unlink ( pidfile_path ); 142 ::unlink ( pidfile_path );
142} 143}
143 144
144void handle_sigterm ( int /* sig */ ) 145void handle_sigterm ( int /* sig */ )
145{ 146{
146 if ( qApp ) 147 if ( qApp )
147 qApp-> quit ( ); 148 qApp-> quit ( );
148} 149}
149 150
150int main( int argc, char ** argv ) 151int main( int argc, char ** argv )
151{ 152{
152 ::signal ( SIGCHLD, SIG_IGN ); 153 ::signal ( SIGCHLD, SIG_IGN );
153 154
154 ::signal ( SIGTERM, handle_sigterm ); 155 ::signal ( SIGTERM, handle_sigterm );
155 ::signal ( SIGINT, handle_sigterm ); 156 ::signal ( SIGINT, handle_sigterm );
156 157
157 ::setsid ( ); 158 ::setsid ( );
158 ::setpgid ( 0, 0 ); 159 ::setpgid ( 0, 0 );
159 160
160 ::atexit ( remove_pidfile ); 161 ::atexit ( remove_pidfile );
161 create_pidfile ( ); 162 create_pidfile ( );
162 163
163 int retVal = initApplication ( argc, argv ); 164 int retVal = initApplication ( argc, argv );
164 165
165 // Kill them. Kill them all. 166 // Kill them. Kill them all.
166 ::kill ( 0, SIGTERM ); 167 ::kill ( 0, SIGTERM );
167 ::sleep ( 1 ); 168 ::sleep ( 1 );
168 ::kill ( 0, SIGKILL ); 169 ::kill ( 0, SIGKILL );
169 170
170 return retVal; 171 return retVal;
171} 172}
172 173
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 85993ee..6177a7c 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,424 +1,422 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "qcopbridge.h" 21#include "qcopbridge.h"
22#include "transferserver.h" 22#include "transferserver.h"
23 23
24#ifdef QWS
25#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
26#endif
27#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
28#include <qpe/version.h> 26#include <qpe/version.h>
29 27
30#include <qdir.h> 28#include <qdir.h>
31#include <qfile.h> 29#include <qfile.h>
32#include <qtextstream.h> 30#include <qtextstream.h>
33#include <qdatastream.h> 31#include <qdatastream.h>
34#include <qstringlist.h> 32#include <qstringlist.h>
35#include <qfileinfo.h> 33#include <qfileinfo.h>
36#include <qregexp.h> 34#include <qregexp.h>
37#ifdef QWS 35#ifdef QWS
38#include <qcopchannel_qws.h> 36#include <qcopchannel_qws.h>
39#endif 37#endif
40 38
41#define _XOPEN_SOURCE 39#define _XOPEN_SOURCE
42#include <pwd.h> 40#include <pwd.h>
43#include <sys/types.h> 41#include <sys/types.h>
44#include <unistd.h> 42#include <unistd.h>
45 43
46#if defined(_OS_LINUX_) 44#if defined(_OS_LINUX_)
47#include <shadow.h> 45#include <shadow.h>
48#endif 46#endif
49 47
50//#define INSECURE 48//#define INSECURE
51 49
52const int block_size = 51200; 50const int block_size = 51200;
53 51
54QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , 52QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent ,
55 const char* name ) 53 const char* name )
56 : QServerSocket( port, 1, parent, name ), 54 : QServerSocket( port, 1, parent, name ),
57 desktopChannel( 0 ), 55 desktopChannel( 0 ),
58 cardChannel( 0 ) 56 cardChannel( 0 )
59{ 57{
60 if ( !ok() ) 58 if ( !ok() )
61 qWarning( "Failed to bind to port %d", port ); 59 qWarning( "Failed to bind to port %d", port );
62 else { 60 else {
63#ifndef QT_NO_COP 61#ifndef QT_NO_COP
64 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 62 desktopChannel = new QCopChannel( "QPE/Desktop", this );
65 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), 63 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)),
66 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 64 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
67 cardChannel = new QCopChannel( "QPE/Card", this ); 65 cardChannel = new QCopChannel( "QPE/Card", this );
68 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), 66 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)),
69 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 67 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
70#endif 68#endif
71 } 69 }
72 sendSync = FALSE; 70 sendSync = FALSE;
73} 71}
74 72
75QCopBridge::~QCopBridge() 73QCopBridge::~QCopBridge()
76{ 74{
77#ifndef QT_NO_COP 75#ifndef QT_NO_COP
78 delete desktopChannel; 76 delete desktopChannel;
79#endif 77#endif
80} 78}
81 79
82void QCopBridge::newConnection( int socket ) 80void QCopBridge::newConnection( int socket )
83{ 81{
84 QCopBridgePI *pi = new QCopBridgePI( socket, this ); 82 QCopBridgePI *pi = new QCopBridgePI( socket, this );
85 openConnections.append( pi ); 83 openConnections.append( pi );
86 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); 84 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) );
87#ifndef QT_NO_COP 85#ifndef QT_NO_COP
88 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; 86 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
89#endif 87#endif
90 88
91 if ( sendSync ) { 89 if ( sendSync ) {
92 pi ->startSync(); 90 pi ->startSync();
93 sendSync = FALSE; 91 sendSync = FALSE;
94 } 92 }
95} 93}
96 94
97void QCopBridge::connectionClosed( QCopBridgePI *pi ) 95void QCopBridge::connectionClosed( QCopBridgePI *pi )
98{ 96{
99 openConnections.remove( pi ); 97 openConnections.remove( pi );
100 if ( openConnections.count() == 0 ) { 98 if ( openConnections.count() == 0 ) {
101#ifndef QT_NO_COP 99#ifndef QT_NO_COP
102 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 100 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
103#endif 101#endif
104 } 102 }
105} 103}
106 104
107void QCopBridge::closeOpenConnections() 105void QCopBridge::closeOpenConnections()
108{ 106{
109 QCopBridgePI *pi; 107 QCopBridgePI *pi;
110 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 108 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
111 pi->close(); 109 pi->close();
112} 110}
113 111
114 112
115void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) 113void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args )
116{ 114{
117 command.stripWhiteSpace(); 115 command.stripWhiteSpace();
118 116
119 int paren = command.find( "(" ); 117 int paren = command.find( "(" );
120 if ( paren <= 0 ) { 118 if ( paren <= 0 ) {
121 qDebug("DesktopMessage: bad qcop syntax"); 119 qDebug("DesktopMessage: bad qcop syntax");
122 return; 120 return;
123 } 121 }
124 122
125 QString params = command.mid( paren + 1 ); 123 QString params = command.mid( paren + 1 );
126 if ( params[params.length()-1] != ')' ) { 124 if ( params[params.length()-1] != ')' ) {
127 qDebug("DesktopMessage: bad qcop syntax"); 125 qDebug("DesktopMessage: bad qcop syntax");
128 return; 126 return;
129 } 127 }
130 128
131 params.truncate( params.length()-1 ); 129 params.truncate( params.length()-1 );
132 130
133 QStringList paramList = QStringList::split( ",", params ); 131 QStringList paramList = QStringList::split( ",", params );
134 QString data; 132 QString data;
135 if ( paramList.count() ) { 133 if ( paramList.count() ) {
136 QDataStream stream( args, IO_ReadOnly ); 134 QDataStream stream( args, IO_ReadOnly );
137 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 135 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
138 QString str; 136 QString str;
139 if ( *it == "QString" ) { 137 if ( *it == "QString" ) {
140 stream >> str; 138 stream >> str;
141 } else if ( *it == "QCString" ) { 139 } else if ( *it == "QCString" ) {
142 QCString cstr; 140 QCString cstr;
143 stream >> cstr; 141 stream >> cstr;
144 str = QString::fromLocal8Bit( cstr ); 142 str = QString::fromLocal8Bit( cstr );
145 } else if ( *it == "int" ) { 143 } else if ( *it == "int" ) {
146 int i; 144 int i;
147 stream >> i; 145 stream >> i;
148 str = QString::number( i ); 146 str = QString::number( i );
149 } else if ( *it == "bool" ) { 147 } else if ( *it == "bool" ) {
150 int i; 148 int i;
151 stream >> i; 149 stream >> i;
152 str = QString::number( i ); 150 str = QString::number( i );
153 } else { 151 } else {
154 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); 152 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
155 return; 153 return;
156 } 154 }
157 QString estr; 155 QString estr;
158 for (int i=0; i<(int)str.length(); i++) { 156 for (int i=0; i<(int)str.length(); i++) {
159 QChar ch = str[i]; 157 QChar ch = str[i];
160 if ( ch.row() ) 158 if ( ch.row() )
161 goto quick; 159 goto quick;
162 switch (ch.cell()) { 160 switch (ch.cell()) {
163 case '&': 161 case '&':
164 estr.append( "&amp;" ); 162 estr.append( "&amp;" );
165 break; 163 break;
166 case ' ': 164 case ' ':
167 estr.append( "&0x20;" ); 165 estr.append( "&0x20;" );
168 break; 166 break;
169 case '\n': 167 case '\n':
170 estr.append( "&0x0d;" ); 168 estr.append( "&0x0d;" );
171 break; 169 break;
172 case '\r': 170 case '\r':
173 estr.append( "&0x0a;" ); 171 estr.append( "&0x0a;" );
174 break; 172 break;
175 default: quick: 173 default: quick:
176 estr.append(ch); 174 estr.append(ch);
177 } 175 }
178 } 176 }
179 data += " " + estr; 177 data += " " + estr;
180 } 178 }
181 } 179 }
182 QString sendCommand = QString(command.data()) + data; 180 QString sendCommand = QString(command.data()) + data;
183 // send the command to all open connections 181 // send the command to all open connections
184 if ( command == "startSync()" ) { 182 if ( command == "startSync()" ) {
185 // we need to buffer it a bit 183 // we need to buffer it a bit
186 sendSync = TRUE; 184 sendSync = TRUE;
187 startTimer( 20000 ); 185 startTimer( 20000 );
188 } 186 }
189 187
190 QCopBridgePI *pi; 188 QCopBridgePI *pi;
191 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 189 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
192 pi->sendDesktopMessage( sendCommand ); 190 pi->sendDesktopMessage( sendCommand );
193 } 191 }
194} 192}
195 193
196void QCopBridge::timerEvent( QTimerEvent * ) 194void QCopBridge::timerEvent( QTimerEvent * )
197{ 195{
198 sendSync = FALSE; 196 sendSync = FALSE;
199 killTimers(); 197 killTimers();
200} 198}
201 199
202 200
203QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name ) 201QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name )
204 : QSocket( parent, name ) 202 : QSocket( parent, name )
205{ 203{
206 setSocket( socket ); 204 setSocket( socket );
207 205
208 peerport = peerPort(); 206 peerport = peerPort();
209 peeraddress = peerAddress(); 207 peeraddress = peerAddress();
210 208
211#ifndef INSECURE 209#ifndef INSECURE
212 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 210 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
213 state = Forbidden; 211 state = Forbidden;
214 startTimer( 0 ); 212 startTimer( 0 );
215 } else 213 } else
216 #endif 214 #endif
217 { 215 {
218 state = Connected; 216 state = Connected;
219 sendSync = FALSE; 217 sendSync = FALSE;
220 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 218 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
221 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 219 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
222 220
223 QString intro="220 Qtopia "; 221 QString intro="220 Qtopia ";
224 intro += QPE_VERSION; intro += ";"; 222 intro += QPE_VERSION; intro += ";";
225 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; 223 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";";
226 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; 224 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";";
227 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; 225 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";";
228 send( intro ); 226 send( intro );
229 state = Wait_USER; 227 state = Wait_USER;
230 228
231 // idle timer to close connections when not used anymore 229 // idle timer to close connections when not used anymore
232 startTimer( 60000 ); 230 startTimer( 60000 );
233 connected = TRUE; 231 connected = TRUE;
234 } 232 }
235} 233}
236 234
237 235
238QCopBridgePI::~QCopBridgePI() 236QCopBridgePI::~QCopBridgePI()
239{ 237{
240 238
241} 239}
242 240
243void QCopBridgePI::connectionClosed() 241void QCopBridgePI::connectionClosed()
244{ 242{
245 emit connectionClosed( this ); 243 emit connectionClosed( this );
246 // qDebug( "Debug: Connection closed" ); 244 // qDebug( "Debug: Connection closed" );
247 delete this; 245 delete this;
248} 246}
249 247
250void QCopBridgePI::sendDesktopMessage( const QString &msg ) 248void QCopBridgePI::sendDesktopMessage( const QString &msg )
251{ 249{
252 QString str = "CALL QPE/Desktop " + msg; 250 QString str = "CALL QPE/Desktop " + msg;
253 send ( str ); 251 send ( str );
254} 252}
255 253
256 254
257void QCopBridgePI::send( const QString& msg ) 255void QCopBridgePI::send( const QString& msg )
258{ 256{
259 QTextStream os( this ); 257 QTextStream os( this );
260 os << msg << endl; 258 os << msg << endl;
261 //qDebug( "sending qcop message: %s", msg.latin1() ); 259 //qDebug( "sending qcop message: %s", msg.latin1() );
262} 260}
263 261
264void QCopBridgePI::read() 262void QCopBridgePI::read()
265{ 263{
266 while ( canReadLine() ) 264 while ( canReadLine() )
267 process( readLine().stripWhiteSpace() ); 265 process( readLine().stripWhiteSpace() );
268} 266}
269 267
270void QCopBridgePI::process( const QString& message ) 268void QCopBridgePI::process( const QString& message )
271{ 269{
272 //qDebug( "Command: %s", message.latin1() ); 270 //qDebug( "Command: %s", message.latin1() );
273 271
274 // split message using "," as separator 272 // split message using "," as separator
275 QStringList msg = QStringList::split( " ", message ); 273 QStringList msg = QStringList::split( " ", message );
276 if ( msg.isEmpty() ) return; 274 if ( msg.isEmpty() ) return;
277 275
278 // command token 276 // command token
279 QString cmd = msg[0].upper(); 277 QString cmd = msg[0].upper();
280 278
281 // argument token 279 // argument token
282 QString arg; 280 QString arg;
283 if ( msg.count() >= 2 ) 281 if ( msg.count() >= 2 )
284 arg = msg[1]; 282 arg = msg[1];
285 283
286 // we always respond to QUIT, regardless of state 284 // we always respond to QUIT, regardless of state
287 if ( cmd == "QUIT" ) { 285 if ( cmd == "QUIT" ) {
288 send( "211 Have a nice day!" ); 286 send( "211 Have a nice day!" );
289 delete this; 287 delete this;
290 return; 288 return;
291 } 289 }
292 290
293 // connected to client 291 // connected to client
294 if ( Connected == state ) 292 if ( Connected == state )
295 return; 293 return;
296 294
297 // waiting for user name 295 // waiting for user name
298 if ( Wait_USER == state ) { 296 if ( Wait_USER == state ) {
299 297
300 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 298 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
301 send( "530 Please login with USER and PASS" ); 299 send( "530 Please login with USER and PASS" );
302 return; 300 return;
303 } 301 }
304 send( "331 User name ok, need password" ); 302 send( "331 User name ok, need password" );
305 state = Wait_PASS; 303 state = Wait_PASS;
306 return; 304 return;
307 } 305 }
308 306
309 // waiting for password 307 // waiting for password
310 if ( Wait_PASS == state ) { 308 if ( Wait_PASS == state ) {
311 309
312 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 310 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
313 send( "530 Please login with USER and PASS" ); 311 send( "530 Please login with USER and PASS" );
314 return; 312 return;
315 } 313 }
316 send( "230 User logged in, proceed" ); 314 send( "230 User logged in, proceed" );
317 state = Ready; 315 state = Ready;
318 if ( sendSync ) { 316 if ( sendSync ) {
319 sendDesktopMessage( "startSync()" ); 317 sendDesktopMessage( "startSync()" );
320 sendSync = FALSE; 318 sendSync = FALSE;
321 } 319 }
322 return; 320 return;
323 } 321 }
324 322
325 // noop (NOOP) 323 // noop (NOOP)
326 else if ( cmd == "NOOP" ) { 324 else if ( cmd == "NOOP" ) {
327 connected = TRUE; 325 connected = TRUE;
328 send( "200 Command okay" ); 326 send( "200 Command okay" );
329 } 327 }
330 328
331 // call (CALL) 329 // call (CALL)
332 else if ( cmd == "CALL" ) { 330 else if ( cmd == "CALL" ) {
333 331
334 // example: call QPE/System execute(QString) addressbook 332 // example: call QPE/System execute(QString) addressbook
335 333
336 if ( msg.count() < 3 ) { 334 if ( msg.count() < 3 ) {
337 send( "500 Syntax error, command unrecognized" ); 335 send( "500 Syntax error, command unrecognized" );
338 } 336 }
339 else { 337 else {
340 338
341 QString channel = msg[1]; 339 QString channel = msg[1];
342 QString command = msg[2]; 340 QString command = msg[2];
343 341
344 command.stripWhiteSpace(); 342 command.stripWhiteSpace();
345 343
346 int paren = command.find( "(" ); 344 int paren = command.find( "(" );
347 if ( paren <= 0 ) { 345 if ( paren <= 0 ) {
348 send( "500 Syntax error, command unrecognized" ); 346 send( "500 Syntax error, command unrecognized" );
349 return; 347 return;
350 } 348 }
351 349
352 QString params = command.mid( paren + 1 ); 350 QString params = command.mid( paren + 1 );
353 if ( params[params.length()-1] != ')' ) { 351 if ( params[params.length()-1] != ')' ) {
354 send( "500 Syntax error, command unrecognized" ); 352 send( "500 Syntax error, command unrecognized" );
355 return; 353 return;
356 } 354 }
357 355
358 params.truncate( params.length()-1 ); 356 params.truncate( params.length()-1 );
359 QByteArray buffer; 357 QByteArray buffer;
360 QDataStream ds( buffer, IO_WriteOnly ); 358 QDataStream ds( buffer, IO_WriteOnly );
361 359
362 int msgId = 3; 360 int msgId = 3;
363 361
364 QStringList paramList = QStringList::split( ",", params ); 362 QStringList paramList = QStringList::split( ",", params );
365 if ( paramList.count() > msg.count() - 3 ) { 363 if ( paramList.count() > msg.count() - 3 ) {
366 send( "500 Syntax error, command unrecognized" ); 364 send( "500 Syntax error, command unrecognized" );
367 return; 365 return;
368 } 366 }
369 367
370 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 368 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
371 369
372 QString arg = msg[msgId]; 370 QString arg = msg[msgId];
373 arg.replace( QRegExp("&0x20;"), " " ); 371 arg.replace( QRegExp("&0x20;"), " " );
374 arg.replace( QRegExp("&amp;"), "&" ); 372 arg.replace( QRegExp("&amp;"), "&" );
375 arg.replace( QRegExp("&0x0d;"), "\n" ); 373 arg.replace( QRegExp("&0x0d;"), "\n" );
376 arg.replace( QRegExp("&0x0a;"), "\r" ); 374 arg.replace( QRegExp("&0x0a;"), "\r" );
377 if ( *it == "QString" ) 375 if ( *it == "QString" )
378 ds << arg; 376 ds << arg;
379 else if ( *it == "QCString" ) 377 else if ( *it == "QCString" )
380 ds << arg.local8Bit(); 378 ds << arg.local8Bit();
381 else if ( *it == "int" ) 379 else if ( *it == "int" )
382 ds << arg.toInt(); 380 ds << arg.toInt();
383 else if ( *it == "bool" ) 381 else if ( *it == "bool" )
384 ds << arg.toInt(); 382 ds << arg.toInt();
385 else { 383 else {
386 send( "500 Syntax error, command unrecognized" ); 384 send( "500 Syntax error, command unrecognized" );
387 return; 385 return;
388 } 386 }
389 msgId++; 387 msgId++;
390 } 388 }
391 389
392#ifndef QT_NO_COP 390#ifndef QT_NO_COP
393 if ( !QCopChannel::isRegistered( channel.latin1() ) ) { 391 if ( !QCopChannel::isRegistered( channel.latin1() ) ) {
394 // send message back about it 392 // send message back about it
395 QString answer = "599 ChannelNotRegistered " + channel; 393 QString answer = "599 ChannelNotRegistered " + channel;
396 send( answer ); 394 send( answer );
397 return; 395 return;
398 } 396 }
399#endif 397#endif
400 398
401#ifndef QT_NO_COP 399#ifndef QT_NO_COP
402 if ( paramList.count() ) 400 if ( paramList.count() )
403 QCopChannel::send( channel.latin1(), command.latin1(), buffer ); 401 QCopChannel::send( channel.latin1(), command.latin1(), buffer );
404 else 402 else
405 QCopChannel::send( channel.latin1(), command.latin1() ); 403 QCopChannel::send( channel.latin1(), command.latin1() );
406 404
407 send( "200 Command okay" ); 405 send( "200 Command okay" );
408#endif 406#endif
409 } 407 }
410 } 408 }
411 // not implemented 409 // not implemented
412 else 410 else
413 send( "502 Command not implemented" ); 411 send( "502 Command not implemented" );
414} 412}
415 413
416 414
417 415
418void QCopBridgePI::timerEvent( QTimerEvent * ) 416void QCopBridgePI::timerEvent( QTimerEvent * )
419{ 417{
420 if ( connected ) 418 if ( connected )
421 connected = FALSE; 419 connected = FALSE;
422 else 420 else
423 connectionClosed(); 421 connectionClosed();
424} 422}
diff --git a/core/launcher/runningappbar.cpp b/core/launcher/runningappbar.cpp
index b830d1b..c8f45d5 100644
--- a/core/launcher/runningappbar.cpp
+++ b/core/launcher/runningappbar.cpp
@@ -1,289 +1,291 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19********************************************************************** 19**********************************************************************
20*/ 20*/
21 21
22#define QTOPIA_INTERNAL_PRELOADACCESS 22#define QTOPIA_INTERNAL_PRELOADACCESS
23 23
24// For "kill" 24// For "kill"
25#include <sys/types.h> 25#include <sys/types.h>
26#include <signal.h> 26#include <signal.h>
27 27
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qpopupmenu.h> 29#include <qpopupmenu.h>
30#include <qmessagebox.h> 30#include <qmessagebox.h>
31#include <qpainter.h> 31#include <qpainter.h>
32#include "qprocess.h" 32#include "qprocess.h"
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#include <qpe/applnk.h> 34#include <qpe/applnk.h>
35#include <qpe/qcopenvelope_qws.h> 35#include <qpe/qcopenvelope_qws.h>
36#include <qpe/global.h> 36#include <qpe/global.h>
37#include <qwindowsystem_qws.h> 37#include <qwindowsystem_qws.h>
38#include "runningappbar.h" 38#include "runningappbar.h"
39 39
40RunningAppBar::RunningAppBar(QWidget* parent) 40RunningAppBar::RunningAppBar(QWidget* parent)
41 : QFrame(parent), m_AppLnkSet(0L), m_SelectedAppIndex(-1) 41 : QFrame(parent), m_AppLnkSet(0L), m_SelectedAppIndex(-1)
42{ 42{
43 setBackgroundMode( PaletteBackground ); 43 setBackgroundMode( PaletteBackground );
44 44
45 m_AppLnkSet = new AppLnkSet( QPEApplication::qpeDir() + "apps" ); 45 m_AppLnkSet = new AppLnkSet( QPEApplication::qpeDir() + "apps" );
46 46
47#ifdef QWS
47 connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); 48 connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&)));
48 connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&))); 49 connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&)));
50#endif
49 QCopChannel* channel = new QCopChannel( "QPE/System", this ); 51 QCopChannel* channel = new QCopChannel( "QPE/System", this );
50 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 52 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
51 this, SLOT(received(const QCString&, const QByteArray&)) ); 53 this, SLOT(received(const QCString&, const QByteArray&)) );
52 54
53 spacing = AppLnk::smallIconSize()+3; 55 spacing = AppLnk::smallIconSize()+3;
54} 56}
55 57
56RunningAppBar::~RunningAppBar() { 58RunningAppBar::~RunningAppBar() {
57} 59}
58 60
59void RunningAppBar::newQcopChannel(const QString& channelName) { 61void RunningAppBar::newQcopChannel(const QString& channelName) {
60 QString prefix("QPE/Application/"); 62 QString prefix("QPE/Application/");
61 if (channelName.startsWith(prefix)) { 63 if (channelName.startsWith(prefix)) {
62 QString appName = channelName.mid(prefix.length()); 64 QString appName = channelName.mid(prefix.length());
63// qDebug("App %s just connected!", appName.latin1()); 65// qDebug("App %s just connected!", appName.latin1());
64 const AppLnk* newGuy = m_AppLnkSet->findExec(appName); 66 const AppLnk* newGuy = m_AppLnkSet->findExec(appName);
65 if (newGuy && !newGuy->isPreloaded()) { 67 if (newGuy && !newGuy->isPreloaded()) {
66 addTask(*newGuy); 68 addTask(*newGuy);
67 } 69 }
68 } 70 }
69} 71}
70 72
71void RunningAppBar::removedQcopChannel(const QString& channelName) { 73void RunningAppBar::removedQcopChannel(const QString& channelName) {
72 QString prefix("QPE/Application/"); 74 QString prefix("QPE/Application/");
73 if (channelName.startsWith(prefix)) { 75 if (channelName.startsWith(prefix)) {
74 QString appName = channelName.mid(prefix.length()); 76 QString appName = channelName.mid(prefix.length());
75 qDebug("App %s just disconnected!", appName.latin1()); 77 qDebug("App %s just disconnected!", appName.latin1());
76 const AppLnk* newGuy = m_AppLnkSet->findExec(appName); 78 const AppLnk* newGuy = m_AppLnkSet->findExec(appName);
77 if (newGuy) { 79 if (newGuy) {
78 removeTask(*newGuy); 80 removeTask(*newGuy);
79 } 81 }
80 } 82 }
81} 83}
82 84
83void RunningAppBar::received(const QCString& msg, const QByteArray& data) { 85void RunningAppBar::received(const QCString& msg, const QByteArray& data) {
84 // Since fast apps appear and disappear without disconnecting from their 86 // Since fast apps appear and disappear without disconnecting from their
85 // channel we need to watch for the showing/hiding events and update according. 87 // channel we need to watch for the showing/hiding events and update according.
86 QDataStream stream( data, IO_ReadOnly ); 88 QDataStream stream( data, IO_ReadOnly );
87 if ( msg == "fastAppShowing(QString)") { 89 if ( msg == "fastAppShowing(QString)") {
88 QString appName; 90 QString appName;
89 stream >> appName; 91 stream >> appName;
90 addTask(*m_AppLnkSet->findExec(appName)); 92 addTask(*m_AppLnkSet->findExec(appName));
91 } else if ( msg == "fastAppHiding(QString)") { 93 } else if ( msg == "fastAppHiding(QString)") {
92 QString appName; 94 QString appName;
93 stream >> appName; 95 stream >> appName;
94 removeTask(*m_AppLnkSet->findExec(appName)); 96 removeTask(*m_AppLnkSet->findExec(appName));
95 } 97 }
96} 98}
97 99
98void RunningAppBar::addTask(const AppLnk& appLnk) { 100void RunningAppBar::addTask(const AppLnk& appLnk) {
99// qDebug("Added %s to app list.", appLnk.name().latin1()); 101// qDebug("Added %s to app list.", appLnk.name().latin1());
100 AppLnk* newApp = new AppLnk(appLnk); 102 AppLnk* newApp = new AppLnk(appLnk);
101 newApp->setExec(appLnk.exec()); 103 newApp->setExec(appLnk.exec());
102 m_AppList.prepend(newApp); 104 m_AppList.prepend(newApp);
103 update(); 105 update();
104} 106}
105 107
106void RunningAppBar::removeTask(const AppLnk& appLnk) { 108void RunningAppBar::removeTask(const AppLnk& appLnk) {
107 unsigned int i = 0; 109 unsigned int i = 0;
108 for (; i < m_AppList.count() ; i++) { 110 for (; i < m_AppList.count() ; i++) {
109 AppLnk* target = m_AppList.at(i); 111 AppLnk* target = m_AppList.at(i);
110 if (target->exec() == appLnk.exec()) { 112 if (target->exec() == appLnk.exec()) {
111 qDebug("Removing %s from app list.", appLnk.name().latin1()); 113 qDebug("Removing %s from app list.", appLnk.name().latin1());
112 m_AppList.remove(); 114 m_AppList.remove();
113 delete target; 115 delete target;
114 } 116 }
115 } 117 }
116 update(); 118 update();
117} 119}
118 120
119void RunningAppBar::mousePressEvent(QMouseEvent *e) 121void RunningAppBar::mousePressEvent(QMouseEvent *e)
120{ 122{
121 // Find out if the user is clicking on an app icon... 123 // Find out if the user is clicking on an app icon...
122 // If so, snag the index so when we repaint we show it 124 // If so, snag the index so when we repaint we show it
123 // as highlighed. 125 // as highlighed.
124 m_SelectedAppIndex = 0; 126 m_SelectedAppIndex = 0;
125 int x=0; 127 int x=0;
126 QListIterator<AppLnk> it( m_AppList ); 128 QListIterator<AppLnk> it( m_AppList );
127 for ( ; it.current(); ++it,++m_SelectedAppIndex,x+=spacing ) { 129 for ( ; it.current(); ++it,++m_SelectedAppIndex,x+=spacing ) {
128 if ( x + spacing <= width() ) { 130 if ( x + spacing <= width() ) {
129 if ( e->x() >= x && e->x() < x+spacing ) { 131 if ( e->x() >= x && e->x() < x+spacing ) {
130 if ( m_SelectedAppIndex < (int)m_AppList.count() ) { 132 if ( m_SelectedAppIndex < (int)m_AppList.count() ) {
131 repaint(FALSE); 133 repaint(FALSE);
132 return; 134 return;
133 } 135 }
134 } 136 }
135 } else { 137 } else {
136 break; 138 break;
137 } 139 }
138 } 140 }
139 m_SelectedAppIndex = -1; 141 m_SelectedAppIndex = -1;
140 repaint( FALSE ); 142 repaint( FALSE );
141} 143}
142 144
143void RunningAppBar::mouseReleaseEvent(QMouseEvent *e) 145void RunningAppBar::mouseReleaseEvent(QMouseEvent *e)
144{ 146{
145 if (e->button() == QMouseEvent::RightButton) { 147 if (e->button() == QMouseEvent::RightButton) {
146 return; 148 return;
147 } 149 }
148 if ( m_SelectedAppIndex >= 0 ) { 150 if ( m_SelectedAppIndex >= 0 ) {
149 QString channel = QString("QPE/Application/") + m_AppList.at(m_SelectedAppIndex)->exec(); 151 QString channel = QString("QPE/Application/") + m_AppList.at(m_SelectedAppIndex)->exec();
150 if (QCopChannel::isRegistered(channel.latin1())) { 152 if (QCopChannel::isRegistered(channel.latin1())) {
151// qDebug("%s is running!", m_AppList.at(m_SelectedAppIndex)->exec().latin1()); 153// qDebug("%s is running!", m_AppList.at(m_SelectedAppIndex)->exec().latin1());
152 QCopEnvelope e(channel.latin1(), "raise()"); 154 QCopEnvelope e(channel.latin1(), "raise()");
153 // This class will delete itself after hearing from the app or the timer expiring 155 // This class will delete itself after hearing from the app or the timer expiring
154 (void)new AppMonitor(*m_AppList.at(m_SelectedAppIndex), *this); 156 (void)new AppMonitor(*m_AppList.at(m_SelectedAppIndex), *this);
155 } 157 }
156 else { 158 else {
157 removeTask(*m_AppList.at(m_SelectedAppIndex)); 159 removeTask(*m_AppList.at(m_SelectedAppIndex));
158 } 160 }
159 161
160 m_SelectedAppIndex = -1; 162 m_SelectedAppIndex = -1;
161 update(); 163 update();
162 } 164 }
163} 165}
164 166
165void RunningAppBar::paintEvent( QPaintEvent * ) 167void RunningAppBar::paintEvent( QPaintEvent * )
166{ 168{
167 QPainter p( this ); 169 QPainter p( this );
168 AppLnk *curApp; 170 AppLnk *curApp;
169 int x = 0; 171 int x = 0;
170 int y = (height() - AppLnk::smallIconSize()) / 2; 172 int y = (height() - AppLnk::smallIconSize()) / 2;
171 int i = 0; 173 int i = 0;
172 174
173 //p.fillRect( 0, 0, width(), height(), colorGroup().background() ); 175 //p.fillRect( 0, 0, width(), height(), colorGroup().background() );
174 176
175 QListIterator<AppLnk> it(m_AppList); 177 QListIterator<AppLnk> it(m_AppList);
176 178
177 for (; it.current(); i++, ++it ) { 179 for (; it.current(); i++, ++it ) {
178 if ( x + spacing <= width() ) { 180 if ( x + spacing <= width() ) {
179 curApp = it.current(); 181 curApp = it.current();
180 if ( (int)i == m_SelectedAppIndex ) 182 if ( (int)i == m_SelectedAppIndex )
181 p.fillRect( x, y, spacing, curApp->pixmap().height()+1, colorGroup().highlight() ); 183 p.fillRect( x, y, spacing, curApp->pixmap().height()+1, colorGroup().highlight() );
182 else 184 else
183 // p.eraseRect( x, y, spacing, curApp->pixmap().height()+1 ); 185 // p.eraseRect( x, y, spacing, curApp->pixmap().height()+1 );
184 p.drawPixmap( x, y, curApp->pixmap() ); 186 p.drawPixmap( x, y, curApp->pixmap() );
185 x += spacing; 187 x += spacing;
186 } 188 }
187 } 189 }
188} 190}
189 191
190QSize RunningAppBar::sizeHint() const 192QSize RunningAppBar::sizeHint() const
191{ 193{
192 return QSize( frameWidth(), AppLnk::smallIconSize()+frameWidth()*2+3 ); 194 return QSize( frameWidth(), AppLnk::smallIconSize()+frameWidth()*2+3 );
193} 195}
194 196
195const int AppMonitor::RAISE_TIMEOUT_MS = 500; 197const int AppMonitor::RAISE_TIMEOUT_MS = 500;
196 198
197AppMonitor::AppMonitor(const AppLnk& app, RunningAppBar& owner) 199AppMonitor::AppMonitor(const AppLnk& app, RunningAppBar& owner)
198 : QObject(0L), m_Owner(owner), m_App(app), m_PsProc(0L), m_AppKillerBox(0L) { 200 : QObject(0L), m_Owner(owner), m_App(app), m_PsProc(0L), m_AppKillerBox(0L) {
199 QCopChannel* channel = new QCopChannel( "QPE/System", this ); 201 QCopChannel* channel = new QCopChannel( "QPE/System", this );
200 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 202 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
201 this, SLOT(received(const QCString&, const QByteArray&)) ); 203 this, SLOT(received(const QCString&, const QByteArray&)) );
202 connect(&m_Timer, SIGNAL(timeout()), this, SLOT(timerExpired())); 204 connect(&m_Timer, SIGNAL(timeout()), this, SLOT(timerExpired()));
203 m_Timer.start(RAISE_TIMEOUT_MS, TRUE); 205 m_Timer.start(RAISE_TIMEOUT_MS, TRUE);
204} 206}
205 207
206AppMonitor::~AppMonitor() { 208AppMonitor::~AppMonitor() {
207 if (m_AppKillerBox) { 209 if (m_AppKillerBox) {
208 delete m_AppKillerBox; 210 delete m_AppKillerBox;
209 m_AppKillerBox = 0L; 211 m_AppKillerBox = 0L;
210 } 212 }
211} 213}
212 214
213void AppMonitor::received(const QCString& msg, const QByteArray& data) { 215void AppMonitor::received(const QCString& msg, const QByteArray& data) {
214 QDataStream stream( data, IO_ReadOnly ); 216 QDataStream stream( data, IO_ReadOnly );
215 217
216 if (msg == "appRaised(QString)") { 218 if (msg == "appRaised(QString)") {
217 QString appName; 219 QString appName;
218 stream >> appName; 220 stream >> appName;
219 if (appName == m_App.exec()) { 221 if (appName == m_App.exec()) {
220 // qDebug("Got a heartbeat from %s", appName.latin1()); 222 // qDebug("Got a heartbeat from %s", appName.latin1());
221 m_Timer.stop(); 223 m_Timer.stop();
222 // Check to make sure we're not waiting on user input... 224 // Check to make sure we're not waiting on user input...
223 if (m_AppKillerBox) { 225 if (m_AppKillerBox) {
224 // If we are, we kill the dialog box, and the code waiting on the result 226 // If we are, we kill the dialog box, and the code waiting on the result
225 // will clean us up (basically the user said "no"). 227 // will clean us up (basically the user said "no").
226 delete m_AppKillerBox; 228 delete m_AppKillerBox;
227 m_AppKillerBox = 0L; 229 m_AppKillerBox = 0L;
228 } 230 }
229 else { 231 else {
230 // Ok, we're not waiting on user input, so clean us up now. 232 // Ok, we're not waiting on user input, so clean us up now.
231 // WE DELETE OURSELVES HERE! Don't do anything else!! 233 // WE DELETE OURSELVES HERE! Don't do anything else!!
232 delete this; 234 delete this;
233 } 235 }
234 } 236 }
235 } 237 }
236} 238}
237 239
238void AppMonitor::timerExpired() { 240void AppMonitor::timerExpired() {
239 // qDebug("Checking in on %s", m_App.name().latin1()); 241 // qDebug("Checking in on %s", m_App.name().latin1());
240 // We store this incase the application responds while we're 242 // We store this incase the application responds while we're
241 // waiting for user input so we know not to delete ourselves. This 243 // waiting for user input so we know not to delete ourselves. This
242 // will be cleaned up in the destructor. 244 // will be cleaned up in the destructor.
243 m_AppKillerBox = new QMessageBox(tr("Application Problem"), 245 m_AppKillerBox = new QMessageBox(tr("Application Problem"),
244 tr("<p>%1 is not responding.</p>").arg(m_App.name()) + 246 tr("<p>%1 is not responding.</p>").arg(m_App.name()) +
245 tr("<p>Would you like to force the application to exit?</p>"), 247 tr("<p>Would you like to force the application to exit?</p>"),
246 QMessageBox::Warning, QMessageBox::Yes, 248 QMessageBox::Warning, QMessageBox::Yes,
247 QMessageBox::No | QMessageBox::Default, 249 QMessageBox::No | QMessageBox::Default,
248 QMessageBox::NoButton); 250 QMessageBox::NoButton);
249 if (m_AppKillerBox->exec() == QMessageBox::Yes) { 251 if (m_AppKillerBox->exec() == QMessageBox::Yes) {
250 // qDebug("Killing the app!!! Bwuhahahaha!"); 252 // qDebug("Killing the app!!! Bwuhahahaha!");
251 m_PsProc = new QProcess(QString("ps")); 253 m_PsProc = new QProcess(QString("ps"));
252 m_PsProc->addArgument("h"); 254 m_PsProc->addArgument("h");
253 m_PsProc->addArgument("-C"); 255 m_PsProc->addArgument("-C");
254 m_PsProc->addArgument(m_App.exec()); 256 m_PsProc->addArgument(m_App.exec());
255 m_PsProc->addArgument("-o"); 257 m_PsProc->addArgument("-o");
256 m_PsProc->addArgument("pid"); 258 m_PsProc->addArgument("pid");
257 connect(m_PsProc, SIGNAL(processExited()), this, SLOT(psProcFinished())); 259 connect(m_PsProc, SIGNAL(processExited()), this, SLOT(psProcFinished()));
258 m_PsProc->start(); 260 m_PsProc->start();
259 } 261 }
260 else { 262 else {
261 // qDebug("Wuss.."); 263 // qDebug("Wuss..");
262 // WE DELETE OURSELVES HERE! Don't do anything else!! 264 // WE DELETE OURSELVES HERE! Don't do anything else!!
263 delete this; 265 delete this;
264 } 266 }
265} 267}
266 268
267void AppMonitor::psProcFinished() { 269void AppMonitor::psProcFinished() {
268 QString pid = m_PsProc->readLineStdout(); 270 QString pid = m_PsProc->readLineStdout();
269 delete m_PsProc; 271 delete m_PsProc;
270 m_PsProc = 0L; 272 m_PsProc = 0L;
271 273
272 // qDebug("Killing app %s", pid.latin1()); 274 // qDebug("Killing app %s", pid.latin1());
273 if (pid.isEmpty()) { 275 if (pid.isEmpty()) {
274 // Hmm.. did the application bail before we got there? 276 // Hmm.. did the application bail before we got there?
275 qDebug("AppMonitor: Tried to kill application %s but ps couldn't find it.", m_App.exec().latin1()); 277 qDebug("AppMonitor: Tried to kill application %s but ps couldn't find it.", m_App.exec().latin1());
276 } 278 }
277 else { 279 else {
278 int success = kill(pid.toUInt(), SIGKILL); 280 int success = kill(pid.toUInt(), SIGKILL);
279 if (success == 0) { 281 if (success == 0) {
280 m_Owner.removeTask(m_App); 282 m_Owner.removeTask(m_App);
281 } 283 }
282 else { 284 else {
283 qWarning("Could not kill task %s", m_App.exec().latin1()); 285 qWarning("Could not kill task %s", m_App.exec().latin1());
284 } 286 }
285 } 287 }
286 288
287 // WE DELETE OURSELVES HERE! Don't do anything else!! 289 // WE DELETE OURSELVES HERE! Don't do anything else!!
288 delete this; 290 delete this;
289} 291}
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index d2f5501..dea140d 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,829 +1,827 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#define _XOPEN_SOURCE 20#define _XOPEN_SOURCE
21#include <pwd.h> 21#include <pwd.h>
22#include <sys/types.h> 22#include <sys/types.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <time.h> 25#include <time.h>
26#include <shadow.h> 26#include <shadow.h>
27 27
28/* we need the _OS_LINUX stuff first ! */ 28/* we need the _OS_LINUX stuff first ! */
29#include <qglobal.h> 29#include <qglobal.h>
30 30
31#ifndef _OS_LINUX_ 31#ifndef _OS_LINUX_
32 32
33extern "C" { 33extern "C" {
34#include <uuid/uuid.h> 34#include <uuid/uuid.h>
35#define UUID_H_INCLUDED 35#define UUID_H_INCLUDED
36} 36}
37 37
38#endif // not defined linux 38#endif // not defined linux
39 39
40#if defined(_OS_LINUX_) 40#if defined(_OS_LINUX_)
41#include <shadow.h> 41#include <shadow.h>
42#endif 42#endif
43 43
44#include <qdir.h> 44#include <qdir.h>
45#include <qfile.h> 45#include <qfile.h>
46#include <qtextstream.h> 46#include <qtextstream.h>
47#include <qdatastream.h> 47#include <qdatastream.h>
48#include <qmessagebox.h> 48#include <qmessagebox.h>
49#include <qstringlist.h> 49#include <qstringlist.h>
50#include <qfileinfo.h> 50#include <qfileinfo.h>
51#include <qregexp.h> 51#include <qregexp.h>
52//#include <qpe/qcopchannel_qws.h> 52//#include <qpe/qcopchannel_qws.h>
53#include <qpe/process.h> 53#include <qpe/process.h>
54#include <qpe/global.h> 54#include <qpe/global.h>
55#include <qpe/config.h> 55#include <qpe/config.h>
56#include <qpe/contact.h> 56#include <qpe/contact.h>
57#include <qpe/quuid.h> 57#include <qpe/quuid.h>
58#include <qpe/version.h> 58#include <qpe/version.h>
59#ifdef QWS
60#include <qpe/qcopenvelope_qws.h> 59#include <qpe/qcopenvelope_qws.h>
61#endif
62 60
63#include "transferserver.h" 61#include "transferserver.h"
64#include "qprocess.h" 62#include "qprocess.h"
65 63
66const int block_size = 51200; 64const int block_size = 51200;
67 65
68TransferServer::TransferServer( Q_UINT16 port, QObject *parent , 66TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
69 const char* name ) 67 const char* name )
70 : QServerSocket( port, 1, parent, name ) 68 : QServerSocket( port, 1, parent, name )
71{ 69{
72 if ( !ok() ) 70 if ( !ok() )
73 qWarning( "Failed to bind to port %d", port ); 71 qWarning( "Failed to bind to port %d", port );
74} 72}
75 73
76TransferServer::~TransferServer() 74TransferServer::~TransferServer()
77{ 75{
78 76
79} 77}
80 78
81void TransferServer::newConnection( int socket ) 79void TransferServer::newConnection( int socket )
82{ 80{
83 (void) new ServerPI( socket, this ); 81 (void) new ServerPI( socket, this );
84} 82}
85 83
86/* 84/*
87 * small class in anonymous namespace 85 * small class in anonymous namespace
88 * to generate a QUUid for us 86 * to generate a QUUid for us
89 */ 87 */
90namespace { 88namespace {
91 struct UidGen { 89 struct UidGen {
92 QString uuid(); 90 QString uuid();
93 }; 91 };
94#if !defined(_OS_LINUX_) 92#if !defined(_OS_LINUX_)
95 QString UidGen::uuid() { 93 QString UidGen::uuid() {
96 uuid_t uuid; 94 uuid_t uuid;
97 uuid_generate( uuid ); 95 uuid_generate( uuid );
98 return QUUid( uuid ).toString(); 96 return QUUid( uuid ).toString();
99 } 97 }
100#else 98#else
101 /* 99 /*
102 * linux got a /proc/sys/kernel/random/uuid file 100 * linux got a /proc/sys/kernel/random/uuid file
103 * it'll generate the uuids for us 101 * it'll generate the uuids for us
104 */ 102 */
105 QString UidGen::uuid() { 103 QString UidGen::uuid() {
106 QFile file( "/proc/sys/kernel/random/uuid" ); 104 QFile file( "/proc/sys/kernel/random/uuid" );
107 if (!file.open(IO_ReadOnly ) ) 105 if (!file.open(IO_ReadOnly ) )
108 return QString::null; 106 return QString::null;
109 107
110 QTextStream stream(&file); 108 QTextStream stream(&file);
111 109
112 return "{" + stream.read().stripWhiteSpace() + "}"; 110 return "{" + stream.read().stripWhiteSpace() + "}";
113 } 111 }
114#endif 112#endif
115} 113}
116 114
117QString SyncAuthentication::serverId() 115QString SyncAuthentication::serverId()
118{ 116{
119 Config cfg("Security"); 117 Config cfg("Security");
120 cfg.setGroup("Sync"); 118 cfg.setGroup("Sync");
121 QString r=cfg.readEntry("serverid"); 119 QString r=cfg.readEntry("serverid");
122 if ( r.isEmpty() ) { 120 if ( r.isEmpty() ) {
123 UidGen gen; 121 UidGen gen;
124 r = gen.uuid(); 122 r = gen.uuid();
125 cfg.writeEntry("serverid", r ); 123 cfg.writeEntry("serverid", r );
126 } 124 }
127 return r; 125 return r;
128} 126}
129 127
130QString SyncAuthentication::ownerName() 128QString SyncAuthentication::ownerName()
131{ 129{
132 QString vfilename = Global::applicationFileName("addressbook", 130 QString vfilename = Global::applicationFileName("addressbook",
133 "businesscard.vcf"); 131 "businesscard.vcf");
134 if (QFile::exists(vfilename)) { 132 if (QFile::exists(vfilename)) {
135 Contact c; 133 Contact c;
136 c = Contact::readVCard( vfilename )[0]; 134 c = Contact::readVCard( vfilename )[0];
137 return c.fullName(); 135 return c.fullName();
138 } 136 }
139 137
140 return ""; 138 return "";
141} 139}
142 140
143QString SyncAuthentication::loginName() 141QString SyncAuthentication::loginName()
144{ 142{
145 struct passwd *pw; 143 struct passwd *pw;
146 pw = getpwuid( geteuid() ); 144 pw = getpwuid( geteuid() );
147 return QString::fromLocal8Bit( pw->pw_name ); 145 return QString::fromLocal8Bit( pw->pw_name );
148} 146}
149 147
150int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 148int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
151{ 149{
152 Config cfg("Security"); 150 Config cfg("Security");
153 cfg.setGroup("Sync"); 151 cfg.setGroup("Sync");
154// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 152// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
155 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); 153 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100);
156 154
157// QHostAddress allowed; 155// QHostAddress allowed;
158// allowed.setAddress(allowedstr); 156// allowed.setAddress(allowedstr);
159// uint auth_peer = allowed.ip4Addr(); 157// uint auth_peer = allowed.ip4Addr();
160 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 158 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
161 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 159 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
162 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); 160 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits));
163 return (peeraddress.ip4Addr() & mask) == auth_peer; 161 return (peeraddress.ip4Addr() & mask) == auth_peer;
164} 162}
165 163
166bool SyncAuthentication::checkUser( const QString& user ) 164bool SyncAuthentication::checkUser( const QString& user )
167{ 165{
168 if ( user.isEmpty() ) return FALSE; 166 if ( user.isEmpty() ) return FALSE;
169 QString euser = loginName(); 167 QString euser = loginName();
170 return user == euser; 168 return user == euser;
171} 169}
172 170
173bool SyncAuthentication::checkPassword( const QString& password ) 171bool SyncAuthentication::checkPassword( const QString& password )
174{ 172{
175#ifdef ALLOW_UNIX_USER_FTP 173#ifdef ALLOW_UNIX_USER_FTP
176 // First, check system password... 174 // First, check system password...
177 175
178 struct passwd *pw = 0; 176 struct passwd *pw = 0;
179 struct spwd *spw = 0; 177 struct spwd *spw = 0;
180 178
181 pw = getpwuid( geteuid() ); 179 pw = getpwuid( geteuid() );
182 spw = getspnam( pw->pw_name ); 180 spw = getspnam( pw->pw_name );
183 181
184 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 182 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
185 if ( cpwd == "x" && spw ) 183 if ( cpwd == "x" && spw )
186 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 184 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
187 185
188 // Note: some systems use more than crypt for passwords. 186 // Note: some systems use more than crypt for passwords.
189 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 187 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
190 if ( cpwd == cpassword ) 188 if ( cpwd == cpassword )
191 return TRUE; 189 return TRUE;
192#endif 190#endif
193 191
194 static int lastdenial=0; 192 static int lastdenial=0;
195 static int denials=0; 193 static int denials=0;
196 int now = time(0); 194 int now = time(0);
197 195
198 // Detect old Qtopia Desktop (no password) 196 // Detect old Qtopia Desktop (no password)
199 if ( password.isEmpty() ) { 197 if ( password.isEmpty() ) {
200 if ( denials < 1 || now > lastdenial+600 ) { 198 if ( denials < 1 || now > lastdenial+600 ) {
201 QMessageBox::warning( 0,tr("Sync Connection"), 199 QMessageBox::warning( 0,tr("Sync Connection"),
202 tr("<p>An unauthorized system is requesting access to this device." 200 tr("<p>An unauthorized system is requesting access to this device."
203 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 201 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
204 "please upgrade."), 202 "please upgrade."),
205 tr("Deny") ); 203 tr("Deny") );
206 denials++; 204 denials++;
207 lastdenial=now; 205 lastdenial=now;
208 } 206 }
209 return FALSE; 207 return FALSE;
210 } 208 }
211 209
212 // Second, check sync password... 210 // Second, check sync password...
213 QString pass = password.left(6); 211 QString pass = password.left(6);
214 /* old QtopiaDesktops are sending 212 /* old QtopiaDesktops are sending
215 * rootme newer versions got a Qtopia 213 * rootme newer versions got a Qtopia
216 * prefixed. Qtopia prefix will suceed 214 * prefixed. Qtopia prefix will suceed
217 * until the sync software syncs up 215 * until the sync software syncs up
218 * FIXME 216 * FIXME
219 */ 217 */
220 if ( pass == "rootme" || pass == "Qtopia") { 218 if ( pass == "rootme" || pass == "Qtopia") {
221 219
222 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); 220 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
223 Config cfg("Security"); 221 Config cfg("Security");
224 cfg.setGroup("Sync"); 222 cfg.setGroup("Sync");
225 QString pwds = cfg.readEntry("Passwords"); 223 QString pwds = cfg.readEntry("Passwords");
226 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) 224 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) )
227 return TRUE; 225 return TRUE;
228 226
229 // Unrecognized system. Be careful... 227 // Unrecognized system. Be careful...
230 228
231 if ( (denials > 2 && now < lastdenial+600) 229 if ( (denials > 2 && now < lastdenial+600)
232 || QMessageBox::warning(0,tr("Sync Connection"), 230 || QMessageBox::warning(0,tr("Sync Connection"),
233 tr("<p>An unrecognized system is requesting access to this device." 231 tr("<p>An unrecognized system is requesting access to this device."
234 "<p>If you have just initiated a Sync for the first time, this is normal."), 232 "<p>If you have just initiated a Sync for the first time, this is normal."),
235 tr("Allow"),tr("Deny"))==1 ) 233 tr("Allow"),tr("Deny"))==1 )
236 { 234 {
237 denials++; 235 denials++;
238 lastdenial=now; 236 lastdenial=now;
239 return FALSE; 237 return FALSE;
240 } else { 238 } else {
241 denials=0; 239 denials=0;
242 cfg.writeEntry("Passwords",pwds+" "+cpassword); 240 cfg.writeEntry("Passwords",pwds+" "+cpassword);
243 return TRUE; 241 return TRUE;
244 } 242 }
245 } 243 }
246 244
247 return FALSE; 245 return FALSE;
248} 246}
249 247
250ServerPI::ServerPI( int socket, QObject *parent , const char* name ) 248ServerPI::ServerPI( int socket, QObject *parent , const char* name )
251 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) 249 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 )
252{ 250{
253 state = Connected; 251 state = Connected;
254 252
255 setSocket( socket ); 253 setSocket( socket );
256 254
257 peerport = peerPort(); 255 peerport = peerPort();
258 peeraddress = peerAddress(); 256 peeraddress = peerAddress();
259 257
260#ifndef INSECURE 258#ifndef INSECURE
261 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 259 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
262 state = Forbidden; 260 state = Forbidden;
263 startTimer( 0 ); 261 startTimer( 0 );
264 } else 262 } else
265#endif 263#endif
266 { 264 {
267 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 265 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
268 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 266 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
269 267
270 passiv = FALSE; 268 passiv = FALSE;
271 for( int i = 0; i < 4; i++ ) 269 for( int i = 0; i < 4; i++ )
272 wait[i] = FALSE; 270 wait[i] = FALSE;
273 271
274 send( "220 Qtopia " QPE_VERSION " FTP Server" ); 272 send( "220 Qtopia " QPE_VERSION " FTP Server" );
275 state = Wait_USER; 273 state = Wait_USER;
276 274
277 dtp = new ServerDTP( this ); 275 dtp = new ServerDTP( this );
278 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 276 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
279 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 277 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
280 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 278 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) );
281 279
282 280
283 directory = QDir::currentDirPath(); 281 directory = QDir::currentDirPath();
284 282
285 static int p = 1024; 283 static int p = 1024;
286 284
287 while ( !serversocket || !serversocket->ok() ) { 285 while ( !serversocket || !serversocket->ok() ) {
288 delete serversocket; 286 delete serversocket;
289 serversocket = new ServerSocket( ++p, this ); 287 serversocket = new ServerSocket( ++p, this );
290 } 288 }
291 connect( serversocket, SIGNAL( newIncomming( int ) ), 289 connect( serversocket, SIGNAL( newIncomming( int ) ),
292 SLOT( newConnection( int ) ) ); 290 SLOT( newConnection( int ) ) );
293 } 291 }
294} 292}
295 293
296ServerPI::~ServerPI() 294ServerPI::~ServerPI()
297{ 295{
298 296
299} 297}
300 298
301void ServerPI::connectionClosed() 299void ServerPI::connectionClosed()
302{ 300{
303 // qDebug( "Debug: Connection closed" ); 301 // qDebug( "Debug: Connection closed" );
304 delete this; 302 delete this;
305} 303}
306 304
307void ServerPI::send( const QString& msg ) 305void ServerPI::send( const QString& msg )
308{ 306{
309 QTextStream os( this ); 307 QTextStream os( this );
310 os << msg << endl; 308 os << msg << endl;
311 //qDebug( "Reply: %s", msg.latin1() ); 309 //qDebug( "Reply: %s", msg.latin1() );
312} 310}
313 311
314void ServerPI::read() 312void ServerPI::read()
315{ 313{
316 while ( canReadLine() ) 314 while ( canReadLine() )
317 process( readLine().stripWhiteSpace() ); 315 process( readLine().stripWhiteSpace() );
318} 316}
319 317
320bool ServerPI::checkReadFile( const QString& file ) 318bool ServerPI::checkReadFile( const QString& file )
321{ 319{
322 QString filename; 320 QString filename;
323 321
324 if ( file[0] != "/" ) 322 if ( file[0] != "/" )
325 filename = directory.path() + "/" + file; 323 filename = directory.path() + "/" + file;
326 else 324 else
327 filename = file; 325 filename = file;
328 326
329 QFileInfo fi( filename ); 327 QFileInfo fi( filename );
330 return ( fi.exists() && fi.isReadable() ); 328 return ( fi.exists() && fi.isReadable() );
331} 329}
332 330
333bool ServerPI::checkWriteFile( const QString& file ) 331bool ServerPI::checkWriteFile( const QString& file )
334{ 332{
335 QString filename; 333 QString filename;
336 334
337 if ( file[0] != "/" ) 335 if ( file[0] != "/" )
338 filename = directory.path() + "/" + file; 336 filename = directory.path() + "/" + file;
339 else 337 else
340 filename = file; 338 filename = file;
341 339
342 QFileInfo fi( filename ); 340 QFileInfo fi( filename );
343 341
344 if ( fi.exists() ) 342 if ( fi.exists() )
345 if ( !QFile( filename ).remove() ) 343 if ( !QFile( filename ).remove() )
346 return FALSE; 344 return FALSE;
347 return TRUE; 345 return TRUE;
348} 346}
349 347
350void ServerPI::process( const QString& message ) 348void ServerPI::process( const QString& message )
351{ 349{
352 //qDebug( "Command: %s", message.latin1() ); 350 //qDebug( "Command: %s", message.latin1() );
353 351
354 // split message using "," as separator 352 // split message using "," as separator
355 QStringList msg = QStringList::split( " ", message ); 353 QStringList msg = QStringList::split( " ", message );
356 if ( msg.isEmpty() ) return; 354 if ( msg.isEmpty() ) return;
357 355
358 // command token 356 // command token
359 QString cmd = msg[0].upper(); 357 QString cmd = msg[0].upper();
360 358
361 // argument token 359 // argument token
362 QString arg; 360 QString arg;
363 if ( msg.count() >= 2 ) 361 if ( msg.count() >= 2 )
364 arg = msg[1]; 362 arg = msg[1];
365 363
366 // full argument string 364 // full argument string
367 QString args; 365 QString args;
368 if ( msg.count() >= 2 ) { 366 if ( msg.count() >= 2 ) {
369 QStringList copy( msg ); 367 QStringList copy( msg );
370 // FIXME: for Qt3 368 // FIXME: for Qt3
371 // copy.pop_front() 369 // copy.pop_front()
372 copy.remove( copy.begin() ); 370 copy.remove( copy.begin() );
373 args = copy.join( " " ); 371 args = copy.join( " " );
374 } 372 }
375 373
376 //qDebug( "args: %s", args.latin1() ); 374 //qDebug( "args: %s", args.latin1() );
377 375
378 // we always respond to QUIT, regardless of state 376 // we always respond to QUIT, regardless of state
379 if ( cmd == "QUIT" ) { 377 if ( cmd == "QUIT" ) {
380 send( "211 Good bye!" ); 378 send( "211 Good bye!" );
381 delete this; 379 delete this;
382 return; 380 return;
383 } 381 }
384 382
385 // connected to client 383 // connected to client
386 if ( Connected == state ) 384 if ( Connected == state )
387 return; 385 return;
388 386
389 // waiting for user name 387 // waiting for user name
390 if ( Wait_USER == state ) { 388 if ( Wait_USER == state ) {
391 389
392 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 390 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
393 send( "530 Please login with USER and PASS" ); 391 send( "530 Please login with USER and PASS" );
394 return; 392 return;
395 } 393 }
396 send( "331 User name ok, need password" ); 394 send( "331 User name ok, need password" );
397 state = Wait_PASS; 395 state = Wait_PASS;
398 return; 396 return;
399 } 397 }
400 398
401 // waiting for password 399 // waiting for password
402 if ( Wait_PASS == state ) { 400 if ( Wait_PASS == state ) {
403 401
404 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 402 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
405 send( "530 Please login with USER and PASS" ); 403 send( "530 Please login with USER and PASS" );
406 return; 404 return;
407 } 405 }
408 send( "230 User logged in, proceed" ); 406 send( "230 User logged in, proceed" );
409 state = Ready; 407 state = Ready;
410 return; 408 return;
411 } 409 }
412 410
413 // ACCESS CONTROL COMMANDS 411 // ACCESS CONTROL COMMANDS
414 412
415 413
416 // account (ACCT) 414 // account (ACCT)
417 if ( cmd == "ACCT" ) { 415 if ( cmd == "ACCT" ) {
418 // even wu-ftp does not support it 416 // even wu-ftp does not support it
419 send( "502 Command not implemented" ); 417 send( "502 Command not implemented" );
420 } 418 }
421 419
422 // change working directory (CWD) 420 // change working directory (CWD)
423 else if ( cmd == "CWD" ) { 421 else if ( cmd == "CWD" ) {
424 422
425 if ( !args.isEmpty() ) { 423 if ( !args.isEmpty() ) {
426 if ( directory.cd( args, TRUE ) ) 424 if ( directory.cd( args, TRUE ) )
427 send( "250 Requested file action okay, completed" ); 425 send( "250 Requested file action okay, completed" );
428 else 426 else
429 send( "550 Requested action not taken" ); 427 send( "550 Requested action not taken" );
430 } 428 }
431 else 429 else
432 send( "500 Syntax error, command unrecognized" ); 430 send( "500 Syntax error, command unrecognized" );
433 } 431 }
434 432
435 // change to parent directory (CDUP) 433 // change to parent directory (CDUP)
436 else if ( cmd == "CDUP" ) { 434 else if ( cmd == "CDUP" ) {
437 if ( directory.cdUp() ) 435 if ( directory.cdUp() )
438 send( "250 Requested file action okay, completed" ); 436 send( "250 Requested file action okay, completed" );
439 else 437 else
440 send( "550 Requested action not taken" ); 438 send( "550 Requested action not taken" );
441 } 439 }
442 440
443 // structure mount (SMNT) 441 // structure mount (SMNT)
444 else if ( cmd == "SMNT" ) { 442 else if ( cmd == "SMNT" ) {
445 // even wu-ftp does not support it 443 // even wu-ftp does not support it
446 send( "502 Command not implemented" ); 444 send( "502 Command not implemented" );
447 } 445 }
448 446
449 // reinitialize (REIN) 447 // reinitialize (REIN)
450 else if ( cmd == "REIN" ) { 448 else if ( cmd == "REIN" ) {
451 // even wu-ftp does not support it 449 // even wu-ftp does not support it
452 send( "502 Command not implemented" ); 450 send( "502 Command not implemented" );
453 } 451 }
454 452
455 453
456 // TRANSFER PARAMETER COMMANDS 454 // TRANSFER PARAMETER COMMANDS
457 455
458 456
459 // data port (PORT) 457 // data port (PORT)
460 else if ( cmd == "PORT" ) { 458 else if ( cmd == "PORT" ) {
461 if ( parsePort( arg ) ) 459 if ( parsePort( arg ) )
462 send( "200 Command okay" ); 460 send( "200 Command okay" );
463 else 461 else
464 send( "500 Syntax error, command unrecognized" ); 462 send( "500 Syntax error, command unrecognized" );
465 } 463 }
466 464
467 // passive (PASV) 465 // passive (PASV)
468 else if ( cmd == "PASV" ) { 466 else if ( cmd == "PASV" ) {
469 passiv = TRUE; 467 passiv = TRUE;
470 send( "227 Entering Passive Mode (" 468 send( "227 Entering Passive Mode ("
471 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 469 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
472 + QString::number( ( serversocket->port() ) >> 8 ) + "," 470 + QString::number( ( serversocket->port() ) >> 8 ) + ","
473 + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); 471 + QString::number( ( serversocket->port() ) & 0xFF ) +")" );
474 } 472 }
475 473
476 // representation type (TYPE) 474 // representation type (TYPE)
477 else if ( cmd == "TYPE" ) { 475 else if ( cmd == "TYPE" ) {
478 if ( arg.upper() == "A" || arg.upper() == "I" ) 476 if ( arg.upper() == "A" || arg.upper() == "I" )
479 send( "200 Command okay" ); 477 send( "200 Command okay" );
480 else 478 else
481 send( "504 Command not implemented for that parameter" ); 479 send( "504 Command not implemented for that parameter" );
482 } 480 }
483 481
484 // file structure (STRU) 482 // file structure (STRU)
485 else if ( cmd == "STRU" ) { 483 else if ( cmd == "STRU" ) {
486 if ( arg.upper() == "F" ) 484 if ( arg.upper() == "F" )
487 send( "200 Command okay" ); 485 send( "200 Command okay" );
488 else 486 else
489 send( "504 Command not implemented for that parameter" ); 487 send( "504 Command not implemented for that parameter" );
490 } 488 }
491 489
492 // transfer mode (MODE) 490 // transfer mode (MODE)
493 else if ( cmd == "MODE" ) { 491 else if ( cmd == "MODE" ) {
494 if ( arg.upper() == "S" ) 492 if ( arg.upper() == "S" )
495 send( "200 Command okay" ); 493 send( "200 Command okay" );
496 else 494 else
497 send( "504 Command not implemented for that parameter" ); 495 send( "504 Command not implemented for that parameter" );
498 } 496 }
499 497
500 498
501 // FTP SERVICE COMMANDS 499 // FTP SERVICE COMMANDS
502 500
503 501
504 // retrieve (RETR) 502 // retrieve (RETR)
505 else if ( cmd == "RETR" ) 503 else if ( cmd == "RETR" )
506 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 504 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
507 || backupRestoreGzip( absFilePath( args ) ) ) { 505 || backupRestoreGzip( absFilePath( args ) ) ) {
508 send( "150 File status okay" ); 506 send( "150 File status okay" );
509 sendFile( absFilePath( args ) ); 507 sendFile( absFilePath( args ) );
510 } 508 }
511 else { 509 else {
512 qDebug("550 Requested action not taken"); 510 qDebug("550 Requested action not taken");
513 send( "550 Requested action not taken" ); 511 send( "550 Requested action not taken" );
514 } 512 }
515 513
516 // store (STOR) 514 // store (STOR)
517 else if ( cmd == "STOR" ) 515 else if ( cmd == "STOR" )
518 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 516 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
519 send( "150 File status okay" ); 517 send( "150 File status okay" );
520 retrieveFile( absFilePath( args ) ); 518 retrieveFile( absFilePath( args ) );
521 } 519 }
522 else 520 else
523 send( "550 Requested action not taken" ); 521 send( "550 Requested action not taken" );
524 522
525 // store unique (STOU) 523 // store unique (STOU)
526 else if ( cmd == "STOU" ) { 524 else if ( cmd == "STOU" ) {
527 send( "502 Command not implemented" ); 525 send( "502 Command not implemented" );
528 } 526 }
529 527
530 // append (APPE) 528 // append (APPE)
531 else if ( cmd == "APPE" ) { 529 else if ( cmd == "APPE" ) {
532 send( "502 Command not implemented" ); 530 send( "502 Command not implemented" );
533 } 531 }
534 532
535 // allocate (ALLO) 533 // allocate (ALLO)
536 else if ( cmd == "ALLO" ) { 534 else if ( cmd == "ALLO" ) {
537 send( "200 Command okay" ); 535 send( "200 Command okay" );
538 } 536 }
539 537
540 // restart (REST) 538 // restart (REST)
541 else if ( cmd == "REST" ) { 539 else if ( cmd == "REST" ) {
542 send( "502 Command not implemented" ); 540 send( "502 Command not implemented" );
543 } 541 }
544 542
545 // rename from (RNFR) 543 // rename from (RNFR)
546 else if ( cmd == "RNFR" ) { 544 else if ( cmd == "RNFR" ) {
547 renameFrom = QString::null; 545 renameFrom = QString::null;
548 if ( args.isEmpty() ) 546 if ( args.isEmpty() )
549 send( "500 Syntax error, command unrecognized" ); 547 send( "500 Syntax error, command unrecognized" );
550 else { 548 else {
551 QFile file( absFilePath( args ) ); 549 QFile file( absFilePath( args ) );
552 if ( file.exists() ) { 550 if ( file.exists() ) {
553 send( "350 File exists, ready for destination name" ); 551 send( "350 File exists, ready for destination name" );
554 renameFrom = absFilePath( args ); 552 renameFrom = absFilePath( args );
555 } 553 }
556 else 554 else
557 send( "550 Requested action not taken" ); 555 send( "550 Requested action not taken" );
558 } 556 }
559 } 557 }
560 558
561 // rename to (RNTO) 559 // rename to (RNTO)
562 else if ( cmd == "RNTO" ) { 560 else if ( cmd == "RNTO" ) {
563 if ( lastCommand != "RNFR" ) 561 if ( lastCommand != "RNFR" )
564 send( "503 Bad sequence of commands" ); 562 send( "503 Bad sequence of commands" );
565 else if ( args.isEmpty() ) 563 else if ( args.isEmpty() )
566 send( "500 Syntax error, command unrecognized" ); 564 send( "500 Syntax error, command unrecognized" );
567 else { 565 else {
568 QDir dir( absFilePath( args ) ); 566 QDir dir( absFilePath( args ) );
569 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 567 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
570 send( "250 Requested file action okay, completed." ); 568 send( "250 Requested file action okay, completed." );
571 else 569 else
572 send( "550 Requested action not taken" ); 570 send( "550 Requested action not taken" );
573 } 571 }
574 } 572 }
575 573
576 // abort (ABOR) 574 // abort (ABOR)
577 else if ( cmd.contains( "ABOR" ) ) { 575 else if ( cmd.contains( "ABOR" ) ) {
578 dtp->close(); 576 dtp->close();
579 if ( dtp->dtpMode() != ServerDTP::Idle ) 577 if ( dtp->dtpMode() != ServerDTP::Idle )
580 send( "426 Connection closed; transfer aborted" ); 578 send( "426 Connection closed; transfer aborted" );
581 else 579 else
582 send( "226 Closing data connection" ); 580 send( "226 Closing data connection" );
583 } 581 }
584 582
585 // delete (DELE) 583 // delete (DELE)
586 else if ( cmd == "DELE" ) { 584 else if ( cmd == "DELE" ) {
587 if ( args.isEmpty() ) 585 if ( args.isEmpty() )
588 send( "500 Syntax error, command unrecognized" ); 586 send( "500 Syntax error, command unrecognized" );
589 else { 587 else {
590 QFile file( absFilePath( args ) ) ; 588 QFile file( absFilePath( args ) ) ;
591 if ( file.remove() ) { 589 if ( file.remove() ) {
592 send( "250 Requested file action okay, completed" ); 590 send( "250 Requested file action okay, completed" );
593 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 591 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
594 e << file.name(); 592 e << file.name();
595 } else { 593 } else {
596 send( "550 Requested action not taken" ); 594 send( "550 Requested action not taken" );
597 } 595 }
598 } 596 }
599 } 597 }
600 598
601 // remove directory (RMD) 599 // remove directory (RMD)
602 else if ( cmd == "RMD" ) { 600 else if ( cmd == "RMD" ) {
603 if ( args.isEmpty() ) 601 if ( args.isEmpty() )
604 send( "500 Syntax error, command unrecognized" ); 602 send( "500 Syntax error, command unrecognized" );
605 else { 603 else {
606 QDir dir; 604 QDir dir;
607 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 605 if ( dir.rmdir( absFilePath( args ), TRUE ) )
608 send( "250 Requested file action okay, completed" ); 606 send( "250 Requested file action okay, completed" );
609 else 607 else
610 send( "550 Requested action not taken" ); 608 send( "550 Requested action not taken" );
611 } 609 }
612 } 610 }
613 611
614 // make directory (MKD) 612 // make directory (MKD)
615 else if ( cmd == "MKD" ) { 613 else if ( cmd == "MKD" ) {
616 if ( args.isEmpty() ) { 614 if ( args.isEmpty() ) {
617 qDebug(" Error: no arg"); 615 qDebug(" Error: no arg");
618 send( "500 Syntax error, command unrecognized" ); 616 send( "500 Syntax error, command unrecognized" );
619 } 617 }
620 else { 618 else {
621 QDir dir; 619 QDir dir;
622 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 620 if ( dir.mkdir( absFilePath( args ), TRUE ) )
623 send( "250 Requested file action okay, completed." ); 621 send( "250 Requested file action okay, completed." );
624 else 622 else
625 send( "550 Requested action not taken" ); 623 send( "550 Requested action not taken" );
626 } 624 }
627 } 625 }
628 626
629 // print working directory (PWD) 627 // print working directory (PWD)
630 else if ( cmd == "PWD" ) { 628 else if ( cmd == "PWD" ) {
631 send( "257 \"" + directory.path() +"\"" ); 629 send( "257 \"" + directory.path() +"\"" );
632 } 630 }
633 631
634 // list (LIST) 632 // list (LIST)
635 else if ( cmd == "LIST" ) { 633 else if ( cmd == "LIST" ) {
636 if ( sendList( absFilePath( args ) ) ) 634 if ( sendList( absFilePath( args ) ) )
637 send( "150 File status okay" ); 635 send( "150 File status okay" );
638 else 636 else
639 send( "500 Syntax error, command unrecognized" ); 637 send( "500 Syntax error, command unrecognized" );
640 } 638 }
641 639
642 // size (SIZE) 640 // size (SIZE)
643 else if ( cmd == "SIZE" ) { 641 else if ( cmd == "SIZE" ) {
644 QString filePath = absFilePath( args ); 642 QString filePath = absFilePath( args );
645 QFileInfo fi( filePath ); 643 QFileInfo fi( filePath );
646 bool gzipfile = backupRestoreGzip( filePath ); 644 bool gzipfile = backupRestoreGzip( filePath );
647 if ( !fi.exists() && !gzipfile ) 645 if ( !fi.exists() && !gzipfile )
648 send( "500 Syntax error, command unrecognized" ); 646 send( "500 Syntax error, command unrecognized" );
649 else { 647 else {
650 if ( !gzipfile ) 648 if ( !gzipfile )
651 send( "213 " + QString::number( fi.size() ) ); 649 send( "213 " + QString::number( fi.size() ) );
652 else { 650 else {
653 Process duproc( QString("du") ); 651 Process duproc( QString("du") );
654 duproc.addArgument("-s"); 652 duproc.addArgument("-s");
655 QString in, out; 653 QString in, out;
656 if ( !duproc.exec(in, out) ) { 654 if ( !duproc.exec(in, out) ) {
657 qDebug("du process failed; just sending back 1K"); 655 qDebug("du process failed; just sending back 1K");
658 send( "213 1024"); 656 send( "213 1024");
659 } 657 }
660 else { 658 else {
661 QString size = out.left( out.find("\t") ); 659 QString size = out.left( out.find("\t") );
662 int guess = size.toInt()/5; 660 int guess = size.toInt()/5;
663 if ( filePath.contains("doc") ) 661 if ( filePath.contains("doc") )
664 guess *= 1000; 662 guess *= 1000;
665 qDebug("sending back gzip guess of %d", guess); 663 qDebug("sending back gzip guess of %d", guess);
666 send( "213 " + QString::number(guess) ); 664 send( "213 " + QString::number(guess) );
667 } 665 }
668 } 666 }
669 } 667 }
670 } 668 }
671 // name list (NLST) 669 // name list (NLST)
672 else if ( cmd == "NLST" ) { 670 else if ( cmd == "NLST" ) {
673 send( "502 Command not implemented" ); 671 send( "502 Command not implemented" );
674 } 672 }
675 673
676 // site parameters (SITE) 674 // site parameters (SITE)
677 else if ( cmd == "SITE" ) { 675 else if ( cmd == "SITE" ) {
678 send( "502 Command not implemented" ); 676 send( "502 Command not implemented" );
679 } 677 }
680 678
681 // system (SYST) 679 // system (SYST)
682 else if ( cmd == "SYST" ) { 680 else if ( cmd == "SYST" ) {
683 send( "215 UNIX Type: L8" ); 681 send( "215 UNIX Type: L8" );
684 } 682 }
685 683
686 // status (STAT) 684 // status (STAT)
687 else if ( cmd == "STAT" ) { 685 else if ( cmd == "STAT" ) {
688 send( "502 Command not implemented" ); 686 send( "502 Command not implemented" );
689 } 687 }
690 688
691 // help (HELP ) 689 // help (HELP )
692 else if ( cmd == "HELP" ) { 690 else if ( cmd == "HELP" ) {
693 send( "502 Command not implemented" ); 691 send( "502 Command not implemented" );
694 } 692 }
695 693
696 // noop (NOOP) 694 // noop (NOOP)
697 else if ( cmd == "NOOP" ) { 695 else if ( cmd == "NOOP" ) {
698 send( "200 Command okay" ); 696 send( "200 Command okay" );
699 } 697 }
700 698
701 // not implemented 699 // not implemented
702 else 700 else
703 send( "502 Command not implemented" ); 701 send( "502 Command not implemented" );
704 702
705 lastCommand = cmd; 703 lastCommand = cmd;
706} 704}
707 705
708bool ServerPI::backupRestoreGzip( const QString &file ) 706bool ServerPI::backupRestoreGzip( const QString &file )
709{ 707{
710 return (file.find( "backup" ) != -1 && 708 return (file.find( "backup" ) != -1 &&
711 file.findRev( ".tgz" ) == (int)file.length()-4 ); 709 file.findRev( ".tgz" ) == (int)file.length()-4 );
712} 710}
713 711
714bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 712bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
715{ 713{
716 if ( file.find( "backup" ) != -1 && 714 if ( file.find( "backup" ) != -1 &&
717 file.findRev( ".tgz" ) == (int)file.length()-4 ) { 715 file.findRev( ".tgz" ) == (int)file.length()-4 ) {
718 QFileInfo info( file ); 716 QFileInfo info( file );
719 targets = info.dirPath( TRUE ); 717 targets = info.dirPath( TRUE );
720 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), 718 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(),
721 targets.join(" ").latin1() ); 719 targets.join(" ").latin1() );
722 return true; 720 return true;
723 } 721 }
724 return false; 722 return false;
725} 723}
726 724
727void ServerPI::sendFile( const QString& file ) 725void ServerPI::sendFile( const QString& file )
728{ 726{
729 if ( passiv ) { 727 if ( passiv ) {
730 wait[SendFile] = TRUE; 728 wait[SendFile] = TRUE;
731 waitfile = file; 729 waitfile = file;
732 if ( waitsocket ) 730 if ( waitsocket )
733 newConnection( waitsocket ); 731 newConnection( waitsocket );
734 } 732 }
735 else { 733 else {
736 QStringList targets; 734 QStringList targets;
737 if ( backupRestoreGzip( file, targets ) ) 735 if ( backupRestoreGzip( file, targets ) )
738 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 736 dtp->sendGzipFile( file, targets, peeraddress, peerport );
739 else dtp->sendFile( file, peeraddress, peerport ); 737 else dtp->sendFile( file, peeraddress, peerport );
740 } 738 }
741} 739}
742 740
743void ServerPI::retrieveFile( const QString& file ) 741void ServerPI::retrieveFile( const QString& file )
744{ 742{
745 if ( passiv ) { 743 if ( passiv ) {
746 wait[RetrieveFile] = TRUE; 744 wait[RetrieveFile] = TRUE;
747 waitfile = file; 745 waitfile = file;
748 if ( waitsocket ) 746 if ( waitsocket )
749 newConnection( waitsocket ); 747 newConnection( waitsocket );
750 } 748 }
751 else { 749 else {
752 QStringList targets; 750 QStringList targets;
753 if ( backupRestoreGzip( file, targets ) ) 751 if ( backupRestoreGzip( file, targets ) )
754 dtp->retrieveGzipFile( file, peeraddress, peerport ); 752 dtp->retrieveGzipFile( file, peeraddress, peerport );
755 else 753 else
756 dtp->retrieveFile( file, peeraddress, peerport ); 754 dtp->retrieveFile( file, peeraddress, peerport );
757 } 755 }
758} 756}
759 757
760bool ServerPI::parsePort( const QString& pp ) 758bool ServerPI::parsePort( const QString& pp )
761{ 759{
762 QStringList p = QStringList::split( ",", pp ); 760 QStringList p = QStringList::split( ",", pp );
763 if ( p.count() != 6 ) return FALSE; 761 if ( p.count() != 6 ) return FALSE;
764 762
765 // h1,h2,h3,h4,p1,p2 763 // h1,h2,h3,h4,p1,p2
766 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 764 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
767 ( p[2].toInt() << 8 ) + p[3].toInt() ); 765 ( p[2].toInt() << 8 ) + p[3].toInt() );
768 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 766 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
769 return TRUE; 767 return TRUE;
770} 768}
771 769
772void ServerPI::dtpCompleted() 770void ServerPI::dtpCompleted()
773{ 771{
774 send( "226 Closing data connection, file transfer successful" ); 772 send( "226 Closing data connection, file transfer successful" );
775 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 773 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
776 QString fn = dtp->fileName(); 774 QString fn = dtp->fileName();
777 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { 775 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
778 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 776 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
779 e << fn; 777 e << fn;
780 } 778 }
781 } 779 }
782 waitsocket = 0; 780 waitsocket = 0;
783 dtp->close(); 781 dtp->close();
784} 782}
785 783
786void ServerPI::dtpFailed() 784void ServerPI::dtpFailed()
787{ 785{
788 dtp->close(); 786 dtp->close();
789 waitsocket = 0; 787 waitsocket = 0;
790 send( "451 Requested action aborted: local error in processing" ); 788 send( "451 Requested action aborted: local error in processing" );
791} 789}
792 790
793void ServerPI::dtpError( int ) 791void ServerPI::dtpError( int )
794{ 792{
795 dtp->close(); 793 dtp->close();
796 waitsocket = 0; 794 waitsocket = 0;
797 send( "451 Requested action aborted: local error in processing" ); 795 send( "451 Requested action aborted: local error in processing" );
798} 796}
799 797
800bool ServerPI::sendList( const QString& arg ) 798bool ServerPI::sendList( const QString& arg )
801{ 799{
802 QByteArray listing; 800 QByteArray listing;
803 QBuffer buffer( listing ); 801 QBuffer buffer( listing );
804 802
805 if ( !buffer.open( IO_WriteOnly ) ) 803 if ( !buffer.open( IO_WriteOnly ) )
806 return FALSE; 804 return FALSE;
807 805
808 QTextStream ts( &buffer ); 806 QTextStream ts( &buffer );
809 QString fn = arg; 807 QString fn = arg;
810 808
811 if ( fn.isEmpty() ) 809 if ( fn.isEmpty() )
812 fn = directory.path(); 810 fn = directory.path();
813 811
814 QFileInfo fi( fn ); 812 QFileInfo fi( fn );
815 if ( !fi.exists() ) return FALSE; 813 if ( !fi.exists() ) return FALSE;
816 814
817 // return file listing 815 // return file listing
818 if ( fi.isFile() ) { 816 if ( fi.isFile() ) {
819 ts << fileListing( &fi ) << endl; 817 ts << fileListing( &fi ) << endl;
820 } 818 }
821 819
822 // return directory listing 820 // return directory listing
823 else if ( fi.isDir() ) { 821 else if ( fi.isDir() ) {
824 QDir dir( fn ); 822 QDir dir( fn );
825 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 823 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
826 824
827 QFileInfoListIterator it( *list ); 825 QFileInfoListIterator it( *list );
828 QFileInfo *info; 826 QFileInfo *info;
829 827