summaryrefslogtreecommitdiff
authorzecke <zecke>2002-11-03 11:08:07 (UTC)
committer zecke <zecke>2002-11-03 11:08:07 (UTC)
commit2ddf0a555fc848930de8b0f7b237bbd7f2a028ca (patch) (unidiff)
treeae30e333c5c1ee830e46f7f868c5e56876f7e93c
parent207f7430db6c90e88825ea2bedc9ae1bf68e3d99 (diff)
downloadopie-2ddf0a555fc848930de8b0f7b237bbd7f2a028ca.zip
opie-2ddf0a555fc848930de8b0f7b237bbd7f2a028ca.tar.gz
opie-2ddf0a555fc848930de8b0f7b237bbd7f2a028ca.tar.bz2
Nice to see more kde dudes here!
A patch from jowenn to make Opie compile with gcc3 again No default arguments! Some namespace issues
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp5
-rw-r--r--core/launcher/transferserver.cpp2
2 files changed, 4 insertions, 3 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index 2a051a6..95a1d4a 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -1,981 +1,982 @@
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 <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24#include <qpe/applnk.h> 24#include <qpe/applnk.h>
25#include <qpe/qpedebug.h> 25#include <qpe/qpedebug.h>
26#include <qpe/categories.h> 26#include <qpe/categories.h>
27#include <qpe/categoryselect.h> 27#include <qpe/categoryselect.h>
28#include <qpe/menubutton.h> 28#include <qpe/menubutton.h>
29#include <qpe/mimetype.h> 29#include <qpe/mimetype.h>
30#include <qpe/resource.h> 30#include <qpe/resource.h>
31#include <qpe/qpetoolbar.h> 31#include <qpe/qpetoolbar.h>
32//#include <qtopia/private/palmtoprecord.h> 32//#include <qtopia/private/palmtoprecord.h>
33 33
34#include <qtimer.h> 34#include <qtimer.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qdict.h> 36#include <qdict.h>
37#include <qfile.h> 37#include <qfile.h>
38#include <qfileinfo.h> 38#include <qfileinfo.h>
39#include <qhbox.h> 39#include <qhbox.h>
40#include <qiconview.h> 40#include <qiconview.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qregexp.h> 42#include <qregexp.h>
43#include <qtoolbutton.h> 43#include <qtoolbutton.h>
44#include <qimage.h> 44#include <qimage.h>
45 45
46#include <cstdlib>
46 47
47class BgPixmap 48class BgPixmap
48{ 49{
49public: 50public:
50 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} 51 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
51 QPixmap pm; 52 QPixmap pm;
52 int ref; 53 int ref;
53}; 54};
54 55
55enum BusyIndicatorType { 56enum BusyIndicatorType {
56 BIT_Normal = 0, 57 BIT_Normal = 0,
57 BIT_Blinking 58 BIT_Blinking
58}; 59};
59 60
60static QMap<QString,BgPixmap*> *bgCache = 0; 61static QMap<QString,BgPixmap*> *bgCache = 0;
61 62
62class LauncherIconView : public QIconView { 63class LauncherIconView : public QIconView {
63public: 64public:
64 LauncherIconView( QWidget* parent, const char* name=0 ) : 65 LauncherIconView( QWidget* parent, const char* name=0 ) :
65 QIconView(parent,name), 66 QIconView(parent,name),
66 tf(""), 67 tf(""),
67 cf(0), 68 cf(0),
68 bsy(0), 69 bsy(0),
69 bigIcns(TRUE), 70 bigIcns(TRUE),
70 bgColor(white) 71 bgColor(white)
71 { 72 {
72 sortmeth = Name; 73 sortmeth = Name;
73 hidden.setAutoDelete(TRUE); 74 hidden.setAutoDelete(TRUE);
74 ike = FALSE; 75 ike = FALSE;
75 busytimer = 0; 76 busytimer = 0;
76 calculateGrid( Bottom ); 77 calculateGrid( Bottom );
77 } 78 }
78 79
79 ~LauncherIconView() 80 ~LauncherIconView()
80 { 81 {
81#if 0 // debuggery 82#if 0 // debuggery
82 QListIterator<AppLnk> it(hidden); 83 QListIterator<AppLnk> it(hidden);
83 AppLnk* l; 84 AppLnk* l;
84 while ((l=it.current())) { 85 while ((l=it.current())) {
85 ++it; 86 ++it;
86 //qDebug("%p: hidden (should remove)",l); 87 //qDebug("%p: hidden (should remove)",l);
87 } 88 }
88#endif 89#endif
89 } 90 }
90 91
91 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } 92 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
92 93
93 QPixmap* busyPixmap() const { return (QPixmap*)&bpm[::abs(busystate)]; } 94 QPixmap* busyPixmap() const { return (QPixmap*)&bpm[abs(busystate)]; }
94 QIconViewItem* busyItem() const { return bsy; } 95 QIconViewItem* busyItem() const { return bsy; }
95 void setBigIcons( bool bi ) { bigIcns = bi; } 96 void setBigIcons( bool bi ) { bigIcns = bi; }
96 97
97 void updateCategoriesAndMimeTypes(); 98 void updateCategoriesAndMimeTypes();
98 99
99 void doAutoScroll() 100 void doAutoScroll()
100 { 101 {
101 // We don't want rubberbanding (yet) 102 // We don't want rubberbanding (yet)
102 } 103 }
103 104
104 void setBusy(bool on) 105 void setBusy(bool on)
105 { 106 {
106 QIconViewItem *c = on ? currentItem() : 0; 107 QIconViewItem *c = on ? currentItem() : 0;
107 108
108 if ( bsy != c ) { 109 if ( bsy != c ) {
109 QIconViewItem *oldbsy = bsy; 110 QIconViewItem *oldbsy = bsy;
110 bsy = c; 111 bsy = c;
111 112
112 if ( oldbsy ) 113 if ( oldbsy )
113 oldbsy-> repaint ( ); 114 oldbsy-> repaint ( );
114 115
115 if ( busytimer ) { 116 if ( busytimer ) {
116 killTimer ( busytimer ); 117 killTimer ( busytimer );
117 busytimer = 0; 118 busytimer = 0;
118 } 119 }
119 120
120 if ( bsy ) { 121 if ( bsy ) {
121 QPixmap *src = bsy-> QIconViewItem::pixmap(); 122 QPixmap *src = bsy-> QIconViewItem::pixmap();
122 for ( int i = 0; i <= 5; i++ ) { 123 for ( int i = 0; i <= 5; i++ ) {
123 QImage img = src->convertToImage(); 124 QImage img = src->convertToImage();
124 QRgb* rgb; 125 QRgb* rgb;
125 int count; 126 int count;
126 if ( img.depth() == 32 ) { 127 if ( img.depth() == 32 ) {
127 rgb = (QRgb*)img.bits(); 128 rgb = (QRgb*)img.bits();
128 count = img.bytesPerLine()/sizeof(QRgb)*img.height(); 129 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
129 } else { 130 } else {
130 rgb = img.colorTable(); 131 rgb = img.colorTable();
131 count = img.numColors(); 132 count = img.numColors();
132 } 133 }
133 int rc, gc, bc; 134 int rc, gc, bc;
134 int bs = ::abs ( i * 10 ) + 25; 135 int bs = abs ( i * 10 ) + 25;
135 colorGroup().highlight().rgb( &rc, &gc, &bc ); 136 colorGroup().highlight().rgb( &rc, &gc, &bc );
136 rc = rc * bs / 100; 137 rc = rc * bs / 100;
137 gc = gc * bs / 100; 138 gc = gc * bs / 100;
138 bc = bc * bs / 100; 139 bc = bc * bs / 100;
139 140
140 for ( int r = 0; r < count; r++, rgb++ ) { 141 for ( int r = 0; r < count; r++, rgb++ ) {
141 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100; 142 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100;
142 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100; 143 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100;
143 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100; 144 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100;
144 int ai = qAlpha ( *rgb ); 145 int ai = qAlpha ( *rgb );
145 *rgb = qRgba ( ri, gi, bi, ai ); 146 *rgb = qRgba ( ri, gi, bi, ai );
146 } 147 }
147 148
148 bpm [i].convertFromImage( img ); 149 bpm [i].convertFromImage( img );
149 } 150 }
150 151
151 if ( busyType == BIT_Blinking ) { 152 if ( busyType == BIT_Blinking ) {
152 busystate = 0; 153 busystate = 0;
153 busytimer = startTimer ( 200 ); 154 busytimer = startTimer ( 200 );
154 } 155 }
155 else { 156 else {
156 busystate = 3; 157 busystate = 3;
157 } 158 }
158 timerEvent ( 0 ); 159 timerEvent ( 0 );
159 } 160 }
160 } 161 }
161 } 162 }
162 163
163 virtual void timerEvent ( QTimerEvent *te ) 164 virtual void timerEvent ( QTimerEvent *te )
164 { 165 {
165 if ( !te || ( te-> timerId ( ) == busytimer )) { 166 if ( !te || ( te-> timerId ( ) == busytimer )) {
166 if ( bsy ) { 167 if ( bsy ) {
167 busystate++; 168 busystate++;
168 if ( busystate > 5 ) 169 if ( busystate > 5 )
169 busystate = -4; 170 busystate = -4;
170 171
171 QScrollView::updateContents ( bsy-> pixmapRect ( false )); 172 QScrollView::updateContents ( bsy-> pixmapRect ( false ));
172 } 173 }
173 } 174 }
174 } 175 }
175 176
176 bool inKeyEvent() const { return ike; } 177 bool inKeyEvent() const { return ike; }
177 void keyPressEvent(QKeyEvent* e) 178 void keyPressEvent(QKeyEvent* e)
178 { 179 {
179 ike = TRUE; 180 ike = TRUE;
180 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) 181 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space )
181 returnPressed(currentItem()); 182 returnPressed(currentItem());
182 QIconView::keyPressEvent(e); 183 QIconView::keyPressEvent(e);
183 ike = FALSE; 184 ike = FALSE;
184 } 185 }
185 186
186 void addItem(AppLnk* app, bool resort=TRUE); 187 void addItem(AppLnk* app, bool resort=TRUE);
187 bool removeLink(const QString& linkfile); 188 bool removeLink(const QString& linkfile);
188 189
189 QStringList mimeTypes() const; 190 QStringList mimeTypes() const;
190 QStringList categories() const; 191 QStringList categories() const;
191 192
192 void clear() 193 void clear()
193 { 194 {
194 mimes.clear(); 195 mimes.clear();
195 cats.clear(); 196 cats.clear();
196 QIconView::clear(); 197 QIconView::clear();
197 hidden.clear(); 198 hidden.clear();
198 } 199 }
199 200
200 void addCatsAndMimes(AppLnk* app) 201 void addCatsAndMimes(AppLnk* app)
201 { 202 {
202 // QStringList c = app->categories(); 203 // QStringList c = app->categories();
203 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 204 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
204 // cats.replace(*cit,(void*)1); 205 // cats.replace(*cit,(void*)1);
205 // } 206 // }
206 QString maj=app->type(); 207 QString maj=app->type();
207 int sl=maj.find('/'); 208 int sl=maj.find('/');
208 if (sl>=0) { 209 if (sl>=0) {
209 QString k; 210 QString k;
210 k = maj.left(12) == "application/" ? maj : maj.left(sl); 211 k = maj.left(12) == "application/" ? maj : maj.left(sl);
211 mimes.replace(k,(void*)1); 212 mimes.replace(k,(void*)1);
212 } 213 }
213 } 214 }
214 215
215 void setBackgroundPixmap( const QPixmap &pm ) { 216 void setBackgroundPixmap( const QPixmap &pm ) {
216 if ( pm. isNull ( )) { 217 if ( pm. isNull ( )) {
217 bgPixmap = pm; 218 bgPixmap = pm;
218 } 219 }
219 else { 220 else {
220 // This is need for bg images with alpha channel 221 // This is need for bg images with alpha channel
221 222
222 QPixmap tmp ( pm. size ( ), pm. depth ( )); 223 QPixmap tmp ( pm. size ( ), pm. depth ( ));
223 224
224 QPainter p ( &tmp ); 225 QPainter p ( &tmp );
225 p. fillRect ( 0, 0, pm. width ( ), pm. height ( ), bgColor. isValid ( ) ? bgColor : white ); 226 p. fillRect ( 0, 0, pm. width ( ), pm. height ( ), bgColor. isValid ( ) ? bgColor : white );
226 p. drawPixmap ( 0, 0, pm ); 227 p. drawPixmap ( 0, 0, pm );
227 p. end ( ); 228 p. end ( );
228 229
229 bgPixmap = tmp; 230 bgPixmap = tmp;
230 } 231 }
231 } 232 }
232 233
233 void setBackgroundColor( const QColor &c ) { 234 void setBackgroundColor( const QColor &c ) {
234 bgColor = c; 235 bgColor = c;
235 } 236 }
236 237
237 void drawBackground( QPainter *p, const QRect &r ) 238 void drawBackground( QPainter *p, const QRect &r )
238 { 239 {
239 if ( !bgPixmap.isNull() ) { 240 if ( !bgPixmap.isNull() ) {
240 //p-> fillRect ( r, bgColor ); 241 //p-> fillRect ( r, bgColor );
241 p->drawTiledPixmap( r, bgPixmap, 242 p->drawTiledPixmap( r, bgPixmap,
242 QPoint( (r.x() + contentsX()) % bgPixmap.width(), 243 QPoint( (r.x() + contentsX()) % bgPixmap.width(),
243 (r.y() + contentsY()) % bgPixmap.height() ) ); 244 (r.y() + contentsY()) % bgPixmap.height() ) );
244 } else { 245 } else {
245 p->fillRect( r, bgColor ); 246 p->fillRect( r, bgColor );
246 } 247 }
247 } 248 }
248 249
249 void setItemTextPos( ItemTextPos pos ) 250 void setItemTextPos( ItemTextPos pos )
250 { 251 {
251 calculateGrid( pos ); 252 calculateGrid( pos );
252 QIconView::setItemTextPos( pos ); 253 QIconView::setItemTextPos( pos );
253 } 254 }
254 255
255 void hideOrShowItems(bool resort); 256 void hideOrShowItems(bool resort);
256 257
257 void setTypeFilter(const QString& typefilter, bool resort) 258 void setTypeFilter(const QString& typefilter, bool resort)
258 { 259 {
259 tf = QRegExp(typefilter,FALSE,TRUE); 260 tf = QRegExp(typefilter,FALSE,TRUE);
260 hideOrShowItems(resort); 261 hideOrShowItems(resort);
261 } 262 }
262 263
263 void setCategoryFilter( int catfilter, bool resort ) 264 void setCategoryFilter( int catfilter, bool resort )
264 { 265 {
265 Categories cat; 266 Categories cat;
266 cat.load( categoryFileName() ); 267 cat.load( categoryFileName() );
267 QString str; 268 QString str;
268 if ( catfilter == -2 ) 269 if ( catfilter == -2 )
269 cf = 0; 270 cf = 0;
270 else 271 else
271 cf = catfilter; 272 cf = catfilter;
272 hideOrShowItems(resort); 273 hideOrShowItems(resort);
273 } 274 }
274 275
275 enum SortMethod { Name, Date, Type }; 276 enum SortMethod { Name, Date, Type };
276 277
277 void setSortMethod( SortMethod m ) 278 void setSortMethod( SortMethod m )
278 { 279 {
279 if ( sortmeth != m ) { 280 if ( sortmeth != m ) {
280 sortmeth = m; 281 sortmeth = m;
281 sort(); 282 sort();
282 } 283 }
283 } 284 }
284 285
285 int compare(const AppLnk* a, const AppLnk* b) 286 int compare(const AppLnk* a, const AppLnk* b)
286 { 287 {
287 switch (sortmeth) { 288 switch (sortmeth) {
288 case Name: 289 case Name:
289 return a->name().compare(b->name()); 290 return a->name().compare(b->name());
290 case Date: { 291 case Date: {
291 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); 292 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file());
292 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); 293 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file());
293 return fa.lastModified().secsTo(fb.lastModified()); 294 return fa.lastModified().secsTo(fb.lastModified());
294 } 295 }
295 case Type: 296 case Type:
296 return a->type().compare(b->type()); 297 return a->type().compare(b->type());
297 } 298 }
298 return 0; 299 return 0;
299 } 300 }
300 301
301 QString getAllDocLinkInfo() const; 302 QString getAllDocLinkInfo() const;
302 303
303protected: 304protected:
304 305
305 void styleChange( QStyle &old ) 306 void styleChange( QStyle &old )
306 { 307 {
307 QIconView::styleChange( old ); 308 QIconView::styleChange( old );
308 calculateGrid( itemTextPos() ); 309 calculateGrid( itemTextPos() );
309 } 310 }
310 311
311 void calculateGrid( ItemTextPos pos ) 312 void calculateGrid( ItemTextPos pos )
312 { 313 {
313 int dw = QApplication::desktop()->width(); 314 int dw = QApplication::desktop()->width();
314 int viewerWidth = dw-style().scrollBarExtent().width(); 315 int viewerWidth = dw-style().scrollBarExtent().width();
315 if ( pos == Bottom ) { 316 if ( pos == Bottom ) {
316 int cols = 3; 317 int cols = 3;
317 if ( viewerWidth <= 200 ) 318 if ( viewerWidth <= 200 )
318 cols = 2; 319 cols = 2;
319 else if ( viewerWidth >= 400 ) 320 else if ( viewerWidth >= 400 )
320 cols = viewerWidth/96; 321 cols = viewerWidth/96;
321 setSpacing( 4 ); 322 setSpacing( 4 );
322 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 323 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
323 setGridY( fontMetrics().height()*2+24 ); 324 setGridY( fontMetrics().height()*2+24 );
324 } else { 325 } else {
325 int cols = 2; 326 int cols = 2;
326 if ( viewerWidth < 150 ) 327 if ( viewerWidth < 150 )
327 cols = 1; 328 cols = 1;
328 else if ( viewerWidth >= 400 ) 329 else if ( viewerWidth >= 400 )
329 cols = viewerWidth/150; 330 cols = viewerWidth/150;
330 setSpacing( 2 ); 331 setSpacing( 2 );
331 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 332 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
332 setGridY( fontMetrics().height()+2 ); 333 setGridY( fontMetrics().height()+2 );
333 } 334 }
334 } 335 }
335 336
336 337
337 // flicker free redrawing of busy indicator 338 // flicker free redrawing of busy indicator
338 // code was taken from QScrollView::viewportPaintEvent 339 // code was taken from QScrollView::viewportPaintEvent
339 void viewportPaintEvent( QPaintEvent* pe ) 340 void viewportPaintEvent( QPaintEvent* pe )
340 { 341 {
341 static QPixmap *pix = new QPixmap ( ); 342 static QPixmap *pix = new QPixmap ( );
342 343
343 QWidget* vp = viewport(); 344 QWidget* vp = viewport();
344 345
345 if ( vp-> size ( ) != pix-> size ( )) 346 if ( vp-> size ( ) != pix-> size ( ))
346 pix-> resize ( vp-> size ( )); 347 pix-> resize ( vp-> size ( ));
347 348
348 QPainter p(pix, vp); 349 QPainter p(pix, vp);
349 QRect r = pe->rect(); 350 QRect r = pe->rect();
350 if ( clipper ( ) != vp ) { 351 if ( clipper ( ) != vp ) {
351 QRect rr( 352 QRect rr(
352 -vp->x(), -vp->y(), 353 -vp->x(), -vp->y(),
353 clipper()->width(), clipper()->height() 354 clipper()->width(), clipper()->height()
354 ); 355 );
355 r &= rr; 356 r &= rr;
356 if ( r.isValid() ) { 357 if ( r.isValid() ) {
357 int ex = r.x() + vp->x() + contentsX(); 358 int ex = r.x() + vp->x() + contentsX();
358 int ey = r.y() + vp->y() + contentsY(); 359 int ey = r.y() + vp->y() + contentsY();
359 int ew = r.width(); 360 int ew = r.width();
360 int eh = r.height(); 361 int eh = r.height();
361 drawContentsOffset(&p, 362 drawContentsOffset(&p,
362 contentsX()+vp->x(), 363 contentsX()+vp->x(),
363 contentsY()+vp->y(), 364 contentsY()+vp->y(),
364 ex, ey, ew, eh); 365 ex, ey, ew, eh);
365 } 366 }
366 } else { 367 } else {
367 r &= clipper()->rect(); 368 r &= clipper()->rect();
368 int ex = r.x() + contentsX(); 369 int ex = r.x() + contentsX();
369 int ey = r.y() + contentsY(); 370 int ey = r.y() + contentsY();
370 int ew = r.width(); 371 int ew = r.width();
371 int eh = r.height(); 372 int eh = r.height();
372 drawContentsOffset(&p, contentsX(), contentsY(), ex, ey, ew, eh); 373 drawContentsOffset(&p, contentsX(), contentsY(), ex, ey, ew, eh);
373 } 374 }
374 bitBlt ( vp, r.topLeft(), pix, r ); 375 bitBlt ( vp, r.topLeft(), pix, r );
375 } 376 }
376 377
377private: 378private:
378 QList<AppLnk> hidden; 379 QList<AppLnk> hidden;
379 QDict<void> mimes; 380 QDict<void> mimes;
380 QDict<void> cats; 381 QDict<void> cats;
381 SortMethod sortmeth; 382 SortMethod sortmeth;
382 QRegExp tf; 383 QRegExp tf;
383 int cf; 384 int cf;
384 QIconViewItem* bsy; 385 QIconViewItem* bsy;
385 bool ike; 386 bool ike;
386 bool bigIcns; 387 bool bigIcns;
387 QPixmap bgPixmap; 388 QPixmap bgPixmap;
388 QPixmap bpm [6]; 389 QPixmap bpm [6];
389 QColor bgColor; 390 QColor bgColor;
390 int busytimer; 391 int busytimer;
391 int busystate; 392 int busystate;
392 BusyIndicatorType busyType; 393 BusyIndicatorType busyType;
393}; 394};
394 395
395 396
396bool LauncherView::bsy=FALSE; 397bool LauncherView::bsy=FALSE;
397 398
398void LauncherView::setBusy(bool on) 399void LauncherView::setBusy(bool on)
399{ 400{
400 icons->setBusy(on); 401 icons->setBusy(on);
401} 402}
402 403
403class LauncherItem : public QIconViewItem 404class LauncherItem : public QIconViewItem
404{ 405{
405public: 406public:
406 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); 407 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
407 ~LauncherItem() 408 ~LauncherItem()
408 { 409 {
409 LauncherIconView* liv = (LauncherIconView*)iconView(); 410 LauncherIconView* liv = (LauncherIconView*)iconView();
410 if ( liv->busyItem() == this ) 411 if ( liv->busyItem() == this )
411 liv->setBusy(FALSE); 412 liv->setBusy(FALSE);
412 delete app; 413 delete app;
413 } 414 }
414 415
415 AppLnk* appLnk() const { return app; } 416 AppLnk* appLnk() const { return app; }
416 AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } 417 AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; }
417 418
418 virtual int compare ( QIconViewItem * i ) const; 419 virtual int compare ( QIconViewItem * i ) const;
419 420
420 void paintItem( QPainter *p, const QColorGroup &cg ) 421 void paintItem( QPainter *p, const QColorGroup &cg )
421 { 422 {
422 LauncherIconView* liv = (LauncherIconView*)iconView(); 423 LauncherIconView* liv = (LauncherIconView*)iconView();
423 QBrush oldBrush( liv->itemTextBackground() ); 424 QBrush oldBrush( liv->itemTextBackground() );
424 QColorGroup mycg( cg ); 425 QColorGroup mycg( cg );
425 if ( liv->currentItem() == this ) { 426 if ( liv->currentItem() == this ) {
426 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); 427 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
427 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); 428 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
428 } 429 }
429 QIconViewItem::paintItem(p,mycg); 430 QIconViewItem::paintItem(p,mycg);
430 if ( liv->currentItem() == this ) 431 if ( liv->currentItem() == this )
431 liv->setItemTextBackground( oldBrush ); 432 liv->setItemTextBackground( oldBrush );
432 } 433 }
433 434
434 virtual QPixmap* pixmap () const 435 virtual QPixmap* pixmap () const
435 { 436 {
436 const LauncherIconView* liv = (LauncherIconView*)iconView(); 437 const LauncherIconView* liv = (LauncherIconView*)iconView();
437 if ( (const LauncherItem *)liv->busyItem() == this ) 438 if ( (const LauncherItem *)liv->busyItem() == this )
438 return liv->busyPixmap(); 439 return liv->busyPixmap();
439 return QIconViewItem::pixmap(); 440 return QIconViewItem::pixmap();
440 } 441 }
441 442
442protected: 443protected:
443 AppLnk* app; 444 AppLnk* app;
444}; 445};
445 446
446 447
447LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) 448LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon )
448 : QIconViewItem( parent, applnk->name(), 449 : QIconViewItem( parent, applnk->name(),
449 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), 450 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ),
450 app(applnk) // Takes ownership 451 app(applnk) // Takes ownership
451{ 452{
452} 453}
453 454
454int LauncherItem::compare ( QIconViewItem * i ) const 455int LauncherItem::compare ( QIconViewItem * i ) const
455{ 456{
456 LauncherIconView* view = (LauncherIconView*)iconView(); 457 LauncherIconView* view = (LauncherIconView*)iconView();
457 return view->compare(app,((LauncherItem *)i)->appLnk()); 458 return view->compare(app,((LauncherItem *)i)->appLnk());
458} 459}
459 460
460QStringList LauncherIconView::mimeTypes() const 461QStringList LauncherIconView::mimeTypes() const
461{ 462{
462 QStringList r; 463 QStringList r;
463 QDictIterator<void> it(mimes); 464 QDictIterator<void> it(mimes);
464 while (it.current()) { 465 while (it.current()) {
465 r.append(it.currentKey()); 466 r.append(it.currentKey());
466 ++it; 467 ++it;
467 } 468 }
468 r.sort(); 469 r.sort();
469 return r; 470 return r;
470} 471}
471 472
472void LauncherIconView::addItem(AppLnk* app, bool resort) 473void LauncherIconView::addItem(AppLnk* app, bool resort)
473{ 474{
474 addCatsAndMimes(app); 475 addCatsAndMimes(app);
475 476
476 if ( (tf.isEmpty() || tf.match(app->type()) >= 0) 477 if ( (tf.isEmpty() || tf.match(app->type()) >= 0)
477 && (cf == 0 || app->categories().contains(cf) 478 && (cf == 0 || app->categories().contains(cf)
478 || cf == -1 && app->categories().count() == 0 ) ) 479 || cf == -1 && app->categories().count() == 0 ) )
479 (void) new LauncherItem( this, app, bigIcns ); 480 (void) new LauncherItem( this, app, bigIcns );
480 else 481 else
481 hidden.append(app); 482 hidden.append(app);
482 if ( resort ) 483 if ( resort )
483 sort(); 484 sort();
484} 485}
485 486
486void LauncherIconView::updateCategoriesAndMimeTypes() 487void LauncherIconView::updateCategoriesAndMimeTypes()
487{ 488{
488 mimes.clear(); 489 mimes.clear();
489 cats.clear(); 490 cats.clear();
490 LauncherItem* item = (LauncherItem*)firstItem(); 491 LauncherItem* item = (LauncherItem*)firstItem();
491 while (item) { 492 while (item) {
492 addCatsAndMimes(item->appLnk()); 493 addCatsAndMimes(item->appLnk());
493 item = (LauncherItem*)item->nextItem(); 494 item = (LauncherItem*)item->nextItem();
494 } 495 }
495 QListIterator<AppLnk> it(hidden); 496 QListIterator<AppLnk> it(hidden);
496 AppLnk* l; 497 AppLnk* l;
497 while ((l=it.current())) { 498 while ((l=it.current())) {
498 addCatsAndMimes(l); 499 addCatsAndMimes(l);
499 ++it; 500 ++it;
500 } 501 }
501} 502}
502 503
503void LauncherIconView::hideOrShowItems(bool resort) 504void LauncherIconView::hideOrShowItems(bool resort)
504{ 505{
505 hidden.setAutoDelete(FALSE); 506 hidden.setAutoDelete(FALSE);
506 QList<AppLnk> links=hidden; 507 QList<AppLnk> links=hidden;
507 hidden.clear(); 508 hidden.clear();
508 hidden.setAutoDelete(TRUE); 509 hidden.setAutoDelete(TRUE);
509 LauncherItem* item = (LauncherItem*)firstItem(); 510 LauncherItem* item = (LauncherItem*)firstItem();
510 while (item) { 511 while (item) {
511 links.append(item->takeAppLnk()); 512 links.append(item->takeAppLnk());
512 item = (LauncherItem*)item->nextItem(); 513 item = (LauncherItem*)item->nextItem();
513 } 514 }
514 viewport()->setUpdatesEnabled( FALSE ); 515 viewport()->setUpdatesEnabled( FALSE );
515 clear(); 516 clear();
516 QListIterator<AppLnk> it(links); 517 QListIterator<AppLnk> it(links);
517 AppLnk* l; 518 AppLnk* l;
518 while ((l=it.current())) { 519 while ((l=it.current())) {
519 addItem(l,FALSE); 520 addItem(l,FALSE);
520 ++it; 521 ++it;
521 } 522 }
522 viewport()->setUpdatesEnabled( TRUE ); 523 viewport()->setUpdatesEnabled( TRUE );
523 if ( resort && !autoArrange() ) 524 if ( resort && !autoArrange() )
524 sort(); 525 sort();
525} 526}
526 527
527bool LauncherIconView::removeLink(const QString& linkfile) 528bool LauncherIconView::removeLink(const QString& linkfile)
528{ 529{
529 LauncherItem* item = (LauncherItem*)firstItem(); 530 LauncherItem* item = (LauncherItem*)firstItem();
530 AppLnk* l; 531 AppLnk* l;
531 bool did = FALSE; 532 bool did = FALSE;
532 DocLnk dl(linkfile); 533 DocLnk dl(linkfile);
533 while (item) { 534 while (item) {
534 l = item->appLnk(); 535 l = item->appLnk();
535 if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile )) 536 if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile ))
536 || ( l->fileKnown() && ( l->file() == linkfile )) 537 || ( l->fileKnown() && ( l->file() == linkfile ))
537 || ( dl.fileKnown() && l->fileKnown() && ( dl.file() == l->file() )) ) { 538 || ( dl.fileKnown() && l->fileKnown() && ( dl.file() == l->file() )) ) {
538 delete item; 539 delete item;
539 did = TRUE; 540 did = TRUE;
540 } 541 }
541 item = (LauncherItem*)item->nextItem(); 542 item = (LauncherItem*)item->nextItem();
542 } 543 }
543 QListIterator<AppLnk> it(hidden); 544 QListIterator<AppLnk> it(hidden);
544 while ((l=it.current())) { 545 while ((l=it.current())) {
545 ++it; 546 ++it;
546 if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile )) 547 if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile ))
547 || ( l->file() == linkfile ) 548 || ( l->file() == linkfile )
548 || ( dl.fileKnown() && ( dl.file() == l->file() )) ) { 549 || ( dl.fileKnown() && ( dl.file() == l->file() )) ) {
549 hidden.removeRef(l); 550 hidden.removeRef(l);
550 did = TRUE; 551 did = TRUE;
551 } 552 }
552 } 553 }
553 return did; 554 return did;
554} 555}
555 556
556static QString docLinkInfo(const Categories& cats, DocLnk* doc) 557static QString docLinkInfo(const Categories& cats, DocLnk* doc)
557{ 558{
558 QString contents; 559 QString contents;
559 560
560 QFileInfo fi( doc->file() ); 561 QFileInfo fi( doc->file() );
561 if ( !fi.exists() ) 562 if ( !fi.exists() )
562 return contents; 563 return contents;
563 564
564 if ( doc->linkFileKnown() ) { 565 if ( doc->linkFileKnown() ) {
565 QString lfn = doc->linkFile(); 566 QString lfn = doc->linkFile();
566 QFile f( lfn ); 567 QFile f( lfn );
567 if ( f.open( IO_ReadOnly ) ) { 568 if ( f.open( IO_ReadOnly ) ) {
568 QTextStream ts( &f ); 569 QTextStream ts( &f );
569 ts.setEncoding( QTextStream::UnicodeUTF8 ); 570 ts.setEncoding( QTextStream::UnicodeUTF8 );
570 contents += ts.read(); 571 contents += ts.read();
571 f.close(); 572 f.close();
572 goto calcsize; 573 goto calcsize;
573 } 574 }
574 } 575 }
575 576
576 contents += "[Desktop Entry]\n"; 577 contents += "[Desktop Entry]\n";
577 contents += "Categories = " // No tr 578 contents += "Categories = " // No tr
578 + cats.labels("Document View", doc->categories()).join(";") + "\n"; // No tr 579 + cats.labels("Document View", doc->categories()).join(";") + "\n"; // No tr
579 contents += "File = "+doc->file()+"\n"; // No tr 580 contents += "File = "+doc->file()+"\n"; // No tr
580 contents += "Name = "+doc->name()+"\n"; // No tr 581 contents += "Name = "+doc->name()+"\n"; // No tr
581 contents += "Type = "+doc->type()+"\n"; // No tr 582 contents += "Type = "+doc->type()+"\n"; // No tr
582 583
583calcsize: 584calcsize:
584 contents += QString("Size = %1\n").arg( fi.size() ); // No tr 585 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
585 return contents; 586 return contents;
586} 587}
587 588
588QString LauncherIconView::getAllDocLinkInfo() const 589QString LauncherIconView::getAllDocLinkInfo() const
589{ 590{
590 QString contents; 591 QString contents;
591 LauncherItem* item = (LauncherItem*)firstItem(); 592 LauncherItem* item = (LauncherItem*)firstItem();
592 Categories cats; 593 Categories cats;
593 while (item) { 594 while (item) {
594 DocLnk* doc = (DocLnk*)item->appLnk(); 595 DocLnk* doc = (DocLnk*)item->appLnk();
595 contents += docLinkInfo(cats,doc); 596 contents += docLinkInfo(cats,doc);
596 item = (LauncherItem*)item->nextItem(); 597 item = (LauncherItem*)item->nextItem();
597 } 598 }
598 QListIterator<AppLnk> it(hidden); 599 QListIterator<AppLnk> it(hidden);
599 DocLnk* doc; 600 DocLnk* doc;
600 while ((doc=(DocLnk*)it.current())) { 601 while ((doc=(DocLnk*)it.current())) {
601 contents += docLinkInfo(cats,doc); 602 contents += docLinkInfo(cats,doc);
602 ++it; 603 ++it;
603 } 604 }
604 return contents; 605 return contents;
605} 606}
606 607
607//=========================================================================== 608//===========================================================================
608 609
609LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) 610LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl )
610 : QVBox( parent, name, fl ) 611 : QVBox( parent, name, fl )
611{ 612{
612 icons = new LauncherIconView( this ); 613 icons = new LauncherIconView( this );
613 setFocusProxy(icons); 614 setFocusProxy(icons);
614 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); 615 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold );
615 616
616 icons->setItemsMovable( FALSE ); 617 icons->setItemsMovable( FALSE );
617 icons->setAutoArrange( TRUE ); 618 icons->setAutoArrange( TRUE );
618 icons->setSorting( TRUE ); 619 icons->setSorting( TRUE );
619 icons->setFrameStyle( QFrame::NoFrame ); 620 icons->setFrameStyle( QFrame::NoFrame );
620 icons->setMargin( 0 ); 621 icons->setMargin( 0 );
621 icons->setSelectionMode( QIconView::NoSelection ); 622 icons->setSelectionMode( QIconView::NoSelection );
622 icons->setBackgroundMode( PaletteBase ); 623 icons->setBackgroundMode( PaletteBase );
623 icons->setResizeMode( QIconView::Fixed ); 624 icons->setResizeMode( QIconView::Fixed );
624 vmode = (ViewMode)-1; 625 vmode = (ViewMode)-1;
625 setViewMode( Icon ); 626 setViewMode( Icon );
626 627
627 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), 628 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)),
628 SLOT(itemClicked(int, QIconViewItem *)) ); 629 SLOT(itemClicked(int, QIconViewItem *)) );
629 connect( icons, SIGNAL(selectionChanged()), 630 connect( icons, SIGNAL(selectionChanged()),
630 SLOT(selectionChanged()) ); 631 SLOT(selectionChanged()) );
631 connect( icons, SIGNAL(returnPressed(QIconViewItem *)), 632 connect( icons, SIGNAL(returnPressed(QIconViewItem *)),
632 SLOT(returnPressed(QIconViewItem *)) ); 633 SLOT(returnPressed(QIconViewItem *)) );
633 connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), 634 connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)),
634 SLOT(itemPressed(int, QIconViewItem *)) ); 635 SLOT(itemPressed(int, QIconViewItem *)) );
635 636
636 tools = 0; 637 tools = 0;
637 setBackgroundType( Ruled, QString::null ); 638 setBackgroundType( Ruled, QString::null );
638} 639}
639 640
640LauncherView::~LauncherView() 641LauncherView::~LauncherView()
641{ 642{
642} 643}
643 644
644void LauncherView::setToolsEnabled(bool y) 645void LauncherView::setToolsEnabled(bool y)
645{ 646{
646 if ( !y != !tools ) { 647 if ( !y != !tools ) {
647 if ( y ) { 648 if ( y ) {
648 tools = new QHBox(this); 649 tools = new QHBox(this);
649 650
650 // Type filter 651 // Type filter
651 typemb = new QComboBox(tools); 652 typemb = new QComboBox(tools);
652 653
653 // Category filter 654 // Category filter
654 catmb = new CategorySelect(tools); 655 catmb = new CategorySelect(tools);
655 656
656 updateTools(); 657 updateTools();
657 tools->show(); 658 tools->show();
658 } else { 659 } else {
659 delete tools; 660 delete tools;
660 tools = 0; 661 tools = 0;
661 } 662 }
662 } 663 }
663} 664}
664 665
665void LauncherView::updateTools() 666void LauncherView::updateTools()
666{ 667{
667 disconnect( typemb, SIGNAL(activated(int)), 668 disconnect( typemb, SIGNAL(activated(int)),
668 this, SLOT(showType(int)) ); 669 this, SLOT(showType(int)) );
669 disconnect( catmb, SIGNAL(signalSelected(int)), 670 disconnect( catmb, SIGNAL(signalSelected(int)),
670 this, SLOT(showCategory(int)) ); 671 this, SLOT(showCategory(int)) );
671 672
672 icons->updateCategoriesAndMimeTypes(); 673 icons->updateCategoriesAndMimeTypes();
673 674
674 QString prev; 675 QString prev;
675 676
676 // Type filter 677 // Type filter
677 QStringList types; 678 QStringList types;
678 typelist = icons->mimeTypes(); 679 typelist = icons->mimeTypes();
679 for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { 680 for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) {
680 QString t = *it; 681 QString t = *it;
681 if ( t.left(12) == "application/" ) { 682 if ( t.left(12) == "application/" ) {
682 MimeType mt(t); 683 MimeType mt(t);
683 const AppLnk* app = mt.application(); 684 const AppLnk* app = mt.application();
684 if ( app ) 685 if ( app )
685 t = app->name(); 686 t = app->name();
686 else 687 else
687 t = t.mid(12); 688 t = t.mid(12);
688 } else { 689 } else {
689 t[0] = t[0].upper(); 690 t[0] = t[0].upper();
690 } 691 }
691 types += tr("%1 files").arg(t); 692 types += tr("%1 files").arg(t);
692 } 693 }
693 types << tr("All types of file"); 694 types << tr("All types of file");
694 prev = typemb->currentText(); 695 prev = typemb->currentText();
695 typemb->clear(); 696 typemb->clear();
696 typemb->insertStringList(types); 697 typemb->insertStringList(types);
697 for (int i=0; i<typemb->count(); i++) { 698 for (int i=0; i<typemb->count(); i++) {
698 if ( typemb->text(i) == prev ) { 699 if ( typemb->text(i) == prev ) {
699 typemb->setCurrentItem(i); 700 typemb->setCurrentItem(i);
700 break; 701 break;
701 } 702 }
702 } 703 }
703 if ( prev.isNull() ) 704 if ( prev.isNull() )
704 typemb->setCurrentItem(typemb->count()-1); 705 typemb->setCurrentItem(typemb->count()-1);
705 706
706 Categories cats( 0 ); 707 Categories cats( 0 );
707 cats.load( categoryFileName() ); 708 cats.load( categoryFileName() );
708 QArray<int> vl( 0 ); 709 QArray<int> vl( 0 );
709 catmb->setCategories( vl, "Document View", // No tr 710 catmb->setCategories( vl, "Document View", // No tr
710 tr("Document View") ); 711 tr("Document View") );
711 catmb->setRemoveCategoryEdit( TRUE ); 712 catmb->setRemoveCategoryEdit( TRUE );
712 catmb->setAllCategories( TRUE ); 713 catmb->setAllCategories( TRUE );
713 714
714 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); 715 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int)));
715 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); 716 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));
716} 717}
717 718
718void LauncherView::sortBy(int s) 719void LauncherView::sortBy(int s)
719{ 720{
720 icons->setSortMethod((LauncherIconView::SortMethod)s); 721 icons->setSortMethod((LauncherIconView::SortMethod)s);
721} 722}
722 723
723void LauncherView::showType(int t) 724void LauncherView::showType(int t)
724{ 725{
725 if ( t >= (int)typelist.count() ) { 726 if ( t >= (int)typelist.count() ) {
726 icons->setTypeFilter("",TRUE); 727 icons->setTypeFilter("",TRUE);
727 } else { 728 } else {
728 QString ty = typelist[t]; 729 QString ty = typelist[t];
729 if ( !ty.contains('/') ) 730 if ( !ty.contains('/') )
730 ty += "/*"; 731 ty += "/*";
731 icons->setTypeFilter(ty,TRUE); 732 icons->setTypeFilter(ty,TRUE);
732 } 733 }
733} 734}
734 735
735void LauncherView::showCategory( int c ) 736void LauncherView::showCategory( int c )
736{ 737{
737 icons->setCategoryFilter( c, TRUE ); 738 icons->setCategoryFilter( c, TRUE );
738} 739}
739 740
740void LauncherView::setViewMode( ViewMode m ) 741void LauncherView::setViewMode( ViewMode m )
741{ 742{
742 if ( vmode != m ) { 743 if ( vmode != m ) {
743 bool bigIcons = m == Icon; 744 bool bigIcons = m == Icon;
744 icons->viewport()->setUpdatesEnabled( FALSE ); 745 icons->viewport()->setUpdatesEnabled( FALSE );
745 icons->setBigIcons( bigIcons ); 746 icons->setBigIcons( bigIcons );
746 switch ( m ) { 747 switch ( m ) {
747 case List: 748 case List:
748 icons->setItemTextPos( QIconView::Right ); 749 icons->setItemTextPos( QIconView::Right );
749 break; 750 break;
750 case Icon: 751 case Icon:
751 icons->setItemTextPos( QIconView::Bottom ); 752 icons->setItemTextPos( QIconView::Bottom );
752 break; 753 break;
753 } 754 }
754 icons->hideOrShowItems( FALSE ); 755 icons->hideOrShowItems( FALSE );
755 icons->viewport()->setUpdatesEnabled( TRUE ); 756 icons->viewport()->setUpdatesEnabled( TRUE );
756 vmode = m; 757 vmode = m;
757 } 758 }
758} 759}
759 760
760void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) 761void LauncherView::setBackgroundType( BackgroundType t, const QString &val )
761{ 762{
762 if ( !bgCache ) 763 if ( !bgCache )
763 bgCache = new QMap<QString,BgPixmap*>; 764 bgCache = new QMap<QString,BgPixmap*>;
764 if ( bgCache->contains( bgName ) ) 765 if ( bgCache->contains( bgName ) )
765 (*bgCache)[bgName]->ref--; 766 (*bgCache)[bgName]->ref--;
766 767
767 switch ( t ) { 768 switch ( t ) {
768 case Ruled: { 769 case Ruled: {
769 bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr 770 bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr
770 QPixmap bg; 771 QPixmap bg;
771 if ( bgCache->contains( bgName ) ) { 772 if ( bgCache->contains( bgName ) ) {
772 (*bgCache)[bgName]->ref++; 773 (*bgCache)[bgName]->ref++;
773 bg = (*bgCache)[bgName]->pm; 774 bg = (*bgCache)[bgName]->pm;
774 } else { 775 } else {
775 bg.resize( width(), 9 ); 776 bg.resize( width(), 9 );
776 QPainter painter( &bg ); 777 QPainter painter( &bg );
777 for ( int i = 0; i < 3; i++ ) { 778 for ( int i = 0; i < 3; i++ ) {
778 painter.setPen( white ); 779 painter.setPen( white );
779 painter.drawLine( 0, i*3, width()-1, i*3 ); 780 painter.drawLine( 0, i*3, width()-1, i*3 );
780 painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); 781 painter.drawLine( 0, i*3+1, width()-1, i*3+1 );
781 painter.setPen( colorGroup().background().light(105) ); 782 painter.setPen( colorGroup().background().light(105) );
782 painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); 783 painter.drawLine( 0, i*3+2, width()-1, i*3+2 );
783 } 784 }
784 painter.end(); 785 painter.end();
785 bgCache->insert( bgName, new BgPixmap(bg) ); 786 bgCache->insert( bgName, new BgPixmap(bg) );
786 } 787 }
787 icons->setBackgroundPixmap( bg ); 788 icons->setBackgroundPixmap( bg );
788 break; 789 break;
789 } 790 }
790 791
791 case SolidColor: 792 case SolidColor:
792 icons->setBackgroundPixmap( QPixmap() ); 793 icons->setBackgroundPixmap( QPixmap() );
793 if ( val.isEmpty() ) { 794 if ( val.isEmpty() ) {
794 icons->setBackgroundColor( colorGroup().base() ); 795 icons->setBackgroundColor( colorGroup().base() );
795 } else { 796 } else {
796 icons->setBackgroundColor( val ); 797 icons->setBackgroundColor( val );
797 } 798 }
798 bgName = ""; 799 bgName = "";
799 break; 800 break;
800 801
801 case Image: 802 case Image:
802 bgName = val; 803 bgName = val;
803 if ( bgCache->contains( bgName ) ) { 804 if ( bgCache->contains( bgName ) ) {
804 (*bgCache)[bgName]->ref++; 805 (*bgCache)[bgName]->ref++;
805 icons->setBackgroundPixmap( (*bgCache)[bgName]->pm ); 806 icons->setBackgroundPixmap( (*bgCache)[bgName]->pm );
806 } else { 807 } else {
807 qDebug( "Loading image: %s", val.latin1() ); 808 qDebug( "Loading image: %s", val.latin1() );
808 QPixmap bg( Resource::loadPixmap( val ) ); 809 QPixmap bg( Resource::loadPixmap( val ) );
809 if ( bg.isNull() ) { 810 if ( bg.isNull() ) {
810 QImageIO imgio; 811 QImageIO imgio;
811 imgio.setFileName( bgName ); 812 imgio.setFileName( bgName );
812 QSize ds = qApp->desktop()->size(); 813 QSize ds = qApp->desktop()->size();
813 QString param( "Scale( %1, %2, ScaleMin )" ); // No tr 814 QString param( "Scale( %1, %2, ScaleMin )" ); // No tr
814 imgio.setParameters( param.arg(ds.width()).arg(ds.height()).latin1() ); 815 imgio.setParameters( param.arg(ds.width()).arg(ds.height()).latin1() );
815 imgio.read(); 816 imgio.read();
816 bg = imgio.image(); 817 bg = imgio.image();
817 } 818 }
818 bgCache->insert( bgName, new BgPixmap(bg) ); 819 bgCache->insert( bgName, new BgPixmap(bg) );
819 icons->setBackgroundPixmap( bg ); 820 icons->setBackgroundPixmap( bg );
820 } 821 }
821 break; 822 break;
822 } 823 }
823 824
824 // remove unreferenced backgrounds. 825 // remove unreferenced backgrounds.
825 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); 826 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
826 while ( it != bgCache->end() ) { 827 while ( it != bgCache->end() ) {
827 QMap<QString,BgPixmap*>::Iterator curr = it; 828 QMap<QString,BgPixmap*>::Iterator curr = it;
828 ++it; 829 ++it;
829 if ( (*curr)->ref == 0 ) { 830 if ( (*curr)->ref == 0 ) {
830 delete (*curr); 831 delete (*curr);
831 bgCache->remove( curr ); 832 bgCache->remove( curr );
832 } 833 }
833 } 834 }
834 835
835 bgType = t; 836 bgType = t;
836 icons->viewport()->update(); 837 icons->viewport()->update();
837} 838}
838 839
839void LauncherView::setTextColor( const QColor &tc ) 840void LauncherView::setTextColor( const QColor &tc )
840{ 841{
841 textCol = tc; 842 textCol = tc;
842 QColorGroup cg = icons->colorGroup(); 843 QColorGroup cg = icons->colorGroup();
843 cg.setColor( QColorGroup::Text, tc ); 844 cg.setColor( QColorGroup::Text, tc );
844 icons->setPalette( QPalette(cg,cg,cg) ); 845 icons->setPalette( QPalette(cg,cg,cg) );
845 icons->viewport()->update(); 846 icons->viewport()->update();
846} 847}
847 848
848void LauncherView::setViewFont( const QFont &f ) 849void LauncherView::setViewFont( const QFont &f )
849{ 850{
850 icons->setFont( f ); 851 icons->setFont( f );
851} 852}
852 853
853void LauncherView::unsetViewFont( ) 854void LauncherView::unsetViewFont( )
854{ 855{
855 icons->unsetFont( ); 856 icons->unsetFont( );
856} 857}
857 858
858void LauncherView::resizeEvent(QResizeEvent *e) 859void LauncherView::resizeEvent(QResizeEvent *e)
859{ 860{
860 QVBox::resizeEvent( e ); 861 QVBox::resizeEvent( e );
861 if ( e->size().width() != e->oldSize().width() ) 862 if ( e->size().width() != e->oldSize().width() )
862 sort(); 863 sort();
863} 864}
864 865
865void LauncherView::populate( AppLnkSet *folder, const QString& typefilter ) 866void LauncherView::populate( AppLnkSet *folder, const QString& typefilter )
866{ 867{
867 icons->clear(); 868 icons->clear();
868 internalPopulate( folder, typefilter ); 869 internalPopulate( folder, typefilter );
869} 870}
870 871
871QString LauncherView::getAllDocLinkInfo() const 872QString LauncherView::getAllDocLinkInfo() const
872{ 873{
873 return icons->getAllDocLinkInfo(); 874 return icons->getAllDocLinkInfo();
874} 875}
875 876
876void LauncherView::selectionChanged() 877void LauncherView::selectionChanged()
877{ 878{
878 QIconViewItem* item = icons->currentItem(); 879 QIconViewItem* item = icons->currentItem();
879 if ( item && item->isSelected() ) { 880 if ( item && item->isSelected() ) {
880 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 881 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
881 if ( icons->inKeyEvent() ) // not for mouse press 882 if ( icons->inKeyEvent() ) // not for mouse press
882 emit clicked( appLnk ); 883 emit clicked( appLnk );
883 item->setSelected(FALSE); 884 item->setSelected(FALSE);
884 } 885 }
885} 886}
886 887
887void LauncherView::returnPressed( QIconViewItem *item ) 888void LauncherView::returnPressed( QIconViewItem *item )
888{ 889{
889 if ( item ) { 890 if ( item ) {
890 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 891 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
891 emit clicked( appLnk ); 892 emit clicked( appLnk );
892 } 893 }
893} 894}
894 895
895void LauncherView::itemClicked( int btn, QIconViewItem *item ) 896void LauncherView::itemClicked( int btn, QIconViewItem *item )
896{ 897{
897 if ( item ) { 898 if ( item ) {
898 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 899 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
899 if ( btn == LeftButton ) { 900 if ( btn == LeftButton ) {
900 // Make sure it's the item we execute that gets highlighted 901 // Make sure it's the item we execute that gets highlighted
901 icons->setCurrentItem( item ); 902 icons->setCurrentItem( item );
902 emit clicked( appLnk ); 903 emit clicked( appLnk );
903 } 904 }
904 item->setSelected(FALSE); 905 item->setSelected(FALSE);
905 } 906 }
906} 907}
907 908
908void LauncherView::itemPressed( int btn, QIconViewItem *item ) 909void LauncherView::itemPressed( int btn, QIconViewItem *item )
909{ 910{
910 if ( item ) { 911 if ( item ) {
911 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 912 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
912 if ( btn == RightButton ) 913 if ( btn == RightButton )
913 emit rightPressed( appLnk ); 914 emit rightPressed( appLnk );
914/* 915/*
915 else if ( btn == LeftButton ) 916 else if ( btn == LeftButton )
916 emit clicked( appLnk ); 917 emit clicked( appLnk );
917*/ 918*/
918 item->setSelected(FALSE); 919 item->setSelected(FALSE);
919 } 920 }
920} 921}
921 922
922void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) 923void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter )
923{ 924{
924 QListIterator<AppLnk> it( folder->children() ); 925 QListIterator<AppLnk> it( folder->children() );
925 icons->setTypeFilter(typefilter,FALSE); 926 icons->setTypeFilter(typefilter,FALSE);
926 927
927 while ( it.current() ) { 928 while ( it.current() ) {
928 // show only the icons for existing files 929 // show only the icons for existing files
929 if (QFile(it.current()->file()).exists() || ( it.current()->file().left(4) == "http" )) { 930 if (QFile(it.current()->file()).exists() || ( it.current()->file().left(4) == "http" )) {
930 icons->addItem(*it,FALSE); 931 icons->addItem(*it,FALSE);
931 } 932 }
932 else { 933 else {
933 //maybe insert some .desktop file deletion code later 934 //maybe insert some .desktop file deletion code later
934 //maybe dir specific 935 //maybe dir specific
935 } 936 }
936 ++it; 937 ++it;
937 } 938 }
938 939
939 icons->sort(); 940 icons->sort();
940} 941}
941 942
942bool LauncherView::removeLink(const QString& linkfile) 943bool LauncherView::removeLink(const QString& linkfile)
943{ 944{
944 return icons->removeLink(linkfile); 945 return icons->removeLink(linkfile);
945} 946}
946 947
947void LauncherView::sort() 948void LauncherView::sort()
948{ 949{
949 icons->sort(); 950 icons->sort();
950} 951}
951 952
952void LauncherView::addItem(AppLnk* app, bool resort) 953void LauncherView::addItem(AppLnk* app, bool resort)
953{ 954{
954 icons->addItem(app,resort); 955 icons->addItem(app,resort);
955} 956}
956 957
957void LauncherView::setFileSystems(const QList<FileSystem> &) 958void LauncherView::setFileSystems(const QList<FileSystem> &)
958{ 959{
959 // ### does nothing now... 960 // ### does nothing now...
960} 961}
961 962
962void LauncherView::paletteChange( const QPalette &p ) 963void LauncherView::paletteChange( const QPalette &p )
963{ 964{
964 icons->unsetPalette(); 965 icons->unsetPalette();
965 QVBox::paletteChange( p ); 966 QVBox::paletteChange( p );
966 if ( bgType == Ruled ) 967 if ( bgType == Ruled )
967 setBackgroundType( Ruled, QString::null ); 968 setBackgroundType( Ruled, QString::null );
968 QColorGroup cg = icons->colorGroup(); 969 QColorGroup cg = icons->colorGroup();
969 cg.setColor( QColorGroup::Text, textCol ); 970 cg.setColor( QColorGroup::Text, textCol );
970 icons->setPalette( QPalette(cg,cg,cg) ); 971 icons->setPalette( QPalette(cg,cg,cg) );
971} 972}
972 973
973 974
974void LauncherView::setBusyIndicatorType ( const QString &type ) 975void LauncherView::setBusyIndicatorType ( const QString &type )
975{ 976{
976 if ( type. lower ( ) == "blink" ) 977 if ( type. lower ( ) == "blink" )
977 icons-> setBusyIndicatorType ( BIT_Blinking ); 978 icons-> setBusyIndicatorType ( BIT_Blinking );
978 else 979 else
979 icons-> setBusyIndicatorType ( BIT_Normal ); 980 icons-> setBusyIndicatorType ( BIT_Normal );
980} 981}
981 982
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index aaa4425..cbda247 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,1389 +1,1389 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#define _XOPEN_SOURCE 20#define _XOPEN_SOURCE
21#include <pwd.h> 21#include <pwd.h>
22#include <sys/types.h> 22#include <sys/types.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <time.h> 25#include <time.h>
26#include <shadow.h> 26#include <shadow.h>
27 27
28/* we need the _OS_LINUX stuff first ! */ 28/* we need the _OS_LINUX stuff first ! */
29#include <qglobal.h> 29#include <qglobal.h>
30 30
31#ifndef _OS_LINUX_ 31#ifndef _OS_LINUX_
32 32
33extern "C" { 33extern "C" {
34#include <uuid/uuid.h> 34#include <uuid/uuid.h>
35#define UUID_H_INCLUDED 35#define UUID_H_INCLUDED
36} 36}
37 37
38#endif // not defined linux 38#endif // not defined linux
39 39
40#if defined(_OS_LINUX_) 40#if defined(_OS_LINUX_)
41#include <shadow.h> 41#include <shadow.h>
42#endif 42#endif
43 43
44#include <qdir.h> 44#include <qdir.h>
45#include <qfile.h> 45#include <qfile.h>
46#include <qtextstream.h> 46#include <qtextstream.h>
47#include <qdatastream.h> 47#include <qdatastream.h>
48#include <qmessagebox.h> 48#include <qmessagebox.h>
49#include <qstringlist.h> 49#include <qstringlist.h>
50#include <qfileinfo.h> 50#include <qfileinfo.h>
51#include <qregexp.h> 51#include <qregexp.h>
52//#include <qpe/qcopchannel_qws.h> 52//#include <qpe/qcopchannel_qws.h>
53#include <qpe/process.h> 53#include <qpe/process.h>
54#include <qpe/global.h> 54#include <qpe/global.h>
55#include <qpe/config.h> 55#include <qpe/config.h>
56#include <qpe/contact.h> 56#include <qpe/contact.h>
57#include <qpe/quuid.h> 57#include <qpe/quuid.h>
58#include <qpe/version.h> 58#include <qpe/version.h>
59#include <qpe/qcopenvelope_qws.h> 59#include <qpe/qcopenvelope_qws.h>
60 60
61#include "transferserver.h" 61#include "transferserver.h"
62#include "qprocess.h" 62#include "qprocess.h"
63 63
64const int block_size = 51200; 64const int block_size = 51200;
65 65
66TransferServer::TransferServer( Q_UINT16 port, QObject *parent , 66TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
67 const char* name ) 67 const char* name )
68 : QServerSocket( port, 1, parent, name ) 68 : QServerSocket( port, 1, parent, name )
69{ 69{
70 if ( !ok() ) 70 if ( !ok() )
71 qWarning( "Failed to bind to port %d", port ); 71 qWarning( "Failed to bind to port %d", port );
72} 72}
73 73
74TransferServer::~TransferServer() 74TransferServer::~TransferServer()
75{ 75{
76 76
77} 77}
78 78
79void TransferServer::newConnection( int socket ) 79void TransferServer::newConnection( int socket )
80{ 80{
81 (void) new ServerPI( socket, this ); 81 (void) new ServerPI( socket, this );
82} 82}
83 83
84/* 84/*
85 * small class in anonymous namespace 85 * small class in anonymous namespace
86 * to generate a QUUid for us 86 * to generate a QUUid for us
87 */ 87 */
88namespace { 88namespace {
89 struct UidGen { 89 struct UidGen {
90 QString uuid(); 90 QString uuid();
91 }; 91 };
92#if !defined(_OS_LINUX_) 92#if !defined(_OS_LINUX_)
93 QString UidGen::uuid() { 93 QString UidGen::uuid() {
94 uuid_t uuid; 94 uuid_t uuid;
95 uuid_generate( uuid ); 95 uuid_generate( uuid );
96 return QUUid( uuid ).toString(); 96 return QUUid( uuid ).toString();
97 } 97 }
98#else 98#else
99 /* 99 /*
100 * linux got a /proc/sys/kernel/random/uuid file 100 * linux got a /proc/sys/kernel/random/uuid file
101 * it'll generate the uuids for us 101 * it'll generate the uuids for us
102 */ 102 */
103 QString UidGen::uuid() { 103 QString UidGen::uuid() {
104 QFile file( "/proc/sys/kernel/random/uuid" ); 104 QFile file( "/proc/sys/kernel/random/uuid" );
105 if (!file.open(IO_ReadOnly ) ) 105 if (!file.open(IO_ReadOnly ) )
106 return QString::null; 106 return QString::null;
107 107
108 QTextStream stream(&file); 108 QTextStream stream(&file);
109 109
110 return "{" + stream.read().stripWhiteSpace() + "}"; 110 return "{" + stream.read().stripWhiteSpace() + "}";
111 } 111 }
112#endif 112#endif
113} 113}
114 114
115QString SyncAuthentication::serverId() 115QString SyncAuthentication::serverId()
116{ 116{
117 Config cfg("Security"); 117 Config cfg("Security");
118 cfg.setGroup("Sync"); 118 cfg.setGroup("Sync");
119 QString r=cfg.readEntry("serverid"); 119 QString r=cfg.readEntry("serverid");
120 if ( r.isEmpty() ) { 120 if ( r.isEmpty() ) {
121 UidGen gen; 121 UidGen gen;
122 r = gen.uuid(); 122 r = gen.uuid();
123 cfg.writeEntry("serverid", r ); 123 cfg.writeEntry("serverid", r );
124 } 124 }
125 return r; 125 return r;
126} 126}
127 127
128QString SyncAuthentication::ownerName() 128QString SyncAuthentication::ownerName()
129{ 129{
130 QString vfilename = Global::applicationFileName("addressbook", 130 QString vfilename = Global::applicationFileName("addressbook",
131 "businesscard.vcf"); 131 "businesscard.vcf");
132 if (QFile::exists(vfilename)) { 132 if (QFile::exists(vfilename)) {
133 Contact c; 133 Contact c;
134 c = Contact::readVCard( vfilename )[0]; 134 c = Contact::readVCard( vfilename )[0];
135 return c.fullName(); 135 return c.fullName();
136 } 136 }
137 137
138 return ""; 138 return "";
139} 139}
140 140
141QString SyncAuthentication::loginName() 141QString SyncAuthentication::loginName()
142{ 142{
143 struct passwd *pw; 143 struct passwd *pw;
144 pw = getpwuid( geteuid() ); 144 pw = getpwuid( geteuid() );
145 return QString::fromLocal8Bit( pw->pw_name ); 145 return QString::fromLocal8Bit( pw->pw_name );
146} 146}
147 147
148int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 148int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
149{ 149{
150 Config cfg("Security"); 150 Config cfg("Security");
151 cfg.setGroup("Sync"); 151 cfg.setGroup("Sync");
152// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 152// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
153 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); 153 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100);
154 154
155// QHostAddress allowed; 155// QHostAddress allowed;
156// allowed.setAddress(allowedstr); 156// allowed.setAddress(allowedstr);
157// uint auth_peer = allowed.ip4Addr(); 157// uint auth_peer = allowed.ip4Addr();
158 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 158 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
159 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 159 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
160 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); 160 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits));
161 return (peeraddress.ip4Addr() & mask) == auth_peer; 161 return (peeraddress.ip4Addr() & mask) == auth_peer;
162} 162}
163 163
164bool SyncAuthentication::checkUser( const QString& user ) 164bool SyncAuthentication::checkUser( const QString& user )
165{ 165{
166 if ( user.isEmpty() ) return FALSE; 166 if ( user.isEmpty() ) return FALSE;
167 QString euser = loginName(); 167 QString euser = loginName();
168 return user == euser; 168 return user == euser;
169} 169}
170 170
171bool SyncAuthentication::checkPassword( const QString& password ) 171bool SyncAuthentication::checkPassword( const QString& password )
172{ 172{
173#ifdef ALLOW_UNIX_USER_FTP 173#ifdef ALLOW_UNIX_USER_FTP
174 // First, check system password... 174 // First, check system password...
175 175
176 struct passwd *pw = 0; 176 struct passwd *pw = 0;
177 struct spwd *spw = 0; 177 struct spwd *spw = 0;
178 178
179 pw = getpwuid( geteuid() ); 179 pw = getpwuid( geteuid() );
180 spw = getspnam( pw->pw_name ); 180 spw = getspnam( pw->pw_name );
181 181
182 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 182 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
183 if ( cpwd == "x" && spw ) 183 if ( cpwd == "x" && spw )
184 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 184 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
185 185
186 // Note: some systems use more than crypt for passwords. 186 // Note: some systems use more than crypt for passwords.
187 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 187 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
188 if ( cpwd == cpassword ) 188 if ( cpwd == cpassword )
189 return TRUE; 189 return TRUE;
190#endif 190#endif
191 191
192 static int lastdenial=0; 192 static int lastdenial=0;
193 static int denials=0; 193 static int denials=0;
194 int now = time(0); 194 int now = time(0);
195 195
196 // Detect old Qtopia Desktop (no password) 196 // Detect old Qtopia Desktop (no password)
197 if ( password.isEmpty() ) { 197 if ( password.isEmpty() ) {
198 if ( denials < 1 || now > lastdenial+600 ) { 198 if ( denials < 1 || now > lastdenial+600 ) {
199 QMessageBox::warning( 0,tr("Sync Connection"), 199 QMessageBox::warning( 0,tr("Sync Connection"),
200 tr("<p>An unauthorized system is requesting access to this device." 200 tr("<p>An unauthorized system is requesting access to this device."
201 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 201 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
202 "please upgrade."), 202 "please upgrade."),
203 tr("Deny") ); 203 tr("Deny") );
204 denials++; 204 denials++;
205 lastdenial=now; 205 lastdenial=now;
206 } 206 }
207 return FALSE; 207 return FALSE;
208 } 208 }
209 209
210 // Second, check sync password... 210 // Second, check sync password...
211 QString pass = password.left(6); 211 QString pass = password.left(6);
212 /* old QtopiaDesktops are sending 212 /* old QtopiaDesktops are sending
213 * rootme newer versions got a Qtopia 213 * rootme newer versions got a Qtopia
214 * prefixed. Qtopia prefix will suceed 214 * prefixed. Qtopia prefix will suceed
215 * until the sync software syncs up 215 * until the sync software syncs up
216 * FIXME 216 * FIXME
217 */ 217 */
218 if ( pass == "rootme" || pass == "Qtopia") { 218 if ( pass == "rootme" || pass == "Qtopia") {
219 219
220 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); 220 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
221 Config cfg("Security"); 221 Config cfg("Security");
222 cfg.setGroup("Sync"); 222 cfg.setGroup("Sync");
223 QString pwds = cfg.readEntry("Passwords"); 223 QString pwds = cfg.readEntry("Passwords");
224 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) 224 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) )
225 return TRUE; 225 return TRUE;
226 226
227 // Unrecognized system. Be careful... 227 // Unrecognized system. Be careful...
228 228
229 if ( (denials > 2 && now < lastdenial+600) 229 if ( (denials > 2 && now < lastdenial+600)
230 || QMessageBox::warning(0,tr("Sync Connection"), 230 || QMessageBox::warning(0,tr("Sync Connection"),
231 tr("<p>An unrecognized system is requesting access to this device." 231 tr("<p>An unrecognized system is requesting access to this device."
232 "<p>If you have just initiated a Sync for the first time, this is normal."), 232 "<p>If you have just initiated a Sync for the first time, this is normal."),
233 tr("Allow"),tr("Deny"), 0, 1, 1 ) ==1 ) 233 tr("Allow"),tr("Deny"), 0, 1, 1 ) ==1 )
234 { 234 {
235 denials++; 235 denials++;
236 lastdenial=now; 236 lastdenial=now;
237 return FALSE; 237 return FALSE;
238 } else { 238 } else {
239 denials=0; 239 denials=0;
240 cfg.writeEntry("Passwords",pwds+" "+cpassword); 240 cfg.writeEntry("Passwords",pwds+" "+cpassword);
241 return TRUE; 241 return TRUE;
242 } 242 }
243 } 243 }
244 244
245 return FALSE; 245 return FALSE;
246} 246}
247 247
248ServerPI::ServerPI( int socket, QObject *parent , const char* name ) 248ServerPI::ServerPI( int socket, QObject *parent , const char* name )
249 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) 249 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 )
250{ 250{
251 state = Connected; 251 state = Connected;
252 252
253 setSocket( socket ); 253 setSocket( socket );
254 254
255 peerport = peerPort(); 255 peerport = peerPort();
256 peeraddress = peerAddress(); 256 peeraddress = peerAddress();
257 257
258#ifndef INSECURE 258#ifndef INSECURE
259 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 259 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
260 state = Forbidden; 260 state = Forbidden;
261 startTimer( 0 ); 261 startTimer( 0 );
262 } else 262 } else
263#endif 263#endif
264 { 264 {
265 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 265 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
266 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 266 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
267 267
268 passiv = FALSE; 268 passiv = FALSE;
269 for( int i = 0; i < 4; i++ ) 269 for( int i = 0; i < 4; i++ )
270 wait[i] = FALSE; 270 wait[i] = FALSE;
271 271
272 send( "220 Qtopia " QPE_VERSION " FTP Server" ); 272 send( "220 Qtopia " QPE_VERSION " FTP Server" );
273 state = Wait_USER; 273 state = Wait_USER;
274 274
275 dtp = new ServerDTP( this ); 275 dtp = new ServerDTP( this );
276 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 276 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
277 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 277 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
278 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 278 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) );
279 279
280 280
281 directory = QDir::currentDirPath(); 281 directory = QDir::currentDirPath();
282 282
283 static int p = 1024; 283 static int p = 1024;
284 284
285 while ( !serversocket || !serversocket->ok() ) { 285 while ( !serversocket || !serversocket->ok() ) {
286 delete serversocket; 286 delete serversocket;
287 serversocket = new ServerSocket( ++p, this ); 287 serversocket = new ServerSocket( ++p, this );
288 } 288 }
289 connect( serversocket, SIGNAL( newIncomming( int ) ), 289 connect( serversocket, SIGNAL( newIncomming( int ) ),
290 SLOT( newConnection( int ) ) ); 290 SLOT( newConnection( int ) ) );
291 } 291 }
292} 292}
293 293
294ServerPI::~ServerPI() 294ServerPI::~ServerPI()
295{ 295{
296 296
297} 297}
298 298
299void ServerPI::connectionClosed() 299void ServerPI::connectionClosed()
300{ 300{
301 // qDebug( "Debug: Connection closed" ); 301 // qDebug( "Debug: Connection closed" );
302 delete this; 302 delete this;
303} 303}
304 304
305void ServerPI::send( const QString& msg ) 305void ServerPI::send( const QString& msg )
306{ 306{
307 QTextStream os( this ); 307 QTextStream os( this );
308 os << msg << endl; 308 os << msg << endl;
309 //qDebug( "Reply: %s", msg.latin1() ); 309 //qDebug( "Reply: %s", msg.latin1() );
310} 310}
311 311
312void ServerPI::read() 312void ServerPI::read()
313{ 313{
314 while ( canReadLine() ) 314 while ( canReadLine() )
315 process( readLine().stripWhiteSpace() ); 315 process( readLine().stripWhiteSpace() );
316} 316}
317 317
318bool ServerPI::checkReadFile( const QString& file ) 318bool ServerPI::checkReadFile( const QString& file )
319{ 319{
320 QString filename; 320 QString filename;
321 321
322 if ( file[0] != "/" ) 322 if ( file[0] != "/" )
323 filename = directory.path() + "/" + file; 323 filename = directory.path() + "/" + file;
324 else 324 else
325 filename = file; 325 filename = file;
326 326
327 QFileInfo fi( filename ); 327 QFileInfo fi( filename );
328 return ( fi.exists() && fi.isReadable() ); 328 return ( fi.exists() && fi.isReadable() );
329} 329}
330 330
331bool ServerPI::checkWriteFile( const QString& file ) 331bool ServerPI::checkWriteFile( const QString& file )
332{ 332{
333 QString filename; 333 QString filename;
334 334
335 if ( file[0] != "/" ) 335 if ( file[0] != "/" )
336 filename = directory.path() + "/" + file; 336 filename = directory.path() + "/" + file;
337 else 337 else
338 filename = file; 338 filename = file;
339 339
340 QFileInfo fi( filename ); 340 QFileInfo fi( filename );
341 341
342 if ( fi.exists() ) 342 if ( fi.exists() )
343 if ( !QFile( filename ).remove() ) 343 if ( !QFile( filename ).remove() )
344 return FALSE; 344 return FALSE;
345 return TRUE; 345 return TRUE;
346} 346}
347 347
348void ServerPI::process( const QString& message ) 348void ServerPI::process( const QString& message )
349{ 349{
350 //qDebug( "Command: %s", message.latin1() ); 350 //qDebug( "Command: %s", message.latin1() );
351 351
352 // split message using "," as separator 352 // split message using "," as separator
353 QStringList msg = QStringList::split( " ", message ); 353 QStringList msg = QStringList::split( " ", message );
354 if ( msg.isEmpty() ) return; 354 if ( msg.isEmpty() ) return;
355 355
356 // command token 356 // command token
357 QString cmd = msg[0].upper(); 357 QString cmd = msg[0].upper();
358 358
359 // argument token 359 // argument token
360 QString arg; 360 QString arg;
361 if ( msg.count() >= 2 ) 361 if ( msg.count() >= 2 )
362 arg = msg[1]; 362 arg = msg[1];
363 363
364 // full argument string 364 // full argument string
365 QString args; 365 QString args;
366 if ( msg.count() >= 2 ) { 366 if ( msg.count() >= 2 ) {
367 QStringList copy( msg ); 367 QStringList copy( msg );
368 // FIXME: for Qt3 368 // FIXME: for Qt3
369 // copy.pop_front() 369 // copy.pop_front()
370 copy.remove( copy.begin() ); 370 copy.remove( copy.begin() );
371 args = copy.join( " " ); 371 args = copy.join( " " );
372 } 372 }
373 373
374 //qDebug( "args: %s", args.latin1() ); 374 //qDebug( "args: %s", args.latin1() );
375 375
376 // we always respond to QUIT, regardless of state 376 // we always respond to QUIT, regardless of state
377 if ( cmd == "QUIT" ) { 377 if ( cmd == "QUIT" ) {
378 send( "211 Good bye!" ); 378 send( "211 Good bye!" );
379 delete this; 379 delete this;
380 return; 380 return;
381 } 381 }
382 382
383 // connected to client 383 // connected to client
384 if ( Connected == state ) 384 if ( Connected == state )
385 return; 385 return;
386 386
387 // waiting for user name 387 // waiting for user name
388 if ( Wait_USER == state ) { 388 if ( Wait_USER == state ) {
389 389
390 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 390 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
391 send( "530 Please login with USER and PASS" ); 391 send( "530 Please login with USER and PASS" );
392 return; 392 return;
393 } 393 }
394 send( "331 User name ok, need password" ); 394 send( "331 User name ok, need password" );
395 state = Wait_PASS; 395 state = Wait_PASS;
396 return; 396 return;
397 } 397 }
398 398
399 // waiting for password 399 // waiting for password
400 if ( Wait_PASS == state ) { 400 if ( Wait_PASS == state ) {
401 401
402 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 402 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
403 send( "530 Please login with USER and PASS" ); 403 send( "530 Please login with USER and PASS" );
404 return; 404 return;
405 } 405 }
406 send( "230 User logged in, proceed" ); 406 send( "230 User logged in, proceed" );
407 state = Ready; 407 state = Ready;
408 return; 408 return;
409 } 409 }
410 410
411 // ACCESS CONTROL COMMANDS 411 // ACCESS CONTROL COMMANDS
412 412
413 413
414 // account (ACCT) 414 // account (ACCT)
415 if ( cmd == "ACCT" ) { 415 if ( cmd == "ACCT" ) {
416 // even wu-ftp does not support it 416 // even wu-ftp does not support it
417 send( "502 Command not implemented" ); 417 send( "502 Command not implemented" );
418 } 418 }
419 419
420 // change working directory (CWD) 420 // change working directory (CWD)
421 else if ( cmd == "CWD" ) { 421 else if ( cmd == "CWD" ) {
422 422
423 if ( !args.isEmpty() ) { 423 if ( !args.isEmpty() ) {
424 if ( directory.cd( args, TRUE ) ) 424 if ( directory.cd( args, TRUE ) )
425 send( "250 Requested file action okay, completed" ); 425 send( "250 Requested file action okay, completed" );
426 else 426 else
427 send( "550 Requested action not taken" ); 427 send( "550 Requested action not taken" );
428 } 428 }
429 else 429 else
430 send( "500 Syntax error, command unrecognized" ); 430 send( "500 Syntax error, command unrecognized" );
431 } 431 }
432 432
433 // change to parent directory (CDUP) 433 // change to parent directory (CDUP)
434 else if ( cmd == "CDUP" ) { 434 else if ( cmd == "CDUP" ) {
435 if ( directory.cdUp() ) 435 if ( directory.cdUp() )
436 send( "250 Requested file action okay, completed" ); 436 send( "250 Requested file action okay, completed" );
437 else 437 else
438 send( "550 Requested action not taken" ); 438 send( "550 Requested action not taken" );
439 } 439 }
440 440
441 // structure mount (SMNT) 441 // structure mount (SMNT)
442 else if ( cmd == "SMNT" ) { 442 else if ( cmd == "SMNT" ) {
443 // even wu-ftp does not support it 443 // even wu-ftp does not support it
444 send( "502 Command not implemented" ); 444 send( "502 Command not implemented" );
445 } 445 }
446 446
447 // reinitialize (REIN) 447 // reinitialize (REIN)
448 else if ( cmd == "REIN" ) { 448 else if ( cmd == "REIN" ) {
449 // even wu-ftp does not support it 449 // even wu-ftp does not support it
450 send( "502 Command not implemented" ); 450 send( "502 Command not implemented" );
451 } 451 }
452 452
453 453
454 // TRANSFER PARAMETER COMMANDS 454 // TRANSFER PARAMETER COMMANDS
455 455
456 456
457 // data port (PORT) 457 // data port (PORT)
458 else if ( cmd == "PORT" ) { 458 else if ( cmd == "PORT" ) {
459 if ( parsePort( arg ) ) 459 if ( parsePort( arg ) )
460 send( "200 Command okay" ); 460 send( "200 Command okay" );
461 else 461 else
462 send( "500 Syntax error, command unrecognized" ); 462 send( "500 Syntax error, command unrecognized" );
463 } 463 }
464 464
465 // passive (PASV) 465 // passive (PASV)
466 else if ( cmd == "PASV" ) { 466 else if ( cmd == "PASV" ) {
467 passiv = TRUE; 467 passiv = TRUE;
468 send( "227 Entering Passive Mode (" 468 send( "227 Entering Passive Mode ("
469 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 469 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
470 + QString::number( ( serversocket->port() ) >> 8 ) + "," 470 + QString::number( ( serversocket->port() ) >> 8 ) + ","
471 + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); 471 + QString::number( ( serversocket->port() ) & 0xFF ) +")" );
472 } 472 }
473 473
474 // representation type (TYPE) 474 // representation type (TYPE)
475 else if ( cmd == "TYPE" ) { 475 else if ( cmd == "TYPE" ) {
476 if ( arg.upper() == "A" || arg.upper() == "I" ) 476 if ( arg.upper() == "A" || arg.upper() == "I" )
477 send( "200 Command okay" ); 477 send( "200 Command okay" );
478 else 478 else
479 send( "504 Command not implemented for that parameter" ); 479 send( "504 Command not implemented for that parameter" );
480 } 480 }
481 481
482 // file structure (STRU) 482 // file structure (STRU)
483 else if ( cmd == "STRU" ) { 483 else if ( cmd == "STRU" ) {
484 if ( arg.upper() == "F" ) 484 if ( arg.upper() == "F" )
485 send( "200 Command okay" ); 485 send( "200 Command okay" );
486 else 486 else
487 send( "504 Command not implemented for that parameter" ); 487 send( "504 Command not implemented for that parameter" );
488 } 488 }
489 489
490 // transfer mode (MODE) 490 // transfer mode (MODE)
491 else if ( cmd == "MODE" ) { 491 else if ( cmd == "MODE" ) {
492 if ( arg.upper() == "S" ) 492 if ( arg.upper() == "S" )
493 send( "200 Command okay" ); 493 send( "200 Command okay" );
494 else 494 else
495 send( "504 Command not implemented for that parameter" ); 495 send( "504 Command not implemented for that parameter" );
496 } 496 }
497 497
498 498
499 // FTP SERVICE COMMANDS 499 // FTP SERVICE COMMANDS
500 500
501 501
502 // retrieve (RETR) 502 // retrieve (RETR)
503 else if ( cmd == "RETR" ) 503 else if ( cmd == "RETR" )
504 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) 504 if ( !args.isEmpty() && checkReadFile( absFilePath( args ) )
505 || backupRestoreGzip( absFilePath( args ) ) ) { 505 || backupRestoreGzip( absFilePath( args ) ) ) {
506 send( "150 File status okay" ); 506 send( "150 File status okay" );
507 sendFile( absFilePath( args ) ); 507 sendFile( absFilePath( args ) );
508 } 508 }
509 else { 509 else {
510 qDebug("550 Requested action not taken"); 510 qDebug("550 Requested action not taken");
511 send( "550 Requested action not taken" ); 511 send( "550 Requested action not taken" );
512 } 512 }
513 513
514 // store (STOR) 514 // store (STOR)
515 else if ( cmd == "STOR" ) 515 else if ( cmd == "STOR" )
516 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 516 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
517 send( "150 File status okay" ); 517 send( "150 File status okay" );
518 retrieveFile( absFilePath( args ) ); 518 retrieveFile( absFilePath( args ) );
519 } 519 }
520 else 520 else
521 send( "550 Requested action not taken" ); 521 send( "550 Requested action not taken" );
522 522
523 // store unique (STOU) 523 // store unique (STOU)
524 else if ( cmd == "STOU" ) { 524 else if ( cmd == "STOU" ) {
525 send( "502 Command not implemented" ); 525 send( "502 Command not implemented" );
526 } 526 }
527 527
528 // append (APPE) 528 // append (APPE)
529 else if ( cmd == "APPE" ) { 529 else if ( cmd == "APPE" ) {
530 send( "502 Command not implemented" ); 530 send( "502 Command not implemented" );
531 } 531 }
532 532
533 // allocate (ALLO) 533 // allocate (ALLO)
534 else if ( cmd == "ALLO" ) { 534 else if ( cmd == "ALLO" ) {
535 send( "200 Command okay" ); 535 send( "200 Command okay" );
536 } 536 }
537 537
538 // restart (REST) 538 // restart (REST)
539 else if ( cmd == "REST" ) { 539 else if ( cmd == "REST" ) {
540 send( "502 Command not implemented" ); 540 send( "502 Command not implemented" );
541 } 541 }
542 542
543 // rename from (RNFR) 543 // rename from (RNFR)
544 else if ( cmd == "RNFR" ) { 544 else if ( cmd == "RNFR" ) {
545 renameFrom = QString::null; 545 renameFrom = QString::null;
546 if ( args.isEmpty() ) 546 if ( args.isEmpty() )
547 send( "500 Syntax error, command unrecognized" ); 547 send( "500 Syntax error, command unrecognized" );
548 else { 548 else {
549 QFile file( absFilePath( args ) ); 549 QFile file( absFilePath( args ) );
550 if ( file.exists() ) { 550 if ( file.exists() ) {
551 send( "350 File exists, ready for destination name" ); 551 send( "350 File exists, ready for destination name" );
552 renameFrom = absFilePath( args ); 552 renameFrom = absFilePath( args );
553 } 553 }
554 else 554 else
555 send( "550 Requested action not taken" ); 555 send( "550 Requested action not taken" );
556 } 556 }
557 } 557 }
558 558
559 // rename to (RNTO) 559 // rename to (RNTO)
560 else if ( cmd == "RNTO" ) { 560 else if ( cmd == "RNTO" ) {
561 if ( lastCommand != "RNFR" ) 561 if ( lastCommand != "RNFR" )
562 send( "503 Bad sequence of commands" ); 562 send( "503 Bad sequence of commands" );
563 else if ( args.isEmpty() ) 563 else if ( args.isEmpty() )
564 send( "500 Syntax error, command unrecognized" ); 564 send( "500 Syntax error, command unrecognized" );
565 else { 565 else {
566 QDir dir( absFilePath( args ) ); 566 QDir dir( absFilePath( args ) );
567 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 567 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
568 send( "250 Requested file action okay, completed." ); 568 send( "250 Requested file action okay, completed." );
569 else 569 else
570 send( "550 Requested action not taken" ); 570 send( "550 Requested action not taken" );
571 } 571 }
572 } 572 }
573 573
574 // abort (ABOR) 574 // abort (ABOR)
575 else if ( cmd.contains( "ABOR" ) ) { 575 else if ( cmd.contains( "ABOR" ) ) {
576 dtp->close(); 576 dtp->close();
577 if ( dtp->dtpMode() != ServerDTP::Idle ) 577 if ( dtp->dtpMode() != ServerDTP::Idle )
578 send( "426 Connection closed; transfer aborted" ); 578 send( "426 Connection closed; transfer aborted" );
579 else 579 else
580 send( "226 Closing data connection" ); 580 send( "226 Closing data connection" );
581 } 581 }
582 582
583 // delete (DELE) 583 // delete (DELE)
584 else if ( cmd == "DELE" ) { 584 else if ( cmd == "DELE" ) {
585 if ( args.isEmpty() ) 585 if ( args.isEmpty() )
586 send( "500 Syntax error, command unrecognized" ); 586 send( "500 Syntax error, command unrecognized" );
587 else { 587 else {
588 QFile file( absFilePath( args ) ) ; 588 QFile file( absFilePath( args ) ) ;
589 if ( file.remove() ) { 589 if ( file.remove() ) {
590 send( "250 Requested file action okay, completed" ); 590 send( "250 Requested file action okay, completed" );
591 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 591 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
592 e << file.name(); 592 e << file.name();
593 } else { 593 } else {
594 send( "550 Requested action not taken" ); 594 send( "550 Requested action not taken" );
595 } 595 }
596 } 596 }
597 } 597 }
598 598
599 // remove directory (RMD) 599 // remove directory (RMD)
600 else if ( cmd == "RMD" ) { 600 else if ( cmd == "RMD" ) {
601 if ( args.isEmpty() ) 601 if ( args.isEmpty() )
602 send( "500 Syntax error, command unrecognized" ); 602 send( "500 Syntax error, command unrecognized" );
603 else { 603 else {
604 QDir dir; 604 QDir dir;
605 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 605 if ( dir.rmdir( absFilePath( args ), TRUE ) )
606 send( "250 Requested file action okay, completed" ); 606 send( "250 Requested file action okay, completed" );
607 else 607 else
608 send( "550 Requested action not taken" ); 608 send( "550 Requested action not taken" );
609 } 609 }
610 } 610 }
611 611
612 // make directory (MKD) 612 // make directory (MKD)
613 else if ( cmd == "MKD" ) { 613 else if ( cmd == "MKD" ) {
614 if ( args.isEmpty() ) { 614 if ( args.isEmpty() ) {
615 qDebug(" Error: no arg"); 615 qDebug(" Error: no arg");
616 send( "500 Syntax error, command unrecognized" ); 616 send( "500 Syntax error, command unrecognized" );
617 } 617 }
618 else { 618 else {
619 QDir dir; 619 QDir dir;
620 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 620 if ( dir.mkdir( absFilePath( args ), TRUE ) )
621 send( "250 Requested file action okay, completed." ); 621 send( "250 Requested file action okay, completed." );
622 else 622 else
623 send( "550 Requested action not taken" ); 623 send( "550 Requested action not taken" );
624 } 624 }
625 } 625 }
626 626
627 // print working directory (PWD) 627 // print working directory (PWD)
628 else if ( cmd == "PWD" ) { 628 else if ( cmd == "PWD" ) {
629 send( "257 \"" + directory.path() +"\"" ); 629 send( "257 \"" + directory.path() +"\"" );
630 } 630 }
631 631
632 // list (LIST) 632 // list (LIST)
633 else if ( cmd == "LIST" ) { 633 else if ( cmd == "LIST" ) {
634 if ( sendList( absFilePath( args ) ) ) 634 if ( sendList( absFilePath( args ) ) )
635 send( "150 File status okay" ); 635 send( "150 File status okay" );
636 else 636 else
637 send( "500 Syntax error, command unrecognized" ); 637 send( "500 Syntax error, command unrecognized" );
638 } 638 }
639 639
640 // size (SIZE) 640 // size (SIZE)
641 else if ( cmd == "SIZE" ) { 641 else if ( cmd == "SIZE" ) {
642 QString filePath = absFilePath( args ); 642 QString filePath = absFilePath( args );
643 QFileInfo fi( filePath ); 643 QFileInfo fi( filePath );
644 bool gzipfile = backupRestoreGzip( filePath ); 644 bool gzipfile = backupRestoreGzip( filePath );
645 if ( !fi.exists() && !gzipfile ) 645 if ( !fi.exists() && !gzipfile )
646 send( "500 Syntax error, command unrecognized" ); 646 send( "500 Syntax error, command unrecognized" );
647 else { 647 else {
648 if ( !gzipfile ) 648 if ( !gzipfile )
649 send( "213 " + QString::number( fi.size() ) ); 649 send( "213 " + QString::number( fi.size() ) );
650 else { 650 else {
651 Process duproc( QString("du") ); 651 Process duproc( QString("du") );
652 duproc.addArgument("-s"); 652 duproc.addArgument("-s");
653 QString in, out; 653 QString in, out;
654 if ( !duproc.exec(in, out) ) { 654 if ( !duproc.exec(in, out) ) {
655 qDebug("du process failed; just sending back 1K"); 655 qDebug("du process failed; just sending back 1K");
656 send( "213 1024"); 656 send( "213 1024");
657 } 657 }
658 else { 658 else {
659 QString size = out.left( out.find("\t") ); 659 QString size = out.left( out.find("\t") );
660 int guess = size.toInt()/5; 660 int guess = size.toInt()/5;
661 if ( filePath.contains("doc") ) 661 if ( filePath.contains("doc") )
662 guess *= 1000; 662 guess *= 1000;
663 qDebug("sending back gzip guess of %d", guess); 663 qDebug("sending back gzip guess of %d", guess);
664 send( "213 " + QString::number(guess) ); 664 send( "213 " + QString::number(guess) );
665 } 665 }
666 } 666 }
667 } 667 }
668 } 668 }
669 // name list (NLST) 669 // name list (NLST)
670 else if ( cmd == "NLST" ) { 670 else if ( cmd == "NLST" ) {
671 send( "502 Command not implemented" ); 671 send( "502 Command not implemented" );
672 } 672 }
673 673
674 // site parameters (SITE) 674 // site parameters (SITE)
675 else if ( cmd == "SITE" ) { 675 else if ( cmd == "SITE" ) {
676 send( "502 Command not implemented" ); 676 send( "502 Command not implemented" );
677 } 677 }
678 678
679 // system (SYST) 679 // system (SYST)
680 else if ( cmd == "SYST" ) { 680 else if ( cmd == "SYST" ) {
681 send( "215 UNIX Type: L8" ); 681 send( "215 UNIX Type: L8" );
682 } 682 }
683 683
684 // status (STAT) 684 // status (STAT)
685 else if ( cmd == "STAT" ) { 685 else if ( cmd == "STAT" ) {
686 send( "502 Command not implemented" ); 686 send( "502 Command not implemented" );
687 } 687 }
688 688
689 // help (HELP ) 689 // help (HELP )
690 else if ( cmd == "HELP" ) { 690 else if ( cmd == "HELP" ) {
691 send( "502 Command not implemented" ); 691 send( "502 Command not implemented" );
692 } 692 }
693 693
694 // noop (NOOP) 694 // noop (NOOP)
695 else if ( cmd == "NOOP" ) { 695 else if ( cmd == "NOOP" ) {
696 send( "200 Command okay" ); 696 send( "200 Command okay" );
697 } 697 }
698 698
699 // not implemented 699 // not implemented
700 else 700 else
701 send( "502 Command not implemented" ); 701 send( "502 Command not implemented" );
702 702
703 lastCommand = cmd; 703 lastCommand = cmd;
704} 704}
705 705
706bool ServerPI::backupRestoreGzip( const QString &file ) 706bool ServerPI::backupRestoreGzip( const QString &file )
707{ 707{
708 return (file.find( "backup" ) != -1 && 708 return (file.find( "backup" ) != -1 &&
709 file.findRev( ".tgz" ) == (int)file.length()-4 ); 709 file.findRev( ".tgz" ) == (int)file.length()-4 );
710} 710}
711 711
712bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 712bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
713{ 713{
714 if ( file.find( "backup" ) != -1 && 714 if ( file.find( "backup" ) != -1 &&
715 file.findRev( ".tgz" ) == (int)file.length()-4 ) { 715 file.findRev( ".tgz" ) == (int)file.length()-4 ) {
716 QFileInfo info( file ); 716 QFileInfo info( file );
717 targets = info.dirPath( TRUE ); 717 targets = info.dirPath( TRUE );
718 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), 718 qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(),
719 targets.join(" ").latin1() ); 719 targets.join(" ").latin1() );
720 return true; 720 return true;
721 } 721 }
722 return false; 722 return false;
723} 723}
724 724
725void ServerPI::sendFile( const QString& file ) 725void ServerPI::sendFile( const QString& file )
726{ 726{
727 if ( passiv ) { 727 if ( passiv ) {
728 wait[SendFile] = TRUE; 728 wait[SendFile] = TRUE;
729 waitfile = file; 729 waitfile = file;
730 if ( waitsocket ) 730 if ( waitsocket )
731 newConnection( waitsocket ); 731 newConnection( waitsocket );
732 } 732 }
733 else { 733 else {
734 QStringList targets; 734 QStringList targets;
735 if ( backupRestoreGzip( file, targets ) ) 735 if ( backupRestoreGzip( file, targets ) )
736 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 736 dtp->sendGzipFile( file, targets, peeraddress, peerport );
737 else dtp->sendFile( file, peeraddress, peerport ); 737 else dtp->sendFile( file, peeraddress, peerport );
738 } 738 }
739} 739}
740 740
741void ServerPI::retrieveFile( const QString& file ) 741void ServerPI::retrieveFile( const QString& file )
742{ 742{
743 if ( passiv ) { 743 if ( passiv ) {
744 wait[RetrieveFile] = TRUE; 744 wait[RetrieveFile] = TRUE;
745 waitfile = file; 745 waitfile = file;
746 if ( waitsocket ) 746 if ( waitsocket )
747 newConnection( waitsocket ); 747 newConnection( waitsocket );
748 } 748 }
749 else { 749 else {
750 QStringList targets; 750 QStringList targets;
751 if ( backupRestoreGzip( file, targets ) ) 751 if ( backupRestoreGzip( file, targets ) )
752 dtp->retrieveGzipFile( file, peeraddress, peerport ); 752 dtp->retrieveGzipFile( file, peeraddress, peerport );
753 else 753 else
754 dtp->retrieveFile( file, peeraddress, peerport ); 754 dtp->retrieveFile( file, peeraddress, peerport );
755 } 755 }
756} 756}
757 757
758bool ServerPI::parsePort( const QString& pp ) 758bool ServerPI::parsePort( const QString& pp )
759{ 759{
760 QStringList p = QStringList::split( ",", pp ); 760 QStringList p = QStringList::split( ",", pp );
761 if ( p.count() != 6 ) return FALSE; 761 if ( p.count() != 6 ) return FALSE;
762 762
763 // h1,h2,h3,h4,p1,p2 763 // h1,h2,h3,h4,p1,p2
764 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + 764 peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) +
765 ( p[2].toInt() << 8 ) + p[3].toInt() ); 765 ( p[2].toInt() << 8 ) + p[3].toInt() );
766 peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); 766 peerport = ( p[4].toInt() << 8 ) + p[5].toInt();
767 return TRUE; 767 return TRUE;
768} 768}
769 769
770void ServerPI::dtpCompleted() 770void ServerPI::dtpCompleted()
771{ 771{
772 send( "226 Closing data connection, file transfer successful" ); 772 send( "226 Closing data connection, file transfer successful" );
773 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 773 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
774 QString fn = dtp->fileName(); 774 QString fn = dtp->fileName();
775 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { 775 if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
776 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 776 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
777 e << fn; 777 e << fn;
778 } 778 }
779 } 779 }
780 waitsocket = 0; 780 waitsocket = 0;
781 dtp->close(); 781 dtp->close();
782} 782}
783 783
784void ServerPI::dtpFailed() 784void ServerPI::dtpFailed()
785{ 785{
786 dtp->close(); 786 dtp->close();
787 waitsocket = 0; 787 waitsocket = 0;
788 send( "451 Requested action aborted: local error in processing" ); 788 send( "451 Requested action aborted: local error in processing" );
789} 789}
790 790
791void ServerPI::dtpError( int ) 791void ServerPI::dtpError( int )
792{ 792{
793 dtp->close(); 793 dtp->close();
794 waitsocket = 0; 794 waitsocket = 0;
795 send( "451 Requested action aborted: local error in processing" ); 795 send( "451 Requested action aborted: local error in processing" );
796} 796}
797 797
798bool ServerPI::sendList( const QString& arg ) 798bool ServerPI::sendList( const QString& arg )
799{ 799{
800 QByteArray listing; 800 QByteArray listing;
801 QBuffer buffer( listing ); 801 QBuffer buffer( listing );
802 802
803 if ( !buffer.open( IO_WriteOnly ) ) 803 if ( !buffer.open( IO_WriteOnly ) )
804 return FALSE; 804 return FALSE;
805 805
806 QTextStream ts( &buffer ); 806 QTextStream ts( &buffer );
807 QString fn = arg; 807 QString fn = arg;
808 808
809 if ( fn.isEmpty() ) 809 if ( fn.isEmpty() )
810 fn = directory.path(); 810 fn = directory.path();
811 811
812 QFileInfo fi( fn ); 812 QFileInfo fi( fn );
813 if ( !fi.exists() ) return FALSE; 813 if ( !fi.exists() ) return FALSE;
814 814
815 // return file listing 815 // return file listing
816 if ( fi.isFile() ) { 816 if ( fi.isFile() ) {
817 ts << fileListing( &fi ) << endl; 817 ts << fileListing( &fi ) << endl;
818 } 818 }
819 819
820 // return directory listing 820 // return directory listing
821 else if ( fi.isDir() ) { 821 else if ( fi.isDir() ) {
822 QDir dir( fn ); 822 QDir dir( fn );
823 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); 823 const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden );
824 824
825 QFileInfoListIterator it( *list ); 825 QFileInfoListIterator it( *list );
826 QFileInfo *info; 826 QFileInfo *info;
827 827
828 unsigned long total = 0; 828 unsigned long total = 0;
829 while ( ( info = it.current() ) ) { 829 while ( ( info = it.current() ) ) {
830 if ( info->fileName() != "." && info->fileName() != ".." ) 830 if ( info->fileName() != "." && info->fileName() != ".." )
831 total += info->size(); 831 total += info->size();
832 ++it; 832 ++it;
833 } 833 }
834 834
835 ts << "total " << QString::number( total / 1024 ) << endl; 835 ts << "total " << QString::number( total / 1024 ) << endl;
836 836
837 it.toFirst(); 837 it.toFirst();
838 while ( ( info = it.current() ) ) { 838 while ( ( info = it.current() ) ) {
839 if ( info->fileName() == "." || info->fileName() == ".." ) { 839 if ( info->fileName() == "." || info->fileName() == ".." ) {
840 ++it; 840 ++it;
841 continue; 841 continue;
842 } 842 }
843 ts << fileListing( info ) << endl; 843 ts << fileListing( info ) << endl;
844 ++it; 844 ++it;
845 } 845 }
846 } 846 }
847 847
848 if ( passiv ) { 848 if ( passiv ) {
849 waitarray = buffer.buffer(); 849 waitarray = buffer.buffer();
850 wait[SendByteArray] = TRUE; 850 wait[SendByteArray] = TRUE;
851 if ( waitsocket ) 851 if ( waitsocket )
852 newConnection( waitsocket ); 852 newConnection( waitsocket );
853 } 853 }
854 else 854 else
855 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); 855 dtp->sendByteArray( buffer.buffer(), peeraddress, peerport );
856 return TRUE; 856 return TRUE;
857} 857}
858 858
859QString ServerPI::fileListing( QFileInfo *info ) 859QString ServerPI::fileListing( QFileInfo *info )
860{ 860{
861 if ( !info ) return QString::null; 861 if ( !info ) return QString::null;
862 QString s; 862 QString s;
863 863
864 // type char 864 // type char
865 if ( info->isDir() ) 865 if ( info->isDir() )
866 s += "d"; 866 s += "d";
867 else if ( info->isSymLink() ) 867 else if ( info->isSymLink() )
868 s += "l"; 868 s += "l";
869 else 869 else
870 s += "-"; 870 s += "-";
871 871
872 // permisson string 872 // permisson string
873 s += permissionString( info ) + " "; 873 s += permissionString( info ) + " ";
874 874
875 // number of hardlinks 875 // number of hardlinks
876 int subdirs = 1; 876 int subdirs = 1;
877 877
878 if ( info->isDir() ) 878 if ( info->isDir() )
879 subdirs = 2; 879 subdirs = 2;
880 // FIXME : this is to slow 880 // FIXME : this is to slow
881 //if ( info->isDir() ) 881 //if ( info->isDir() )
882 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); 882 //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count();
883 883
884 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; 884 s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " ";
885 885
886 // owner 886 // owner
887 s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; 887 s += info->owner().leftJustify( 8, ' ', TRUE ) + " ";
888 888
889 // group 889 // group
890 s += info->group().leftJustify( 8, ' ', TRUE ) + " "; 890 s += info->group().leftJustify( 8, ' ', TRUE ) + " ";
891 891
892 // file size in bytes 892 // file size in bytes
893 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; 893 s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " ";
894 894
895 // last modified date 895 // last modified date
896 QDate date = info->lastModified().date(); 896 QDate date = info->lastModified().date();
897 QTime time = info->lastModified().time(); 897 QTime time = info->lastModified().time();
898 s += date.monthName( date.month() ) + " " 898 s += date.monthName( date.month() ) + " "
899 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " 899 + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " "
900 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" 900 + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":"
901 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; 901 + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " ";
902 902
903 // file name 903 // file name
904 s += info->fileName(); 904 s += info->fileName();
905 905
906 return s; 906 return s;
907} 907}
908 908
909QString ServerPI::permissionString( QFileInfo *info ) 909QString ServerPI::permissionString( QFileInfo *info )
910{ 910{
911 if ( !info ) return QString( "---------" ); 911 if ( !info ) return QString( "---------" );
912 QString s; 912 QString s;
913 913
914 // user 914 // user
915 if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; 915 if ( info->permission( QFileInfo::ReadUser ) ) s += "r";
916 else s += "-"; 916 else s += "-";
917 if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; 917 if ( info->permission( QFileInfo::WriteUser ) ) s += "w";
918 else s += "-"; 918 else s += "-";
919 if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; 919 if ( info->permission( QFileInfo::ExeUser ) ) s += "x";
920 else s += "-"; 920 else s += "-";
921 921
922 // group 922 // group
923 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; 923 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r";
924 else s += "-"; 924 else s += "-";
925 if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; 925 if ( info->permission( QFileInfo::WriteGroup ) )s += "w";
926 else s += "-"; 926 else s += "-";
927 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; 927 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x";
928 else s += "-"; 928 else s += "-";
929 929
930 // exec 930 // exec
931 if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; 931 if ( info->permission( QFileInfo::ReadOther ) ) s += "r";
932 else s += "-"; 932 else s += "-";
933 if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; 933 if ( info->permission( QFileInfo::WriteOther ) ) s += "w";
934 else s += "-"; 934 else s += "-";
935 if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; 935 if ( info->permission( QFileInfo::ExeOther ) ) s += "x";
936 else s += "-"; 936 else s += "-";
937 937
938 return s; 938 return s;
939} 939}
940 940
941void ServerPI::newConnection( int socket ) 941void ServerPI::newConnection( int socket )
942{ 942{
943 //qDebug( "New incomming connection" ); 943 //qDebug( "New incomming connection" );
944 944
945 if ( !passiv ) return; 945 if ( !passiv ) return;
946 946
947 if ( wait[SendFile] ) { 947 if ( wait[SendFile] ) {
948 QStringList targets; 948 QStringList targets;
949 if ( backupRestoreGzip( waitfile, targets ) ) 949 if ( backupRestoreGzip( waitfile, targets ) )
950 dtp->sendGzipFile( waitfile, targets ); 950 dtp->sendGzipFile( waitfile, targets );
951 else 951 else
952 dtp->sendFile( waitfile ); 952 dtp->sendFile( waitfile );
953 dtp->setSocket( socket ); 953 dtp->setSocket( socket );
954 } 954 }
955 else if ( wait[RetrieveFile] ) { 955 else if ( wait[RetrieveFile] ) {
956 qDebug("check retrieve file"); 956 qDebug("check retrieve file");
957 if ( backupRestoreGzip( waitfile ) ) 957 if ( backupRestoreGzip( waitfile ) )
958 dtp->retrieveGzipFile( waitfile ); 958 dtp->retrieveGzipFile( waitfile );
959 else 959 else
960 dtp->retrieveFile( waitfile ); 960 dtp->retrieveFile( waitfile );
961 dtp->setSocket( socket ); 961 dtp->setSocket( socket );
962 } 962 }
963 else if ( wait[SendByteArray] ) { 963 else if ( wait[SendByteArray] ) {
964 dtp->sendByteArray( waitarray ); 964 dtp->sendByteArray( waitarray );
965 dtp->setSocket( socket ); 965 dtp->setSocket( socket );
966 } 966 }
967 else if ( wait[RetrieveByteArray] ) { 967 else if ( wait[RetrieveByteArray] ) {
968 qDebug("retrieve byte array"); 968 qDebug("retrieve byte array");
969 dtp->retrieveByteArray(); 969 dtp->retrieveByteArray();
970 dtp->setSocket( socket ); 970 dtp->setSocket( socket );
971 } 971 }
972 else 972 else
973 waitsocket = socket; 973 waitsocket = socket;
974 974
975 for( int i = 0; i < 4; i++ ) 975 for( int i = 0; i < 4; i++ )
976 wait[i] = FALSE; 976 wait[i] = FALSE;
977} 977}
978 978
979QString ServerPI::absFilePath( const QString& file ) 979QString ServerPI::absFilePath( const QString& file )
980{ 980{
981 if ( file.isEmpty() ) return file; 981 if ( file.isEmpty() ) return file;
982 982
983 QString filepath( file ); 983 QString filepath( file );
984 if ( file[0] != "/" ) 984 if ( file[0] != "/" )
985 filepath = directory.path() + "/" + file; 985 filepath = directory.path() + "/" + file;
986 986
987 return filepath; 987 return filepath;
988} 988}
989 989
990 990
991void ServerPI::timerEvent( QTimerEvent * ) 991void ServerPI::timerEvent( QTimerEvent * )
992{ 992{
993 connectionClosed(); 993 connectionClosed();
994} 994}
995 995
996 996
997ServerDTP::ServerDTP( QObject *parent = 0, const char* name = 0) 997ServerDTP::ServerDTP( QObject *parent, const char* name)
998 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 998 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
999retrieveTargzProc( 0 ), gzipProc( 0 ) 999retrieveTargzProc( 0 ), gzipProc( 0 )
1000{ 1000{
1001 1001
1002 connect( this, SIGNAL( connected() ), SLOT( connected() ) ); 1002 connect( this, SIGNAL( connected() ), SLOT( connected() ) );
1003 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 1003 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
1004 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); 1004 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) );
1005 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 1005 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
1006 1006
1007 gzipProc = new QProcess( this, "gzipProc" ); 1007 gzipProc = new QProcess( this, "gzipProc" );
1008 gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); 1008 gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout );
1009 1009
1010 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); 1010 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc");
1011 createTargzProc->setCommunication( QProcess::Stdout ); 1011 createTargzProc->setCommunication( QProcess::Stdout );
1012 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1012 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1013 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 1013 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
1014 1014
1015 QStringList args = "tar"; 1015 QStringList args = "tar";
1016 args += "-xv"; 1016 args += "-xv";
1017 retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); 1017 retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" );
1018 retrieveTargzProc->setCommunication( QProcess::Stdin ); 1018 retrieveTargzProc->setCommunication( QProcess::Stdin );
1019 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1019 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1020 connect( retrieveTargzProc, SIGNAL( processExited() ), 1020 connect( retrieveTargzProc, SIGNAL( processExited() ),
1021 SIGNAL( completed() ) ); 1021 SIGNAL( completed() ) );
1022 connect( retrieveTargzProc, SIGNAL( processExited() ), 1022 connect( retrieveTargzProc, SIGNAL( processExited() ),
1023 SLOT( extractTarDone() ) ); 1023 SLOT( extractTarDone() ) );
1024} 1024}
1025 1025
1026ServerDTP::~ServerDTP() 1026ServerDTP::~ServerDTP()
1027{ 1027{
1028 buf.close(); 1028 buf.close();
1029 file.close(); 1029 file.close();
1030 createTargzProc->kill(); 1030 createTargzProc->kill();
1031} 1031}
1032 1032
1033void ServerDTP::extractTarDone() 1033void ServerDTP::extractTarDone()
1034{ 1034{
1035 qDebug("extract done"); 1035 qDebug("extract done");
1036#ifndef QT_NO_COP 1036#ifndef QT_NO_COP
1037 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); 1037 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
1038 e << file.name(); 1038 e << file.name();
1039#endif 1039#endif
1040} 1040}
1041 1041
1042void ServerDTP::connected() 1042void ServerDTP::connected()
1043{ 1043{
1044 // send file mode 1044 // send file mode
1045 switch ( mode ) { 1045 switch ( mode ) {
1046 case SendFile : 1046 case SendFile :
1047 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 1047 if ( !file.exists() || !file.open( IO_ReadOnly) ) {
1048 emit failed(); 1048 emit failed();
1049 mode = Idle; 1049 mode = Idle;
1050 return; 1050 return;
1051 } 1051 }
1052 1052
1053 //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); 1053 //qDebug( "Debug: Sending file '%s'", file.name().latin1() );
1054 1054
1055 bytes_written = 0; 1055 bytes_written = 0;
1056 if ( file.size() == 0 ) { 1056 if ( file.size() == 0 ) {
1057 //make sure it doesn't hang on empty files 1057 //make sure it doesn't hang on empty files
1058 file.close(); 1058 file.close();
1059 emit completed(); 1059 emit completed();
1060 mode = Idle; 1060 mode = Idle;
1061 } else { 1061 } else {
1062 1062
1063 if( !file.atEnd() ) { 1063 if( !file.atEnd() ) {
1064 QCString s; 1064 QCString s;
1065 s.resize( block_size ); 1065 s.resize( block_size );
1066 int bytes = file.readBlock( s.data(), block_size ); 1066 int bytes = file.readBlock( s.data(), block_size );
1067 writeBlock( s.data(), bytes ); 1067 writeBlock( s.data(), bytes );
1068 } 1068 }
1069 } 1069 }
1070 break; 1070 break;
1071 case SendGzipFile: 1071 case SendGzipFile:
1072 if ( createTargzProc->isRunning() ) { 1072 if ( createTargzProc->isRunning() ) {
1073 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY 1073 // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY
1074 qWarning("Previous tar --gzip process is still running; killing it..."); 1074 qWarning("Previous tar --gzip process is still running; killing it...");
1075 createTargzProc->kill(); 1075 createTargzProc->kill();
1076 } 1076 }
1077 1077
1078 bytes_written = 0; 1078 bytes_written = 0;
1079 qDebug("==>start send tar process"); 1079 qDebug("==>start send tar process");
1080 if ( !createTargzProc->start() ) 1080 if ( !createTargzProc->start() )
1081 qWarning("Error starting %s or %s", 1081 qWarning("Error starting %s or %s",
1082 createTargzProc->arguments().join(" ").latin1(), 1082 createTargzProc->arguments().join(" ").latin1(),
1083 gzipProc->arguments().join(" ").latin1() ); 1083 gzipProc->arguments().join(" ").latin1() );
1084 break; 1084 break;
1085 case SendBuffer: 1085 case SendBuffer:
1086 if ( !buf.open( IO_ReadOnly) ) { 1086 if ( !buf.open( IO_ReadOnly) ) {
1087 emit failed(); 1087 emit failed();
1088 mode = Idle; 1088 mode = Idle;
1089 return; 1089 return;
1090 } 1090 }
1091 1091
1092 // qDebug( "Debug: Sending byte array" ); 1092 // qDebug( "Debug: Sending byte array" );
1093 bytes_written = 0; 1093 bytes_written = 0;
1094 while( !buf.atEnd() ) 1094 while( !buf.atEnd() )
1095 putch( buf.getch() ); 1095 putch( buf.getch() );
1096 buf.close(); 1096 buf.close();
1097 break; 1097 break;
1098 case RetrieveFile: 1098 case RetrieveFile:
1099 // retrieve file mode 1099 // retrieve file mode
1100 if ( file.exists() && !file.remove() ) { 1100 if ( file.exists() && !file.remove() ) {
1101 emit failed(); 1101 emit failed();
1102 mode = Idle; 1102 mode = Idle;
1103 return; 1103 return;
1104 } 1104 }
1105 1105
1106 if ( !file.open( IO_WriteOnly) ) { 1106 if ( !file.open( IO_WriteOnly) ) {
1107 emit failed(); 1107 emit failed();
1108 mode = Idle; 1108 mode = Idle;
1109 return; 1109 return;
1110 } 1110 }
1111 // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); 1111 // qDebug( "Debug: Retrieving file %s", file.name().latin1() );
1112 break; 1112 break;
1113 case RetrieveGzipFile: 1113 case RetrieveGzipFile:
1114 qDebug("=-> starting tar process to receive .tgz file"); 1114 qDebug("=-> starting tar process to receive .tgz file");
1115 break; 1115 break;
1116 case RetrieveBuffer: 1116 case RetrieveBuffer:
1117 // retrieve buffer mode 1117 // retrieve buffer mode
1118 if ( !buf.open( IO_WriteOnly) ) { 1118 if ( !buf.open( IO_WriteOnly) ) {
1119 emit failed(); 1119 emit failed();
1120 mode = Idle; 1120 mode = Idle;
1121 return; 1121 return;
1122 } 1122 }
1123 // qDebug( "Debug: Retrieving byte array" ); 1123 // qDebug( "Debug: Retrieving byte array" );
1124 break; 1124 break;
1125 case Idle: 1125 case Idle:
1126 qDebug("connection established but mode set to Idle; BUG!"); 1126 qDebug("connection established but mode set to Idle; BUG!");
1127 break; 1127 break;
1128 } 1128 }
1129} 1129}
1130 1130
1131void ServerDTP::connectionClosed() 1131void ServerDTP::connectionClosed()
1132{ 1132{
1133 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); 1133 //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written );
1134 1134
1135 // send file mode 1135 // send file mode
1136 if ( SendFile == mode ) { 1136 if ( SendFile == mode ) {
1137 if ( bytes_written == file.size() ) 1137 if ( bytes_written == file.size() )
1138 emit completed(); 1138 emit completed();
1139 else 1139 else
1140 emit failed(); 1140 emit failed();
1141 } 1141 }
1142 1142
1143 // send buffer mode 1143 // send buffer mode
1144 else if ( SendBuffer == mode ) { 1144 else if ( SendBuffer == mode ) {
1145 if ( bytes_written == buf.size() ) 1145 if ( bytes_written == buf.size() )
1146 emit completed(); 1146 emit completed();
1147 else 1147 else
1148 emit failed(); 1148 emit failed();
1149 } 1149 }
1150 1150
1151 // retrieve file mode 1151 // retrieve file mode
1152 else if ( RetrieveFile == mode ) { 1152 else if ( RetrieveFile == mode ) {
1153 file.close(); 1153 file.close();
1154 emit completed(); 1154 emit completed();
1155 } 1155 }
1156 1156
1157 else if ( RetrieveGzipFile == mode ) { 1157 else if ( RetrieveGzipFile == mode ) {
1158 qDebug("Done writing ungzip file; closing input"); 1158 qDebug("Done writing ungzip file; closing input");
1159 gzipProc->flushStdin(); 1159 gzipProc->flushStdin();
1160 gzipProc->closeStdin(); 1160 gzipProc->closeStdin();
1161 } 1161 }
1162 1162
1163 // retrieve buffer mode 1163 // retrieve buffer mode
1164 else if ( RetrieveBuffer == mode ) { 1164 else if ( RetrieveBuffer == mode ) {
1165 buf.close(); 1165 buf.close();
1166 emit completed(); 1166 emit completed();
1167 } 1167 }
1168 1168
1169 mode = Idle; 1169 mode = Idle;
1170} 1170}
1171 1171
1172void ServerDTP::bytesWritten( int bytes ) 1172void ServerDTP::bytesWritten( int bytes )
1173{ 1173{
1174 bytes_written += bytes; 1174 bytes_written += bytes;
1175 1175
1176 // send file mode 1176 // send file mode
1177 if ( SendFile == mode ) { 1177 if ( SendFile == mode ) {
1178 1178
1179 if ( bytes_written == file.size() ) { 1179 if ( bytes_written == file.size() ) {
1180 // qDebug( "Debug: Sending complete: %d bytes", file.size() ); 1180 // qDebug( "Debug: Sending complete: %d bytes", file.size() );
1181 file.close(); 1181 file.close();
1182 emit completed(); 1182 emit completed();
1183 mode = Idle; 1183 mode = Idle;
1184 } 1184 }
1185 else if( !file.atEnd() ) { 1185 else if( !file.atEnd() ) {
1186 QCString s; 1186 QCString s;
1187 s.resize( block_size ); 1187 s.resize( block_size );
1188 int bytes = file.readBlock( s.data(), block_size ); 1188 int bytes = file.readBlock( s.data(), block_size );
1189 writeBlock( s.data(), bytes ); 1189 writeBlock( s.data(), bytes );
1190 } 1190 }
1191 } 1191 }
1192 1192
1193 // send buffer mode 1193 // send buffer mode
1194 if ( SendBuffer == mode ) { 1194 if ( SendBuffer == mode ) {
1195 1195
1196 if ( bytes_written == buf.size() ) { 1196 if ( bytes_written == buf.size() ) {
1197 // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); 1197 // qDebug( "Debug: Sending complete: %d bytes", buf.size() );
1198 emit completed(); 1198 emit completed();
1199 mode = Idle; 1199 mode = Idle;
1200 } 1200 }
1201 } 1201 }
1202} 1202}
1203 1203
1204void ServerDTP::readyRead() 1204void ServerDTP::readyRead()
1205{ 1205{
1206 // retrieve file mode 1206 // retrieve file mode
1207 if ( RetrieveFile == mode ) { 1207 if ( RetrieveFile == mode ) {
1208 QCString s; 1208 QCString s;
1209 s.resize( bytesAvailable() ); 1209 s.resize( bytesAvailable() );
1210 readBlock( s.data(), bytesAvailable() ); 1210 readBlock( s.data(), bytesAvailable() );
1211 file.writeBlock( s.data(), s.size() ); 1211 file.writeBlock( s.data(), s.size() );
1212 } 1212 }
1213 else if ( RetrieveGzipFile == mode ) { 1213 else if ( RetrieveGzipFile == mode ) {
1214 if ( !gzipProc->isRunning() ) 1214 if ( !gzipProc->isRunning() )
1215 gzipProc->start(); 1215 gzipProc->start();
1216 1216
1217 QByteArray s; 1217 QByteArray s;
1218 s.resize( bytesAvailable() ); 1218 s.resize( bytesAvailable() );
1219 readBlock( s.data(), bytesAvailable() ); 1219 readBlock( s.data(), bytesAvailable() );
1220 gzipProc->writeToStdin( s ); 1220 gzipProc->writeToStdin( s );
1221 qDebug("wrote %d bytes to ungzip ", s.size() ); 1221 qDebug("wrote %d bytes to ungzip ", s.size() );
1222 } 1222 }
1223 // retrieve buffer mode 1223 // retrieve buffer mode
1224 else if ( RetrieveBuffer == mode ) { 1224 else if ( RetrieveBuffer == mode ) {
1225 QCString s; 1225 QCString s;
1226 s.resize( bytesAvailable() ); 1226 s.resize( bytesAvailable() );
1227 readBlock( s.data(), bytesAvailable() ); 1227 readBlock( s.data(), bytesAvailable() );
1228 buf.writeBlock( s.data(), s.size() ); 1228 buf.writeBlock( s.data(), s.size() );
1229 } 1229 }
1230} 1230}
1231 1231
1232void ServerDTP::writeTargzBlock() 1232void ServerDTP::writeTargzBlock()
1233{ 1233{
1234 QByteArray block = gzipProc->readStdout(); 1234 QByteArray block = gzipProc->readStdout();
1235 writeBlock( block.data(), block.size() ); 1235 writeBlock( block.data(), block.size() );
1236 qDebug("writeTargzBlock %d", block.size()); 1236 qDebug("writeTargzBlock %d", block.size());
1237 if ( !createTargzProc->isRunning() ) { 1237 if ( !createTargzProc->isRunning() ) {
1238 qDebug("tar and gzip done"); 1238 qDebug("tar and gzip done");
1239 emit completed(); 1239 emit completed();
1240 mode = Idle; 1240 mode = Idle;
1241 disconnect( gzipProc, SIGNAL( readyReadStdout() ), 1241 disconnect( gzipProc, SIGNAL( readyReadStdout() ),
1242 this, SLOT( writeTargzBlock() ) ); 1242 this, SLOT( writeTargzBlock() ) );
1243 } 1243 }
1244} 1244}
1245 1245
1246void ServerDTP::targzDone() 1246void ServerDTP::targzDone()
1247{ 1247{
1248 //qDebug("targz done"); 1248 //qDebug("targz done");
1249 disconnect( createTargzProc, SIGNAL( readyReadStdout() ), 1249 disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
1250 this, SLOT( gzipTarBlock() ) ); 1250 this, SLOT( gzipTarBlock() ) );
1251 gzipProc->closeStdin(); 1251 gzipProc->closeStdin();
1252} 1252}
1253 1253
1254void ServerDTP::gzipTarBlock() 1254void ServerDTP::gzipTarBlock()
1255{ 1255{
1256 //qDebug("gzipTarBlock"); 1256 //qDebug("gzipTarBlock");
1257 if ( !gzipProc->isRunning() ) { 1257 if ( !gzipProc->isRunning() ) {
1258 //qDebug("auto start gzip proc"); 1258 //qDebug("auto start gzip proc");
1259 gzipProc->start(); 1259 gzipProc->start();
1260 } 1260 }
1261 gzipProc->writeToStdin( createTargzProc->readStdout() ); 1261 gzipProc->writeToStdin( createTargzProc->readStdout() );
1262} 1262}
1263 1263
1264void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1264void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1265{ 1265{
1266 file.setName( fn ); 1266 file.setName( fn );
1267 mode = SendFile; 1267 mode = SendFile;
1268 connectToHost( host.toString(), port ); 1268 connectToHost( host.toString(), port );
1269} 1269}
1270 1270
1271void ServerDTP::sendFile( const QString fn ) 1271void ServerDTP::sendFile( const QString fn )
1272{ 1272{
1273 file.setName( fn ); 1273 file.setName( fn );
1274 mode = SendFile; 1274 mode = SendFile;
1275} 1275}
1276 1276
1277void ServerDTP::sendGzipFile( const QString &fn, 1277void ServerDTP::sendGzipFile( const QString &fn,
1278 const QStringList &archiveTargets, 1278 const QStringList &archiveTargets,
1279 const QHostAddress& host, Q_UINT16 port ) 1279 const QHostAddress& host, Q_UINT16 port )
1280{ 1280{
1281 sendGzipFile( fn, archiveTargets ); 1281 sendGzipFile( fn, archiveTargets );
1282 connectToHost( host.toString(), port ); 1282 connectToHost( host.toString(), port );
1283} 1283}
1284 1284
1285void ServerDTP::sendGzipFile( const QString &fn, 1285void ServerDTP::sendGzipFile( const QString &fn,
1286 const QStringList &archiveTargets ) 1286 const QStringList &archiveTargets )
1287{ 1287{
1288 mode = SendGzipFile; 1288 mode = SendGzipFile;
1289 file.setName( fn ); 1289 file.setName( fn );
1290 1290
1291 QStringList args = "tar"; 1291 QStringList args = "tar";
1292 args += "-cv"; 1292 args += "-cv";
1293 args += archiveTargets; 1293 args += archiveTargets;
1294 qDebug("sendGzipFile %s", args.join(" ").latin1() ); 1294 qDebug("sendGzipFile %s", args.join(" ").latin1() );
1295 createTargzProc->setArguments( args ); 1295 createTargzProc->setArguments( args );
1296 connect( createTargzProc, 1296 connect( createTargzProc,
1297 SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); 1297 SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) );
1298 1298
1299 gzipProc->setArguments( "gzip" ); 1299 gzipProc->setArguments( "gzip" );
1300 connect( gzipProc, SIGNAL( readyReadStdout() ), 1300 connect( gzipProc, SIGNAL( readyReadStdout() ),
1301 SLOT( writeTargzBlock() ) ); 1301 SLOT( writeTargzBlock() ) );
1302} 1302}
1303 1303
1304void ServerDTP::gunzipDone() 1304void ServerDTP::gunzipDone()
1305{ 1305{
1306 qDebug("gunzipDone"); 1306 qDebug("gunzipDone");
1307 disconnect( gzipProc, SIGNAL( processExited() ), 1307 disconnect( gzipProc, SIGNAL( processExited() ),
1308 this, SLOT( gunzipDone() ) ); 1308 this, SLOT( gunzipDone() ) );
1309 retrieveTargzProc->closeStdin(); 1309 retrieveTargzProc->closeStdin();
1310 disconnect( gzipProc, SIGNAL( readyReadStdout() ), 1310 disconnect( gzipProc, SIGNAL( readyReadStdout() ),
1311 this, SLOT( tarExtractBlock() ) ); 1311 this, SLOT( tarExtractBlock() ) );
1312} 1312}
1313 1313
1314void ServerDTP::tarExtractBlock() 1314void ServerDTP::tarExtractBlock()
1315{ 1315{
1316 qDebug("ungzipTarBlock"); 1316 qDebug("ungzipTarBlock");
1317 if ( !retrieveTargzProc->isRunning() ) { 1317 if ( !retrieveTargzProc->isRunning() ) {
1318 qDebug("auto start ungzip proc"); 1318 qDebug("auto start ungzip proc");
1319 if ( !retrieveTargzProc->start() ) 1319 if ( !retrieveTargzProc->start() )
1320 qWarning(" failed to start tar -x process"); 1320 qWarning(" failed to start tar -x process");
1321 } 1321 }
1322 retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); 1322 retrieveTargzProc->writeToStdin( gzipProc->readStdout() );
1323} 1323}
1324 1324
1325 1325
1326void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1326void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1327{ 1327{
1328 file.setName( fn ); 1328 file.setName( fn );
1329 mode = RetrieveFile; 1329 mode = RetrieveFile;
1330 connectToHost( host.toString(), port ); 1330 connectToHost( host.toString(), port );
1331} 1331}
1332 1332
1333void ServerDTP::retrieveFile( const QString fn ) 1333void ServerDTP::retrieveFile( const QString fn )
1334{ 1334{
1335 file.setName( fn ); 1335 file.setName( fn );
1336 mode = RetrieveFile; 1336 mode = RetrieveFile;
1337} 1337}
1338 1338
1339void ServerDTP::retrieveGzipFile( const QString &fn ) 1339void ServerDTP::retrieveGzipFile( const QString &fn )
1340{ 1340{
1341 qDebug("retrieveGzipFile %s", fn.latin1()); 1341 qDebug("retrieveGzipFile %s", fn.latin1());
1342 file.setName( fn ); 1342 file.setName( fn );
1343 mode = RetrieveGzipFile; 1343 mode = RetrieveGzipFile;
1344 1344
1345 gzipProc->setArguments( "gunzip" ); 1345 gzipProc->setArguments( "gunzip" );
1346 connect( gzipProc, SIGNAL( readyReadStdout() ), 1346 connect( gzipProc, SIGNAL( readyReadStdout() ),
1347 SLOT( tarExtractBlock() ) ); 1347 SLOT( tarExtractBlock() ) );
1348 connect( gzipProc, SIGNAL( processExited() ), 1348 connect( gzipProc, SIGNAL( processExited() ),
1349 SLOT( gunzipDone() ) ); 1349 SLOT( gunzipDone() ) );
1350} 1350}
1351 1351
1352void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) 1352void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port )
1353{ 1353{
1354 retrieveGzipFile( fn ); 1354 retrieveGzipFile( fn );
1355 connectToHost( host.toString(), port ); 1355 connectToHost( host.toString(), port );
1356} 1356}
1357 1357
1358void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) 1358void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port )
1359{ 1359{
1360 buf.setBuffer( array ); 1360 buf.setBuffer( array );
1361 mode = SendBuffer; 1361 mode = SendBuffer;
1362 connectToHost( host.toString(), port ); 1362 connectToHost( host.toString(), port );
1363} 1363}
1364 1364
1365void ServerDTP::sendByteArray( const QByteArray& array ) 1365void ServerDTP::sendByteArray( const QByteArray& array )
1366{ 1366{
1367 buf.setBuffer( array ); 1367 buf.setBuffer( array );
1368 mode = SendBuffer; 1368 mode = SendBuffer;
1369} 1369}
1370 1370
1371void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) 1371void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port )
1372{ 1372{
1373 buf.setBuffer( QByteArray() ); 1373 buf.setBuffer( QByteArray() );
1374 mode = RetrieveBuffer; 1374 mode = RetrieveBuffer;
1375 connectToHost( host.toString(), port ); 1375 connectToHost( host.toString(), port );
1376} 1376}
1377 1377
1378void ServerDTP::retrieveByteArray() 1378void ServerDTP::retrieveByteArray()
1379{ 1379{
1380 buf.setBuffer( QByteArray() ); 1380 buf.setBuffer( QByteArray() );
1381 mode = RetrieveBuffer; 1381 mode = RetrieveBuffer;
1382} 1382}
1383 1383
1384void ServerDTP::setSocket( int socket ) 1384void ServerDTP::setSocket( int socket )
1385{ 1385{
1386 QSocket::setSocket( socket ); 1386 QSocket::setSocket( socket );
1387 connected(); 1387 connected();
1388} 1388}
1389 1389