summaryrefslogtreecommitdiff
path: root/src/plugins/mercurial/mercurialsettings.cpp
blob: 32ff663990b14aebcea1471016a19034690ebbcf (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
#include "mercurialsettings.h"
#include "constants.h"

#include <coreplugin/icore.h>

#include <QtCore/QSettings>


using namespace Mercurial::Internal;

MercurialSettings::MercurialSettings()
{
    readSettings();
}

QString MercurialSettings::binary()
{
    return bin;
}

QString MercurialSettings::application()
{
    return app;
}

QStringList MercurialSettings::standardArguments()
{
    return standardArgs;
}

QString MercurialSettings::userName()
{
    return user;
}

QString MercurialSettings::email()
{
    return mail;
}

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

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

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

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

void MercurialSettings::writeSettings(const QString &application, const QString &userName,
                                      const QString &email, int logCount, int timeout, bool prompt)
{
    QSettings *settings = Core::ICore::instance()->settings();
    if (settings) {
        settings->beginGroup("Mercurial");
        settings->setValue(Constants::MERCURIALPATH, application);
        settings->setValue(Constants::MERCURIALUSERNAME, userName);
        settings->setValue(Constants::MERCURIALEMAIL, email);
        settings->setValue(Constants::MERCURIALLOGCOUNT, logCount);
        settings->setValue(Constants::MERCURIALTIMEOUT, timeout);
        settings->setValue(Constants::MERCURIALPROMPTSUBMIT, prompt);
        settings->endGroup();
    }

    app = application;
    user = userName;
    mail = email;
    m_logCount = logCount;
    m_timeout = timeout;
    m_prompt = prompt;
    setBinAndArgs();
}

void MercurialSettings::readSettings()
{
    QSettings *settings = Core::ICore::instance()->settings();
    if (settings) {
        settings->beginGroup("Mercurial");
        app = settings->value(Constants::MERCURIALPATH, Constants::MERCURIALDEFAULT).toString();
        user = settings->value(Constants::MERCURIALUSERNAME, "").toString();
        mail = settings->value(Constants::MERCURIALEMAIL, "").toString();
        m_logCount = settings->value(Constants::MERCURIALLOGCOUNT, 0).toInt();
        m_timeout = settings->value(Constants::MERCURIALTIMEOUT, 30).toInt();
        m_prompt = settings->value(Constants::MERCURIALPROMPTSUBMIT, true).toBool();
        settings->endGroup();
    }

    setBinAndArgs();
}

void MercurialSettings::setBinAndArgs()
{
    standardArgs.clear();

#ifdef Q_OS_WIN
    bin = QLatin1String("cmd.exe");
    standardArgs << "/c" << app;
#else
    bin = app;
#endif
}