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