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

bool KalleryFunctions::openProject ( const QString &  projectFileName  ) 

Load the project from a file.

Parameters:
projectFileName points to the project file
Returns:
true in case of success, false in case of failure

Definition at line 326 of file kalleryfunctions.cpp.

References OptionType::afterHtmlFile, OptionType::backColor, OptionType::backPic, OptionType::backStr, OptionType::beforeHtmlFile, OptionType::columnNum, OptionType::Convert, OptionType::convertImages, OptionType::copyright, OptionType::descFile, OptionType::descList, OptionType::descSetting, OptionType::encoding, OptionType::fileName, OptionType::fullFormat, OptionType::fullHeight, OptionType::fullsizeTemplate, OptionType::fullWidth, OptionType::galleryCSSFile, OptionType::galleryFile, OptionType::galleryTemplate, OptionType::galleryTitle, OptionType::GenerateThumbnails, OptionType::imageBackColor, OptionType::imageCSSFile, OptionType::imageDestDir, OptionType::ImageInfoFileName, OptionType::imageList, OptionType::imageTextColor, OptionType::imageVisitedColor, OptionType::infoSetting, OptionType::insertCopyright, OptionType::keepRatio, OptionType::language, OptionType::LoadImageInfo, mainWidget, makeAbsolutePath(), OptionType::nextPic, OptionType::nextStr, OptionType::onlyLarger, KalleryGlobals::options, OptionType::prevPic, OptionType::prevStr, OptionType::projectFileName, OptionType::quality, readDescriptions(), KalleryGlobals::ref(), OptionType::relativePaths, OptionType::resize, OptionType::tableColor, OptionType::textButtons, OptionType::textColor, OptionType::thumbDestDir, OptionType::thumbFormat, OptionType::thumbHeight, OptionType::thumbList, OptionType::thumbSetting, OptionType::thumbWidth, OptionType::useHtmlImages, and OptionType::visitedColor.

Referenced by FirstPage::slotOpenProject().

{
  QFile projectFile;
  KSimpleConfig *config;
  OptionType options = KalleryGlobals::ref()->options;

  projectFile.setName(projectFileName);
  if ( (! projectFile.open(IO_ReadOnly)) ||  (!projectFile.exists()) )
  {
    KMessageBox::error(mainWidget,i18n("Cannot open the project file %1.\nSelect another file and try again.").arg(projectFileName),i18n("Error"));
    return false;
  }
  projectFile.close();

  config = new KSimpleConfig(projectFileName,false);
  config->setGroup("General");
  QString version = config->readEntry("kallery_version");
  if ((version == 0)  || (version != "Project_Format_1"))
  {
    KMessageBox::error(mainWidget,i18n("The file %1 is not a valid Kallery project.\nSelect another file and try again.").arg(projectFileName),i18n("Error"));
    return false;
  }
  options.encoding = config->readEntry("Encoding", "utf8");
  options.relativePaths = config->readBoolEntry("RelativePaths",true);
  options.projectFileName = QFileInfo(projectFileName).dirPath() + "/"+config->readEntry("ProjectName");
  options.fileName = projectFileName;

  config->setGroup("Gallery");
  options.galleryTitle = config->readEntry("GalleryTitle",i18n("Image gallery"));
  options.galleryFile =  config->readPathEntry("GalleryFile",QDir::currentDirPath() + "/myGallery/gallery.html");
  options.imageDestDir = config->readPathEntry("ImageDestDir",QDir::currentDirPath() + "/myGallery/fullsize");
  options.thumbDestDir = config->readPathEntry("ThumbDestDir",QDir::currentDirPath() + "/myGallery/thumbs");
  options.language = config->readEntry("Language", "United Kindom (gb)");

  config->setGroup("Thumbnails");
  options.thumbSetting = (OptionType::ThumbSettings) config->readUnsignedNumEntry("ThumbSetting", OptionType::GenerateThumbnails);
  options.thumbWidth = config->readUnsignedNumEntry("ThumbWidth", 100);
  options.thumbHeight = config->readUnsignedNumEntry("ThumbHeight", 75);
  options.thumbFormat = config->readEntry("ThumbFormat", "jpg");
  options.thumbList = config->readListEntry("ThumbList");

  config->setGroup("Images");
  options.convertImages =(OptionType::ConvertMode) config->readUnsignedNumEntry("ConvertImages", OptionType::Convert);
  options.resize = config->readBoolEntry("Resize", true);
  options.keepRatio = config->readBoolEntry("KeepRatio", true);
  options.onlyLarger = config->readBoolEntry("OnlyLarger", true);
  options.fullWidth = config->readUnsignedNumEntry("FullWidth", 600);
  options.fullHeight = config->readUnsignedNumEntry("FullHeight", 450);
  options.insertCopyright = config->readBoolEntry("InsertCopyright", true);
  options.copyright = config->readEntry("Copyright"," " + i18n("This year, You"));
  options.fullFormat = config->readEntry("FullFormat","jpg");
  options.quality = config->readUnsignedNumEntry("Quality", 80);
  options.imageList = config->readListEntry("ImageList");

  config->setGroup("HTML options");
  options.columnNum = config->readUnsignedNumEntry("ColumnNum",3);
  options.useHtmlImages = config->readBoolEntry("UseHtmlImages",true);
  options.textButtons = config->readBoolEntry("TextButtons",true);
  options.nextStr = config->readEntry("NextStr", i18n("Next"));
  options.prevStr = config->readEntry("PrevStr", i18n("Previous"));
  options.backStr = config->readEntry("BackStr", i18n("Back"));
  options.nextPic = config->readPathEntry("NextPic",KalleryGlobals::ref()->baseDir() + "images/next.png");
  options.prevPic = config->readPathEntry("PrevPic",KalleryGlobals::ref()->baseDir() + "images/prev.png");
  options.backPic = config->readPathEntry("BackPic", KalleryGlobals::ref()->baseDir() + "images/back.png");
  options.backColor.setNamedColor(config->readEntry("BackColor","#000000"));
  options.tableColor.setNamedColor(config->readEntry("TableColor","#000000"));
  options.textColor.setNamedColor(config->readEntry("TextColor","#FFFFFF"));
  options.visitedColor.setNamedColor(config->readEntry("VisitedColor","#AAAAAA"));
  options.imageBackColor.setNamedColor(config->readEntry("ImageBackColor","#000000"));
  options.imageTextColor.setNamedColor(config->readEntry("ImageTextColor","#FFFFFF"));
  options.imageVisitedColor.setNamedColor(config->readEntry("ImageVisitedColor","#AAAAAA"));
  options.fullsizeTemplate = config->readEntry("FullsizeTemplate",i18n("Buttons above the image"));
  options.galleryTemplate = config->readEntry("GalleryTemplate",i18n("Default template"));
  options.galleryCSSFile = config->readPathEntry("GalleryCSSFile");
  options.beforeHtmlFile = config->readPathEntry("BeforeHtmlFile");
  options.afterHtmlFile = config->readPathEntry("AfterHtmlFile");
  options.imageCSSFile = config->readPathEntry("ImageCSSFile");

  config->setGroup("Descriptions");
  options.descSetting = (OptionType::DescSettings)config->readUnsignedNumEntry("DescSetting", OptionType::LoadImageInfo);
  options.infoSetting = config->readUnsignedNumEntry("InfoSetting", OptionType::ImageInfoFileName);
  options.descFile = config->readPathEntry("DescFile");
  readDescriptions(QFileInfo(projectFileName).dirPath()+"/"+options.descFile, options.descList);

  for (uint i = options.descList.count(); i < options.imageList.count(); i ++)
  {
    options.descList.append(OptionType::Description());
  }

  if (options.relativePaths)
  {
    QString baseDir = QFileInfo(options.galleryFile).dirPath();
    QString CSSDir;
    makeAbsolutePath(baseDir,options.imageDestDir);
    makeAbsolutePath(baseDir,options.thumbDestDir);
    if (!options.galleryCSSFile.isEmpty())
    {
      CSSDir = QFileInfo(options.galleryCSSFile).dirPath();
      if (makeAbsolutePath(baseDir,CSSDir))
      {
        options.galleryCSSFile = CSSDir + QFileInfo(options.galleryCSSFile).fileName();
      }
    }
    if (!options.imageCSSFile.isEmpty())
    {
      CSSDir = QFileInfo(options.imageCSSFile).dirPath();
      if (makeAbsolutePath(options.imageDestDir,CSSDir))
      {
        options.imageCSSFile = CSSDir + QFileInfo(options.imageCSSFile).fileName();
      }
    }

    QString thumbDir;
    for (uint i=0; i < options.thumbList.count(); i++)
    {
      thumbDir = QFileInfo(options.thumbList[i]).dirPath();
      makeAbsolutePath(baseDir,thumbDir);
      options.thumbList[i] = thumbDir + QFileInfo(options.thumbList[i]).fileName();
    }
  }
  delete config;
  KalleryGlobals::ref()->options = options;
  return true;
}


Generated by  Doxygen 1.6.0   Back to index