• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

project

projectconfigskeleton.cpp

00001 /* This file is part of KDevelop
00002 Copyright 2006 Adam Treat <treat@kde.org>
00003 Copyright 2007 Andreas Pakulat <apaku@gmx.de>
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public
00007 License as published by the Free Software Foundation; either
00008 version 2 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public License
00016 along with this library; see the file COPYING.LIB.  If not, write to
00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018 Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "projectconfigskeleton.h"
00022 #include <interfaces/iproject.h>
00023 
00024 #include <kdebug.h>
00025 #include <kio/netaccess.h>
00026 
00027 namespace KDevelop
00028 {
00029 
00030 struct ProjectConfigSkeletonPrivate
00031 {
00032     QString m_developerTempFile;
00033     QString m_projectTempFile;
00034     KUrl m_projectFileUrl;
00035     KUrl m_developerFileUrl;
00036     bool mUseDefaults;
00037 };
00038 
00039 ProjectConfigSkeleton::ProjectConfigSkeleton( const QString & configname )
00040         : KConfigSkeleton( configname ), d( new ProjectConfigSkeletonPrivate )
00041 {
00042     d->m_developerTempFile = configname;
00043 }
00044 
00045 ProjectConfigSkeleton::ProjectConfigSkeleton( KSharedConfig::Ptr config )
00046         : KConfigSkeleton( config ), d( new ProjectConfigSkeletonPrivate )
00047 {
00048 }
00049 
00050 void ProjectConfigSkeleton::setDeveloperTempFile( const QString& cfg )
00051 {
00052     d->m_developerTempFile = cfg;
00053     setSharedConfig( KSharedConfig::openConfig( cfg ) );
00054 }
00055 
00056 void ProjectConfigSkeleton::setProjectTempFile( const QString& cfg )
00057 {
00058     d->m_projectTempFile = cfg;
00059     config()->addConfigSources( QStringList() << cfg );
00060     readConfig();
00061 }
00062 
00063 void ProjectConfigSkeleton::setProjectFileUrl( const QString& cfg )
00064 {
00065     d->m_projectFileUrl = KUrl(cfg);
00066 }
00067 
00068 void ProjectConfigSkeleton::setDeveloperFileUrl( const QString& cfg )
00069 {
00070     d->m_developerFileUrl = KUrl(cfg);
00071 }
00072 
00073 KUrl ProjectConfigSkeleton::projectFileUrl() const
00074 {
00075     return d->m_projectFileUrl;
00076 }
00077 
00078 KUrl ProjectConfigSkeleton::developerFileUrl() const
00079 {
00080     return d->m_developerFileUrl;
00081 }
00082 
00083 void ProjectConfigSkeleton::setDefaults()
00084 {
00085     kDebug(9503) << "Setting Defaults";
00086     KConfig cfg( d->m_projectTempFile );
00087     Q_FOREACH( KConfigSkeletonItem* item, items() )
00088     {
00089         item->swapDefault();
00090         if( cfg.hasGroup( item->group() ) )
00091         {
00092             KConfigGroup grp = cfg.group( item->group() );
00093             if( grp.hasKey( item->key() ) )
00094                 item->setProperty( grp.readEntry( item->key(), item->property() ) );
00095         }
00096     }
00097 }
00098 
00099 bool ProjectConfigSkeleton::useDefaults( bool b )
00100 {
00101     if( b == d->mUseDefaults )
00102         return d->mUseDefaults;
00103 
00104     if( b )
00105     {
00106         KConfig cfg( d->m_projectTempFile );
00107         Q_FOREACH( KConfigSkeletonItem* item, items() )
00108         {
00109             item->swapDefault();
00110             if( cfg.hasGroup( item->group() ) )
00111             {
00112                 kDebug(9503) << "reading";
00113                 KConfigGroup grp = cfg.group( item->group() );
00114         if( grp.hasKey( item->key() ) )
00115                     item->setProperty( grp.readEntry( item->key(), item->property() ) );
00116             }
00117         }
00118     }else
00119     {
00120         KConfig cfg( d->m_developerTempFile );
00121         KConfig defCfg( d->m_projectTempFile );
00122         Q_FOREACH( KConfigSkeletonItem* item, items() )
00123         {
00124             if( cfg.hasGroup( item->group() ) )
00125             {
00126                 KConfigGroup grp = cfg.group( item->group() );
00127         if( grp.hasKey( item->key() ) )
00128                     item->setProperty( grp.readEntry( item->key(), item->property() ) );
00129         else
00130         {
00131                     KConfigGroup grp = defCfg.group( item->group() );
00132                     item->setProperty( grp.readEntry( item->key(), item->property() ) );
00133         }
00134             }else
00135             {
00136                 KConfigGroup grp = defCfg.group( item->group() );
00137                 item->setProperty( grp.readEntry( item->key(), item->property() ) );
00138             }
00139         }
00140     }
00141     d->mUseDefaults = b;
00142     return !d->mUseDefaults;
00143 }
00144 
00145 void ProjectConfigSkeleton::writeConfig()
00146 {
00147     KConfigSkeletonItem::List myitems = items();
00148     KConfigSkeletonItem::List::ConstIterator it;
00149     for( it = myitems.begin(); it != myitems.end(); ++it )
00150     {
00151         (*it)->writeConfig( config() );
00152     }
00153 
00154     config()->sync();
00155 
00156     readConfig();
00157 
00158     KIO::NetAccess::upload( d->m_developerTempFile, d->m_developerFileUrl, 0 );
00159 
00160     emit configChanged();
00161 }
00162 
00163 ProjectConfigSkeleton::~ProjectConfigSkeleton()
00164 {
00165     delete d;
00166 }
00167 
00168 }
00169 #include "projectconfigskeleton.moc"
00170 

project

Skip menu "project"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  •     interfaces
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal