summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp1
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp2
-rw-r--r--core/applets/cardmon/cardmon.cpp2
-rw-r--r--core/applets/homeapplet/home.cpp2
-rw-r--r--core/applets/irdaapplet/irda.cpp5
-rw-r--r--core/applets/logoutapplet/logout.cpp2
-rw-r--r--core/applets/multikeyapplet/multikey.cpp6
-rw-r--r--core/launcher/applauncher.cpp4
-rw-r--r--core/launcher/firstuse.cpp8
-rw-r--r--core/launcher/inputmethods.cpp6
-rw-r--r--core/launcher/irserver.cpp1
-rw-r--r--core/launcher/launcher.cpp2
-rw-r--r--core/launcher/launcherglobal.cpp4
-rw-r--r--core/launcher/launchertab.cpp3
-rw-r--r--core/launcher/launcherview.cpp14
-rw-r--r--core/launcher/main.cpp5
-rw-r--r--core/launcher/packageslave.cpp2
-rw-r--r--core/launcher/qcopbridge.cpp8
-rw-r--r--core/launcher/runningappbar.cpp7
-rw-r--r--core/launcher/screensaver.cpp1
-rw-r--r--core/launcher/server.cpp3
-rw-r--r--core/launcher/shutdownimpl.cpp1
-rw-r--r--core/launcher/stabmon.cpp1
-rw-r--r--core/launcher/startmenu.cpp4
-rw-r--r--core/launcher/syncdialog.cpp1
-rw-r--r--core/launcher/systray.cpp2
-rw-r--r--core/launcher/transferserver.cpp10
-rw-r--r--core/launcher/wait.cpp4
28 files changed, 1 insertions, 110 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index fed9b34..b2cef55 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -1,183 +1,182 @@
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#include "battery.h" 20#include "battery.h"
21#include "batterystatus.h" 21#include "batterystatus.h"
22 22
23/* OPIE */ 23/* OPIE */
24#include <opie2/otaskbarapplet.h> 24#include <opie2/otaskbarapplet.h>
25#include <qpe/applnk.h> 25#include <qpe/applnk.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27#include <qpe/power.h> 27#include <qpe/power.h>
28#include <qpe/qpeapplication.h>
29 28
30/* QT */ 29/* QT */
31#include <qpainter.h> 30#include <qpainter.h>
32#include <qtimer.h> 31#include <qtimer.h>
33 32
34 33
35BatteryMeter::BatteryMeter( QWidget *parent ) 34BatteryMeter::BatteryMeter( QWidget *parent )
36 : QWidget( parent ), charging(false) 35 : QWidget( parent ), charging(false)
37{ 36{
38 ps = new PowerStatus; 37 ps = new PowerStatus;
39 startTimer( 10000 ); 38 startTimer( 10000 );
40 39
41 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); 40 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) );
42 setFixedHeight( AppLnk::smallIconSize() ); 41 setFixedHeight( AppLnk::smallIconSize() );
43 42
44 chargeTimer = new QTimer( this ); 43 chargeTimer = new QTimer( this );
45 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); 44 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) );
46 timerEvent(0); 45 timerEvent(0);
47 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 46 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
48 Config c( "qpe" ); 47 Config c( "qpe" );
49 c.setGroup( "Battery" ); 48 c.setGroup( "Battery" );
50 style = c.readNumEntry( "Style", 0 ); 49 style = c.readNumEntry( "Style", 0 );
51} 50}
52 51
53BatteryMeter::~BatteryMeter() 52BatteryMeter::~BatteryMeter()
54{ 53{
55 delete ps; 54 delete ps;
56} 55}
57 56
58QSize BatteryMeter::sizeHint() const 57QSize BatteryMeter::sizeHint() const
59{ 58{
60 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); 59 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() );
61} 60}
62 61
63void BatteryMeter::mousePressEvent( QMouseEvent* e ) 62void BatteryMeter::mousePressEvent( QMouseEvent* e )
64{ 63{
65 if ( e->button() == RightButton ) 64 if ( e->button() == RightButton )
66 { 65 {
67 style = 1-style; 66 style = 1-style;
68 Config c( "qpe" ); 67 Config c( "qpe" );
69 c.setGroup( "Battery" ); 68 c.setGroup( "Battery" );
70 c.writeEntry( "Style", style ); 69 c.writeEntry( "Style", style );
71 repaint( true ); 70 repaint( true );
72 } 71 }
73 QWidget::mousePressEvent( e ); 72 QWidget::mousePressEvent( e );
74} 73}
75 74
76void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) 75void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ )
77{ 76{
78 if ( batteryView && batteryView->isVisible() ) { 77 if ( batteryView && batteryView->isVisible() ) {
79 delete (QWidget *) batteryView; 78 delete (QWidget *) batteryView;
80 } else { 79 } else {
81 if ( !batteryView ) batteryView = new BatteryStatus( ps ); 80 if ( !batteryView ) batteryView = new BatteryStatus( ps );
82 QPEApplication::showWidget( batteryView ); 81 QPEApplication::showWidget( batteryView );
83 batteryView->raise(); 82 batteryView->raise();
84 batteryView->show(); 83 batteryView->show();
85 } 84 }
86} 85}
87 86
88void BatteryMeter::timerEvent( QTimerEvent * ) 87void BatteryMeter::timerEvent( QTimerEvent * )
89{ 88{
90 PowerStatus prev = *ps; 89 PowerStatus prev = *ps;
91 90
92 *ps = PowerStatusManager::readStatus(); 91 *ps = PowerStatusManager::readStatus();
93 92
94 if ( prev != *ps ) { 93 if ( prev != *ps ) {
95 percent = ps->batteryPercentRemaining(); 94 percent = ps->batteryPercentRemaining();
96 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { 95 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) {
97 percent = 0; 96 percent = 0;
98 charging = true; 97 charging = true;
99 chargeTimer->start( 500 ); 98 chargeTimer->start( 500 );
100 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { 99 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) {
101 charging = false; 100 charging = false;
102 chargeTimer->stop(); 101 chargeTimer->stop();
103 if ( batteryView ) 102 if ( batteryView )
104 batteryView->updatePercent( percent ); 103 batteryView->updatePercent( percent );
105 } 104 }
106 repaint( style != 0 ); 105 repaint( style != 0 );
107 if ( batteryView ) 106 if ( batteryView )
108 batteryView->repaint(); 107 batteryView->repaint();
109 } 108 }
110} 109}
111 110
112void BatteryMeter::chargeTimeout() 111void BatteryMeter::chargeTimeout()
113{ 112{
114 percent += 20; 113 percent += 20;
115 if ( percent > 100 ) 114 if ( percent > 100 )
116 percent = 0; 115 percent = 0;
117 116
118 repaint(FALSE); 117 repaint(FALSE);
119 if ( batteryView ) 118 if ( batteryView )
120 batteryView->updatePercent( percent ); 119 batteryView->updatePercent( percent );
121} 120}
122 121
123void BatteryMeter::paintEvent( QPaintEvent* ) 122void BatteryMeter::paintEvent( QPaintEvent* )
124{ 123{
125 124
126 if ( style == 1 ) 125 if ( style == 1 )
127 { 126 {
128 QPainter p(this); 127 QPainter p(this);
129 QFont f( "Fixed", AppLnk::smallIconSize()/2 ); 128 QFont f( "Fixed", AppLnk::smallIconSize()/2 );
130 QFontMetrics fm( f ); 129 QFontMetrics fm( f );
131 p.setFont( f ); 130 p.setFont( f );
132 p.drawText( 0, height()/2, QString::number( percent ) ); 131 p.drawText( 0, height()/2, QString::number( percent ) );
133 p.drawText( width()/4, height(), "%" ); 132 p.drawText( width()/4, height(), "%" );
134 return; 133 return;
135 } 134 }
136 135
137 QPainter p(this); 136 QPainter p(this);
138 QColor color; 137 QColor color;
139 QColor g = gray.light( 160 ); 138 QColor g = gray.light( 160 );
140 switch ( ps->acStatus() ) 139 switch ( ps->acStatus() )
141 { 140 {
142 case PowerStatus::Offline: color = blue.light( 150 ); break; 141 case PowerStatus::Offline: color = blue.light( 150 ); break;
143 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; 142 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break;
144 default: color = red.light( 160 ); 143 default: color = red.light( 160 );
145 } 144 }
146 145
147 int w = height() / 2; 146 int w = height() / 2;
148 if ( !(w%2) ) w--; // should have an odd value to get a real middle line 147 if ( !(w%2) ) w--; // should have an odd value to get a real middle line
149 int h = height() - 4; 148 int h = height() - 4;
150 int pix = (percent * h) / 100; 149 int pix = (percent * h) / 100;
151 int y2 = height() -2; 150 int y2 = height() -2;
152 int y = y2 - pix; 151 int y = y2 - pix;
153 int x1 = (width() - w ) / 2; 152 int x1 = (width() - w ) / 2;
154 153
155 p.setPen(QColor(80,80,80)); 154 p.setPen(QColor(80,80,80));
156 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header 155 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header
157 p.drawRect(x1,1,w,height()-1); // corpus 156 p.drawRect(x1,1,w,height()-1); // corpus
158 p.setBrush(color); 157 p.setBrush(color);
159 158
160 //int extra = ((percent * h) % 100)/(100/4); 159 //int extra = ((percent * h) % 100)/(100/4);
161 160
162 int middle = w/2; 161 int middle = w/2;
163 for ( int i = 0; i < middle; i++ ) 162 for ( int i = 0; i < middle; i++ )
164 { 163 {
165 p.setPen( gray.dark( 100+i*20 ) ); 164 p.setPen( gray.dark( 100+i*20 ) );
166 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); 165 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 );
167 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); 166 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 );
168 p.setPen( color.dark( 100+i*20 ) ); 167 p.setPen( color.dark( 100+i*20 ) );
169 p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); 168 p.drawLine( x1+middle-i, y, x1+middle-i, y2 );
170 p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); 169 p.drawLine( x1+middle+i, y, x1+middle+i, y2 );
171 } 170 }
172} 171}
173 172
174int BatteryMeter::position() 173int BatteryMeter::position()
175{ 174{
176 return 8; 175 return 8;
177} 176}
178 177
179Q_EXPORT_INTERFACE() 178Q_EXPORT_INTERFACE()
180{ 179{
181 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<BatteryMeter> ); 180 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<BatteryMeter> );
182} 181}
183 182
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index b9ca7b5..ea11495 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -1,253 +1,251 @@
1 1
2#include "batterystatus.h" 2#include "batterystatus.h"
3 3
4/* OPIE */ 4/* OPIE */
5#include <opie2/odevice.h> 5#include <opie2/odevice.h>
6#include <qpe/power.h> 6#include <qpe/power.h>
7 7
8/* QT */ 8/* QT */
9#include <qpainter.h>
10#include <qpushbutton.h> 9#include <qpushbutton.h>
11#include <qdrawutil.h> 10#include <qdrawutil.h>
12#include <qfile.h> 11#include <qfile.h>
13#include <qlayout.h> 12#include <qlayout.h>
14#include <qtextstream.h> 13#include <qtextstream.h>
15#include <qapplication.h>
16#include <qmessagebox.h> 14#include <qmessagebox.h>
17 15
18using namespace Opie; 16using namespace Opie;
19 17
20BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) 18BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent )
21 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { 19 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) {
22 setCaption( tr("Battery status") ); 20 setCaption( tr("Battery status") );
23 setMinimumSize( 150, 200 ); 21 setMinimumSize( 150, 200 );
24 22
25 QPushButton *pb = new QPushButton( tr("Close"), this ); 23 QPushButton *pb = new QPushButton( tr("Close"), this );
26 QVBoxLayout *layout = new QVBoxLayout ( this ); 24 QVBoxLayout *layout = new QVBoxLayout ( this );
27 25
28 jackPercent = 0; 26 jackPercent = 0;
29 27
30 pb->setMaximumSize( 120, 40 ); 28 pb->setMaximumSize( 120, 40 );
31 29
32 pb->show(); 30 pb->show();
33 31
34 layout->addStretch(); 32 layout->addStretch();
35 layout->addWidget( pb ); 33 layout->addWidget( pb );
36 34
37 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 35 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
38 getProcApmStatusIpaq(); 36 getProcApmStatusIpaq();
39 } 37 }
40 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); 38 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) );
41 percent = ps->batteryPercentRemaining(); 39 percent = ps->batteryPercentRemaining();
42 show(); 40 show();
43} 41}
44 42
45BatteryStatus::~BatteryStatus() 43BatteryStatus::~BatteryStatus()
46{ 44{
47} 45}
48 46
49/* 47/*
50 * Make use of the advanced apm interface of the ipaq 48 * Make use of the advanced apm interface of the ipaq
51 */ 49 */
52bool BatteryStatus::getProcApmStatusIpaq() { 50bool BatteryStatus::getProcApmStatusIpaq() {
53 51
54 bat2 = false; 52 bat2 = false;
55 53
56 QFile procApmIpaq("/proc/hal/battery"); 54 QFile procApmIpaq("/proc/hal/battery");
57 55
58 if (procApmIpaq.open(IO_ReadOnly) ) { 56 if (procApmIpaq.open(IO_ReadOnly) ) {
59 QStringList list; 57 QStringList list;
60 // since it is /proc we _must_ use QTextStream 58 // since it is /proc we _must_ use QTextStream
61 QTextStream stream ( &procApmIpaq); 59 QTextStream stream ( &procApmIpaq);
62 QString streamIn; 60 QString streamIn;
63 streamIn = stream.read(); 61 streamIn = stream.read();
64 list = QStringList::split("\n", streamIn); 62 list = QStringList::split("\n", streamIn);
65 63
66 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 64 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
67 // not nice, need a rewrite later 65 // not nice, need a rewrite later
68 if( (*line).startsWith(" Percentage") ){ 66 if( (*line).startsWith(" Percentage") ){
69 if (bat2 == true) { 67 if (bat2 == true) {
70 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 68 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
71 } else { 69 } else {
72 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 70 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
73 } 71 }
74 }else if( (*line).startsWith(" Life") ){ 72 }else if( (*line).startsWith(" Life") ){
75 if (bat2 == true) { 73 if (bat2 == true) {
76 sec2 = (*line).mid(((*line).find(':')+2), 5 ); 74 sec2 = (*line).mid(((*line).find(':')+2), 5 );
77 } else { 75 } else {
78 sec1 = (*line).mid(((*line).find(':')+2), 5 ); 76 sec1 = (*line).mid(((*line).find(':')+2), 5 );
79 } 77 }
80 }else if( (*line).startsWith("Battery #1") ){ 78 }else if( (*line).startsWith("Battery #1") ){
81 bat2 = true; 79 bat2 = true;
82 }else if( (*line).startsWith(" Status") ){ 80 }else if( (*line).startsWith(" Status") ){
83 if (bat2 == true) { 81 if (bat2 == true) {
84 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 82 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
85 } else { 83 } else {
86 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 84 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
87 } 85 }
88 }else if( (*line).startsWith(" Chemistry") ) { 86 }else if( (*line).startsWith(" Chemistry") ) {
89 if (bat2 == true) { 87 if (bat2 == true) {
90 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 88 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
91 } else { 89 } else {
92 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 90 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
93 } 91 }
94 } 92 }
95 } 93 }
96 } else { 94 } else {
97 QMessageBox::warning(this, tr("Failure"),tr("could not open file")); 95 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
98 } 96 }
99 97
100 procApmIpaq.close(); 98 procApmIpaq.close();
101 99
102 jackPercent = perc2.toInt(); 100 jackPercent = perc2.toInt();
103 ipaqPercent = perc1.toInt(); 101 ipaqPercent = perc1.toInt();
104 102
105 if (perc2.isEmpty()) { 103 if (perc2.isEmpty()) {
106 perc2 = tr("no data"); 104 perc2 = tr("no data");
107 } else { 105 } else {
108 perc2 += " %"; 106 perc2 += " %";
109 } 107 }
110 108
111 109
112 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { 110 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
113 sec2 = tr("no data"); 111 sec2 = tr("no data");
114 } else { 112 } else {
115 sec2 += " min"; 113 sec2 += " min";
116 } 114 }
117 115
118 jackStatus == (" ( " + jackStatus + " )"); 116 jackStatus == (" ( " + jackStatus + " )");
119 117
120 return true; 118 return true;
121} 119}
122 120
123 121
124void BatteryStatus::updatePercent( int pc ) { 122void BatteryStatus::updatePercent( int pc ) {
125 percent = pc; 123 percent = pc;
126 repaint(FALSE); 124 repaint(FALSE);
127} 125}
128 126
129void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { 127void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) {
130 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; 128 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height;
131 topgrad.hsv( &h1, &s1, &v1 ); 129 topgrad.hsv( &h1, &s1, &v1 );
132 botgrad.hsv( &h2, &s2, &v2 ); 130 botgrad.hsv( &h2, &s2, &v2 );
133 for ( int j = 0; j < hy-2; j++ ) { 131 for ( int j = 0; j < hy-2; j++ ) {
134 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 132 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
135 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 133 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
136 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); 134 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j );
137 } 135 }
138 for ( int j = 0; j < hh; j++ ) { 136 for ( int j = 0; j < hh; j++ ) {
139 p->setPen( highlight ); 137 p->setPen( highlight );
140 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); 138 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j );
141 } 139 }
142 for ( int j = 0; j < ng-hy-hh; j++ ) { 140 for ( int j = 0; j < ng-hy-hh; j++ ) {
143 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 141 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
144 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 142 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
145 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); 143 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j );
146 } 144 }
147} 145}
148 146
149void BatteryStatus::paintEvent( QPaintEvent * ) { 147void BatteryStatus::paintEvent( QPaintEvent * ) {
150 148
151 QPainter p(this); 149 QPainter p(this);
152 QString text; 150 QString text;
153 if ( ps->batteryStatus() == PowerStatus::Charging ) { 151 if ( ps->batteryStatus() == PowerStatus::Charging ) {
154 if (bat2) { 152 if (bat2) {
155 text = tr("Charging both devices"); 153 text = tr("Charging both devices");
156 } else { 154 } else {
157 text = tr("Charging"); 155 text = tr("Charging");
158 } 156 }
159 } else if ( ps->batteryPercentAccurate() ) { 157 } else if ( ps->batteryPercentAccurate() ) {
160 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); 158 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent );
161 } else { 159 } else {
162 text = tr("Battery status: "); 160 text = tr("Battery status: ");
163 switch ( ps->batteryStatus() ) { 161 switch ( ps->batteryStatus() ) {
164 case PowerStatus::High: 162 case PowerStatus::High:
165 text += tr("Good"); 163 text += tr("Good");
166 break; 164 break;
167 case PowerStatus::Low: 165 case PowerStatus::Low:
168 text += tr("Low"); 166 text += tr("Low");
169 break; 167 break;
170 case PowerStatus::VeryLow: 168 case PowerStatus::VeryLow:
171 text += tr("Very Low"); 169 text += tr("Very Low");
172 break; 170 break;
173 case PowerStatus::Critical: 171 case PowerStatus::Critical:
174 text += tr("Critical"); 172 text += tr("Critical");
175 break; 173 break;
176 default: // NotPresent, etc. 174 default: // NotPresent, etc.
177 text += tr("Unknown"); 175 text += tr("Unknown");
178 } 176 }
179 } 177 }
180 p.drawText( 10, 90, text ); 178 p.drawText( 10, 90, text );
181 179
182 if ( ps->acStatus() == PowerStatus::Backup ) 180 if ( ps->acStatus() == PowerStatus::Backup )
183 p.drawText( 10, 110, tr("On backup power") ); 181 p.drawText( 10, 110, tr("On backup power") );
184 else if ( ps->acStatus() == PowerStatus::Online ) 182 else if ( ps->acStatus() == PowerStatus::Online )
185 p.drawText( 10, 110, tr("Power on-line") ); 183 p.drawText( 10, 110, tr("Power on-line") );
186 else if ( ps->acStatus() == PowerStatus::Offline ) 184 else if ( ps->acStatus() == PowerStatus::Offline )
187 p.drawText( 10, 110, tr("External power disconnected") ); 185 p.drawText( 10, 110, tr("External power disconnected") );
188 186
189 if ( ps->batteryTimeRemaining() >= 0 ) { 187 if ( ps->batteryTimeRemaining() >= 0 ) {
190 text.sprintf( tr("Battery time remaining") + ": %im %02is", 188 text.sprintf( tr("Battery time remaining") + ": %im %02is",
191 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); 189 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );
192 p.drawText( 10, 130, text ); 190 p.drawText( 10, 130, text );
193 } 191 }
194 192
195 QColor c; 193 QColor c;
196 QColor darkc; 194 QColor darkc;
197 QColor lightc; 195 QColor lightc;
198 if ( ps->acStatus() == PowerStatus::Offline ) { 196 if ( ps->acStatus() == PowerStatus::Offline ) {
199 c = blue.light(120); 197 c = blue.light(120);
200 darkc = c.dark(280); 198 darkc = c.dark(280);
201 lightc = c.light(145); 199 lightc = c.light(145);
202 } else if ( ps->acStatus() == PowerStatus::Online ) { 200 } else if ( ps->acStatus() == PowerStatus::Online ) {
203 c = green.dark(130); 201 c = green.dark(130);
204 darkc = c.dark(200); 202 darkc = c.dark(200);
205 lightc = c.light(220); 203 lightc = c.light(220);
206 } else { 204 } else {
207 c = red; 205 c = red;
208 darkc = c.dark(280); 206 darkc = c.dark(280);
209 lightc = c.light(140); 207 lightc = c.light(140);
210 } 208 }
211 if ( percent < 0 ) 209 if ( percent < 0 )
212 return; 210 return;
213 211
214 int rightEnd1 = width() - 47; 212 int rightEnd1 = width() - 47;
215 int rightEnd2 = width() - 35; 213 int rightEnd2 = width() - 35;
216 int percent2 = ( percent / 100 ) * rightEnd1 ; 214 int percent2 = ( percent / 100 ) * rightEnd1 ;
217 p.setPen( black ); 215 p.setPen( black );
218 qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); 216 qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL);
219 qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL); 217 qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL);
220 drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); 218 drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 );
221 drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); 219 drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 );
222 drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 ); 220 drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 );
223 p.setPen( black); 221 p.setPen( black);
224 222
225 223
226 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 224 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
227 225
228 p.drawText(15, 50, tr ("Ipaq ") + ipaqChem); 226 p.drawText(15, 50, tr ("Ipaq ") + ipaqChem);
229 227
230 QString jacketMsg; 228 QString jacketMsg;
231 if (bat2) { 229 if (bat2) {
232 p.setPen(black); 230 p.setPen(black);
233 p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus); 231 p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus);
234 p.drawText(10,240, tr("Battery time remaining: ") + sec2); 232 p.drawText(10,240, tr("Battery time remaining: ") + sec2);
235 jacketMsg = tr("Jacket ") + jackChem; 233 jacketMsg = tr("Jacket ") + jackChem;
236 } else { 234 } else {
237 jackPercent = 0; 235 jackPercent = 0;
238 jacketMsg = tr("No jacket with battery inserted"); 236 jacketMsg = tr("No jacket with battery inserted");
239 } 237 }
240 238
241 int jackPerc = ( jackPercent / 100 ) * ( width() - 47 ) ; 239 int jackPerc = ( jackPercent / 100 ) * ( width() - 47 ) ;
242 240
243 qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); 241 qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL);
244 qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL); 242 qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL);
245 drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); 243 drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 );
246 drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); 244 drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 );
247 drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 ); 245 drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 );
248 p.setPen( black ); 246 p.setPen( black );
249 p.drawText(15, 180, jacketMsg); 247 p.drawText(15, 180, jacketMsg);
250 } 248 }
251 249
252} 250}
253 251
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
index 8ffaada..7625545 100644
--- a/core/applets/cardmon/cardmon.cpp
+++ b/core/applets/cardmon/cardmon.cpp
@@ -1,425 +1,423 @@
1/* 1/*
2* cardmon.cpp 2* cardmon.cpp
3* 3*
4* --------------------- 4* ---------------------
5* 5*
6* copyright : (c) 2002 by Maximilian Reiss 6* copyright : (c) 2002 by Maximilian Reiss
7* email : max.reiss@gmx.de 7* email : max.reiss@gmx.de
8* based on two apps by Devin Butterfield 8* based on two apps by Devin Butterfield
9*/ 9*/
10/*************************************************************************** 10/***************************************************************************
11 * * 11 * *
12 * This program is free software; you can redistribute it and/or modify * 12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by * 13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or * 14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. * 15 * (at your option) any later version. *
16 * * 16 * *
17 ***************************************************************************/ 17 ***************************************************************************/
18 18
19#include "cardmon.h" 19#include "cardmon.h"
20 20
21/* OPIE */ 21/* OPIE */
22#include <opie2/odevice.h> 22#include <opie2/odevice.h>
23#include <opie2/otaskbarapplet.h> 23#include <opie2/otaskbarapplet.h>
24#include <qpe/applnk.h> 24#include <qpe/applnk.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26 26
27/* QT */ 27/* QT */
28#include <qapplication.h>
29#include <qcopchannel_qws.h> 28#include <qcopchannel_qws.h>
30#include <qpainter.h> 29#include <qpainter.h>
31#include <qmessagebox.h>
32#include <qfile.h> 30#include <qfile.h>
33#include <qtextstream.h> 31#include <qtextstream.h>
34#include <qsound.h> 32#include <qsound.h>
35#include <qtimer.h> 33#include <qtimer.h>
36 34
37/* STD */ 35/* STD */
38#include <stdio.h> 36#include <stdio.h>
39#include <unistd.h> 37#include <unistd.h>
40#include <stdlib.h> 38#include <stdlib.h>
41#include <string.h> 39#include <string.h>
42#include <fcntl.h> 40#include <fcntl.h>
43 41
44#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 42#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
45#include <sys/vfs.h> 43#include <sys/vfs.h>
46#include <mntent.h> 44#include <mntent.h>
47#endif 45#endif
48 46
49using namespace Opie; 47using namespace Opie;
50 48
51CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), 49CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ),
52 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) 50 pm( Resource::loadPixmap( "cardmon/pcmcia" ) )
53{ 51{
54 52
55 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); 53 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this );
56 connect( pcmciaChannel, 54 connect( pcmciaChannel,
57 SIGNAL( received( const QCString &, const QByteArray & ) ), this, 55 SIGNAL( received( const QCString &, const QByteArray & ) ), this,
58 SLOT( cardMessage( const QCString &, const QByteArray & ) ) ); 56 SLOT( cardMessage( const QCString &, const QByteArray & ) ) );
59 57
60 QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this ); 58 QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this );
61 connect( sdChannel, 59 connect( sdChannel,
62 SIGNAL( received( const QCString &, const QByteArray & ) ), this, 60 SIGNAL( received( const QCString &, const QByteArray & ) ), this,
63 SLOT( cardMessage( const QCString &, const QByteArray & ) ) ); 61 SLOT( cardMessage( const QCString &, const QByteArray & ) ) );
64 62
65 cardInPcmcia0 = FALSE; 63 cardInPcmcia0 = FALSE;
66 cardInPcmcia1 = FALSE; 64 cardInPcmcia1 = FALSE;
67 cardInSd = FALSE; 65 cardInSd = FALSE;
68 66
69 setFocusPolicy( NoFocus ); 67 setFocusPolicy( NoFocus );
70 68
71 setFixedWidth ( AppLnk::smallIconSize() ); 69 setFixedWidth ( AppLnk::smallIconSize() );
72 setFixedHeight ( AppLnk::smallIconSize() ); 70 setFixedHeight ( AppLnk::smallIconSize() );
73 71
74 getStatusPcmcia( TRUE ); 72 getStatusPcmcia( TRUE );
75 getStatusSd( TRUE ); 73 getStatusSd( TRUE );
76 repaint( FALSE ); 74 repaint( FALSE );
77 popupMenu = 0; 75 popupMenu = 0;
78} 76}
79 77
80CardMonitor::~CardMonitor() 78CardMonitor::~CardMonitor()
81{ 79{
82 if ( popupMenu ) 80 if ( popupMenu )
83 { 81 {
84 delete popupMenu; 82 delete popupMenu;
85 } 83 }
86} 84}
87 85
88void CardMonitor::popUp( QString message, QString icon ) 86void CardMonitor::popUp( QString message, QString icon )
89{ 87{
90 if ( !popupMenu ) 88 if ( !popupMenu )
91 { 89 {
92 popupMenu = new QPopupMenu( this ); 90 popupMenu = new QPopupMenu( this );
93 } 91 }
94 92
95 popupMenu->clear(); 93 popupMenu->clear();
96 if ( icon.isEmpty() ) 94 if ( icon.isEmpty() )
97 { 95 {
98 popupMenu->insertItem( message, 0 ); 96 popupMenu->insertItem( message, 0 );
99 } 97 }
100 else 98 else
101 { 99 {
102 popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), 100 popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ),
103 message, 0 ); 101 message, 0 );
104 } 102 }
105 103
106 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 104 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
107 QSize s = popupMenu->sizeHint(); 105 QSize s = popupMenu->sizeHint();
108 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 106 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
109 p.y() - s.height() ), 0 ); 107 p.y() - s.height() ), 0 );
110 108
111 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); 109 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) );
112} 110}
113 111
114void CardMonitor::popupTimeout() 112void CardMonitor::popupTimeout()
115{ 113{
116 popupMenu->hide(); 114 popupMenu->hide();
117} 115}
118 116
119void CardMonitor::mousePressEvent( QMouseEvent * ) 117void CardMonitor::mousePressEvent( QMouseEvent * )
120{ 118{
121 QPopupMenu * menu = new QPopupMenu( this ); 119 QPopupMenu * menu = new QPopupMenu( this );
122 QString cmd; 120 QString cmd;
123 int err = 0; 121 int err = 0;
124 122
125 if ( cardInSd ) 123 if ( cardInSd )
126 { 124 {
127 menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), 125 menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ),
128 tr( "Eject SD/MMC card" ), 0 ); 126 tr( "Eject SD/MMC card" ), 0 );
129 } 127 }
130 128
131 if ( cardInPcmcia0 ) 129 if ( cardInPcmcia0 )
132 { 130 {
133 menu-> 131 menu->
134 insertItem( QIconSet 132 insertItem( QIconSet
135 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), 133 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ),
136 tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); 134 tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 );
137 } 135 }
138 136
139 if ( cardInPcmcia1 ) 137 if ( cardInPcmcia1 )
140 { 138 {
141 menu-> 139 menu->
142 insertItem( QIconSet 140 insertItem( QIconSet
143 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), 141 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ),
144 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); 142 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 );
145 } 143 }
146 144
147 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 145 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
148 QSize s = menu->sizeHint(); 146 QSize s = menu->sizeHint();
149 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 147 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
150 p.y() - s.height() ), 0 ); 148 p.y() - s.height() ), 0 );
151 149
152 if ( opt == 1 ) 150 if ( opt == 1 )
153 { 151 {
154 cmd = "/sbin/cardctl eject 0"; 152 cmd = "/sbin/cardctl eject 0";
155 err = system( ( const char * ) cmd ); 153 err = system( ( const char * ) cmd );
156 if ( err != 0 ) 154 if ( err != 0 )
157 { 155 {
158 qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", 156 qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d",
159 err ); 157 err );
160 popUp( tr( "CF/PCMCIA card eject failed!" ) ); 158 popUp( tr( "CF/PCMCIA card eject failed!" ) );
161 } 159 }
162 } 160 }
163 else if ( opt == 0 ) 161 else if ( opt == 0 )
164 { 162 {
165 if ( ODevice::inst() ->system() == System_Familiar ) 163 if ( ODevice::inst() ->system() == System_Familiar )
166 { 164 {
167 cmd = "umount /dev/mmc/part1"; 165 cmd = "umount /dev/mmc/part1";
168 } 166 }
169 else 167 else
170 { 168 {
171 cmd = "umount /dev/mmcda1"; 169 cmd = "umount /dev/mmcda1";
172 } 170 }
173 err = system( ( const char * ) cmd ); 171 err = system( ( const char * ) cmd );
174 if ( err != 0 ) 172 if ( err != 0 )
175 { 173 {
176 popUp( tr( "SD/MMC card eject failed!" ) ); 174 popUp( tr( "SD/MMC card eject failed!" ) );
177 } 175 }
178 } 176 }
179 else if ( opt == 2 ) 177 else if ( opt == 2 )
180 { 178 {
181 cmd = "/sbin/cardctl eject 1"; 179 cmd = "/sbin/cardctl eject 1";
182 err = system( ( const char * ) cmd ); 180 err = system( ( const char * ) cmd );
183 if ( err != 0 ) 181 if ( err != 0 )
184 { 182 {
185 qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", 183 qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d",
186 err ); 184 err );
187 popUp( tr( "CF/PCMCIA card eject failed!" ) ); 185 popUp( tr( "CF/PCMCIA card eject failed!" ) );
188 } 186 }
189 } 187 }
190 delete menu; 188 delete menu;
191} 189}
192 190
193 191
194void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) 192void CardMonitor::cardMessage( const QCString & msg, const QByteArray & )
195{ 193{
196 if ( msg == "stabChanged()" ) 194 if ( msg == "stabChanged()" )
197 { 195 {
198 // qDebug("Pcmcia: stabchanged"); 196 // qDebug("Pcmcia: stabchanged");
199 getStatusPcmcia(); 197 getStatusPcmcia();
200 } 198 }
201 else if ( msg == "mtabChanged()" ) 199 else if ( msg == "mtabChanged()" )
202 { 200 {
203 // qDebug("CARDMONAPPLET: mtabchanged"); 201 // qDebug("CARDMONAPPLET: mtabchanged");
204 getStatusSd(); 202 getStatusSd();
205 } 203 }
206} 204}
207 205
208bool CardMonitor::getStatusPcmcia( int showPopUp ) 206bool CardMonitor::getStatusPcmcia( int showPopUp )
209{ 207{
210 208
211 bool cardWas0 = cardInPcmcia0;// remember last state 209 bool cardWas0 = cardInPcmcia0;// remember last state
212 bool cardWas1 = cardInPcmcia1; 210 bool cardWas1 = cardInPcmcia1;
213 211
214 QString fileName; 212 QString fileName;
215 213
216 // one of these 3 files should exist 214 // one of these 3 files should exist
217 if ( QFile::exists( "/var/run/stab" ) ) 215 if ( QFile::exists( "/var/run/stab" ) )
218 { 216 {
219 fileName = "/var/run/stab"; 217 fileName = "/var/run/stab";
220 } 218 }
221 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) 219 else if ( QFile::exists( "/var/state/pcmcia/stab" ) )
222 { 220 {
223 fileName = "/var/state/pcmcia/stab"; 221 fileName = "/var/state/pcmcia/stab";
224 } 222 }
225 else 223 else
226 { 224 {
227 fileName = "/var/lib/pcmcia/stab"; 225 fileName = "/var/lib/pcmcia/stab";
228 } 226 }
229 227
230 QFile f( fileName ); 228 QFile f( fileName );
231 229
232 if ( f.open( IO_ReadOnly ) ) 230 if ( f.open( IO_ReadOnly ) )
233 { 231 {
234 QStringList list; 232 QStringList list;
235 QTextStream stream( &f ); 233 QTextStream stream( &f );
236 QString streamIn; 234 QString streamIn;
237 streamIn = stream.read(); 235 streamIn = stream.read();
238 list = QStringList::split( "\n", streamIn ); 236 list = QStringList::split( "\n", streamIn );
239 for ( QStringList::Iterator line = list.begin(); line != list.end(); 237 for ( QStringList::Iterator line = list.begin(); line != list.end();
240 line++ ) 238 line++ )
241 { 239 {
242 if ( ( *line ).startsWith( "Socket 0:" ) ) 240 if ( ( *line ).startsWith( "Socket 0:" ) )
243 { 241 {
244 if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) 242 if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 )
245 { 243 {
246 cardInPcmcia0 = FALSE; 244 cardInPcmcia0 = FALSE;
247 } 245 }
248 else if ( !( *line ).startsWith( "Socket 0: empty" ) 246 else if ( !( *line ).startsWith( "Socket 0: empty" )
249 && !cardInPcmcia0 ) 247 && !cardInPcmcia0 )
250 { 248 {
251 cardInPcmcia0Name = 249 cardInPcmcia0Name =
252 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), 250 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ),
253 ( *line ).length() - 9 ); 251 ( *line ).length() - 9 );
254 cardInPcmcia0Name.stripWhiteSpace(); 252 cardInPcmcia0Name.stripWhiteSpace();
255 cardInPcmcia0 = TRUE; 253 cardInPcmcia0 = TRUE;
256 show(); 254 show();
257 line++; 255 line++;
258 int pos = ( *line ).find( '\t' ) + 1; 256 int pos = ( *line ).find( '\t' ) + 1;
259 cardInPcmcia0Type = 257 cardInPcmcia0Type =
260 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); 258 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos );
261 } 259 }
262 } 260 }
263 else if ( ( *line ).startsWith( "Socket 1:" ) ) 261 else if ( ( *line ).startsWith( "Socket 1:" ) )
264 { 262 {
265 if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) 263 if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 )
266 { 264 {
267 cardInPcmcia1 = FALSE; 265 cardInPcmcia1 = FALSE;
268 } 266 }
269 else if ( !( *line ).startsWith( "Socket 1: empty" ) 267 else if ( !( *line ).startsWith( "Socket 1: empty" )
270 && !cardInPcmcia1 ) 268 && !cardInPcmcia1 )
271 { 269 {
272 cardInPcmcia1Name = 270 cardInPcmcia1Name =
273 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), 271 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ),
274 ( *line ).length() - 9 ); 272 ( *line ).length() - 9 );
275 cardInPcmcia1Name.stripWhiteSpace(); 273 cardInPcmcia1Name.stripWhiteSpace();
276 cardInPcmcia1 = TRUE; 274 cardInPcmcia1 = TRUE;
277 show(); 275 show();
278 line++; 276 line++;
279 int pos = ( *line ).find( '\t' ) + 1; 277 int pos = ( *line ).find( '\t' ) + 1;
280 cardInPcmcia1Type = 278 cardInPcmcia1Type =
281 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); 279 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos );
282 } 280 }
283 } 281 }
284 } 282 }
285 f.close(); 283 f.close();
286 284
287 if ( !showPopUp 285 if ( !showPopUp
288 && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) 286 && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) )
289 { 287 {
290 QString text = QString::null; 288 QString text = QString::null;
291 QString what = QString::null; 289 QString what = QString::null;
292 if ( cardWas0 != cardInPcmcia0 ) 290 if ( cardWas0 != cardInPcmcia0 )
293 { 291 {
294 if ( cardInPcmcia0 ) 292 if ( cardInPcmcia0 )
295 { 293 {
296 text += tr( "New card: " ); 294 text += tr( "New card: " );
297 what = "on"; 295 what = "on";
298 } 296 }
299 else 297 else
300 { 298 {
301 text += tr( "Ejected: " ); 299 text += tr( "Ejected: " );
302 what = "off"; 300 what = "off";
303 } 301 }
304 text += cardInPcmcia0Name; 302 text += cardInPcmcia0Name;
305 popUp( text, "cardmon/" + cardInPcmcia0Type ); 303 popUp( text, "cardmon/" + cardInPcmcia0Type );
306 } 304 }
307 305
308 if ( cardWas1 != cardInPcmcia1 ) 306 if ( cardWas1 != cardInPcmcia1 )
309 { 307 {
310 if ( cardInPcmcia1 ) 308 if ( cardInPcmcia1 )
311 { 309 {
312 text += tr( "New card: " ); 310 text += tr( "New card: " );
313 what = "on"; 311 what = "on";
314 } 312 }
315 else 313 else
316 { 314 {
317 text += tr( "Ejected: " ); 315 text += tr( "Ejected: " );
318 what = "off"; 316 what = "off";
319 } 317 }
320 text += cardInPcmcia1Name; 318 text += cardInPcmcia1Name;
321 popUp( text, "cardmon/" + cardInPcmcia1Type ); 319 popUp( text, "cardmon/" + cardInPcmcia1Type );
322 } 320 }
323#ifndef QT_NO_SOUND 321#ifndef QT_NO_SOUND
324 QSound::play( Resource::findSound( "cardmon/card" + what ) ); 322 QSound::play( Resource::findSound( "cardmon/card" + what ) );
325#endif 323#endif
326 324
327 } 325 }
328 } 326 }
329 else 327 else
330 { 328 {
331 // no file found 329 // no file found
332 qDebug( "no file found" ); 330 qDebug( "no file found" );
333 cardInPcmcia0 = FALSE; 331 cardInPcmcia0 = FALSE;
334 cardInPcmcia1 = FALSE; 332 cardInPcmcia1 = FALSE;
335 } 333 }
336 repaint( FALSE ); 334 repaint( FALSE );
337 return ( ( cardWas0 == cardInPcmcia0 335 return ( ( cardWas0 == cardInPcmcia0
338 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); 336 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE );
339 337
340} 338}
341 339
342 340
343bool CardMonitor::getStatusSd( int showPopUp ) 341bool CardMonitor::getStatusSd( int showPopUp )
344{ 342{
345 343
346 bool cardWas = cardInSd;// remember last state 344 bool cardWas = cardInSd;// remember last state
347 cardInSd = FALSE; 345 cardInSd = FALSE;
348 346
349#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 347#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
350 struct mntent *me; 348 struct mntent *me;
351 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 349 FILE *mntfp = setmntent( "/etc/mtab", "r" );
352 350
353 if ( mntfp ) 351 if ( mntfp )
354 { 352 {
355 while ( ( me = getmntent( mntfp ) ) != 0 ) 353 while ( ( me = getmntent( mntfp ) ) != 0 )
356 { 354 {
357 QString fs = me->mnt_fsname; 355 QString fs = me->mnt_fsname;
358 //qDebug( fs ); 356 //qDebug( fs );
359 if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" 357 if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd"
360 || fs.left( 9 ) == "/dev/mmcd" ) 358 || fs.left( 9 ) == "/dev/mmcd" )
361 { 359 {
362 cardInSd = TRUE; 360 cardInSd = TRUE;
363 show(); 361 show();
364 } 362 }
365 // else { 363 // else {
366 // cardInSd = FALSE; 364 // cardInSd = FALSE;
367 // } 365 // }
368 } 366 }
369 endmntent( mntfp ); 367 endmntent( mntfp );
370 } 368 }
371 369
372 if ( !showPopUp && cardWas != cardInSd ) 370 if ( !showPopUp && cardWas != cardInSd )
373 { 371 {
374 QString text = QString::null; 372 QString text = QString::null;
375 QString what = QString::null; 373 QString what = QString::null;
376 if ( cardInSd ) 374 if ( cardInSd )
377 { 375 {
378 text += "New card: SD/MMC"; 376 text += "New card: SD/MMC";
379 what = "on"; 377 what = "on";
380 } 378 }
381 else 379 else
382 { 380 {
383 text += "Ejected: SD/MMC"; 381 text += "Ejected: SD/MMC";
384 what = "off"; 382 what = "off";
385 } 383 }
386 //qDebug("TEXT: " + text ); 384 //qDebug("TEXT: " + text );
387#ifndef QT_NO_SOUND 385#ifndef QT_NO_SOUND
388 QSound::play( Resource::findSound( "cardmon/card" + what ) ); 386 QSound::play( Resource::findSound( "cardmon/card" + what ) );
389#endif 387#endif
390 popUp( text, "cardmon/ide" );// XX add SD pic 388 popUp( text, "cardmon/ide" );// XX add SD pic
391 } 389 }
392#else 390#else
393#error "Not on Linux" 391#error "Not on Linux"
394#endif 392#endif
395 repaint( FALSE ); 393 repaint( FALSE );
396 return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); 394 return ( ( cardWas == cardInSd ) ? FALSE : TRUE );
397} 395}
398 396
399void CardMonitor::paintEvent( QPaintEvent * ) 397void CardMonitor::paintEvent( QPaintEvent * )
400{ 398{
401 399
402 QPainter p( this ); 400 QPainter p( this );
403 401
404 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) 402 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd )
405 { 403 {
406 p.drawPixmap( 0, 0, pm ); 404 p.drawPixmap( 0, 0, pm );
407 show(); 405 show();
408 } 406 }
409 else 407 else
410 { 408 {
411 //p.eraseRect(rect()); 409 //p.eraseRect(rect());
412 hide(); 410 hide();
413 } 411 }
414} 412}
415 413
416int CardMonitor::position() 414int CardMonitor::position()
417{ 415{
418 return 7; 416 return 7;
419} 417}
420 418
421Q_EXPORT_INTERFACE() 419Q_EXPORT_INTERFACE()
422{ 420{
423 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<CardMonitor> ); 421 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<CardMonitor> );
424} 422}
425 423
diff --git a/core/applets/homeapplet/home.cpp b/core/applets/homeapplet/home.cpp
index 455575f..8a930be 100644
--- a/core/applets/homeapplet/home.cpp
+++ b/core/applets/homeapplet/home.cpp
@@ -1,87 +1,85 @@
1#include <qpe/resource.h> 1#include <qpe/resource.h>
2#include <qpe/qcopenvelope_qws.h> 2#include <qpe/qcopenvelope_qws.h>
3 3
4#include <qapplication.h> 4#include <qapplication.h>
5#include <qiconset.h>
6#include <qpopupmenu.h>
7 5
8#include "home.h" 6#include "home.h"
9 7
10 8
11HomeApplet::HomeApplet ( ) 9HomeApplet::HomeApplet ( )
12 : QObject ( 0, "HomeApplet" ) 10 : QObject ( 0, "HomeApplet" )
13{ 11{
14} 12}
15 13
16HomeApplet::~HomeApplet ( ) 14HomeApplet::~HomeApplet ( )
17{ 15{
18} 16}
19 17
20int HomeApplet::position ( ) const 18int HomeApplet::position ( ) const
21{ 19{
22 return 4; 20 return 4;
23} 21}
24 22
25QString HomeApplet::name ( ) const 23QString HomeApplet::name ( ) const
26{ 24{
27 return tr( "Home shortcut" ); 25 return tr( "Home shortcut" );
28} 26}
29 27
30QString HomeApplet::text ( ) const 28QString HomeApplet::text ( ) const
31{ 29{
32 return tr( "Desktop" ); 30 return tr( "Desktop" );
33} 31}
34 32
35QString HomeApplet::tr( const char* s ) const 33QString HomeApplet::tr( const char* s ) const
36{ 34{
37 return qApp->translate( "HomeApplet", s, 0 ); 35 return qApp->translate( "HomeApplet", s, 0 );
38} 36}
39 37
40QString HomeApplet::tr( const char* s, const char* p ) const 38QString HomeApplet::tr( const char* s, const char* p ) const
41{ 39{
42 return qApp->translate( "HomeApplet", s, p ); 40 return qApp->translate( "HomeApplet", s, p );
43} 41}
44 42
45QIconSet HomeApplet::icon ( ) const 43QIconSet HomeApplet::icon ( ) const
46{ 44{
47 QPixmap pix; 45 QPixmap pix;
48 QImage img = Resource::loadImage ( "home" ); 46 QImage img = Resource::loadImage ( "home" );
49 47
50 if ( !img. isNull ( )) 48 if ( !img. isNull ( ))
51 pix. convertFromImage ( img. smoothScale ( 14, 14 )); 49 pix. convertFromImage ( img. smoothScale ( 14, 14 ));
52 return pix; 50 return pix;
53} 51}
54 52
55QPopupMenu *HomeApplet::popup ( QWidget * ) const 53QPopupMenu *HomeApplet::popup ( QWidget * ) const
56{ 54{
57 return 0; 55 return 0;
58} 56}
59 57
60void HomeApplet::activated ( ) 58void HomeApplet::activated ( )
61{ 59{
62 // to desktop (home) 60 // to desktop (home)
63 QCopEnvelope ( "QPE/Application/qpe", "raise()" ); 61 QCopEnvelope ( "QPE/Application/qpe", "raise()" );
64} 62}
65 63
66 64
67QRESULT HomeApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) 65QRESULT HomeApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface )
68{ 66{
69 *iface = 0; 67 *iface = 0;
70 if ( uuid == IID_QUnknown ) 68 if ( uuid == IID_QUnknown )
71 *iface = this; 69 *iface = this;
72 else if ( uuid == IID_MenuApplet ) 70 else if ( uuid == IID_MenuApplet )
73 *iface = this; 71 *iface = this;
74 else 72 else
75 return QS_FALSE; 73 return QS_FALSE;
76 74
77 if ( *iface ) 75 if ( *iface )
78 (*iface)-> addRef ( ); 76 (*iface)-> addRef ( );
79 return QS_OK; 77 return QS_OK;
80} 78}
81 79
82Q_EXPORT_INTERFACE( ) 80Q_EXPORT_INTERFACE( )
83{ 81{
84 Q_CREATE_INSTANCE( HomeApplet ) 82 Q_CREATE_INSTANCE( HomeApplet )
85} 83}
86 84
87 85
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp
index f850424..a47f33d 100644
--- a/core/applets/irdaapplet/irda.cpp
+++ b/core/applets/irdaapplet/irda.cpp
@@ -1,357 +1,352 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 David Woodhouse <dwmw2@infradead.org> 2** Copyright (C) 2002 David Woodhouse <dwmw2@infradead.org>
3** Max Reiss <harlekin@handhelds.org> [trivial stuff] 3** Max Reiss <harlekin@handhelds.org> [trivial stuff]
4** Robert Griebl <sandman@handhelds.org> 4** Robert Griebl <sandman@handhelds.org>
5** Holger Freyther <zecke@handhelds.org> QCOP Interface 5** Holger Freyther <zecke@handhelds.org> QCOP Interface
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15**********************************************************************/ 15**********************************************************************/
16 16
17#include <qcopchannel_qws.h>
18 17
19#include <qpe/qpeapplication.h>
20#include <qpe/resource.h> 18#include <qpe/resource.h>
21#include <qpe/ir.h>
22#include <qpe/qcopenvelope_qws.h> 19#include <qpe/qcopenvelope_qws.h>
23#include <qpe/sound.h>
24 20
25#include <qpainter.h> 21#include <qpainter.h>
26#include <qfile.h> 22#include <qfile.h>
27#include <qtimer.h> 23#include <qtimer.h>
28#include <qtextstream.h> 24#include <qtextstream.h>
29#include <qpopupmenu.h>
30 25
31#include <unistd.h> 26#include <unistd.h>
32#include <net/if.h> 27#include <net/if.h>
33#include <netinet/in.h> 28#include <netinet/in.h>
34#include <sys/types.h> 29#include <sys/types.h>
35#include <sys/socket.h> 30#include <sys/socket.h>
36#include <sys/ioctl.h> 31#include <sys/ioctl.h>
37 32
38#include "irda.h" 33#include "irda.h"
39 34
40//=========================================================================== 35//===========================================================================
41 36
42IrdaApplet::IrdaApplet ( QWidget *parent, const char *name ) 37IrdaApplet::IrdaApplet ( QWidget *parent, const char *name )
43 : QWidget ( parent, name ) 38 : QWidget ( parent, name )
44{ 39{
45 setFixedHeight ( 18 ); 40 setFixedHeight ( 18 );
46 setFixedWidth ( 14 ); 41 setFixedWidth ( 14 );
47 42
48 m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP ); 43 m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP );
49 44
50 m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); 45 m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" );
51 m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); 46 m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" );
52 m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); 47 m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" );
53 m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" ); 48 m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" );
54 49
55 m_irda_active = false; 50 m_irda_active = false;
56 m_irda_discovery_active = false; 51 m_irda_discovery_active = false;
57 m_receive_active = false; 52 m_receive_active = false;
58 m_receive_state_changed = false; 53 m_receive_state_changed = false;
59 m_popup = 0; 54 m_popup = 0;
60 m_wasOn = false; 55 m_wasOn = false;
61 m_wasDiscover = false; 56 m_wasDiscover = false;
62 57
63 QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this ); 58 QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this );
64 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 59 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
65 this, SLOT(slotMessage(const QCString&, const QByteArray& ) ) ); 60 this, SLOT(slotMessage(const QCString&, const QByteArray& ) ) );
66} 61}
67 62
68void IrdaApplet::show() 63void IrdaApplet::show()
69{ 64{
70 QWidget::show ( ); 65 QWidget::show ( );
71 startTimer ( 2000 ); 66 startTimer ( 2000 );
72} 67}
73 68
74IrdaApplet::~IrdaApplet() 69IrdaApplet::~IrdaApplet()
75{ 70{
76 if ( m_sockfd >= 0 ) 71 if ( m_sockfd >= 0 )
77 ::close ( m_sockfd ); 72 ::close ( m_sockfd );
78} 73}
79 74
80void IrdaApplet::popup ( QString message, QString icon ) 75void IrdaApplet::popup ( QString message, QString icon )
81{ 76{
82 if ( !m_popup ) 77 if ( !m_popup )
83 m_popup = new QPopupMenu ( this ); 78 m_popup = new QPopupMenu ( this );
84 79
85 m_popup-> clear ( ); 80 m_popup-> clear ( );
86 81
87 if ( icon. isEmpty ( )) 82 if ( icon. isEmpty ( ))
88 m_popup-> insertItem ( message, 0 ); 83 m_popup-> insertItem ( message, 0 );
89 else 84 else
90 m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 ); 85 m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 );
91 86
92 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 87 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
93 QSize s = m_popup-> sizeHint ( ); 88 QSize s = m_popup-> sizeHint ( );
94 m_popup-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 89 m_popup-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
95 p. y ( ) - s. height ( ))); 90 p. y ( ) - s. height ( )));
96 91
97 QTimer::singleShot ( 2000, this, SLOT( popupTimeout ( ))); 92 QTimer::singleShot ( 2000, this, SLOT( popupTimeout ( )));
98} 93}
99 94
100void IrdaApplet::popupTimeout ( ) 95void IrdaApplet::popupTimeout ( )
101{ 96{
102 m_popup-> hide ( ); 97 m_popup-> hide ( );
103} 98}
104 99
105bool IrdaApplet::checkIrdaStatus ( ) 100bool IrdaApplet::checkIrdaStatus ( )
106{ 101{
107 struct ifreq ifr; 102 struct ifreq ifr;
108 strcpy ( ifr. ifr_name, "irda0" ); 103 strcpy ( ifr. ifr_name, "irda0" );
109 104
110 if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) 105 if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 )
111 return false; 106 return false;
112 107
113 return ( ifr. ifr_flags & IFF_UP ); 108 return ( ifr. ifr_flags & IFF_UP );
114} 109}
115 110
116bool IrdaApplet::setIrdaStatus ( bool b ) 111bool IrdaApplet::setIrdaStatus ( bool b )
117{ 112{
118 struct ifreq ifr; 113 struct ifreq ifr;
119 strcpy ( ifr. ifr_name, "irda0" ); 114 strcpy ( ifr. ifr_name, "irda0" );
120 115
121 if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) 116 if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 )
122 return false; 117 return false;
123 118
124 if ( b ) { 119 if ( b ) {
125 ifr. ifr_flags |= IFF_UP; 120 ifr. ifr_flags |= IFF_UP;
126 } 121 }
127 else { 122 else {
128 setIrdaDiscoveryStatus ( 0 ); 123 setIrdaDiscoveryStatus ( 0 );
129 setIrdaReceiveStatus ( 0 ); 124 setIrdaReceiveStatus ( 0 );
130 ifr. ifr_flags &= ~IFF_UP; 125 ifr. ifr_flags &= ~IFF_UP;
131 } 126 }
132 127
133 if ( ::ioctl ( m_sockfd, SIOCSIFFLAGS, &ifr ) < 0 ) 128 if ( ::ioctl ( m_sockfd, SIOCSIFFLAGS, &ifr ) < 0 )
134 return false; 129 return false;
135 130
136 return true; 131 return true;
137} 132}
138 133
139bool IrdaApplet::checkIrdaDiscoveryStatus ( ) 134bool IrdaApplet::checkIrdaDiscoveryStatus ( )
140{ 135{
141 QFile discovery ( "/proc/sys/net/irda/discovery" ); 136 QFile discovery ( "/proc/sys/net/irda/discovery" );
142 137
143 QString streamIn = "0"; 138 QString streamIn = "0";
144 139
145 if ( discovery. open ( IO_ReadOnly )) { 140 if ( discovery. open ( IO_ReadOnly )) {
146 QTextStream stream ( &discovery ); 141 QTextStream stream ( &discovery );
147 streamIn = stream. read ( ); 142 streamIn = stream. read ( );
148 } 143 }
149 144
150 return streamIn. toInt ( ) > 0; 145 return streamIn. toInt ( ) > 0;
151} 146}
152 147
153 148
154bool IrdaApplet::setIrdaDiscoveryStatus ( bool d ) 149bool IrdaApplet::setIrdaDiscoveryStatus ( bool d )
155{ 150{
156 QFile discovery ( "/proc/sys/net/irda/discovery" ); 151 QFile discovery ( "/proc/sys/net/irda/discovery" );
157 152
158 if ( discovery. open ( IO_WriteOnly | IO_Raw )) { 153 if ( discovery. open ( IO_WriteOnly | IO_Raw )) {
159 discovery.putch ( d ? '1' : '0' ); 154 discovery.putch ( d ? '1' : '0' );
160 return true; 155 return true;
161 } 156 }
162 return false; 157 return false;
163} 158}
164 159
165 160
166bool IrdaApplet::setIrdaReceiveStatus ( bool d ) 161bool IrdaApplet::setIrdaReceiveStatus ( bool d )
167{ 162{
168 QCopEnvelope e ( "QPE/Obex", "receive(int)" ); 163 QCopEnvelope e ( "QPE/Obex", "receive(int)" );
169 e << ( d ? 1 : 0 ); 164 e << ( d ? 1 : 0 );
170 165
171 m_receive_active = d; 166 m_receive_active = d;
172 m_receive_state_changed = true; 167 m_receive_state_changed = true;
173 168
174 return true; 169 return true;
175} 170}
176 171
177 172
178void IrdaApplet::showDiscovered ( ) 173void IrdaApplet::showDiscovered ( )
179{ 174{
180 //static Sound snd_found ( "irdaapplet/irdaon" ); 175 //static Sound snd_found ( "irdaapplet/irdaon" );
181 //static Sound snd_lost ( "irdaapplet/irdaoff" ); 176 //static Sound snd_lost ( "irdaapplet/irdaoff" );
182 177
183 QFile discovery ( "/proc/net/irda/discovery" ); 178 QFile discovery ( "/proc/net/irda/discovery" );
184 179
185 if ( discovery. open ( IO_ReadOnly )) { 180 if ( discovery. open ( IO_ReadOnly )) {
186 bool qcopsend = false; 181 bool qcopsend = false;
187 182
188 QString discoveredDevice; 183 QString discoveredDevice;
189 QString deviceAddr; 184 QString deviceAddr;
190 185
191 // since it is /proc we _must_ use QTextStream 186 // since it is /proc we _must_ use QTextStream
192 QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( )); 187 QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( ));
193 188
194 QMap <QString, QString>::Iterator it; 189 QMap <QString, QString>::Iterator it;
195 190
196 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ++it ) 191 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ++it )
197 it. data ( ). prepend ( "+++" ); 192 it. data ( ). prepend ( "+++" );
198 193
199 for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) { 194 for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) {
200 const QString &line = *lit; 195 const QString &line = *lit;
201 196
202 if ( line. startsWith ( "nickname:" )) { 197 if ( line. startsWith ( "nickname:" )) {
203 discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 ); 198 discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 );
204 deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 ); 199 deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 );
205 200
206 // qDebug(discoveredDevice + "(" + deviceAddr + ")"); 201 // qDebug(discoveredDevice + "(" + deviceAddr + ")");
207 202
208 if ( !m_devices. contains ( deviceAddr )) { 203 if ( !m_devices. contains ( deviceAddr )) {
209 popup ( tr( "Found:" ) + " " + discoveredDevice ); 204 popup ( tr( "Found:" ) + " " + discoveredDevice );
210 //snd_found. play ( ); 205 //snd_found. play ( );
211 qcopsend = true; 206 qcopsend = true;
212 } 207 }
213 m_devices. replace ( deviceAddr, discoveredDevice ); 208 m_devices. replace ( deviceAddr, discoveredDevice );
214 } 209 }
215 } 210 }
216 211
217 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) { 212 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) {
218 // qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?"); 213 // qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?");
219 214
220 if ( it. data ( ). left ( 3 ) == "+++" ) { 215 if ( it. data ( ). left ( 3 ) == "+++" ) {
221 popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 )); 216 popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 ));
222 //snd_lost. play ( ); 217 //snd_lost. play ( );
223 218
224 QMap <QString, QString>::Iterator tmp = it; 219 QMap <QString, QString>::Iterator tmp = it;
225 tmp++; 220 tmp++;
226 m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator 221 m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator
227 it = tmp; 222 it = tmp;
228 223
229 qcopsend = true; 224 qcopsend = true;
230 } 225 }
231 else 226 else
232 it++; 227 it++;
233 } 228 }
234 // XXX if( qcopsend ) { 229 // XXX if( qcopsend ) {
235 QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" ); 230 QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" );
236 e << ( m_devices. count ( ) > 0 ); 231 e << ( m_devices. count ( ) > 0 );
237 // } 232 // }
238 } 233 }
239} 234}
240 235
241void IrdaApplet::mousePressEvent ( QMouseEvent * ) 236void IrdaApplet::mousePressEvent ( QMouseEvent * )
242{ 237{
243 QPopupMenu *menu = new QPopupMenu ( this ); 238 QPopupMenu *menu = new QPopupMenu ( this );
244 QString cmd; 239 QString cmd;
245 240
246 /* Refresh active state */ 241 /* Refresh active state */
247 timerEvent ( 0 ); 242 timerEvent ( 0 );
248 243
249 //menu->insertItem( tr("More..."), 4 ); 244 //menu->insertItem( tr("More..."), 4 );
250 245
251 if ( m_irda_active && !m_devices. isEmpty ( )) { 246 if ( m_irda_active && !m_devices. isEmpty ( )) {
252 menu-> insertItem ( tr( "Discovered Device:" ), 9 ); 247 menu-> insertItem ( tr( "Discovered Device:" ), 9 );
253 248
254 for ( QMap<QString, QString>::Iterator it = m_devices. begin ( ); it != m_devices. end ( ); ++it ) 249 for ( QMap<QString, QString>::Iterator it = m_devices. begin ( ); it != m_devices. end ( ); ++it )
255 menu-> insertItem ( *it ); 250 menu-> insertItem ( *it );
256 251
257 menu-> insertSeparator ( ); 252 menu-> insertSeparator ( );
258 } 253 }
259 254
260 menu-> insertItem ( m_irda_active ? tr( "Disable IrDA" ) : tr( "Enable IrDA" ), 0 ); 255 menu-> insertItem ( m_irda_active ? tr( "Disable IrDA" ) : tr( "Enable IrDA" ), 0 );
261 256
262 if ( m_irda_active ) { 257 if ( m_irda_active ) {
263 menu-> insertItem ( m_irda_discovery_active ? tr( "Disable Discovery" ) : tr( "Enable Discovery" ), 1 ); 258 menu-> insertItem ( m_irda_discovery_active ? tr( "Disable Discovery" ) : tr( "Enable Discovery" ), 1 );
264 menu-> insertItem ( m_receive_active ? tr( "Disable Receive" ) : tr( "Enable Receive" ), 2 ); 259 menu-> insertItem ( m_receive_active ? tr( "Disable Receive" ) : tr( "Enable Receive" ), 2 );
265 } 260 }
266 261
267 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); 262 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) );
268 QSize s = menu-> sizeHint ( ); 263 QSize s = menu-> sizeHint ( );
269 264
270 p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( )); 265 p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ));
271 266
272 switch ( menu-> exec ( p )) { 267 switch ( menu-> exec ( p )) {
273 case 0: 268 case 0:
274 setIrdaStatus ( !m_irda_active ); 269 setIrdaStatus ( !m_irda_active );
275 timerEvent ( 0 ); 270 timerEvent ( 0 );
276 break; 271 break;
277 case 1: 272 case 1:
278 setIrdaDiscoveryStatus ( !m_irda_discovery_active ); 273 setIrdaDiscoveryStatus ( !m_irda_discovery_active );
279 timerEvent ( 0 ); 274 timerEvent ( 0 );
280 break; 275 break;
281 case 2: 276 case 2:
282 setIrdaReceiveStatus ( !m_receive_active ); 277 setIrdaReceiveStatus ( !m_receive_active );
283 timerEvent( 0 ); 278 timerEvent( 0 );
284 break; 279 break;
285 } 280 }
286 281
287 delete menu; 282 delete menu;
288} 283}
289 284
290void IrdaApplet::timerEvent ( QTimerEvent * ) 285void IrdaApplet::timerEvent ( QTimerEvent * )
291{ 286{
292 bool oldactive = m_irda_active; 287 bool oldactive = m_irda_active;
293 bool olddiscovery = m_irda_discovery_active; 288 bool olddiscovery = m_irda_discovery_active;
294 bool receiveUpdate = false; 289 bool receiveUpdate = false;
295 290
296 if ( m_receive_state_changed ) { 291 if ( m_receive_state_changed ) {
297 receiveUpdate = true; 292 receiveUpdate = true;
298 m_receive_state_changed = false; 293 m_receive_state_changed = false;
299 } 294 }
300 295
301 m_irda_active = checkIrdaStatus ( ); 296 m_irda_active = checkIrdaStatus ( );
302 m_irda_discovery_active = checkIrdaDiscoveryStatus ( ); 297 m_irda_discovery_active = checkIrdaDiscoveryStatus ( );
303 298
304 if ( m_irda_discovery_active ) 299 if ( m_irda_discovery_active )
305 showDiscovered ( ); 300 showDiscovered ( );
306 301
307 if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate ) 302 if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate )
308 update ( ); 303 update ( );
309} 304}
310 305
311void IrdaApplet::paintEvent ( QPaintEvent * ) 306void IrdaApplet::paintEvent ( QPaintEvent * )
312{ 307{
313 QPainter p ( this ); 308 QPainter p ( this );
314 309
315 p. drawPixmap ( 0, 1, m_irda_active ? m_irdaOnPixmap : m_irdaOffPixmap ); 310 p. drawPixmap ( 0, 1, m_irda_active ? m_irdaOnPixmap : m_irdaOffPixmap );
316 311
317 if ( m_irda_discovery_active ) 312 if ( m_irda_discovery_active )
318 p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap ); 313 p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap );
319 314
320 if ( m_receive_active ) 315 if ( m_receive_active )
321 p. drawPixmap( 0, 1, m_receiveActivePixmap ); 316 p. drawPixmap( 0, 1, m_receiveActivePixmap );
322} 317}
323/* 318/*
324 * We know 3 calls 319 * We know 3 calls
325 * a) enable 320 * a) enable
326 * b) disable 321 * b) disable
327 * a and b will temp enable the IrDa device and disable will disable it again if it wasn't on 322 * a and b will temp enable the IrDa device and disable will disable it again if it wasn't on
328 * c) listDevices: We will return a list of known devices 323 * c) listDevices: We will return a list of known devices
329 */ 324 */
330void IrdaApplet::slotMessage( const QCString& str, const QByteArray& ar ) { 325void IrdaApplet::slotMessage( const QCString& str, const QByteArray& ar ) {
331 if ( str == "enableIrda()") { 326 if ( str == "enableIrda()") {
332 m_wasOn = checkIrdaStatus(); 327 m_wasOn = checkIrdaStatus();
333 m_wasDiscover = checkIrdaDiscoveryStatus(); 328 m_wasDiscover = checkIrdaDiscoveryStatus();
334 if (!m_wasOn) { 329 if (!m_wasOn) {
335 setIrdaStatus( true ); 330 setIrdaStatus( true );
336 } 331 }
337 if ( !m_wasDiscover ) { 332 if ( !m_wasDiscover ) {
338 setIrdaDiscoveryStatus ( true ); 333 setIrdaDiscoveryStatus ( true );
339 } 334 }
340 } else if ( str == "disableIrda()") { 335 } else if ( str == "disableIrda()") {
341 if (!m_wasOn) { 336 if (!m_wasOn) {
342 setIrdaStatus( false ); 337 setIrdaStatus( false );
343 } 338 }
344 if ( !m_wasDiscover ) { 339 if ( !m_wasDiscover ) {
345 setIrdaDiscoveryStatus ( false ); 340 setIrdaDiscoveryStatus ( false );
346 } 341 }
347 } else if ( str == "listDevices()") { 342 } else if ( str == "listDevices()") {
348 QCopEnvelope e("QPE/IrDaAppletBack", "devices(QStringList)"); 343 QCopEnvelope e("QPE/IrDaAppletBack", "devices(QStringList)");
349 344
350 QStringList list; 345 QStringList list;
351 QMap<QString, QString>::Iterator it; 346 QMap<QString, QString>::Iterator it;
352 for (it = m_devices.begin(); it != m_devices.end(); ++it ) 347 for (it = m_devices.begin(); it != m_devices.end(); ++it )
353 list << (*it); 348 list << (*it);
354 349
355 e << list; 350 e << list;
356 } 351 }
357} 352}
diff --git a/core/applets/logoutapplet/logout.cpp b/core/applets/logoutapplet/logout.cpp
index 92222c9..0ac0067 100644
--- a/core/applets/logoutapplet/logout.cpp
+++ b/core/applets/logoutapplet/logout.cpp
@@ -1,126 +1,124 @@
1#include <qpe/resource.h> 1#include <qpe/resource.h>
2#include <qpe/qcopenvelope_qws.h> 2#include <qpe/qcopenvelope_qws.h>
3 3
4#include <qapplication.h> 4#include <qapplication.h>
5#include <qiconset.h>
6#include <qpopupmenu.h>
7#include <qmessagebox.h> 5#include <qmessagebox.h>
8 6
9#include <unistd.h> 7#include <unistd.h>
10 8
11#include "logout.h" 9#include "logout.h"
12 10
13 11
14LogoutApplet::LogoutApplet ( ) 12LogoutApplet::LogoutApplet ( )
15 : QObject ( 0, "LogoutApplet" ) 13 : QObject ( 0, "LogoutApplet" )
16{ 14{
17} 15}
18 16
19LogoutApplet::~LogoutApplet ( ) 17LogoutApplet::~LogoutApplet ( )
20{ 18{
21} 19}
22 20
23int LogoutApplet::position ( ) const 21int LogoutApplet::position ( ) const
24{ 22{
25 return 0; 23 return 0;
26} 24}
27 25
28QString LogoutApplet::name ( ) const 26QString LogoutApplet::name ( ) const
29{ 27{
30 return tr( "Logout shortcut" ); 28 return tr( "Logout shortcut" );
31} 29}
32 30
33QString LogoutApplet::text ( ) const 31QString LogoutApplet::text ( ) const
34{ 32{
35 return tr( "Logout" ); 33 return tr( "Logout" );
36} 34}
37 35
38QString LogoutApplet::tr( const char* s ) const 36QString LogoutApplet::tr( const char* s ) const
39{ 37{
40 return qApp->translate( "LogoutApplet", s, 0 ); 38 return qApp->translate( "LogoutApplet", s, 0 );
41} 39}
42 40
43QString LogoutApplet::tr( const char* s, const char* p ) const 41QString LogoutApplet::tr( const char* s, const char* p ) const
44{ 42{
45 return qApp->translate( "LogoutApplet", s, p ); 43 return qApp->translate( "LogoutApplet", s, p );
46} 44}
47 45
48QIconSet LogoutApplet::icon ( ) const 46QIconSet LogoutApplet::icon ( ) const
49{ 47{
50 QPixmap pix; 48 QPixmap pix;
51 QImage img = Resource::loadImage ( "logout" ); 49 QImage img = Resource::loadImage ( "logout" );
52 50
53 if ( !img. isNull ( )) 51 if ( !img. isNull ( ))
54 pix. convertFromImage ( img. smoothScale ( 14, 14 )); 52 pix. convertFromImage ( img. smoothScale ( 14, 14 ));
55 return pix; 53 return pix;
56} 54}
57 55
58QPopupMenu *LogoutApplet::popup ( QWidget * ) const 56QPopupMenu *LogoutApplet::popup ( QWidget * ) const
59{ 57{
60 return 0; 58 return 0;
61} 59}
62 60
63// This is a workaround for a Qt bug 61// This is a workaround for a Qt bug
64// clipboard applet has to stop its poll timer, or Qt/E 62// clipboard applet has to stop its poll timer, or Qt/E
65// will hang on quit() right before it emits aboutToQuit() 63// will hang on quit() right before it emits aboutToQuit()
66 64
67class HackApplication : public QApplication { 65class HackApplication : public QApplication {
68public: 66public:
69 HackApplication ( ) : QApplication ( dummy, 0 ) 67 HackApplication ( ) : QApplication ( dummy, 0 )
70 { 68 {
71 } 69 }
72 70
73 void emit_about_to_quit ( ) 71 void emit_about_to_quit ( )
74 { 72 {
75 emit aboutToQuit ( ); 73 emit aboutToQuit ( );
76 } 74 }
77 75
78 int dummy; 76 int dummy;
79}; 77};
80 78
81 79
82void LogoutApplet::activated ( ) 80void LogoutApplet::activated ( )
83{ 81{
84 QMessageBox mb ( tr( "Logout" ), 82 QMessageBox mb ( tr( "Logout" ),
85 tr( "Do you really want to\nend this session ?" ), 83 tr( "Do you really want to\nend this session ?" ),
86 QMessageBox::NoIcon, 84 QMessageBox::NoIcon,
87 QMessageBox::Yes | QMessageBox::Default, 85 QMessageBox::Yes | QMessageBox::Default,
88 QMessageBox::No | QMessageBox::Escape, 86 QMessageBox::No | QMessageBox::Escape,
89 QMessageBox::NoButton ); 87 QMessageBox::NoButton );
90 88
91 mb. setButtonText ( QMessageBox::Yes, "Yes" ); 89 mb. setButtonText ( QMessageBox::Yes, "Yes" );
92 mb. setButtonText ( QMessageBox::No, "No" ); 90 mb. setButtonText ( QMessageBox::No, "No" );
93 mb. setIconPixmap ( icon ( ). pixmap ( )); 91 mb. setIconPixmap ( icon ( ). pixmap ( ));
94 92
95 if ( mb. exec ( ) == QMessageBox::Yes ) { 93 if ( mb. exec ( ) == QMessageBox::Yes ) {
96 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); } 94 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); }
97 95
98 qApp-> processEvents ( ); // ensure the message goes out. 96 qApp-> processEvents ( ); // ensure the message goes out.
99 sleep ( 1 ); // You have 1 second to comply. 97 sleep ( 1 ); // You have 1 second to comply.
100 98
101 ((HackApplication *) qApp )-> emit_about_to_quit ( ); 99 ((HackApplication *) qApp )-> emit_about_to_quit ( );
102 qApp-> quit(); 100 qApp-> quit();
103 } 101 }
104} 102}
105 103
106 104
107QRESULT LogoutApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) 105QRESULT LogoutApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface )
108{ 106{
109 *iface = 0; 107 *iface = 0;
110 if ( uuid == IID_QUnknown ) 108 if ( uuid == IID_QUnknown )
111 *iface = this; 109 *iface = this;
112 else if ( uuid == IID_MenuApplet ) 110 else if ( uuid == IID_MenuApplet )
113 *iface = this; 111 *iface = this;
114 else 112 else
115 return QS_FALSE; 113 return QS_FALSE;
116 114
117 if ( *iface ) 115 if ( *iface )
118 (*iface)-> addRef ( ); 116 (*iface)-> addRef ( );
119 return QS_OK; 117 return QS_OK;
120} 118}
121 119
122Q_EXPORT_INTERFACE( ) 120Q_EXPORT_INTERFACE( )
123{ 121{
124 Q_CREATE_INSTANCE( LogoutApplet ) 122 Q_CREATE_INSTANCE( LogoutApplet )
125} 123}
126 124
diff --git a/core/applets/multikeyapplet/multikey.cpp b/core/applets/multikeyapplet/multikey.cpp
index b36ee12..b17498d 100644
--- a/core/applets/multikeyapplet/multikey.cpp
+++ b/core/applets/multikeyapplet/multikey.cpp
@@ -1,149 +1,143 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2004 Anton Kachalov mouse@altlinux.ru 2** Copyright (C) 2004 Anton Kachalov mouse@altlinux.ru
3** All rights reserved. 3** All rights reserved.
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13**********************************************************************/ 13**********************************************************************/
14 14
15#include "multikey.h" 15#include "multikey.h"
16 16
17/* OPIE */ 17/* OPIE */
18#include <opie2/otaskbarapplet.h> 18#include <opie2/otaskbarapplet.h>
19#include <qpe/global.h>
20#include <qpe/config.h>
21#include <qpe/qcopenvelope_qws.h> 19#include <qpe/qcopenvelope_qws.h>
22#include <qpe/qpeapplication.h>
23 20
24/* QT */ 21/* QT */
25#include <qlabel.h>
26#include <qdir.h> 22#include <qdir.h>
27#include <qfileinfo.h>
28#include <qcopchannel_qws.h>
29 23
30Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN") 24Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN")
31{ 25{
32 QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this); 26 QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this);
33 connect( swChannel, SIGNAL(received(const QCString &, const QByteArray &)), 27 connect( swChannel, SIGNAL(received(const QCString &, const QByteArray &)),
34 this, SLOT(message(const QCString &, const QByteArray &))); 28 this, SLOT(message(const QCString &, const QByteArray &)));
35 29
36 setFont( QFont( "Helvetica", 10, QFont::Normal ) ); 30 setFont( QFont( "Helvetica", 10, QFont::Normal ) );
37 QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold); 31 QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold);
38 lang = 0; 32 lang = 0;
39 QCopEnvelope e("MultiKey/Keyboard", "getmultikey()"); 33 QCopEnvelope e("MultiKey/Keyboard", "getmultikey()");
40 setText("EN"); 34 setText("EN");
41 popupMenu.insertItem("EN", 0); 35 popupMenu.insertItem("EN", 0);
42 show(); 36 show();
43} 37}
44 38
45void Multikey::mousePressEvent(QMouseEvent *ev) 39void Multikey::mousePressEvent(QMouseEvent *ev)
46{ 40{
47 if (!sw_maps.count()) 41 if (!sw_maps.count())
48 return; 42 return;
49 43
50 if (ev->button() == RightButton) { 44 if (ev->button() == RightButton) {
51 45
52 QPoint p = mapToGlobal(QPoint(0, 0)); 46 QPoint p = mapToGlobal(QPoint(0, 0));
53 QSize s = popupMenu.sizeHint(); 47 QSize s = popupMenu.sizeHint();
54 int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), 48 int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2),
55 p.y() - s.height()), 0); 49 p.y() - s.height()), 0);
56 50
57 if (opt == -1) 51 if (opt == -1)
58 return; 52 return;
59 lang = opt; 53 lang = opt;
60 54
61 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); 55 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)");
62 e << sw_maps[lang]; 56 e << sw_maps[lang];
63 setText(labels[lang]); 57 setText(labels[lang]);
64 } 58 }
65 QWidget::mousePressEvent(ev); 59 QWidget::mousePressEvent(ev);
66} 60}
67 61
68void Multikey::mouseReleaseEvent(QMouseEvent *ev) 62void Multikey::mouseReleaseEvent(QMouseEvent *ev)
69{ 63{
70 if (!sw_maps.count()) 64 if (!sw_maps.count())
71 return; 65 return;
72 66
73 lang = lang < sw_maps.count()-1 ? lang+1 : 0; 67 lang = lang < sw_maps.count()-1 ? lang+1 : 0;
74 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); 68 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)");
75 //qDebug("Lang=%d, count=%d, lab=%s", lang, sw_maps.count(), labels[lang].ascii()); 69 //qDebug("Lang=%d, count=%d, lab=%s", lang, sw_maps.count(), labels[lang].ascii());
76 e << sw_maps[lang]; 70 e << sw_maps[lang];
77 setText(labels[lang]); 71 setText(labels[lang]);
78} 72}
79 73
80void Multikey::message(const QCString &message, const QByteArray &data) 74void Multikey::message(const QCString &message, const QByteArray &data)
81{ 75{
82 if ( message == "setsw(QString,QString)" ) { 76 if ( message == "setsw(QString,QString)" ) {
83 77
84 QDataStream stream(data, IO_ReadOnly); 78 QDataStream stream(data, IO_ReadOnly);
85 QString maps, current_map; 79 QString maps, current_map;
86 stream >> maps >> current_map; 80 stream >> maps >> current_map;
87 QStringList sw = QStringList::split(QChar('|'), maps); 81 QStringList sw = QStringList::split(QChar('|'), maps);
88 sw.append(current_map); 82 sw.append(current_map);
89 83
90 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap"); 84 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap");
91 lang = 0; 85 lang = 0;
92 labels.clear(); 86 labels.clear();
93 sw_maps.clear(); 87 sw_maps.clear();
94 popupMenu.clear(); 88 popupMenu.clear();
95 89
96 for (uint i = 0; i < sw.count(); ++i) { 90 for (uint i = 0; i < sw.count(); ++i) {
97 QString keymap_map; 91 QString keymap_map;
98 if (sw[i][0] != '/') { 92 if (sw[i][0] != '/') {
99 93
100 keymap_map = map_dir.absPath() + "/" + sw[i]; 94 keymap_map = map_dir.absPath() + "/" + sw[i];
101 } else { 95 } else {
102 96
103 if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false) 97 if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false)
104 && i != sw.count()-1) || !QFile::exists(sw[i])) { 98 && i != sw.count()-1) || !QFile::exists(sw[i])) {
105 continue; 99 continue;
106 } 100 }
107 keymap_map = sw[i]; 101 keymap_map = sw[i];
108 } 102 }
109 103
110 QFile map(keymap_map); 104 QFile map(keymap_map);
111 if (map.open(IO_ReadOnly)) { 105 if (map.open(IO_ReadOnly)) {
112 QString line; 106 QString line;
113 107
114 map.readLine(line, 1024); 108 map.readLine(line, 1024);
115 while (!map.atEnd()) { 109 while (!map.atEnd()) {
116 110
117 if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) { 111 if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) {
118 112
119 if (i != sw.count()-1) { 113 if (i != sw.count()-1) {
120 if (keymap_map == current_map) { 114 if (keymap_map == current_map) {
121 lang = i; 115 lang = i;
122 } 116 }
123 sw_maps.append(keymap_map); 117 sw_maps.append(keymap_map);
124 labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); 118 labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
125 popupMenu.insertItem(labels[labels.count()-1], labels.count()-1); 119 popupMenu.insertItem(labels[labels.count()-1], labels.count()-1);
126 } else { 120 } else {
127 current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace(); 121 current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace();
128 } 122 }
129 break; 123 break;
130 } 124 }
131 map.readLine(line, 1024); 125 map.readLine(line, 1024);
132 } 126 }
133 map.close(); 127 map.close();
134 } 128 }
135 } 129 }
136 130
137 setText(current); 131 setText(current);
138 } 132 }
139} 133}
140 134
141int Multikey::position() 135int Multikey::position()
142{ 136{
143 return 10; 137 return 10;
144} 138}
145 139
146Q_EXPORT_INTERFACE() 140Q_EXPORT_INTERFACE()
147{ 141{
148 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<Multikey> ); 142 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<Multikey> );
149} 143}
diff --git a/core/launcher/applauncher.cpp b/core/launcher/applauncher.cpp
index c3584ad..7d3c032 100644
--- a/core/launcher/applauncher.cpp
+++ b/core/launcher/applauncher.cpp
@@ -1,724 +1,720 @@
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#ifndef QTOPIA_INTERNAL_PRELOADACCESS 21#ifndef QTOPIA_INTERNAL_PRELOADACCESS
22#define QTOPIA_INTERNAL_PRELOADACCESS 22#define QTOPIA_INTERNAL_PRELOADACCESS
23#endif 23#endif
24#ifndef QTOPIA_INTERNAL_FILEOPERATIONS 24#ifndef QTOPIA_INTERNAL_FILEOPERATIONS
25#define QTOPIA_INTERNAL_FILEOPERATIONS 25#define QTOPIA_INTERNAL_FILEOPERATIONS
26#endif 26#endif
27#ifndef QTOPIA_PROGRAM_MONITOR 27#ifndef QTOPIA_PROGRAM_MONITOR
28#define QTOPIA_PROGRAM_MONITOR 28#define QTOPIA_PROGRAM_MONITOR
29#endif 29#endif
30#include <opie2/oglobal.h> 30#include <opie2/oglobal.h>
31 31
32#ifndef Q_OS_WIN32 32#ifndef Q_OS_WIN32
33#include <sys/stat.h> 33#include <sys/stat.h>
34#include <sys/wait.h> 34#include <sys/wait.h>
35#include <sys/file.h> 35#include <sys/file.h>
36#include <unistd.h> 36#include <unistd.h>
37#include <sys/time.h> 37#include <sys/time.h>
38#include <sys/resource.h> 38#include <sys/resource.h>
39#include <errno.h> 39#include <errno.h>
40#else 40#else
41#include <process.h> 41#include <process.h>
42#include <windows.h> 42#include <windows.h>
43#include <winbase.h> 43#include <winbase.h>
44#endif 44#endif
45 45
46#include <signal.h> 46#include <signal.h>
47#include <sys/types.h> 47#include <sys/types.h>
48#include <stdlib.h> 48#include <stdlib.h>
49 49
50#include <qtimer.h> 50#include <qtimer.h>
51#include <qwindowsystem_qws.h> 51#include <qwindowsystem_qws.h>
52#include <qmessagebox.h> 52#include <qmessagebox.h>
53#include <qfile.h>
54#include <qfileinfo.h> 53#include <qfileinfo.h>
55 54
56#include <qtopia/qcopenvelope_qws.h> 55#include <qtopia/qcopenvelope_qws.h>
57#include <qtopia/applnk.h>
58#include <qtopia/qpeapplication.h> 56#include <qtopia/qpeapplication.h>
59#include <qtopia/config.h>
60#include <qtopia/global.h>
61 57
62#include "applauncher.h" 58#include "applauncher.h"
63#include "documentlist.h" 59#include "documentlist.h"
64 60
65const int AppLauncher::RAISE_TIMEOUT_MS = 5000; 61const int AppLauncher::RAISE_TIMEOUT_MS = 5000;
66 62
67//--------------------------------------------------------------------------- 63//---------------------------------------------------------------------------
68 64
69static AppLauncher* appLauncherPtr; 65static AppLauncher* appLauncherPtr;
70 66
71const int appStopEventID = 1290; 67const int appStopEventID = 1290;
72 68
73class AppStoppedEvent : public QCustomEvent 69class AppStoppedEvent : public QCustomEvent
74{ 70{
75public: 71public:
76 AppStoppedEvent(int pid, int status) 72 AppStoppedEvent(int pid, int status)
77 : QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { } 73 : QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { }
78 74
79 int pid() { return mPid; } 75 int pid() { return mPid; }
80 int status() { return mStatus; } 76 int status() { return mStatus; }
81 77
82private: 78private:
83 int mPid, mStatus; 79 int mPid, mStatus;
84}; 80};
85 81
86AppLauncher::AppLauncher(QObject *parent, const char *name) 82AppLauncher::AppLauncher(QObject *parent, const char *name)
87 : QObject(parent, name), qlPid(0), qlReady(FALSE), 83 : QObject(parent, name), qlPid(0), qlReady(FALSE),
88 appKillerBox(0) 84 appKillerBox(0)
89{ 85{
90 connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); 86 connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&)));
91 connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&))); 87 connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&)));
92 QCopChannel* channel = new QCopChannel( "QPE/System", this ); 88 QCopChannel* channel = new QCopChannel( "QPE/System", this );
93 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 89 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
94 this, SLOT(received(const QCString&, const QByteArray&)) ); 90 this, SLOT(received(const QCString&, const QByteArray&)) );
95 91
96 channel = new QCopChannel( "QPE/Server", this ); 92 channel = new QCopChannel( "QPE/Server", this );
97 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 93 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
98 this, SLOT(received(const QCString&, const QByteArray&)) ); 94 this, SLOT(received(const QCString&, const QByteArray&)) );
99 95
100#ifndef Q_OS_WIN32 96#ifndef Q_OS_WIN32
101 signal(SIGCHLD, signalHandler); 97 signal(SIGCHLD, signalHandler);
102#else 98#else
103 runningAppsProc.setAutoDelete( TRUE ); 99 runningAppsProc.setAutoDelete( TRUE );
104#endif 100#endif
105 QString tmp = qApp->argv()[0]; 101 QString tmp = qApp->argv()[0];
106 int pos = tmp.findRev('/'); 102 int pos = tmp.findRev('/');
107 if ( pos > -1 ) 103 if ( pos > -1 )
108 tmp = tmp.mid(++pos); 104 tmp = tmp.mid(++pos);
109 runningApps[::getpid()] = tmp; 105 runningApps[::getpid()] = tmp;
110 106
111 appLauncherPtr = this; 107 appLauncherPtr = this;
112 108
113 QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) ); 109 QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) );
114} 110}
115 111
116AppLauncher::~AppLauncher() 112AppLauncher::~AppLauncher()
117{ 113{
118 appLauncherPtr = 0; 114 appLauncherPtr = 0;
119#ifndef Q_OS_WIN32 115#ifndef Q_OS_WIN32
120 signal(SIGCHLD, SIG_DFL); 116 signal(SIGCHLD, SIG_DFL);
121#endif 117#endif
122 if ( qlPid ) { 118 if ( qlPid ) {
123 int status; 119 int status;
124 ::kill( qlPid, SIGTERM ); 120 ::kill( qlPid, SIGTERM );
125 waitpid( qlPid, &status, 0 ); 121 waitpid( qlPid, &status, 0 );
126 } 122 }
127} 123}
128 124
129/* We use the QCopChannel of the app as an indicator of when it has been launched 125/* We use the QCopChannel of the app as an indicator of when it has been launched
130 so that we can disable the busy indicators */ 126 so that we can disable the busy indicators */
131void AppLauncher::newQcopChannel(const QString& channelName) 127void AppLauncher::newQcopChannel(const QString& channelName)
132{ 128{
133// qDebug("channel %s added", channelName.data() ); 129// qDebug("channel %s added", channelName.data() );
134 QString prefix("QPE/Application/"); 130 QString prefix("QPE/Application/");
135 if (channelName.startsWith(prefix)) { 131 if (channelName.startsWith(prefix)) {
136 { 132 {
137 QCopEnvelope e("QPE/System", "newChannel(QString)"); 133 QCopEnvelope e("QPE/System", "newChannel(QString)");
138 e << channelName; 134 e << channelName;
139 } 135 }
140 QString appName = channelName.mid(prefix.length()); 136 QString appName = channelName.mid(prefix.length());
141 if ( appName != "quicklauncher" ) { 137 if ( appName != "quicklauncher" ) {
142 emit connected( appName ); 138 emit connected( appName );
143 QCopEnvelope e("QPE/System", "notBusy(QString)"); 139 QCopEnvelope e("QPE/System", "notBusy(QString)");
144 e << appName; 140 e << appName;
145 } 141 }
146 } else if (channelName.startsWith("QPE/QuickLauncher-")) { 142 } else if (channelName.startsWith("QPE/QuickLauncher-")) {
147 qDebug("Registered %s", channelName.latin1()); 143 qDebug("Registered %s", channelName.latin1());
148 int pid = channelName.mid(18).toInt(); 144 int pid = channelName.mid(18).toInt();
149 if (pid == qlPid) 145 if (pid == qlPid)
150 qlReady = TRUE; 146 qlReady = TRUE;
151 } 147 }
152} 148}
153 149
154void AppLauncher::removedQcopChannel(const QString& channelName) 150void AppLauncher::removedQcopChannel(const QString& channelName)
155{ 151{
156 if (channelName.startsWith("QPE/Application/")) { 152 if (channelName.startsWith("QPE/Application/")) {
157 QCopEnvelope e("QPE/System", "removedChannel(QString)"); 153 QCopEnvelope e("QPE/System", "removedChannel(QString)");
158 e << channelName; 154 e << channelName;
159 } 155 }
160} 156}
161 157
162void AppLauncher::received(const QCString& msg, const QByteArray& data) 158void AppLauncher::received(const QCString& msg, const QByteArray& data)
163{ 159{
164 QDataStream stream( data, IO_ReadOnly ); 160 QDataStream stream( data, IO_ReadOnly );
165 if ( msg == "execute(QString)" ) { 161 if ( msg == "execute(QString)" ) {
166 QString t; 162 QString t;
167 stream >> t; 163 stream >> t;
168 if ( !executeBuiltin( t, QString::null ) ) 164 if ( !executeBuiltin( t, QString::null ) )
169 execute(t, QString::null); 165 execute(t, QString::null);
170 } else if ( msg == "execute(QString,QString)" ) { 166 } else if ( msg == "execute(QString,QString)" ) {
171 QString t,d; 167 QString t,d;
172 stream >> t >> d; 168 stream >> t >> d;
173 if ( !executeBuiltin( t, d ) ) 169 if ( !executeBuiltin( t, d ) )
174 execute( t, d ); 170 execute( t, d );
175 } else if ( msg == "processQCop(QString)" ) { // from QPE/Server 171 } else if ( msg == "processQCop(QString)" ) { // from QPE/Server
176 QString t; 172 QString t;
177 stream >> t; 173 stream >> t;
178 if ( !executeBuiltin( t, QString::null ) ) 174 if ( !executeBuiltin( t, QString::null ) )
179 execute( t, QString::null, TRUE); 175 execute( t, QString::null, TRUE);
180 } else if ( msg == "raise(QString)" ) { 176 } else if ( msg == "raise(QString)" ) {
181 QString appName; 177 QString appName;
182 stream >> appName; 178 stream >> appName;
183 179
184 if ( !executeBuiltin( appName, QString::null ) ) { 180 if ( !executeBuiltin( appName, QString::null ) ) {
185 if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { 181 if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) {
186 //qDebug( "Raising: %s", appName.latin1() ); 182 //qDebug( "Raising: %s", appName.latin1() );
187 QCString channel = "QPE/Application/"; 183 QCString channel = "QPE/Application/";
188 channel += appName.latin1(); 184 channel += appName.latin1();
189 185
190 // Need to lock it to avoid race conditions with QPEApplication::processQCopFile 186 // Need to lock it to avoid race conditions with QPEApplication::processQCopFile
191 QFile f("/tmp/qcop-msg-" + appName); 187 QFile f("/tmp/qcop-msg-" + appName);
192 if ( f.open(IO_WriteOnly | IO_Append) ) { 188 if ( f.open(IO_WriteOnly | IO_Append) ) {
193#ifndef Q_OS_WIN32 189#ifndef Q_OS_WIN32
194 flock(f.handle(), LOCK_EX); 190 flock(f.handle(), LOCK_EX);
195#endif 191#endif
196 QDataStream ds(&f); 192 QDataStream ds(&f);
197 QByteArray b; 193 QByteArray b;
198 QDataStream bstream(b, IO_WriteOnly); 194 QDataStream bstream(b, IO_WriteOnly);
199 ds << channel << QCString("raise()") << b; 195 ds << channel << QCString("raise()") << b;
200 f.flush(); 196 f.flush();
201#ifndef Q_OS_WIN32 197#ifndef Q_OS_WIN32
202 flock(f.handle(), LOCK_UN); 198 flock(f.handle(), LOCK_UN);
203#endif 199#endif
204 f.close(); 200 f.close();
205 } 201 }
206 bool alreadyRunning = isRunning( appName ); 202 bool alreadyRunning = isRunning( appName );
207 if ( execute(appName, QString::null) ) { 203 if ( execute(appName, QString::null) ) {
208 int id = startTimer(RAISE_TIMEOUT_MS + alreadyRunning?2000:0); 204 int id = startTimer(RAISE_TIMEOUT_MS + alreadyRunning?2000:0);
209 waitingHeartbeat.insert( appName, id ); 205 waitingHeartbeat.insert( appName, id );
210 } 206 }
211 } 207 }
212 } 208 }
213 } else if ( msg == "sendRunningApps()" ) { 209 } else if ( msg == "sendRunningApps()" ) {
214 QStringList apps; 210 QStringList apps;
215 QMap<int,QString>::Iterator it; 211 QMap<int,QString>::Iterator it;
216 for( it = runningApps.begin(); it != runningApps.end(); ++it ) 212 for( it = runningApps.begin(); it != runningApps.end(); ++it )
217 apps.append( *it ); 213 apps.append( *it );
218 QCopEnvelope e( "QPE/Desktop", "runningApps(QStringList)" ); 214 QCopEnvelope e( "QPE/Desktop", "runningApps(QStringList)" );
219 e << apps; 215 e << apps;
220 } else if ( msg == "appRaised(QString)" ) { 216 } else if ( msg == "appRaised(QString)" ) {
221 QString appName; 217 QString appName;
222 stream >> appName; 218 stream >> appName;
223 qDebug("Got a heartbeat from %s", appName.latin1()); 219 qDebug("Got a heartbeat from %s", appName.latin1());
224 QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName); 220 QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName);
225 if ( it != waitingHeartbeat.end() ) { 221 if ( it != waitingHeartbeat.end() ) {
226 killTimer( *it ); 222 killTimer( *it );
227 waitingHeartbeat.remove(it); 223 waitingHeartbeat.remove(it);
228 } 224 }
229 // Check to make sure we're not waiting on user input... 225 // Check to make sure we're not waiting on user input...
230 if ( appKillerBox && appName == appKillerName ) { 226 if ( appKillerBox && appName == appKillerName ) {
231 // If we are, we kill the dialog box, and the code waiting on the result 227 // If we are, we kill the dialog box, and the code waiting on the result
232 // will clean us up (basically the user said "no"). 228 // will clean us up (basically the user said "no").
233 delete appKillerBox; 229 delete appKillerBox;
234 appKillerBox = 0; 230 appKillerBox = 0;
235 appKillerName = QString::null; 231 appKillerName = QString::null;
236 } 232 }
237 } 233 }
238} 234}
239 235
240void AppLauncher::signalHandler(int) 236void AppLauncher::signalHandler(int)
241{ 237{
242#ifndef Q_OS_WIN32 238#ifndef Q_OS_WIN32
243 int status; 239 int status;
244 pid_t pid = waitpid(-1, &status, WNOHANG); 240 pid_t pid = waitpid(-1, &status, WNOHANG);
245/* if (pid == 0 || &status == 0 ) { 241/* if (pid == 0 || &status == 0 ) {
246 qDebug("hmm, could not get return value from signal"); 242 qDebug("hmm, could not get return value from signal");
247 } 243 }
248*/ 244*/
249 QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) ); 245 QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) );
250#else 246#else
251 qDebug("Unhandled signal see by AppLauncher::signalHandler(int)"); 247 qDebug("Unhandled signal see by AppLauncher::signalHandler(int)");
252#endif 248#endif
253} 249}
254 250
255bool AppLauncher::event(QEvent *e) 251bool AppLauncher::event(QEvent *e)
256{ 252{
257 if ( e->type() == appStopEventID ) { 253 if ( e->type() == appStopEventID ) {
258 AppStoppedEvent *ae = (AppStoppedEvent *) e; 254 AppStoppedEvent *ae = (AppStoppedEvent *) e;
259 sigStopped(ae->pid(), ae->status() ); 255 sigStopped(ae->pid(), ae->status() );
260 return TRUE; 256 return TRUE;
261 } 257 }
262 258
263 return QObject::event(e); 259 return QObject::event(e);
264} 260}
265 261
266void AppLauncher::timerEvent( QTimerEvent *e ) 262void AppLauncher::timerEvent( QTimerEvent *e )
267{ 263{
268 int id = e->timerId(); 264 int id = e->timerId();
269 QMap<QString,int>::Iterator it; 265 QMap<QString,int>::Iterator it;
270 for ( it = waitingHeartbeat.begin(); it != waitingHeartbeat.end(); ++it ) { 266 for ( it = waitingHeartbeat.begin(); it != waitingHeartbeat.end(); ++it ) {
271 if ( *it == id ) { 267 if ( *it == id ) {
272 if ( appKillerBox ) // we're already dealing with one 268 if ( appKillerBox ) // we're already dealing with one
273 return; 269 return;
274 270
275 appKillerName = it.key(); 271 appKillerName = it.key();
276 killTimer( id ); 272 killTimer( id );
277 waitingHeartbeat.remove( it ); 273 waitingHeartbeat.remove( it );
278 274
279 // qDebug("Checking in on %s", appKillerName.latin1()); 275 // qDebug("Checking in on %s", appKillerName.latin1());
280 276
281 // We store this incase the application responds while we're 277 // We store this incase the application responds while we're
282 // waiting for user input so we know not to delete ourselves. 278 // waiting for user input so we know not to delete ourselves.
283 appKillerBox = new QMessageBox(tr("Application Problem"), 279 appKillerBox = new QMessageBox(tr("Application Problem"),
284 tr("<p>%1 is not responding.</p>").arg(appKillerName) + 280 tr("<p>%1 is not responding.</p>").arg(appKillerName) +
285 tr("<p>Would you like to force the application to exit?</p>"), 281 tr("<p>Would you like to force the application to exit?</p>"),
286 QMessageBox::Warning, QMessageBox::Yes, 282 QMessageBox::Warning, QMessageBox::Yes,
287 QMessageBox::No | QMessageBox::Default, 283 QMessageBox::No | QMessageBox::Default,
288 QMessageBox::NoButton); 284 QMessageBox::NoButton);
289 if (appKillerBox->exec() == QMessageBox::Yes) { 285 if (appKillerBox->exec() == QMessageBox::Yes) {
290 // qDebug("Killing the app!!! Bwuhahahaha!"); 286 // qDebug("Killing the app!!! Bwuhahahaha!");
291 int pid = pidForName(appKillerName); 287 int pid = pidForName(appKillerName);
292 if ( pid > 0 ) 288 if ( pid > 0 )
293 kill( pid ); 289 kill( pid );
294 } 290 }
295 appKillerName = QString::null; 291 appKillerName = QString::null;
296 delete appKillerBox; 292 delete appKillerBox;
297 appKillerBox = 0; 293 appKillerBox = 0;
298 return; 294 return;
299 } 295 }
300 } 296 }
301 297
302 QObject::timerEvent( e ); 298 QObject::timerEvent( e );
303} 299}
304 300
305#ifndef Q_OS_WIN32 301#ifndef Q_OS_WIN32
306void AppLauncher::sigStopped(int sigPid, int sigStatus) 302void AppLauncher::sigStopped(int sigPid, int sigStatus)
307{ 303{
308 int exitStatus = 0; 304 int exitStatus = 0;
309 305
310 bool crashed = WIFSIGNALED(sigStatus); 306 bool crashed = WIFSIGNALED(sigStatus);
311 if ( !crashed ) { 307 if ( !crashed ) {
312 if ( WIFEXITED(sigStatus) ) 308 if ( WIFEXITED(sigStatus) )
313 exitStatus = WEXITSTATUS(sigStatus); 309 exitStatus = WEXITSTATUS(sigStatus);
314 } else { 310 } else {
315 exitStatus = WTERMSIG(sigStatus); 311 exitStatus = WTERMSIG(sigStatus);
316 } 312 }
317 313
318 QMap<int,QString>::Iterator it = runningApps.find( sigPid ); 314 QMap<int,QString>::Iterator it = runningApps.find( sigPid );
319 if ( it == runningApps.end() ) { 315 if ( it == runningApps.end() ) {
320 if ( sigPid == qlPid ) { 316 if ( sigPid == qlPid ) {
321 qDebug( "quicklauncher stopped" ); 317 qDebug( "quicklauncher stopped" );
322 qlPid = 0; 318 qlPid = 0;
323 qlReady = FALSE; 319 qlReady = FALSE;
324 QFile::remove("/tmp/qcop-msg-quicklauncher" ); 320 QFile::remove("/tmp/qcop-msg-quicklauncher" );
325 QTimer::singleShot( 2000, this, SLOT(createQuickLauncher()) ); 321 QTimer::singleShot( 2000, this, SLOT(createQuickLauncher()) );
326 } 322 }
327/* 323/*
328 if ( sigPid == -1 ) 324 if ( sigPid == -1 )
329 qDebug("non-qtopia application exited (disregarded)"); 325 qDebug("non-qtopia application exited (disregarded)");
330 else 326 else
331 qDebug("==== no pid matching %d in list, definite bug", sigPid); 327 qDebug("==== no pid matching %d in list, definite bug", sigPid);
332*/ 328*/
333 return; 329 return;
334 } 330 }
335 QString appName = *it; 331 QString appName = *it;
336 runningApps.remove(it); 332 runningApps.remove(it);
337 333
338 QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName); 334 QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName);
339 if ( hbit != waitingHeartbeat.end() ) { 335 if ( hbit != waitingHeartbeat.end() ) {
340 killTimer( *hbit ); 336 killTimer( *hbit );
341 waitingHeartbeat.remove( hbit ); 337 waitingHeartbeat.remove( hbit );
342 } 338 }
343 if ( appName == appKillerName ) { 339 if ( appName == appKillerName ) {
344 appKillerName = QString::null; 340 appKillerName = QString::null;
345 delete appKillerBox; 341 delete appKillerBox;
346 appKillerBox = 0; 342 appKillerBox = 0;
347 } 343 }
348 344
349 /* we must disable preload for an app that crashes as the system logic relies on preloaded apps 345 /* we must disable preload for an app that crashes as the system logic relies on preloaded apps
350 actually being loaded. If eg. the crash happened in the constructor, we can't automatically reload 346 actually being loaded. If eg. the crash happened in the constructor, we can't automatically reload
351 the app (withouth some timeout value for eg. 3 tries (which I think is a bad solution) 347 the app (withouth some timeout value for eg. 3 tries (which I think is a bad solution)
352 */ 348 */
353 bool preloadDisabled = FALSE; 349 bool preloadDisabled = FALSE;
354 if ( !DocumentList::appLnkSet ) return; 350 if ( !DocumentList::appLnkSet ) return;
355 const AppLnk* app = DocumentList::appLnkSet->findExec( appName ); 351 const AppLnk* app = DocumentList::appLnkSet->findExec( appName );
356 if ( !app ) return; // QCop messages processed to slow? 352 if ( !app ) return; // QCop messages processed to slow?
357 if ( crashed && app->isPreloaded() ) { 353 if ( crashed && app->isPreloaded() ) {
358 Config cfg("Launcher"); 354 Config cfg("Launcher");
359 cfg.setGroup("Preload"); 355 cfg.setGroup("Preload");
360 QStringList apps = cfg.readListEntry("Apps",','); 356 QStringList apps = cfg.readListEntry("Apps",',');
361 QString exe = app->exec(); 357 QString exe = app->exec();
362 apps.remove(exe); 358 apps.remove(exe);
363 cfg.writeEntry("Apps",apps,','); 359 cfg.writeEntry("Apps",apps,',');
364 preloadDisabled = TRUE; 360 preloadDisabled = TRUE;
365 } 361 }
366 362
367 // clean up 363 // clean up
368 if ( exitStatus ) { 364 if ( exitStatus ) {
369 QCopEnvelope e("QPE/System", "notBusy(QString)"); 365 QCopEnvelope e("QPE/System", "notBusy(QString)");
370 e << app->exec(); 366 e << app->exec();
371 } 367 }
372/* 368/*
373 // debug info 369 // debug info
374 for (it = runningApps.begin(); it != runningApps.end(); ++it) { 370 for (it = runningApps.begin(); it != runningApps.end(); ++it) {
375 qDebug("running according to internal list: %s, with pid %d", (*it).data(), it.key() ); 371 qDebug("running according to internal list: %s, with pid %d", (*it).data(), it.key() );
376 } 372 }
377*/ 373*/
378 374
379#ifdef QTOPIA_PROGRAM_MONITOR 375#ifdef QTOPIA_PROGRAM_MONITOR
380 if ( crashed ) { 376 if ( crashed ) {
381 QString sig; 377 QString sig;
382 switch( exitStatus ) { 378 switch( exitStatus ) {
383 case SIGABRT: sig = "SIGABRT"; break; 379 case SIGABRT: sig = "SIGABRT"; break;
384 case SIGALRM: sig = "SIGALRM"; break; 380 case SIGALRM: sig = "SIGALRM"; break;
385 case SIGBUS: sig = "SIGBUS"; break; 381 case SIGBUS: sig = "SIGBUS"; break;
386 case SIGFPE: sig = "SIGFPE"; break; 382 case SIGFPE: sig = "SIGFPE"; break;
387 case SIGHUP: sig = "SIGHUP"; break; 383 case SIGHUP: sig = "SIGHUP"; break;
388 case SIGILL: sig = "SIGILL"; break; 384 case SIGILL: sig = "SIGILL"; break;
389 case SIGKILL: sig = "SIGKILL"; break; 385 case SIGKILL: sig = "SIGKILL"; break;
390 case SIGPIPE: sig = "SIGPIPE"; break; 386 case SIGPIPE: sig = "SIGPIPE"; break;
391 case SIGQUIT: sig = "SIGQUIT"; break; 387 case SIGQUIT: sig = "SIGQUIT"; break;
392 case SIGSEGV: sig = "SIGSEGV"; break; 388 case SIGSEGV: sig = "SIGSEGV"; break;
393 case SIGTERM: sig = "SIGTERM"; break; 389 case SIGTERM: sig = "SIGTERM"; break;
394 case SIGTRAP: sig = "SIGTRAP"; break; 390 case SIGTRAP: sig = "SIGTRAP"; break;
395 default: sig = QString("Unkown %1").arg(exitStatus); 391 default: sig = QString("Unkown %1").arg(exitStatus);
396 } 392 }
397 if ( preloadDisabled ) 393 if ( preloadDisabled )
398 sig += tr("<qt><p>Fast loading has been disabled for this application. Tap and hold the application icon to reenable it.</qt>"); 394 sig += tr("<qt><p>Fast loading has been disabled for this application. Tap and hold the application icon to reenable it.</qt>");
399 395
400 QString str = tr("<qt><b>%1</b> was terminated due to signal code %2</qt>").arg( app->name() ).arg( sig ); 396 QString str = tr("<qt><b>%1</b> was terminated due to signal code %2</qt>").arg( app->name() ).arg( sig );
401 QMessageBox::information(0, tr("Application terminated"), str ); 397 QMessageBox::information(0, tr("Application terminated"), str );
402 } else { 398 } else {
403 if ( exitStatus == 255 ) { //could not find app (because global returns -1) 399 if ( exitStatus == 255 ) { //could not find app (because global returns -1)
404 QMessageBox::information(0, tr("Application not found"), tr("<qt>Could not locate application <b>%1</b></qt>").arg( app->exec() ) ); 400 QMessageBox::information(0, tr("Application not found"), tr("<qt>Could not locate application <b>%1</b></qt>").arg( app->exec() ) );
405 } else { 401 } else {
406 QFileInfo fi(QString::fromLatin1("/tmp/qcop-msg-") + appName); 402 QFileInfo fi(QString::fromLatin1("/tmp/qcop-msg-") + appName);
407 if ( fi.exists() && fi.size() ) { 403 if ( fi.exists() && fi.size() ) {
408 emit terminated(sigPid, appName); 404 emit terminated(sigPid, appName);
409 qWarning("Re executing obmitted for %s", appName.latin1() ); 405 qWarning("Re executing obmitted for %s", appName.latin1() );
410 // execute( appName, QString::null ); 406 // execute( appName, QString::null );
411 return; 407 return;
412 } 408 }
413 } 409 }
414 } 410 }
415 411
416#endif 412#endif
417 413
418 emit terminated(sigPid, appName); 414 emit terminated(sigPid, appName);
419} 415}
420#else 416#else
421void AppLauncher::sigStopped(int sigPid, int sigStatus) 417void AppLauncher::sigStopped(int sigPid, int sigStatus)
422{ 418{
423 qDebug("Unhandled signal : AppLauncher::sigStopped(int sigPid, int sigStatus)"); 419 qDebug("Unhandled signal : AppLauncher::sigStopped(int sigPid, int sigStatus)");
424} 420}
425#endif // Q_OS_WIN32 421#endif // Q_OS_WIN32
426 422
427bool AppLauncher::isRunning(const QString &app) 423bool AppLauncher::isRunning(const QString &app)
428{ 424{
429 for (QMap<int,QString>::ConstIterator it = runningApps.begin(); it != runningApps.end(); ++it) { 425 for (QMap<int,QString>::ConstIterator it = runningApps.begin(); it != runningApps.end(); ++it) {
430 if ( *it == app ) { 426 if ( *it == app ) {
431#ifdef Q_OS_UNIX 427#ifdef Q_OS_UNIX
432 pid_t t = ::__getpgid( it.key() ); 428 pid_t t = ::__getpgid( it.key() );
433 if ( t == -1 ) { 429 if ( t == -1 ) {
434 qDebug("appLauncher bug, %s believed running, but pid %d is not existing", app.data(), it.key() ); 430 qDebug("appLauncher bug, %s believed running, but pid %d is not existing", app.data(), it.key() );
435 runningApps.remove( it.key() ); 431 runningApps.remove( it.key() );
436 return FALSE; 432 return FALSE;
437 } 433 }
438#endif 434#endif
439 return TRUE; 435 return TRUE;
440 } 436 }
441 } 437 }
442 438
443 return FALSE; 439 return FALSE;
444} 440}
445 441
446bool AppLauncher::executeBuiltin(const QString &c, const QString &document) 442bool AppLauncher::executeBuiltin(const QString &c, const QString &document)
447{ 443{
448 Global::Command* builtin = OGlobal::builtinCommands(); 444 Global::Command* builtin = OGlobal::builtinCommands();
449 QGuardedPtr<QWidget> *running = OGlobal::builtinRunning(); 445 QGuardedPtr<QWidget> *running = OGlobal::builtinRunning();
450 446
451 // Attempt to execute the app using a builtin class for the app 447 // Attempt to execute the app using a builtin class for the app
452 if (builtin) { 448 if (builtin) {
453 for (int i = 0; builtin[i].file; i++) { 449 for (int i = 0; builtin[i].file; i++) {
454 if ( builtin[i].file == c ) { 450 if ( builtin[i].file == c ) {
455 if ( running[i] ) { 451 if ( running[i] ) {
456 if ( !document.isNull() && builtin[i].documentary ) 452 if ( !document.isNull() && builtin[i].documentary )
457 Global::setDocument(running[i], document); 453 Global::setDocument(running[i], document);
458 running[i]->raise(); 454 running[i]->raise();
459 running[i]->show(); 455 running[i]->show();
460 running[i]->setActiveWindow(); 456 running[i]->setActiveWindow();
461 } else { 457 } else {
462 running[i] = builtin[i].func( builtin[i].maximized ); 458 running[i] = builtin[i].func( builtin[i].maximized );
463 } 459 }
464#ifndef QT_NO_COP 460#ifndef QT_NO_COP
465 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 461 QCopEnvelope e("QPE/System", "notBusy(QString)" );
466 e << c; // that was quick ;-) 462 e << c; // that was quick ;-)
467#endif 463#endif
468 return TRUE; 464 return TRUE;
469 } 465 }
470 } 466 }
471 } 467 }
472 468
473 // Convert the command line in to a list of arguments 469 // Convert the command line in to a list of arguments
474 QStringList list = QStringList::split(QRegExp(" *"),c); 470 QStringList list = QStringList::split(QRegExp(" *"),c);
475 QString ap=list[0]; 471 QString ap=list[0];
476 472
477 if ( ap == "suspend" ) { // No tr 473 if ( ap == "suspend" ) { // No tr
478 QWSServer::processKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 474 QWSServer::processKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
479 return TRUE; 475 return TRUE;
480 } 476 }
481 477
482 return FALSE; 478 return FALSE;
483} 479}
484 480
485bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRaise) 481bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRaise)
486{ 482{
487 qWarning("AppLauncher::execute '%s' '%s'", (const char*) c, (const char*) docParam ); 483 qWarning("AppLauncher::execute '%s' '%s'", (const char*) c, (const char*) docParam );
488 // Convert the command line in to a list of arguments 484 // Convert the command line in to a list of arguments
489 QStringList list = QStringList::split(QRegExp(" *"),c); 485 QStringList list = QStringList::split(QRegExp(" *"),c);
490 if ( !docParam.isEmpty() ) 486 if ( !docParam.isEmpty() )
491 list.append( docParam ); 487 list.append( docParam );
492 488
493 QString appName = list[0]; 489 QString appName = list[0];
494 if ( isRunning(appName) ) { 490 if ( isRunning(appName) ) {
495 QCString channel = "QPE/Application/"; 491 QCString channel = "QPE/Application/";
496 channel += appName.latin1(); 492 channel += appName.latin1();
497 493
498 // Need to lock it to avoid race conditions with QPEApplication::processQCopFile 494 // Need to lock it to avoid race conditions with QPEApplication::processQCopFile
499 QFile f(QString::fromLatin1("/tmp/qcop-msg-") + appName); 495 QFile f(QString::fromLatin1("/tmp/qcop-msg-") + appName);
500 if ( !noRaise && f.open(IO_WriteOnly | IO_Append) ) { 496 if ( !noRaise && f.open(IO_WriteOnly | IO_Append) ) {
501#ifndef Q_OS_WIN32 497#ifndef Q_OS_WIN32
502 flock(f.handle(), LOCK_EX); 498 flock(f.handle(), LOCK_EX);
503#endif 499#endif
504 500
505 QDataStream ds(&f); 501 QDataStream ds(&f);
506 QByteArray b; 502 QByteArray b;
507 QDataStream bstream(b, IO_WriteOnly); 503 QDataStream bstream(b, IO_WriteOnly);
508 if ( !f.size() ) { 504 if ( !f.size() ) {
509 ds << channel << QCString("raise()") << b; 505 ds << channel << QCString("raise()") << b;
510 if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { 506 if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) {
511 int id = startTimer(RAISE_TIMEOUT_MS); 507 int id = startTimer(RAISE_TIMEOUT_MS);
512 waitingHeartbeat.insert( appName, id ); 508 waitingHeartbeat.insert( appName, id );
513 } 509 }
514 } 510 }
515 if ( !docParam.isEmpty() ) { 511 if ( !docParam.isEmpty() ) {
516 bstream << docParam; 512 bstream << docParam;
517 ds << channel << QCString("setDocument(QString)") << b; 513 ds << channel << QCString("setDocument(QString)") << b;
518 } 514 }
519 515
520 f.flush(); 516 f.flush();
521#ifndef Q_OS_WIN32 517#ifndef Q_OS_WIN32
522 flock(f.handle(), LOCK_UN); 518 flock(f.handle(), LOCK_UN);
523#endif 519#endif
524 f.close(); 520 f.close();
525 } 521 }
526 if ( QCopChannel::isRegistered(channel) ) // avoid unnecessary warnings 522 if ( QCopChannel::isRegistered(channel) ) // avoid unnecessary warnings
527 QCopChannel::send(channel,"QPEProcessQCop()"); 523 QCopChannel::send(channel,"QPEProcessQCop()");
528 524
529 return TRUE; 525 return TRUE;
530 } 526 }
531 527
532#ifdef QT_NO_QWS_MULTIPROCESS 528#ifdef QT_NO_QWS_MULTIPROCESS
533 QMessageBox::warning( 0, tr("Error"), tr("<qt>Could not find the application %1</qt>").arg(c), 529 QMessageBox::warning( 0, tr("Error"), tr("<qt>Could not find the application %1</qt>").arg(c),
534 tr("OK"), 0, 0, 0, 1 ); 530 tr("OK"), 0, 0, 0, 1 );
535#else 531#else
536 532
537 QStrList slist; 533 QStrList slist;
538 unsigned j; 534 unsigned j;
539 for ( j = 0; j < list.count(); j++ ) 535 for ( j = 0; j < list.count(); j++ )
540 slist.append( list[j].utf8() ); 536 slist.append( list[j].utf8() );
541 537
542 const char **args = new const char *[slist.count() + 1]; 538 const char **args = new const char *[slist.count() + 1];
543 for ( j = 0; j < slist.count(); j++ ) 539 for ( j = 0; j < slist.count(); j++ )
544 args[j] = slist.at(j); 540 args[j] = slist.at(j);
545 args[j] = NULL; 541 args[j] = NULL;
546 542
547#ifndef Q_OS_WIN32 543#ifndef Q_OS_WIN32
548#ifdef Q_OS_MACX 544#ifdef Q_OS_MACX
549 if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".dylib" ) ) { 545 if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".dylib" ) ) {
550#else 546#else
551 if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".so" ) ) { 547 if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".so" ) ) {
552#endif /* Q_OS_MACX */ 548#endif /* Q_OS_MACX */
553 qDebug( "Quick launching: %s", args[0] ); 549 qDebug( "Quick launching: %s", args[0] );
554 if ( getuid() == 0 ) 550 if ( getuid() == 0 )
555 setpriority( PRIO_PROCESS, qlPid, 0 ); 551 setpriority( PRIO_PROCESS, qlPid, 0 );
556 QCString qlch("QPE/QuickLauncher-"); 552 QCString qlch("QPE/QuickLauncher-");
557 qlch += QString::number(qlPid); 553 qlch += QString::number(qlPid);
558 QCopEnvelope env( qlch, "execute(QStrList)" ); 554 QCopEnvelope env( qlch, "execute(QStrList)" );
559 env << slist; 555 env << slist;
560 runningApps[qlPid] = QString(args[0]); 556 runningApps[qlPid] = QString(args[0]);
561 emit launched(qlPid, QString(args[0])); 557 emit launched(qlPid, QString(args[0]));
562 QCopEnvelope e("QPE/System", "busy()"); 558 QCopEnvelope e("QPE/System", "busy()");
563 qlPid = 0; 559 qlPid = 0;
564 qlReady = FALSE; 560 qlReady = FALSE;
565 QTimer::singleShot( getuid() == 0 ? 800 : 1500, this, SLOT(createQuickLauncher()) ); 561 QTimer::singleShot( getuid() == 0 ? 800 : 1500, this, SLOT(createQuickLauncher()) );
566 } else { 562 } else {
567 int pid = ::vfork(); 563 int pid = ::vfork();
568 if ( !pid ) { 564 if ( !pid ) {
569 for ( int fd = 3; fd < 100; fd++ ) 565 for ( int fd = 3; fd < 100; fd++ )
570 ::close( fd ); 566 ::close( fd );
571 ::setpgid( ::getpid(), ::getppid() ); 567 ::setpgid( ::getpid(), ::getppid() );
572 // Try bindir first, so that foo/bar works too 568 // Try bindir first, so that foo/bar works too
573 ::execv( QPEApplication::qpeDir()+"bin/"+args[0], (char * const *)args ); 569 ::execv( QPEApplication::qpeDir()+"bin/"+args[0], (char * const *)args );
574 ::execvp( args[0], (char * const *)args ); 570 ::execvp( args[0], (char * const *)args );
575 _exit( -1 ); 571 _exit( -1 );
576 } 572 }
577 573
578 runningApps[pid] = QString(args[0]); 574 runningApps[pid] = QString(args[0]);
579 emit launched(pid, QString(args[0])); 575 emit launched(pid, QString(args[0]));
580 QCopEnvelope e("QPE/System", "busy()"); 576 QCopEnvelope e("QPE/System", "busy()");
581 } 577 }
582#else 578#else
583 QProcess *proc = new QProcess(this); 579 QProcess *proc = new QProcess(this);
584 if (proc){ 580 if (proc){
585 for (int i=0; i < slist.count(); i++) 581 for (int i=0; i < slist.count(); i++)
586 proc->addArgument(args[i]); 582 proc->addArgument(args[i]);
587 connect(proc, SIGNAL(processExited()), this, SLOT(processExited())); 583 connect(proc, SIGNAL(processExited()), this, SLOT(processExited()));
588 if (!proc->start()){ 584 if (!proc->start()){
589 qDebug("Unable to start application %s", args[0]); 585 qDebug("Unable to start application %s", args[0]);
590 }else{ 586 }else{
591 PROCESS_INFORMATION *procInfo = (PROCESS_INFORMATION *)proc->processIdentifier(); 587 PROCESS_INFORMATION *procInfo = (PROCESS_INFORMATION *)proc->processIdentifier();
592 if (procInfo){ 588 if (procInfo){
593 DWORD pid = procInfo->dwProcessId; 589 DWORD pid = procInfo->dwProcessId;
594 runningApps[pid] = QString(args[0]); 590 runningApps[pid] = QString(args[0]);
595 runningAppsProc.append(proc); 591 runningAppsProc.append(proc);
596 emit launched(pid, QString(args[0])); 592 emit launched(pid, QString(args[0]));
597 QCopEnvelope e("QPE/System", "busy()"); 593 QCopEnvelope e("QPE/System", "busy()");
598 }else{ 594 }else{
599 qDebug("Unable to read process inforation #1 for %s", args[0]); 595 qDebug("Unable to read process inforation #1 for %s", args[0]);
600 } 596 }
601 } 597 }
602 }else{ 598 }else{
603 qDebug("Unable to create process for application %s", args[0]); 599 qDebug("Unable to create process for application %s", args[0]);
604 return FALSE; 600 return FALSE;
605 } 601 }
606#endif 602#endif
607#endif //QT_NO_QWS_MULTIPROCESS 603#endif //QT_NO_QWS_MULTIPROCESS
608 604
609 delete [] args; 605 delete [] args;
610 return TRUE; 606 return TRUE;
611} 607}
612 608
613void AppLauncher::kill( int pid ) 609void AppLauncher::kill( int pid )
614{ 610{
615#ifndef Q_OS_WIN32 611#ifndef Q_OS_WIN32
616 ::kill( pid, SIGTERM ); 612 ::kill( pid, SIGTERM );
617#else 613#else
618 for ( QProcess *proc = runningAppsProc.first(); proc; proc = runningAppsProc.next() ) { 614 for ( QProcess *proc = runningAppsProc.first(); proc; proc = runningAppsProc.next() ) {
619 if ( proc->processIdentifier() == pid ) { 615 if ( proc->processIdentifier() == pid ) {
620 proc->kill(); 616 proc->kill();
621 break; 617 break;
622 } 618 }
623 } 619 }
624#endif 620#endif
625} 621}
626 622
627int AppLauncher::pidForName( const QString &appName ) 623int AppLauncher::pidForName( const QString &appName )
628{ 624{
629 int pid = -1; 625 int pid = -1;
630 626
631 QMap<int, QString>::Iterator it; 627 QMap<int, QString>::Iterator it;
632 for (it = runningApps.begin(); it!= runningApps.end(); ++it) { 628 for (it = runningApps.begin(); it!= runningApps.end(); ++it) {
633 if (*it == appName) { 629 if (*it == appName) {
634 pid = it.key(); 630 pid = it.key();
635 break; 631 break;
636 } 632 }
637 } 633 }
638 634
639 return pid; 635 return pid;
640} 636}
641 637
642void AppLauncher::createQuickLauncher() 638void AppLauncher::createQuickLauncher()
643{ 639{
644 static bool disabled = FALSE; 640 static bool disabled = FALSE;
645 if (disabled) 641 if (disabled)
646 return; 642 return;
647 643
648 qlReady = FALSE; 644 qlReady = FALSE;
649 qlPid = ::vfork(); 645 qlPid = ::vfork();
650 if ( !qlPid ) { 646 if ( !qlPid ) {
651 char **args = new char *[2]; 647 char **args = new char *[2];
652 args[0] = "quicklauncher"; 648 args[0] = "quicklauncher";
653 args[1] = 0; 649 args[1] = 0;
654 for ( int fd = 3; fd < 100; fd++ ) 650 for ( int fd = 3; fd < 100; fd++ )
655 ::close( fd ); 651 ::close( fd );
656 ::setpgid( ::getpid(), ::getppid() ); 652 ::setpgid( ::getpid(), ::getppid() );
657 // Try bindir first, so that foo/bar works too 653 // Try bindir first, so that foo/bar works too
658 /* 654 /*
659 * LD_BIND_NOW will change the behaviour of ld.so and dlopen 655 * LD_BIND_NOW will change the behaviour of ld.so and dlopen
660 * RTLD_LAZY will be made RTLD_NOW which leads to problem 656 * RTLD_LAZY will be made RTLD_NOW which leads to problem
661 * with miscompiled libraries... if LD_BIND_NOW is set.. there 657 * with miscompiled libraries... if LD_BIND_NOW is set.. there
662 * is no way back.. We will wait for numbers from TT to see 658 * is no way back.. We will wait for numbers from TT to see
663 * if using LD_BIND_NOW is worth it - zecke 659 * if using LD_BIND_NOW is worth it - zecke
664 */ 660 */
665 //setenv( "LD_BIND_NOW", "1", 1 ); 661 //setenv( "LD_BIND_NOW", "1", 1 );
666 ::execv( QPEApplication::qpeDir()+"bin/quicklauncher", args ); 662 ::execv( QPEApplication::qpeDir()+"bin/quicklauncher", args );
667 ::execvp( "quicklauncher", args ); 663 ::execvp( "quicklauncher", args );
668 delete []args; 664 delete []args;
669 disabled = TRUE; 665 disabled = TRUE;
670 _exit( -1 ); 666 _exit( -1 );
671 } else if ( qlPid == -1 ) { 667 } else if ( qlPid == -1 ) {
672 qlPid = 0; 668 qlPid = 0;
673 } else { 669 } else {
674 if ( getuid() == 0 ) 670 if ( getuid() == 0 )
675 setpriority( PRIO_PROCESS, qlPid, 19 ); 671 setpriority( PRIO_PROCESS, qlPid, 19 );
676 } 672 }
677} 673}
678 674
679// Used only by Win32 675// Used only by Win32
680void AppLauncher::processExited() 676void AppLauncher::processExited()
681{ 677{
682#ifdef Q_OS_WIN32 678#ifdef Q_OS_WIN32
683 qDebug("AppLauncher::processExited()"); 679 qDebug("AppLauncher::processExited()");
684 bool found = FALSE; 680 bool found = FALSE;
685 QProcess *proc = (QProcess *) sender(); 681 QProcess *proc = (QProcess *) sender();
686 if (!proc){ 682 if (!proc){
687 qDebug("Interanl error NULL proc"); 683 qDebug("Interanl error NULL proc");
688 return; 684 return;
689 } 685 }
690 686
691 QString appName = proc->arguments()[0]; 687 QString appName = proc->arguments()[0];
692 qDebug("Removing application %s", appName.latin1()); 688 qDebug("Removing application %s", appName.latin1());
693 runningAppsProc.remove(proc); 689 runningAppsProc.remove(proc);
694 690
695 QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName); 691 QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName);
696 if ( hbit != waitingHeartbeat.end() ) { 692 if ( hbit != waitingHeartbeat.end() ) {
697 killTimer( *hbit ); 693 killTimer( *hbit );
698 waitingHeartbeat.remove( hbit ); 694 waitingHeartbeat.remove( hbit );
699 } 695 }
700 if ( appName == appKillerName ) { 696 if ( appName == appKillerName ) {
701 appKillerName = QString::null; 697 appKillerName = QString::null;
702 delete appKillerBox; 698 delete appKillerBox;
703 appKillerBox = 0; 699 appKillerBox = 0;
704 } 700 }
705 701
706 // Search for the app to find its PID 702 // Search for the app to find its PID
707 QMap<int, QString>::Iterator it; 703 QMap<int, QString>::Iterator it;
708 for (it = runningApps.begin(); it!= runningApps.end(); ++it){ 704 for (it = runningApps.begin(); it!= runningApps.end(); ++it){
709 if (it.data() == appName){ 705 if (it.data() == appName){
710 found = TRUE; 706 found = TRUE;
711 break; 707 break;
712 } 708 }
713 } 709 }
714 710
715 if (found){ 711 if (found){
716 emit terminated(it.key(), it.data()); 712 emit terminated(it.key(), it.data());
717 runningApps.remove(it.key()); 713 runningApps.remove(it.key());
718 }else{ 714 }else{
719 qDebug("Internal error application %s not listed as running", appName.latin1()); 715 qDebug("Internal error application %s not listed as running", appName.latin1());
720 } 716 }
721 717
722#endif 718#endif
723} 719}
724 720
diff --git a/core/launcher/firstuse.cpp b/core/launcher/firstuse.cpp
index e07920f..50ae6c2 100644
--- a/core/launcher/firstuse.cpp
+++ b/core/launcher/firstuse.cpp
@@ -1,521 +1,513 @@
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// I need access to some things you don't normally get access to. 21// I need access to some things you don't normally get access to.
22 22
23#ifndef _MSC_VER 23#ifndef _MSC_VER
24 //### revise to allow removal of translators under MSVC 24 //### revise to allow removal of translators under MSVC
25#define private public 25#define private public
26#define protected public 26#define protected public
27#endif 27#endif
28#include "firstuse.h" 28#include "firstuse.h"
29#include "inputmethods.h" 29#include "inputmethods.h"
30#include "applauncher.h" 30#include "applauncher.h"
31#include "serverapp.h" 31#include "serverapp.h"
32//#include <qtopia/custom.h> 32//#include <qtopia/custom.h>
33 33
34#include "calibrate.h" 34#include "calibrate.h"
35#include "documentlist.h" 35#include "documentlist.h"
36 36
37#include <qtopia/resource.h> 37#include <qtopia/resource.h>
38#include <qtopia/qcopenvelope_qws.h> 38#include <qtopia/qcopenvelope_qws.h>
39#include <qtopia/qpeapplication.h>
40#include <qtopia/config.h> 39#include <qtopia/config.h>
41#include <qtopia/applnk.h>
42#include <qtopia/mimetype.h>
43#include <qtopia/fontmanager.h> 40#include <qtopia/fontmanager.h>
44 41
45#include <qapplication.h>
46#include <qfile.h> 42#include <qfile.h>
47#include <qpainter.h> 43#include <qpainter.h>
48#include <qcstring.h>
49#include <qsimplerichtext.h> 44#include <qsimplerichtext.h>
50#include <qcolor.h>
51#include <qpushbutton.h> 45#include <qpushbutton.h>
52#include <qhbox.h>
53#include <qlabel.h> 46#include <qlabel.h>
54#include <qtimer.h> 47#include <qtimer.h>
55 48
56#if defined( Q_WS_QWS ) 49#if defined( Q_WS_QWS )
57#include <qwsdisplay_qws.h> 50#include <qwsdisplay_qws.h>
58#include <qgfx_qws.h> 51#include <qgfx_qws.h>
59#endif 52#endif
60 53
61#include <qwindowsystem_qws.h>
62 54
63#include <stdlib.h> 55#include <stdlib.h>
64#include <sys/types.h> 56#include <sys/types.h>
65#if defined(Q_OS_LINUX) || defined(_OS_LINUX_) 57#if defined(Q_OS_LINUX) || defined(_OS_LINUX_)
66#include <unistd.h> 58#include <unistd.h>
67#endif 59#endif
68 60
69 61
70struct { 62struct {
71 bool enabled; 63 bool enabled;
72 const char *app; 64 const char *app;
73 const char *start; 65 const char *start;
74 const char *stop; 66 const char *stop;
75 const char *desc; 67 const char *desc;
76} 68}
77settingsTable [] = 69settingsTable [] =
78{ 70{
79 { FALSE, "language", "raise()", "accept()", // No tr 71 { FALSE, "language", "raise()", "accept()", // No tr
80 QT_TR_NOOP("Language") }, 72 QT_TR_NOOP("Language") },
81 { FALSE, "doctab", "raise()", "accept()", // No tr 73 { FALSE, "doctab", "raise()", "accept()", // No tr
82 QT_TR_NOOP("DocTab") }, 74 QT_TR_NOOP("DocTab") },
83#ifndef Q_OS_WIN32 75#ifndef Q_OS_WIN32
84 { FALSE, "systemtime", "raise()", "accept()", // No tr 76 { FALSE, "systemtime", "raise()", "accept()", // No tr
85 QT_TR_NOOP("Time and Date") }, 77 QT_TR_NOOP("Time and Date") },
86#endif 78#endif
87 { FALSE, "addressbook", "editPersonalAndClose()", "accept()", // No tr 79 { FALSE, "addressbook", "editPersonalAndClose()", "accept()", // No tr
88 QT_TR_NOOP("Personal Information") }, 80 QT_TR_NOOP("Personal Information") },
89 { FALSE, 0, 0, 0, 0 } 81 { FALSE, 0, 0, 0, 0 }
90}; 82};
91 83
92 84
93FirstUse::FirstUse(QWidget* parent, const char * name, WFlags wf) : 85FirstUse::FirstUse(QWidget* parent, const char * name, WFlags wf) :
94 QDialog( parent, name, TRUE, wf), 86 QDialog( parent, name, TRUE, wf),
95 transApp(0), transLib(0), needCalibrate(FALSE), currApp(-1), 87 transApp(0), transLib(0), needCalibrate(FALSE), currApp(-1),
96 waitForExit(-1), waitingForLaunch(FALSE), needRestart(FALSE) 88 waitForExit(-1), waitingForLaunch(FALSE), needRestart(FALSE)
97{ 89{
98 ServerApplication::allowRestart = FALSE; 90 ServerApplication::allowRestart = FALSE;
99 // we force our height beyound the maximum (which we set anyway) 91 // we force our height beyound the maximum (which we set anyway)
100 QRect desk = qApp->desktop()->geometry(); 92 QRect desk = qApp->desktop()->geometry();
101 setGeometry( 0, 0, desk.width(), desk.height() ); 93 setGeometry( 0, 0, desk.width(), desk.height() );
102 94
103 connect(qwsServer, SIGNAL(newChannel(const QString&)), 95 connect(qwsServer, SIGNAL(newChannel(const QString&)),
104 this, SLOT(newQcopChannel(const QString&))); 96 this, SLOT(newQcopChannel(const QString&)));
105 97
106 // Create a DocumentList so appLauncher has appLnkSet to search 98 // Create a DocumentList so appLauncher has appLnkSet to search
107 docList = new DocumentList( 0, FALSE ); 99 docList = new DocumentList( 0, FALSE );
108 appLauncher = new AppLauncher( this ); 100 appLauncher = new AppLauncher( this );
109 connect( appLauncher, SIGNAL(terminated(int, const QString&)), 101 connect( appLauncher, SIGNAL(terminated(int, const QString&)),
110 this, SLOT(terminated(int, const QString&)) ); 102 this, SLOT(terminated(int, const QString&)) );
111 103
112 // more hackery 104 // more hackery
113 // I will be run as either the main server or as part of the main server 105 // I will be run as either the main server or as part of the main server
114 QWSServer::setScreenSaverIntervals(0); 106 QWSServer::setScreenSaverIntervals(0);
115 loadPixmaps(); 107 loadPixmaps();
116 108
117 //check if there is a language program 109 //check if there is a language program
118#ifndef Q_OS_WIN32 110#ifndef Q_OS_WIN32
119 QString exeSuffix; 111 QString exeSuffix;
120#else 112#else
121 QString exeSuffix(".exe"); 113 QString exeSuffix(".exe");
122#endif 114#endif
123 115
124 for ( int i = 0; settingsTable[i].app; i++ ) { 116 for ( int i = 0; settingsTable[i].app; i++ ) {
125 QString file = QPEApplication::qpeDir() + "bin/"; 117 QString file = QPEApplication::qpeDir() + "bin/";
126 file += settingsTable[i].app; 118 file += settingsTable[i].app;
127 file += exeSuffix; 119 file += exeSuffix;
128 if ( QFile::exists(file) ) 120 if ( QFile::exists(file) )
129 settingsTable[i].enabled = TRUE; 121 settingsTable[i].enabled = TRUE;
130 } 122 }
131 123
132 setFocusPolicy(NoFocus); 124 setFocusPolicy(NoFocus);
133 125
134 taskBar = new QWidget(0, 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop | WGroupLeader); 126 taskBar = new QWidget(0, 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop | WGroupLeader);
135 127
136 inputMethods = new InputMethods(taskBar); 128 inputMethods = new InputMethods(taskBar);
137 connect(inputMethods, SIGNAL(inputToggled(bool)), 129 connect(inputMethods, SIGNAL(inputToggled(bool)),
138 this, SLOT(calcMaxWindowRect())); 130 this, SLOT(calcMaxWindowRect()));
139 131
140 back = new QPushButton(tr("<< Back"), taskBar); 132 back = new QPushButton(tr("<< Back"), taskBar);
141 back->setFocusPolicy(NoFocus); 133 back->setFocusPolicy(NoFocus);
142 connect(back, SIGNAL(clicked()), this, SLOT(previousDialog()) ); 134 connect(back, SIGNAL(clicked()), this, SLOT(previousDialog()) );
143 135
144 next = new QPushButton(tr("Next >>"), taskBar); 136 next = new QPushButton(tr("Next >>"), taskBar);
145 next->setFocusPolicy(NoFocus); 137 next->setFocusPolicy(NoFocus);
146 connect(next, SIGNAL(clicked()), this, SLOT(nextDialog()) ); 138 connect(next, SIGNAL(clicked()), this, SLOT(nextDialog()) );
147 139
148 // need to set the geom to lower corner 140 // need to set the geom to lower corner
149 QSize sz = inputMethods->sizeHint(); 141 QSize sz = inputMethods->sizeHint();
150 int buttonWidth = (width() - sz.width()) / 2; 142 int buttonWidth = (width() - sz.width()) / 2;
151 int x = 0; 143 int x = 0;
152 144
153 controlHeight = back->sizeHint().height(); 145 controlHeight = back->sizeHint().height();
154 146
155 inputMethods->setGeometry(0,0, sz.width(), controlHeight ); 147 inputMethods->setGeometry(0,0, sz.width(), controlHeight );
156 x += sz.width(); 148 x += sz.width();
157 149
158 back->setGeometry(x, 0, buttonWidth, controlHeight); 150 back->setGeometry(x, 0, buttonWidth, controlHeight);
159 x += buttonWidth; 151 x += buttonWidth;
160 next->setGeometry(x, 0, buttonWidth, controlHeight); 152 next->setGeometry(x, 0, buttonWidth, controlHeight);
161 153
162 taskBar->setGeometry( 0, height() - controlHeight, desk.width(), controlHeight); 154 taskBar->setGeometry( 0, height() - controlHeight, desk.width(), controlHeight);
163 taskBar->hide(); 155 taskBar->hide();
164 156
165#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 157#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
166 qDebug("Setting up QCop to QPE/System"); 158 qDebug("Setting up QCop to QPE/System");
167 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); 159 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this );
168 connect(sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), 160 connect(sysChannel, SIGNAL(received(const QCString &, const QByteArray &)),
169 this, SLOT(message(const QCString &, const QByteArray &)) ); 161 this, SLOT(message(const QCString &, const QByteArray &)) );
170#endif 162#endif
171 calcMaxWindowRect(); 163 calcMaxWindowRect();
172 164
173 m_calHandler = ( QWSServer::mouseHandler() && QWSServer::mouseHandler()->inherits("QCalibratedMouseHandler") ) ? true : false; 165 m_calHandler = ( QWSServer::mouseHandler() && QWSServer::mouseHandler()->inherits("QCalibratedMouseHandler") ) ? true : false;
174 166
175 if ( m_calHandler) { 167 if ( m_calHandler) {
176 if ( !QFile::exists("/etc/pointercal") ) { 168 if ( !QFile::exists("/etc/pointercal") ) {
177 needCalibrate = TRUE; 169 needCalibrate = TRUE;
178 grabMouse(); 170 grabMouse();
179 } 171 }
180 } 172 }
181 173
182 Config config("locale"); 174 Config config("locale");
183 config.setGroup( "Language"); 175 config.setGroup( "Language");
184 lang = config.readEntry( "Language", "en"); 176 lang = config.readEntry( "Language", "en");
185 177
186 defaultFont = font(); 178 defaultFont = font();
187 179
188 //###language/font hack; should look it up somewhere 180 //###language/font hack; should look it up somewhere
189#ifdef Q_WS_QWS 181#ifdef Q_WS_QWS
190 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 182 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
191 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 183 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
192 qApp->setFont( fn, TRUE ); 184 qApp->setFont( fn, TRUE );
193 } 185 }
194#endif 186#endif
195} 187}
196 188
197FirstUse::~FirstUse() 189FirstUse::~FirstUse()
198{ 190{
199 delete appLauncher; 191 delete appLauncher;
200 delete docList; 192 delete docList;
201 delete taskBar; 193 delete taskBar;
202 ServerApplication::allowRestart = TRUE; 194 ServerApplication::allowRestart = TRUE;
203} 195}
204 196
205void FirstUse::calcMaxWindowRect() 197void FirstUse::calcMaxWindowRect()
206{ 198{
207#ifdef Q_WS_QWS 199#ifdef Q_WS_QWS
208 QRect wr; 200 QRect wr;
209 int displayWidth = qApp->desktop()->width(); 201 int displayWidth = qApp->desktop()->width();
210 QRect ir = inputMethods->inputRect(); 202 QRect ir = inputMethods->inputRect();
211 if ( ir.isValid() ) { 203 if ( ir.isValid() ) {
212 wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); 204 wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 );
213 } else { 205 } else {
214 wr.setCoords( 0, 0, displayWidth-1, 206 wr.setCoords( 0, 0, displayWidth-1,
215 qApp->desktop()->height() - controlHeight-1); 207 qApp->desktop()->height() - controlHeight-1);
216 } 208 }
217 209
218#if QT_VERSION < 0x030000 210#if QT_VERSION < 0x030000
219 QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr, 211 QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr,
220 QSize(qt_screen->width(),qt_screen->height())) 212 QSize(qt_screen->width(),qt_screen->height()))
221 ); 213 );
222#else 214#else
223 QWSServer::setMaxWindowRect( wr ); 215 QWSServer::setMaxWindowRect( wr );
224#endif 216#endif
225#endif 217#endif
226} 218}
227 219
228/* cancel current dialog, and bring up next */ 220/* cancel current dialog, and bring up next */
229void FirstUse::nextDialog() 221void FirstUse::nextDialog()
230{ 222{
231 int prevApp = currApp; 223 int prevApp = currApp;
232 do { 224 do {
233 currApp++; 225 currApp++;
234 qDebug( "currApp = %d", currApp ); 226 qDebug( "currApp = %d", currApp );
235 if ( settingsTable[currApp].app == 0 ) { 227 if ( settingsTable[currApp].app == 0 ) {
236 if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) { 228 if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) {
237 // The last application is still running. 229 // The last application is still running.
238 // Tell it to stop, and when its done we'll come back 230 // Tell it to stop, and when its done we'll come back
239 // to nextDialog and exit. 231 // to nextDialog and exit.
240 qDebug( "Waiting for %s to exit", settingsTable[prevApp].app ); 232 qDebug( "Waiting for %s to exit", settingsTable[prevApp].app );
241 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, 233 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app,
242 settingsTable[prevApp].stop ); 234 settingsTable[prevApp].stop );
243 currApp = prevApp; 235 currApp = prevApp;
244 } else { 236 } else {
245 qDebug( "Done!" ); 237 qDebug( "Done!" );
246 Config config( "qpe" ); 238 Config config( "qpe" );
247 config.setGroup( "Startup" ); 239 config.setGroup( "Startup" );
248 config.writeEntry( "FirstUse", FALSE ); 240 config.writeEntry( "FirstUse", FALSE );
249 QPixmap pix = Resource::loadPixmap("bigwait"); 241 QPixmap pix = Resource::loadPixmap("bigwait");
250 QLabel *lblWait = new QLabel(0, "wait hack!", // No tr 242 QLabel *lblWait = new QLabel(0, "wait hack!", // No tr
251 QWidget::WStyle_Customize | QWidget::WDestructiveClose | 243 QWidget::WStyle_Customize | QWidget::WDestructiveClose |
252 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool | 244 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool |
253 QWidget::WStyle_StaysOnTop); 245 QWidget::WStyle_StaysOnTop);
254 lblWait->setPixmap( pix ); 246 lblWait->setPixmap( pix );
255 lblWait->setAlignment( QWidget::AlignCenter ); 247 lblWait->setAlignment( QWidget::AlignCenter );
256 lblWait->setGeometry( qApp->desktop()->geometry() ); 248 lblWait->setGeometry( qApp->desktop()->geometry() );
257 lblWait->show(); 249 lblWait->show();
258 qApp->processEvents(); 250 qApp->processEvents();
259 QTimer::singleShot( 1000, lblWait, SLOT(close()) ); 251 QTimer::singleShot( 1000, lblWait, SLOT(close()) );
260 repaint(); 252 repaint();
261 close(); 253 close();
262 ServerApplication::allowRestart = TRUE; 254 ServerApplication::allowRestart = TRUE;
263 } 255 }
264 return; 256 return;
265 } 257 }
266 } while ( !settingsTable[currApp].enabled ); 258 } while ( !settingsTable[currApp].enabled );
267 259
268 if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) { 260 if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) {
269 qDebug( "Shutdown: %s", settingsTable[prevApp].app ); 261 qDebug( "Shutdown: %s", settingsTable[prevApp].app );
270 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, 262 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app,
271 settingsTable[prevApp].stop ); 263 settingsTable[prevApp].stop );
272 waitForExit = prevApp; 264 waitForExit = prevApp;
273 } else { 265 } else {
274 qDebug( "Startup: %s", settingsTable[currApp].app ); 266 qDebug( "Startup: %s", settingsTable[currApp].app );
275 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, 267 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app,
276 settingsTable[currApp].start ); 268 settingsTable[currApp].start );
277 waitingForLaunch = TRUE; 269 waitingForLaunch = TRUE;
278 } 270 }
279 271
280 updateButtons(); 272 updateButtons();
281} 273}
282 274
283/* accept current dialog and bring up previous */ 275/* accept current dialog and bring up previous */
284void FirstUse::previousDialog() 276void FirstUse::previousDialog()
285{ 277{
286 int prevApp = currApp; 278 int prevApp = currApp;
287 do { 279 do {
288 currApp--; 280 currApp--;
289 if ( currApp < 0 ) { 281 if ( currApp < 0 ) {
290 currApp = prevApp; 282 currApp = prevApp;
291 return; 283 return;
292 } 284 }
293 } while ( !settingsTable[currApp].enabled ); 285 } while ( !settingsTable[currApp].enabled );
294 286
295 if ( prevApp >= 0 ) { 287 if ( prevApp >= 0 ) {
296 qDebug( "Shutdown: %s", settingsTable[prevApp].app ); 288 qDebug( "Shutdown: %s", settingsTable[prevApp].app );
297 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, 289 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app,
298 settingsTable[prevApp].stop ); 290 settingsTable[prevApp].stop );
299/* 291/*
300 if (settingsTable[prevApp].app == QString("systemtime")) 292 if (settingsTable[prevApp].app == QString("systemtime"))
301 QCopEnvelope e("QPE/Application/citytime", "close()"); 293 QCopEnvelope e("QPE/Application/citytime", "close()");
302*/ 294*/
303 waitForExit = prevApp; 295 waitForExit = prevApp;
304 } else { 296 } else {
305 qDebug( "Startup: %s", settingsTable[currApp].app ); 297 qDebug( "Startup: %s", settingsTable[currApp].app );
306 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, 298 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app,
307 settingsTable[currApp].start ); 299 settingsTable[currApp].start );
308 waitingForLaunch = TRUE; 300 waitingForLaunch = TRUE;
309 } 301 }
310 302
311 updateButtons(); 303 updateButtons();
312} 304}
313 305
314void FirstUse::message(const QCString &msg, const QByteArray &data) 306void FirstUse::message(const QCString &msg, const QByteArray &data)
315{ 307{
316 QDataStream stream( data, IO_ReadOnly ); 308 QDataStream stream( data, IO_ReadOnly );
317 if ( msg == "timeChange(QString)" ) { 309 if ( msg == "timeChange(QString)" ) {
318 QString t; 310 QString t;
319 stream >> t; 311 stream >> t;
320 if ( t.isNull() ) 312 if ( t.isNull() )
321 unsetenv("TZ"); 313 unsetenv("TZ");
322 else 314 else
323 setenv( "TZ", t.latin1(), 1 ); 315 setenv( "TZ", t.latin1(), 1 );
324 } 316 }
325} 317}
326 318
327void FirstUse::terminated( int, const QString &app ) 319void FirstUse::terminated( int, const QString &app )
328{ 320{
329 qDebug( "--- terminated: %s", app.latin1() ); 321 qDebug( "--- terminated: %s", app.latin1() );
330 if ( waitForExit != -1 && settingsTable[waitForExit].app == app ) { 322 if ( waitForExit != -1 && settingsTable[waitForExit].app == app ) {
331 qDebug( "Startup: %s", settingsTable[currApp].app ); 323 qDebug( "Startup: %s", settingsTable[currApp].app );
332 if ( settingsTable[waitForExit].app == "language" ) { // No tr 324 if ( settingsTable[waitForExit].app == "language" ) { // No tr
333 Config config("locale"); 325 Config config("locale");
334 config.setGroup( "Language"); 326 config.setGroup( "Language");
335 QString l = config.readEntry( "Language", "en"); 327 QString l = config.readEntry( "Language", "en");
336 if ( l != lang ) { 328 if ( l != lang ) {
337 reloadLanguages(); 329 reloadLanguages();
338 needRestart = TRUE; 330 needRestart = TRUE;
339 lang = l; 331 lang = l;
340 } 332 }
341 } 333 }
342 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, 334 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app,
343 settingsTable[currApp].start ); 335 settingsTable[currApp].start );
344 waitingForLaunch = TRUE; 336 waitingForLaunch = TRUE;
345 updateButtons(); 337 updateButtons();
346 repaint(); 338 repaint();
347 waitForExit = -1; 339 waitForExit = -1;
348 } else if ( settingsTable[currApp].app == app ) { 340 } else if ( settingsTable[currApp].app == app ) {
349 nextDialog(); 341 nextDialog();
350 } else { 342 } else {
351 back->setEnabled(TRUE); 343 back->setEnabled(TRUE);
352 next->setEnabled(TRUE); 344 next->setEnabled(TRUE);
353 } 345 }
354} 346}
355 347
356void FirstUse::newQcopChannel(const QString& channelName) 348void FirstUse::newQcopChannel(const QString& channelName)
357{ 349{
358 qDebug("channel %s added", channelName.data() ); 350 qDebug("channel %s added", channelName.data() );
359 QString prefix("QPE/Application/"); 351 QString prefix("QPE/Application/");
360 if (channelName.startsWith(prefix)) { 352 if (channelName.startsWith(prefix)) {
361 QString appName = channelName.mid(prefix.length()); 353 QString appName = channelName.mid(prefix.length());
362 if ( currApp >= 0 && appName == settingsTable[currApp].app ) { 354 if ( currApp >= 0 && appName == settingsTable[currApp].app ) {
363 qDebug( "Application: %s started", settingsTable[currApp].app ); 355 qDebug( "Application: %s started", settingsTable[currApp].app );
364 waitingForLaunch = FALSE; 356 waitingForLaunch = FALSE;
365 updateButtons(); 357 updateButtons();
366 repaint(); 358 repaint();
367 } else if (appName != "quicklauncher") { 359 } else if (appName != "quicklauncher") {
368 back->setEnabled(FALSE); 360 back->setEnabled(FALSE);
369 next->setEnabled(FALSE); 361 next->setEnabled(FALSE);
370 } 362 }
371 } 363 }
372} 364}
373 365
374void FirstUse::reloadLanguages() 366void FirstUse::reloadLanguages()
375{ 367{
376 // read language from config file. Waiting on QCop takes too long. 368 // read language from config file. Waiting on QCop takes too long.
377 Config config("locale"); 369 Config config("locale");
378 config.setGroup( "Language"); 370 config.setGroup( "Language");
379 QString l = config.readEntry( "Language", "en"); 371 QString l = config.readEntry( "Language", "en");
380 QString cl = getenv("LANG"); 372 QString cl = getenv("LANG");
381 qWarning("language message - " + l); 373 qWarning("language message - " + l);
382 // setting anyway... 374 // setting anyway...
383 if (l.isNull() ) 375 if (l.isNull() )
384 unsetenv( "LANG" ); 376 unsetenv( "LANG" );
385 else { 377 else {
386 qWarning("and its not null"); 378 qWarning("and its not null");
387 setenv( "LANG", l.latin1(), 1 ); 379 setenv( "LANG", l.latin1(), 1 );
388 } 380 }
389#ifndef QT_NO_TRANSLATION 381#ifndef QT_NO_TRANSLATION
390 // clear old translators 382 // clear old translators
391#ifndef _MSC_VER 383#ifndef _MSC_VER
392 //### revise to allow removal of translators under MSVC 384 //### revise to allow removal of translators under MSVC
393 if(qApp->translators) { 385 if(qApp->translators) {
394 qApp->translators->setAutoDelete(TRUE); 386 qApp->translators->setAutoDelete(TRUE);
395 delete (qApp->translators); 387 delete (qApp->translators);
396 qApp->translators = 0; 388 qApp->translators = 0;
397 } 389 }
398#endif 390#endif
399 391
400 // load translation tables 392 // load translation tables
401 transApp = new QTranslator(qApp); 393 transApp = new QTranslator(qApp);
402 QString tfn = QPEApplication::qpeDir() + "i18n/"+l+"/qpe.qm"; 394 QString tfn = QPEApplication::qpeDir() + "i18n/"+l+"/qpe.qm";
403 qWarning("loading " + tfn); 395 qWarning("loading " + tfn);
404 if ( transApp->load(tfn) ) { 396 if ( transApp->load(tfn) ) {
405 qWarning("installing translator"); 397 qWarning("installing translator");
406 qApp->installTranslator( transApp ); 398 qApp->installTranslator( transApp );
407 } else { 399 } else {
408 delete transApp; 400 delete transApp;
409 transApp = 0; 401 transApp = 0;
410 } 402 }
411 403
412 transLib = new QTranslator(qApp); 404 transLib = new QTranslator(qApp);
413 tfn = QPEApplication::qpeDir() + "i18n/"+l+"/libqpe.qm"; 405 tfn = QPEApplication::qpeDir() + "i18n/"+l+"/libqpe.qm";
414 qWarning("loading " + tfn); 406 qWarning("loading " + tfn);
415 if ( transLib->load(tfn) ) { 407 if ( transLib->load(tfn) ) {
416 qWarning("installing translator library"); 408 qWarning("installing translator library");
417 qApp->installTranslator( transLib ); 409 qApp->installTranslator( transLib );
418 } else { 410 } else {
419 delete transLib; 411 delete transLib;
420 transLib = 0; 412 transLib = 0;
421 } 413 }
422 loadPixmaps(); 414 loadPixmaps();
423 //###language/font hack; should look it up somewhere 415 //###language/font hack; should look it up somewhere
424#ifdef Q_WS_QWS 416#ifdef Q_WS_QWS
425 if ( l == "ja" || l == "zh_CN" || l == "zh_TW" || l == "ko" ) { 417 if ( l == "ja" || l == "zh_CN" || l == "zh_TW" || l == "ko" ) {
426 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 418 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
427 qApp->setFont( fn, TRUE ); 419 qApp->setFont( fn, TRUE );
428 } else { 420 } else {
429 qApp->setFont( defaultFont, TRUE ); 421 qApp->setFont( defaultFont, TRUE );
430 } 422 }
431#endif 423#endif
432#endif 424#endif
433} 425}
434 426
435void FirstUse::paintEvent( QPaintEvent * ) 427void FirstUse::paintEvent( QPaintEvent * )
436{ 428{
437 QPainter p( this ); 429 QPainter p( this );
438 430
439 p.drawPixmap(0,0, splash); 431 p.drawPixmap(0,0, splash);
440 432
441 QFont f = p.font(); 433 QFont f = p.font();
442 f.setPointSize(15); 434 f.setPointSize(15);
443 f.setItalic(FALSE); 435 f.setItalic(FALSE);
444 f.setBold(FALSE); 436 f.setBold(FALSE);
445 p.setFont(f); 437 p.setFont(f);
446 438
447 if ( currApp < 0 ) { 439 if ( currApp < 0 ) {
448 drawText(p, tr( "Tap anywhere on the screen to continue." )); 440 drawText(p, tr( "Tap anywhere on the screen to continue." ));
449 } else if ( settingsTable[currApp].app ) { 441 } else if ( settingsTable[currApp].app ) {
450 if ( waitingForLaunch ) 442 if ( waitingForLaunch )
451 drawText(p, tr("Please wait, loading %1 settings.").arg(tr(settingsTable[currApp].desc)) ); 443 drawText(p, tr("Please wait, loading %1 settings.").arg(tr(settingsTable[currApp].desc)) );
452 } else { 444 } else {
453 drawText(p, tr("Please wait...")); 445 drawText(p, tr("Please wait..."));
454 } 446 }
455} 447}
456 448
457void FirstUse::loadPixmaps() 449void FirstUse::loadPixmaps()
458{ 450{
459 /* create background, tr so can change image with language. 451 /* create background, tr so can change image with language.
460 images will likely contain text. */ 452 images will likely contain text. */
461 splash.convertFromImage( Resource::loadImage(tr("FirstUseBackground")) 453 splash.convertFromImage( Resource::loadImage(tr("FirstUseBackground"))
462 .smoothScale( width(), height() ) ); 454 .smoothScale( width(), height() ) );
463 455
464 setBackgroundPixmap(splash); 456 setBackgroundPixmap(splash);
465} 457}
466 458
467void FirstUse::drawText(QPainter &p, const QString &text) 459void FirstUse::drawText(QPainter &p, const QString &text)
468{ 460{
469 QString altered = "<CENTER>" + text + "</CENTER>"; 461 QString altered = "<CENTER>" + text + "</CENTER>";
470 462
471 QSimpleRichText rt(altered, p.font()); 463 QSimpleRichText rt(altered, p.font());
472 rt.setWidth(width() - 20); 464 rt.setWidth(width() - 20);
473 465
474 int h = (height() * 3) / 10; // start at 30% 466 int h = (height() * 3) / 10; // start at 30%
475 if (rt.height() < height() / 2) 467 if (rt.height() < height() / 2)
476 h += ((height() / 2) - rt.height()) / 2; 468 h += ((height() / 2) - rt.height()) / 2;
477 rt.draw(&p, 10, h, QRegion(0,0, width()-20, height()), palette()); 469 rt.draw(&p, 10, h, QRegion(0,0, width()-20, height()), palette());
478} 470}
479 471
480void FirstUse::updateButtons() 472void FirstUse::updateButtons()
481{ 473{
482 if ( currApp >= 0 ) { 474 if ( currApp >= 0 ) {
483 taskBar->show(); 475 taskBar->show();
484 } 476 }
485 477
486 int i = currApp-1; 478 int i = currApp-1;
487 while ( i >= 0 && !settingsTable[i].enabled ) 479 while ( i >= 0 && !settingsTable[i].enabled )
488 i--; 480 i--;
489 back->setText(tr("<< Back")); 481 back->setText(tr("<< Back"));
490 back->setEnabled( i >= 0 && !waitingForLaunch ); 482 back->setEnabled( i >= 0 && !waitingForLaunch );
491 483
492 i = currApp+1; 484 i = currApp+1;
493 while ( settingsTable[i].app && !settingsTable[i].enabled ) 485 while ( settingsTable[i].app && !settingsTable[i].enabled )
494 i++; 486 i++;
495 if ( !settingsTable[i].app ) 487 if ( !settingsTable[i].app )
496 next->setText(tr("Finish")); 488 next->setText(tr("Finish"));
497 else 489 else
498 next->setText(tr("Next >>")); 490 next->setText(tr("Next >>"));
499 491
500 next->setEnabled( !waitingForLaunch ); 492 next->setEnabled( !waitingForLaunch );
501} 493}
502 494
503void FirstUse::keyPressEvent( QKeyEvent *e ) 495void FirstUse::keyPressEvent( QKeyEvent *e )
504{ 496{
505 // Allow cancelling at first dialog, in case display is broken. 497 // Allow cancelling at first dialog, in case display is broken.
506 if ( e->key() == Key_Escape && currApp < 0 ) 498 if ( e->key() == Key_Escape && currApp < 0 )
507 QDialog::keyPressEvent(e); 499 QDialog::keyPressEvent(e);
508} 500}
509 501
510void FirstUse::mouseReleaseEvent( QMouseEvent * ) 502void FirstUse::mouseReleaseEvent( QMouseEvent * )
511{ 503{
512 if ( currApp < 0 ) { 504 if ( currApp < 0 ) {
513 if ( m_calHandler && needCalibrate ) { 505 if ( m_calHandler && needCalibrate ) {
514 releaseMouse(); 506 releaseMouse();
515 Calibrate *cal = new Calibrate; 507 Calibrate *cal = new Calibrate;
516 cal->exec(); 508 cal->exec();
517 delete cal; 509 delete cal;
518 } 510 }
519 nextDialog(); 511 nextDialog();
520 } 512 }
521} 513}
diff --git a/core/launcher/inputmethods.cpp b/core/launcher/inputmethods.cpp
index 5d8faf7..683f1e2 100644
--- a/core/launcher/inputmethods.cpp
+++ b/core/launcher/inputmethods.cpp
@@ -1,630 +1,624 @@
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#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22#include "inputmethods.h" 22#include "inputmethods.h"
23 23
24#include <qtopia/config.h> 24#include <qtopia/config.h>
25#include <qtopia/qpeapplication.h> 25#include <qtopia/qpeapplication.h>
26#include <qtopia/inputmethodinterface.h>
27#include <qtopia/global.h>
28 26
29#include <qpopupmenu.h> 27#include <qpopupmenu.h>
30#include <qpushbutton.h>
31#include <qtoolbutton.h> 28#include <qtoolbutton.h>
32#include <qwidgetstack.h> 29#include <qwidgetstack.h>
33#include <qwidget.h>
34#include <qlayout.h> 30#include <qlayout.h>
35#include <qtimer.h>
36#include <qdir.h> 31#include <qdir.h>
37#include <stdlib.h> 32#include <stdlib.h>
38#include <qtranslator.h>
39#include <qtl.h> 33#include <qtl.h>
40 34
41#ifdef Q_WS_QWS 35#ifdef Q_WS_QWS
42#include <qwindowsystem_qws.h> 36#include <qwindowsystem_qws.h>
43#include <qwsevent_qws.h> 37#include <qwsevent_qws.h>
44#include <qcopchannel_qws.h> 38#include <qcopchannel_qws.h>
45#endif 39#endif
46 40
47/* ### SingleFloppy if someone is interested? */ 41/* ### SingleFloppy if someone is interested? */
48#if 0 42#if 0
49#ifdef QT_NO_COMPONENT 43#ifdef QT_NO_COMPONENT
50#include "../plugins/inputmethods/handwriting/handwritingimpl.h" 44#include "../plugins/inputmethods/handwriting/handwritingimpl.h"
51#include "../plugins/inputmethods/keyboard/keyboardimpl.h" 45#include "../plugins/inputmethods/keyboard/keyboardimpl.h"
52#include "../3rdparty/plugins/inputmethods/pickboard/pickboardimpl.h" 46#include "../3rdparty/plugins/inputmethods/pickboard/pickboardimpl.h"
53#endif 47#endif
54#endif 48#endif
55 49
56/* XPM */ 50/* XPM */
57static const char * tri_xpm[]={ 51static const char * tri_xpm[]={
58"9 9 2 1", 52"9 9 2 1",
59"a c #000000", 53"a c #000000",
60". c None", 54". c None",
61".........", 55".........",
62".........", 56".........",
63".........", 57".........",
64"....a....", 58"....a....",
65"...aaa...", 59"...aaa...",
66"..aaaaa..", 60"..aaaaa..",
67".aaaaaaa.", 61".aaaaaaa.",
68".........", 62".........",
69"........."}; 63"........."};
70 64
71int InputMethod::operator <(const InputMethod& o) const 65int InputMethod::operator <(const InputMethod& o) const
72{ 66{
73 return name() < o.name(); 67 return name() < o.name();
74} 68}
75int InputMethod::operator >(const InputMethod& o) const 69int InputMethod::operator >(const InputMethod& o) const
76{ 70{
77 return name() > o.name(); 71 return name() > o.name();
78} 72}
79int InputMethod::operator <=(const InputMethod& o) const 73int InputMethod::operator <=(const InputMethod& o) const
80{ 74{
81 return name() <= o.name(); 75 return name() <= o.name();
82} 76}
83 77
84 78
85/* 79/*
86 Slightly hacky: We use WStyle_Tool as a flag to say "this widget 80 Slightly hacky: We use WStyle_Tool as a flag to say "this widget
87 belongs to the IM system, so clicking it should not cause a reset". 81 belongs to the IM system, so clicking it should not cause a reset".
88 */ 82 */
89class IMToolButton : public QToolButton 83class IMToolButton : public QToolButton
90{ 84{
91public: 85public:
92 IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent ) 86 IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent )
93 { setWFlags( WStyle_Tool ); } 87 { setWFlags( WStyle_Tool ); }
94}; 88};
95 89
96 90
97InputMethods::InputMethods( QWidget *parent ) : 91InputMethods::InputMethods( QWidget *parent ) :
98 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ), 92 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ),
99 mkeyboard(0), imethod(0) 93 mkeyboard(0), imethod(0)
100{ 94{
101 Config cfg( "Launcher" ); 95 Config cfg( "Launcher" );
102 cfg.setGroup( "InputMethods" ); 96 cfg.setGroup( "InputMethods" );
103 inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool; 97 inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool;
104 inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : 0; 98 inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : 0;
105 inputWidgetWidth = cfg.readNumEntry( "Width", 100 ); 99 inputWidgetWidth = cfg.readNumEntry( "Width", 100 );
106 100
107 setBackgroundMode( PaletteBackground ); 101 setBackgroundMode( PaletteBackground );
108 QHBoxLayout *hbox = new QHBoxLayout( this ); 102 QHBoxLayout *hbox = new QHBoxLayout( this );
109 103
110 kbdButton = new IMToolButton( this); 104 kbdButton = new IMToolButton( this);
111 kbdButton->setFocusPolicy(NoFocus); 105 kbdButton->setFocusPolicy(NoFocus);
112 kbdButton->setToggleButton( TRUE ); 106 kbdButton->setToggleButton( TRUE );
113 if (parent->sizeHint().height() > 0) 107 if (parent->sizeHint().height() > 0)
114 kbdButton->setFixedHeight( parent->sizeHint().height() ); 108 kbdButton->setFixedHeight( parent->sizeHint().height() );
115 kbdButton->setFixedWidth( 32 ); 109 kbdButton->setFixedWidth( 32 );
116 kbdButton->setAutoRaise( TRUE ); 110 kbdButton->setAutoRaise( TRUE );
117 kbdButton->setUsesBigPixmap( TRUE ); 111 kbdButton->setUsesBigPixmap( TRUE );
118 hbox->addWidget( kbdButton ); 112 hbox->addWidget( kbdButton );
119 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); 113 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) );
120 114
121 kbdChoice = new IMToolButton( this ); 115 kbdChoice = new IMToolButton( this );
122 kbdChoice->setFocusPolicy(NoFocus); 116 kbdChoice->setFocusPolicy(NoFocus);
123 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); 117 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
124 if (parent->sizeHint().height() > 0) 118 if (parent->sizeHint().height() > 0)
125 kbdChoice->setFixedHeight( parent->sizeHint().height() ); 119 kbdChoice->setFixedHeight( parent->sizeHint().height() );
126 kbdChoice->setFixedWidth( 13 ); 120 kbdChoice->setFixedWidth( 13 );
127 kbdChoice->setAutoRaise( TRUE ); 121 kbdChoice->setAutoRaise( TRUE );
128 hbox->addWidget( kbdChoice ); 122 hbox->addWidget( kbdChoice );
129 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); 123 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) );
130 124
131 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), 125 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()),
132 this, SLOT(resetStates()) ); 126 this, SLOT(resetStates()) );
133 127
134 128
135 imButton = new QWidgetStack( this ); // later a widget stack 129 imButton = new QWidgetStack( this ); // later a widget stack
136 imButton->setFocusPolicy(NoFocus); 130 imButton->setFocusPolicy(NoFocus);
137 if (parent->sizeHint().height() > 0) 131 if (parent->sizeHint().height() > 0)
138 imButton->setFixedHeight( parent->sizeHint().height() ); 132 imButton->setFixedHeight( parent->sizeHint().height() );
139 hbox->addWidget(imButton); 133 hbox->addWidget(imButton);
140 134
141 imChoice = new QToolButton( this ); 135 imChoice = new QToolButton( this );
142 imChoice->setFocusPolicy(NoFocus); 136 imChoice->setFocusPolicy(NoFocus);
143 imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); 137 imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
144 if (parent->sizeHint().height() > 0) 138 if (parent->sizeHint().height() > 0)
145 imChoice->setFixedHeight( parent->sizeHint().height() ); 139 imChoice->setFixedHeight( parent->sizeHint().height() );
146 imChoice->setFixedWidth( 13 ); 140 imChoice->setFixedWidth( 13 );
147 imChoice->setAutoRaise( TRUE ); 141 imChoice->setAutoRaise( TRUE );
148 hbox->addWidget( imChoice ); 142 hbox->addWidget( imChoice );
149 connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) ); 143 connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) );
150 144
151 loadInputMethods(); 145 loadInputMethods();
152 146
153 QCopChannel *channel = new QCopChannel( "QPE/IME", this ); 147 QCopChannel *channel = new QCopChannel( "QPE/IME", this );
154 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 148 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
155 this, SLOT(qcopReceive(const QCString&, const QByteArray&)) ); 149 this, SLOT(qcopReceive(const QCString&, const QByteArray&)) );
156} 150}
157 151
158InputMethods::~InputMethods() 152InputMethods::~InputMethods()
159{ 153{
160 Config cfg("qpe"); 154 Config cfg("qpe");
161 cfg.setGroup("InputMethod"); 155 cfg.setGroup("InputMethod");
162 if (imethod) 156 if (imethod)
163 cfg.writeEntry("im", imethod->name() ); 157 cfg.writeEntry("im", imethod->name() );
164 if (mkeyboard) 158 if (mkeyboard)
165 cfg.writeEntry("current", mkeyboard->name() ); 159 cfg.writeEntry("current", mkeyboard->name() );
166 160
167 unloadInputMethods(); 161 unloadInputMethods();
168} 162}
169 163
170void InputMethods::hideInputMethod() 164void InputMethods::hideInputMethod()
171{ 165{
172 kbdButton->setOn( FALSE ); 166 kbdButton->setOn( FALSE );
173} 167}
174 168
175void InputMethods::showInputMethod() 169void InputMethods::showInputMethod()
176{ 170{
177 kbdButton->setOn( TRUE ); 171 kbdButton->setOn( TRUE );
178} 172}
179 173
180void InputMethods::showInputMethod(const QString& name) 174void InputMethods::showInputMethod(const QString& name)
181{ 175{
182 int i = 0; 176 int i = 0;
183 QValueList<InputMethod>::Iterator it; 177 QValueList<InputMethod>::Iterator it;
184 InputMethod *im = 0; 178 InputMethod *im = 0;
185 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 179 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
186 QString lname = (*it).libName.mid((*it).libName.findRev('/') + 1); 180 QString lname = (*it).libName.mid((*it).libName.findRev('/') + 1);
187 if ( (*it).name() == name || lname == name ) { 181 if ( (*it).name() == name || lname == name ) {
188 im = &(*it); 182 im = &(*it);
189 break; 183 break;
190 } 184 }
191 } 185 }
192 if ( im ) 186 if ( im )
193 chooseKeyboard(im); 187 chooseKeyboard(im);
194} 188}
195 189
196void InputMethods::resetStates() 190void InputMethods::resetStates()
197{ 191{
198 if ( mkeyboard && !mkeyboard->newIM ) 192 if ( mkeyboard && !mkeyboard->newIM )
199 mkeyboard->interface->resetState(); 193 mkeyboard->interface->resetState();
200} 194}
201 195
202QRect InputMethods::inputRect() const 196QRect InputMethods::inputRect() const
203{ 197{
204 if ( !mkeyboard || !mkeyboard->widget || !mkeyboard->widget->isVisible() ) 198 if ( !mkeyboard || !mkeyboard->widget || !mkeyboard->widget->isVisible() )
205 return QRect(); 199 return QRect();
206 else 200 else
207 return mkeyboard->widget->geometry(); 201 return mkeyboard->widget->geometry();
208} 202}
209 203
210void InputMethods::unloadInputMethods() 204void InputMethods::unloadInputMethods()
211{ 205{
212 unloadMethod( inputMethodList ); 206 unloadMethod( inputMethodList );
213 unloadMethod( inputModifierList ); 207 unloadMethod( inputModifierList );
214 inputMethodList.clear(); 208 inputMethodList.clear();
215 inputModifierList.clear(); 209 inputModifierList.clear();
216 210
217} 211}
218 212
219void InputMethods::unloadMethod( QValueList<InputMethod>& list ) { 213void InputMethods::unloadMethod( QValueList<InputMethod>& list ) {
220 QValueList<InputMethod>::Iterator it; 214 QValueList<InputMethod>::Iterator it;
221 215
222 for (it = list.begin(); it != list.end(); ++it ) 216 for (it = list.begin(); it != list.end(); ++it )
223 (*it).releaseInterface(); 217 (*it).releaseInterface();
224 218
225} 219}
226 220
227 221
228QStringList InputMethods::plugins()const { 222QStringList InputMethods::plugins()const {
229 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; 223 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods";
230#ifdef Q_OS_MACX 224#ifdef Q_OS_MACX
231 QDir dir( path, "lib*.dylib" ); 225 QDir dir( path, "lib*.dylib" );
232#else 226#else
233 QDir dir( path, "lib*.so" ); 227 QDir dir( path, "lib*.so" );
234#endif /* Q_OS_MACX */ 228#endif /* Q_OS_MACX */
235 return dir.entryList(); 229 return dir.entryList();
236} 230}
237 231
238void InputMethods::installTranslator( const QString& type ) { 232void InputMethods::installTranslator( const QString& type ) {
239 QStringList langs = Global::languageList(); 233 QStringList langs = Global::languageList();
240 QStringList::ConstIterator lit; 234 QStringList::ConstIterator lit;
241 for ( lit= langs.begin(); lit!=langs.end(); ++lit) { 235 for ( lit= langs.begin(); lit!=langs.end(); ++lit) {
242 QString lang = *lit; 236 QString lang = *lit;
243 QTranslator * trans = new QTranslator(qApp); 237 QTranslator * trans = new QTranslator(qApp);
244 238
245 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 239 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
246 240
247 if ( trans->load( tfn )) 241 if ( trans->load( tfn ))
248 qApp->installTranslator( trans ); 242 qApp->installTranslator( trans );
249 else 243 else
250 delete trans; 244 delete trans;
251 } 245 }
252} 246}
253 247
254void InputMethods::setPreferedHandlers() { 248void InputMethods::setPreferedHandlers() {
255 Config cfg("qpe"); 249 Config cfg("qpe");
256 cfg.setGroup("InputMethod"); 250 cfg.setGroup("InputMethod");
257 QString current = cfg.readEntry("current"); 251 QString current = cfg.readEntry("current");
258 QString im = cfg.readEntry("im"); 252 QString im = cfg.readEntry("im");
259 253
260 QValueList<InputMethod>::Iterator it; 254 QValueList<InputMethod>::Iterator it;
261 if (!inputModifierList.isEmpty() && !im.isEmpty() ) { 255 if (!inputModifierList.isEmpty() && !im.isEmpty() ) {
262 for (it = inputModifierList.begin(); it != inputModifierList.end(); ++it ) 256 for (it = inputModifierList.begin(); it != inputModifierList.end(); ++it )
263 if ( (*it).name() == im ) { 257 if ( (*it).name() == im ) {
264 imethod = &(*it); break; 258 imethod = &(*it); break;
265 } 259 }
266 260
267 } 261 }
268 if (!inputMethodList.isEmpty() && !current.isEmpty() ) { 262 if (!inputMethodList.isEmpty() && !current.isEmpty() ) {
269 for (it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) 263 for (it = inputMethodList.begin(); it != inputMethodList.end(); ++it )
270 if ( (*it).name() == current ) { 264 if ( (*it).name() == current ) {
271 qWarning("preferred keyboard is %s", current.latin1() ); 265 qWarning("preferred keyboard is %s", current.latin1() );
272 mkeyboard = &(*it); 266 mkeyboard = &(*it);
273 kbdButton->setPixmap( *mkeyboard->icon() ); 267 kbdButton->setPixmap( *mkeyboard->icon() );
274 break; 268 break;
275 } 269 }
276 } 270 }
277 271
278} 272}
279 273
280void InputMethods::loadInputMethods() 274void InputMethods::loadInputMethods()
281{ 275{
282#ifndef QT_NO_COMPONENT 276#ifndef QT_NO_COMPONENT
283 hideInputMethod(); 277 hideInputMethod();
284 mkeyboard = 0; 278 mkeyboard = 0;
285 279
286 unloadInputMethods(); 280 unloadInputMethods();
287 281
288 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; 282 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods";
289 QStringList list = plugins(); 283 QStringList list = plugins();
290 QStringList::Iterator it; 284 QStringList::Iterator it;
291 for ( it = list.begin(); it != list.end(); ++it ) { 285 for ( it = list.begin(); it != list.end(); ++it ) {
292 InputMethodInterface *iface = 0; 286 InputMethodInterface *iface = 0;
293 ExtInputMethodInterface *eface = 0; 287 ExtInputMethodInterface *eface = 0;
294 QLibrary *lib = new QLibrary( path + "/" + *it ); 288 QLibrary *lib = new QLibrary( path + "/" + *it );
295 289
296 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) { 290 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) {
297 InputMethod input; 291 InputMethod input;
298 input.newIM = FALSE; 292 input.newIM = FALSE;
299 input.library = lib; 293 input.library = lib;
300 input.libName = *it; 294 input.libName = *it;
301 input.interface = iface; 295 input.interface = iface;
302 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 296 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
303 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 297 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
304 inputMethodList.append( input ); 298 inputMethodList.append( input );
305 } else if ( lib->queryInterface( IID_ExtInputMethod, (QUnknownInterface**)&eface ) == QS_OK ) { 299 } else if ( lib->queryInterface( IID_ExtInputMethod, (QUnknownInterface**)&eface ) == QS_OK ) {
306 InputMethod input; 300 InputMethod input;
307 input.newIM = TRUE; 301 input.newIM = TRUE;
308 input.library = lib; 302 input.library = lib;
309 input.libName = *it; 303 input.libName = *it;
310 input.extInterface = eface; 304 input.extInterface = eface;
311 input.widget = input.extInterface->keyboardWidget( 0, inputWidgetStyle ); 305 input.widget = input.extInterface->keyboardWidget( 0, inputWidgetStyle );
312 // may be either a simple, or advanced. 306 // may be either a simple, or advanced.
313 if (input.widget) { 307 if (input.widget) {
314 //qDebug("its a keyboard"); 308 //qDebug("its a keyboard");
315 inputMethodList.append( input ); 309 inputMethodList.append( input );
316 } else { 310 } else {
317 //qDebug("its a real im"); 311 //qDebug("its a real im");
318 input.widget = input.extInterface->statusWidget( 0, 0 ); 312 input.widget = input.extInterface->statusWidget( 0, 0 );
319 if (input.widget) { 313 if (input.widget) {
320 //qDebug("blah"); 314 //qDebug("blah");
321 inputModifierList.append( input ); 315 inputModifierList.append( input );
322 imButton->addWidget(input.widget, inputModifierList.count()); 316 imButton->addWidget(input.widget, inputModifierList.count());
323 } 317 }
324 } 318 }
325 }else{ 319 }else{
326 delete lib; 320 delete lib;
327 lib = 0l; 321 lib = 0l;
328 } 322 }
329 installTranslator( (*it).left( (*it).find(".") ) ); 323 installTranslator( (*it).left( (*it).find(".") ) );
330 } 324 }
331 qHeapSort( inputMethodList ); 325 qHeapSort( inputMethodList );
332#endif /* killed BUILT in cause they would not compile */ 326#endif /* killed BUILT in cause they would not compile */
333 327
334 QWSServer::setCurrentInputMethod( 0 ); 328 QWSServer::setCurrentInputMethod( 0 );
335 329
336 /* set the prefered IM + handler */ 330 /* set the prefered IM + handler */
337 setPreferedHandlers(); 331 setPreferedHandlers();
338 if ( !inputModifierList.isEmpty() ) { 332 if ( !inputModifierList.isEmpty() ) {
339 if (!imethod) 333 if (!imethod)
340 imethod = &inputModifierList[0]; 334 imethod = &inputModifierList[0];
341 imButton->raiseWidget(imethod->widget); 335 imButton->raiseWidget(imethod->widget);
342 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); 336 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() );
343 } else { 337 } else {
344 imethod = 0; 338 imethod = 0;
345 } 339 }
346 340
347 // we need to update keyboards afterwards, as some of them may not be compatible with 341 // we need to update keyboards afterwards, as some of them may not be compatible with
348 // the current input method 342 // the current input method
349 updateKeyboards(imethod); 343 updateKeyboards(imethod);
350 344
351 if ( !inputModifierList.isEmpty() ) 345 if ( !inputModifierList.isEmpty() )
352 imButton->show(); 346 imButton->show();
353 else 347 else
354 imButton->hide(); 348 imButton->hide();
355 349
356 if ( inputModifierList.count() > 1 ) 350 if ( inputModifierList.count() > 1 )
357 imChoice->show(); 351 imChoice->show();
358 else 352 else
359 imChoice->hide(); 353 imChoice->hide();
360} 354}
361 355
362void InputMethods::chooseKbd() 356void InputMethods::chooseKbd()
363{ 357{
364 QPopupMenu pop( this ); 358 QPopupMenu pop( this );
365 pop.setFocusPolicy( NoFocus ); //don't reset IM 359 pop.setFocusPolicy( NoFocus ); //don't reset IM
366 360
367 QString imname; 361 QString imname;
368 if (imethod) 362 if (imethod)
369 imname = imethod->libName.mid(imethod->libName.findRev('/') + 1); 363 imname = imethod->libName.mid(imethod->libName.findRev('/') + 1);
370 364
371 int i = 0; 365 int i = 0;
372 int firstDepKbd = 0; 366 int firstDepKbd = 0;
373 367
374 QValueList<InputMethod>::Iterator it; 368 QValueList<InputMethod>::Iterator it;
375 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 369 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
376 // add empty new items, all old items. 370 // add empty new items, all old items.
377 if (!(*it).newIM || (*it).extInterface->compatible().count() == 0 ) { 371 if (!(*it).newIM || (*it).extInterface->compatible().count() == 0 ) {
378 pop.insertItem( (*it).name(), i, firstDepKbd); 372 pop.insertItem( (*it).name(), i, firstDepKbd);
379 if ( mkeyboard == &(*it) ) 373 if ( mkeyboard == &(*it) )
380 pop.setItemChecked( i, TRUE ); 374 pop.setItemChecked( i, TRUE );
381 375
382 firstDepKbd++; 376 firstDepKbd++;
383 } else if ( (*it).extInterface->compatible().contains(imname)) { 377 } else if ( (*it).extInterface->compatible().contains(imname)) {
384 // check if we need to insert a sep. 378 // check if we need to insert a sep.
385 if (firstDepKbd == i) 379 if (firstDepKbd == i)
386 pop.insertSeparator(); 380 pop.insertSeparator();
387 pop.insertItem( (*it).name(), i, -1); 381 pop.insertItem( (*it).name(), i, -1);
388 if ( mkeyboard == &(*it) ) 382 if ( mkeyboard == &(*it) )
389 pop.setItemChecked( i, TRUE ); 383 pop.setItemChecked( i, TRUE );
390 } 384 }
391 } 385 }
392 386
393 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight()); 387 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight());
394 QSize s = pop.sizeHint(); 388 QSize s = pop.sizeHint();
395 pt.ry() -= s.height(); 389 pt.ry() -= s.height();
396 pt.rx() -= s.width(); 390 pt.rx() -= s.width();
397 i = pop.exec( pt ); 391 i = pop.exec( pt );
398 if ( i == -1 ) 392 if ( i == -1 )
399 return; 393 return;
400 InputMethod *im = &inputMethodList[i]; 394 InputMethod *im = &inputMethodList[i];
401 chooseKeyboard(im); 395 chooseKeyboard(im);
402} 396}
403 397
404void InputMethods::chooseIm() 398void InputMethods::chooseIm()
405{ 399{
406 QPopupMenu pop( this ); 400 QPopupMenu pop( this );
407 401
408 int i = 0; 402 int i = 0;
409 QValueList<InputMethod>::Iterator it; 403 QValueList<InputMethod>::Iterator it;
410 for ( it = inputModifierList.begin(); it != inputModifierList.end(); ++it, i++ ) { 404 for ( it = inputModifierList.begin(); it != inputModifierList.end(); ++it, i++ ) {
411 pop.insertItem( (*it).name(), i ); 405 pop.insertItem( (*it).name(), i );
412 if ( imethod == &(*it) ) 406 if ( imethod == &(*it) )
413 pop.setItemChecked( i, TRUE ); 407 pop.setItemChecked( i, TRUE );
414 } 408 }
415 409
416 QPoint pt = mapToGlobal(imChoice->geometry().topRight()); 410 QPoint pt = mapToGlobal(imChoice->geometry().topRight());
417 QSize s = pop.sizeHint(); 411 QSize s = pop.sizeHint();
418 pt.ry() -= s.height(); 412 pt.ry() -= s.height();
419 pt.rx() -= s.width(); 413 pt.rx() -= s.width();
420 i = pop.exec( pt ); 414 i = pop.exec( pt );
421 if ( i == -1 ) 415 if ( i == -1 )
422 return; 416 return;
423 InputMethod *im = &inputModifierList[i]; 417 InputMethod *im = &inputModifierList[i];
424 418
425 chooseMethod(im); 419 chooseMethod(im);
426} 420}
427 421
428void InputMethods::chooseKeyboard(InputMethod* im) 422void InputMethods::chooseKeyboard(InputMethod* im)
429{ 423{
430 if ( im != mkeyboard ) { 424 if ( im != mkeyboard ) {
431 if ( mkeyboard && mkeyboard->widget->isVisible() ) 425 if ( mkeyboard && mkeyboard->widget->isVisible() )
432 mkeyboard->widget->hide(); 426 mkeyboard->widget->hide();
433 mkeyboard = im; 427 mkeyboard = im;
434 kbdButton->setPixmap( *mkeyboard->icon() ); 428 kbdButton->setPixmap( *mkeyboard->icon() );
435 } 429 }
436 if ( !kbdButton->isOn() ) 430 if ( !kbdButton->isOn() )
437 kbdButton->setOn( TRUE ); 431 kbdButton->setOn( TRUE );
438 else 432 else
439 showKbd( TRUE ); 433 showKbd( TRUE );
440} 434}
441 435
442static bool keyboardCompatible(InputMethod *keyb, const QString &imname ) 436static bool keyboardCompatible(InputMethod *keyb, const QString &imname )
443{ 437{
444 if ( !keyb || !keyb->newIM || !keyb->extInterface->compatible().count() ) 438 if ( !keyb || !keyb->newIM || !keyb->extInterface->compatible().count() )
445 return TRUE; 439 return TRUE;
446 440
447 if ( keyb->extInterface->compatible().contains(imname) ) 441 if ( keyb->extInterface->compatible().contains(imname) )
448 return TRUE; 442 return TRUE;
449 443
450 return FALSE; 444 return FALSE;
451} 445}
452 446
453// Updates the display of the soft keyboards available to the current input method 447// Updates the display of the soft keyboards available to the current input method
454void InputMethods::updateKeyboards(InputMethod *im ) 448void InputMethods::updateKeyboards(InputMethod *im )
455{ 449{
456 uint count; 450 uint count;
457 451
458 if ( im ) { 452 if ( im ) {
459 QString imname = im->libName.mid(im->libName.findRev('/') + 1); 453 QString imname = im->libName.mid(im->libName.findRev('/') + 1);
460 454
461 if ( mkeyboard && !keyboardCompatible(mkeyboard, imname) ) { 455 if ( mkeyboard && !keyboardCompatible(mkeyboard, imname) ) {
462 kbdButton->setOn( FALSE ); 456 kbdButton->setOn( FALSE );
463 showKbd( FALSE ); 457 showKbd( FALSE );
464 mkeyboard = 0; 458 mkeyboard = 0;
465 } 459 }
466 460
467 count = 0; 461 count = 0;
468 462
469 QValueList<InputMethod>::Iterator it; 463 QValueList<InputMethod>::Iterator it;
470 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) { 464 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) {
471 if ( keyboardCompatible( &(*it), imname ) ) { 465 if ( keyboardCompatible( &(*it), imname ) ) {
472 if ( !mkeyboard ) { 466 if ( !mkeyboard ) {
473 mkeyboard = &(*it); 467 mkeyboard = &(*it);
474 kbdButton->setPixmap( *mkeyboard->icon() ); 468 kbdButton->setPixmap( *mkeyboard->icon() );
475 } 469 }
476 470
477 count++; 471 count++;
478 } 472 }
479 } 473 }
480 } else { 474 } else {
481 count = inputMethodList.count(); 475 count = inputMethodList.count();
482 if ( count && !mkeyboard ) { 476 if ( count && !mkeyboard ) {
483 mkeyboard = &inputMethodList[0]; 477 mkeyboard = &inputMethodList[0];
484 kbdButton->setPixmap( *mkeyboard->icon() ); 478 kbdButton->setPixmap( *mkeyboard->icon() );
485 } else if (!count){ 479 } else if (!count){
486 mkeyboard = 0; //might be redundant 480 mkeyboard = 0; //might be redundant
487 } 481 }
488 } 482 }
489 483
490 if ( count > 1 ) 484 if ( count > 1 )
491 kbdChoice->show(); 485 kbdChoice->show();
492 else 486 else
493 kbdChoice->hide(); 487 kbdChoice->hide();
494 488
495 if ( count ) 489 if ( count )
496 kbdButton->show(); 490 kbdButton->show();
497 else 491 else
498 kbdButton->hide(); 492 kbdButton->hide();
499} 493}
500 494
501void InputMethods::chooseMethod(InputMethod* im) 495void InputMethods::chooseMethod(InputMethod* im)
502{ 496{
503 if ( im != imethod ) { 497 if ( im != imethod ) {
504 updateKeyboards( im ); 498 updateKeyboards( im );
505 499
506 Config cfg("qpe"); 500 Config cfg("qpe");
507 cfg.setGroup("InputMethod"); 501 cfg.setGroup("InputMethod");
508 if (im ) 502 if (im )
509 cfg.writeEntry("im", im->name() ); 503 cfg.writeEntry("im", im->name() );
510 if (mkeyboard) 504 if (mkeyboard)
511 cfg.writeEntry("current", mkeyboard->name() ); 505 cfg.writeEntry("current", mkeyboard->name() );
512 506
513 QWSServer::setCurrentInputMethod( 0 ); 507 QWSServer::setCurrentInputMethod( 0 );
514 imethod = im; 508 imethod = im;
515 if ( imethod && imethod->newIM ) 509 if ( imethod && imethod->newIM )
516 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); 510 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() );
517 else 511 else
518 QWSServer::setCurrentInputMethod( 0 ); 512 QWSServer::setCurrentInputMethod( 0 );
519 513
520 if ( im ) 514 if ( im )
521 imButton->raiseWidget(im->widget); 515 imButton->raiseWidget(im->widget);
522 else 516 else
523 imButton->hide(); //### good UI? make sure it is shown again! 517 imButton->hide(); //### good UI? make sure it is shown again!
524 } 518 }
525} 519}
526 520
527void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data ) 521void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data )
528{ 522{
529 if ( imethod && imethod->newIM ) 523 if ( imethod && imethod->newIM )
530 imethod->extInterface->qcopReceive( msg, data ); 524 imethod->extInterface->qcopReceive( msg, data );
531} 525}
532 526
533 527
534void InputMethods::showKbd( bool on ) 528void InputMethods::showKbd( bool on )
535{ 529{
536 if ( !mkeyboard ) 530 if ( !mkeyboard )
537 return; 531 return;
538 532
539 if ( on ) 533 if ( on )
540 { 534 {
541 mkeyboard->resetState(); 535 mkeyboard->resetState();
542 536
543 int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 ); 537 int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 );
544 int width = qApp->desktop()->width() * (inputWidgetWidth*0.01); 538 int width = qApp->desktop()->width() * (inputWidgetWidth*0.01);
545 int left = 0; 539 int left = 0;
546 int top = mapToGlobal( QPoint() ).y() - height; 540 int top = mapToGlobal( QPoint() ).y() - height;
547 541
548 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) 542 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
549 { 543 {
550 qDebug( "InputMethods: reading geometry." ); 544 qDebug( "InputMethods: reading geometry." );
551 Config cfg( "Launcher" ); 545 Config cfg( "Launcher" );
552 cfg.setGroup( "InputMethods" ); 546 cfg.setGroup( "InputMethods" );
553 int l = cfg.readNumEntry( "absX", -1 ); 547 int l = cfg.readNumEntry( "absX", -1 );
554 int t = cfg.readNumEntry( "absY", -1 ); 548 int t = cfg.readNumEntry( "absY", -1 );
555 int w = cfg.readNumEntry( "absWidth", -1 ); 549 int w = cfg.readNumEntry( "absWidth", -1 );
556 int h = cfg.readNumEntry( "absHeight", -1 ); 550 int h = cfg.readNumEntry( "absHeight", -1 );
557 551
558 if ( l > -1 && t > -1 && w > -1 && h > -1 ) 552 if ( l > -1 && t > -1 && w > -1 && h > -1 )
559 { 553 {
560 qDebug( "InputMethods: config values ( %d, %d, %d, %d ) are ok.", l, t, w, h ); 554 qDebug( "InputMethods: config values ( %d, %d, %d, %d ) are ok.", l, t, w, h );
561 left = l; 555 left = l;
562 top = t; 556 top = t;
563 width = w; 557 width = w;
564 height = h; 558 height = h;
565 } 559 }
566 else 560 else
567 { 561 {
568 qDebug( "InputMethods: config values are new or not ok." ); 562 qDebug( "InputMethods: config values are new or not ok." );
569 } 563 }
570 } 564 }
571 else 565 else
572 { 566 {
573 qDebug( "InputMethods: no floating selected." ); 567 qDebug( "InputMethods: no floating selected." );
574 } 568 }
575 mkeyboard->widget->resize( width, height ); 569 mkeyboard->widget->resize( width, height );
576 mkeyboard->widget->move( left, top ); 570 mkeyboard->widget->move( left, top );
577 mkeyboard->widget->show(); 571 mkeyboard->widget->show();
578 mkeyboard->widget->installEventFilter( this ); 572 mkeyboard->widget->installEventFilter( this );
579 } 573 }
580 else 574 else
581 { 575 {
582 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) 576 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
583 { 577 {
584 QPoint pos = mkeyboard->widget->pos(); 578 QPoint pos = mkeyboard->widget->pos();
585 QSize siz = mkeyboard->widget->size(); 579 QSize siz = mkeyboard->widget->size();
586 qDebug( "InputMethods: saving geometry." ); 580 qDebug( "InputMethods: saving geometry." );
587 Config cfg( "Launcher" ); 581 Config cfg( "Launcher" );
588 cfg.setGroup( "InputMethods" ); 582 cfg.setGroup( "InputMethods" );
589 cfg.writeEntry( "absX", pos.x() ); 583 cfg.writeEntry( "absX", pos.x() );
590 cfg.writeEntry( "absY", pos.y() ); 584 cfg.writeEntry( "absY", pos.y() );
591 cfg.writeEntry( "absWidth", siz.width() ); 585 cfg.writeEntry( "absWidth", siz.width() );
592 cfg.writeEntry( "absHeight", siz.height() ); 586 cfg.writeEntry( "absHeight", siz.height() );
593 cfg.write(); 587 cfg.write();
594 mkeyboard->widget->removeEventFilter( this ); 588 mkeyboard->widget->removeEventFilter( this );
595 } 589 }
596 mkeyboard->widget->hide(); 590 mkeyboard->widget->hide();
597 } 591 }
598 592
599 emit inputToggled( on ); 593 emit inputToggled( on );
600} 594}
601 595
602bool InputMethods::shown() const 596bool InputMethods::shown() const
603{ 597{
604 return mkeyboard && mkeyboard->widget->isVisible(); 598 return mkeyboard && mkeyboard->widget->isVisible();
605} 599}
606 600
607QString InputMethods::currentShown() const 601QString InputMethods::currentShown() const
608{ 602{
609 return mkeyboard && mkeyboard->widget->isVisible() 603 return mkeyboard && mkeyboard->widget->isVisible()
610 ? mkeyboard->name() : QString::null; 604 ? mkeyboard->name() : QString::null;
611} 605}
612 606
613void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) 607void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat )
614{ 608{
615#if defined(Q_WS_QWS) 609#if defined(Q_WS_QWS)
616 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat ); 610 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat );
617#endif 611#endif
618} 612}
619 613
620bool InputMethods::eventFilter( QObject* o, QEvent* e ) 614bool InputMethods::eventFilter( QObject* o, QEvent* e )
621{ 615{
622 if ( e->type() == QEvent::Close ) 616 if ( e->type() == QEvent::Close )
623 { 617 {
624 ( (QCloseEvent*) e )->ignore(); 618 ( (QCloseEvent*) e )->ignore();
625 showKbd( false ); 619 showKbd( false );
626 kbdButton->setOn( false ); 620 kbdButton->setOn( false );
627 return true; 621 return true;
628 } 622 }
629 return false; 623 return false;
630} 624}
diff --git a/core/launcher/irserver.cpp b/core/launcher/irserver.cpp
index 63f8d05..a0e9c16 100644
--- a/core/launcher/irserver.cpp
+++ b/core/launcher/irserver.cpp
@@ -1,77 +1,76 @@
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#include "irserver.h" 22#include "irserver.h"
23 23
24#include <qtopia/qlibrary.h> 24#include <qtopia/qlibrary.h>
25#include <qtopia/qpeapplication.h> 25#include <qtopia/qpeapplication.h>
26 26
27#include <qtranslator.h>
28 27
29#include "obexinterface.h" 28#include "obexinterface.h"
30 29
31#include <qdir.h> 30#include <qdir.h>
32 31
33IrServer::IrServer( QObject *parent, const char *name ) 32IrServer::IrServer( QObject *parent, const char *name )
34 : QObject( parent, name ), obexIface(0) 33 : QObject( parent, name ), obexIface(0)
35{ 34{
36 lib = 0; 35 lib = 0;
37 obexIface = 0; 36 obexIface = 0;
38 QString path = QPEApplication::qpeDir() + "/plugins/obex/"; 37 QString path = QPEApplication::qpeDir() + "/plugins/obex/";
39#ifdef Q_OS_MACX 38#ifdef Q_OS_MACX
40 QDir dir( path, "lib*.dylib" ); 39 QDir dir( path, "lib*.dylib" );
41#else 40#else
42 QDir dir( path, "lib*.so" ); 41 QDir dir( path, "lib*.so" );
43#endif /* Q_OS_MACX */ 42#endif /* Q_OS_MACX */
44 QStringList list = dir.entryList(); 43 QStringList list = dir.entryList();
45 QStringList::Iterator it; 44 QStringList::Iterator it;
46 for ( it = list.begin(); it != list.end(); ++it ) { 45 for ( it = list.begin(); it != list.end(); ++it ) {
47 QLibrary *trylib = new QLibrary( path + *it ); 46 QLibrary *trylib = new QLibrary( path + *it );
48 //qDebug("trying lib %s", (path + (*it)).latin1() ); 47 //qDebug("trying lib %s", (path + (*it)).latin1() );
49 if ( trylib->queryInterface( IID_ObexInterface, (QUnknownInterface**)&obexIface ) == QS_OK ) { 48 if ( trylib->queryInterface( IID_ObexInterface, (QUnknownInterface**)&obexIface ) == QS_OK ) {
50 lib = trylib; 49 lib = trylib;
51 //qDebug("found obex lib" ); 50 //qDebug("found obex lib" );
52 QString lang = getenv( "LANG" ); 51 QString lang = getenv( "LANG" );
53 QTranslator * trans = new QTranslator(qApp); 52 QTranslator * trans = new QTranslator(qApp);
54 QString type = (*it).left( (*it).find(".") ); 53 QString type = (*it).left( (*it).find(".") );
55 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 54 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
56 //qDebug("tr fpr obex: %s", tfn.latin1() ); 55 //qDebug("tr fpr obex: %s", tfn.latin1() );
57 if ( trans->load( tfn )) 56 if ( trans->load( tfn ))
58 qApp->installTranslator( trans ); 57 qApp->installTranslator( trans );
59 else 58 else
60 delete trans; 59 delete trans;
61 60
62 break; 61 break;
63 } else { 62 } else {
64 delete lib; 63 delete lib;
65 } 64 }
66 } 65 }
67 if ( !lib ) 66 if ( !lib )
68 qDebug("could not load IR plugin" ); 67 qDebug("could not load IR plugin" );
69} 68}
70 69
71IrServer::~IrServer() 70IrServer::~IrServer()
72{ 71{
73 if ( obexIface ) 72 if ( obexIface )
74 obexIface->release(); 73 obexIface->release();
75 delete lib; 74 delete lib;
76} 75}
77 76
diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp
index 984a57d..54efb0b 100644
--- a/core/launcher/launcher.cpp
+++ b/core/launcher/launcher.cpp
@@ -1,781 +1,779 @@
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 <qtopia/global.h> 21#include <qtopia/global.h>
22#ifdef Q_WS_QWS 22#ifdef Q_WS_QWS
23#include <qtopia/qcopenvelope_qws.h> 23#include <qtopia/qcopenvelope_qws.h>
24#endif 24#endif
25#include <qtopia/resource.h> 25#include <qtopia/resource.h>
26#include <qtopia/applnk.h> 26#include <qtopia/applnk.h>
27#include <qtopia/config.h> 27#include <qtopia/config.h>
28#include <qtopia/global.h>
29#include <qtopia/qpeapplication.h> 28#include <qtopia/qpeapplication.h>
30#include <qtopia/mimetype.h> 29#include <qtopia/mimetype.h>
31#include <qtopia/private/categories.h> 30#include <qtopia/private/categories.h>
32//#include <qtopia/custom.h> 31//#include <qtopia/custom.h>
33 32
34#include <qdir.h> 33#include <qdir.h>
35#ifdef Q_WS_QWS 34#ifdef Q_WS_QWS
36#include <qwindowsystem_qws.h> 35#include <qwindowsystem_qws.h>
37#endif 36#endif
38#include <qtimer.h> 37#include <qtimer.h>
39#include <qcombobox.h> 38#include <qcombobox.h>
40#include <qvbox.h> 39#include <qvbox.h>
41#include <qlayout.h> 40#include <qlayout.h>
42#include <qstyle.h> 41#include <qstyle.h>
43#include <qpushbutton.h> 42#include <qpushbutton.h>
44#include <qtabbar.h> 43#include <qtabbar.h>
45#include <qwidgetstack.h> 44#include <qwidgetstack.h>
46#include <qlayout.h>
47#include <qregexp.h> 45#include <qregexp.h>
48#include <qmessagebox.h> 46#include <qmessagebox.h>
49#include <qframe.h> 47#include <qframe.h>
50#include <qpainter.h> 48#include <qpainter.h>
51#include <qlabel.h> 49#include <qlabel.h>
52#include <qtextstream.h> 50#include <qtextstream.h>
53#include <qpopupmenu.h> 51#include <qpopupmenu.h>
54 52
55#include "startmenu.h" 53#include "startmenu.h"
56#include "taskbar.h" 54#include "taskbar.h"
57 55
58#include "serverinterface.h" 56#include "serverinterface.h"
59#include "launcherview.h" 57#include "launcherview.h"
60#include "launcher.h" 58#include "launcher.h"
61#include "server.h" 59#include "server.h"
62 60
63#define QTOPIA_INTERNAL_FSLP 61#define QTOPIA_INTERNAL_FSLP
64#include <qtopia/lnkproperties.h> 62#include <qtopia/lnkproperties.h>
65#include <stdlib.h> 63#include <stdlib.h>
66#include <assert.h> 64#include <assert.h>
67 65
68#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 66#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
69#include <unistd.h> 67#include <unistd.h>
70#include <stdio.h> 68#include <stdio.h>
71#include <sys/vfs.h> 69#include <sys/vfs.h>
72#include <mntent.h> 70#include <mntent.h>
73#endif 71#endif
74 72
75#ifdef Q_WS_QWS 73#ifdef Q_WS_QWS
76#include <qkeyboard_qws.h> 74#include <qkeyboard_qws.h>
77#include <qpe/lnkproperties.h> 75#include <qpe/lnkproperties.h>
78#endif 76#endif
79 77
80 78
81static bool isVisibleWindow( int ); 79static bool isVisibleWindow( int );
82//=========================================================================== 80//===========================================================================
83 81
84LauncherTabWidget::LauncherTabWidget( Launcher* parent ) : 82LauncherTabWidget::LauncherTabWidget( Launcher* parent ) :
85 QVBox( parent ), docview( 0 ) 83 QVBox( parent ), docview( 0 )
86{ 84{
87 docLoadingWidgetEnabled = false; 85 docLoadingWidgetEnabled = false;
88 docLoadingWidget = 0; 86 docLoadingWidget = 0;
89 docLoadingWidgetProgress = 0; 87 docLoadingWidgetProgress = 0;
90 launcher = parent; 88 launcher = parent;
91 categoryBar = new LauncherTabBar( this ); 89 categoryBar = new LauncherTabBar( this );
92 QPalette pal = categoryBar->palette(); 90 QPalette pal = categoryBar->palette();
93 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); 91 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
94 pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); 92 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
95 categoryBar->setPalette( pal ); 93 categoryBar->setPalette( pal );
96 stack = new QWidgetStack(this); 94 stack = new QWidgetStack(this);
97 connect( categoryBar, SIGNAL(selected(int)), this, SLOT(raiseTabWidget()) ); 95 connect( categoryBar, SIGNAL(selected(int)), this, SLOT(raiseTabWidget()) );
98 categoryBar->show(); 96 categoryBar->show();
99 stack->show(); 97 stack->show();
100 98
101#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 99#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
102 QCopChannel *channel = new QCopChannel( "QPE/Launcher", this ); 100 QCopChannel *channel = new QCopChannel( "QPE/Launcher", this );
103 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 101 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
104 this, SLOT(launcherMessage(const QCString&, const QByteArray&)) ); 102 this, SLOT(launcherMessage(const QCString&, const QByteArray&)) );
105 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 103 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
106 this, SLOT(appMessage(const QCString&, const QByteArray&))); 104 this, SLOT(appMessage(const QCString&, const QByteArray&)));
107#endif 105#endif
108 106
109 createDocLoadingWidget(); 107 createDocLoadingWidget();
110} 108}
111 109
112void LauncherTabWidget::createDocLoadingWidget() 110void LauncherTabWidget::createDocLoadingWidget()
113{ 111{
114 // Construct the 'doc loading widget' shown when finding documents 112 // Construct the 'doc loading widget' shown when finding documents
115 113
116 // ### LauncherView class needs changing to be more generic so 114 // ### LauncherView class needs changing to be more generic so
117 // this widget can change its background similar to the iconviews 115 // this widget can change its background similar to the iconviews
118 // so the background for this matches 116 // so the background for this matches
119 docLoadingWidget = new LauncherView( stack ); 117 docLoadingWidget = new LauncherView( stack );
120 docLoadingWidget->hideIcons(); 118 docLoadingWidget->hideIcons();
121 QVBox *docLoadingVBox = new QVBox( docLoadingWidget ); 119 QVBox *docLoadingVBox = new QVBox( docLoadingWidget );
122 120
123 docLoadingVBox->setSpacing( 20 ); 121 docLoadingVBox->setSpacing( 20 );
124 docLoadingVBox->setMargin( 10 ); 122 docLoadingVBox->setMargin( 10 );
125 123
126 QWidget *space1 = new QWidget( docLoadingVBox ); 124 QWidget *space1 = new QWidget( docLoadingVBox );
127 docLoadingVBox->setStretchFactor( space1, 1 ); 125 docLoadingVBox->setStretchFactor( space1, 1 );
128 126
129 QLabel *waitPixmap = new QLabel( docLoadingVBox ); 127 QLabel *waitPixmap = new QLabel( docLoadingVBox );
130 waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) ); 128 waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) );
131 waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) ); 129 waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) );
132 waitPixmap->setAlignment( int( QLabel::AlignCenter ) ); 130 waitPixmap->setAlignment( int( QLabel::AlignCenter ) );
133 131
134 Config cfg( "Launcher" ); 132 Config cfg( "Launcher" );
135 cfg.setGroup( "DocTab" ); 133 cfg.setGroup( "DocTab" );
136 bool docTabEnabled = cfg.readBoolEntry( "Enable", true ); 134 bool docTabEnabled = cfg.readBoolEntry( "Enable", true );
137 135
138 QLabel *textLabel = new QLabel( docLoadingVBox ); 136 QLabel *textLabel = new QLabel( docLoadingVBox );
139 textLabel->setAlignment( int( QLabel::AlignCenter ) ); 137 textLabel->setAlignment( int( QLabel::AlignCenter ) );
140 docLoadingWidgetProgress = new QProgressBar( docLoadingVBox ); 138 docLoadingWidgetProgress = new QProgressBar( docLoadingVBox );
141 docLoadingWidgetProgress->setProgress( 0 ); 139 docLoadingWidgetProgress->setProgress( 0 );
142 docLoadingWidgetProgress->setCenterIndicator( TRUE ); 140 docLoadingWidgetProgress->setCenterIndicator( TRUE );
143 docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker 141 docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker
144 setProgressStyle(); 142 setProgressStyle();
145 143
146 if ( docTabEnabled ) 144 if ( docTabEnabled )
147 { 145 {
148 textLabel->setText( tr( "<b>Finding Documents...</b>" ) ); 146 textLabel->setText( tr( "<b>Finding Documents...</b>" ) );
149 } 147 }
150 else 148 else
151 { 149 {
152 textLabel->setText( tr( "<b>The Documents Tab<p>has been disabled.<p>" 150 textLabel->setText( tr( "<b>The Documents Tab<p>has been disabled.<p>"
153 "Use Settings->Launcher->DocTab<p>to reenable it.</b></center>" ) ); 151 "Use Settings->Launcher->DocTab<p>to reenable it.</b></center>" ) );
154 docLoadingWidgetProgress->hide(); 152 docLoadingWidgetProgress->hide();
155 docLoadingWidgetEnabled = true; 153 docLoadingWidgetEnabled = true;
156 } 154 }
157 155
158 QWidget *space2 = new QWidget( docLoadingVBox ); 156 QWidget *space2 = new QWidget( docLoadingVBox );
159 docLoadingVBox->setStretchFactor( space2, 1 ); 157 docLoadingVBox->setStretchFactor( space2, 1 );
160 158
161 cfg.setGroup( "Tab Documents" ); // No tr 159 cfg.setGroup( "Tab Documents" ); // No tr
162 setTabViewAppearance( docLoadingWidget, cfg ); 160 setTabViewAppearance( docLoadingWidget, cfg );
163 161
164 stack->addWidget( docLoadingWidget, 0 ); 162 stack->addWidget( docLoadingWidget, 0 );
165} 163}
166 164
167void LauncherTabWidget::initLayout() 165void LauncherTabWidget::initLayout()
168{ 166{
169 layout()->activate(); 167 layout()->activate();
170 docView()->setFocus(); 168 docView()->setFocus();
171 categoryBar->showTab("Documents"); 169 categoryBar->showTab("Documents");
172} 170}
173 171
174void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&) 172void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&)
175{ 173{
176 if ( message == "nextView()" ) 174 if ( message == "nextView()" )
177 categoryBar->nextTab(); 175 categoryBar->nextTab();
178} 176}
179 177
180void LauncherTabWidget::raiseTabWidget() 178void LauncherTabWidget::raiseTabWidget()
181{ 179{
182 if ( categoryBar->currentView() == docView() 180 if ( categoryBar->currentView() == docView()
183 && docLoadingWidgetEnabled ) { 181 && docLoadingWidgetEnabled ) {
184 stack->raiseWidget( docLoadingWidget ); 182 stack->raiseWidget( docLoadingWidget );
185 docLoadingWidget->updateGeometry(); 183 docLoadingWidget->updateGeometry();
186 } else { 184 } else {
187 stack->raiseWidget( categoryBar->currentView() ); 185 stack->raiseWidget( categoryBar->currentView() );
188 } 186 }
189} 187}
190 188
191void LauncherTabWidget::tabProperties() 189void LauncherTabWidget::tabProperties()
192{ 190{
193 LauncherView *view = categoryBar->currentView(); 191 LauncherView *view = categoryBar->currentView();
194 QPopupMenu *m = new QPopupMenu( this ); 192 QPopupMenu *m = new QPopupMenu( this );
195 m->insertItem( tr("Icon View"), LauncherView::Icon ); 193 m->insertItem( tr("Icon View"), LauncherView::Icon );
196 m->insertItem( tr("List View"), LauncherView::List ); 194 m->insertItem( tr("List View"), LauncherView::List );
197 m->setItemChecked( (int)view->viewMode(), TRUE ); 195 m->setItemChecked( (int)view->viewMode(), TRUE );
198 int rv = m->exec( QCursor::pos() ); 196 int rv = m->exec( QCursor::pos() );
199 if ( rv >= 0 && rv != view->viewMode() ) { 197 if ( rv >= 0 && rv != view->viewMode() ) {
200 view->setViewMode( (LauncherView::ViewMode)rv ); 198 view->setViewMode( (LauncherView::ViewMode)rv );
201 } 199 }
202 200
203 delete m; 201 delete m;
204} 202}
205 203
206void LauncherTabWidget::deleteView( const QString& id ) 204void LauncherTabWidget::deleteView( const QString& id )
207{ 205{
208 LauncherTab *t = categoryBar->launcherTab(id); 206 LauncherTab *t = categoryBar->launcherTab(id);
209 if ( t ) { 207 if ( t ) {
210 stack->removeWidget( t->view ); 208 stack->removeWidget( t->view );
211 delete t->view; 209 delete t->view;
212 categoryBar->removeTab( t ); 210 categoryBar->removeTab( t );
213 } 211 }
214} 212}
215 213
216LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label ) 214LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label )
217{ 215{
218 LauncherView* view = new LauncherView( stack ); 216 LauncherView* view = new LauncherView( stack );
219 connect( view, SIGNAL(clicked(const AppLnk*)), 217 connect( view, SIGNAL(clicked(const AppLnk*)),
220 this, SIGNAL(clicked(const AppLnk*))); 218 this, SIGNAL(clicked(const AppLnk*)));
221 connect( view, SIGNAL(rightPressed(AppLnk*)), 219 connect( view, SIGNAL(rightPressed(AppLnk*)),
222 this, SIGNAL(rightPressed(AppLnk*))); 220 this, SIGNAL(rightPressed(AppLnk*)));
223 221
224 int n = categoryBar->count(); 222 int n = categoryBar->count();
225 stack->addWidget( view, n ); 223 stack->addWidget( view, n );
226 224
227 LauncherTab *tab = new LauncherTab( id, view, pm, label ); 225 LauncherTab *tab = new LauncherTab( id, view, pm, label );
228 categoryBar->insertTab( tab, n-1 ); 226 categoryBar->insertTab( tab, n-1 );
229 227
230 if ( id == "Documents" ) 228 if ( id == "Documents" )
231 docview = view; 229 docview = view;
232 230
233 qDebug("inserting %s at %d", id.latin1(), n-1 ); 231 qDebug("inserting %s at %d", id.latin1(), n-1 );
234 232
235 Config cfg("Launcher"); 233 Config cfg("Launcher");
236 setTabAppearance( tab, cfg ); 234 setTabAppearance( tab, cfg );
237 235
238 cfg.setGroup( "GUI" ); 236 cfg.setGroup( "GUI" );
239 view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) ); 237 view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) );
240 238
241 return view; 239 return view;
242} 240}
243 241
244LauncherView *LauncherTabWidget::view( const QString &id ) 242LauncherView *LauncherTabWidget::view( const QString &id )
245{ 243{
246 LauncherTab *t = categoryBar->launcherTab(id); 244 LauncherTab *t = categoryBar->launcherTab(id);
247 if ( !t ) 245 if ( !t )
248 return 0; 246 return 0;
249 return t->view; 247 return t->view;
250} 248}
251 249
252LauncherView *LauncherTabWidget::docView() 250LauncherView *LauncherTabWidget::docView()
253{ 251{
254 return docview; 252 return docview;
255} 253}
256 254
257void LauncherTabWidget::setLoadingWidgetEnabled( bool v ) 255void LauncherTabWidget::setLoadingWidgetEnabled( bool v )
258{ 256{
259 if ( v != docLoadingWidgetEnabled && docLoadingWidget ) { 257 if ( v != docLoadingWidgetEnabled && docLoadingWidget ) {
260 docLoadingWidgetEnabled = v; 258 docLoadingWidgetEnabled = v;
261 raiseTabWidget(); 259 raiseTabWidget();
262 } 260 }
263} 261}
264 262
265void LauncherTabWidget::setLoadingProgress( int percent ) 263void LauncherTabWidget::setLoadingProgress( int percent )
266{ 264{
267 docLoadingWidgetProgress->setProgress( (percent / 4) * 4 ); 265 docLoadingWidgetProgress->setProgress( (percent / 4) * 4 );
268} 266}
269 267
270// ### this function could more to LauncherView 268// ### this function could more to LauncherView
271void LauncherTabWidget::setTabViewAppearance( LauncherView *v, Config &cfg ) 269void LauncherTabWidget::setTabViewAppearance( LauncherView *v, Config &cfg )
272{ 270{
273 // View 271 // View
274 QString view = cfg.readEntry( "View", "Icon" ); 272 QString view = cfg.readEntry( "View", "Icon" );
275 if ( view == "List" ) // No tr 273 if ( view == "List" ) // No tr
276 v->setViewMode( LauncherView::List ); 274 v->setViewMode( LauncherView::List );
277 QString bgType = cfg.readEntry( "BackgroundType", "Image" ); 275 QString bgType = cfg.readEntry( "BackgroundType", "Image" );
278 if ( bgType == "Image" ) { // No tr 276 if ( bgType == "Image" ) { // No tr
279 QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" ); 277 QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" );
280 v->setBackgroundType( LauncherView::Image, pm ); 278 v->setBackgroundType( LauncherView::Image, pm );
281 } else if ( bgType == "SolidColor" ) { 279 } else if ( bgType == "SolidColor" ) {
282 QString c = cfg.readEntry( "BackgroundColor" ); 280 QString c = cfg.readEntry( "BackgroundColor" );
283 v->setBackgroundType( LauncherView::SolidColor, c ); 281 v->setBackgroundType( LauncherView::SolidColor, c );
284 } else { 282 } else {
285 v->setBackgroundType( LauncherView::Ruled, QString::null ); 283 v->setBackgroundType( LauncherView::Ruled, QString::null );
286 } 284 }
287 QString textCol = cfg.readEntry( "TextColor" ); 285 QString textCol = cfg.readEntry( "TextColor" );
288 if ( textCol.isEmpty() ) 286 if ( textCol.isEmpty() )
289 v->setTextColor( QColor() ); 287 v->setTextColor( QColor() );
290 else 288 else
291 v->setTextColor( QColor(textCol) ); 289 v->setTextColor( QColor(textCol) );
292// bool customFont = cfg.readBoolEntry( "CustomFont", FALSE ); 290// bool customFont = cfg.readBoolEntry( "CustomFont", FALSE );
293 291
294 292
295 QStringList font = cfg.readListEntry( "Font", ',' ); 293 QStringList font = cfg.readListEntry( "Font", ',' );
296 if ( font.count() == 4 ) 294 if ( font.count() == 4 )
297 v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) ); 295 v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) );
298 296
299 // ### FIXME TabColor TabTextColor 297 // ### FIXME TabColor TabTextColor
300 298
301} 299}
302 300
303// ### Could move to LauncherTab 301// ### Could move to LauncherTab
304void LauncherTabWidget::setTabAppearance( LauncherTab *tab, Config &cfg ) 302void LauncherTabWidget::setTabAppearance( LauncherTab *tab, Config &cfg )
305{ 303{
306 cfg.setGroup( QString( "Tab %1" ).arg(tab->type) ); // No tr 304 cfg.setGroup( QString( "Tab %1" ).arg(tab->type) ); // No tr
307 305
308 setTabViewAppearance( tab->view, cfg ); 306 setTabViewAppearance( tab->view, cfg );
309 307
310 // Tabs 308 // Tabs
311 QString tabCol = cfg.readEntry( "TabColor" ); 309 QString tabCol = cfg.readEntry( "TabColor" );
312 if ( tabCol.isEmpty() ) 310 if ( tabCol.isEmpty() )
313 tab->bgColor = QColor(); 311 tab->bgColor = QColor();
314 else 312 else
315 tab->bgColor = QColor(tabCol); 313 tab->bgColor = QColor(tabCol);
316 QString tabTextCol = cfg.readEntry( "TabTextColor" ); 314 QString tabTextCol = cfg.readEntry( "TabTextColor" );
317 if ( tabTextCol.isEmpty() ) 315 if ( tabTextCol.isEmpty() )
318 tab->fgColor = QColor(); 316 tab->fgColor = QColor();
319 else 317 else
320 tab->fgColor = QColor(tabTextCol); 318 tab->fgColor = QColor(tabTextCol);
321} 319}
322 320
323void LauncherTabWidget::paletteChange( const QPalette &p ) 321void LauncherTabWidget::paletteChange( const QPalette &p )
324{ 322{
325 QVBox::paletteChange( p ); 323 QVBox::paletteChange( p );
326 QPalette pal = palette(); 324 QPalette pal = palette();
327 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); 325 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
328 pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); 326 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
329 categoryBar->setPalette( pal ); 327 categoryBar->setPalette( pal );
330 categoryBar->update(); 328 categoryBar->update();
331} 329}
332 330
333void LauncherTabWidget::styleChange( QStyle & ) 331void LauncherTabWidget::styleChange( QStyle & )
334{ 332{
335 QTimer::singleShot( 0, this, SLOT(setProgressStyle()) ); 333 QTimer::singleShot( 0, this, SLOT(setProgressStyle()) );
336} 334}
337 335
338void LauncherTabWidget::setProgressStyle() 336void LauncherTabWidget::setProgressStyle()
339{ 337{
340 if (docLoadingWidgetProgress) { 338 if (docLoadingWidgetProgress) {
341 docLoadingWidgetProgress->setFrameShape( QProgressBar::Box ); 339 docLoadingWidgetProgress->setFrameShape( QProgressBar::Box );
342 docLoadingWidgetProgress->setFrameShadow( QProgressBar::Plain ); 340 docLoadingWidgetProgress->setFrameShadow( QProgressBar::Plain );
343 docLoadingWidgetProgress->setMargin( 1 ); 341 docLoadingWidgetProgress->setMargin( 1 );
344 docLoadingWidgetProgress->setLineWidth( 1 ); 342 docLoadingWidgetProgress->setLineWidth( 1 );
345 } 343 }
346} 344}
347 345
348void LauncherTabWidget::setBusy(bool on) 346void LauncherTabWidget::setBusy(bool on)
349{ 347{
350 if ( on ) 348 if ( on )
351 currentView()->setBusy(TRUE); 349 currentView()->setBusy(TRUE);
352 else { 350 else {
353 for ( int i = 0; i < categoryBar->count(); i++ ) { 351 for ( int i = 0; i < categoryBar->count(); i++ ) {
354 LauncherView *view = ((LauncherTab *)categoryBar->tab(i))->view; 352 LauncherView *view = ((LauncherTab *)categoryBar->tab(i))->view;
355 view->setBusy( FALSE ); 353 view->setBusy( FALSE );
356 } 354 }
357 } 355 }
358} 356}
359 357
360void LauncherTabWidget::setBusyIndicatorType( const QString& str ) { 358void LauncherTabWidget::setBusyIndicatorType( const QString& str ) {
361 for (int i = 0; i < categoryBar->count(); i++ ) { 359 for (int i = 0; i < categoryBar->count(); i++ ) {
362 LauncherView* view = static_cast<LauncherTab*>( categoryBar->tab(i) )->view; 360 LauncherView* view = static_cast<LauncherTab*>( categoryBar->tab(i) )->view;
363 view->setBusyIndicatorType( str ); 361 view->setBusyIndicatorType( str );
364 } 362 }
365} 363}
366 364
367LauncherView *LauncherTabWidget::currentView(void) 365LauncherView *LauncherTabWidget::currentView(void)
368{ 366{
369 return (LauncherView*)stack->visibleWidget(); 367 return (LauncherView*)stack->visibleWidget();
370} 368}
371 369
372 370
373 371
374void LauncherTabWidget::launcherMessage( const QCString &msg, const QByteArray &data) 372void LauncherTabWidget::launcherMessage( const QCString &msg, const QByteArray &data)
375{ 373{
376 QDataStream stream( data, IO_ReadOnly ); 374 QDataStream stream( data, IO_ReadOnly );
377 if ( msg == "setTabView(QString,int)" ) { 375 if ( msg == "setTabView(QString,int)" ) {
378 QString id; 376 QString id;
379 stream >> id; 377 stream >> id;
380 int mode; 378 int mode;
381 stream >> mode; 379 stream >> mode;
382 if ( view(id) ) 380 if ( view(id) )
383 view(id)->setViewMode( (LauncherView::ViewMode)mode ); 381 view(id)->setViewMode( (LauncherView::ViewMode)mode );
384 } else if ( msg == "setTabBackground(QString,int,QString)" ) { 382 } else if ( msg == "setTabBackground(QString,int,QString)" ) {
385 QString id; 383 QString id;
386 stream >> id; 384 stream >> id;
387 int mode; 385 int mode;
388 stream >> mode; 386 stream >> mode;
389 QString pixmapOrColor; 387 QString pixmapOrColor;
390 stream >> pixmapOrColor; 388 stream >> pixmapOrColor;
391 if ( view(id) ) 389 if ( view(id) )
392 view(id)->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor ); 390 view(id)->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor );
393 if ( id == "Documents" ) 391 if ( id == "Documents" )
394 docLoadingWidget->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor ); 392 docLoadingWidget->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor );
395 } else if ( msg == "setTextColor(QString,QString)" ) { 393 } else if ( msg == "setTextColor(QString,QString)" ) {
396 QString id; 394 QString id;
397 stream >> id; 395 stream >> id;
398 QString color; 396 QString color;
399 stream >> color; 397 stream >> color;
400 if ( view(id) ) 398 if ( view(id) )
401 view(id)->setTextColor( QColor(color) ); 399 view(id)->setTextColor( QColor(color) );
402 if ( id == "Documents" ) 400 if ( id == "Documents" )
403 docLoadingWidget->setTextColor( QColor(color) ); 401 docLoadingWidget->setTextColor( QColor(color) );
404 } else if ( msg == "setFont(QString,QString,int,int,int)" ) { 402 } else if ( msg == "setFont(QString,QString,int,int,int)" ) {
405 QString id; 403 QString id;
406 stream >> id; 404 stream >> id;
407 QString fam; 405 QString fam;
408 stream >> fam; 406 stream >> fam;
409 int size; 407 int size;
410 stream >> size; 408 stream >> size;
411 int weight; 409 int weight;
412 stream >> weight; 410 stream >> weight;
413 int italic; 411 int italic;
414 stream >> italic; 412 stream >> italic;
415 if ( view(id) ) { 413 if ( view(id) ) {
416 if ( !fam.isEmpty() ) { 414 if ( !fam.isEmpty() ) {
417 view(id)->setViewFont( QFont(fam, size, weight, italic!=0) ); 415 view(id)->setViewFont( QFont(fam, size, weight, italic!=0) );
418 qDebug( "setFont: %s, %d, %d, %d", fam.latin1(), size, weight, italic ); 416 qDebug( "setFont: %s, %d, %d, %d", fam.latin1(), size, weight, italic );
419 } else { 417 } else {
420 view(id)->clearViewFont(); 418 view(id)->clearViewFont();
421 } 419 }
422 } 420 }
423 }else if ( msg == "setBusyIndicatorType(QString)" ) { 421 }else if ( msg == "setBusyIndicatorType(QString)" ) {
424 QString type; 422 QString type;
425 stream >> type; 423 stream >> type;
426 setBusyIndicatorType( type ); 424 setBusyIndicatorType( type );
427 }else if ( msg == "home()" ) { 425 }else if ( msg == "home()" ) {
428 if ( isVisibleWindow( static_cast<QWidget*>(parent())->winId() ) ) { 426 if ( isVisibleWindow( static_cast<QWidget*>(parent())->winId() ) ) {
429 if (categoryBar) 427 if (categoryBar)
430 categoryBar->nextTab(); 428 categoryBar->nextTab();
431 }else 429 }else
432 static_cast<QWidget*>(parent())->raise(); 430 static_cast<QWidget*>(parent())->raise();
433 } 431 }
434} 432}
435 433
436 434
437 435
438//--------------------------------------------------------------------------- 436//---------------------------------------------------------------------------
439 437
440Launcher::Launcher() 438Launcher::Launcher()
441 : QMainWindow( 0, "PDA User Interface", QWidget::WStyle_Customize | QWidget::WGroupLeader ) 439 : QMainWindow( 0, "PDA User Interface", QWidget::WStyle_Customize | QWidget::WGroupLeader )
442{ 440{
443 tabs = 0; 441 tabs = 0;
444 tb = 0; 442 tb = 0;
445 Config cfg( "Launcher" ); 443 Config cfg( "Launcher" );
446 cfg.setGroup( "DocTab" ); 444 cfg.setGroup( "DocTab" );
447 docTabEnabled = cfg.readBoolEntry( "Enable", true ); 445 docTabEnabled = cfg.readBoolEntry( "Enable", true );
448} 446}
449 447
450void Launcher::createGUI() 448void Launcher::createGUI()
451{ 449{
452 setCaption( tr("Launcher") ); 450 setCaption( tr("Launcher") );
453 451
454 // we have a pretty good idea how big we'll be 452 // we have a pretty good idea how big we'll be
455 setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() ); 453 setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() );
456 454
457 tb = new TaskBar; 455 tb = new TaskBar;
458 tabs = new LauncherTabWidget( this ); 456 tabs = new LauncherTabWidget( this );
459 setCentralWidget( tabs ); 457 setCentralWidget( tabs );
460 458
461 ServerInterface::dockWidget( tb, ServerInterface::Bottom ); 459 ServerInterface::dockWidget( tb, ServerInterface::Bottom );
462 tb->show(); 460 tb->show();
463 461
464 qApp->installEventFilter( this ); 462 qApp->installEventFilter( this );
465 463
466 464
467 connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) ); 465 connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) );
468 connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) ); 466 connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) );
469 connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) ); 467 connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) );
470 468
471 connect( tb, SIGNAL(tabSelected(const QString&)), 469 connect( tb, SIGNAL(tabSelected(const QString&)),
472 this, SLOT(showTab(const QString&)) ); 470 this, SLOT(showTab(const QString&)) );
473 connect( tabs, SIGNAL(selected(const QString&)), 471 connect( tabs, SIGNAL(selected(const QString&)),
474 this, SLOT(viewSelected(const QString&)) ); 472 this, SLOT(viewSelected(const QString&)) );
475 connect( tabs, SIGNAL(clicked(const AppLnk*)), 473 connect( tabs, SIGNAL(clicked(const AppLnk*)),
476 this, SLOT(select(const AppLnk*))); 474 this, SLOT(select(const AppLnk*)));
477 connect( tabs, SIGNAL(rightPressed(AppLnk*)), 475 connect( tabs, SIGNAL(rightPressed(AppLnk*)),
478 this, SLOT(properties(AppLnk*))); 476 this, SLOT(properties(AppLnk*)));
479 477
480#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 478#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
481 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); 479 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this );
482 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), 480 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)),
483 this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); 481 this, SLOT(systemMessage( const QCString &, const QByteArray &)) );
484#endif 482#endif
485 483
486 // all documents 484 // all documents
487 QImage img( Resource::loadImage( "DocsIcon" ) ); 485 QImage img( Resource::loadImage( "DocsIcon" ) );
488 QPixmap pm; 486 QPixmap pm;
489 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 487 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
490 // It could add this itself if it handles docs 488 // It could add this itself if it handles docs
491 489
492 tabs->newView("Documents", pm, tr("Documents") )->setToolsEnabled( TRUE ); 490 tabs->newView("Documents", pm, tr("Documents") )->setToolsEnabled( TRUE );
493 491
494 QTimer::singleShot( 0, tabs, SLOT( initLayout() ) ); 492 QTimer::singleShot( 0, tabs, SLOT( initLayout() ) );
495 qApp->setMainWidget( this ); 493 qApp->setMainWidget( this );
496 QTimer::singleShot( 500, this, SLOT( makeVisible() ) ); 494 QTimer::singleShot( 500, this, SLOT( makeVisible() ) );
497} 495}
498 496
499Launcher::~Launcher() 497Launcher::~Launcher()
500{ 498{
501 if ( tb ) 499 if ( tb )
502 destroyGUI(); 500 destroyGUI();
503} 501}
504 502
505 bool Launcher::requiresDocuments() const 503 bool Launcher::requiresDocuments() const
506 { 504 {
507 Config cfg( "Launcher" ); 505 Config cfg( "Launcher" );
508 cfg.setGroup( "DocTab" ); 506 cfg.setGroup( "DocTab" );
509 return cfg.readBoolEntry( "Enable", true ); 507 return cfg.readBoolEntry( "Enable", true );
510} 508}
511 509
512void Launcher::makeVisible() 510void Launcher::makeVisible()
513{ 511{
514 showMaximized(); 512 showMaximized();
515} 513}
516 514
517void Launcher::destroyGUI() 515void Launcher::destroyGUI()
518{ 516{
519 delete tb; 517 delete tb;
520 tb = 0; 518 tb = 0;
521 delete tabs; 519 delete tabs;
522 tabs =0; 520 tabs =0;
523} 521}
524 522
525bool Launcher::eventFilter( QObject*, QEvent *ev ) 523bool Launcher::eventFilter( QObject*, QEvent *ev )
526{ 524{
527#ifdef QT_QWS_CUSTOM 525#ifdef QT_QWS_CUSTOM
528 if ( ev->type() == QEvent::KeyPress ) { 526 if ( ev->type() == QEvent::KeyPress ) {
529 QKeyEvent *ke = (QKeyEvent *)ev; 527 QKeyEvent *ke = (QKeyEvent *)ev;
530 if ( ke->key() == Qt::Key_F11 ) { // menu key 528 if ( ke->key() == Qt::Key_F11 ) { // menu key
531 QWidget *active = qApp->activeWindow(); 529 QWidget *active = qApp->activeWindow();
532 if ( active && active->isPopup() ) 530 if ( active && active->isPopup() )
533 active->close(); 531 active->close();
534 else { 532 else {
535 Global::terminateBuiltin("calibrate"); // No tr 533 Global::terminateBuiltin("calibrate"); // No tr
536 tb->launchStartMenu(); 534 tb->launchStartMenu();
537 } 535 }
538 return TRUE; 536 return TRUE;
539 } 537 }
540 } 538 }
541#else 539#else
542 Q_UNUSED(ev); 540 Q_UNUSED(ev);
543#endif 541#endif
544 return FALSE; 542 return FALSE;
545} 543}
546 544
547void Launcher::toggleSymbolInput() 545void Launcher::toggleSymbolInput()
548{ 546{
549 tb->toggleSymbolInput(); 547 tb->toggleSymbolInput();
550} 548}
551 549
552void Launcher::toggleNumLockState() 550void Launcher::toggleNumLockState()
553{ 551{
554 tb->toggleNumLockState(); 552 tb->toggleNumLockState();
555} 553}
556 554
557void Launcher::toggleCapsLockState() 555void Launcher::toggleCapsLockState()
558{ 556{
559 tb->toggleCapsLockState(); 557 tb->toggleCapsLockState();
560} 558}
561 559
562static bool isVisibleWindow(int wid) 560static bool isVisibleWindow(int wid)
563{ 561{
564#ifdef Q_WS_QWS 562#ifdef Q_WS_QWS
565 const QList<QWSWindow> &list = qwsServer->clientWindows(); 563 const QList<QWSWindow> &list = qwsServer->clientWindows();
566 QWSWindow* w; 564 QWSWindow* w;
567 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 565 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
568 if ( w->winId() == wid ) 566 if ( w->winId() == wid )
569 return !w->isFullyObscured(); 567 return !w->isFullyObscured();
570 } 568 }
571#endif 569#endif
572 return FALSE; 570 return FALSE;
573} 571}
574 572
575void Launcher::viewSelected(const QString& s) 573void Launcher::viewSelected(const QString& s)
576{ 574{
577 setCaption( s + tr(" - Launcher") ); 575 setCaption( s + tr(" - Launcher") );
578} 576}
579 577
580void Launcher::showTab(const QString& id) 578void Launcher::showTab(const QString& id)
581{ 579{
582 tabs->categoryBar->showTab(id); 580 tabs->categoryBar->showTab(id);
583 raise(); 581 raise();
584} 582}
585 583
586void Launcher::select( const AppLnk *appLnk ) 584void Launcher::select( const AppLnk *appLnk )
587{ 585{
588 if ( appLnk->type() == "Folder" ) { // No tr 586 if ( appLnk->type() == "Folder" ) { // No tr
589 // Not supported: flat is simpler for the user 587 // Not supported: flat is simpler for the user
590 } else { 588 } else {
591 if ( appLnk->exec().isNull() ) { 589 if ( appLnk->exec().isNull() ) {
592 int i = QMessageBox::information(this,tr("No application"), 590 int i = QMessageBox::information(this,tr("No application"),
593 tr("<p>No application is defined for this document." 591 tr("<p>No application is defined for this document."
594 "<p>Type is %1.").arg(appLnk->type()), tr("OK"), tr("View as text"), 0, 0, 1); 592 "<p>Type is %1.").arg(appLnk->type()), tr("OK"), tr("View as text"), 0, 0, 1);
595 593
596 /* ### Fixme */ 594 /* ### Fixme */
597 if ( i == 1 ) 595 if ( i == 1 )
598 Global::execute("textedit",appLnk->file()); 596 Global::execute("textedit",appLnk->file());
599 597
600 return; 598 return;
601 } 599 }
602 tabs->setBusy(TRUE); 600 tabs->setBusy(TRUE);
603 emit executing( appLnk ); 601 emit executing( appLnk );
604 appLnk->execute(); 602 appLnk->execute();
605 } 603 }
606} 604}
607 605
608void Launcher::properties( AppLnk *appLnk ) 606void Launcher::properties( AppLnk *appLnk )
609{ 607{
610 if ( appLnk->type() == "Folder" ) { // No tr 608 if ( appLnk->type() == "Folder" ) { // No tr
611 // Not supported: flat is simpler for the user 609 // Not supported: flat is simpler for the user
612 } else { 610 } else {
613/* ### libqtopia FIXME also moving docLnks... */ 611/* ### libqtopia FIXME also moving docLnks... */
614 LnkProperties prop(appLnk,0 ); 612 LnkProperties prop(appLnk,0 );
615 613
616 QPEApplication::execDialog( &prop ); 614 QPEApplication::execDialog( &prop );
617 } 615 }
618} 616}
619 617
620void Launcher::storageChanged( const QList<FileSystem> &fs ) 618void Launcher::storageChanged( const QList<FileSystem> &fs )
621{ 619{
622 // ### update combo boxes if we had a combo box for the storage type 620 // ### update combo boxes if we had a combo box for the storage type
623} 621}
624 622
625void Launcher::systemMessage( const QCString &msg, const QByteArray &data) 623void Launcher::systemMessage( const QCString &msg, const QByteArray &data)
626{ 624{
627 QDataStream stream( data, IO_ReadOnly ); 625 QDataStream stream( data, IO_ReadOnly );
628 if ( msg == "busy()" ) { 626 if ( msg == "busy()" ) {
629 tb->startWait(); 627 tb->startWait();
630 } else if ( msg == "notBusy(QString)" ) { 628 } else if ( msg == "notBusy(QString)" ) {
631 QString app; 629 QString app;
632 stream >> app; 630 stream >> app;
633 tabs->setBusy(FALSE); 631 tabs->setBusy(FALSE);
634 tb->stopWait(app); 632 tb->stopWait(app);
635 } else if (msg == "applyStyle()") { 633 } else if (msg == "applyStyle()") {
636 tabs->currentView()->relayout(); 634 tabs->currentView()->relayout();
637 } 635 }
638} 636}
639 637
640// These are the update functions from the server 638// These are the update functions from the server
641void Launcher::typeAdded( const QString& type, const QString& name, 639void Launcher::typeAdded( const QString& type, const QString& name,
642 const QPixmap& pixmap, const QPixmap& ) 640 const QPixmap& pixmap, const QPixmap& )
643{ 641{
644 tabs->newView( type, pixmap, name ); 642 tabs->newView( type, pixmap, name );
645 ids.append( type ); 643 ids.append( type );
646 /* this will be called in applicationScanningProgress with value 100! */ 644 /* this will be called in applicationScanningProgress with value 100! */
647// tb->refreshStartMenu(); 645// tb->refreshStartMenu();
648 646
649 static bool first = TRUE; 647 static bool first = TRUE;
650 if ( first ) { 648 if ( first ) {
651 first = FALSE; 649 first = FALSE;
652 tabs->categoryBar->showTab(type); 650 tabs->categoryBar->showTab(type);
653 } 651 }
654 652
655 tabs->view( type )->setUpdatesEnabled( FALSE ); 653 tabs->view( type )->setUpdatesEnabled( FALSE );
656 tabs->view( type )->setSortEnabled( FALSE ); 654 tabs->view( type )->setSortEnabled( FALSE );
657} 655}
658 656
659void Launcher::typeRemoved( const QString& type ) 657void Launcher::typeRemoved( const QString& type )
660{ 658{
661 tabs->view( type )->removeAllItems(); 659 tabs->view( type )->removeAllItems();
662 tabs->deleteView( type ); 660 tabs->deleteView( type );
663 ids.remove( type ); 661 ids.remove( type );
664 /* this will be called in applicationScanningProgress with value 100! */ 662 /* this will be called in applicationScanningProgress with value 100! */
665// tb->refreshStartMenu(); 663// tb->refreshStartMenu();
666} 664}
667 665
668void Launcher::applicationAdded( const QString& type, const AppLnk& app ) 666void Launcher::applicationAdded( const QString& type, const AppLnk& app )
669{ 667{
670 if ( app.type() == "Separator" ) // No tr 668 if ( app.type() == "Separator" ) // No tr
671 return; 669 return;
672 670
673 LauncherView *view = tabs->view( type ); 671 LauncherView *view = tabs->view( type );
674 if ( view ) 672 if ( view )
675 view->addItem( new AppLnk( app ), FALSE ); 673 view->addItem( new AppLnk( app ), FALSE );
676 else 674 else
677 qWarning("addAppLnk: No view for type %s. Can't add app %s!", 675 qWarning("addAppLnk: No view for type %s. Can't add app %s!",
678 type.latin1(),app.name().latin1() ); 676 type.latin1(),app.name().latin1() );
679 677
680 MimeType::registerApp( app ); 678 MimeType::registerApp( app );
681} 679}
682 680
683void Launcher::applicationRemoved( const QString& type, const AppLnk& app ) 681void Launcher::applicationRemoved( const QString& type, const AppLnk& app )
684{ 682{
685 LauncherView *view = tabs->view( type ); 683 LauncherView *view = tabs->view( type );
686 if ( view ) 684 if ( view )
687 view->removeLink( app.linkFile() ); 685 view->removeLink( app.linkFile() );
688 else 686 else
689 qWarning("removeAppLnk: No view for %s!", type.latin1() ); 687 qWarning("removeAppLnk: No view for %s!", type.latin1() );
690} 688}
691 689
692void Launcher::allApplicationsRemoved() 690void Launcher::allApplicationsRemoved()
693{ 691{
694 MimeType::clear(); 692 MimeType::clear();
695 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) 693 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it)
696 tabs->view( (*it) )->removeAllItems(); 694 tabs->view( (*it) )->removeAllItems();
697} 695}
698 696
699void Launcher::documentAdded( const DocLnk& doc ) 697void Launcher::documentAdded( const DocLnk& doc )
700{ 698{
701 tabs->docView()->addItem( new DocLnk( doc ), FALSE ); 699 tabs->docView()->addItem( new DocLnk( doc ), FALSE );
702} 700}
703 701
704void Launcher::showLoadingDocs() 702void Launcher::showLoadingDocs()
705{ 703{
706 tabs->docView()->hide(); 704 tabs->docView()->hide();
707} 705}
708 706
709void Launcher::showDocTab() 707void Launcher::showDocTab()
710{ 708{
711 if ( tabs->categoryBar->currentView() == tabs->docView() ) 709 if ( tabs->categoryBar->currentView() == tabs->docView() )
712 tabs->docView()->show(); 710 tabs->docView()->show();
713} 711}
714 712
715void Launcher::documentRemoved( const DocLnk& doc ) 713void Launcher::documentRemoved( const DocLnk& doc )
716{ 714{
717 tabs->docView()->removeLink( doc.linkFile() ); 715 tabs->docView()->removeLink( doc.linkFile() );
718} 716}
719 717
720void Launcher::documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc ) 718void Launcher::documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc )
721{ 719{
722 documentRemoved( oldDoc ); 720 documentRemoved( oldDoc );
723 documentAdded( newDoc ); 721 documentAdded( newDoc );
724} 722}
725 723
726void Launcher::allDocumentsRemoved() 724void Launcher::allDocumentsRemoved()
727{ 725{
728 tabs->docView()->removeAllItems(); 726 tabs->docView()->removeAllItems();
729} 727}
730 728
731void Launcher::applicationStateChanged( const QString& name, ApplicationState state ) 729void Launcher::applicationStateChanged( const QString& name, ApplicationState state )
732{ 730{
733 tb->setApplicationState( name, state ); 731 tb->setApplicationState( name, state );
734} 732}
735 733
736void Launcher::applicationScanningProgress( int percent ) 734void Launcher::applicationScanningProgress( int percent )
737{ 735{
738 switch ( percent ) { 736 switch ( percent ) {
739 case 0: { 737 case 0: {
740 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) { 738 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) {
741 tabs->view( (*it) )->setUpdatesEnabled( FALSE ); 739 tabs->view( (*it) )->setUpdatesEnabled( FALSE );
742 tabs->view( (*it) )->setSortEnabled( FALSE ); 740 tabs->view( (*it) )->setSortEnabled( FALSE );
743 } 741 }
744 break; 742 break;
745 } 743 }
746 case 100: { 744 case 100: {
747 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) { 745 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) {
748 tabs->view( (*it) )->setUpdatesEnabled( TRUE ); 746 tabs->view( (*it) )->setUpdatesEnabled( TRUE );
749 tabs->view( (*it) )->setSortEnabled( TRUE ); 747 tabs->view( (*it) )->setSortEnabled( TRUE );
750 } 748 }
751 tb->refreshStartMenu(); 749 tb->refreshStartMenu();
752 break; 750 break;
753 } 751 }
754 default: 752 default:
755 break; 753 break;
756 } 754 }
757} 755}
758 756
759void Launcher::documentScanningProgress( int percent ) 757void Launcher::documentScanningProgress( int percent )
760{ 758{
761 switch ( percent ) { 759 switch ( percent ) {
762 case 0: { 760 case 0: {
763 tabs->setLoadingProgress( 0 ); 761 tabs->setLoadingProgress( 0 );
764 tabs->setLoadingWidgetEnabled( TRUE ); 762 tabs->setLoadingWidgetEnabled( TRUE );
765 tabs->docView()->setUpdatesEnabled( FALSE ); 763 tabs->docView()->setUpdatesEnabled( FALSE );
766 tabs->docView()->setSortEnabled( FALSE ); 764 tabs->docView()->setSortEnabled( FALSE );
767 break; 765 break;
768 } 766 }
769 case 100: { 767 case 100: {
770 tabs->docView()->updateTools(); 768 tabs->docView()->updateTools();
771 tabs->docView()->setSortEnabled( TRUE ); 769 tabs->docView()->setSortEnabled( TRUE );
772 tabs->docView()->setUpdatesEnabled( TRUE ); 770 tabs->docView()->setUpdatesEnabled( TRUE );
773 tabs->setLoadingWidgetEnabled( FALSE ); 771 tabs->setLoadingWidgetEnabled( FALSE );
774 break; 772 break;
775 } 773 }
776 default: 774 default:
777 tabs->setLoadingProgress( percent ); 775 tabs->setLoadingProgress( percent );
778 break; 776 break;
779 } 777 }
780} 778}
781 779
diff --git a/core/launcher/launcherglobal.cpp b/core/launcher/launcherglobal.cpp
index 84caa93..9abcae9 100644
--- a/core/launcher/launcherglobal.cpp
+++ b/core/launcher/launcherglobal.cpp
@@ -1,83 +1,79 @@
1/* 1/*
2 * GPLv2 only 2 * GPLv2 only
3 * 3 *
4 * TT 2002-2002,2003 4 * TT 2002-2002,2003
5 */ 5 */
6#include <qstring.h>
7#include <qcstring.h>
8#include <qwidget.h>
9#include <qguardedptr.h>
10#include <qfile.h> 6#include <qfile.h>
11#include <qtextstream.h> 7#include <qtextstream.h>
12 8
13#include <qtopia/mimetype.h> 9#include <qtopia/mimetype.h>
14 10
15#include "launcherglobal.h" 11#include "launcherglobal.h"
16 12
17bool Opie::Global::isAppLnkFileName( const QString& file ) { 13bool Opie::Global::isAppLnkFileName( const QString& file ) {
18 if ( file.right(1) == "/" ) 14 if ( file.right(1) == "/" )
19 return FALSE; 15 return FALSE;
20 16
21 return file.find(MimeType::appsFolderName()+"/")==0; 17 return file.find(MimeType::appsFolderName()+"/")==0;
22} 18}
23 19
24QString Opie::Global::tempDir() { 20QString Opie::Global::tempDir() {
25 return QString::fromLatin1("/tmp/"); 21 return QString::fromLatin1("/tmp/");
26} 22}
27 23
28Global::Command* Opie::Global::builtinCommands() { 24Global::Command* Opie::Global::builtinCommands() {
29 return builtin; 25 return builtin;
30} 26}
31 27
32QGuardedPtr<QWidget>* Opie::Global::builtinRunning() { 28QGuardedPtr<QWidget>* Opie::Global::builtinRunning() {
33 return running; 29 return running;
34} 30}
35 31
36QString Opie::Global::uuid() { 32QString Opie::Global::uuid() {
37 QFile file( "/proc/sys/kernel/random/uuid" ); 33 QFile file( "/proc/sys/kernel/random/uuid" );
38 if (!file.open(IO_ReadOnly ) ) 34 if (!file.open(IO_ReadOnly ) )
39 return QString::null; 35 return QString::null;
40 36
41 QTextStream stream(&file); 37 QTextStream stream(&file);
42 38
43 return "{" + stream.read().stripWhiteSpace() + "}"; 39 return "{" + stream.read().stripWhiteSpace() + "}";
44} 40}
45 41
46QByteArray Opie::Global::encodeBase64(const QByteArray& origData ) { 42QByteArray Opie::Global::encodeBase64(const QByteArray& origData ) {
47// follows simple algorithm from rsync code 43// follows simple algorithm from rsync code
48 uchar *in = (uchar*)origData.data(); 44 uchar *in = (uchar*)origData.data();
49 45
50 int inbytes = origData.size(); 46 int inbytes = origData.size();
51 int outbytes = ((inbytes * 8) + 5) / 6; 47 int outbytes = ((inbytes * 8) + 5) / 6;
52 int padding = 4-outbytes%4; if ( padding == 4 ) padding = 0; 48 int padding = 4-outbytes%4; if ( padding == 4 ) padding = 0;
53 49
54 QByteArray outbuf(outbytes+padding); 50 QByteArray outbuf(outbytes+padding);
55 uchar* out = (uchar*)outbuf.data(); 51 uchar* out = (uchar*)outbuf.data();
56 52
57 const char *b64 = 53 const char *b64 =
58 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 54 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
59 55
60 for (int i = 0; i < outbytes; i++) { 56 for (int i = 0; i < outbytes; i++) {
61 int byte = (i * 6) / 8; 57 int byte = (i * 6) / 8;
62 int bit = (i * 6) % 8; 58 int bit = (i * 6) % 8;
63 if (bit < 3) { 59 if (bit < 3) {
64 if (byte < inbytes) 60 if (byte < inbytes)
65 *out = (b64[(in[byte] >> (2 - bit)) & 0x3F]); 61 *out = (b64[(in[byte] >> (2 - bit)) & 0x3F]);
66 } else { 62 } else {
67 if (byte + 1 == inbytes) { 63 if (byte + 1 == inbytes) {
68 *out = (b64[(in[byte] << (bit - 2)) & 0x3F]); 64 *out = (b64[(in[byte] << (bit - 2)) & 0x3F]);
69 } else { 65 } else {
70 *out = (b64[(in[byte] << (bit - 2) | 66 *out = (b64[(in[byte] << (bit - 2) |
71 in[byte + 1] >> (10 - bit)) & 0x3F]); 67 in[byte + 1] >> (10 - bit)) & 0x3F]);
72 } 68 }
73 } 69 }
74 ++out; 70 ++out;
75 } 71 }
76 ASSERT(out == (uchar*)outbuf.data() + outbuf.size() - padding); 72 ASSERT(out == (uchar*)outbuf.data() + outbuf.size() - padding);
77 while ( padding-- ) 73 while ( padding-- )
78 *out++='='; 74 *out++='=';
79 75
80 return outbuf; 76 return outbuf;
81} 77}
82 78
83 79
diff --git a/core/launcher/launchertab.cpp b/core/launcher/launchertab.cpp
index 10cfd5f..710f259 100644
--- a/core/launcher/launchertab.cpp
+++ b/core/launcher/launchertab.cpp
@@ -1,284 +1,281 @@
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#include "launchertab.h" 20#include "launchertab.h"
21#include <qapplication.h> 21#include <qapplication.h>
22#include <qstyle.h>
23#include <qpainter.h>
24#include <qbitmap.h>
25 22
26 23
27LauncherTabBar::LauncherTabBar( QWidget *parent, const char *name ) 24LauncherTabBar::LauncherTabBar( QWidget *parent, const char *name )
28 : QTabBar( parent, name ) 25 : QTabBar( parent, name )
29{ 26{
30 setFocusPolicy( NoFocus ); 27 setFocusPolicy( NoFocus );
31 connect( this, SIGNAL( selected(int) ), this, SLOT( layoutTabs() ) ); 28 connect( this, SIGNAL( selected(int) ), this, SLOT( layoutTabs() ) );
32} 29}
33 30
34LauncherTabBar::~LauncherTabBar() 31LauncherTabBar::~LauncherTabBar()
35{ 32{
36} 33}
37 34
38void LauncherTabBar::insertTab( LauncherTab *t, int index ) 35void LauncherTabBar::insertTab( LauncherTab *t, int index )
39{ 36{
40 if ( index < 0 ) 37 if ( index < 0 )
41 items.append( t ); 38 items.append( t );
42 else 39 else
43 items.insert( (uint)index, t ); 40 items.insert( (uint)index, t );
44 tabs.insert( t->type, t ); 41 tabs.insert( t->type, t );
45 QTabBar::insertTab( t, index ); 42 QTabBar::insertTab( t, index );
46} 43}
47 44
48void LauncherTabBar::removeTab( QTab *tab ) 45void LauncherTabBar::removeTab( QTab *tab )
49{ 46{
50 LauncherTab *t = (LauncherTab *)tab; 47 LauncherTab *t = (LauncherTab *)tab;
51 tabs.remove( t->type ); 48 tabs.remove( t->type );
52 items.remove( t ); 49 items.remove( t );
53 QTabBar::removeTab( t ); 50 QTabBar::removeTab( t );
54} 51}
55 52
56void LauncherTabBar::prevTab() 53void LauncherTabBar::prevTab()
57{ 54{
58 int n = count(); 55 int n = count();
59 int tab = currentTab(); 56 int tab = currentTab();
60 if ( tab >= 0 ) 57 if ( tab >= 0 )
61 setCurrentTab( (tab - 1 + n)%n ); 58 setCurrentTab( (tab - 1 + n)%n );
62} 59}
63 60
64void LauncherTabBar::nextTab() 61void LauncherTabBar::nextTab()
65{ 62{
66 int n = count(); 63 int n = count();
67 int tab = currentTab(); 64 int tab = currentTab();
68 setCurrentTab( (tab + 1)%n ); 65 setCurrentTab( (tab + 1)%n );
69} 66}
70 67
71void LauncherTabBar::showTab( const QString& id ) 68void LauncherTabBar::showTab( const QString& id )
72{ 69{
73 setCurrentTab( tabs[id] ); 70 setCurrentTab( tabs[id] );
74} 71}
75 72
76void LauncherTabBar::layoutTabs() 73void LauncherTabBar::layoutTabs()
77{ 74{
78 if ( !count() ) 75 if ( !count() )
79 return; 76 return;
80 77
81 int available = width()-1; 78 int available = width()-1;
82 79
83 QFontMetrics fm = fontMetrics(); 80 QFontMetrics fm = fontMetrics();
84 int hiddenTabWidth = -12; 81 int hiddenTabWidth = -12;
85 LauncherTab *current = currentLauncherTab(); 82 LauncherTab *current = currentLauncherTab();
86 int hframe, vframe, overlap; 83 int hframe, vframe, overlap;
87 style().tabbarMetrics( this, hframe, vframe, overlap ); 84 style().tabbarMetrics( this, hframe, vframe, overlap );
88 int x = 0; 85 int x = 0;
89 QRect r; 86 QRect r;
90 LauncherTab *t; 87 LauncherTab *t;
91 QListIterator< LauncherTab > it( items ); 88 QListIterator< LauncherTab > it( items );
92 int required = 0; 89 int required = 0;
93 int eventabwidth = (width()-1)/count(); 90 int eventabwidth = (width()-1)/count();
94 enum Mode { HideBackText, Pack, Even } mode=Even; 91 enum Mode { HideBackText, Pack, Even } mode=Even;
95 for (it.toFirst(); it.current(); ++it ) { 92 for (it.toFirst(); it.current(); ++it ) {
96 t = it.current(); 93 t = it.current();
97 if ( !t ) 94 if ( !t )
98 continue; 95 continue;
99 int iw = fm.width( t->text() ) + hframe - overlap; 96 int iw = fm.width( t->text() ) + hframe - overlap;
100 if ( t != current ) { 97 if ( t != current ) {
101 available -= hiddenTabWidth + hframe - overlap; 98 available -= hiddenTabWidth + hframe - overlap;
102 if ( t->iconSet() != 0 ) 99 if ( t->iconSet() != 0 )
103 available -= t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); 100 available -= t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
104 } 101 }
105 if ( t->iconSet() != 0 ) 102 if ( t->iconSet() != 0 )
106 iw += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); 103 iw += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
107 required += iw; 104 required += iw;
108 // As space gets tight, packed looks better than even. "10" must be at least 0. 105 // As space gets tight, packed looks better than even. "10" must be at least 0.
109 if ( iw >= eventabwidth-10 ) 106 if ( iw >= eventabwidth-10 )
110 mode = Pack; 107 mode = Pack;
111 } 108 }
112 if ( mode == Pack && required > width()-1 ) 109 if ( mode == Pack && required > width()-1 )
113 mode = HideBackText; 110 mode = HideBackText;
114 for ( it.toFirst(); it.current(); ++it ) { 111 for ( it.toFirst(); it.current(); ++it ) {
115 t = it.current(); 112 t = it.current();
116 if ( !t ) 113 if ( !t )
117 continue; 114 continue;
118 if ( mode != HideBackText ) { 115 if ( mode != HideBackText ) {
119 int w = fm.width( t->text() ); 116 int w = fm.width( t->text() );
120 int ih = 0; 117 int ih = 0;
121 if ( t->iconSet() != 0 ) { 118 if ( t->iconSet() != 0 ) {
122 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); 119 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
123 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); 120 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
124 } 121 }
125 int h = QMAX( fm.height(), ih ); 122 int h = QMAX( fm.height(), ih );
126 h = QMAX( h, QApplication::globalStrut().height() ); 123 h = QMAX( h, QApplication::globalStrut().height() );
127 124
128 h += vframe; 125 h += vframe;
129 w += hframe; 126 w += hframe;
130 127
131 QRect totr(x, 0, 128 QRect totr(x, 0,
132 mode == Even ? eventabwidth : w * (width()-1)/required, h); 129 mode == Even ? eventabwidth : w * (width()-1)/required, h);
133 t->setRect(totr); 130 t->setRect(totr);
134 x += totr.width() - overlap; 131 x += totr.width() - overlap;
135 r = r.unite(totr); 132 r = r.unite(totr);
136 } else if ( t != current ) { 133 } else if ( t != current ) {
137 int w = hiddenTabWidth; 134 int w = hiddenTabWidth;
138 int ih = 0; 135 int ih = 0;
139 if ( t->iconSet() != 0 ) { 136 if ( t->iconSet() != 0 ) {
140 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); 137 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
141 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); 138 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
142 } 139 }
143 int h = QMAX( fm.height(), ih ); 140 int h = QMAX( fm.height(), ih );
144 h = QMAX( h, QApplication::globalStrut().height() ); 141 h = QMAX( h, QApplication::globalStrut().height() );
145 142
146 h += vframe; 143 h += vframe;
147 w += hframe; 144 w += hframe;
148 145
149 t->setRect( QRect(x, 0, w, h) ); 146 t->setRect( QRect(x, 0, w, h) );
150 x += t->rect().width() - overlap; 147 x += t->rect().width() - overlap;
151 r = r.unite( t->rect() ); 148 r = r.unite( t->rect() );
152 } else { 149 } else {
153 int ih = 0; 150 int ih = 0;
154 if ( t->iconSet() != 0 ) { 151 if ( t->iconSet() != 0 ) {
155 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); 152 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
156 } 153 }
157 int h = QMAX( fm.height(), ih ); 154 int h = QMAX( fm.height(), ih );
158 h = QMAX( h, QApplication::globalStrut().height() ); 155 h = QMAX( h, QApplication::globalStrut().height() );
159 156
160 h += vframe; 157 h += vframe;
161 158
162 t->setRect( QRect(x, 0, available, h) ); 159 t->setRect( QRect(x, 0, available, h) );
163 x += t->rect().width() - overlap; 160 x += t->rect().width() - overlap;
164 r = r.unite( t->rect() ); 161 r = r.unite( t->rect() );
165 } 162 }
166 } 163 }
167 164
168 t = it.toLast(); 165 t = it.toLast();
169 if (t) { 166 if (t) {
170 QRect rr = t->rect(); 167 QRect rr = t->rect();
171 rr.setRight(width()-1); 168 rr.setRight(width()-1);
172 t->setRect( rr ); 169 t->setRect( rr );
173 } 170 }
174 171
175 for (it.toFirst(); it.current(); ++it ) { 172 for (it.toFirst(); it.current(); ++it ) {
176 t = it.current(); 173 t = it.current();
177 QRect tr = t->rect(); 174 QRect tr = t->rect();
178 tr.setHeight( r.height() ); 175 tr.setHeight( r.height() );
179 t->setRect( tr ); 176 t->setRect( tr );
180 } 177 }
181 178
182 update(); 179 update();
183} 180}
184 181
185void LauncherTabBar::paint( QPainter * p, QTab * t, bool selected ) const 182void LauncherTabBar::paint( QPainter * p, QTab * t, bool selected ) const
186{ 183{
187 LauncherTabBar *that = (LauncherTabBar *) this; 184 LauncherTabBar *that = (LauncherTabBar *) this;
188 LauncherTab *ct = (LauncherTab *)t; 185 LauncherTab *ct = (LauncherTab *)t;
189 QPalette pal = palette(); 186 QPalette pal = palette();
190 bool setPal = FALSE; 187 bool setPal = FALSE;
191 if ( ct->bgColor.isValid() ) { 188 if ( ct->bgColor.isValid() ) {
192 pal.setColor( QPalette::Active, QColorGroup::Background, ct->bgColor ); 189 pal.setColor( QPalette::Active, QColorGroup::Background, ct->bgColor );
193 pal.setColor( QPalette::Active, QColorGroup::Button, ct->bgColor ); 190 pal.setColor( QPalette::Active, QColorGroup::Button, ct->bgColor );
194 pal.setColor( QPalette::Inactive, QColorGroup::Background, ct->bgColor ); 191 pal.setColor( QPalette::Inactive, QColorGroup::Background, ct->bgColor );
195 pal.setColor( QPalette::Inactive, QColorGroup::Button, ct->bgColor ); 192 pal.setColor( QPalette::Inactive, QColorGroup::Button, ct->bgColor );
196 that->setUpdatesEnabled( FALSE ); 193 that->setUpdatesEnabled( FALSE );
197 that->setPalette( pal ); 194 that->setPalette( pal );
198 setPal = TRUE; 195 setPal = TRUE;
199 } 196 }
200#if QT_VERSION >= 0x030000 197#if QT_VERSION >= 0x030000
201 QStyle::SFlags flags = QStyle::Style_Default; 198 QStyle::SFlags flags = QStyle::Style_Default;
202 if ( selected ) 199 if ( selected )
203 flags |= QStyle::Style_Selected; 200 flags |= QStyle::Style_Selected;
204 style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(), 201 style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(),
205 colorGroup(), flags, QStyleOption(t) ); 202 colorGroup(), flags, QStyleOption(t) );
206#else 203#else
207 style().drawTab( p, this, t, selected ); 204 style().drawTab( p, this, t, selected );
208#endif 205#endif
209 206
210 QRect r( t->rect() ); 207 QRect r( t->rect() );
211 QFont f( font() ); 208 QFont f( font() );
212 if ( selected ) 209 if ( selected )
213 f.setBold( TRUE ); 210 f.setBold( TRUE );
214 p->setFont( f ); 211 p->setFont( f );
215 212
216 if ( ct->fgColor.isValid() ) { 213 if ( ct->fgColor.isValid() ) {
217 pal.setColor( QPalette::Active, QColorGroup::Foreground, ct->fgColor ); 214 pal.setColor( QPalette::Active, QColorGroup::Foreground, ct->fgColor );
218 pal.setColor( QPalette::Inactive, QColorGroup::Foreground, ct->fgColor ); 215 pal.setColor( QPalette::Inactive, QColorGroup::Foreground, ct->fgColor );
219 that->setUpdatesEnabled( FALSE ); 216 that->setUpdatesEnabled( FALSE );
220 that->setPalette( pal ); 217 that->setPalette( pal );
221 setPal = TRUE; 218 setPal = TRUE;
222 } 219 }
223 int iw = 0; 220 int iw = 0;
224 int ih = 0; 221 int ih = 0;
225 if ( t->iconSet() != 0 ) { 222 if ( t->iconSet() != 0 ) {
226 iw = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 2; 223 iw = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 2;
227 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); 224 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
228 } 225 }
229 int w = iw + p->fontMetrics().width( t->text() ) + 4; 226 int w = iw + p->fontMetrics().width( t->text() ) + 4;
230 int h = QMAX(p->fontMetrics().height() + 4, ih ); 227 int h = QMAX(p->fontMetrics().height() + 4, ih );
231 paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3, 228 paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3,
232 r.top() + (r.height()-h)/2, w, h ), t, 229 r.top() + (r.height()-h)/2, w, h ), t,
233#if QT_VERSION >= 0x030000 230#if QT_VERSION >= 0x030000
234 t->identifier() == keyboardFocusTab() 231 t->identifier() == keyboardFocusTab()
235#else 232#else
236 t->identitifer() == keyboardFocusTab() 233 t->identitifer() == keyboardFocusTab()
237#endif 234#endif
238 ); 235 );
239 if ( setPal ) { 236 if ( setPal ) {
240 that->unsetPalette(); 237 that->unsetPalette();
241 that->setUpdatesEnabled( TRUE ); 238 that->setUpdatesEnabled( TRUE );
242 } 239 }
243} 240}
244 241
245void LauncherTabBar::paintLabel( QPainter* p, const QRect&, 242void LauncherTabBar::paintLabel( QPainter* p, const QRect&,
246 QTab* t, bool has_focus ) const 243 QTab* t, bool has_focus ) const
247{ 244{
248 QRect r = t->rect(); 245 QRect r = t->rect();
249 // if ( t->id != currentTab() ) 246 // if ( t->id != currentTab() )
250 //r.moveBy( 1, 1 ); 247 //r.moveBy( 1, 1 );
251 // 248 //
252 if ( t->iconSet() ) { 249 if ( t->iconSet() ) {
253 // the tab has an iconset, draw it in the right mode 250 // the tab has an iconset, draw it in the right mode
254 QIconSet::Mode mode = (t->isEnabled() && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled; 251 QIconSet::Mode mode = (t->isEnabled() && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled;
255 if ( mode == QIconSet::Normal && has_focus ) 252 if ( mode == QIconSet::Normal && has_focus )
256 mode = QIconSet::Active; 253 mode = QIconSet::Active;
257 QPixmap pixmap = t->iconSet()->pixmap( QIconSet::Small, mode ); 254 QPixmap pixmap = t->iconSet()->pixmap( QIconSet::Small, mode );
258 int pixw = pixmap.width(); 255 int pixw = pixmap.width();
259 int pixh = pixmap.height(); 256 int pixh = pixmap.height();
260 p->drawPixmap( r.left() + 6, r.center().y() - pixh / 2 + 1, pixmap ); 257 p->drawPixmap( r.left() + 6, r.center().y() - pixh / 2 + 1, pixmap );
261 r.setLeft( r.left() + pixw + 5 ); 258 r.setLeft( r.left() + pixw + 5 );
262 } 259 }
263 260
264 QRect tr = r; 261 QRect tr = r;
265 262
266 if ( r.width() < 20 ) 263 if ( r.width() < 20 )
267 return; 264 return;
268 265
269 if ( t->isEnabled() && isEnabled() ) { 266 if ( t->isEnabled() && isEnabled() ) {
270#if defined(_WS_WIN32_) 267#if defined(_WS_WIN32_)
271 if ( colorGroup().brush( QColorGroup::Button ) == colorGroup().brush( QColorGroup::Background ) ) 268 if ( colorGroup().brush( QColorGroup::Button ) == colorGroup().brush( QColorGroup::Background ) )
272 p->setPen( colorGroup().buttonText() ); 269 p->setPen( colorGroup().buttonText() );
273 else 270 else
274 p->setPen( colorGroup().foreground() ); 271 p->setPen( colorGroup().foreground() );
275#else 272#else
276 p->setPen( colorGroup().foreground() ); 273 p->setPen( colorGroup().foreground() );
277#endif 274#endif
278 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() ); 275 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() );
279 } else { 276 } else {
280 p->setPen( palette().disabled().foreground() ); 277 p->setPen( palette().disabled().foreground() );
281 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() ); 278 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() );
282 } 279 }
283} 280}
284 281
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index 62c678d..513b1bd 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -1,1070 +1,1056 @@
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 "launcherview.h" 21#include "launcherview.h"
22 22
23#include <qtopia/qpeapplication.h> 23#include <qtopia/qpeapplication.h>
24#include <qtopia/applnk.h>
25#include <qtopia/qpedebug.h>
26#include <qtopia/private/categories.h> 24#include <qtopia/private/categories.h>
27#include <qtopia/categoryselect.h> 25#include <qtopia/categoryselect.h>
28#include <qtopia/menubutton.h>
29#include <qtopia/mimetype.h> 26#include <qtopia/mimetype.h>
30#include <qtopia/resource.h> 27#include <qtopia/resource.h>
31#include <qtopia/qpetoolbar.h>
32//#include <qtopia/private/palmtoprecord.h> 28//#include <qtopia/private/palmtoprecord.h>
33 29
34#include <qtimer.h> 30#include <qtimer.h>
35#include <qtextstream.h>
36#include <qdict.h>
37#include <qfile.h>
38#include <qfileinfo.h> 31#include <qfileinfo.h>
39#include <qhbox.h>
40#include <qiconview.h> 32#include <qiconview.h>
41#include <qwidgetstack.h>
42#include <qpainter.h>
43#include <qregexp.h>
44#include <qtoolbutton.h>
45#include <qimage.h>
46#include <qlabel.h>
47#include <qobjectlist.h> 33#include <qobjectlist.h>
48 34
49 35
50// These define how the busy icon is animated and highlighted 36// These define how the busy icon is animated and highlighted
51#define BRIGHTEN_BUSY_ICON 37#define BRIGHTEN_BUSY_ICON
52//#define ALPHA_FADE_BUSY_ICON 38//#define ALPHA_FADE_BUSY_ICON
53//#define USE_ANIMATED_BUSY_ICON_OVERLAY 39//#define USE_ANIMATED_BUSY_ICON_OVERLAY
54#define BOUNCE_BUSY_ICON 40#define BOUNCE_BUSY_ICON
55 41
56 42
57class BgPixmap 43class BgPixmap
58{ 44{
59public: 45public:
60 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} 46 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
61 QPixmap pm; 47 QPixmap pm;
62 int ref; 48 int ref;
63}; 49};
64 50
65 51
66static QMap<QString,BgPixmap*> *bgCache = 0; 52static QMap<QString,BgPixmap*> *bgCache = 0;
67 53
68static void cleanup_cache() 54static void cleanup_cache()
69{ 55{
70 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); 56 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
71 while ( it != bgCache->end() ) { 57 while ( it != bgCache->end() ) {
72 QMap<QString,BgPixmap*>::Iterator curr = it; 58 QMap<QString,BgPixmap*>::Iterator curr = it;
73 ++it; 59 ++it;
74 delete (*curr); 60 delete (*curr);
75 bgCache->remove( curr ); 61 bgCache->remove( curr );
76 } 62 }
77 delete bgCache; 63 delete bgCache;
78 bgCache = 0; 64 bgCache = 0;
79} 65}
80 66
81 67
82class LauncherItem : public QIconViewItem 68class LauncherItem : public QIconViewItem
83{ 69{
84public: 70public:
85 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); 71 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
86 ~LauncherItem(); 72 ~LauncherItem();
87 73
88 AppLnk *appLnk() const { return app; } 74 AppLnk *appLnk() const { return app; }
89 AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } 75 AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; }
90 76
91 void animateIcon(); 77 void animateIcon();
92 void resetIcon(); 78 void resetIcon();
93 79
94 virtual int compare ( QIconViewItem * i ) const; 80 virtual int compare ( QIconViewItem * i ) const;
95 void paintItem( QPainter *p, const QColorGroup &cg ); 81 void paintItem( QPainter *p, const QColorGroup &cg );
96 82
97 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } 83 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
98protected: 84protected:
99 bool isBigIcon; 85 bool isBigIcon;
100 int iteration; 86 int iteration;
101 AppLnk* app; 87 AppLnk* app;
102private: 88private:
103 void paintAnimatedIcon( QPainter *p ); 89 void paintAnimatedIcon( QPainter *p );
104 BusyIndicatorType busyType; 90 BusyIndicatorType busyType;
105}; 91};
106 92
107 93
108class LauncherIconView : public QIconView { 94class LauncherIconView : public QIconView {
109public: 95public:
110 LauncherIconView( QWidget* parent, const char* name=0 ) : 96 LauncherIconView( QWidget* parent, const char* name=0 ) :
111 QIconView(parent,name), 97 QIconView(parent,name),
112 tf(""), 98 tf(""),
113 cf(0), 99 cf(0),
114 bsy(0), 100 bsy(0),
115 busyTimer(0), 101 busyTimer(0),
116 bigIcns(TRUE), 102 bigIcns(TRUE),
117 bgColor(white) 103 bgColor(white)
118 { 104 {
119 sortmeth = Name; 105 sortmeth = Name;
120 hidden.setAutoDelete(TRUE); 106 hidden.setAutoDelete(TRUE);
121 ike = FALSE; 107 ike = FALSE;
122 calculateGrid( Bottom ); 108 calculateGrid( Bottom );
123 } 109 }
124 110
125 ~LauncherIconView() 111 ~LauncherIconView()
126 { 112 {
127#if 0 // debuggery 113#if 0 // debuggery
128 QListIterator<AppLnk> it(hidden); 114 QListIterator<AppLnk> it(hidden);
129 AppLnk* l; 115 AppLnk* l;
130 while ((l=it.current())) { 116 while ((l=it.current())) {
131 ++it; 117 ++it;
132 //qDebug("%p: hidden (should remove)",l); 118 //qDebug("%p: hidden (should remove)",l);
133 } 119 }
134#endif 120#endif
135 } 121 }
136 122
137 QIconViewItem* busyItem() const { return bsy; } 123 QIconViewItem* busyItem() const { return bsy; }
138#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 124#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
139 QPixmap busyPixmap() const { return busyPix; } 125 QPixmap busyPixmap() const { return busyPix; }
140#endif 126#endif
141 void setBigIcons( bool bi ) { 127 void setBigIcons( bool bi ) {
142 bigIcns = bi; 128 bigIcns = bi;
143#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 129#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
144 busyPix.resize(0,0); 130 busyPix.resize(0,0);
145#endif 131#endif
146 } 132 }
147 133
148 void updateCategoriesAndMimeTypes(); 134 void updateCategoriesAndMimeTypes();
149 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } 135 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
150 void doAutoScroll() 136 void doAutoScroll()
151 { 137 {
152 // We don't want rubberbanding (yet) 138 // We don't want rubberbanding (yet)
153 } 139 }
154 140
155 void setBusy(bool on) 141 void setBusy(bool on)
156 { 142 {
157#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 143#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
158 if ( busyPix.isNull() ) { 144 if ( busyPix.isNull() ) {
159 int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); 145 int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize();
160 busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) ); 146 busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) );
161 } 147 }
162#endif 148#endif
163 149
164 if ( on ) { 150 if ( on ) {
165 busyTimer = startTimer( 100 ); 151 busyTimer = startTimer( 100 );
166 } else { 152 } else {
167 if ( busyTimer ) { 153 if ( busyTimer ) {
168 killTimer( busyTimer ); 154 killTimer( busyTimer );
169 busyTimer = 0; 155 busyTimer = 0;
170 } 156 }
171 } 157 }
172 158
173 LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; 159 LauncherItem *c = on ? (LauncherItem*)currentItem() : 0;
174 160
175 if ( bsy != c ) { 161 if ( bsy != c ) {
176 LauncherItem *oldBusy = bsy; 162 LauncherItem *oldBusy = bsy;
177 bsy = c; 163 bsy = c;
178 if ( oldBusy ) { 164 if ( oldBusy ) {
179 oldBusy->resetIcon(); 165 oldBusy->resetIcon();
180 } 166 }
181 if ( bsy ) { 167 if ( bsy ) {
182 bsy->setBusyIndicatorType( busyType ) ; 168 bsy->setBusyIndicatorType( busyType ) ;
183 bsy->animateIcon(); 169 bsy->animateIcon();
184 } 170 }
185 } 171 }
186 } 172 }
187 173
188 bool inKeyEvent() const { return ike; } 174 bool inKeyEvent() const { return ike; }
189 void keyPressEvent(QKeyEvent* e) 175 void keyPressEvent(QKeyEvent* e)
190 { 176 {
191 ike = TRUE; 177 ike = TRUE;
192 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) { 178 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) {
193 if ( (e->state() & ShiftButton) ) 179 if ( (e->state() & ShiftButton) )
194 emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() ); 180 emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() );
195 else 181 else
196 returnPressed(currentItem()); 182 returnPressed(currentItem());
197 } 183 }
198 184
199 QIconView::keyPressEvent(e); 185 QIconView::keyPressEvent(e);
200 ike = FALSE; 186 ike = FALSE;
201 } 187 }
202 188
203 void addItem(AppLnk* app, bool resort=TRUE); 189 void addItem(AppLnk* app, bool resort=TRUE);
204 bool removeLink(const QString& linkfile); 190 bool removeLink(const QString& linkfile);
205 191
206 QStringList mimeTypes() const; 192 QStringList mimeTypes() const;
207 QStringList categories() const; 193 QStringList categories() const;
208 194
209 void clear() 195 void clear()
210 { 196 {
211 mimes.clear(); 197 mimes.clear();
212 cats.clear(); 198 cats.clear();
213 QIconView::clear(); 199 QIconView::clear();
214 hidden.clear(); 200 hidden.clear();
215 } 201 }
216 202
217 void addCatsAndMimes(AppLnk* app) 203 void addCatsAndMimes(AppLnk* app)
218 { 204 {
219 // QStringList c = app->categories(); 205 // QStringList c = app->categories();
220 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 206 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
221 // cats.replace(*cit,(void*)1); 207 // cats.replace(*cit,(void*)1);
222 // } 208 // }
223 QString maj=app->type(); 209 QString maj=app->type();
224 int sl=maj.find('/'); 210 int sl=maj.find('/');
225 if (sl>=0) { 211 if (sl>=0) {
226 QString k; 212 QString k;
227 k = maj.left(12) == "application/" ? maj : maj.left(sl); 213 k = maj.left(12) == "application/" ? maj : maj.left(sl);
228 mimes.replace(k,(void*)1); 214 mimes.replace(k,(void*)1);
229 } 215 }
230 } 216 }
231 217
232 void setBackgroundOrigin( QWidget::BackgroundOrigin ) { 218 void setBackgroundOrigin( QWidget::BackgroundOrigin ) {
233 } 219 }
234 220
235 void setBackgroundPixmap( const QPixmap &pm ) { 221 void setBackgroundPixmap( const QPixmap &pm ) {
236 bgPixmap = pm; 222 bgPixmap = pm;
237 } 223 }
238 224
239 void setBackgroundColor( const QColor &c ) { 225 void setBackgroundColor( const QColor &c ) {
240 bgColor = c; 226 bgColor = c;
241 } 227 }
242 228
243 void drawBackground( QPainter *p, const QRect &r ) 229 void drawBackground( QPainter *p, const QRect &r )
244 { 230 {
245 if ( !bgPixmap.isNull() ) { 231 if ( !bgPixmap.isNull() ) {
246 p->drawTiledPixmap( r, bgPixmap, 232 p->drawTiledPixmap( r, bgPixmap,
247 QPoint( (r.x() + contentsX()) % bgPixmap.width(), 233 QPoint( (r.x() + contentsX()) % bgPixmap.width(),
248 (r.y() + contentsY()) % bgPixmap.height() ) ); 234 (r.y() + contentsY()) % bgPixmap.height() ) );
249 } else { 235 } else {
250 p->fillRect( r, bgColor ); 236 p->fillRect( r, bgColor );
251 } 237 }
252 } 238 }
253 239
254 void setItemTextPos( ItemTextPos pos ) 240 void setItemTextPos( ItemTextPos pos )
255 { 241 {
256 calculateGrid( pos ); 242 calculateGrid( pos );
257 QIconView::setItemTextPos( pos ); 243 QIconView::setItemTextPos( pos );
258 } 244 }
259 245
260 void hideOrShowItems(bool resort); 246 void hideOrShowItems(bool resort);
261 247
262 void setTypeFilter(const QString& typefilter, bool resort) 248 void setTypeFilter(const QString& typefilter, bool resort)
263 { 249 {
264 tf = QRegExp(typefilter,FALSE,TRUE); 250 tf = QRegExp(typefilter,FALSE,TRUE);
265 hideOrShowItems(resort); 251 hideOrShowItems(resort);
266 } 252 }
267 253
268 void setCategoryFilter( int catfilter, bool resort ) 254 void setCategoryFilter( int catfilter, bool resort )
269 { 255 {
270 Categories cat; 256 Categories cat;
271 cat.load( categoryFileName() ); 257 cat.load( categoryFileName() );
272 QString str; 258 QString str;
273 if ( catfilter == -2 ) 259 if ( catfilter == -2 )
274 cf = 0; 260 cf = 0;
275 else 261 else
276 cf = catfilter; 262 cf = catfilter;
277 hideOrShowItems(resort); 263 hideOrShowItems(resort);
278 } 264 }
279 265
280 enum SortMethod { Name, Date, Type }; 266 enum SortMethod { Name, Date, Type };
281 267
282 void setSortMethod( SortMethod m ) 268 void setSortMethod( SortMethod m )
283 { 269 {
284 if ( sortmeth != m ) { 270 if ( sortmeth != m ) {
285 sortmeth = m; 271 sortmeth = m;
286 sort(); 272 sort();
287 } 273 }
288 } 274 }
289 275
290 int compare(const AppLnk* a, const AppLnk* b) 276 int compare(const AppLnk* a, const AppLnk* b)
291 { 277 {
292 switch (sortmeth) { 278 switch (sortmeth) {
293 case Name: 279 case Name:
294 return a->name().lower().compare(b->name().lower()); 280 return a->name().lower().compare(b->name().lower());
295 case Date: { 281 case Date: {
296 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); 282 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file());
297 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); 283 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file());
298 return fa.lastModified().secsTo(fb.lastModified()); 284 return fa.lastModified().secsTo(fb.lastModified());
299 } 285 }
300 case Type: 286 case Type:
301 return a->type().compare(b->type()); 287 return a->type().compare(b->type());
302 } 288 }
303 return 0; 289 return 0;
304 } 290 }
305 291
306protected: 292protected:
307 293
308 void timerEvent( QTimerEvent *te ) 294 void timerEvent( QTimerEvent *te )
309 { 295 {
310 if ( te->timerId() == busyTimer ) { 296 if ( te->timerId() == busyTimer ) {
311 if ( bsy ) 297 if ( bsy )
312 bsy->animateIcon(); 298 bsy->animateIcon();
313 } else { 299 } else {
314 QIconView::timerEvent( te ); 300 QIconView::timerEvent( te );
315 } 301 }
316 } 302 }
317 303
318 void styleChange( QStyle &old ) 304 void styleChange( QStyle &old )
319 { 305 {
320 QIconView::styleChange( old ); 306 QIconView::styleChange( old );
321 calculateGrid( itemTextPos() ); 307 calculateGrid( itemTextPos() );
322 } 308 }
323 309
324 void calculateGrid( ItemTextPos pos ) 310 void calculateGrid( ItemTextPos pos )
325 { 311 {
326 int dw = QApplication::desktop()->width(); 312 int dw = QApplication::desktop()->width();
327 int viewerWidth = dw-style().scrollBarExtent().width(); 313 int viewerWidth = dw-style().scrollBarExtent().width();
328 if ( pos == Bottom ) { 314 if ( pos == Bottom ) {
329 int cols = 3; 315 int cols = 3;
330 if ( viewerWidth <= 200 ) 316 if ( viewerWidth <= 200 )
331 cols = 2; 317 cols = 2;
332 else if ( viewerWidth >= 400 ) 318 else if ( viewerWidth >= 400 )
333 cols = viewerWidth/96; 319 cols = viewerWidth/96;
334 setSpacing( 4 ); 320 setSpacing( 4 );
335 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 321 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
336 setGridY( fontMetrics().height()*2+24 ); 322 setGridY( fontMetrics().height()*2+24 );
337 } else { 323 } else {
338 int cols = 2; 324 int cols = 2;
339 if ( viewerWidth < 150 ) 325 if ( viewerWidth < 150 )
340 cols = 1; 326 cols = 1;
341 else if ( viewerWidth >= 400 ) 327 else if ( viewerWidth >= 400 )
342 cols = viewerWidth/150; 328 cols = viewerWidth/150;
343 setSpacing( 2 ); 329 setSpacing( 2 );
344 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 330 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
345 setGridY( fontMetrics().height()+2 ); 331 setGridY( fontMetrics().height()+2 );
346 } 332 }
347 } 333 }
348 334
349 void focusInEvent( QFocusEvent * ) {} 335 void focusInEvent( QFocusEvent * ) {}
350 void focusOutEvent( QFocusEvent * ) {} 336 void focusOutEvent( QFocusEvent * ) {}
351 337
352private: 338private:
353 QList<AppLnk> hidden; 339 QList<AppLnk> hidden;
354 QDict<void> mimes; 340 QDict<void> mimes;
355 QDict<void> cats; 341 QDict<void> cats;
356 SortMethod sortmeth; 342 SortMethod sortmeth;
357 QRegExp tf; 343 QRegExp tf;
358 int cf; 344 int cf;
359 LauncherItem* bsy; 345 LauncherItem* bsy;
360 int busyTimer; 346 int busyTimer;
361 bool ike; 347 bool ike;
362 bool bigIcns; 348 bool bigIcns;
363 QPixmap bgPixmap; 349 QPixmap bgPixmap;
364 QColor bgColor; 350 QColor bgColor;
365#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 351#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
366 QPixmap busyPix; 352 QPixmap busyPix;
367#endif 353#endif
368 BusyIndicatorType busyType; 354 BusyIndicatorType busyType;
369}; 355};
370 356
371 357
372bool LauncherView::bsy=FALSE; 358bool LauncherView::bsy=FALSE;
373 359
374void LauncherView::setBusy(bool on) 360void LauncherView::setBusy(bool on)
375{ 361{
376 icons->setBusy(on); 362 icons->setBusy(on);
377} 363}
378 364
379void LauncherView::setBusyIndicatorType( const QString& type ) { 365void LauncherView::setBusyIndicatorType( const QString& type ) {
380 if ( type. lower ( ) == "animated" ) 366 if ( type. lower ( ) == "animated" )
381 icons->setBusyIndicatorType( BIT_Animated ) ; 367 icons->setBusyIndicatorType( BIT_Animated ) ;
382 else 368 else
383 icons->setBusyIndicatorType( BIT_Normal ) ; 369 icons->setBusyIndicatorType( BIT_Normal ) ;
384} 370}
385 371
386LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) 372LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon )
387 : QIconViewItem( parent, applnk->name(), 373 : QIconViewItem( parent, applnk->name(),
388 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), 374 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ),
389 isBigIcon( bigIcon ), 375 isBigIcon( bigIcon ),
390 iteration(0), 376 iteration(0),
391 app(applnk) // Takes ownership 377 app(applnk) // Takes ownership
392{ 378{
393} 379}
394 380
395LauncherItem::~LauncherItem() 381LauncherItem::~LauncherItem()
396{ 382{
397 LauncherIconView* liv = (LauncherIconView*)iconView(); 383 LauncherIconView* liv = (LauncherIconView*)iconView();
398 if ( liv->busyItem() == this ) 384 if ( liv->busyItem() == this )
399 liv->setBusy(FALSE); 385 liv->setBusy(FALSE);
400 delete app; 386 delete app;
401} 387}
402 388
403int LauncherItem::compare ( QIconViewItem * i ) const 389int LauncherItem::compare ( QIconViewItem * i ) const
404{ 390{
405 LauncherIconView* view = (LauncherIconView*)iconView(); 391 LauncherIconView* view = (LauncherIconView*)iconView();
406 return view->compare(app,((LauncherItem *)i)->appLnk()); 392 return view->compare(app,((LauncherItem *)i)->appLnk());
407} 393}
408 394
409void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg ) 395void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg )
410{ 396{
411 LauncherIconView* liv = (LauncherIconView*)iconView(); 397 LauncherIconView* liv = (LauncherIconView*)iconView();
412 QBrush oldBrush( liv->itemTextBackground() ); 398 QBrush oldBrush( liv->itemTextBackground() );
413 QColorGroup mycg( cg ); 399 QColorGroup mycg( cg );
414 if ( liv->currentItem() == this ) { 400 if ( liv->currentItem() == this ) {
415 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); 401 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
416 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); 402 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
417 } 403 }
418 404
419 QIconViewItem::paintItem(p,mycg); 405 QIconViewItem::paintItem(p,mycg);
420 406
421 // Paint animation overlay 407 // Paint animation overlay
422 if ( liv->busyItem() == this ) 408 if ( liv->busyItem() == this )
423 paintAnimatedIcon(p); 409 paintAnimatedIcon(p);
424 410
425 if ( liv->currentItem() == this ) 411 if ( liv->currentItem() == this )
426 liv->setItemTextBackground( oldBrush ); 412 liv->setItemTextBackground( oldBrush );
427} 413}
428 414
429 415
430 416
431void LauncherItem::paintAnimatedIcon( QPainter *p ) 417void LauncherItem::paintAnimatedIcon( QPainter *p )
432{ 418{
433 LauncherIconView* liv = (LauncherIconView*)iconView(); 419 LauncherIconView* liv = (LauncherIconView*)iconView();
434 int pic = iteration % 16; 420 int pic = iteration % 16;
435 int w = pixmap()->width(), h = pixmap()->height(); 421 int w = pixmap()->width(), h = pixmap()->height();
436 QPixmap dblBuf( w, h + 4 ); 422 QPixmap dblBuf( w, h + 4 );
437 QPainter p2( &dblBuf ); 423 QPainter p2( &dblBuf );
438 int x1, y1; 424 int x1, y1;
439 if ( liv->itemTextPos() == QIconView::Bottom ) { 425 if ( liv->itemTextPos() == QIconView::Bottom ) {
440 x1 = x() + (width() - w) / 2 - liv->contentsX(); 426 x1 = x() + (width() - w) / 2 - liv->contentsX();
441 y1 = y() - liv->contentsY(); 427 y1 = y() - liv->contentsY();
442 } else { 428 } else {
443 x1 = x() - liv->contentsX(); 429 x1 = x() - liv->contentsX();
444 y1 = y() + (height() - h) / 2 - liv->contentsY(); 430 y1 = y() + (height() - h) / 2 - liv->contentsY();
445 } 431 }
446 y1 -= 2; 432 y1 -= 2;
447 p2.translate(-x1,-y1); 433 p2.translate(-x1,-y1);
448 liv->drawBackground( &p2, QRect(x1,y1,w,h+4) ); 434 liv->drawBackground( &p2, QRect(x1,y1,w,h+4) );
449 int bounceY = 2; 435 int bounceY = 2;
450#ifdef BOUNCE_BUSY_ICON 436#ifdef BOUNCE_BUSY_ICON
451 if ( busyType == BIT_Animated ) { 437 if ( busyType == BIT_Animated ) {
452 bounceY = 4 - ((iteration+2)%8); 438 bounceY = 4 - ((iteration+2)%8);
453 bounceY = bounceY < 0 ? -bounceY : bounceY; 439 bounceY = bounceY < 0 ? -bounceY : bounceY;
454 } 440 }
455#endif 441#endif
456 p2.drawPixmap( x1, y1 + bounceY, *pixmap() ); 442 p2.drawPixmap( x1, y1 + bounceY, *pixmap() );
457#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY 443#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
458 p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h ); 444 p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h );
459#endif 445#endif
460 p->drawPixmap( x1, y1, dblBuf ); 446 p->drawPixmap( x1, y1, dblBuf );
461} 447}
462 448
463void LauncherItem::animateIcon() 449void LauncherItem::animateIcon()
464{ 450{
465 LauncherIconView* liv = (LauncherIconView*)iconView(); 451 LauncherIconView* liv = (LauncherIconView*)iconView();
466 452
467 if ( liv->busyItem() != this || !app ) 453 if ( liv->busyItem() != this || !app )
468 return; 454 return;
469 455
470 // Highlight the icon 456 // Highlight the icon
471 if ( iteration == 0 ) { 457 if ( iteration == 0 ) {
472 QPixmap src = isBigIcon ? app->bigPixmap() : app->pixmap(); 458 QPixmap src = isBigIcon ? app->bigPixmap() : app->pixmap();
473 QImage img = src.convertToImage(); 459 QImage img = src.convertToImage();
474 QRgb *rgb; 460 QRgb *rgb;
475 int count; 461 int count;
476 if ( img.depth() == 32 ) { 462 if ( img.depth() == 32 ) {
477 rgb = (QRgb*)img.bits(); 463 rgb = (QRgb*)img.bits();
478 count = img.bytesPerLine()/sizeof(QRgb)*img.height(); 464 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
479 } else { 465 } else {
480 rgb = img.colorTable(); 466 rgb = img.colorTable();
481 count = img.numColors(); 467 count = img.numColors();
482 } 468 }
483 for ( int r = 0; r < count; r++, rgb++ ) { 469 for ( int r = 0; r < count; r++, rgb++ ) {
484#if defined(BRIGHTEN_BUSY_ICON) 470#if defined(BRIGHTEN_BUSY_ICON)
485 QColor c(*rgb); 471 QColor c(*rgb);
486 int h, s, v; 472 int h, s, v;
487 c.hsv(&h,&s,&v); 473 c.hsv(&h,&s,&v);
488 c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255)); 474 c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255));
489 *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb)); 475 *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb));
490#elif defined(ALPHA_FADE_BUSY_ICON) 476#elif defined(ALPHA_FADE_BUSY_ICON)
491 *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2); 477 *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2);
492#endif 478#endif
493 } 479 }
494 src.convertFromImage( img ); 480 src.convertFromImage( img );
495 setPixmap( src ); 481 setPixmap( src );
496 } 482 }
497 483
498 iteration++; 484 iteration++;
499 485
500 // Paint animation overlay 486 // Paint animation overlay
501 QPainter p( liv->viewport() ); 487 QPainter p( liv->viewport() );
502 paintAnimatedIcon( &p ); 488 paintAnimatedIcon( &p );
503} 489}
504 490
505void LauncherItem::resetIcon() 491void LauncherItem::resetIcon()
506{ 492{
507 iteration = 0; 493 iteration = 0;
508 setPixmap( isBigIcon ? app->bigPixmap() : app->pixmap() ); 494 setPixmap( isBigIcon ? app->bigPixmap() : app->pixmap() );
509} 495}
510 496
511//=========================================================================== 497//===========================================================================
512 498
513QStringList LauncherIconView::mimeTypes() const 499QStringList LauncherIconView::mimeTypes() const
514{ 500{
515 QStringList r; 501 QStringList r;
516 QDictIterator<void> it(mimes); 502 QDictIterator<void> it(mimes);
517 while (it.current()) { 503 while (it.current()) {
518 r.append(it.currentKey()); 504 r.append(it.currentKey());
519 ++it; 505 ++it;
520 } 506 }
521 r.sort(); 507 r.sort();
522 return r; 508 return r;
523} 509}
524 510
525void LauncherIconView::addItem(AppLnk* app, bool resort) 511void LauncherIconView::addItem(AppLnk* app, bool resort)
526{ 512{
527 addCatsAndMimes(app); 513 addCatsAndMimes(app);
528 514
529 if ( (tf.isEmpty() || tf.match(app->type()) >= 0) 515 if ( (tf.isEmpty() || tf.match(app->type()) >= 0)
530 && (cf == 0 || app->categories().contains(cf) 516 && (cf == 0 || app->categories().contains(cf)
531 || cf == -1 && app->categories().count() == 0 ) ) 517 || cf == -1 && app->categories().count() == 0 ) )
532 (void) new LauncherItem( this, app, bigIcns ); 518 (void) new LauncherItem( this, app, bigIcns );
533 else 519 else
534 hidden.append(app); 520 hidden.append(app);
535 if ( resort ) 521 if ( resort )
536 sort(); 522 sort();
537} 523}
538 524
539void LauncherIconView::updateCategoriesAndMimeTypes() 525void LauncherIconView::updateCategoriesAndMimeTypes()
540{ 526{
541 mimes.clear(); 527 mimes.clear();
542 cats.clear(); 528 cats.clear();
543 LauncherItem* item = (LauncherItem*)firstItem(); 529 LauncherItem* item = (LauncherItem*)firstItem();
544 while (item) { 530 while (item) {
545 addCatsAndMimes(item->appLnk()); 531 addCatsAndMimes(item->appLnk());
546 item = (LauncherItem*)item->nextItem(); 532 item = (LauncherItem*)item->nextItem();
547 } 533 }
548 QListIterator<AppLnk> it(hidden); 534 QListIterator<AppLnk> it(hidden);
549 AppLnk* l; 535 AppLnk* l;
550 while ((l=it.current())) { 536 while ((l=it.current())) {
551 addCatsAndMimes(l); 537 addCatsAndMimes(l);
552 ++it; 538 ++it;
553 } 539 }
554} 540}
555 541
556void LauncherIconView::hideOrShowItems(bool resort) 542void LauncherIconView::hideOrShowItems(bool resort)
557{ 543{
558 viewport()->setUpdatesEnabled( FALSE ); 544 viewport()->setUpdatesEnabled( FALSE );
559 hidden.setAutoDelete(FALSE); 545 hidden.setAutoDelete(FALSE);
560 QList<AppLnk> links=hidden; 546 QList<AppLnk> links=hidden;
561 hidden.clear(); 547 hidden.clear();
562 hidden.setAutoDelete(TRUE); 548 hidden.setAutoDelete(TRUE);
563 LauncherItem* item = (LauncherItem*)firstItem(); 549 LauncherItem* item = (LauncherItem*)firstItem();
564 while (item) { 550 while (item) {
565 links.append(item->takeAppLnk()); 551 links.append(item->takeAppLnk());
566 item = (LauncherItem*)item->nextItem(); 552 item = (LauncherItem*)item->nextItem();
567 } 553 }
568 clear(); 554 clear();
569 QListIterator<AppLnk> it(links); 555 QListIterator<AppLnk> it(links);
570 AppLnk* l; 556 AppLnk* l;
571 while ((l=it.current())) { 557 while ((l=it.current())) {
572 addItem(l,FALSE); 558 addItem(l,FALSE);
573 ++it; 559 ++it;
574 } 560 }
575 if ( resort && !autoArrange() ) 561 if ( resort && !autoArrange() )
576 sort(); 562 sort();
577 viewport()->setUpdatesEnabled( TRUE ); 563 viewport()->setUpdatesEnabled( TRUE );
578} 564}
579 565
580bool LauncherIconView::removeLink(const QString& linkfile) 566bool LauncherIconView::removeLink(const QString& linkfile)
581{ 567{
582 LauncherItem* item = (LauncherItem*)firstItem(); 568 LauncherItem* item = (LauncherItem*)firstItem();
583 AppLnk* l; 569 AppLnk* l;
584 bool did = FALSE; 570 bool did = FALSE;
585 DocLnk dl(linkfile); 571 DocLnk dl(linkfile);
586 while (item) { 572 while (item) {
587 l = item->appLnk(); 573 l = item->appLnk();
588 LauncherItem *nextItem = (LauncherItem *)item->nextItem(); 574 LauncherItem *nextItem = (LauncherItem *)item->nextItem();
589 if ( l->linkFileKnown() && l->linkFile() == linkfile 575 if ( l->linkFileKnown() && l->linkFile() == linkfile
590 || l->fileKnown() && ( 576 || l->fileKnown() && (
591 l->file() == linkfile 577 l->file() == linkfile
592 || dl.isValid() && dl.file() == l->file() ) ) { 578 || dl.isValid() && dl.file() == l->file() ) ) {
593 delete item; 579 delete item;
594 did = TRUE; 580 did = TRUE;
595 } 581 }
596 item = nextItem; 582 item = nextItem;
597 } 583 }
598 QListIterator<AppLnk> it(hidden); 584 QListIterator<AppLnk> it(hidden);
599 while ((l=it.current())) { 585 while ((l=it.current())) {
600 ++it; 586 ++it;
601 if ( l->linkFileKnown() && l->linkFile() == linkfile 587 if ( l->linkFileKnown() && l->linkFile() == linkfile
602 || l->file() == linkfile 588 || l->file() == linkfile
603 || dl.isValid() && dl.file() == l->file() ) { 589 || dl.isValid() && dl.file() == l->file() ) {
604 hidden.removeRef(l); 590 hidden.removeRef(l);
605 did = TRUE; 591 did = TRUE;
606 } 592 }
607 } 593 }
608 return did; 594 return did;
609} 595}
610 596
611//=========================================================================== 597//===========================================================================
612 598
613LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) 599LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl )
614 : QVBox( parent, name, fl ) 600 : QVBox( parent, name, fl )
615{ 601{
616 catmb = 0; 602 catmb = 0;
617 icons = new LauncherIconView( this ); 603 icons = new LauncherIconView( this );
618 setFocusProxy(icons); 604 setFocusProxy(icons);
619 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); 605 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold );
620 606
621 icons->setItemsMovable( FALSE ); 607 icons->setItemsMovable( FALSE );
622 icons->setAutoArrange( TRUE ); 608 icons->setAutoArrange( TRUE );
623 icons->setSorting( TRUE ); 609 icons->setSorting( TRUE );
624 icons->setFrameStyle( QFrame::NoFrame ); 610 icons->setFrameStyle( QFrame::NoFrame );
625 icons->setMargin( 0 ); 611 icons->setMargin( 0 );
626 icons->setSelectionMode( QIconView::NoSelection ); 612 icons->setSelectionMode( QIconView::NoSelection );
627 icons->setBackgroundMode( PaletteBase ); 613 icons->setBackgroundMode( PaletteBase );
628 icons->setResizeMode( QIconView::Fixed ); 614 icons->setResizeMode( QIconView::Fixed );
629 vmode = (ViewMode)-1; 615 vmode = (ViewMode)-1;
630 setViewMode( Icon ); 616 setViewMode( Icon );
631 617
632 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), 618 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)),
633 SLOT(itemClicked(int, QIconViewItem *)) ); 619 SLOT(itemClicked(int, QIconViewItem *)) );
634 connect( icons, SIGNAL(selectionChanged()), 620 connect( icons, SIGNAL(selectionChanged()),
635 SLOT(selectionChanged()) ); 621 SLOT(selectionChanged()) );
636 connect( icons, SIGNAL(returnPressed(QIconViewItem *)), 622 connect( icons, SIGNAL(returnPressed(QIconViewItem *)),
637 SLOT(returnPressed(QIconViewItem *)) ); 623 SLOT(returnPressed(QIconViewItem *)) );
638 connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), 624 connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)),
639 SLOT(itemPressed(int, QIconViewItem *)) ); 625 SLOT(itemPressed(int, QIconViewItem *)) );
640 626
641 tools = 0; 627 tools = 0;
642 setBackgroundType( Ruled, QString::null ); 628 setBackgroundType( Ruled, QString::null );
643} 629}
644 630
645LauncherView::~LauncherView() 631LauncherView::~LauncherView()
646{ 632{
647 if ( bgCache && bgCache->contains( bgName ) ) 633 if ( bgCache && bgCache->contains( bgName ) )
648 (*bgCache)[bgName]->ref--; 634 (*bgCache)[bgName]->ref--;
649} 635}
650 636
651void LauncherView::hideIcons() 637void LauncherView::hideIcons()
652{ 638{
653 icons->hide(); 639 icons->hide();
654} 640}
655 641
656void LauncherView::setToolsEnabled(bool y) 642void LauncherView::setToolsEnabled(bool y)
657{ 643{
658 if ( !y != !tools ) { 644 if ( !y != !tools ) {
659 if ( y ) { 645 if ( y ) {
660 tools = new QHBox(this); 646 tools = new QHBox(this);
661 647
662 // Type filter 648 // Type filter
663 typemb = new QComboBox(tools); 649 typemb = new QComboBox(tools);
664 QSizePolicy p = typemb->sizePolicy(); 650 QSizePolicy p = typemb->sizePolicy();
665 p.setHorData(QSizePolicy::Expanding); 651 p.setHorData(QSizePolicy::Expanding);
666 typemb->setSizePolicy(p); 652 typemb->setSizePolicy(p);
667 653
668 // Category filter 654 // Category filter
669 updateTools(); 655 updateTools();
670 tools->show(); 656 tools->show();
671 657
672 // Always show vscrollbar 658 // Always show vscrollbar
673 icons->setVScrollBarMode( QScrollView::AlwaysOn ); 659 icons->setVScrollBarMode( QScrollView::AlwaysOn );
674 } else { 660 } else {
675 delete tools; 661 delete tools;
676 tools = 0; 662 tools = 0;
677 } 663 }
678 } 664 }
679} 665}
680 666
681void LauncherView::updateTools() 667void LauncherView::updateTools()
682{ 668{
683 disconnect( typemb, SIGNAL(activated(int)), 669 disconnect( typemb, SIGNAL(activated(int)),
684 this, SLOT(showType(int)) ); 670 this, SLOT(showType(int)) );
685 if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)), 671 if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)),
686 this, SLOT(showCategory(int)) ); 672 this, SLOT(showCategory(int)) );
687 673
688 // ### I want to remove this 674 // ### I want to remove this
689 icons->updateCategoriesAndMimeTypes(); 675 icons->updateCategoriesAndMimeTypes();
690 676
691 QString prev; 677 QString prev;
692 678
693 // Type filter 679 // Type filter
694 QStringList types; 680 QStringList types;
695 typelist = icons->mimeTypes(); 681 typelist = icons->mimeTypes();
696 for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { 682 for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) {
697 QString t = *it; 683 QString t = *it;
698 if ( t.left(12) == "application/" ) { 684 if ( t.left(12) == "application/" ) {
699 MimeType mt(t); 685 MimeType mt(t);
700 const AppLnk* app = mt.application(); 686 const AppLnk* app = mt.application();
701 if ( app ) 687 if ( app )
702 t = app->name(); 688 t = app->name();
703 else 689 else
704 t = t.mid(12); 690 t = t.mid(12);
705 } else { 691 } else {
706 t[0] = t[0].upper(); 692 t[0] = t[0].upper();
707 } 693 }
708 types += t; 694 types += t;
709 } 695 }
710 types << tr("All types"); 696 types << tr("All types");
711 prev = typemb->currentText(); 697 prev = typemb->currentText();
712 typemb->clear(); 698 typemb->clear();
713 typemb->insertStringList(types); 699 typemb->insertStringList(types);
714 for (int i=0; i<typemb->count(); i++) { 700 for (int i=0; i<typemb->count(); i++) {
715 if ( typemb->text(i) == prev ) { 701 if ( typemb->text(i) == prev ) {
716 typemb->setCurrentItem(i); 702 typemb->setCurrentItem(i);
717 break; 703 break;
718 } 704 }
719 } 705 }
720 if ( prev.isNull() ) 706 if ( prev.isNull() )
721 typemb->setCurrentItem(typemb->count()-1); 707 typemb->setCurrentItem(typemb->count()-1);
722 708
723 int pcat = catmb ? catmb->currentCategory() : -2; 709 int pcat = catmb ? catmb->currentCategory() : -2;
724 if ( !catmb ) 710 if ( !catmb )
725 catmb = new CategorySelect(tools); 711 catmb = new CategorySelect(tools);
726 Categories cats( 0 ); 712 Categories cats( 0 );
727 cats.load( categoryFileName() ); 713 cats.load( categoryFileName() );
728 QArray<int> vl( 0 ); 714 QArray<int> vl( 0 );
729 catmb->setCategories( vl, "Document View", // No tr 715 catmb->setCategories( vl, "Document View", // No tr
730 tr("Document View") ); 716 tr("Document View") );
731 catmb->setRemoveCategoryEdit( TRUE ); 717 catmb->setRemoveCategoryEdit( TRUE );
732 catmb->setAllCategories( TRUE ); 718 catmb->setAllCategories( TRUE );
733 catmb->setCurrentCategory(pcat); 719 catmb->setCurrentCategory(pcat);
734 720
735 // if type has changed we need to redisplay 721 // if type has changed we need to redisplay
736 if ( typemb->currentText() != prev ) 722 if ( typemb->currentText() != prev )
737 showType( typemb->currentItem() ); 723 showType( typemb->currentItem() );
738 724
739 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); 725 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int)));
740 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); 726 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));
741} 727}
742 728
743void LauncherView::sortBy(int s) 729void LauncherView::sortBy(int s)
744{ 730{
745 icons->setSortMethod((LauncherIconView::SortMethod)s); 731 icons->setSortMethod((LauncherIconView::SortMethod)s);
746} 732}
747 733
748void LauncherView::showType(int t) 734void LauncherView::showType(int t)
749{ 735{
750 if ( t >= (int)typelist.count() ) { 736 if ( t >= (int)typelist.count() ) {
751 icons->setTypeFilter("",TRUE); 737 icons->setTypeFilter("",TRUE);
752 } else { 738 } else {
753 QString ty = typelist[t]; 739 QString ty = typelist[t];
754 if ( !ty.contains('/') ) 740 if ( !ty.contains('/') )
755 ty += "/*"; 741 ty += "/*";
756 icons->setTypeFilter(ty,TRUE); 742 icons->setTypeFilter(ty,TRUE);
757 } 743 }
758} 744}
759 745
760void LauncherView::showCategory( int c ) 746void LauncherView::showCategory( int c )
761{ 747{
762 icons->setCategoryFilter( c, TRUE ); 748 icons->setCategoryFilter( c, TRUE );
763} 749}
764 750
765void LauncherView::setViewMode( ViewMode m ) 751void LauncherView::setViewMode( ViewMode m )
766{ 752{
767 if ( vmode != m ) { 753 if ( vmode != m ) {
768 bool bigIcons = m == Icon; 754 bool bigIcons = m == Icon;
769 icons->viewport()->setUpdatesEnabled( FALSE ); 755 icons->viewport()->setUpdatesEnabled( FALSE );
770 icons->setBigIcons( bigIcons ); 756 icons->setBigIcons( bigIcons );
771 switch ( m ) { 757 switch ( m ) {
772 case List: 758 case List:
773 icons->setItemTextPos( QIconView::Right ); 759 icons->setItemTextPos( QIconView::Right );
774 break; 760 break;
775 case Icon: 761 case Icon:
776 icons->setItemTextPos( QIconView::Bottom ); 762 icons->setItemTextPos( QIconView::Bottom );
777 break; 763 break;
778 } 764 }
779 icons->hideOrShowItems( FALSE ); 765 icons->hideOrShowItems( FALSE );
780 icons->viewport()->setUpdatesEnabled( TRUE ); 766 icons->viewport()->setUpdatesEnabled( TRUE );
781 vmode = m; 767 vmode = m;
782 } 768 }
783} 769}
784 770
785// 771//
786// User images may require scaling. 772// User images may require scaling.
787// 773//
788QImage LauncherView::loadBackgroundImage(QString &bgName) 774QImage LauncherView::loadBackgroundImage(QString &bgName)
789{ 775{
790 QImageIO imgio; 776 QImageIO imgio;
791 QSize ds = qApp->desktop()->size(); // should be launcher, not desktop 777 QSize ds = qApp->desktop()->size(); // should be launcher, not desktop
792 bool further_scaling = TRUE; 778 bool further_scaling = TRUE;
793 779
794 imgio.setFileName( bgName ); 780 imgio.setFileName( bgName );
795 imgio.setParameters("GetHeaderInformation"); 781 imgio.setParameters("GetHeaderInformation");
796 782
797 if (imgio.read() == FALSE) { 783 if (imgio.read() == FALSE) {
798 return imgio.image(); 784 return imgio.image();
799 } 785 }
800 786
801 if (imgio.image().width() < ds.width() && 787 if (imgio.image().width() < ds.width() &&
802 imgio.image().height() < ds.height()) { 788 imgio.image().height() < ds.height()) {
803 further_scaling = FALSE; 789 further_scaling = FALSE;
804 } 790 }
805 791
806 if (!imgio.image().bits()) { 792 if (!imgio.image().bits()) {
807 // 793 //
808 // Scale and load. Note we don't scale up. 794 // Scale and load. Note we don't scale up.
809 // 795 //
810 QString param( "Scale( %1, %2, ScaleMin )" ); // No tr 796 QString param( "Scale( %1, %2, ScaleMin )" ); // No tr
811 imgio.setParameters(further_scaling ? 797 imgio.setParameters(further_scaling ?
812 param.arg(ds.width()).arg(ds.height()).latin1() : 798 param.arg(ds.width()).arg(ds.height()).latin1() :
813 ""); 799 "");
814 imgio.read(); 800 imgio.read();
815 } else { 801 } else {
816 if (further_scaling) { 802 if (further_scaling) {
817 intt1 = imgio.image().width() * ds.height(); 803 intt1 = imgio.image().width() * ds.height();
818 int t2 = imgio.image().height() * ds.width(); 804 int t2 = imgio.image().height() * ds.width();
819 int dsth = ds.height(); 805 int dsth = ds.height();
820 int dstw = ds.width(); 806 int dstw = ds.width();
821 807
822 if (t1 > t2) { 808 if (t1 > t2) {
823 dsth = t2 / imgio.image().width(); 809 dsth = t2 / imgio.image().width();
824 } else { 810 } else {
825 dstw = t1 / imgio.image().height(); 811 dstw = t1 / imgio.image().height();
826 } 812 }
827 813
828 // 814 //
829 // Loader didn't scale for us. Do it manually. 815 // Loader didn't scale for us. Do it manually.
830 // 816 //
831 return imgio.image().smoothScale(dstw, dsth); 817 return imgio.image().smoothScale(dstw, dsth);
832 } 818 }
833 } 819 }
834 820
835 return imgio.image(); 821 return imgio.image();
836} 822}
837 823
838void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) 824void LauncherView::setBackgroundType( BackgroundType t, const QString &val )
839{ 825{
840 if ( !bgCache ) { 826 if ( !bgCache ) {
841 bgCache = new QMap<QString,BgPixmap*>; 827 bgCache = new QMap<QString,BgPixmap*>;
842 qAddPostRoutine( cleanup_cache ); 828 qAddPostRoutine( cleanup_cache );
843 } 829 }
844 830
845 if ( bgCache->contains( bgName ) ) 831 if ( bgCache->contains( bgName ) )
846 (*bgCache)[bgName]->ref--; 832 (*bgCache)[bgName]->ref--;
847 bgName = ""; 833 bgName = "";
848 834
849 QPixmap bg; 835 QPixmap bg;
850 836
851 switch ( t ) { 837 switch ( t ) {
852 case Ruled: { 838 case Ruled: {
853 bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr 839 bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr
854 if ( bgCache->contains( bgName ) ) { 840 if ( bgCache->contains( bgName ) ) {
855 (*bgCache)[bgName]->ref++; 841 (*bgCache)[bgName]->ref++;
856 bg = (*bgCache)[bgName]->pm; 842 bg = (*bgCache)[bgName]->pm;
857 } else { 843 } else {
858 bg.resize( width(), 9 ); 844 bg.resize( width(), 9 );
859 QPainter painter( &bg ); 845 QPainter painter( &bg );
860 for ( int i = 0; i < 3; i++ ) { 846 for ( int i = 0; i < 3; i++ ) {
861 painter.setPen( white ); 847 painter.setPen( white );
862 painter.drawLine( 0, i*3, width()-1, i*3 ); 848 painter.drawLine( 0, i*3, width()-1, i*3 );
863 painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); 849 painter.drawLine( 0, i*3+1, width()-1, i*3+1 );
864 painter.setPen( colorGroup().background().light(105) ); 850 painter.setPen( colorGroup().background().light(105) );
865 painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); 851 painter.drawLine( 0, i*3+2, width()-1, i*3+2 );
866 } 852 }
867 painter.end(); 853 painter.end();
868 bgCache->insert( bgName, new BgPixmap(bg) ); 854 bgCache->insert( bgName, new BgPixmap(bg) );
869 } 855 }
870 break; 856 break;
871 } 857 }
872 858
873 case Image: 859 case Image:
874 if (!val.isEmpty()) { 860 if (!val.isEmpty()) {
875 bgName = val; 861 bgName = val;
876 if ( bgCache->contains( bgName ) ) { 862 if ( bgCache->contains( bgName ) ) {
877 (*bgCache)[bgName]->ref++; 863 (*bgCache)[bgName]->ref++;
878 bg = (*bgCache)[bgName]->pm; 864 bg = (*bgCache)[bgName]->pm;
879 } else { 865 } else {
880 QString imgFile = bgName; 866 QString imgFile = bgName;
881 bool tile = FALSE; 867 bool tile = FALSE;
882 if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) { 868 if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) {
883 imgFile = Resource::findPixmap( imgFile ); 869 imgFile = Resource::findPixmap( imgFile );
884 tile = TRUE; 870 tile = TRUE;
885 } 871 }
886 QImage img = loadBackgroundImage(imgFile); 872 QImage img = loadBackgroundImage(imgFile);
887 873
888 874
889 if ( img.depth() == 1 ) 875 if ( img.depth() == 1 )
890 img = img.convertDepth(8); 876 img = img.convertDepth(8);
891 img.setAlphaBuffer(FALSE); 877 img.setAlphaBuffer(FALSE);
892 bg.convertFromImage(img); 878 bg.convertFromImage(img);
893 bgCache->insert( bgName, new BgPixmap(bg) ); 879 bgCache->insert( bgName, new BgPixmap(bg) );
894 } 880 }
895 } 881 }
896 break; 882 break;
897 883
898 case SolidColor: 884 case SolidColor:
899 default: 885 default:
900 break; 886 break;
901 } 887 }
902 888
903 const QObjectList *list = queryList( "QWidget", 0, FALSE ); 889 const QObjectList *list = queryList( "QWidget", 0, FALSE );
904 QObject *obj; 890 QObject *obj;
905 for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) { 891 for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) {
906 if ( obj->isWidgetType() ) { 892 if ( obj->isWidgetType() ) {
907 QWidget *w = (QWidget*)obj; 893 QWidget *w = (QWidget*)obj;
908 w->setBackgroundPixmap( bg ); 894 w->setBackgroundPixmap( bg );
909 if ( bgName.isEmpty() ) { 895 if ( bgName.isEmpty() ) {
910 // Solid Color 896 // Solid Color
911 if ( val.isEmpty() ) 897 if ( val.isEmpty() )
912 w->setBackgroundColor( colorGroup().base() ); 898 w->setBackgroundColor( colorGroup().base() );
913 else 899 else
914 w->setBackgroundColor( val ); 900 w->setBackgroundColor( val );
915 } else { 901 } else {
916 // Ruled or Image pixmap 902 // Ruled or Image pixmap
917 w->setBackgroundOrigin( ParentOrigin ); 903 w->setBackgroundOrigin( ParentOrigin );
918 } 904 }
919 } 905 }
920 } 906 }
921 delete list; 907 delete list;
922 908
923 bgType = t; 909 bgType = t;
924 icons->viewport()->update(); 910 icons->viewport()->update();
925 911
926 QTimer::singleShot( 1000, this, SLOT(flushBgCache()) ); 912 QTimer::singleShot( 1000, this, SLOT(flushBgCache()) );
927} 913}
928 914
929void LauncherView::setTextColor( const QColor &tc ) 915void LauncherView::setTextColor( const QColor &tc )
930{ 916{
931 textCol = tc; 917 textCol = tc;
932 QColorGroup cg = icons->colorGroup(); 918 QColorGroup cg = icons->colorGroup();
933 cg.setColor( QColorGroup::Text, tc ); 919 cg.setColor( QColorGroup::Text, tc );
934 icons->setPalette( QPalette(cg,cg,cg) ); 920 icons->setPalette( QPalette(cg,cg,cg) );
935 icons->viewport()->update(); 921 icons->viewport()->update();
936} 922}
937 923
938void LauncherView::setViewFont( const QFont &f ) 924void LauncherView::setViewFont( const QFont &f )
939{ 925{
940 icons->setFont( f ); 926 icons->setFont( f );
941 icons->hideOrShowItems( FALSE ); 927 icons->hideOrShowItems( FALSE );
942} 928}
943 929
944void LauncherView::clearViewFont() 930void LauncherView::clearViewFont()
945{ 931{
946 icons->unsetFont(); 932 icons->unsetFont();
947 icons->hideOrShowItems( FALSE ); 933 icons->hideOrShowItems( FALSE );
948} 934}
949 935
950void LauncherView::resizeEvent(QResizeEvent *e) 936void LauncherView::resizeEvent(QResizeEvent *e)
951{ 937{
952 QVBox::resizeEvent( e ); 938 QVBox::resizeEvent( e );
953 if ( e->size().width() != e->oldSize().width() ) 939 if ( e->size().width() != e->oldSize().width() )
954 sort(); 940 sort();
955} 941}
956 942
957void LauncherView::selectionChanged() 943void LauncherView::selectionChanged()
958{ 944{
959 QIconViewItem* item = icons->currentItem(); 945 QIconViewItem* item = icons->currentItem();
960 if ( item && item->isSelected() ) { 946 if ( item && item->isSelected() ) {
961 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 947 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
962 if ( icons->inKeyEvent() ) // not for mouse press 948 if ( icons->inKeyEvent() ) // not for mouse press
963 emit clicked( appLnk ); 949 emit clicked( appLnk );
964 item->setSelected(FALSE); 950 item->setSelected(FALSE);
965 } 951 }
966} 952}
967 953
968void LauncherView::returnPressed( QIconViewItem *item ) 954void LauncherView::returnPressed( QIconViewItem *item )
969{ 955{
970 if ( item ) { 956 if ( item ) {
971 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 957 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
972 emit clicked( appLnk ); 958 emit clicked( appLnk );
973 } 959 }
974} 960}
975 961
976void LauncherView::itemClicked( int btn, QIconViewItem *item ) 962void LauncherView::itemClicked( int btn, QIconViewItem *item )
977{ 963{
978 if ( item ) { 964 if ( item ) {
979 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 965 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
980 if ( btn == LeftButton ) { 966 if ( btn == LeftButton ) {
981 // Make sure it's the item we execute that gets highlighted 967 // Make sure it's the item we execute that gets highlighted
982 icons->setCurrentItem( item ); 968 icons->setCurrentItem( item );
983 emit clicked( appLnk ); 969 emit clicked( appLnk );
984 } 970 }
985 item->setSelected(FALSE); 971 item->setSelected(FALSE);
986 } 972 }
987} 973}
988 974
989void LauncherView::itemPressed( int btn, QIconViewItem *item ) 975void LauncherView::itemPressed( int btn, QIconViewItem *item )
990{ 976{
991 if ( item ) { 977 if ( item ) {
992 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 978 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
993 if ( btn == RightButton ) 979 if ( btn == RightButton )
994 emit rightPressed( appLnk ); 980 emit rightPressed( appLnk );
995 else if ( btn == ShiftButton ) 981 else if ( btn == ShiftButton )
996 emit rightPressed( appLnk ); 982 emit rightPressed( appLnk );
997 item->setSelected(FALSE); 983 item->setSelected(FALSE);
998 } 984 }
999} 985}
1000 986
1001void LauncherView::removeAllItems() 987void LauncherView::removeAllItems()
1002{ 988{
1003 icons->clear(); 989 icons->clear();
1004} 990}
1005 991
1006bool LauncherView::removeLink(const QString& linkfile) 992bool LauncherView::removeLink(const QString& linkfile)
1007{ 993{
1008 return icons->removeLink(linkfile); 994 return icons->removeLink(linkfile);
1009} 995}
1010 996
1011void LauncherView::setSortEnabled( bool v ) 997void LauncherView::setSortEnabled( bool v )
1012{ 998{
1013 icons->setSorting( v ); 999 icons->setSorting( v );
1014 if ( v ) 1000 if ( v )
1015 sort(); 1001 sort();
1016} 1002}
1017 1003
1018void LauncherView::setUpdatesEnabled( bool u ) 1004void LauncherView::setUpdatesEnabled( bool u )
1019{ 1005{
1020 icons->setUpdatesEnabled( u ); 1006 icons->setUpdatesEnabled( u );
1021} 1007}
1022 1008
1023void LauncherView::sort() 1009void LauncherView::sort()
1024{ 1010{
1025 icons->sort(); 1011 icons->sort();
1026} 1012}
1027 1013
1028void LauncherView::addItem(AppLnk* app, bool resort) 1014void LauncherView::addItem(AppLnk* app, bool resort)
1029{ 1015{
1030 icons->addItem(app,resort); 1016 icons->addItem(app,resort);
1031} 1017}
1032 1018
1033void LauncherView::paletteChange( const QPalette &p ) 1019void LauncherView::paletteChange( const QPalette &p )
1034{ 1020{
1035 icons->unsetPalette(); 1021 icons->unsetPalette();
1036 QVBox::paletteChange( p ); 1022 QVBox::paletteChange( p );
1037 if ( bgType == Ruled ) 1023 if ( bgType == Ruled )
1038 setBackgroundType( Ruled, QString::null ); 1024 setBackgroundType( Ruled, QString::null );
1039 QColorGroup cg = icons->colorGroup(); 1025 QColorGroup cg = icons->colorGroup();
1040 cg.setColor( QColorGroup::Text, textCol ); 1026 cg.setColor( QColorGroup::Text, textCol );
1041 icons->setPalette( QPalette(cg,cg,cg) ); 1027 icons->setPalette( QPalette(cg,cg,cg) );
1042} 1028}
1043 1029
1044void LauncherView::fontChanged(const QFont&) 1030void LauncherView::fontChanged(const QFont&)
1045{ 1031{
1046 qDebug("LauncherView::fontChanged()"); 1032 qDebug("LauncherView::fontChanged()");
1047 icons->hideOrShowItems( FALSE ); 1033 icons->hideOrShowItems( FALSE );
1048} 1034}
1049 1035
1050void LauncherView::relayout(void) 1036void LauncherView::relayout(void)
1051{ 1037{
1052 icons->hideOrShowItems(FALSE); 1038 icons->hideOrShowItems(FALSE);
1053} 1039}
1054 1040
1055void LauncherView::flushBgCache() 1041void LauncherView::flushBgCache()
1056{ 1042{
1057 if ( !bgCache ) 1043 if ( !bgCache )
1058 return; 1044 return;
1059 // remove unreferenced backgrounds. 1045 // remove unreferenced backgrounds.
1060 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); 1046 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
1061 while ( it != bgCache->end() ) { 1047 while ( it != bgCache->end() ) {
1062 QMap<QString,BgPixmap*>::Iterator curr = it; 1048 QMap<QString,BgPixmap*>::Iterator curr = it;
1063 ++it; 1049 ++it;
1064 if ( (*curr)->ref == 0 ) { 1050 if ( (*curr)->ref == 0 ) {
1065 delete (*curr); 1051 delete (*curr);
1066 bgCache->remove( curr ); 1052 bgCache->remove( curr );
1067 } 1053 }
1068 } 1054 }
1069} 1055}
1070 1056
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
index 9e53bb0..c136bd9 100644
--- a/core/launcher/main.cpp
+++ b/core/launcher/main.cpp
@@ -1,357 +1,352 @@
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#ifndef QTOPIA_INTERNAL_FILEOPERATIONS 21#ifndef QTOPIA_INTERNAL_FILEOPERATIONS
22#define QTOPIA_INTERNAL_FILEOPERATIONS 22#define QTOPIA_INTERNAL_FILEOPERATIONS
23#endif 23#endif
24#include "server.h" 24#include "server.h"
25#include "serverapp.h" 25#include "serverapp.h"
26#include "taskbar.h"
27#include "stabmon.h" 26#include "stabmon.h"
28#include "launcher.h"
29#include "firstuse.h" 27#include "firstuse.h"
30 28
31#include <opie2/oglobal.h> 29#include <opie2/oglobal.h>
32 30
33#include <qtopia/qpeapplication.h>
34#include <qtopia/network.h> 31#include <qtopia/network.h>
35#include <qtopia/config.h>
36//#include <qtopia/custom.h> 32//#include <qtopia/custom.h>
37 33
38 34
39#include <qfile.h>
40#include <qdir.h> 35#include <qdir.h>
41#ifdef QWS 36#ifdef QWS
42#include <qwindowsystem_qws.h> 37#include <qwindowsystem_qws.h>
43#include <qtopia/qcopenvelope_qws.h> 38#include <qtopia/qcopenvelope_qws.h>
44#endif 39#endif
45#include <qtopia/alarmserver.h> 40#include <qtopia/alarmserver.h>
46 41
47#include <stdlib.h> 42#include <stdlib.h>
48#include <stdio.h> 43#include <stdio.h>
49#include <signal.h> 44#include <signal.h>
50#ifndef Q_OS_WIN32 45#ifndef Q_OS_WIN32
51#include <unistd.h> 46#include <unistd.h>
52#else 47#else
53#include <process.h> 48#include <process.h>
54#endif 49#endif
55 50
56#include "calibrate.h" 51#include "calibrate.h"
57 52
58 53
59#ifdef QT_QWS_LOGIN 54#ifdef QT_QWS_LOGIN
60#include "../login/qdmdialogimpl.h" 55#include "../login/qdmdialogimpl.h"
61#endif 56#endif
62 57
63#ifdef Q_WS_QWS 58#ifdef Q_WS_QWS
64#include <qkeyboard_qws.h> 59#include <qkeyboard_qws.h>
65#endif 60#endif
66 61
67#include <qmessagebox.h> 62#include <qmessagebox.h>
68#include <opie2/odevice.h> 63#include <opie2/odevice.h>
69 64
70using namespace Opie; 65using namespace Opie;
71 66
72 67
73static void cleanup() 68static void cleanup()
74{ 69{
75 QDir dir( "/tmp", "qcop-msg-*" ); 70 QDir dir( "/tmp", "qcop-msg-*" );
76 71
77 QStringList stale = dir.entryList(); 72 QStringList stale = dir.entryList();
78 QStringList::Iterator it; 73 QStringList::Iterator it;
79 for ( it = stale.begin(); it != stale.end(); ++it ) { 74 for ( it = stale.begin(); it != stale.end(); ++it ) {
80 dir.remove( *it ); 75 dir.remove( *it );
81 } 76 }
82} 77}
83 78
84static void refreshTimeZoneConfig() 79static void refreshTimeZoneConfig()
85{ 80{
86 /* ### FIXME timezone handling */ 81 /* ### FIXME timezone handling */
87#if 0 82#if 0
88 // We need to help WorldTime in setting up its configuration for 83 // We need to help WorldTime in setting up its configuration for
89 // the current translation 84 // the current translation
90 // BEGIN no tr 85 // BEGIN no tr
91 const char *defaultTz[] = { 86 const char *defaultTz[] = {
92 "America/New_York", 87 "America/New_York",
93 "America/Los_Angeles", 88 "America/Los_Angeles",
94 "Europe/Oslo", 89 "Europe/Oslo",
95 "Asia/Tokyo", 90 "Asia/Tokyo",
96 "Asia/Hong_Kong", 91 "Asia/Hong_Kong",
97 "Australia/Brisbane", 92 "Australia/Brisbane",
98 0 93 0
99 }; 94 };
100 // END no tr 95 // END no tr
101 96
102 TimeZone curZone; 97 TimeZone curZone;
103 QString zoneID; 98 QString zoneID;
104 int zoneIndex; 99 int zoneIndex;
105 Config cfg = Config( "WorldTime" ); 100 Config cfg = Config( "WorldTime" );
106 cfg.setGroup( "TimeZones" ); 101 cfg.setGroup( "TimeZones" );
107 if (!cfg.hasKey( "Zone0" )){ 102 if (!cfg.hasKey( "Zone0" )){
108 // We have no existing timezones use the defaults which are untranslated strings 103 // We have no existing timezones use the defaults which are untranslated strings
109 QString currTz = TimeZone::current().id(); 104 QString currTz = TimeZone::current().id();
110 QStringList zoneDefaults; 105 QStringList zoneDefaults;
111 zoneDefaults.append( currTz ); 106 zoneDefaults.append( currTz );
112 for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) { 107 for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) {
113 if ( defaultTz[i] != currTz ) 108 if ( defaultTz[i] != currTz )
114 zoneDefaults.append( defaultTz[i] ); 109 zoneDefaults.append( defaultTz[i] );
115 } 110 }
116 zoneIndex = 0; 111 zoneIndex = 0;
117 for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){ 112 for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){
118 cfg.writeEntry( "Zone" + QString::number( zoneIndex ) , *it); 113 cfg.writeEntry( "Zone" + QString::number( zoneIndex ) , *it);
119 zoneIndex++; 114 zoneIndex++;
120 } 115 }
121 } 116 }
122 // We have an existing list of timezones refresh the 117 // We have an existing list of timezones refresh the
123 // translations of TimeZone name 118 // translations of TimeZone name
124 zoneIndex = 0; 119 zoneIndex = 0;
125 while (cfg.hasKey( "Zone"+ QString::number( zoneIndex ))){ 120 while (cfg.hasKey( "Zone"+ QString::number( zoneIndex ))){
126 zoneID = cfg.readEntry( "Zone" + QString::number( zoneIndex )); 121 zoneID = cfg.readEntry( "Zone" + QString::number( zoneIndex ));
127 curZone = TimeZone( zoneID ); 122 curZone = TimeZone( zoneID );
128 if ( !curZone.isValid() ){ 123 if ( !curZone.isValid() ){
129 qDebug( "initEnvironment() Invalid TimeZone %s", zoneID.latin1() ); 124 qDebug( "initEnvironment() Invalid TimeZone %s", zoneID.latin1() );
130 break; 125 break;
131 } 126 }
132 cfg.writeEntry( "ZoneName" + QString::number( zoneIndex ), curZone.city() ); 127 cfg.writeEntry( "ZoneName" + QString::number( zoneIndex ), curZone.city() );
133 zoneIndex++; 128 zoneIndex++;
134 } 129 }
135#endif 130#endif
136} 131}
137 132
138void initEnvironment() 133void initEnvironment()
139{ 134{
140#ifdef Q_OS_WIN32 135#ifdef Q_OS_WIN32
141 // Config file requires HOME dir which uses QDir which needs the winver 136 // Config file requires HOME dir which uses QDir which needs the winver
142 qt_init_winver(); 137 qt_init_winver();
143#endif 138#endif
144 Config config("locale"); 139 Config config("locale");
145 config.setGroup( "Location" ); 140 config.setGroup( "Location" );
146 QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace(); 141 QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace();
147 142
148 // if not timezone set, pick New York 143 // if not timezone set, pick New York
149 if (tz.isNull() || tz.isEmpty()) 144 if (tz.isNull() || tz.isEmpty())
150 tz = "America/New_York"; 145 tz = "America/New_York";
151 146
152 setenv( "TZ", tz, 1 ); 147 setenv( "TZ", tz, 1 );
153 config.writeEntry( "Timezone", tz); 148 config.writeEntry( "Timezone", tz);
154 149
155 config.setGroup( "Language" ); 150 config.setGroup( "Language" );
156 QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace(); 151 QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace();
157 if( lang.isNull() || lang.isEmpty()) 152 if( lang.isNull() || lang.isEmpty())
158 lang = "en_US"; 153 lang = "en_US";
159 154
160 setenv( "LANG", lang, 1 ); 155 setenv( "LANG", lang, 1 );
161 config.writeEntry("Language", lang); 156 config.writeEntry("Language", lang);
162 config.write(); 157 config.write();
163 158
164#if 0 159#if 0
165 setenv( "QWS_SIZE", "240x320", 0 ); 160 setenv( "QWS_SIZE", "240x320", 0 );
166#endif 161#endif
167 162
168 163
169 164
170 QString env(getenv("QWS_DISPLAY")); 165 QString env(getenv("QWS_DISPLAY"));
171 if (env.contains("Transformed")) { 166 if (env.contains("Transformed")) {
172 int rot; 167 int rot;
173 // transformed driver default rotation is controlled by the hardware. 168 // transformed driver default rotation is controlled by the hardware.
174 Config config("qpe"); 169 Config config("qpe");
175 config.setGroup( "Rotation" ); 170 config.setGroup( "Rotation" );
176 if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 ) 171 if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 )
177 rot = ODevice::inst ( )-> rotation ( ) * 90; 172 rot = ODevice::inst ( )-> rotation ( ) * 90;
178 173
179 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); 174 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
180 QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */ 175 QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */
181 } 176 }
182} 177}
183 178
184static void initKeyboard() 179static void initKeyboard()
185{ 180{
186 Config config("qpe"); 181 Config config("qpe");
187 182
188 config.setGroup( "Keyboard" ); 183 config.setGroup( "Keyboard" );
189 184
190 int ard = config.readNumEntry( "RepeatDelay" ); 185 int ard = config.readNumEntry( "RepeatDelay" );
191 int arp = config.readNumEntry( "RepeatPeriod" ); 186 int arp = config.readNumEntry( "RepeatPeriod" );
192 if ( ard > 0 && arp > 0 ) 187 if ( ard > 0 && arp > 0 )
193 qwsSetKeyboardAutoRepeat( ard, arp ); 188 qwsSetKeyboardAutoRepeat( ard, arp );
194 189
195 QString layout = config.readEntry( "Layout", "us101" ); 190 QString layout = config.readEntry( "Layout", "us101" );
196 Server::setKeyboardLayout( layout ); 191 Server::setKeyboardLayout( layout );
197} 192}
198 193
199static bool firstUse() 194static bool firstUse()
200{ 195{
201 bool needFirstUse = FALSE; 196 bool needFirstUse = FALSE;
202 if ( QWSServer::mouseHandler() && 197 if ( QWSServer::mouseHandler() &&
203 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { 198 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) {
204 if ( !QFile::exists( "/etc/pointercal" ) ) 199 if ( !QFile::exists( "/etc/pointercal" ) )
205 needFirstUse = TRUE; 200 needFirstUse = TRUE;
206 } 201 }
207 202
208 { 203 {
209 Config config( "qpe" ); 204 Config config( "qpe" );
210 config.setGroup( "Startup" ); 205 config.setGroup( "Startup" );
211 needFirstUse |= config.readBoolEntry( "FirstUse", TRUE ); 206 needFirstUse |= config.readBoolEntry( "FirstUse", TRUE );
212 } 207 }
213 208
214 if ( !needFirstUse ) 209 if ( !needFirstUse )
215 return FALSE; 210 return FALSE;
216 211
217 FirstUse *fu = new FirstUse(); 212 FirstUse *fu = new FirstUse();
218 fu->exec(); 213 fu->exec();
219 bool rs = fu->restartNeeded(); 214 bool rs = fu->restartNeeded();
220 delete fu; 215 delete fu;
221 return rs; 216 return rs;
222} 217}
223 218
224int initApplication( int argc, char ** argv ) 219int initApplication( int argc, char ** argv )
225{ 220{
226 cleanup(); 221 cleanup();
227 222
228 223
229 initEnvironment(); 224 initEnvironment();
230 225
231 //Don't flicker at startup: 226 //Don't flicker at startup:
232#ifdef QWS 227#ifdef QWS
233 QWSServer::setDesktopBackground( QImage() ); 228 QWSServer::setDesktopBackground( QImage() );
234#endif 229#endif
235 ServerApplication a( argc, argv, QApplication::GuiServer ); 230 ServerApplication a( argc, argv, QApplication::GuiServer );
236 231
237 refreshTimeZoneConfig(); 232 refreshTimeZoneConfig();
238 233
239 initKeyboard(); 234 initKeyboard();
240 235
241 // Don't use first use under Windows 236 // Don't use first use under Windows
242 if ( firstUse() ) { 237 if ( firstUse() ) {
243 a.restart(); 238 a.restart();
244 return 0; 239 return 0;
245 } 240 }
246 241
247 ODevice::inst ( )-> setSoftSuspend ( true ); 242 ODevice::inst ( )-> setSoftSuspend ( true );
248 243
249 { 244 {
250 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 245 QCopEnvelope e("QPE/System", "setBacklight(int)" );
251 e << -3; // Forced on 246 e << -3; // Forced on
252 } 247 }
253 248
254 AlarmServer::initialize(); 249 AlarmServer::initialize();
255 250
256 251
257 252
258 Server *s = new Server(); 253 Server *s = new Server();
259 254
260 (void)new SysFileMonitor(s); 255 (void)new SysFileMonitor(s);
261#ifdef QWS 256#ifdef QWS
262 Network::createServer(s); 257 Network::createServer(s);
263#endif 258#endif
264 259
265 s->show(); 260 s->show();
266 261
267 /* THE ARM rtc has problem holdings the time on reset */ 262 /* THE ARM rtc has problem holdings the time on reset */
268 if ( QDate::currentDate ( ). year ( ) < 2000 ) { 263 if ( QDate::currentDate ( ). year ( ) < 2000 ) {
269 if ( QMessageBox::information ( 0, ServerApplication::tr( "Information" ), ServerApplication::tr( "<p>The system date doesn't seem to be valid.\n(%1)</p><p>Do you want to correct the clock ?</p>" ). arg( TimeString::dateString ( QDate::currentDate ( ))), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { 264 if ( QMessageBox::information ( 0, ServerApplication::tr( "Information" ), ServerApplication::tr( "<p>The system date doesn't seem to be valid.\n(%1)</p><p>Do you want to correct the clock ?</p>" ). arg( TimeString::dateString ( QDate::currentDate ( ))), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) {
270 QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" ); 265 QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" );
271 e << QString ( ); 266 e << QString ( );
272 } 267 }
273 } 268 }
274 269
275 int rv = a.exec(); 270 int rv = a.exec();
276 271
277 qDebug("exiting..."); 272 qDebug("exiting...");
278 delete s; 273 delete s;
279 274
280#ifndef Q_OS_MACX 275#ifndef Q_OS_MACX
281 ODevice::inst()->setSoftSuspend( false ); 276 ODevice::inst()->setSoftSuspend( false );
282#endif 277#endif
283 278
284 return rv; 279 return rv;
285} 280}
286 281
287static const char *pidfile_path = "/var/run/opie.pid"; 282static const char *pidfile_path = "/var/run/opie.pid";
288 283
289void create_pidfile ( ) 284void create_pidfile ( )
290{ 285{
291 FILE *f; 286 FILE *f;
292 287
293 if (( f = ::fopen ( pidfile_path, "w" ))) { 288 if (( f = ::fopen ( pidfile_path, "w" ))) {
294 ::fprintf ( f, "%d", getpid ( )); 289 ::fprintf ( f, "%d", getpid ( ));
295 ::fclose ( f ); 290 ::fclose ( f );
296 } 291 }
297} 292}
298 293
299void remove_pidfile ( ) 294void remove_pidfile ( )
300{ 295{
301 ::unlink ( pidfile_path ); 296 ::unlink ( pidfile_path );
302} 297}
303 298
304void handle_sigterm ( int /* sig */ ) 299void handle_sigterm ( int /* sig */ )
305{ 300{
306 if ( qApp ) 301 if ( qApp )
307 qApp-> quit ( ); 302 qApp-> quit ( );
308} 303}
309 304
310#ifndef Q_OS_WIN32 305#ifndef Q_OS_WIN32
311int main( int argc, char ** argv ) 306int main( int argc, char ** argv )
312{ 307{
313 308
314 ::signal ( SIGCHLD, SIG_IGN ); 309 ::signal ( SIGCHLD, SIG_IGN );
315 310
316 ::signal ( SIGTERM, handle_sigterm ); 311 ::signal ( SIGTERM, handle_sigterm );
317 ::signal ( SIGINT, handle_sigterm ); 312 ::signal ( SIGINT, handle_sigterm );
318 313
319 ::setsid ( ); 314 ::setsid ( );
320 ::setpgid ( 0, 0 ); 315 ::setpgid ( 0, 0 );
321 316
322 ::atexit ( remove_pidfile ); 317 ::atexit ( remove_pidfile );
323 create_pidfile ( ); 318 create_pidfile ( );
324 319
325 int retVal = initApplication( argc, argv ); 320 int retVal = initApplication( argc, argv );
326 321
327 // Have we been asked to restart? 322 // Have we been asked to restart?
328 if ( ServerApplication::doRestart ) { 323 if ( ServerApplication::doRestart ) {
329 for ( int fd = 3; fd < 100; fd++ ) 324 for ( int fd = 3; fd < 100; fd++ )
330 close( fd ); 325 close( fd );
331 326
332 execl( (QPEApplication::qpeDir()+"bin/qpe").latin1(), "qpe", 0 ); 327 execl( (QPEApplication::qpeDir()+"bin/qpe").latin1(), "qpe", 0 );
333 } 328 }
334 329
335 // Kill them. Kill them all. 330 // Kill them. Kill them all.
336 ::kill ( 0, SIGTERM ); 331 ::kill ( 0, SIGTERM );
337 ::sleep ( 1 ); 332 ::sleep ( 1 );
338 ::kill ( 0, SIGKILL ); 333 ::kill ( 0, SIGKILL );
339 334
340 return retVal; 335 return retVal;
341} 336}
342#else 337#else
343 338
344int main( int argc, char ** argv ) 339int main( int argc, char ** argv )
345{ 340{
346 int retVal = initApplication( argc, argv ); 341 int retVal = initApplication( argc, argv );
347 342
348 if ( DesktopApplication::doRestart ) { 343 if ( DesktopApplication::doRestart ) {
349 qDebug("Trying to restart"); 344 qDebug("Trying to restart");
350 execl( (QPEApplication::qpeDir()+"bin\\qpe").latin1(), "qpe", 0 ); 345 execl( (QPEApplication::qpeDir()+"bin\\qpe").latin1(), "qpe", 0 );
351 } 346 }
352 347
353 return retVal; 348 return retVal;
354} 349}
355 350
356#endif 351#endif
357 352
diff --git a/core/launcher/packageslave.cpp b/core/launcher/packageslave.cpp
index bf34368..321b5dd 100644
--- a/core/launcher/packageslave.cpp
+++ b/core/launcher/packageslave.cpp
@@ -1,341 +1,339 @@
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 "packageslave.h" 21#include "packageslave.h"
22#include <qtopia/qprocess.h> 22#include <qtopia/qprocess.h>
23 23
24#ifdef Q_WS_QWS 24#ifdef Q_WS_QWS
25#include <qtopia/qcopenvelope_qws.h> 25#include <qtopia/qcopenvelope_qws.h>
26#endif 26#endif
27 27
28#include <qdatastream.h>
29#ifdef Q_WS_QWS 28#ifdef Q_WS_QWS
30#include <qcopchannel_qws.h> 29#include <qcopchannel_qws.h>
31#endif 30#endif
32 31
33#include <qtextstream.h> 32#include <qtextstream.h>
34#include <qdir.h>
35 33
36#include <stdlib.h> 34#include <stdlib.h>
37#include <sys/stat.h> // mkdir() 35#include <sys/stat.h> // mkdir()
38 36
39#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 37#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
40#include <unistd.h> 38#include <unistd.h>
41#include <sys/vfs.h> 39#include <sys/vfs.h>
42#include <mntent.h> 40#include <mntent.h>
43#elif defined(Q_OS_WIN32) 41#elif defined(Q_OS_WIN32)
44#include <windows.h> 42#include <windows.h>
45#include <winbase.h> 43#include <winbase.h>
46#elif defined(Q_OS_MACX) 44#elif defined(Q_OS_MACX)
47#include <unistd.h> 45#include <unistd.h>
48#endif 46#endif
49 47
50 48
51PackageHandler::PackageHandler( QObject *parent, char* name ) 49PackageHandler::PackageHandler( QObject *parent, char* name )
52 : QObject( parent, name ), packageChannel( 0 ), currentProcess( 0 ), mNoSpaceLeft( FALSE ) 50 : QObject( parent, name ), packageChannel( 0 ), currentProcess( 0 ), mNoSpaceLeft( FALSE )
53{ 51{
54 // setup qcop channel 52 // setup qcop channel
55#ifndef QT_NO_COP 53#ifndef QT_NO_COP
56 packageChannel = new QCopChannel( "QPE/Package", this ); 54 packageChannel = new QCopChannel( "QPE/Package", this );
57 connect( packageChannel, SIGNAL( received(const QCString &, const QByteArray &) ), 55 connect( packageChannel, SIGNAL( received(const QCString &, const QByteArray &) ),
58 this, SLOT( qcopMessage( const QCString &, const QByteArray &) ) ); 56 this, SLOT( qcopMessage( const QCString &, const QByteArray &) ) );
59#endif 57#endif
60} 58}
61 59
62void PackageHandler::qcopMessage( const QCString &msg, const QByteArray &data ) 60void PackageHandler::qcopMessage( const QCString &msg, const QByteArray &data )
63{ 61{
64 QDataStream stream( data, IO_ReadOnly ); 62 QDataStream stream( data, IO_ReadOnly );
65 63
66 if ( msg == "installPackage(QString)" ) { 64 if ( msg == "installPackage(QString)" ) {
67 QString file; 65 QString file;
68 stream >> file; 66 stream >> file;
69 installPackage( file ); 67 installPackage( file );
70 } else if ( msg == "removePackage(QString)" ) { 68 } else if ( msg == "removePackage(QString)" ) {
71 QString file; 69 QString file;
72 stream >> file; 70 stream >> file;
73 removePackage( file ); 71 removePackage( file );
74 } else if ( msg == "addPackageFiles(QString,QString)" ) { 72 } else if ( msg == "addPackageFiles(QString,QString)" ) {
75 QString location, listfile; 73 QString location, listfile;
76 stream >> location >> listfile; 74 stream >> location >> listfile;
77 addPackageFiles( location, listfile); 75 addPackageFiles( location, listfile);
78 } else if ( msg == "addPackages(QString)" ) { 76 } else if ( msg == "addPackages(QString)" ) {
79 QString location; 77 QString location;
80 stream >> location; 78 stream >> location;
81 addPackages( location ); 79 addPackages( location );
82 } else if ( msg == "cleanupPackageFiles(QString)" ) { 80 } else if ( msg == "cleanupPackageFiles(QString)" ) {
83 QString listfile; 81 QString listfile;
84 stream >> listfile; 82 stream >> listfile;
85 cleanupPackageFiles( listfile ); 83 cleanupPackageFiles( listfile );
86 } else if ( msg == "cleanupPackages(QString)" ) { 84 } else if ( msg == "cleanupPackages(QString)" ) {
87 QString location; 85 QString location;
88 stream >> location; 86 stream >> location;
89 cleanupPackages( location ); 87 cleanupPackages( location );
90 } else if ( msg == "prepareInstall(QString,QString)" ) { 88 } else if ( msg == "prepareInstall(QString,QString)" ) {
91 QString size, path; 89 QString size, path;
92 stream >> size; 90 stream >> size;
93 stream >> path; 91 stream >> path;
94 prepareInstall( size, path ); 92 prepareInstall( size, path );
95 } 93 }
96} 94}
97 95
98void PackageHandler::installPackage( const QString &package ) 96void PackageHandler::installPackage( const QString &package )
99{ 97{
100 if ( mNoSpaceLeft ) { 98 if ( mNoSpaceLeft ) {
101 mNoSpaceLeft = FALSE; 99 mNoSpaceLeft = FALSE;
102 // Don't emit that for now, I still couldn't test it (Wener) 100 // Don't emit that for now, I still couldn't test it (Wener)
103 //sendReply( "installFailed(QString)", package ); 101 //sendReply( "installFailed(QString)", package );
104 //return; 102 //return;
105 } 103 }
106 104
107 currentProcess = new QProcess( QStringList() << "ipkg" << "install" << package ); // No tr 105 currentProcess = new QProcess( QStringList() << "ipkg" << "install" << package ); // No tr
108 connect( currentProcess, SIGNAL( processExited() ), SLOT( iProcessExited() ) ); 106 connect( currentProcess, SIGNAL( processExited() ), SLOT( iProcessExited() ) );
109 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); 107 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) );
110 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); 108 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) );
111 currentPackage = package; 109 currentPackage = package;
112 110
113 currentProcessError=""; 111 currentProcessError="";
114 sendReply( "installStarted(QString)", package ); 112 sendReply( "installStarted(QString)", package );
115 currentProcess->start(); 113 currentProcess->start();
116} 114}
117 115
118void PackageHandler::removePackage( const QString &package ) 116void PackageHandler::removePackage( const QString &package )
119{ 117{
120 currentProcess = new QProcess( QStringList() << "ipkg" << "remove" << package ); // No tr 118 currentProcess = new QProcess( QStringList() << "ipkg" << "remove" << package ); // No tr
121 connect( currentProcess, SIGNAL( processExited() ), SLOT( rmProcessExited() ) ); 119 connect( currentProcess, SIGNAL( processExited() ), SLOT( rmProcessExited() ) );
122 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); 120 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) );
123 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); 121 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) );
124 currentPackage = package; 122 currentPackage = package;
125 123
126 currentProcessError=""; 124 currentProcessError="";
127 sendReply( "removeStarted(QString)", package ); 125 sendReply( "removeStarted(QString)", package );
128 currentProcess->start(); 126 currentProcess->start();
129} 127}
130 128
131void PackageHandler::sendReply( const QCString& msg, const QString& arg ) 129void PackageHandler::sendReply( const QCString& msg, const QString& arg )
132{ 130{
133#ifndef QT_NO_COP 131#ifndef QT_NO_COP
134 QCopEnvelope e( "QPE/Desktop", msg ); 132 QCopEnvelope e( "QPE/Desktop", msg );
135 e << arg; 133 e << arg;
136#endif 134#endif
137} 135}
138 136
139void PackageHandler::addPackageFiles( const QString &location, 137void PackageHandler::addPackageFiles( const QString &location,
140 const QString &listfile ) 138 const QString &listfile )
141{ 139{
142 QFile f(listfile); 140 QFile f(listfile);
143#ifndef Q_OS_WIN32 141#ifndef Q_OS_WIN32
144 //make a copy so we can remove the symlinks later 142 //make a copy so we can remove the symlinks later
145 mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 ); 143 mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 );
146 system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); 144 system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii());
147#else 145#else
148 QDir d; 146 QDir d;
149 //#### revise 147 //#### revise
150 qDebug("Copy file at %s: %s", __FILE__, __LINE__ ); 148 qDebug("Copy file at %s: %s", __FILE__, __LINE__ );
151 d.mkdir(("/usr/lib/ipkg/info/" + location).ascii()); 149 d.mkdir(("/usr/lib/ipkg/info/" + location).ascii());
152 system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); 150 system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii());
153#endif 151#endif
154 152
155 153
156 if ( f.open(IO_ReadOnly) ) { 154 if ( f.open(IO_ReadOnly) ) {
157 QTextStream ts(&f); 155 QTextStream ts(&f);
158 156
159 QString s; 157 QString s;
160 while ( !ts.eof() ) { // until end of file... 158 while ( !ts.eof() ) { // until end of file...
161 s = ts.readLine(); // line of text excluding '\n' 159 s = ts.readLine(); // line of text excluding '\n'
162 // for s, do link/mkdir. 160 // for s, do link/mkdir.
163 if ( s.right(1) == "/" ) { 161 if ( s.right(1) == "/" ) {
164 qDebug("do mkdir for %s", s.ascii()); 162 qDebug("do mkdir for %s", s.ascii());
165#ifndef Q_OS_WIN32 163#ifndef Q_OS_WIN32
166 mkdir( s.ascii(), 0777 ); 164 mkdir( s.ascii(), 0777 );
167 //possible optimization: symlink directories 165 //possible optimization: symlink directories
168 //that don't exist already. -- Risky. 166 //that don't exist already. -- Risky.
169#else 167#else
170 d.mkdir( s.ascii()); 168 d.mkdir( s.ascii());
171#endif 169#endif
172 170
173 } else { 171 } else {
174#ifndef Q_OS_WIN32 172#ifndef Q_OS_WIN32
175 qDebug("do symlink for %s", s.ascii()); 173 qDebug("do symlink for %s", s.ascii());
176 symlink( (location + s).ascii(), s.ascii() ); 174 symlink( (location + s).ascii(), s.ascii() );
177#else 175#else
178 qDebug("Copy file instead of a symlink for WIN32"); 176 qDebug("Copy file instead of a symlink for WIN32");
179 if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE)) 177 if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE))
180 qWarning("Unable to create symlinkfor %s", 178 qWarning("Unable to create symlinkfor %s",
181 (location + s).ascii()); 179 (location + s).ascii());
182#endif 180#endif
183 } 181 }
184 } 182 }
185 f.close(); 183 f.close();
186 } 184 }
187} 185}
188 186
189void PackageHandler::addPackages( const QString &location ) 187void PackageHandler::addPackages( const QString &location )
190{ 188{
191 // get list of *.list in location/usr/lib/ipkg/info/*.list 189 // get list of *.list in location/usr/lib/ipkg/info/*.list
192 QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr 190 QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr
193 QDir::Name, QDir::Files); 191 QDir::Name, QDir::Files);
194 if ( !dir.exists() ) 192 if ( !dir.exists() )
195 return; 193 return;
196 194
197 QStringList packages = dir.entryList(); 195 QStringList packages = dir.entryList();
198 for ( QStringList::Iterator it = packages.begin(); 196 for ( QStringList::Iterator it = packages.begin();
199 it != packages.end(); ++it ) { 197 it != packages.end(); ++it ) {
200 addPackageFiles( location, *it ); 198 addPackageFiles( location, *it );
201 } 199 }
202} 200}
203 201
204 202
205void PackageHandler::cleanupPackageFiles( const QString &listfile ) 203void PackageHandler::cleanupPackageFiles( const QString &listfile )
206{ 204{
207 QFile f(listfile); 205 QFile f(listfile);
208 206
209 if ( f.open(IO_ReadOnly) ) { 207 if ( f.open(IO_ReadOnly) ) {
210 QTextStream ts(&f); 208 QTextStream ts(&f);
211 209
212 QString s; 210 QString s;
213 while ( !ts.eof() ) { // until end of file... 211 while ( !ts.eof() ) { // until end of file...
214 s = ts.readLine(); // line of text excluding '\n' 212 s = ts.readLine(); // line of text excluding '\n'
215 // for s, do link/mkdir. 213 // for s, do link/mkdir.
216 if ( s.right(1) == "/" ) { 214 if ( s.right(1) == "/" ) {
217 //should rmdir if empty, after all files have been removed 215 //should rmdir if empty, after all files have been removed
218 } else { 216 } else {
219#ifndef Q_OS_WIN32 217#ifndef Q_OS_WIN32
220 qDebug("remove symlink for %s", s.ascii()); 218 qDebug("remove symlink for %s", s.ascii());
221 //check if it is a symlink first (don't remove /etc/passwd...) 219 //check if it is a symlink first (don't remove /etc/passwd...)
222 char buf[10]; //we don't care about the contents 220 char buf[10]; //we don't care about the contents
223 if ( ::readlink( s.ascii(),buf, 10 >= 0 ) ) 221 if ( ::readlink( s.ascii(),buf, 10 >= 0 ) )
224 ::unlink( s.ascii() ); 222 ::unlink( s.ascii() );
225 #else 223 #else
226 // ### revise 224 // ### revise
227 qWarning("Unable to remove symlink %s:%s", __FILE__, __LINE__); 225 qWarning("Unable to remove symlink %s:%s", __FILE__, __LINE__);
228#endif 226#endif
229 } 227 }
230 } 228 }
231 f.close(); 229 f.close();
232 230
233 //remove the list file 231 //remove the list file
234 ::unlink( listfile.ascii() ); 232 ::unlink( listfile.ascii() );
235 233
236 } 234 }
237} 235}
238 236
239void PackageHandler::cleanupPackages( const QString &location ) 237void PackageHandler::cleanupPackages( const QString &location )
240{ 238{
241 // get list of *.list in location/usr/lib/ipkg/info/*.list 239 // get list of *.list in location/usr/lib/ipkg/info/*.list
242 QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr 240 QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr
243 QDir::Name, QDir::Files); 241 QDir::Name, QDir::Files);
244 if ( !dir.exists() ) 242 if ( !dir.exists() )
245 return; 243 return;
246 244
247 QStringList packages = dir.entryList(); 245 QStringList packages = dir.entryList();
248 for ( QStringList::Iterator it = packages.begin(); 246 for ( QStringList::Iterator it = packages.begin();
249 it != packages.end(); ++it ) { 247 it != packages.end(); ++it ) {
250 cleanupPackageFiles( *it ); 248 cleanupPackageFiles( *it );
251 } 249 }
252 250
253 //remove the backup directory 251 //remove the backup directory
254 //### 252 //###
255} 253}
256 254
257void PackageHandler::prepareInstall( const QString& size, const QString& path ) 255void PackageHandler::prepareInstall( const QString& size, const QString& path )
258{ 256{
259 // Check whether there will be enough space to install the next package. 257 // Check whether there will be enough space to install the next package.
260 bool ok; 258 bool ok;
261 unsigned int s = size.toUInt( &ok ); 259 unsigned int s = size.toUInt( &ok );
262 260
263 if ( !ok ) 261 if ( !ok )
264 return; 262 return;
265 263
266 // Shamelessly stolen from the sysinfo application (Werner) 264 // Shamelessly stolen from the sysinfo application (Werner)
267#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 265#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
268 struct statfs fs; 266 struct statfs fs;
269 if ( statfs( path.latin1(), &fs ) == 0 ) 267 if ( statfs( path.latin1(), &fs ) == 0 )
270 if ( s > fs.f_bsize * fs.f_bavail ) { 268 if ( s > fs.f_bsize * fs.f_bavail ) {
271 //qDebug("############### Not enough space left ###############"); 269 //qDebug("############### Not enough space left ###############");
272 mNoSpaceLeft = TRUE; 270 mNoSpaceLeft = TRUE;
273 } 271 }
274#endif 272#endif
275} 273}
276 274
277void PackageHandler::iProcessExited() 275void PackageHandler::iProcessExited()
278{ 276{
279 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) 277 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 )
280 sendReply( "installDone(QString)", currentPackage ); 278 sendReply( "installDone(QString)", currentPackage );
281 else { 279 else {
282#ifndef QT_NO_COP 280#ifndef QT_NO_COP
283 QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" ); 281 QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" );
284 e << currentPackage << currentProcess->exitStatus() 282 e << currentPackage << currentProcess->exitStatus()
285 << currentProcessError; 283 << currentProcessError;
286#endif 284#endif
287 } 285 }
288 286
289 delete currentProcess; 287 delete currentProcess;
290 currentProcess = 0; 288 currentProcess = 0;
291 289
292#ifndef QT_NO_COP 290#ifndef QT_NO_COP
293 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 291 QCopEnvelope e("QPE/System", "linkChanged(QString)");
294 QString lf = QString::null; 292 QString lf = QString::null;
295 e << lf; 293 e << lf;
296#endif 294#endif
297 unlink( currentPackage ); 295 unlink( currentPackage );
298} 296}
299 297
300void PackageHandler::rmProcessExited() 298void PackageHandler::rmProcessExited()
301{ 299{
302 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) 300 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 )
303 sendReply( "removeDone(QString)", currentPackage ); 301 sendReply( "removeDone(QString)", currentPackage );
304 else 302 else
305 sendReply( "removeFailed(QString)", currentPackage ); 303 sendReply( "removeFailed(QString)", currentPackage );
306 304
307#ifndef QT_NO_COP 305#ifndef QT_NO_COP
308 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 306 QCopEnvelope e("QPE/System", "linkChanged(QString)");
309 QString lf = QString::null; 307 QString lf = QString::null;
310 e << lf; 308 e << lf;
311#endif 309#endif
312} 310}
313 311
314void PackageHandler::readyReadStdout() 312void PackageHandler::readyReadStdout()
315{ 313{
316 while ( currentProcess->canReadLineStdout() ) { 314 while ( currentProcess->canReadLineStdout() ) {
317 QString line = currentProcess->readLineStdout(); 315 QString line = currentProcess->readLineStdout();
318 currentProcessError.append("OUT:"+line); 316 currentProcessError.append("OUT:"+line);
319 if ( line.contains( "Unpacking" ) ) // No tr 317 if ( line.contains( "Unpacking" ) ) // No tr
320 sendReply( "installStep(QString)", "one" ); // No tr 318 sendReply( "installStep(QString)", "one" ); // No tr
321 else if ( line.contains( "Configuring" ) ) // No tr 319 else if ( line.contains( "Configuring" ) ) // No tr
322 sendReply( "installStep(QString)", "two" ); // No tr 320 sendReply( "installStep(QString)", "two" ); // No tr
323 } 321 }
324} 322}
325 323
326void PackageHandler::readyReadStderr() 324void PackageHandler::readyReadStderr()
327{ 325{
328 while ( currentProcess->canReadLineStderr() ) { 326 while ( currentProcess->canReadLineStderr() ) {
329 QString line = currentProcess->readLineStderr(); 327 QString line = currentProcess->readLineStderr();
330 currentProcessError.append("ERR:"+line); 328 currentProcessError.append("ERR:"+line);
331 } 329 }
332} 330}
333 331
334void PackageHandler::redoPackages() 332void PackageHandler::redoPackages()
335{ 333{
336 //get list of filesystems 334 //get list of filesystems
337 335
338 //call cleanupPackages for the ones that have disappeared 336 //call cleanupPackages for the ones that have disappeared
339 337
340 //call addPackageFiles for the new ones 338 //call addPackageFiles for the new ones
341} 339}
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 9bca360..24f471d 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,498 +1,490 @@
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#include <opie2/oglobal.h> 24#include <opie2/oglobal.h>
25 25
26#ifdef Q_WS_QWS 26#ifdef Q_WS_QWS
27#include <qtopia/qcopenvelope_qws.h> 27#include <qtopia/qcopenvelope_qws.h>
28#endif 28#endif
29#include <qtopia/qpeapplication.h> 29#include <qtopia/qpeapplication.h>
30 30
31#include <qtopia/version.h> 31#include <qtopia/version.h>
32#include <qtopia/config.h>
33 32
34#include <qdir.h>
35#include <qfile.h>
36#include <qtextstream.h> 33#include <qtextstream.h>
37#include <qdatastream.h>
38#include <qcstring.h>
39#include <qstringlist.h>
40#include <qfileinfo.h>
41#include <qregexp.h>
42#include <qtimer.h> 34#include <qtimer.h>
43#ifdef Q_WS_QWS 35#ifdef Q_WS_QWS
44#include <qcopchannel_qws.h> 36#include <qcopchannel_qws.h>
45#endif 37#endif
46 38
47#ifndef _XOPEN_SOURCE 39#ifndef _XOPEN_SOURCE
48#define _XOPEN_SOURCE 40#define _XOPEN_SOURCE
49#endif 41#endif
50#ifndef Q_OS_WIN32 42#ifndef Q_OS_WIN32
51#include <pwd.h> 43#include <pwd.h>
52#include <unistd.h> 44#include <unistd.h>
53#include <sys/types.h> 45#include <sys/types.h>
54#endif 46#endif
55 47
56#if defined(_OS_LINUX_) 48#if defined(_OS_LINUX_)
57#include <shadow.h> 49#include <shadow.h>
58#endif 50#endif
59 51
60 52
61//#define INSECURE 53//#define INSECURE
62 54
63const int block_size = 51200; 55const int block_size = 51200;
64 56
65QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, 57QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
66 const char* name ) 58 const char* name )
67 : QServerSocket( port, 1, parent, name ), 59 : QServerSocket( port, 1, parent, name ),
68 desktopChannel( 0 ), 60 desktopChannel( 0 ),
69 cardChannel( 0 ) 61 cardChannel( 0 )
70{ 62{
71 if ( !ok() ) 63 if ( !ok() )
72 qWarning( "Failed to bind to port %d", port ); 64 qWarning( "Failed to bind to port %d", port );
73 else { 65 else {
74#ifndef QT_NO_COP 66#ifndef QT_NO_COP
75 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 67 desktopChannel = new QCopChannel( "QPE/Desktop", this );
76 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), 68 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)),
77 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 69 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
78 cardChannel = new QCopChannel( "QPE/Card", this ); 70 cardChannel = new QCopChannel( "QPE/Card", this );
79 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), 71 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)),
80 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 72 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
81#endif 73#endif
82 } 74 }
83 sendSync = FALSE; 75 sendSync = FALSE;
84 openConnections.setAutoDelete( TRUE ); 76 openConnections.setAutoDelete( TRUE );
85 authorizeConnections(); 77 authorizeConnections();
86} 78}
87 79
88QCopBridge::~QCopBridge() 80QCopBridge::~QCopBridge()
89{ 81{
90#ifndef QT_NO_COP 82#ifndef QT_NO_COP
91 delete desktopChannel; 83 delete desktopChannel;
92#endif 84#endif
93} 85}
94 86
95void QCopBridge::authorizeConnections() 87void QCopBridge::authorizeConnections()
96{ 88{
97 Config cfg("Security"); 89 Config cfg("Security");
98 cfg.setGroup("SyncMode"); 90 cfg.setGroup("SyncMode");
99 m_mode = Mode(cfg.readNumEntry("Mode", Sharp )); 91 m_mode = Mode(cfg.readNumEntry("Mode", Sharp ));
100 QListIterator<QCopBridgePI> it(openConnections); 92 QListIterator<QCopBridgePI> it(openConnections);
101 while ( it.current() ) { 93 while ( it.current() ) {
102 if ( !it.current()->verifyAuthorised() ) { 94 if ( !it.current()->verifyAuthorised() ) {
103 disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 95 disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
104 openConnections.removeRef( it.current() ); 96 openConnections.removeRef( it.current() );
105 } else 97 } else
106 ++it; 98 ++it;
107 } 99 }
108} 100}
109 101
110void QCopBridge::newConnection( int socket ) 102void QCopBridge::newConnection( int socket )
111{ 103{
112 QCopBridgePI *pi = new QCopBridgePI( socket, this ); 104 QCopBridgePI *pi = new QCopBridgePI( socket, this );
113 openConnections.append( pi ); 105 openConnections.append( pi );
114 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 106 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
115 107
116 /* ### libqtopia merge FIXME */ 108 /* ### libqtopia merge FIXME */
117#if 0 109#if 0
118 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); 110 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend );
119#endif 111#endif
120#ifndef QT_NO_COP 112#ifndef QT_NO_COP
121 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; 113 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
122#endif 114#endif
123 115
124 if ( sendSync ) { 116 if ( sendSync ) {
125 pi ->startSync(); 117 pi ->startSync();
126 sendSync = FALSE; 118 sendSync = FALSE;
127 } 119 }
128} 120}
129 121
130void QCopBridge::closed( QCopBridgePI *pi ) 122void QCopBridge::closed( QCopBridgePI *pi )
131{ 123{
132 emit connectionClosed( pi->peerAddress() ); 124 emit connectionClosed( pi->peerAddress() );
133 openConnections.removeRef( pi ); 125 openConnections.removeRef( pi );
134 if ( openConnections.count() == 0 ) { 126 if ( openConnections.count() == 0 ) {
135 /* ### FIXME libqtopia merge */ 127 /* ### FIXME libqtopia merge */
136#if 0 128#if 0
137 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); 129 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable );
138#endif 130#endif
139#ifndef QT_NO_COP 131#ifndef QT_NO_COP
140 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 132 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
141#endif 133#endif
142 } 134 }
143} 135}
144 136
145void QCopBridge::closeOpenConnections() 137void QCopBridge::closeOpenConnections()
146{ 138{
147 QCopBridgePI *pi; 139 QCopBridgePI *pi;
148 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 140 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
149 pi->close(); 141 pi->close();
150} 142}
151 143
152 144
153void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) 145void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data )
154{ 146{
155 if ( command == "startSync()" ) { 147 if ( command == "startSync()" ) {
156 // we need to buffer it a bit 148 // we need to buffer it a bit
157 sendSync = TRUE; 149 sendSync = TRUE;
158 startTimer( 20000 ); 150 startTimer( 20000 );
159 } 151 }
160 152
161 if ( m_mode & Qtopia1_7 ) { 153 if ( m_mode & Qtopia1_7 ) {
162 // send the command to all open connections 154 // send the command to all open connections
163 QCopBridgePI *pi; 155 QCopBridgePI *pi;
164 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 156 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
165 pi->sendDesktopMessage( command, data ); 157 pi->sendDesktopMessage( command, data );
166 } 158 }
167 } 159 }
168 if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) ) 160 if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) )
169 sendDesktopMessageOld( command, data ); 161 sendDesktopMessageOld( command, data );
170} 162}
171 163
172#ifndef OPIE_NO_OLD_SYNC_CODE 164#ifndef OPIE_NO_OLD_SYNC_CODE
173/* 165/*
174 * Old compat mode 166 * Old compat mode
175 */ 167 */
176void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { 168void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) {
177 command.stripWhiteSpace(); 169 command.stripWhiteSpace();
178 170
179 int paren = command.find( "(" ); 171 int paren = command.find( "(" );
180 if ( paren <= 0 ) { 172 if ( paren <= 0 ) {
181 qDebug("DesktopMessage: bad qcop syntax"); 173 qDebug("DesktopMessage: bad qcop syntax");
182 return; 174 return;
183 } 175 }
184 176
185 QString params = command.mid( paren + 1 ); 177 QString params = command.mid( paren + 1 );
186 if ( params[params.length()-1] != ')' ) { 178 if ( params[params.length()-1] != ')' ) {
187 qDebug("DesktopMessage: bad qcop syntax"); 179 qDebug("DesktopMessage: bad qcop syntax");
188 return; 180 return;
189 } 181 }
190 182
191 params.truncate( params.length()-1 ); 183 params.truncate( params.length()-1 );
192 184
193 QStringList paramList = QStringList::split( ",", params ); 185 QStringList paramList = QStringList::split( ",", params );
194 QString data; 186 QString data;
195 if ( paramList.count() ) { 187 if ( paramList.count() ) {
196 QDataStream stream( args, IO_ReadOnly ); 188 QDataStream stream( args, IO_ReadOnly );
197 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 189 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
198 QString str; 190 QString str;
199 if ( *it == "QString" ) { 191 if ( *it == "QString" ) {
200 stream >> str; 192 stream >> str;
201 } else if ( *it == "QCString" ) { 193 } else if ( *it == "QCString" ) {
202 QCString cstr; 194 QCString cstr;
203 stream >> cstr; 195 stream >> cstr;
204 str = QString::fromLocal8Bit( cstr ); 196 str = QString::fromLocal8Bit( cstr );
205 } else if ( *it == "int" ) { 197 } else if ( *it == "int" ) {
206 int i; 198 int i;
207 stream >> i; 199 stream >> i;
208 str = QString::number( i ); 200 str = QString::number( i );
209 } else if ( *it == "bool" ) { 201 } else if ( *it == "bool" ) {
210 int i; 202 int i;
211 stream >> i; 203 stream >> i;
212 str = QString::number( i ); 204 str = QString::number( i );
213 } else { 205 } else {
214 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); 206 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
215 return; 207 return;
216 } 208 }
217 QString estr; 209 QString estr;
218 for (int i=0; i<(int)str.length(); i++) { 210 for (int i=0; i<(int)str.length(); i++) {
219 QChar ch = str[i]; 211 QChar ch = str[i];
220 if ( ch.row() ) 212 if ( ch.row() )
221 goto quick; 213 goto quick;
222 switch (ch.cell()) { 214 switch (ch.cell()) {
223 case '&': 215 case '&':
224 estr.append( "&amp;" ); 216 estr.append( "&amp;" );
225 break; 217 break;
226 case ' ': 218 case ' ':
227 estr.append( "&0x20;" ); 219 estr.append( "&0x20;" );
228 break; 220 break;
229 case '\n': 221 case '\n':
230 estr.append( "&0x0d;" ); 222 estr.append( "&0x0d;" );
231 break; 223 break;
232 case '\r': 224 case '\r':
233 estr.append( "&0x0a;" ); 225 estr.append( "&0x0a;" );
234 break; 226 break;
235 default: quick: 227 default: quick:
236 estr.append(ch); 228 estr.append(ch);
237 } 229 }
238 } 230 }
239 data += " " + estr; 231 data += " " + estr;
240 } 232 }
241 } 233 }
242 QString sendCommand = QString(command.data()) + data; 234 QString sendCommand = QString(command.data()) + data;
243 235
244 236
245 // send the command to all open connections 237 // send the command to all open connections
246 QCopBridgePI *pi; 238 QCopBridgePI *pi;
247 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 239 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
248 pi->sendDesktopMessage( sendCommand ); 240 pi->sendDesktopMessage( sendCommand );
249 241
250} 242}
251#endif 243#endif
252 244
253 245
254void QCopBridge::timerEvent( QTimerEvent * ) 246void QCopBridge::timerEvent( QTimerEvent * )
255{ 247{
256 sendSync = FALSE; 248 sendSync = FALSE;
257 killTimers(); 249 killTimers();
258} 250}
259 251
260 252
261QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) 253QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
262 : QSocket( parent, name ) 254 : QSocket( parent, name )
263{ 255{
264 setSocket( socket ); 256 setSocket( socket );
265 257
266 peerport = peerPort(); 258 peerport = peerPort();
267 peeraddress = peerAddress(); 259 peeraddress = peerAddress();
268 260
269#ifndef INSECURE 261#ifndef INSECURE
270 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 262 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
271 state = Forbidden; 263 state = Forbidden;
272 close(); 264 close();
273 } else 265 } else
274#endif 266#endif
275 { 267 {
276 state = Connected; 268 state = Connected;
277 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 269 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
278 QString intro="220 Qtopia "; 270 QString intro="220 Qtopia ";
279 intro += QPE_VERSION; intro += ";"; 271 intro += QPE_VERSION; intro += ";";
280 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr 272 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr
281 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; 273 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";";
282 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; 274 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";";
283 send( intro ); 275 send( intro );
284 state = Wait_USER; 276 state = Wait_USER;
285 } 277 }
286 sendSync = FALSE; 278 sendSync = FALSE;
287 connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) ); 279 connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) );
288 280
289 // idle timer to close connections when not used anymore 281 // idle timer to close connections when not used anymore
290 timer = new QTimer(this); 282 timer = new QTimer(this);
291 connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) ); 283 connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) );
292 timer->start( 300000, TRUE ); 284 timer->start( 300000, TRUE );
293} 285}
294 286
295 287
296QCopBridgePI::~QCopBridgePI() 288QCopBridgePI::~QCopBridgePI()
297{ 289{
298} 290}
299 291
300bool QCopBridgePI::verifyAuthorised() 292bool QCopBridgePI::verifyAuthorised()
301{ 293{
302 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 294 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
303 state = Forbidden; 295 state = Forbidden;
304 return FALSE; 296 return FALSE;
305 } 297 }
306 return TRUE; 298 return TRUE;
307} 299}
308 300
309void QCopBridgePI::myConnectionClosed() 301void QCopBridgePI::myConnectionClosed()
310{ 302{
311 emit connectionClosed( this ); 303 emit connectionClosed( this );
312} 304}
313 305
314void QCopBridgePI::sendDesktopMessage( const QString &msg ) 306void QCopBridgePI::sendDesktopMessage( const QString &msg )
315{ 307{
316 QString str = "CALL QPE/Desktop " + msg; // No tr 308 QString str = "CALL QPE/Desktop " + msg; // No tr
317 send ( str ); 309 send ( str );
318} 310}
319 311
320void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data ) 312void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data )
321{ 313{
322 if ( !isOpen() ) // eg. Forbidden 314 if ( !isOpen() ) // eg. Forbidden
323 return; 315 return;
324 316
325 const char hdr[]="CALLB QPE/Desktop "; 317 const char hdr[]="CALLB QPE/Desktop ";
326 writeBlock(hdr,sizeof(hdr)-1); 318 writeBlock(hdr,sizeof(hdr)-1);
327 writeBlock(msg,msg.length()); 319 writeBlock(msg,msg.length());
328 writeBlock(" ",1); 320 writeBlock(" ",1);
329 QByteArray b64 = OGlobal::encodeBase64(data); 321 QByteArray b64 = OGlobal::encodeBase64(data);
330 writeBlock(b64.data(),b64.size()); 322 writeBlock(b64.data(),b64.size());
331 writeBlock("\r\n",2); 323 writeBlock("\r\n",2);
332 324
333} 325}
334 326
335 327
336void QCopBridgePI::send( const QString& msg ) 328void QCopBridgePI::send( const QString& msg )
337{ 329{
338 if ( !isOpen() ) // eg. Forbidden 330 if ( !isOpen() ) // eg. Forbidden
339 return; 331 return;
340 QTextStream os( this ); 332 QTextStream os( this );
341 os << msg << endl; 333 os << msg << endl;
342 //qDebug( "sending qcop message: %s", msg.latin1() ); 334 //qDebug( "sending qcop message: %s", msg.latin1() );
343} 335}
344 336
345void QCopBridgePI::read() 337void QCopBridgePI::read()
346{ 338{
347 while ( canReadLine() ) { 339 while ( canReadLine() ) {
348 timer->start( 300000, TRUE ); 340 timer->start( 300000, TRUE );
349 process( readLine().stripWhiteSpace() ); 341 process( readLine().stripWhiteSpace() );
350 } 342 }
351} 343}
352 344
353void QCopBridgePI::process( const QString& message ) 345void QCopBridgePI::process( const QString& message )
354{ 346{
355 //qDebug( "Command: %s", message.latin1() ); 347 //qDebug( "Command: %s", message.latin1() );
356 348
357 // split message using "," as separator 349 // split message using "," as separator
358 QStringList msg = QStringList::split( " ", message ); 350 QStringList msg = QStringList::split( " ", message );
359 if ( msg.isEmpty() ) return; 351 if ( msg.isEmpty() ) return;
360 352
361 // command token 353 // command token
362 QString cmd = msg[0].upper(); 354 QString cmd = msg[0].upper();
363 355
364 // argument token 356 // argument token
365 QString arg; 357 QString arg;
366 if ( msg.count() >= 2 ) 358 if ( msg.count() >= 2 )
367 arg = msg[1]; 359 arg = msg[1];
368 360
369 // we always respond to QUIT, regardless of state 361 // we always respond to QUIT, regardless of state
370 if ( cmd == "QUIT" ) { 362 if ( cmd == "QUIT" ) {
371 send( "211 Have a nice day!" ); // No tr 363 send( "211 Have a nice day!" ); // No tr
372 close(); 364 close();
373 return; 365 return;
374 } 366 }
375 367
376 // connected to client 368 // connected to client
377 if ( Connected == state ) 369 if ( Connected == state )
378 return; 370 return;
379 371
380 // waiting for user name 372 // waiting for user name
381 if ( Wait_USER == state ) { 373 if ( Wait_USER == state ) {
382 374
383 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 375 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
384 send( "530 Please login with USER and PASS" ); // No tr 376 send( "530 Please login with USER and PASS" ); // No tr
385 return; 377 return;
386 } 378 }
387 send( "331 User name ok, need password" ); // No tr 379 send( "331 User name ok, need password" ); // No tr
388 state = Wait_PASS; 380 state = Wait_PASS;
389 return; 381 return;
390 } 382 }
391 383
392 // waiting for password 384 // waiting for password
393 if ( Wait_PASS == state ) { 385 if ( Wait_PASS == state ) {
394 386
395 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 387 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
396 send( "530 Please login with USER and PASS" ); // No tr 388 send( "530 Please login with USER and PASS" ); // No tr
397 return; 389 return;
398 } 390 }
399 send( "230 User logged in, proceed" ); // No tr 391 send( "230 User logged in, proceed" ); // No tr
400 state = Ready; 392 state = Ready;
401 if ( sendSync ) { 393 if ( sendSync ) {
402 sendDesktopMessage( "startSync()" ); 394 sendDesktopMessage( "startSync()" );
403 sendSync = FALSE; 395 sendSync = FALSE;
404 } 396 }
405 return; 397 return;
406 } 398 }
407 399
408 // noop (NOOP) 400 // noop (NOOP)
409 else if ( cmd == "NOOP" ) { 401 else if ( cmd == "NOOP" ) {
410 send( "200 Command okay" ); // No tr 402 send( "200 Command okay" ); // No tr
411 } 403 }
412 404
413 // call (CALL) 405 // call (CALL)
414 else if ( cmd == "CALL" ) { 406 else if ( cmd == "CALL" ) {
415 407
416 // example: call QPE/System execute(QString) addressbook 408 // example: call QPE/System execute(QString) addressbook
417 409
418 if ( msg.count() < 3 ) { 410 if ( msg.count() < 3 ) {
419 send( "500 Syntax error, command unrecognized" ); // No tr 411 send( "500 Syntax error, command unrecognized" ); // No tr
420 } 412 }
421 else { 413 else {
422 414
423 QString channel = msg[1]; 415 QString channel = msg[1];
424 QString command = msg[2]; 416 QString command = msg[2];
425 417
426 command.stripWhiteSpace(); 418 command.stripWhiteSpace();
427 419
428 int paren = command.find( "(" ); 420 int paren = command.find( "(" );
429 if ( paren <= 0 ) { 421 if ( paren <= 0 ) {
430 send( "500 Syntax error, command unrecognized" ); // No tr 422 send( "500 Syntax error, command unrecognized" ); // No tr
431 return; 423 return;
432 } 424 }
433 425
434 QString params = command.mid( paren + 1 ); 426 QString params = command.mid( paren + 1 );
435 if ( params[(int)params.length()-1] != ')' ) { 427 if ( params[(int)params.length()-1] != ')' ) {
436 send( "500 Syntax error, command unrecognized" ); // No tr 428 send( "500 Syntax error, command unrecognized" ); // No tr
437 return; 429 return;
438 } 430 }
439 431
440 params.truncate( params.length()-1 ); 432 params.truncate( params.length()-1 );
441 QByteArray buffer; 433 QByteArray buffer;
442 QDataStream ds( buffer, IO_WriteOnly ); 434 QDataStream ds( buffer, IO_WriteOnly );
443 435
444 int msgId = 3; 436 int msgId = 3;
445 437
446 QStringList paramList = QStringList::split( ",", params ); 438 QStringList paramList = QStringList::split( ",", params );
447 if ( paramList.count() > msg.count() - 3 ) { 439 if ( paramList.count() > msg.count() - 3 ) {
448 send( "500 Syntax error, command unrecognized" ); // No tr 440 send( "500 Syntax error, command unrecognized" ); // No tr
449 return; 441 return;
450 } 442 }
451 443
452 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 444 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
453 445
454 QString arg = msg[msgId]; 446 QString arg = msg[msgId];
455 arg.replace( QRegExp("&0x20;"), " " ); 447 arg.replace( QRegExp("&0x20;"), " " );
456 arg.replace( QRegExp("&amp;"), "&" ); 448 arg.replace( QRegExp("&amp;"), "&" );
457 arg.replace( QRegExp("&0x0d;"), "\n" ); 449 arg.replace( QRegExp("&0x0d;"), "\n" );
458 arg.replace( QRegExp("&0x0a;"), "\r" ); 450 arg.replace( QRegExp("&0x0a;"), "\r" );
459 if ( *it == "QString" ) 451 if ( *it == "QString" )
460 ds << arg; 452 ds << arg;
461 else if ( *it == "QCString" ) 453 else if ( *it == "QCString" )
462 ds << arg.local8Bit(); 454 ds << arg.local8Bit();
463 else if ( *it == "int" ) 455 else if ( *it == "int" )
464 ds << arg.toInt(); 456 ds << arg.toInt();
465 else if ( *it == "bool" ) 457 else if ( *it == "bool" )
466 ds << arg.toInt(); 458 ds << arg.toInt();
467 else { 459 else {
468 send( "500 Syntax error, command unrecognized" ); // No tr 460 send( "500 Syntax error, command unrecognized" ); // No tr
469 return; 461 return;
470 } 462 }
471 msgId++; 463 msgId++;
472 } 464 }
473 465
474#ifndef QT_NO_COP 466#ifndef QT_NO_COP
475 if ( !QCopChannel::isRegistered( channel.latin1() ) ) { 467 if ( !QCopChannel::isRegistered( channel.latin1() ) ) {
476 // send message back about it 468 // send message back about it
477 QString answer = "599 ChannelNotRegistered " + channel; 469 QString answer = "599 ChannelNotRegistered " + channel;
478 send( answer ); 470 send( answer );
479 return; 471 return;
480 } 472 }
481#endif 473#endif
482 474
483#ifndef QT_NO_COP 475#ifndef QT_NO_COP
484 if ( paramList.count() ) 476 if ( paramList.count() )
485 QCopChannel::send( channel.latin1(), command.latin1(), buffer ); 477 QCopChannel::send( channel.latin1(), command.latin1(), buffer );
486 else 478 else
487 QCopChannel::send( channel.latin1(), command.latin1() ); 479 QCopChannel::send( channel.latin1(), command.latin1() );
488 480
489 send( "200 Command okay" ); // No tr 481 send( "200 Command okay" ); // No tr
490#endif 482#endif
491 } 483 }
492 } 484 }
493 // not implemented 485 // not implemented
494 else 486 else
495 send( "502 Command not implemented" ); // No tr 487 send( "502 Command not implemented" ); // No tr
496} 488}
497 489
498 490
diff --git a/core/launcher/runningappbar.cpp b/core/launcher/runningappbar.cpp
index 1fda5a4..11d10dc 100644
--- a/core/launcher/runningappbar.cpp
+++ b/core/launcher/runningappbar.cpp
@@ -1,179 +1,172 @@
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#define QTOPIA_INTERNAL_PRELOADACCESS 21#define QTOPIA_INTERNAL_PRELOADACCESS
22 22
23#include <qtopia/global.h>
24 23
25#include <stdlib.h> 24#include <stdlib.h>
26 25
27#include <qtimer.h>
28#include <qpopupmenu.h>
29#include <qpainter.h> 26#include <qpainter.h>
30#include <qmessagebox.h>
31 27
32#include <qtopia/qpeapplication.h>
33#include <qtopia/applnk.h>
34#include <qtopia/qcopenvelope_qws.h> 28#include <qtopia/qcopenvelope_qws.h>
35#include <qtopia/mimetype.h>
36 29
37#include "runningappbar.h" 30#include "runningappbar.h"
38#include "serverinterface.h" 31#include "serverinterface.h"
39 32
40RunningAppBar::RunningAppBar(QWidget* parent) 33RunningAppBar::RunningAppBar(QWidget* parent)
41 : QFrame(parent), selectedAppIndex(-1) 34 : QFrame(parent), selectedAppIndex(-1)
42{ 35{
43 QCopChannel* channel = new QCopChannel( "QPE/System", this ); 36 QCopChannel* channel = new QCopChannel( "QPE/System", this );
44 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 37 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
45 this, SLOT(received(const QCString&, const QByteArray&)) ); 38 this, SLOT(received(const QCString&, const QByteArray&)) );
46 39
47 spacing = AppLnk::smallIconSize()+3; 40 spacing = AppLnk::smallIconSize()+3;
48} 41}
49 42
50RunningAppBar::~RunningAppBar() 43RunningAppBar::~RunningAppBar()
51{ 44{
52} 45}
53 46
54void RunningAppBar::received(const QCString& msg, const QByteArray& data) { 47void RunningAppBar::received(const QCString& msg, const QByteArray& data) {
55 // Since fast apps appear and disappear without disconnecting from their 48 // Since fast apps appear and disappear without disconnecting from their
56 // channel we need to watch for the showing/hiding events and update according. 49 // channel we need to watch for the showing/hiding events and update according.
57 QDataStream stream( data, IO_ReadOnly ); 50 QDataStream stream( data, IO_ReadOnly );
58 if ( msg == "fastAppShowing(QString)") { 51 if ( msg == "fastAppShowing(QString)") {
59 QString appName; 52 QString appName;
60 stream >> appName; 53 stream >> appName;
61 // qDebug("fastAppShowing %s", appName.data() ); 54 // qDebug("fastAppShowing %s", appName.data() );
62 const AppLnk* f = ServerInterface::appLnks().findExec(appName); 55 const AppLnk* f = ServerInterface::appLnks().findExec(appName);
63 if ( f ) addTask(*f); 56 if ( f ) addTask(*f);
64 } else if ( msg == "fastAppHiding(QString)") { 57 } else if ( msg == "fastAppHiding(QString)") {
65 QString appName; 58 QString appName;
66 stream >> appName; 59 stream >> appName;
67 const AppLnk* f = ServerInterface::appLnks().findExec(appName); 60 const AppLnk* f = ServerInterface::appLnks().findExec(appName);
68 if ( f ) removeTask(*f); 61 if ( f ) removeTask(*f);
69 } 62 }
70} 63}
71 64
72void RunningAppBar::addTask(const AppLnk& appLnk) { 65void RunningAppBar::addTask(const AppLnk& appLnk) {
73 qDebug("Added %s to app list.", appLnk.name().latin1()); 66 qDebug("Added %s to app list.", appLnk.name().latin1());
74 AppLnk* newApp = new AppLnk(appLnk); 67 AppLnk* newApp = new AppLnk(appLnk);
75 newApp->setExec(appLnk.exec()); 68 newApp->setExec(appLnk.exec());
76 appList.prepend(newApp); 69 appList.prepend(newApp);
77 update(); 70 update();
78} 71}
79 72
80void RunningAppBar::removeTask(const AppLnk& appLnk) { 73void RunningAppBar::removeTask(const AppLnk& appLnk) {
81 unsigned int i = 0; 74 unsigned int i = 0;
82 for (; i < appList.count() ; i++) { 75 for (; i < appList.count() ; i++) {
83 AppLnk* target = appList.at(i); 76 AppLnk* target = appList.at(i);
84 if (target->exec() == appLnk.exec()) { 77 if (target->exec() == appLnk.exec()) {
85 qDebug("Removing %s from app list.", appLnk.name().latin1()); 78 qDebug("Removing %s from app list.", appLnk.name().latin1());
86 appList.remove(); 79 appList.remove();
87 delete target; 80 delete target;
88 } 81 }
89 } 82 }
90 update(); 83 update();
91} 84}
92 85
93void RunningAppBar::mousePressEvent(QMouseEvent *e) 86void RunningAppBar::mousePressEvent(QMouseEvent *e)
94{ 87{
95 // Find out if the user is clicking on an app icon... 88 // Find out if the user is clicking on an app icon...
96 // If so, snag the index so when we repaint we show it 89 // If so, snag the index so when we repaint we show it
97 // as highlighed. 90 // as highlighed.
98 selectedAppIndex = 0; 91 selectedAppIndex = 0;
99 int x=0; 92 int x=0;
100 QListIterator<AppLnk> it( appList ); 93 QListIterator<AppLnk> it( appList );
101 for ( ; it.current(); ++it,++selectedAppIndex,x+=spacing ) { 94 for ( ; it.current(); ++it,++selectedAppIndex,x+=spacing ) {
102 if ( x + spacing <= width() ) { 95 if ( x + spacing <= width() ) {
103 if ( e->x() >= x && e->x() < x+spacing ) { 96 if ( e->x() >= x && e->x() < x+spacing ) {
104 if ( selectedAppIndex < (int)appList.count() ) { 97 if ( selectedAppIndex < (int)appList.count() ) {
105 repaint(FALSE); 98 repaint(FALSE);
106 return; 99 return;
107 } 100 }
108 } 101 }
109 } else { 102 } else {
110 break; 103 break;
111 } 104 }
112 } 105 }
113 selectedAppIndex = -1; 106 selectedAppIndex = -1;
114 repaint( FALSE ); 107 repaint( FALSE );
115} 108}
116 109
117void RunningAppBar::mouseReleaseEvent(QMouseEvent *e) 110void RunningAppBar::mouseReleaseEvent(QMouseEvent *e)
118{ 111{
119 if (e->button() == QMouseEvent::RightButton) 112 if (e->button() == QMouseEvent::RightButton)
120 return; 113 return;
121 if ( selectedAppIndex >= 0 ) { 114 if ( selectedAppIndex >= 0 ) {
122 QString app = appList.at(selectedAppIndex)->exec(); 115 QString app = appList.at(selectedAppIndex)->exec();
123 QCopEnvelope e("QPE/System", "raise(QString)"); 116 QCopEnvelope e("QPE/System", "raise(QString)");
124 e << app; 117 e << app;
125 selectedAppIndex = -1; 118 selectedAppIndex = -1;
126 update(); 119 update();
127 } 120 }
128} 121}
129 122
130void RunningAppBar::paintEvent( QPaintEvent * ) 123void RunningAppBar::paintEvent( QPaintEvent * )
131{ 124{
132 QPainter p( this ); 125 QPainter p( this );
133 AppLnk *curApp; 126 AppLnk *curApp;
134 int x = 0; 127 int x = 0;
135 int y = (height() - AppLnk::smallIconSize()) / 2; 128 int y = (height() - AppLnk::smallIconSize()) / 2;
136 int i = 0; 129 int i = 0;
137 130
138 p.fillRect( 0, 0, width(), height(), colorGroup().background() ); 131 p.fillRect( 0, 0, width(), height(), colorGroup().background() );
139 132
140 QListIterator<AppLnk> it(appList); 133 QListIterator<AppLnk> it(appList);
141 134
142 for (; it.current(); i++, ++it ) { 135 for (; it.current(); i++, ++it ) {
143 if ( x + spacing <= width() ) { 136 if ( x + spacing <= width() ) {
144 curApp = it.current(); 137 curApp = it.current();
145 qWarning("Drawing %s", curApp->name().latin1() ); 138 qWarning("Drawing %s", curApp->name().latin1() );
146 if ( (int)i == selectedAppIndex ) 139 if ( (int)i == selectedAppIndex )
147 p.fillRect( x, y, spacing, curApp->pixmap().height()+1, colorGroup().highlight() ); 140 p.fillRect( x, y, spacing, curApp->pixmap().height()+1, colorGroup().highlight() );
148 else 141 else
149 p.eraseRect( x, y, spacing, curApp->pixmap().height()+1 ); 142 p.eraseRect( x, y, spacing, curApp->pixmap().height()+1 );
150 p.drawPixmap( x, y, curApp->pixmap() ); 143 p.drawPixmap( x, y, curApp->pixmap() );
151 x += spacing; 144 x += spacing;
152 } 145 }
153 } 146 }
154} 147}
155 148
156QSize RunningAppBar::sizeHint() const 149QSize RunningAppBar::sizeHint() const
157{ 150{
158 return QSize( frameWidth(), AppLnk::smallIconSize()+frameWidth()*2+3 ); 151 return QSize( frameWidth(), AppLnk::smallIconSize()+frameWidth()*2+3 );
159} 152}
160 153
161void RunningAppBar::applicationLaunched(const QString &appName) 154void RunningAppBar::applicationLaunched(const QString &appName)
162{ 155{
163 qDebug("desktop:: app: %s launched with pid ", appName.data() ); 156 qDebug("desktop:: app: %s launched with pid ", appName.data() );
164 const AppLnk* newGuy = ServerInterface::appLnks().findExec(appName); 157 const AppLnk* newGuy = ServerInterface::appLnks().findExec(appName);
165 if ( newGuy && !newGuy->isPreloaded() ) { 158 if ( newGuy && !newGuy->isPreloaded() ) {
166 addTask( *newGuy ); 159 addTask( *newGuy );
167 } 160 }
168} 161}
169 162
170void RunningAppBar::applicationTerminated(const QString &app) 163void RunningAppBar::applicationTerminated(const QString &app)
171{ 164{
172 const AppLnk* gone = ServerInterface::appLnks().findExec(app); 165 const AppLnk* gone = ServerInterface::appLnks().findExec(app);
173 if ( gone ) { 166 if ( gone ) {
174 removeTask(*gone); 167 removeTask(*gone);
175 } 168 }
176} 169}
177 170
178 171
179 172
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp
index 1146dcd..e544c61 100644
--- a/core/launcher/screensaver.cpp
+++ b/core/launcher/screensaver.cpp
@@ -1,329 +1,328 @@
1 1
2#include "screensaver.h" 2#include "screensaver.h"
3 3
4#include <qpe/config.h> 4#include <qpe/config.h>
5#include <qpe/power.h>
6#include <qpe/network.h> 5#include <qpe/network.h>
7 6
8#include <opie2/odevice.h> 7#include <opie2/odevice.h>
9 8
10 9
11using namespace Opie; 10using namespace Opie;
12 11
13 12
14 13
15OpieScreenSaver::OpieScreenSaver ( ) 14OpieScreenSaver::OpieScreenSaver ( )
16 : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) 15 : QObject ( 0, "screensaver" ), QWSScreenSaver ( )
17{ 16{
18 m_disable_suspend = 100; 17 m_disable_suspend = 100;
19 m_enable_dim = false; 18 m_enable_dim = false;
20 m_enable_lightoff = false; 19 m_enable_lightoff = false;
21 m_enable_suspend = false; 20 m_enable_suspend = false;
22 m_onlylcdoff = false; 21 m_onlylcdoff = false;
23 22
24 m_enable_dim_ac = false; 23 m_enable_dim_ac = false;
25 m_enable_lightoff_ac = false; 24 m_enable_lightoff_ac = false;
26 m_enable_suspend_ac = false; 25 m_enable_suspend_ac = false;
27 m_onlylcdoff_ac = false; 26 m_onlylcdoff_ac = false;
28 27
29 m_use_light_sensor = false; 28 m_use_light_sensor = false;
30 m_backlight_sensor = -1; 29 m_backlight_sensor = -1;
31 ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); 30 ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] ));
32 31
33 m_lcd_status = true; 32 m_lcd_status = true;
34 33
35 m_backlight_normal = -1; 34 m_backlight_normal = -1;
36 m_backlight_current = -1; 35 m_backlight_current = -1;
37 m_backlight_forcedoff = false; 36 m_backlight_forcedoff = false;
38 37
39 m_on_ac = false; 38 m_on_ac = false;
40 39
41 m_level = -1; 40 m_level = -1;
42 41
43 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 42 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
44 ODevice::inst ( )-> setDisplayStatus ( true ); 43 ODevice::inst ( )-> setDisplayStatus ( true );
45 setBacklight ( -1 ); 44 setBacklight ( -1 );
46} 45}
47 46
48 47
49/** 48/**
50 * Stops the screen saver 49 * Stops the screen saver
51 */ 50 */
52void OpieScreenSaver::restore() 51void OpieScreenSaver::restore()
53{ 52{
54 m_level = -1; 53 m_level = -1;
55 54
56 if ( !m_lcd_status ) { // We must have turned it off 55 if ( !m_lcd_status ) { // We must have turned it off
57 ODevice::inst ( ) -> setDisplayStatus ( true ); 56 ODevice::inst ( ) -> setDisplayStatus ( true );
58 m_lcd_status = true; 57 m_lcd_status = true;
59 } 58 }
60 59
61 setBacklightInternal ( -1 ); 60 setBacklightInternal ( -1 );
62} 61}
63 62
64 63
65/** 64/**
66 * Starts the screen saver 65 * Starts the screen saver
67 * 66 *
68 * @param level what level of screen saving should happen (0=lowest non-off, 1=off, 67 * @param level what level of screen saving should happen (0=lowest non-off, 1=off,
69 * 2=suspend whole machine) 68 * 2=suspend whole machine)
70 * @returns true on success 69 * @returns true on success
71 */ 70 */
72bool OpieScreenSaver::save( int level ) 71bool OpieScreenSaver::save( int level )
73{ 72{
74 m_level = level; 73 m_level = level;
75 74
76 switch ( level ) { 75 switch ( level ) {
77 case 0: 76 case 0:
78 if (( m_on_ac && m_enable_dim_ac ) || 77 if (( m_on_ac && m_enable_dim_ac ) ||
79 ( !m_on_ac && m_enable_dim )) { 78 ( !m_on_ac && m_enable_dim )) {
80 if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) 79 if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor )
81 setBacklightInternal ( 1 ); // lowest non-off 80 setBacklightInternal ( 1 ); // lowest non-off
82 } 81 }
83 return true; 82 return true;
84 break; 83 break;
85 84
86 case 1: 85 case 1:
87 if (( m_on_ac && m_enable_lightoff_ac ) || 86 if (( m_on_ac && m_enable_lightoff_ac ) ||
88 ( !m_on_ac && m_enable_lightoff )) { 87 ( !m_on_ac && m_enable_lightoff )) {
89 if ( m_disable_suspend > 1 ) 88 if ( m_disable_suspend > 1 )
90 setBacklightInternal ( 0 ); // off 89 setBacklightInternal ( 0 ); // off
91 } 90 }
92 return true; 91 return true;
93 break; 92 break;
94 93
95 case 2: 94 case 2:
96 if (( m_on_ac && !m_enable_suspend_ac ) || 95 if (( m_on_ac && !m_enable_suspend_ac ) ||
97 ( !m_on_ac && !m_enable_suspend )) { 96 ( !m_on_ac && !m_enable_suspend )) {
98 return true; 97 return true;
99 } 98 }
100 99
101 if (( m_on_ac && m_onlylcdoff_ac ) || 100 if (( m_on_ac && m_onlylcdoff_ac ) ||
102 ( !m_on_ac && m_onlylcdoff )) { 101 ( !m_on_ac && m_onlylcdoff )) {
103 ODevice::inst ( ) -> setDisplayStatus ( false ); 102 ODevice::inst ( ) -> setDisplayStatus ( false );
104 m_lcd_status = false; 103 m_lcd_status = false;
105 return true; 104 return true;
106 } 105 }
107 106
108 // We're going to suspend the whole machine 107 // We're going to suspend the whole machine
109 108
110 if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { 109 if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) {
111 // TODO: why is this key F34 hard coded? -- schurig 110 // TODO: why is this key F34 hard coded? -- schurig
112 // Does this now only work an devices with a ODevice::filter? 111 // Does this now only work an devices with a ODevice::filter?
113 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 112 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
114 return true; 113 return true;
115 } 114 }
116 115
117 break; 116 break;
118 } 117 }
119 return false; 118 return false;
120} 119}
121 120
122 121
123/** 122/**
124 * Set intervals in seconds for automatic dimming, light off and suspend 123 * Set intervals in seconds for automatic dimming, light off and suspend
125 * 124 *
126 * This function also sets the member variables m_m_enable_dim[_ac], 125 * This function also sets the member variables m_m_enable_dim[_ac],
127 * m_enable_lightoff[_ac], m_enable_suspend[_ac], m_onlylcdoff[_ac] 126 * m_enable_lightoff[_ac], m_enable_suspend[_ac], m_onlylcdoff[_ac]
128 * 127 *
129 * @param dim time in seconds to dim, -1 to read value from config file, 128 * @param dim time in seconds to dim, -1 to read value from config file,
130 * 0 to disable 129 * 0 to disable
131 * @param lightoff time in seconds to turn LCD backlight off, -1 to 130 * @param lightoff time in seconds to turn LCD backlight off, -1 to
132 * read value from config file, 0 to disable 131 * read value from config file, 0 to disable
133 * @param suspend time in seconds to do an APM suspend, -1 to 132 * @param suspend time in seconds to do an APM suspend, -1 to
134 * read value from config file, 0 to disable 133 * read value from config file, 0 to disable
135 */ 134 */
136void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) 135void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend )
137{ 136{
138 Config config ( "apm" ); 137 Config config ( "apm" );
139 config. setGroup ( m_on_ac ? "AC" : "Battery" ); 138 config. setGroup ( m_on_ac ? "AC" : "Battery" );
140 139
141 int v[ 4 ]; 140 int v[ 4 ];
142 if ( dim < 0 ) 141 if ( dim < 0 )
143 dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); 142 dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 );
144 if ( lightoff < 0 ) 143 if ( lightoff < 0 )
145 lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); 144 lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 );
146 if ( suspend < 0 ) 145 if ( suspend < 0 )
147 suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); 146 suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 );
148 147
149 if ( m_on_ac ) { 148 if ( m_on_ac ) {
150 m_enable_dim_ac = ( dim > 0 ); 149 m_enable_dim_ac = ( dim > 0 );
151 m_enable_lightoff_ac = ( lightoff > 0 ); 150 m_enable_lightoff_ac = ( lightoff > 0 );
152 m_enable_suspend_ac = ( suspend > 0 ); 151 m_enable_suspend_ac = ( suspend > 0 );
153 m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); 152 m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false );
154 } 153 }
155 else { 154 else {
156 m_enable_dim = ( dim > 0 ); 155 m_enable_dim = ( dim > 0 );
157 m_enable_lightoff = ( lightoff > 0 ); 156 m_enable_lightoff = ( lightoff > 0 );
158 m_enable_suspend = ( suspend > 0 ); 157 m_enable_suspend = ( suspend > 0 );
159 m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); 158 m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false );
160 } 159 }
161 160
162 //qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend); 161 //qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend);
163 162
164 v [ 0 ] = QMAX( 1000 * dim, 100 ); 163 v [ 0 ] = QMAX( 1000 * dim, 100 );
165 v [ 1 ] = QMAX( 1000 * lightoff, 100 ); 164 v [ 1 ] = QMAX( 1000 * lightoff, 100 );
166 v [ 2 ] = QMAX( 1000 * suspend, 100 ); 165 v [ 2 ] = QMAX( 1000 * suspend, 100 );
167 v [ 3 ] = 0; 166 v [ 3 ] = 0;
168 167
169 if ( !dim && !lightoff && !suspend ) 168 if ( !dim && !lightoff && !suspend )
170 QWSServer::setScreenSaverInterval( 0 ); 169 QWSServer::setScreenSaverInterval( 0 );
171 else 170 else
172 QWSServer::setScreenSaverIntervals( v ); 171 QWSServer::setScreenSaverIntervals( v );
173} 172}
174 173
175 174
176/** 175/**
177 * Set suspend time. Will read the dim and lcd-off times from the config file. 176 * Set suspend time. Will read the dim and lcd-off times from the config file.
178 * 177 *
179 * @param suspend time in seconds to go into APM suspend, -1 to 178 * @param suspend time in seconds to go into APM suspend, -1 to
180 * read value from config file, 0 to disable 179 * read value from config file, 0 to disable
181 */ 180 */
182void OpieScreenSaver::setInterval ( int interval ) 181void OpieScreenSaver::setInterval ( int interval )
183{ 182{
184 setIntervals ( -1, -1, interval ); 183 setIntervals ( -1, -1, interval );
185} 184}
186 185
187 186
188void OpieScreenSaver::setMode ( int mode ) 187void OpieScreenSaver::setMode ( int mode )
189{ 188{
190 if ( mode > m_disable_suspend ) 189 if ( mode > m_disable_suspend )
191 setInterval ( -1 ); 190 setInterval ( -1 );
192 m_disable_suspend = mode; 191 m_disable_suspend = mode;
193} 192}
194 193
195 194
196/** 195/**
197 * Set display brightness 196 * Set display brightness
198 * 197 *
199 * Get's default values for backlight, contrast and light sensor from config file. 198 * Get's default values for backlight, contrast and light sensor from config file.
200 * 199 *
201 * @param bright desired brighness (-1 to use automatic sensor data or value 200 * @param bright desired brighness (-1 to use automatic sensor data or value
202 * from config file, -2 to toggle backlight on and off, -3 to 201 * from config file, -2 to toggle backlight on and off, -3 to
203 * force backlight off) 202 * force backlight off)
204 */ 203 */
205void OpieScreenSaver::setBacklight ( int bright ) 204void OpieScreenSaver::setBacklight ( int bright )
206{ 205{
207 // Read from config 206 // Read from config
208 Config config ( "apm" ); 207 Config config ( "apm" );
209 config. setGroup ( m_on_ac ? "AC" : "Battery" ); 208 config. setGroup ( m_on_ac ? "AC" : "Battery" );
210 m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); 209 m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 );
211 int contrast = config. readNumEntry ( "Contrast", 127); 210 int contrast = config. readNumEntry ( "Contrast", 127);
212 m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); 211 m_use_light_sensor = config. readBoolEntry ( "LightSensor", false );
213 212
214 //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); 213 //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 );
215 214
216 killTimers ( ); 215 killTimers ( );
217 if (( bright < 0 ) && m_use_light_sensor ) { 216 if (( bright < 0 ) && m_use_light_sensor ) {
218 QStringList sl = config. readListEntry ( "LightSensorData", ';' ); 217 QStringList sl = config. readListEntry ( "LightSensorData", ';' );
219 218
220 m_sensordata [LS_SensorMin] = 40; 219 m_sensordata [LS_SensorMin] = 40;
221 m_sensordata [LS_SensorMax] = 215; 220 m_sensordata [LS_SensorMax] = 215;
222 m_sensordata [LS_LightMin] = 1; 221 m_sensordata [LS_LightMin] = 1;
223 m_sensordata [LS_LightMax] = 255; 222 m_sensordata [LS_LightMax] = 255;
224 m_sensordata [LS_Steps] = 12; 223 m_sensordata [LS_Steps] = 12;
225 m_sensordata [LS_Interval] = 2000; 224 m_sensordata [LS_Interval] = 2000;
226 225
227 for ( uint i = 0; i < LS_Count; i++ ) { 226 for ( uint i = 0; i < LS_Count; i++ ) {
228 if ( i < sl. count ( )) 227 if ( i < sl. count ( ))
229 m_sensordata [i] = sl [i]. toInt ( ); 228 m_sensordata [i] = sl [i]. toInt ( );
230 } 229 }
231 if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE 230 if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE
232 m_sensordata [LS_Steps] = 2; 231 m_sensordata [LS_Steps] = 2;
233 232
234 timerEvent ( 0 ); 233 timerEvent ( 0 );
235 startTimer ( m_sensordata [LS_Interval] ); 234 startTimer ( m_sensordata [LS_Interval] );
236 } 235 }
237 236
238 setBacklightInternal ( bright ); 237 setBacklightInternal ( bright );
239 ODevice::inst ( )-> setDisplayContrast(contrast); 238 ODevice::inst ( )-> setDisplayContrast(contrast);
240} 239}
241 240
242 241
243/** 242/**
244 * Internal brightness setting method 243 * Internal brightness setting method
245 * 244 *
246 * Get's default values for backlight and light sensor from config file. 245 * Get's default values for backlight and light sensor from config file.
247 * 246 *
248 * @param bright desired brighness (-1 to use automatic sensor data or value 247 * @param bright desired brighness (-1 to use automatic sensor data or value
249 * from config file, -2 to toggle backlight on and off, -3 to 248 * from config file, -2 to toggle backlight on and off, -3 to
250 * force backlight off) 249 * force backlight off)
251 */ 250 */
252void OpieScreenSaver::setBacklightInternal ( int bright ) 251void OpieScreenSaver::setBacklightInternal ( int bright )
253{ 252{
254 if ( bright == -3 ) { 253 if ( bright == -3 ) {
255 // Forced on 254 // Forced on
256 m_backlight_forcedoff = false; 255 m_backlight_forcedoff = false;
257 bright = -1; 256 bright = -1;
258 } 257 }
259 if ( m_backlight_forcedoff && bright != -2 ) 258 if ( m_backlight_forcedoff && bright != -2 )
260 return ; 259 return ;
261 if ( bright == -2 ) { 260 if ( bright == -2 ) {
262 // Toggle between off and on 261 // Toggle between off and on
263 bright = m_backlight_current ? 0 : -1; 262 bright = m_backlight_current ? 0 : -1;
264 m_backlight_forcedoff = !bright; 263 m_backlight_forcedoff = !bright;
265 } 264 }
266 if ( bright == -1 ) 265 if ( bright == -1 )
267 bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; 266 bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal;
268 267
269 if ( bright != m_backlight_current ) { 268 if ( bright != m_backlight_current ) {
270 ODevice::inst ( )-> setDisplayBrightness ( bright ); 269 ODevice::inst ( )-> setDisplayBrightness ( bright );
271 m_backlight_current = bright; 270 m_backlight_current = bright;
272 } 271 }
273} 272}
274 273
275 274
276/** 275/**
277 * Timer event used for automatic setting the backlight according to a light sensor 276 * Timer event used for automatic setting the backlight according to a light sensor
278 * and to set the default brightness 277 * and to set the default brightness
279 */ 278 */
280void OpieScreenSaver::timerEvent ( QTimerEvent * ) 279void OpieScreenSaver::timerEvent ( QTimerEvent * )
281{ 280{
282 int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); 281 int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( );
283 282
284 if ( s < m_sensordata [LS_SensorMin] ) 283 if ( s < m_sensordata [LS_SensorMin] )
285 m_backlight_sensor = m_sensordata [LS_LightMax]; 284 m_backlight_sensor = m_sensordata [LS_LightMax];
286 else if ( s >= m_sensordata [LS_SensorMax] ) 285 else if ( s >= m_sensordata [LS_SensorMax] )
287 m_backlight_sensor = m_sensordata [LS_LightMin]; 286 m_backlight_sensor = m_sensordata [LS_LightMin];
288 else { 287 else {
289 int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; 288 int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin];
290 int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; 289 int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin];
291 290
292 int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 291 int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0
293 292
294 m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); 293 m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 );
295 } 294 }
296 295
297 //qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); 296 //qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] );
298 297
299 if ( m_level <= 0 ) 298 if ( m_level <= 0 )
300 setBacklightInternal ( -1 ); 299 setBacklightInternal ( -1 );
301} 300}
302 301
303 302
304/** 303/**
305 * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status. 304 * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status.
306 */ 305 */
307void OpieScreenSaver::setDisplayState ( bool on ) 306void OpieScreenSaver::setDisplayState ( bool on )
308{ 307{
309 if ( m_lcd_status != on ) { 308 if ( m_lcd_status != on ) {
310 ODevice::inst ( ) -> setDisplayStatus ( on ); 309 ODevice::inst ( ) -> setDisplayStatus ( on );
311 m_lcd_status = on; 310 m_lcd_status = on;
312 } 311 }
313} 312}
314 313
315 314
316/** 315/**
317 * Set display to default ac/battery settings when power status changed. 316 * Set display to default ac/battery settings when power status changed.
318 */ 317 */
319void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) 318void OpieScreenSaver::powerStatusChanged ( PowerStatus ps )
320{ 319{
321 bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); 320 bool newonac = ( ps. acStatus ( ) == PowerStatus::Online );
322 321
323 if ( newonac != m_on_ac ) { 322 if ( newonac != m_on_ac ) {
324 m_on_ac = newonac; 323 m_on_ac = newonac;
325 setInterval ( -1 ); 324 setInterval ( -1 );
326 setBacklight ( -1 ); 325 setBacklight ( -1 );
327 restore ( ); 326 restore ( );
328 } 327 }
329} 328}
diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp
index 32fcdd0..068d716 100644
--- a/core/launcher/server.cpp
+++ b/core/launcher/server.cpp
@@ -1,730 +1,729 @@
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 "server.h" 21#include "server.h"
22#include "serverapp.h" 22#include "serverapp.h"
23#include "launcher.h"
24#include "startmenu.h" 23#include "startmenu.h"
24#include "launcher.h"
25#include "transferserver.h" 25#include "transferserver.h"
26#include "qcopbridge.h" 26#include "qcopbridge.h"
27#include "irserver.h" 27#include "irserver.h"
28#include "packageslave.h" 28#include "packageslave.h"
29#include "calibrate.h" 29#include "calibrate.h"
30#include "qrsync.h" 30#include "qrsync.h"
31#include "syncdialog.h" 31#include "syncdialog.h"
32#include "launcher.h"
33#include "shutdownimpl.h" 32#include "shutdownimpl.h"
34#include "applauncher.h" 33#include "applauncher.h"
35#if 0 34#if 0
36#include "suspendmonitor.h" 35#include "suspendmonitor.h"
37#endif 36#endif
38#include "documentlist.h" 37#include "documentlist.h"
39 38
40#include <qtopia/applnk.h> 39#include <qtopia/applnk.h>
41#include <qtopia/private/categories.h> 40#include <qtopia/private/categories.h>
42#include <qtopia/mimetype.h> 41#include <qtopia/mimetype.h>
43#include <qtopia/config.h> 42#include <qtopia/config.h>
44#include <qtopia/resource.h> 43#include <qtopia/resource.h>
45#include <qtopia/version.h> 44#include <qtopia/version.h>
46#include <qtopia/storage.h> 45#include <qtopia/storage.h>
47 46
48#include <qtopia/qcopenvelope_qws.h> 47#include <qtopia/qcopenvelope_qws.h>
49#include <qwindowsystem_qws.h> 48#include <qwindowsystem_qws.h>
50#include <qgfx_qws.h> 49#include <qgfx_qws.h>
51#include <qtopia/global.h> 50#include <qtopia/global.h>
52//#include <qtopia/custom.h> 51//#include <qtopia/custom.h>
53 52
54#include <opie2/odevicebutton.h> 53#include <opie2/odevicebutton.h>
55#include <opie2/odevice.h> 54#include <opie2/odevice.h>
56 55
57#include <unistd.h> 56#include <unistd.h>
58#include <qmainwindow.h> 57#include <qmainwindow.h>
59#include <qmessagebox.h> 58#include <qmessagebox.h>
60#include <qtimer.h> 59#include <qtimer.h>
61#include <qtextstream.h> 60#include <qtextstream.h>
62 61
63#include <stdlib.h> 62#include <stdlib.h>
64 63
65extern QRect qt_maxWindowRect; 64extern QRect qt_maxWindowRect;
66 65
67using namespace Opie; 66using namespace Opie;
68 67
69static QWidget *calibrate(bool) 68static QWidget *calibrate(bool)
70{ 69{
71#ifdef Q_WS_QWS 70#ifdef Q_WS_QWS
72 Calibrate *c = new Calibrate; 71 Calibrate *c = new Calibrate;
73 c->show(); 72 c->show();
74 return c; 73 return c;
75#else 74#else
76 return 0; 75 return 0;
77#endif 76#endif
78} 77}
79 78
80#define FACTORY(T) \ 79#define FACTORY(T) \
81 static QWidget *new##T( bool maximized ) { \ 80 static QWidget *new##T( bool maximized ) { \
82 QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ 81 QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \
83 if ( maximized ) { \ 82 if ( maximized ) { \
84 if ( qApp->desktop()->width() <= 350 ) { \ 83 if ( qApp->desktop()->width() <= 350 ) { \
85 w->showMaximized(); \ 84 w->showMaximized(); \
86 } else { \ 85 } else { \
87 w->resize( QSize( 300, 300 ) ); \ 86 w->resize( QSize( 300, 300 ) ); \
88 } \ 87 } \
89 } \ 88 } \
90 w->show(); \ 89 w->show(); \
91 return w; \ 90 return w; \
92 } 91 }
93 92
94 93
95#ifdef SINGLE_APP 94#ifdef SINGLE_APP
96#define APP(a,b,c,d) FACTORY(b) 95#define APP(a,b,c,d) FACTORY(b)
97#include "apps.h" 96#include "apps.h"
98#undef APP 97#undef APP
99#endif // SINGLE_APP 98#endif // SINGLE_APP
100 99
101static Global::Command builtins[] = { 100static Global::Command builtins[] = {
102 101
103#ifdef SINGLE_APP 102#ifdef SINGLE_APP
104#define APP(a,b,c,d) { a, new##b, c, d }, 103#define APP(a,b,c,d) { a, new##b, c, d },
105#include "apps.h" 104#include "apps.h"
106#undef APP 105#undef APP
107#endif 106#endif
108 107
109 /* FIXME defines need to be defined*/ 108 /* FIXME defines need to be defined*/
110#if !defined(OPIE_NO_BUILTIN_CALIBRATE) 109#if !defined(OPIE_NO_BUILTIN_CALIBRATE)
111 { "calibrate", calibrate, 1, 0 }, // No tr 110 { "calibrate", calibrate, 1, 0 }, // No tr
112#endif 111#endif
113#if !defined(OPIE_NO_BUILTIN_SHUTDOWN) 112#if !defined(OPIE_NO_BUILTIN_SHUTDOWN)
114 { "shutdown", Global::shutdown, 1, 0 }, // No tr 113 { "shutdown", Global::shutdown, 1, 0 }, // No tr
115 // { "run", run, 1, 0 }, // No tr 114 // { "run", run, 1, 0 }, // No tr
116#endif 115#endif
117 116
118 { 0, calibrate,0, 0 }, 117 { 0, calibrate,0, 0 },
119}; 118};
120 119
121 120
122//--------------------------------------------------------------------------- 121//---------------------------------------------------------------------------
123 122
124 123
125//=========================================================================== 124//===========================================================================
126 125
127Server::Server() : 126Server::Server() :
128 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 127 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
129 qcopBridge( 0 ), 128 qcopBridge( 0 ),
130 transferServer( 0 ), 129 transferServer( 0 ),
131 packageHandler( 0 ), 130 packageHandler( 0 ),
132 syncDialog( 0 ) 131 syncDialog( 0 )
133{ 132{
134 Global::setBuiltinCommands(builtins); 133 Global::setBuiltinCommands(builtins);
135 134
136 tid_xfer = 0; 135 tid_xfer = 0;
137 /* ### FIXME ### */ 136 /* ### FIXME ### */
138/* tid_today = startTimer(3600*2*1000);*/ 137/* tid_today = startTimer(3600*2*1000);*/
139 last_today_show = QDate::currentDate(); 138 last_today_show = QDate::currentDate();
140 139
141#if 0 140#if 0
142 tsmMonitor = new TempScreenSaverMode(); 141 tsmMonitor = new TempScreenSaverMode();
143 connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) ); 142 connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) );
144#endif 143#endif
145 144
146 serverGui = new Launcher; 145 serverGui = new Launcher;
147 serverGui->createGUI(); 146 serverGui->createGUI();
148 147
149 docList = new DocumentList( serverGui ); 148 docList = new DocumentList( serverGui );
150 appLauncher = new AppLauncher(this); 149 appLauncher = new AppLauncher(this);
151 connect(appLauncher, SIGNAL(launched(int, const QString &)), this, SLOT(applicationLaunched(int, const QString &)) ); 150 connect(appLauncher, SIGNAL(launched(int, const QString &)), this, SLOT(applicationLaunched(int, const QString &)) );
152 connect(appLauncher, SIGNAL(terminated(int, const QString &)), this, SLOT(applicationTerminated(int, const QString &)) ); 151 connect(appLauncher, SIGNAL(terminated(int, const QString &)), this, SLOT(applicationTerminated(int, const QString &)) );
153 connect(appLauncher, SIGNAL(connected(const QString &)), this, SLOT(applicationConnected(const QString &)) ); 152 connect(appLauncher, SIGNAL(connected(const QString &)), this, SLOT(applicationConnected(const QString &)) );
154 153
155 storage = new StorageInfo( this ); 154 storage = new StorageInfo( this );
156 connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) ); 155 connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) );
157 156
158 // start services 157 // start services
159 startTransferServer(); 158 startTransferServer();
160 (void) new IrServer( this ); 159 (void) new IrServer( this );
161 160
162 packageHandler = new PackageHandler( this ); 161 packageHandler = new PackageHandler( this );
163 connect(qApp, SIGNAL(activate(const Opie::ODeviceButton*,bool)), 162 connect(qApp, SIGNAL(activate(const Opie::ODeviceButton*,bool)),
164 this,SLOT(activate(const Opie::ODeviceButton*,bool))); 163 this,SLOT(activate(const Opie::ODeviceButton*,bool)));
165 164
166 setGeometry( -10, -10, 9, 9 ); 165 setGeometry( -10, -10, 9, 9 );
167 166
168 QCopChannel *channel = new QCopChannel("QPE/System", this); 167 QCopChannel *channel = new QCopChannel("QPE/System", this);
169 connect(channel, SIGNAL(received(const QCString &, const QByteArray &)), 168 connect(channel, SIGNAL(received(const QCString &, const QByteArray &)),
170 this, SLOT(systemMsg(const QCString &, const QByteArray &)) ); 169 this, SLOT(systemMsg(const QCString &, const QByteArray &)) );
171 170
172 QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); 171 QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this );
173 connect( tbChannel, SIGNAL(received(const QCString&, const QByteArray&)), 172 connect( tbChannel, SIGNAL(received(const QCString&, const QByteArray&)),
174 this, SLOT(receiveTaskBar(const QCString&, const QByteArray&)) ); 173 this, SLOT(receiveTaskBar(const QCString&, const QByteArray&)) );
175 174
176 connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); 175 connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) );
177 connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); 176 connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) );
178 177
179 preloadApps(); 178 preloadApps();
180} 179}
181 180
182void Server::show() 181void Server::show()
183{ 182{
184 ServerApplication::login(TRUE); 183 ServerApplication::login(TRUE);
185 QWidget::show(); 184 QWidget::show();
186} 185}
187 186
188Server::~Server() 187Server::~Server()
189{ 188{
190 serverGui->destroyGUI(); 189 serverGui->destroyGUI();
191 delete docList; 190 delete docList;
192 delete qcopBridge; 191 delete qcopBridge;
193 delete transferServer; 192 delete transferServer;
194 delete serverGui; 193 delete serverGui;
195#if 0 194#if 0
196 delete tsmMonitor; 195 delete tsmMonitor;
197#endif 196#endif
198} 197}
199 198
200static bool hasVisibleWindow(const QString& clientname, bool partial) 199static bool hasVisibleWindow(const QString& clientname, bool partial)
201{ 200{
202#ifdef QWS 201#ifdef QWS
203 const QList<QWSWindow> &list = qwsServer->clientWindows(); 202 const QList<QWSWindow> &list = qwsServer->clientWindows();
204 QWSWindow* w; 203 QWSWindow* w;
205 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 204 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
206 if ( w->client()->identity() == clientname ) { 205 if ( w->client()->identity() == clientname ) {
207 if ( partial && !w->isFullyObscured() ) 206 if ( partial && !w->isFullyObscured() )
208 return TRUE; 207 return TRUE;
209 if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { 208 if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) {
210# if QT_VERSION < 0x030000 209# if QT_VERSION < 0x030000
211 QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, 210 QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect,
212 QSize(qt_screen->width(),qt_screen->height()) ); 211 QSize(qt_screen->width(),qt_screen->height()) );
213# else 212# else
214 QRect mwr = qt_maxWindowRect; 213 QRect mwr = qt_maxWindowRect;
215# endif 214# endif
216 if ( mwr.contains(w->requested().boundingRect()) ) 215 if ( mwr.contains(w->requested().boundingRect()) )
217 return TRUE; 216 return TRUE;
218 } 217 }
219 } 218 }
220 } 219 }
221#endif 220#endif
222 return FALSE; 221 return FALSE;
223} 222}
224 223
225void Server::activate(const Opie::ODeviceButton* button, bool held) 224void Server::activate(const Opie::ODeviceButton* button, bool held)
226{ 225{
227 Global::terminateBuiltin("calibrate"); // No tr 226 Global::terminateBuiltin("calibrate"); // No tr
228 Opie::OQCopMessage om; 227 Opie::OQCopMessage om;
229 if ( held ) { 228 if ( held ) {
230 om = button->heldAction(); 229 om = button->heldAction();
231 } else { 230 } else {
232 om = button->pressedAction(); 231 om = button->pressedAction();
233 } 232 }
234 233
235 if ( om.channel() != "ignore" ) 234 if ( om.channel() != "ignore" )
236 om.send(); 235 om.send();
237 236
238 // A button with no action defined, will return a null ServiceRequest. Don't attempt 237 // A button with no action defined, will return a null ServiceRequest. Don't attempt
239 // to send/do anything with this as it will crash 238 // to send/do anything with this as it will crash
240 /* ### FIXME */ 239 /* ### FIXME */
241#if 0 240#if 0
242 if ( !sr.isNull() ) { 241 if ( !sr.isNull() ) {
243 QString app = sr.app(); 242 QString app = sr.app();
244 bool vis = hasVisibleWindow(app, app != "qpe"); 243 bool vis = hasVisibleWindow(app, app != "qpe");
245 if ( sr.message() == "raise()" && vis ) { 244 if ( sr.message() == "raise()" && vis ) {
246 sr.setMessage("nextView()"); 245 sr.setMessage("nextView()");
247 } else { 246 } else {
248 // "back door" 247 // "back door"
249 sr << (int)vis; 248 sr << (int)vis;
250 } 249 }
251 250
252 sr.send(); 251 sr.send();
253 } 252 }
254#endif 253#endif
255} 254}
256 255
257 256
258#ifdef Q_WS_QWS 257#ifdef Q_WS_QWS
259 258
260 259
261typedef struct KeyOverride { 260typedef struct KeyOverride {
262 ushort scan_code; 261 ushort scan_code;
263 QWSServer::KeyMap map; 262 QWSServer::KeyMap map;
264}; 263};
265 264
266 265
267static const KeyOverride jp109keys[] = { 266static const KeyOverride jp109keys[] = {
268 { 0x03, { Qt::Key_2, '2' , 0x22 , 0xffff } }, 267 { 0x03, { Qt::Key_2, '2' , 0x22 , 0xffff } },
269 { 0x07, { Qt::Key_6, '6' , '&' , 0xffff } }, 268 { 0x07, { Qt::Key_6, '6' , '&' , 0xffff } },
270 { 0x08, { Qt::Key_7, '7' , '\'' , 0xffff } }, 269 { 0x08, { Qt::Key_7, '7' , '\'' , 0xffff } },
271 { 0x09, { Qt::Key_8, '8' , '(' , 0xffff } }, 270 { 0x09, { Qt::Key_8, '8' , '(' , 0xffff } },
272 { 0x0a, { Qt::Key_9, '9' , ')' , 0xffff } }, 271 { 0x0a, { Qt::Key_9, '9' , ')' , 0xffff } },
273 { 0x0b, { Qt::Key_0, '0' , 0xffff , 0xffff } }, 272 { 0x0b, { Qt::Key_0, '0' , 0xffff , 0xffff } },
274 { 0x0c, { Qt::Key_Minus, '-' , '=' , 0xffff } }, 273 { 0x0c, { Qt::Key_Minus, '-' , '=' , 0xffff } },
275 { 0x0d, { Qt::Key_AsciiCircum,'^' , '~' , '^' - 64 } }, 274 { 0x0d, { Qt::Key_AsciiCircum,'^' , '~' , '^' - 64 } },
276 { 0x1a, { Qt::Key_At, '@' , '`' , 0xffff } }, 275 { 0x1a, { Qt::Key_At, '@' , '`' , 0xffff } },
277 { 0x1b, { Qt::Key_BraceLeft, '[' , '{' , '[' - 64 } }, 276 { 0x1b, { Qt::Key_BraceLeft, '[' , '{' , '[' - 64 } },
278 { 0x27, { Qt::Key_Semicolon, ';' , '+' , 0xffff } }, 277 { 0x27, { Qt::Key_Semicolon, ';' , '+' , 0xffff } },
279 { 0x28, { Qt::Key_Colon, ':' , '*' , 0xffff } }, 278 { 0x28, { Qt::Key_Colon, ':' , '*' , 0xffff } },
280 { 0x29, { Qt::Key_Zenkaku_Hankaku, 0xffff , 0xffff , 0xffff } }, 279 { 0x29, { Qt::Key_Zenkaku_Hankaku, 0xffff , 0xffff , 0xffff } },
281 { 0x2b, { Qt::Key_BraceRight, ']' , '}' , ']'-64 } }, 280 { 0x2b, { Qt::Key_BraceRight, ']' , '}' , ']'-64 } },
282 { 0x70, { Qt::Key_Hiragana_Katakana, 0xffff , 0xffff , 0xffff } }, 281 { 0x70, { Qt::Key_Hiragana_Katakana, 0xffff , 0xffff , 0xffff } },
283 { 0x73, { Qt::Key_Backslash, '\\' , '_' , 0xffff } }, 282 { 0x73, { Qt::Key_Backslash, '\\' , '_' , 0xffff } },
284 { 0x79, { Qt::Key_Henkan, 0xffff , 0xffff , 0xffff } }, 283 { 0x79, { Qt::Key_Henkan, 0xffff , 0xffff , 0xffff } },
285 { 0x7b, { Qt::Key_Muhenkan, 0xffff , 0xffff , 0xffff } }, 284 { 0x7b, { Qt::Key_Muhenkan, 0xffff , 0xffff , 0xffff } },
286 { 0x7d, { Qt::Key_yen, 0x00a5 , '|' , 0xffff } }, 285 { 0x7d, { Qt::Key_yen, 0x00a5 , '|' , 0xffff } },
287 { 0x00, { 0, 0xffff , 0xffff , 0xffff } } 286 { 0x00, { 0, 0xffff , 0xffff , 0xffff } }
288}; 287};
289 288
290bool Server::setKeyboardLayout( const QString &kb ) 289bool Server::setKeyboardLayout( const QString &kb )
291{ 290{
292 //quick demo version that can be extended 291 //quick demo version that can be extended
293 292
294 QIntDict<QWSServer::KeyMap> *om = 0; 293 QIntDict<QWSServer::KeyMap> *om = 0;
295 if ( kb == "us101" ) { // No tr 294 if ( kb == "us101" ) { // No tr
296 om = 0; 295 om = 0;
297 } else if ( kb == "jp109" ) { 296 } else if ( kb == "jp109" ) {
298 om = new QIntDict<QWSServer::KeyMap>(37); 297 om = new QIntDict<QWSServer::KeyMap>(37);
299 const KeyOverride *k = jp109keys; 298 const KeyOverride *k = jp109keys;
300 while ( k->scan_code ) { 299 while ( k->scan_code ) {
301 om->insert( k->scan_code, &k->map ); 300 om->insert( k->scan_code, &k->map );
302 k++; 301 k++;
303 } 302 }
304 } 303 }
305 QWSServer::setOverrideKeys( om ); 304 QWSServer::setOverrideKeys( om );
306 305
307 return TRUE; 306 return TRUE;
308} 307}
309 308
310#endif 309#endif
311 310
312void Server::systemMsg(const QCString &msg, const QByteArray &data) 311void Server::systemMsg(const QCString &msg, const QByteArray &data)
313{ 312{
314 QDataStream stream( data, IO_ReadOnly ); 313 QDataStream stream( data, IO_ReadOnly );
315 314
316 if ( msg == "securityChanged()" ) { 315 if ( msg == "securityChanged()" ) {
317 if ( transferServer ) 316 if ( transferServer )
318 transferServer->authorizeConnections(); 317 transferServer->authorizeConnections();
319 if ( qcopBridge ) 318 if ( qcopBridge )
320 qcopBridge->authorizeConnections(); 319 qcopBridge->authorizeConnections();
321 } 320 }
322 /* ### FIXME support TempScreenSaverMode */ 321 /* ### FIXME support TempScreenSaverMode */
323#if 0 322#if 0
324 else if ( msg == "setTempScreenSaverMode(int,int)" ) { 323 else if ( msg == "setTempScreenSaverMode(int,int)" ) {
325 int mode, pid; 324 int mode, pid;
326 stream >> mode >> pid; 325 stream >> mode >> pid;
327 tsmMonitor->setTempMode(mode, pid); 326 tsmMonitor->setTempMode(mode, pid);
328 } 327 }
329#endif 328#endif
330 else if ( msg == "linkChanged(QString)" ) { 329 else if ( msg == "linkChanged(QString)" ) {
331 QString link; 330 QString link;
332 stream >> link; 331 stream >> link;
333 qDebug( "desktop.cpp systemMsg -> linkchanged( %s )", link.latin1() ); 332 qDebug( "desktop.cpp systemMsg -> linkchanged( %s )", link.latin1() );
334 docList->linkChanged(link); 333 docList->linkChanged(link);
335 } else if ( msg == "serviceChanged(QString)" ) { 334 } else if ( msg == "serviceChanged(QString)" ) {
336 MimeType::updateApplications(); 335 MimeType::updateApplications();
337 } else if ( msg == "mkdir(QString)" ) { 336 } else if ( msg == "mkdir(QString)" ) {
338 QString dir; 337 QString dir;
339 stream >> dir; 338 stream >> dir;
340 if ( !dir.isEmpty() ) 339 if ( !dir.isEmpty() )
341 mkdir( dir ); 340 mkdir( dir );
342 } else if ( msg == "rdiffGenSig(QString,QString)" ) { 341 } else if ( msg == "rdiffGenSig(QString,QString)" ) {
343 QString baseFile, sigFile; 342 QString baseFile, sigFile;
344 stream >> baseFile >> sigFile; 343 stream >> baseFile >> sigFile;
345 QRsync::generateSignature( baseFile, sigFile ); 344 QRsync::generateSignature( baseFile, sigFile );
346 } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { 345 } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) {
347 QString baseFile, sigFile, deltaFile; 346 QString baseFile, sigFile, deltaFile;
348 stream >> baseFile >> sigFile >> deltaFile; 347 stream >> baseFile >> sigFile >> deltaFile;
349 QRsync::generateDiff( baseFile, sigFile, deltaFile ); 348 QRsync::generateDiff( baseFile, sigFile, deltaFile );
350 } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { 349 } else if ( msg == "rdiffApplyPatch(QString,QString)" ) {
351 QString baseFile, deltaFile; 350 QString baseFile, deltaFile;
352 stream >> baseFile >> deltaFile; 351 stream >> baseFile >> deltaFile;
353 if ( !QFile::exists( baseFile ) ) { 352 if ( !QFile::exists( baseFile ) ) {
354 QFile f( baseFile ); 353 QFile f( baseFile );
355 f.open( IO_WriteOnly ); 354 f.open( IO_WriteOnly );
356 f.close(); 355 f.close();
357 } 356 }
358 QRsync::applyDiff( baseFile, deltaFile ); 357 QRsync::applyDiff( baseFile, deltaFile );
359#ifndef QT_NO_COP 358#ifndef QT_NO_COP
360 QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); 359 QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" );
361 e << baseFile; 360 e << baseFile;
362#endif 361#endif
363 } else if ( msg == "rdiffCleanup()" ) { 362 } else if ( msg == "rdiffCleanup()" ) {
364 mkdir( "/tmp/rdiff" ); 363 mkdir( "/tmp/rdiff" );
365 QDir dir; 364 QDir dir;
366 dir.setPath( "/tmp/rdiff" ); 365 dir.setPath( "/tmp/rdiff" );
367 QStringList entries = dir.entryList(); 366 QStringList entries = dir.entryList();
368 for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) 367 for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it )
369 dir.remove( *it ); 368 dir.remove( *it );
370 } else if ( msg == "sendHandshakeInfo()" ) { 369 } else if ( msg == "sendHandshakeInfo()" ) {
371 QString home = getenv( "HOME" ); 370 QString home = getenv( "HOME" );
372#ifndef QT_NO_COP 371#ifndef QT_NO_COP
373 QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); 372 QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" );
374 e << home; 373 e << home;
375 int locked = (int) ServerApplication::screenLocked(); 374 int locked = (int) ServerApplication::screenLocked();
376 e << locked; 375 e << locked;
377#endif 376#endif
378 377
379 } 378 }
380 /* 379 /*
381 * QtopiaDesktop relies on the major number 380 * QtopiaDesktop relies on the major number
382 * to start with 1. We're at 0.9 381 * to start with 1. We're at 0.9
383 * so wee need to fake at least 1.4 to be able 382 * so wee need to fake at least 1.4 to be able
384 * to sync with QtopiaDesktop1.6 383 * to sync with QtopiaDesktop1.6
385 */ 384 */
386 else if ( msg == "sendVersionInfo()" ) { 385 else if ( msg == "sendVersionInfo()" ) {
387 QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); 386 QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" );
388 /* ### FIXME Architecture ### */ 387 /* ### FIXME Architecture ### */
389 e << QString::fromLatin1("1.7") << "Uncustomized Device"; 388 e << QString::fromLatin1("1.7") << "Uncustomized Device";
390 } else if ( msg == "sendCardInfo()" ) { 389 } else if ( msg == "sendCardInfo()" ) {
391#ifndef QT_NO_COP 390#ifndef QT_NO_COP
392 QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); 391 QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" );
393#endif 392#endif
394 storage->update(); 393 storage->update();
395 const QList<FileSystem> &fs = storage->fileSystems(); 394 const QList<FileSystem> &fs = storage->fileSystems();
396 QListIterator<FileSystem> it ( fs ); 395 QListIterator<FileSystem> it ( fs );
397 QString s; 396 QString s;
398 QString homeDir = getenv("HOME"); 397 QString homeDir = getenv("HOME");
399 QString homeFs, homeFsPath; 398 QString homeFs, homeFsPath;
400 for ( ; it.current(); ++it ) { 399 for ( ; it.current(); ++it ) {
401 int k4 = (*it)->blockSize()/256; 400 int k4 = (*it)->blockSize()/256;
402 if ( (*it)->isRemovable() ) { 401 if ( (*it)->isRemovable() ) {
403 s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr 402 s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr
404 + QString::number( (*it)->availBlocks() * k4/4 ) 403 + QString::number( (*it)->availBlocks() * k4/4 )
405 + "K " + (*it)->options() + ";"; 404 + "K " + (*it)->options() + ";";
406 } else if ( homeDir.contains( (*it)->path() ) && 405 } else if ( homeDir.contains( (*it)->path() ) &&
407 (*it)->path().length() > homeFsPath.length() ) { 406 (*it)->path().length() > homeFsPath.length() ) {
408 homeFsPath = (*it)->path(); 407 homeFsPath = (*it)->path();
409 homeFs = 408 homeFs =
410 (*it)->name() + "=" + homeDir + "/Documents " // No tr 409 (*it)->name() + "=" + homeDir + "/Documents " // No tr
411 + QString::number( (*it)->availBlocks() * k4/4 ) 410 + QString::number( (*it)->availBlocks() * k4/4 )
412 + "K " + (*it)->options() + ";"; 411 + "K " + (*it)->options() + ";";
413 } 412 }
414 } 413 }
415 if ( !homeFs.isEmpty() ) 414 if ( !homeFs.isEmpty() )
416 s += homeFs; 415 s += homeFs;
417 416
418#ifndef QT_NO_COP 417#ifndef QT_NO_COP
419 e << s; 418 e << s;
420#endif 419#endif
421 } else if ( msg == "sendSyncDate(QString)" ) { 420 } else if ( msg == "sendSyncDate(QString)" ) {
422 QString app; 421 QString app;
423 stream >> app; 422 stream >> app;
424 Config cfg( "qpe" ); 423 Config cfg( "qpe" );
425 cfg.setGroup("SyncDate"); 424 cfg.setGroup("SyncDate");
426#ifndef QT_NO_COP 425#ifndef QT_NO_COP
427 QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); 426 QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" );
428 e << app << cfg.readEntry( app ); 427 e << app << cfg.readEntry( app );
429#endif 428#endif
430 //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(), 429 //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(),
431 //cfg.readEntry( app ).latin1() ); 430 //cfg.readEntry( app ).latin1() );
432 } else if ( msg == "setSyncDate(QString,QString)" ) { 431 } else if ( msg == "setSyncDate(QString,QString)" ) {
433 QString app, date; 432 QString app, date;
434 stream >> app >> date; 433 stream >> app >> date;
435 Config cfg( "qpe" ); 434 Config cfg( "qpe" );
436 cfg.setGroup("SyncDate"); 435 cfg.setGroup("SyncDate");
437 cfg.writeEntry( app, date ); 436 cfg.writeEntry( app, date );
438 //qDebug("setSyncDate(QString,QString) %s %s", app.latin1(), date.latin1()); 437 //qDebug("setSyncDate(QString,QString) %s %s", app.latin1(), date.latin1());
439 } else if ( msg == "startSync(QString)" ) { 438 } else if ( msg == "startSync(QString)" ) {
440 QString what; 439 QString what;
441 stream >> what; 440 stream >> what;
442 delete syncDialog; 441 delete syncDialog;
443 syncDialog = new SyncDialog( this, what ); 442 syncDialog = new SyncDialog( this, what );
444 syncDialog->show(); 443 syncDialog->show();
445 connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); 444 connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) );
446 } else if ( msg == "stopSync()") { 445 } else if ( msg == "stopSync()") {
447 delete syncDialog; 446 delete syncDialog;
448 syncDialog = 0; 447 syncDialog = 0;
449 } else if (msg == "restoreDone(QString)") { 448 } else if (msg == "restoreDone(QString)") {
450 docList->restoreDone(); 449 docList->restoreDone();
451 } else if ( msg == "getAllDocLinks()" ) { 450 } else if ( msg == "getAllDocLinks()" ) {
452 docList->sendAllDocLinks(); 451 docList->sendAllDocLinks();
453 } 452 }
454#ifdef Q_WS_QWS 453#ifdef Q_WS_QWS
455 else if ( msg == "setMouseProto(QString)" ) { 454 else if ( msg == "setMouseProto(QString)" ) {
456 QString mice; 455 QString mice;
457 stream >> mice; 456 stream >> mice;
458 setenv("QWS_MOUSE_PROTO",mice.latin1(),1); 457 setenv("QWS_MOUSE_PROTO",mice.latin1(),1);
459 qwsServer->openMouse(); 458 qwsServer->openMouse();
460 } else if ( msg == "setKeyboard(QString)" ) { 459 } else if ( msg == "setKeyboard(QString)" ) {
461 QString kb; 460 QString kb;
462 stream >> kb; 461 stream >> kb;
463 setenv("QWS_KEYBOARD",kb.latin1(),1); 462 setenv("QWS_KEYBOARD",kb.latin1(),1);
464 qwsServer->openKeyboard(); 463 qwsServer->openKeyboard();
465 464
466 } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) { 465 } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) {
467 int delay, period; 466 int delay, period;
468 stream >> delay >> period; 467 stream >> delay >> period;
469 qwsSetKeyboardAutoRepeat( delay, period ); 468 qwsSetKeyboardAutoRepeat( delay, period );
470 Config cfg( "qpe" ); 469 Config cfg( "qpe" );
471 cfg.setGroup("Keyboard"); 470 cfg.setGroup("Keyboard");
472 cfg.writeEntry( "RepeatDelay", delay ); 471 cfg.writeEntry( "RepeatDelay", delay );
473 cfg.writeEntry( "RepeatPeriod", period ); 472 cfg.writeEntry( "RepeatPeriod", period );
474 } else if ( msg == "setKeyboardLayout(QString)" ) { 473 } else if ( msg == "setKeyboardLayout(QString)" ) {
475 QString kb; 474 QString kb;
476 stream >> kb; 475 stream >> kb;
477 setKeyboardLayout( kb ); 476 setKeyboardLayout( kb );
478 Config cfg( "qpe" ); 477 Config cfg( "qpe" );
479 cfg.setGroup("Keyboard"); 478 cfg.setGroup("Keyboard");
480 cfg.writeEntry( "Layout", kb ); 479 cfg.writeEntry( "Layout", kb );
481 } else if ( msg == "autoStart(QString)" ) { 480 } else if ( msg == "autoStart(QString)" ) {
482 QString appName; 481 QString appName;
483 stream >> appName; 482 stream >> appName;
484 Config cfg( "autostart" ); 483 Config cfg( "autostart" );
485 cfg.setGroup( "AutoStart" ); 484 cfg.setGroup( "AutoStart" );
486 if ( appName.compare("clear") == 0){ 485 if ( appName.compare("clear") == 0){
487 cfg.writeEntry("Apps", ""); 486 cfg.writeEntry("Apps", "");
488 } 487 }
489 } else if ( msg == "autoStart(QString,QString)" ) { 488 } else if ( msg == "autoStart(QString,QString)" ) {
490 QString modifier, appName; 489 QString modifier, appName;
491 stream >> modifier >> appName; 490 stream >> modifier >> appName;
492 Config cfg( "autostart" ); 491 Config cfg( "autostart" );
493 cfg.setGroup( "AutoStart" ); 492 cfg.setGroup( "AutoStart" );
494 if ( modifier.compare("add") == 0 ){ 493 if ( modifier.compare("add") == 0 ){
495 // only add if appname is entered 494 // only add if appname is entered
496 if (!appName.isEmpty()) { 495 if (!appName.isEmpty()) {
497 cfg.writeEntry("Apps", appName); 496 cfg.writeEntry("Apps", appName);
498 } 497 }
499 } else if (modifier.compare("remove") == 0 ) { 498 } else if (modifier.compare("remove") == 0 ) {
500 // need to change for multiple entries 499 // need to change for multiple entries
501 // actually remove is right now simular to clear, but in future there 500 // actually remove is right now simular to clear, but in future there
502 // should be multiple apps in autostart possible. 501 // should be multiple apps in autostart possible.
503 QString checkName; 502 QString checkName;
504 checkName = cfg.readEntry("Apps", ""); 503 checkName = cfg.readEntry("Apps", "");
505 if (checkName == appName) { 504 if (checkName == appName) {
506 cfg.writeEntry("Apps", ""); 505 cfg.writeEntry("Apps", "");
507 } 506 }
508 } 507 }
509 // case the autostart feature should be delayed 508 // case the autostart feature should be delayed
510 } else if ( msg == "autoStart(QString,QString,QString)") { 509 } else if ( msg == "autoStart(QString,QString,QString)") {
511 QString modifier, appName, delay; 510 QString modifier, appName, delay;
512 stream >> modifier >> appName >> delay; 511 stream >> modifier >> appName >> delay;
513 Config cfg( "autostart" ); 512 Config cfg( "autostart" );
514 513
515 cfg.setGroup( "AutoStart" ); 514 cfg.setGroup( "AutoStart" );
516 if ( modifier.compare("add") == 0 ){ 515 if ( modifier.compare("add") == 0 ){
517 // only add it appname is entered 516 // only add it appname is entered
518 if (!appName.isEmpty()) { 517 if (!appName.isEmpty()) {
519 cfg.writeEntry("Apps", appName); 518 cfg.writeEntry("Apps", appName);
520 cfg.writeEntry("Delay", delay); 519 cfg.writeEntry("Delay", delay);
521 } 520 }
522 } else { 521 } else {
523 } 522 }
524 } 523 }
525#endif 524#endif
526} 525}
527 526
528void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) 527void Server::receiveTaskBar(const QCString &msg, const QByteArray &data)
529{ 528{
530 QDataStream stream( data, IO_ReadOnly ); 529 QDataStream stream( data, IO_ReadOnly );
531 530
532 if ( msg == "reloadApps()" ) { 531 if ( msg == "reloadApps()" ) {
533 docList->reloadAppLnks(); 532 docList->reloadAppLnks();
534 } else if ( msg == "soundAlarm()" ) { 533 } else if ( msg == "soundAlarm()" ) {
535 ServerApplication::soundAlarm(); 534 ServerApplication::soundAlarm();
536 } 535 }
537 else if ( msg == "setLed(int,bool)" ) { 536 else if ( msg == "setLed(int,bool)" ) {
538 int led, status; 537 int led, status;
539 stream >> led >> status; 538 stream >> led >> status;
540 539
541 QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); 540 QValueList <OLed> ll = ODevice::inst ( )-> ledList ( );
542 if ( ll. count ( )){ 541 if ( ll. count ( )){
543 OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; 542 OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0];
544 bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); 543 bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow );
545 544
546 ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off ); 545 ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off );
547 } 546 }
548 } 547 }
549} 548}
550 549
551void Server::cancelSync() 550void Server::cancelSync()
552{ 551{
553#ifndef QT_NO_COP 552#ifndef QT_NO_COP
554 QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); 553 QCopEnvelope e( "QPE/Desktop", "cancelSync()" );
555#endif 554#endif
556 delete syncDialog; 555 delete syncDialog;
557 syncDialog = 0; 556 syncDialog = 0;
558} 557}
559 558
560bool Server::mkdir(const QString &localPath) 559bool Server::mkdir(const QString &localPath)
561{ 560{
562 QDir fullDir(localPath); 561 QDir fullDir(localPath);
563 if (fullDir.exists()) 562 if (fullDir.exists())
564 return true; 563 return true;
565 564
566 // at this point the directory doesn't exist 565 // at this point the directory doesn't exist
567 // go through the directory tree and start creating the direcotories 566 // go through the directory tree and start creating the direcotories
568 // that don't exist; if we can't create the directories, return false 567 // that don't exist; if we can't create the directories, return false
569 568
570 QString dirSeps = "/"; 569 QString dirSeps = "/";
571 int dirIndex = localPath.find(dirSeps); 570 int dirIndex = localPath.find(dirSeps);
572 QString checkedPath; 571 QString checkedPath;
573 572
574 // didn't find any seps; weird, use the cur dir instead 573 // didn't find any seps; weird, use the cur dir instead
575 if (dirIndex == -1) { 574 if (dirIndex == -1) {
576 //qDebug("No seperators found in path %s", localPath.latin1()); 575 //qDebug("No seperators found in path %s", localPath.latin1());
577 checkedPath = QDir::currentDirPath(); 576 checkedPath = QDir::currentDirPath();
578 } 577 }
579 578
580 while (checkedPath != localPath) { 579 while (checkedPath != localPath) {
581 // no more seperators found, use the local path 580 // no more seperators found, use the local path
582 if (dirIndex == -1) 581 if (dirIndex == -1)
583 checkedPath = localPath; 582 checkedPath = localPath;
584 else { 583 else {
585 // the next directory to check 584 // the next directory to check
586 checkedPath = localPath.left(dirIndex) + "/"; 585 checkedPath = localPath.left(dirIndex) + "/";
587 // advance the iterator; the next dir seperator 586 // advance the iterator; the next dir seperator
588 dirIndex = localPath.find(dirSeps, dirIndex+1); 587 dirIndex = localPath.find(dirSeps, dirIndex+1);
589 } 588 }
590 589
591 QDir checkDir(checkedPath); 590 QDir checkDir(checkedPath);
592 if (!checkDir.exists()) { 591 if (!checkDir.exists()) {
593 //qDebug("mkdir making dir %s", checkedPath.latin1()); 592 //qDebug("mkdir making dir %s", checkedPath.latin1());
594 593
595 if (!checkDir.mkdir(checkedPath)) { 594 if (!checkDir.mkdir(checkedPath)) {
596 qDebug("Unable to make directory %s", checkedPath.latin1()); 595 qDebug("Unable to make directory %s", checkedPath.latin1());
597 return FALSE; 596 return FALSE;
598 } 597 }
599 } 598 }
600 599
601 } 600 }
602 return TRUE; 601 return TRUE;
603} 602}
604 603
605void Server::styleChange( QStyle &s ) 604void Server::styleChange( QStyle &s )
606{ 605{
607 QWidget::styleChange( s ); 606 QWidget::styleChange( s );
608} 607}
609 608
610void Server::startTransferServer() 609void Server::startTransferServer()
611{ 610{
612 if ( !qcopBridge ) { 611 if ( !qcopBridge ) {
613 // start qcop bridge server 612 // start qcop bridge server
614 qcopBridge = new QCopBridge( 4243 ); 613 qcopBridge = new QCopBridge( 4243 );
615 if ( qcopBridge->ok() ) { 614 if ( qcopBridge->ok() ) {
616 // ... OK 615 // ... OK
617 connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress &)), 616 connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress &)),
618 this, SLOT(syncConnectionClosed(const QHostAddress &)) ); 617 this, SLOT(syncConnectionClosed(const QHostAddress &)) );
619 } else { 618 } else {
620 delete qcopBridge; 619 delete qcopBridge;
621 qcopBridge = 0; 620 qcopBridge = 0;
622 } 621 }
623 } 622 }
624 if ( !transferServer ) { 623 if ( !transferServer ) {
625 // start transfer server 624 // start transfer server
626 transferServer = new TransferServer( 4242 ); 625 transferServer = new TransferServer( 4242 );
627 if ( transferServer->ok() ) { 626 if ( transferServer->ok() ) {
628 // ... OK 627 // ... OK
629 } else { 628 } else {
630 delete transferServer; 629 delete transferServer;
631 transferServer = 0; 630 transferServer = 0;
632 } 631 }
633 } 632 }
634 if ( !transferServer || !qcopBridge ) 633 if ( !transferServer || !qcopBridge )
635 tid_xfer = startTimer( 2000 ); 634 tid_xfer = startTimer( 2000 );
636} 635}
637 636
638void Server::timerEvent( QTimerEvent *e ) 637void Server::timerEvent( QTimerEvent *e )
639{ 638{
640 if ( e->timerId() == tid_xfer ) { 639 if ( e->timerId() == tid_xfer ) {
641 killTimer( tid_xfer ); 640 killTimer( tid_xfer );
642 tid_xfer = 0; 641 tid_xfer = 0;
643 startTransferServer(); 642 startTransferServer();
644 } 643 }
645 /* ### FIXME today startin */ 644 /* ### FIXME today startin */
646#if 0 645#if 0
647 else if ( e->timerId() == tid_today ) { 646 else if ( e->timerId() == tid_today ) {
648 QDate today = QDate::currentDate(); 647 QDate today = QDate::currentDate();
649 if ( today != last_today_show ) { 648 if ( today != last_today_show ) {
650 last_today_show = today; 649 last_today_show = today;
651 Config cfg("today"); 650 Config cfg("today");
652 cfg.setGroup("Start"); 651 cfg.setGroup("Start");
653#ifndef QPE_DEFAULT_TODAY_MODE 652#ifndef QPE_DEFAULT_TODAY_MODE
654#define QPE_DEFAULT_TODAY_MODE "Never" 653#define QPE_DEFAULT_TODAY_MODE "Never"
655#endif 654#endif
656 if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { 655 if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) {
657 QCopEnvelope env(Service::channel("today"),"raise()"); 656 QCopEnvelope env(Service::channel("today"),"raise()");
658 } 657 }
659 } 658 }
660 } 659 }
661#endif 660#endif
662} 661}
663 662
664void Server::terminateServers() 663void Server::terminateServers()
665{ 664{
666 delete transferServer; 665 delete transferServer;
667 delete qcopBridge; 666 delete qcopBridge;
668 transferServer = 0; 667 transferServer = 0;
669 qcopBridge = 0; 668 qcopBridge = 0;
670} 669}
671 670
672void Server::syncConnectionClosed( const QHostAddress & ) 671void Server::syncConnectionClosed( const QHostAddress & )
673{ 672{
674 qDebug( "Lost sync connection" ); 673 qDebug( "Lost sync connection" );
675 delete syncDialog; 674 delete syncDialog;
676 syncDialog = 0; 675 syncDialog = 0;
677} 676}
678 677
679void Server::pokeTimeMonitors() 678void Server::pokeTimeMonitors()
680{ 679{
681#if 0 680#if 0
682 // inform all TimeMonitors 681 // inform all TimeMonitors
683 QStrList tms = Service::channels("TimeMonitor"); 682 QStrList tms = Service::channels("TimeMonitor");
684 for (const char* ch = tms.first(); ch; ch=tms.next()) { 683 for (const char* ch = tms.first(); ch; ch=tms.next()) {
685 QString t = getenv("TZ"); 684 QString t = getenv("TZ");
686 QCopEnvelope e(ch, "timeChange(QString)"); 685 QCopEnvelope e(ch, "timeChange(QString)");
687 e << t; 686 e << t;
688 } 687 }
689#endif 688#endif
690} 689}
691 690
692void Server::applicationLaunched(int, const QString &app) 691void Server::applicationLaunched(int, const QString &app)
693{ 692{
694 serverGui->applicationStateChanged( app, ServerInterface::Launching ); 693 serverGui->applicationStateChanged( app, ServerInterface::Launching );
695} 694}
696 695
697void Server::applicationTerminated(int pid, const QString &app) 696void Server::applicationTerminated(int pid, const QString &app)
698{ 697{
699 serverGui->applicationStateChanged( app, ServerInterface::Terminated ); 698 serverGui->applicationStateChanged( app, ServerInterface::Terminated );
700#if 0 699#if 0
701 tsmMonitor->applicationTerminated( pid ); 700 tsmMonitor->applicationTerminated( pid );
702#endif 701#endif
703} 702}
704 703
705void Server::applicationConnected(const QString &app) 704void Server::applicationConnected(const QString &app)
706{ 705{
707 serverGui->applicationStateChanged( app, ServerInterface::Running ); 706 serverGui->applicationStateChanged( app, ServerInterface::Running );
708} 707}
709 708
710void Server::storageChanged() 709void Server::storageChanged()
711{ 710{
712 system( "qtopia-update-symlinks" ); 711 system( "qtopia-update-symlinks" );
713 serverGui->storageChanged( storage->fileSystems() ); 712 serverGui->storageChanged( storage->fileSystems() );
714 docList->storageChanged(); 713 docList->storageChanged();
715} 714}
716 715
717 716
718 717
719void Server::preloadApps() 718void Server::preloadApps()
720{ 719{
721 Config cfg("Launcher"); 720 Config cfg("Launcher");
722 cfg.setGroup("Preload"); 721 cfg.setGroup("Preload");
723 QStringList apps = cfg.readListEntry("Apps",','); 722 QStringList apps = cfg.readListEntry("Apps",',');
724 for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { 723 for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) {
725#ifndef QT_NO_COP 724#ifndef QT_NO_COP
726 QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); 725 QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()");
727#endif 726#endif
728 } 727 }
729} 728}
730 729
diff --git a/core/launcher/shutdownimpl.cpp b/core/launcher/shutdownimpl.cpp
index 899d9ac..f43a2a3 100644
--- a/core/launcher/shutdownimpl.cpp
+++ b/core/launcher/shutdownimpl.cpp
@@ -1,174 +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 "shutdownimpl.h" 21#include "shutdownimpl.h"
22 22
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
25 25
26#include <qtimer.h> 26#include <qtimer.h>
27#include <qprogressbar.h> 27#include <qprogressbar.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qbuttongroup.h> 29#include <qbuttongroup.h>
30#include <qlabel.h> 30#include <qlabel.h>
31#include <qlayout.h> 31#include <qlayout.h>
32#include <qpalette.h>
33 32
34 33
35static void changeButtonColor ( QPushButton *btn, const QColor &col ) 34static void changeButtonColor ( QPushButton *btn, const QColor &col )
36{ 35{
37 QPalette pal = btn-> palette ( ); 36 QPalette pal = btn-> palette ( );
38 37
39 pal. setColor ( QPalette::Active, QColorGroup::Button, col ); 38 pal. setColor ( QPalette::Active, QColorGroup::Button, col );
40 pal. setColor ( QPalette::Disabled, QColorGroup::Button, col ); 39 pal. setColor ( QPalette::Disabled, QColorGroup::Button, col );
41 pal. setColor ( QPalette::Inactive, QColorGroup::Button, col ); 40 pal. setColor ( QPalette::Inactive, QColorGroup::Button, col );
42 41
43 btn-> setPalette ( pal ); 42 btn-> setPalette ( pal );
44} 43}
45 44
46 45
47ShutdownImpl::ShutdownImpl( QWidget* parent, const char *name, WFlags fl ) 46ShutdownImpl::ShutdownImpl( QWidget* parent, const char *name, WFlags fl )
48 : QWidget ( parent, name, fl ) 47 : QWidget ( parent, name, fl )
49{ 48{
50 setCaption ( tr( "Shutdown..." ) ); 49 setCaption ( tr( "Shutdown..." ) );
51 50
52 QVBoxLayout *vbox = new QVBoxLayout ( this ); 51 QVBoxLayout *vbox = new QVBoxLayout ( this );
53 vbox-> setSpacing ( 3 ); 52 vbox-> setSpacing ( 3 );
54 vbox-> setMargin ( 6 ); 53 vbox-> setMargin ( 6 );
55 54
56 QButtonGroup *btngrp = new QButtonGroup ( this ); 55 QButtonGroup *btngrp = new QButtonGroup ( this );
57 56
58 btngrp-> setTitle ( tr( "Terminate" ) ); 57 btngrp-> setTitle ( tr( "Terminate" ) );
59 btngrp-> setColumnLayout ( 0, Qt::Vertical ); 58 btngrp-> setColumnLayout ( 0, Qt::Vertical );
60 btngrp-> layout ( ) -> setSpacing ( 0 ); 59 btngrp-> layout ( ) -> setSpacing ( 0 );
61 btngrp-> layout ( ) -> setMargin ( 0 ); 60 btngrp-> layout ( ) -> setMargin ( 0 );
62 61
63 QGridLayout *grid = new QGridLayout ( btngrp-> layout ( ) ); 62 QGridLayout *grid = new QGridLayout ( btngrp-> layout ( ) );
64 grid-> setAlignment ( Qt::AlignTop ); 63 grid-> setAlignment ( Qt::AlignTop );
65 grid-> setSpacing ( 3 ); 64 grid-> setSpacing ( 3 );
66 grid-> setMargin ( 7 ); 65 grid-> setMargin ( 7 );
67 66
68 QPushButton *quit = new QPushButton ( tr( "Terminate Opie" ), btngrp, "quit" ); 67 QPushButton *quit = new QPushButton ( tr( "Terminate Opie" ), btngrp, "quit" );
69 changeButtonColor ( quit, QColor ( 236, 236, 179 ) ); 68 changeButtonColor ( quit, QColor ( 236, 236, 179 ) );
70 btngrp-> insert ( quit, 4 ); 69 btngrp-> insert ( quit, 4 );
71 grid-> addWidget ( quit, 1, 1 ); 70 grid-> addWidget ( quit, 1, 1 );
72 71
73 QPushButton *reboot = new QPushButton ( tr( "Reboot" ), btngrp, "reboot" ); 72 QPushButton *reboot = new QPushButton ( tr( "Reboot" ), btngrp, "reboot" );
74 changeButtonColor ( reboot, QColor( 236, 183, 181 ) ); 73 changeButtonColor ( reboot, QColor( 236, 183, 181 ) );
75 btngrp-> insert ( reboot, 2 ); 74 btngrp-> insert ( reboot, 2 );
76 grid-> addWidget( reboot, 1, 0 ); 75 grid-> addWidget( reboot, 1, 0 );
77 76
78 QPushButton *restart = new QPushButton ( tr( "Restart Opie" ), btngrp, "restart" ); 77 QPushButton *restart = new QPushButton ( tr( "Restart Opie" ), btngrp, "restart" );
79 changeButtonColor ( restart, QColor( 236, 236, 179 ) ); 78 changeButtonColor ( restart, QColor( 236, 236, 179 ) );
80 btngrp-> insert ( restart, 3 ); 79 btngrp-> insert ( restart, 3 );
81 grid-> addWidget ( restart, 0, 1 ); 80 grid-> addWidget ( restart, 0, 1 );
82 81
83 QPushButton *shutdown = new QPushButton( tr( "Shutdown" ), btngrp, "shutdown" ); 82 QPushButton *shutdown = new QPushButton( tr( "Shutdown" ), btngrp, "shutdown" );
84 changeButtonColor ( shutdown, QColor( 236, 183, 181 ) ); 83 changeButtonColor ( shutdown, QColor( 236, 183, 181 ) );
85 btngrp-> insert ( shutdown, 1 ); 84 btngrp-> insert ( shutdown, 1 );
86 grid-> addWidget ( shutdown, 0, 0 ); 85 grid-> addWidget ( shutdown, 0, 0 );
87 86
88 vbox-> addWidget ( btngrp ); 87 vbox-> addWidget ( btngrp );
89 88
90 m_info = new QLabel ( this, "info" ); 89 m_info = new QLabel ( this, "info" );
91 m_info-> setText( tr( "<p>\n" "These termination options are provided primarily for use while developing and testing the Opie system. In a normal environment, these concepts are unnecessary." ) ); 90 m_info-> setText( tr( "<p>\n" "These termination options are provided primarily for use while developing and testing the Opie system. In a normal environment, these concepts are unnecessary." ) );
92 vbox-> addWidget ( m_info ); 91 vbox-> addWidget ( m_info );
93 92
94 m_progress = new QProgressBar ( this, "progressBar" ); 93 m_progress = new QProgressBar ( this, "progressBar" );
95 m_progress-> setFrameShape ( QProgressBar::Panel ); 94 m_progress-> setFrameShape ( QProgressBar::Panel );
96 m_progress-> setFrameShadow ( QProgressBar::Sunken ); 95 m_progress-> setFrameShadow ( QProgressBar::Sunken );
97 m_progress-> setTotalSteps ( 20 ); 96 m_progress-> setTotalSteps ( 20 );
98 m_progress-> setIndicatorFollowsStyle ( false ); 97 m_progress-> setIndicatorFollowsStyle ( false );
99 vbox-> addWidget ( m_progress ); 98 vbox-> addWidget ( m_progress );
100 99
101 vbox-> addItem ( new QSpacerItem ( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 100 vbox-> addItem ( new QSpacerItem ( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
102 101
103 QPushButton *cancel = new QPushButton ( tr( "Cancel" ), this, "cancel" ); 102 QPushButton *cancel = new QPushButton ( tr( "Cancel" ), this, "cancel" );
104 changeButtonColor ( cancel, QColor( 181, 222, 178 ) ); 103 changeButtonColor ( cancel, QColor( 181, 222, 178 ) );
105 cancel-> setDefault ( true ); 104 cancel-> setDefault ( true );
106 cancel-> setSizePolicy ( QSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding, cancel-> sizePolicy ( ). hasHeightForWidth ( ) ) ); 105 cancel-> setSizePolicy ( QSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding, cancel-> sizePolicy ( ). hasHeightForWidth ( ) ) );
107 vbox-> addWidget ( cancel ); 106 vbox-> addWidget ( cancel );
108 107
109 m_timer = new QTimer ( this ); 108 m_timer = new QTimer ( this );
110 connect ( m_timer, SIGNAL( timeout ( ) ), this, SLOT( timeout ( ) ) ); 109 connect ( m_timer, SIGNAL( timeout ( ) ), this, SLOT( timeout ( ) ) );
111 110
112 connect ( btngrp, SIGNAL( clicked ( int ) ), this, SLOT( buttonClicked ( int ) ) ); 111 connect ( btngrp, SIGNAL( clicked ( int ) ), this, SLOT( buttonClicked ( int ) ) );
113 connect ( cancel, SIGNAL( clicked ( ) ), this, SLOT( cancelClicked ( ) ) ); 112 connect ( cancel, SIGNAL( clicked ( ) ), this, SLOT( cancelClicked ( ) ) );
114 113
115 m_progress-> hide ( ); 114 m_progress-> hide ( );
116 Global::hideInputMethod ( ); 115 Global::hideInputMethod ( );
117} 116}
118 117
119void ShutdownImpl::buttonClicked ( int b ) 118void ShutdownImpl::buttonClicked ( int b )
120{ 119{
121 m_counter = 0; 120 m_counter = 0;
122 121
123 switch ( b ) { 122 switch ( b ) {
124 case 1: 123 case 1:
125 m_operation = ShutdownSystem; 124 m_operation = ShutdownSystem;
126 break; 125 break;
127 case 2: 126 case 2:
128 m_operation = RebootSystem; 127 m_operation = RebootSystem;
129 break; 128 break;
130 case 3: 129 case 3:
131 m_operation = RestartDesktop; 130 m_operation = RestartDesktop;
132 break; 131 break;
133 case 4: 132 case 4:
134 m_operation = TerminateDesktop; 133 m_operation = TerminateDesktop;
135 break; 134 break;
136 } 135 }
137 m_info-> hide ( ); 136 m_info-> hide ( );
138 m_progress-> show ( ); 137 m_progress-> show ( );
139 m_timer-> start ( 300 ); 138 m_timer-> start ( 300 );
140 timeout ( ); 139 timeout ( );
141} 140}
142 141
143void ShutdownImpl::cancelClicked ( ) 142void ShutdownImpl::cancelClicked ( )
144{ 143{
145 m_progress-> hide ( ); 144 m_progress-> hide ( );
146 m_info-> show ( ); 145 m_info-> show ( );
147 if ( m_timer-> isActive ( ) ) 146 if ( m_timer-> isActive ( ) )
148 m_timer-> stop ( ); 147 m_timer-> stop ( );
149 else 148 else
150 close ( ); 149 close ( );
151} 150}
152 151
153void ShutdownImpl::timeout ( ) 152void ShutdownImpl::timeout ( )
154{ 153{
155 if ( ( m_counter += 2 ) > m_progress-> totalSteps ( ) ) { 154 if ( ( m_counter += 2 ) > m_progress-> totalSteps ( ) ) {
156 m_progress-> hide ( ); 155 m_progress-> hide ( );
157 m_timer-> stop ( ); 156 m_timer-> stop ( );
158 emit shutdown ( m_operation ); 157 emit shutdown ( m_operation );
159 } 158 }
160 else 159 else
161 m_progress-> setProgress ( m_counter ); 160 m_progress-> setProgress ( m_counter );
162} 161}
163 162
164void ShutdownImpl::hide ( ) 163void ShutdownImpl::hide ( )
165{ 164{
166 if ( isVisible ( )) { 165 if ( isVisible ( )) {
167 // hack - shutdown is a launcher dialog, but treated like a standalone app 166 // hack - shutdown is a launcher dialog, but treated like a standalone app
168 QCopEnvelope e( "QPE/System", "closing(QString)" ); 167 QCopEnvelope e( "QPE/System", "closing(QString)" );
169 e << QString ( "shutdown" ); 168 e << QString ( "shutdown" );
170 169
171 } 170 }
172 QWidget::hide ( ); 171 QWidget::hide ( );
173} 172}
174 173
diff --git a/core/launcher/stabmon.cpp b/core/launcher/stabmon.cpp
index 4e5f290..f2d694b 100644
--- a/core/launcher/stabmon.cpp
+++ b/core/launcher/stabmon.cpp
@@ -1,102 +1,101 @@
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#include "stabmon.h" 22#include "stabmon.h"
23 23
24#ifdef QWS 24#ifdef QWS
25#include <qtopia/qcopenvelope_qws.h> 25#include <qtopia/qcopenvelope_qws.h>
26#endif 26#endif
27 27
28#include <qfile.h> 28#include <qfile.h>
29#include <qcstring.h>
30 29
31#include <sys/stat.h> 30#include <sys/stat.h>
32#if defined(Q_OS_LINUX) || defined(_OS_LINUX_) 31#if defined(Q_OS_LINUX) || defined(_OS_LINUX_)
33#include <unistd.h> 32#include <unistd.h>
34#endif 33#endif
35#include <stdlib.h> 34#include <stdlib.h>
36 35
37SysFileMonitor::SysFileMonitor(QObject* parent) : 36SysFileMonitor::SysFileMonitor(QObject* parent) :
38 QObject(parent) 37 QObject(parent)
39{ 38{
40 startTimer(2000); 39 startTimer(2000);
41} 40}
42 41
43const char * stab0 = "/var/run/stab"; 42const char * stab0 = "/var/run/stab";
44const char * stab1 = "/var/state/pcmcia/stab"; 43const char * stab1 = "/var/state/pcmcia/stab";
45const char * stab2 = "/var/lib/pcmcia/stab"; 44const char * stab2 = "/var/lib/pcmcia/stab";
46 45
47void SysFileMonitor::timerEvent(QTimerEvent*) 46void SysFileMonitor::timerEvent(QTimerEvent*)
48{ 47{
49 struct stat s; 48 struct stat s;
50 49
51 static const char * tab [] = { 50 static const char * tab [] = {
52 stab0, 51 stab0,
53 stab1, 52 stab1,
54 stab2 53 stab2
55 }; 54 };
56 static const int nstab = sizeof(tab)/sizeof(const char *); 55 static const int nstab = sizeof(tab)/sizeof(const char *);
57 static int last[nstab]; 56 static int last[nstab];
58 57
59 bool ch = FALSE; 58 bool ch = FALSE;
60 for ( int i=0; i<nstab; i++ ) { 59 for ( int i=0; i<nstab; i++ ) {
61 if ( ::stat(tab[i], &s)==0 && (long)s.st_mtime != last[i] ) { 60 if ( ::stat(tab[i], &s)==0 && (long)s.st_mtime != last[i] ) {
62 last[i] = (long)s.st_mtime; 61 last[i] = (long)s.st_mtime;
63 ch=TRUE; 62 ch=TRUE;
64 } 63 }
65 if ( ch ) { 64 if ( ch ) {
66#ifndef QT_NO_COP 65#ifndef QT_NO_COP
67 QCopEnvelope("QPE/Card", "stabChanged()" ); 66 QCopEnvelope("QPE/Card", "stabChanged()" );
68#endif 67#endif
69 break; 68 break;
70 } 69 }
71 } 70 }
72 71
73 // st_size is no use, it's 0 for /proc/mounts too. Read it all. 72 // st_size is no use, it's 0 for /proc/mounts too. Read it all.
74 static int mtabSize = 0; 73 static int mtabSize = 0;
75 QFile f( "/proc/mounts" ); 74 QFile f( "/proc/mounts" );
76 if ( f.open(IO_ReadOnly) ) { 75 if ( f.open(IO_ReadOnly) ) {
77#if 0 76#if 0
78 // readAll does not work correctly on sequential devices (as eg. /proc files) 77 // readAll does not work correctly on sequential devices (as eg. /proc files)
79 QByteArray ba = f.readAll(); 78 QByteArray ba = f.readAll();
80 if ( (int)ba.size() != mtabSize ) { 79 if ( (int)ba.size() != mtabSize ) {
81 mtabSize = (int)ba.size(); 80 mtabSize = (int)ba.size();
82#ifndef QT_NO_COP 81#ifndef QT_NO_COP
83 QCopEnvelope("QPE/Card", "mtabChanged()" ); 82 QCopEnvelope("QPE/Card", "mtabChanged()" );
84#endif 83#endif
85 } 84 }
86#else 85#else
87 QString s; 86 QString s;
88 while( !f.atEnd() ) { 87 while( !f.atEnd() ) {
89 QString tmp; 88 QString tmp;
90 f.readLine( tmp, 1024 ); 89 f.readLine( tmp, 1024 );
91 s += tmp; 90 s += tmp;
92 } 91 }
93 if ( (int)s.length() != mtabSize ) { 92 if ( (int)s.length() != mtabSize ) {
94 mtabSize = (int)s.length(); 93 mtabSize = (int)s.length();
95#ifndef QT_NO_COP 94#ifndef QT_NO_COP
96 QCopEnvelope("QPE/Card", "mtabChanged()" ); 95 QCopEnvelope("QPE/Card", "mtabChanged()" );
97#endif 96#endif
98 } 97 }
99#endif 98#endif
100 } 99 }
101} 100}
102 101
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp
index c199063..f3a7651 100644
--- a/core/launcher/startmenu.cpp
+++ b/core/launcher/startmenu.cpp
@@ -1,394 +1,390 @@
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// TODO. During startup 21// TODO. During startup
22// Launcher::typeAdded 22// Launcher::typeAdded
23// is called for each new tab and calls then each time the refresh of startmenu 23// is called for each new tab and calls then each time the refresh of startmenu
24// suboptimal 24// suboptimal
25 25
26#define INCLUDE_MENUITEM_DEF 26#define INCLUDE_MENUITEM_DEF
27 27
28#include "startmenu.h" 28#include "startmenu.h"
29 29
30#include <qtopia/qpeapplication.h> 30#include <qtopia/qpeapplication.h>
31#include <qtopia/config.h> 31#include <qtopia/config.h>
32#include <qtopia/applnk.h>
33#include <qtopia/global.h>
34#include <qtopia/resource.h> 32#include <qtopia/resource.h>
35#include <qtopia/mimetype.h> 33#include <qtopia/mimetype.h>
36#include <qtopia/qlibrary.h> 34#include <qtopia/qlibrary.h>
37 35
38#include <qdict.h>
39#include <qdir.h>
40//#include <qpainter.h> 36//#include <qpainter.h>
41 37
42//#include <stdlib.h> 38//#include <stdlib.h>
43 39
44 40
45#define APPLNK_ID_OFFSET 250 41#define APPLNK_ID_OFFSET 250
46#define NO_ID -1 42#define NO_ID -1
47 43
48 44
49void StartPopupMenu::keyPressEvent( QKeyEvent *e ) 45void StartPopupMenu::keyPressEvent( QKeyEvent *e )
50{ 46{
51 if ( e->key() == Key_F33 || e->key() == Key_Space ) { 47 if ( e->key() == Key_F33 || e->key() == Key_Space ) {
52 // "OK" button, little hacky 48 // "OK" button, little hacky
53 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0); 49 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0);
54 QPopupMenu::keyPressEvent( &ke ); 50 QPopupMenu::keyPressEvent( &ke );
55 } else { 51 } else {
56 QPopupMenu::keyPressEvent( e ); 52 QPopupMenu::keyPressEvent( e );
57 } 53 }
58} 54}
59 55
60//--------------------------------------------------------------------------- 56//---------------------------------------------------------------------------
61 57
62StartMenu::StartMenu(QWidget *parent) : QLabel( parent ) 58StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
63{ 59{
64 startButtonPixmap = "go"; // No tr 60 startButtonPixmap = "go"; // No tr
65 61
66 int sz = AppLnk::smallIconSize()+3; 62 int sz = AppLnk::smallIconSize()+3;
67 QPixmap pm; 63 QPixmap pm;
68 pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) ); 64 pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) );
69 setPixmap(pm); 65 setPixmap(pm);
70 setFocusPolicy( NoFocus ); 66 setFocusPolicy( NoFocus );
71 67
72 useWidePopupMenu = true; 68 useWidePopupMenu = true;
73 launchMenu = 0; 69 launchMenu = 0;
74 refreshMenu(); 70 refreshMenu();
75} 71}
76 72
77 73
78void StartMenu::mousePressEvent( QMouseEvent * ) 74void StartMenu::mousePressEvent( QMouseEvent * )
79{ 75{
80 launch(); 76 launch();
81} 77}
82 78
83 79
84StartMenu::~StartMenu() 80StartMenu::~StartMenu()
85{ 81{
86 clearApplets(); 82 clearApplets();
87} 83}
88 84
89void StartMenu::createMenu() 85void StartMenu::createMenu()
90{ 86{
91 clearApplets(); 87 clearApplets();
92 delete launchMenu; 88 delete launchMenu;
93 89
94 launchMenu = new StartPopupMenu( this ); 90 launchMenu = new StartPopupMenu( this );
95 loadMenu( launchMenu ); 91 loadMenu( launchMenu );
96 loadApplets(); 92 loadApplets();
97 93
98 bool result = currentItem || menuApplets.count(); 94 bool result = currentItem || menuApplets.count();
99 if ( result ) 95 if ( result )
100 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 96 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
101} 97}
102 98
103void StartMenu::refreshMenu() 99void StartMenu::refreshMenu()
104{ 100{
105 Config cfg( "StartMenu" ); 101 Config cfg( "StartMenu" );
106 cfg.setGroup( "Menu" ); 102 cfg.setGroup( "Menu" );
107 bool ltabs = cfg.readBoolEntry( "LauncherTabs", TRUE ); 103 bool ltabs = cfg.readBoolEntry( "LauncherTabs", TRUE );
108 bool lot = cfg.readBoolEntry( "LauncherOther", TRUE ); 104 bool lot = cfg.readBoolEntry( "LauncherOther", TRUE );
109 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE ); 105 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
110 106
111 if ( launchMenu && !(ltabs || lot) ) return; // nothing to do 107 if ( launchMenu && !(ltabs || lot) ) return; // nothing to do
112 108
113 createMenu(); 109 createMenu();
114} 110}
115 111
116void StartMenu::itemSelected( int id ) 112void StartMenu::itemSelected( int id )
117{ 113{
118 if ( id == NO_ID ) return; 114 if ( id == NO_ID ) return;
119 115
120 if ( id < 0 ) { 116 if ( id < 0 ) {
121 MenuApplet *applet = menuApplets.find( id ); 117 MenuApplet *applet = menuApplets.find( id );
122 if ( applet ) { 118 if ( applet ) {
123 applet->iface->activated(); 119 applet->iface->activated();
124 } 120 }
125 } else if ( id >= APPLNK_ID_OFFSET ) { 121 } else if ( id >= APPLNK_ID_OFFSET ) {
126 AppLnk * appLnk = appLnks.find( id ); 122 AppLnk * appLnk = appLnks.find( id );
127 if ( appLnk ) { 123 if ( appLnk ) {
128 appLnk->execute(); 124 appLnk->execute();
129 } 125 }
130 } else { 126 } else {
131 QString *tabName = tabNames.find( id ); 127 QString *tabName = tabNames.find( id );
132 if ( tabName ) { 128 if ( tabName ) {
133 emit tabSelected( *tabName ); 129 emit tabSelected( *tabName );
134 } 130 }
135 } 131 }
136} 132}
137 133
138void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file ) 134void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file )
139{ 135{
140 if ( file.right(8) == ".desktop" ) { 136 if ( file.right(8) == ".desktop" ) {
141 AppLnk* applnk = new AppLnk( dir.path() + "/" + file ); 137 AppLnk* applnk = new AppLnk( dir.path() + "/" + file );
142 if ( !applnk->isValid() ) { 138 if ( !applnk->isValid() ) {
143 delete applnk; 139 delete applnk;
144 return; 140 return;
145 } 141 }
146 142
147 if ( applnk->type() == "Separator" ) { // No tr 143 if ( applnk->type() == "Separator" ) { // No tr
148 menu->insertSeparator(); 144 menu->insertSeparator();
149 delete applnk; 145 delete applnk;
150 } else { 146 } else {
151 QPixmap test; 147 QPixmap test;
152 QImage img = Resource::loadImage( applnk->icon() ); 148 QImage img = Resource::loadImage( applnk->icon() );
153 if(!img.isNull() ) 149 if(!img.isNull() )
154 test.convertFromImage( 150 test.convertFromImage(
155 img.smoothScale( 151 img.smoothScale(
156 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 ); 152 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
157 153
158 menu->insertItem( test, applnk->name(), 154 menu->insertItem( test, applnk->name(),
159 currentItem + APPLNK_ID_OFFSET ); 155 currentItem + APPLNK_ID_OFFSET );
160 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk ); 156 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk );
161 currentItem++; 157 currentItem++;
162 } 158 }
163 } 159 }
164 160
165} 161}
166 162
167void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot ) 163void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot )
168{ 164{
169 // do some sanity checks and collect information 165 // do some sanity checks and collect information
170 166
171 if ( file == "." || file == ".." ) return; 167 if ( file == "." || file == ".." ) return;
172 168
173 Config cfg( dir.path() + "/" + file + "/.directory", Config::File ); 169 Config cfg( dir.path() + "/" + file + "/.directory", Config::File );
174 if ( !cfg.isValid() ) return; 170 if ( !cfg.isValid() ) return;
175 171
176 QString name = cfg.readEntry( "Name" ); 172 QString name = cfg.readEntry( "Name" );
177 QString icon = cfg.readEntry( "Icon" ); 173 QString icon = cfg.readEntry( "Icon" );
178 if ( !name || !icon ) return; 174 if ( !name || !icon ) return;
179 175
180 QDir subdir = QDir( dir ); 176 QDir subdir = QDir( dir );
181 subdir.cd( file ); 177 subdir.cd( file );
182 subdir.setFilter( QDir::Files ); 178 subdir.setFilter( QDir::Files );
183 subdir.setNameFilter( "*.desktop" ); 179 subdir.setNameFilter( "*.desktop" );
184 // we don' t show the menu if there are no entries 180 // we don' t show the menu if there are no entries
185 // perhaps one should check if there exist subsubdirs with entries... 181 // perhaps one should check if there exist subsubdirs with entries...
186 if ( subdir.entryList().isEmpty() ) return; 182 if ( subdir.entryList().isEmpty() ) return;
187 183
188 // checks were ok 184 // checks were ok
189 185
190 QPixmap test; 186 QPixmap test;
191 test.convertFromImage( Resource::loadImage( icon ).smoothScale( 187 test.convertFromImage( Resource::loadImage( icon ).smoothScale(
192 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 ); 188 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
193 189
194 if ( useWidePopupMenu ) { 190 if ( useWidePopupMenu ) {
195 // generate submenu 191 // generate submenu
196 QPopupMenu *submenu = new QPopupMenu( menu ); 192 QPopupMenu *submenu = new QPopupMenu( menu );
197 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 193 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
198 menu->insertItem( test, name, submenu, NO_ID ); 194 menu->insertItem( test, name, submenu, NO_ID );
199 195
200 // ltabs is true cause else we wouldn't stuck around.. 196 // ltabs is true cause else we wouldn't stuck around..
201 createMenuEntries( submenu, subdir, true, lot ); 197 createMenuEntries( submenu, subdir, true, lot );
202 } else { 198 } else {
203 // no submenus - just bring corresponding tab to front 199 // no submenus - just bring corresponding tab to front
204 menu->insertItem( test, name, currentItem ); 200 menu->insertItem( test, name, currentItem );
205 tabNames.insert( currentItem, new QString( file ) ); 201 tabNames.insert( currentItem, new QString( file ) );
206 currentItem++; 202 currentItem++;
207 } 203 }
208} 204}
209 205
210void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot ) 206void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot )
211{ 207{
212 if ( lot ) { 208 if ( lot ) {
213 dir.setFilter( QDir::Files ); 209 dir.setFilter( QDir::Files );
214 dir.setNameFilter( "*.desktop" ); 210 dir.setNameFilter( "*.desktop" );
215 QStringList files = dir.entryList(); 211 QStringList files = dir.entryList();
216 files.sort(); 212 files.sort();
217 213
218 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) { 214 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) {
219 createAppEntry( menu, dir, *it ); 215 createAppEntry( menu, dir, *it );
220 } 216 }
221 } 217 }
222 if ( ltabs ) { 218 if ( ltabs ) {
223 dir.setNameFilter( "*" ); 219 dir.setNameFilter( "*" );
224 dir.setFilter( QDir::Dirs ); 220 dir.setFilter( QDir::Dirs );
225 QStringList dirs = dir.entryList(); 221 QStringList dirs = dir.entryList();
226 dirs.sort(); 222 dirs.sort();
227 223
228 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) { 224 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) {
229 createDirEntry( menu, dir, *it, lot ); 225 createDirEntry( menu, dir, *it, lot );
230 } 226 }
231 } 227 }
232} 228}
233 229
234bool StartMenu::loadMenu( QPopupMenu *menu ) 230bool StartMenu::loadMenu( QPopupMenu *menu )
235{ 231{
236 Config cfg("StartMenu"); 232 Config cfg("StartMenu");
237 cfg.setGroup("Menu"); 233 cfg.setGroup("Menu");
238 234
239 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE); 235 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE);
240 bool lot = cfg.readBoolEntry("LauncherOther", TRUE); 236 bool lot = cfg.readBoolEntry("LauncherOther", TRUE);
241 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE ); 237 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
242 bool sepfirst = !ltabs && !lot; 238 bool sepfirst = !ltabs && !lot;
243 239
244 currentItem = 0; 240 currentItem = 0;
245 launchMenu->clear(); 241 launchMenu->clear();
246 242
247 appLnks.setAutoDelete( true ); 243 appLnks.setAutoDelete( true );
248 tabNames.setAutoDelete( true ); 244 tabNames.setAutoDelete( true );
249 appLnks.clear(); 245 appLnks.clear();
250 tabNames.clear(); 246 tabNames.clear();
251 appLnks.setAutoDelete( false ); 247 appLnks.setAutoDelete( false );
252 tabNames.setAutoDelete( false ); 248 tabNames.setAutoDelete( false );
253 249
254 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name ); 250 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name );
255 createMenuEntries( menu, dir, ltabs, lot ); 251 createMenuEntries( menu, dir, ltabs, lot );
256 252
257 if ( !menu->count() ) sepfirst = TRUE; 253 if ( !menu->count() ) sepfirst = TRUE;
258 254
259 launchMenu->setName( sepfirst ? "accessories" : "accessories_need_sep" ); // No tr 255 launchMenu->setName( sepfirst ? "accessories" : "accessories_need_sep" ); // No tr
260 256
261 return currentItem; 257 return currentItem;
262} 258}
263 259
264 260
265void StartMenu::launch() 261void StartMenu::launch()
266{ 262{
267 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height(); 263 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height();
268 264
269 if ( launchMenu->isVisible() ) 265 if ( launchMenu->isVisible() )
270 launchMenu->hide(); 266 launchMenu->hide();
271 else 267 else
272 launchMenu->popup( QPoint( 1, y ) ); 268 launchMenu->popup( QPoint( 1, y ) );
273} 269}
274 270
275 271
276 272
277 273
278static int compareAppletPositions(const void *b, const void *a) 274static int compareAppletPositions(const void *b, const void *a)
279{ 275{
280 const MenuApplet* aa = *(const MenuApplet**)a; 276 const MenuApplet* aa = *(const MenuApplet**)a;
281 const MenuApplet* ab = *(const MenuApplet**)b; 277 const MenuApplet* ab = *(const MenuApplet**)b;
282 int d = aa->iface->position() - ab->iface->position(); 278 int d = aa->iface->position() - ab->iface->position();
283 if ( d ) return d; 279 if ( d ) return d;
284 return QString::compare(aa->library->library(),ab->library->library()); 280 return QString::compare(aa->library->library(),ab->library->library());
285} 281}
286 282
287void StartMenu::clearApplets() 283void StartMenu::clearApplets()
288{ 284{
289 if ( launchMenu ) 285 if ( launchMenu )
290 launchMenu-> hide(); 286 launchMenu-> hide();
291 287
292 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) { 288 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
293 MenuApplet *applet = it.current(); 289 MenuApplet *applet = it.current();
294 if ( launchMenu ) { 290 if ( launchMenu ) {
295 launchMenu->removeItem( applet-> id ); 291 launchMenu->removeItem( applet-> id );
296 delete applet->popup; 292 delete applet->popup;
297 } 293 }
298 294
299 applet->iface->release(); 295 applet->iface->release();
300 applet->library->unload(); 296 applet->library->unload();
301 delete applet-> library; 297 delete applet-> library;
302 } 298 }
303 menuApplets.clear(); 299 menuApplets.clear();
304} 300}
305 301
306 302
307 303
308 304
309void StartMenu::loadApplets() 305void StartMenu::loadApplets()
310{ 306{
311 Config cfg( "StartMenu" ); 307 Config cfg( "StartMenu" );
312 cfg.setGroup( "Applets" ); 308 cfg.setGroup( "Applets" );
313 309
314 // SafeMode causes too much problems, so we disable it for now -- 310 // SafeMode causes too much problems, so we disable it for now --
315 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02 311 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02
316 // removed in the remerge PluginManager could handle it 312 // removed in the remerge PluginManager could handle it
317 // we don't currently use it -zecke 313 // we don't currently use it -zecke
318 314
319 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); 315 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' );
320 316
321 QString lang = getenv( "LANG" ); 317 QString lang = getenv( "LANG" );
322 QString path = QPEApplication::qpeDir() + "/plugins/applets"; 318 QString path = QPEApplication::qpeDir() + "/plugins/applets";
323 QDir dir( path, "lib*.so" ); 319 QDir dir( path, "lib*.so" );
324 QStringList list = dir.entryList(); 320 QStringList list = dir.entryList();
325 QStringList::Iterator it; 321 QStringList::Iterator it;
326 int napplets = 0; 322 int napplets = 0;
327 MenuApplet* *xapplets = new MenuApplet*[list.count()]; 323 MenuApplet* *xapplets = new MenuApplet*[list.count()];
328 for ( it = list.begin(); it != list.end(); ++it ) { 324 for ( it = list.begin(); it != list.end(); ++it ) {
329 if ( exclude.find( *it ) != exclude.end() ) 325 if ( exclude.find( *it ) != exclude.end() )
330 continue; 326 continue;
331 MenuAppletInterface *iface = 0; 327 MenuAppletInterface *iface = 0;
332 QLibrary *lib = new QLibrary( path + "/" + *it ); 328 QLibrary *lib = new QLibrary( path + "/" + *it );
333 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { 329 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) {
334 MenuApplet *applet = new MenuApplet; 330 MenuApplet *applet = new MenuApplet;
335 xapplets[napplets++] = applet; 331 xapplets[napplets++] = applet;
336 applet->library = lib; 332 applet->library = lib;
337 applet->iface = iface; 333 applet->iface = iface;
338 334
339 QTranslator *trans = new QTranslator(qApp); 335 QTranslator *trans = new QTranslator(qApp);
340 QString type = (*it).left( (*it).find(".") ); 336 QString type = (*it).left( (*it).find(".") );
341 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 337 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
342 if ( trans->load( tfn )) 338 if ( trans->load( tfn ))
343 qApp->installTranslator( trans ); 339 qApp->installTranslator( trans );
344 else 340 else
345 delete trans; 341 delete trans;
346 } else { 342 } else {
347 exclude += *it; 343 exclude += *it;
348 delete lib; 344 delete lib;
349 } 345 }
350 } 346 }
351 cfg.writeEntry( "ExcludeApplets", exclude, ',' ); 347 cfg.writeEntry( "ExcludeApplets", exclude, ',' );
352 qsort(xapplets, napplets, sizeof(menuApplets[0]), compareAppletPositions); 348 qsort(xapplets, napplets, sizeof(menuApplets[0]), compareAppletPositions);
353 349
354 350
355 while ( napplets-- ) { 351 while ( napplets-- ) {
356 MenuApplet *applet = xapplets[napplets]; 352 MenuApplet *applet = xapplets[napplets];
357 applet->popup = applet->iface->popup( this ); 353 applet->popup = applet->iface->popup( this );
358 354
359 // menuApplets got an id < -1 355 // menuApplets got an id < -1
360 menuApplets.insert( -( currentItem + 2 ), new MenuApplet( *applet ) ); 356 menuApplets.insert( -( currentItem + 2 ), new MenuApplet( *applet ) );
361 currentItem++; 357 currentItem++;
362 } 358 }
363 delete [] xapplets; 359 delete [] xapplets;
364 360
365 addApplets( launchMenu ); 361 addApplets( launchMenu );
366} 362}
367 363
368 364
369/* 365/*
370 * Launcher calls loadMenu too often fix that 366 * Launcher calls loadMenu too often fix that
371 */ 367 */
372void StartMenu::addApplets(QPopupMenu* pop) { 368void StartMenu::addApplets(QPopupMenu* pop) {
373 QIntDict<MenuApplet> dict; 369 QIntDict<MenuApplet> dict;
374 if( pop-> count ( )) 370 if( pop-> count ( ))
375 pop-> insertSeparator ( ); 371 pop-> insertSeparator ( );
376 372
377 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) { 373 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
378 MenuApplet *applet = it.current(); 374 MenuApplet *applet = it.current();
379 if ( applet->popup ) 375 if ( applet->popup )
380 applet->id = pop->insertItem( applet->iface->icon(), 376 applet->id = pop->insertItem( applet->iface->icon(),
381 applet->iface->text(), applet->popup ); 377 applet->iface->text(), applet->popup );
382 else 378 else
383 applet->id = pop->insertItem( applet->iface->icon(), 379 applet->id = pop->insertItem( applet->iface->icon(),
384 applet->iface->text() ); 380 applet->iface->text() );
385 381
386 382
387 dict.insert( applet->id, new MenuApplet( *applet ) ); 383 dict.insert( applet->id, new MenuApplet( *applet ) );
388 } 384 }
389 /* need to update the key */ 385 /* need to update the key */
390 menuApplets.setAutoDelete( true ); 386 menuApplets.setAutoDelete( true );
391 menuApplets.clear(); 387 menuApplets.clear();
392 menuApplets.setAutoDelete( false ); 388 menuApplets.setAutoDelete( false );
393 menuApplets = dict; 389 menuApplets = dict;
394} 390}
diff --git a/core/launcher/syncdialog.cpp b/core/launcher/syncdialog.cpp
index 6f6c781..4a2b8ff 100644
--- a/core/launcher/syncdialog.cpp
+++ b/core/launcher/syncdialog.cpp
@@ -1,184 +1,183 @@
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 "syncdialog.h" 21#include "syncdialog.h"
22 22
23#include <qtopia/resource.h> 23#include <qtopia/resource.h>
24 24
25#include <qimage.h>
26#include <qpainter.h> 25#include <qpainter.h>
27#include <qapplication.h> 26#include <qapplication.h>
28#include <qpushbutton.h> 27#include <qpushbutton.h>
29#include <qfile.h> 28#include <qfile.h>
30 29
31 30
32SyncDialog::SyncDialog( QWidget *parent, const QString &w ) 31SyncDialog::SyncDialog( QWidget *parent, const QString &w )
33 : QDialog( parent, "SyncDialog", FALSE, WStyle_Tool | WStyle_Customize | 32 : QDialog( parent, "SyncDialog", FALSE, WStyle_Tool | WStyle_Customize |
34 WStyle_StaysOnTop ), what(w), nextPt(0), rev(FALSE), hideDot(TRUE) 33 WStyle_StaysOnTop ), what(w), nextPt(0), rev(FALSE), hideDot(TRUE)
35{ 34{
36 QFont f( font() ); 35 QFont f( font() );
37 f.setPointSize( 16 ); 36 f.setPointSize( 16 );
38 setFont(f); 37 setFont(f);
39 38
40 loadPath(); 39 loadPath();
41 40
42 QSize ds = qApp->desktop()->size(); 41 QSize ds = qApp->desktop()->size();
43 setGeometry( 0, 0, ds.width(), ds.height() ); 42 setGeometry( 0, 0, ds.width(), ds.height() );
44 img = Resource::loadImage( "SyncScreen" ); 43 img = Resource::loadImage( "SyncScreen" );
45 if ( img.width() > ds.width() || img.height() > ds.height() ) { 44 if ( img.width() > ds.width() || img.height() > ds.height() ) {
46 path = scalePath( path, ds.width(), img.width(), ds.height(), img.height() ); 45 path = scalePath( path, ds.width(), img.width(), ds.height(), img.height() );
47 img = img.smoothScale( ds.width(), ds.height() ); 46 img = img.smoothScale( ds.width(), ds.height() );
48 } 47 }
49 dot = Resource::loadImage( "syncdot" ); 48 dot = Resource::loadImage( "syncdot" );
50 setBackgroundColor( white ); 49 setBackgroundColor( white );
51 50
52 QPushButton *pb = new QPushButton( tr("Abort"), this, "CancelSync" ); 51 QPushButton *pb = new QPushButton( tr("Abort"), this, "CancelSync" );
53 QSize bs = pb->sizeHint(); 52 QSize bs = pb->sizeHint();
54 bs.rwidth() += 10; 53 bs.rwidth() += 10;
55 bs.rheight() += 5; 54 bs.rheight() += 5;
56 pb->setGeometry( (ds.width()-bs.width())/2, 4*ds.height()/5, 55 pb->setGeometry( (ds.width()-bs.width())/2, 4*ds.height()/5,
57 bs.width(), bs.height() ); 56 bs.width(), bs.height() );
58 connect( pb, SIGNAL(clicked()), this, SIGNAL(cancel()) ); 57 connect( pb, SIGNAL(clicked()), this, SIGNAL(cancel()) );
59 58
60 if ( path.count() >= 2 ) { 59 if ( path.count() >= 2 ) {
61 path = generatePath( path, 8 ); 60 path = generatePath( path, 8 );
62 startTimer( 200 ); 61 startTimer( 200 );
63 } 62 }
64} 63}
65 64
66void SyncDialog::paintEvent( QPaintEvent *pe ) 65void SyncDialog::paintEvent( QPaintEvent *pe )
67{ 66{
68 QPainter p(this ); 67 QPainter p(this );
69 p.setClipRect( pe->rect() ); 68 p.setClipRect( pe->rect() );
70 int ox = (width() - img.width())/2; 69 int ox = (width() - img.width())/2;
71 int oy = (height() - img.height())/2; 70 int oy = (height() - img.height())/2;
72 71
73 QRect ir = QRect(ox, oy, img.width(), img.height()) & pe->rect(); 72 QRect ir = QRect(ox, oy, img.width(), img.height()) & pe->rect();
74 73
75 if ( ir.isValid() ) 74 if ( ir.isValid() )
76 p.drawImage( ir.x(), ir.y(), img, ir.x()-ox, ir.y()-oy, ir.width(), ir.height() ); 75 p.drawImage( ir.x(), ir.y(), img, ir.x()-ox, ir.y()-oy, ir.width(), ir.height() );
77 76
78 QString syncMsg = tr("Syncing:"); 77 QString syncMsg = tr("Syncing:");
79 p.setPen( black ); 78 p.setPen( black );
80 QRect r( 0, 0, width()/2-5, QMAX(oy,80) ); 79 QRect r( 0, 0, width()/2-5, QMAX(oy,80) );
81 p.drawText( r, AlignRight | AlignVCenter, syncMsg ); 80 p.drawText( r, AlignRight | AlignVCenter, syncMsg );
82 r.moveBy( width()/2, 0 ); 81 r.moveBy( width()/2, 0 );
83 QFont f( font() ); 82 QFont f( font() );
84 f.setWeight( QFont::Bold ); 83 f.setWeight( QFont::Bold );
85 p.setFont( f ); 84 p.setFont( f );
86 p.drawText( r, AlignLeft | AlignVCenter, what ); 85 p.drawText( r, AlignLeft | AlignVCenter, what );
87 86
88 if ( !hideDot ) 87 if ( !hideDot )
89 p.drawImage( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2, dot ); 88 p.drawImage( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2, dot );
90} 89}
91 90
92void SyncDialog::timerEvent( QTimerEvent * ) 91void SyncDialog::timerEvent( QTimerEvent * )
93{ 92{
94 int ox = (width() - img.width())/2; 93 int ox = (width() - img.width())/2;
95 int oy = (height() - img.height())/2; 94 int oy = (height() - img.height())/2;
96 int oldPt = nextPt; 95 int oldPt = nextPt;
97 96
98 if ( !rev ) { 97 if ( !rev ) {
99 nextPt++; 98 nextPt++;
100 if ( nextPt == (int)path.count() ) { 99 if ( nextPt == (int)path.count() ) {
101 nextPt -= 2; 100 nextPt -= 2;
102 rev = TRUE; 101 rev = TRUE;
103 } 102 }
104 } else { 103 } else {
105 nextPt--; 104 nextPt--;
106 if ( nextPt < 0 ) { 105 if ( nextPt < 0 ) {
107 nextPt = 1; 106 nextPt = 1;
108 rev = FALSE; 107 rev = FALSE;
109 } 108 }
110 } 109 }
111 110
112 hideDot = FALSE; 111 hideDot = FALSE;
113 repaint( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2, 112 repaint( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2,
114 dot.width(), dot.height() ); 113 dot.width(), dot.height() );
115 hideDot = TRUE; 114 hideDot = TRUE;
116 repaint( ox+path[oldPt].x()-dot.width()/2, oy+path[oldPt].y()-dot.height()/2, 115 repaint( ox+path[oldPt].x()-dot.width()/2, oy+path[oldPt].y()-dot.height()/2,
117 dot.width(), dot.height() ); 116 dot.width(), dot.height() );
118} 117}
119 118
120void SyncDialog::loadPath() 119void SyncDialog::loadPath()
121{ 120{
122 QString pfile = Resource::findPixmap( "syncdot" ); 121 QString pfile = Resource::findPixmap( "syncdot" );
123 if ( pfile.isEmpty() ) 122 if ( pfile.isEmpty() )
124 return; 123 return;
125 int dp = pfile.findRev('.'); 124 int dp = pfile.findRev('.');
126 pfile.replace( dp, pfile.length()-dp, ".path" ); 125 pfile.replace( dp, pfile.length()-dp, ".path" );
127 126
128 int count = 0; 127 int count = 0;
129 QFile file( pfile ); 128 QFile file( pfile );
130 if ( file.open( IO_ReadOnly ) ) { 129 if ( file.open( IO_ReadOnly ) ) {
131 QString line; 130 QString line;
132 while ( file.readLine( line, 256 ) > 0 ) { 131 while ( file.readLine( line, 256 ) > 0 ) {
133 int x, y; 132 int x, y;
134 if ( sscanf( line.latin1(), "%d %d", &x, &y ) == 2 ) { 133 if ( sscanf( line.latin1(), "%d %d", &x, &y ) == 2 ) {
135 path.resize( count+1 ); 134 path.resize( count+1 );
136 path[count++] = QPoint(x, y); 135 path[count++] = QPoint(x, y);
137 } 136 }
138 } 137 }
139 } 138 }
140} 139}
141 140
142QPointArray SyncDialog::scalePath( const QPointArray &pa, int xn, int xd, int yn, int yd ) 141QPointArray SyncDialog::scalePath( const QPointArray &pa, int xn, int xd, int yn, int yd )
143{ 142{
144 QPointArray sa( pa.size() ); 143 QPointArray sa( pa.size() );
145 144
146 for ( unsigned i = 0; i < pa.count(); i++ ) { 145 for ( unsigned i = 0; i < pa.count(); i++ ) {
147 int x = xn * pa[int(i)].x() / xd; 146 int x = xn * pa[int(i)].x() / xd;
148 int y = yn * pa[int(i)].y() / yd; 147 int y = yn * pa[int(i)].y() / yd;
149 sa[int(i)] = QPoint( x, y ); 148 sa[int(i)] = QPoint( x, y );
150 } 149 }
151 150
152 return sa; 151 return sa;
153} 152}
154 153
155QPointArray SyncDialog::generatePath( const QPointArray &pa, int dist ) 154QPointArray SyncDialog::generatePath( const QPointArray &pa, int dist )
156{ 155{
157 if ( pa.count() < 2 ) 156 if ( pa.count() < 2 )
158 return pa; 157 return pa;
159 158
160 QPointArray fa; 159 QPointArray fa;
161 int count = 0; 160 int count = 0;
162 fa.resize( count+1 ); 161 fa.resize( count+1 );
163 fa[count++] = pa[0]; 162 fa[count++] = pa[0];
164 for ( unsigned i = 0; i < pa.count()-1; i++ ) { 163 for ( unsigned i = 0; i < pa.count()-1; i++ ) {
165 int x1 = pa[int(i)].x(); 164 int x1 = pa[int(i)].x();
166 int y1 = pa[int(i)].y(); 165 int y1 = pa[int(i)].y();
167 int x2 = pa[int(i+1)].x(); 166 int x2 = pa[int(i+1)].x();
168 int y2 = pa[int(i+1)].y(); 167 int y2 = pa[int(i+1)].y();
169 int dx = x2 - x1; 168 int dx = x2 - x1;
170 int dy = y2 - y1; 169 int dy = y2 - y1;
171 int pts = (QMAX(QABS(dx),QABS(dy)) + dist/2 )/dist; 170 int pts = (QMAX(QABS(dx),QABS(dy)) + dist/2 )/dist;
172 for ( int j = 1; j < pts; j++ ) { 171 for ( int j = 1; j < pts; j++ ) {
173 int x = j * dx / pts; 172 int x = j * dx / pts;
174 int y = j * dy / pts; 173 int y = j * dy / pts;
175 fa.resize( count+1 ); 174 fa.resize( count+1 );
176 fa[count++] = pa[int(i)] + QPoint( x, y ); 175 fa[count++] = pa[int(i)] + QPoint( x, y );
177 } 176 }
178 fa.resize( count+1 ); 177 fa.resize( count+1 );
179 fa[count++] = pa[int(i+1)]; 178 fa[count++] = pa[int(i+1)];
180 } 179 }
181 180
182 return fa; 181 return fa;
183} 182}
184 183
diff --git a/core/launcher/systray.cpp b/core/launcher/systray.cpp
index 691f6b8..6cc1446 100644
--- a/core/launcher/systray.cpp
+++ b/core/launcher/systray.cpp
@@ -1,154 +1,152 @@
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 <qtopia/qpeapplication.h> 21#include <qtopia/qpeapplication.h>
22#include <qtopia/qlibrary.h> 22#include <qtopia/qlibrary.h>
23#include <qtopia/config.h> 23#include <qtopia/config.h>
24 24
25#include <qlayout.h> 25#include <qlayout.h>
26#include <qdir.h> 26#include <qdir.h>
27#include <qmessagebox.h>
28#include <qtranslator.h>
29 27
30#include "systray.h" 28#include "systray.h"
31 29
32#include <stdlib.h> 30#include <stdlib.h>
33 31
34/* ### Single build floppies ### */ 32/* ### Single build floppies ### */
35#if 0 33#if 0
36#ifdef QT_NO_COMPONENTS 34#ifdef QT_NO_COMPONENTS
37#include "../plugins/applets/clockapplet/clockappletimpl.h" 35#include "../plugins/applets/clockapplet/clockappletimpl.h"
38#endif 36#endif
39#endif 37#endif
40 38
41SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0) 39SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0)
42{ 40{
43 //setFrameStyle( QFrame::Panel | QFrame::Sunken ); 41 //setFrameStyle( QFrame::Panel | QFrame::Sunken );
44 loadApplets(); 42 loadApplets();
45} 43}
46 44
47SysTray::~SysTray() 45SysTray::~SysTray()
48{ 46{
49 clearApplets(); 47 clearApplets();
50} 48}
51 49
52static int compareAppletPositions(const void *a, const void *b) 50static int compareAppletPositions(const void *a, const void *b)
53{ 51{
54 const TaskbarApplet* aa = *(const TaskbarApplet**)a; 52 const TaskbarApplet* aa = *(const TaskbarApplet**)a;
55 const TaskbarApplet* ab = *(const TaskbarApplet**)b; 53 const TaskbarApplet* ab = *(const TaskbarApplet**)b;
56 int d = ab->iface->position() - aa->iface->position(); 54 int d = ab->iface->position() - aa->iface->position();
57 if ( d ) return d; 55 if ( d ) return d;
58 return QString::compare(ab->name,aa->name); 56 return QString::compare(ab->name,aa->name);
59} 57}
60 58
61void SysTray::loadApplets() 59void SysTray::loadApplets()
62{ 60{
63 hide(); 61 hide();
64 clearApplets(); 62 clearApplets();
65 addApplets(); 63 addApplets();
66} 64}
67 65
68void SysTray::clearApplets() 66void SysTray::clearApplets()
69{ 67{
70#ifndef QT_NO_COMPONENTS 68#ifndef QT_NO_COMPONENTS
71 69
72 /* 70 /*
73 * Note on clearing. SOme applets delete their 71 * Note on clearing. SOme applets delete their
74 * applets themselves some don't do it 72 * applets themselves some don't do it
75 * and on restart this can crash. If we delete it 73 * and on restart this can crash. If we delete it
76 * here we might end up in a double deletion. We could 74 * here we might end up in a double deletion. We could
77 * use QGuardedPtr but that would be one QOBject 75 * use QGuardedPtr but that would be one QOBject
78 * for every applet more but only useful for restart 76 * for every applet more but only useful for restart
79 */ 77 */
80 QValueList<TaskbarApplet>::Iterator mit; 78 QValueList<TaskbarApplet>::Iterator mit;
81 for ( mit = appletList.begin(); mit != appletList.end(); ++mit ) { 79 for ( mit = appletList.begin(); mit != appletList.end(); ++mit ) {
82 (*mit).iface->release(); 80 (*mit).iface->release();
83 (*mit).library->unload(); 81 (*mit).library->unload();
84 delete (*mit).library; 82 delete (*mit).library;
85 } 83 }
86 84
87#endif 85#endif
88 appletList.clear(); 86 appletList.clear();
89 if ( layout ) 87 if ( layout )
90 delete layout; 88 delete layout;
91 layout = new QHBoxLayout( this, 0, 1 ); 89 layout = new QHBoxLayout( this, 0, 1 );
92 layout->setAutoAdd(TRUE); 90 layout->setAutoAdd(TRUE);
93} 91}
94 92
95void SysTray::addApplets() 93void SysTray::addApplets()
96{ 94{
97 hide(); 95 hide();
98#ifndef QT_NO_COMPONENTS 96#ifndef QT_NO_COMPONENTS
99 Config cfg( "Taskbar" ); 97 Config cfg( "Taskbar" );
100 cfg.setGroup( "Applets" ); 98 cfg.setGroup( "Applets" );
101 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); 99 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' );
102 100
103 QString lang = getenv( "LANG" ); 101 QString lang = getenv( "LANG" );
104 QString path = QPEApplication::qpeDir() + "/plugins/applets"; 102 QString path = QPEApplication::qpeDir() + "/plugins/applets";
105#ifdef Q_OS_MACX 103#ifdef Q_OS_MACX
106 QDir dir( path, "lib*.dylib" ); 104 QDir dir( path, "lib*.dylib" );
107#else 105#else
108 QDir dir( path, "lib*.so" ); 106 QDir dir( path, "lib*.so" );
109#endif /* Q_OS_MACX */ 107#endif /* Q_OS_MACX */
110 QStringList list = dir.entryList(); 108 QStringList list = dir.entryList();
111 QStringList::Iterator it; 109 QStringList::Iterator it;
112 int napplets=0; 110 int napplets=0;
113 TaskbarApplet* *applets = new TaskbarApplet*[list.count()]; 111 TaskbarApplet* *applets = new TaskbarApplet*[list.count()];
114 for ( it = list.begin(); it != list.end(); ++it ) { 112 for ( it = list.begin(); it != list.end(); ++it ) {
115 if ( exclude.find( *it ) != exclude.end() ) 113 if ( exclude.find( *it ) != exclude.end() )
116 continue; 114 continue;
117 qWarning( "Found Applet: %s", (*it).latin1() ); 115 qWarning( "Found Applet: %s", (*it).latin1() );
118 TaskbarAppletInterface *iface = 0; 116 TaskbarAppletInterface *iface = 0;
119 QLibrary *lib = new QLibrary( path + "/" + *it ); 117 QLibrary *lib = new QLibrary( path + "/" + *it );
120 if (( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { 118 if (( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) {
121 TaskbarApplet *applet = new TaskbarApplet; 119 TaskbarApplet *applet = new TaskbarApplet;
122 applets[napplets++] = applet; 120 applets[napplets++] = applet;
123 applet->library = lib; 121 applet->library = lib;
124 applet->iface = iface; 122 applet->iface = iface;
125 123
126 QTranslator *trans = new QTranslator(qApp); 124 QTranslator *trans = new QTranslator(qApp);
127 QString type = (*it).left( (*it).find(".") ); 125 QString type = (*it).left( (*it).find(".") );
128 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 126 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
129 if ( trans->load( tfn )) 127 if ( trans->load( tfn ))
130 qApp->installTranslator( trans ); 128 qApp->installTranslator( trans );
131 else 129 else
132 delete trans; 130 delete trans;
133 } else { 131 } else {
134 exclude += *it; 132 exclude += *it;
135 delete lib; 133 delete lib;
136 } 134 }
137 } 135 }
138 cfg.writeEntry( "ExcludeApplets", exclude, ',' ); 136 cfg.writeEntry( "ExcludeApplets", exclude, ',' );
139 qsort(applets,napplets,sizeof(applets[0]),compareAppletPositions); 137 qsort(applets,napplets,sizeof(applets[0]),compareAppletPositions);
140 while (napplets--) { 138 while (napplets--) {
141 TaskbarApplet *applet = applets[napplets]; 139 TaskbarApplet *applet = applets[napplets];
142 applet->applet = applet->iface->applet( this ); 140 applet->applet = applet->iface->applet( this );
143 appletList.append(*applet); 141 appletList.append(*applet);
144 } 142 }
145 delete [] applets; 143 delete [] applets;
146#else /* ## FIXME single app */ 144#else /* ## FIXME single app */
147 TaskbarApplet * const applet = new TaskbarApplet(); 145 TaskbarApplet * const applet = new TaskbarApplet();
148 applet->iface = new ClockAppletImpl(); 146 applet->iface = new ClockAppletImpl();
149 applet->applet = applet->iface->applet( this ); 147 applet->applet = applet->iface->applet( this );
150 appletList.append( applet ); 148 appletList.append( applet );
151#endif 149#endif
152 show(); 150 show();
153} 151}
154 152
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 8367a62..b998e95 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,1451 +1,1441 @@
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 21
22#include <opie2/oglobal.h> 22#include <opie2/oglobal.h>
23#include <qtopia/qpeapplication.h>
24 23
25#ifndef Q_OS_WIN32 24#ifndef Q_OS_WIN32
26#include <pwd.h> 25#include <pwd.h>
27#include <sys/types.h> 26#include <sys/types.h>
28#include <unistd.h> 27#include <unistd.h>
29#include <stdlib.h> 28#include <stdlib.h>
30#include <time.h> 29#include <time.h>
31 30
32#ifndef Q_OS_MACX 31#ifndef Q_OS_MACX
33#include <shadow.h> 32#include <shadow.h>
34#include <crypt.h> 33#include <crypt.h>
35#endif /* Q_OS_MACX */ 34#endif /* Q_OS_MACX */
36 35
37#else 36#else
38#include <stdlib.h> 37#include <stdlib.h>
39#include <time.h> 38#include <time.h>
40#endif 39#endif
41 40
42 41
43#if defined(_OS_LINUX_) 42#if defined(_OS_LINUX_)
44#include <shadow.h> 43#include <shadow.h>
45#endif 44#endif
46 45
47#include <qdir.h>
48#include <qfile.h>
49#include <qtextstream.h> 46#include <qtextstream.h>
50#include <qdatastream.h>
51#include <qmessagebox.h> 47#include <qmessagebox.h>
52#include <qstringlist.h>
53#include <qfileinfo.h>
54#include <qregexp.h>
55//#include <qtopia/qcopchannel_qws.h> 48//#include <qtopia/qcopchannel_qws.h>
56#include <qtopia/process.h> 49#include <qtopia/process.h>
57#include <qtopia/global.h>
58#include <qtopia/config.h>
59#include <qtopia/private/contact.h> 50#include <qtopia/private/contact.h>
60#include <qtopia/quuid.h>
61#include <qtopia/version.h> 51#include <qtopia/version.h>
62#ifdef Q_WS_QWS 52#ifdef Q_WS_QWS
63#include <qtopia/qcopenvelope_qws.h> 53#include <qtopia/qcopenvelope_qws.h>
64#endif 54#endif
65 55
66 56
67#include "transferserver.h" 57#include "transferserver.h"
68#include <qtopia/qprocess.h> 58#include <qtopia/qprocess.h>
69 59
70const int block_size = 51200; 60const int block_size = 51200;
71 61
72TransferServer::TransferServer( Q_UINT16 port, QObject *parent, 62TransferServer::TransferServer( Q_UINT16 port, QObject *parent,
73 const char* name) 63 const char* name)
74 : QServerSocket( port, 1, parent, name ) 64 : QServerSocket( port, 1, parent, name )
75{ 65{
76 connections.setAutoDelete( TRUE ); 66 connections.setAutoDelete( TRUE );
77 if ( !ok() ) 67 if ( !ok() )
78 qWarning( "Failed to bind to port %d", port ); 68 qWarning( "Failed to bind to port %d", port );
79} 69}
80 70
81void TransferServer::authorizeConnections() 71void TransferServer::authorizeConnections()
82{ 72{
83 QListIterator<ServerPI> it(connections); 73 QListIterator<ServerPI> it(connections);
84 while ( it.current() ) { 74 while ( it.current() ) {
85 if ( !it.current()->verifyAuthorised() ) { 75 if ( !it.current()->verifyAuthorised() ) {
86 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); 76 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
87 connections.removeRef( it.current() ); 77 connections.removeRef( it.current() );
88 } else 78 } else
89 ++it; 79 ++it;
90 } 80 }
91} 81}
92 82
93void TransferServer::closed(ServerPI *item) 83void TransferServer::closed(ServerPI *item)
94{ 84{
95 connections.removeRef(item); 85 connections.removeRef(item);
96} 86}
97 87
98TransferServer::~TransferServer() 88TransferServer::~TransferServer()
99{ 89{
100} 90}
101 91
102void TransferServer::newConnection( int socket ) 92void TransferServer::newConnection( int socket )
103{ 93{
104 ServerPI *ptr = new ServerPI( socket, this ); 94 ServerPI *ptr = new ServerPI( socket, this );
105 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); 95 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
106 connections.append( ptr ); 96 connections.append( ptr );
107} 97}
108 98
109QString SyncAuthentication::serverId() 99QString SyncAuthentication::serverId()
110{ 100{
111 Config cfg("Security"); 101 Config cfg("Security");
112 cfg.setGroup("Sync"); 102 cfg.setGroup("Sync");
113 QString r = cfg.readEntry("serverid"); 103 QString r = cfg.readEntry("serverid");
114 104
115 if ( r.isEmpty() ) { 105 if ( r.isEmpty() ) {
116 r = OGlobal::generateUuid(); 106 r = OGlobal::generateUuid();
117 cfg.writeEntry("serverid", r ); 107 cfg.writeEntry("serverid", r );
118 } 108 }
119 return r; 109 return r;
120} 110}
121 111
122QString SyncAuthentication::ownerName() 112QString SyncAuthentication::ownerName()
123{ 113{
124 QString vfilename = Global::applicationFileName("addressbook", 114 QString vfilename = Global::applicationFileName("addressbook",
125 "businesscard.vcf"); 115 "businesscard.vcf");
126 if (QFile::exists(vfilename)) { 116 if (QFile::exists(vfilename)) {
127 Contact c; 117 Contact c;
128 c = Contact::readVCard( vfilename )[0]; 118 c = Contact::readVCard( vfilename )[0];
129 return c.fullName(); 119 return c.fullName();
130 } 120 }
131 121
132 return QString::null; 122 return QString::null;
133} 123}
134 124
135QString SyncAuthentication::loginName() 125QString SyncAuthentication::loginName()
136{ 126{
137 struct passwd *pw = 0L; 127 struct passwd *pw = 0L;
138#ifndef Q_OS_WIN32 128#ifndef Q_OS_WIN32
139 pw = getpwuid( geteuid() ); 129 pw = getpwuid( geteuid() );
140 return QString::fromLocal8Bit( pw->pw_name ); 130 return QString::fromLocal8Bit( pw->pw_name );
141#else 131#else
142 //### revise 132 //### revise
143 return QString(); 133 return QString();
144#endif 134#endif
145} 135}
146 136
147int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 137int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
148{ 138{
149 Config cfg("Security"); 139 Config cfg("Security");
150 cfg.setGroup("Sync"); 140 cfg.setGroup("Sync");
151 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 141 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
152 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 142 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
153 143
154 // QHostAddress allowed; 144 // QHostAddress allowed;
155 // allowed.setAddress(allowedstr); 145 // allowed.setAddress(allowedstr);
156 // uint auth_peer = allowed.ip4Addr(); 146 // uint auth_peer = allowed.ip4Addr();
157 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); 147 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
158 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 148 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
159 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 149 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
160 150
161 return (peeraddress.ip4Addr() & mask) == auth_peer; 151 return (peeraddress.ip4Addr() & mask) == auth_peer;
162} 152}
163 153
164bool SyncAuthentication::checkUser( const QString& user ) 154bool SyncAuthentication::checkUser( const QString& user )
165{ 155{
166 if ( user.isEmpty() ) return FALSE; 156 if ( user.isEmpty() ) return FALSE;
167 QString euser = loginName(); 157 QString euser = loginName();
168 return user == euser; 158 return user == euser;
169} 159}
170 160
171bool SyncAuthentication::checkPassword( const QString& password ) 161bool SyncAuthentication::checkPassword( const QString& password )
172{ 162{
173#ifdef ALLOW_UNIX_USER_FTP 163#ifdef ALLOW_UNIX_USER_FTP
174 // First, check system password... 164 // First, check system password...
175 165
176 struct passwd *pw = 0; 166 struct passwd *pw = 0;
177 struct spwd *spw = 0; 167 struct spwd *spw = 0;
178 168
179 pw = getpwuid( geteuid() ); 169 pw = getpwuid( geteuid() );
180 spw = getspnam( pw->pw_name ); 170 spw = getspnam( pw->pw_name );
181 171
182 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 172 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
183 if ( cpwd == "x" && spw ) 173 if ( cpwd == "x" && spw )
184 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 174 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
185 175
186 // Note: some systems use more than crypt for passwords. 176 // Note: some systems use more than crypt for passwords.
187 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 177 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
188 if ( cpwd == cpassword ) 178 if ( cpwd == cpassword )
189 return TRUE; 179 return TRUE;
190#endif 180#endif
191 181
192 static int lastdenial=0; 182 static int lastdenial=0;
193 static int denials=0; 183 static int denials=0;
194 int now = time(0); 184 int now = time(0);
195 185
196 Config cfg("Security"); 186 Config cfg("Security");
197 cfg.setGroup("SyncMode"); 187 cfg.setGroup("SyncMode");
198 int mode = cfg.readNumEntry("Mode", 0x02 ); 188 int mode = cfg.readNumEntry("Mode", 0x02 );
199 189
200 //No pass word needed if the user really needs it 190 //No pass word needed if the user really needs it
201 if (mode & 0x04) { 191 if (mode & 0x04) {
202 QMessageBox unauth( 192 QMessageBox unauth(
203 tr("Sync Connection"), 193 tr("Sync Connection"),
204 tr("<qt><p>An unauthorized system is requesting access to this device." 194 tr("<qt><p>An unauthorized system is requesting access to this device."
205 "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ), 195 "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ),
206 QMessageBox::Warning, 196 QMessageBox::Warning,
207 QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton, 197 QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton,
208 0, QString::null, TRUE, WStyle_StaysOnTop); 198 0, QString::null, TRUE, WStyle_StaysOnTop);
209 unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) ); 199 unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) );
210 unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); 200 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
211 switch( unauth.exec() ) { 201 switch( unauth.exec() ) {
212 case QMessageBox::Ok: 202 case QMessageBox::Ok:
213 return TRUE; 203 return TRUE;
214 break; 204 break;
215 case QMessageBox::Cancel: 205 case QMessageBox::Cancel:
216 default: 206 default:
217 denials++; 207 denials++;
218 lastdenial=now; 208 lastdenial=now;
219 return FALSE; 209 return FALSE;
220 } 210 }
221 } 211 }
222 212
223 // Detect old Qtopia Desktop (no password) and fail 213 // Detect old Qtopia Desktop (no password) and fail
224 if ( password.isEmpty() ) { 214 if ( password.isEmpty() ) {
225 if ( denials < 3 || now > lastdenial+600 ) { 215 if ( denials < 3 || now > lastdenial+600 ) {
226 QMessageBox unauth( 216 QMessageBox unauth(
227 tr("Sync Connection"), 217 tr("Sync Connection"),
228 tr("<p>An unauthorized system is requesting access to this device." 218 tr("<p>An unauthorized system is requesting access to this device."
229 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 219 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
230 "please upgrade or change the security setting to use IntelliSync." ), 220 "please upgrade or change the security setting to use IntelliSync." ),
231 QMessageBox::Warning, 221 QMessageBox::Warning,
232 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 222 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
233 0, QString::null, TRUE, WStyle_StaysOnTop); 223 0, QString::null, TRUE, WStyle_StaysOnTop);
234 unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); 224 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
235 unauth.exec(); 225 unauth.exec();
236 226
237 denials++; 227 denials++;
238 lastdenial=now; 228 lastdenial=now;
239 } 229 }
240 return FALSE; 230 return FALSE;
241 231
242 } 232 }
243 233
244 // Second, check sync password... 234 // Second, check sync password...
245 235
246 static int lock=0; 236 static int lock=0;
247 if ( lock ) return FALSE; 237 if ( lock ) return FALSE;
248 238
249 ++lock; 239 ++lock;
250 240
251 /* 241 /*
252 * we need to support old Sync software and QtopiaDesktop 242 * we need to support old Sync software and QtopiaDesktop
253 */ 243 */
254 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { 244 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) {
255 Config cfg( "Security" ); 245 Config cfg( "Security" );
256 cfg.setGroup("Sync"); 246 cfg.setGroup("Sync");
257 QStringList pwds = cfg.readListEntry("Passwords",' '); 247 QStringList pwds = cfg.readListEntry("Passwords",' ');
258 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { 248 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
259#ifndef Q_OS_WIN32 249#ifndef Q_OS_WIN32
260 QString cpassword = QString::fromLocal8Bit( 250 QString cpassword = QString::fromLocal8Bit(
261 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); 251 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
262#else 252#else
263 // ### revise 253 // ### revise
264 QString cpassword(""); 254 QString cpassword("");
265#endif 255#endif
266 if ( *it == cpassword ) { 256 if ( *it == cpassword ) {
267 lock--; 257 lock--;
268 return TRUE; 258 return TRUE;
269 } 259 }
270 } 260 }
271 261
272 // Unrecognized system. Be careful... 262 // Unrecognized system. Be careful...
273 QMessageBox unrecbox( 263 QMessageBox unrecbox(
274 tr("Sync Connection"), 264 tr("Sync Connection"),
275 tr("<p>An unrecognized system is requesting access to this device." 265 tr("<p>An unrecognized system is requesting access to this device."
276 "<p>If you have just initiated a Sync for the first time, this is normal."), 266 "<p>If you have just initiated a Sync for the first time, this is normal."),
277 QMessageBox::Warning, 267 QMessageBox::Warning,
278 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 268 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
279 0, QString::null, TRUE, WStyle_StaysOnTop); 269 0, QString::null, TRUE, WStyle_StaysOnTop);
280 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); 270 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
281 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); 271 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
282 272
283 if ( (denials > 2 && now < lastdenial+600) 273 if ( (denials > 2 && now < lastdenial+600)
284 || unrecbox.exec() != QMessageBox::Yes) 274 || unrecbox.exec() != QMessageBox::Yes)
285 { 275 {
286 denials++; 276 denials++;
287 lastdenial=now; 277 lastdenial=now;
288 lock--; 278 lock--;
289 return FALSE; 279 return FALSE;
290 } else { 280 } else {
291 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; 281 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
292 char salt[2]; 282 char salt[2];
293 salt[0]= salty[rand() % (sizeof(salty)-1)]; 283 salt[0]= salty[rand() % (sizeof(salty)-1)];
294 salt[1]= salty[rand() % (sizeof(salty)-1)]; 284 salt[1]= salty[rand() % (sizeof(salty)-1)];
295#ifndef Q_OS_WIN32 285#ifndef Q_OS_WIN32
296 QString cpassword = QString::fromLocal8Bit( 286 QString cpassword = QString::fromLocal8Bit(
297 crypt( password.mid(8).local8Bit(), salt ) ); 287 crypt( password.mid(8).local8Bit(), salt ) );
298#else 288#else
299 //### revise 289 //### revise
300 QString cpassword(""); 290 QString cpassword("");
301#endif 291#endif
302 denials=0; 292 denials=0;
303 pwds.prepend(cpassword); 293 pwds.prepend(cpassword);
304 cfg.writeEntry("Passwords",pwds,' '); 294 cfg.writeEntry("Passwords",pwds,' ');
305 lock--; 295 lock--;
306 return TRUE; 296 return TRUE;
307 } 297 }
308 } 298 }
309 lock--; 299 lock--;
310 300
311 return FALSE; 301 return FALSE;
312} 302}
313 303
314 304
315ServerPI::ServerPI( int socket, QObject *parent, const char* name ) 305ServerPI::ServerPI( int socket, QObject *parent, const char* name )
316 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), 306 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ),
317 storFileSize(-1) 307 storFileSize(-1)
318{ 308{
319 state = Connected; 309 state = Connected;
320 310
321 setSocket( socket ); 311 setSocket( socket );
322 312
323 peerport = peerPort(); 313 peerport = peerPort();
324 peeraddress = peerAddress(); 314 peeraddress = peerAddress();
325 315
326#ifndef INSECURE 316#ifndef INSECURE
327 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 317 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
328 state = Forbidden; 318 state = Forbidden;
329 startTimer( 0 ); 319 startTimer( 0 );
330 } else 320 } else
331#endif 321#endif
332 { 322 {
333 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 323 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
334 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 324 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
335 325
336 passiv = FALSE; 326 passiv = FALSE;
337 for( int i = 0; i < 4; i++ ) 327 for( int i = 0; i < 4; i++ )
338 wait[i] = FALSE; 328 wait[i] = FALSE;
339 329
340 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr 330 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr
341 state = Wait_USER; 331 state = Wait_USER;
342 332
343 dtp = new ServerDTP( this ); 333 dtp = new ServerDTP( this );
344 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 334 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
345 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 335 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
346 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 336 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) );
347 337
348 338
349 directory = QDir::currentDirPath(); 339 directory = QDir::currentDirPath();
350 340
351 static int p = 1024; 341 static int p = 1024;
352 342
353 while ( !serversocket || !serversocket->ok() ) { 343 while ( !serversocket || !serversocket->ok() ) {
354 delete serversocket; 344 delete serversocket;
355 serversocket = new ServerSocket( ++p, this ); 345 serversocket = new ServerSocket( ++p, this );
356 } 346 }
357 connect( serversocket, SIGNAL( newIncomming( int ) ), 347 connect( serversocket, SIGNAL( newIncomming( int ) ),
358 SLOT( newConnection( int ) ) ); 348 SLOT( newConnection( int ) ) );
359 } 349 }
360} 350}
361 351
362ServerPI::~ServerPI() 352ServerPI::~ServerPI()
363{ 353{
364 close(); 354 close();
365 355
366 if ( dtp ) 356 if ( dtp )
367 dtp->close(); 357 dtp->close();
368 delete dtp; 358 delete dtp;
369 delete serversocket; 359 delete serversocket;
370} 360}
371 361
372bool ServerPI::verifyAuthorised() 362bool ServerPI::verifyAuthorised()
373{ 363{
374 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 364 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
375 state = Forbidden; 365 state = Forbidden;
376 return FALSE; 366 return FALSE;
377 } 367 }
378 return TRUE; 368 return TRUE;
379} 369}
380 370
381void ServerPI::connectionClosed() 371void ServerPI::connectionClosed()
382{ 372{
383 // qDebug( "Debug: Connection closed" ); 373 // qDebug( "Debug: Connection closed" );
384 emit connectionClosed(this); 374 emit connectionClosed(this);
385} 375}
386 376
387void ServerPI::send( const QString& msg ) 377void ServerPI::send( const QString& msg )
388{ 378{
389 QTextStream os( this ); 379 QTextStream os( this );
390 os << msg << endl; 380 os << msg << endl;
391 //qDebug( "Reply: %s", msg.latin1() ); 381 //qDebug( "Reply: %s", msg.latin1() );
392} 382}
393 383
394void ServerPI::read() 384void ServerPI::read()
395{ 385{
396 while ( canReadLine() ) 386 while ( canReadLine() )
397 process( readLine().stripWhiteSpace() ); 387 process( readLine().stripWhiteSpace() );
398} 388}
399 389
400bool ServerPI::checkReadFile( const QString& file ) 390bool ServerPI::checkReadFile( const QString& file )
401{ 391{
402 QString filename; 392 QString filename;
403 393
404 if ( file[0] != "/" ) 394 if ( file[0] != "/" )
405 filename = directory.path() + "/" + file; 395 filename = directory.path() + "/" + file;
406 else 396 else
407 filename = file; 397 filename = file;
408 398
409 QFileInfo fi( filename ); 399 QFileInfo fi( filename );
410 return ( fi.exists() && fi.isReadable() ); 400 return ( fi.exists() && fi.isReadable() );
411} 401}
412 402
413bool ServerPI::checkWriteFile( const QString& file ) 403bool ServerPI::checkWriteFile( const QString& file )
414{ 404{
415 QString filename; 405 QString filename;
416 406
417 if ( file[0] != "/" ) 407 if ( file[0] != "/" )
418 filename = directory.path() + "/" + file; 408 filename = directory.path() + "/" + file;
419 else 409 else
420 filename = file; 410 filename = file;
421 411
422 QFileInfo fi( filename ); 412 QFileInfo fi( filename );
423 413
424 if ( fi.exists() ) 414 if ( fi.exists() )
425 if ( !QFile( filename ).remove() ) 415 if ( !QFile( filename ).remove() )
426 return FALSE; 416 return FALSE;
427 return TRUE; 417 return TRUE;
428} 418}
429 419
430void ServerPI::process( const QString& message ) 420void ServerPI::process( const QString& message )
431{ 421{
432 //qDebug( "Command: %s", message.latin1() ); 422 //qDebug( "Command: %s", message.latin1() );
433 423
434 // split message using "," as separator 424 // split message using "," as separator
435 QStringList msg = QStringList::split( " ", message ); 425 QStringList msg = QStringList::split( " ", message );
436 if ( msg.isEmpty() ) return; 426 if ( msg.isEmpty() ) return;
437 427
438 // command token 428 // command token
439 QString cmd = msg[0].upper(); 429 QString cmd = msg[0].upper();
440 430
441 // argument token 431 // argument token
442 QString arg; 432 QString arg;
443 if ( msg.count() >= 2 ) 433 if ( msg.count() >= 2 )
444 arg = msg[1]; 434 arg = msg[1];
445 435
446 // full argument string 436 // full argument string
447 QString args; 437 QString args;
448 if ( msg.count() >= 2 ) { 438 if ( msg.count() >= 2 ) {
449 QStringList copy( msg ); 439 QStringList copy( msg );
450 // FIXME: for Qt3 440 // FIXME: for Qt3
451 // copy.pop_front() 441 // copy.pop_front()
452 copy.remove( copy.begin() ); 442 copy.remove( copy.begin() );
453 args = copy.join( " " ); 443 args = copy.join( " " );
454 } 444 }
455 445
456 //qDebug( "args: %s", args.latin1() ); 446 //qDebug( "args: %s", args.latin1() );
457 447
458 // we always respond to QUIT, regardless of state 448 // we always respond to QUIT, regardless of state
459 if ( cmd == "QUIT" ) { 449 if ( cmd == "QUIT" ) {
460 send( "211 Good bye!" ); // No tr 450 send( "211 Good bye!" ); // No tr
461 close(); 451 close();
462 return; 452 return;
463 } 453 }
464 454
465 // connected to client 455 // connected to client
466 if ( Connected == state ) 456 if ( Connected == state )
467 return; 457 return;
468 458
469 // waiting for user name 459 // waiting for user name
470 if ( Wait_USER == state ) { 460 if ( Wait_USER == state ) {
471 461
472 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 462 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
473 send( "530 Please login with USER and PASS" ); // No tr 463 send( "530 Please login with USER and PASS" ); // No tr
474 return; 464 return;
475 } 465 }
476 send( "331 User name ok, need password" ); // No tr 466 send( "331 User name ok, need password" ); // No tr
477 state = Wait_PASS; 467 state = Wait_PASS;
478 return; 468 return;
479 } 469 }
480 470
481 // waiting for password 471 // waiting for password
482 if ( Wait_PASS == state ) { 472 if ( Wait_PASS == state ) {
483 473
484 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 474 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
485 send( "530 Please login with USER and PASS" ); // No tr 475 send( "530 Please login with USER and PASS" ); // No tr
486 return; 476 return;
487 } 477 }
488 send( "230 User logged in, proceed" ); // No tr 478 send( "230 User logged in, proceed" ); // No tr
489 state = Ready; 479 state = Ready;
490 return; 480 return;
491 } 481 }
492 482
493 // ACCESS CONTROL COMMANDS 483 // ACCESS CONTROL COMMANDS
494 484
495 // Only an ALLO sent immediately before STOR is valid. 485 // Only an ALLO sent immediately before STOR is valid.
496 if ( cmd != "STOR" ) 486 if ( cmd != "STOR" )
497 storFileSize = -1; 487 storFileSize = -1;
498 488
499 // account (ACCT) 489 // account (ACCT)
500 if ( cmd == "ACCT" ) { 490 if ( cmd == "ACCT" ) {
501 // even wu-ftp does not support it 491 // even wu-ftp does not support it
502 send( "502 Command not implemented" ); // No tr 492 send( "502 Command not implemented" ); // No tr
503 } 493 }
504 494
505 // change working directory (CWD) 495 // change working directory (CWD)
506 else if ( cmd == "CWD" ) { 496 else if ( cmd == "CWD" ) {
507 497
508 if ( !args.isEmpty() ) { 498 if ( !args.isEmpty() ) {
509 if ( directory.cd( args, TRUE ) ) 499 if ( directory.cd( args, TRUE ) )
510 send( "250 Requested file action okay, completed" ); // No tr 500 send( "250 Requested file action okay, completed" ); // No tr
511 else 501 else
512 send( "550 Requested action not taken" ); // No tr 502 send( "550 Requested action not taken" ); // No tr
513 } 503 }
514 else 504 else
515 send( "500 Syntax error, command unrecognized" ); // No tr 505 send( "500 Syntax error, command unrecognized" ); // No tr
516 } 506 }
517 507
518 // change to parent directory (CDUP) 508 // change to parent directory (CDUP)
519 else if ( cmd == "CDUP" ) { 509 else if ( cmd == "CDUP" ) {
520 if ( directory.cdUp() ) 510 if ( directory.cdUp() )
521 send( "250 Requested file action okay, completed" ); // No tr 511 send( "250 Requested file action okay, completed" ); // No tr
522 else 512 else
523 send( "550 Requested action not taken" ); // No tr 513 send( "550 Requested action not taken" ); // No tr
524 } 514 }
525 515
526 // structure mount (SMNT) 516 // structure mount (SMNT)
527 else if ( cmd == "SMNT" ) { 517 else if ( cmd == "SMNT" ) {
528 // even wu-ftp does not support it 518 // even wu-ftp does not support it
529 send( "502 Command not implemented" ); // No tr 519 send( "502 Command not implemented" ); // No tr
530 } 520 }
531 521
532 // reinitialize (REIN) 522 // reinitialize (REIN)
533 else if ( cmd == "REIN" ) { 523 else if ( cmd == "REIN" ) {
534 // even wu-ftp does not support it 524 // even wu-ftp does not support it
535 send( "502 Command not implemented" ); // No tr 525 send( "502 Command not implemented" ); // No tr
536 } 526 }
537 527
538 528
539 // TRANSFER PARAMETER COMMANDS 529 // TRANSFER PARAMETER COMMANDS
540 530
541 531
542 // data port (PORT) 532 // data port (PORT)
543 else if ( cmd == "PORT" ) { 533 else if ( cmd == "PORT" ) {
544 if ( parsePort( arg ) ) 534 if ( parsePort( arg ) )
545 send( "200 Command okay" ); // No tr 535 send( "200 Command okay" ); // No tr
546 else 536 else
547 send( "500 Syntax error, command unrecognized" ); // No tr 537 send( "500 Syntax error, command unrecognized" ); // No tr
548 } 538 }
549 539
550 // passive (PASV) 540 // passive (PASV)
551 else if ( cmd == "PASV" ) { 541 else if ( cmd == "PASV" ) {
552 passiv = TRUE; 542 passiv = TRUE;
553 send( "227 Entering Passive Mode (" // No tr 543 send( "227 Entering Passive Mode (" // No tr
554 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 544 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
555 + QString::number( ( serversocket->port() ) >> 8 ) + "," 545 + QString::number( ( serversocket->port() ) >> 8 ) + ","
556 + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); 546 + QString::number( ( serversocket->port() ) & 0xFF ) +")" );
557 } 547 }
558 548
559 // representation type (TYPE) 549 // representation type (TYPE)
560 else if ( cmd == "TYPE" ) { 550 else if ( cmd == "TYPE" ) {
561 if ( arg.upper() == "A" || arg.upper() == "I" ) 551 if ( arg.upper() == "A" || arg.upper() == "I" )
562 send( "200 Command okay" ); // No tr 552 send( "200 Command okay" ); // No tr
563 else 553 else
564 send( "504 Command not implemented for that parameter" ); // No tr 554 send( "504 Command not implemented for that parameter" ); // No tr
565 } 555 }
566 556
567 // file structure (STRU) 557 // file structure (STRU)
568 else if ( cmd == "STRU" ) { 558 else if ( cmd == "STRU" ) {
569 if ( arg.upper() == "F" ) 559 if ( arg.upper() == "F" )
570 send( "200 Command okay" ); // No tr 560 send( "200 Command okay" ); // No tr
571 else 561 else
572 send( "504 Command not implemented for that parameter" ); // No tr 562 send( "504 Command not implemented for that parameter" ); // No tr
573 } 563 }
574 564
575 // transfer mode (MODE) 565 // transfer mode (MODE)
576 else if ( cmd == "MODE" ) { 566 else if ( cmd == "MODE" ) {
577 if ( arg.upper() == "S" ) 567 if ( arg.upper() == "S" )
578 send( "200 Command okay" ); // No tr 568 send( "200 Command okay" ); // No tr
579 else 569 else
580 send( "504 Command not implemented for that parameter" ); // No tr 570 send( "504 Command not implemented for that parameter" ); // No tr
581 } 571 }
582 572
583 573
584 // FTP SERVICE COMMANDS 574 // FTP SERVICE COMMANDS
585 575
586 576
587 // retrieve (RETR) 577 // retrieve (RETR)
588 else if ( cmd == "RETR" ) 578 else if ( cmd == "RETR" )
589 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 579 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
590 || backupRestoreGzip( absFilePath( args ) ) ) { 580 || backupRestoreGzip( absFilePath( args ) ) ) {
591 send( "150 File status okay" ); // No tr 581 send( "150 File status okay" ); // No tr
592 sendFile( absFilePath( args ) ); 582 sendFile( absFilePath( args ) );
593 } 583 }
594 else { 584 else {
595 qDebug("550 Requested action not taken"); 585 qDebug("550 Requested action not taken");
596 send( "550 Requested action not taken" ); // No tr 586 send( "550 Requested action not taken" ); // No tr
597 } 587 }
598 588
599 // store (STOR) 589 // store (STOR)
600 else if ( cmd == "STOR" ) 590 else if ( cmd == "STOR" )
601 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 591 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
602 send( "150 File status okay" ); // No tr 592 send( "150 File status okay" ); // No tr
603 retrieveFile( absFilePath( args ) ); 593 retrieveFile( absFilePath( args ) );
604 } 594 }
605 else 595 else
606 send( "550 Requested action not taken" ); // No tr 596 send( "550 Requested action not taken" ); // No tr
607 597
608 // store unique (STOU) 598 // store unique (STOU)
609 else if ( cmd == "STOU" ) { 599 else if ( cmd == "STOU" ) {
610 send( "502 Command not implemented" ); // No tr 600 send( "502 Command not implemented" ); // No tr
611 } 601 }
612 602
613 // append (APPE) 603 // append (APPE)
614 else if ( cmd == "APPE" ) { 604 else if ( cmd == "APPE" ) {
615 send( "502 Command not implemented" ); // No tr 605 send( "502 Command not implemented" ); // No tr
616 } 606 }
617 607
618 // allocate (ALLO) 608 // allocate (ALLO)
619 else if ( cmd == "ALLO" ) { 609 else if ( cmd == "ALLO" ) {
620 storFileSize = args.toInt(); 610 storFileSize = args.toInt();
621 send( "200 Command okay" ); // No tr 611 send( "200 Command okay" ); // No tr
622 } 612 }
623 613
624 // restart (REST) 614 // restart (REST)
625 else if ( cmd == "REST" ) { 615 else if ( cmd == "REST" ) {
626 send( "502 Command not implemented" ); // No tr 616 send( "502 Command not implemented" ); // No tr
627 } 617 }
628 618
629 // rename from (RNFR) 619 // rename from (RNFR)
630 else if ( cmd == "RNFR" ) { 620 else if ( cmd == "RNFR" ) {
631 renameFrom = QString::null; 621 renameFrom = QString::null;
632 if ( args.isEmpty() ) 622 if ( args.isEmpty() )
633 send( "500 Syntax error, command unrecognized" ); // No tr 623 send( "500 Syntax error, command unrecognized" ); // No tr
634 else { 624 else {
635 QFile file( absFilePath( args ) ); 625 QFile file( absFilePath( args ) );
636 if ( file.exists() ) { 626 if ( file.exists() ) {
637 send( "350 File exists, ready for destination name" ); // No tr 627 send( "350 File exists, ready for destination name" ); // No tr
638 renameFrom = absFilePath( args ); 628 renameFrom = absFilePath( args );
639 } 629 }
640 else 630 else
641 send( "550 Requested action not taken" ); // No tr 631 send( "550 Requested action not taken" ); // No tr
642 } 632 }
643 } 633 }
644 634
645 // rename to (RNTO) 635 // rename to (RNTO)
646 else if ( cmd == "RNTO" ) { 636 else if ( cmd == "RNTO" ) {
647 if ( lastCommand != "RNFR" ) 637 if ( lastCommand != "RNFR" )
648 send( "503 Bad sequence of commands" ); // No tr 638 send( "503 Bad sequence of commands" ); // No tr
649 else if ( args.isEmpty() ) 639 else if ( args.isEmpty() )
650 send( "500 Syntax error, command unrecognized" ); // No tr 640 send( "500 Syntax error, command unrecognized" ); // No tr
651 else { 641 else {
652 QDir dir( absFilePath( args ) ); 642 QDir dir( absFilePath( args ) );
653 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 643 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
654 send( "250 Requested file action okay, completed." ); // No tr 644 send( "250 Requested file action okay, completed." ); // No tr
655 else 645 else
656 send( "550 Requested action not taken" ); // No tr 646 send( "550 Requested action not taken" ); // No tr
657 } 647 }
658 } 648 }
659 649
660 // abort (ABOR) 650 // abort (ABOR)
661 else if ( cmd.contains( "ABOR" ) ) { 651 else if ( cmd.contains( "ABOR" ) ) {
662 dtp->close(); 652 dtp->close();
663 if ( dtp->dtpMode() != ServerDTP::Idle ) 653 if ( dtp->dtpMode() != ServerDTP::Idle )
664 send( "426 Connection closed; transfer aborted" ); // No tr 654 send( "426 Connection closed; transfer aborted" ); // No tr
665 else 655 else
666 send( "226 Closing data connection" ); // No tr 656 send( "226 Closing data connection" ); // No tr
667 } 657 }
668 658
669 // delete (DELE) 659 // delete (DELE)
670 else if ( cmd == "DELE" ) { 660 else if ( cmd == "DELE" ) {
671 if ( args.isEmpty() ) 661 if ( args.isEmpty() )
672 send( "500 Syntax error, command unrecognized" ); // No tr 662 send( "500 Syntax error, command unrecognized" ); // No tr
673 else { 663 else {
674 QFile file( absFilePath( args ) ) ; 664 QFile file( absFilePath( args ) ) ;
675 if ( file.remove() ) { 665 if ( file.remove() ) {
676 send( "250 Requested file action okay, completed" ); // No tr 666 send( "250 Requested file action okay, completed" ); // No tr
677 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 667 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
678 e << file.name(); 668 e << file.name();
679 } else { 669 } else {
680 send( "550 Requested action not taken" ); // No tr 670 send( "550 Requested action not taken" ); // No tr
681 } 671 }
682 } 672 }
683 } 673 }
684 674
685 // remove directory (RMD) 675 // remove directory (RMD)
686 else if ( cmd == "RMD" ) { 676 else if ( cmd == "RMD" ) {
687 if ( args.isEmpty() ) 677 if ( args.isEmpty() )
688 send( "500 Syntax error, command unrecognized" ); // No tr 678 send( "500 Syntax error, command unrecognized" ); // No tr
689 else { 679 else {
690 QDir dir; 680 QDir dir;
691 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 681 if ( dir.rmdir( absFilePath( args ), TRUE ) )
692 send( "250 Requested file action okay, completed" ); // No tr 682 send( "250 Requested file action okay, completed" ); // No tr
693 else 683 else
694 send( "550 Requested action not taken" ); // No tr 684 send( "550 Requested action not taken" ); // No tr
695 } 685 }
696 } 686 }
697 687
698 // make directory (MKD) 688 // make directory (MKD)
699 else if ( cmd == "MKD" ) { 689 else if ( cmd == "MKD" ) {
700 if ( args.isEmpty() ) { 690 if ( args.isEmpty() ) {
701 qDebug(" Error: no arg"); 691 qDebug(" Error: no arg");
702 send( "500 Syntax error, command unrecognized" ); // No tr 692 send( "500 Syntax error, command unrecognized" ); // No tr
703 } 693 }
704 else { 694 else {
705 QDir dir; 695 QDir dir;
706 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 696 if ( dir.mkdir( absFilePath( args ), TRUE ) )
707 send( "250 Requested file action okay, completed." ); // No tr 697 send( "250 Requested file action okay, completed." ); // No tr
708 else 698 else
709 send( "550 Requested action not taken" ); // No tr 699 send( "550 Requested action not taken" ); // No tr
710 } 700 }
711 } 701 }
712 702
713 // print working directory (PWD) 703 // print working directory (PWD)
714 else if ( cmd == "PWD" ) { 704 else if ( cmd == "PWD" ) {
715 send( "257 \"" + directory.path() +"\"" ); 705 send( "257 \"" + directory.path() +"\"" );
716 } 706 }
717 707
718 // list (LIST) 708 // list (LIST)
719 else if ( cmd == "LIST" ) { 709 else if ( cmd == "LIST" ) {
720 if ( sendList( absFilePath( args ) ) ) 710 if ( sendList( absFilePath( args ) ) )
721 send( "150 File status okay" ); // No tr 711 send( "150 File status okay" ); // No tr
722 else 712 else
723 send( "500 Syntax error, command unrecognized" ); // No tr 713 send( "500 Syntax error, command unrecognized" ); // No tr
724 } 714 }
725 715
726 // size (SIZE) 716 // size (SIZE)
727 else if ( cmd == "SIZE" ) { 717 else if ( cmd == "SIZE" ) {
728 QString filePath = absFilePath( args ); 718 QString filePath = absFilePath( args );
729 QFileInfo fi( filePath ); 719 QFileInfo fi( filePath );
730 bool gzipfile = backupRestoreGzip( filePath ); 720 bool gzipfile = backupRestoreGzip( filePath );
731 if ( !fi.exists() && !gzipfile ) 721 if ( !fi.exists() && !gzipfile )
732 send( "500 Syntax error, command unrecognized" ); // No tr 722 send( "500 Syntax error, command unrecognized" ); // No tr
733 else { 723 else {
734 if ( !gzipfile ) 724 if ( !gzipfile )
735 send( "213 " + QString::number( fi.size() ) ); 725 send( "213 " + QString::number( fi.size() ) );
736 else { 726 else {
737 Process duproc( QString("du") ); 727 Process duproc( QString("du") );
738 duproc.addArgument("-s"); 728 duproc.addArgument("-s");
739 QString in, out; 729 QString in, out;
740 if ( !duproc.exec(in, out) ) { 730 if ( !duproc.exec(in, out) ) {
741 qDebug("du process failed; just sending back 1K"); 731 qDebug("du process failed; just sending back 1K");
742 send( "213 1024"); 732 send( "213 1024");
743 } 733 }
744 else { 734 else {
745 QString size = out.left( out.find("\t") ); 735 QString size = out.left( out.find("\t") );
746 int guess = size.toInt()/5; 736 int guess = size.toInt()/5;
747 if ( filePath.contains("doc") ) // No tr 737 if ( filePath.contains("doc") ) // No tr
748 guess *= 1000; 738 guess *= 1000;
749 qDebug("sending back gzip guess of %d", guess); 739 qDebug("sending back gzip guess of %d", guess);
750 send( "213 " + QString::number(guess) ); 740 send( "213 " + QString::number(guess) );
751 } 741 }
752 } 742 }
753 } 743 }
754 } 744 }
755 // name list (NLST) 745 // name list (NLST)
756 else if ( cmd == "NLST" ) { 746 else if ( cmd == "NLST" ) {
757 send( "502 Command not implemented" ); // No tr 747 send( "502 Command not implemented" ); // No tr
758 } 748 }
759 749
760 // site parameters (SITE) 750 // site parameters (SITE)
761 else if ( cmd == "SITE" ) { 751 else if ( cmd == "SITE" ) {
762 send( "502 Command not implemented" ); // No tr 752 send( "502 Command not implemented" ); // No tr
763 } 753 }
764 754
765 // system (SYST) 755 // system (SYST)
766 else if ( cmd == "SYST" ) { 756 else if ( cmd == "SYST" ) {
767 send( "215 UNIX Type: L8" ); // No tr 757 send( "215 UNIX Type: L8" ); // No tr
768 } 758 }
769 759
770 // status (STAT) 760 // status (STAT)
771 else if ( cmd == "STAT" ) { 761 else if ( cmd == "STAT" ) {
772 send( "502 Command not implemented" ); // No tr 762 send( "502 Command not implemented" ); // No tr
773 } 763 }
774 764
775 // help (HELP ) 765 // help (HELP )
776 else if ( cmd == "HELP" ) { 766 else if ( cmd == "HELP" ) {
777 send( "502 Command not implemented" ); // No tr 767 send( "502 Command not implemented" ); // No tr
778 } 768 }
779 769
780 // noop (NOOP) 770 // noop (NOOP)
781 else if ( cmd == "NOOP" ) { 771 else if ( cmd == "NOOP" ) {
782 send( "200 Command okay" ); // No tr 772 send( "200 Command okay" ); // No tr
783 } 773 }
784 774
785 // not implemented 775 // not implemented
786 else 776 else
787 send( "502 Command not implemented" ); // No tr 777 send( "502 Command not implemented" ); // No tr
788 778
789 lastCommand = cmd; 779 lastCommand = cmd;
790} 780}
791 781
792bool ServerPI::backupRestoreGzip( const QString &file ) 782bool ServerPI::backupRestoreGzip( const QString &file )
793{ 783{
794 return (file.find( "backup" ) != -1 && // No tr 784 return (file.find( "backup" ) != -1 && // No tr
795 file.findRev( ".tgz" ) == (int)file.length()-4 ); 785 file.findRev( ".tgz" ) == (int)file.length()-4 );
796} 786}
797 787
798bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 788bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
799{ 789{
800 if ( file.find( "backup" ) != -1 && // No tr 790 if ( file.find( "backup" ) != -1 && // No tr
801 file.findRev( ".tgz" ) == (int)file.length()-4 ) { 791 file.findRev( ".tgz" ) == (int)file.length()-4 ) {
802 QFileInfo info( file ); 792 QFileInfo info( file );
803 targets = info.dirPath( TRUE ); 793 targets = info.dirPath( TRUE );
804 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), 794 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(),
805 targets.join(" ").latin1() ); 795 targets.join(" ").latin1() );
806 return true; 796 return true;
807 } 797 }
808 return false; 798 return false;
809} 799}
810 800
811void ServerPI::sendFile( const QString& file ) 801void ServerPI::sendFile( const QString& file )
812{ 802{
813 if ( passiv ) { 803 if ( passiv ) {
814 wait[SendFile] = TRUE; 804 wait[SendFile] = TRUE;
815 waitfile = file; 805 waitfile = file;
816 if ( waitsocket ) 806 if ( waitsocket )
817 newConnection( waitsocket ); 807 newConnection( waitsocket );
818 } 808 }
819 else { 809 else {
820 QStringList targets; 810 QStringList targets;
821 if ( backupRestoreGzip( file, targets ) ) 811 if ( backupRestoreGzip( file, targets ) )
822 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 812 dtp->sendGzipFile( file, targets, peeraddress, peerport );
823 else dtp->sendFile( file, peeraddress, peerport ); 813 else dtp->sendFile( file, peeraddress, peerport );
824 } 814 }
825} 815}
826 816
827void ServerPI::retrieveFile( const QString& file ) 817void ServerPI::retrieveFile( const QString& file )
828{ 818{
829 if ( passiv ) { 819 if ( passiv ) {
830 wait[RetrieveFile] = TRUE; 820 wait[RetrieveFile] = TRUE;
831 waitfile = file; 821 waitfile = file;
832 if ( waitsocket ) 822 if ( waitsocket )
833 newConnection( waitsocket ); 823 newConnection( waitsocket );
834 } 824 }
835 else { 825 else {
836 QStringList targets; 826 QStringList targets;
837 if ( backupRestoreGzip( file, targets ) ) 827 if ( backupRestoreGzip( file, targets ) )
838 dtp->retrieveGzipFile( file, peeraddress, peerport ); 828 dtp->retrieveGzipFile( file, peeraddress, peerport );
839 else 829 else
840 dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); 830 dtp->retrieveFile( file, peeraddress, peerport, storFileSize );
841 } 831 }
842} 832}
843 833
844bool ServerPI::parsePort( const QString& pp ) 834bool ServerPI::parsePort( const QString& pp )
845{ 835{
846 QStringList p = QStringList::split( ",", pp ); 836 QStringList p = QStringList::split( ",", pp );
847 if ( p.count() != 6 ) return FALSE; 837 if ( p.count() != 6 ) return FALSE;
848 838
849 // h1,h2,h3,h4,p1,p2 839 // h1,h2,h3,h4,p1,p2
850 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 840 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
851 ( p[2].toInt() << 8 ) + p[3].toInt() ); 841 ( p[2].toInt() << 8 ) + p[3].toInt() );
852 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 842 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
853 return TRUE; 843 return TRUE;
854} 844}
855 845
856void ServerPI::dtpCompleted() 846void ServerPI::dtpCompleted()
857{ 847{
858 send( "226 Closing data connection, file transfer successful" ); // No tr 848 send( "226 Closing data connection, file transfer successful" ); // No tr
859 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 849 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
860 QString fn = dtp->fileName(); 850 QString fn = dtp->fileName();
861 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { 851 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
862 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 852 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
863 e << fn; 853 e << fn;
864 } 854 }
865 } 855 }
866 waitsocket = 0; 856 waitsocket = 0;
867 dtp->close(); 857 dtp->close();
868 storFileSize = -1; 858 storFileSize = -1;
869} 859}
870 860
871void ServerPI::dtpFailed() 861void ServerPI::dtpFailed()
872{ 862{
873 dtp->close(); 863 dtp->close();
874 waitsocket = 0; 864 waitsocket = 0;
875 send( "451 Requested action aborted: local error in processing" ); // No tr 865 send( "451 Requested action aborted: local error in processing" ); // No tr
876 storFileSize = -1; 866 storFileSize = -1;
877} 867}
878 868
879void ServerPI::dtpError( int ) 869void ServerPI::dtpError( int )
880{ 870{
881 dtp->close(); 871 dtp->close();
882 waitsocket = 0; 872 waitsocket = 0;
883 send( "451 Requested action aborted: local error in processing" ); // No tr 873 send( "451 Requested action aborted: local error in processing" ); // No tr
884 storFileSize = -1; 874 storFileSize = -1;
885} 875}
886 876
887bool ServerPI::sendList( const QString& arg ) 877bool ServerPI::sendList( const QString& arg )
888{ 878{
889 QByteArray listing; 879 QByteArray listing;
890 QBuffer buffer( listing ); 880 QBuffer buffer( listing );
891 881
892 if ( !buffer.open( IO_WriteOnly ) ) 882 if ( !buffer.open( IO_WriteOnly ) )
893 return FALSE; 883 return FALSE;
894 884
895 QTextStream ts( &buffer ); 885 QTextStream ts( &buffer );
896 QString fn = arg; 886 QString fn = arg;
897 887
898 if ( fn.isEmpty() ) 888 if ( fn.isEmpty() )
899 fn = directory.path(); 889 fn = directory.path();
900 890
901 QFileInfo fi( fn ); 891 QFileInfo fi( fn );
902 if ( !fi.exists() ) return FALSE; 892 if ( !fi.exists() ) return FALSE;
903 893
904 // return file listing 894 // return file listing
905 if ( fi.isFile() ) { 895 if ( fi.isFile() ) {
906 ts << fileListing( &fi ) << endl; 896 ts << fileListing( &fi ) << endl;
907 } 897 }
908 898
909 // return directory listing 899 // return directory listing
910 else if ( fi.isDir() ) { 900 else if ( fi.isDir() ) {
911 QDir dir( fn ); 901 QDir dir( fn );
912 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 902 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
913 903
914 QFileInfoListIterator it( *list ); 904 QFileInfoListIterator it( *list );
915 QFileInfo *info; 905 QFileInfo *info;
916 906
917 unsigned long total = 0; 907 unsigned long total = 0;
918 while ( ( info = it.current() ) ) { 908 while ( ( info = it.current() ) ) {
919 if ( info->fileName() != "." && info->fileName() != ".." ) 909 if ( info->fileName() != "." && info->fileName() != ".." )
920 total += info->size(); 910 total += info->size();
921 ++it; 911 ++it;
922 } 912 }
923 913
924 ts << "total " << QString::number( total / 1024 ) << endl; // No tr 914 ts << "total " << QString::number( total / 1024 ) << endl; // No tr
925 915
926 it.toFirst(); 916 it.toFirst();
927 while ( ( info = it.current() ) ) { 917 while ( ( info = it.current() ) ) {
928 if ( info->fileName() == "." || info->fileName() == ".." ) { 918 if ( info->fileName() == "." || info->fileName() == ".." ) {
929 ++it; 919 ++it;
930 continue; 920 continue;
931 } 921 }
932 ts << fileListing( info ) << endl; 922 ts << fileListing( info ) << endl;
933 ++it; 923 ++it;
934 } 924 }
935 } 925 }
936 926
937 if ( passiv ) { 927 if ( passiv ) {
938 waitarray = buffer.buffer(); 928 waitarray = buffer.buffer();
939 wait[SendByteArray] = TRUE; 929 wait[SendByteArray] = TRUE;
940 if ( waitsocket ) 930 if ( waitsocket )
941 newConnection( waitsocket ); 931 newConnection( waitsocket );
942 } 932 }
943 else 933 else
944 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); 934 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
945 return TRUE; 935 return TRUE;
946} 936}
947 937
948QString ServerPI::fileListing( QFileInfo *info ) 938QString ServerPI::fileListing( QFileInfo *info )
949{ 939{
950 if ( !info ) return QString::null; 940 if ( !info ) return QString::null;
951 QString s; 941 QString s;
952 942
953 // type char 943 // type char
954 if ( info->isDir() ) 944 if ( info->isDir() )
955 s += "d"; 945 s += "d";
956 else if ( info->isSymLink() ) 946 else if ( info->isSymLink() )
957 s += "l"; 947 s += "l";
958 else 948 else
959 s += "-"; 949 s += "-";
960 950
961 // permisson string 951 // permisson string
962 s += permissionString( info ) + " "; 952 s += permissionString( info ) + " ";
963 953
964 // number of hardlinks 954 // number of hardlinks
965 int subdirs = 1; 955 int subdirs = 1;
966 956
967 if ( info->isDir() ) 957 if ( info->isDir() )
968 subdirs = 2; 958 subdirs = 2;
969 // FIXME : this is to slow 959 // FIXME : this is to slow
970 //if ( info->isDir() ) 960 //if ( info->isDir() )
971 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); 961 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count();
972 962
973 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; 963 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " ";
974 964
975 // owner 965 // owner
976 QString o = info->owner(); 966 QString o = info->owner();
977 if ( o.isEmpty() ) 967 if ( o.isEmpty() )
978 o = QString::number(info->ownerId()); 968 o = QString::number(info->ownerId());
979 s += o.leftJustify( 8, ' ', TRUE ) + " "; 969 s += o.leftJustify( 8, ' ', TRUE ) + " ";
980 970
981 // group 971 // group
982 QString g = info->group(); 972 QString g = info->group();
983 if ( g.isEmpty() ) 973 if ( g.isEmpty() )
984 g = QString::number(info->groupId()); 974 g = QString::number(info->groupId());
985 s += g.leftJustify( 8, ' ', TRUE ) + " "; 975 s += g.leftJustify( 8, ' ', TRUE ) + " ";
986 976
987 // file size in bytes 977 // file size in bytes
988 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; 978 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " ";
989 979
990 // last modified date 980 // last modified date
991 QDate date = info->lastModified().date(); 981 QDate date = info->lastModified().date();
992 QTime time = info->lastModified().time(); 982 QTime time = info->lastModified().time();
993 s += date.monthName( date.month() ) + " " 983 s += date.monthName( date.month() ) + " "
994 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " 984 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
995 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" 985 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
996 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; 986 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
997 987
998 // file name 988 // file name
999 s += info->fileName(); 989 s += info->fileName();
1000 990
1001 return s; 991 return s;
1002} 992}
1003 993
1004QString ServerPI::permissionString( QFileInfo *info ) 994QString ServerPI::permissionString( QFileInfo *info )
1005{ 995{
1006 if ( !info ) return QString( "---------" ); 996 if ( !info ) return QString( "---------" );
1007 QString s; 997 QString s;
1008 998
1009 // user 999 // user
1010 if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; 1000 if ( info->permission( QFileInfo::ReadUser ) ) s += "r";
1011 else s += "-"; 1001 else s += "-";
1012 if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; 1002 if ( info->permission( QFileInfo::WriteUser ) ) s += "w";
1013 else s += "-"; 1003 else s += "-";
1014 if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; 1004 if ( info->permission( QFileInfo::ExeUser ) ) s += "x";
1015 else s += "-"; 1005 else s += "-";
1016 1006
1017 // group 1007 // group
1018 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; 1008 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r";
1019 else s += "-"; 1009 else s += "-";
1020 if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; 1010 if ( info->permission( QFileInfo::WriteGroup ) )s += "w";
1021 else s += "-"; 1011 else s += "-";
1022 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; 1012 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x";
1023 else s += "-"; 1013 else s += "-";
1024 1014
1025 // exec 1015 // exec
1026 if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; 1016 if ( info->permission( QFileInfo::ReadOther ) ) s += "r";
1027 else s += "-"; 1017 else s += "-";
1028 if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; 1018 if ( info->permission( QFileInfo::WriteOther ) ) s += "w";
1029 else s += "-"; 1019 else s += "-";
1030 if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; 1020 if ( info->permission( QFileInfo::ExeOther ) ) s += "x";
1031 else s += "-"; 1021 else s += "-";
1032 1022
1033 return s; 1023 return s;
1034} 1024}
1035 1025
1036void ServerPI::newConnection( int socket ) 1026void ServerPI::newConnection( int socket )
1037{ 1027{
1038 //qDebug( "New incomming connection" ); 1028 //qDebug( "New incomming connection" );
1039 1029
1040 if ( !passiv ) return; 1030 if ( !passiv ) return;
1041 1031
1042 if ( wait[SendFile] ) { 1032 if ( wait[SendFile] ) {
1043 QStringList targets; 1033 QStringList targets;
1044 if ( backupRestoreGzip( waitfile, targets ) ) 1034 if ( backupRestoreGzip( waitfile, targets ) )
1045 dtp->sendGzipFile( waitfile, targets ); 1035 dtp->sendGzipFile( waitfile, targets );
1046 else 1036 else
1047 dtp->sendFile( waitfile ); 1037 dtp->sendFile( waitfile );
1048 dtp->setSocket( socket ); 1038 dtp->setSocket( socket );
1049 } 1039 }
1050 else if ( wait[RetrieveFile] ) { 1040 else if ( wait[RetrieveFile] ) {
1051 qDebug("check retrieve file"); 1041 qDebug("check retrieve file");
1052 if ( backupRestoreGzip( waitfile ) ) 1042 if ( backupRestoreGzip( waitfile ) )
1053 dtp->retrieveGzipFile( waitfile ); 1043 dtp->retrieveGzipFile( waitfile );
1054 else 1044 else
1055 dtp->retrieveFile( waitfile, storFileSize ); 1045 dtp->retrieveFile( waitfile, storFileSize );
1056 dtp->setSocket( socket ); 1046 dtp->setSocket( socket );
1057 } 1047 }
1058 else if ( wait[SendByteArray] ) { 1048 else if ( wait[SendByteArray] ) {
1059 dtp->sendByteArray( waitarray ); 1049 dtp->sendByteArray( waitarray );
1060 dtp->setSocket( socket ); 1050 dtp->setSocket( socket );
1061 } 1051 }
1062 else if ( wait[RetrieveByteArray] ) { 1052 else if ( wait[RetrieveByteArray] ) {
1063 qDebug("retrieve byte array"); 1053 qDebug("retrieve byte array");
1064 dtp->retrieveByteArray(); 1054 dtp->retrieveByteArray();
1065 dtp->setSocket( socket ); 1055 dtp->setSocket( socket );
1066 } 1056 }
1067 else 1057 else
1068 waitsocket = socket; 1058 waitsocket = socket;
1069 1059
1070 for( int i = 0; i < 4; i++ ) 1060 for( int i = 0; i < 4; i++ )
1071 wait[i] = FALSE; 1061 wait[i] = FALSE;
1072} 1062}
1073 1063
1074QString ServerPI::absFilePath( const QString& file ) 1064QString ServerPI::absFilePath( const QString& file )
1075{ 1065{
1076 if ( file.isEmpty() ) return file; 1066 if ( file.isEmpty() ) return file;
1077 1067
1078 QString filepath( file ); 1068 QString filepath( file );
1079 if ( file[0] != "/" ) 1069 if ( file[0] != "/" )
1080 filepath = directory.path() + "/" + file; 1070 filepath = directory.path() + "/" + file;
1081 1071
1082 return filepath; 1072 return filepath;
1083} 1073}
1084 1074
1085 1075
1086void ServerPI::timerEvent( QTimerEvent * ) 1076void ServerPI::timerEvent( QTimerEvent * )
1087{ 1077{
1088 connectionClosed(); 1078 connectionClosed();
1089} 1079}
1090 1080
1091 1081
1092ServerDTP::ServerDTP( QObject *parent, const char* name) 1082ServerDTP::ServerDTP( QObject *parent, const char* name)
1093 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 1083 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
1094 retrieveTargzProc( 0 ) 1084 retrieveTargzProc( 0 )
1095{ 1085{
1096 1086
1097 connect( this, SIGNAL( connected() ), SLOT( connected() ) ); 1087 connect( this, SIGNAL( connected() ), SLOT( connected() ) );
1098 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 1088 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
1099 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); 1089 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) );
1100 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 1090 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
1101 1091
1102 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr 1092 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr
1103 createTargzProc->setCommunication( QProcess::Stdout ); 1093 createTargzProc->setCommunication( QProcess::Stdout );
1104 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1094 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1105 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 1095 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
1106 1096
1107 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" ); 1097 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" );
1108 retrieveTargzProc->setCommunication( QProcess::Stdin ); 1098 retrieveTargzProc->setCommunication( QProcess::Stdin );
1109 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1099 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1110 connect( retrieveTargzProc, SIGNAL( processExited() ), 1100 connect( retrieveTargzProc, SIGNAL( processExited() ),
1111 SIGNAL( completed() ) ); 1101 SIGNAL( completed() ) );
1112 connect( retrieveTargzProc, SIGNAL( processExited() ), 1102 connect( retrieveTargzProc, SIGNAL( processExited() ),
1113 SLOT( extractTarDone() ) ); 1103 SLOT( extractTarDone() ) );
1114} 1104}
1115 1105
1116ServerDTP::~ServerDTP() 1106ServerDTP::~ServerDTP()
1117{ 1107{
1118 buf.close(); 1108 buf.close();
1119 if ( RetrieveFile == mode && file.isOpen() ) { 1109 if ( RetrieveFile == mode && file.isOpen() ) {
1120 // We're being shutdown before the client closed. 1110 // We're being shutdown before the client closed.
1121 file.close(); 1111 file.close();
1122 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1112 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1123 qDebug( "STOR incomplete" ); 1113 qDebug( "STOR incomplete" );
1124 file.remove(); 1114 file.remove();
1125 } 1115 }
1126 } else { 1116 } else {
1127 file.close(); 1117 file.close();
1128 } 1118 }
1129 createTargzProc->kill(); 1119 createTargzProc->kill();
1130} 1120}
1131 1121
1132void ServerDTP::extractTarDone() 1122void ServerDTP::extractTarDone()
1133{ 1123{
1134 qDebug("extract done"); 1124 qDebug("extract done");
1135#ifndef QT_NO_COP 1125#ifndef QT_NO_COP
1136 QCopEnvelope e( "QPE/System", "restoreDone(QString)" ); 1126 QCopEnvelope e( "QPE/System", "restoreDone(QString)" );
1137 e << file.name(); 1127 e << file.name();
1138#endif 1128#endif
1139} 1129}
1140 1130
1141void ServerDTP::connected() 1131void ServerDTP::connected()
1142{ 1132{
1143 // send file mode 1133 // send file mode
1144 switch ( mode ) { 1134 switch ( mode ) {
1145 case SendFile : 1135 case SendFile :
1146 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 1136 if ( !file.exists() || !file.open( IO_ReadOnly) ) {
1147 emit failed(); 1137 emit failed();
1148 mode = Idle; 1138 mode = Idle;
1149 return; 1139 return;
1150 } 1140 }
1151 1141
1152 //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); 1142 //qDebug( "Debug: Sending file '%s'", file.name().latin1() );
1153 1143
1154 bytes_written = 0; 1144 bytes_written = 0;
1155 if ( file.size() == 0 ) { 1145 if ( file.size() == 0 ) {
1156 //make sure it doesn't hang on empty files 1146 //make sure it doesn't hang on empty files
1157 file.close(); 1147 file.close();
1158 emit completed(); 1148 emit completed();
1159 mode = Idle; 1149 mode = Idle;
1160 } else { 1150 } else {
1161 // Don't write more if there is plenty buffered already. 1151 // Don't write more if there is plenty buffered already.
1162 if ( bytesToWrite() <= block_size && !file.atEnd() ) { 1152 if ( bytesToWrite() <= block_size && !file.atEnd() ) {
1163 QCString s; 1153 QCString s;
1164 s.resize( block_size ); 1154 s.resize( block_size );
1165 int bytes = file.readBlock( s.data(), block_size ); 1155 int bytes = file.readBlock( s.data(), block_size );
1166 writeBlock( s.data(), bytes ); 1156 writeBlock( s.data(), bytes );
1167 } 1157 }
1168 } 1158 }
1169 break; 1159 break;
1170 case SendGzipFile: 1160 case SendGzipFile:
1171 if ( createTargzProc->isRunning() ) { 1161 if ( createTargzProc->isRunning() ) {
1172 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY 1162 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY
1173 qWarning("Previous tar --gzip process is still running; killing it..."); 1163 qWarning("Previous tar --gzip process is still running; killing it...");
1174 createTargzProc->kill(); 1164 createTargzProc->kill();
1175 } 1165 }
1176 1166
1177 bytes_written = 0; 1167 bytes_written = 0;
1178 qDebug("==>start send tar process"); 1168 qDebug("==>start send tar process");
1179 if ( !createTargzProc->start() ) 1169 if ( !createTargzProc->start() )
1180 qWarning("Error starting %s", 1170 qWarning("Error starting %s",
1181 createTargzProc->arguments().join(" ").latin1()); 1171 createTargzProc->arguments().join(" ").latin1());
1182 break; 1172 break;
1183 case SendBuffer: 1173 case SendBuffer:
1184 if ( !buf.open( IO_ReadOnly) ) { 1174 if ( !buf.open( IO_ReadOnly) ) {
1185 emit failed(); 1175 emit failed();
1186 mode = Idle; 1176 mode = Idle;
1187 return; 1177 return;
1188 } 1178 }
1189 1179
1190 // qDebug( "Debug: Sending byte array" ); 1180 // qDebug( "Debug: Sending byte array" );
1191 bytes_written = 0; 1181 bytes_written = 0;
1192 while( !buf.atEnd() ) 1182 while( !buf.atEnd() )
1193 putch( buf.getch() ); 1183 putch( buf.getch() );
1194 buf.close(); 1184 buf.close();
1195 break; 1185 break;
1196 case RetrieveFile: 1186 case RetrieveFile:
1197 // retrieve file mode 1187 // retrieve file mode
1198 if ( file.exists() && !file.remove() ) { 1188 if ( file.exists() && !file.remove() ) {
1199 emit failed(); 1189 emit failed();
1200 mode = Idle; 1190 mode = Idle;
1201 return; 1191 return;
1202 } 1192 }
1203 1193
1204 if ( !file.open( IO_WriteOnly) ) { 1194 if ( !file.open( IO_WriteOnly) ) {
1205 emit failed(); 1195 emit failed();
1206 mode = Idle; 1196 mode = Idle;
1207 return; 1197 return;
1208 } 1198 }
1209 // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); 1199 // qDebug( "Debug: Retrieving file %s", file.name().latin1() );
1210 break; 1200 break;
1211 case RetrieveGzipFile: 1201 case RetrieveGzipFile:
1212 qDebug("=-> starting tar process to receive .tgz file"); 1202 qDebug("=-> starting tar process to receive .tgz file");
1213 break; 1203 break;
1214 case RetrieveBuffer: 1204 case RetrieveBuffer:
1215 // retrieve buffer mode 1205 // retrieve buffer mode
1216 if ( !buf.open( IO_WriteOnly) ) { 1206 if ( !buf.open( IO_WriteOnly) ) {
1217 emit failed(); 1207 emit failed();
1218 mode = Idle; 1208 mode = Idle;
1219 return; 1209 return;
1220 } 1210 }
1221 // qDebug( "Debug: Retrieving byte array" ); 1211 // qDebug( "Debug: Retrieving byte array" );
1222 break; 1212 break;
1223 case Idle: 1213 case Idle:
1224 qDebug("connection established but mode set to Idle; BUG!"); 1214 qDebug("connection established but mode set to Idle; BUG!");
1225 break; 1215 break;
1226 } 1216 }
1227} 1217}
1228 1218
1229void ServerDTP::connectionClosed() 1219void ServerDTP::connectionClosed()
1230{ 1220{
1231 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); 1221 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written );
1232 1222
1233 // send file mode 1223 // send file mode
1234 if ( SendFile == mode ) { 1224 if ( SendFile == mode ) {
1235 if ( bytes_written == file.size() ) 1225 if ( bytes_written == file.size() )
1236 emit completed(); 1226 emit completed();
1237 else 1227 else
1238 emit failed(); 1228 emit failed();
1239 } 1229 }
1240 1230
1241 // send buffer mode 1231 // send buffer mode
1242 else if ( SendBuffer == mode ) { 1232 else if ( SendBuffer == mode ) {
1243 if ( bytes_written == buf.size() ) 1233 if ( bytes_written == buf.size() )
1244 emit completed(); 1234 emit completed();
1245 else 1235 else
1246 emit failed(); 1236 emit failed();
1247 } 1237 }
1248 1238
1249 // retrieve file mode 1239 // retrieve file mode
1250 else if ( RetrieveFile == mode ) { 1240 else if ( RetrieveFile == mode ) {
1251 file.close(); 1241 file.close();
1252 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1242 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1253 qDebug( "STOR incomplete" ); 1243 qDebug( "STOR incomplete" );
1254 file.remove(); 1244 file.remove();
1255 emit failed(); 1245 emit failed();
1256 } else { 1246 } else {
1257 emit completed(); 1247 emit completed();
1258 } 1248 }
1259 } 1249 }
1260 1250
1261 else if ( RetrieveGzipFile == mode ) { 1251 else if ( RetrieveGzipFile == mode ) {
1262 qDebug("Done writing ungzip file; closing input"); 1252 qDebug("Done writing ungzip file; closing input");
1263 retrieveTargzProc->flushStdin(); 1253 retrieveTargzProc->flushStdin();
1264 retrieveTargzProc->closeStdin(); 1254 retrieveTargzProc->closeStdin();
1265 } 1255 }
1266 1256
1267 // retrieve buffer mode 1257 // retrieve buffer mode
1268 else if ( RetrieveBuffer == mode ) { 1258 else if ( RetrieveBuffer == mode ) {
1269 buf.close(); 1259 buf.close();
1270 emit completed(); 1260 emit completed();
1271 } 1261 }
1272 1262
1273 mode = Idle; 1263 mode = Idle;
1274} 1264}
1275 1265
1276void ServerDTP::bytesWritten( int bytes ) 1266void ServerDTP::bytesWritten( int bytes )
1277{ 1267{
1278 bytes_written += bytes; 1268 bytes_written += bytes;
1279 1269
1280 // send file mode 1270 // send file mode
1281 if ( SendFile == mode ) { 1271 if ( SendFile == mode ) {
1282 1272
1283 if ( bytes_written == file.size() ) { 1273 if ( bytes_written == file.size() ) {
1284 // qDebug( "Debug: Sending complete: %d bytes", file.size() ); 1274 // qDebug( "Debug: Sending complete: %d bytes", file.size() );
1285 file.close(); 1275 file.close();
1286 emit completed(); 1276 emit completed();
1287 mode = Idle; 1277 mode = Idle;
1288 } 1278 }
1289 else if( !file.atEnd() ) { 1279 else if( !file.atEnd() ) {
1290 QCString s; 1280 QCString s;
1291 s.resize( block_size ); 1281 s.resize( block_size );
1292 int bytes = file.readBlock( s.data(), block_size ); 1282 int bytes = file.readBlock( s.data(), block_size );
1293 writeBlock( s.data(), bytes ); 1283 writeBlock( s.data(), bytes );
1294 } 1284 }
1295 } 1285 }
1296 1286
1297 // send buffer mode 1287 // send buffer mode
1298 if ( SendBuffer == mode ) { 1288 if ( SendBuffer == mode ) {
1299 1289
1300 if ( bytes_written == buf.size() ) { 1290 if ( bytes_written == buf.size() ) {
1301 // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); 1291 // qDebug( "Debug: Sending complete: %d bytes", buf.size() );
1302 emit completed(); 1292 emit completed();
1303 mode = Idle; 1293 mode = Idle;
1304 } 1294 }
1305 } 1295 }
1306} 1296}
1307 1297
1308void ServerDTP::readyRead() 1298void ServerDTP::readyRead()
1309{ 1299{
1310 // retrieve file mode 1300 // retrieve file mode
1311 if ( RetrieveFile == mode ) { 1301 if ( RetrieveFile == mode ) {
1312 QCString s; 1302 QCString s;
1313 s.resize( bytesAvailable() ); 1303 s.resize( bytesAvailable() );
1314 readBlock( s.data(), bytesAvailable() ); 1304 readBlock( s.data(), bytesAvailable() );
1315 file.writeBlock( s.data(), s.size() ); 1305 file.writeBlock( s.data(), s.size() );
1316 } 1306 }
1317 else if ( RetrieveGzipFile == mode ) { 1307 else if ( RetrieveGzipFile == mode ) {
1318 if ( !retrieveTargzProc->isRunning() ) 1308 if ( !retrieveTargzProc->isRunning() )
1319 retrieveTargzProc->start(); 1309 retrieveTargzProc->start();
1320 1310
1321 QByteArray s; 1311 QByteArray s;
1322 s.resize( bytesAvailable() ); 1312 s.resize( bytesAvailable() );
1323 readBlock( s.data(), bytesAvailable() ); 1313 readBlock( s.data(), bytesAvailable() );
1324 retrieveTargzProc->writeToStdin( s ); 1314 retrieveTargzProc->writeToStdin( s );
1325 qDebug("wrote %d bytes to ungzip ", s.size() ); 1315 qDebug("wrote %d bytes to ungzip ", s.size() );
1326 } 1316 }
1327 // retrieve buffer mode 1317 // retrieve buffer mode
1328 else if ( RetrieveBuffer == mode ) { 1318 else if ( RetrieveBuffer == mode ) {
1329 QCString s; 1319 QCString s;
1330 s.resize( bytesAvailable() ); 1320 s.resize( bytesAvailable() );
1331 readBlock( s.data(), bytesAvailable() ); 1321 readBlock( s.data(), bytesAvailable() );
1332 buf.writeBlock( s.data(), s.size() ); 1322 buf.writeBlock( s.data(), s.size() );
1333 } 1323 }
1334} 1324}
1335 1325
1336void ServerDTP::writeTargzBlock() 1326void ServerDTP::writeTargzBlock()
1337{ 1327{
1338 QByteArray block = createTargzProc->readStdout(); 1328 QByteArray block = createTargzProc->readStdout();
1339 writeBlock( block.data(), block.size() ); 1329 writeBlock( block.data(), block.size() );
1340 qDebug("writeTargzBlock %d", block.size()); 1330 qDebug("writeTargzBlock %d", block.size());
1341} 1331}
1342 1332
1343void ServerDTP::targzDone() 1333void ServerDTP::targzDone()
1344{ 1334{
1345 qDebug("tar and gzip done"); 1335 qDebug("tar and gzip done");
1346 emit completed(); 1336 emit completed();
1347 mode = Idle; 1337 mode = Idle;
1348 disconnect( createTargzProc, SIGNAL( readyReadStdout() ), 1338 disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
1349 this, SLOT( writeTargzBlock() ) ); 1339 this, SLOT( writeTargzBlock() ) );
1350} 1340}
1351 1341
1352void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1342void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1353{ 1343{
1354 file.setName( fn ); 1344 file.setName( fn );
1355 mode = SendFile; 1345 mode = SendFile;
1356 connectToHost( host.toString(), port ); 1346 connectToHost( host.toString(), port );
1357} 1347}
1358 1348
1359void ServerDTP::sendFile( const QString fn ) 1349void ServerDTP::sendFile( const QString fn )
1360{ 1350{
1361 file.setName( fn ); 1351 file.setName( fn );
1362 mode = SendFile; 1352 mode = SendFile;
1363} 1353}
1364 1354
1365void ServerDTP::sendGzipFile( const QString &fn, 1355void ServerDTP::sendGzipFile( const QString &fn,
1366 const QStringList &archiveTargets, 1356 const QStringList &archiveTargets,
1367 const QHostAddress& host, Q_UINT16 port ) 1357 const QHostAddress& host, Q_UINT16 port )
1368{ 1358{
1369 sendGzipFile( fn, archiveTargets ); 1359 sendGzipFile( fn, archiveTargets );
1370 connectToHost( host.toString(), port ); 1360 connectToHost( host.toString(), port );
1371} 1361}
1372 1362
1373void ServerDTP::sendGzipFile( const QString &fn, 1363void ServerDTP::sendGzipFile( const QString &fn,
1374 const QStringList &archiveTargets ) 1364 const QStringList &archiveTargets )
1375{ 1365{
1376 mode = SendGzipFile; 1366 mode = SendGzipFile;
1377 file.setName( fn ); 1367 file.setName( fn );
1378 1368
1379 QStringList args = "targzip"; 1369 QStringList args = "targzip";
1380 //args += "-cv"; 1370 //args += "-cv";
1381 args += archiveTargets; 1371 args += archiveTargets;
1382 qDebug("sendGzipFile %s", args.join(" ").latin1() ); 1372 qDebug("sendGzipFile %s", args.join(" ").latin1() );
1383 createTargzProc->setArguments( args ); 1373 createTargzProc->setArguments( args );
1384 connect( createTargzProc, 1374 connect( createTargzProc,
1385 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); 1375 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) );
1386} 1376}
1387 1377
1388void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) 1378void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize )
1389{ 1379{
1390 recvFileSize = fileSize; 1380 recvFileSize = fileSize;
1391 file.setName( fn ); 1381 file.setName( fn );
1392 mode = RetrieveFile; 1382 mode = RetrieveFile;
1393 connectToHost( host.toString(), port ); 1383 connectToHost( host.toString(), port );
1394} 1384}
1395 1385
1396void ServerDTP::retrieveFile( const QString fn, int fileSize ) 1386void ServerDTP::retrieveFile( const QString fn, int fileSize )
1397{ 1387{
1398 recvFileSize = fileSize; 1388 recvFileSize = fileSize;
1399 file.setName( fn ); 1389 file.setName( fn );
1400 mode = RetrieveFile; 1390 mode = RetrieveFile;
1401} 1391}
1402 1392
1403void ServerDTP::retrieveGzipFile( const QString &fn ) 1393void ServerDTP::retrieveGzipFile( const QString &fn )
1404{ 1394{
1405 qDebug("retrieveGzipFile %s", fn.latin1()); 1395 qDebug("retrieveGzipFile %s", fn.latin1());
1406 file.setName( fn ); 1396 file.setName( fn );
1407 mode = RetrieveGzipFile; 1397 mode = RetrieveGzipFile;
1408 1398
1409 retrieveTargzProc->setArguments( "targunzip" ); 1399 retrieveTargzProc->setArguments( "targunzip" );
1410 connect( retrieveTargzProc, SIGNAL( processExited() ), 1400 connect( retrieveTargzProc, SIGNAL( processExited() ),
1411 SLOT( extractTarDone() ) ); 1401 SLOT( extractTarDone() ) );
1412} 1402}
1413 1403
1414void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) 1404void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port )
1415{ 1405{
1416 retrieveGzipFile( fn ); 1406 retrieveGzipFile( fn );
1417 connectToHost( host.toString(), port ); 1407 connectToHost( host.toString(), port );
1418} 1408}
1419 1409
1420void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) 1410void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port )
1421{ 1411{
1422 buf.setBuffer( array ); 1412 buf.setBuffer( array );
1423 mode = SendBuffer; 1413 mode = SendBuffer;
1424 connectToHost( host.toString(), port ); 1414 connectToHost( host.toString(), port );
1425} 1415}
1426 1416
1427void ServerDTP::sendByteArray( const QByteArray& array ) 1417void ServerDTP::sendByteArray( const QByteArray& array )
1428{ 1418{
1429 buf.setBuffer( array ); 1419 buf.setBuffer( array );
1430 mode = SendBuffer; 1420 mode = SendBuffer;
1431} 1421}
1432 1422
1433void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) 1423void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port )
1434{ 1424{
1435 buf.setBuffer( QByteArray() ); 1425 buf.setBuffer( QByteArray() );
1436 mode = RetrieveBuffer; 1426 mode = RetrieveBuffer;
1437 connectToHost( host.toString(), port ); 1427 connectToHost( host.toString(), port );
1438} 1428}
1439 1429
1440void ServerDTP::retrieveByteArray() 1430void ServerDTP::retrieveByteArray()
1441{ 1431{
1442 buf.setBuffer( QByteArray() ); 1432 buf.setBuffer( QByteArray() );
1443 mode = RetrieveBuffer; 1433 mode = RetrieveBuffer;
1444} 1434}
1445 1435
1446void ServerDTP::setSocket( int socket ) 1436void ServerDTP::setSocket( int socket )
1447{ 1437{
1448 QSocket::setSocket( socket ); 1438 QSocket::setSocket( socket );
1449 connected(); 1439 connected();
1450} 1440}
1451 1441
diff --git a/core/launcher/wait.cpp b/core/launcher/wait.cpp
index 34ffd1a..4148e57 100644
--- a/core/launcher/wait.cpp
+++ b/core/launcher/wait.cpp
@@ -1,78 +1,74 @@
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 "wait.h" 21#include "wait.h"
22 22
23#include <qtopia/resource.h>
24#include <qtopia/config.h> 23#include <qtopia/config.h>
25 24
26#include <opie2/owait.h> 25#include <opie2/owait.h>
27 26
28#include <qwidget.h>
29#include <qpixmap.h>
30#include <qpainter.h>
31 27
32 28
33Wait *lastWaitObject = NULL; 29Wait *lastWaitObject = NULL;
34 30
35 31
36Wait::Wait( QWidget *parent ) : QWidget( parent ), 32Wait::Wait( QWidget *parent ) : QWidget( parent ),
37 pm( Resource::loadPixmap( "wait" ) ), waiting( FALSE ) 33 pm( Resource::loadPixmap( "wait" ) ), waiting( FALSE )
38{ 34{
39 setFixedSize( pm.size() ); 35 setFixedSize( pm.size() );
40 lastWaitObject = this; 36 lastWaitObject = this;
41 m_centralWait = new OWait( 0l ); 37 m_centralWait = new OWait( 0l );
42 m_centralWait->hide(); 38 m_centralWait->hide();
43 hide(); 39 hide();
44} 40}
45 41
46 42
47Wait *Wait::getWaitObject() 43Wait *Wait::getWaitObject()
48{ 44{
49 return lastWaitObject; 45 return lastWaitObject;
50} 46}
51 47
52 48
53void Wait::setWaiting( bool w ) 49void Wait::setWaiting( bool w )
54{ 50{
55 Config cfg ( "Launcher" ); 51 Config cfg ( "Launcher" );
56 cfg.setGroup("GUI"); 52 cfg.setGroup("GUI");
57 53
58 54
59 waiting = w; 55 waiting = w;
60 if ( w ) { 56 if ( w ) {
61 if ( cfg. readBoolEntry( "BigBusy" ) ) 57 if ( cfg. readBoolEntry( "BigBusy" ) )
62 m_centralWait->show(); 58 m_centralWait->show();
63 else 59 else
64 show(); 60 show();
65 }else{ 61 }else{
66 m_centralWait->hide(); 62 m_centralWait->hide();
67 hide(); 63 hide();
68 } 64 }
69} 65}
70 66
71 67
72void Wait::paintEvent( QPaintEvent * ) 68void Wait::paintEvent( QPaintEvent * )
73{ 69{
74 QPainter p( this ); 70 QPainter p( this );
75 p.drawPixmap( 0, 0, pm ); 71 p.drawPixmap( 0, 0, pm );
76} 72}
77 73
78 74