kate Library API Documentation

project.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016    Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include "project.h"
00020 #include "project.moc"
00021 
00022 #include "projectiface.h"
00023 
00024 #include "plugin.h"
00025 
00026 #include "../app/kateprojectmanager.h"
00027 
00028 #include <kconfig.h>
00029 
00030 KateProjectDCOPIface::KateProjectDCOPIface (Kate::Project *p)
00031  : DCOPObject ((QString("KateProject#%1").arg(p->projectNumber())).latin1()), m_p (p)
00032 {
00033 }
00034 
00035 void KateProjectDCOPIface::test ()
00036 {
00037 }
00038 
00039 namespace Kate
00040 {
00041 
00042 class PrivateProject
00043 {
00044   public:
00045     PrivateProject ()
00046     {
00047     }
00048 
00049     ~PrivateProject ()
00050     {
00051       delete m_dcop;
00052       delete m_data;
00053       delete m_config;
00054       delete m_plugin;
00055     }
00056 
00057     KateInternalProjectData *m_data;
00058     Kate::ProjectPlugin *m_plugin;
00059     KConfig *m_config;
00060     QString m_dir;
00061     KateProjectDCOPIface *m_dcop;
00062 };
00063 
00064 unsigned int Project::globalProjectNumber = 0;
00065 
00066 Project::Project (void *project) : QObject (((KateInternalProjectData*) project)->proMan)
00067 {
00068   globalProjectNumber++;
00069   myProjectNumber = globalProjectNumber;
00070 
00071   d = new PrivateProject ();
00072   d->m_data = ((KateInternalProjectData*) project);
00073 
00074   d->m_config = new KConfig (d->m_data->fileName, false, false);
00075   d->m_dir = d->m_data->fileName.left (d->m_data->fileName.findRev (QChar ('/')));
00076 
00077   d->m_dcop = new KateProjectDCOPIface (this);
00078 
00079   // LAST STEP, IMPORTANT, LOAD PLUGIN AFTER ALL OTHER WORK IS DONE !
00080   d->m_plugin = d->m_data->proMan->createPlugin (this);
00081 }
00082 
00083 Project::~Project ()
00084 {
00085   delete d;
00086 }
00087 
00088 unsigned int Project::projectNumber () const
00089 {
00090   return myProjectNumber;
00091 }
00092 
00093 DCOPObject *Project::dcopObject ()
00094 {
00095   return d->m_dcop;
00096 }
00097 
00098 ProjectPlugin *Project::plugin () const
00099 {
00100   return d->m_plugin;
00101 }
00102 
00103 KConfig *Project::data ()
00104 {
00105   return d->m_config;
00106 }
00107 
00108 KConfig *Project::dirData (const QString &dir)
00109 {
00110   if (dir.isNull())
00111     d->m_config->setGroup("Project Dir");
00112   else
00113     d->m_config->setGroup ("Dir "+dir);
00114 
00115   return d->m_config;
00116 }
00117 
00118 KConfig *Project::fileData (const QString &file)
00119 {
00120   if (file.isNull())
00121     d->m_config->setGroup("Project File");
00122   else
00123     d->m_config->setGroup ("File "+file);
00124 
00125   return d->m_config;
00126 }
00127 
00128 QString Project::type ()
00129 {
00130   return fileData()->readEntry ("Type", "Default");
00131 }
00132 
00133 QString Project::name ()
00134 {
00135   return fileData()->readEntry ("Name", "Untitled");
00136 }
00137 
00138 QString Project::fileName ()
00139 {
00140   return d->m_data->fileName;
00141 }
00142 
00143 QString Project::dir ()
00144 {
00145   return d->m_dir;
00146 }
00147 
00148 bool Project::save ()
00149 {
00150   d->m_config->sync();
00151 
00152   return d->m_plugin->save ();
00153 }
00154 
00155 bool Project::queryClose ()
00156 {
00157   return d->m_plugin->queryClose ();
00158 }
00159 
00160 bool Project::close ()
00161 {
00162   return d->m_plugin->close ();
00163 }
00164 
00165 QStringList Project::dirs (const QString &dir)
00166 {
00167   return dirData(dir)->readListEntry ("Dirs", '/');
00168 }
00169 
00170 QStringList Project::files (const QString &dir)
00171 {
00172   return dirData(dir)->readListEntry ("Files", '/');
00173 }
00174 
00175 void Project::addDirs (const QString &dir, QStringList &dirs)
00176 {
00177   QStringList existing = this->dirs (dir);
00178   for (uint z=0; z < existing.count(); z++)
00179   {
00180     dirs.remove (existing[z]);
00181   }
00182 
00183   plugin()->addDirs (dir, dirs);
00184 
00185   dirData (dir);
00186   d->m_config->writeEntry ("Dirs", existing + dirs, '/');
00187   d->m_config->sync ();
00188 
00189   emit dirsAdded (dir, dirs);
00190 }
00191 
00192 void Project::removeDirs (const QString &dir, QStringList &dirs)
00193 {
00194   QStringList toRemove;
00195   QStringList existing = this->dirs (dir);
00196   for (uint z=0; z < dirs.count(); z++)
00197   {
00198     if (existing.findIndex(dirs[z]) != -1)
00199       toRemove.append (dirs[z]);
00200   }
00201 
00202   dirs = toRemove;
00203 
00204   plugin()->removeDirs (dir, dirs);
00205 
00206   for (uint z=0; z < dirs.count(); z++)
00207   {
00208     existing.remove (dirs[z]);
00209   }
00210 
00211   dirData (dir);
00212   d->m_config->writeEntry ("Dirs", existing, '/');
00213   d->m_config->sync ();
00214 
00215   emit dirsRemoved (dir, dirs);
00216 }
00217 
00218 void Project::addFiles (const QString &dir, QStringList &files)
00219 {
00220   QStringList existing = this->files (dir);
00221   for (uint z=0; z < existing.count(); z++)
00222   {
00223     files.remove (existing[z]);
00224   }
00225 
00226   plugin()->addFiles (dir, files);
00227 
00228   dirData (dir);
00229   d->m_config->writeEntry ("Files", existing + files, '/');
00230   d->m_config->sync ();
00231 
00232   emit filesAdded (dir, files);
00233 }
00234 
00235 void Project::removeFiles (const QString &dir, QStringList &files)
00236 {
00237   QStringList toRemove;
00238   QStringList existing = this->files (dir);
00239   for (uint z=0; z < files.count(); z++)
00240   {
00241     if (existing.findIndex(files[z]) != -1)
00242       toRemove.append (files[z]);
00243   }
00244 
00245   files = toRemove;
00246 
00247   plugin()->removeDirs (dir, files);
00248 
00249   for (uint z=0; z < files.count(); z++)
00250   {
00251     existing.remove (files[z]);
00252   }
00253 
00254   dirData (dir);
00255   d->m_config->writeEntry ("Files", existing, '/');
00256   d->m_config->sync ();
00257 
00258   emit filesRemoved (dir, files);
00259 }
00260 
00261 }
00262 
KDE Logo
This file is part of the documentation for kate Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 8 02:43:14 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003