kpresenter

KPrWebPresentation.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00004    Copyright 2001, 2002 Nicolas GOUTTE <goutte@kde.org>
00005    Copyright 2002 Ariya Hidayat <ariya@kde.org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "KPrWebPresentation.h"
00024 
00025 #include "KPrView.h"
00026 #include "KPrDocument.h"
00027 #include "KPrCanvas.h"
00028 #include "KPrPage.h"
00029 
00030 #include <kstandarddirs.h>
00031 #include <unistd.h>
00032 #include <sys/types.h>
00033 #include <ktempfile.h>
00034 
00035 #include <qfile.h>
00036 #include <qtextstream.h>
00037 #include <qvbox.h>
00038 #include <qhbox.h>
00039 #include <qlabel.h>
00040 #include <qpushbutton.h>
00041 #include <qfileinfo.h>
00042 #include <qframe.h>
00043 #include <qfont.h>
00044 #include <qpixmap.h>
00045 #include <qdatetime.h>
00046 #include <qdir.h>
00047 #include <qheader.h>
00048 #include <qwmatrix.h>
00049 #include <qtextcodec.h>
00050 #include <qregexp.h>
00051 #include <qimage.h>
00052 #include <qlayout.h>
00053 #include <qwhatsthis.h>
00054 #include <qcheckbox.h>
00055 
00056 #include <kdebug.h>
00057 #include <klocale.h>
00058 #include <kcolorbutton.h>
00059 #include <kfiledialog.h>
00060 #include <kmessagebox.h>
00061 #include <kbuttonbox.h>
00062 #include <ksimpleconfig.h>
00063 #include <kapplication.h>
00064 #include <kprogress.h>
00065 #include <kglobal.h>
00066 #include <kglobalsettings.h>
00067 #include <kcharsets.h>
00068 #include <kurlrequester.h>
00069 #include <klineedit.h>
00070 #include <klistview.h>
00071 #include <knuminput.h>
00072 #include <kcombobox.h>
00073 #include <kurl.h>
00074 #include <kio/netaccess.h>
00075 #include <kdialog.h>
00076 
00077 #include "KoDocumentInfo.h"
00078 
00079 
00080 // Comes from koffice/filters/libexport/KWEFUtils.cc
00081 static QString EscapeSgmlText(const QTextCodec* codec, const QString& strIn,
00082                               const bool quot = false , const bool apos = false )
00083 {
00084     QString strReturn;
00085     QChar ch;
00086 
00087     for (uint i=0; i<strIn.length(); i++)
00088     {
00089         ch=strIn[i];
00090         switch (ch.unicode())
00091         {
00092         case 38: // &
00093         {
00094             strReturn+="&amp;";
00095             break;
00096         }
00097         case 60: // <
00098         {
00099             strReturn+="&lt;";
00100             break;
00101         }
00102         case 62: // >
00103         {
00104             strReturn+="&gt;";
00105             break;
00106         }
00107         case 34: // "
00108         {
00109             if (quot)
00110                 strReturn+="&quot;";
00111             else
00112                 strReturn+=ch;
00113             break;
00114         }
00115         case 39: // '
00116         {
00117             // NOTE:  HTML does not define &apos; by default (only XML/XHTML does)
00118             if (apos)
00119                 strReturn+="&apos;";
00120             else
00121                 strReturn+=ch;
00122             break;
00123         }
00124         default:
00125         {
00126             // verify that the character ch can be expressed in the
00127             //   encoding in which we will write the HTML file.
00128             if (codec)
00129             {
00130                 if (!codec->canEncode(ch))
00131                 {
00132                     strReturn+=QString("&#%1;").arg(ch.unicode());
00133                     break;
00134                 }
00135             }
00136             strReturn+=ch;
00137             break;
00138         }
00139         }
00140     }
00141 
00142     return strReturn;
00143 }
00144 
00145 // Escape only if the encoding do not support the character
00146 // Special SGML characters like < > & are supposed to be already escaped.
00147 static QString EscapeEncodingOnly(const QTextCodec* codec, const QString& strIn)
00148 {
00149     QString strReturn;
00150     QChar ch;
00151 
00152     for (uint i=0; i<strIn.length(); i++)
00153     {
00154         ch=strIn[i];
00155         if (codec)
00156         {
00157             if (!codec->canEncode(ch))
00158             {
00159                 strReturn+=QString("&#%1;").arg(ch.unicode());
00160                 continue;
00161             }
00162         }
00163         strReturn+=ch;
00164     }
00165     return strReturn;
00166 }
00167 
00168 KPrWebPresentation::KPrWebPresentation( KPrDocument *_doc, KPrView *_view )
00169     : config( QString::null ), xml( false )
00170 {
00171     doc = _doc;
00172     view = _view;
00173     init();
00174 }
00175 
00176 KPrWebPresentation::KPrWebPresentation( const QString &_config, KPrDocument *_doc, KPrView *_view )
00177     : config( _config ), xml( false ), m_bWriteHeader( true ), m_bWriteFooter( true ), m_bLoopSlides( false )
00178 {
00179     doc = _doc;
00180     view = _view;
00181     init();
00182     loadConfig();
00183 }
00184 
00185 KPrWebPresentation::KPrWebPresentation( const KPrWebPresentation &webPres )
00186     : config( webPres.config ), author( webPres.author ), title( webPres.title ), email( webPres.email ),
00187       slideInfos( webPres.slideInfos ), backColor( webPres.backColor ), titleColor( webPres.titleColor ),
00188       textColor( webPres.textColor ), path( webPres.path ), xml( webPres.xml),
00189       m_bWriteHeader( webPres.m_bWriteHeader ),
00190       m_bWriteFooter( webPres.m_bWriteFooter ), m_bLoopSlides( webPres.m_bLoopSlides ),
00191       timeBetweenSlides ( webPres.timeBetweenSlides ), zoom( webPres.zoom ), m_encoding( webPres.m_encoding )
00192 {
00193     doc = webPres.doc;
00194     view = webPres.view;
00195 }
00196 
00197 void KPrWebPresentation::loadConfig()
00198 {
00199     if ( config.isEmpty() )
00200         return;
00201 
00202     KSimpleConfig cfg( config );
00203     cfg.setGroup( "General" );
00204 
00205     author = cfg.readEntry( "Author", author );
00206     title = cfg.readEntry( "Title", title );
00207     email = cfg.readEntry( "EMail", email );
00208     unsigned int num = cfg.readNumEntry( "Slides", slideInfos.count() );
00209     //kdDebug(33001) << "KPrWebPresentation::loadConfig num=" << num << endl;
00210 
00211     if ( num <= slideInfos.count() ) {
00212         for ( unsigned int i = 0; i < num; i++ )
00213         {
00214             QString key = QString::fromLatin1( "SlideTitle%1" ).arg( i );
00215             if ( cfg.hasKey( key ) )
00216             {
00217                 // We'll assume that the selected pages haven't changed... Hmm.
00218                 slideInfos[ i ].slideTitle = cfg.readEntry( key );
00219                 kdDebug(33001) << "KPrWebPresentation::loadConfig key=" << key << " data=" << slideInfos[i].slideTitle << endl;
00220             } else kdDebug(33001) << " key not found " << key << endl;
00221         }
00222     }
00223 
00224     backColor = cfg.readColorEntry( "BackColor", &backColor );
00225     titleColor = cfg.readColorEntry( "TitleColor", &titleColor );
00226     textColor = cfg.readColorEntry( "TextColor", &textColor );
00227     path = cfg.readPathEntry( "Path", path );
00228     xml = cfg.readBoolEntry( "XML", xml );
00229     m_bWriteHeader = cfg.readBoolEntry( "WriteHeader", m_bWriteHeader );
00230     m_bWriteFooter = cfg.readBoolEntry( "WriteFooter", m_bWriteFooter );
00231     m_bLoopSlides = cfg.readBoolEntry( "LoopSlides", m_bLoopSlides );
00232     zoom = cfg.readNumEntry( "Zoom", zoom );
00233     timeBetweenSlides = cfg.readNumEntry("TimeBetweenSlides", timeBetweenSlides );
00234     m_encoding = cfg.readEntry( "Encoding", m_encoding );
00235 }
00236 
00237 void KPrWebPresentation::saveConfig()
00238 {
00239     KSimpleConfig cfg( config );
00240     cfg.setGroup( "General" );
00241 
00242     cfg.writeEntry( "Author", author );
00243     cfg.writeEntry( "Title", title );
00244     cfg.writeEntry( "EMail", email );
00245     cfg.writeEntry( "Slides", slideInfos.count() );
00246 
00247     for ( unsigned int i = 0; i < slideInfos.count(); i++ )
00248         cfg.writeEntry( QString::fromLatin1( "SlideTitle%1" ).arg( i ), slideInfos[ i ].slideTitle );
00249 
00250     cfg.writeEntry( "BackColor", backColor );
00251     cfg.writeEntry( "TitleColor", titleColor );
00252     cfg.writeEntry( "TextColor", textColor );
00253 #if KDE_IS_VERSION(3,1,3)
00254     cfg.writePathEntry( "Path", path );
00255 #else
00256     cfg.writeEntry( "Path", path );
00257 #endif
00258     cfg.writeEntry( "XML", xml );
00259     cfg.writeEntry( "WriteHeader", m_bWriteHeader );
00260     cfg.writeEntry( "WriteFooter", m_bWriteFooter );
00261     cfg.writeEntry( "LoopSlides", m_bLoopSlides );
00262     cfg.writeEntry( "Zoom", zoom );
00263     cfg.writeEntry( "TimeBetweenSlides", timeBetweenSlides );
00264     cfg.writeEntry( "Encoding", m_encoding );
00265 }
00266 
00267 void KPrWebPresentation::initCreation( KProgress *progressBar )
00268 {
00269     QString cmd;
00270     int p;
00271     KURL str(  path + "/html"  );
00272     KIO::NetAccess::mkdir( str,( QWidget* )0L  );
00273 
00274     p = progressBar->progress();
00275     progressBar->setProgress( ++p );
00276     kapp->processEvents();
00277 
00278     str = path + "/pics";
00279     KIO::NetAccess::mkdir( str,( QWidget* )0L );
00280 
00281     p = progressBar->progress();
00282     progressBar->setProgress( ++p );
00283     kapp->processEvents();
00284 
00285     const char *pics[] = { "home", "first", "next", "prev", "last", 0 };
00286 
00287     KURL srcurl, desturl;
00288 
00289     for ( uint index = 0; pics[ index ]; index ++ )
00290     {
00291         QString filename = pics[ index ];
00292         filename += ".png";
00293         srcurl.setPath( locate( "slideshow", filename, KPrFactory::global() ) );
00294         desturl = path;
00295         desturl.addPath( "/pics/" + filename );
00296         KIO::NetAccess::file_copy( srcurl, desturl, -1, true /*overwrite*/);
00297         p = progressBar->progress();
00298         progressBar->setProgress( ++p );
00299         kapp->processEvents();
00300     }
00301 }
00302 
00303 void KPrWebPresentation::createSlidesPictures( KProgress *progressBar )
00304 {
00305     if ( slideInfos.isEmpty() )
00306         return;
00307     QPixmap pix( 10, 10 );
00308     QString filename;
00309     int p;
00310     for ( unsigned int i = 0; i < slideInfos.count(); i++ ) {
00311         int pgNum = slideInfos[i].pageNumber;
00312         view->getCanvas()->drawPageInPix( pix, pgNum, zoom, true /*force real variable value*/ );
00313         filename = QString( "%1/pics/slide_%2.png" ).arg( path ).arg( i + 1 );
00314 
00315         KTempFile tmp;
00316         pix.save( tmp.name(), "PNG" );
00317 
00318         KIO::NetAccess::file_move( tmp.name(), filename, -1, true /*overwrite*/);
00319 
00320         p = progressBar->progress();
00321         progressBar->setProgress( ++p );
00322         kapp->processEvents();
00323     }
00324 }
00325 
00326 QString KPrWebPresentation::escapeHtmlText( QTextCodec *codec, const QString& strText ) const
00327 {
00328     // Escape quotes (needed in attributes)
00329     // Do not escape apostrophs (only allowed in XHTML!)
00330     return EscapeSgmlText( codec, strText, true, false );
00331 }
00332 
00333 void KPrWebPresentation::writeStartOfHeader(QTextStream& streamOut, QTextCodec *codec, const QString& subtitle, const QString& next)
00334 {
00335     QString mimeName ( codec->mimeName() );
00336     if ( isXML() )
00337     {   //Write out the XML declaration
00338         streamOut << "<?xml version=\"1.0\" encoding=\""
00339                   << mimeName << "\"?>\n";
00340     }
00341     // write <!DOCTYPE
00342     streamOut << "<!DOCTYPE ";
00343     if ( isXML() )
00344     {
00345         streamOut << "html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"";
00346         streamOut << " \"DTD/xhtml1-transitional.dtd\">\n";
00347     }
00348     else
00349     {
00350         streamOut << "HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"";
00351         streamOut << " \"http://www.w3.org/TR/html4/loose.dtd\">\n";
00352     }
00353     streamOut << "<html";
00354     if ( isXML() )
00355     {
00356         // XHTML has an extra attribute defining its namespace (in the <html> opening tag)
00357         streamOut << " xmlns=\"http://www.w3.org/1999/xhtml\"";
00358     }
00359     streamOut << ">\n" << "<head>\n";
00360 
00361     // Declare what charset we are using
00362     streamOut << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=";
00363     streamOut << mimeName << '"' << ( isXML() ?" /":"") << ">\n" ;
00364 
00365     // Tell who we are (with the CVS revision number) in case we have a bug in our output!
00366     QString strVersion("$Revision: 508787 $");
00367     // Eliminate the dollar signs
00368     //  (We don't want that the version number changes if the HTML file is itself put in a CVS storage.)
00369     streamOut << "<meta name=\"Generator\" content=\"KPresenter's Web Presentation "
00370               << strVersion.mid(10).replace("$","")
00371               << "\""<< ( isXML() ?" /":"") // X(HT)ML closes empty elements, HTML not!
00372               << ">\n";
00373 
00374     // Load the next slide after time elapsed
00375     if ( (timeBetweenSlides > 0) && ( ! next.isNull() ) )
00376     {
00377         streamOut << "<meta http-equiv=\"refresh\" content=\""
00378                   << timeBetweenSlides
00379                   << ";url=" << next
00380                   << "\">\n";
00381     }
00382 
00383     streamOut << "<title>"<< escapeHtmlText( codec, title ) << " - " << escapeHtmlText( codec, subtitle ) << "</title>\n";
00384 
00385     // ### TODO: transform documentinfo.xml into many <META> elements (at least the author!)
00386 }
00387 
00388 void KPrWebPresentation::createSlidesHTML( KProgress *progressBar )
00389 {
00390     QTextCodec *codec = KGlobal::charsets()->codecForName( m_encoding );
00391 
00392     const QString brtag ( "<br" + QString(isXML()?" /":"") + ">" );
00393 
00394     for ( unsigned int i = 0; i < slideInfos.count(); i++ ) {
00395 
00396         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
00397         KTempFile tmp;
00398         QString dest= QString( "%1/html/slide_%2.html" ).arg( path ).arg( pgNum );
00399         QString next= QString( "slide_%2.html" ).arg( pgNum<slideInfos.count() ? pgNum+1 : (m_bLoopSlides ? 1 : pgNum ) ); // Ugly, but it works
00400 
00401         QFile file( tmp.name() );
00402         file.open( IO_WriteOnly );
00403         QTextStream streamOut( &file );
00404         streamOut.setCodec( codec );
00405 
00406         writeStartOfHeader( streamOut, codec, slideInfos[ i ].slideTitle, next );
00407 
00408         // ### TODO: transform documentinfo.xml into many <META> elements (at least the author!)
00409 
00410         if ( i > 0 ) {
00411             streamOut <<  "<link rel=\"first\" href=\"slide_1.html\"" << ( isXML() ?" /":"") << ">\n";
00412             streamOut <<  "<link rel=\"prev\" href=\"slide_" << pgNum - 1 << ".html\"" << ( isXML() ?" /":"") << ">\n";
00413         }
00414         if ( i < slideInfos.count() - 1 ) {
00415             streamOut <<  "<link rel=\"next\" href=\"slide_" << pgNum + 1 << ".html\"" << ( isXML() ?" /":"") << ">\n";
00416             streamOut <<  "<link rel=\"last\" href=\"slide_" << slideInfos.count() << ".html\"" << ( isXML() ?" /":"") << ">\n";
00417         }
00418         streamOut <<  "<link rel=\"contents\" href=\"../index.html\"" << ( isXML() ?" /":"") << ">\n";
00419 
00420         streamOut << "</head>\n";
00421         streamOut << "<body bgcolor=\"" << backColor.name() << "\" text=\"" << textColor.name() << "\">\n";
00422 
00423         if (m_bWriteHeader) {
00424             streamOut << "  <center>\n";
00425 
00426             if ( i > 0 )
00427                 streamOut << "    <a href=\"slide_1.html\">";
00428                 streamOut << "<img src=\"../pics/first.png\" border=\"0\" alt=\"" << i18n( "First" )
00429                               << "\" title=\"" << i18n( "First" ) << "\"" << ( isXML() ?" /":"") << ">";
00430             if ( i > 0 )
00431                 streamOut << "</a>";
00432 
00433             streamOut << "\n";
00434 
00435             if ( i > 0 )
00436                 streamOut << "    <a href=\"slide_" << pgNum - 1 << ".html\">";
00437                 streamOut << "<img src=\"../pics/prev.png\" border=\"0\" alt=\"" << i18n( "Previous" )
00438                               << "\" title=\"" << i18n( "Previous" ) << "\"" << ( isXML() ?" /":"") << ">";
00439             if ( i > 0 )
00440                 streamOut << "</a>";
00441 
00442             streamOut << "\n";
00443 
00444             if ( (m_bLoopSlides) || (i < slideInfos.count() - 1 ) )
00445                 streamOut << "    <a href=\"" << next << "\">";
00446                 streamOut << "<img src=\"../pics/next.png\" border=\"0\" alt=\"" << i18n( "Next" )
00447                           << "\" title=\"" << i18n( "Next" ) << "\"" << ( isXML() ?" /":"") << ">";
00448             if ( (m_bLoopSlides) || (i < slideInfos.count() - 1 ) )
00449                 streamOut << "</a>";
00450 
00451             streamOut << "\n";
00452 
00453             if ( i < slideInfos.count() - 1 )
00454                 streamOut << "    <a href=\"slide_" << slideInfos.count() << ".html\">";
00455                 streamOut << "<img src=\"../pics/last.png\" border=\"0\" alt=\"" << i18n( "Last" )
00456                       << "\" title=\"" << i18n( "Last" ) << "\"" << ( isXML() ?" /":"") << ">";
00457             if ( i < slideInfos.count() - 1 )
00458                 streamOut << "</a>";
00459 
00460             streamOut << "\n" << "    &nbsp; &nbsp; &nbsp; &nbsp;\n";
00461 
00462             streamOut << "    <a href=\"../index.html\">";
00463             streamOut << "<img src=\"../pics/home.png\" border=\"0\" alt=\"" << i18n( "Home" )
00464                       << "\" title=\"" << i18n( "Home" ) << "\"" << ( isXML() ?" /":"") << ">";
00465             streamOut << "</a>\n";
00466 
00467             streamOut << " </center>" << brtag << "<hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n"; // ### TODO: is noshade W3C?
00468 
00469             streamOut << "  <center>\n    <font color=\"" << escapeHtmlText( codec, titleColor.name() ) << "\">\n";
00470             streamOut << "    <b>" << escapeHtmlText( codec, title ) << "</b> - <i>" << escapeHtmlText( codec, slideInfos[ i ].slideTitle ) << "</i>\n";
00471 
00472             streamOut << "    </font>\n  </center>\n";
00473 
00474             streamOut << "<hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">" << brtag << "\n";
00475     }
00476 
00477         streamOut << "  <center>\n    ";
00478 
00479     if ( (m_bLoopSlides) || (i < slideInfos.count() - 1) )
00480             streamOut << "<a href=\"" << next << "\">";
00481 
00482         streamOut << "<img src=\"../pics/slide_" << pgNum << ".png\" border=\"0\" alt=\""
00483                       << i18n( "Slide %1" ).arg( pgNum ) << "\"" << ( isXML() ?" /":"") << ">";
00484 
00485         if ( i < slideInfos.count() - 1 )
00486                 streamOut << "</a>";
00487 
00488             streamOut << "\n";
00489 
00490             streamOut << "    </center>\n";
00491 
00492     if (m_bWriteFooter) {
00493             streamOut << brtag << "<hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n";
00494 
00495             QPtrList<KPrPage> _tmpList( doc->getPageList() );
00496             QString note ( escapeHtmlText( codec, _tmpList.at(i)->noteText() ) );
00497             if ( !note.isEmpty() ) {
00498                 streamOut << "  <b>" << escapeHtmlText( codec, i18n( "Note" ) ) << "</b>\n";
00499                 streamOut << " <blockquote>\n";
00500 
00501                 streamOut << note.replace( "\n", brtag );
00502 
00503                 streamOut << "  </blockquote><hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n";
00504             }
00505 
00506             streamOut << "  <center>\n";
00507 
00508             QString htmlAuthor;
00509             if (email.isEmpty())
00510                 htmlAuthor=escapeHtmlText( codec, author );
00511             else
00512                 htmlAuthor=QString("<a href=\"mailto:%1\">%2</a>").arg( escapeHtmlText( codec, email )).arg( escapeHtmlText( codec, author ));
00513             streamOut << EscapeEncodingOnly ( codec, i18n( "Created on %1 by <i>%2</i> with <a href=\"http://www.koffice.org/kpresenter\">KPresenter</a>" )
00514                                           .arg( KGlobal::locale()->formatDate ( QDate::currentDate() ) ).arg( htmlAuthor ) );
00515 
00516             streamOut << "    </center><hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n";
00517         }
00518 
00519         streamOut << "</body>\n</html>\n";
00520 
00521         file.close();
00522 
00523         KIO::NetAccess::file_move( tmp.name(), dest, -1, true /*overwrite*/);
00524 
00525         int p = progressBar->progress();
00526         progressBar->setProgress( ++p );
00527         kapp->processEvents();
00528     }
00529 }
00530 
00531 void KPrWebPresentation::createMainPage( KProgress *progressBar )
00532 {
00533     QTextCodec *codec = KGlobal::charsets()->codecForName( m_encoding );
00534     KTempFile tmp;
00535     QString dest = QString( "%1/index.html" ).arg( path );
00536     QFile file( tmp.name() );
00537     file.open( IO_WriteOnly );
00538     QTextStream streamOut( &file );
00539     streamOut.setCodec( codec );
00540 
00541     writeStartOfHeader( streamOut, codec, i18n("Table of Contents"), QString() );
00542     streamOut << "</head>\n";
00543 
00544     streamOut << "<body bgcolor=\"" << backColor.name() << "\" text=\"" << textColor.name() << "\">\n";
00545 
00546     streamOut << "<h1 align=\"center\"><font color=\"" << titleColor.name()
00547               << "\">" << title << "</font></h1>";
00548 
00549     streamOut << "<p align=\"center\"><a href=\"html/slide_1.html\">";
00550     streamOut << i18n("Click here to start the Slideshow");
00551     streamOut << "</a></p>\n";
00552 
00553     streamOut << "<p><b>" << i18n("Table of Contents") << "</b></p>\n";
00554 
00555     // create list of slides (with proper link)
00556     streamOut << "<ol>\n";
00557     for ( unsigned int i = 0; i < slideInfos.count(); i++ )
00558         streamOut << "  <li><a href=\"html/slide_" << i+1 << ".html\">" << slideInfos[ i ].slideTitle << "</a></li>\n";
00559     streamOut << "</ol>\n";
00560 
00561     // footer: author name, e-mail
00562     QString htmlAuthor = email.isEmpty() ? escapeHtmlText( codec, author ) :
00563                          QString("<a href=\"mailto:%1\">%2</a>").arg( escapeHtmlText( codec, email )).arg( escapeHtmlText( codec, author ));
00564     streamOut << EscapeEncodingOnly ( codec, i18n( "Created on %1 by <i>%2</i> with <a href=\"http://www.koffice.org/kpresenter\">KPresenter</a>" )
00565                                       .arg( KGlobal::locale()->formatDate ( QDate::currentDate() ) ).arg( htmlAuthor ) );
00566 
00567     streamOut << "</body>\n</html>\n";
00568     file.close();
00569 
00570     KIO::NetAccess::file_move( tmp.name(), dest, -1, true /*overwrite*/);
00571 
00572 
00573     progressBar->setProgress( progressBar->totalSteps() );
00574     kapp->processEvents();
00575 }
00576 
00577 void KPrWebPresentation::init()
00578 {
00579 
00580     KoDocumentInfo * info = doc->documentInfo();
00581     KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
00582     if ( !authorPage )
00583         kdWarning() << "Author information not found in documentInfo !" << endl;
00584     else
00585     {
00586         author = authorPage->fullName();
00587         email = authorPage->email();
00588     }
00589 
00590     title = i18n("Slideshow");
00591     kdDebug(33001) << "KPrWebPresentation::init : " << doc->getPageNums() << " pages." << endl;
00592     for ( unsigned int i = 0; i < doc->getPageNums(); i++ )
00593     {
00594         if ( doc->isSlideSelected( i ) )
00595         {
00596             SlideInfo info;
00597             info.pageNumber = i;
00598             info.slideTitle = doc->pageList().at(i)->pageTitle();
00599             slideInfos.append( info );
00600         }
00601     }
00602     if ( slideInfos.isEmpty() )
00603         kdWarning() << "No slides selected!" << endl;
00604     backColor = Qt::white;
00605     textColor = Qt::black;
00606     titleColor = Qt::red;
00607 
00608     path = KGlobalSettings::documentPath() + "www";
00609 
00610     zoom = 100;
00611 
00612     timeBetweenSlides = 0;
00613 
00614     m_encoding = QTextCodec::codecForLocale()->name();
00615 }
00616 
00617 KPrWebPresentationWizard::KPrWebPresentationWizard( const QString &_config, KPrDocument *_doc,
00618                                                   KPrView *_view )
00619     : KWizard( 0, "", false ), config( _config ), webPres( config, _doc, _view )
00620 {
00621     doc = _doc;
00622     view = _view;
00623 
00624     setupPage1();
00625     setupPage2();
00626     setupPage3();
00627     setupPage4();
00628     setupPage5();
00629 
00630     connect( nextButton(), SIGNAL( clicked() ), this, SLOT( pageChanged() ) );
00631     connect( backButton(), SIGNAL( clicked() ), this, SLOT( pageChanged() ) );
00632     connect( finishButton(), SIGNAL( clicked() ), this, SLOT( finish() ) );
00633 }
00634 
00635 KPrWebPresentationWizard::~KPrWebPresentationWizard()
00636 {
00637     view->enableWebPres();
00638 }
00639 
00640 void KPrWebPresentationWizard::createWebPresentation( const QString &_config, KPrDocument *_doc,
00641                                                      KPrView *_view )
00642 {
00643     KPrWebPresentationWizard *dlg = new KPrWebPresentationWizard( _config, _doc, _view );
00644 
00645     dlg->setCaption( i18n( "Create HTML Slideshow Wizard" ) );
00646     dlg->show();
00647 }
00648 
00649 void KPrWebPresentationWizard::setupPage1()
00650 {
00651     page1 = new QHBox( this );
00652     QWhatsThis::add( page1, i18n("This page allows you to specify some of the key"
00653                                  " values for how your presentation will be shown"
00654                                  " in HTML. Select individual items for more help"
00655                                  " on what they do.") );
00656     page1->setSpacing( KDialog::spacingHint() );
00657     page1->setMargin( KDialog::marginHint() );
00658 
00659     QLabel* sidebar = new QLabel( page1 );
00660     sidebar->setMinimumSize( 106, 318 );
00661     sidebar->setMaximumSize( 106, 318 );
00662     sidebar->setFrameShape( QFrame::Panel );
00663     sidebar->setFrameShadow( QFrame::Sunken );
00664     sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
00665 
00666     QWidget* canvas = new QWidget( page1 );
00667     QGridLayout *layout = new QGridLayout( canvas, 7, 2,
00668                                            KDialog::marginHint(), KDialog::spacingHint() );
00669 
00670     QLabel *helptext = new QLabel( canvas );
00671     helptext->setAlignment( Qt::WordBreak | Qt::AlignTop| Qt::AlignLeft );
00672     helptext->setText( i18n( "Enter your name, email address and "
00673                              "the title of the web presentation. "
00674                              "Also enter the output directory where the "
00675                              "web presentation should be saved. " ) );
00676     layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
00677 
00678     layout->addMultiCell( new QSpacerItem( 1, 50 ), 1, 1, 0, 1 );
00679 
00680     QLabel *label1 = new QLabel( i18n("Author:"), canvas );
00681     label1->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00682     QWhatsThis::add( label1, i18n("This is where you enter the name of the person or "
00683                                   "organization that should be named as the author of "
00684                                   "the presentation.") );
00685     layout->addWidget( label1, 2, 0 );
00686 
00687     QLabel *label2 = new QLabel( i18n("Title:"), canvas );
00688     label2->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00689     QWhatsThis::add( label2, i18n("This is where you enter the title of the overall "
00690                                   "presentation." ) );
00691     layout->addWidget( label2, 3, 0 );
00692 
00693     QLabel *label3 = new QLabel( i18n("Email address:"), canvas );
00694     label3->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00695     QWhatsThis::add( label3, i18n("This is where you enter the email address of the "
00696                                   "person or organization that is responsible for "
00697                                   "the presentation.") );
00698     layout->addWidget( label3, 4, 0 );
00699 
00700     QLabel *label4 = new QLabel( i18n("Path:"), canvas );
00701     label4->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00702     QWhatsThis::add( label4, i18n("The value entered for the path is the directory "
00703                                   "where the presentation will be saved. If it does "
00704                                   "not exist, you'll be asked if you want to create "
00705                                   "the directory or abort the creation.") );
00706     layout->addWidget( label4, 5, 0 );
00707 
00708     author = new KLineEdit( webPres.getAuthor(), canvas );
00709     QWhatsThis::add( author, i18n("This is where you enter the name of the person or "
00710                                   "organization that should be named as the author of "
00711                                   "the presentation.") );
00712     layout->addWidget( author, 2, 1 );
00713 
00714     title = new KLineEdit( webPres.getTitle(), canvas );
00715     QWhatsThis::add( title, i18n("This is where you enter the title of the overall "
00716                                  "presentation." ) );
00717     layout->addWidget( title, 3, 1 );
00718 
00719     email = new KLineEdit( webPres.getEmail(), canvas );
00720     QWhatsThis::add( email, i18n("This is where you enter the email address of the "
00721                                  "person or organization that is responsible for "
00722                                  "the presentation.") );
00723     layout->addWidget( email, 4, 1 );
00724 
00725     path=new KURLRequester( canvas );
00726     path->setMode( KFile::Directory);
00727     path->lineEdit()->setText(webPres.getPath());
00728     QWhatsThis::add( path, i18n("The value entered for the path is the directory "
00729                                 "where the presentation will be saved. If it does "
00730                                 "not exist, you'll be asked if you want to create "
00731                                 "the directory or abort the creation.") );
00732     layout->addWidget( path, 5, 1 );
00733 
00734     QSpacerItem* spacer = new QSpacerItem( 1, 10,
00735                                            QSizePolicy::Minimum, QSizePolicy::Expanding );
00736     layout->addMultiCell( spacer, 6, 6, 0, 1 );
00737 
00738     connect(path, SIGNAL(textChanged(const QString&)),
00739             this,SLOT(slotChoosePath(const QString&)));
00740     connect(path, SIGNAL(urlSelected( const QString& )),
00741             this,SLOT(slotChoosePath(const QString&)));
00742 
00743     addPage( page1, i18n( "Step 1: General Information" ) );
00744 
00745     setHelpEnabled(page1, false);  //doesn't do anything currently
00746 }
00747 
00748 void KPrWebPresentationWizard::setupPage2()
00749 {
00750     page2 = new QHBox( this );
00751     QWhatsThis::add( page2, i18n("This page allows you to specify how the HTML "
00752                                  "for your presentation will be displayed. Select "
00753                                  "individual items for more help on what they do.") );
00754     page2->setSpacing( KDialog::spacingHint() );
00755     page2->setMargin( KDialog::marginHint() );
00756 
00757     QLabel* sidebar = new QLabel( page2 );
00758     sidebar->setMinimumSize( 106, 318 );
00759     sidebar->setMaximumSize( 106, 318 );
00760     sidebar->setFrameShape( QFrame::Panel );
00761     sidebar->setFrameShadow( QFrame::Sunken );
00762     sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
00763 
00764     QWidget* canvas = new QWidget( page2 );
00765     QGridLayout *layout = new QGridLayout( canvas, 6, 2,
00766                                            KDialog::marginHint(), KDialog::spacingHint() );
00767 
00768     QLabel *helptext = new QLabel( canvas );
00769     helptext->setAlignment( Qt::WordBreak | Qt::AlignVCenter| Qt::AlignLeft );
00770     QString help = i18n("Here you can configure the style of the web pages.");
00771     help += i18n( "You can also specify the zoom for the slides." );
00772     helptext->setText(help);
00773 
00774     layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
00775 
00776     layout->addMultiCell( new QSpacerItem( 1, 50 ), 1, 1, 0, 1 );
00777 
00778     QLabel *label1 = new QLabel( i18n("Zoom:"), canvas );
00779     label1->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00780     QWhatsThis::add( label1, i18n( "This selection allows you to specify "
00781                                    "the size of the slide image." ) );
00782     layout->addWidget( label1, 2, 0 );
00783 
00784     QLabel *label2 = new QLabel( i18n( "Encoding:" ), canvas );
00785     label2->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00786 
00787     layout->addWidget( label2, 3, 0 );
00788 
00789     QLabel *label3 = new QLabel( i18n( "Document type:" ), canvas );
00790     label3->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00791     layout->addWidget( label3, 4, 0 );
00792 
00793     zoom = new KIntNumInput( webPres.getZoom(), canvas );
00794     QWhatsThis::add( zoom, i18n( "This selection allows you to specify "
00795                                  "the size of the slide image." ) );
00796     layout->addWidget( zoom, 2, 1 );
00797     zoom->setSuffix( " %" );
00798     zoom->setRange( 25, 1000, 5 );
00799 
00800     encoding = new KComboBox( false, canvas );
00801     layout->addWidget( encoding, 3, 1 );
00802 
00803     // Fill encoding combo
00804     // Stolen from kdelibs/kate/part/katedialogs.cpp
00805     QStringList encodings(KGlobal::charsets()->descriptiveEncodingNames());
00806     int idx = 0;
00807     for (uint i = 0; i < encodings.count(); i++)
00808     {
00809       bool found = false;
00810       QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(KGlobal::charsets()->encodingForName(encodings[i]), found);
00811       if (found)
00812       {
00813         encoding->insertItem(encodings[i]);
00814 
00815         if ( codecForEnc->name() == webPres.getEncoding() )
00816           encoding->setCurrentItem(idx);
00817         idx++;
00818       }
00819     }
00820 
00821     doctype = new KComboBox( false, canvas );
00822     layout->addWidget( doctype, 4, 1 );
00823     doctype->insertItem( "HTML 4.01", -1 );
00824     doctype->insertItem( "XHTML 1.0", -1 );
00825 
00826     doctype->setCurrentItem( webPres.isXML() ? 1 : 0 );
00827 
00828     QSpacerItem* spacer = new QSpacerItem( 1, 10,
00829                                            QSizePolicy::Minimum, QSizePolicy::Expanding );
00830     layout->addMultiCell( spacer, 5, 5, 0, 1 );
00831 
00832     addPage( page2, i18n( "Step 2: Configure HTML" ) );
00833 
00834     setHelpEnabled(page2, false);  //doesn't do anything currently
00835 }
00836 
00837 void KPrWebPresentationWizard::setupPage3()
00838 {
00839     page3 = new QHBox( this );
00840     QWhatsThis::add( page3, i18n("This page allows you to specify the colors for "
00841                                  "your presentation display. Select individual "
00842                                  "items for more help on what they do.") );
00843 
00844     page3->setSpacing( KDialog::spacingHint() );
00845     page3->setMargin( KDialog::marginHint() );
00846 
00847     QLabel* sidebar = new QLabel( page3 );
00848     sidebar->setMinimumSize( 106, 318 );
00849     sidebar->setMaximumSize( 106, 318 );
00850     sidebar->setFrameShape( QFrame::Panel );
00851     sidebar->setFrameShadow( QFrame::Sunken );
00852     sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
00853 
00854     QWidget* canvas = new QWidget( page3 );
00855     QGridLayout *layout = new QGridLayout( canvas, 6, 2,
00856                                            KDialog::marginHint(), KDialog::spacingHint() );
00857 
00858     QLabel *helptext = new QLabel( canvas );
00859     helptext->setAlignment( Qt::WordBreak | Qt::AlignVCenter| Qt::AlignLeft );
00860     helptext->setText( i18n( "Now you can customize the colors of the web pages." ) );
00861     layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
00862 
00863     layout->addMultiCell( new QSpacerItem( 1, 50 ), 1, 1, 0, 1 );
00864 
00865     QLabel *label1 = new QLabel( i18n("Text color:"), canvas );
00866     label1->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00867     layout->addWidget( label1, 2, 0 );
00868 
00869     QLabel *label2 = new QLabel( i18n("Title color:"), canvas );
00870     label2->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00871     layout->addWidget( label2, 3, 0 );
00872 
00873     QLabel *label3 = new QLabel( i18n("Background color:"), canvas );
00874     label3->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00875     layout->addWidget( label3, 4, 0 );
00876 
00877     textColor = new KColorButton( webPres.getTextColor(), canvas );
00878     layout->addWidget( textColor, 2, 1 );
00879 
00880     titleColor = new KColorButton( webPres.getTitleColor(), canvas );
00881     layout->addWidget( titleColor, 3, 1 );
00882 
00883     backColor = new KColorButton( webPres.getBackColor(), canvas );
00884     layout->addWidget( backColor, 4, 1 );
00885 
00886     QSpacerItem* spacer = new QSpacerItem( 1, 10,
00887                                            QSizePolicy::Minimum, QSizePolicy::Expanding );
00888     layout->addMultiCell( spacer, 5, 5, 0, 1 );
00889 
00890     addPage( page3, i18n( "Step 3: Customize Colors" ) );
00891 
00892     setHelpEnabled(page3, false);  //doesn't do anything currently
00893 }
00894 
00895 void KPrWebPresentationWizard::setupPage4()
00896 {
00897     page4 = new QHBox( this );
00898     QWhatsThis::add( page4, i18n("This page allows you to modify the titles of "
00899                                  "each slide, if required. You normally do not need "
00900                                  "to do this, but it is available if required.") );
00901     page4->setSpacing( KDialog::spacingHint() );
00902     page4->setMargin( KDialog::marginHint() );
00903 
00904     QLabel* sidebar = new QLabel( page4 );
00905     sidebar->setMinimumSize( 106, 318 );
00906     sidebar->setMaximumSize( 106, 318 );
00907     sidebar->setFrameShape( QFrame::Panel );
00908     sidebar->setFrameShadow( QFrame::Sunken );
00909     sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
00910 
00911     QWidget* canvas = new QWidget( page4 );
00912     QGridLayout *layout = new QGridLayout( canvas, 3, 2,
00913                                            KDialog::marginHint(), KDialog::spacingHint() );
00914 
00915     QLabel *helptext = new QLabel( canvas );
00916     helptext->setAlignment( Qt::WordBreak | Qt::AlignVCenter| Qt::AlignLeft );
00917     helptext->setText( i18n( "Here you can specify titles for "
00918                              "each slide. Click on a slide in "
00919                              "the list and then enter the title "
00920                              "in the textbox below. If you "
00921                              "click on a title, KPresenter "
00922                              "mainview will display the slide.") );
00923 
00924     layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
00925 
00926     QLabel *label = new QLabel( i18n( "Slide title:" ), canvas );
00927     label->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00928     layout->addWidget( label, 1, 0 );
00929 
00930     slideTitle = new KLineEdit( canvas );
00931     layout->addWidget( slideTitle, 1, 1 );
00932     connect( slideTitle, SIGNAL( textChanged( const QString & ) ), this,
00933              SLOT( slideTitleChanged( const QString & ) ) );
00934 
00935     slideTitles = new KListView( canvas );
00936     layout->addMultiCellWidget( slideTitles, 2, 2, 0, 1 );
00937     slideTitles->addColumn( i18n( "No." ) );
00938     slideTitles->addColumn( i18n( "Slide Title" ) );
00939     connect( slideTitles, SIGNAL( selectionChanged( QListViewItem * ) ), this,
00940              SLOT( slideTitleChanged( QListViewItem * ) ) );
00941     slideTitles->setSorting( -1 );
00942     slideTitles->setAllColumnsShowFocus( true );
00943     slideTitles->setResizeMode( QListView::LastColumn );
00944     slideTitles->header()->setMovingEnabled( false );
00945 
00946     QValueList<KPrWebPresentation::SlideInfo> infos = webPres.getSlideInfos();
00947     for ( int i = infos.count() - 1; i >= 0; --i ) {
00948         KListViewItem *item = new KListViewItem( slideTitles );
00949         item->setText( 0, QString::number( i + 1 ) );
00950         //kdDebug(33001) << "KPrWebPresentationWizard::setupPage3 " << infos[ i ].slideTitle << endl;
00951         item->setText( 1, infos[ i ].slideTitle );
00952     }
00953 
00954     slideTitles->setSelected( slideTitles->firstChild(), true );
00955 
00956     addPage( page4, i18n( "Step 4: Customize Slide Titles" ) );
00957 
00958     setHelpEnabled(page4, false);  //doesn't do anything currently
00959 }
00960 
00961 void KPrWebPresentationWizard::setupPage5()
00962 {
00963     page5 = new QHBox( this );
00964     QWhatsThis::add( page5, i18n("This page allows you to specify some options for "
00965                                  "presentations which run unattended, such as time "
00966                                  "elapsed before advancing to the next slide, looping "
00967                                  "and the presence of headers. If you do not want "
00968                                  "an unattended presentation, just leave defaults unchanged.") );
00969     page5->setSpacing( KDialog::spacingHint() );
00970     page5->setMargin( KDialog::marginHint() );
00971 
00972     QLabel* sidebar = new QLabel( page5 );
00973     sidebar->setMinimumSize( 106, 318 );
00974     sidebar->setMaximumSize( 106, 318 );
00975     sidebar->setFrameShape( QFrame::Panel );
00976     sidebar->setFrameShadow( QFrame::Sunken );
00977     sidebar->setPixmap(locate("data", "kpresenter/pics/webslideshow-sidebar.png"));
00978 
00979     QWidget* canvas = new QWidget( page5 );
00980     QGridLayout *layout = new QGridLayout( canvas, 6, 2,
00981                                            KDialog::marginHint(), KDialog::spacingHint() );
00982 
00983     QLabel *helptext = new QLabel( canvas );
00984     helptext->setAlignment( Qt::WordBreak | Qt::AlignVCenter| Qt::AlignLeft );
00985     QString help = i18n("Here you can configure some options for unattended "
00986                         "presentations, such as time elapsed before automatically advance to "
00987                         "the next slide, looping and the presence of headers.");
00988     helptext->setText(help);
00989 
00990     layout->addMultiCellWidget( helptext, 0, 0, 0, 1 );
00991 
00992     layout->addMultiCell( new QSpacerItem( 1, 50 ), 1, 1, 0, 1 );
00993 
00994     QLabel *label1 = new QLabel( i18n("Advance after:"), canvas );
00995     label1->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
00996     QWhatsThis::add( label1, i18n( "This selection allows you to specify "
00997                                    "the time between slides." ) );
00998     layout->addWidget( label1, 2, 0 );
00999 
01000     timeBetweenSlides = new KIntNumInput( webPres.getTimeBetweenSlides(), canvas );
01001     timeBetweenSlides->setSpecialValueText(i18n( "Disabled" ));
01002     QWhatsThis::add( timeBetweenSlides, i18n( "This selection allows you to specify "
01003                                  "the time between slides." ) );
01004     layout->addWidget( timeBetweenSlides, 2, 1 );
01005     timeBetweenSlides->setSuffix( " seconds" );
01006     timeBetweenSlides->setRange( 0, 900, 1 );
01007 
01008     layout->addMultiCell( new QSpacerItem( 1, 10 ), 1, 1, 0, 1 );
01009 
01010     writeHeader=new QCheckBox( i18n("Write header to the slides"), canvas);
01011     QWhatsThis::add( writeHeader, i18n( "This checkbox allows you to specify if you "
01012                                        "want to write the navigation buttons on top "
01013                                        "of the slide." ) );
01014     writeHeader->setChecked( webPres.wantHeader() );
01015     layout->addWidget( writeHeader, 3, 1);
01016 
01017     writeFooter=new QCheckBox( i18n("Write footer to the slides"), canvas);
01018     QWhatsThis::add( writeFooter, i18n( "This checkbox allows you to specify if you "
01019                                        "want to write an imprint consisting on the author "
01020                                        "and the software used to create these slides." ) );
01021     writeFooter->setChecked( webPres.wantFooter() );
01022     layout->addWidget( writeFooter, 4, 1);
01023 
01024     loopSlides=new QCheckBox( i18n("Loop presentation"), canvas);
01025     QWhatsThis::add( loopSlides, i18n( "This checkbox allows you to specify if you "
01026                                        "want the presentation to start again once "
01027                                        "the latest slide is reached." ) );
01028     loopSlides->setChecked( webPres.wantLoopSlides() );
01029     layout->addWidget( loopSlides, 5, 1);
01030 
01031     QSpacerItem* spacer = new QSpacerItem( 1, 10,
01032                                            QSizePolicy::Minimum, QSizePolicy::Expanding );
01033     layout->addMultiCell( spacer, 5, 5, 0, 1 );
01034 
01035     addPage( page5, i18n( "Step 5: Options for Unattended Presentations" ) );
01036 
01037     setHelpEnabled(page5, false);  //doesn't do anything currently
01038 
01039     setFinish( page5, true );
01040 }
01041 
01042 void KPrWebPresentationWizard::finish()
01043 {
01044     webPres.setAuthor( author->text() );
01045     webPres.setEMail( email->text() );
01046     webPres.setTitle( title->text() );
01047 
01048     QListViewItemIterator it( slideTitles );
01049     for ( ; it.current(); ++it )
01050         webPres.setSlideTitle( it.current()->text( 0 ).toInt() - 1, it.current()->text( 1 ) );
01051 
01052     webPres.setBackColor( backColor->color() );
01053     webPres.setTitleColor( titleColor->color() );
01054     webPres.setTextColor( textColor->color() );
01055     webPres.setPath( path->lineEdit()->text() );
01056     webPres.setZoom( zoom->value() );
01057     webPres.setTimeBetweenSlides( timeBetweenSlides->value() );
01058     webPres.setWriteHeader( writeHeader->isChecked() );
01059     webPres.setWriteFooter( writeFooter->isChecked() );
01060     webPres.setLoopSlides( loopSlides->isChecked() );
01061     webPres.setXML( doctype->currentItem() != 0 );
01062     bool found = false;
01063     QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(KGlobal::charsets()->encodingForName(encoding->currentText()), found);
01064     if ( found )
01065     {
01066         webPres.setEncoding( codecForEnc->name() );
01067     }
01068 
01069     close();
01070     KPrWebPresentationCreateDialog::createWebPresentation( doc, view, webPres );
01071 }
01072 
01073 void KPrWebPresentationWizard::pageChanged()
01074 {
01075     if ( currentPage() != page5 )
01076     {
01077         QString pathname = path->lineEdit()->text();
01078 
01079         // path doesn't exist. ask user if it should be created.
01080         if ( !KIO::NetAccess::exists( pathname, true/*write*/,this ) )
01081         {
01082             QString msg = i18n( "<qt>The directory <b>%1</b> does not exist.<br>"
01083                                 "Do you want create it?</qt>" );
01084             if( KMessageBox::questionYesNo( this, msg.arg( pathname ),
01085                                             i18n( "Directory Not Found" ) )
01086                 == KMessageBox::Yes)
01087             {
01088                 bool ok = KIO::NetAccess::mkdir( pathname, this );
01089                 if( !ok )
01090                 {
01091                     KMessageBox::sorry( this,
01092                                         i18n( "Cannot create directory." ) );
01093                     // go back to first step
01094                     showPage( page1 );
01095                     path->setFocus();
01096                 }
01097 
01098             }
01099             else
01100             {
01101                 // go back to first step
01102                 showPage( page1 );
01103                 path->setFocus();
01104             }
01105         }
01106     } else
01107         finishButton()->setEnabled( true );
01108 }
01109 
01110 void KPrWebPresentationWizard::slideTitleChanged( const QString &s )
01111 {
01112     if ( slideTitles->currentItem() )
01113         slideTitles->currentItem()->setText( 1, s );
01114 }
01115 
01116 void KPrWebPresentationWizard::slideTitleChanged( QListViewItem *i )
01117 {
01118     if ( !i ) return;
01119 
01120     slideTitle->setText( i->text( 1 ) );
01121     view->skipToPage( i->text( 0 ).toInt() - 1 );
01122 }
01123 
01124 void KPrWebPresentationWizard::closeEvent( QCloseEvent *e )
01125 {
01126     view->enableWebPres();
01127     KWizard::closeEvent( e );
01128 }
01129 
01130 void KPrWebPresentationWizard::slotChoosePath(const QString &text)
01131 {
01132     webPres.setPath(text);
01133 }
01134 
01135 KPrWebPresentationCreateDialog::KPrWebPresentationCreateDialog( KPrDocument *_doc, KPrView *_view,
01136                                                               const KPrWebPresentation &_webPres )
01137     : QDialog( 0, "", false ), webPres( _webPres )
01138 {
01139     doc = _doc;
01140     view = _view;
01141 
01142     setupGUI();
01143 }
01144 
01145 KPrWebPresentationCreateDialog::~KPrWebPresentationCreateDialog()
01146 {
01147     view->enableWebPres();
01148 }
01149 
01150 void KPrWebPresentationCreateDialog::createWebPresentation( KPrDocument *_doc, KPrView *_view,
01151                                                            const KPrWebPresentation &_webPres )
01152 {
01153     KPrWebPresentationCreateDialog *dlg = new KPrWebPresentationCreateDialog( _doc, _view, _webPres );
01154 
01155     dlg->setCaption( i18n( "Create HTML Slideshow" ) );
01156     dlg->resize( 400, 300 );
01157     dlg->show();
01158     dlg->start();
01159 }
01160 
01161 void KPrWebPresentationCreateDialog::start()
01162 {
01163     setCursor( waitCursor );
01164     initCreation();
01165     createSlidesPictures();
01166     createSlidesHTML();
01167     createMainPage();
01168     setCursor( arrowCursor );
01169 
01170     bDone->setEnabled( true );
01171     bSave->setEnabled( true );
01172 }
01173 
01174 void KPrWebPresentationCreateDialog::initCreation()
01175 {
01176     QFont f = step1->font(), f2 = step1->font();
01177     f.setBold( true );
01178     step1->setFont( f );
01179 
01180     progressBar->setProgress( 0 );
01181     progressBar->setTotalSteps( webPres.initSteps() );
01182 
01183     webPres.initCreation( progressBar );
01184 
01185     step1->setFont( f2 );
01186     progressBar->setProgress( progressBar->totalSteps() );
01187 }
01188 
01189 void KPrWebPresentationCreateDialog::createSlidesPictures()
01190 {
01191     QFont f = step2->font(), f2 = f;
01192     f.setBold( true );
01193     step2->setFont( f );
01194 
01195     progressBar->setProgress( 0 );
01196     if ( webPres.slides1Steps() > 0 )
01197     {
01198         progressBar->setTotalSteps( webPres.slides1Steps() );
01199         webPres.createSlidesPictures( progressBar );
01200     }
01201 
01202     step2->setFont( f2 );
01203     progressBar->setProgress( progressBar->totalSteps() );
01204 }
01205 
01206 void KPrWebPresentationCreateDialog::createSlidesHTML()
01207 {
01208     QFont f = step3->font(), f2 = step3->font();
01209     f.setBold( true );
01210     step3->setFont( f );
01211 
01212     progressBar->setProgress( 0 );
01213     if ( webPres.slides1Steps() > 0 )
01214     {
01215         progressBar->setTotalSteps( webPres.slides1Steps() );
01216         webPres.createSlidesHTML( progressBar );
01217     }
01218 
01219     step3->setFont( f2 );
01220     progressBar->setProgress( progressBar->totalSteps() );
01221 }
01222 
01223 void KPrWebPresentationCreateDialog::createMainPage()
01224 {
01225     QFont f = step4->font(), f2 = step4->font();
01226     f.setBold( true );
01227     step4->setFont( f );
01228 
01229     progressBar->setProgress( 0 );
01230     progressBar->setTotalSteps( webPres.slides1Steps() );
01231 
01232     webPres.createMainPage( progressBar );
01233 
01234     step4->setFont( f2 );
01235     progressBar->setProgress( progressBar->totalSteps() );
01236 }
01237 
01238 void KPrWebPresentationCreateDialog::setupGUI()
01239 {
01240     back = new QVBox( this );
01241     back->setMargin( KDialog::marginHint() );
01242 
01243     QFrame *line;
01244 
01245     line = new QFrame( back );
01246     line->setFrameStyle( QFrame::HLine | QFrame::Sunken );
01247     line->setMaximumHeight( 20 );
01248 
01249     step1 = new QLabel( i18n( "Initialize (create file structure, etc.)" ), back );
01250     step2 = new QLabel( i18n( "Create Pictures of the Slides" ), back );
01251     step3 = new QLabel( i18n( "Create HTML Pages for the Slides" ), back );
01252     step4 = new QLabel( i18n( "Create Main Page (Table of Contents)" ), back );
01253     step5 = new QLabel( i18n( "Options for Unattended Presentations" ), back);
01254 
01255     line = new QFrame( back );
01256     line->setFrameStyle( QFrame::HLine | QFrame::Sunken );
01257     line->setMaximumHeight( 20 );
01258 
01259     progressBar = new KProgress( back );
01260 
01261     line = new QFrame( back );
01262     line->setFrameStyle( QFrame::HLine | QFrame::Sunken );
01263     line->setMaximumHeight( 20 );
01264 
01265     KButtonBox *bb = new KButtonBox( back );
01266     bSave = bb->addButton( i18n( "Save Configuration..." ) );
01267     bb->addStretch();
01268     bDone = bb->addButton( i18n( "Done" ) );
01269 
01270     bSave->setEnabled( false );
01271     bDone->setEnabled( false );
01272 
01273     connect( bDone, SIGNAL( clicked() ), this, SLOT( accept() ) );
01274     connect( bSave, SIGNAL( clicked() ), this, SLOT( saveConfig() ) );
01275 }
01276 
01277 void KPrWebPresentationCreateDialog::resizeEvent( QResizeEvent *e )
01278 {
01279     QDialog::resizeEvent( e );
01280     back->resize( size() );
01281 }
01282 
01283 void KPrWebPresentationCreateDialog::saveConfig()
01284 {
01285     QString filename = webPres.getConfig();
01286     if ( QFileInfo( filename ).exists() )
01287         filename = QFileInfo( filename ).absFilePath();
01288     else
01289         filename = QString::null;
01290 
01291     KFileDialog fd (filename, i18n("*.kpweb|KPresenter Web-Presentation (*.kpweb)"),
01292                     0/*parent*/, 0/*name*/, true/*modal*/);
01293     fd.setCaption (i18n ("Save Web Presentation Configuration"));
01294     fd.setOperationMode (KFileDialog::Saving);
01295     fd.setMode (KFile::File | KFile::LocalOnly);
01296 
01297     if (fd.exec ())
01298     {
01299         webPres.setConfig( fd.selectedFile () );
01300         webPres.saveConfig();
01301     }
01302 }
01303 
01304 #include "KPrGradient.h"
01305 #include "KPrWebPresentation.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys