aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/clearcase/settingspage.cpp
blob: 010d3d1e98ee06cde035e2c04d4125d4a477920c (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Copyright (C) 2016 AudioCodes Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "settingspage.h"

#include "clearcaseconstants.h"
#include "clearcaseplugin.h"
#include "clearcasesettings.h"
#include "clearcasetr.h"

#include <vcsbase/vcsbaseconstants.h>

#include <utils/environment.h>
#include <utils/hostosinfo.h>
#include <utils/layoutbuilder.h>
#include <utils/pathchooser.h>

#include <QCheckBox>
#include <QCoreApplication>
#include <QLabel>
#include <QLineEdit>
#include <QRadioButton>
#include <QSpinBox>

using namespace Utils;

namespace ClearCase::Internal {

class SettingsPageWidget final : public Core::IOptionsPageWidget
{
public:
    SettingsPageWidget();

private:
    void apply() final;

    Utils::PathChooser *commandPathChooser;
    QRadioButton *graphicalDiffRadioButton;
    QRadioButton *externalDiffRadioButton;
    QLineEdit *diffArgsEdit;
    QSpinBox *historyCountSpinBox;
    QSpinBox *timeOutSpinBox;
    QCheckBox *autoCheckOutCheckBox;
    QCheckBox *promptCheckBox;
    QCheckBox *disableIndexerCheckBox;
    QLineEdit *indexOnlyVOBsEdit;
    QCheckBox *autoAssignActivityCheckBox;
    QCheckBox *noCommentCheckBox;
};

SettingsPageWidget::SettingsPageWidget()
{
    commandPathChooser = new PathChooser;
    commandPathChooser->setPromptDialogTitle(Tr::tr("ClearCase Command"));
    commandPathChooser->setExpectedKind(PathChooser::ExistingCommand);
    commandPathChooser->setHistoryCompleter("ClearCase.Command.History");

    graphicalDiffRadioButton = new QRadioButton(Tr::tr("&Graphical (single file only)"));
    graphicalDiffRadioButton->setChecked(true);

    auto diffWidget = new QWidget;
    diffWidget->setEnabled(false);

    externalDiffRadioButton = new QRadioButton(Tr::tr("&External"));
    QObject::connect(externalDiffRadioButton, &QRadioButton::toggled, diffWidget, &QWidget::setEnabled);

    diffArgsEdit = new QLineEdit(diffWidget);

    QPalette palette;
    QBrush brush(QColor(255, 0, 0, 255));
    brush.setStyle(Qt::SolidPattern);
    palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
    palette.setBrush(QPalette::Inactive, QPalette::WindowText, brush);
    QBrush brush1(QColor(68, 96, 92, 255));
    brush1.setStyle(Qt::SolidPattern);
    palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush1);

    auto diffWarningLabel = new QLabel;
    diffWarningLabel->setPalette(palette);
    diffWarningLabel->setWordWrap(true);

    historyCountSpinBox = new QSpinBox;
    historyCountSpinBox->setMaximum(10000);

    timeOutSpinBox = new QSpinBox;
    timeOutSpinBox->setSuffix(Tr::tr("s", nullptr));
    timeOutSpinBox->setRange(1, 360);
    timeOutSpinBox->setValue(30);

    autoCheckOutCheckBox = new QCheckBox(Tr::tr("&Automatically check out files on edit"));

    promptCheckBox = new QCheckBox(Tr::tr("&Prompt on check-in"));

    disableIndexerCheckBox = new QCheckBox(Tr::tr("Di&sable indexer"));

    indexOnlyVOBsEdit = new QLineEdit;
    indexOnlyVOBsEdit->setToolTip(Tr::tr("VOBs list, separated by comma. Indexer will only traverse "
        "the specified VOBs. If left blank, all active VOBs will be indexed."));

    autoAssignActivityCheckBox = new QCheckBox(Tr::tr("Aut&o assign activity names"));
    autoAssignActivityCheckBox->setToolTip(Tr::tr("Check this if you have a trigger that renames "
        "the activity automatically. You will not be prompted for activity name."));

    noCommentCheckBox = new QCheckBox(Tr::tr("Do &not prompt for comment during checkout or check-in"));
    noCommentCheckBox->setToolTip(Tr::tr("Check out or check in files with no comment (-nc/omment)."));

    using namespace Layouting;

    Form {
        Tr::tr("Arg&uments:"), diffArgsEdit, noMargin
    }.attachTo(diffWidget);

    Column {
        Group {
            title(Tr::tr("Configuration")),
            Form {
                Tr::tr("&Command:"), commandPathChooser
            }
        },

        Group {
            title(Tr::tr("Diff")),
            Form {
                graphicalDiffRadioButton, br,
                externalDiffRadioButton, diffWidget, br,
                Span(2, diffWarningLabel)
            }
        },

        Group {
            title(Tr::tr("Miscellaneous")),
            Form {
                Tr::tr("&History count:"), historyCountSpinBox, br,
                Tr::tr("&Timeout:"), timeOutSpinBox, br,
                autoCheckOutCheckBox, br,
                autoAssignActivityCheckBox, br,
                noCommentCheckBox, br,
                promptCheckBox, br,
                disableIndexerCheckBox, br,
                Tr::tr("&Index only VOBs:"), indexOnlyVOBsEdit,
             }
        },
        st
    }.attachTo(this);

    const ClearCaseSettings &s = settings();

    commandPathChooser->setFilePath(FilePath::fromString(s.ccCommand));
    timeOutSpinBox->setValue(s.timeOutS);
    autoCheckOutCheckBox->setChecked(s.autoCheckOut);
    noCommentCheckBox->setChecked(s.noComment);
    bool extDiffAvailable = !Environment::systemEnvironment().searchInPath(QLatin1String("diff")).isEmpty();
    if (extDiffAvailable) {
        diffWarningLabel->setVisible(false);
    } else {
        QString diffWarning = Tr::tr("In order to use External diff, \"diff\" command needs to be accessible.");
        if (HostOsInfo::isWindowsHost()) {
            diffWarning += QLatin1Char(' ');
            diffWarning.append(Tr::tr("DiffUtils is available for free download at "
                                      "http://gnuwin32.sourceforge.net/packages/diffutils.htm. "
                                      "Extract it to a directory in your PATH."));
        }
        diffWarningLabel->setText(diffWarning);
        externalDiffRadioButton->setEnabled(false);
    }
    if (extDiffAvailable && s.diffType == ExternalDiff)
        externalDiffRadioButton->setChecked(true);
    else
        graphicalDiffRadioButton->setChecked(true);
    autoAssignActivityCheckBox->setChecked(s.autoAssignActivityName);
    historyCountSpinBox->setValue(s.historyCount);
    disableIndexerCheckBox->setChecked(s.disableIndexer);
    diffArgsEdit->setText(s.diffArgs);
    indexOnlyVOBsEdit->setText(s.indexOnlyVOBs);
}

void SettingsPageWidget::apply()
{
    ClearCaseSettings rc;
    rc.ccCommand = commandPathChooser->rawFilePath().toString();
    rc.ccBinaryPath = commandPathChooser->filePath();
    rc.timeOutS = timeOutSpinBox->value();
    rc.autoCheckOut = autoCheckOutCheckBox->isChecked();
    rc.noComment = noCommentCheckBox->isChecked();
    if (graphicalDiffRadioButton->isChecked())
        rc.diffType = GraphicalDiff;
    else if (externalDiffRadioButton->isChecked())
        rc.diffType = ExternalDiff;
    rc.autoAssignActivityName = autoAssignActivityCheckBox->isChecked();
    rc.historyCount = historyCountSpinBox->value();
    rc.disableIndexer = disableIndexerCheckBox->isChecked();
    rc.diffArgs = diffArgsEdit->text();
    rc.indexOnlyVOBs = indexOnlyVOBsEdit->text();
    rc.extDiffAvailable = externalDiffRadioButton->isEnabled();

    setSettings(rc);
}

ClearCaseSettingsPage::ClearCaseSettingsPage()
{
    setId(ClearCase::Constants::VCS_ID_CLEARCASE);
    setDisplayName(Tr::tr("ClearCase"));
    setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
    setWidgetCreator([] { return new SettingsPageWidget; });
}

} // ClearCase::Internal