void KOViewManager::readSettings( KConfig *config )
{
    KConfigGroup generalConfig( config, "General" );
    QString view = generalConfig.readEntry( "Current View" );

    if ( view == QLatin1String( "WhatsNext" ) ) {
        showWhatsNextView();
    } else if ( view == QLatin1String( "OldMonth" ) ) {
        // the oldmonth view is gone, so we assume the new month view
        showMonthView();
    } else if ( view == QLatin1String( "List" ) ) {
        showListView();
    } else if ( view == QLatin1String( "Journal" ) ) {
        showJournalView();
    } else if ( view == QLatin1String( "Todo" ) ) {
        showTodoView();
    } else if ( view == QLatin1String( "Timeline" ) ) {
        showTimeLineView();
    } else if ( view == QLatin1String( "TimeSpent" ) ) {
        showTimeSpentView();
    } else if ( view == QLatin1String( "Month" ) ) {
        showMonthView();
    } else {
        mAgendaMode = AgendaMode( generalConfig.readEntry( "Agenda Mode", int( AGENDA_OTHER ) ) );

        switch ( mAgendaMode ) {
        case AGENDA_WORK_WEEK:
            showWorkWeekView();
            break;
        case AGENDA_WEEK:
            showWeekView();
            break;
        case AGENDA_NEXTX:
            showNextXView();
            break;
        case AGENDA_DAY:
            showDayView();
            break;
        case AGENDA_NONE:
        // Someone has been playing with the config file.
        default:
            mAgendaMode = AGENDA_OTHER;
            showAgendaView();
        }
    }
}
void KOViewManager::writeSettings( KConfig *config )
{
    KConfigGroup generalConfig( config, "General" );

    QString view;
    if ( mCurrentView == mWhatsNextView ) {
        view = QLatin1String( "WhatsNext" );
    } else if ( mCurrentView == mListView ) {
        view = QLatin1String( "List" );
    } else if ( mCurrentView == mJournalView ) {
        view = QLatin1String( "Journal" );
    } else if ( mCurrentView == mTodoView ) {
        view = QLatin1String( "Todo" );
    } else if ( mCurrentView == mTimelineView ) {
        view = QLatin1String( "Timeline" );
    } else if ( mCurrentView == mTimeSpentView ) {
        view = QLatin1String( "TimeSpent" );
    } else if ( mCurrentView == mMonthView ) {
        view = QLatin1String( "Month" );
    } else {
        view = QLatin1String( "Agenda" );
        generalConfig.writeEntry( "Agenda Mode", int( mAgendaMode ) );
    }

    generalConfig.writeEntry( "Current View", view );

    if ( mAgendaView ) {
        mAgendaView->writeSettings( config );
    }
    if ( mListView ) {
        mListView->writeSettings( config );
    }
    if ( mTodoView ) {
        mTodoView->saveLayout( config, "Todo View" );
    }
}
/** 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)
*/
void KateSyntaxDocument::setupModeList (bool force)
{
  // If there's something in myModeList the Mode List was already built so, don't do it again
  if (!myModeList.isEmpty())
    return;

  // We'll store the ModeList in katesyntaxhighlightingrc
  KConfigGroup generalConfig(m_config, "General");

  // figure our if the kate install is too new
  if (generalConfig.readEntry ("Version",0) > generalConfig.readEntry ("CachedVersion",0))
  {
    generalConfig.writeEntry ("CachedVersion", generalConfig.readEntry ("Version",0));
    force = true;
  }

  // Let's get a list of all the xml files for hl
  const QStringList list = KGlobal::dirs()->findAllResources("data","katepart/syntax/*.xml",
                                                       KStandardDirs::NoDuplicates);

  // Let's iterate through the list and build the Mode List
  for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
  {
    // Each file has a group called:
    QString Group="Cache "+ *it;

    // Let's go to this group
    KConfigGroup config(m_config, Group);

    // stat the file
    KDE_struct_stat sbuf;
    memset (&sbuf, 0, sizeof(sbuf));
    KDE::stat(*it, &sbuf);

    // If the group exist and we're not forced to read the xml file, let's build myModeList for katesyntax..rc
    if (!force && config.exists() && (sbuf.st_mtime == config.readEntry("lastModified",0)))
    {
      // Let's make a new KateSyntaxModeListItem to instert in myModeList from the information in katesyntax..rc
      KateSyntaxModeListItem *mli=new KateSyntaxModeListItem;
      mli->name       = config.readEntry("name");
      mli->nameTranslated = i18nc("Language",mli->name.toUtf8());
      mli->section    = i18nc("Language Section",config.readEntry("section").toUtf8());
      mli->mimetype   = config.readEntry("mimetype");
      mli->extension  = config.readEntry("extension");
      mli->version    = config.readEntry("version");
      mli->priority   = config.readEntry("priority");
      mli->style      = config.readEntry("style");
      mli->author    = config.readEntry("author");
      mli->license   = config.readEntry("license");
      mli->indenter = config.readEntry("indenter");
      mli->hidden   =  config.readEntry("hidden", false);
      mli->identifier = *it;

      // Apend the item to the list
      myModeList.append(mli);
    }
    else
    {
#ifdef KSD_OVER_VERBOSE
      kDebug (13010) << "UPDATE hl cache for: " << *it;
#endif

      // 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);

        f.close();

        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.
              KateSyntaxModeListItem *mli = new KateSyntaxModeListItem;

              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->style     = root.attribute("style");
              mli->author    = root.attribute("author");
              mli->license   = root.attribute("license");
              mli->indenter   = root.attribute("indenter");

              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
              config = KConfigGroup(m_config, Group);
              config.writeEntry("name",mli->name);
              config.writeEntry("section",mli->section);
              config.writeEntry("mimetype",mli->mimetype);
              config.writeEntry("extension",mli->extension);
              config.writeEntry("version",mli->version);
              config.writeEntry("priority",mli->priority);
              config.writeEntry("style",mli->style);
              config.writeEntry("author",mli->author);
              config.writeEntry("license",mli->license);
              config.writeEntry("indenter",mli->indenter);
              config.writeEntry("hidden",mli->hidden);

              // modified time to keep cache in sync
              config.writeEntry("lastModified", int(sbuf.st_mtime));

              // Now that the data is in the config file, translate section
              mli->section    = i18nc("Language Section",mli->section.toUtf8());
              mli->nameTranslated = i18nc("Language",mli->name.toUtf8());

              // Append the new item to the list.
              myModeList.append(mli);
            }
          }
        }
        else
        {
          KateSyntaxModeListItem *emli=new KateSyntaxModeListItem;

          emli->section=i18n("Errors!");
          emli->mimetype="invalid_file/invalid_file";
          emli->extension="invalid_file.invalid_file";
          emli->version="1.";
          emli->name=QString ("Error: %1").arg(*it); // internal
          emli->nameTranslated=i18n("Error: %1", *it); // translated
          emli->identifier=(*it);

          myModeList.append(emli);
        }
      }
    }
  }

  // Synchronize with the file katesyntax...rc
  generalConfig.sync();
}