author | llornkcor <llornkcor> | 2004-01-18 05:11:58 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-01-18 05:11:58 (UTC) |
commit | f5d28a9b86f5fdf8b4512d34c34e77284756f95c (patch) (unidiff) | |
tree | 9c6bf9022095a957c16f7a31f447608612a1589e | |
parent | 933d897346745d3d51e41591c59387ef6d2bb917 (diff) | |
download | opie-f5d28a9b86f5fdf8b4512d34c34e77284756f95c.zip opie-f5d28a9b86f5fdf8b4512d34c34e77284756f95c.tar.gz opie-f5d28a9b86f5fdf8b4512d34c34e77284756f95c.tar.bz2 |
fix for QWS_DISPLAY not being set
-rw-r--r-- | core/applets/screenshotapplet/screenshot.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/core/applets/screenshotapplet/screenshot.cpp b/core/applets/screenshotapplet/screenshot.cpp index f024f47..99effa5 100644 --- a/core/applets/screenshotapplet/screenshot.cpp +++ b/core/applets/screenshotapplet/screenshot.cpp | |||
@@ -227,298 +227,305 @@ static char * snapshot_xpm[] = { | |||
227 | "9 0 a b b b c _ ) : : ! ! ~ ~ 5 ~ d e f [ 8 g h h } ", | 227 | "9 0 a b b b c _ ) : : ! ! ~ ~ 5 ~ d e f [ 8 g h h } ", |
228 | "| i j k j l m n 3 ) : ! ! ! ~ o o o p 6 q f / r r r s ", | 228 | "| i j k j l m n 3 ) : ! ! ! ~ o o o p 6 q f / r r r s ", |
229 | "t u v w x y y z a 1 3 ' : ! ~ A A B A p = C D E F G ( s ", | 229 | "t u v w x y y z a 1 3 ' : ! ~ A A B A p = C D E F G ( s ", |
230 | "| u H I J K L M H k N 3 3 : ~ o o 5 O P Q R S T T U V W X Y ", | 230 | "| u H I J K L M H k N 3 3 : ~ o o 5 O P Q R S T T U V W X Y ", |
231 | "| Z ` J .....+.@.z #.3 _ 3 3 ) $.P W %.S &.*.*.&.S W Q P =.-. ", | 231 | "| Z ` J .....+.@.z #.3 _ 3 3 ) $.P W %.S &.*.*.&.S W Q P =.-. ", |
232 | ";.>.,.'.).!.!.).~.,.{.) : ) 3 ].h ^./.(._._._.:.<.[.g }.= & |. ", | 232 | ";.>.,.'.).!.!.).~.,.{.) : ) 3 ].h ^./.(._._._.:.<.[.g }.= & |. ", |
233 | ";.>.1.2.3.4.4.5.6.,.{._ : : : 7.8.9.0.a.b.b.c.d.} e.4 = 6 q # ", | 233 | ";.>.1.2.3.4.4.5.6.,.{._ : : : 7.8.9.0.a.b.b.c.d.} e.4 = 6 q # ", |
234 | ";.>.z f.g.h.i.j.k.l.N ) : ! ! 4 m.n.c.o.p.q.r.|.5 { d e e s.. ", | 234 | ";.>.z f.g.h.i.j.k.l.N ) : ! ! 4 m.n.c.o.p.q.r.|.5 { d e e s.. ", |
235 | "t Z l t.f.u.g.1.v.#.w.' : ! ~ ~ 7.|.n.x.y.z.A.A q - e e e B.> ", | 235 | "t Z l t.f.u.g.1.v.#.w.' : ! ~ ~ 7.|.n.x.y.z.A.A q - e e e B.> ", |
236 | "| 0 c k t.t.l l C.D.) * * ! 5 { B o E.F.F.G.= H.e e e e q B.. ", | 236 | "| 0 c k t.t.l l C.D.) * * ! 5 { B o E.F.F.G.= H.e e e e q B.. ", |
237 | "; + D.I.J.I.I.I.w.) : : * o K.7 - L.= O = }.6 6 e q q e q s.> ", | 237 | "; + D.I.J.I.I.I.w.) : : * o K.7 - L.= O = }.6 6 e q q e q s.> ", |
238 | "9 + ) ) ) ) ' ' , * : ! ! ! K.< . M.q 6 B N.{ d q e e e e s.9 ", | 238 | "9 + ) ) ) ) ' ' , * : ! ! ! K.< . M.q 6 B N.{ d q e e e e s.9 ", |
239 | "9 # O.) ) ' , , P.* ! ! ! ! = % . . M.e d p L.d B.B.e B.B.Q.9 ", | 239 | "9 # O.) ) ' , , P.* ! ! ! ! = % . . M.e d p L.d B.B.e B.B.Q.9 ", |
240 | "; < ' ' ' ' , , 4 4 ~ ! ! ~ ! 5 e q e e q A H.d q q e e B.Q.9 ", | 240 | "; < ' ' ' ' , , 4 4 ~ ! ! ~ ! 5 e q e e q A H.d q q e e B.Q.9 ", |
241 | "; $ R.K.5 4 4 ' ! ! 4 ~ ! ~ ~ ~ o { B o A A L.S.B.B.B.B.B.Q.> ", | 241 | "; $ R.K.5 4 4 ' ! ! 4 ~ ! ~ ~ ~ o { B o A A L.S.B.B.B.B.B.Q.> ", |
242 | " ] $ 0 R.= ' ' 4 4 5 4 5 5 o B o B p A A L.d e e B.B.B.Q.9 ", | 242 | " ] $ 0 R.= ' ' 4 4 5 4 5 5 o B o B p A A L.d e e B.B.B.Q.9 ", |
243 | " # + - { 4 4 ~ ! o { o L.p p p p p H.S.B.B.s.Q.Q.M.T. ", | 243 | " # + - { 4 4 ~ ! o { o L.p p p p p H.S.B.B.s.Q.Q.M.T. ", |
244 | " + s.6 B o o 5 B p L.p p L.p H.q B.Q.Q.Q.Q.M.; ", | 244 | " + s.6 B o o 5 B p L.p p L.p H.q B.Q.Q.Q.Q.M.; ", |
245 | " < # s.- B o B p p L.L.H.L.H.d B.Q.Q.Q.Q.Q.9 ", | 245 | " < # s.- B o B p p L.L.H.L.H.d B.Q.Q.Q.Q.Q.9 ", |
246 | " $ . s.d 6 B A p H.S.L.H.q B.Q.Q.M.M.. ; ", | 246 | " $ . s.d 6 B A p H.S.L.H.q B.Q.Q.M.M.. ; ", |
247 | " ; 9 . 6 L.p L.d L.H.d Q.M.M.. 9 ; ] ", | 247 | " ; 9 . 6 L.p L.d L.H.d Q.M.M.. 9 ; ] ", |
248 | " | > e L.d L.H.e M.. ; ] ] ", | 248 | " | > e L.d L.H.e M.. ; ] ] ", |
249 | " > 9 . S.Q.. ; ] ", | 249 | " > 9 . S.Q.. ; ] ", |
250 | " T.; ] "}; | 250 | " T.; ] "}; |
251 | 251 | ||
252 | static const char *SCAP_hostname = "www.handhelds.org"; | 252 | static const char *SCAP_hostname = "www.handhelds.org"; |
253 | static const int SCAP_port = 80; | 253 | static const int SCAP_port = 80; |
254 | 254 | ||
255 | 255 | ||
256 | ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name ) | 256 | ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name ) |
257 | : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) | 257 | : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) |
258 | { | 258 | { |
259 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 259 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
260 | QVBoxLayout *vbox = new QVBoxLayout ( this, 5, 3 ); | 260 | QVBoxLayout *vbox = new QVBoxLayout ( this, 5, 3 ); |
261 | QHBoxLayout *hbox; | 261 | QHBoxLayout *hbox; |
262 | 262 | ||
263 | hbox = new QHBoxLayout ( vbox ); | 263 | hbox = new QHBoxLayout ( vbox ); |
264 | 264 | ||
265 | QLabel *l = new QLabel ( tr( "Delay" ), this ); | 265 | QLabel *l = new QLabel ( tr( "Delay" ), this ); |
266 | hbox-> addWidget ( l ); | 266 | hbox-> addWidget ( l ); |
267 | 267 | ||
268 | delaySpin = new QSpinBox( 0, 60, 1, this, "Spinner" ); | 268 | delaySpin = new QSpinBox( 0, 60, 1, this, "Spinner" ); |
269 | delaySpin-> setButtonSymbols ( QSpinBox::PlusMinus ); | 269 | delaySpin-> setButtonSymbols ( QSpinBox::PlusMinus ); |
270 | delaySpin-> setSuffix ( tr( "sec" )); | 270 | delaySpin-> setSuffix ( tr( "sec" )); |
271 | delaySpin-> setFocusPolicy( QWidget::NoFocus ); | 271 | delaySpin-> setFocusPolicy( QWidget::NoFocus ); |
272 | delaySpin-> setValue ( 1 ); | 272 | delaySpin-> setValue ( 1 ); |
273 | hbox-> addWidget ( delaySpin ); | 273 | hbox-> addWidget ( delaySpin ); |
274 | 274 | ||
275 | saveNamedCheck = new QCheckBox ( tr( "Save named" ), this); | 275 | saveNamedCheck = new QCheckBox ( tr( "Save named" ), this); |
276 | saveNamedCheck-> setFocusPolicy ( QWidget::NoFocus ); | 276 | saveNamedCheck-> setFocusPolicy ( QWidget::NoFocus ); |
277 | vbox->addWidget( saveNamedCheck); | 277 | vbox->addWidget( saveNamedCheck); |
278 | 278 | ||
279 | vbox-> addSpacing ( 3 ); | 279 | vbox-> addSpacing ( 3 ); |
280 | 280 | ||
281 | l = new QLabel ( tr( "Save screenshot as..." ), this ); | 281 | l = new QLabel ( tr( "Save screenshot as..." ), this ); |
282 | vbox-> addWidget ( l, AlignCenter ); | 282 | vbox-> addWidget ( l, AlignCenter ); |
283 | 283 | ||
284 | hbox = new QHBoxLayout ( vbox ); | 284 | hbox = new QHBoxLayout ( vbox ); |
285 | 285 | ||
286 | grabItButton = new QPushButton( tr( "File" ), this, "GrabButton" ); | 286 | grabItButton = new QPushButton( tr( "File" ), this, "GrabButton" ); |
287 | grabItButton ->setFocusPolicy( QWidget::TabFocus ); | 287 | grabItButton ->setFocusPolicy( QWidget::TabFocus ); |
288 | hbox-> addWidget ( grabItButton ); | 288 | hbox-> addWidget ( grabItButton ); |
289 | 289 | ||
290 | scapButton = new QPushButton( tr( "Scap" ), this, "ScapButton" ); | 290 | scapButton = new QPushButton( tr( "Scap" ), this, "ScapButton" ); |
291 | scapButton ->setFocusPolicy( QWidget::TabFocus ); | 291 | scapButton ->setFocusPolicy( QWidget::TabFocus ); |
292 | hbox-> addWidget ( scapButton ); | 292 | hbox-> addWidget ( scapButton ); |
293 | 293 | ||
294 | setFixedSize ( sizeHint ( )); | 294 | setFixedSize ( sizeHint ( )); |
295 | setFocusPolicy ( QWidget::NoFocus ); | 295 | setFocusPolicy ( QWidget::NoFocus ); |
296 | 296 | ||
297 | 297 | ||
298 | grabTimer = new QTimer ( this, "grab timer"); | 298 | grabTimer = new QTimer ( this, "grab timer"); |
299 | 299 | ||
300 | connect ( grabTimer, SIGNAL( timeout ( )), this, SLOT( performGrab ( ))); | 300 | connect ( grabTimer, SIGNAL( timeout ( )), this, SLOT( performGrab ( ))); |
301 | connect ( grabItButton, SIGNAL( clicked ( )), SLOT( slotGrab ( ))); | 301 | connect ( grabItButton, SIGNAL( clicked ( )), SLOT( slotGrab ( ))); |
302 | connect ( scapButton, SIGNAL( clicked ( )), SLOT( slotScap ( ))); | 302 | connect ( scapButton, SIGNAL( clicked ( )), SLOT( slotScap ( ))); |
303 | } | 303 | } |
304 | 304 | ||
305 | void ScreenshotControl::slotGrab() | 305 | void ScreenshotControl::slotGrab() |
306 | { | 306 | { |
307 | buttonPushed = 1; | 307 | buttonPushed = 1; |
308 | hide(); | 308 | hide(); |
309 | 309 | ||
310 | setFileName = FALSE; | 310 | setFileName = FALSE; |
311 | if ( saveNamedCheck->isChecked()) { | 311 | if ( saveNamedCheck->isChecked()) { |
312 | setFileName = TRUE; | 312 | setFileName = TRUE; |
313 | InputDialog *fileDlg; | 313 | InputDialog *fileDlg; |
314 | 314 | ||
315 | fileDlg = new InputDialog( 0 , tr("Name of screenshot "), TRUE, 0); | 315 | fileDlg = new InputDialog( 0 , tr("Name of screenshot "), TRUE, 0); |
316 | fileDlg->exec(); | 316 | fileDlg->exec(); |
317 | fileDlg->raise(); | 317 | fileDlg->raise(); |
318 | QString fileName, list; | 318 | QString fileName, list; |
319 | if ( fileDlg->result() == 1 ) { | 319 | if ( fileDlg->result() == 1 ) { |
320 | fileName = fileDlg->LineEdit1->text(); | 320 | fileName = fileDlg->LineEdit1->text(); |
321 | 321 | ||
322 | if (fileName.find("/", 0, TRUE) == -1) | 322 | if (fileName.find("/", 0, TRUE) == -1) |
323 | FileNamePath = QDir::homeDirPath() + "/Documents/image/png/" + fileName; | 323 | FileNamePath = QDir::homeDirPath() + "/Documents/image/png/" + fileName; |
324 | else | 324 | else |
325 | FileNamePath = fileName; | 325 | FileNamePath = fileName; |
326 | 326 | ||
327 | } | 327 | } |
328 | delete fileDlg; | 328 | delete fileDlg; |
329 | } | 329 | } |
330 | 330 | ||
331 | if ( delaySpin->value() ) | 331 | if ( delaySpin->value() ) |
332 | grabTimer->start( delaySpin->value() * 1000, true ); | 332 | grabTimer->start( delaySpin->value() * 1000, true ); |
333 | else | 333 | else |
334 | show(); | 334 | show(); |
335 | } | 335 | } |
336 | 336 | ||
337 | void ScreenshotControl::slotScap() | 337 | void ScreenshotControl::slotScap() |
338 | { | 338 | { |
339 | buttonPushed = 2; | 339 | buttonPushed = 2; |
340 | hide(); | 340 | hide(); |
341 | 341 | ||
342 | if ( delaySpin->value() ) | 342 | if ( delaySpin->value() ) |
343 | grabTimer->start( delaySpin->value() * 1000, true ); | 343 | grabTimer->start( delaySpin->value() * 1000, true ); |
344 | else | 344 | else |
345 | show(); | 345 | show(); |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
349 | void ScreenshotControl::savePixmap() | 349 | void ScreenshotControl::savePixmap() |
350 | { | 350 | { |
351 | DocLnk lnk; | 351 | DocLnk lnk; |
352 | QString fileName; | 352 | QString fileName; |
353 | 353 | ||
354 | if ( setFileName) { | 354 | if ( setFileName) { |
355 | fileName = FileNamePath; | 355 | fileName = FileNamePath; |
356 | //not sure why this is needed here, but it forgets fileName | 356 | //not sure why this is needed here, but it forgets fileName |
357 | // if this is below the braces | 357 | // if this is below the braces |
358 | 358 | ||
359 | if (fileName.right(3) != "png") | 359 | if (fileName.right(3) != "png") |
360 | fileName = fileName + ".png"; | 360 | fileName = fileName + ".png"; |
361 | lnk.setFile(fileName); //sets File property | 361 | lnk.setFile(fileName); //sets File property |
362 | qDebug("saving file " + fileName); | 362 | qDebug("saving file " + fileName); |
363 | snapshot.save( fileName, "PNG"); | 363 | snapshot.save( fileName, "PNG"); |
364 | QFileInfo fi( fileName); | 364 | QFileInfo fi( fileName); |
365 | lnk.setName( fi.fileName()); //sets file name | 365 | lnk.setName( fi.fileName()); //sets file name |
366 | 366 | ||
367 | if (!lnk.writeLink()) | 367 | if (!lnk.writeLink()) |
368 | qDebug("Writing doclink did not work"); | 368 | qDebug("Writing doclink did not work"); |
369 | } | 369 | } |
370 | else { | 370 | else { |
371 | 371 | ||
372 | fileName = "sc_" + QDateTime::currentDateTime().toString(); | 372 | fileName = "sc_" + QDateTime::currentDateTime().toString(); |
373 | fileName.replace(QRegExp("'"), ""); | 373 | fileName.replace(QRegExp("'"), ""); |
374 | fileName.replace(QRegExp(" "), "_"); | 374 | fileName.replace(QRegExp(" "), "_"); |
375 | fileName.replace(QRegExp(":"), "."); | 375 | fileName.replace(QRegExp(":"), "."); |
376 | fileName.replace(QRegExp(","), ""); | 376 | fileName.replace(QRegExp(","), ""); |
377 | QString dirName = QDir::homeDirPath() + "/Documents/image/png/"; | 377 | QString dirName = QDir::homeDirPath() + "/Documents/image/png/"; |
378 | 378 | ||
379 | if ( !QDir( dirName).exists() ) { | 379 | if ( !QDir( dirName).exists() ) { |
380 | qDebug("making dir " + dirName); | 380 | qDebug("making dir " + dirName); |
381 | QString msg = "mkdir -p " + dirName; | 381 | QString msg = "mkdir -p " + dirName; |
382 | system(msg.latin1()); | 382 | system(msg.latin1()); |
383 | } | 383 | } |
384 | fileName = dirName + fileName; | 384 | fileName = dirName + fileName; |
385 | if (fileName.right(3) != "png") | 385 | if (fileName.right(3) != "png") |
386 | fileName = fileName + ".png"; | 386 | fileName = fileName + ".png"; |
387 | lnk.setFile(fileName); //sets File property | 387 | lnk.setFile(fileName); //sets File property |
388 | qDebug("saving file " + fileName); | 388 | qDebug("saving file " + fileName); |
389 | snapshot.save( fileName, "PNG"); | 389 | snapshot.save( fileName, "PNG"); |
390 | QFileInfo fi( fileName); | 390 | QFileInfo fi( fileName); |
391 | lnk.setName( fi.fileName()); //sets file name | 391 | lnk.setName( fi.fileName()); //sets file name |
392 | 392 | ||
393 | if (!lnk.writeLink()) | 393 | if (!lnk.writeLink()) |
394 | qDebug("Writing doclink did not work"); | 394 | qDebug("Writing doclink did not work"); |
395 | 395 | ||
396 | } | 396 | } |
397 | 397 | ||
398 | QPEApplication::beep(); | 398 | QPEApplication::beep(); |
399 | } | 399 | } |
400 | 400 | ||
401 | void ScreenshotControl::performGrab() | 401 | void ScreenshotControl::performGrab() |
402 | { | 402 | { |
403 | snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(), 0, 0, QApplication::desktop()->width(), QApplication::desktop()->height() ); | 403 | snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(), 0, 0, QApplication::desktop()->width(), QApplication::desktop()->height() ); |
404 | 404 | ||
405 | if (buttonPushed == 1) { | 405 | if (buttonPushed == 1) { |
406 | qDebug("grabbing screen"); | 406 | qDebug("grabbing screen"); |
407 | grabTimer->stop(); | 407 | grabTimer->stop(); |
408 | show(); | 408 | show(); |
409 | qApp->processEvents(); | 409 | qApp->processEvents(); |
410 | savePixmap(); | 410 | savePixmap(); |
411 | } else { | 411 | } else { |
412 | grabTimer->stop(); | 412 | grabTimer->stop(); |
413 | 413 | ||
414 | struct sockaddr_in raddr; | 414 | struct sockaddr_in raddr; |
415 | struct hostent *rhost_info; | 415 | struct hostent *rhost_info; |
416 | int sock = -1; | 416 | int sock = -1; |
417 | bool ok = false; | 417 | bool ok = false; |
418 | 418 | ||
419 | if (( rhost_info = (struct hostent *) ::gethostbyname ((char *) SCAP_hostname )) != 0 ) { | 419 | QString displayEnv = getenv("QWS_DISPLAY"); |
420 | qDebug(displayEnv); | ||
421 | |||
422 | if(( displayEnv.left(2) != ":0" ) && (!displayEnv.isEmpty())) { | ||
423 | |||
424 | if (( rhost_info = (struct hostent *) ::gethostbyname ((char *) SCAP_hostname )) != 0 ) { | ||
420 | ::memset ( &raddr, 0, sizeof (struct sockaddr_in)); | 425 | ::memset ( &raddr, 0, sizeof (struct sockaddr_in)); |
421 | ::memcpy ( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length ); | 426 | ::memcpy ( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length ); |
422 | raddr. sin_family = rhost_info-> h_addrtype; | 427 | raddr. sin_family = rhost_info-> h_addrtype; |
423 | raddr. sin_port = htons ( SCAP_port ); | 428 | raddr. sin_port = htons ( SCAP_port ); |
424 | 429 | ||
425 | if (( sock = ::socket ( AF_INET, SOCK_STREAM, 0 )) >= 0 ) { | 430 | if (( sock = ::socket ( AF_INET, SOCK_STREAM, 0 )) >= 0 ) { |
426 | if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) { | 431 | if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) { |
427 | 432 | ||
428 | QString header; | 433 | QString header; |
429 | 434 | ||
430 | QPixmap pix; | 435 | QPixmap pix; |
431 | QString displayEnv = getenv("QWS_DISPLAY"); | ||
432 | qDebug(displayEnv); | ||
433 | 436 | ||
434 | QString SCAP_model=""; | 437 | QString SCAP_model=""; |
435 | #warning FIXME: model string should be filled with actual device model | 438 | #warning FIXME: model string should be filled with actual device model |
436 | if( snapshot.width() > 320) | 439 | if( snapshot.width() > 320) |
437 | SCAP_model ="Corgi"; | 440 | SCAP_model ="Corgi"; |
438 | 441 | ||
439 | if(displayEnv == "QVFb:0") {//set this if you plan on using this app in qvfb!! | 442 | if(displayEnv == "QVFb:0") {//set this if you plan on using this app in qvfb!! |
440 | pix = snapshot.xForm(QWMatrix().rotate(90)); | 443 | pix = snapshot.xForm(QWMatrix().rotate(90)); |
441 | } else | 444 | } else |
442 | pix = ( snapshot.width() > snapshot.height() ) ? snapshot : snapshot.xForm( QWMatrix().rotate(90) ); | 445 | pix = ( snapshot.width() > snapshot.height() ) ? snapshot : snapshot.xForm( QWMatrix().rotate(90) ); |
443 | 446 | ||
444 | QImage img = pix.convertToImage().convertDepth( 16 ); // could make that also depth independent, if hh.org/scap can handle it | 447 | QImage img = pix.convertToImage().convertDepth( 16 ); // could make that also depth independent, if hh.org/scap can handle it |
445 | 448 | ||
446 | header = "POST /scap/capture.cgi?%1+%2 HTTP/1.1\n" // 1: model / 2: user | 449 | header = "POST /scap/capture.cgi?%1+%2 HTTP/1.1\n" // 1: model / 2: user |
447 | "Content-length: %3\n" // 3: content length | 450 | "Content-length: %3\n" // 3: content length |
448 | "Content-Type: image/png\n" | 451 | "Content-Type: image/png\n" |
449 | "Host: %4\n" // 4: scap host | 452 | "Host: %4\n" // 4: scap host |
450 | "\n"; | 453 | "\n"; |
451 | 454 | ||
452 | 455 | ||
453 | header = header.arg( SCAP_model).arg( ::getenv( "USER" ) ).arg( img.numBytes() ).arg( SCAP_hostname ); | 456 | header = header.arg( SCAP_model).arg( ::getenv( "USER" ) ).arg( img.numBytes() ).arg( SCAP_hostname ); |
454 | qDebug(header); | 457 | qDebug(header); |
455 | 458 | ||
456 | if ( !pix.isNull() ) { | 459 | if ( !pix.isNull() ) { |
457 | const char *ascii = header.latin1( ); | 460 | const char *ascii = header.latin1( ); |
458 | uint ascii_len = ::strlen( ascii ); | 461 | uint ascii_len = ::strlen( ascii ); |
459 | ::write ( sock, ascii, ascii_len ); | 462 | // ::write ( sock, ascii, ascii_len ); |
460 | ::write ( sock, img.bits(), img.numBytes() ); | 463 | // ::write ( sock, img.bits(), img.numBytes() ); |
461 | 464 | ||
462 | ok = true; | 465 | ok = true; |
463 | } | 466 | } |
464 | } | 467 | } |
465 | ::close ( sock ); | 468 | ::close ( sock ); |
466 | } | 469 | } |
467 | } | 470 | } |
468 | if ( ok ) | 471 | if ( ok ) { |
469 | QMessageBox::information( 0, tr( "Success" ), QString( "<p>%1</p>" ).arg ( tr( "Screenshot was uploaded to %1" )).arg( SCAP_hostname )); | 472 | QMessageBox::information( 0, tr( "Success" ), QString( "<p>%1</p>" ).arg ( tr( "Screenshot was uploaded to %1" )).arg( SCAP_hostname )); |
470 | else | 473 | } else { |
471 | QMessageBox::warning( 0, tr( "Error" ), QString( "<p>%1</p>" ).arg( tr( "Connection to %1 failed." )).arg( SCAP_hostname )); | 474 | QMessageBox::warning( 0, tr( "Error" ), QString( "<p>%1</p>" ).arg( tr( "Connection to %1 failed." )).arg( SCAP_hostname )); |
475 | } | ||
476 | } else { | ||
477 | QMessageBox::warning( 0, tr( "Error" ),tr("Please set <b>QWS_DISPLAY</b> environmental variable.")); | ||
478 | } | ||
472 | } | 479 | } |
473 | 480 | ||
474 | } | 481 | } |
475 | 482 | ||
476 | 483 | ||
477 | 484 | ||
478 | //=========================================================================== | 485 | //=========================================================================== |
479 | 486 | ||
480 | ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name ) | 487 | ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name ) |
481 | : QWidget( parent, name ) | 488 | : QWidget( parent, name ) |
482 | { | 489 | { |
483 | setFixedWidth( AppLnk::smallIconSize()); | 490 | setFixedWidth( AppLnk::smallIconSize()); |
484 | 491 | ||
485 | QImage img = (const char **)snapshot_xpm; | 492 | QImage img = (const char **)snapshot_xpm; |
486 | img = img.smoothScale(AppLnk::smallIconSize(), AppLnk::smallIconSize()); | 493 | img = img.smoothScale(AppLnk::smallIconSize(), AppLnk::smallIconSize()); |
487 | m_icon.convertFromImage(img); | 494 | m_icon.convertFromImage(img); |
488 | } | 495 | } |
489 | 496 | ||
490 | ScreenshotApplet::~ScreenshotApplet() | 497 | ScreenshotApplet::~ScreenshotApplet() |
491 | { | 498 | { |
492 | } | 499 | } |
493 | 500 | ||
494 | void ScreenshotApplet::mousePressEvent( QMouseEvent *) | 501 | void ScreenshotApplet::mousePressEvent( QMouseEvent *) |
495 | { | 502 | { |
496 | ScreenshotControl *sc = new ScreenshotControl ( ); | 503 | ScreenshotControl *sc = new ScreenshotControl ( ); |
497 | QPoint curPos = mapToGlobal ( QPoint ( 0, 0 )); | 504 | QPoint curPos = mapToGlobal ( QPoint ( 0, 0 )); |
498 | 505 | ||
499 | // windowPosX is the windows position centered above the applets icon. | 506 | // windowPosX is the windows position centered above the applets icon. |
500 | // If the icon is near the edge of the screen, the window would leave the visible area | 507 | // If the icon is near the edge of the screen, the window would leave the visible area |
501 | // so we check the position against the screen width and correct the difference if needed | 508 | // so we check the position against the screen width and correct the difference if needed |
502 | 509 | ||
503 | int screenWidth = qApp->desktop()->width(); | 510 | int screenWidth = qApp->desktop()->width(); |
504 | int windowPosX = curPos. x ( ) - ( sc-> sizeHint ( ). width ( ) - width ( )) / 2 ; | 511 | int windowPosX = curPos. x ( ) - ( sc-> sizeHint ( ). width ( ) - width ( )) / 2 ; |
505 | int ZwindowPosX, XwindowPosX; | 512 | int ZwindowPosX, XwindowPosX; |
506 | 513 | ||
507 | // the window would be placed beyond the screen wich doesn't look tooo good | 514 | // the window would be placed beyond the screen wich doesn't look tooo good |
508 | if ( (windowPosX + sc-> sizeHint ( ). width ( )) > screenWidth ) { | 515 | if ( (windowPosX + sc-> sizeHint ( ). width ( )) > screenWidth ) { |
509 | XwindowPosX = windowPosX + sc-> sizeHint ( ). width ( ) - screenWidth; | 516 | XwindowPosX = windowPosX + sc-> sizeHint ( ). width ( ) - screenWidth; |
510 | ZwindowPosX = windowPosX - XwindowPosX - 1; | 517 | ZwindowPosX = windowPosX - XwindowPosX - 1; |
511 | } else { | 518 | } else { |
512 | ZwindowPosX = windowPosX; | 519 | ZwindowPosX = windowPosX; |
513 | } | 520 | } |
514 | 521 | ||
515 | sc-> move ( ZwindowPosX, curPos. y ( ) - sc-> sizeHint ( ). height ( ) ); | 522 | sc-> move ( ZwindowPosX, curPos. y ( ) - sc-> sizeHint ( ). height ( ) ); |
516 | sc-> show ( ); | 523 | sc-> show ( ); |
517 | } | 524 | } |
518 | 525 | ||
519 | void ScreenshotApplet::paintEvent( QPaintEvent* ) | 526 | void ScreenshotApplet::paintEvent( QPaintEvent* ) |
520 | { | 527 | { |
521 | QPainter p ( this ); | 528 | QPainter p ( this ); |
522 | p.drawPixmap( 0,0, m_icon ); | 529 | p.drawPixmap( 0,0, m_icon ); |
523 | } | 530 | } |
524 | 531 | ||