Logo Search packages:      
Sourcecode: kallery version File versions  Download package

void KalleryFunctions::createHtmls ( QProgressDialog *  progress  ) 

Create the gallery html and the htmls for the images, if needed.

Parameters:
progress pointer to the progress dialog

Definition at line 814 of file kalleryfunctions.cpp.

References OptionType::afterHtmlFile, OptionType::backColor, OptionType::backPic, OptionType::beforeHtmlFile, OptionType::columnNum, OptionType::Convert, convertEncodingName(), OptionType::convertImages, createHtmlForImage(), OptionType::descList, OptionType::encoding, OptionType::fullFormat, OptionType::fullsizeTemplate, OptionType::galleryCSSFile, OptionType::galleryFile, OptionType::galleryTemplateFile, OptionType::galleryTitle, OptionType::GenerateThumbnails, OptionType::imageDestDir, OptionType::imageList, insertFile(), OptionType::language, OptionType::LoadThumbnails, mainWidget, makeAbsolutePath(), OptionType::nextPic, OptionType::NoThumbnails, KalleryGlobals::options, OptionType::prevPic, OptionType::printToStdOut, KalleryGlobals::ref(), OptionType::tableColor, OptionType::textButtons, OptionType::textColor, OptionType::thumbDestDir, OptionType::thumbFormat, OptionType::thumbList, OptionType::thumbSetting, OptionType::useFrames, OptionType::useHtmlImages, and OptionType::visitedColor.

Referenced by Kallery::accept().

{
  QString tmpString;
  QString rowTemplate;
  QString baseName;
  QString fileName;
  KURL::List copySourceList;
  KURL::List copyDestList;
  QString languageString;
  OptionType options = KalleryGlobals::ref()->options;
  QString galleryTemplateFilename = options.galleryTemplateFile;
  QString galleryFilename = options.galleryFile;
  QFile templateFile;
  QFile galleryFile;
  QString mainFrameFileName;

  kdDebug() << "Creating the htmls." << endl;

  bool printToStdOut = KalleryGlobals::ref()->options.printToStdOut;
  languageString = options.language;
  languageString = languageString.mid(languageString.find('(')+1,10);
  languageString.truncate(languageString.find(')'));

  kdDebug() << "The gallery template files is: " << galleryTemplateFilename << endl;
  kdDebug() << "The fullsize template files is: " << options.fullsizeTemplate << endl;

  /*Start to build up the gallery html file, using the template*/
  templateFile.setName(galleryTemplateFilename);
  if (!templateFile.open(IO_ReadOnly))
  {
    KMessageBox::error(mainWidget,i18n("Cannot open the template file %1 for reading.").arg(galleryTemplateFilename),i18n("Input/Output error"));
    return;
  }
  
  QTextStream str(&templateFile);
  str.setEncoding(QTextStream::UnicodeUTF8);
  while (!str.atEnd())
  {
    tmpString = str.readLine();
    if (tmpString.contains("MAINFRAMEFILE="))
    {
      options.useFrames = true;
      KalleryGlobals::ref()->options.useFrames = true;
      mainFrameFileName = tmpString.replace("MAINFRAMEFILE=", "").stripWhiteSpace();
      break;
    }
  }
  templateFile.close();
  if (options.useFrames)
  {
    galleryFilename = QFileInfo(options.galleryFile).dirPath() + "/gallery_frame.html";

    copySourceList.append(KalleryGlobals::ref()->baseDir() + "htmls/" + mainFrameFileName);
    copyDestList.append(options.galleryFile);
    copySourceList.append(KalleryGlobals::ref()->baseDir() + "htmls/description.html");
    copyDestList.append(QFileInfo(options.galleryFile).dirPath() + "/description.html");
  }

  /*Copy the next, previous and back button images to the image directory*/

  if (!options.textButtons)
  {
    tmpString = options.imageDestDir;
    makeAbsolutePath(QFileInfo(options.galleryFile).dirPath(),tmpString);
    if (QFileInfo(options.prevPic).exists())
    {
      copySourceList.append(options.prevPic);
      if (!options.prevPic.contains(languageString))
      {
        KalleryGlobals::ref()->options.prevPic = tmpString + QFileInfo(options.prevPic).baseName()+"_"+
                         languageString + "."+ QFileInfo(options.prevPic).extension();
      }
      else
      {
        KalleryGlobals::ref()->options.prevPic = tmpString + QFileInfo(options.prevPic).fileName();
      }
      copyDestList.append(KalleryGlobals::ref()->options.prevPic);
    }
    if (QFileInfo(options.nextPic).exists())
    {
      copySourceList.append(options.nextPic);
      if (!options.nextPic.contains(languageString))
      {
        KalleryGlobals::ref()->options.nextPic = tmpString + QFileInfo(options.nextPic).baseName()+"_"+
                        languageString + "."+ QFileInfo(options.nextPic).extension();
      }
      else
      {
        KalleryGlobals::ref()->options.nextPic = tmpString + QFileInfo(options.nextPic).fileName();
      }
      copyDestList.append(KalleryGlobals::ref()->options.nextPic);
    }
    if (QFileInfo(options.backPic).exists())
    {
      copySourceList.append(options.backPic);
      if (!options.backPic.contains(languageString))
      {
        KalleryGlobals::ref()->options.backPic = tmpString + QFileInfo(options.backPic).baseName()+"_"+
                        languageString + "."+ QFileInfo(options.backPic).extension();
      }
      else
      {
        KalleryGlobals::ref()->options.backPic = tmpString + QFileInfo(options.backPic).fileName();
      }
      copyDestList.append(KalleryGlobals::ref()->options.backPic);
    }
  }

  for (uint i = 0; i < copySourceList.count(); i++)
  {
    if (copySourceList[i] != copyDestList[i])
    {
      KIO::Job* job= KIO::file_copy(copySourceList[i],copyDestList[i],-1,true,true,false);
      connect( job, SIGNAL( result( KIO::Job * ) ), mainWidget, SLOT( slotResult( KIO::Job * ) ) );
      kapp->ref();
      if (printToStdOut)
        printf("%s\n",copyDestList[i].path().latin1());
    }
  }
  
  templateFile.setName(galleryTemplateFilename);
  if (!templateFile.open(IO_ReadOnly))
  {
    KMessageBox::error(mainWidget,i18n("Cannot open the template file %1 for reading.").arg(galleryTemplateFilename),i18n("Input/Output error"));
    return;
  }

  galleryFile.setName(galleryFilename);
  if (!galleryFile.open(IO_WriteOnly))
  {
    KMessageBox::error(mainWidget,i18n("Cannot open the gallery file %1 for writing.").arg(galleryFilename),i18n("Input/Output error"));
    templateFile.close();
    return;
  }

  if (printToStdOut)
    printf("%s,[MAIN GALLERY]\n",galleryFilename.latin1());

  QTextStream galleryTemplateStream(&templateFile);
  QTextStream galleryFileStream(&galleryFile);

  galleryTemplateStream.setEncoding(QTextStream::UnicodeUTF8);
  galleryFileStream.setCodec(QTextCodec::codecForName(options.encoding));

  while (! galleryTemplateStream.atEnd())
  {
    tmpString = galleryTemplateStream.readLine();
    tmpString.replace(QRegExp("%TITLE%"),options.galleryTitle);
    tmpString.replace(QRegExp("%BACKCOLOR%"),options.backColor.name());
    tmpString.replace(QRegExp("%TABLECOLOR%"),options.tableColor.name());
    tmpString.replace(QRegExp("%TEXTCOLOR%"),options.textColor.name());
    tmpString.replace(QRegExp("%VISITEDCOLOR%"),options.visitedColor.name());
    tmpString.replace(QRegExp("%CSSFILE%"),options.galleryCSSFile);
    tmpString.replace(QRegExp("%CHARSET%"),convertEncodingName(options.encoding));
    /*copy the content of options.beforeHtmlFile to the gallery html*/
    if (tmpString.contains("Html formatted text before the table"))
    {
      insertFile(options.beforeHtmlFile,galleryFileStream);
      tmpString = "";
    }
    /*copy the content of options.afterHtmlFile to the gallery html*/
    if (tmpString.contains("Html formatted text after the table"))
    {
      insertFile(options.afterHtmlFile,galleryFileStream);
      tmpString = "";
    }
    /*Start to build the tables */
    if (tmpString.contains("Table begins here"))
    {
      rowTemplate = galleryTemplateStream.readLine();

      for (uint i=0; i < options.imageList.count(); i++)
      {
        progress->setProgress(i+1+options.imageList.count());
        if ( (options.columnNum !=0) && (i % options.columnNum) == 0)
        {
          galleryFileStream << "<tr>\n";
        }

        tmpString = rowTemplate;
        baseName =  options.imageDestDir+ QFileInfo(options.imageList[i]).baseName() + "_" + languageString + ".";
        /*If we don't convert the images, we must keep the original extension of them,
        otherwise we must replace the extension with the options.fullFormat*/
        if (options.convertImages == OptionType::Convert)
        {
          fileName =  QFileInfo(options.imageList[i]).baseName()+"."+options.fullFormat;
        }
        else
        {
          fileName =  QFileInfo(options.imageList[i]).fileName();
        }

        if (options.useHtmlImages)
        {
          tmpString.replace(QRegExp("%IMAGEREF%"),baseName+"html");
          tmpString.replace(QRegExp("%MIMETYPE%"),"text/html");
          createHtmlForImage(i,baseName+"html",languageString);
        }
        else
        {
          tmpString.replace(QRegExp("%IMAGEREF%"),options.imageDestDir +fileName);
          tmpString.replace(QRegExp("%MIMETYPE%"),"image/"+QFileInfo(fileName).extension());
        }

        /*What to do, if there is no thumbnail used...*/
        if (options.thumbSetting == OptionType::NoThumbnails)
        {
          tmpString.replace(QRegExp("<img src=\"%IMAGESRC%\" alt=\"%ALTNAME%\" border=0><br>"),"");
        }
        /*...and when they are generated...*/
        if (options.thumbSetting == OptionType::GenerateThumbnails)
        {
          tmpString.replace(QRegExp("%IMAGESRC%"),options.thumbDestDir+
                             QFileInfo(options.imageList[i]).baseName()+"."+options.thumbFormat);
        }
        /*...and when we use an already generated thumbnail list.*/
        if (options.thumbSetting == OptionType::LoadThumbnails)
        {
          tmpString.replace(QRegExp("%IMAGESRC%"),options.thumbList[i]);
        }

        tmpString.replace(QRegExp("%ALTNAME%"),fileName);
        tmpString.replace(QRegExp("%IMAGENAME%"), QFileInfo(fileName).fileName());
        tmpString.replace(QRegExp("%IMAGEDESC%"),options.descList[i].full());
        tmpString.replace(QRegExp("%COMMENT%"),options.descList[i].comment);
        tmpString.replace(QRegExp("%FILESIZE%"),options.descList[i].fileSize);
        tmpString.replace(QRegExp("%DIMENSION%"),options.descList[i].dimension);
        tmpString.replace(QRegExp("%DATE%"),options.descList[i].shootingDate);
        tmpString.replace(QRegExp("%EXPOSURE%"),options.descList[i].exposureInfo);    
        if ( (options.columnNum !=0) && ((i+1) % options.columnNum) == 0)
          tmpString += "\n</tr>";
        galleryFileStream << tmpString << "\n";
      }
      if ( (options.columnNum !=0) && (options.imageList.count() % options.columnNum) != 0)
        galleryFileStream <<  "</tr>\n";
      tmpString = "";
    }
    galleryFileStream << tmpString << "\n";
  }
  
  templateFile.close();
  galleryFile.close();
  
  if (options.useFrames)
  {
    QFile mainFrameFile(options.galleryFile);
    if (mainFrameFile.open(IO_ReadOnly))
    {
      QTextStream str(&mainFrameFile);
      str.setEncoding(QTextStream::UnicodeUTF8);
      QString s = str.read();
      s.replace(QRegExp("%TITLE%"),options.galleryTitle);
      mainFrameFile.close();
      if (mainFrameFile.open(IO_WriteOnly))
      { 
        QTextStream str2(&mainFrameFile);
        str2.setEncoding(QTextStream::UnicodeUTF8);
        str2 << s;
        mainFrameFile.close();
      }
    }
    
  }


  kdDebug() << "Html generation successful." << endl;
}


Generated by  Doxygen 1.6.0   Back to index