-rw-r--r-- | core/launcher/launcherview.cpp | 5 | ||||
-rw-r--r-- | core/launcher/transferserver.cpp | 2 |
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,390 +1,391 @@ | |||
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 | ||
47 | class BgPixmap | 48 | class BgPixmap |
48 | { | 49 | { |
49 | public: | 50 | public: |
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 | ||
55 | enum BusyIndicatorType { | 56 | enum BusyIndicatorType { |
56 | BIT_Normal = 0, | 57 | BIT_Normal = 0, |
57 | BIT_Blinking | 58 | BIT_Blinking |
58 | }; | 59 | }; |
59 | 60 | ||
60 | static QMap<QString,BgPixmap*> *bgCache = 0; | 61 | static QMap<QString,BgPixmap*> *bgCache = 0; |
61 | 62 | ||
62 | class LauncherIconView : public QIconView { | 63 | class LauncherIconView : public QIconView { |
63 | public: | 64 | public: |
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 | ||
303 | protected: | 304 | protected: |
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 | ||
377 | private: | 378 | private: |
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; |
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 | |||
@@ -741,513 +741,513 @@ void ServerPI::sendFile( const QString& file ) | |||
741 | void ServerPI::retrieveFile( const QString& file ) | 741 | void 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 | ||
758 | bool ServerPI::parsePort( const QString& pp ) | 758 | bool 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 | ||
770 | void ServerPI::dtpCompleted() | 770 | void 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 | ||
784 | void ServerPI::dtpFailed() | 784 | void 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 | ||
791 | void ServerPI::dtpError( int ) | 791 | void 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 | ||
798 | bool ServerPI::sendList( const QString& arg ) | 798 | bool 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 | ||
859 | QString ServerPI::fileListing( QFileInfo *info ) | 859 | QString 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 | ||
909 | QString ServerPI::permissionString( QFileInfo *info ) | 909 | QString 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 | ||
941 | void ServerPI::newConnection( int socket ) | 941 | void 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 | ||
979 | QString ServerPI::absFilePath( const QString& file ) | 979 | QString 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 | ||
991 | void ServerPI::timerEvent( QTimerEvent * ) | 991 | void ServerPI::timerEvent( QTimerEvent * ) |
992 | { | 992 | { |
993 | connectionClosed(); | 993 | connectionClosed(); |
994 | } | 994 | } |
995 | 995 | ||
996 | 996 | ||
997 | ServerDTP::ServerDTP( QObject *parent = 0, const char* name = 0) | 997 | ServerDTP::ServerDTP( QObject *parent, const char* name) |
998 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), | 998 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), |
999 | retrieveTargzProc( 0 ), gzipProc( 0 ) | 999 | retrieveTargzProc( 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 | ||
1026 | ServerDTP::~ServerDTP() | 1026 | ServerDTP::~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 | ||
1033 | void ServerDTP::extractTarDone() | 1033 | void 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 | ||
1042 | void ServerDTP::connected() | 1042 | void 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 | ||
1131 | void ServerDTP::connectionClosed() | 1131 | void 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 | ||
1172 | void ServerDTP::bytesWritten( int bytes ) | 1172 | void 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 | ||
1204 | void ServerDTP::readyRead() | 1204 | void 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 | ||
1232 | void ServerDTP::writeTargzBlock() | 1232 | void 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 | ||
1246 | void ServerDTP::targzDone() | 1246 | void 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 | ||