24#include "KPrMSPresentationSetup.h"
27#include "KPrDocument.h"
32#include <tdeio/netaccess.h>
33#include <tdetempfile.h>
37#include <tqfileinfo.h>
43#include <tqpushbutton.h>
45#include <tqwhatsthis.h>
47#include <tdeapplication.h>
48#include <kbuttonbox.h>
49#include <kcolorbutton.h>
51#include <tdeglobalsettings.h>
54#include <tdemessagebox.h>
56#include <kstandarddirs.h>
57#include <kurlrequester.h>
58#include <kstdguiitem.h>
59#include <kpushbutton.h>
61KPrMSPresentation::KPrMSPresentation( KPrDocument *_doc, KPrView *_view )
68KPrMSPresentation::KPrMSPresentation(
const KPrMSPresentation &msPres )
69 : title( msPres.title ),
70 slideInfos( msPres.slideInfos ), backColour( msPres.backColour ),
71 textColour( msPres.textColour ), path( msPres.path )
77void KPrMSPresentation::initCreation( KProgress *progressBar )
85 KURL str( path +
"/DCIM" );
86 TDEIO::NetAccess::mkdir( str,( TQWidget* )0L );
88 p = progressBar->progress();
89 progressBar->setProgress( ++p );
90 kapp->processEvents();
92 for (
int dirNum = 101; dirNum < 999; dirNum++) {
93 slidePath = TQString(
"/DCIM/%1MSPJP").arg(dirNum);
94 if (! TDEIO::NetAccess::exists(( path + slidePath),
true, ( TQWidget* )0L) )
98 p = progressBar->progress();
99 progressBar->setProgress( ++p );
100 kapp->processEvents();
102 str = ( path + slidePath );
103 TDEIO::NetAccess::mkdir( str,( TQWidget* )0L );
104 p = progressBar->progress();
105 progressBar->setProgress( ++p );
106 kapp->processEvents();
109 str = ( path +
"/MSSONY" );
110 TDEIO::NetAccess::mkdir( str,( TQWidget* )0L );
112 p = progressBar->progress();
113 progressBar->setProgress( ++p );
114 kapp->processEvents();
115 str = ( path +
"/MSSONY/PJ" );
116 TDEIO::NetAccess::mkdir( str,( TQWidget* )0L );
119 p = progressBar->progress();
120 progressBar->setProgress( ++p );
121 kapp->processEvents();
124 TQPixmap titleSlide( 1024, 768 );
125 titleSlide.fill( backColour );
126 TQPainter painter( &titleSlide );
130 TQString filename = path + slidePath +
"/SPJT0002.JPG";
131 titleSlide.save( tmp.name(),
"JPEG" );
132 TDEIO::NetAccess::file_move( tmp.name(), filename, -1,
true );
134 p = progressBar->progress();
135 progressBar->setProgress( ++p );
136 kapp->processEvents();
139 TQFont textFont(
"SansSerif", 96 );
140 painter.setFont( textFont );
141 painter.setPen( textColour );
142 painter.drawText( titleSlide.rect(), TQt::AlignCenter | TQt::WordBreak, title );
143 filename = path + slidePath +
"/SPJT0001.JPG";
146 titleSlide.save( tmp2.name(),
"JPEG" );
147 TDEIO::NetAccess::file_move( tmp2.name(), filename, -1,
true );
149 p = progressBar->progress();
150 progressBar->setProgress( ++p );
151 kapp->processEvents();
155void KPrMSPresentation::createSlidesPictures( KProgress *progressBar )
157 if ( slideInfos.isEmpty() )
161 for (
unsigned int i = 0; i < slideInfos.count(); i++ ) {
162 int pgNum = slideInfos[i].pageNumber;
163 filename.sprintf(
"/SPJP%04i.JPG", i+3);
167 view->getCanvas()->exportPage( pgNum, 1023, 767,
168 tmp.name(),
"JPEG" );
170 TDEIO::NetAccess::file_move( tmp.name(), ( path + slidePath + filename ), -1,
true );
172 p = progressBar->progress();
173 progressBar->setProgress( ++p );
174 kapp->processEvents();
178void KPrMSPresentation::createIndexFile( KProgress *progressBar )
183 TQString filenameStore = (path +
"/MSSONY/PJ/" + title +
".SPP");
185 TQDataStream sppStream( sppFile.file() );
186 sppStream.setByteOrder(TQDataStream::LittleEndian);
187 p = progressBar->progress();
188 progressBar->setProgress( ++p );
189 kapp->processEvents();
192 sppStream << (TQ_UINT32)0x00505053;
193 sppStream << (TQ_UINT32)0x00000000;
194 sppStream << (TQ_UINT32)0x30303130;
195 sppStream << (TQ_UINT32)0x00000000;
196 sppStream << (TQ_UINT32)(slideInfos.count());
200 strncpy( buff, TQString(
"%1").arg(slidePath).ascii(), 67 );
202 sppStream.writeRawBytes( buff, 68 );
203 sppStream << (TQ_UINT32)0x00000001;
204 sppStream << (TQ_UINT32)0x00000005;
205 sppStream << (TQ_UINT32)0x00000000;
206 sppStream << (TQ_UINT32)0x00000000;
207 sppStream << (TQ_UINT32)0x00000000;
208 sppStream << (TQ_UINT32)0x00000000;
209 sppStream << (TQ_UINT32)0x00000000;
210 sppStream << (TQ_UINT32)0x00000000;
211 p = progressBar->progress();
212 progressBar->setProgress( ++p );
213 kapp->processEvents();
216 strncpy( buff,
"SPJT0001.JPG", 15 );
218 sppStream.writeRawBytes( buff, 16 );
221 strncpy( buff,
"SPJT0002.JPG", 15 );
223 sppStream.writeRawBytes( buff, 16 );
227 strncpy( buff,
"MS Sans Serif", 43 );
229 sppStream.writeRawBytes( buff, 44 );
232 sppStream << (TQ_UINT32)0xffff0000;
233 sppStream << (TQ_UINT32)0xffff00ff;
234 sppStream << (TQ_UINT32)0xffff00ff;
235 sppStream << (TQ_UINT32)0x000000ff;
236 sppStream << (TQ_UINT32)0x00000002;
237 for (
int i = 0; i < (296/4); i++) {
238 sppStream << (TQ_UINT32)0x00000000;
240 p = progressBar->progress();
241 progressBar->setProgress( ++p );
242 kapp->processEvents();
246 for (
unsigned int i = 0; i < slideInfos.count(); i++ ) {
247 filename.sprintf(
"SPJP%04i.JPG", i+3);
248 strncpy( buff, filename.ascii(), 63 );
250 sppStream.writeRawBytes( buff, 64 );
251 p = progressBar->progress();
252 progressBar->setProgress( ++p );
253 kapp->processEvents();
259 for(
unsigned int i = 0; i < (16384-512-64*(slideInfos.count()))/4; i++) {
260 sppStream << (TQ_UINT32)0x00000000;
263 p = progressBar->progress();
264 progressBar->setProgress( ++p );
265 kapp->processEvents();
268 TDEIO::NetAccess::file_move( sppFile.name(), filenameStore, -1,
true );
271void KPrMSPresentation::init()
273 title = i18n(
"Slideshow");
275 for (
unsigned int i = 0; i < doc->getPageNums(); i++ )
277 if ( doc->isSlideSelected( i ) )
281 slideInfos.append( info );
284 if ( slideInfos.isEmpty() )
285 kdWarning() <<
"No slides selected!" << endl;
286 backColour = TQt::black;
287 textColour = TQt::white;
289 path = TDEGlobalSettings::documentPath();
292KPrMSPresentationSetup::KPrMSPresentationSetup( KPrDocument *_doc, KPrView *_view )
293 : TQDialog( 0,
"", false ), msPres( _doc, _view )
299 TQLabel *helptext =
new TQLabel(
this );
300 helptext->setAlignment( TQt::WordBreak | TQt::AlignTop| TQt::AlignLeft );
301 helptext->setText( i18n(
"Please enter the directory where the memory stick "
302 "presentation should be saved. Please also enter a "
303 "title for the slideshow presentation. " ) );
305 TQLabel *lable2 =
new TQLabel( i18n(
"Path:"),
this );
306 lable2->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
307 path=
new KURLRequester(
this );
308 path->setMode( KFile::Directory);
309 path->lineEdit()->setText(msPres.getPath());
310 lable2->setBuddy(path);
311 TQHBoxLayout *pathLayout =
new TQHBoxLayout;
312 pathLayout->addWidget(lable2);
313 pathLayout->addWidget(path);
315 connect( path, TQ_SIGNAL( textChanged(
const TQString&) ),
316 this, TQ_SLOT( slotChoosePath(
const TQString&) ) );
317 connect( path, TQ_SIGNAL( urlSelected(
const TQString&) ),
318 this, TQ_SLOT( slotChoosePath(
const TQString&) ) );
321 TQLabel *lable1 =
new TQLabel( i18n(
"Title:"),
this,
"lable1" );
322 lable1->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
325 title =
new KLineEdit( msPres.getTitle(),
this );
326 lable1->setBuddy( title );
327 TQHBoxLayout *titleLayout =
new TQHBoxLayout;
328 titleLayout->addWidget( lable1 );
329 titleLayout->addWidget( title );
331 TQHBox *moreBox =
new TQHBox(
this );
332 TQPushButton *showColourButton =
new TQPushButton( i18n(
"&Set Colors"), moreBox );
333 showColourButton->setToggleButton(
true );
334 connect( showColourButton, TQ_SIGNAL( toggled(
bool) ),
this, TQ_SLOT( showColourGroup(
bool) ) );
336 TQVBoxLayout *topLayout =
new TQVBoxLayout;
337 topLayout->addWidget( helptext );
338 topLayout->addSpacing( 10 );
339 topLayout->addLayout( pathLayout );
340 topLayout->addLayout( titleLayout );
341 topLayout->addWidget( moreBox );
343 colourGroup =
new TQGroupBox( 2, TQt::Vertical,
344 i18n(
"Preliminary Slides"),
345 this ,
"colourBox" );
346 TQWhatsThis::add( colourGroup,
347 i18n(
"This section allows you to set the colors for "
348 "the preliminary slides; it does not affect the "
349 "presentation in any way, and it is normal to "
350 "leave these set to the default.") );
351 TQHBox *textColourLayout =
new TQHBox( colourGroup );
352 TQLabel *lable3 =
new TQLabel( i18n(
"Text color:"), textColourLayout );
353 lable3->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
354 textColour =
new KColorButton( msPres.getTextColour(), textColourLayout );
355 lable3->setBuddy( textColour );
357 TQHBox *backgroundColourLayout =
new TQHBox( colourGroup );
358 TQLabel *lable4 =
new TQLabel( i18n(
"Background color:"), backgroundColourLayout );
359 lable4->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
360 backColour =
new KColorButton( msPres.getBackColour(), backgroundColourLayout );
361 lable4->setBuddy( backColour );
362 colourGroup->setHidden(
true );
364 TQHBox *buttonLayout =
new TQHBox(
this );
365 KPushButton *helpButton =
new KPushButton( KStdGuiItem::help(), buttonLayout );
366 TQWhatsThis::add( helpButton,
367 i18n(
"Selecting this button will take you to the KPresenter "
368 "documentation that provides more information on how "
369 "to use the Memory Stick export function. ") );
370 KPushButton *createButton =
new KPushButton( KStdGuiItem::ok(), buttonLayout );
371 TQWhatsThis::add( createButton,
372 i18n(
"Selecting this button will proceed to generating "
373 "the presentation in the special Sony format." ) );
374 KPushButton *cancelButton =
new KPushButton( KStdGuiItem::cancel(), buttonLayout );
375 TQWhatsThis::add( cancelButton,
376 i18n(
"Selecting this button will cancel out of the "
377 "generation of the presentation, and return "
378 "to the normal KPresenter view. No files will "
381 mainLayout =
new TQVBoxLayout(
this );
382 mainLayout->setMargin(11);
383 mainLayout->setSpacing(6);
384 mainLayout->addLayout(topLayout);
385 mainLayout->addSpacing( 10 );
386 mainLayout->addWidget(colourGroup);
387 mainLayout->addWidget(buttonLayout);
388 mainLayout->setResizeMode( TQLayout::Fixed );
389 mainLayout->setGeometry( TQRect( 0, 0, 300, 220 ) );
391 connect( helpButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT ( helpMe() ) );
392 connect( cancelButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( reject() ) );
393 connect( createButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( finish() ) );
396KPrMSPresentationSetup::~KPrMSPresentationSetup()
398 view->enableMSPres();
401void KPrMSPresentationSetup::createMSPresentation( KPrDocument *_doc, KPrView *_view )
403 KPrMSPresentationSetup *dlg =
new KPrMSPresentationSetup( _doc, _view );
405 dlg->setCaption( i18n(
"Create Memory Stick Slideshow" ) );
410void KPrMSPresentationSetup::showColourGroup(
bool on)
413 colourGroup->setHidden(
false );
414 mainLayout->setGeometry( TQRect(0, 0, 300, 220 ) );
416 colourGroup->setHidden(
true );
417 mainLayout->setGeometry( TQRect(0, 0, 300, 320 ) );
421void KPrMSPresentationSetup::helpMe()
423 kapp->invokeHelp(
"ms-export");
426void KPrMSPresentationSetup::finish()
428 msPres.setTitle( title->text() );
430 msPres.setBackColour( backColour->color() );
431 msPres.setTextColour( textColour->color() );
432 msPres.setPath( path->lineEdit()->text() );
440 TQString pathname = path->lineEdit()->text();
443 if ( !TDEIO::NetAccess::exists(pathname,
false,
this) ) {
444 TQString msg = i18n(
"<qt>The directory <b>%1</b> does not exist.<br>"
445 "Do you want create it?</qt>" );
446 if( KMessageBox::questionYesNo(
this, msg.arg( pathname ),
447 i18n(
"Directory Not Found" ) )
452 bool ok = TDEIO::NetAccess::mkdir( pathname,
this );
455 KMessageBox::sorry(
this,
456 i18n(
"Cannot create directory." ) );
468 TQString sppFile( pathname +
"/MSSONY/PJ/" + title->text() +
".SPP" );
469 if (TDEIO::NetAccess::exists(sppFile,
false,
this ) ) {
470 if ( KMessageBox::warningYesNo( 0,
471 i18n(
"You are about to overwrite an existing index "
473 "Do you want to proceed?" ).arg( sppFile ),
474 i18n(
"Overwrite Presentation" ) )
475 == KMessageBox::No) {
483 KPrMSPresentationCreateDialog::createMSPresentation( doc, view, msPres );
487void KPrMSPresentationSetup::slotChoosePath(
const TQString &text)
489 msPres.setPath(text);
495KPrMSPresentationCreateDialog::KPrMSPresentationCreateDialog( KPrDocument *_doc, KPrView *_view,
496 const KPrMSPresentation &_msPres )
497 : TQDialog( 0,
"", false ), msPres( _msPres )
505KPrMSPresentationCreateDialog::~KPrMSPresentationCreateDialog()
507 view->enableMSPres();
510void KPrMSPresentationCreateDialog::createMSPresentation( KPrDocument *_doc, KPrView *_view,
511 const KPrMSPresentation &_msPres )
513 KPrMSPresentationCreateDialog *dlg =
new KPrMSPresentationCreateDialog( _doc, _view, _msPres );
515 dlg->setCaption( i18n(
"Create Memory Stick Slideshow" ) );
516 dlg->resize( 400, 250 );
521void KPrMSPresentationCreateDialog::start()
523 setCursor( waitCursor );
525 createSlidesPictures();
527 setCursor( arrowCursor );
529 bDone->setEnabled(
true );
532void KPrMSPresentationCreateDialog::initCreation()
534 TQFont f = step1->font(), f2 = step1->font();
538 progressBar->setProgress( 0 );
539 progressBar->setTotalSteps( msPres.initSteps() );
541 msPres.initCreation( progressBar );
543 step1->setFont( f2 );
544 progressBar->setProgress( progressBar->totalSteps() );
547void KPrMSPresentationCreateDialog::createSlidesPictures()
549 TQFont f = step2->font(), f2 = f;
553 progressBar->setProgress( 0 );
554 if ( msPres.slidesSteps() > 0 )
556 progressBar->setTotalSteps( msPres.slidesSteps() );
557 msPres.createSlidesPictures( progressBar );
560 step2->setFont( f2 );
561 progressBar->setProgress( progressBar->totalSteps() );
564void KPrMSPresentationCreateDialog::createIndexFile()
566 TQFont f = step3->font(), f2 = f;
570 progressBar->setProgress( 0 );
571 if ( msPres.indexFileSteps() > 0 )
573 progressBar->setTotalSteps( msPres.indexFileSteps() );
574 msPres.createIndexFile( progressBar );
577 step3->setFont( f2 );
578 progressBar->setProgress( progressBar->totalSteps() );
581void KPrMSPresentationCreateDialog::setupGUI()
583 back =
new TQVBox(
this );
584 back->setMargin( KDialog::marginHint() );
588 step1 =
new TQLabel( i18n(
"Create directory structure" ), back );
589 step2 =
new TQLabel( i18n(
"Create pictures of the slides" ), back );
590 step3 =
new TQLabel( i18n(
"Create index file" ), back );
592 line =
new TQFrame( back );
593 line->setFrameStyle( TQFrame::HLine | TQFrame::Sunken );
594 line->setMaximumHeight( 20 );
596 progressBar =
new KProgress( back );
598 line =
new TQFrame( back );
599 line->setFrameStyle( TQFrame::HLine | TQFrame::Sunken );
600 line->setMaximumHeight( 20 );
602 KButtonBox *bb =
new KButtonBox( back );
604 bDone = bb->addButton( i18n(
"Done" ) );
606 bDone->setEnabled(
false );
608 connect( bDone, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( accept() ) );
611void KPrMSPresentationCreateDialog::resizeEvent( TQResizeEvent *e )
613 TQDialog::resizeEvent( e );
614 back->resize( size() );
617#include "KPrGradient.h"
618#include "KPrMSPresentationSetup.moc"