summaryrefslogtreecommitdiff
path: root/src/plugins/mercurial/mercurialsettings.cpp
blob: cbe398b9ec7667d7e52a5c89d6849a921d89cc83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Brian McGillion
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#include "mercurialsettings.h"
#include "constants.h"

#include <QtCore/QSettings>

using namespace Mercurial::Internal;

enum { timeOutDefaultSeconds = 30 };

MercurialSettings::MercurialSettings() :
   m_binary(QLatin1String(Constants::MERCURIALDEFAULT)),
   m_logCount(0),
   m_timeoutSeconds(timeOutDefaultSeconds),
   m_prompt(true)
{
}

QString MercurialSettings::binary() const
{
    return m_binary;
}

void MercurialSettings::setBinary(const QString &b)
{
    m_binary = b;
}

QStringList MercurialSettings::standardArguments() const
{
    return m_standardArguments;
}

QString MercurialSettings::userName() const
{
    return m_user;
}

void MercurialSettings::setUserName(const QString &u)
{
    m_user = u;
}

QString MercurialSettings::email() const
{
    return m_mail;
}

void MercurialSettings::setEmail(const QString &m)
{
    m_mail = m;
}

int MercurialSettings::logCount() const
{
    return m_logCount;
}

void MercurialSettings::setLogCount(int l)
{
    m_logCount = l;
}

int MercurialSettings::timeoutMilliSeconds() const
{
    //return timeout is in Ms
    return m_timeoutSeconds * 1000;
}

int MercurialSettings::timeoutSeconds() const
{
    //return timeout in seconds (as the user specifies on the options page
    return m_timeoutSeconds;
}

void MercurialSettings::setTimeoutSeconds(int s)
{
    m_timeoutSeconds = s;
}

bool MercurialSettings::prompt() const
{
    return m_prompt;
}

void MercurialSettings::setPrompt(bool b)
{
    m_prompt = b;
}

void MercurialSettings::writeSettings(QSettings *settings) const
{
    settings->beginGroup(QLatin1String("Mercurial"));
    settings->setValue(QLatin1String(Constants::MERCURIALPATH), m_binary);
    settings->setValue(QLatin1String(Constants::MERCURIALUSERNAME), m_user);
    settings->setValue(QLatin1String(Constants::MERCURIALEMAIL), m_mail);
    settings->setValue(QLatin1String(Constants::MERCURIALLOGCOUNT), m_logCount);
    settings->setValue(QLatin1String(Constants::MERCURIALTIMEOUT), m_timeoutSeconds);
    settings->setValue(QLatin1String(Constants::MERCURIALPROMPTSUBMIT), m_prompt);
    settings->endGroup();
}

void MercurialSettings::readSettings(const QSettings *settings)
{
    const QString keyRoot = QLatin1String("Mercurial/");
    m_binary = settings->value(keyRoot + QLatin1String(Constants::MERCURIALPATH),
                               QLatin1String(Constants::MERCURIALDEFAULT)).toString();
    m_user = settings->value(keyRoot + QLatin1String(Constants::MERCURIALUSERNAME), QString()).toString();
    m_mail = settings->value(keyRoot + QLatin1String(Constants::MERCURIALEMAIL), QString()).toString();
    m_logCount = settings->value(keyRoot + QLatin1String(Constants::MERCURIALLOGCOUNT), 0).toInt();
    m_timeoutSeconds = settings->value(keyRoot + QLatin1String(Constants::MERCURIALTIMEOUT), timeOutDefaultSeconds).toInt();
    m_prompt = settings->value(keyRoot + QLatin1String(Constants::MERCURIALPROMPTSUBMIT), true).toBool();
}

bool MercurialSettings::equals(const MercurialSettings &rhs) const
{
    return m_binary == rhs.m_binary && m_standardArguments == rhs.m_standardArguments
            && m_user == rhs.m_user && m_mail == rhs.m_mail
            && m_logCount == rhs.m_logCount && m_timeoutSeconds == rhs.m_timeoutSeconds
            && m_prompt == rhs.m_prompt;
}