summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/screenshotapplet/screenshot.cpp127
1 files changed, 70 insertions, 57 deletions
diff --git a/core/applets/screenshotapplet/screenshot.cpp b/core/applets/screenshotapplet/screenshot.cpp
index 7e2fdf0..f024f47 100644
--- a/core/applets/screenshotapplet/screenshot.cpp
+++ b/core/applets/screenshotapplet/screenshot.cpp
@@ -307,205 +307,218 @@ void ScreenshotControl::slotGrab()
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
337void ScreenshotControl::slotScap() 337void 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
349void ScreenshotControl::savePixmap() 349void 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
401void ScreenshotControl::performGrab() 401void 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 } 411 } else {
412 else { 412 grabTimer->stop();
413 grabTimer->stop(); 413
414 414 struct sockaddr_in raddr;
415 struct sockaddr_in raddr; 415 struct hostent *rhost_info;
416 struct hostent *rhost_info; 416 int sock = -1;
417 int sock = -1; 417 bool ok = false;
418 bool ok = false; 418
419 419 if (( rhost_info = (struct hostent *) ::gethostbyname ((char *) SCAP_hostname )) != 0 ) {
420 if (( rhost_info = (struct hostent *) ::gethostbyname ((char *) SCAP_hostname )) != 0 ) { 420 ::memset ( &raddr, 0, sizeof (struct sockaddr_in));
421 ::memset ( &raddr, 0, sizeof (struct sockaddr_in)); 421 ::memcpy ( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length );
422 ::memcpy ( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length ); 422 raddr. sin_family = rhost_info-> h_addrtype;
423 raddr. sin_family = rhost_info-> h_addrtype; 423 raddr. sin_port = htons ( SCAP_port );
424 raddr. sin_port = htons ( SCAP_port ); 424
425 425 if (( sock = ::socket ( AF_INET, SOCK_STREAM, 0 )) >= 0 ) {
426 if (( sock = ::socket ( AF_INET, SOCK_STREAM, 0 )) >= 0 ) 426 if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) {
427 { 427
428 if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) { 428 QString header;
429 QString header; 429
430 430 QPixmap pix;
431 QPixmap pix = ( snapshot.width() > snapshot.height() ) ? snapshot : snapshot.xForm( QWMatrix().rotate(90) ); 431 QString displayEnv = getenv("QWS_DISPLAY");
432 QImage img = pix.convertToImage().convertDepth( 16 ); // could make that also depth independent, if hh.org/scap can handle it 432 qDebug(displayEnv);
433 433
434 header = "POST /scap/capture.cgi?%1+%2 HTTP/1.1\n" // 1: model / 2: user 434 QString SCAP_model="";
435 "Content-length: %3\n" // 3: content length 435#warning FIXME: model string should be filled with actual device model
436 "Content-Type: image/gif\n" 436 if( snapshot.width() > 320)
437 "Host: %4\n" // 4: scap host 437 SCAP_model ="Corgi";
438 "\n"; 438
439 439 if(displayEnv == "QVFb:0") {//set this if you plan on using this app in qvfb!!
440 header = header.arg( "" ).arg( ::getenv ( "USER" ) ).arg( img.numBytes() ).arg( SCAP_hostname ); 440 pix = snapshot.xForm(QWMatrix().rotate(90));
441 441 } else
442 if ( !pix.isNull() ) 442 pix = ( snapshot.width() > snapshot.height() ) ? snapshot : snapshot.xForm( QWMatrix().rotate(90) );
443 { 443
444 const char *ascii = header.latin1( ); 444 QImage img = pix.convertToImage().convertDepth( 16 ); // could make that also depth independent, if hh.org/scap can handle it
445 uint ascii_len = ::strlen( ascii ); 445
446 ::write ( sock, ascii, ascii_len ); 446 header = "POST /scap/capture.cgi?%1+%2 HTTP/1.1\n" // 1: model / 2: user
447 ::write ( sock, img.bits(), img.numBytes() ); 447 "Content-length: %3\n" // 3: content length
448 448 "Content-Type: image/png\n"
449 ok = true; 449 "Host: %4\n" // 4: scap host
450 } 450 "\n";
451 } 451
452 ::close ( sock ); 452
453 } 453 header = header.arg( SCAP_model).arg( ::getenv( "USER" ) ).arg( img.numBytes() ).arg( SCAP_hostname );
454 } 454 qDebug(header);
455 if ( ok ) 455
456 QMessageBox::information( 0, tr( "Success" ), QString( "<p>%1</p>" ).arg ( tr( "Screenshot was uploaded to %1" )).arg( SCAP_hostname )); 456 if ( !pix.isNull() ) {
457 else 457 const char *ascii = header.latin1( );
458 QMessageBox::warning( 0, tr( "Error" ), QString( "<p>%1</p>" ).arg( tr( "Connection to %1 failed." )).arg( SCAP_hostname )); 458 uint ascii_len = ::strlen( ascii );
459 } 459 ::write ( sock, ascii, ascii_len );
460 ::write ( sock, img.bits(), img.numBytes() );
461
462 ok = true;
463 }
464 }
465 ::close ( sock );
466 }
467 }
468 if ( ok )
469 QMessageBox::information( 0, tr( "Success" ), QString( "<p>%1</p>" ).arg ( tr( "Screenshot was uploaded to %1" )).arg( SCAP_hostname ));
470 else
471 QMessageBox::warning( 0, tr( "Error" ), QString( "<p>%1</p>" ).arg( tr( "Connection to %1 failed." )).arg( SCAP_hostname ));
472 }
460 473
461} 474}
462 475
463 476
464 477
465//=========================================================================== 478//===========================================================================
466 479
467ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name ) 480ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name )
468 : QWidget( parent, name ) 481 : QWidget( parent, name )
469{ 482{
470 setFixedWidth( AppLnk::smallIconSize()); 483 setFixedWidth( AppLnk::smallIconSize());
471 484
472 QImage img = (const char **)snapshot_xpm; 485 QImage img = (const char **)snapshot_xpm;
473 img = img.smoothScale(AppLnk::smallIconSize(), AppLnk::smallIconSize()); 486 img = img.smoothScale(AppLnk::smallIconSize(), AppLnk::smallIconSize());
474 m_icon.convertFromImage(img); 487 m_icon.convertFromImage(img);
475} 488}
476 489
477ScreenshotApplet::~ScreenshotApplet() 490ScreenshotApplet::~ScreenshotApplet()
478{ 491{
479} 492}
480 493
481void ScreenshotApplet::mousePressEvent( QMouseEvent *) 494void ScreenshotApplet::mousePressEvent( QMouseEvent *)
482{ 495{
483 ScreenshotControl *sc = new ScreenshotControl ( ); 496 ScreenshotControl *sc = new ScreenshotControl ( );
484 QPoint curPos = mapToGlobal ( QPoint ( 0, 0 )); 497 QPoint curPos = mapToGlobal ( QPoint ( 0, 0 ));
485 498
486 // windowPosX is the windows position centered above the applets icon. 499 // windowPosX is the windows position centered above the applets icon.
487 // If the icon is near the edge of the screen, the window would leave the visible area 500 // If the icon is near the edge of the screen, the window would leave the visible area
488 // so we check the position against the screen width and correct the difference if needed 501 // so we check the position against the screen width and correct the difference if needed
489 502
490 int screenWidth = qApp->desktop()->width(); 503 int screenWidth = qApp->desktop()->width();
491 int windowPosX = curPos. x ( ) - ( sc-> sizeHint ( ). width ( ) - width ( )) / 2 ; 504 int windowPosX = curPos. x ( ) - ( sc-> sizeHint ( ). width ( ) - width ( )) / 2 ;
492 int ZwindowPosX, XwindowPosX; 505 int ZwindowPosX, XwindowPosX;
493 506
494 // the window would be placed beyond the screen wich doesn't look tooo good 507 // the window would be placed beyond the screen wich doesn't look tooo good
495 if ( (windowPosX + sc-> sizeHint ( ). width ( )) > screenWidth ) { 508 if ( (windowPosX + sc-> sizeHint ( ). width ( )) > screenWidth ) {
496 XwindowPosX = windowPosX + sc-> sizeHint ( ). width ( ) - screenWidth; 509 XwindowPosX = windowPosX + sc-> sizeHint ( ). width ( ) - screenWidth;
497 ZwindowPosX = windowPosX - XwindowPosX - 1; 510 ZwindowPosX = windowPosX - XwindowPosX - 1;
498 } else { 511 } else {
499 ZwindowPosX = windowPosX; 512 ZwindowPosX = windowPosX;
500 } 513 }
501 514
502 sc-> move ( ZwindowPosX, curPos. y ( ) - sc-> sizeHint ( ). height ( ) ); 515 sc-> move ( ZwindowPosX, curPos. y ( ) - sc-> sizeHint ( ). height ( ) );
503 sc-> show ( ); 516 sc-> show ( );
504} 517}
505 518
506void ScreenshotApplet::paintEvent( QPaintEvent* ) 519void ScreenshotApplet::paintEvent( QPaintEvent* )
507{ 520{
508 QPainter p ( this ); 521 QPainter p ( this );
509 p.drawPixmap( 0,0, m_icon ); 522 p.drawPixmap( 0,0, m_icon );
510} 523}
511 524