kpresenter

KPrWebPresentation.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright 2001, 2002 Nicolas GOUTTE <goutte@kde.org>
4 Copyright 2002 Ariya Hidayat <ariya@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include "KPrWebPresentation.h"
23
24#include "KPrView.h"
25#include "KPrDocument.h"
26#include "KPrCanvas.h"
27#include "KPrPage.h"
28
29#include <kstandarddirs.h>
30#include <unistd.h>
31#include <sys/types.h>
32#include <tdetempfile.h>
33
34#include <tqfile.h>
35#include <tqtextstream.h>
36#include <tqvbox.h>
37#include <tqhbox.h>
38#include <tqlabel.h>
39#include <tqpushbutton.h>
40#include <tqfileinfo.h>
41#include <tqframe.h>
42#include <tqfont.h>
43#include <tqpixmap.h>
44#include <tqdatetime.h>
45#include <tqdir.h>
46#include <tqheader.h>
47#include <tqwmatrix.h>
48#include <tqtextcodec.h>
49#include <tqregexp.h>
50#include <tqimage.h>
51#include <tqlayout.h>
52#include <tqwhatsthis.h>
53#include <tqcheckbox.h>
54
55#include <kdebug.h>
56#include <tdelocale.h>
57#include <kcolorbutton.h>
58#include <tdefiledialog.h>
59#include <tdemessagebox.h>
60#include <kbuttonbox.h>
61#include <ksimpleconfig.h>
62#include <tdeapplication.h>
63#include <kprogress.h>
64#include <tdeglobal.h>
65#include <tdeglobalsettings.h>
66#include <kcharsets.h>
67#include <kurlrequester.h>
68#include <klineedit.h>
69#include <tdelistview.h>
70#include <knuminput.h>
71#include <kcombobox.h>
72#include <kurl.h>
73#include <tdeio/netaccess.h>
74#include <kdialog.h>
75
76#include "KoDocumentInfo.h"
77
78
79// Comes from koffice/filters/libexport/KWEFUtils.cpp
80static TQString EscapeSgmlText(const TQTextCodec* codec, const TQString& strIn,
81 const bool quot = false , const bool apos = false )
82{
83 TQString strReturn;
84 TQChar ch;
85
86 for (uint i=0; i<strIn.length(); i++)
87 {
88 ch=strIn[i];
89 switch (ch.unicode())
90 {
91 case 38: // &
92 {
93 strReturn+="&amp;";
94 break;
95 }
96 case 60: // <
97 {
98 strReturn+="&lt;";
99 break;
100 }
101 case 62: // >
102 {
103 strReturn+="&gt;";
104 break;
105 }
106 case 34: // "
107 {
108 if (quot)
109 strReturn+="&quot;";
110 else
111 strReturn+=ch;
112 break;
113 }
114 case 39: // '
115 {
116 // NOTE: HTML does not define &apos; by default (only XML/XHTML does)
117 if (apos)
118 strReturn+="&apos;";
119 else
120 strReturn+=ch;
121 break;
122 }
123 default:
124 {
125 // verify that the character ch can be expressed in the
126 // encoding in which we will write the HTML file.
127 if (codec)
128 {
129 if (!codec->canEncode(ch))
130 {
131 strReturn+=TQString("&#%1;").arg(ch.unicode());
132 break;
133 }
134 }
135 strReturn+=ch;
136 break;
137 }
138 }
139 }
140
141 return strReturn;
142}
143
144// Escape only if the encoding do not support the character
145// Special SGML characters like < > & are supposed to be already escaped.
146static TQString EscapeEncodingOnly(const TQTextCodec* codec, const TQString& strIn)
147{
148 TQString strReturn;
149 TQChar ch;
150
151 for (uint i=0; i<strIn.length(); i++)
152 {
153 ch=strIn[i];
154 if (codec)
155 {
156 if (!codec->canEncode(ch))
157 {
158 strReturn+=TQString("&#%1;").arg(ch.unicode());
159 continue;
160 }
161 }
162 strReturn+=ch;
163 }
164 return strReturn;
165}
166
167KPrWebPresentation::KPrWebPresentation( KPrDocument *_doc, KPrView *_view )
168 : config( TQString() ), xml( false )
169{
170 doc = _doc;
171 view = _view;
172 init();
173}
174
175KPrWebPresentation::KPrWebPresentation( const TQString &_config, KPrDocument *_doc, KPrView *_view )
176 : config( _config ), xml( false ), m_bWriteHeader( true ), m_bWriteFooter( true ), m_bLoopSlides( false )
177{
178 doc = _doc;
179 view = _view;
180 init();
181 loadConfig();
182}
183
184KPrWebPresentation::KPrWebPresentation( const KPrWebPresentation &webPres )
185 : config( webPres.config ), author( webPres.author ), title( webPres.title ), email( webPres.email ),
186 slideInfos( webPres.slideInfos ), backColor( webPres.backColor ), titleColor( webPres.titleColor ),
187 textColor( webPres.textColor ), path( webPres.path ), xml( webPres.xml),
188 m_bWriteHeader( webPres.m_bWriteHeader ),
189 m_bWriteFooter( webPres.m_bWriteFooter ), m_bLoopSlides( webPres.m_bLoopSlides ),
190 timeBetweenSlides ( webPres.timeBetweenSlides ), zoom( webPres.zoom ), m_encoding( webPres.m_encoding )
191{
192 doc = webPres.doc;
193 view = webPres.view;
194}
195
196void KPrWebPresentation::loadConfig()
197{
198 if ( config.isEmpty() )
199 return;
200
201 KSimpleConfig cfg( config );
202 cfg.setGroup( "General" );
203
204 author = cfg.readEntry( "Author", author );
205 title = cfg.readEntry( "Title", title );
206 email = cfg.readEntry( "EMail", email );
207 unsigned int num = cfg.readNumEntry( "Slides", slideInfos.count() );
208 //kdDebug(33001) << "KPrWebPresentation::loadConfig num=" << num << endl;
209
210 if ( num <= slideInfos.count() ) {
211 for ( unsigned int i = 0; i < num; i++ )
212 {
213 TQString key = TQString::fromLatin1( "SlideTitle%1" ).arg( i );
214 if ( cfg.hasKey( key ) )
215 {
216 // We'll assume that the selected pages haven't changed... Hmm.
217 slideInfos[ i ].slideTitle = cfg.readEntry( key );
218 kdDebug(33001) << "KPrWebPresentation::loadConfig key=" << key << " data=" << slideInfos[i].slideTitle << endl;
219 } else kdDebug(33001) << " key not found " << key << endl;
220 }
221 }
222
223 backColor = cfg.readColorEntry( "BackColor", &backColor );
224 titleColor = cfg.readColorEntry( "TitleColor", &titleColor );
225 textColor = cfg.readColorEntry( "TextColor", &textColor );
226 path = cfg.readPathEntry( "Path", path );
227 xml = cfg.readBoolEntry( "XML", xml );
228 m_bWriteHeader = cfg.readBoolEntry( "WriteHeader", m_bWriteHeader );
229 m_bWriteFooter = cfg.readBoolEntry( "WriteFooter", m_bWriteFooter );
230 m_bLoopSlides = cfg.readBoolEntry( "LoopSlides", m_bLoopSlides );
231 zoom = cfg.readNumEntry( "Zoom", zoom );
232 timeBetweenSlides = cfg.readNumEntry("TimeBetweenSlides", timeBetweenSlides );
233 m_encoding = cfg.readEntry( "Encoding", m_encoding );
234}
235
236void KPrWebPresentation::saveConfig()
237{
238 KSimpleConfig cfg( config );
239 cfg.setGroup( "General" );
240
241 cfg.writeEntry( "Author", author );
242 cfg.writeEntry( "Title", title );
243 cfg.writeEntry( "EMail", email );
244 cfg.writeEntry( "Slides", slideInfos.count() );
245
246 for ( unsigned int i = 0; i < slideInfos.count(); i++ )
247 cfg.writeEntry( TQString::fromLatin1( "SlideTitle%1" ).arg( i ), slideInfos[ i ].slideTitle );
248
249 cfg.writeEntry( "BackColor", backColor );
250 cfg.writeEntry( "TitleColor", titleColor );
251 cfg.writeEntry( "TextColor", textColor );
252#if KDE_IS_VERSION(3,1,3)
253 cfg.writePathEntry( "Path", path );
254#else
255 cfg.writeEntry( "Path", path );
256#endif
257 cfg.writeEntry( "XML", xml );
258 cfg.writeEntry( "WriteHeader", m_bWriteHeader );
259 cfg.writeEntry( "WriteFooter", m_bWriteFooter );
260 cfg.writeEntry( "LoopSlides", m_bLoopSlides );
261 cfg.writeEntry( "Zoom", zoom );
262 cfg.writeEntry( "TimeBetweenSlides", timeBetweenSlides );
263 cfg.writeEntry( "Encoding", m_encoding );
264}
265
266void KPrWebPresentation::initCreation( KProgress *progressBar )
267{
268 TQString cmd;
269 int p;
270 KURL str( path + "/html" );
271 TDEIO::NetAccess::mkdir( str,( TQWidget* )0L );
272
273 p = progressBar->progress();
274 progressBar->setProgress( ++p );
275 kapp->processEvents();
276
277 str = path + "/pics";
278 TDEIO::NetAccess::mkdir( str,( TQWidget* )0L );
279
280 p = progressBar->progress();
281 progressBar->setProgress( ++p );
282 kapp->processEvents();
283
284 const char *pics[] = { "home", "first", "next", "prev", "last", 0 };
285
286 KURL srcurl, desturl;
287
288 for ( uint index = 0; pics[ index ]; index ++ )
289 {
290 TQString filename = pics[ index ];
291 filename += ".png";
292 srcurl.setPath( locate( "slideshow", filename, KPrFactory::global() ) );
293 desturl = path;
294 desturl.addPath( "/pics/" + filename );
295 TDEIO::NetAccess::file_copy( srcurl, desturl, -1, true /*overwrite*/);
296 p = progressBar->progress();
297 progressBar->setProgress( ++p );
298 kapp->processEvents();
299 }
300}
301
302void KPrWebPresentation::createSlidesPictures( KProgress *progressBar )
303{
304 if ( slideInfos.isEmpty() )
305 return;
306 TQPixmap pix( 10, 10 );
307 TQString filename;
308 int p;
309 for ( unsigned int i = 0; i < slideInfos.count(); i++ ) {
310 int pgNum = slideInfos[i].pageNumber;
311 view->getCanvas()->drawPageInPix( pix, pgNum, zoom, true /*force real variable value*/ );
312 filename = TQString( "%1/pics/slide_%2.png" ).arg( path ).arg( i + 1 );
313
314 KTempFile tmp;
315 pix.save( tmp.name(), "PNG" );
316
317 TDEIO::NetAccess::file_move( tmp.name(), filename, -1, true /*overwrite*/);
318
319 p = progressBar->progress();
320 progressBar->setProgress( ++p );
321 kapp->processEvents();
322 }
323}
324
325TQString KPrWebPresentation::escapeHtmlText( TQTextCodec *codec, const TQString& strText ) const
326{
327 // Escape quotes (needed in attributes)
328 // Do not escape apostrophs (only allowed in XHTML!)
329 return EscapeSgmlText( codec, strText, true, false );
330}
331
332void KPrWebPresentation::writeStartOfHeader(TQTextStream& streamOut, TQTextCodec *codec, const TQString& subtitle, const TQString& next)
333{
334 TQString mimeName ( codec->mimeName() );
335 if ( isXML() )
336 { //Write out the XML declaration
337 streamOut << "<?xml version=\"1.0\" encoding=\""
338 << mimeName << "\"?>\n";
339 }
340 // write <!DOCTYPE
341 streamOut << "<!DOCTYPE ";
342 if ( isXML() )
343 {
344 streamOut << "html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"";
345 streamOut << " \"DTD/xhtml1-transitional.dtd\">\n";
346 }
347 else
348 {
349 streamOut << "HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"";
350 streamOut << " \"http://www.w3.org/TR/html4/loose.dtd\">\n";
351 }
352 streamOut << "<html";
353 if ( isXML() )
354 {
355 // XHTML has an extra attribute defining its namespace (in the <html> opening tag)
356 streamOut << " xmlns=\"http://www.w3.org/1999/xhtml\"";
357 }
358 streamOut << ">\n" << "<head>\n";
359
360 // Declare what charset we are using
361 streamOut << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=";
362 streamOut << mimeName << '"' << ( isXML() ?" /":"") << ">\n" ;
363
364 // Tell who we are (with the CVS revision number) in case we have a bug in our output!
365 TQString strVersion("$Revision: 508787 $");
366 // Eliminate the dollar signs
367 // (We don't want that the version number changes if the HTML file is itself put in a CVS storage.)
368 streamOut << "<meta name=\"Generator\" content=\"KPresenter's Web Presentation "
369 << strVersion.mid(10).replace("$","")
370 << "\""<< ( isXML() ?" /":"") // X(HT)ML closes empty elements, HTML not!
371 << ">\n";
372
373 // Load the next slide after time elapsed
374 if ( (timeBetweenSlides > 0) && ( ! next.isNull() ) )
375 {
376 streamOut << "<meta http-equiv=\"refresh\" content=\""
377 << timeBetweenSlides
378 << ";url=" << next
379 << "\">\n";
380 }
381
382 streamOut << "<title>"<< escapeHtmlText( codec, title ) << " - " << escapeHtmlText( codec, subtitle ) << "</title>\n";
383
384 // ### TODO: transform documentinfo.xml into many <META> elements (at least the author!)
385}
386
387void KPrWebPresentation::createSlidesHTML( KProgress *progressBar )
388{
389 TQTextCodec *codec = TDEGlobal::charsets()->codecForName( m_encoding );
390
391 const TQString brtag ( "<br" + TQString(isXML()?" /":"") + ">" );
392
393 for ( unsigned int i = 0; i < slideInfos.count(); i++ ) {
394
395 unsigned int pgNum = i + 1; // pgquiles # elpauer . org - I think this is a bug, seems to be an overflow if we have max_unsigned_int slides
396 KTempFile tmp;
397 TQString dest= TQString( "%1/html/slide_%2.html" ).arg( path ).arg( pgNum );
398 TQString next= TQString( "slide_%2.html" ).arg( pgNum<slideInfos.count() ? pgNum+1 : (m_bLoopSlides ? 1 : pgNum ) ); // Ugly, but it works
399
400 TQFile file( tmp.name() );
401 file.open( IO_WriteOnly );
402 TQTextStream streamOut( &file );
403 streamOut.setCodec( codec );
404
405 writeStartOfHeader( streamOut, codec, slideInfos[ i ].slideTitle, next );
406
407 // ### TODO: transform documentinfo.xml into many <META> elements (at least the author!)
408
409 if ( i > 0 ) {
410 streamOut << "<link rel=\"first\" href=\"slide_1.html\"" << ( isXML() ?" /":"") << ">\n";
411 streamOut << "<link rel=\"prev\" href=\"slide_" << pgNum - 1 << ".html\"" << ( isXML() ?" /":"") << ">\n";
412 }
413 if ( i < slideInfos.count() - 1 ) {
414 streamOut << "<link rel=\"next\" href=\"slide_" << pgNum + 1 << ".html\"" << ( isXML() ?" /":"") << ">\n";
415 streamOut << "<link rel=\"last\" href=\"slide_" << slideInfos.count() << ".html\"" << ( isXML() ?" /":"") << ">\n";
416 }
417 streamOut << "<link rel=\"contents\" href=\"../index.html\"" << ( isXML() ?" /":"") << ">\n";
418
419 streamOut << "</head>\n";
420 streamOut << "<body bgcolor=\"" << backColor.name() << "\" text=\"" << textColor.name() << "\">\n";
421
422 if (m_bWriteHeader) {
423 streamOut << " <center>\n";
424
425 if ( i > 0 )
426 streamOut << " <a href=\"slide_1.html\">";
427 streamOut << "<img src=\"../pics/first.png\" border=\"0\" alt=\"" << i18n( "First" )
428 << "\" title=\"" << i18n( "First" ) << "\"" << ( isXML() ?" /":"") << ">";
429 if ( i > 0 )
430 streamOut << "</a>";
431
432 streamOut << "\n";
433
434 if ( i > 0 )
435 streamOut << " <a href=\"slide_" << pgNum - 1 << ".html\">";
436 streamOut << "<img src=\"../pics/prev.png\" border=\"0\" alt=\"" << i18n( "Previous" )
437 << "\" title=\"" << i18n( "Previous" ) << "\"" << ( isXML() ?" /":"") << ">";
438 if ( i > 0 )
439 streamOut << "</a>";
440
441 streamOut << "\n";
442
443 if ( (m_bLoopSlides) || (i < slideInfos.count() - 1 ) )
444 streamOut << " <a href=\"" << next << "\">";
445 streamOut << "<img src=\"../pics/next.png\" border=\"0\" alt=\"" << i18n( "Next" )
446 << "\" title=\"" << i18n( "Next" ) << "\"" << ( isXML() ?" /":"") << ">";
447 if ( (m_bLoopSlides) || (i < slideInfos.count() - 1 ) )
448 streamOut << "</a>";
449
450 streamOut << "\n";
451
452 if ( i < slideInfos.count() - 1 )
453 streamOut << " <a href=\"slide_" << slideInfos.count() << ".html\">";
454 streamOut << "<img src=\"../pics/last.png\" border=\"0\" alt=\"" << i18n( "Last" )
455 << "\" title=\"" << i18n( "Last" ) << "\"" << ( isXML() ?" /":"") << ">";
456 if ( i < slideInfos.count() - 1 )
457 streamOut << "</a>";
458
459 streamOut << "\n" << " &nbsp; &nbsp; &nbsp; &nbsp;\n";
460
461 streamOut << " <a href=\"../index.html\">";
462 streamOut << "<img src=\"../pics/home.png\" border=\"0\" alt=\"" << i18n( "Home" )
463 << "\" title=\"" << i18n( "Home" ) << "\"" << ( isXML() ?" /":"") << ">";
464 streamOut << "</a>\n";
465
466 streamOut << " </center>" << brtag << "<hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n"; // ### TODO: is noshade W3C?
467
468 streamOut << " <center>\n <font color=\"" << escapeHtmlText( codec, titleColor.name() ) << "\">\n";
469 streamOut << " <b>" << escapeHtmlText( codec, title ) << "</b> - <i>" << escapeHtmlText( codec, slideInfos[ i ].slideTitle ) << "</i>\n";
470
471 streamOut << " </font>\n </center>\n";
472
473 streamOut << "<hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">" << brtag << "\n";
474 }
475
476 streamOut << " <center>\n ";
477
478 if ( (m_bLoopSlides) || (i < slideInfos.count() - 1) )
479 streamOut << "<a href=\"" << next << "\">";
480
481 streamOut << "<img src=\"../pics/slide_" << pgNum << ".png\" border=\"0\" alt=\""
482 << i18n( "Slide %1" ).arg( pgNum ) << "\"" << ( isXML() ?" /":"") << ">";
483
484 if ( i < slideInfos.count() - 1 )
485 streamOut << "</a>";
486
487 streamOut << "\n";
488
489 streamOut << " </center>\n";
490
491 if (m_bWriteFooter) {
492 streamOut << brtag << "<hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n";
493
494 TQPtrList<KPrPage> _tmpList( doc->getPageList() );
495 TQString note ( escapeHtmlText( codec, _tmpList.at(i)->noteText() ) );
496 if ( !note.isEmpty() ) {
497 streamOut << " <b>" << escapeHtmlText( codec, i18n( "Note" ) ) << "</b>\n";
498 streamOut << " <blockquote>\n";
499
500 streamOut << note.replace( "\n", brtag );
501
502 streamOut << " </blockquote><hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n";
503 }
504
505 streamOut << " <center>\n";
506
507 TQString htmlAuthor;
508 if (email.isEmpty())
509 htmlAuthor=escapeHtmlText( codec, author );
510 else
511 htmlAuthor=TQString("<a href=\"mailto:%1\">%2</a>").arg( escapeHtmlText( codec, email )).arg( escapeHtmlText( codec, author ));
512 streamOut << EscapeEncodingOnly ( codec, i18n( "Created on %1 by <i>%2</i> with <a href=\"http://www.trinitydesktop.org\">KPresenter</a>" )
513 .arg( TDEGlobal::locale()->formatDate ( TQDate::currentDate() ) ).arg( htmlAuthor ) );
514
515 streamOut << " </center><hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n";
516 }
517
518 streamOut << "</body>\n</html>\n";
519
520 file.close();
521
522 TDEIO::NetAccess::file_move( tmp.name(), dest, -1, true /*overwrite*/);
523
524 int p = progressBar->progress();
525 progressBar->setProgress( ++p );
526 kapp->processEvents();
527 }
528}
529
530void KPrWebPresentation::createMainPage( KProgress *progressBar )
531{
532 TQTextCodec *codec = TDEGlobal::charsets()->codecForName( m_encoding );
533 KTempFile tmp;
534 TQString dest = TQString( "%1/index.html" ).arg( path );
535 TQFile file( tmp.name() );
536 file.open( IO_WriteOnly );
537 TQTextStream streamOut( &file );
538 streamOut.setCodec( codec );
539
540 writeStartOfHeader( streamOut, codec, i18n("Table of Contents"), TQString() );
541 streamOut << "</head>\n";
542
543 streamOut << "<body bgcolor=\"" << backColor.name() << "\" text=\"" << textColor.name() << "\">\n";
544
545 streamOut << "<h1 align=\"center\"><font color=\"" << titleColor.name()
546 << "\">" << title << "</font></h1>";
547
548 streamOut << "<p align=\"center\"><a href=\"html/slide_1.html\">";
549 streamOut << i18n("Click here to start the Slideshow");
550 streamOut << "</a></p>\n";
551
552 streamOut << "<p><b>" << i18n("Table of Contents") << "</b></p>\n";
553
554 // create list of slides (with proper link)
555 streamOut << "<ol>\n";
556 for ( unsigned int i = 0; i < slideInfos.count(); i++ )
557 streamOut << " <li><a href=\"html/slide_" << i+1 << ".html\">" << slideInfos[ i ].slideTitle << "</a></li>\n";
558 streamOut << "</ol>\n";
559
560 // footer: author name, e-mail
561 TQString htmlAuthor = email.isEmpty() ? escapeHtmlText( codec, author ) :
562 TQString("<a href=\"mailto:%1\">%2</a>").arg( escapeHtmlText( codec, email )).arg( escapeHtmlText( codec, author ));
563 streamOut << EscapeEncodingOnly ( codec, i18n( "Created on %1 by <i>%2</i> with <a href=\"http://www.trinitydesktop.org\">KPresenter</a>" )
564 .arg( TDEGlobal::locale()->formatDate ( TQDate::currentDate() ) ).arg( htmlAuthor ) );
565
566 streamOut << "</body>\n</html>\n";
567 file.close();
568
569 TDEIO::NetAccess::file_move( tmp.name(), dest, -1, true /*overwrite*/);
570
571
572 progressBar->setProgress( progressBar->totalSteps() );
573 kapp->processEvents();
574}
575
576void KPrWebPresentation::init()
577{
578
579 KoDocumentInfo * info = doc->documentInfo();
580 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
581 if ( !authorPage )
582 kdWarning() << "Author information not found in documentInfo !" << endl;
583 else
584 {
585 author = authorPage->fullName();
586 email = authorPage->email();
587 }
588
589 title = i18n("Slideshow");
590 kdDebug(33001) << "KPrWebPresentation::init : " << doc->getPageNums() << " pages." << endl;
591 for ( unsigned int i = 0; i < doc->getPageNums(); i++ )
592 {
593 if ( doc->isSlideSelected( i ) )
594 {
595 SlideInfo info;
596 info.pageNumber = i;
597 info.slideTitle = doc->pageList().at(i)->pageTitle();
598 slideInfos.append( info );
599 }
600 }
601 if ( slideInfos.isEmpty() )
602 kdWarning() << "No slides selected!" << endl;
603 backColor = TQt::white;
604 textColor = TQt::black;
605 titleColor = TQt::red;
606
607 path = TDEGlobalSettings::documentPath() + "www";
608
609 zoom = 100;
610
611 timeBetweenSlides = 0;
612
613 m_encoding = TQTextCodec::codecForLocale()->name();
614}
615
616KPrWebPresentationWizard::KPrWebPresentationWizard( const TQString &_config, KPrDocument *_doc,
617 KPrView *_view )
618 : KWizard( 0, "", false ), config( _config ), webPres( config, _doc, _view )
619{
620 doc = _doc;
621 view = _view;
622
623 setupPage1();
624 setupPage2();
625 setupPage3();
626 setupPage4();
627 setupPage5();
628
629 connect( nextButton(), TQ_SIGNAL( clicked() ), this, TQ_SLOT( pageChanged() ) );
630 connect( backButton(), TQ_SIGNAL( clicked() ), this, TQ_SLOT( pageChanged() ) );
631 connect( finishButton(), TQ_SIGNAL( clicked() ), this, TQ_SLOT( finish() ) );
632}
633
634KPrWebPresentationWizard::~KPrWebPresentationWizard()
635{
636 view->enableWebPres();
637}
638
639void KPrWebPresentationWizard::createWebPresentation( const TQString &_config, KPrDocument *_doc,
640 KPrView *_view )
641{
642 KPrWebPresentationWizard *dlg = new KPrWebPresentationWizard( _config, _doc, _view );
643
644 dlg->setCaption( i18n( "Create HTML Slideshow Wizard" ) );
645 dlg->show();
646}
647
648void KPrWebPresentationWizard::setupPage1()
649{
650 page1 = new TQHBox( this );
651 TQWhatsThis::add( page1, i18n("This page allows you to specify some of the key"
652 " values for how your presentation will be shown"
653 " in HTML. Select individual items for more help"
654 " on what they do.") );
655 page1->setSpacing( KDialog::spacingHint() );
656 page1->setMargin( KDialog::marginHint() );
657
658 TQLabel* sidebar = new TQLabel( page1 );
659 sidebar->setMinimumSize( 106, 318 );
660 sidebar->setMaximumSize( 106, 318 );
661 sidebar->setFrameShape( TQFrame::Panel );
662 sidebar->setFrameShadow( TQFrame::Sunken );
663 sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
664
665 TQWidget* canvas = new TQWidget( page1 );
666 TQGridLayout *layout = new TQGridLayout( canvas, 7, 2,
667 KDialog::marginHint(), KDialog::spacingHint() );
668
669 TQLabel *helptext = new TQLabel( canvas );
670 helptext->setAlignment( TQt::WordBreak | TQt::AlignTop| TQt::AlignLeft );
671 helptext->setText( i18n( "Enter your name, email address and "
672 "the title of the web presentation. "
673 "Also enter the output directory where the "
674 "web presentation should be saved. " ) );
675 layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
676
677 layout->addMultiCell( new TQSpacerItem( 1, 50 ), 1, 1, 0, 1 );
678
679 TQLabel *label1 = new TQLabel( i18n("Author:"), canvas );
680 label1->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
681 TQWhatsThis::add( label1, i18n("This is where you enter the name of the person or "
682 "organization that should be named as the author of "
683 "the presentation.") );
684 layout->addWidget( label1, 2, 0 );
685
686 TQLabel *label2 = new TQLabel( i18n("Title:"), canvas );
687 label2->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
688 TQWhatsThis::add( label2, i18n("This is where you enter the title of the overall "
689 "presentation." ) );
690 layout->addWidget( label2, 3, 0 );
691
692 TQLabel *label3 = new TQLabel( i18n("Email address:"), canvas );
693 label3->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
694 TQWhatsThis::add( label3, i18n("This is where you enter the email address of the "
695 "person or organization that is responsible for "
696 "the presentation.") );
697 layout->addWidget( label3, 4, 0 );
698
699 TQLabel *label4 = new TQLabel( i18n("Path:"), canvas );
700 label4->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
701 TQWhatsThis::add( label4, i18n("The value entered for the path is the directory "
702 "where the presentation will be saved. If it does "
703 "not exist, you'll be asked if you want to create "
704 "the directory or abort the creation.") );
705 layout->addWidget( label4, 5, 0 );
706
707 author = new KLineEdit( webPres.getAuthor(), canvas );
708 TQWhatsThis::add( author, i18n("This is where you enter the name of the person or "
709 "organization that should be named as the author of "
710 "the presentation.") );
711 layout->addWidget( author, 2, 1 );
712
713 title = new KLineEdit( webPres.getTitle(), canvas );
714 TQWhatsThis::add( title, i18n("This is where you enter the title of the overall "
715 "presentation." ) );
716 layout->addWidget( title, 3, 1 );
717
718 email = new KLineEdit( webPres.getEmail(), canvas );
719 TQWhatsThis::add( email, i18n("This is where you enter the email address of the "
720 "person or organization that is responsible for "
721 "the presentation.") );
722 layout->addWidget( email, 4, 1 );
723
724 path=new KURLRequester( canvas );
725 path->setMode( KFile::Directory);
726 path->lineEdit()->setText(webPres.getPath());
727 TQWhatsThis::add( path, i18n("The value entered for the path is the directory "
728 "where the presentation will be saved. If it does "
729 "not exist, you'll be asked if you want to create "
730 "the directory or abort the creation.") );
731 layout->addWidget( path, 5, 1 );
732
733 TQSpacerItem* spacer = new TQSpacerItem( 1, 10,
734 TQSizePolicy::Minimum, TQSizePolicy::Expanding );
735 layout->addMultiCell( spacer, 6, 6, 0, 1 );
736
737 connect(path, TQ_SIGNAL(textChanged(const TQString&)),
738 this,TQ_SLOT(slotChoosePath(const TQString&)));
739 connect(path, TQ_SIGNAL(urlSelected( const TQString& )),
740 this,TQ_SLOT(slotChoosePath(const TQString&)));
741
742 addPage( page1, i18n( "Step 1: General Information" ) );
743
744 setHelpEnabled(page1, false); //doesn't do anything currently
745}
746
747void KPrWebPresentationWizard::setupPage2()
748{
749 page2 = new TQHBox( this );
750 TQWhatsThis::add( page2, i18n("This page allows you to specify how the HTML "
751 "for your presentation will be displayed. Select "
752 "individual items for more help on what they do.") );
753 page2->setSpacing( KDialog::spacingHint() );
754 page2->setMargin( KDialog::marginHint() );
755
756 TQLabel* sidebar = new TQLabel( page2 );
757 sidebar->setMinimumSize( 106, 318 );
758 sidebar->setMaximumSize( 106, 318 );
759 sidebar->setFrameShape( TQFrame::Panel );
760 sidebar->setFrameShadow( TQFrame::Sunken );
761 sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
762
763 TQWidget* canvas = new TQWidget( page2 );
764 TQGridLayout *layout = new TQGridLayout( canvas, 6, 2,
765 KDialog::marginHint(), KDialog::spacingHint() );
766
767 TQLabel *helptext = new TQLabel( canvas );
768 helptext->setAlignment( TQt::WordBreak | TQt::AlignVCenter| TQt::AlignLeft );
769 TQString help = i18n("Here you can configure the style of the web pages.");
770 help += i18n( "You can also specify the zoom for the slides." );
771 helptext->setText(help);
772
773 layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
774
775 layout->addMultiCell( new TQSpacerItem( 1, 50 ), 1, 1, 0, 1 );
776
777 TQLabel *label1 = new TQLabel( i18n("Zoom:"), canvas );
778 label1->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
779 TQWhatsThis::add( label1, i18n( "This selection allows you to specify "
780 "the size of the slide image." ) );
781 layout->addWidget( label1, 2, 0 );
782
783 TQLabel *label2 = new TQLabel( i18n( "Encoding:" ), canvas );
784 label2->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
785
786 layout->addWidget( label2, 3, 0 );
787
788 TQLabel *label3 = new TQLabel( i18n( "Document type:" ), canvas );
789 label3->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
790 layout->addWidget( label3, 4, 0 );
791
792 zoom = new KIntNumInput( webPres.getZoom(), canvas );
793 TQWhatsThis::add( zoom, i18n( "This selection allows you to specify "
794 "the size of the slide image." ) );
795 layout->addWidget( zoom, 2, 1 );
796 zoom->setSuffix( " %" );
797 zoom->setRange( 25, 1000, 5 );
798
799 encoding = new KComboBox( false, canvas );
800 layout->addWidget( encoding, 3, 1 );
801
802 // Fill encoding combo
803 // Stolen from tdelibs/kate/part/katedialogs.cpp
804 TQStringList encodings(TDEGlobal::charsets()->descriptiveEncodingNames());
805 int idx = 0;
806 for (uint i = 0; i < encodings.count(); i++)
807 {
808 bool found = false;
809 TQTextCodec *codecForEnc = TDEGlobal::charsets()->codecForName(TDEGlobal::charsets()->encodingForName(encodings[i]), found);
810 if (found)
811 {
812 encoding->insertItem(encodings[i]);
813
814 if ( codecForEnc->name() == webPres.getEncoding() )
815 encoding->setCurrentItem(idx);
816 idx++;
817 }
818 }
819
820 doctype = new KComboBox( false, canvas );
821 layout->addWidget( doctype, 4, 1 );
822 doctype->insertItem( "HTML 4.01", -1 );
823 doctype->insertItem( "XHTML 1.0", -1 );
824
825 doctype->setCurrentItem( webPres.isXML() ? 1 : 0 );
826
827 TQSpacerItem* spacer = new TQSpacerItem( 1, 10,
828 TQSizePolicy::Minimum, TQSizePolicy::Expanding );
829 layout->addMultiCell( spacer, 5, 5, 0, 1 );
830
831 addPage( page2, i18n( "Step 2: Configure HTML" ) );
832
833 setHelpEnabled(page2, false); //doesn't do anything currently
834}
835
836void KPrWebPresentationWizard::setupPage3()
837{
838 page3 = new TQHBox( this );
839 TQWhatsThis::add( page3, i18n("This page allows you to specify the colors for "
840 "your presentation display. Select individual "
841 "items for more help on what they do.") );
842
843 page3->setSpacing( KDialog::spacingHint() );
844 page3->setMargin( KDialog::marginHint() );
845
846 TQLabel* sidebar = new TQLabel( page3 );
847 sidebar->setMinimumSize( 106, 318 );
848 sidebar->setMaximumSize( 106, 318 );
849 sidebar->setFrameShape( TQFrame::Panel );
850 sidebar->setFrameShadow( TQFrame::Sunken );
851 sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
852
853 TQWidget* canvas = new TQWidget( page3 );
854 TQGridLayout *layout = new TQGridLayout( canvas, 6, 2,
855 KDialog::marginHint(), KDialog::spacingHint() );
856
857 TQLabel *helptext = new TQLabel( canvas );
858 helptext->setAlignment( TQt::WordBreak | TQt::AlignVCenter| TQt::AlignLeft );
859 helptext->setText( i18n( "Now you can customize the colors of the web pages." ) );
860 layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
861
862 layout->addMultiCell( new TQSpacerItem( 1, 50 ), 1, 1, 0, 1 );
863
864 TQLabel *label1 = new TQLabel( i18n("Text color:"), canvas );
865 label1->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
866 layout->addWidget( label1, 2, 0 );
867
868 TQLabel *label2 = new TQLabel( i18n("Title color:"), canvas );
869 label2->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
870 layout->addWidget( label2, 3, 0 );
871
872 TQLabel *label3 = new TQLabel( i18n("Background color:"), canvas );
873 label3->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
874 layout->addWidget( label3, 4, 0 );
875
876 textColor = new KColorButton( webPres.getTextColor(), canvas );
877 layout->addWidget( textColor, 2, 1 );
878
879 titleColor = new KColorButton( webPres.getTitleColor(), canvas );
880 layout->addWidget( titleColor, 3, 1 );
881
882 backColor = new KColorButton( webPres.getBackColor(), canvas );
883 layout->addWidget( backColor, 4, 1 );
884
885 TQSpacerItem* spacer = new TQSpacerItem( 1, 10,
886 TQSizePolicy::Minimum, TQSizePolicy::Expanding );
887 layout->addMultiCell( spacer, 5, 5, 0, 1 );
888
889 addPage( page3, i18n( "Step 3: Customize Colors" ) );
890
891 setHelpEnabled(page3, false); //doesn't do anything currently
892}
893
894void KPrWebPresentationWizard::setupPage4()
895{
896 page4 = new TQHBox( this );
897 TQWhatsThis::add( page4, i18n("This page allows you to modify the titles of "
898 "each slide, if required. You normally do not need "
899 "to do this, but it is available if required.") );
900 page4->setSpacing( KDialog::spacingHint() );
901 page4->setMargin( KDialog::marginHint() );
902
903 TQLabel* sidebar = new TQLabel( page4 );
904 sidebar->setMinimumSize( 106, 318 );
905 sidebar->setMaximumSize( 106, 318 );
906 sidebar->setFrameShape( TQFrame::Panel );
907 sidebar->setFrameShadow( TQFrame::Sunken );
908 sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
909
910 TQWidget* canvas = new TQWidget( page4 );
911 TQGridLayout *layout = new TQGridLayout( canvas, 3, 2,
912 KDialog::marginHint(), KDialog::spacingHint() );
913
914 TQLabel *helptext = new TQLabel( canvas );
915 helptext->setAlignment( TQt::WordBreak | TQt::AlignVCenter| TQt::AlignLeft );
916 helptext->setText( i18n( "Here you can specify titles for "
917 "each slide. Click on a slide in "
918 "the list and then enter the title "
919 "in the textbox below. If you "
920 "click on a title, KPresenter "
921 "mainview will display the slide.") );
922
923 layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
924
925 TQLabel *label = new TQLabel( i18n( "Slide title:" ), canvas );
926 label->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
927 layout->addWidget( label, 1, 0 );
928
929 slideTitle = new KLineEdit( canvas );
930 layout->addWidget( slideTitle, 1, 1 );
931 connect( slideTitle, TQ_SIGNAL( textChanged( const TQString & ) ), this,
932 TQ_SLOT( slideTitleChanged( const TQString & ) ) );
933
934 slideTitles = new TDEListView( canvas );
935 layout->addMultiCellWidget( slideTitles, 2, 2, 0, 1 );
936 slideTitles->addColumn( i18n( "No." ) );
937 slideTitles->addColumn( i18n( "Slide Title" ) );
938 connect( slideTitles, TQ_SIGNAL( selectionChanged( TQListViewItem * ) ), this,
939 TQ_SLOT( slideTitleChanged( TQListViewItem * ) ) );
940 slideTitles->setSorting( -1 );
941 slideTitles->setAllColumnsShowFocus( true );
942 slideTitles->setResizeMode( TQListView::LastColumn );
943 slideTitles->header()->setMovingEnabled( false );
944
945 TQValueList<KPrWebPresentation::SlideInfo> infos = webPres.getSlideInfos();
946 for ( int i = infos.count() - 1; i >= 0; --i ) {
947 TDEListViewItem *item = new TDEListViewItem( slideTitles );
948 item->setText( 0, TQString::number( i + 1 ) );
949 //kdDebug(33001) << "KPrWebPresentationWizard::setupPage3 " << infos[ i ].slideTitle << endl;
950 item->setText( 1, infos[ i ].slideTitle );
951 }
952
953 slideTitles->setSelected( slideTitles->firstChild(), true );
954
955 addPage( page4, i18n( "Step 4: Customize Slide Titles" ) );
956
957 setHelpEnabled(page4, false); //doesn't do anything currently
958}
959
960void KPrWebPresentationWizard::setupPage5()
961{
962 page5 = new TQHBox( this );
963 TQWhatsThis::add( page5, i18n("This page allows you to specify some options for "
964 "presentations which run unattended, such as time "
965 "elapsed before advancing to the next slide, looping "
966 "and the presence of headers. If you do not want "
967 "an unattended presentation, just leave defaults unchanged.") );
968 page5->setSpacing( KDialog::spacingHint() );
969 page5->setMargin( KDialog::marginHint() );
970
971 TQLabel* sidebar = new TQLabel( page5 );
972 sidebar->setMinimumSize( 106, 318 );
973 sidebar->setMaximumSize( 106, 318 );
974 sidebar->setFrameShape( TQFrame::Panel );
975 sidebar->setFrameShadow( TQFrame::Sunken );
976 sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
977
978 TQWidget* canvas = new TQWidget( page5 );
979 TQGridLayout *layout = new TQGridLayout( canvas, 6, 2,
980 KDialog::marginHint(), KDialog::spacingHint() );
981
982 TQLabel *helptext = new TQLabel( canvas );
983 helptext->setAlignment( TQt::WordBreak | TQt::AlignVCenter| TQt::AlignLeft );
984 TQString help = i18n("Here you can configure some options for unattended "
985 "presentations, such as time elapsed before automatically advance to "
986 "the next slide, looping and the presence of headers.");
987 helptext->setText(help);
988
989 layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
990
991 layout->addMultiCell( new TQSpacerItem( 1, 50 ), 1, 1, 0, 1 );
992
993 TQLabel *label1 = new TQLabel( i18n("Advance after:"), canvas );
994 label1->setAlignment( TQt::AlignVCenter | TQt::AlignRight );
995 TQWhatsThis::add( label1, i18n( "This selection allows you to specify "
996 "the time between slides." ) );
997 layout->addWidget( label1, 2, 0 );
998
999 timeBetweenSlides = new KIntNumInput( webPres.getTimeBetweenSlides(), canvas );
1000 timeBetweenSlides->setSpecialValueText(i18n( "Disabled" ));
1001 TQWhatsThis::add( timeBetweenSlides, i18n( "This selection allows you to specify "
1002 "the time between slides." ) );
1003 layout->addWidget( timeBetweenSlides, 2, 1 );
1004 timeBetweenSlides->setSuffix( " seconds" );
1005 timeBetweenSlides->setRange( 0, 900, 1 );
1006
1007 layout->addMultiCell( new TQSpacerItem( 1, 10 ), 1, 1, 0, 1 );
1008
1009 writeHeader=new TQCheckBox( i18n("Write header to the slides"), canvas);
1010 TQWhatsThis::add( writeHeader, i18n( "This checkbox allows you to specify if you "
1011 "want to write the navigation buttons on top "
1012 "of the slide." ) );
1013 writeHeader->setChecked( webPres.wantHeader() );
1014 layout->addWidget( writeHeader, 3, 1);
1015
1016 writeFooter=new TQCheckBox( i18n("Write footer to the slides"), canvas);
1017 TQWhatsThis::add( writeFooter, i18n( "This checkbox allows you to specify if you "
1018 "want to write an imprint consisting on the author "
1019 "and the software used to create these slides." ) );
1020 writeFooter->setChecked( webPres.wantFooter() );
1021 layout->addWidget( writeFooter, 4, 1);
1022
1023 loopSlides=new TQCheckBox( i18n("Loop presentation"), canvas);
1024 TQWhatsThis::add( loopSlides, i18n( "This checkbox allows you to specify if you "
1025 "want the presentation to start again once "
1026 "the latest slide is reached." ) );
1027 loopSlides->setChecked( webPres.wantLoopSlides() );
1028 layout->addWidget( loopSlides, 5, 1);
1029
1030 TQSpacerItem* spacer = new TQSpacerItem( 1, 10,
1031 TQSizePolicy::Minimum, TQSizePolicy::Expanding );
1032 layout->addMultiCell( spacer, 5, 5, 0, 1 );
1033
1034 addPage( page5, i18n( "Step 5: Options for Unattended Presentations" ) );
1035
1036 setHelpEnabled(page5, false); //doesn't do anything currently
1037
1038 setFinish( page5, true );
1039}
1040
1041void KPrWebPresentationWizard::finish()
1042{
1043 webPres.setAuthor( author->text() );
1044 webPres.setEMail( email->text() );
1045 webPres.setTitle( title->text() );
1046
1047 TQListViewItemIterator it( slideTitles );
1048 for ( ; it.current(); ++it )
1049 webPres.setSlideTitle( it.current()->text( 0 ).toInt() - 1, it.current()->text( 1 ) );
1050
1051 webPres.setBackColor( backColor->color() );
1052 webPres.setTitleColor( titleColor->color() );
1053 webPres.setTextColor( textColor->color() );
1054 webPres.setPath( path->lineEdit()->text() );
1055 webPres.setZoom( zoom->value() );
1056 webPres.setTimeBetweenSlides( timeBetweenSlides->value() );
1057 webPres.setWriteHeader( writeHeader->isChecked() );
1058 webPres.setWriteFooter( writeFooter->isChecked() );
1059 webPres.setLoopSlides( loopSlides->isChecked() );
1060 webPres.setXML( doctype->currentItem() != 0 );
1061 bool found = false;
1062 TQTextCodec *codecForEnc = TDEGlobal::charsets()->codecForName(TDEGlobal::charsets()->encodingForName(encoding->currentText()), found);
1063 if ( found )
1064 {
1065 webPres.setEncoding( codecForEnc->name() );
1066 }
1067
1068 close();
1069 KPrWebPresentationCreateDialog::createWebPresentation( doc, view, webPres );
1070}
1071
1072void KPrWebPresentationWizard::pageChanged()
1073{
1074 if ( currentPage() != page5 )
1075 {
1076 TQString pathname = path->lineEdit()->text();
1077
1078 // path doesn't exist. ask user if it should be created.
1079 if ( !TDEIO::NetAccess::exists( pathname, true/*write*/,this ) )
1080 {
1081 TQString msg = i18n( "<qt>The directory <b>%1</b> does not exist.<br>"
1082 "Do you want create it?</qt>" );
1083 if( KMessageBox::questionYesNo( this, msg.arg( pathname ),
1084 i18n( "Directory Not Found" ) )
1085 == KMessageBox::Yes)
1086 {
1087 bool ok = TDEIO::NetAccess::mkdir( pathname, this );
1088 if( !ok )
1089 {
1090 KMessageBox::sorry( this,
1091 i18n( "Cannot create directory." ) );
1092 // go back to first step
1093 showPage( page1 );
1094 path->setFocus();
1095 }
1096
1097 }
1098 else
1099 {
1100 // go back to first step
1101 showPage( page1 );
1102 path->setFocus();
1103 }
1104 }
1105 } else
1106 finishButton()->setEnabled( true );
1107}
1108
1109void KPrWebPresentationWizard::slideTitleChanged( const TQString &s )
1110{
1111 if ( slideTitles->currentItem() )
1112 slideTitles->currentItem()->setText( 1, s );
1113}
1114
1115void KPrWebPresentationWizard::slideTitleChanged( TQListViewItem *i )
1116{
1117 if ( !i ) return;
1118
1119 slideTitle->setText( i->text( 1 ) );
1120 view->skipToPage( i->text( 0 ).toInt() - 1 );
1121}
1122
1123void KPrWebPresentationWizard::closeEvent( TQCloseEvent *e )
1124{
1125 view->enableWebPres();
1126 KWizard::closeEvent( e );
1127}
1128
1129void KPrWebPresentationWizard::slotChoosePath(const TQString &text)
1130{
1131 webPres.setPath(text);
1132}
1133
1134KPrWebPresentationCreateDialog::KPrWebPresentationCreateDialog( KPrDocument *_doc, KPrView *_view,
1135 const KPrWebPresentation &_webPres )
1136 : TQDialog( 0, "", false ), webPres( _webPres )
1137{
1138 doc = _doc;
1139 view = _view;
1140
1141 setupGUI();
1142}
1143
1144KPrWebPresentationCreateDialog::~KPrWebPresentationCreateDialog()
1145{
1146 view->enableWebPres();
1147}
1148
1149void KPrWebPresentationCreateDialog::createWebPresentation( KPrDocument *_doc, KPrView *_view,
1150 const KPrWebPresentation &_webPres )
1151{
1152 KPrWebPresentationCreateDialog *dlg = new KPrWebPresentationCreateDialog( _doc, _view, _webPres );
1153
1154 dlg->setCaption( i18n( "Create HTML Slideshow" ) );
1155 dlg->resize( 400, 300 );
1156 dlg->show();
1157 dlg->start();
1158}
1159
1160void KPrWebPresentationCreateDialog::start()
1161{
1162 setCursor( waitCursor );
1163 initCreation();
1164 createSlidesPictures();
1165 createSlidesHTML();
1166 createMainPage();
1167 setCursor( arrowCursor );
1168
1169 bDone->setEnabled( true );
1170 bSave->setEnabled( true );
1171}
1172
1173void KPrWebPresentationCreateDialog::initCreation()
1174{
1175 TQFont f = step1->font(), f2 = step1->font();
1176 f.setBold( true );
1177 step1->setFont( f );
1178
1179 progressBar->setProgress( 0 );
1180 progressBar->setTotalSteps( webPres.initSteps() );
1181
1182 webPres.initCreation( progressBar );
1183
1184 step1->setFont( f2 );
1185 progressBar->setProgress( progressBar->totalSteps() );
1186}
1187
1188void KPrWebPresentationCreateDialog::createSlidesPictures()
1189{
1190 TQFont f = step2->font(), f2 = f;
1191 f.setBold( true );
1192 step2->setFont( f );
1193
1194 progressBar->setProgress( 0 );
1195 if ( webPres.slides1Steps() > 0 )
1196 {
1197 progressBar->setTotalSteps( webPres.slides1Steps() );
1198 webPres.createSlidesPictures( progressBar );
1199 }
1200
1201 step2->setFont( f2 );
1202 progressBar->setProgress( progressBar->totalSteps() );
1203}
1204
1205void KPrWebPresentationCreateDialog::createSlidesHTML()
1206{
1207 TQFont f = step3->font(), f2 = step3->font();
1208 f.setBold( true );
1209 step3->setFont( f );
1210
1211 progressBar->setProgress( 0 );
1212 if ( webPres.slides1Steps() > 0 )
1213 {
1214 progressBar->setTotalSteps( webPres.slides1Steps() );
1215 webPres.createSlidesHTML( progressBar );
1216 }
1217
1218 step3->setFont( f2 );
1219 progressBar->setProgress( progressBar->totalSteps() );
1220}
1221
1222void KPrWebPresentationCreateDialog::createMainPage()
1223{
1224 TQFont f = step4->font(), f2 = step4->font();
1225 f.setBold( true );
1226 step4->setFont( f );
1227
1228 progressBar->setProgress( 0 );
1229 progressBar->setTotalSteps( webPres.slides1Steps() );
1230
1231 webPres.createMainPage( progressBar );
1232
1233 step4->setFont( f2 );
1234 progressBar->setProgress( progressBar->totalSteps() );
1235}
1236
1237void KPrWebPresentationCreateDialog::setupGUI()
1238{
1239 back = new TQVBox( this );
1240 back->setMargin( KDialog::marginHint() );
1241
1242 TQFrame *line;
1243
1244 line = new TQFrame( back );
1245 line->setFrameStyle( TQFrame::HLine | TQFrame::Sunken );
1246 line->setMaximumHeight( 20 );
1247
1248 step1 = new TQLabel( i18n( "Initialize (create file structure, etc.)" ), back );
1249 step2 = new TQLabel( i18n( "Create Pictures of the Slides" ), back );
1250 step3 = new TQLabel( i18n( "Create HTML Pages for the Slides" ), back );
1251 step4 = new TQLabel( i18n( "Create Main Page (Table of Contents)" ), back );
1252 step5 = new TQLabel( i18n( "Options for Unattended Presentations" ), back);
1253
1254 line = new TQFrame( back );
1255 line->setFrameStyle( TQFrame::HLine | TQFrame::Sunken );
1256 line->setMaximumHeight( 20 );
1257
1258 progressBar = new KProgress( back );
1259
1260 line = new TQFrame( back );
1261 line->setFrameStyle( TQFrame::HLine | TQFrame::Sunken );
1262 line->setMaximumHeight( 20 );
1263
1264 KButtonBox *bb = new KButtonBox( back );
1265 bSave = bb->addButton( i18n( "Save Configuration..." ) );
1266 bb->addStretch();
1267 bDone = bb->addButton( i18n( "Done" ) );
1268
1269 bSave->setEnabled( false );
1270 bDone->setEnabled( false );
1271
1272 connect( bDone, TQ_SIGNAL( clicked() ), this, TQ_SLOT( accept() ) );
1273 connect( bSave, TQ_SIGNAL( clicked() ), this, TQ_SLOT( saveConfig() ) );
1274}
1275
1276void KPrWebPresentationCreateDialog::resizeEvent( TQResizeEvent *e )
1277{
1278 TQDialog::resizeEvent( e );
1279 back->resize( size() );
1280}
1281
1282void KPrWebPresentationCreateDialog::saveConfig()
1283{
1284 TQString filename = webPres.getConfig();
1285 if ( TQFileInfo( filename ).exists() )
1286 filename = TQFileInfo( filename ).absFilePath();
1287 else
1288 filename = TQString();
1289
1290 KFileDialog fd (filename, i18n("*.kpweb|KPresenter Web-Presentation (*.kpweb)"),
1291 0/*parent*/, 0/*name*/, true/*modal*/);
1292 fd.setCaption (i18n ("Save Web Presentation Configuration"));
1293 fd.setOperationMode (KFileDialog::Saving);
1294 fd.setMode (KFile::File | KFile::LocalOnly);
1295
1296 if (fd.exec ())
1297 {
1298 webPres.setConfig( fd.selectedFile () );
1299 webPres.saveConfig();
1300 }
1301}
1302
1303#include "KPrGradient.h"
1304#include "KPrWebPresentation.moc"