vcsconfigurationpage.cpp 6.58 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
Eike Ziller's avatar
Eike Ziller committed
13
14
** conditions see http://www.qt.io/licensing.  For further information
** use the contact form at http://www.qt.io/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
25
26
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30
31
32

#include "vcsconfigurationpage.h"

33
#include "../vcsbaseconstants.h"
34
35
36

#include <coreplugin/icore.h>
#include <coreplugin/iversioncontrol.h>
37
#include <coreplugin/vcsmanager.h>
38
#include <projectexplorer/jsonwizard/jsonwizard.h>
39
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
40

41
42
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
43
44
#include <utils/qtcassert.h>

hjk's avatar
hjk committed
45
46
47
48
#include <QPushButton>
#include <QVBoxLayout>
#include <QWizardPage>

49
using namespace Core;
50
using namespace ProjectExplorer;
51

hjk's avatar
hjk committed
52
namespace VcsBase {
53
namespace Internal {
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
VcsConfigurationPageFactory::VcsConfigurationPageFactory()
{
    setTypeIdsSuffix(QLatin1String("VcsConfiguration"));
}

Utils::WizardPage *VcsConfigurationPageFactory::create(JsonWizard *wizard, Id typeId,
                                                       const QVariant &data)
{
    Q_UNUSED(wizard);

    QTC_ASSERT(canCreate(typeId), return 0);

    QVariantMap tmp = data.toMap();
    const QString vcsId = tmp.value(QLatin1String("vcsId")).toString();
    QTC_ASSERT(!vcsId.isEmpty(), return 0);

Tobias Hunger's avatar
Tobias Hunger committed
71
    auto page = new VcsConfigurationPage;
72
    page->setVersionControlId(vcsId);
73

74
    return page;
75
76
77
78
79
80
81
82
}

bool VcsConfigurationPageFactory::validateData(Id typeId, const QVariant &data,
                                               QString *errorMessage)
{
    QTC_ASSERT(canCreate(typeId), return false);

    if (data.isNull() || data.type() != QVariant::Map) {
83
        //: Do not translate "VcsConfiguration", because it is the id of a page.
84
85
86
87
88
89
90
91
        *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
                                                    "\"data\" must be a JSON object for \"VcsConfiguration\" pages.");
        return false;
    }

    QVariantMap tmp = data.toMap();
    const QString vcsId = tmp.value(QLatin1String("vcsId")).toString();
    if (vcsId.isEmpty()) {
92
        //: Do not translate "VcsConfiguration", because it is the id of a page.
93
94
95
96
97
98
99
        *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
                                                    "\"VcsConfiguration\" page requires a \"vcsId\" set.");
        return false;
    }
    return true;
}

100
101
102
class VcsConfigurationPagePrivate
{
public:
103
    const IVersionControl *m_versionControl;
104
    QString m_versionControlId;
hjk's avatar
hjk committed
105
    QPushButton *m_configureButton;
106
107
};

108
109
} // namespace Internal

110
VcsConfigurationPage::VcsConfigurationPage() : d(new Internal::VcsConfigurationPagePrivate)
111
112
113
{
    setTitle(tr("Configuration"));

114
    d->m_versionControl = 0;
115
    d->m_configureButton = new QPushButton(ICore::msgShowOptionsDialog(), this);
116
    d->m_configureButton->setEnabled(false);
117

Tobias Hunger's avatar
Tobias Hunger committed
118
    auto verticalLayout = new QVBoxLayout(this);
hjk's avatar
hjk committed
119
    verticalLayout->addWidget(d->m_configureButton);
120

Hugues Delorme's avatar
Hugues Delorme committed
121
122
    connect(d->m_configureButton, &QAbstractButton::clicked,
            this, &VcsConfigurationPage::openConfiguration);
123
124
125
126
}

VcsConfigurationPage::~VcsConfigurationPage()
{
Montel Laurent's avatar
Montel Laurent committed
127
    delete d;
128
129
}

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
void VcsConfigurationPage::setVersionControl(const IVersionControl *vc)
{
    if (vc)
        d->m_versionControlId = vc->id().toString();
    else
        d->m_versionControlId.clear();
    d->m_versionControl = 0;
}

void VcsConfigurationPage::setVersionControlId(const QString &id)
{
    d->m_versionControlId = id;
}

void VcsConfigurationPage::initializePage()
{
146
147
148
149
150
    if (d->m_versionControl) {
        disconnect(d->m_versionControl, &IVersionControl::configurationChanged,
                   this, &QWizardPage::completeChanged);
    }

151
152
    if (!d->m_versionControlId.isEmpty()) {
        auto jw = qobject_cast<JsonWizard *>(wizard());
153
154
        if (!jw) {
            //: Do not translate "VcsConfiguration", because it is the id of a page.
155
            emit reportError(tr("No version control set on \"VcsConfiguration\" page."));
156
        }
157
158
159
160
161
162

        const QString vcsId = jw ? jw->expander()->expand(d->m_versionControlId) : d->m_versionControlId;

        d->m_versionControl = VcsManager::versionControl(Id::fromString(vcsId));
        if (!d->m_versionControl) {
            emit reportError(
163
                        //: Do not translate "VcsConfiguration", because it is the id of a page.
164
165
166
167
168
169
170
171
172
                        tr("\"vcsId\" (\"%1\") is invalid for \"VcsConfiguration\" page. "
                           "Possible values are: %2.")
                        .arg(vcsId)
                        .arg(QStringList(Utils::transform(VcsManager::versionControls(), [](const IVersionControl *vc) {
                return vc->id().toString();
            })).join(QLatin1String(", "))));
        }
    }

173
174
175
    connect(d->m_versionControl, &IVersionControl::configurationChanged,
            this, &QWizardPage::completeChanged);

176
177
178
179
180
181
182
    d->m_configureButton->setEnabled(d->m_versionControl);
    if (d->m_versionControl)
        setSubTitle(tr("Please configure <b>%1</b> now.").arg(d->m_versionControl->displayName()));
    else
        setSubTitle(tr("No known version control selected."));
}

183
184
bool VcsConfigurationPage::isComplete() const
{
185
    return d->m_versionControl ? d->m_versionControl->isConfigured() : false;
186
187
188
189
}

void VcsConfigurationPage::openConfiguration()
{
190
    ICore::showOptionsDialog(d->m_versionControl->id(), this);
191
192
}

hjk's avatar
hjk committed
193
} // namespace VcsBase