cvsoptions.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qfile.h>
00013 #include <qtextstream.h>
00014
00015 #include <kdebug.h>
00016 #include <kconfig.h>
00017
00018 #include "domutil.h"
00019 #include "kdevproject.h"
00020 #include "cvsoptions.h"
00021
00023
00025
00026 #define default_revert QString::fromLatin1("-C")
00027 #define default_diff QString::fromLatin1("-p")
00028 #define default_rsh QString::fromLatin1("")
00029 #define default_contextLines 3
00030 #define default_compression 0
00031
00033
00035
00036 CvsOptions *CvsOptions::m_instance = 0;
00037 QString CvsOptions::invalidLocation( "ERROR-LOCATION-IS-NOT-SET-IN-PROJECT" );
00038
00040
00042
00043 CvsOptions::CvsOptions()
00044 : m_recursiveWhenCommitRemove( true ),
00045 m_pruneEmptyDirsWhenUpdate( true ),
00046 m_recursiveWhenUpdate( true ),
00047 m_createDirsWhenUpdate( true ),
00048 m_revertOptions( default_revert ),
00049 m_diffOptions( default_diff ),
00050 m_cvsRshEnvVar( default_rsh ),
00051 m_compressionLevel( default_compression ),
00052 m_contextLines( default_contextLines )
00053 {
00054 kdDebug( 9006 ) << " **** CvsOptions instance CREATED!" << endl;
00055
00056 m_serviceConfig = new KConfig( "cvsservicerc" );
00057 }
00058
00060
00061 CvsOptions::~CvsOptions()
00062 {
00063 kdDebug( 9006 ) << " **** CvsOptions instance DESTROYED!" << endl;
00064 delete m_serviceConfig;
00065
00066 m_instance = 0;
00067 }
00068
00070
00071 CvsOptions* CvsOptions::instance()
00072 {
00073 if (!m_instance)
00074 {
00075 m_instance = new CvsOptions();
00076 }
00077 return m_instance;
00078 }
00079
00081
00082 void CvsOptions::save( KDevProject *project )
00083 {
00084 kdDebug( 9006 ) << " **** CvsOptions::save( KDevProject* ) here" << endl;
00085 Q_ASSERT( project );
00086
00087 QDomDocument &dom = *project->projectDom();
00088
00089 DomUtil::writeBoolEntry( dom, "/kdevcvsservice/recursivewhenupdate", recursiveWhenUpdate() );
00090 DomUtil::writeBoolEntry( dom, "/kdevcvsservice/prunedirswhenupdate", pruneEmptyDirsWhenUpdate() );
00091 DomUtil::writeBoolEntry( dom, "/kdevcvsservice/createdirswhenupdate", createDirsWhenUpdate() );
00092 DomUtil::writeBoolEntry( dom, "/kdevcvsservice/recursivewhencommitremove", recursiveWhenCommitRemove() );
00093 DomUtil::writeEntry( dom, "/kdevcvsservice/revertoptions", revertOptions() );
00094
00095
00096
00097 QString groupName = "Repository-" + guessLocation( project->projectDirectory() );
00098 m_serviceConfig->setGroup( groupName );
00099
00100 m_serviceConfig->writeEntry( "ContextLines", contextLines() );
00101 m_serviceConfig->writeEntry( "DiffOptions", diffOptions() );
00102 m_serviceConfig->writeEntry( "rsh", cvsRshEnvVar() );
00103 }
00104
00106
00107 void CvsOptions::load( KDevProject *project )
00108 {
00109 kdDebug( 9006 ) << " **** CvsOptions::load( KDevProject* ) here" << endl;
00110 Q_ASSERT( project );
00111 QDomDocument &dom = *project->projectDom();
00112
00113 m_recursiveWhenUpdate = DomUtil::readBoolEntry( dom, "/kdevcvsservice/recursivewhenupdate", true );
00114 m_pruneEmptyDirsWhenUpdate = DomUtil::readBoolEntry( dom, "/kdevcvsservice/prunedirswhenupdate", true );
00115 m_createDirsWhenUpdate = DomUtil::readBoolEntry( dom, "/kdevcvsservice/createdirswhenupdate", true );
00116 m_recursiveWhenCommitRemove = DomUtil::readBoolEntry( dom, "/kdevcvsservice/recursivewhencommitremove", true );
00117 m_revertOptions = DomUtil::readEntry( dom, "/kdevcvsservice/revertoptions", default_revert );
00118
00119
00120 QString groupName = "Repository-" + guessLocation( project->projectDirectory() );
00121 m_serviceConfig->setGroup( groupName );
00122
00123 m_contextLines = m_serviceConfig->readUnsignedNumEntry( "ContextLines", default_contextLines );
00124 m_diffOptions = m_serviceConfig->readEntry( "DiffOptions", default_diff );
00125 m_cvsRshEnvVar = m_serviceConfig->readEntry( "rsh", default_rsh );
00126 }
00127
00129
00130 void CvsOptions::setRecursiveWhenCommitRemove( bool b )
00131 {
00132 this->m_recursiveWhenCommitRemove = b;
00133 }
00134
00136
00137 bool CvsOptions::recursiveWhenCommitRemove() const
00138 {
00139 return this->m_recursiveWhenCommitRemove;
00140 }
00141
00143
00144 void CvsOptions::setPruneEmptyDirsWhenUpdate( bool b )
00145 {
00146 this->m_pruneEmptyDirsWhenUpdate = b;
00147 }
00148
00150
00151 bool CvsOptions::pruneEmptyDirsWhenUpdate() const
00152 {
00153 return this->m_pruneEmptyDirsWhenUpdate;
00154 }
00155
00157
00158 void CvsOptions::setRecursiveWhenUpdate( bool b )
00159 {
00160 this->m_recursiveWhenUpdate = b;
00161 }
00162
00164
00165 bool CvsOptions::recursiveWhenUpdate() const
00166 {
00167 return this->m_recursiveWhenUpdate;
00168 }
00169
00171
00172 void CvsOptions::setCreateDirsWhenUpdate( bool b )
00173 {
00174 this->m_createDirsWhenUpdate = b;
00175 }
00176
00178
00179 bool CvsOptions::createDirsWhenUpdate() const
00180 {
00181 return this->m_createDirsWhenUpdate;
00182 }
00183
00185
00186 void CvsOptions::setRevertOptions( const QString &p )
00187 {
00188 this->m_revertOptions = p;
00189 }
00190
00192
00193 QString CvsOptions::revertOptions()
00194 {
00195 return this->m_revertOptions;
00196 }
00197
00199
00200 void CvsOptions::setDiffOptions( const QString &p )
00201 {
00202 this->m_diffOptions = p;
00203 }
00204
00206
00207 QString CvsOptions::diffOptions()
00208 {
00209 return this->m_diffOptions;
00210 }
00211
00213
00214 void CvsOptions::setCvsRshEnvVar( const QString &p )
00215 {
00216 this->m_cvsRshEnvVar = p;
00217 }
00218
00220
00221 QString CvsOptions::cvsRshEnvVar()
00222 {
00223 return this->m_cvsRshEnvVar;
00224 }
00225
00227
00228 QString CvsOptions::location()
00229 {
00230 return m_location;
00231 }
00232
00234
00235 void CvsOptions::setLocation( const QString &p )
00236 {
00237 m_location = p;
00238 }
00239
00241
00242 void CvsOptions::setContextLines( unsigned int contextLines )
00243 {
00244 m_contextLines = contextLines;
00245 }
00246
00248
00249 unsigned int CvsOptions::contextLines() const
00250 {
00251 return m_contextLines;
00252 }
00253
00255
00256 void CvsOptions::setCompressionLevel( unsigned int compressionLevel )
00257 {
00258 m_compressionLevel = compressionLevel;
00259 }
00260
00262
00263 unsigned int CvsOptions::compressionLevel() const
00264 {
00265 return m_compressionLevel;
00266 }
00267
00269
00270 QString CvsOptions::guessLocation( const QString &projectDir ) const
00271 {
00272 QString rootFileName( projectDir + "/CVS/Root" );
00273
00274 QFile f( rootFileName );
00275 if (f.open( IO_ReadOnly ))
00276 {
00277 QTextStream t( &f );
00278 QString serverLocation = t.readLine();
00279 kdDebug(9000) << "===> Server location guessed: " << serverLocation << endl;
00280 return serverLocation;
00281 }
00282 else
00283 {
00284 kdDebug(9000) << "===> Error: could not open CVS/Entries!! " << endl;
00285 return "Error while guessing repository location!!";
00286 }
00287 }
This file is part of the documentation for KDevelop Version 3.1.2.