Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

katesyntaxdocument.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           katesyntaxdocument.cpp  -  description
00003                              -------------------
00004     begin                : Sat 31 March 2001
00005     copyright            : (C) 2001,2002 by Joseph Wenninger
00006     email                : jowenn@kde.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "katesyntaxdocument.h"
00019 #include "kateconfig.h"
00020 #include "kdebug.h"
00021 #include "kstddirs.h"
00022 #include "klocale.h"
00023 #include "kmessagebox.h"
00024 #include "kglobal.h"
00025 
00026 /* OPIE */
00027 #include <opie2/odebug.h>
00028 #include <qpe/qpeapplication.h>
00029 
00030 /* QT */
00031 #include <qfile.h>
00032 #include <qstringlist.h>
00033 #include <qdir.h>
00034 
00035 SyntaxDocument::SyntaxDocument()
00036 {
00037   m_root=0;
00038   currentFile="";
00039   setupModeList();
00040 }
00041 
00042 void SyntaxDocument::setIdentifier(const QString& identifier)
00043 {
00044 #warning FIXME  delete m_root;
00045   m_root=Opie::Core::XMLElement::load(identifier);
00046   if (!m_root)    KMessageBox::error( 0L, i18n("Can't open %1").arg(identifier) );
00047 
00048 }
00049 
00050 SyntaxDocument::~SyntaxDocument()
00051 {
00052 }
00053 
00054 void SyntaxDocument::setupModeList(bool force)
00055 {
00056 
00057   if (myModeList.count() > 0) return;
00058 
00059   KateConfig *config=KGlobal::config();
00060   KStandardDirs *dirs = KGlobal::dirs();
00061 
00062 //  QStringList list=dirs->findAllResources("data","kate/syntax/*.xml",false,true);
00063   QString path=QPEApplication::qpeDir() +"share/tinykate/syntax/";
00064 
00065   QDir dir(path);
00066   QStringList list=dir.entryList("*.xml");
00067 
00068   for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
00069   {
00070     QString Group="Highlighting_Cache"+path+*it;
00071     if ((config->hasGroup(Group)) && (!force))
00072     {
00073       config->setGroup(Group);
00074       syntaxModeListItem *mli=new syntaxModeListItem;
00075       mli->name = config->readEntry("name","");
00076       mli->section = config->readEntry("section","");
00077       mli->mimetype = config->readEntry("mimetype","");
00078       mli->extension = config->readEntry("extension","");
00079       mli->identifier = path+*it;
00080       myModeList.append(mli);
00081     }
00082     else
00083     {
00084     odebug << "Found a description file:"+path+(*it) << oendl;
00085         setIdentifier(path+(*it));
00086         Opie::Core::XMLElement *e=m_root;
00087         if (e)
00088         {
00089       e=e->firstChild();
00090       odebug << e->tagName() << oendl;
00091           if (e->tagName()=="language")
00092           {
00093             syntaxModeListItem *mli=new syntaxModeListItem;
00094             mli->name = e->attribute("name");
00095             mli->section = e->attribute("section");
00096             mli->mimetype = e->attribute("mimetype");
00097             mli->extension = e->attribute("extensions");
00098         odebug << QString("valid description for: %1/%2").arg(mli->section).arg(mli->name) << oendl;
00099             if (mli->section.isEmpty())
00100               mli->section=i18n("Other");
00101 
00102             mli->identifier = path+(*it);
00103             config->setGroup(Group);
00104             config->writeEntry("name",mli->name);
00105             config->writeEntry("section",mli->section);
00106             config->writeEntry("mimetype",mli->mimetype);
00107             config->writeEntry("extension",mli->extension);
00108             myModeList.append(mli);
00109           }
00110         }
00111     }
00112   }
00113   config->write();
00114 //  config->sync();
00115 }
00116 
00117 SyntaxModeList SyntaxDocument::modeList()
00118 {
00119   return myModeList;
00120 }
00121 
00122 bool SyntaxDocument::nextGroup( syntaxContextData* data)
00123 {
00124   if(!data) return false;
00125 
00126   if (!data->currentGroup)
00127     data->currentGroup=data->parent->firstChild();
00128   else
00129     data->currentGroup=data->currentGroup->nextChild();
00130 
00131   data->item=0;
00132 
00133   if (!data->currentGroup)
00134     return false;
00135   else
00136     return true;
00137 }
00138 
00139 bool SyntaxDocument::nextItem( syntaxContextData* data)
00140 {
00141   if(!data) return false;
00142 
00143   if (!data->item)
00144     data->item=data->currentGroup->firstChild();
00145   else
00146     data->item=data->item->nextChild();
00147 
00148   if (!data->item)
00149     return false;
00150   else
00151     return true;
00152 }
00153 
00154 QString SyntaxDocument::groupItemData( syntaxContextData* data,QString name)
00155 {
00156   if(!data)
00157     return QString::null;
00158 
00159   if ( (data->item) && (name.isEmpty()))
00160     return data->item->tagName();
00161 
00162   if (data->item)
00163     return data->item->attribute(name);
00164   else
00165     return QString();
00166 }
00167 
00168 QString SyntaxDocument::groupData( syntaxContextData* data,QString name)
00169 {
00170   if(!data)
00171     return QString::null;
00172 
00173   if (data->currentGroup)
00174     return data->currentGroup->attribute(name);
00175   else
00176     return QString();
00177 }
00178 
00179 void SyntaxDocument::freeGroupInfo( syntaxContextData* data)
00180 {
00181   if (data)
00182     delete data;
00183 }
00184 
00185 syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data)
00186 {
00187   syntaxContextData *retval=new syntaxContextData;
00188     retval->parent=0;
00189     retval->currentGroup=0;
00190     retval->item=0;
00191   if (data != 0)
00192   {
00193     retval->parent=data->currentGroup;
00194     retval->currentGroup=data->item;
00195     retval->item=0;
00196    }
00197 
00198   return retval;
00199 }
00200 
00201 syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const QString &Config)
00202 {
00203   Opie::Core::XMLElement *e = m_root->firstChild()->firstChild();
00204 
00205   while (e)
00206   {
00207     kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl;
00208 
00209     if (e->tagName().compare(mainGroupName)==0 )
00210     {
00211        Opie::Core::XMLElement *e1=e->firstChild();
00212 
00213       while (e1)
00214       {
00215         kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl;
00216 
00217         if (e1->tagName()==Config)
00218         {
00219           syntaxContextData *data=new ( syntaxContextData);
00220       data->currentGroup=0;
00221       data->parent=0;
00222           data->item=e1;
00223           return data;
00224         }
00225 
00226         e1=e1->nextChild();
00227       }
00228 
00229       kdDebug(13010) << "WARNING :returning null 3"<< endl;
00230       return 0;
00231     }
00232 
00233     e=e->nextChild();
00234   }
00235 
00236   kdDebug(13010) << "WARNING :returning null 4"  << endl;
00237   return 0;
00238 }
00239 
00240 
00241 
00242 syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const QString &group)
00243 {
00244 
00245   Opie::Core::XMLElement *e=m_root->firstChild()->firstChild();
00246 
00247   while (e)
00248   {
00249     kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl;
00250 
00251     if (e->tagName().compare(mainGroupName)==0 )
00252     {
00253       Opie::Core::XMLElement *e1=e->firstChild();
00254 
00255       while (e1)
00256       {
00257         kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl;
00258         if (e1->tagName()==group+"s")
00259         {
00260           syntaxContextData *data=new ( syntaxContextData);
00261           data->parent=e1;
00262       data->currentGroup=0;
00263       data->item=0;
00264           return data;
00265         }
00266 
00267         e1=e1->nextChild();
00268       }
00269 
00270       kdDebug(13010) << "WARNING : getGroupInfo returning null :1 " << endl;
00271       return 0;
00272     }
00273 
00274     e=e->nextChild();
00275   }
00276 
00277   kdDebug(13010) << "WARNING : getGroupInfo returning null :2" << endl;
00278   return 0;
00279 }
00280 
00281 
00282 QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& type,bool clearList)
00283 {
00284   Opie::Core::XMLElement *e  = m_root->firstChild();
00285   if (clearList)
00286     m_data.clear();
00287 
00288   for(e=e->firstChild(); e; e=e->nextChild())
00289   {
00290     if (e->tagName()==mainGroup)
00291     {
00292     for (Opie::Core::XMLElement *e1=e->firstChild();e1;e1=e1->nextChild())
00293     {
00294       if (e1->tagName()!="list") continue;
00295 
00296             if (e1->attribute("name")==type)
00297             {
00298             for (Opie::Core::XMLElement *e2=e1->firstChild();e2;e2=e2->nextChild())
00299             {
00300                 odebug << "FOUND A LIST ENTRY("+e2->tagName()+"):"+e2->firstChild()->value() << oendl;
00301                         m_data+=e2->firstChild()->value().stripWhiteSpace();
00302             }
00303                break;
00304         }
00305         }
00306       break;
00307     }
00308   }
00309 
00310   return m_data;
00311 }

Generated on Sat Nov 5 16:17:10 2005 for OPIE by  doxygen 1.4.2