aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/bazaar/pullorpushdialog.cpp
blob: 3789338d4f25e54de4ee8c26475b1d0360f1ceb9 (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
150
151
152
153
154
155
156
// Copyright (C) 2016 Hugues Delorme
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "pullorpushdialog.h"

#include "bazaartr.h"

#include <utils/qtcassert.h>
#include <utils/layoutbuilder.h>

#include <QCheckBox>
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QRadioButton>

namespace Bazaar::Internal {

PullOrPushDialog::PullOrPushDialog(Mode mode, QWidget *parent)
    : QDialog(parent), m_mode(mode)
{
    resize(477, 388);

    setWindowTitle(Tr::tr("Dialog"));

    m_defaultButton = new QRadioButton(Tr::tr("Default location"));
    m_defaultButton->setChecked(true);

    m_localButton = new QRadioButton(Tr::tr("Local filesystem:"));

    m_localPathChooser = new Utils::PathChooser;
    m_localPathChooser->setEnabled(false);

    auto urlButton = new QRadioButton(Tr::tr("Specify URL:"));
    urlButton->setToolTip(Tr::tr("For example: \"https://[user[:pass]@]host[:port]/[path]\"."));

    m_urlLineEdit = new QLineEdit;
    m_urlLineEdit->setEnabled(false);
    m_urlLineEdit->setToolTip(Tr::tr("For example: \"https://[user[:pass]@]host[:port]/[path]\"."));

    m_rememberCheckBox = new QCheckBox(Tr::tr("Remember specified location as default"));
    m_rememberCheckBox->setEnabled(false);

    m_overwriteCheckBox = new QCheckBox(Tr::tr("Overwrite"));
    m_overwriteCheckBox->setToolTip(Tr::tr("Ignores differences between branches and overwrites\n"
        "unconditionally."));

    m_useExistingDirCheckBox = new QCheckBox(Tr::tr("Use existing directory"));
    m_useExistingDirCheckBox->setToolTip(Tr::tr("By default, push will fail if the target directory "
        "exists, but does not already have a control directory.\n"
        "This flag will allow push to proceed."));

    m_createPrefixCheckBox = new QCheckBox(Tr::tr("Create prefix"));
    m_createPrefixCheckBox->setToolTip(Tr::tr("Creates the path leading up to the branch "
                                          "if it does not already exist."));

    m_revisionLineEdit = new QLineEdit;

    m_localCheckBox = new QCheckBox(Tr::tr("Local"));
    m_localCheckBox->setToolTip(Tr::tr("Performs a local pull in a bound branch.\n"
        "Local pulls are not applied to the master branch."));

    auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);

    m_localPathChooser->setExpectedKind(Utils::PathChooser::Directory);
    if (m_mode == PullMode) {
        setWindowTitle(Tr::tr("Pull Source"));
        m_useExistingDirCheckBox->setVisible(false);
        m_createPrefixCheckBox->setVisible(false);
    } else {
        setWindowTitle(Tr::tr("Push Destination"));
        m_localCheckBox->setVisible(false);
    }

    using namespace Layouting;
    Column {
        Group {
            title(Tr::tr("Branch Location")),
            Form {
                m_defaultButton, br,
                m_localButton, m_localPathChooser, br,
                urlButton,  m_urlLineEdit, br,
            }
        },
        Group {
            title(Tr::tr("Options")),
            Column {
                m_rememberCheckBox,
                m_overwriteCheckBox,
                m_localCheckBox,
                m_useExistingDirCheckBox,
                m_createPrefixCheckBox,
                Row { Tr::tr("Revision:"), m_revisionLineEdit },
            }
        },
        buttonBox,
    }.attachTo(this);

    setFixedHeight(sizeHint().height());
    setSizeGripEnabled(true);

    connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
    connect(urlButton, &QRadioButton::toggled, m_urlLineEdit, &QWidget::setEnabled);
    connect(m_localButton, &QAbstractButton::toggled, m_localPathChooser, &QWidget::setEnabled);
    connect(urlButton, &QRadioButton::toggled, m_rememberCheckBox, &QWidget::setEnabled);
    connect(m_localButton, &QRadioButton::toggled, m_rememberCheckBox, &QWidget::setEnabled);
}

PullOrPushDialog::~PullOrPushDialog() = default;

QString PullOrPushDialog::branchLocation() const
{
    if (m_defaultButton->isChecked())
        return {};
    if (m_localButton->isChecked())
        return m_localPathChooser->filePath().path();
    return m_urlLineEdit->text();
}

bool PullOrPushDialog::isRememberOptionEnabled() const
{
    if (m_defaultButton->isChecked())
        return false;
    return m_rememberCheckBox->isChecked();
}

bool PullOrPushDialog::isOverwriteOptionEnabled() const
{
    return m_overwriteCheckBox->isChecked();
}

QString PullOrPushDialog::revision() const
{
    return m_revisionLineEdit->text().simplified();
}

bool PullOrPushDialog::isLocalOptionEnabled() const
{
    QTC_ASSERT(m_mode == PullMode, return false);
    return m_localCheckBox->isChecked();
}

bool PullOrPushDialog::isUseExistingDirectoryOptionEnabled() const
{
    QTC_ASSERT(m_mode == PushMode, return false);
    return m_useExistingDirCheckBox->isChecked();
}

bool PullOrPushDialog::isCreatePrefixOptionEnabled() const
{
    QTC_ASSERT(m_mode == PushMode, return false);
    return m_createPrefixCheckBox->isChecked();
}

} // Bazaar::Internal