OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / cvs / cvssettings.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "cvssettings.h"
35
36 #include <QtCore/QSettings>
37 #include <QtCore/QTextStream>
38
39 static const char *groupC = "CVS";
40 static const char *commandKeyC = "Command";
41 static const char *rootC = "Root";
42 static const char *promptToSubmitKeyC = "PromptForSubmit";
43 static const char *diffOptionsKeyC = "DiffOptions";
44 static const char *describeByCommitIdKeyC = "DescribeByCommitId";
45 static const char *defaultDiffOptions = "-du";
46 static const char *timeOutKeyC = "TimeOut";
47
48 enum { defaultTimeOutS = 30 };
49
50 static QString defaultCommand()
51 {
52     QString rc;
53     rc = QLatin1String("cvs");
54 #if defined(Q_OS_WIN32)
55     rc.append(QLatin1String(".exe"));
56 #endif
57     return rc;
58 }
59
60 namespace CVS {
61 namespace Internal {
62
63 CVSSettings::CVSSettings() :
64     cvsCommand(defaultCommand()),
65     cvsDiffOptions(QLatin1String(defaultDiffOptions)),
66     timeOutS(defaultTimeOutS),
67     promptToSubmit(true),
68     describeByCommitId(true)
69 {
70 }
71
72 void CVSSettings::fromSettings(QSettings *settings)
73 {
74     settings->beginGroup(QLatin1String(groupC));
75     cvsCommand = settings->value(QLatin1String(commandKeyC), defaultCommand()).toString();
76     promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
77     cvsRoot = settings->value(QLatin1String(rootC), QString()).toString();
78     cvsDiffOptions = settings->value(QLatin1String(diffOptionsKeyC), QLatin1String(defaultDiffOptions)).toString();
79     describeByCommitId = settings->value(QLatin1String(describeByCommitIdKeyC), true).toBool();
80     timeOutS = settings->value(QLatin1String(timeOutKeyC), defaultTimeOutS).toInt();
81     settings->endGroup();
82 }
83
84 void CVSSettings::toSettings(QSettings *settings) const
85 {
86     settings->beginGroup(QLatin1String(groupC));
87     settings->setValue(QLatin1String(commandKeyC), cvsCommand);
88     settings->setValue(QLatin1String(promptToSubmitKeyC), promptToSubmit);
89     settings->setValue(QLatin1String(rootC), cvsRoot);
90     settings->setValue(QLatin1String(diffOptionsKeyC), cvsDiffOptions);
91     settings->setValue(QLatin1String(timeOutKeyC), timeOutS);
92     settings->setValue(QLatin1String(describeByCommitIdKeyC), describeByCommitId);
93     settings->endGroup();
94 }
95
96 bool CVSSettings::equals(const CVSSettings &s) const
97 {
98     return promptToSubmit     == promptToSubmit
99         && describeByCommitId == s.describeByCommitId
100         && cvsCommand         == s.cvsCommand
101         && cvsRoot            == s.cvsRoot
102         && timeOutS           == s.timeOutS
103         && cvsDiffOptions     == s.cvsDiffOptions;
104 }
105
106 QStringList CVSSettings::addOptions(const QStringList &args) const
107 {
108     if (cvsRoot.isEmpty())
109         return args;
110
111     QStringList rc;
112     rc.push_back(QLatin1String("-d"));
113     rc.push_back(cvsRoot);
114     rc.append(args);
115     return rc;
116 }
117
118 } // namespace Internal
119 } // namespace CVS