Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [C++] Modificare azione che nomina i file .html

    ho un file .cpp che dice al suo interno come trasformare dei dati presenti in un programma.

    Questo codice produce una pagina web principale e tante pagine contenti i diversi oggetti che ha in lista da esportare.
    Ora io vorrei fare assegnare al programma un nome basto invece che sulla variabile "title" su quella "ID"

    Questo è il codice che devo modificare

    codice:
    bool HTMLExporter::writeEntryFiles() {
      if(m_entryXSLTFile.isEmpty()) {
        myWarning() << "no entry XSLT file";
        return false;
      }
    
      const int start = 60;
      const int stepSize = qMax(1, entries().count()/40);
      int j = 0;
    
      // now worry about actually exporting entry files
      // I can't reliable encode a string as a URI, so I'm punting, and I'll just replace everything but
      // a-zA-Z0-9 with an underscore. This MUST match the filename template in tellico2html.xsl
      // the id is used so uniqueness is guaranteed
      const QRegExp badChars(QLatin1String("[^-a-zA-Z0-9]"));
      FieldFormat::Request formatted = (options() & Export::ExportFormatted ?
                                                       FieldFormat::ForceFormat :
                                                       FieldFormat::AsIsFormat);
    
      KUrl outputFile = fileDir();
    
      GUI::CursorSaver cs(Qt::WaitCursor);
    
      HTMLExporter exporter(collection());
      long opt = options() | Export::ExportForce;
      opt &= ~ExportProgress;
      exporter.setOptions(opt);
      exporter.setXSLTFile(m_entryXSLTFile);
      exporter.setCollectionURL(url());
      bool parseDOM = true;
    
      const QString title = QLatin1String("title");
      const QString html = QLatin1String(".html");
      bool multipleTitles = collection()->fieldByName(title)->hasFlag(Data::Field::AllowMultiple);
      Data::EntryList entries = this->entries(); // not const since the pointer has to be copied
      foreach(Data::EntryPtr entryIt, entries) {
        QString file = entryIt->formattedField(title, formatted);
    
        // but only use the first title if it has multiple
        if(multipleTitles) {
          file = file.section(QLatin1Char(';'), 0, 0);
        }
        file.replace(badChars, QLatin1String("_"));
        file += QLatin1Char('-') + QString::number(entryIt->id()) + html;
        outputFile.setFileName(file);
    
        exporter.setEntries(Data::EntryList() << entryIt);
        exporter.setURL(outputFile);
        exporter.exec();
    
        // no longer need to parse DOM
        if(parseDOM) {
          parseDOM = false;
          exporter.setParseDOM(false);
          // this is rather stupid, but I'm too lazy to figure out the better way
          // since we parsed the DOM for the first entry file to grab any
          // images used in the template, need to resave it so the image links
          // get written correctly
          exporter.exec();
        }
    
        if(j%stepSize == 0) {
          if(options() & ExportProgress) {
            ProgressManager::self()->setProgress(this, qMin(start+j/stepSize, 99));
          }
          kapp->processEvents();
        }
        ++j;
      }
      // the images in "pics/" are special data images, copy them always
      // since the entry files may refer to them, but we don't know that
      QStringList dataImages;
      dataImages << QLatin1String("checkmark.png");
      for(uint i = 1; i <= 10; ++i) {
        dataImages << QString::fromLatin1("stars%1.png").arg(i);
      }
      KUrl dataDir;
      dataDir.setPath(KGlobal::dirs()->findResourceDir("appdata", QLatin1String("pics/tellico.png")) + QLatin1String("pics/"));
      KUrl target = fileDir();
      target.addPath(QLatin1String("pics/"));
      KIO::NetAccess::mkdir(target, m_widget);
      foreach(const QString& dataImage, dataImages) {
        dataDir.setFileName(dataImage);
        target.setFileName(dataImage);
        KIO::NetAccess::file_copy(dataDir, target, m_widget);
      }
    Qualcuno riesce a farmi capire cosa devo cambiare

    PS questo naturalmente è parte del file intero.

  2. #2
    up

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.