1 /* This file is part of KDevelop
2 Copyright 2006 Adam Treat <treat@kde.org>
3 Copyright 2007 Andreas Pakulat <apaku@gmx.de>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "projectconfigskeleton.h"
22 #include <interfaces/iproject.h>
25 #include <kio/netaccess.h>
30 struct ProjectConfigSkeletonPrivate
32 QString m_developerTempFile
;
33 QString m_projectTempFile
;
34 KUrl m_projectFileUrl
;
35 KUrl m_developerFileUrl
;
39 ProjectConfigSkeleton::ProjectConfigSkeleton( const QString
& configname
)
40 : KConfigSkeleton( configname
), d( new ProjectConfigSkeletonPrivate
)
42 d
->m_developerTempFile
= configname
;
45 ProjectConfigSkeleton::ProjectConfigSkeleton( KSharedConfig::Ptr config
)
46 : KConfigSkeleton( config
), d( new ProjectConfigSkeletonPrivate
)
50 void ProjectConfigSkeleton::setDeveloperTempFile( const QString
& cfg
)
52 d
->m_developerTempFile
= cfg
;
53 setSharedConfig( KSharedConfig::openConfig( cfg
) );
56 void ProjectConfigSkeleton::setProjectTempFile( const QString
& cfg
)
58 d
->m_projectTempFile
= cfg
;
59 config()->addConfigSources( QStringList() << cfg
);
63 void ProjectConfigSkeleton::setProjectFileUrl( const QString
& cfg
)
65 d
->m_projectFileUrl
= KUrl(cfg
);
68 void ProjectConfigSkeleton::setDeveloperFileUrl( const QString
& cfg
)
70 d
->m_developerFileUrl
= KUrl(cfg
);
73 KUrl
ProjectConfigSkeleton::projectFileUrl() const
75 return d
->m_projectFileUrl
;
78 KUrl
ProjectConfigSkeleton::developerFileUrl() const
80 return d
->m_developerFileUrl
;
83 void ProjectConfigSkeleton::setDefaults()
85 kDebug(9503) << "Setting Defaults";
86 KConfig
cfg( d
->m_projectTempFile
);
87 Q_FOREACH( KConfigSkeletonItem
* item
, items() )
90 if( cfg
.hasGroup( item
->group() ) )
92 KConfigGroup grp
= cfg
.group( item
->group() );
93 if( grp
.hasKey( item
->key() ) )
94 item
->setProperty( grp
.readEntry( item
->key(), item
->property() ) );
99 bool ProjectConfigSkeleton::useDefaults( bool b
)
101 if( b
== d
->mUseDefaults
)
102 return d
->mUseDefaults
;
106 KConfig
cfg( d
->m_projectTempFile
);
107 Q_FOREACH( KConfigSkeletonItem
* item
, items() )
110 if( cfg
.hasGroup( item
->group() ) )
112 kDebug(9503) << "reading";
113 KConfigGroup grp
= cfg
.group( item
->group() );
114 if( grp
.hasKey( item
->key() ) )
115 item
->setProperty( grp
.readEntry( item
->key(), item
->property() ) );
120 KConfig
cfg( d
->m_developerTempFile
);
121 KConfig
defCfg( d
->m_projectTempFile
);
122 Q_FOREACH( KConfigSkeletonItem
* item
, items() )
124 if( cfg
.hasGroup( item
->group() ) )
126 KConfigGroup grp
= cfg
.group( item
->group() );
127 if( grp
.hasKey( item
->key() ) )
128 item
->setProperty( grp
.readEntry( item
->key(), item
->property() ) );
131 KConfigGroup grp
= defCfg
.group( item
->group() );
132 item
->setProperty( grp
.readEntry( item
->key(), item
->property() ) );
136 KConfigGroup grp
= defCfg
.group( item
->group() );
137 item
->setProperty( grp
.readEntry( item
->key(), item
->property() ) );
142 return !d
->mUseDefaults
;
145 void ProjectConfigSkeleton::writeConfig()
147 KConfigSkeletonItem::List myitems
= items();
148 KConfigSkeletonItem::List::ConstIterator it
;
149 for( it
= myitems
.begin(); it
!= myitems
.end(); ++it
)
151 (*it
)->writeConfig( config() );
158 KIO::NetAccess::upload( d
->m_developerTempFile
, d
->m_developerFileUrl
, 0 );
160 emit
configChanged();
163 ProjectConfigSkeleton::~ProjectConfigSkeleton()
169 #include "projectconfigskeleton.moc"