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 KConfig *Project::pluginData(Plugin *plugin,const QString& group) {
00129     if (!plugin) return 0;
00130     QString groupName="Plugin:"+QString::fromUtf8(plugin->name());
00131     if (!group.isEmpty()) groupName+="/"+group;
00132     d->m_config->setGroup(groupName);
00133     return d->m_config;
00134 }
00135 
00136 
00137 QString Project::type ()
00138 {
00139   return fileData()->readEntry ("Type", "Default");
00140 }
00141 
00142 QString Project::name ()
00143 {
00144   return fileData()->readEntry ("Name", "Untitled");
00145 }
00146 
00147 QString Project::fileName ()
00148 {
00149   return d->m_data->fileName;
00150 }
00151 
00152 QString Project::dir ()
00153 {
00154   return d->m_dir;
00155 }
00156 
00157 bool Project::save ()
00158 {
00159   d->m_config->sync();
00160 
00161   return d->m_plugin->save ();
00162 }
00163 
00164 bool Project::queryClose ()
00165 {
00166   return d->m_plugin->queryClose ();
00167 }
00168 
00169 bool Project::close ()
00170 {
00171   return d->m_plugin->close ();
00172 }
00173 
00174 QStringList Project::dirs (const QString &dir)
00175 {
00176   return dirData(dir)->readListEntry ("Dirs", '/');
00177 }
00178 
00179 QStringList Project::files (const QString &dir)
00180 {
00181   return dirData(dir)->readListEntry ("Files", '/');
00182 }
00183 
00184 void Project::addDirs (const QString &dir, QStringList &dirs)
00185 {
00186   QStringList existing = this->dirs (dir);
00187   for (uint z=0; z < existing.count(); z++)
00188   {
00189     dirs.remove (existing[z]);
00190   }
00191 
00192   plugin()->addDirs (dir, dirs);
00193 
00194   dirData (dir);
00195   d->m_config->writeEntry ("Dirs", existing + dirs, '/');
00196   d->m_config->sync ();
00197 
00198   emit dirsAdded (dir, dirs);
00199 }
00200 
00201 void Project::removeDirs (const QString &dir, QStringList &dirs)
00202 {
00203   QStringList toRemove;
00204   QStringList existing = this->dirs (dir);
00205   for (uint z=0; z < dirs.count(); z++)
00206   {
00207     if (existing.findIndex(dirs[z]) != -1)
00208       toRemove.append (dirs[z]);
00209   }
00210 
00211   dirs = toRemove;
00212 
00213   plugin()->removeDirs (dir, dirs);
00214 
00215   for (uint z=0; z < dirs.count(); z++)
00216   {
00217     existing.remove (dirs[z]);
00218   }
00219 
00220   dirData (dir);
00221   d->m_config->writeEntry ("Dirs", existing, '/');
00222   d->m_config->sync ();
00223 
00224   emit dirsRemoved (dir, dirs);
00225 }
00226 
00227 void Project::addFiles (const QString &dir, QStringList &files)
00228 {
00229   QStringList existing = this->files (dir);
00230   for (uint z=0; z < existing.count(); z++)
00231   {
00232     files.remove (existing[z]);
00233   }
00234 
00235   plugin()->addFiles (dir, files);
00236 
00237   dirData (dir);
00238   d->m_config->writeEntry ("Files", existing + files, '/');
00239   d->m_config->sync ();
00240 
00241   emit filesAdded (dir, files);
00242 }
00243 
00244 void Project::removeFiles (const QString &dir, QStringList &files)
00245 {
00246   QStringList toRemove;
00247   QStringList existing = this->files (dir);
00248   for (uint z=0; z < files.count(); z++)
00249   {
00250     if (existing.findIndex(files[z]) != -1)
00251       toRemove.append (files[z]);
00252   }
00253 
00254   files = toRemove;
00255 
00256   plugin()->removeDirs (dir, files);
00257 
00258   for (uint z=0; z < files.count(); z++)
00259   {
00260     existing.remove (files[z]);
00261   }
00262 
00263   dirData (dir);
00264   d->m_config->writeEntry ("Files", existing, '/');
00265   d->m_config->sync ();
00266 
00267   emit filesRemoved (dir, files);
00268 }
00269 
00270 }
00271 
KDE Logo
This file is part of the documentation for kate Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Nov 4 00:45:19 2005 by doxygen 1.4.0 written by Dimitri van Heesch, © 1997-2003