~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to vcs/cvsservice/cvsoptions.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2003 by Mario Scalas                                    *
 
3
 *   mario.scalas@libero.it                                                *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 ***************************************************************************/
 
11
 
 
12
#include <qfile.h>
 
13
#include <qtextstream.h>
 
14
 
 
15
#include <kdebug.h>
 
16
#include <kconfig.h>
 
17
#include <klocale.h>
 
18
 
 
19
#include "domutil.h"
 
20
#include "kdevproject.h"
 
21
#include "cvsoptions.h"
 
22
 
 
23
///////////////////////////////////////////////////////////////////////////////
 
24
// Macros
 
25
///////////////////////////////////////////////////////////////////////////////
 
26
 
 
27
#define default_revert          QString::fromLatin1("-C")
 
28
#define default_diff            QString::fromLatin1("-p")
 
29
#define default_rsh             QString::fromLatin1("")
 
30
#define default_contextLines    3
 
31
#define default_compression     0
 
32
 
 
33
///////////////////////////////////////////////////////////////////////////////
 
34
// static members
 
35
///////////////////////////////////////////////////////////////////////////////
 
36
 
 
37
CvsOptions *CvsOptions::m_instance = 0;
 
38
QString CvsOptions::invalidLocation( "ERROR-LOCATION-IS-NOT-SET-IN-PROJECT" );
 
39
 
 
40
///////////////////////////////////////////////////////////////////////////////
 
41
// class CvsOptions
 
42
///////////////////////////////////////////////////////////////////////////////
 
43
 
 
44
CvsOptions::CvsOptions()
 
45
    : m_recursiveWhenCommitRemove( true ),
 
46
    m_pruneEmptyDirsWhenUpdate( true ),
 
47
    m_recursiveWhenUpdate( true ),
 
48
    m_createDirsWhenUpdate( true ),
 
49
    m_revertOptions( default_revert ),
 
50
    m_diffOptions( default_diff ),
 
51
    m_cvsRshEnvVar( default_rsh ),
 
52
    m_compressionLevel( default_compression ),
 
53
    m_contextLines( default_contextLines )
 
54
{
 
55
    kdDebug( 9006 ) << " **** CvsOptions instance CREATED!" << endl;
 
56
    // We share some configuration data with cvsservice
 
57
    m_serviceConfig = new KConfig( "cvsservicerc" );
 
58
}
 
59
 
 
60
///////////////////////////////////////////////////////////////////////////////
 
61
 
 
62
CvsOptions::~CvsOptions()
 
63
{
 
64
    kdDebug( 9006 ) << " **** CvsOptions instance DESTROYED!" << endl;
 
65
    delete m_serviceConfig;
 
66
 
 
67
    m_instance = 0;
 
68
}
 
69
 
 
70
///////////////////////////////////////////////////////////////////////////////
 
71
 
 
72
CvsOptions* CvsOptions::instance()
 
73
{
 
74
    if (!m_instance)
 
75
    {
 
76
        m_instance = new CvsOptions();
 
77
    }
 
78
    return m_instance;
 
79
}
 
80
 
 
81
///////////////////////////////////////////////////////////////////////////////
 
82
 
 
83
void CvsOptions::save( KDevProject *project )
 
84
{
 
85
    kdDebug( 9006 ) << " **** CvsOptions::save( KDevProject* ) here" << endl;
 
86
    Q_ASSERT( project );
 
87
 
 
88
    QDomDocument &dom = *project->projectDom();
 
89
 
 
90
    DomUtil::writeBoolEntry( dom, "/kdevcvsservice/recursivewhenupdate", recursiveWhenUpdate() );
 
91
    DomUtil::writeBoolEntry( dom, "/kdevcvsservice/prunedirswhenupdate", pruneEmptyDirsWhenUpdate() );
 
92
    DomUtil::writeBoolEntry( dom, "/kdevcvsservice/createdirswhenupdate", createDirsWhenUpdate() );
 
93
    DomUtil::writeBoolEntry( dom, "/kdevcvsservice/recursivewhencommitremove", recursiveWhenCommitRemove() );
 
94
    DomUtil::writeEntry( dom, "/kdevcvsservice/revertoptions", revertOptions() );
 
95
//    DomUtil::writeEntry( dom, "/kdevcvsservice/location", location() );
 
96
 
 
97
    // [Repository-:ext:anonymous@cvs.ogre.sourceforge.net:/cvsroot/ogrenew]
 
98
    QString groupName = "Repository-" + guessLocation( project->projectDirectory() );
 
99
    m_serviceConfig->setGroup( groupName );
 
100
 
 
101
    m_serviceConfig->writeEntry( "ContextLines", contextLines() );
 
102
    m_serviceConfig->writeEntry( "DiffOptions", diffOptions() );
 
103
    m_serviceConfig->writeEntry( "rsh", cvsRshEnvVar() );
 
104
}
 
105
 
 
106
///////////////////////////////////////////////////////////////////////////////
 
107
 
 
108
void CvsOptions::load( KDevProject *project )
 
109
{
 
110
    kdDebug( 9006 ) << " **** CvsOptions::load( KDevProject* ) here" << endl;
 
111
    Q_ASSERT( project );
 
112
    QDomDocument &dom = *project->projectDom();
 
113
 
 
114
    m_recursiveWhenUpdate = DomUtil::readBoolEntry( dom, "/kdevcvsservice/recursivewhenupdate", true );
 
115
    m_pruneEmptyDirsWhenUpdate = DomUtil::readBoolEntry( dom, "/kdevcvsservice/prunedirswhenupdate", true );
 
116
    m_createDirsWhenUpdate = DomUtil::readBoolEntry( dom, "/kdevcvsservice/createdirswhenupdate", true );
 
117
    m_recursiveWhenCommitRemove = DomUtil::readBoolEntry( dom, "/kdevcvsservice/recursivewhencommitremove", true );
 
118
    m_revertOptions = DomUtil::readEntry( dom, "/kdevcvsservice/revertoptions", default_revert );
 
119
//    m_location = DomUtil::readEntry( dom, "/kdevcvsservice/location", guessLocation( project->projectDirectory() ) );
 
120
 
 
121
    QString groupName = "Repository-" + guessLocation( project->projectDirectory() );
 
122
    m_serviceConfig->setGroup( groupName );
 
123
 
 
124
    m_contextLines = m_serviceConfig->readUnsignedNumEntry( "ContextLines", default_contextLines );
 
125
    m_diffOptions  = m_serviceConfig->readEntry( "DiffOptions", default_diff );
 
126
    m_cvsRshEnvVar = m_serviceConfig->readEntry( "rsh", default_rsh );
 
127
}
 
128
 
 
129
///////////////////////////////////////////////////////////////////////////////
 
130
 
 
131
void CvsOptions::setRecursiveWhenCommitRemove( bool b )
 
132
{
 
133
    this->m_recursiveWhenCommitRemove = b;
 
134
}
 
135
 
 
136
///////////////////////////////////////////////////////////////////////////////
 
137
 
 
138
bool CvsOptions::recursiveWhenCommitRemove() const
 
139
{
 
140
    return this->m_recursiveWhenCommitRemove;
 
141
}
 
142
 
 
143
///////////////////////////////////////////////////////////////////////////////
 
144
 
 
145
void CvsOptions::setPruneEmptyDirsWhenUpdate( bool b )
 
146
{
 
147
    this->m_pruneEmptyDirsWhenUpdate = b;
 
148
}
 
149
 
 
150
///////////////////////////////////////////////////////////////////////////////
 
151
 
 
152
bool CvsOptions::pruneEmptyDirsWhenUpdate() const
 
153
{
 
154
    return this->m_pruneEmptyDirsWhenUpdate;
 
155
}
 
156
 
 
157
///////////////////////////////////////////////////////////////////////////////
 
158
 
 
159
void CvsOptions::setRecursiveWhenUpdate( bool b )
 
160
{
 
161
    this->m_recursiveWhenUpdate = b;
 
162
}
 
163
 
 
164
///////////////////////////////////////////////////////////////////////////////
 
165
 
 
166
bool CvsOptions::recursiveWhenUpdate() const
 
167
{
 
168
    return this->m_recursiveWhenUpdate;
 
169
}
 
170
 
 
171
///////////////////////////////////////////////////////////////////////////////
 
172
 
 
173
void CvsOptions::setCreateDirsWhenUpdate( bool b )
 
174
{
 
175
    this->m_createDirsWhenUpdate = b;
 
176
}
 
177
 
 
178
///////////////////////////////////////////////////////////////////////////////
 
179
 
 
180
bool CvsOptions::createDirsWhenUpdate() const
 
181
{
 
182
    return this->m_createDirsWhenUpdate;
 
183
}
 
184
 
 
185
///////////////////////////////////////////////////////////////////////////////
 
186
 
 
187
void CvsOptions::setRevertOptions( const QString &p )
 
188
{
 
189
    this->m_revertOptions = p;
 
190
}
 
191
 
 
192
///////////////////////////////////////////////////////////////////////////////
 
193
 
 
194
QString CvsOptions::revertOptions()
 
195
{
 
196
    return this->m_revertOptions;
 
197
}
 
198
 
 
199
///////////////////////////////////////////////////////////////////////////////
 
200
 
 
201
void CvsOptions::setDiffOptions( const QString &p )
 
202
{
 
203
    this->m_diffOptions = p;
 
204
}
 
205
 
 
206
///////////////////////////////////////////////////////////////////////////////
 
207
 
 
208
QString CvsOptions::diffOptions()
 
209
{
 
210
    return this->m_diffOptions;
 
211
}
 
212
 
 
213
///////////////////////////////////////////////////////////////////////////////
 
214
 
 
215
void CvsOptions::setCvsRshEnvVar( const QString &p )
 
216
{
 
217
    this->m_cvsRshEnvVar = p;
 
218
}
 
219
 
 
220
///////////////////////////////////////////////////////////////////////////////
 
221
 
 
222
QString CvsOptions::cvsRshEnvVar()
 
223
{
 
224
    return this->m_cvsRshEnvVar;
 
225
}
 
226
 
 
227
///////////////////////////////////////////////////////////////////////////////
 
228
 
 
229
QString CvsOptions::location()
 
230
{
 
231
    return m_location;
 
232
}
 
233
 
 
234
///////////////////////////////////////////////////////////////////////////////
 
235
 
 
236
void CvsOptions::setLocation( const QString &p )
 
237
{
 
238
    m_location = p;
 
239
}
 
240
 
 
241
///////////////////////////////////////////////////////////////////////////////
 
242
 
 
243
void CvsOptions::setContextLines( unsigned int contextLines )
 
244
{
 
245
    m_contextLines = contextLines;
 
246
}
 
247
 
 
248
///////////////////////////////////////////////////////////////////////////////
 
249
 
 
250
unsigned int CvsOptions::contextLines() const
 
251
{
 
252
    return m_contextLines;
 
253
}
 
254
 
 
255
///////////////////////////////////////////////////////////////////////////////
 
256
 
 
257
void CvsOptions::setCompressionLevel( unsigned int compressionLevel )
 
258
{
 
259
    m_compressionLevel = compressionLevel;
 
260
}
 
261
 
 
262
///////////////////////////////////////////////////////////////////////////////
 
263
 
 
264
unsigned int CvsOptions::compressionLevel() const
 
265
{
 
266
    return m_compressionLevel;
 
267
}
 
268
 
 
269
///////////////////////////////////////////////////////////////////////////////
 
270
 
 
271
QString CvsOptions::guessLocation( const QString &projectDir ) const
 
272
{
 
273
    QString rootFileName( projectDir + "/CVS/Root" );
 
274
 
 
275
    QFile f( rootFileName );
 
276
    if (f.open( IO_ReadOnly ))
 
277
    {
 
278
        QTextStream t( &f );
 
279
        QString serverLocation = t.readLine();
 
280
        kdDebug(9000) << "===> Server location guessed: " << serverLocation << endl;
 
281
        return serverLocation;
 
282
    }
 
283
    else
 
284
    {
 
285
        kdDebug(9000) << "===> Error: could not open CVS/Entries!! " << endl;
 
286
        return i18n( "Error while guessing repository location." );
 
287
    }
 
288
}