00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "KPrMSPresentationSetup.h"
00026
00027 #include "KPrView.h"
00028 #include "KPrDocument.h"
00029
00030 #include "KPrCanvas.h"
00031 #include "KPrPage.h"
00032
00033 #include <kio/netaccess.h>
00034 #include <ktempfile.h>
00035
00036 #include <qdir.h>
00037 #include <qframe.h>
00038 #include <qfileinfo.h>
00039 #include <qhbox.h>
00040 #include <qlabel.h>
00041 #include <qlayout.h>
00042 #include <qpixmap.h>
00043 #include <qpainter.h>
00044 #include <qpushbutton.h>
00045 #include <qvbox.h>
00046 #include <qwhatsthis.h>
00047
00048 #include <kapplication.h>
00049 #include <kbuttonbox.h>
00050 #include <kcolorbutton.h>
00051 #include <kglobal.h>
00052 #include <kglobalsettings.h>
00053 #include <klineedit.h>
00054 #include <klocale.h>
00055 #include <kmessagebox.h>
00056 #include <kprogress.h>
00057 #include <kstandarddirs.h>
00058 #include <kurlrequester.h>
00059 #include <kstdguiitem.h>
00060 #include <kpushbutton.h>
00061
00062 KPrMSPresentation::KPrMSPresentation( KPrDocument *_doc, KPrView *_view )
00063 {
00064 doc = _doc;
00065 view = _view;
00066 init();
00067 }
00068
00069 KPrMSPresentation::KPrMSPresentation( const KPrMSPresentation &msPres )
00070 : title( msPres.title ),
00071 slideInfos( msPres.slideInfos ), backColour( msPres.backColour ),
00072 textColour( msPres.textColour ), path( msPres.path )
00073 {
00074 doc = msPres.doc;
00075 view = msPres.view;
00076 }
00077
00078 void KPrMSPresentation::initCreation( KProgress *progressBar )
00079 {
00080 int p;
00081
00082
00083
00084
00085
00086 KURL str( path + "/DCIM" );
00087 KIO::NetAccess::mkdir( str,( QWidget* )0L );
00088
00089 p = progressBar->progress();
00090 progressBar->setProgress( ++p );
00091 kapp->processEvents();
00092
00093 for (int dirNum = 101; dirNum < 999; dirNum++) {
00094 slidePath = QString("/DCIM/%1MSPJP").arg(dirNum);
00095 if (! KIO::NetAccess::exists(( path + slidePath), true, ( QWidget* )0L) )
00096 break;
00097 }
00098
00099 p = progressBar->progress();
00100 progressBar->setProgress( ++p );
00101 kapp->processEvents();
00102
00103 str = ( path + slidePath );
00104 KIO::NetAccess::mkdir( str,( QWidget* )0L );
00105 p = progressBar->progress();
00106 progressBar->setProgress( ++p );
00107 kapp->processEvents();
00108
00109
00110 str = ( path + "/MSSONY" );
00111 KIO::NetAccess::mkdir( str,( QWidget* )0L );
00112
00113 p = progressBar->progress();
00114 progressBar->setProgress( ++p );
00115 kapp->processEvents();
00116 str = ( path + "/MSSONY/PJ" );
00117 KIO::NetAccess::mkdir( str,( QWidget* )0L );
00118
00119
00120 p = progressBar->progress();
00121 progressBar->setProgress( ++p );
00122 kapp->processEvents();
00123
00124
00125 QPixmap titleSlide( 1024, 768 );
00126 titleSlide.fill( backColour );
00127 QPainter painter( &titleSlide );
00128
00129
00130 KTempFile tmp;
00131 QString filename = path + slidePath + "/SPJT0002.JPG";
00132 titleSlide.save( tmp.name(), "JPEG" );
00133 KIO::NetAccess::file_move( tmp.name(), filename, -1, true );
00134
00135 p = progressBar->progress();
00136 progressBar->setProgress( ++p );
00137 kapp->processEvents();
00138
00139
00140 QFont textFont( "SansSerif", 96 );
00141 painter.setFont( textFont );
00142 painter.setPen( textColour );
00143 painter.drawText( titleSlide.rect(), Qt::AlignCenter | Qt::WordBreak, title );
00144 filename = path + slidePath + "/SPJT0001.JPG";
00145
00146 KTempFile tmp2;
00147 titleSlide.save( tmp2.name(), "JPEG" );
00148 KIO::NetAccess::file_move( tmp2.name(), filename, -1, true );
00149
00150 p = progressBar->progress();
00151 progressBar->setProgress( ++p );
00152 kapp->processEvents();
00153
00154 }
00155
00156 void KPrMSPresentation::createSlidesPictures( KProgress *progressBar )
00157 {
00158 if ( slideInfos.isEmpty() )
00159 return;
00160 QString filename;
00161 int p;
00162 for ( unsigned int i = 0; i < slideInfos.count(); i++ ) {
00163 int pgNum = slideInfos[i].pageNumber;
00164 filename.sprintf("/SPJP%04i.JPG", i+3);
00165
00166 KTempFile tmp;
00167
00168 view->getCanvas()->exportPage( pgNum, 1023, 767,
00169 tmp.name(), "JPEG" );
00170
00171 KIO::NetAccess::file_move( tmp.name(), ( path + slidePath + filename ), -1, true );
00172
00173 p = progressBar->progress();
00174 progressBar->setProgress( ++p );
00175 kapp->processEvents();
00176 }
00177 }
00178
00179 void KPrMSPresentation::createIndexFile( KProgress *progressBar )
00180 {
00181 int p;
00182 KTempFile sppFile;
00183
00184 QString filenameStore = (path + "/MSSONY/PJ/" + title + ".SPP");
00185
00186 QDataStream sppStream( sppFile.file() );
00187 sppStream.setByteOrder(QDataStream::LittleEndian);
00188 p = progressBar->progress();
00189 progressBar->setProgress( ++p );
00190 kapp->processEvents();
00191
00192
00193 sppStream << (Q_UINT32)0x00505053;
00194 sppStream << (Q_UINT32)0x00000000;
00195 sppStream << (Q_UINT32)0x30303130;
00196 sppStream << (Q_UINT32)0x00000000;
00197 sppStream << (Q_UINT32)(slideInfos.count());
00198
00199
00200 char buff[68];
00201 strncpy( buff, QString("%1").arg(slidePath).ascii(), 67 );
00202 buff[67] = 0x00;
00203 sppStream.writeRawBytes( buff, 68 );
00204 sppStream << (Q_UINT32)0x00000001;
00205 sppStream << (Q_UINT32)0x00000005;
00206 sppStream << (Q_UINT32)0x00000000;
00207 sppStream << (Q_UINT32)0x00000000;
00208 sppStream << (Q_UINT32)0x00000000;
00209 sppStream << (Q_UINT32)0x00000000;
00210 sppStream << (Q_UINT32)0x00000000;
00211 sppStream << (Q_UINT32)0x00000000;
00212 p = progressBar->progress();
00213 progressBar->setProgress( ++p );
00214 kapp->processEvents();
00215
00216
00217 strncpy( buff, "SPJT0001.JPG", 15 );
00218 buff[15] = 0x00;
00219 sppStream.writeRawBytes( buff, 16 );
00220
00221
00222 strncpy( buff, "SPJT0002.JPG", 15 );
00223 buff[15] = 0x00;
00224 sppStream.writeRawBytes( buff, 16 );
00225
00226
00227
00228 strncpy( buff, "MS Sans Serif", 43 );
00229 buff[44] = 0x00;
00230 sppStream.writeRawBytes( buff, 44 );
00231
00232
00233 sppStream << (Q_UINT32)0xffff0000;
00234 sppStream << (Q_UINT32)0xffff00ff;
00235 sppStream << (Q_UINT32)0xffff00ff;
00236 sppStream << (Q_UINT32)0x000000ff;
00237 sppStream << (Q_UINT32)0x00000002;
00238 for (int i = 0; i < (296/4); i++) {
00239 sppStream << (Q_UINT32)0x00000000;
00240 }
00241 p = progressBar->progress();
00242 progressBar->setProgress( ++p );
00243 kapp->processEvents();
00244
00245
00246 QString filename;
00247 for ( unsigned int i = 0; i < slideInfos.count(); i++ ) {
00248 filename.sprintf("SPJP%04i.JPG", i+3);
00249 strncpy( buff, filename.ascii(), 63 );
00250 buff[64] = 0x00;
00251 sppStream.writeRawBytes( buff, 64 );
00252 p = progressBar->progress();
00253 progressBar->setProgress( ++p );
00254 kapp->processEvents();
00255 }
00256
00257
00258
00259
00260 for(unsigned int i = 0; i < (16384-512-64*(slideInfos.count()))/4; i++) {
00261 sppStream << (Q_UINT32)0x00000000;
00262 }
00263
00264 p = progressBar->progress();
00265 progressBar->setProgress( ++p );
00266 kapp->processEvents();
00267
00268 sppFile.close();
00269 KIO::NetAccess::file_move( sppFile.name(), filenameStore, -1, true );
00270 }
00271
00272 void KPrMSPresentation::init()
00273 {
00274 title = i18n("Slideshow");
00275
00276 for ( unsigned int i = 0; i < doc->getPageNums(); i++ )
00277 {
00278 if ( doc->isSlideSelected( i ) )
00279 {
00280 SlideInfo info;
00281 info.pageNumber = i;
00282 slideInfos.append( info );
00283 }
00284 }
00285 if ( slideInfos.isEmpty() )
00286 kdWarning() << "No slides selected!" << endl;
00287 backColour = Qt::black;
00288 textColour = Qt::white;
00289
00290 path = KGlobalSettings::documentPath();
00291 }
00292
00293 KPrMSPresentationSetup::KPrMSPresentationSetup( KPrDocument *_doc, KPrView *_view )
00294 : QDialog( 0, "", false ), msPres( _doc, _view )
00295 {
00296 doc = _doc;
00297 view = _view;
00298
00299
00300 QLabel *helptext = new QLabel( this );
00301 helptext->setAlignment( Qt::WordBreak | Qt::AlignTop| Qt::AlignLeft );
00302 helptext->setText( i18n( "Please enter the directory where the memory stick "
00303 "presentation should be saved. Please also enter a "
00304 "title for the slideshow presentation. " ) );
00305
00306 QLabel *lable2 = new QLabel( i18n("Path:"), this );
00307 lable2->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00308 path=new KURLRequester( this );
00309 path->setMode( KFile::Directory);
00310 path->lineEdit()->setText(msPres.getPath());
00311 lable2->setBuddy(path);
00312 QHBoxLayout *pathLayout = new QHBoxLayout;
00313 pathLayout->addWidget(lable2);
00314 pathLayout->addWidget(path);
00315
00316 connect( path, SIGNAL( textChanged(const QString&) ),
00317 this, SLOT( slotChoosePath(const QString&) ) );
00318 connect( path, SIGNAL( urlSelected( const QString&) ),
00319 this, SLOT( slotChoosePath(const QString&) ) );
00320
00321
00322 QLabel *lable1 = new QLabel( i18n("Title:"), this, "lable1" );
00323 lable1->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00324
00325
00326 title = new KLineEdit( msPres.getTitle(), this );
00327 lable1->setBuddy( title );
00328 QHBoxLayout *titleLayout = new QHBoxLayout;
00329 titleLayout->addWidget( lable1 );
00330 titleLayout->addWidget( title );
00331
00332 QHBox *moreBox = new QHBox( this );
00333 QPushButton *showColourButton = new QPushButton( i18n("&Set Colors"), moreBox );
00334 showColourButton->setToggleButton( true );
00335 connect( showColourButton, SIGNAL( toggled(bool) ), this, SLOT( showColourGroup(bool) ) );
00336
00337 QVBoxLayout *topLayout = new QVBoxLayout;
00338 topLayout->addWidget( helptext );
00339 topLayout->addSpacing( 10 );
00340 topLayout->addLayout( pathLayout );
00341 topLayout->addLayout( titleLayout );
00342 topLayout->addWidget( moreBox );
00343
00344 colourGroup = new QGroupBox( 2, Qt::Vertical,
00345 i18n("Preliminary Slides"),
00346 this , "colourBox" );
00347 QWhatsThis::add( colourGroup,
00348 i18n( "This section allows you to set the colors for "
00349 "the preliminary slides; it does not affect the "
00350 "presentation in any way, and it is normal to "
00351 "leave these set to the default.") );
00352 QHBox *textColourLayout = new QHBox( colourGroup );
00353 QLabel *lable3 = new QLabel( i18n("Text color:"), textColourLayout );
00354 lable3->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00355 textColour = new KColorButton( msPres.getTextColour(), textColourLayout );
00356 lable3->setBuddy( textColour );
00357
00358 QHBox *backgroundColourLayout = new QHBox( colourGroup );
00359 QLabel *lable4 = new QLabel( i18n("Background color:"), backgroundColourLayout );
00360 lable4->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00361 backColour = new KColorButton( msPres.getBackColour(), backgroundColourLayout );
00362 lable4->setBuddy( backColour );
00363 colourGroup->setHidden( true );
00364
00365 QHBox *buttonLayout = new QHBox( this );
00366 KPushButton *helpButton = new KPushButton( KStdGuiItem::help(), buttonLayout );
00367 QWhatsThis::add( helpButton,
00368 i18n( "Selecting this button will take you to the KPresenter "
00369 "documentation that provides more information on how "
00370 "to use the Memory Stick export function. ") );
00371 KPushButton *createButton = new KPushButton( KStdGuiItem::ok(), buttonLayout );
00372 QWhatsThis::add( createButton,
00373 i18n( "Selecting this button will proceed to generating "
00374 "the presentation in the special Sony format." ) );
00375 KPushButton *cancelButton = new KPushButton( KStdGuiItem::cancel(), buttonLayout );
00376 QWhatsThis::add( cancelButton,
00377 i18n( "Selecting this button will cancel out of the "
00378 "generation of the presentation, and return "
00379 "to the normal KPresenter view. No files will "
00380 "be affected." ) );
00381
00382 mainLayout = new QVBoxLayout( this );
00383 mainLayout->setMargin(11);
00384 mainLayout->setSpacing(6);
00385 mainLayout->addLayout(topLayout);
00386 mainLayout->addSpacing( 10 );
00387 mainLayout->addWidget(colourGroup);
00388 mainLayout->addWidget(buttonLayout);
00389 mainLayout->setResizeMode( QLayout::Fixed );
00390 mainLayout->setGeometry( QRect( 0, 0, 300, 220 ) );
00391
00392 connect( helpButton, SIGNAL( clicked() ), this, SLOT ( helpMe() ) );
00393 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00394 connect( createButton, SIGNAL( clicked() ), this, SLOT( finish() ) );
00395 }
00396
00397 KPrMSPresentationSetup::~KPrMSPresentationSetup()
00398 {
00399 view->enableMSPres();
00400 }
00401
00402 void KPrMSPresentationSetup::createMSPresentation( KPrDocument *_doc, KPrView *_view )
00403 {
00404 KPrMSPresentationSetup *dlg = new KPrMSPresentationSetup( _doc, _view );
00405
00406 dlg->setCaption( i18n( "Create Memory Stick Slideshow" ) );
00407 dlg->exec();
00408 delete dlg;
00409 }
00410
00411 void KPrMSPresentationSetup::showColourGroup(bool on)
00412 {
00413 if (on) {
00414 colourGroup->setHidden( false );
00415 mainLayout->setGeometry( QRect(0, 0, 300, 220 ) );
00416 } else {
00417 colourGroup->setHidden( true );
00418 mainLayout->setGeometry( QRect(0, 0, 300, 320 ) );
00419 }
00420 }
00421
00422 void KPrMSPresentationSetup::helpMe()
00423 {
00424 kapp->invokeHelp("ms-export");
00425 }
00426
00427 void KPrMSPresentationSetup::finish()
00428 {
00429 msPres.setTitle( title->text() );
00430
00431 msPres.setBackColour( backColour->color() );
00432 msPres.setTextColour( textColour->color() );
00433 msPres.setPath( path->lineEdit()->text() );
00434
00435
00436
00437
00438
00439
00440
00441 QString pathname = path->lineEdit()->text();
00442
00443
00444 if ( !KIO::NetAccess::exists(pathname, false, this) ) {
00445 QString msg = i18n( "<qt>The directory <b>%1</b> does not exist.<br>"
00446 "Do you want create it?</qt>" );
00447 if( KMessageBox::questionYesNo( this, msg.arg( pathname ),
00448 i18n( "Directory Not Found" ) )
00449 == KMessageBox::Yes)
00450 {
00451
00452 QDir dir;
00453 bool ok = KIO::NetAccess::mkdir( pathname,this );
00454 if( !ok ) {
00455
00456 KMessageBox::sorry( this,
00457 i18n( "Cannot create directory." ) );
00458 path->setFocus();
00459 return;
00460 }
00461 }
00462 else {
00463
00464 path->setFocus();
00465 return;
00466 }
00467 }
00468
00469 QString sppFile( pathname + "/MSSONY/PJ/" + title->text() + ".SPP" );
00470 if (KIO::NetAccess::exists(sppFile, false, this ) ) {
00471 if ( KMessageBox::warningYesNo( 0,
00472 i18n( "You are about to overwrite an existing index "
00473 "file : %1.\n "
00474 "Do you want to proceed?" ).arg( sppFile ),
00475 i18n( "Overwrite Presentation" ) )
00476 == KMessageBox::No) {
00477 path->setFocus();
00478 return;
00479 }
00480 }
00481
00482 close();
00483
00484 KPrMSPresentationCreateDialog::createMSPresentation( doc, view, msPres );
00485
00486 }
00487
00488 void KPrMSPresentationSetup::slotChoosePath(const QString &text)
00489 {
00490 msPres.setPath(text);
00491 }
00492
00493
00494
00495
00496 KPrMSPresentationCreateDialog::KPrMSPresentationCreateDialog( KPrDocument *_doc, KPrView *_view,
00497 const KPrMSPresentation &_msPres )
00498 : QDialog( 0, "", false ), msPres( _msPres )
00499 {
00500 doc = _doc;
00501 view = _view;
00502
00503 setupGUI();
00504 }
00505
00506 KPrMSPresentationCreateDialog::~KPrMSPresentationCreateDialog()
00507 {
00508 view->enableMSPres();
00509 }
00510
00511 void KPrMSPresentationCreateDialog::createMSPresentation( KPrDocument *_doc, KPrView *_view,
00512 const KPrMSPresentation &_msPres )
00513 {
00514 KPrMSPresentationCreateDialog *dlg = new KPrMSPresentationCreateDialog( _doc, _view, _msPres );
00515
00516 dlg->setCaption( i18n( "Create Memory Stick Slideshow" ) );
00517 dlg->resize( 400, 250 );
00518 dlg->show();
00519 dlg->start();
00520 }
00521
00522 void KPrMSPresentationCreateDialog::start()
00523 {
00524 setCursor( waitCursor );
00525 initCreation();
00526 createSlidesPictures();
00527 createIndexFile();
00528 setCursor( arrowCursor );
00529
00530 bDone->setEnabled( true );
00531 }
00532
00533 void KPrMSPresentationCreateDialog::initCreation()
00534 {
00535 QFont f = step1->font(), f2 = step1->font();
00536 f.setBold( true );
00537 step1->setFont( f );
00538
00539 progressBar->setProgress( 0 );
00540 progressBar->setTotalSteps( msPres.initSteps() );
00541
00542 msPres.initCreation( progressBar );
00543
00544 step1->setFont( f2 );
00545 progressBar->setProgress( progressBar->totalSteps() );
00546 }
00547
00548 void KPrMSPresentationCreateDialog::createSlidesPictures()
00549 {
00550 QFont f = step2->font(), f2 = f;
00551 f.setBold( true );
00552 step2->setFont( f );
00553
00554 progressBar->setProgress( 0 );
00555 if ( msPres.slidesSteps() > 0 )
00556 {
00557 progressBar->setTotalSteps( msPres.slidesSteps() );
00558 msPres.createSlidesPictures( progressBar );
00559 }
00560
00561 step2->setFont( f2 );
00562 progressBar->setProgress( progressBar->totalSteps() );
00563 }
00564
00565 void KPrMSPresentationCreateDialog::createIndexFile()
00566 {
00567 QFont f = step3->font(), f2 = f;
00568 f.setBold( true );
00569 step3->setFont( f );
00570
00571 progressBar->setProgress( 0 );
00572 if ( msPres.indexFileSteps() > 0 )
00573 {
00574 progressBar->setTotalSteps( msPres.indexFileSteps() );
00575 msPres.createIndexFile( progressBar );
00576 }
00577
00578 step3->setFont( f2 );
00579 progressBar->setProgress( progressBar->totalSteps() );
00580 }
00581
00582 void KPrMSPresentationCreateDialog::setupGUI()
00583 {
00584 back = new QVBox( this );
00585 back->setMargin( KDialog::marginHint() );
00586
00587 QFrame *line;
00588
00589 step1 = new QLabel( i18n( "Create directory structure" ), back );
00590 step2 = new QLabel( i18n( "Create pictures of the slides" ), back );
00591 step3 = new QLabel( i18n( "Create index file" ), back );
00592
00593 line = new QFrame( back );
00594 line->setFrameStyle( QFrame::HLine | QFrame::Sunken );
00595 line->setMaximumHeight( 20 );
00596
00597 progressBar = new KProgress( back );
00598
00599 line = new QFrame( back );
00600 line->setFrameStyle( QFrame::HLine | QFrame::Sunken );
00601 line->setMaximumHeight( 20 );
00602
00603 KButtonBox *bb = new KButtonBox( back );
00604 bb->addStretch();
00605 bDone = bb->addButton( i18n( "Done" ) );
00606
00607 bDone->setEnabled( false );
00608
00609 connect( bDone, SIGNAL( clicked() ), this, SLOT( accept() ) );
00610 }
00611
00612 void KPrMSPresentationCreateDialog::resizeEvent( QResizeEvent *e )
00613 {
00614 QDialog::resizeEvent( e );
00615 back->resize( size() );
00616 }
00617
00618 #include "KPrGradient.h"
00619 #include "KPrMSPresentationSetup.moc"