settingspage.cpp 6.02 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "settingspage.h"
31 32
#include "gitsettings.h"
#include "gitplugin.h"
33
#include "gitclient.h"
con's avatar
con committed
34

35
#include <vcsbase/vcsbaseconstants.h>
36
#include <utils/hostosinfo.h>
37

38 39 40 41
#include <QDir>
#include <QDebug>
#include <QTextStream>
#include <QMessageBox>
con's avatar
con committed
42

43 44
namespace Git {
namespace Internal {
con's avatar
con committed
45

46 47 48 49
SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
    QWidget(parent)
{
    m_ui.setupUi(this);
50 51 52 53 54 55 56 57 58 59 60 61 62
    if (Utils::HostOsInfo::isWindowsHost()) {
        const QByteArray currentHome = qgetenv("HOME");
        const QString toolTip
                = tr("Set the environment variable HOME to '%1'\n(%2).\n"
                     "This causes msysgit to look for the SSH-keys in that location\n"
                     "instead of its installation directory when run outside git bash.").
                arg(QDir::homePath(),
                    currentHome.isEmpty() ? tr("not currently set") :
                            tr("currently set to '%1'").arg(QString::fromLocal8Bit(currentHome)));
        m_ui.winHomeCheckBox->setToolTip(toolTip);
    } else {
        m_ui.winHomeCheckBox->setVisible(false);
    }
63 64
    m_ui.repBrowserCommandPathChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
    m_ui.repBrowserCommandPathChooser->setPromptDialogTitle(tr("Git Repository Browser Command"));
65
}
con's avatar
con committed
66

67
GitSettings SettingsPageWidget::settings() const
con's avatar
con committed
68
{
69
    GitSettings rc;
70 71 72 73
    rc.setValue(GitSettings::pathKey, m_ui.pathLineEdit->text());
    rc.setValue(GitSettings::logCountKey, m_ui.logCountSpinBox->value());
    rc.setValue(GitSettings::timeoutKey, m_ui.timeoutSpinBox->value());
    rc.setValue(GitSettings::pullRebaseKey, m_ui.pullRebaseCheckBox->isChecked());
74
    rc.setValue(GitSettings::showTagsKey, m_ui.showTagsCheckBox->isChecked());
75 76 77
    rc.setValue(GitSettings::promptOnSubmitKey, m_ui.promptToSubmitCheckBox->isChecked());
    rc.setValue(GitSettings::winSetHomeEnvironmentKey, m_ui.winHomeCheckBox->isChecked());
    rc.setValue(GitSettings::gitkOptionsKey, m_ui.gitkOptionsLineEdit->text().trimmed());
78
    rc.setValue(GitSettings::repositoryBrowserCmd, m_ui.repBrowserCommandPathChooser->path().trimmed());
79 80
    return rc;
}
con's avatar
con committed
81

82 83
void SettingsPageWidget::setSettings(const GitSettings &s)
{
84 85 86 87
    m_ui.pathLineEdit->setText(s.stringValue(GitSettings::pathKey));
    m_ui.logCountSpinBox->setValue(s.intValue(GitSettings::logCountKey));
    m_ui.timeoutSpinBox->setValue(s.intValue(GitSettings::timeoutKey));
    m_ui.pullRebaseCheckBox->setChecked(s.boolValue(GitSettings::pullRebaseKey));
88
    m_ui.showTagsCheckBox->setChecked(s.boolValue(GitSettings::showTagsKey));
89 90 91
    m_ui.promptToSubmitCheckBox->setChecked(s.boolValue(GitSettings::promptOnSubmitKey));
    m_ui.winHomeCheckBox->setChecked(s.boolValue(GitSettings::winSetHomeEnvironmentKey));
    m_ui.gitkOptionsLineEdit->setText(s.stringValue(GitSettings::gitkOptionsKey));
92
    m_ui.repBrowserCommandPathChooser->setPath(s.stringValue(GitSettings::repositoryBrowserCmd));
93 94
}

95 96 97
QString SettingsPageWidget::searchKeywords() const
{
    QString rc;
98 99 100 101 102 103 104 105 106 107 108
    QLatin1Char sep(' ');
    QTextStream(&rc)
            << sep << m_ui.pathlabel->text()
            << sep << m_ui.winHomeCheckBox->text()
            << sep << m_ui.groupBox->title()
            << sep << m_ui.logCountLabel->text()
            << sep << m_ui.timeoutLabel->text()
            << sep << m_ui.promptToSubmitCheckBox->text()
            << sep << m_ui.promptToSubmitCheckBox->text()
            << sep << m_ui.gitkGroupBox->title()
            << sep << m_ui.gitkOptionsLabel->text()
109 110
            << sep << m_ui.repBrowserGroupBox->title()
            << sep << m_ui.repBrowserCommandLabel->text()
111
               ;
112 113 114 115
    rc.remove(QLatin1Char('&'));
    return rc;
}

116
// -------- SettingsPage
117 118
SettingsPage::SettingsPage() :
    m_widget(0)
119
{
hjk's avatar
hjk committed
120
    setId(VcsBase::Constants::VCS_ID_GIT);
121
    setDisplayName(tr("Git"));
con's avatar
con committed
122 123 124 125
}

QWidget *SettingsPage::createPage(QWidget *parent)
{
dt's avatar
dt committed
126
    m_widget = new SettingsPageWidget(parent);
127
    m_widget->setSettings(GitPlugin::instance()->settings());
128 129
    if (m_searchKeywords.isEmpty())
        m_searchKeywords = m_widget->searchKeywords();
130
    return m_widget;
con's avatar
con committed
131 132
}

133
void SettingsPage::apply()
con's avatar
con committed
134
{
135 136 137 138 139 140 141 142 143
    const GitSettings newSettings = m_widget->settings();
    // Warn if git cannot be found in path if the widget is on top
    if (m_widget->isVisible()) {
        bool gitFoundOk;
        QString errorMessage;
        newSettings.gitBinaryPath(&gitFoundOk, &errorMessage);
        if (!gitFoundOk)
            QMessageBox::warning(m_widget, tr("Git Settings"), errorMessage);
    }
con's avatar
con committed
144

145 146
    GitPlugin::instance()->setSettings(newSettings);
}
147 148 149 150 151 152

bool SettingsPage::matches(const QString &s) const
{
    return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}

153
}
con's avatar
con committed
154
}