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

void KalleryFunctions::createHtmlForImage ( uint  imageIndex,
const QString &  htmlName,
const QString &  language 
) [private]

Creates a html file with the image and the navigation buttons.

Parameters:
imageIndex the index of the image in the list
htmlName the name of the html file to be created
language the language used for descriptions

Definition at line 662 of file kalleryfunctions.cpp.

References OptionType::backPic, OptionType::backStr, OptionType::Convert, convertEncodingName(), OptionType::convertImages, OptionType::CopyOnly, OptionType::descList, OptionType::encoding, OptionType::fullFormat, OptionType::fullsizeTemplateFile, OptionType::galleryFile, OptionType::imageBackColor, OptionType::imageCSSFile, OptionType::imageDestDir, OptionType::imageList, OptionType::imageTextColor, OptionType::imageVisitedColor, mainWidget, makeAbsolutePath(), makeRelativePath(), OptionType::nextPic, OptionType::nextStr, OptionType::NoCopyConvert, KalleryGlobals::options, OptionType::prevPic, OptionType::prevStr, OptionType::printToStdOut, KalleryGlobals::ref(), OptionType::relativePaths, OptionType::textButtons, OptionType::UseExisting, and OptionType::useFrames.

Referenced by createHtmls().

{
  QFile templateFile;
  QFile htmlFile;
  OptionType options = KalleryGlobals::ref()->options;
  QString templateFilename =  options.fullsizeTemplateFile;
  QString htmlFilename;
  QString tmpString;
  QString prevRef;
  QString prevButton;
  QString nextRef;
  QString nextButton;
  QString backRef;
  QString backButton;
  QString backTarget;
  QString imageFileName;
  
  bool printToStdOut = KalleryGlobals::ref()->options.printToStdOut;

  switch (options.convertImages)
  {
    case OptionType::NoCopyConvert:
      imageFileName = options.imageList[imageIndex];
      break;
    case OptionType::CopyOnly:
    case OptionType::UseExisting:
      imageFileName = QFileInfo(options.imageList[imageIndex]).baseName() + "." + QFileInfo(options.imageList[imageIndex]).extension().lower();
      break;
    case OptionType::Convert:
      imageFileName = QFileInfo(options.imageList[imageIndex]).baseName()+"."+options.fullFormat;
      break;
  }

  tmpString = QFileInfo(htmlName).dirPath();
  makeAbsolutePath(QFileInfo(options.galleryFile).dirPath(),tmpString);
  htmlFilename = tmpString+QFileInfo(htmlName).fileName();

  /*Create the next and/or previous text or bitmap buttons, if needed */
  if (imageIndex > 0)
  {
    prevRef = QFileInfo(options.imageList[imageIndex-1]).baseName()+"_"+language+".html";
    if (! options.textButtons)
    {
      if (!options.prevPic.isEmpty())
        prevButton="<img src=\""+QFileInfo(options.prevPic).fileName() +"\" align=\"middle\" alt=\""+options.prevStr+"\" border=0>";
    }
    else
    {
      prevButton = options.prevStr;
    }
  }
  if (imageIndex+1 < options.imageList.count())
  {
    nextRef = QFileInfo(options.imageList[imageIndex+1]).baseName()+"_"+language+".html";
    if (! options.textButtons)
    {
      if (!options.nextPic.isEmpty())
        nextButton="<img src=\""+QFileInfo(options.nextPic).fileName() +"\" align=\"middle\" alt=\""+options.nextStr+"\" border=0>";
    }
    else
    {
      nextButton = options.nextStr;
    }
  }

  /*Set the back button or text*/
  tmpString = options.imageDestDir;
  makeAbsolutePath(QFileInfo(options.galleryFile).dirPath(),tmpString);
  QString tmpString2;
  tmpString2 =  QFileInfo(options.galleryFile).dirPath() + "/";
  if (options.relativePaths)
    makeRelativePath(tmpString,tmpString2);
  backRef = tmpString2 + QFileInfo(options.galleryFile).fileName();

  if (! options.textButtons)
  {
    if (!options.backPic.isEmpty())
      backButton="<img src=\""+QFileInfo(options.backPic).fileName() +"\" align=\"middle\" alt=\""+options.backStr+"\" border=0>";
  }
  else
  {
    backButton = options.backStr;
  }

  if (options.useFrames)
  {
    backTarget = "_parent";
  }
  else
  {
    backTarget = "_self";
  }

  /*Start to build the html, using the selected fullsize template*/
  templateFile.setName(templateFilename);
  if (!templateFile.open(IO_ReadOnly))
  {
    KMessageBox::error(mainWidget,i18n("Cannot open the template file %1 for reading.").arg(templateFilename),i18n("Input/Output error"));
    return;
  }
  htmlFile.setName(htmlFilename);
  if (!htmlFile.open(IO_WriteOnly))
  {
    KMessageBox::error(mainWidget,i18n("Cannot open the file %1 for writing.").arg(htmlFilename),i18n("Input/Output error"));
    templateFile.close();
    return;
  }

  if (printToStdOut)
    printf("%s\n", htmlFilename.latin1());

  QTextStream templateFileStream(&templateFile);
  QTextStream htmlFileStream(&htmlFile);
  templateFileStream.setEncoding(QTextStream::UnicodeUTF8);
  htmlFileStream.setCodec(QTextCodec::codecForName(options.encoding));

  while (! templateFileStream.atEnd())
  {
    tmpString = templateFileStream.readLine();

    tmpString.replace(QRegExp("%CSSFILE%"),options.imageCSSFile);
    tmpString.replace(QRegExp("%BACKCOLOR%"),options.imageBackColor.name());
    tmpString.replace(QRegExp("%TEXTCOLOR%"),options.imageTextColor.name());
    tmpString.replace(QRegExp("%VISITEDCOLOR%"),options.imageVisitedColor.name());
    tmpString.replace(QRegExp("%TITLE%"),imageFileName);
    tmpString.replace(QRegExp("%IMAGENAME%"),imageFileName);
    tmpString.replace(QRegExp("%IMAGEDESC%"),options.descList[imageIndex].full());
    tmpString.replace(QRegExp("%COMMENT%"),options.descList[imageIndex].comment);
    tmpString.replace(QRegExp("%FILESIZE%"),options.descList[imageIndex].fileSize);
    tmpString.replace(QRegExp("%DIMENSION%"),options.descList[imageIndex].dimension);
    tmpString.replace(QRegExp("%DATE%"),options.descList[imageIndex].shootingDate);
    tmpString.replace(QRegExp("%EXPOSURE%"),options.descList[imageIndex].exposureInfo);    tmpString.replace(QRegExp("%IMAGENAME%"),imageFileName);
    tmpString.replace(QRegExp("%CHARSET%"),convertEncodingName(options.encoding));
    tmpString.replace(QRegExp("%PREVREF%"),prevRef);
    tmpString.replace(QRegExp("%PREVNAME%"),options.prevStr);
    tmpString.replace(QRegExp("%PREVBUTTON%"),prevButton);

    tmpString.replace(QRegExp("%NEXTREF%"),nextRef);
    tmpString.replace(QRegExp("%NEXTNAME%"),options.nextStr);
    tmpString.replace(QRegExp("%NEXTBUTTON%"),nextButton);

    tmpString.replace(QRegExp("%BACKREF%"),backRef);
    tmpString.replace(QRegExp("%BACKNAME%"),options.backStr);
    tmpString.replace(QRegExp("%BACKBUTTON%"),backButton);
    tmpString.replace(QRegExp("%BACKTARGET%"),backTarget);
    htmlFileStream << tmpString << "\n";
  }

  templateFile.close();
  htmlFile.close();
}


Generated by  Doxygen 1.6.0   Back to index