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

void Kallery::accept (  )  [protected, virtual, slot]

Called when Finish is pressed. Starts the generation, saves the project and exists the application.

Definition at line 243 of file kallery.cpp.

References KalleryFunctions::createHtmls(), OptionType::descList, OptionType::galleryCSSFile, OptionType::GenerateThumbnails, OptionType::imageCSSFile, OptionType::imageList, OptionType::LoadThumbnails, KalleryFunctions::makeRelativePath(), KalleryGlobals::options, progress, KalleryGlobals::projectFile(), KalleryFunctions::ref(), KalleryGlobals::ref(), KalleryFunctions::saveProject(), OptionType::thumbFormat, OptionType::thumbList, and KalleryFunctions::writeDescriptions().

{
  if (KalleryGlobals::ref()->options.relativePaths)
  {
    QString CSSDir;
    if (!KalleryGlobals::ref()->options.imageCSSFile.isEmpty())
    {
      CSSDir = QFileInfo(KalleryGlobals::ref()->options.imageCSSFile).dirPath();
      if (KalleryFunctions::ref()->makeRelativePath(KalleryGlobals::ref()->options.imageDestDir,CSSDir))
      {
        KalleryGlobals::ref()->options.imageCSSFile = CSSDir + QFileInfo(KalleryGlobals::ref()->options.imageCSSFile).fileName();
      }
    }
    if (!KalleryGlobals::ref()->options.galleryCSSFile.isEmpty())
    {
      CSSDir = QFileInfo(KalleryGlobals::ref()->options.galleryCSSFile).dirPath();
      if (KalleryFunctions::ref()->makeRelativePath(KalleryGlobals::ref()->projectBaseDir(),CSSDir))
      {
        KalleryGlobals::ref()->options.galleryCSSFile = CSSDir + QFileInfo(KalleryGlobals::ref()->options.galleryCSSFile).fileName();
      }
    }
    KalleryFunctions::ref()->makeRelativePath(KalleryGlobals::ref()->projectBaseDir(),KalleryGlobals::ref()->options.thumbDestDir);
    KalleryFunctions::ref()->makeRelativePath(KalleryGlobals::ref()->projectBaseDir(),KalleryGlobals::ref()->options.imageDestDir);
    if (KalleryGlobals::ref()->options.thumbSetting == OptionType::LoadThumbnails)
    {
      QString thumbDir;
      for (uint i = 0; i < KalleryGlobals::ref()->options.thumbList.count(); i++)
      {
        thumbDir = QFileInfo(KalleryGlobals::ref()->options.thumbList[i]).dirPath();
        KalleryFunctions::ref()->makeRelativePath(KalleryGlobals::ref()->projectBaseDir(),thumbDir);
        KalleryGlobals::ref()->options.thumbList[i] = thumbDir + QFileInfo(KalleryGlobals::ref()->options.thumbList[i]).fileName();
      }
    }
  }

  if (KalleryGlobals::ref()->options.thumbSetting == OptionType::GenerateThumbnails)
  {
    KalleryGlobals::ref()->options.thumbList.clear();
    for (uint i = 0; i < KalleryGlobals::ref()->options.imageList.count(); i++)
    {
      KalleryGlobals::ref()->options.thumbList.append(KalleryGlobals::ref()->options.thumbDestDir+QFileInfo(KalleryGlobals::ref()->options.imageList[i]).baseName()+"."+KalleryGlobals::ref()->options.thumbFormat);
    }
  }

  bool projectSaved = false;
  bool ok = false;
  while (!ok)
  {
    bool retry = false;
    QString projectFileName = KalleryGlobals::ref()->projectFile();
    if (projectFileName.isEmpty())
    {
      if (KMessageBox::questionYesNo(this,i18n("Do you want to save the project?"), i18n("Save project")) == KMessageBox::Yes)
      {
        projectFileName = KFileDialog::getSaveFileName(QFileInfo(KalleryGlobals::ref()->options.fileName).dirPath(),"*.kallery\n*|All files",this,i18n("Save project"));
        if (QFileInfo(projectFileName).exists())
        {
          if (KMessageBox::questionYesNo(this, i18n("<qt>The file <b>%1</b> exists.<br>Do you want to overwrite it?</qt>").arg(projectFileName), i18n("Overwrite project")) == KMessageBox::No)
          {
            projectFileName = "";
            ok = false;
            retry = true;
          }
        }
      } else
        projectFileName = "";
    } else
    {
      int choice = KMessageBox::questionYesNoCancel(this, i18n("Do you want to save the project?"), i18n("Save project"), KGuiItem(i18n("&Save"), BarIconSet("filesave")), KGuiItem(i18n("Save &as..."), BarIconSet("filesaveas")));
      if (choice == KMessageBox::No) //Save As
      {
        projectFileName = KFileDialog::getSaveFileName(QFileInfo(KalleryGlobals::ref()->options.fileName).dirPath(),"*.kallery\n*|All files",this,i18n("Save project"));

        if (QFileInfo(projectFileName).exists())
        {
          if (KMessageBox::questionYesNo(this, i18n("<qt>The file <b>%1</b> exists.<br>Do you want to overwrite it?</qt>").arg(projectFileName), i18n("Overwrite project")) == KMessageBox::No)
          {
            projectFileName = "";
            ok = false;
            retry = true;
          }
        }
      } else
      if (choice == KMessageBox::Cancel) // Do not save
        projectFileName = "";
    }
      
    if (!projectFileName.isEmpty())
    {
      if (QFileInfo(projectFileName).extension().isEmpty())
      {
        projectFileName += ".kallery";
      }
      ok = KalleryFunctions::ref()->saveProject(projectFileName);
      if (!ok)
      {
        if (KMessageBox::warningYesNo(this, i18n("There was an error when trying to save the project. Do you want to retry and possibly choose another location?"), i18n("Project Saving Error")) == KMessageBox::No)
          ok = true;
      } else
        projectSaved = true;
    } else
      if (!retry)
        ok = true; //do not save
  }
  
  progress = new QProgressDialog(i18n("Converting..."), i18n("Cancel"),
                                 2 * KalleryGlobals::ref()->options.imageList.count(), 
                                 this, "prg", true);
  progress->show();
  progress->setCaption(i18n("Converting..."));
  progress->setProgress(1);
  kapp->processEvents(QEventLoop::ExcludeSocketNotifiers);
  if (!KalleryFunctions::ref()->convertImages(progress))
  {
    delete progress;
    kapp->deref();
    DestroyMagick();
    return;
  }

  progress->setCaption(i18n("Creating web pages..."));
  progress->setLabelText("");
  KalleryFunctions::ref()->createHtmls(progress);

  if (projectSaved)
    KalleryFunctions::ref()->writeDescriptions(KalleryGlobals::ref()->projectBaseDir() + "/" + KalleryGlobals::ref()->options.descFile, KalleryGlobals::ref()->options.descList);

  delete progress;

  if (KMessageBox::questionYesNo(this,i18n("The image gallery was generated. Do you want to open it in your browser?"), i18n("Game over"), KGuiItem(i18n("&Open"), BarIconSet("konqueror")), KGuiItem(i18n("E&xit"), BarIconSet("no"))) == KMessageBox::Yes)
    kapp->invokeBrowser(KalleryGlobals::ref()->options.galleryFile, "");

  kapp->deref();
  DestroyMagick();
  KWizard::accept();
}


Generated by  Doxygen 1.6.0   Back to index