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

void YzisSyntaxDocument::setupModeList ( bool  force  )  [private]

Generate the list of hl modes, store them in myModeList force: if true forces to rebuild the Mode List from the xml files (instead of katesyntax...rc)

force if true forces to rebuild the Mode List from the xml files (instead of katesyntax...rc)
Generate the list of hl modes, store them in myModeList force: if true forces to rebuild the Mode List from the xml files (instead of configfile)

Definition at line 547 of file syntaxdocument.cpp.

References YzisSyntaxModeListItem::author, YzisSyntaxModeListItem::extension, YResourceMgr::findResource(), YSession::getOptions(), YInternalOptionPool::hasGroup(), YzisSyntaxModeListItem::hidden, YzisSyntaxModeListItem::identifier, YzisSyntaxModeListItem::license, YzisSyntaxModeListItem::mimetype, myModeList, YzisSyntaxModeListItem::name, YzisSyntaxModeListItem::nameTranslated, YzisSyntaxModeListItem::priority, YInternalOptionPool::readBoolEntry(), YInternalOptionPool::readIntEntry(), YInternalOptionPool::readQStringEntry(), YResourceMgr::resourceDirList(), resourceMgr(), YInternalOptionPool::saveTo(), YzisSyntaxModeListItem::section, YSession::self(), YInternalOptionPool::setBoolEntry(), YInternalOptionPool::setGroup(), YInternalOptionPool::setIntEntry(), YInternalOptionPool::setQStringEntry(), SyntaxHlResource, YzisSyntaxModeListItem::version, and WritableConfigResource.

Referenced by YzisSyntaxDocument().

  // If there's something in myModeList the Mode List was already built so, don't do it again
  if (!myModeList.isEmpty())

  // We'll store the ModeList in katesyntaxhighlightingrc
  //KConfig config("katesyntaxhighlightingrc", false, false);
  YInternalOptionPool* config = YSession::self()->getOptions();

  // figure our if the kate install is too new
  config->setGroup ("General");
  if (config->readIntEntry ("Version") > config->readIntEntry ("CachedVersion"))
    config->setIntEntry ("CachedVersion", config->readIntEntry ("Version"));
    force = true;

  // Let's get a list of all the xml files for hl
  QStringList resourceDirList = resourceMgr()->resourceDirList( SyntaxHlResource );
  QStringList list;
  foreach( QString resourceDir, resourceDirList ) {
        list += findAllResources("data", resourceDir + "/*.xml",false,true);

  deepdbg() << "setupModeList(): syntax file list = " << list.join("\n") << endl;

  // Let's iterate through the list and build the Mode List
  QStringList::Iterator it = list.begin(), end = list.end();
  for ( ; it != end; ++it )
    deepdbg() << "setupModeList(): analysing resource " << *it << endl;
    // Each file has a group called:
    QString Group="HL Cache "+ *it;

      // Let's go to this group

    // stat the file
    struct stat sbuf;
    memset (&sbuf, 0, sizeof(sbuf));
    stat(QFile::encodeName(*it), &sbuf);

    // If the group exist and we're not forced to read the xml file, let's build myModeList for katesyntax..rc
    if ( config->hasGroup(Group) && !force && (sbuf.st_mtime == config->readIntEntry("lastModified")) )
      // Let's make a new YzisSyntaxModeListItem to instert in myModeList from the information in katesyntax..rc
      YzisSyntaxModeListItem *mli=new YzisSyntaxModeListItem;
      mli->name       = config->readQStringEntry("name");
      mli->nameTranslated = _(mli->name.toUtf8());
      mli->section    = config->readQStringEntry("section").toUtf8();
      mli->mimetype   = config->readQStringEntry("mimetype");
      mli->extension  = config->readQStringEntry("extension");
      mli->version    = config->readQStringEntry("version");
      mli->priority   = config->readQStringEntry("priority");
      mli->author    = config->readQStringEntry("author");
      mli->license   = config->readQStringEntry("license");
      mli->hidden   =  config->readBoolEntry("hidden");
      mli->identifier = *it;

      // Apend the item to the list
      deepdbg() << "NO update hl cache for: " << *it << endl;
      deepdbg() << "UPDATE hl cache for: " << *it << endl;

      // We're forced to read the xml files or the mode doesn't exist in the katesyntax...rc
      QFile f(*it);

      if (f.open(QIODevice::ReadOnly))
        // Ok we opened the file, let's read the contents and close the file
        /* the return of setContent should be checked because a false return shows a parsing error */
        QString errMsg;
        int line, col;

        bool success = setContent(&f,&errMsg,&line,&col);


        if (success)
          QDomElement root = documentElement();

          if (!root.isNull())
            // If the 'first' tag is language, go on
            if (root.tagName()=="language")
              // let's make the mode list item.
              YzisSyntaxModeListItem *mli = new YzisSyntaxModeListItem;

              mli->name      = root.attribute("name");
              mli->section   = root.attribute("section");
              mli->mimetype  = root.attribute("mimetype");
              mli->extension = root.attribute("extensions");
              mli->version   = root.attribute("version");
              mli->priority  = root.attribute("priority");
              mli->author    = root.attribute("author");
              mli->license   = root.attribute("license");

              QString hidden = root.attribute("hidden");
              mli->hidden    = (hidden == "true" || hidden == "TRUE");

              mli->identifier = *it;

              // Now let's write or overwrite (if force==true) the entry in katesyntax...rc

              // modified time to keep cache in sync
              config->setIntEntry("lastModified", sbuf.st_mtime);

              // Now that the data is in the config file, translate section
                    mli->section    = _( "Language Section"); // We need the i18n context for when reading again the config
              mli->nameTranslated = _(mli->name.toUtf8());

              // Append the new item to the list.
          YzisSyntaxModeListItem *emli=new YzisSyntaxModeListItem;

          emli->section=_( "Errors!" );
          emli->name=QString ("Error: %1").arg(*it); // internal
          emli->nameTranslated=QString("Error: %1").arg(*it); // translated

  QString resource = resourceMgr()->findResource( WritableConfigResource, "hl.conf" );
  if (! resource.isEmpty()) {
      config->saveTo( resource, "HL Cache", "", true );

Generated by  Doxygen 1.6.0   Back to index